InertiaComputationsVoxelGrid Namespace Reference

Functions

def BoundingBox (pebbles)
 
def VoxelGridFromPebbles (pebbles, N)
 
def ComputeVolCOMVoxelGrid (bbox, span, vox)
 
def ShiftToVoxelCOMBBoxPebbles (com, pebbles, bbox)
 
def ClumpTOIVoxelGrid (density, com, vox, bbox, span)
 
def ComputeInertiaFromVoxelGrid (OPT, DATA)
 

Function Documentation

◆ BoundingBox()

def InertiaComputationsVoxelGrid.BoundingBox (   pebbles)
14 def BoundingBox(pebbles):
15  # returns CUBIC bounding box in the shape [x_min, x_max, y_min, y_max, z_min, z_max]
16  # that encloses the clump. This bounding box is used for voxelization. Such an approach
17  # is OK if the shapes are not too oblique.
18 
19  spans = 0.5 * np.array([np.max(pebbles[:, 0] + pebbles[:, 3]) - np.min(pebbles[:, 0] - pebbles[:, 3]),
20  np.max(pebbles[:, 1] + pebbles[:, 3]) - np.min(pebbles[:, 1] - pebbles[:, 3]),
21  np.max(pebbles[:, 2] + pebbles[:, 3]) - np.min(pebbles[:, 2] - pebbles[:, 3])])
22  box_center = 0.5 * np.array([np.max(pebbles[:, 0] + pebbles[:, 3]) + np.min(pebbles[:, 0] - pebbles[:, 3]),
23  np.max(pebbles[:, 1] + pebbles[:, 3]) + np.min(pebbles[:, 1] - pebbles[:, 3]),
24  np.max(pebbles[:, 2] + pebbles[:, 3]) + np.min(pebbles[:, 2] - pebbles[:, 3])])
25  max_span = np.max(spans)
26 
27  return np.array([box_center[0] - max_span,
28  box_center[0] + max_span,
29  box_center[1] - max_span,
30  box_center[1] + max_span,
31  box_center[2] - max_span,
32  box_center[2] + max_span]), max_span
33 
34 @jit(nopython=True)
def BoundingBox(pebbles)
Definition: InertiaComputationsVoxelGrid.py:14

Referenced by VoxelGridFromPebbles().

◆ ClumpTOIVoxelGrid()

def InertiaComputationsVoxelGrid.ClumpTOIVoxelGrid (   density,
  com,
  vox,
  bbox,
  span 
)
80 def ClumpTOIVoxelGrid(density, com, vox, bbox, span):
81  TOI = np.zeros(9).reshape(3,3)
82  N = vox.shape[0]
83  for i in range(N):
84  for j in range(N):
85  for k in range(N):
86  if (vox[i,j,k]):
87  r = np.array([ bbox[0] + 2.*span *(1./ (2.*N) + i / N),
88  bbox[2] + 2.*span *(1./ (2.*N) + j / N),
89  bbox[4] + 2.*span *(1./ (2.*N) + k / N)]) - com
90  X = r[0]
91  Y = r[1]
92  Z = r[2]
93  TOI += np.array([[Y**2 + Z**2, -X*Y, -X*Z],
94  [-X*Y, X**2 + Z**2, -Y*Z],
95  [-X*Z, -Y*Z, X**2 + Y**2]])
96  return density * (2*span/N)**3 * TOI
97 
def ClumpTOIVoxelGrid(density, com, vox, bbox, span)
Definition: InertiaComputationsVoxelGrid.py:80

Referenced by ComputeInertiaFromVoxelGrid().

◆ ComputeInertiaFromVoxelGrid()

def InertiaComputationsVoxelGrid.ComputeInertiaFromVoxelGrid (   OPT,
  DATA 
)
98 def ComputeInertiaFromVoxelGrid(OPT, DATA):
99  # take array of pebbles
100  pebbles = DATA['pebbles']
101  density = DATA['density']
102 
103  # Compute voxel grid
104  N = OPT['voxNum']
105  bbox, span, vox = VoxelGridFromPebbles(pebbles, N)
106 
107  # Compute mass, and center of mass
108  vol, com = ComputeVolCOMVoxelGrid(bbox, span, vox)
109 
110  # Shift pebbles and span to make com an origin
111  pebbles, bbox = ShiftToVoxelCOMBBoxPebbles(com, pebbles, bbox)
112 
113  # Compute tensor of inertia
114  toi = ClumpTOIVoxelGrid(density, com, vox, bbox, span)
115  if OPT['verbose']: print("Tensor of inertia of voxels: ", toi)
116 
117  # Compute principal directions
118  v1, v2, v3 = ComputePrincipalDirections(toi)
119  if OPT['verbose']: print("Principal directions (voxel grid): ", v1, v2, v3)
120 
121  # Rotate to principal directions
122  if OPT['rotateToPD']:
123  pebbles, toi, v1, v2, v3 = RotateToPDPebblesTOI(pebbles, toi, v1, v2, v3)
124  if OPT['verbose']: print("Rotated principal directions: ", v1, v2, v3)
125  if OPT['verbose']:
126  print("Rotated toi: ")
127  print(toi)
128 
129  # Save all the data
130  DATA['pebbles'] = pebbles
131  DATA['mass'] = vol * DATA['density']
132  DATA['pd'] = v1, v2, v3
133  DATA['toi'] = toi
134  DATA['voxelGrid'] = vox, bbox, span
135 
136 
137  return OPT, DATA
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def ComputePrincipalDirections(toi)
Definition: InertiaComputationsPebbles.py:49
def RotateToPDPebblesTOI(pebbles, toi, v1, v2, v3)
Definition: InertiaComputationsPebbles.py:79
def VoxelGridFromPebbles(pebbles, N)
Definition: InertiaComputationsVoxelGrid.py:35
def ComputeInertiaFromVoxelGrid(OPT, DATA)
Definition: InertiaComputationsVoxelGrid.py:98
def ComputeVolCOMVoxelGrid(bbox, span, vox)
Definition: InertiaComputationsVoxelGrid.py:54
def ShiftToVoxelCOMBBoxPebbles(com, pebbles, bbox)
Definition: InertiaComputationsVoxelGrid.py:69

References ClumpTOIVoxelGrid(), InertiaComputationsPebbles.ComputePrincipalDirections(), ComputeVolCOMVoxelGrid(), Eigen::internal.print(), InertiaComputationsPebbles.RotateToPDPebblesTOI(), ShiftToVoxelCOMBBoxPebbles(), and VoxelGridFromPebbles().

Referenced by MClump.main().

◆ ComputeVolCOMVoxelGrid()

def InertiaComputationsVoxelGrid.ComputeVolCOMVoxelGrid (   bbox,
  span,
  vox 
)
54 def ComputeVolCOMVoxelGrid(bbox, span, vox):
55  # This function defines the absolute position of center of gravity of all voxels
56  N = vox.shape[0]
57  vol = np.sum(vox) * (2. * span / N)**3
58 
59  com = np.array([0.,0.,0.])
60  for i in range(N):
61  for j in range(N):
62  for k in range(N):
63  com += vox[i,j,k] * np.array([ bbox[0] + 2.*span *(1./ (2.*N) + i / N),
64  bbox[2] + 2.*span *(1./ (2.*N) + j / N),
65  bbox[4] + 2.*span *(1./ (2.*N) + k / N)])
66  return vol, com / np.sum(vox)
67 
68 @jit(nopython=True)

Referenced by ComputeInertiaFromVoxelGrid().

◆ ShiftToVoxelCOMBBoxPebbles()

def InertiaComputationsVoxelGrid.ShiftToVoxelCOMBBoxPebbles (   com,
  pebbles,
  bbox 
)
69 def ShiftToVoxelCOMBBoxPebbles(com, pebbles, bbox):
70  # Returns the coordinates of pebbles shifted such that the center of mass (COM) is at zero.
71  for j in range(len(pebbles)):
72  pebbles[j][:3] -= com
73  for i in range(3):
74  bbox[2 * i] -= com[i]
75  bbox[2 * i + 1] -= com[i]
76 
77  return pebbles, bbox
78 
79 @jit(nopython=True)

Referenced by ComputeInertiaFromVoxelGrid().

◆ VoxelGridFromPebbles()

def InertiaComputationsVoxelGrid.VoxelGridFromPebbles (   pebbles,
  N 
)
35 def VoxelGridFromPebbles(pebbles, N):
36  # this function returns decomposition of cubic domain with void and material split in binary voxels
37 
38  vox = np.zeros(N ** 3).reshape(N, N, N)
39  bbox, span = BoundingBox(pebbles)
40 
41  for i in range(N):
42  for j in range(N):
43  for k in range(N):
44  for pebble in range(len(pebbles)):
45  pos_v = np.array([bbox[0] + 2. * span * (1. / (2. * N) + i / N),
46  bbox[2] + 2. * span * (1. / (2. * N) + j / N),
47  bbox[4] + 2. * span * (1. / (2. * N) + k / N)])
48  pos_c = pebbles[pebble, :3]
49  if (np.linalg.norm(pos_c - pos_v) < pebbles[pebble, 3]):
50  vox[i, j, k] = 1.
51  return bbox, span, vox
52 
53 @jit(nopython=True)

References BoundingBox().

Referenced by ComputeInertiaFromVoxelGrid().