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,643 @@
1
+ """OpenRadioss on this machine: where it is installed (:func:`find_openradioss`), the
2
+ environment its programs need, its runs (:func:`run_openradioss`: the Starter, then the
3
+ Engine, their progress followed in their listings, stopped at a checkpoint of
4
+ :mod:`morphogen.stopping`), the conversion of its outputs (``anim_to_vtk`` for the
5
+ animations, ``th_to_csv`` for the time histories) and the installation of a release that
6
+ the OpenRadioss project publishes on GitHub (:func:`install_openradioss`).
7
+
8
+ OpenRadioss (https://github.com/OpenRadioss/OpenRadioss, AGPL-3.0) is a separate
9
+ program: morphoGen writes its inputs, runs its executables and reads their outputs, and
10
+ neither ships nor links it. An installation is the folder of a release (its ``exec``,
11
+ ``hm_cfg_files`` and ``extlib`` folders), found from, in order: the path given, the
12
+ environment variables ``MORPHOGEN_OPENRADIOSS`` and ``OPENRADIOSS_PATH`` (that of
13
+ OpenRadioss's documentation), the folder where :func:`install_openradioss` puts it
14
+ (``~/morphogen/openradioss``), and a Starter on the ``PATH``."""
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ import platform
21
+ import shutil
22
+ import stat
23
+ import subprocess
24
+ import sys
25
+ import tempfile
26
+ import time
27
+ import urllib.request
28
+ import zipfile
29
+ from collections.abc import Callable
30
+ from dataclasses import dataclass, field
31
+ from pathlib import Path
32
+
33
+ from morphogen._version import __version__
34
+ from morphogen.stopping import Stopped, checkpoint
35
+
36
+ #: The environment variables of the folder of an installation, in order
37
+ ENVIRONMENT = ("MORPHOGEN_OPENRADIOSS", "OPENRADIOSS_PATH")
38
+ #: The repository of OpenRadioss, whose releases :func:`install_openradioss` installs
39
+ REPOSITORY = "OpenRadioss/OpenRadioss"
40
+ GITHUB_API = "https://api.github.com"
41
+ #: The file that records the release installed in its folder
42
+ RELEASE_FILE = "morphogen_release.json"
43
+ #: The words of the names of the archives of the releases, by system and machine
44
+ ASSETS = {
45
+ ("Linux", "x86_64"): ("linux64",),
46
+ ("Linux", "aarch64"): ("linuxa64", "linux_arm64", "aarch64", "arm64"),
47
+ ("Linux", "arm64"): ("linuxa64", "linux_arm64", "aarch64", "arm64"),
48
+ ("Windows", "AMD64"): ("win64",),
49
+ ("Windows", "x86_64"): ("win64",),
50
+ ("Darwin", "arm64"): ("macos", "mac", "darwin"),
51
+ ("Darwin", "x86_64"): ("macos", "mac", "darwin"),
52
+ }
53
+
54
+
55
+ def default_home() -> Path:
56
+ """The folder where :func:`install_openradioss` installs OpenRadioss by default."""
57
+ return Path.home() / "morphogen" / "openradioss"
58
+
59
+
60
+ @dataclass
61
+ class OpenRadioss:
62
+ """An installation of OpenRadioss: its folder (``root``), the Starter, the Engine
63
+ (and its MPI version), the converters of its outputs when it has them, the suffix of
64
+ the names of its executables (``linux64_gf``, ``win64``...) and the release
65
+ installed (when :func:`install_openradioss` installed it)."""
66
+
67
+ root: Path
68
+ starter: Path
69
+ engine: Path
70
+ engine_mpi: Path | None = None
71
+ anim_to_vtk: Path | None = None
72
+ th_to_csv: Path | None = None
73
+ suffix: str = ""
74
+ release: dict = field(default_factory=dict)
75
+
76
+ @property
77
+ def version(self) -> str | None:
78
+ return self.release.get("tag")
79
+
80
+ def library_folders(self) -> list[Path]:
81
+ """The folders of the shared libraries of its programs (the reader of the
82
+ inputs, H3D, the runtimes of the compilers), for the platform of the executables."""
83
+ extlib = self.root / "extlib"
84
+ if not extlib.is_dir():
85
+ return []
86
+ names = {self.suffix.split("_")[0], self.suffix}
87
+ found = []
88
+ for folder in sorted(extlib.rglob("*")):
89
+ if folder.is_dir() and folder.name in names:
90
+ found.append(folder)
91
+ return found
92
+
93
+ def environment(self, threads: int | None = None, base: dict | None = None) -> dict:
94
+ """The environment of its programs: ``OPENRADIOSS_PATH``, ``RAD_CFG_PATH`` (the
95
+ configuration of the reader of the inputs), ``RAD_H3D_PATH``, the stack of the
96
+ OpenMP threads, their number, and the folders of its libraries on the search path
97
+ of the system."""
98
+ env = dict(os.environ if base is None else base)
99
+ env["OPENRADIOSS_PATH"] = str(self.root)
100
+ env["RAD_CFG_PATH"] = str(self.root / "hm_cfg_files")
101
+ folders = self.library_folders()
102
+ h3d = [f for f in folders if "h3d" in f.parts]
103
+ if h3d:
104
+ env["RAD_H3D_PATH"] = str(h3d[0])
105
+ env.setdefault("OMP_STACKSIZE", "400m")
106
+ env.setdefault("KMP_STACKSIZE", "400m")
107
+ if threads:
108
+ env["OMP_NUM_THREADS"] = str(int(threads))
109
+ if folders:
110
+ name = {"win32": "PATH", "darwin": "DYLD_LIBRARY_PATH"}.get(
111
+ sys.platform, "LD_LIBRARY_PATH"
112
+ )
113
+ paths = [str(f) for f in folders]
114
+ if env.get(name):
115
+ paths.append(env[name])
116
+ env[name] = os.pathsep.join(paths)
117
+ return env
118
+
119
+ def describe(self) -> dict:
120
+ """Its folder, executables and release, for the page and the command line."""
121
+ out = {
122
+ "root": str(self.root),
123
+ "starter": str(self.starter),
124
+ "engine": str(self.engine),
125
+ "engine (MPI)": str(self.engine_mpi) if self.engine_mpi else "none",
126
+ "anim_to_vtk": str(self.anim_to_vtk) if self.anim_to_vtk else "none",
127
+ "th_to_csv": str(self.th_to_csv) if self.th_to_csv else "none",
128
+ }
129
+ if self.version:
130
+ out["release"] = self.version
131
+ return out
132
+
133
+
134
+ def _executable(path: Path) -> bool:
135
+ return path.is_file() and (sys.platform == "win32" or os.access(path, os.X_OK))
136
+
137
+
138
+ def _make_executable(folder: Path) -> None:
139
+ """Restore the permission to run the programs of a folder (an archive unpacked
140
+ without its permission bits)."""
141
+ if sys.platform == "win32" or not folder.is_dir():
142
+ return
143
+ for path in folder.iterdir():
144
+ if path.is_file() and not os.access(path, os.X_OK):
145
+ try:
146
+ path.chmod(path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
147
+ except OSError:
148
+ pass
149
+
150
+
151
+ def _exec_folder(path: Path) -> Path | None:
152
+ """The folder of the executables of the installation at ``path``: ``path/exec``, a
153
+ folder holding a Starter, the folder of a Starter given, or that of the only
154
+ installation in ``path`` (an archive unpacked into it)."""
155
+ path = Path(path).expanduser()
156
+ if path.is_file():
157
+ return path.parent if path.name.lower().startswith("starter_") else None
158
+ if not path.is_dir():
159
+ return None
160
+ for candidate in (path / "exec", path):
161
+ if candidate.is_dir() and any(
162
+ p.name.lower().startswith("starter_") for p in candidate.iterdir()
163
+ ):
164
+ return candidate
165
+ inner = [p for p in path.iterdir() if p.is_dir() and (p / "exec").is_dir()]
166
+ return inner[0] / "exec" if len(inner) == 1 else None
167
+
168
+
169
+ def _pick(folder: Path, prefix: str, suffix: str, variants=("",)) -> Path | None:
170
+ """The program ``<prefix><suffix><variant>`` of a folder (with ``.exe`` on Windows),
171
+ the first variant found."""
172
+ for variant in variants:
173
+ for ext in ("", ".exe"):
174
+ path = folder / f"{prefix}{suffix}{variant}{ext}"
175
+ if path.is_file():
176
+ return path
177
+ return None
178
+
179
+
180
+ def _installation(folder: Path) -> OpenRadioss:
181
+ folder = Path(folder).resolve()
182
+ _make_executable(folder)
183
+ starters = sorted(
184
+ p
185
+ for p in folder.iterdir()
186
+ if p.name.lower().startswith("starter_")
187
+ and p.suffix.lower() in ("", ".exe")
188
+ and not p.stem.endswith("_sp")
189
+ )
190
+ if not starters:
191
+ raise FileNotFoundError(f"no Starter of OpenRadioss in {folder}")
192
+ # the double precision Starter of the machine: the shortest name (no _sp, no variant)
193
+ starter = min(starters, key=lambda p: len(p.stem))
194
+ suffix = starter.stem[len("starter_") :]
195
+ engine = _pick(folder, "engine_", suffix)
196
+ if engine is None:
197
+ raise FileNotFoundError(f"no Engine of OpenRadioss in {folder} (engine_{suffix})")
198
+ root = folder.parent if folder.name == "exec" else folder
199
+ release = {}
200
+ for place in (root, root.parent):
201
+ record = place / RELEASE_FILE
202
+ if record.is_file():
203
+ try:
204
+ release = json.loads(record.read_text(encoding="utf-8"))
205
+ except (OSError, ValueError):
206
+ release = {}
207
+ break
208
+ return OpenRadioss(
209
+ root=root,
210
+ starter=starter,
211
+ engine=engine,
212
+ engine_mpi=_pick(folder, "engine_", suffix, ("_ompi", "_impi", "_mpi")),
213
+ anim_to_vtk=_pick(folder, "anim_to_vtk_", suffix),
214
+ th_to_csv=_pick(folder, "th_to_csv_", suffix),
215
+ suffix=suffix,
216
+ release=release,
217
+ )
218
+
219
+
220
+ def find_openradioss(path=None) -> OpenRadioss:
221
+ """The installation of OpenRadioss at ``path`` (its folder, its ``exec`` folder or
222
+ its Starter), else the first found in the places of the module; raises
223
+ FileNotFoundError, saying how to install it, when there is none."""
224
+ tried = []
225
+ places = [(str(path), "the path given")] if path not in (None, "") else []
226
+ places += [(os.environ[v], f"${v}") for v in ENVIRONMENT if os.environ.get(v)]
227
+ places.append((str(default_home()), "the folder of morphogen radioss install"))
228
+ for place, origin in places:
229
+ folder = _exec_folder(Path(place))
230
+ if folder is not None:
231
+ return _installation(folder)
232
+ tried.append(f"{origin} ({place})")
233
+ if origin == "the path given":
234
+ raise FileNotFoundError(f"no installation of OpenRadioss at {place}")
235
+ for name in ("starter_linux64_gf", "starter_win64", "starter_linuxa64", "starter_macos64"):
236
+ exe = shutil.which(name)
237
+ if exe:
238
+ return _installation(Path(exe).resolve().parent)
239
+ raise FileNotFoundError(
240
+ "OpenRadioss not found (tried " + ", ".join(tried) + " and the PATH): install a "
241
+ "release with `morphogen radioss install` (or the tool OpenRadioss installation of the "
242
+ "interface), or set OPENRADIOSS_PATH to the folder of one (https://github.com/OpenRadioss/"
243
+ "OpenRadioss/releases)"
244
+ )
245
+
246
+
247
+ def has_openradioss(path=None) -> bool:
248
+ """Whether an installation of OpenRadioss is found."""
249
+ try:
250
+ find_openradioss(path)
251
+ except FileNotFoundError:
252
+ return False
253
+ return True
254
+
255
+
256
+ # -- runs ----------------------------------------------------------------------------------
257
+
258
+
259
+ @dataclass
260
+ class RadiossRun:
261
+ """A run of OpenRadioss in its ``directory``: its animations converted to legacy VTK
262
+ files (``frames``, in their order), its time history converted to CSV (``history``,
263
+ None without ``th_to_csv``), its listings and the time it took (s)."""
264
+
265
+ directory: Path
266
+ name: str
267
+ frames: list[Path]
268
+ history: Path | None
269
+ listings: dict[str, Path]
270
+ elapsed: float = 0.0
271
+ warnings: list[str] = field(default_factory=list)
272
+
273
+
274
+ def _wait(
275
+ process: subprocess.Popen,
276
+ listing: Path | None,
277
+ end_time: float | None,
278
+ progress: Callable | None,
279
+ span: tuple[float, float],
280
+ label: str,
281
+ timeout: float | None,
282
+ ) -> int:
283
+ """Wait for a program, its progress read in its listing (the time of its last cycle
284
+ over ``end_time``, mapped on ``span``), stopped at a checkpoint (it is killed)."""
285
+ from morphogen.io.radioss import read_radioss_listing
286
+
287
+ started = time.monotonic()
288
+ last = -1.0
289
+ while True:
290
+ try:
291
+ code = process.wait(timeout=0.5)
292
+ except subprocess.TimeoutExpired:
293
+ code = None
294
+ try:
295
+ checkpoint()
296
+ except Stopped:
297
+ _kill(process)
298
+ raise
299
+ if timeout is not None and time.monotonic() - started > timeout:
300
+ _kill(process)
301
+ raise RuntimeError(f"{label}: stopped after {timeout:g} s (timeout)")
302
+ if progress is not None and listing is not None and end_time and listing.is_file():
303
+ try:
304
+ now = read_radioss_listing(listing).time
305
+ except OSError:
306
+ now = last
307
+ if now > last:
308
+ last = now
309
+ share = min(max(now / end_time, 0.0), 1.0)
310
+ progress(
311
+ span[0] + share * (span[1] - span[0]),
312
+ f"{label}: t = {now:.4g} of {end_time:.4g}",
313
+ )
314
+ if code is not None:
315
+ return int(code)
316
+
317
+
318
+ def _kill(process: subprocess.Popen) -> None:
319
+ try:
320
+ process.kill()
321
+ process.wait(timeout=10)
322
+ except (OSError, subprocess.TimeoutExpired):
323
+ pass
324
+
325
+
326
+ def _check(listing: Path, code: int, label: str, log: Path) -> None:
327
+ """Raise RuntimeError when a program failed: its exit code, its listing's errors or
328
+ its abnormal termination (the end of its log otherwise)."""
329
+ from morphogen.io.radioss import read_radioss_listing
330
+
331
+ state = read_radioss_listing(listing) if listing.is_file() else None
332
+ errors = state.errors if state is not None else []
333
+ if code == 0 and state is not None and state.normal is not False and not errors:
334
+ return
335
+ if code == 0 and state is None:
336
+ return
337
+ detail = "; ".join(errors[:3])
338
+ if not detail and log.is_file():
339
+ tail = log.read_text(encoding="utf-8", errors="replace").strip().splitlines()[-8:]
340
+ detail = " | ".join(s.strip() for s in tail if s.strip())
341
+ where = listing.name if listing.is_file() else log.name
342
+ raise RuntimeError(f"{label} failed (exit code {code}; see {where}): {detail or 'no detail'}")
343
+
344
+
345
+ def run_openradioss(
346
+ directory,
347
+ name: str | None = None,
348
+ *,
349
+ threads: int | None = None,
350
+ mpi: int | None = None,
351
+ installation=None,
352
+ progress: Callable | None = None,
353
+ convert: bool = True,
354
+ timeout: float | None = None,
355
+ ) -> RadiossRun:
356
+ """Run the inputs written in ``directory`` (:func:`morphogen.io.write_radioss`): the
357
+ Starter, then the Engine with ``threads`` OpenMP threads (all the cores by default)
358
+ or on ``mpi`` processes (``mpiexec`` and the Engine built with MPI), then the
359
+ conversion of the animations and of the time history (``convert``).
360
+
361
+ ``progress(fraction, message)`` is called as the run advances (the time of the
362
+ last cycle printed in the listing of the Engine); a stop asked by
363
+ :mod:`morphogen.stopping` kills the programs. Raises RuntimeError when a program
364
+ fails (the errors of its listing); its logs stay in the directory."""
365
+ from morphogen.io.radioss import read_manifest
366
+
367
+ directory = Path(directory).resolve()
368
+ manifest = read_manifest(directory)
369
+ name = name or manifest["name"]
370
+ install = (
371
+ installation if isinstance(installation, OpenRadioss) else find_openradioss(installation)
372
+ )
373
+ threads = int(threads or os.cpu_count() or 1)
374
+ env = install.environment(threads)
375
+ started = time.monotonic()
376
+ end_time = float(manifest.get("end_time") or 0.0) or None
377
+ domains = int(mpi or 1)
378
+ listings = {"starter": directory / f"{name}_0000.out", "engine": directory / f"{name}_0001.out"}
379
+ for stale in listings.values():
380
+ stale.unlink(missing_ok=True)
381
+ if progress:
382
+ progress(0.0, "OpenRadioss Starter")
383
+ log = directory / "starter.log"
384
+ with open(log, "w", encoding="utf-8") as out:
385
+ process = subprocess.Popen(
386
+ [str(install.starter), "-i", f"{name}_0000.rad", "-np", str(domains)],
387
+ cwd=directory,
388
+ env=env,
389
+ stdout=out,
390
+ stderr=subprocess.STDOUT,
391
+ )
392
+ code = _wait(process, None, None, None, (0.0, 0.05), "Starter", timeout)
393
+ _check(listings["starter"], code, "the Starter of OpenRadioss", log)
394
+ if domains > 1:
395
+ mpiexec = shutil.which("mpiexec") or shutil.which("mpirun")
396
+ if install.engine_mpi is None or mpiexec is None:
397
+ raise RuntimeError(
398
+ f"{domains} MPI processes: an Engine built with MPI "
399
+ f"({'found' if install.engine_mpi else 'none in ' + str(install.root)}) and "
400
+ f"mpiexec ({'found' if mpiexec else 'not on the PATH'})"
401
+ )
402
+ command = [mpiexec, "-n", str(domains), str(install.engine_mpi)]
403
+ env["OMP_NUM_THREADS"] = str(max(1, threads // domains))
404
+ else:
405
+ command = [str(install.engine)]
406
+ command += ["-i", f"{name}_0001.rad", "-nt", env.get("OMP_NUM_THREADS", str(threads))]
407
+ log = directory / "engine.log"
408
+ with open(log, "w", encoding="utf-8") as out:
409
+ process = subprocess.Popen(
410
+ command, cwd=directory, env=env, stdout=out, stderr=subprocess.STDOUT
411
+ )
412
+ code = _wait(
413
+ process, listings["engine"], end_time, progress, (0.05, 0.9), "OpenRadioss", timeout
414
+ )
415
+ _check(listings["engine"], code, "the Engine of OpenRadioss", log)
416
+ run = RadiossRun(directory, name, [], None, listings, time.monotonic() - started)
417
+ if convert:
418
+ convert_outputs(run, install, env=env, progress=progress)
419
+ run.elapsed = time.monotonic() - started
420
+ return run
421
+
422
+
423
+ def animation_files(directory, name: str) -> list[Path]:
424
+ """The animation files of a run (``<name>A001``, ``<name>A002``...), in order."""
425
+ found = []
426
+ for path in Path(directory).glob(f"{name}A*"):
427
+ tail = path.name[len(name) + 1 :]
428
+ if tail.isdigit():
429
+ found.append(path)
430
+ return sorted(found, key=lambda p: int(p.name[len(name) + 1 :]))
431
+
432
+
433
+ def convert_outputs(run: RadiossRun, installation=None, *, env=None, progress=None) -> RadiossRun:
434
+ """Convert the outputs of a run: each animation to a legacy VTK file (``anim_to_vtk``,
435
+ ``<name>A001.vtk``...) and the time history to CSV (``th_to_csv``); the outputs
436
+ already converted are kept. A converter missing from the installation is skipped
437
+ with a warning of the run."""
438
+ install = (
439
+ installation if isinstance(installation, OpenRadioss) else find_openradioss(installation)
440
+ )
441
+ env = env or install.environment()
442
+ directory, name = Path(run.directory), run.name
443
+ animations = animation_files(directory, name)
444
+ frames = []
445
+ if animations and install.anim_to_vtk is None:
446
+ run.warnings.append("no anim_to_vtk in the installation: the animations are not read")
447
+ for k, path in enumerate(animations):
448
+ target = path.with_name(path.name + ".vtk")
449
+ if install.anim_to_vtk is not None and not target.is_file():
450
+ checkpoint()
451
+ if progress:
452
+ progress(
453
+ 0.9 + 0.08 * k / len(animations), f"animation {k + 1} of {len(animations)}"
454
+ )
455
+ with open(target, "wb") as out:
456
+ done = subprocess.run(
457
+ [str(install.anim_to_vtk), path.name],
458
+ cwd=directory,
459
+ env=env,
460
+ stdout=out,
461
+ stderr=subprocess.PIPE,
462
+ )
463
+ if done.returncode != 0 or target.stat().st_size == 0:
464
+ target.unlink(missing_ok=True)
465
+ run.warnings.append(
466
+ f"anim_to_vtk failed on {path.name}: "
467
+ f"{done.stderr.decode(errors='replace').strip()[:200]}"
468
+ )
469
+ continue
470
+ if target.is_file():
471
+ frames.append(target)
472
+ run.frames = frames
473
+ history = directory / f"{name}T01"
474
+ if history.is_file():
475
+ found = sorted(directory.glob(f"{name}T01*.csv"))
476
+ if not found and install.th_to_csv is not None:
477
+ checkpoint()
478
+ done = subprocess.run(
479
+ [str(install.th_to_csv), history.name], cwd=directory, env=env, capture_output=True
480
+ )
481
+ found = sorted(directory.glob(f"{name}T01*.csv"))
482
+ if not found and done.returncode == 0 and done.stdout.strip():
483
+ target = directory / f"{name}T01.csv" # a converter writing to its output
484
+ target.write_bytes(done.stdout)
485
+ found = [target]
486
+ if not found:
487
+ run.warnings.append(
488
+ f"th_to_csv gave no CSV file: "
489
+ f"{done.stderr.decode(errors='replace').strip()[:200]}"
490
+ )
491
+ elif not found:
492
+ run.warnings.append("no th_to_csv in the installation: the time history is not read")
493
+ run.history = found[0] if found else None
494
+ return run
495
+
496
+
497
+ # -- installation of a release -------------------------------------------------------------
498
+
499
+
500
+ def _request(url: str, timeout: float):
501
+ request = urllib.request.Request(
502
+ url,
503
+ headers={
504
+ "Accept": "application/vnd.github+json, application/octet-stream;q=0.9",
505
+ "User-Agent": f"morphoGen/{__version__}",
506
+ },
507
+ )
508
+ return urllib.request.urlopen(request, timeout=timeout)
509
+
510
+
511
+ def release_info(tag: str | None = None, *, api: str = GITHUB_API, timeout: float = 60) -> dict:
512
+ """The release ``tag`` of OpenRadioss on GitHub (the latest by default): its name,
513
+ tag and archives (``assets``: name, size, URL)."""
514
+ path = f"tags/{tag}" if tag else "latest"
515
+ with _request(f"{api.rstrip('/')}/repos/{REPOSITORY}/releases/{path}", timeout) as res:
516
+ data = json.loads(res.read().decode("utf-8"))
517
+ assets = [
518
+ {
519
+ "name": a.get("name", ""),
520
+ "size": int(a.get("size") or 0),
521
+ "url": a.get("browser_download_url", ""),
522
+ }
523
+ for a in data.get("assets", [])
524
+ ]
525
+ return {
526
+ "tag": data.get("tag_name", tag or ""),
527
+ "name": data.get("name", ""),
528
+ "published": data.get("published_at", ""),
529
+ "assets": assets,
530
+ }
531
+
532
+
533
+ def release_asset(release: dict, system: str | None = None, machine: str | None = None) -> dict:
534
+ """The archive of a release (:func:`release_info`) for this system and machine."""
535
+ system = system or platform.system()
536
+ machine = machine or platform.machine()
537
+ words = ASSETS.get((system, machine))
538
+ if words is None:
539
+ raise RuntimeError(
540
+ f"no release of OpenRadioss is published for {system} on {machine}: build it from "
541
+ "its sources (https://github.com/OpenRadioss/OpenRadioss) and set OPENRADIOSS_PATH"
542
+ )
543
+ archives = [
544
+ a
545
+ for a in release.get("assets", [])
546
+ if a["name"].lower().endswith((".zip", ".tar.gz", ".tgz"))
547
+ ]
548
+ for word in words:
549
+ for asset in archives:
550
+ name = asset["name"].lower()
551
+ if word in name and "src" not in name and "source" not in name:
552
+ if word == "linux64" and ("linuxa64" in name or "arm" in name):
553
+ continue
554
+ return asset
555
+ raise RuntimeError(
556
+ f"the release {release.get('tag')} of OpenRadioss has no archive for {system} on "
557
+ f"{machine} (archives: {', '.join(a['name'] for a in archives) or 'none'})"
558
+ )
559
+
560
+
561
+ def _extract(archive: Path, target: Path) -> None:
562
+ """Unpack a zip or tar archive into ``target``, refusing the members that would land
563
+ outside it, with the permission bits of the zip members kept."""
564
+ target = target.resolve()
565
+ if archive.name.lower().endswith(".zip"):
566
+ with zipfile.ZipFile(archive) as zf:
567
+ for member in zf.infolist():
568
+ path = (target / member.filename).resolve()
569
+ if target != path and target not in path.parents:
570
+ raise RuntimeError(
571
+ f"{archive.name}: the member {member.filename} leaves the folder"
572
+ )
573
+ zf.extract(member, target)
574
+ mode = (member.external_attr >> 16) & 0o777
575
+ if mode and not member.is_dir():
576
+ path.chmod(mode | stat.S_IRUSR | stat.S_IWUSR)
577
+ return
578
+ import tarfile
579
+
580
+ with tarfile.open(archive) as tf:
581
+ tf.extractall(target, filter="data")
582
+
583
+
584
+ def install_openradioss(
585
+ target=None,
586
+ *,
587
+ tag: str | None = None,
588
+ api: str = GITHUB_API,
589
+ progress: Callable | None = None,
590
+ timeout: float = 120,
591
+ system: str | None = None,
592
+ machine: str | None = None,
593
+ ) -> OpenRadioss:
594
+ """Download the release ``tag`` of OpenRadioss (the latest by default) for this system
595
+ from GitHub and unpack it into ``target`` (``~/morphogen/openradioss`` by default),
596
+ which replaces an earlier installation there; returns the installation. Releases are
597
+ published for Linux (x86-64, ARM) and Windows; elsewhere OpenRadioss is built from its
598
+ sources. ``progress(fraction, message)`` follows the download."""
599
+ target = Path(target).expanduser() if target else default_home()
600
+ if progress:
601
+ progress(0.0, "the release of OpenRadioss")
602
+ release = release_info(tag, api=api, timeout=timeout)
603
+ asset = release_asset(release, system, machine)
604
+ target.parent.mkdir(parents=True, exist_ok=True)
605
+ with tempfile.TemporaryDirectory(prefix=".openradioss-", dir=target.parent) as tmp:
606
+ archive = Path(tmp) / Path(asset["name"]).name
607
+ with _request(asset["url"], timeout) as res, open(archive, "wb") as out:
608
+ total = int(res.headers.get("Content-Length") or asset.get("size") or 0)
609
+ done = 0
610
+ while True:
611
+ checkpoint()
612
+ block = res.read(1 << 20)
613
+ if not block:
614
+ break
615
+ out.write(block)
616
+ done += len(block)
617
+ if progress and total:
618
+ progress(
619
+ 0.9 * done / total,
620
+ f"{asset['name']}: {done / 2**20:.0f} of {total / 2**20:.0f} MB",
621
+ )
622
+ if progress:
623
+ progress(0.92, f"unpacking {asset['name']}")
624
+ unpacked = Path(tmp) / "unpacked"
625
+ unpacked.mkdir()
626
+ _extract(archive, unpacked)
627
+ folder = _exec_folder(unpacked)
628
+ if folder is None:
629
+ raise RuntimeError(f"{asset['name']}: no Starter of OpenRadioss in the archive")
630
+ record = {
631
+ "tag": release["tag"],
632
+ "name": release["name"],
633
+ "asset": asset["name"],
634
+ "url": asset["url"],
635
+ "installed": time.strftime("%Y-%m-%d %H:%M:%S"),
636
+ }
637
+ (unpacked / RELEASE_FILE).write_text(json.dumps(record, indent=1), encoding="utf-8")
638
+ if target.exists():
639
+ shutil.rmtree(target)
640
+ shutil.move(str(unpacked), str(target))
641
+ if progress:
642
+ progress(1.0, f"OpenRadioss {release['tag']} in {target}")
643
+ return find_openradioss(target)