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,768 @@
1
+ """Multiaxial high-cycle fatigue: criteria on the stress histories of a cycle.
2
+
3
+ In the high-cycle regime a material stays elastic at the scale of the cell, and whether
4
+ a point lasts is read from the cycle of its stress: an amplitude of shear, which
5
+ initiates the cracks, and a normal or hydrostatic stress, which opens them. The criteria
6
+ below judge the stresses of the points of a cell along a cycle of a loading path (its
7
+ fields at each step: :func:`path_fatigue`), or any history of stresses (``steps x ... x
8
+ 6``, Voigt components 11, 22, 33, 23, 31, 12).
9
+
10
+ *The amplitude of a multiaxial cycle.* The deviator of the stress describes a closed
11
+ path in the five-dimensional space of deviators, with the norm ``sqrt(J2) = sqrt(s : s /
12
+ 2)``. Its amplitude is the radius of the smallest hypersphere that holds the path, and
13
+ its mean the centre of that hypersphere (Papadopoulos et al. 1997; the longest chord, which
14
+ does not see the phase of the components, is not used): half the range of a
15
+ proportional cycle, the larger of ``σ_a / sqrt(3)`` and ``τ_a`` for a tension and a
16
+ torsion a quarter of a cycle apart. The hypersphere is found by Frank and Wolfe's
17
+ iteration with away steps on the dual problem (Yıldırım 2008), from the two points
18
+ farthest apart: at once for a proportional cycle.
19
+
20
+ *Criteria* (``f``: the fatigue limit in fully reversed tension or bending, ``t``: in
21
+ fully reversed torsion, ``f0``: in repeated tension, the largest stress of a cycle from
22
+ zero; each criterion gives an equivalent stress, to be compared with its limit):
23
+
24
+ * :class:`Crossland` (1956): ``sqrt(J2)_a + α σ_H,max <= β``, ``σ_H`` the hydrostatic
25
+ stress; ``α = 3 t / f - sqrt(3)``, ``β = t``.
26
+ * :class:`Sines` (1959): ``sqrt(J2)_a + α σ_H,mean <= β``; ``α = 6 t / f0 - sqrt(3)``,
27
+ ``β = t``.
28
+ * :class:`DangVan` (1973; Dang Van, Griveau & Message 1989): at each instant, Tresca's
29
+ shear of the deviator less its mean (the stress of a grain that has shaken down in
30
+ its elastic matrix) and the hydrostatic stress, ``max_t [τ(t) + α σ_H(t)] <= β``;
31
+ ``α = 3 t / f - 3 / 2``, ``β = t``.
32
+ * :class:`Findley` (1959), a critical plane: ``max_n [τ_a(n) + k σ_n,max(n)] <= λ`` over
33
+ the planes of normal ``n``, ``τ_a`` the amplitude of the shear vector of the plane
34
+ (the radius of the smallest circle that holds its path) and ``σ_n,max`` its largest
35
+ normal stress; with ``r = f / t``, ``k = (2 - r) / (2 sqrt(r - 1))`` and ``λ = t
36
+ sqrt(1 + k²)``.
37
+ * :class:`Matake` (1977): ``τ_a + k σ_n,max <= λ`` on the plane of the largest shear
38
+ amplitude; ``k = 2 t / f - 1``, ``λ = t``.
39
+
40
+ The planes are searched on a spiral of normals over a hemisphere, then around the best
41
+ of them by grids three times finer at each of four levels.
42
+ """
43
+
44
+ from __future__ import annotations
45
+
46
+ import math
47
+ from dataclasses import dataclass, field
48
+
49
+ import numpy as np
50
+ from numba import njit, prange
51
+
52
+ #: The criteria by their names in configurations
53
+ CRITERIA = ("crossland", "sines", "dang_van", "findley", "matake")
54
+ #: Normals of the first search of a critical plane (a spiral over a hemisphere)
55
+ PLANES = 400
56
+ _SQRT2 = math.sqrt(2.0)
57
+
58
+
59
+ # -- the smallest ball of a path ------------------------------------------------------------
60
+
61
+
62
+ @njit(cache=True)
63
+ def _ball(points, tol, weights, centre):
64
+ """The smallest ball that holds ``points`` (rows): its radius, to the relative
65
+ accuracy ``tol``, and its ``centre`` (written); ``weights``: a work array, one value
66
+ per point."""
67
+ n, d = points.shape
68
+ first, best = 0, -1.0
69
+ for i in range(n):
70
+ dist = 0.0
71
+ for c in range(d):
72
+ dist += (points[i, c] - points[0, c]) ** 2
73
+ if dist > best:
74
+ best, first = dist, i
75
+ second, best = first, -1.0
76
+ for i in range(n):
77
+ dist = 0.0
78
+ for c in range(d):
79
+ dist += (points[i, c] - points[first, c]) ** 2
80
+ if dist > best:
81
+ best, second = dist, i
82
+ for i in range(n):
83
+ weights[i] = 0.0
84
+ weights[first] += 0.5
85
+ weights[second] += 0.5
86
+ for c in range(d):
87
+ centre[c] = 0.5 * (points[first, c] + points[second, c])
88
+ if best <= 0.0:
89
+ return 0.0
90
+ bound = (1.0 + tol) ** 2 - 1.0
91
+ far_dist = 0.25 * best
92
+ for _ in range(100 * n + 1000):
93
+ gamma, far, near = 0.0, 0, -1
94
+ far_dist, near_dist = -1.0, math.inf
95
+ for i in range(n):
96
+ dist = 0.0
97
+ for c in range(d):
98
+ dist += (points[i, c] - centre[c]) ** 2
99
+ if dist > far_dist:
100
+ far_dist, far = dist, i
101
+ if weights[i] > 0.0:
102
+ gamma += weights[i] * dist
103
+ if dist < near_dist:
104
+ near_dist, near = dist, i
105
+ if gamma <= 0.0:
106
+ break
107
+ plus = far_dist / gamma - 1.0
108
+ minus = 1.0 - near_dist / gamma
109
+ if plus <= bound and minus <= bound:
110
+ break
111
+ if plus > minus: # towards the farthest point
112
+ step = plus / (2.0 * (1.0 + plus))
113
+ for i in range(n):
114
+ weights[i] *= 1.0 - step
115
+ weights[far] += step
116
+ for c in range(d):
117
+ centre[c] = (1.0 - step) * centre[c] + step * points[far, c]
118
+ else: # away from the nearest point of the support
119
+ limit = weights[near] / (1.0 - weights[near])
120
+ step = limit if near_dist <= 0.0 else min(limit, minus / (2.0 * (1.0 - minus)))
121
+ for i in range(n):
122
+ weights[i] *= 1.0 + step
123
+ weights[near] = 0.0 if step >= limit else weights[near] - step
124
+ for c in range(d):
125
+ centre[c] = (1.0 + step) * centre[c] - step * points[near, c]
126
+ far_dist = 0.0
127
+ for i in range(n):
128
+ dist = 0.0
129
+ for c in range(d):
130
+ dist += (points[i, c] - centre[c]) ** 2
131
+ if dist > far_dist:
132
+ far_dist = dist
133
+ return math.sqrt(far_dist)
134
+
135
+
136
+ @njit(parallel=True, cache=True)
137
+ def _amplitudes(vectors, tol, centres, radii):
138
+ """The smallest balls of the paths ``vectors`` (steps x points x d) of each point."""
139
+ steps, n, d = vectors.shape
140
+ for p in prange(n):
141
+ path = np.empty((steps, d))
142
+ for t in range(steps):
143
+ for c in range(d):
144
+ path[t, c] = vectors[t, p, c]
145
+ centre = np.empty(d)
146
+ radii[p] = _ball(path, tol, np.empty(steps), centre)
147
+ for c in range(d):
148
+ centres[p, c] = centre[c]
149
+
150
+
151
+ @njit(cache=True)
152
+ def _tresca(s):
153
+ """Tresca's shear (half the difference of the extreme principal values) of a
154
+ deviator in Voigt components."""
155
+ j2 = 0.5 * (s[0] * s[0] + s[1] * s[1] + s[2] * s[2]) + s[3] * s[3] + s[4] * s[4] + s[5] * s[5]
156
+ if j2 <= 0.0:
157
+ return 0.0
158
+ j3 = (
159
+ s[0] * s[1] * s[2]
160
+ + 2.0 * s[3] * s[4] * s[5]
161
+ - s[0] * s[3] * s[3]
162
+ - s[1] * s[4] * s[4]
163
+ - s[2] * s[5] * s[5]
164
+ )
165
+ cos3 = 1.5 * math.sqrt(3.0) * j3 / j2**1.5
166
+ cos3 = min(1.0, max(-1.0, cos3))
167
+ theta = math.acos(cos3) / 3.0 # Lode's angle, in [0, π/3]
168
+ return math.sqrt(j2) * math.sin(theta + math.pi / 3.0)
169
+
170
+
171
+ @njit(parallel=True, cache=True)
172
+ def _dang_van(deviators, hydro, means, alpha, out):
173
+ """``max_t [τ(t) + α σ_H(t)]`` of each point, ``τ`` Tresca's shear of its deviator
174
+ less its mean."""
175
+ steps, n, _ = deviators.shape
176
+ for p in prange(n):
177
+ s = np.empty(6)
178
+ best = -math.inf
179
+ for t in range(steps):
180
+ for c in range(6):
181
+ s[c] = deviators[t, p, c] - means[p, c]
182
+ value = _tresca(s) + alpha * hydro[t, p]
183
+ if value > best:
184
+ best = value
185
+ out[p] = best
186
+
187
+
188
+ # -- critical planes ---------------------------------------------------------------------------
189
+
190
+
191
+ def _spiral(count: int) -> np.ndarray:
192
+ """Normals spread over a hemisphere (a Fibonacci spiral)."""
193
+ k = np.arange(count) + 0.5
194
+ z = 1.0 - k / count
195
+ angle = math.pi * (1.0 + math.sqrt(5.0)) * k
196
+ r = np.sqrt(1.0 - z * z)
197
+ return np.ascontiguousarray(np.stack([r * np.cos(angle), r * np.sin(angle), z], axis=1))
198
+
199
+
200
+ @njit(cache=True)
201
+ def _plane(stress, normal, tol, shear, weights, centre):
202
+ """The amplitude of the shear vector and the largest normal stress of the plane of
203
+ ``normal`` along the stresses ``stress`` (steps x 6); ``shear`` (steps x 3),
204
+ ``weights`` and ``centre``: work arrays."""
205
+ steps = stress.shape[0]
206
+ nx, ny, nz = normal[0], normal[1], normal[2]
207
+ largest = -math.inf
208
+ for t in range(steps):
209
+ s = stress[t]
210
+ tx = s[0] * nx + s[5] * ny + s[4] * nz
211
+ ty = s[5] * nx + s[1] * ny + s[3] * nz
212
+ tz = s[4] * nx + s[3] * ny + s[2] * nz
213
+ sn = tx * nx + ty * ny + tz * nz
214
+ shear[t, 0] = tx - sn * nx
215
+ shear[t, 1] = ty - sn * ny
216
+ shear[t, 2] = tz - sn * nz
217
+ if sn > largest:
218
+ largest = sn
219
+ return _ball(shear, tol, weights, centre), largest
220
+
221
+
222
+ @njit(parallel=True, cache=True)
223
+ def _critical_planes(stress, normals, k, matake, tol, values, planes, shears, pressures):
224
+ """The critical plane of each point (``stress``: steps x points x 6): the value of
225
+ its criterion, its normal, its shear amplitude and its largest normal stress.
226
+ ``matake``: the plane of the largest shear amplitude (among the planes within a
227
+ thousandth of it, that of the largest value); otherwise that of the largest value
228
+ ``τ_a + k σ_n,max``."""
229
+ steps, n, _ = stress.shape
230
+ m = normals.shape[0]
231
+ spacing = math.sqrt(2.0 * math.pi / m)
232
+ starts = 6
233
+ for p in prange(n):
234
+ history = np.empty((steps, 6))
235
+ for t in range(steps):
236
+ for c in range(6):
237
+ history[t, c] = stress[t, p, c]
238
+ shear = np.empty((steps, 3))
239
+ weights = np.empty(steps)
240
+ centre = np.empty(3)
241
+ # the best normals of the spiral, for the objective of the search
242
+ top = np.full(starts, -math.inf)
243
+ index = np.zeros(starts, dtype=np.int64)
244
+ for j in range(m):
245
+ amplitude, largest = _plane(history, normals[j], tol, shear, weights, centre)
246
+ objective = amplitude if matake else amplitude + k * largest
247
+ worst = 0
248
+ for q in range(1, starts):
249
+ if top[q] < top[worst]:
250
+ worst = q
251
+ if objective > top[worst]:
252
+ top[worst], index[worst] = objective, j
253
+ found = np.empty((starts, 5)) # objective, amplitude, largest, and the normal below
254
+ found_normals = np.empty((starts, 3))
255
+ trial = np.empty(3)
256
+ e1 = np.empty(3)
257
+ e2 = np.empty(3)
258
+ for q in range(starts):
259
+ best = normals[index[q]].copy()
260
+ amplitude, largest = _plane(history, best, tol, shear, weights, centre)
261
+ objective = amplitude if matake else amplitude + k * largest
262
+ step = 0.5 * spacing
263
+ for _ in range(4):
264
+ # two tangents of the sphere at the best normal
265
+ a = 0 if abs(best[0]) < 0.9 else 1
266
+ e1[:] = 0.0
267
+ e1[a] = 1.0
268
+ dot = e1[0] * best[0] + e1[1] * best[1] + e1[2] * best[2]
269
+ for c in range(3):
270
+ e1[c] -= dot * best[c]
271
+ norm = math.sqrt(e1[0] ** 2 + e1[1] ** 2 + e1[2] ** 2)
272
+ for c in range(3):
273
+ e1[c] /= norm
274
+ e2[0] = best[1] * e1[2] - best[2] * e1[1]
275
+ e2[1] = best[2] * e1[0] - best[0] * e1[2]
276
+ e2[2] = best[0] * e1[1] - best[1] * e1[0]
277
+ origin = best.copy()
278
+ for i in range(-2, 3):
279
+ for j in range(-2, 3):
280
+ if i == 0 and j == 0:
281
+ continue
282
+ for c in range(3):
283
+ trial[c] = origin[c] + step * (i * e1[c] + j * e2[c])
284
+ norm = math.sqrt(trial[0] ** 2 + trial[1] ** 2 + trial[2] ** 2)
285
+ for c in range(3):
286
+ trial[c] /= norm
287
+ amp, big = _plane(history, trial, tol, shear, weights, centre)
288
+ value = amp if matake else amp + k * big
289
+ if value > objective:
290
+ objective, amplitude, largest = value, amp, big
291
+ best[:] = trial
292
+ step /= 3.0
293
+ found[q, 0], found[q, 1], found[q, 2] = objective, amplitude, largest
294
+ found_normals[q] = best
295
+ choice, chosen = 0, -math.inf
296
+ peak = found[:, 0].max()
297
+ for q in range(starts):
298
+ if matake and found[q, 0] < 0.999 * peak:
299
+ continue
300
+ value = found[q, 1] + k * found[q, 2]
301
+ if value > chosen:
302
+ chosen, choice = value, q
303
+ values[p] = chosen
304
+ shears[p] = found[choice, 1]
305
+ pressures[p] = found[choice, 2]
306
+ for c in range(3):
307
+ planes[p, c] = found_normals[choice, c]
308
+
309
+
310
+ # -- measures of a history ---------------------------------------------------------------------
311
+
312
+
313
+ def _history(history) -> np.ndarray:
314
+ stress = np.asarray(history, dtype=float)
315
+ if stress.ndim < 2 or stress.shape[-1] != 6 or stress.shape[0] < 2:
316
+ raise ValueError(
317
+ "fatigue: the stresses of a cycle, steps x ... x 6 (Voigt components 11, 22, "
318
+ "33, 23, 31, 12), at two steps at least"
319
+ )
320
+ if not np.all(np.isfinite(stress)):
321
+ raise ValueError("fatigue: stresses that are not finite")
322
+ return stress
323
+
324
+
325
+ def hydrostatic(history) -> np.ndarray:
326
+ """The hydrostatic stress ``tr σ / 3`` of the stresses of a history (steps x ...)."""
327
+ return _history(history)[..., :3].mean(axis=-1)
328
+
329
+
330
+ def stress_amplitude(history, tol: float = 1e-10) -> tuple[np.ndarray, np.ndarray]:
331
+ """The amplitude and the mean of the deviator of a cycle of stresses (``history``:
332
+ steps x ... x 6): ``sqrt(J2)_a``, the radius of the smallest hypersphere that holds
333
+ the path of the deviator (norm ``sqrt(s : s / 2)``; to the relative accuracy
334
+ ``tol``), and its centre, the mean deviator (... x 6)."""
335
+ stress = _history(history)
336
+ shape = stress.shape[1:-1]
337
+ flat = stress.reshape(stress.shape[0], -1, 6)
338
+ deviator = flat.copy()
339
+ deviator[..., :3] -= flat[..., :3].mean(axis=-1, keepdims=True)
340
+ # components whose Euclidean norm is sqrt(J2)
341
+ scale = np.array([1.0, 1.0, 1.0, _SQRT2, _SQRT2, _SQRT2]) / _SQRT2
342
+ vectors = np.ascontiguousarray(deviator * scale)
343
+ centres = np.zeros((flat.shape[1], 6))
344
+ radii = np.zeros(flat.shape[1])
345
+ _amplitudes(vectors, float(tol), centres, radii)
346
+ return radii.reshape(shape), (centres / scale).reshape(*shape, 6)
347
+
348
+
349
+ # -- criteria -------------------------------------------------------------------------------------
350
+
351
+
352
+ def _positive(name: str, **values) -> None:
353
+ for key, value in values.items():
354
+ if not (math.isfinite(value) and value > 0):
355
+ raise ValueError(f"{name}: a positive {key}, got {value!r}")
356
+
357
+
358
+ def _ratio(name: str, bending: float, torsion: float, low: float, high: float) -> float:
359
+ """The ratio of the torsion limit to the bending limit, within the bounds for which
360
+ the criterion has a meaning (a normal stress that lowers the limit)."""
361
+ _positive(name, bending=bending, torsion=torsion)
362
+ ratio = torsion / bending
363
+ if not low <= ratio <= high:
364
+ raise ValueError(
365
+ f"{name}: a torsion limit between {low:.3g} and {high:.3g} times the bending "
366
+ f"limit, got {ratio:.3g} times"
367
+ )
368
+ return ratio
369
+
370
+
371
+ @dataclass(frozen=True)
372
+ class Crossland:
373
+ """Crossland's criterion (see the module): ``sqrt(J2)_a + alpha σ_H,max <= beta``."""
374
+
375
+ alpha: float
376
+ beta: float
377
+ name = "crossland"
378
+
379
+ def __post_init__(self) -> None:
380
+ _positive("Crossland", beta=self.beta)
381
+ if not (math.isfinite(self.alpha) and self.alpha >= 0):
382
+ raise ValueError("Crossland: alpha of 0 or more")
383
+
384
+ @classmethod
385
+ def from_limits(cls, bending: float, torsion: float) -> Crossland:
386
+ """From the fatigue limits in fully reversed bending (or tension) and torsion."""
387
+ ratio = _ratio("Crossland", bending, torsion, 1.0 / math.sqrt(3.0), math.inf)
388
+ return cls(3.0 * ratio - math.sqrt(3.0), float(torsion))
389
+
390
+ @property
391
+ def limit(self) -> float:
392
+ return self.beta
393
+
394
+ def equivalent(self, history) -> np.ndarray:
395
+ """The equivalent stress of each point, to be compared with :attr:`limit`."""
396
+ amplitude, _ = stress_amplitude(history)
397
+ return amplitude + self.alpha * hydrostatic(history).max(axis=0)
398
+
399
+
400
+ @dataclass(frozen=True)
401
+ class Sines:
402
+ """Sines' criterion (see the module): ``sqrt(J2)_a + alpha σ_H,mean <= beta``, the
403
+ mean of the hydrostatic stress being that of its extremes over the cycle."""
404
+
405
+ alpha: float
406
+ beta: float
407
+ name = "sines"
408
+
409
+ def __post_init__(self) -> None:
410
+ _positive("Sines", beta=self.beta)
411
+ if not (math.isfinite(self.alpha) and self.alpha >= 0):
412
+ raise ValueError("Sines: alpha of 0 or more")
413
+
414
+ @classmethod
415
+ def from_limits(cls, torsion: float, repeated: float) -> Sines:
416
+ """From the fatigue limits in fully reversed torsion and in repeated tension (the
417
+ largest stress of a cycle from zero)."""
418
+ _positive("Sines", torsion=torsion, repeated=repeated)
419
+ alpha = 6.0 * torsion / repeated - math.sqrt(3.0)
420
+ if alpha < 0:
421
+ raise ValueError(
422
+ "Sines: a limit in repeated tension below 2 sqrt(3) times the torsion limit"
423
+ )
424
+ return cls(alpha, float(torsion))
425
+
426
+ @property
427
+ def limit(self) -> float:
428
+ return self.beta
429
+
430
+ def equivalent(self, history) -> np.ndarray:
431
+ amplitude, _ = stress_amplitude(history)
432
+ hydro = hydrostatic(history)
433
+ return amplitude + self.alpha * 0.5 * (hydro.max(axis=0) + hydro.min(axis=0))
434
+
435
+
436
+ @dataclass(frozen=True)
437
+ class DangVan:
438
+ """Dang Van's criterion (see the module): ``max_t [τ(t) + alpha σ_H(t)] <= beta``."""
439
+
440
+ alpha: float
441
+ beta: float
442
+ name = "dang_van"
443
+
444
+ def __post_init__(self) -> None:
445
+ _positive("DangVan", beta=self.beta)
446
+ if not (math.isfinite(self.alpha) and self.alpha >= 0):
447
+ raise ValueError("DangVan: alpha of 0 or more")
448
+
449
+ @classmethod
450
+ def from_limits(cls, bending: float, torsion: float) -> DangVan:
451
+ """From the fatigue limits in fully reversed bending (or tension) and torsion."""
452
+ ratio = _ratio("DangVan", bending, torsion, 0.5, math.inf)
453
+ return cls(3.0 * ratio - 1.5, float(torsion))
454
+
455
+ @property
456
+ def limit(self) -> float:
457
+ return self.beta
458
+
459
+ def equivalent(self, history) -> np.ndarray:
460
+ stress = _history(history)
461
+ shape = stress.shape[1:-1]
462
+ _, mean = stress_amplitude(stress)
463
+ flat = stress.reshape(stress.shape[0], -1, 6)
464
+ hydro = flat[..., :3].mean(axis=-1)
465
+ deviator = flat.copy()
466
+ deviator[..., :3] -= hydro[..., None]
467
+ out = np.zeros(flat.shape[1])
468
+ _dang_van(np.ascontiguousarray(deviator), np.ascontiguousarray(hydro),
469
+ np.ascontiguousarray(mean.reshape(-1, 6)), float(self.alpha), out) # fmt: skip
470
+ return out.reshape(shape)
471
+
472
+
473
+ class _CriticalPlane:
474
+ """The criteria of a critical plane: ``τ_a + k σ_n,max <= limit`` on a plane."""
475
+
476
+ k: float
477
+ limit: float
478
+ planes: int
479
+ _matake = False
480
+
481
+ def critical_plane(self, history) -> dict:
482
+ """The critical plane of each point: the ``equivalent`` stress of the criterion,
483
+ the ``normal`` of the plane (... x 3), its ``shear`` amplitude and its largest
484
+ ``normal_stress``."""
485
+ stress = _history(history)
486
+ shape = stress.shape[1:-1]
487
+ flat = np.ascontiguousarray(stress.reshape(stress.shape[0], -1, 6))
488
+ n = flat.shape[1]
489
+ values, shears, pressures = np.zeros(n), np.zeros(n), np.zeros(n)
490
+ normals = np.zeros((n, 3))
491
+ _critical_planes(flat, _spiral(self.planes), float(self.k), self._matake, 1e-7,
492
+ values, normals, shears, pressures) # fmt: skip
493
+ return {
494
+ "equivalent": values.reshape(shape),
495
+ "normal": normals.reshape(*shape, 3),
496
+ "shear": shears.reshape(shape),
497
+ "normal_stress": pressures.reshape(shape),
498
+ }
499
+
500
+ def equivalent(self, history) -> np.ndarray:
501
+ return self.critical_plane(history)["equivalent"]
502
+
503
+ def _check(self, name: str) -> None:
504
+ _positive(name, limit=self.limit)
505
+ if not (math.isfinite(self.k) and self.k >= 0):
506
+ raise ValueError(f"{name}: k of 0 or more")
507
+ if self.planes < 20:
508
+ raise ValueError(f"{name}: 20 planes at least for the first search")
509
+
510
+
511
+ @dataclass(frozen=True)
512
+ class Findley(_CriticalPlane):
513
+ """Findley's criterion (see the module): ``max_n [τ_a(n) + k σ_n,max(n)] <= limit``;
514
+ ``planes``: the normals of the first search."""
515
+
516
+ k: float
517
+ limit: float
518
+ planes: int = PLANES
519
+ name = "findley"
520
+
521
+ def __post_init__(self) -> None:
522
+ self._check("Findley")
523
+
524
+ @classmethod
525
+ def from_limits(cls, bending: float, torsion: float, planes: int = PLANES) -> Findley:
526
+ """From the fatigue limits in fully reversed bending (or tension) and torsion."""
527
+ ratio = 1.0 / _ratio("Findley", bending, torsion, 0.5, 1.0 - 1e-12)
528
+ k = (2.0 - ratio) / (2.0 * math.sqrt(ratio - 1.0))
529
+ return cls(k, float(torsion) * math.sqrt(1.0 + k * k), planes)
530
+
531
+
532
+ @dataclass(frozen=True)
533
+ class Matake(_CriticalPlane):
534
+ """Matake's criterion (see the module): ``τ_a + k σ_n,max <= limit`` on the plane of
535
+ the largest shear amplitude; ``planes``: the normals of the first search."""
536
+
537
+ k: float
538
+ limit: float
539
+ planes: int = PLANES
540
+ name = "matake"
541
+ _matake = True
542
+
543
+ def __post_init__(self) -> None:
544
+ self._check("Matake")
545
+
546
+ @classmethod
547
+ def from_limits(cls, bending: float, torsion: float, planes: int = PLANES) -> Matake:
548
+ """From the fatigue limits in fully reversed bending (or tension) and torsion."""
549
+ ratio = _ratio("Matake", bending, torsion, 0.5, math.inf)
550
+ return cls(2.0 * ratio - 1.0, float(torsion), planes)
551
+
552
+
553
+ def criterion_from_config(spec):
554
+ """A criterion from a mapping: its ``criterion`` (one of :data:`CRITERIA`) and either
555
+ its fatigue limits (``bending`` and ``torsion``; ``torsion`` and ``repeated`` for
556
+ Sines) or its coefficients (``alpha`` and ``beta``; ``k`` and ``limit`` for the
557
+ critical planes, with their ``planes``)."""
558
+ if not isinstance(spec, dict):
559
+ raise ValueError("fatigue: a mapping of a criterion and its limits")
560
+ spec = dict(spec)
561
+ name = spec.pop("criterion", None)
562
+ classes = {"crossland": Crossland, "sines": Sines, "dang_van": DangVan,
563
+ "findley": Findley, "matake": Matake} # fmt: skip
564
+ if name not in classes:
565
+ raise ValueError(f"fatigue: the criterion is one of {list(CRITERIA)}, got {name!r}")
566
+ cls = classes[name]
567
+ plane = name in ("findley", "matake")
568
+ coefficients = ("k", "limit") if plane else ("alpha", "beta")
569
+ limits = ("torsion", "repeated") if name == "sines" else ("bending", "torsion")
570
+ allowed = set(coefficients) | set(limits) | ({"planes"} if plane else set())
571
+ unknown = sorted(set(spec) - allowed)
572
+ if unknown:
573
+ raise ValueError(
574
+ f"fatigue: unknown parameters {unknown} of the criterion {name!r}; use "
575
+ f"{list(limits)} or {list(coefficients)}" + (" and 'planes'" if plane else "")
576
+ )
577
+ try:
578
+ values = {key: float(value) for key, value in spec.items() if key != "planes"}
579
+ extra = {"planes": int(spec["planes"])} if "planes" in spec else {}
580
+ except (TypeError, ValueError):
581
+ raise ValueError(f"fatigue: the parameters of the criterion {name!r} are numbers") from None
582
+ if all(key in values for key in coefficients) and not any(key in values for key in limits):
583
+ return cls(*(values[key] for key in coefficients), **extra)
584
+ if all(key in values for key in limits) and not any(key in values for key in coefficients):
585
+ return cls.from_limits(*(values[key] for key in limits), **extra)
586
+ raise ValueError(
587
+ f"fatigue: the criterion {name!r} takes its limits {list(limits)} or its "
588
+ f"coefficients {list(coefficients)}"
589
+ )
590
+
591
+
592
+ # -- the fields of a loading path -----------------------------------------------------------------
593
+
594
+
595
+ @dataclass
596
+ class FatigueResult:
597
+ """The fatigue of the points of a cell along a cycle: the ``equivalent`` stress of
598
+ the criterion of each point and its ``utilization``, the equivalent stress over the
599
+ limit (1: at the fatigue limit; NaN where no criterion applies), the ``amplitude``
600
+ ``sqrt(J2)_a`` of the deviator, the largest and the mean hydrostatic stress
601
+ (``hydrostatic_max``, ``hydrostatic_mean``), the ``times`` of the cycle, the
602
+ ``weights`` of the points (volumes, when their support gives them) and their
603
+ ``support`` (mesh or image)."""
604
+
605
+ equivalent: np.ndarray
606
+ utilization: np.ndarray
607
+ amplitude: np.ndarray
608
+ hydrostatic_max: np.ndarray
609
+ hydrostatic_mean: np.ndarray
610
+ times: np.ndarray
611
+ weights: np.ndarray | None = field(default=None, repr=False)
612
+ support: object | None = field(default=None, repr=False)
613
+
614
+ @property
615
+ def largest(self) -> float:
616
+ """The largest utilization of the cell (NaN when no point is judged)."""
617
+ judged = self.utilization[np.isfinite(self.utilization)]
618
+ return float(judged.max()) if judged.size else float("nan")
619
+
620
+ @property
621
+ def safety(self) -> float:
622
+ """The factor by which the stresses of the cycle may be multiplied before a
623
+ point reaches its limit, for a loading that grows in proportion: the inverse of
624
+ the largest utilization."""
625
+ largest = self.largest
626
+ return 1.0 / largest if largest > 0 else float("inf")
627
+
628
+ def fraction(self, level: float = 1.0) -> float:
629
+ """The share (of the volume, with ``weights``; of the points otherwise) of the
630
+ points judged whose utilization is above ``level``."""
631
+ judged = np.isfinite(self.utilization)
632
+ if not judged.any():
633
+ return float("nan")
634
+ weights = np.ones(self.utilization.shape) if self.weights is None else self.weights
635
+ above = judged & (self.utilization > level)
636
+ return float(weights[above].sum() / weights[judged].sum())
637
+
638
+ def fields(self) -> dict:
639
+ """The fields of the points, by name (for the writers of fields)."""
640
+ return {
641
+ "fatigue_utilization": self.utilization,
642
+ "fatigue_equivalent": self.equivalent,
643
+ "fatigue_amplitude": self.amplitude,
644
+ "fatigue_hydrostatic_max": self.hydrostatic_max,
645
+ }
646
+
647
+ def components(self) -> dict:
648
+ """The scalar results: the largest utilization, the safety factor and the share
649
+ of the points beyond their limit."""
650
+ return {"utilization": self.largest, "safety": self.safety, "beyond": self.fraction()}
651
+
652
+
653
+ def fatigue(history, criterion, *, phases=None, weights=None, times=None, support=None):
654
+ """The fatigue of points along a cycle of stresses (``history``: steps x ... x 6):
655
+ a :class:`FatigueResult`. ``criterion``: one criterion for all the points, or a
656
+ mapping of the phases to their criteria (or to mappings of them:
657
+ :func:`criterion_from_config`), with ``phases`` the phase of each point; the points
658
+ of the other phases are not judged."""
659
+ stress = np.asarray(history, dtype=float)
660
+ if stress.ndim >= 2 and stress.shape[-1] == 6 and np.isnan(stress).any():
661
+ return _fatigue_of_the_solid(stress, criterion, phases, weights, times, support)
662
+ stress = _history(stress)
663
+ shape = stress.shape[1:-1]
664
+ amplitude, _ = stress_amplitude(stress)
665
+ hydro = hydrostatic(stress)
666
+ equivalent = np.full(shape, np.nan)
667
+ utilization = np.full(shape, np.nan)
668
+ if isinstance(criterion, dict) and "criterion" not in criterion:
669
+ if phases is None:
670
+ raise ValueError("fatigue: criteria by phase need the phase of each point (phases)")
671
+ labels = np.asarray(phases)
672
+ if labels.shape != shape:
673
+ raise ValueError(f"fatigue: one phase per point {shape}, got {labels.shape}")
674
+ groups = [(labels == phase, law) for phase, law in criterion.items()]
675
+ else:
676
+ groups = [(np.ones(shape, dtype=bool), criterion)]
677
+ for mask, law in groups:
678
+ law = criterion_from_config(law) if isinstance(law, dict) else law
679
+ if not hasattr(law, "equivalent") or not hasattr(law, "limit"):
680
+ raise TypeError("fatigue: a criterion (Crossland, Sines, DangVan, Findley, Matake)")
681
+ if not mask.any():
682
+ continue
683
+ equivalent[mask] = law.equivalent(stress[:, mask])
684
+ utilization[mask] = equivalent[mask] / law.limit
685
+ if weights is not None:
686
+ weights = np.asarray(weights, dtype=float)
687
+ if weights.shape != shape:
688
+ raise ValueError(f"fatigue: one weight per point {shape}, got {weights.shape}")
689
+ count = stress.shape[0]
690
+ return FatigueResult(
691
+ equivalent=equivalent,
692
+ utilization=utilization,
693
+ amplitude=amplitude,
694
+ hydrostatic_max=hydro.max(axis=0),
695
+ hydrostatic_mean=0.5 * (hydro.max(axis=0) + hydro.min(axis=0)),
696
+ times=np.arange(count, dtype=float) if times is None else np.asarray(times, dtype=float),
697
+ weights=weights,
698
+ support=support,
699
+ )
700
+
701
+
702
+ def _fatigue_of_the_solid(stress, criterion, phases, weights, times, support) -> FatigueResult:
703
+ """:func:`fatigue` for points some of which have no stress (NaN: the voxels of the
704
+ pores of an image): the others are judged, and these are left out of every field."""
705
+ shape = stress.shape[1:-1]
706
+ solid = ~np.isnan(stress).any(axis=(0, -1))
707
+ if not solid.any():
708
+ raise ValueError("fatigue: stresses that are not finite")
709
+ labels = None if phases is None else np.asarray(phases)
710
+ if labels is not None and labels.shape != shape:
711
+ raise ValueError(f"fatigue: one phase per point {shape}, got {labels.shape}")
712
+ if weights is not None and np.shape(weights) != shape:
713
+ raise ValueError(f"fatigue: one weight per point {shape}, got {np.shape(weights)}")
714
+ part = fatigue(
715
+ stress[:, solid],
716
+ criterion,
717
+ phases=None if labels is None else labels[solid],
718
+ times=times,
719
+ )
720
+
721
+ def whole(values):
722
+ out = np.full(shape, np.nan)
723
+ out[solid] = values
724
+ return out
725
+
726
+ return FatigueResult(
727
+ equivalent=whole(part.equivalent),
728
+ utilization=whole(part.utilization),
729
+ amplitude=whole(part.amplitude),
730
+ hydrostatic_max=whole(part.hydrostatic_max),
731
+ hydrostatic_mean=whole(part.hydrostatic_mean),
732
+ times=part.times,
733
+ weights=None if weights is None else np.asarray(weights, dtype=float),
734
+ support=support,
735
+ )
736
+
737
+
738
+ def path_fatigue(result, criterion, *, cycle=None) -> FatigueResult:
739
+ """The fatigue of the points of a cell along a cycle of a loading path: ``result``, a
740
+ :class:`~morphogen.homogenization.paths.PathResult` that kept its fields at the
741
+ steps of the cycle (``fields="steps"``); ``criterion``: as for :func:`fatigue`, the
742
+ phases being those of the support of the fields; ``cycle``: the times of its start
743
+ and of its end (by default the whole path). The stresses are those of the fields
744
+ (Cauchy's in finite strains)."""
745
+ times = np.array(sorted(result.fields))
746
+ if cycle is not None:
747
+ start, end = (float(v) for v in cycle)
748
+ if not start < end:
749
+ raise ValueError("fatigue: a cycle from a time to a later one")
750
+ slack = 1e-9 * max(abs(start), abs(end), 1.0)
751
+ times = times[(times >= start - slack) & (times <= end + slack)]
752
+ times = np.array([t for t in times if "stress" in result.fields[t]])
753
+ if times.size < 2:
754
+ raise ValueError(
755
+ "fatigue: the stress fields of two steps of the cycle at least (run the path "
756
+ "with fields='steps')"
757
+ )
758
+ history = np.stack([np.asarray(result.fields[t]["stress"], dtype=float) for t in times])
759
+ support = result.support
760
+ phases = weights = None
761
+ if support is not None and hasattr(support, "volumes"): # a mesh
762
+ phases, weights = np.asarray(support.phase), np.abs(support.volumes())
763
+ elif support is not None and hasattr(support, "data"): # an image
764
+ phases = np.asarray(support.data)
765
+ if phases is not None and phases.shape != history.shape[1:-1]:
766
+ phases = weights = None
767
+ return fatigue(history, criterion, phases=phases, weights=weights, times=times,
768
+ support=support) # fmt: skip