MClump Namespace Reference

Functions

def import_or_install_modules ()
 
def main ()
 

Variables

bool NumbaInstalled = True
 

Function Documentation

◆ import_or_install_modules()

def MClump.import_or_install_modules ( )
23  # This function automatically installs required packages if they are missing
24  global NumbaInstalled
25  try:
26  __import__('stl')
27  except ImportError:
28  print("Package numpy-stl not installed, installing...")
29  pip.main(['install', 'numpy-stl'])
30  try:
31  __import__('numba')
32  except ImportError:
33  print("Numba not detected (manual installation required), proceed without it")
34  NumbaInstalled = False
35  return
36 
38 
39 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def import_or_install_modules()
Definition: MClump.py:22

References Eigen::internal.print().

◆ main()

def MClump.main ( )
50 def main():
51  # Load baseline parameters - options (OPT) and model data (DATA)
52  OPT, DATA = Baseline()
53 
54  # Set up terminal output
55  clr = colorClass()
56  clr.set_use_colors(OPT['useColors'])
57  clr.def_colors()
58 
59  # Hello tag
60  print(clr.END + clr.BOLD + clr.VIOLET + "-------------------------------------------")
61  print(clr.END + clr.BOLD + clr.VIOLET + " MercuryDPM clump generation tool ")
62  print(clr.END + clr.BOLD + clr.VIOLET + "-------------------------------------------")
63 
64  # Modification of baseline by the command line arguments (if any)
65  if (len(sys.argv) == 3): # Full format: run -m 2
66  if (sys.argv[1] == "-m"):
67  OPT['mode'] = int(sys.argv[2])
68 
69  # Disable numba usage if enabled, but not installed
70  OPT['useNumba'] = OPT['useNumba'] and NumbaInstalled
71 
72  if OPT['useNumba']:
73  if (OPT['verbose']): print(clr.END + clr.BOLD + clr.GREEN + "Just in time compilation is enabled")
74  else:
75  if (OPT['verbose']): print(clr.END + clr.BOLD + clr.RED + "Just in time compilation is disabled, voxel grid computations may be slow")
76 
77 
78 
79  # Main program
80  if OPT['mode']==1: # 1 - start with the list of pebbles, compute inertia by summation over pebbles
81  out = "Mode 1"
82  if (OPT['verbose']): out +=": clump input from the list of pebbles, inertial properties via summation over pebbles"
83  print(clr.BOLD + clr.GREEN + out)
84  # load the input data
85  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading pebble configuration..." + clr.BLUE)
86  OPT, DATA = LoadPebbles(OPT, DATA)
87  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
88 
89  # Compute mass, center of mass, tensor of inertia, principal directions,
90  # shift to center of mass and rotate to principal directions.
91  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Computing inertial properties..." + clr.BLUE)
92  OPT,DATA = ComputeInertiaFromPebbles(OPT, DATA)
93  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
94 
95  # compute inertial properties
96  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Output clump data..." + clr.BLUE)
97  OPT, DATA = OutputClumpData(OPT, DATA)
98  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
99 
100 
101  if OPT['mode']==2: # 2 - start with the list of pebbles, compute inertia by voxelization
102  out = "Mode 2"
103  if (OPT['verbose']): out += ": clump input from the list of pebbles, inertial properties are via voxel grid"
104  print(clr.BOLD + clr.GREEN + out)
105  # load the input data
106  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading pebble configuration..." + clr.BLUE)
107  OPT, DATA = LoadPebbles(OPT, DATA)
108  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
109 
110  # Compute mass, center of mass, tensor of inertia, principal directions,
111  # shift to center of mass and rotate to principal directions.
112 
113  if OPT['useNumba']:
114  from Src.InertiaComputationsVoxelGrid import ComputeInertiaFromVoxelGrid
115  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Computing inertial properties..." + clr.BLUE)
116  OPT, DATA = ComputeInertiaFromVoxelGrid(OPT, DATA)
117  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
118 
119  else:
120  from Src.InertiaComputationsVoxelGridNonumba import compute_inertia_from_voxel_grid_nonumba
121  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Computing inertial properties..." + clr.BLUE)
122  OPT, DATA = compute_inertia_from_voxel_grid_nonumba(OPT, DATA)
123  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
124 
125 
126  # Output clump data
127  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Output clump data..." + clr.BLUE)
128  OPT, DATA = OutputClumpData(OPT, DATA)
129  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
130 
131 
132  if OPT['mode']==3: # 3 - inertia from stl, external generator of pebbles
133  out = "Mode 3"
134  if (OPT['verbose']):
135  out += ": external clump generation, inertial properties from stl"
136  print(clr.BOLD + clr.GREEN + out)
137 
138  # load stl mesh
139  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading stl configuration..." + clr.BLUE)
140  OPT, DATA = LoadMesh(OPT, DATA)
141  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
142 
143  # load pebbles
144  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading pebble configuration..." + clr.BLUE)
145  OPT, DATA = LoadPebbles(OPT, DATA)
146  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
147 
148  # Compute mass, center of mass, tensor of inertia, principal directions,
149  # shift to center of mass and rotate to principal directions.
150  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Computing inertial properties..." + clr.BLUE)
151  OPT, DATA = ComputeInertiaMixed(OPT, DATA)
152  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
153 
154 
155  # Output clump data
156  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Output clump data..." + clr.BLUE)
157  OPT, DATA = OutputClumpData(OPT, DATA)
158  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
159 
160  if OPT['mode']==4: # 4 - generation of stl sequence for Blender
161  out = "Mode 4"
162  if (OPT['verbose']):
163  out += ": generation of stl sequence for Blender"
164  print(clr.BOLD + clr.GREEN + out)
165 
166  # load stl mesh
167  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading stl configuration..." + clr.BLUE)
168  OPT, DATA = LoadMesh(OPT, DATA)
169  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
170 
171  # load pebbles
172  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Loading pebble configuration..." + clr.BLUE)
173  OPT, DATA = LoadPebbles(OPT, DATA)
174  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
175 
176  # Compute mass, center of mass, tensor of inertia, principal directions,
177  # shift to center of mass and rotate to principal directions.
178  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Computing inertial properties..." + clr.BLUE)
179  OPT, DATA = ComputeInertiaMixed(OPT, DATA)
180  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
181 
182 
183  # Save stl sequence
184  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Saving stl sequence..." + clr.BLUE)
185  OPT, DATA = SaveStlSequence(OPT, DATA)
186  if (OPT['verbose']): print(clr.BOLD + clr.YELLOW + "Done")
187 
188 
189 
void LoadPebbles(ClumpData &a)
Definition: ClumpInput.h:92
return int(ret)+1
Definition: Baseline.py:1
def ComputeInertiaMixed(OPT, DATA)
Definition: InertiaComputationsMixed.py:155
def ComputeInertiaFromPebbles(OPT, DATA)
Definition: InertiaComputationsPebbles.py:96
def ComputeInertiaFromVoxelGrid(OPT, DATA)
Definition: InertiaComputationsVoxelGrid.py:98
def LoadMesh(OPT, DATA)
Definition: InputData.py:27
def main()
Definition: MClump.py:50
def OutputClumpData(OPT, DATA)
Definition: OutputData.py:120
def SaveStlSequence(OPT, DATA)
Definition: SaveToStl.py:157

References InertiaComputationsPebbles.ComputeInertiaFromPebbles(), InertiaComputationsVoxelGrid.ComputeInertiaFromVoxelGrid(), InertiaComputationsMixed.ComputeInertiaMixed(), int(), InputData.LoadMesh(), LoadPebbles(), OutputData.OutputClumpData(), Eigen::internal.print(), and SaveToStl.SaveStlSequence().

Variable Documentation

◆ NumbaInstalled

bool MClump.NumbaInstalled = True