morphogen 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. morphogen/__init__.py +60 -0
  2. morphogen/__main__.py +7 -0
  3. morphogen/_platform.py +55 -0
  4. morphogen/_public.py +153 -0
  5. morphogen/_utils.py +80 -0
  6. morphogen/_version.py +1 -0
  7. morphogen/analysis/__init__.py +174 -0
  8. morphogen/analysis/anisotropy.py +135 -0
  9. morphogen/analysis/basic.py +38 -0
  10. morphogen/analysis/cells.py +54 -0
  11. morphogen/analysis/connectivity.py +156 -0
  12. morphogen/analysis/correlation.py +195 -0
  13. morphogen/analysis/covariance.py +80 -0
  14. morphogen/analysis/fractal.py +54 -0
  15. morphogen/analysis/measures.py +188 -0
  16. morphogen/analysis/morphology.py +265 -0
  17. morphogen/analysis/particles.py +160 -0
  18. morphogen/analysis/percolation.py +2034 -0
  19. morphogen/analysis/power_laws.py +143 -0
  20. morphogen/analysis/random_sets.py +351 -0
  21. morphogen/analysis/stereology.py +289 -0
  22. morphogen/analysis/surface.py +107 -0
  23. morphogen/analysis/topology.py +92 -0
  24. morphogen/automata/__init__.py +74 -0
  25. morphogen/automata/engine.py +211 -0
  26. morphogen/automata/growth.py +686 -0
  27. morphogen/automata/lattice.py +143 -0
  28. morphogen/automata/reaction.py +255 -0
  29. morphogen/automata/rules.py +353 -0
  30. morphogen/automata/tilings.py +1715 -0
  31. morphogen/cli.py +3526 -0
  32. morphogen/config.py +2167 -0
  33. morphogen/contact/__init__.py +113 -0
  34. morphogen/contact/experiments.py +368 -0
  35. morphogen/contact/hertz.py +104 -0
  36. morphogen/contact/kernels.py +827 -0
  37. morphogen/contact/periodic.py +278 -0
  38. morphogen/contact/problem.py +578 -0
  39. morphogen/contact/surfaces.py +310 -0
  40. morphogen/coupling/__init__.py +43 -0
  41. morphogen/coupling/ageing.py +143 -0
  42. morphogen/coupling/diffusion.py +226 -0
  43. morphogen/coupling/fenicsx.py +484 -0
  44. morphogen/coupling/oxidation.py +447 -0
  45. morphogen/coupling/plates.py +247 -0
  46. morphogen/design/__init__.py +51 -0
  47. morphogen/design/csp.py +616 -0
  48. morphogen/design/frames.py +277 -0
  49. morphogen/design/search.py +287 -0
  50. morphogen/design/tiles.py +336 -0
  51. morphogen/distributions.py +312 -0
  52. morphogen/domain.py +203 -0
  53. morphogen/dynamics/__init__.py +179 -0
  54. morphogen/dynamics/model.py +638 -0
  55. morphogen/dynamics/openradioss.py +643 -0
  56. morphogen/dynamics/results.py +515 -0
  57. morphogen/fracture/__init__.py +170 -0
  58. morphogen/fracture/bulk.py +349 -0
  59. morphogen/fracture/cohesive.py +1614 -0
  60. morphogen/fracture/ductile.py +557 -0
  61. morphogen/fracture/lefm.py +1168 -0
  62. morphogen/fracture/mixed.py +1178 -0
  63. morphogen/fracture/periodic.py +733 -0
  64. morphogen/fracture/phasefield.py +714 -0
  65. morphogen/fracture/phasefield_finite.py +368 -0
  66. morphogen/fracture/surface.py +572 -0
  67. morphogen/fracture/toughness.py +566 -0
  68. morphogen/gpu.py +108 -0
  69. morphogen/gui/__init__.py +8 -0
  70. morphogen/gui/api.py +1927 -0
  71. morphogen/gui/desktop.py +387 -0
  72. morphogen/gui/icon.png +0 -0
  73. morphogen/gui/index.html +1909 -0
  74. morphogen/gui/server.py +229 -0
  75. morphogen/gui/tools/__init__.py +629 -0
  76. morphogen/gui/tools/compare.py +149 -0
  77. morphogen/gui/tools/contact.py +391 -0
  78. morphogen/gui/tools/couplings.py +1085 -0
  79. morphogen/gui/tools/crackfront.py +245 -0
  80. morphogen/gui/tools/design.py +224 -0
  81. morphogen/gui/tools/dynamics.py +824 -0
  82. morphogen/gui/tools/fracture.py +2586 -0
  83. morphogen/gui/tools/interop.py +1654 -0
  84. morphogen/gui/tools/learning.py +595 -0
  85. morphogen/gui/tools/mechanics.py +3881 -0
  86. morphogen/gui/tools/nonlocal_damage.py +1321 -0
  87. morphogen/gui/tools/phasefield.py +215 -0
  88. morphogen/gui/tools/physics.py +597 -0
  89. morphogen/gui/tools/stability.py +1756 -0
  90. morphogen/gui/tools/statistics.py +1408 -0
  91. morphogen/gui/viewer.js +1100 -0
  92. morphogen/homogenization/__init__.py +210 -0
  93. morphogen/homogenization/acoustics.py +566 -0
  94. morphogen/homogenization/amg.py +1005 -0
  95. morphogen/homogenization/apparent.py +1046 -0
  96. morphogen/homogenization/behaviours.cu +2285 -0
  97. morphogen/homogenization/behaviours.py +944 -0
  98. morphogen/homogenization/beremin.py +263 -0
  99. morphogen/homogenization/bifurcation.py +1085 -0
  100. morphogen/homogenization/bloch.py +507 -0
  101. morphogen/homogenization/bounds.py +226 -0
  102. morphogen/homogenization/core.py +458 -0
  103. morphogen/homogenization/coupled.py +1135 -0
  104. morphogen/homogenization/crystal.py +2967 -0
  105. morphogen/homogenization/dilatation.py +454 -0
  106. morphogen/homogenization/elements.py +157 -0
  107. morphogen/homogenization/fatigue.py +768 -0
  108. morphogen/homogenization/fe.py +1739 -0
  109. morphogen/homogenization/fenicsx.py +307 -0
  110. morphogen/homogenization/fft.py +499 -0
  111. morphogen/homogenization/fft_nonlinear.py +391 -0
  112. morphogen/homogenization/finite.py +613 -0
  113. morphogen/homogenization/flow.py +361 -0
  114. morphogen/homogenization/frames.py +1125 -0
  115. morphogen/homogenization/gpu.py +1241 -0
  116. morphogen/homogenization/harmonic.py +427 -0
  117. morphogen/homogenization/identification.py +579 -0
  118. morphogen/homogenization/kernels.py +760 -0
  119. morphogen/homogenization/laws.py +2061 -0
  120. morphogen/homogenization/materials.py +1080 -0
  121. morphogen/homogenization/mfront.py +589 -0
  122. morphogen/homogenization/networks.py +880 -0
  123. morphogen/homogenization/nonlinear.py +2612 -0
  124. morphogen/homogenization/ntfa.py +577 -0
  125. morphogen/homogenization/paths.py +476 -0
  126. morphogen/homogenization/photonic.py +467 -0
  127. morphogen/homogenization/poroelastic.py +212 -0
  128. morphogen/homogenization/porous.py +1120 -0
  129. morphogen/homogenization/postprocess.py +290 -0
  130. morphogen/homogenization/solvers.py +1140 -0
  131. morphogen/homogenization/tensors.py +240 -0
  132. morphogen/homogenization/voxel_fe.py +457 -0
  133. morphogen/homogenization/xfem.py +1016 -0
  134. morphogen/homogenization/zmat.py +1258 -0
  135. morphogen/iga/__init__.py +48 -0
  136. morphogen/iga/analysis.py +508 -0
  137. morphogen/iga/basis.py +214 -0
  138. morphogen/iga/geometry.py +501 -0
  139. morphogen/iga/homogenization.py +219 -0
  140. morphogen/iga/optimization.py +700 -0
  141. morphogen/iga/shapes.py +331 -0
  142. morphogen/image.py +128 -0
  143. morphogen/io/__init__.py +246 -0
  144. morphogen/io/amitex.py +741 -0
  145. morphogen/io/ebsd.py +881 -0
  146. morphogen/io/export.py +196 -0
  147. morphogen/io/geometry.py +158 -0
  148. morphogen/io/medit.py +147 -0
  149. morphogen/io/meshes.py +844 -0
  150. morphogen/io/metaimage.py +97 -0
  151. morphogen/io/mfront.py +1104 -0
  152. morphogen/io/native.py +57 -0
  153. morphogen/io/radioss.py +764 -0
  154. morphogen/io/solvers.py +371 -0
  155. morphogen/io/tables.py +278 -0
  156. morphogen/io/tiff.py +66 -0
  157. morphogen/io/vtk.py +701 -0
  158. morphogen/io/xdmf.py +200 -0
  159. morphogen/kernels/__init__.py +5 -0
  160. morphogen/kernels/annealing.py +192 -0
  161. morphogen/kernels/cells.py +69 -0
  162. morphogen/kernels/collective.py +87 -0
  163. morphogen/kernels/force_biased.py +595 -0
  164. morphogen/kernels/implicit.py +145 -0
  165. morphogen/kernels/leaves.py +132 -0
  166. morphogen/kernels/packing.py +304 -0
  167. morphogen/kernels/raster.py +279 -0
  168. morphogen/kernels/rsa.py +371 -0
  169. morphogen/kernels/union.py +135 -0
  170. morphogen/kernels/watershed.py +190 -0
  171. morphogen/laser/__init__.py +234 -0
  172. morphogen/laser/architectures.py +375 -0
  173. morphogen/laser/bending.py +216 -0
  174. morphogen/laser/cells.py +1694 -0
  175. morphogen/laser/design.py +940 -0
  176. morphogen/laser/figures.py +227 -0
  177. morphogen/laser/heat.py +804 -0
  178. morphogen/laser/materials.py +691 -0
  179. morphogen/laser/mechanics.py +1670 -0
  180. morphogen/laser/metallurgy.py +615 -0
  181. morphogen/laser/patterns.py +828 -0
  182. morphogen/laser/periodic.py +392 -0
  183. morphogen/laser/process.py +362 -0
  184. morphogen/laser/run.py +534 -0
  185. morphogen/laser/solid.py +216 -0
  186. morphogen/laser/specimen.py +200 -0
  187. morphogen/laser/structures.py +708 -0
  188. morphogen/learning/__init__.py +81 -0
  189. morphogen/learning/behaviour.py +398 -0
  190. morphogen/learning/data.py +328 -0
  191. morphogen/learning/learned.cpp +668 -0
  192. morphogen/learning/logarithmic.py +202 -0
  193. morphogen/learning/mfront.py +409 -0
  194. morphogen/learning/networks.py +767 -0
  195. morphogen/learning/run.py +212 -0
  196. morphogen/learning/standard.py +814 -0
  197. morphogen/learning/training.py +235 -0
  198. morphogen/mesh/__init__.py +29 -0
  199. morphogen/mesh/conforming.py +1423 -0
  200. morphogen/mesh/curved.py +600 -0
  201. morphogen/mesh/exact.py +1717 -0
  202. morphogen/mesh/octree.py +350 -0
  203. morphogen/mesh/polycrystal.py +1041 -0
  204. morphogen/mesh/polyhedra.py +677 -0
  205. morphogen/mesh/regularize.py +570 -0
  206. morphogen/mesh/surface.py +97 -0
  207. morphogen/mesh/tetra.py +512 -0
  208. morphogen/mesh/voxel.py +124 -0
  209. morphogen/micromorphic/__init__.py +31 -0
  210. morphogen/micromorphic/damage.py +359 -0
  211. morphogen/micromorphic/ductile.py +534 -0
  212. morphogen/micromorphic/finite.py +220 -0
  213. morphogen/micromorphic/microfoam.py +787 -0
  214. morphogen/micromorphic/space.py +341 -0
  215. morphogen/models/__init__.py +195 -0
  216. morphogen/models/affine.py +384 -0
  217. morphogen/models/automata.py +592 -0
  218. morphogen/models/base.py +500 -0
  219. morphogen/models/boolean.py +310 -0
  220. morphogen/models/bouligand.py +331 -0
  221. morphogen/models/branching.py +241 -0
  222. morphogen/models/combination.py +430 -0
  223. morphogen/models/deadleaves.py +766 -0
  224. morphogen/models/design.py +289 -0
  225. morphogen/models/ebsd.py +206 -0
  226. morphogen/models/fibers.py +1476 -0
  227. morphogen/models/foam.py +594 -0
  228. morphogen/models/gaussian.py +314 -0
  229. morphogen/models/growth.py +459 -0
  230. morphogen/models/hardcore.py +317 -0
  231. morphogen/models/hierarchical.py +269 -0
  232. morphogen/models/honeycomb.py +749 -0
  233. morphogen/models/implicit.py +177 -0
  234. morphogen/models/laminate.py +470 -0
  235. morphogen/models/lattice.py +351 -0
  236. morphogen/models/lattice_field.py +345 -0
  237. morphogen/models/levelset_foam.py +563 -0
  238. morphogen/models/nacre.py +411 -0
  239. morphogen/models/nested.py +924 -0
  240. morphogen/models/osteons.py +374 -0
  241. morphogen/models/pieces.py +167 -0
  242. morphogen/models/planar.py +126 -0
  243. morphogen/models/reconstruction.py +203 -0
  244. morphogen/models/scale_rich.py +1409 -0
  245. morphogen/models/scale_rich_3d.py +1616 -0
  246. morphogen/models/tessellation.py +735 -0
  247. morphogen/models/tiling_field.py +302 -0
  248. morphogen/models/tpms.py +197 -0
  249. morphogen/models/transparent.py +406 -0
  250. morphogen/models/union.py +141 -0
  251. morphogen/optimization/__init__.py +43 -0
  252. morphogen/optimization/cell.py +295 -0
  253. morphogen/optimization/filters.py +115 -0
  254. morphogen/optimization/mma.py +226 -0
  255. morphogen/optimization/run.py +219 -0
  256. morphogen/optimization/topology.py +632 -0
  257. morphogen/orientations.py +568 -0
  258. morphogen/parallel.py +599 -0
  259. morphogen/pipeline.py +978 -0
  260. morphogen/primitives.py +188 -0
  261. morphogen/results.py +564 -0
  262. morphogen/rve/__init__.py +73 -0
  263. morphogen/rve/report.py +627 -0
  264. morphogen/rve/scaling.py +363 -0
  265. morphogen/rve/study.py +1054 -0
  266. morphogen/rve/windows.py +345 -0
  267. morphogen/seeding.py +51 -0
  268. morphogen/settings.py +118 -0
  269. morphogen/stopping.py +48 -0
  270. morphogen/symmetry.py +384 -0
  271. morphogen/templates/activator_inhibitor.yaml +22 -0
  272. morphogen/templates/aggregation.yaml +23 -0
  273. morphogen/templates/boolean_cylinders.yaml +20 -0
  274. morphogen/templates/boolean_spheres.yaml +22 -0
  275. morphogen/templates/bouligand.yaml +28 -0
  276. morphogen/templates/cellular_automaton.yaml +25 -0
  277. morphogen/templates/coated_spheres.yaml +26 -0
  278. morphogen/templates/contact_fibers.yaml +27 -0
  279. morphogen/templates/cox_nanocomposite.yaml +22 -0
  280. morphogen/templates/cross_linked_fibers.yaml +26 -0
  281. morphogen/templates/curved_arcs.yaml +28 -0
  282. morphogen/templates/curved_fibers.yaml +24 -0
  283. morphogen/templates/dead_leaves.yaml +22 -0
  284. morphogen/templates/delaunay_network.yaml +22 -0
  285. morphogen/templates/dense_packing.yaml +22 -0
  286. morphogen/templates/diffusion.yaml +33 -0
  287. morphogen/templates/ebsd.yaml +34 -0
  288. morphogen/templates/ebsd_map.ctf +3087 -0
  289. morphogen/templates/fracture_composite.yaml +42 -0
  290. morphogen/templates/fracture_rubber.yaml +47 -0
  291. morphogen/templates/gaussian_excursion.yaml +17 -0
  292. morphogen/templates/graded_lattice.yaml +24 -0
  293. morphogen/templates/hardcore_fibers.yaml +22 -0
  294. morphogen/templates/hardcore_spheres.yaml +22 -0
  295. morphogen/templates/hierarchical_lattice.yaml +22 -0
  296. morphogen/templates/homogenization_acoustic_foam.yaml +36 -0
  297. morphogen/templates/homogenization_beremin.yaml +50 -0
  298. morphogen/templates/homogenization_cleavage.yaml +51 -0
  299. morphogen/templates/homogenization_cleavage_band.yaml +55 -0
  300. morphogen/templates/homogenization_contact.yaml +43 -0
  301. morphogen/templates/homogenization_crack_closure.yaml +49 -0
  302. morphogen/templates/homogenization_crystal_plasticity.yaml +50 -0
  303. morphogen/templates/homogenization_crystal_plasticity_fft.yaml +52 -0
  304. morphogen/templates/homogenization_crystallization.yaml +30 -0
  305. morphogen/templates/homogenization_debonding.yaml +43 -0
  306. morphogen/templates/homogenization_detwinning.yaml +58 -0
  307. morphogen/templates/homogenization_ductile_damage.yaml +47 -0
  308. morphogen/templates/homogenization_fatigue.yaml +40 -0
  309. morphogen/templates/homogenization_grain_fracture.yaml +56 -0
  310. morphogen/templates/homogenization_gyroid.yaml +30 -0
  311. morphogen/templates/homogenization_intergranular.yaml +43 -0
  312. morphogen/templates/homogenization_interphase.yaml +42 -0
  313. morphogen/templates/homogenization_mixed_loading.yaml +33 -0
  314. morphogen/templates/homogenization_ntfa.yaml +56 -0
  315. morphogen/templates/homogenization_piezoelectric.yaml +27 -0
  316. morphogen/templates/homogenization_polycrystal.yaml +30 -0
  317. morphogen/templates/homogenization_polycrystal_inclusions.yaml +30 -0
  318. morphogen/templates/homogenization_poroelastic.yaml +26 -0
  319. morphogen/templates/homogenization_rubber.yaml +40 -0
  320. morphogen/templates/homogenization_slip_cleavage.yaml +50 -0
  321. morphogen/templates/homogenization_spheres.yaml +31 -0
  322. morphogen/templates/homogenization_transport.yaml +29 -0
  323. morphogen/templates/homogenization_twinning.yaml +54 -0
  324. morphogen/templates/homogenization_viscoelastic.yaml +34 -0
  325. morphogen/templates/homogenization_viscoplastic.yaml +42 -0
  326. morphogen/templates/homogenization_voronoi.yaml +26 -0
  327. morphogen/templates/homogenization_xfem.yaml +23 -0
  328. morphogen/templates/hyperuniform_cells.yaml +24 -0
  329. morphogen/templates/laguerre.yaml +18 -0
  330. morphogen/templates/laser_bending.yaml +35 -0
  331. morphogen/templates/laser_cells.yaml +38 -0
  332. morphogen/templates/laser_corrugated.yaml +36 -0
  333. morphogen/templates/level_set_foam.yaml +29 -0
  334. morphogen/templates/menger_sponge.yaml +17 -0
  335. morphogen/templates/nacre.yaml +25 -0
  336. morphogen/templates/nucleation_growth.yaml +25 -0
  337. morphogen/templates/optimize_auxetic.yaml +29 -0
  338. morphogen/templates/optimize_auxetic_3d.yaml +27 -0
  339. morphogen/templates/optimize_bulk.yaml +23 -0
  340. morphogen/templates/optimize_conductivity.yaml +20 -0
  341. morphogen/templates/osteons.yaml +28 -0
  342. morphogen/templates/penetrable_spheres.yaml +21 -0
  343. morphogen/templates/poisson_fibers.yaml +21 -0
  344. morphogen/templates/random_laminate.yaml +26 -0
  345. morphogen/templates/random_lattice.yaml +27 -0
  346. morphogen/templates/random_walk_fibers.yaml +26 -0
  347. morphogen/templates/reaction_diffusion.yaml +22 -0
  348. morphogen/templates/reconstruction.yaml +22 -0
  349. morphogen/templates/rve_cellular_automaton.yaml +23 -0
  350. morphogen/templates/rve_crystal_plasticity_fft.yaml +51 -0
  351. morphogen/templates/rve_multiphysics.yaml +43 -0
  352. morphogen/templates/rve_poisson_fibers.yaml +22 -0
  353. morphogen/templates/rve_poisson_fibers_fe.yaml +33 -0
  354. morphogen/templates/rve_voronoi_windows.yaml +20 -0
  355. morphogen/templates/scale_rich_network.yaml +29 -0
  356. morphogen/templates/scale_rich_plates.yaml +30 -0
  357. morphogen/templates/sequential_dead_leaves.yaml +25 -0
  358. morphogen/templates/strut_lattice.yaml +21 -0
  359. morphogen/templates/tile_assembly.yaml +28 -0
  360. morphogen/templates/tpms.yaml +19 -0
  361. morphogen/templates/trabecular_bone.yaml +29 -0
  362. morphogen/templates/transparent_dead_leaves.yaml +23 -0
  363. morphogen/templates/vascular_tree.yaml +23 -0
  364. morphogen/templates/voronoi.yaml +20 -0
  365. morphogen/templates/wood.yaml +34 -0
  366. morphogen/templates/workflow.yaml +56 -0
  367. morphogen/texture.py +665 -0
  368. morphogen/theory.py +162 -0
  369. morphogen/viz/__init__.py +12 -0
  370. morphogen/viz/export.py +244 -0
  371. morphogen/viz/figures.py +707 -0
  372. morphogen/viz/png.py +148 -0
  373. morphogen/viz/sections.py +696 -0
  374. morphogen/viz/surfaces.py +1352 -0
  375. morphogen/viz/video.py +904 -0
  376. morphogen/viz/workflow.py +488 -0
  377. morphogen-1.0.0.dist-info/METADATA +2316 -0
  378. morphogen-1.0.0.dist-info/RECORD +381 -0
  379. morphogen-1.0.0.dist-info/WHEEL +4 -0
  380. morphogen-1.0.0.dist-info/entry_points.txt +5 -0
  381. morphogen-1.0.0.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,824 @@
1
+ """The tools of the tab Explicit dynamics: the crushing, tension, shear and impact of a
2
+ morphology simulated by OpenRadioss, the explicit finite element solver
3
+ (:mod:`morphogen.dynamics`), its results read back from a run made elsewhere, and the
4
+ installation of OpenRadioss from its releases on GitHub.
5
+
6
+ The forms take engineering units, converted to the consistent system Mg, mm, s of the
7
+ inputs of OpenRadioss: moduli and stresses in MPa, densities in kg/m³, velocities in m/s,
8
+ strain rates in 1/s, durations in ms, the lengths of the morphology in the unit chosen.
9
+ The results come in MPa, J, ms and MJ/m³ (the absorbed energy per unit volume of the box)
10
+ and J/g (per unit mass). Each run keeps the inputs of OpenRadioss, a README of the
11
+ commands that rerun them elsewhere, the curves (``curves.csv``: the nominal strain and
12
+ stress of the morphology in morphoGen's components too, E33 and S33 for a compression
13
+ along z, so that the Comparisons tab draws them with loading paths), the energies, the
14
+ frames of its animations (shown in 3D, the last one first) and a video when VTK renders."""
15
+
16
+ from __future__ import annotations
17
+
18
+ import os
19
+ import shutil
20
+ import warnings
21
+ import zipfile
22
+ from pathlib import Path
23
+
24
+ import numpy as np
25
+
26
+ from morphogen.gui.tools import Field, tab, tool
27
+
28
+ tab(
29
+ "dynamics",
30
+ "Explicit dynamics",
31
+ "Explicit dynamics with OpenRadioss, the open-source crash and impact solver: the "
32
+ "crushing, tension, shear or impact of a morphology at high strain rates, on its voxels "
33
+ "or a conforming mesh, its phases elastic, von Mises elastoplastic (with Norton's "
34
+ "viscosity) or Johnson–Cook, with failure, and the self contact of its folding struts "
35
+ "and closing cells; its nominal stress–strain curves, energies, plateau stress, "
36
+ "densification strain and absorbed energy, and its fields over time in 3D. OpenRadioss "
37
+ "is installed from its releases on GitHub by the tool OpenRadioss installation; a "
38
+ "run made elsewhere (a cluster) is read back.",
39
+ order=67,
40
+ )
41
+
42
+ #: The units of the lengths of the morphologies, by their size in mm
43
+ LENGTH_UNITS = (("mm", "mm"), ("um", "µm"), ("cm", "cm"), ("m", "m"))
44
+ TO_MM = {"mm": 1.0, "um": 1e-3, "cm": 10.0, "m": 1e3}
45
+ LOADINGS = (
46
+ ("compression", "compression: the upper face driven toward the lower one"),
47
+ ("tension", "tension: the upper face pulled away"),
48
+ ("shear", "shear: the upper face driven across"),
49
+ ("impact", "impact: the morphology thrown against a rigid wall"),
50
+ )
51
+ AXES = (("x", "x"), ("y", "y"), ("z", "z"))
52
+ MATERIALS_DOC = (
53
+ "phase -> a material of the configurations in MPa and kg/m³, completing or replacing "
54
+ 'the fields above: {"1": {"johnson_cook": {"a": 300, "b": 450, "n": 0.6, "c": 0.01, '
55
+ '"rate": 1}}} (Johnson–Cook), {"1": {"plasticity": {"yield": 250, "isotropic": '
56
+ '[{"Q": 100, "b": 15}], "norton": {"K": 50, "n": 5}}}} (Voce, viscous), {"2": '
57
+ '{"young": 3000, "poisson": 0.35, "density": 1200}}'
58
+ )
59
+ #: The rows of the curves shown in the page (the file holds them all)
60
+ SHOWN_ROWS = 25
61
+ #: Run on this machine with all the cores but one by default
62
+ THREADS = max(1, (os.cpu_count() or 2) - 1)
63
+
64
+ FIELDS = [
65
+ Field("source", "item", label="morphology", required=True),
66
+ Field("length_unit", "choice", "mm", label="unit of its lengths", choices=LENGTH_UNITS),
67
+ Field(
68
+ "mesh",
69
+ "choice",
70
+ "voxels",
71
+ choices=(
72
+ ("voxels", "voxels: 8-node bricks (robust, any morphology)"),
73
+ ("conforming", "conforming tetrahedra of its level set (MMG)"),
74
+ ),
75
+ ),
76
+ Field(
77
+ "resolution",
78
+ "int",
79
+ 24,
80
+ label="voxels per edge",
81
+ when={"mesh": "voxels"},
82
+ doc="of its longest edge; the time step falls as the voxels shrink",
83
+ ),
84
+ Field(
85
+ "element_size",
86
+ "float",
87
+ unit="length",
88
+ when={"mesh": "conforming"},
89
+ doc="the largest element, in the unit of the morphology (blank: 1/12 of the edge)",
90
+ ),
91
+ Field(
92
+ "order",
93
+ "choice",
94
+ "1",
95
+ when={"mesh": "conforming"},
96
+ choices=(("1", "linear: TETRA4 (nodal pressures)"), ("2", "quadratic: TETRA10")),
97
+ ),
98
+ Field(
99
+ "materials",
100
+ "materials",
101
+ of="source",
102
+ default={"young": 70000, "poisson": 0.33},
103
+ doc="Young's moduli in MPa (an aluminium: 70000, a steel: 210000)",
104
+ ),
105
+ Field("density", "float", 2700.0, unit="kg/m³", doc="of the solid phases"),
106
+ Field(
107
+ "yield_stress",
108
+ "float",
109
+ unit="MPa",
110
+ label="yield stress",
111
+ doc="of the solid phases, von Mises (blank: elastic)",
112
+ ),
113
+ Field("hardening", "float", 0.0, unit="MPa", doc="linear isotropic hardening modulus"),
114
+ Field(
115
+ "failure_strain",
116
+ "float",
117
+ label="failure strain",
118
+ doc="plastic strain at which an element fails and is deleted (blank: none)",
119
+ ),
120
+ Field("behaviours", "json", label="materials of the phases", doc=MATERIALS_DOC),
121
+ Field(
122
+ "kept",
123
+ "item",
124
+ label="behaviour of the workspace",
125
+ items=("behaviour",),
126
+ none="none: the materials above",
127
+ doc="a material point or an identification (B) in MPa, given to the phase below with "
128
+ "the density above",
129
+ ),
130
+ Field("kept_phase", "int", 1, label="its phase"),
131
+ Field("loading", "choice", "compression", choices=LOADINGS),
132
+ Field("axis", "choice", "z", doc="normal to the loaded faces", choices=AXES),
133
+ Field(
134
+ "shear_axis",
135
+ "choice",
136
+ "x",
137
+ label="shear along",
138
+ when={"loading": "shear"},
139
+ choices=AXES,
140
+ ),
141
+ Field(
142
+ "strain",
143
+ "float",
144
+ 0.3,
145
+ label="final strain",
146
+ doc="nominal (shear: engineering); impact: the share of the length travelled at "
147
+ "the impact speed (the duration, unless given)",
148
+ ),
149
+ Field(
150
+ "strain_rate",
151
+ "float",
152
+ 500.0,
153
+ unit="1/s",
154
+ label="strain rate",
155
+ when={"loading": ["compression", "tension", "shear"]},
156
+ doc="nominal, after a smooth start; quasi-static below about 1/s, impacts above 100/s",
157
+ ),
158
+ Field("velocity", "float", 10.0, unit="m/s", label="impact speed", when={"loading": "impact"}),
159
+ Field("duration", "float", unit="ms", doc="blank: the final strain at the rate or speed"),
160
+ Field(
161
+ "lateral",
162
+ "choice",
163
+ "fixed",
164
+ label="loaded faces",
165
+ when={"loading": ["compression", "tension"]},
166
+ choices=(
167
+ ("fixed", "held across the axis (bonded platens)"),
168
+ ("free", "free to slide across the axis"),
169
+ ),
170
+ ),
171
+ Field("contact", "bool", True, label="self contact", doc="folding struts, closing cells"),
172
+ Field("friction", "float", 0.1, doc="Coulomb's coefficient of the contacts"),
173
+ Field(
174
+ "frames",
175
+ "int",
176
+ 40,
177
+ doc="animations written over the run (the curves of the faces "
178
+ "from the time history, of 1000 samples)",
179
+ ),
180
+ Field(
181
+ "time_step",
182
+ "float",
183
+ unit="µs",
184
+ label="minimum time step",
185
+ doc="kept by adding mass to the smallest elements (mass scaling: faster, but heavier "
186
+ "nodes); blank: the stable time step",
187
+ ),
188
+ Field("run", "bool", True, label="run OpenRadioss here", doc="else write its inputs only"),
189
+ Field("threads", "int", THREADS, label="OpenMP threads", doc="of the Engine"),
190
+ Field("mpi", "int", 1, label="MPI processes", doc="above 1: mpiexec and the Engine with MPI"),
191
+ Field(
192
+ "installation",
193
+ "str",
194
+ "",
195
+ label="folder of OpenRadioss",
196
+ doc="blank: OPENRADIOSS_PATH, ~/morphogen/openradioss or the PATH",
197
+ browse="folder",
198
+ ),
199
+ Field("name", "str", "", doc="of the run (blank: the model of the morphology)"),
200
+ ]
201
+
202
+
203
+ def _materials(p: dict, item: dict) -> dict:
204
+ """The materials of the phases in Mg, mm, s: the moduli of the form (MPa), the
205
+ density (kg/m³ in Mg/mm³), the plasticity and failure of the solid phases, then the
206
+ materials of the JSON field and the behaviour of the workspace."""
207
+ density = float(p["density"]) * 1e-12
208
+ if density <= 0:
209
+ raise ValueError("density: > 0 kg/m³")
210
+ base = {int(k): v for k, v in (p.get("materials") or {}).items()}
211
+ if not base: # no editor yet: the phases of the morphology, a void kept void
212
+ phases = item.get("phases") or {"0": "void", "1": "solid"}
213
+ base = {
214
+ int(k): ("void" if v == "void" else {"young": 70000.0, "poisson": 0.33})
215
+ for k, v in phases.items()
216
+ }
217
+ out: dict = {}
218
+ for q, spec in base.items():
219
+ if spec == "void":
220
+ out[q] = "void"
221
+ continue
222
+ material = {
223
+ "young": float(spec["young"]),
224
+ "poisson": float(spec["poisson"]),
225
+ "density": density,
226
+ }
227
+ if p.get("yield_stress"):
228
+ material["plasticity"] = {
229
+ "yield": float(p["yield_stress"]),
230
+ "hardening": float(p.get("hardening") or 0.0),
231
+ }
232
+ if p.get("failure_strain") and "plasticity" in material:
233
+ material["failure_strain"] = float(p["failure_strain"])
234
+ out[q] = material
235
+ extra = p.get("behaviours") or {}
236
+ if not isinstance(extra, dict):
237
+ raise ValueError('materials of the phases: a mapping phase -> material, {"1": {...}}')
238
+ for key, value in extra.items():
239
+ try:
240
+ q = int(key)
241
+ except (TypeError, ValueError):
242
+ raise ValueError(f"materials of the phases: phases are integers, got {key!r}") from None
243
+ if isinstance(value, dict):
244
+ value = dict(value)
245
+ if "density" in value:
246
+ value["density"] = float(value["density"]) * 1e-12
247
+ base_q = out.get(q)
248
+ if isinstance(base_q, dict) and not {"young", "poisson", "bulk", "shear"} & set(value):
249
+ value = {**base_q, **value}
250
+ value.setdefault("density", density)
251
+ if "johnson_cook" in value:
252
+ value.pop("plasticity", None)
253
+ out[q] = value
254
+ if p.get("kept"):
255
+ q = int(p.get("kept_phase") or 1)
256
+ material = dict(p["kept"]["material"])
257
+ material.pop("expansion", None)
258
+ material.setdefault("density", density)
259
+ if "density" in p["kept"]["material"]: # a behaviour of the workspace keeps its own
260
+ material["density"] = float(p["kept"]["material"]["density"])
261
+ out[q] = material
262
+ return out
263
+
264
+
265
+ def _loading(p: dict):
266
+ from morphogen.dynamics import ExplicitLoading
267
+
268
+ duration = float(p["duration"]) * 1e-3 if p.get("duration") else None
269
+ return ExplicitLoading(
270
+ kind=p["loading"],
271
+ axis=p["axis"],
272
+ strain=float(p["strain"]),
273
+ strain_rate=float(p.get("strain_rate") or 1.0),
274
+ shear_axis=p.get("shear_axis") if p["loading"] == "shear" else None,
275
+ velocity=float(p.get("velocity") or 0.0) * 1e3, # m/s in mm/s
276
+ duration=duration,
277
+ lateral=p.get("lateral") or "fixed",
278
+ contact=bool(p.get("contact")),
279
+ friction=float(p.get("friction") or 0.0),
280
+ )
281
+
282
+
283
+ def _scripts(folder: Path, name: str, threads: int) -> None:
284
+ """The scripts that run the inputs of a folder elsewhere (bash and Windows)."""
285
+ sh = folder / "run_openradioss.sh"
286
+ sh.write_text(
287
+ "#!/bin/bash\n"
288
+ f"# OpenRadioss on the inputs of {name}: set OPENRADIOSS_PATH to its folder\n"
289
+ "set -e\n"
290
+ ': "${OPENRADIOSS_PATH:?set OPENRADIOSS_PATH to the folder of OpenRadioss}"\n'
291
+ "export RAD_CFG_PATH=$OPENRADIOSS_PATH/hm_cfg_files\n"
292
+ "export RAD_H3D_PATH=$OPENRADIOSS_PATH/extlib/h3d/lib/linux64\n"
293
+ "export LD_LIBRARY_PATH=$OPENRADIOSS_PATH/extlib/hm_reader/linux64:"
294
+ "$OPENRADIOSS_PATH/extlib/h3d/lib/linux64:$LD_LIBRARY_PATH\n"
295
+ f"export OMP_STACKSIZE=400m OMP_NUM_THREADS=${{THREADS:-{threads}}}\n"
296
+ 'cd "$(dirname "$0")"\n'
297
+ f"$OPENRADIOSS_PATH/exec/starter_linux64_gf -i {name}_0000.rad -np 1\n"
298
+ f"$OPENRADIOSS_PATH/exec/engine_linux64_gf -i {name}_0001.rad -nt $OMP_NUM_THREADS\n"
299
+ f"for f in {name}A[0-9][0-9][0-9]; do\n"
300
+ ' $OPENRADIOSS_PATH/exec/anim_to_vtk_linux64_gf "$f" > "$f.vtk"\n'
301
+ "done\n"
302
+ f"$OPENRADIOSS_PATH/exec/th_to_csv_linux64_gf {name}T01\n",
303
+ encoding="utf-8",
304
+ newline="\n",
305
+ )
306
+ sh.chmod(0o755)
307
+ bat = folder / "run_openradioss.bat"
308
+ bat.write_text(
309
+ "@echo off\r\n"
310
+ f"rem OpenRadioss on the inputs of {name}: set OPENRADIOSS_PATH to its folder\r\n"
311
+ "set RAD_CFG_PATH=%OPENRADIOSS_PATH%\\hm_cfg_files\r\n"
312
+ "set RAD_H3D_PATH=%OPENRADIOSS_PATH%\\extlib\\h3d\\lib\\win64\r\n"
313
+ "set PATH=%OPENRADIOSS_PATH%\\extlib\\hm_reader\\win64;"
314
+ "%OPENRADIOSS_PATH%\\extlib\\intelOneAPI_runtime\\win64;%PATH%\r\n"
315
+ f"set KMP_STACKSIZE=400m\r\nset OMP_NUM_THREADS={threads}\r\n"
316
+ 'cd /d "%~dp0"\r\n'
317
+ f"%OPENRADIOSS_PATH%\\exec\\starter_win64.exe -i {name}_0000.rad -np 1\r\n"
318
+ f"%OPENRADIOSS_PATH%\\exec\\engine_win64.exe -i {name}_0001.rad "
319
+ "-nt %OMP_NUM_THREADS%\r\n"
320
+ f"for %%f in ({name}A???) do "
321
+ "%OPENRADIOSS_PATH%\\exec\\anim_to_vtk_win64.exe %%f > %%f.vtk\r\n"
322
+ f"%OPENRADIOSS_PATH%\\exec\\th_to_csv_win64.exe {name}T01\r\n",
323
+ encoding="utf-8",
324
+ newline="",
325
+ )
326
+
327
+
328
+ def _readme(manifest: dict, folder: Path, ran: bool) -> str:
329
+ """The README of the inputs of a run."""
330
+ from morphogen.dynamics import UnitSystem
331
+
332
+ m = manifest
333
+ name = m["name"]
334
+ units = UnitSystem(*m["units"])
335
+ loading = m["loading"]
336
+ laws = ", ".join(f"phase {q}: {law}" for q, law in m["laws"].items())
337
+ lines = [
338
+ f"# OpenRadioss inputs: {m['title']}",
339
+ "",
340
+ f"* {name}_0000.rad: the Starter input, {m['n_nodes']} nodes, {m['n_elements']} "
341
+ f"{m['elements']} elements (a part per phase), the materials ({laws}), the "
342
+ f"loading ({loading['kind']} along {'xyz'[m['axis']]}), "
343
+ + ("the self contact of the outer surface (TYPE24), " if loading.get("contact") else "")
344
+ + "the time histories;",
345
+ f"* {name}_0001.rad: the Engine input, to t = {m['end_time']:.6g} s, "
346
+ f"{m['frames']} animations;",
347
+ f"* {name}_mesh.npz and morphogen_radioss.json: what morphoGen reads the results "
348
+ "back with.",
349
+ "",
350
+ f"Units: {units.describe()}. The stable time step is about "
351
+ f"{m['critical_time_step']:.3g} s: about {m['cycles']:.3g} cycles"
352
+ + (f" (mass scaling to {m['time_step']:.3g} s)." if m.get("time_step") else "."),
353
+ "",
354
+ "## Run",
355
+ "",
356
+ "With morphoGen (an installation found, or `morphogen radioss install`):",
357
+ "",
358
+ f" morphogen radioss run {folder}",
359
+ "",
360
+ "or with the scripts of this folder (OPENRADIOSS_PATH set to the folder of OpenRadioss):",
361
+ "",
362
+ " ./run_openradioss.sh # Linux",
363
+ " run_openradioss.bat # Windows",
364
+ "",
365
+ "then read the results back (the curves, energies and frames):",
366
+ "",
367
+ f" morphogen radioss read {folder}",
368
+ "",
369
+ "or with the tool OpenRadioss results of the interface.",
370
+ ]
371
+ if ran:
372
+ lines += [
373
+ "",
374
+ f"The run is in {folder} (the animations {name}A*, the time history "
375
+ f"{name}T01 and their conversions, the listings {name}_0000.out and "
376
+ f"{name}_0001.out).",
377
+ ]
378
+ return "\n".join(lines) + "\n"
379
+
380
+
381
+ def _archive(ctx, folder: Path, name: str) -> str:
382
+ """An archive of the inputs of a run (not its outputs, which can be large)."""
383
+ target = ctx.path(f"{name}_openradioss_inputs.zip")
384
+ keep = (
385
+ f"{name}_0000.rad",
386
+ f"{name}_0001.rad",
387
+ f"{name}_mesh.npz",
388
+ "morphogen_radioss.json",
389
+ "run_openradioss.sh",
390
+ "run_openradioss.bat",
391
+ "README.md",
392
+ )
393
+ with zipfile.ZipFile(target, "w", zipfile.ZIP_DEFLATED) as zf:
394
+ for file in keep:
395
+ if (folder / file).is_file():
396
+ zf.write(folder / file, file)
397
+ return ctx.url(target.name)
398
+
399
+
400
+ #: morphoGen's Voigt components of a normal and of a shear loading
401
+ _NORMAL = ("11", "22", "33")
402
+ _SHEAR = {frozenset((0, 1)): "12", frozenset((1, 2)): "23", frozenset((0, 2)): "31"}
403
+
404
+
405
+ def _report(ctx, result, *, title: str, extra: dict) -> dict:
406
+ """The page of the results of a run: the summary (MPa, J, ms, MJ/m³, J/g), the curves
407
+ and energies, their figures, the frames for the 3D view, a video."""
408
+ from morphogen.dynamics import UnitSystem, summary, write_frames
409
+
410
+ m = result.manifest
411
+ units = UnitSystem(*m["units"])
412
+ to_mpa = units.si("stress") / 1e6
413
+ to_j = units.si("energy")
414
+ to_ms = units.si("time") * 1e3
415
+ values = dict(extra)
416
+ s = summary(result)
417
+ labels = {
418
+ "end time": ("end time (ms)", to_ms),
419
+ "stable time step (estimate)": ("stable time step, estimate (µs)", to_ms * 1e3),
420
+ "mass": ("mass (g)", units.si("mass") * 1e3),
421
+ "final stress": ("final stress (MPa)", to_mpa),
422
+ "peak stress": ("peak stress (MPa)", to_mpa),
423
+ "plateau stress (20-40 %)": ("plateau stress, 20-40 % (MPa)", to_mpa),
424
+ "absorbed energy per volume": ("absorbed energy per volume (MJ/m³)", to_mpa),
425
+ "absorbed energy per mass": (
426
+ "absorbed energy per mass (J/g)",
427
+ units.si("energy") / units.si("mass") * 1e-3,
428
+ ),
429
+ "peak force on the wall": ("peak force on the wall (N)", units.si("force")),
430
+ "internal energy at the end": ("internal energy at the end (J)", to_j),
431
+ "kinetic energy at the end": ("kinetic energy at the end (J)", to_j),
432
+ "hourglass energy at the end": ("hourglass energy at the end (J)", to_j),
433
+ "initial kinetic energy": ("initial kinetic energy (J)", to_j),
434
+ }
435
+ for key, value in s.items():
436
+ label, factor = labels.get(key, (key, None))
437
+ values[label] = value * factor if factor is not None and isinstance(value, float) else value
438
+ values["forces from"] = result.source
439
+ for note in result.warnings:
440
+ warnings.warn(note, stacklevel=2)
441
+ # the frames in a folder of their own, the last one beside the files for the 3D view
442
+ frames = write_frames(result, ctx.path("frames"))
443
+ if frames:
444
+ shutil.copyfile(frames[-1], ctx.path("final_state.vtu"))
445
+ c = result.curves
446
+ tables = []
447
+ if c:
448
+ columns = {}
449
+ for key, value in c.items():
450
+ if key == "time":
451
+ columns["time (ms)"] = np.asarray(value) * to_ms
452
+ elif key.startswith("stress"):
453
+ columns[f"{key} (MPa)"] = np.asarray(value) * to_mpa
454
+ elif key.startswith("force"):
455
+ columns[f"{key} (N)"] = np.asarray(value) * units.si("force")
456
+ elif key == "displacement":
457
+ columns["displacement (mm)"] = np.asarray(value) * units.si("length") * 1e3
458
+ else:
459
+ columns[key] = np.asarray(value)
460
+ if "stress_upper" in c: # morphoGen's components, for the Comparisons tab
461
+ axis, drive = int(m["axis"]), int(m["driven"])
462
+ comp = _NORMAL[axis] if axis == drive else _SHEAR[frozenset((axis, drive))]
463
+ sign = float(m["sign"])
464
+ columns[f"E{comp}"] = sign * np.asarray(c["strain"])
465
+ columns[f"S{comp}"] = sign * np.asarray(c["stress_upper"]) * to_mpa
466
+ columns["time"] = np.asarray(c["time"]) * to_ms
467
+ tables.append(
468
+ _table(
469
+ ctx,
470
+ columns,
471
+ "curves",
472
+ "curves of the run (nominal strain and stress "
473
+ "of the faces; E and S in morphoGen's components, MPa)",
474
+ )
475
+ )
476
+ if result.energies:
477
+ columns = {
478
+ ("time (ms)" if k == "time" else f"{k} (J)"): np.asarray(v)
479
+ * (to_ms if k == "time" else to_j)
480
+ for k, v in result.energies.items()
481
+ if not k.startswith("momentum")
482
+ }
483
+ if len(columns) > 1:
484
+ tables.append(_table(ctx, columns, "energies", "energies of the parts over time"))
485
+ _figures(ctx, result, to_mpa, to_ms, to_j)
486
+ _video(ctx, result, to_mpa, to_ms)
487
+ values["frames"] = len(frames)
488
+ return {"title": title, "values": values, "tables": tables}
489
+
490
+
491
+ def _table(ctx, columns: dict, name: str, title: str) -> dict:
492
+ """A table of curves written whole as .csv, every n-th row shown in the page."""
493
+ from morphogen.io.tables import write_table
494
+
495
+ path = write_table(ctx.path(f"{name}.csv"), columns)
496
+ n = len(next(iter(columns.values())))
497
+ rows = np.unique(np.linspace(0, n - 1, min(n, SHOWN_ROWS)).round().astype(int)) if n else []
498
+ names = list(columns)
499
+ from morphogen.gui.tools import _cell
500
+
501
+ return {
502
+ "title": title,
503
+ "columns": names,
504
+ "rows": [[_cell(float(columns[k][i])) for k in names] for i in rows],
505
+ "count": n,
506
+ "url": ctx.url(path.name),
507
+ }
508
+
509
+
510
+ def _figures(ctx, result, to_mpa: float, to_ms: float, to_j: float) -> None:
511
+ try:
512
+ from matplotlib.figure import Figure
513
+ except ImportError:
514
+ warnings.warn("no figures without matplotlib: pip install 'morphogen[plot]'", stacklevel=2)
515
+ return
516
+ c = result.curves
517
+ if "stress_upper" in c:
518
+ fig = Figure(figsize=(5.6, 3.9), layout="constrained")
519
+ ax = fig.subplots()
520
+ strain = np.asarray(c["strain"])
521
+ ax.plot(
522
+ strain,
523
+ np.asarray(c["stress_upper"]) * to_mpa,
524
+ lw=1.8,
525
+ color="#2a78d6",
526
+ label="driven face",
527
+ )
528
+ ax.plot(
529
+ strain,
530
+ np.asarray(c["stress_lower"]) * to_mpa,
531
+ lw=1.2,
532
+ ls="--",
533
+ color="#eb6834",
534
+ label="held face",
535
+ )
536
+ kind = result.manifest["loading"]["kind"]
537
+ ax.set_xlabel("nominal shear strain" if kind == "shear" else "nominal strain")
538
+ ax.set_ylabel("nominal stress (MPa)")
539
+ ax.set_title(
540
+ f"{kind} at {result.manifest['loading'].get('strain_rate', 0):g} /s", fontsize=10
541
+ )
542
+ ax.grid(alpha=0.3)
543
+ ax.legend(fontsize=8, frameon=False)
544
+ ctx.figure(fig, "stress_strain", "nominal stress–strain curves of the faces")
545
+ elif "force_wall" in c:
546
+ fig = Figure(figsize=(5.6, 3.9), layout="constrained")
547
+ ax = fig.subplots()
548
+ from morphogen.dynamics import UnitSystem
549
+
550
+ units = UnitSystem(*result.manifest["units"])
551
+ ax.plot(
552
+ np.asarray(c["time"]) * to_ms,
553
+ np.asarray(c["force_wall"]) * units.si("force"),
554
+ lw=1.6,
555
+ color="#2a78d6",
556
+ )
557
+ ax.set_xlabel("time (ms)")
558
+ ax.set_ylabel("force on the wall (N)")
559
+ ax.grid(alpha=0.3)
560
+ ctx.figure(fig, "wall_force", "force on the wall (the change of the momentum)")
561
+ e = result.energies
562
+ shown = [k for k in ("internal", "kinetic", "hourglass") if k in e]
563
+ if shown:
564
+ fig = Figure(figsize=(5.6, 3.6), layout="constrained")
565
+ ax = fig.subplots()
566
+ colours = {"internal": "#2a78d6", "kinetic": "#eb6834", "hourglass": "#1baf7a"}
567
+ for k in shown:
568
+ ax.plot(
569
+ np.asarray(e["time"]) * to_ms,
570
+ np.asarray(e[k]) * to_j,
571
+ lw=1.5,
572
+ color=colours[k],
573
+ label=k,
574
+ )
575
+ ax.set_xlabel("time (ms)")
576
+ ax.set_ylabel("energy (J)")
577
+ ax.grid(alpha=0.3)
578
+ ax.legend(fontsize=8, frameon=False)
579
+ ctx.figure(fig, "energies", "energies of the parts")
580
+
581
+
582
+ def _video(ctx, result, to_mpa: float, to_ms: float) -> None:
583
+ """The deformed morphology over time, coloured by its von Mises stress (VTK)."""
584
+ if len(result.frames) < 2 or result.frames[0].displacement is None:
585
+ return
586
+ try:
587
+ from morphogen.viz.video import history_frames, vtk_can_render
588
+
589
+ if not vtk_can_render():
590
+ return
591
+ from morphogen.dynamics.results import frames_mesh
592
+
593
+ mesh, owner = frames_mesh(result)
594
+ fields = None
595
+ if all("von_mises" in f.cells for f in result.frames):
596
+ fields = [np.nan_to_num(f.cells["von_mises"][owner]) * to_mpa for f in result.frames]
597
+ images = history_frames(
598
+ mesh,
599
+ [f.displacement for f in result.frames],
600
+ fields,
601
+ magnification=1.0,
602
+ title="von Mises (MPa)" if fields is not None else "|u|",
603
+ captions=[f"t = {f.time * to_ms:.3g} ms" for f in result.frames],
604
+ )
605
+ ctx.video(images, "deformation", "the morphology over time (von Mises stress)", mode="loop")
606
+ except (ImportError, RuntimeError, ValueError) as exc:
607
+ warnings.warn(f"no video of the run: {exc}", stacklevel=2)
608
+
609
+
610
+ @tool(
611
+ "radioss_test",
612
+ "dynamics",
613
+ "Dynamic test (OpenRadioss)",
614
+ "The crushing, tension, shear or impact of a morphology simulated by OpenRadioss: its "
615
+ "mesh (voxels or conforming tetrahedra), the materials of its phases (elastic, von "
616
+ "Mises elastoplastic with a linear, Voce or viscous hardening, Johnson–Cook; failure "
617
+ "by element deletion), the loaded faces held and driven at the strain rate after a "
618
+ "smooth start (or the morphology thrown against a rigid wall), the self contact of its "
619
+ "outer surface; its nominal stress–strain curves (both faces: their gap tells whether "
620
+ "the test is quasi-static), energies, peak and plateau stresses, densification strain, "
621
+ "absorbed energy per volume and mass, its fields over time in 3D and a video. Without "
622
+ "OpenRadioss here, the inputs and the scripts to run them elsewhere.",
623
+ FIELDS,
624
+ order=1,
625
+ groups=(
626
+ ("Specimen", "source"),
627
+ ("Materials", "materials"),
628
+ ("Loading", "loading"),
629
+ ("Solver and outputs", "frames", True),
630
+ ),
631
+ )
632
+ def radioss_test(p: dict, ctx) -> dict:
633
+ from morphogen import dynamics
634
+
635
+ item = p["source"]
636
+ micro = item.get("micro")
637
+ if micro is None:
638
+ raise ValueError(f"{item['title']}: no microstructure in this session")
639
+ installation = None
640
+ if p["run"]: # before the mesh: say at once that OpenRadioss is missing
641
+ try:
642
+ installation = dynamics.find_openradioss(p.get("installation") or None)
643
+ except FileNotFoundError as exc:
644
+ raise ValueError(
645
+ f"{exc} — or uncheck 'run OpenRadioss here' to write its inputs"
646
+ ) from None
647
+ materials = _materials(p, item)
648
+ loading = _loading(p)
649
+ model = (item.get("model") or {}).get("type") or getattr(micro, "kind", "") or "morphology"
650
+ folder = ctx.path("openradioss")
651
+ threads = int(p.get("threads") or THREADS)
652
+ step = float(p["time_step"]) * 1e-6 if p.get("time_step") else None
653
+ test = dynamics.explicit_test(
654
+ micro,
655
+ materials,
656
+ loading,
657
+ folder,
658
+ mesh=p["mesh"],
659
+ resolution=int(p.get("resolution") or 24),
660
+ element_size=p.get("element_size"),
661
+ order=int(p.get("order") or 1),
662
+ units=dynamics.UnitSystem("Mg", "mm", "s"),
663
+ length_scale=TO_MM[p["length_unit"]],
664
+ name=p.get("name") or model,
665
+ frames=int(p.get("frames") or 40),
666
+ time_step=step,
667
+ run=bool(p["run"]),
668
+ threads=threads,
669
+ mpi=int(p.get("mpi") or 1),
670
+ installation=installation,
671
+ progress=lambda f, message: ctx.progress(0.02 + 0.9 * f, message),
672
+ phase_names={int(k): v for k, v in (item.get("phases") or {}).items()},
673
+ )
674
+ manifest = test.inputs.manifest
675
+ name = test.inputs.name
676
+ _scripts(folder, name, threads)
677
+ readme = _readme(manifest, folder, bool(p["run"]))
678
+ (folder / "README.md").write_text(readme, encoding="utf-8")
679
+ shutil.copyfile(folder / "README.md", ctx.path("README.md"))
680
+ archive = _archive(ctx, folder, name)
681
+ extra = {"OpenRadioss": installation.version or str(installation.root)} if installation else {}
682
+ if not p["run"]:
683
+ values = {
684
+ "nodes": manifest["n_nodes"],
685
+ "elements": f"{manifest['n_elements']} {manifest['elements']}",
686
+ "end time (ms)": manifest["end_time"] * 1e3,
687
+ "stable time step, estimate (µs)": manifest["critical_time_step"] * 1e6,
688
+ "cycles (estimate)": round(manifest["cycles"]),
689
+ "mass (g)": manifest["mass"] * 1e6,
690
+ }
691
+ return {
692
+ "title": f"OpenRadioss inputs of {model}",
693
+ "values": values,
694
+ "text": readme,
695
+ "archive": archive,
696
+ }
697
+ extra["run time (s)"] = round(test.run.elapsed, 1)
698
+ out = _report(ctx, test.result, title=f"Dynamic {loading.kind} of {model}", extra=extra)
699
+ out.update(text=readme, archive=archive)
700
+ return out
701
+
702
+
703
+ @tool(
704
+ "radioss_results",
705
+ "dynamics",
706
+ "OpenRadioss results",
707
+ "The results of a run of OpenRadioss made elsewhere (a cluster, the scripts of a Dynamic "
708
+ "test): the folder of its inputs written by morphoGen, with its animations and time "
709
+ "history, converted here when they are not (anim_to_vtk, th_to_csv of the installation "
710
+ "found); its curves, energies, summary and frames in 3D, as a Dynamic test shows them.",
711
+ [
712
+ Field(
713
+ "directory",
714
+ "str",
715
+ required=True,
716
+ label="folder of the run",
717
+ doc="the folder with morphogen_radioss.json, the inputs and the outputs",
718
+ browse="folder",
719
+ ),
720
+ Field("convert", "bool", True, label="convert the outputs", doc="with OpenRadioss's tools"),
721
+ Field(
722
+ "installation",
723
+ "str",
724
+ "",
725
+ label="folder of OpenRadioss",
726
+ browse="folder",
727
+ doc="blank: found as for a Dynamic test",
728
+ ),
729
+ ],
730
+ order=2,
731
+ )
732
+ def radioss_results(p: dict, ctx) -> dict:
733
+ from morphogen import dynamics
734
+ from morphogen.io.radioss import read_manifest
735
+
736
+ folder = Path(str(p["directory"]).strip().strip('"')).expanduser()
737
+ manifest = read_manifest(folder)
738
+ if p["convert"]:
739
+ try:
740
+ install = dynamics.find_openradioss(p.get("installation") or None)
741
+ except FileNotFoundError as exc:
742
+ warnings.warn(f"outputs not converted: {exc}", stacklevel=1)
743
+ else:
744
+ run = dynamics.RadiossRun(folder, manifest["name"], [], None, {})
745
+ dynamics.convert_outputs(run, install, progress=ctx.progress)
746
+ for note in run.warnings:
747
+ warnings.warn(note, stacklevel=1)
748
+ result = dynamics.read_explicit_run(folder)
749
+ if not result.curves and not result.frames:
750
+ raise ValueError(
751
+ f"no results in {folder}: run its inputs first ({manifest['name']}_0000.rad)"
752
+ )
753
+ return _report(
754
+ ctx,
755
+ result,
756
+ title=f"OpenRadioss results of {manifest['title']}",
757
+ extra={"folder": str(folder)},
758
+ )
759
+
760
+
761
+ @tool(
762
+ "radioss_install",
763
+ "dynamics",
764
+ "OpenRadioss installation",
765
+ "The installation of OpenRadioss that the Dynamic tests run: the one found (its "
766
+ "folder, executables and release), or a release downloaded from GitHub (the latest, or "
767
+ "a tag) and unpacked into a folder (~/morphogen/openradioss by default), which the "
768
+ "tests then find. Releases are published for Linux and Windows; elsewhere build "
769
+ "OpenRadioss from its sources and set OPENRADIOSS_PATH. OpenRadioss is free software "
770
+ "(AGPL-3.0) of the OpenRadioss project, run as a separate program.",
771
+ [
772
+ Field(
773
+ "action",
774
+ "choice",
775
+ "check",
776
+ choices=(
777
+ ("check", "show the installation found"),
778
+ ("install", "download and install a release from GitHub"),
779
+ ),
780
+ ),
781
+ Field(
782
+ "target",
783
+ "str",
784
+ "",
785
+ label="folder",
786
+ when={"action": "install"},
787
+ browse="folder",
788
+ doc="blank: ~/morphogen/openradioss (replaced)",
789
+ ),
790
+ Field(
791
+ "tag",
792
+ "str",
793
+ "",
794
+ label="release",
795
+ when={"action": "install"},
796
+ doc="the tag of a release (blank: the latest)",
797
+ ),
798
+ Field(
799
+ "installation",
800
+ "str",
801
+ "",
802
+ label="folder of OpenRadioss",
803
+ when={"action": "check"},
804
+ browse="folder",
805
+ doc="blank: OPENRADIOSS_PATH, ~/morphogen/openradioss or the PATH",
806
+ ),
807
+ ],
808
+ order=3,
809
+ )
810
+ def radioss_install(p: dict, ctx) -> dict:
811
+ from morphogen import dynamics
812
+
813
+ if p["action"] == "install":
814
+ install = dynamics.install_openradioss(
815
+ p.get("target") or None, tag=p.get("tag") or None, progress=ctx.progress
816
+ )
817
+ title = f"OpenRadioss {install.version or ''} installed"
818
+ else:
819
+ try:
820
+ install = dynamics.find_openradioss(p.get("installation") or None)
821
+ except FileNotFoundError as exc:
822
+ raise ValueError(str(exc)) from None
823
+ title = "OpenRadioss found"
824
+ return {"title": title, "values": install.describe()}