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

Referenced by VoxelGridFromPebbles().

◆ ClumpTOIVoxelGrid()

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

Referenced by ComputeInertiaFromVoxelGrid().

◆ ComputeInertiaFromVoxelGrid()

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

References ClumpTOIVoxelGrid(), ComputeVolCOMVoxelGrid(), Eigen::internal.print(), ShiftToVoxelComBBoxPebbles(), and VoxelGridFromPebbles().

◆ ComputeVolCOMVoxelGrid()

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

Referenced by ComputeInertiaFromVoxelGrid().

◆ ShiftToVoxelComBBoxPebbles()

def InertiaComputationsVoxelGridNonumba.ShiftToVoxelComBBoxPebbles (   com,
  pebbles,
  bbox 
)
66 def ShiftToVoxelComBBoxPebbles(com, pebbles, bbox):
67  # Returns the coordinates of pebbles shifted such that the center of mass (COM) is at zero.
68  for j in range(len(pebbles)):
69  pebbles[j][:3] -= com
70  for i in range(3):
71  bbox[2 * i] -= com[i]
72  bbox[2 * i + 1] -= com[i]
73 
74  return pebbles, bbox
75 
76 

Referenced by ComputeInertiaFromVoxelGrid().

◆ VoxelGridFromPebbles()

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

References BoundingBox().

Referenced by ComputeInertiaFromVoxelGrid().