InertiaComputationsPebbles Namespace Reference

Functions

def ComputeMassCOMPebbles (pebbles, density)
 
def ShiftToCOMPebbles (pebbles, density)
 
def ComputeTOIPebbles (pebbles, density)
 
def ComputePrincipalDirections (toi)
 
def RotateToPDPebbles (pebbles, v1, v2, v3)
 
def RotateToPDPebblesTOI (pebbles, toi, v1, v2, v3)
 
def ComputeInertiaFromPebbles (OPT, DATA)
 

Function Documentation

◆ ComputeInertiaFromPebbles()

def InertiaComputationsPebbles.ComputeInertiaFromPebbles (   OPT,
  DATA 
)
96 def ComputeInertiaFromPebbles(OPT, DATA):
97  # take array of pebbles
98  pebbles = DATA['pebbles']
99  density = DATA['density']
100  # Compute mass, shift to center of mass
101  mass, pebbles = ShiftToCOMPebbles(pebbles, density)
102  if OPT['verbose']: print("Total mass of pebbles: ", mass)
103 
104  # Compute tensor of inertia
105  toi = ComputeTOIPebbles(pebbles, density)
106  if OPT['verbose']: print("Tensor of inertia of pebbles: ", toi)
107 
108  # Compute principal directions
109  v1, v2, v3 = ComputePrincipalDirections(toi)
110  if OPT['verbose']: print("Principal directions: ", v1, v2, v3)
111 
112  # Rotate to principal directions
113  if OPT['rotateToPD']:
114  pebbles, toi, v1, v2, v3 = RotateToPDPebblesTOI(pebbles, toi, v1, v2, v3)
115  if OPT['verbose']: print("Rotated principal directions: ", v1, v2, v3)
116  if OPT['verbose']: print("Rotated toi: ", toi)
117 
118  # Save all the data
119  DATA['pebbles'] = pebbles
120  DATA['mass'] = mass
121  DATA['pd'] = v1, v2, v3
122  DATA['toi'] = toi
123 
124 
125  return OPT, DATA
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def ComputeInertiaFromPebbles(OPT, DATA)
Definition: InertiaComputationsPebbles.py:96
def ComputePrincipalDirections(toi)
Definition: InertiaComputationsPebbles.py:49
def ComputeTOIPebbles(pebbles, density)
Definition: InertiaComputationsPebbles.py:33
def ShiftToCOMPebbles(pebbles, density)
Definition: InertiaComputationsPebbles.py:25
def RotateToPDPebblesTOI(pebbles, toi, v1, v2, v3)
Definition: InertiaComputationsPebbles.py:79

References ComputePrincipalDirections(), ComputeTOIPebbles(), Eigen::internal.print(), RotateToPDPebblesTOI(), and ShiftToCOMPebbles().

Referenced by MClump.main().

◆ ComputeMassCOMPebbles()

def InertiaComputationsPebbles.ComputeMassCOMPebbles (   pebbles,
  density 
)
11 def ComputeMassCOMPebbles(pebbles, density):
12  # Computes mass/center of mass (COM) of the assembly of pebbles
13  com = np.zeros(3)
14  mass = 0
15  for j in range(len(pebbles)):
16  c_j = pebbles[j][:3]
17  r = pebbles[j][3]
18  m_j = (4. / 3.) * np.pi * r ** 3 * density
19  com += m_j * c_j
20  mass += m_j
21  com /= mass
22  return mass, com
23 
24 
def ComputeMassCOMPebbles(pebbles, density)
Definition: InertiaComputationsPebbles.py:11

Referenced by ShiftToCOMPebbles().

◆ ComputePrincipalDirections()

def InertiaComputationsPebbles.ComputePrincipalDirections (   toi)
50  # For a given tensor of inertia "toi" returns normalized principal directions
51  w, v = np.linalg.eig(toi)
52  v1 = v[0] / np.linalg.norm(v[0])
53  v2 = v[1] / np.linalg.norm(v[1])
54  v3 = v[2] / np.linalg.norm(v[2])
55 
56  # Make sure found PDs form the RIGHT basis
57  if np.allclose(np.cross(v1, v2), -v3): v3 = -v3
58  return v1, v2, v3
59 

Referenced by ComputeInertiaFromPebbles(), InertiaComputationsVoxelGrid.ComputeInertiaFromVoxelGrid(), and InertiaComputationsMixed.ComputeInertiaMixed().

◆ ComputeTOIPebbles()

def InertiaComputationsPebbles.ComputeTOIPebbles (   pebbles,
  density 
)
33 def ComputeTOIPebbles(pebbles, density):
34  # Tensor of inertia of non-overlapping spherical particles (origin of CS is in center of mass)
35  toi = np.zeros(9).reshape(3, 3)
36  for j in range(len(pebbles)):
37  X = pebbles[j][0]
38  Y = pebbles[j][1]
39  Z = pebbles[j][2]
40  r = pebbles[j][3]
41  m = density * (4. / 3.) * np.pi * r ** 3
42 
43  toi += m * np.array([[0.4 * r ** 2 + Y ** 2 + Z ** 2, -X * Y, -X * Z],
44  [-X * Y, 0.4 * r ** 2 + X ** 2 + Z ** 2, -Y * Z],
45  [-X * Z, -Y * Z, 0.4 * r ** 2 + X ** 2 + Y ** 2]])
46  return toi
47 
48 

Referenced by ComputeInertiaFromPebbles().

◆ RotateToPDPebbles()

def InertiaComputationsPebbles.RotateToPDPebbles (   pebbles,
  v1,
  v2,
  v3 
)
60 def RotateToPDPebbles(pebbles, v1, v2, v3):
61  # This function rotates the centered pebbles to the specified principal directions v1, v2, v3.
62  e1 = np.array([1, 0, 0])
63  e2 = np.array([0, 1, 0])
64  e3 = np.array([0, 0, 1])
65  Q = np.array([
66  [e1 @ v1, e2 @ v1, e3 @ v1],
67  [e1 @ v2, e2 @ v2, e3 @ v2],
68  [e1 @ v3, e2 @ v3, e3 @ v3]])
69 
70  r_pebbles = np.zeros(np.shape(pebbles))
71  for j in range(len(pebbles)):
72  r_pebbles[j][:3] = Q @ pebbles[j][:3]
73  r_pebbles[j][3] = pebbles[j][3]
74 
75  return r_pebbles
76 
77 
78 
def RotateToPDPebbles(pebbles, v1, v2, v3)
Definition: InertiaComputationsPebbles.py:60

Referenced by OutputData.ParaviewOutputPebblesAnimated().

◆ RotateToPDPebblesTOI()

def InertiaComputationsPebbles.RotateToPDPebblesTOI (   pebbles,
  toi,
  v1,
  v2,
  v3 
)
79 def RotateToPDPebblesTOI(pebbles, toi, v1, v2, v3):
80  # This function rotates the centered pebbles to the specified principal directions v1, v2, v3.
81  e1 = np.array([1, 0, 0])
82  e2 = np.array([0, 1, 0])
83  e3 = np.array([0, 0, 1])
84  Q = np.array([
85  [e1 @ v1, e2 @ v1, e3 @ v1],
86  [e1 @ v2, e2 @ v2, e3 @ v2],
87  [e1 @ v3, e2 @ v3, e3 @ v3]])
88 
89  for j in range(len(pebbles)):
90  pebbles[j][:3] = Q @ pebbles[j][:3]
91 
92  toi = np.transpose(Q) @ toi @ Q
93  return pebbles, toi, e1, e2, e3
94 
95 

Referenced by ComputeInertiaFromPebbles(), and InertiaComputationsVoxelGrid.ComputeInertiaFromVoxelGrid().

◆ ShiftToCOMPebbles()

def InertiaComputationsPebbles.ShiftToCOMPebbles (   pebbles,
  density 
)
25 def ShiftToCOMPebbles(pebbles, density):
26  # Returns the coordinates of pebbles shifted such that the center of mass (COM) is at zero.
27  mass, com = ComputeMassCOMPebbles(pebbles, density)
28  for j in range(len(pebbles)):
29  pebbles[j][:3] -= com
30  return mass, pebbles
31 
32 

References ComputeMassCOMPebbles().

Referenced by ComputeInertiaFromPebbles().