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,1120 @@
1
+ """Porous elasto-(visco)plasticity: the ``porous_plastic`` behaviours of Z-mat (Besson,
2
+ Cailletaud, Chaboche & Forest, *Non-linear mechanics of materials*, 2010, chap. 7), for the
3
+ ductile damage of metals (Gurson-Tvergaard-Needleman, Rousselier) and the compaction of
4
+ powders and foams (the elliptic criterion of Abouaf, Green and Shima & Oyane).
5
+
6
+ A porous material has a matrix, the "real material", whose flow stress ``σ*`` (the matrix
7
+ stress) is defined from the macroscopic stress ``σ`` and the porosity ``f`` by a potential
8
+ ``φ(σ, σ*, f) = 0``, an isotropic function of the mean stress ``Σm = tr σ / 3`` and of the
9
+ von Mises stress ``Σeq = sqrt(3/2 s : s)``:
10
+
11
+ * Gurson-Tvergaard-Needleman: ``(Σeq / σ*)² + 2 q1 f* cosh(3 q2 Σm / (2 σ*)) - 1 - q3 f*² =
12
+ 0`` (Gurson 1977; Tvergaard 1981; Tvergaard & Needleman 1984), the effective porosity
13
+ ``f*`` a piecewise linear function of ``f`` (``f`` itself by default; the coalescence of
14
+ Tvergaard & Needleman, ``f* = fc + (1/q1 - fc) (f - fc) / (fF - fc)`` beyond ``fc``),
15
+ kept below ``0.995 / q1`` (the surface vanishes at ``1 / q1``);
16
+ * Rousselier: ``σ* = Σeq / (1 - f) + D σ1 f exp(q Σm / ((1 - f) σ1))`` (Rousselier 1987,
17
+ ``q = 1``; the modified one of Z-mat, ``q2``), which grows the voids in pure shear;
18
+ * elliptic: ``σ*² = C(f) Σeq² + F(f) I1²`` (``I1 = 3 Σm``: Abouaf 1985, Abouaf, Chenot,
19
+ Raisson & Bauduin 1988 for the hot compaction of metal powders; Green 1972; Shima &
20
+ Oyane 1976; foams), ``C`` and ``F`` constants or piecewise linear functions of ``f``
21
+ (``C = 1``, ``F = 0`` for the dense material).
22
+
23
+ At ``f = 0`` the three are von Mises. The overstress ``σ* - R(p)`` drives the flow of the
24
+ matrix: rate-independent plasticity ``σ* = R(p)``, or Norton's viscoplasticity ``ṗ = <(σ*
25
+ - R) / K>^N``, with the isotropic hardening ``R(p) = R0 + H p + Σ Q_i (1 - exp(-b_i p))``
26
+ of the matrix equivalent plastic strain ``p``. The plastic strain is normal to the
27
+ potential, ``ε̇p = Λ̇ ∂σ*/∂σ``, and its rate follows from the equivalence of the plastic
28
+ work of the matrix and of the porous material, ``(1 - f) σ* ṗ = σ : ε̇p`` (``Λ̇ = (1 - f)
29
+ ṗ`` for the potentials homogeneous of degree 1 in ``σ``, GTN and elliptic). The porosity
30
+ is the sum of the growth porosity, by the conservation of the mass of the incompressible
31
+ matrix, ``ḟg = (1 - f) tr ε̇p``, and of the nucleated one, ``ḟn = A(p) ṗ``: a constant
32
+ ``A``, Chu & Needleman's (1980) Gaussian ``A = fN / (sN sqrt(2π)) exp(-((p - εN) / sN)² /
33
+ 2)`` or an exponential ``A = B exp(-p / ε0)``, none below the plastic strain ``p_n``.
34
+
35
+ *Kinematic hardening* (Besson & Guillemer-Neel 2003, the extension of the Gurson and Green
36
+ models; Besson, Cailletaud, Chaboche & Forest 2010, chap. 7), for the potentials
37
+ homogeneous of degree 1 in the stress, GTN and elliptic: the potential is that of the
38
+ relative stress ``σ - X``, ``X = Σ X_i``, the Armstrong-Frederick terms ``Ẋ_i = 2/3 C_i
39
+ ε̇p - D_i X_i ṗ`` (``D_i = 0``: Prager) of the plastic strain normal to the potential at ``σ
40
+ - X``, and the work equivalence is that of the relative stress, ``(1 - f) σ* ṗ = (σ - X) :
41
+ ε̇p`` (``Λ̇ = (1 - f) ṗ``). The plastic strain has the volume change of the growth of the
42
+ voids: the backstresses have a hydrostatic part, ``tr Ẋ_i = 2/3 C_i tr ε̇p - D_i tr X_i ṗ``,
43
+ and the mean stress of the potential is ``Σm - tr X / 3``: the voids grown in hydrostatic
44
+ tension move the surface towards the tensile mean stresses (a hydrostatic Bauschinger
45
+ effect: the reversed, compressive mean stress yields earlier), as the deviatoric part moves
46
+ it along the deviator like that of von Mises points. At ``f = 0`` without nucleation the
47
+ model is von Mises's with the same kinematic terms. Rousselier's potential, whose
48
+ exponential term has the constant stress ``σ1`` (not homogeneous), takes none.
49
+
50
+ *Integration* (backward Euler, Aravas 1987): the trial stress ``σ_tr`` of the elastic
51
+ predictor (isotropic elasticity, bulk modulus ``K_b``, shear modulus ``μ``) is corrected
52
+ along the invariants, ``Σm = Σm_tr - K_b Δεv`` and ``Σeq = Σeq_tr - 3 μ Δεq`` (the
53
+ deviatoric direction ``n = 3/2 s_tr / Σeq_tr`` of the trial stress, isotropic potentials),
54
+ with ``Δεp = Δεv / 3 I + Δεq n``. Four unknowns, ``Δεv``, ``Δεq``, ``Δp`` (or the viscous
55
+ stress over ``K``, better conditioned near no flow) and ``f``, solve four equations: the
56
+ normality ``Δεv ∂σ*/∂Σeq - Δεq ∂σ*/∂Σm = 0``, the flow rule, the equivalence of the plastic
57
+ works and the evolution of the porosity, by Newton's method with their analytical
58
+ Jacobian (the first and second derivatives of ``σ*``: by the implicit function theorem
59
+ on the potential of GTN, in closed form for the others) and a line search, the matrix
60
+ stress of GTN by its own scalar Newton iteration (bracketed from that of the current
61
+ point at the points of the line search: a few evaluations instead of a dozen).
62
+ With backstresses (``X_i = θ_i (X_i,n + 2/3 C_i Δεp)``, ``θ_i = 1 / (1 + D_i Δp)``: the
63
+ implicit recovery) the relative stress is the relative trial stress ``σ_tr - Σ θ_i X_i,n``
64
+ (its deviator ``ξ*``, von Mises stress ``J*`` and mean stress ``m*``) corrected along its
65
+ invariants with the moduli ``3 μ + c`` and ``K_b + 2 c / 9`` (``c = Σ θ_i C_i``): ``Σeq =
66
+ J* - (3 μ + c) Δεq``, ``Σm = m* - (K_b + 2 c / 9) Δεv``, its deviator in the direction ``n
67
+ = 3/2 ξ* / J*``, which ``Δp`` alone sets: the same four unknowns and equations, whose
68
+ invariants depend on ``Δp`` too (``dJ*/dΔp = n : Σ D_i θ_i² X_i,n``, ``dm*/dΔp = Σ D_i
69
+ θ_i² tr X_i,n / 3``, ``dc/dΔp = -Σ D_i θ_i² C_i``) in the analytical Jacobian.
70
+ At the vertex of Rousselier's surface (``Σeq = 0`` under a hydrostatic stress, where its
71
+ deviatoric gradient jumps) the normality gives way to ``Σeq = 0``. The
72
+ consistent tangent comes from the sensitivity of the solution to the trial invariants
73
+ (``dσ = dΣm I + 2/3 dΣeq n + 2 μ Σeq / Σeq_tr (dε_dev - 2/3 (n : dε_dev) n)``), not
74
+ symmetric (the porosity grows with the volumetric flow: 10⁻⁵ to 2·10⁻² of its norm),
75
+ symmetrized for the conjugate gradient solvers like that of the von Mises points or kept
76
+ whole for GMRES (``sym``); with backstresses
77
+ the trial invariant of the deviator is ``J*`` (``dJ* = n : ds_tr``, ``n`` that of ``ξ*``),
78
+ the deviator ``s = s_tr - 2 μ Δεq n`` and the direction turns with ``Δp``: ``dn = 3 / (2
79
+ J*) (dξ* - 2/3 (n : dξ*) n)``, ``dξ* = ds_tr + Σ D_i θ_i² X_i,n dΔp``.
80
+
81
+ In finite strains (:mod:`morphogen.homogenization.finite`) the same update works in the
82
+ space of the logarithmic strain, where the plastic volume change is ``ln J_p``: the
83
+ growth of the porosity is that of the volume of the pores of an incompressible matrix.
84
+
85
+ The kernels of the CPU have their CUDA port for the FFT solvers on the GPU
86
+ (``behaviours.cu``, compared with them point by point).
87
+
88
+ Internal variables of a point: the plastic strain (6, tensor components), ``p``, the
89
+ growth of the porosity from its initial value ``f0``, the nucleated porosity, the
90
+ matrix stress (an output), ``f = f0 + state[7] + state[8]``, then the backstresses (6 each,
91
+ tensor components: :func:`state_width`).
92
+ """
93
+
94
+ from __future__ import annotations
95
+
96
+ import itertools
97
+ import math
98
+ from dataclasses import dataclass
99
+
100
+ import numpy as np
101
+ from numba import njit
102
+
103
+ from morphogen.homogenization.tensors import symmetrize
104
+
105
+ #: Criteria of the porous potentials
106
+ GURSON = 0
107
+ ROUSSELIER = 1
108
+ ELLIPTIC = 2
109
+ CRITERIA = {"gurson": GURSON, "rousselier": ROUSSELIER, "elliptic": ELLIPTIC}
110
+ #: Nucleation of porosity
111
+ NUCLEATION = {"none": 0, "constant": 1, "gaussian": 2, "exponential": 3}
112
+ #: Points of the tables of the coefficients depending on the porosity
113
+ MAX_TABLE = 4
114
+ MAX_ISOTROPIC = 3
115
+ #: Most kinematic terms (C, D) of the matrix, as for the von Mises points
116
+ MAX_KINEMATIC = 4
117
+ #: Layout of a row of parameters (the first twelve as those of the von Mises points)
118
+ P_CRITERION = 12
119
+ P_F0 = 13
120
+ P_Q1, P_Q2, P_Q3 = 14, 15, 16
121
+ P_SIGMA1, P_D, P_QR = 17, 18, 19
122
+ P_NUCLEATION = 20 # type, then three coefficients and the threshold of p
123
+ P_FSTAR = 25 # count, then (f, f*) pairs
124
+ P_C = P_FSTAR + 1 + 2 * MAX_TABLE
125
+ P_F = P_C + 1 + 2 * MAX_TABLE
126
+ P_CAP = P_F + 1 + 2 * MAX_TABLE
127
+ P_NKIN = P_CAP + 1 # the number of kinematic terms, then their (C, D) pairs
128
+ P_KIN = P_NKIN + 1
129
+ N_POROUS = P_KIN + 2 * MAX_KINEMATIC
130
+ #: Internal variables: plastic strain (6), p, growth of the porosity, nucleated porosity,
131
+ #: matrix stress, then the backstresses (6 each); the width without them
132
+ STATE_P = 6
133
+ STATE_FG = 7
134
+ STATE_FN = 8
135
+ STATE_SSTAR = 9
136
+ STATE_BACK = 10
137
+ POROUS_WIDTH = STATE_BACK
138
+
139
+
140
+ def state_width(n_kinematic: int = 0) -> int:
141
+ """Number of internal variables of a porous point with ``n_kinematic`` backstresses."""
142
+ return STATE_BACK + 6 * int(n_kinematic)
143
+
144
+
145
+ def _table(value, name: str) -> tuple[tuple[float, float], ...]:
146
+ """A coefficient depending on the porosity: a number, or pairs ``(f, value)`` (a
147
+ piecewise linear function, extrapolated linearly), at most :data:`MAX_TABLE`."""
148
+ if value is None:
149
+ return ()
150
+ if np.ndim(value) == 0:
151
+ return ((0.0, float(value)),)
152
+ pairs = [tuple(map(float, item)) for item in value]
153
+ if not 1 <= len(pairs) <= MAX_TABLE or any(len(p) != 2 for p in pairs):
154
+ raise ValueError(f"{name}: a number or 1 to {MAX_TABLE} pairs (porosity, value)")
155
+ pairs.sort()
156
+ if any(b[0] <= a[0] for a, b in itertools.pairwise(pairs)):
157
+ raise ValueError(f"{name}: increasing porosities")
158
+ return tuple(pairs)
159
+
160
+
161
+ def _pairs(value, name: str, first: str = "Q", second: str = "b") -> tuple:
162
+ from morphogen.homogenization.behaviours import _pairs as pairs
163
+
164
+ return pairs(value, name, first, second)
165
+
166
+
167
+ @dataclass(frozen=True)
168
+ class PorousPlasticity:
169
+ """Porous elasto-(visco)plasticity of an isotropic elastic material (see the module).
170
+
171
+ ``criterion``: ``"gurson"`` (GTN: ``q1``, ``q2``, ``q3``, by default ``q1²``, the
172
+ effective porosity ``effective`` as pairs ``(f, f*)``, or the coalescence ``fc``,
173
+ ``fF``), ``"rousselier"`` (``sigma1``, ``D``, the factor ``q2`` of the mean stress of
174
+ the modified criterion) or ``"elliptic"`` (``C``, ``F``: numbers or pairs ``(f,
175
+ value)``). ``porosity``: the initial porosity ``f0``. The matrix: ``yield_stress`` (R0),
176
+ ``hardening`` (H), ``isotropic`` (pairs Q, b), Norton's ``viscosity`` (K) and
177
+ ``exponent`` (N) or rate-independent plasticity. ``nucleation``: ``None``, or a
178
+ mapping with the ``type`` (``constant``: ``A``; ``gaussian``: ``fN``, ``eN``, ``sN``;
179
+ ``exponential``: ``B``, ``e0``) and the threshold ``yield`` of ``p``. ``kinematic``:
180
+ the Armstrong-Frederick terms (pairs C, D; ``D = 0``: Prager) of the backstresses of
181
+ the criteria ``gurson`` and ``elliptic``.
182
+ """
183
+
184
+ criterion: str
185
+ yield_stress: float
186
+ porosity: float = 0.0
187
+ hardening: float = 0.0
188
+ isotropic: tuple[tuple[float, float], ...] = ()
189
+ viscosity: float | None = None
190
+ exponent: float | None = None
191
+ q1: float = 1.5
192
+ q2: float = 1.0
193
+ q3: float | None = None
194
+ effective: tuple = ()
195
+ fc: float | None = None
196
+ fF: float | None = None
197
+ sigma1: float | None = None
198
+ D: float | None = None
199
+ C: tuple | float = 1.0
200
+ F: tuple | float = 0.0
201
+ nucleation: dict | None = None
202
+ kinematic: tuple[tuple[float, float], ...] = ()
203
+
204
+ def __post_init__(self) -> None:
205
+ crit = str(self.criterion).lower()
206
+ if crit not in CRITERIA:
207
+ raise ValueError(f"porous plasticity: criterion {self.criterion!r}: {list(CRITERIA)}")
208
+ object.__setattr__(self, "criterion", crit)
209
+ for name in ("yield_stress", "porosity", "hardening"):
210
+ v = float(getattr(self, name))
211
+ if not (math.isfinite(v) and v >= 0.0):
212
+ raise ValueError(f"porous plasticity: {name} must be non-negative")
213
+ object.__setattr__(self, name, v)
214
+ if self.porosity >= 1.0:
215
+ raise ValueError("porous plasticity: an initial porosity below 1")
216
+ iso = _pairs(self.isotropic, "isotropic")
217
+ if len(iso) > MAX_ISOTROPIC or any(q < 0 or not b > 0 for q, b in iso):
218
+ raise ValueError(f"isotropic: at most {MAX_ISOTROPIC} terms (Q >= 0, b > 0)")
219
+ object.__setattr__(self, "isotropic", iso)
220
+ kin = _pairs(self.kinematic, "kinematic", "C", "D")
221
+ if len(kin) > MAX_KINEMATIC:
222
+ raise ValueError(f"kinematic: at most {MAX_KINEMATIC} terms")
223
+ if not all(math.isfinite(c) and math.isfinite(d) and c >= 0 and d >= 0 for c, d in kin):
224
+ raise ValueError("kinematic: terms (C, D) with C >= 0 and D >= 0")
225
+ if kin and crit == "rousselier":
226
+ raise ValueError(
227
+ "porous plasticity: kinematic hardening with the criteria gurson and elliptic "
228
+ "(Besson & Guillemer-Neel's extension of the potentials homogeneous of degree "
229
+ "1 in the stress; Rousselier's, with the constant sigma1 of its exponential "
230
+ "term, is not)"
231
+ )
232
+ object.__setattr__(self, "kinematic", kin)
233
+ if (self.viscosity is None) != (self.exponent is None):
234
+ raise ValueError("norton: give both K and n (or neither: rate-independent)")
235
+ if self.viscosity is not None:
236
+ k, n = float(self.viscosity), float(self.exponent)
237
+ if not (k > 0 and n >= 1.0 and math.isfinite(k) and math.isfinite(n)):
238
+ raise ValueError("norton: K > 0 and n >= 1")
239
+ object.__setattr__(self, "viscosity", k)
240
+ object.__setattr__(self, "exponent", n)
241
+ if crit == "gurson":
242
+ q1, q2 = float(self.q1), float(self.q2)
243
+ q3 = q1 * q1 if self.q3 is None else float(self.q3)
244
+ if not (q1 > 0 and q2 > 0 and q3 > 0):
245
+ raise ValueError("gurson: q1, q2, q3 > 0")
246
+ object.__setattr__(self, "q1", q1)
247
+ object.__setattr__(self, "q2", q2)
248
+ object.__setattr__(self, "q3", q3)
249
+ effective = _table(self.effective or None, "gurson.effective")
250
+ if self.fc is not None or self.fF is not None:
251
+ if effective:
252
+ raise ValueError("gurson: give the effective porosity or fc and fF, not both")
253
+ fc, ff = float(self.fc), float(self.fF)
254
+ if not 0.0 < fc < ff:
255
+ raise ValueError("gurson: 0 < fc < fF")
256
+ effective = ((0.0, 0.0), (fc, fc), (ff, 1.0 / q1))
257
+ object.__setattr__(self, "effective", effective)
258
+ elif crit == "rousselier":
259
+ if self.sigma1 is None or self.D is None:
260
+ raise ValueError("rousselier: sigma1 and D")
261
+ s1, d = float(self.sigma1), float(self.D)
262
+ if not (s1 > 0 and d >= 0):
263
+ raise ValueError("rousselier: sigma1 > 0 and D >= 0")
264
+ object.__setattr__(self, "sigma1", s1)
265
+ object.__setattr__(self, "D", d)
266
+ object.__setattr__(self, "q2", float(self.q2))
267
+ else:
268
+ object.__setattr__(self, "C", _table(self.C, "elliptic.C"))
269
+ object.__setattr__(self, "F", _table(self.F, "elliptic.F"))
270
+ if any(v < 0 for _, v in self.C + self.F):
271
+ raise ValueError("elliptic: C and F >= 0")
272
+ if self.nucleation is not None:
273
+ spec = dict(self.nucleation)
274
+ kind = str(spec.pop("type", "")).lower()
275
+ needed = {"constant": ("A",), "gaussian": ("fN", "eN", "sN"),
276
+ "exponential": ("B", "e0")} # fmt: skip
277
+ if kind not in needed:
278
+ raise ValueError(f"nucleation: type {list(needed)}")
279
+ threshold = float(spec.pop("yield", 0.0))
280
+ unknown = sorted(set(spec) - set(needed[kind]))
281
+ if unknown or any(k not in spec for k in needed[kind]):
282
+ raise ValueError(f"nucleation {kind}: the coefficients {list(needed[kind])}")
283
+ values = {k: float(spec[k]) for k in needed[kind]}
284
+ if kind == "gaussian" and not values["sN"] > 0:
285
+ raise ValueError("nucleation gaussian: sN > 0")
286
+ if kind == "exponential" and not values["e0"] > 0:
287
+ raise ValueError("nucleation exponential: e0 > 0")
288
+ object.__setattr__(self, "nucleation", {"type": kind, "yield": threshold, **values})
289
+
290
+ @property
291
+ def viscous(self) -> bool:
292
+ return self.viscosity is not None
293
+
294
+ def params(self, lam: float, mu: float) -> np.ndarray:
295
+ """Row of parameters of the integration kernels (see the module)."""
296
+ row = np.zeros(N_POROUS)
297
+ row[:4] = (lam, mu, self.yield_stress, self.hardening)
298
+ if self.viscous:
299
+ row[4:6] = (self.viscosity, self.exponent)
300
+ for i, (q, b) in enumerate(self.isotropic):
301
+ row[6 + 2 * i : 8 + 2 * i] = (q, b)
302
+ row[P_CRITERION] = CRITERIA[self.criterion]
303
+ row[P_F0] = self.porosity
304
+ row[P_Q1], row[P_Q2], row[P_Q3] = self.q1, self.q2, self.q3 or 0.0
305
+ if self.criterion == "rousselier":
306
+ row[P_SIGMA1], row[P_D], row[P_QR] = self.sigma1, self.D, self.q2
307
+ if self.nucleation is not None:
308
+ nuc = self.nucleation
309
+ kind = nuc["type"]
310
+ row[P_NUCLEATION] = NUCLEATION[kind]
311
+ names = {"constant": ("A",), "gaussian": ("fN", "eN", "sN"), "exponential": ("B", "e0")}
312
+ for k, name in enumerate(names[kind]):
313
+ row[P_NUCLEATION + 1 + k] = nuc[name]
314
+ row[P_NUCLEATION + 4] = nuc["yield"]
315
+ tables = [(P_FSTAR, self.effective if self.criterion == "gurson" else ())]
316
+ if self.criterion == "elliptic":
317
+ tables += [(P_C, self.C), (P_F, self.F)]
318
+ for at, table in tables:
319
+ row[at] = len(table)
320
+ for k, (x, y) in enumerate(table):
321
+ row[at + 1 + 2 * k : at + 3 + 2 * k] = (x, y)
322
+ row[P_CAP] = 0.995 / self.q1 if self.criterion == "gurson" else 0.999
323
+ row[P_NKIN] = len(self.kinematic)
324
+ for k, (c, d) in enumerate(self.kinematic):
325
+ row[P_KIN + 2 * k : P_KIN + 2 * k + 2] = (c, d)
326
+ return row
327
+
328
+ def to_config(self) -> dict:
329
+ out: dict = {"criterion": self.criterion, "yield": self.yield_stress}
330
+ if self.porosity:
331
+ out["porosity"] = self.porosity
332
+ if self.hardening:
333
+ out["hardening"] = self.hardening
334
+ if self.isotropic:
335
+ out["isotropic"] = [{"Q": q, "b": b} for q, b in self.isotropic]
336
+ if self.viscous:
337
+ out["norton"] = {"K": self.viscosity, "n": self.exponent}
338
+ if self.criterion == "gurson":
339
+ out.update({"q1": self.q1, "q2": self.q2, "q3": self.q3})
340
+ if self.effective:
341
+ out["effective"] = [list(p) for p in self.effective]
342
+ elif self.criterion == "rousselier":
343
+ out.update({"sigma1": self.sigma1, "D": self.D, "q2": self.q2})
344
+ else:
345
+ for name in ("C", "F"):
346
+ table = getattr(self, name)
347
+ out[name] = table[0][1] if len(table) == 1 else [list(p) for p in table]
348
+ if self.nucleation is not None:
349
+ out["nucleation"] = dict(self.nucleation)
350
+ if self.kinematic:
351
+ out["kinematic"] = [{"C": c, "D": d} for c, d in self.kinematic]
352
+ return out
353
+
354
+ @classmethod
355
+ def from_config(cls, spec) -> PorousPlasticity:
356
+ """``{criterion, yield (R0), porosity, hardening (H), isotropic: [{Q, b}...],
357
+ kinematic: [{C, D}...], norton: {K, n}, q1, q2, q3, effective | fc and fF, sigma1,
358
+ D, C, F, nucleation}``."""
359
+ if isinstance(spec, PorousPlasticity):
360
+ return spec
361
+ if not isinstance(spec, dict):
362
+ raise ValueError("porous_plasticity: a mapping (criterion, yield, porosity...)")
363
+ allowed = {"criterion", "yield", "R0", "porosity", "hardening", "H", "isotropic",
364
+ "kinematic", "norton", "q1", "q2", "q3", "effective", "fc", "fF", "sigma1",
365
+ "D", "C", "F", "nucleation"} # fmt: skip
366
+ unknown = sorted(set(spec) - allowed)
367
+ if unknown:
368
+ raise ValueError(
369
+ f"porous_plasticity: unknown keys {unknown}; allowed: {sorted(allowed)}"
370
+ )
371
+ if ("yield" in spec) == ("R0" in spec):
372
+ raise ValueError("porous_plasticity: the yield stress of the matrix (yield, or R0)")
373
+ if "criterion" not in spec:
374
+ raise ValueError(f"porous_plasticity: the criterion ({list(CRITERIA)})")
375
+ norton = spec.get("norton")
376
+ k = n = None
377
+ if norton is not None:
378
+ if not isinstance(norton, dict) or set(norton) != {"K", "n"}:
379
+ raise ValueError("porous_plasticity.norton: {K: viscosity, n: exponent}")
380
+ k, n = float(norton["K"]), float(norton["n"])
381
+ names = ("q1", "q2", "q3", "effective", "fc", "fF", "sigma1", "D", "C", "F", "nucleation")
382
+ kwargs = {key: spec[key] for key in names if key in spec}
383
+ return cls(
384
+ criterion=spec["criterion"],
385
+ yield_stress=float(spec.get("yield", spec.get("R0"))),
386
+ porosity=float(spec.get("porosity", 0.0)),
387
+ hardening=float(spec.get("hardening", spec.get("H", 0.0))),
388
+ isotropic=spec.get("isotropic") or (),
389
+ viscosity=k,
390
+ exponent=n,
391
+ kinematic=spec.get("kinematic") or (),
392
+ **kwargs,
393
+ )
394
+
395
+
396
+ # -- kernels ------------------------------------------------------------------------------
397
+
398
+
399
+ @njit(cache=True, inline="always")
400
+ def _ddot(a, b):
401
+ """a : b of two symmetric tensors given by their Voigt components."""
402
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + 2.0 * (a[3] * b[3] + a[4] * b[4] + a[5] * b[5])
403
+
404
+
405
+ @njit(cache=True)
406
+ def _hardening(par, p):
407
+ """R(p) = R0 + H p + sum Q (1 - exp(-b p))."""
408
+ r = par[2] + par[3] * p
409
+ for i in range(MAX_ISOTROPIC):
410
+ q = par[6 + 2 * i]
411
+ if q != 0.0:
412
+ r += q * (1.0 - math.exp(-par[7 + 2 * i] * p))
413
+ return r
414
+
415
+
416
+ @njit(cache=True)
417
+ def _hardening_slope(par, p):
418
+ """R'(p)."""
419
+ r = par[3]
420
+ for i in range(MAX_ISOTROPIC):
421
+ q = par[6 + 2 * i]
422
+ if q != 0.0:
423
+ b = par[7 + 2 * i]
424
+ r += q * b * math.exp(-b * p)
425
+ return r
426
+
427
+
428
+ @njit(cache=True)
429
+ def _table_value(par, at, x, default):
430
+ """The piecewise linear function of the table at ``par[at]`` (linear extrapolation);
431
+ ``default`` without points."""
432
+ n = int(par[at])
433
+ if n == 0:
434
+ return default
435
+ if n == 1:
436
+ return par[at + 2]
437
+ k = 0
438
+ while k < n - 2 and x > par[at + 1 + 2 * (k + 1)]:
439
+ k += 1
440
+ x0 = par[at + 1 + 2 * k]
441
+ y0 = par[at + 2 + 2 * k]
442
+ x1 = par[at + 3 + 2 * k]
443
+ y1 = par[at + 4 + 2 * k]
444
+ return y0 + (y1 - y0) * (x - x0) / (x1 - x0)
445
+
446
+
447
+ @njit(cache=True)
448
+ def _table_slope(par, at, x, default):
449
+ """The slope of :func:`_table_value` at ``x``; ``default`` without points."""
450
+ n = int(par[at])
451
+ if n == 0:
452
+ return default
453
+ if n == 1:
454
+ return 0.0
455
+ k = 0
456
+ while k < n - 2 and x > par[at + 1 + 2 * (k + 1)]:
457
+ k += 1
458
+ dy = par[at + 4 + 2 * k] - par[at + 2 + 2 * k]
459
+ return dy / (par[at + 3 + 2 * k] - par[at + 1 + 2 * k])
460
+
461
+
462
+ @njit(cache=True)
463
+ def _gurson_stress(q1, q2, q3, fs, seq, sm, guess):
464
+ """The matrix stress of the GTN potential and its derivatives by Σeq and Σm: the root
465
+ bracketed from ``guess`` if it is positive (the matrix stress of a nearby point; by
466
+ factors from 1 + 1e-6 up to 2), else from an estimate (by factors of 2), then a
467
+ safeguarded Newton iteration."""
468
+ if fs <= 0.0:
469
+ return seq, 1.0, 0.0 # von Mises
470
+ if seq == 0.0 and sm == 0.0:
471
+ return 0.0, 1.0, 0.0
472
+ # Φ(s) = (seq/s)^2 + 2 q1 fs cosh(1.5 q2 sm/s) - 1 - q3 fs^2, decreasing in s
473
+ c = 1.0 + q3 * fs * fs
474
+ if c - 2.0 * q1 * fs <= 0.0:
475
+ return math.inf, 0.0, 0.0 # the surface has vanished
476
+ if guess > 0.0 and math.isfinite(guess):
477
+ s = guess
478
+ grow = 1.0 + 1e-6
479
+ else:
480
+ s = math.sqrt(seq * seq + (1.5 * q2 * sm) ** 2) / max(1.0 - q1 * fs, 0.05)
481
+ grow = 2.0
482
+ lo, hi = 0.0, 0.0
483
+ for _ in range(200):
484
+ t = 1.5 * q2 * sm / s
485
+ phi = (seq / s) ** 2 + 2.0 * q1 * fs * math.cosh(t) - c
486
+ if phi > 0.0:
487
+ lo = s
488
+ if hi == 0.0:
489
+ s *= grow
490
+ grow = 1.0 + min(8.0 * (grow - 1.0), 1.0)
491
+ continue
492
+ else:
493
+ hi = s
494
+ if lo == 0.0:
495
+ s /= grow
496
+ grow = 1.0 + min(8.0 * (grow - 1.0), 1.0)
497
+ continue
498
+ break
499
+ for _ in range(100):
500
+ t = 1.5 * q2 * sm / s
501
+ phi = (seq / s) ** 2 + 2.0 * q1 * fs * math.cosh(t) - c
502
+ if phi > 0.0:
503
+ lo = s
504
+ else:
505
+ hi = s
506
+ dphi = -2.0 / s * ((seq / s) ** 2 + q1 * fs * t * math.sinh(t)) # dΦ/ds < 0
507
+ step = s - phi / dphi
508
+ if not (lo < step < hi):
509
+ step = 0.5 * (lo + hi)
510
+ if abs(step - s) <= 1e-15 * s:
511
+ s = step
512
+ break
513
+ s = step
514
+ t = 1.5 * q2 * sm / s
515
+ den = (seq / s) ** 2 + q1 * fs * t * math.sinh(t)
516
+ return s, (seq / s) / den, 1.5 * q1 * q2 * fs * math.sinh(t) / den
517
+
518
+
519
+ @njit(cache=True)
520
+ def matrix_stress(par, seq, sm, f):
521
+ """The matrix stress ``σ*`` of the potential of a point (see the module) and its
522
+ derivatives by ``Σeq`` and ``Σm``, at the porosity ``f``."""
523
+ return _matrix_stress(par, seq, sm, f, 0.0)
524
+
525
+
526
+ @njit(cache=True)
527
+ def _matrix_stress(par, seq, sm, f, guess):
528
+ """:func:`matrix_stress`, Gurson's iteration started from ``guess`` if it is positive."""
529
+ kind = int(par[P_CRITERION])
530
+ if kind == GURSON:
531
+ fs = _table_value(par, P_FSTAR, f, f)
532
+ fs = min(max(fs, 0.0), par[P_CAP])
533
+ return _gurson_stress(par[P_Q1], par[P_Q2], par[P_Q3], fs, seq, sm, guess)
534
+ if kind == ROUSSELIER:
535
+ fe = min(max(f, 0.0), par[P_CAP])
536
+ s1 = par[P_SIGMA1]
537
+ e = par[P_D] * s1 * fe * math.exp(min(par[P_QR] * sm / ((1.0 - fe) * s1), 700.0))
538
+ return seq / (1.0 - fe) + e, 1.0 / (1.0 - fe), e * par[P_QR] / ((1.0 - fe) * s1)
539
+ fe = max(f, 0.0)
540
+ cc = max(_table_value(par, P_C, fe, 1.0), 0.0)
541
+ ff = max(_table_value(par, P_F, fe, 0.0), 0.0)
542
+ s2 = cc * seq * seq + 9.0 * ff * sm * sm
543
+ if s2 <= 0.0:
544
+ return 0.0, 1.0, 0.0
545
+ s = math.sqrt(s2)
546
+ return s, cc * seq / s, 9.0 * ff * sm / s
547
+
548
+
549
+ @njit(cache=True)
550
+ def _nucleation(par, p):
551
+ """The rate ``A(p)`` of the nucleation of porosity per unit of ``ṗ``."""
552
+ kind = int(par[P_NUCLEATION])
553
+ if kind == 0 or p < par[P_NUCLEATION + 4]:
554
+ return 0.0
555
+ a, b, c = par[P_NUCLEATION + 1], par[P_NUCLEATION + 2], par[P_NUCLEATION + 3]
556
+ if kind == 1:
557
+ return a
558
+ if kind == 2:
559
+ z = (p - b) / c
560
+ return a / (c * math.sqrt(2.0 * math.pi)) * math.exp(-0.5 * z * z)
561
+ return a * math.exp(-p / b)
562
+
563
+
564
+ @njit(cache=True)
565
+ def _nucleation_slope(par, p):
566
+ """A'(p), the derivative of :func:`_nucleation` (zero below its threshold)."""
567
+ kind = int(par[P_NUCLEATION])
568
+ if kind <= 1 or p < par[P_NUCLEATION + 4]:
569
+ return 0.0
570
+ a, b, c = par[P_NUCLEATION + 1], par[P_NUCLEATION + 2], par[P_NUCLEATION + 3]
571
+ if kind == 2:
572
+ z = (p - b) / c
573
+ return -a / (c * math.sqrt(2.0 * math.pi)) * math.exp(-0.5 * z * z) * z / c
574
+ return -a / b * math.exp(-p / b)
575
+
576
+
577
+ @njit(cache=True)
578
+ def _matrix_derivatives(par, seq, sm, f, s, d):
579
+ """The derivatives of the matrix stress ``s`` of ``(seq, sm, f)`` in ``d``: by Σeq, Σm
580
+ and f, then the second ones by (Σeq, Σeq), (Σeq, Σm), (Σm, Σm), (Σeq, f) and (Σm, f);
581
+ those of GTN by the implicit function theorem on its potential."""
582
+ for i in range(8):
583
+ d[i] = 0.0
584
+ kind = int(par[P_CRITERION])
585
+ if kind == GURSON:
586
+ raw = _table_value(par, P_FSTAR, f, f)
587
+ cap = par[P_CAP]
588
+ fs = min(max(raw, 0.0), cap)
589
+ dfs = _table_slope(par, P_FSTAR, f, 1.0) if 0.0 <= raw < cap else 0.0
590
+ if not s > 0.0:
591
+ d[0] = 1.0
592
+ return
593
+ q1 = par[P_Q1]
594
+ q3 = par[P_Q3]
595
+ k = 1.5 * par[P_Q2]
596
+ u = k * sm / s
597
+ ch = math.cosh(u)
598
+ sh = math.sinh(u)
599
+ a = seq / s
600
+ # Φ = (Σeq/s)² + 2 q1 fs cosh(k Σm/s) - 1 - q3 fs² and its derivatives
601
+ p_s = -2.0 * (a * a + q1 * fs * u * sh) / s
602
+ p_q = 2.0 * a / s
603
+ p_m = 2.0 * q1 * fs * k * sh / s
604
+ p_f = 2.0 * (q1 * ch - q3 * fs)
605
+ s2 = s * s
606
+ p_qq = 2.0 / s2
607
+ p_qs = -4.0 * a / s2
608
+ p_mm = 2.0 * q1 * fs * k * k * ch / s2
609
+ p_ms = -2.0 * q1 * fs * k * (u * ch + sh) / s2
610
+ p_mf = 2.0 * q1 * k * sh / s
611
+ p_fs = -2.0 * q1 * u * sh / s
612
+ p_ss = (6.0 * a * a + 2.0 * q1 * fs * (2.0 * u * sh + u * u * ch)) / s2
613
+ s_q = -p_q / p_s
614
+ s_m = -p_m / p_s
615
+ s_f = -p_f / p_s
616
+ d[0] = s_q
617
+ d[1] = s_m
618
+ d[2] = s_f * dfs
619
+ d[3] = -(p_qq + 2.0 * p_qs * s_q + p_ss * s_q * s_q) / p_s
620
+ d[4] = -(p_qs * s_m + p_ms * s_q + p_ss * s_q * s_m) / p_s
621
+ d[5] = -(p_mm + 2.0 * p_ms * s_m + p_ss * s_m * s_m) / p_s
622
+ d[6] = -(p_qs * s_f + p_fs * s_q + p_ss * s_q * s_f) / p_s * dfs
623
+ d[7] = -(p_mf + p_ms * s_f + p_fs * s_m + p_ss * s_m * s_f) / p_s * dfs
624
+ return
625
+ if kind == ROUSSELIER:
626
+ cap = par[P_CAP]
627
+ fe = min(max(f, 0.0), cap)
628
+ dfe = 1.0 if 0.0 <= f < cap else 0.0
629
+ s1 = par[P_SIGMA1]
630
+ qr = par[P_QR]
631
+ a = 1.0 / (1.0 - fe)
632
+ arg = qr * sm * a / s1
633
+ free = arg < 700.0
634
+ ex = math.exp(arg if free else 700.0)
635
+ g = par[P_D] * s1 * fe * ex
636
+ dg = par[P_D] * s1 * ex + (g * qr * sm * a * a / s1 if free else 0.0) # d g / d fe
637
+ d[0] = a
638
+ d[1] = g * qr * a / s1
639
+ d[2] = (seq * a * a + dg) * dfe
640
+ d[5] = d[1] * qr * a / s1 if free else 0.0
641
+ d[6] = a * a * dfe
642
+ d[7] = qr / s1 * (dg * a + g * a * a) * dfe
643
+ return
644
+ fe = max(f, 0.0)
645
+ dfe = 1.0 if f >= 0.0 else 0.0
646
+ c_raw = _table_value(par, P_C, fe, 1.0)
647
+ f_raw = _table_value(par, P_F, fe, 0.0)
648
+ cc = max(c_raw, 0.0)
649
+ ff = max(f_raw, 0.0)
650
+ dc = _table_slope(par, P_C, fe, 0.0) * dfe if c_raw > 0.0 else 0.0
651
+ dff = _table_slope(par, P_F, fe, 0.0) * dfe if f_raw > 0.0 else 0.0
652
+ if not s > 0.0:
653
+ d[0] = 1.0
654
+ return
655
+ s3 = s * s * s
656
+ d[0] = cc * seq / s
657
+ d[1] = 9.0 * ff * sm / s
658
+ d[2] = (seq * seq * dc + 9.0 * sm * sm * dff) / (2.0 * s)
659
+ d[3] = 9.0 * cc * ff * sm * sm / s3
660
+ d[4] = -9.0 * cc * ff * seq * sm / s3
661
+ d[5] = 9.0 * ff * cc * seq * seq / s3
662
+ d[6] = dc * seq / s - cc * seq * d[2] / (s * s)
663
+ d[7] = 9.0 * dff * sm / s - 9.0 * ff * sm * d[2] / (s * s)
664
+
665
+
666
+ @njit(cache=True)
667
+ def _relative(par, kin, sm_tr, seq_tr, dp):
668
+ """The invariants of the relative trial stress ``σ_tr - Σ θ_i X_i,n`` after a plastic
669
+ increment ``Δp`` (``θ_i = 1 / (1 + D_i Δp)``, see the module): its von Mises stress
670
+ ``J*`` and mean stress ``m*``, ``c = Σ θ_i C_i``, and their derivatives by ``Δp``;
671
+ ``kin``: the trial deviator (row 0) and the deviators and mean stresses of the
672
+ backstresses at the start of the step (rows 1...); without backstresses, ``(Σeq_tr,
673
+ Σm_tr, 0...)``."""
674
+ nk = int(par[P_NKIN])
675
+ if nk == 0:
676
+ return seq_tr, sm_tr, 0.0, 0.0, 0.0, 0.0
677
+ m, dm, c, dc = sm_tr, 0.0, 0.0, 0.0
678
+ for k in range(nk):
679
+ d = par[P_KIN + 2 * k + 1]
680
+ th = 1.0 / (1.0 + d * dp)
681
+ c += th * par[P_KIN + 2 * k]
682
+ dc -= d * th * th * par[P_KIN + 2 * k]
683
+ m -= th * kin[1 + k, 6]
684
+ dm += d * th * th * kin[1 + k, 6]
685
+ xx = 0.0
686
+ xw = 0.0
687
+ for r in range(6):
688
+ xi = kin[0, r]
689
+ w = 0.0
690
+ for k in range(nk):
691
+ d = par[P_KIN + 2 * k + 1]
692
+ th = 1.0 / (1.0 + d * dp)
693
+ xi -= th * kin[1 + k, r]
694
+ w += d * th * th * kin[1 + k, r]
695
+ g = 1.0 if r < 3 else 2.0
696
+ xx += g * xi * xi
697
+ xw += g * xi * w
698
+ j = math.sqrt(max(1.5 * xx, 0.0))
699
+ return j, m, c, (1.5 * xw / j if j > 0.0 else 0.0), dm, dc
700
+
701
+
702
+ @njit(cache=True)
703
+ def _relative_deviator(par, kin, dp, xi, w):
704
+ """The deviator ``ξ*`` of the relative trial stress after a plastic increment ``Δp``
705
+ (:func:`_relative`) and its derivative ``w = Σ D_i θ_i² X_i,n`` by ``Δp``."""
706
+ for r in range(6):
707
+ xi[r] = kin[0, r]
708
+ w[r] = 0.0
709
+ for k in range(int(par[P_NKIN])):
710
+ d = par[P_KIN + 2 * k + 1]
711
+ th = 1.0 / (1.0 + d * dp)
712
+ for r in range(6):
713
+ xi[r] -= th * kin[1 + k, r]
714
+ w[r] += d * th * th * kin[1 + k, r]
715
+
716
+
717
+ @njit(cache=True)
718
+ def _residual(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, out, guess, kin):
719
+ """The four equations of the update (see the module) at ``x = (Δεv, Δεq, z, f)``, the
720
+ matrix stress sought from ``guess`` (if positive: that of a nearby point), ``kin`` the
721
+ trial deviator and the backstresses (:func:`_relative`); returns the matrix stress, or
722
+ -1 when ``x`` is out of bounds."""
723
+ dv, dq, z, f = x[0], x[1], x[2], x[3]
724
+ if z < 0.0 or not (0.0 <= f < 0.9999):
725
+ return -1.0
726
+ viscous = par[4] > 0.0
727
+ dp = dt * z ** par[5] if viscous else z
728
+ jstar, mstar, c, _, _, _ = _relative(par, kin, sm_tr, seq_tr, dp)
729
+ sm = mstar - (kb + 2.0 * c / 9.0) * dv
730
+ seq = jstar - (3.0 * mu + c) * dq
731
+ s, s_q, s_m = _matrix_stress(par, seq, sm, f, guess)
732
+ if not math.isfinite(s):
733
+ return -1.0
734
+ p = p_old + dp
735
+ out[0] = dq - jstar / (3.0 * mu + c) if vertex else dv * s_q - dq * s_m
736
+ out[1] = s - _hardening(par, p) - (par[4] * z if viscous else 0.0)
737
+ out[2] = (1.0 - f) * s * dp - sm * dv - seq * dq
738
+ out[3] = f - f_old - (1.0 - f) * dv - _nucleation(par, p) * dp
739
+ return s
740
+
741
+
742
+ @njit(cache=True)
743
+ def _solve4(a, b, n_rhs, m):
744
+ """Solves ``a x = b`` (4 x 4, ``n_rhs`` columns of ``b``) by Gaussian elimination with
745
+ partial pivoting, in place in ``b`` (``m``: a work matrix of 4 x 4); returns False if
746
+ singular."""
747
+ for r in range(4):
748
+ for c in range(4):
749
+ m[r, c] = a[r, c]
750
+ for col in range(4):
751
+ piv = col
752
+ for r in range(col + 1, 4):
753
+ if abs(m[r, col]) > abs(m[piv, col]):
754
+ piv = r
755
+ if abs(m[piv, col]) < 1e-300:
756
+ return False
757
+ if piv != col:
758
+ for c in range(4):
759
+ m[col, c], m[piv, c] = m[piv, c], m[col, c]
760
+ for c in range(n_rhs):
761
+ b[col, c], b[piv, c] = b[piv, c], b[col, c]
762
+ for r in range(col + 1, 4):
763
+ g = m[r, col] / m[col, col]
764
+ if g != 0.0:
765
+ for c in range(col, 4):
766
+ m[r, c] -= g * m[col, c]
767
+ for c in range(n_rhs):
768
+ b[r, c] -= g * b[col, c]
769
+ for col in range(3, -1, -1):
770
+ for c in range(n_rhs):
771
+ acc = b[col, c]
772
+ for k in range(col + 1, 4):
773
+ acc -= m[col, k] * b[k, c]
774
+ b[col, c] = acc / m[col, col]
775
+ return True
776
+
777
+
778
+ @njit(cache=True)
779
+ def _scaled_norm(r, e_scale, s_scale):
780
+ return max(abs(r[0]) / e_scale, abs(r[1]) / s_scale, abs(r[2]) / (s_scale * e_scale),
781
+ abs(r[3])) # fmt: skip
782
+
783
+
784
+ @njit(cache=True)
785
+ def _jacobian(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, s, d, jac, dr, kin):
786
+ """The Jacobian ``jac`` of the residual (:func:`_residual`) at ``x``, whose matrix
787
+ stress is ``s``, and in ``dr`` (4 x 2) its derivatives by the trial invariants Σm_tr
788
+ and Σeq_tr (with backstresses: m* and J*); ``d``: a work vector of 8
789
+ (:func:`_matrix_derivatives`)."""
790
+ dv, dq, z, f = x[0], x[1], x[2], x[3]
791
+ kv = par[4]
792
+ viscous = kv > 0.0
793
+ nv = par[5]
794
+ if viscous:
795
+ dp = dt * z**nv
796
+ dpz = nv * dt * z ** (nv - 1.0) if z > 0.0 else (dt if nv == 1.0 else 0.0)
797
+ else:
798
+ dp = z
799
+ dpz = 1.0
800
+ jstar, mstar, c, dj, dm, dc = _relative(par, kin, sm_tr, seq_tr, dp)
801
+ kbe = kb + 2.0 * c / 9.0
802
+ mue = 3.0 * mu + c
803
+ sm = mstar - kbe * dv
804
+ seq = jstar - mue * dq
805
+ # the derivatives of the relative invariants by Δp (the recovery of the backstresses)
806
+ seq_p = dj - dc * dq
807
+ sm_p = dm - 2.0 * dc / 9.0 * dv
808
+ _matrix_derivatives(par, seq, sm, f, s, d)
809
+ s_q, s_m, s_f = d[0], d[1], d[2]
810
+ s_qq, s_qm, s_mm, s_qf, s_mf = d[3], d[4], d[5], d[6], d[7]
811
+ s_p = s_q * seq_p + s_m * sm_p
812
+ p = p_old + dp
813
+ if vertex: # dq - J* / (3 μ + c)
814
+ jac[0, 0] = 0.0
815
+ jac[0, 1] = 1.0
816
+ jac[0, 2] = -dpz * (dj - jstar * dc / mue) / mue
817
+ jac[0, 3] = 0.0
818
+ dr[0, 0] = 0.0
819
+ dr[0, 1] = -1.0 / mue
820
+ else: # dv S_q - dq S_m
821
+ nq = dv * s_qq - dq * s_qm
822
+ nm = dv * s_qm - dq * s_mm
823
+ jac[0, 0] = s_q - kbe * nm
824
+ jac[0, 1] = -s_m - mue * nq
825
+ jac[0, 2] = dpz * (nq * seq_p + nm * sm_p)
826
+ jac[0, 3] = dv * s_qf - dq * s_mf
827
+ dr[0, 0] = nm
828
+ dr[0, 1] = nq
829
+ # σ* - R(p) - K z
830
+ jac[1, 0] = -kbe * s_m
831
+ jac[1, 1] = -mue * s_q
832
+ jac[1, 2] = (s_p - _hardening_slope(par, p)) * dpz - (kv if viscous else 0.0)
833
+ jac[1, 3] = s_f
834
+ dr[1, 0] = s_m
835
+ dr[1, 1] = s_q
836
+ # (1 - f) σ* dp - Σm dv - Σeq dq
837
+ g = 1.0 - f
838
+ jac[2, 0] = -g * dp * kbe * s_m + kbe * dv - sm
839
+ jac[2, 1] = -mue * g * dp * s_q + mue * dq - seq
840
+ jac[2, 2] = (g * s + g * dp * s_p - dv * sm_p - dq * seq_p) * dpz
841
+ jac[2, 3] = (g * s_f - s) * dp
842
+ dr[2, 0] = g * dp * s_m - dv
843
+ dr[2, 1] = g * dp * s_q - dq
844
+ # f - f_old - (1 - f) dv - A(p) dp
845
+ jac[3, 0] = -g
846
+ jac[3, 1] = 0.0
847
+ jac[3, 2] = -dpz * (_nucleation(par, p) + _nucleation_slope(par, p) * dp)
848
+ jac[3, 3] = 1.0 + dv
849
+ dr[3, 0] = 0.0
850
+ dr[3, 1] = 0.0
851
+
852
+
853
+ @njit(cache=True)
854
+ def _porous_works(count):
855
+ """``count`` sets of the work arrays of :func:`_porous_update`: the vectors of 6 and
856
+ of 4, the matrices of 4 x 4, the right-hand sides, the derivatives of the residual by
857
+ the trial invariants, those of the matrix stress, and the trial deviator with the
858
+ backstresses (:func:`_relative`), with one more axis, the first one. The loops over
859
+ the points allocate a set per chunk of points before their parallel loop, and take
860
+ that of each chunk (:func:`_porous_set`): rows of arrays allocated in the loop would
861
+ count their references (:func:`morphogen.homogenization.crystal.work_block`)."""
862
+ return (np.empty((count, 6, 6)), np.empty((count, 4, 4)), np.empty((count, 2, 4, 4)),
863
+ np.empty((count, 4, 2)), np.empty((count, 4, 2)), np.empty((count, 8)),
864
+ np.zeros((count, 1 + MAX_KINEMATIC, 7))) # fmt: skip
865
+
866
+
867
+ @njit(cache=True)
868
+ def _porous_set(works, k):
869
+ """The set ``k`` of the work arrays of :func:`_porous_works` (views)."""
870
+ return (works[0][k], works[1][k], works[2][k], works[3][k], works[4][k], works[5][k],
871
+ works[6][k]) # fmt: skip
872
+
873
+
874
+ @njit(cache=True)
875
+ def _porous_work():
876
+ """Work arrays of :func:`_porous_update` (a set of :func:`_porous_works`)."""
877
+ return _porous_set(_porous_works(1), 0)
878
+
879
+
880
+ @njit(cache=True)
881
+ def porous_update(par, eps, eth, dt, old, new, sig, tan):
882
+ """Implicit update of a porous point over a step ``dt`` (see the module): strain
883
+ ``eps`` (engineering), thermal strain ``eth`` (tensor components). Fills the stress,
884
+ the new internal variables and the tangent; returns 1 if the local iteration fails."""
885
+ return _porous_update(par, eps, eth, dt, old, new, sig, tan, _porous_work())
886
+
887
+
888
+ @njit(cache=True)
889
+ def _porous_update(par, eps, eth, dt, old, new, sig, tan, wk, sym=True):
890
+ """:func:`porous_update` with its work arrays ``wk`` (:func:`_porous_work`), the
891
+ tangent symmetrized with ``sym``."""
892
+ lam = par[0]
893
+ mu = par[1]
894
+ kb = lam + 2.0 * mu / 3.0
895
+ viscous = par[4] > 0.0
896
+ vec6, vec4, mat4, rhs, dr, ds, kin = wk
897
+ ee = vec6[0]
898
+ s_tr = vec6[1]
899
+ nrm = vec6[2]
900
+ d = vec6[3]
901
+ xi = vec6[4]
902
+ w = vec6[5]
903
+ x = vec4[0]
904
+ res = vec4[1]
905
+ trial = vec4[2]
906
+ rt = vec4[3]
907
+ jac = mat4[0]
908
+ m4 = mat4[1]
909
+ for r in range(6):
910
+ e = eps[r] if r < 3 else 0.5 * eps[r]
911
+ ee[r] = e - eth[r] - old[r]
912
+ tr = ee[0] + ee[1] + ee[2]
913
+ sm_tr = kb * tr
914
+ for r in range(6):
915
+ s_tr[r] = 2.0 * mu * (ee[r] - tr / 3.0 if r < 3 else ee[r])
916
+ seq_tr = math.sqrt(max(1.5 * _ddot(s_tr, s_tr), 0.0))
917
+ for r in range(old.shape[0]):
918
+ new[r] = old[r]
919
+ # the trial deviator and the deviators and mean stresses of the backstresses
920
+ nk = int(par[P_NKIN])
921
+ for r in range(6):
922
+ kin[0, r] = s_tr[r]
923
+ for k in range(nk):
924
+ base = STATE_BACK + 6 * k
925
+ xm = (old[base] + old[base + 1] + old[base + 2]) / 3.0
926
+ for r in range(6):
927
+ kin[1 + k, r] = old[base + r] - (xm if r < 3 else 0.0)
928
+ kin[1 + k, 6] = xm
929
+ f_old = max(par[P_F0] + old[STATE_FG] + old[STATE_FN], 0.0)
930
+ p_old = old[STATE_P]
931
+ # the relative trial stress (the trial one without backstresses)
932
+ jstar0, mstar0, c0, _, _, _ = _relative(par, kin, sm_tr, seq_tr, 0.0)
933
+ s0, sq0, smd0 = matrix_stress(par, jstar0, mstar0, f_old)
934
+ r_old = _hardening(par, p_old)
935
+ # the stresses of the trial state (not σ*, whose exponential term of Rousselier may be
936
+ # out of all proportion with them)
937
+ s_scale = max(seq_tr, abs(sm_tr), jstar0, abs(mstar0), r_old, 1e-300)
938
+ tiny = 1e-14 * s_scale
939
+ inv = 1.5 / seq_tr if seq_tr > tiny else 0.0
940
+ for r in range(6):
941
+ nrm[r] = inv * s_tr[r]
942
+ if not math.isfinite(s0):
943
+ return 1
944
+ if s0 - r_old <= 1e-13 * s_scale:
945
+ for r in range(6):
946
+ sig[r] = s_tr[r] + (sm_tr if r < 3 else 0.0)
947
+ for c in range(6):
948
+ tan[r, c] = 0.0
949
+ for r in range(3):
950
+ for c in range(3):
951
+ tan[r, c] = lam
952
+ tan[r, r] += 2.0 * mu
953
+ tan[3 + r, 3 + r] = mu
954
+ new[STATE_SSTAR] = s0
955
+ return 0
956
+ # plastic flow: initial guess, the cutting-plane step along the normal at the trial
957
+ # stress, d(σ*)/dΛ = K_b S_m² + 3 μ S_q² + R' dp/dΛ, dp/dΛ = (σ - X) : N / ((1 - f) σ*)
958
+ # (the backstresses: K_b + 2 c / 9 and 3 μ + c)
959
+ e_scale = s_scale / (3.0 * mu)
960
+ work = jstar0 * sq0 + mstar0 * smd0
961
+ dp_dl = work / ((1.0 - f_old) * s0) if work > 0.0 else 1.0 / (1.0 - f_old)
962
+ slope = (_hardening(par, p_old + 1e-6) - _hardening(par, max(p_old - 1e-6, 0.0))) / (
963
+ p_old + 1e-6 - max(p_old - 1e-6, 0.0)
964
+ )
965
+ kbe = kb + 2.0 * c0 / 9.0
966
+ mue = 3.0 * mu + c0
967
+ lam0 = (s0 - r_old) / (kbe * smd0 * smd0 + mue * sq0 * sq0 + slope * dp_dl)
968
+ dp0 = lam0 * dp_dl
969
+ x[0] = lam0 * smd0
970
+ x[1] = min(lam0 * sq0, 0.5 * jstar0 / mue)
971
+ x[3] = f_old
972
+ if viscous: # the viscous stress of the rate-independent increment, at most the overstress
973
+ bound = (s0 - r_old) / par[4]
974
+ x[2] = min((dp0 / dt) ** (1.0 / par[5]), bound) if dt > 0.0 else bound
975
+ else:
976
+ x[2] = dp0
977
+ vertex = jstar0 <= tiny and int(par[P_CRITERION]) == ROUSSELIER
978
+ converged = False
979
+ for _attempt in range(2):
980
+ # sx: the matrix stress of x, the guess of the nearby points
981
+ sx = _residual(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, res, 0.0, kin)
982
+ if sx < 0.0:
983
+ x[0] = 0.0
984
+ x[1] = 0.0
985
+ x[2] = 0.0
986
+ x[3] = f_old
987
+ sx = _residual(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, res, 0.0,
988
+ kin) # fmt: skip
989
+ if sx < 0.0:
990
+ return 1
991
+ norm = _scaled_norm(res, e_scale, s_scale)
992
+ for _ in range(80):
993
+ if norm <= 1e-12:
994
+ converged = True
995
+ break
996
+ _jacobian(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, sx, ds, jac, dr,
997
+ kin) # fmt: skip
998
+ for i in range(4):
999
+ rhs[i, 0] = -res[i]
1000
+ if not _solve4(jac, rhs, 1, m4):
1001
+ return 1
1002
+ # the porosity falls at most by 90 % per iteration: it approaches full density
1003
+ # (the elliptic surface grows without bound as F(f) vanishes) without passing it
1004
+ alpha = 1.0
1005
+ if rhs[3, 0] < 0.0 and x[3] > 0.0:
1006
+ alpha = min(1.0, 0.9 * x[3] / -rhs[3, 0])
1007
+ accepted = False
1008
+ n_t = norm
1009
+ for _ in range(30):
1010
+ for i in range(4):
1011
+ trial[i] = x[i] + alpha * rhs[i, 0]
1012
+ trial[3] = max(trial[3], 0.0) # a dense point stays dense (no roundoff below)
1013
+ inside = _residual(par, trial, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, rt,
1014
+ sx, kin) # fmt: skip
1015
+ if inside >= 0.0:
1016
+ n_t = _scaled_norm(rt, e_scale, s_scale)
1017
+ if n_t < (1.0 - 1e-4 * alpha) * norm or alpha < 1e-6:
1018
+ accepted = True
1019
+ break
1020
+ alpha *= 0.5
1021
+ if not accepted:
1022
+ return 1
1023
+ for i in range(4):
1024
+ x[i] = trial[i]
1025
+ res[i] = rt[i]
1026
+ sx = inside
1027
+ norm = n_t
1028
+ if not converged:
1029
+ return 1
1030
+ dp = dt * x[2] ** par[5] if viscous else x[2]
1031
+ jstar, _, c, _, _, _ = _relative(par, kin, sm_tr, seq_tr, dp)
1032
+ seq = jstar - (3.0 * mu + c) * x[1]
1033
+ if seq >= -1e-10 * s_scale or vertex:
1034
+ break
1035
+ # Rousselier's vertex: the hydrostatic return
1036
+ vertex = True
1037
+ converged = False
1038
+ x[1] = jstar / (3.0 * mu + c)
1039
+ if not converged:
1040
+ return 1
1041
+ dv, dq, z, f = x[0], x[1], x[2], x[3]
1042
+ if viscous:
1043
+ dp = dt * z ** par[5]
1044
+ dpz = par[5] * dt * z ** (par[5] - 1.0) if z > 0.0 else (dt if par[5] == 1.0 else 0.0)
1045
+ else:
1046
+ dp = z
1047
+ dpz = 1.0
1048
+ jstar, mstar, c, _, _, _ = _relative(par, kin, sm_tr, seq_tr, dp)
1049
+ sm = mstar - (kb + 2.0 * c / 9.0) * dv
1050
+ seq = max(jstar - (3.0 * mu + c) * dq, 0.0)
1051
+ s, _, _ = matrix_stress(par, seq, sm, f)
1052
+ # the deviator of the relative trial stress, whose direction the plastic strain takes
1053
+ _relative_deviator(par, kin, dp, xi, w)
1054
+ if nk > 0:
1055
+ inv = 1.5 / jstar if jstar > tiny else 0.0
1056
+ for r in range(6):
1057
+ nrm[r] = inv * xi[r]
1058
+ for r in range(6):
1059
+ new[r] = old[r] + (dv / 3.0 if r < 3 else 0.0) + dq * nrm[r]
1060
+ new[STATE_P] = p_old + dp
1061
+ new[STATE_FN] = old[STATE_FN] + _nucleation(par, p_old + dp) * dp
1062
+ # no porosity below zero (a dense point whose volume change is a roundoff)
1063
+ new[STATE_FG] = max(old[STATE_FG] + (1.0 - f) * dv, -par[P_F0] - new[STATE_FN])
1064
+ new[STATE_SSTAR] = s
1065
+ for k in range(nk): # X = θ (X_n + 2/3 C Δεp), its hydrostatic part included
1066
+ th = 1.0 / (1.0 + par[P_KIN + 2 * k + 1] * dp)
1067
+ cc = 2.0 / 3.0 * par[P_KIN + 2 * k]
1068
+ base = STATE_BACK + 6 * k
1069
+ for r in range(6):
1070
+ dep = (dv / 3.0 if r < 3 else 0.0) + dq * nrm[r]
1071
+ new[base + r] = th * (old[base + r] + cc * dep)
1072
+ # σ = σ_tr - K_b Δεv I - 2 μ Δεq n: the deviator (s_tr - ξ*) + (1 - 3 μ Δεq / J*) ξ*
1073
+ ratio_s = max(jstar - 3.0 * mu * dq, 0.0) / jstar if jstar > tiny else 1.0
1074
+ sm_abs = sm_tr - kb * dv
1075
+ for r in range(6):
1076
+ sig[r] = (s_tr[r] - xi[r]) + ratio_s * xi[r] + (sm_abs if r < 3 else 0.0)
1077
+ # consistent tangent: the sensitivity of the solution to the trial invariants,
1078
+ # jac dx = -dr d(Σm_tr, Σeq_tr) (with backstresses: d(m*, J*), dJ* = n : ds_tr)
1079
+ _jacobian(par, x, sm_tr, seq_tr, kb, mu, f_old, p_old, dt, vertex, sx, ds, jac, dr, kin)
1080
+ for i in range(4):
1081
+ rhs[i, 0] = -dr[i, 0]
1082
+ rhs[i, 1] = -dr[i, 1]
1083
+ if not _solve4(jac, rhs, 2, m4):
1084
+ return 1
1085
+ gq = rhs[1, 1]
1086
+ ratio = ratio_s if jstar > tiny else 1.0 - 3.0 * mu * gq
1087
+ # the turn of the direction with Δp: dn = 3 / (2 J*) (w - 2/3 (n : w) n) dΔp
1088
+ turn = 3.0 * mu * dq / jstar if nk > 0 and jstar > tiny else 0.0
1089
+ nw = _ddot(nrm, w)
1090
+ for j in range(6):
1091
+ for r in range(6):
1092
+ d[r] = 0.0
1093
+ d[j] = 1.0 if j < 3 else 0.5
1094
+ trd = 1.0 if j < 3 else 0.0
1095
+ nd = _ddot(nrm, d)
1096
+ dsm_tr = kb * trd
1097
+ dseq_tr = 2.0 * mu * nd
1098
+ ddv = rhs[0, 0] * dsm_tr + rhs[0, 1] * dseq_tr
1099
+ ddq = rhs[1, 0] * dsm_tr + rhs[1, 1] * dseq_tr
1100
+ ddp = turn * dpz * (rhs[2, 0] * dsm_tr + rhs[2, 1] * dseq_tr)
1101
+ dsm = dsm_tr - kb * ddv
1102
+ dseq = dseq_tr - 3.0 * mu * ddq
1103
+ for r in range(6):
1104
+ dev = d[r] - trd / 3.0 if r < 3 else d[r]
1105
+ value = 2.0 / 3.0 * dseq * nrm[r] + 2.0 * mu * ratio * (dev - 2.0 / 3.0 * nd * nrm[r])
1106
+ if turn != 0.0:
1107
+ value -= ddp * (w[r] - 2.0 / 3.0 * nw * nrm[r])
1108
+ if r < 3:
1109
+ value += dsm
1110
+ tan[r, j] = value
1111
+ if sym:
1112
+ symmetrize(tan)
1113
+ return 0
1114
+
1115
+
1116
+ def porosity(state, params, pmat) -> np.ndarray:
1117
+ """The porosity ``f`` of porous points from their internal variables (points x width),
1118
+ the rows of parameters and the row of each point."""
1119
+ state = np.asarray(state)
1120
+ return params[np.asarray(pmat), P_F0] + state[:, STATE_FG] + state[:, STATE_FN]