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,944 @@
1
+ """Nonlinear behaviours of the phases: von Mises elasto-(visco)plasticity, and the
2
+ integration of the behaviours of all the points (crystal plasticity:
3
+ :mod:`morphogen.homogenization.crystal`; porous plasticity:
4
+ :mod:`morphogen.homogenization.porous`).
5
+
6
+ The model of Lemaitre & Chaboche (1990), in small strains, with isotropic elasticity
7
+ (``sigma = D (eps - eps_th - eps_p)``):
8
+
9
+ * yield function ``f = J(sigma - X) - R(p) - R0``, with ``J`` the von Mises norm
10
+ ``sqrt(3/2 s : s)`` of the deviator;
11
+ * isotropic hardening ``R(p) = H p + sum_i Q_i (1 - exp(-b_i p))`` of the cumulated
12
+ plastic strain ``p``;
13
+ * kinematic hardening ``X = sum_k X_k``, ``dX_k = 2/3 C_k deps_p - D_k X_k dp``
14
+ (Armstrong-Frederick; ``D_k = 0``: linear, Prager);
15
+ * normality ``deps_p = dp n``, ``n = 3/2 (s - X) / J(sigma - X)``;
16
+ * Norton's viscous flow ``dp/dt = <f / K>^N`` (viscoplasticity), or the consistency
17
+ condition ``f = 0`` when there is no viscosity (rate-independent plasticity).
18
+
19
+ The equations are integrated implicitly (backward Euler) over each time step. The
20
+ Armstrong-Frederick backstresses then read ``X_k = theta_k (X_k^n + 2/3 C_k dp n)`` with
21
+ ``theta_k = 1 / (1 + D_k dp)``; the relative stress ``s - X`` is parallel to ``xi* = s_tr
22
+ - sum theta_k X_k^n`` (``s_tr``: the elastic trial deviator), and the whole update reduces
23
+ to one scalar equation for the increment ``dp`` (or, for viscoplasticity, for the
24
+ viscous stress, which is better conditioned near ``dp = 0``), solved by Newton's method
25
+ safeguarded by bisection. Its linearization gives the consistent tangent operator
26
+ ``d sigma / d eps`` of the step (Simo & Taylor 1985), symmetric but for the
27
+ Armstrong-Frederick terms (the backstresses turn the direction of flow: about 1 % of
28
+ its largest entries). The kernels symmetrize it for the conjugate gradient solvers
29
+ (which only removes the round-off of the symmetric laws), or keep it whole for GMRES
30
+ (``symmetric=False``: :mod:`morphogen.homogenization.nonlinear` decides by the laws of
31
+ the phases).
32
+
33
+ Stresses and the internal tensors are stored by their Voigt components ``(11, 22, 33,
34
+ 23, 31, 12)``; strains in the engineering convention of the solvers (shears doubled).
35
+ """
36
+
37
+ from __future__ import annotations
38
+
39
+ import math
40
+ from dataclasses import dataclass
41
+
42
+ import numpy as np
43
+ from numba import njit, prange
44
+
45
+ from morphogen.homogenization.crystal import cp_small, work_block, work_blocks
46
+ from morphogen.homogenization.porous import (
47
+ N_POROUS,
48
+ _porous_set,
49
+ _porous_update,
50
+ _porous_works,
51
+ )
52
+ from morphogen.homogenization.tensors import symmetrize
53
+
54
+ #: Revision of the kernels of the other modules compiled into :func:`update_points`
55
+ #: (crystal, porous). Numba dates the cache of a compiled function by the file that
56
+ #: defines it alone: a change of those kernels comes with a change of this number, and
57
+ #: so of this file, which makes the caches of the earlier versions stale (2: twins and
58
+ #: cleavage planes among the systems of the crystals).
59
+ _KERNELS = 22
60
+
61
+ #: Most nonlinear isotropic terms ``Q (1 - exp(-b p))`` and kinematic terms ``(C, D)``.
62
+ MAX_ISOTROPIC = 3
63
+ MAX_KINEMATIC = 4
64
+ #: Layout of a row of parameters: lambda, mu, R0, H, K, N, then the (Q, b) and (C, D) pairs.
65
+ _KIN = 6 + 2 * MAX_ISOTROPIC
66
+ N_PARAMS = _KIN + 2 * MAX_KINEMATIC
67
+ #: The rows of parameters of the GPU: those of von Mises, then the six coefficients of Hill
68
+ PARAMS_WIDTH = N_PARAMS + 6
69
+ #: Rows of parameters of the kernels of the GPU: those of von Mises and Hill, or of a
70
+ #: porous point
71
+ ROW_WIDTH = max(PARAMS_WIDTH, N_POROUS)
72
+ #: Internal variables of a point: plastic strain (6, tensor components), p, backstresses.
73
+ STATE_P = 6
74
+ STATE_X = 7
75
+ #: Behaviours of the points: elastic, von Mises, crystal plasticity, an MFront behaviour
76
+ #: (integrated by MGIS: :mod:`morphogen.homogenization.mfront`; the kernels skip them),
77
+ #: porous plasticity
78
+ ELASTIC = 0
79
+ PLASTIC = 1
80
+ CRYSTAL = 2
81
+ MFRONT = 3
82
+ POROUS = 4
83
+ HILL = 5 # Hill's criterion
84
+ #: The components of Hill's coefficients in the configurations (those of Z-set's ``hill1``
85
+ #: ... ``hill6``), and their places in the Voigt order of the kernels (11, 22, 33, 23, 31, 12)
86
+ HILL_COMPONENTS = ("11", "22", "33", "12", "23", "31")
87
+ _HILL_VOIGT = {"11": 0, "22": 1, "33": 2, "23": 3, "31": 4, "12": 5}
88
+
89
+
90
+ def kernel_constants(ns: int, width: int) -> dict:
91
+ """The constants of the C ports of the kernels of the points (``behaviours.cu``, for
92
+ the GPU and the MFront sources of crystals in finite strains): the slip systems of the
93
+ arrays of the crystals (NS), the internal variables of a point (WIDTH) and the
94
+ constants of the Python modules."""
95
+ from morphogen.homogenization import crystal as cp
96
+ from morphogen.homogenization import porous as pp
97
+
98
+ assert pp.STATE_P == STATE_P
99
+ porous = {name: getattr(pp, name) for name in (
100
+ "P_CRITERION", "P_F0", "P_Q1", "P_Q2", "P_Q3", "P_SIGMA1", "P_D", "P_QR",
101
+ "P_NUCLEATION", "P_FSTAR", "P_C", "P_F", "P_CAP", "P_NKIN", "P_KIN", "GURSON",
102
+ "ROUSSELIER", "ELLIPTIC", "STATE_FG", "STATE_FN", "STATE_SSTAR", "STATE_BACK")} # fmt: skip
103
+ return {
104
+ "NS": int(ns),
105
+ "WIDTH": int(width),
106
+ "CP_ALPHA": cp.CP_ALPHA,
107
+ "STATE_P": STATE_P,
108
+ "STATE_X": STATE_X,
109
+ "KIN": _KIN,
110
+ "N_PARAMS": N_PARAMS,
111
+ "PARAMS_WIDTH": PARAMS_WIDTH,
112
+ "ROW_WIDTH": ROW_WIDTH,
113
+ "N_CP": len(cp.PARAMS),
114
+ "MAX_ISOTROPIC": MAX_ISOTROPIC,
115
+ "ELASTIC": ELASTIC,
116
+ "PLASTIC": PLASTIC,
117
+ "CRYSTAL": CRYSTAL,
118
+ "MFRONT": MFRONT,
119
+ "HILL": HILL,
120
+ "POROUS": POROUS,
121
+ "POROUS_ISOTROPIC": pp.MAX_ISOTROPIC,
122
+ "POROUS_KINEMATIC": pp.MAX_KINEMATIC,
123
+ **porous,
124
+ "HILL_IT": _HILL_IT,
125
+ "SLIP_FLOOR": float(cp._SLIP_FLOOR),
126
+ "LOCAL_TOL": float(cp._LOCAL_TOL),
127
+ "MAX_LOCAL": cp._MAX_LOCAL,
128
+ "MAX_ROUNDS": cp._MAX_ROUNDS,
129
+ "SHRINK": float(cp._SHRINK),
130
+ "SUBSTEP_LEVELS": cp._SUBSTEP_LEVELS,
131
+ }
132
+
133
+
134
+ def _pairs(value, name: str, first: str, second: str) -> tuple[tuple[float, float], ...]:
135
+ """Pairs of parameters given as a mapping ``{first: .., second: ..}``, a list of such
136
+ mappings, or a list of pairs."""
137
+ if value is None:
138
+ return ()
139
+ items = [value] if isinstance(value, dict) else list(value)
140
+ if items and not isinstance(items[0], (dict, list, tuple)):
141
+ items = [items] # a single pair
142
+ out = []
143
+ for item in items:
144
+ if isinstance(item, dict):
145
+ unknown = set(item) - {first, second}
146
+ if unknown or first not in item or second not in item:
147
+ raise ValueError(f"{name}: each term gives {first} and {second}")
148
+ pair = (item[first], item[second])
149
+ else:
150
+ if len(item) != 2:
151
+ raise ValueError(f"{name}: each term is a pair ({first}, {second})")
152
+ pair = tuple(item)
153
+ out.append((float(pair[0]), float(pair[1])))
154
+ return tuple(out)
155
+
156
+
157
+ @dataclass(frozen=True)
158
+ class Plasticity:
159
+ """Von Mises elasto-(visco)plasticity of an isotropic elastic material.
160
+
161
+ ``yield_stress`` (R0), linear isotropic hardening ``hardening`` (H), nonlinear
162
+ isotropic terms ``isotropic`` (pairs Q, b), kinematic terms ``kinematic`` (pairs
163
+ C, D), and Norton's viscosity ``viscosity`` (K) and exponent ``exponent`` (N) for
164
+ viscoplasticity (rate-independent plasticity without them). Stresses in the units
165
+ of the elastic moduli, times in those of the loading paths.
166
+ """
167
+
168
+ yield_stress: float
169
+ hardening: float = 0.0
170
+ isotropic: tuple[tuple[float, float], ...] = ()
171
+ kinematic: tuple[tuple[float, float], ...] = ()
172
+ viscosity: float | None = None
173
+ exponent: float | None = None
174
+ hill: tuple[float, ...] | None = None
175
+
176
+ def __post_init__(self) -> None:
177
+ r0 = float(self.yield_stress)
178
+ if not (math.isfinite(r0) and r0 >= 0.0):
179
+ raise ValueError(f"yield: a non-negative yield stress, got {self.yield_stress!r}")
180
+ object.__setattr__(self, "yield_stress", r0)
181
+ h = float(self.hardening)
182
+ if not (math.isfinite(h) and h >= 0.0):
183
+ raise ValueError("hardening: a non-negative linear isotropic hardening modulus")
184
+ object.__setattr__(self, "hardening", h)
185
+ iso = _pairs(self.isotropic, "isotropic", "Q", "b")
186
+ kin = _pairs(self.kinematic, "kinematic", "C", "D")
187
+ if len(iso) > MAX_ISOTROPIC:
188
+ raise ValueError(f"isotropic: at most {MAX_ISOTROPIC} terms")
189
+ if len(kin) > MAX_KINEMATIC:
190
+ raise ValueError(f"kinematic: at most {MAX_KINEMATIC} terms")
191
+ for q, b in iso:
192
+ if not (math.isfinite(q) and math.isfinite(b) and b > 0):
193
+ raise ValueError("isotropic: terms (Q, b) with b > 0")
194
+ if q < 0:
195
+ raise ValueError("isotropic: Q >= 0 (no softening)")
196
+ for c, d in kin:
197
+ if not (math.isfinite(c) and math.isfinite(d) and c >= 0 and d >= 0):
198
+ raise ValueError("kinematic: terms (C, D) with C >= 0 and D >= 0")
199
+ object.__setattr__(self, "isotropic", iso)
200
+ object.__setattr__(self, "kinematic", kin)
201
+ if (self.viscosity is None) != (self.exponent is None):
202
+ raise ValueError("norton: give both K and n (or neither: rate-independent)")
203
+ if self.viscosity is not None:
204
+ k, n = float(self.viscosity), float(self.exponent)
205
+ if not (math.isfinite(k) and k > 0):
206
+ raise ValueError("norton: K > 0")
207
+ if not (math.isfinite(n) and n >= 1.0):
208
+ raise ValueError("norton: n >= 1")
209
+ object.__setattr__(self, "viscosity", k)
210
+ object.__setattr__(self, "exponent", n)
211
+ if self.hill is not None:
212
+ object.__setattr__(self, "hill", _hill_coefficients(self.hill))
213
+
214
+ @property
215
+ def viscous(self) -> bool:
216
+ return self.viscosity is not None
217
+
218
+ def yield_stresses(self) -> dict[str, float]:
219
+ """The initial yield stresses in tension along the axes and in shear in their planes
220
+ (``"11"`` ... ``"12"``...): ``R0`` and ``R0 / sqrt(3)`` for von Mises; for Hill's
221
+ criterion, ``R0 sqrt(6 / (4 h11 + h22 + h33))`` along 1 (and its permutations)
222
+ and ``R0 / sqrt(3 h12)`` in the plane 12."""
223
+ h = dict(zip(HILL_COMPONENTS, self.hill or (1.0,) * 6, strict=True))
224
+ r0 = self.yield_stress
225
+ out = {}
226
+ for i, j, k in (("11", "22", "33"), ("22", "33", "11"), ("33", "11", "22")):
227
+ out[i] = r0 * math.sqrt(6.0 / (4.0 * h[i] + h[j] + h[k]))
228
+ for c in ("12", "23", "31"):
229
+ out[c] = r0 / math.sqrt(3.0 * h[c])
230
+ return out
231
+
232
+ def params(self, lam: float, mu: float) -> np.ndarray:
233
+ """Row of parameters of the integration kernels (with Hill's coefficients after
234
+ those of von Mises, in the order of the kernels)."""
235
+ row = np.zeros(N_PARAMS + (6 if self.hill is not None else 0))
236
+ if self.hill is not None:
237
+ for c, value in zip(HILL_COMPONENTS, self.hill, strict=True):
238
+ row[N_PARAMS + _HILL_VOIGT[c]] = value
239
+ row[:4] = (lam, mu, self.yield_stress, self.hardening)
240
+ if self.viscous:
241
+ row[4:6] = (self.viscosity, self.exponent)
242
+ for i, (q, b) in enumerate(self.isotropic):
243
+ row[6 + 2 * i : 8 + 2 * i] = (q, b)
244
+ for k, (c, d) in enumerate(self.kinematic):
245
+ row[_KIN + 2 * k : _KIN + 2 * k + 2] = (c, d)
246
+ return row
247
+
248
+ def to_config(self) -> dict:
249
+ out: dict = {"yield": self.yield_stress}
250
+ if self.hardening:
251
+ out["hardening"] = self.hardening
252
+ if self.isotropic:
253
+ out["isotropic"] = [{"Q": q, "b": b} for q, b in self.isotropic]
254
+ if self.kinematic:
255
+ out["kinematic"] = [{"C": c, "D": d} for c, d in self.kinematic]
256
+ if self.viscous:
257
+ out["norton"] = {"K": self.viscosity, "n": self.exponent}
258
+ if self.hill is not None:
259
+ out["hill"] = dict(zip(HILL_COMPONENTS, self.hill, strict=True))
260
+ return out
261
+
262
+ @classmethod
263
+ def from_config(cls, spec) -> Plasticity:
264
+ """``{yield: R0, hardening: H, isotropic: [{Q, b}...], kinematic: [{C, D}...],
265
+ norton: {K, n}, hill: {11: h11, 22: h22, 33: h33, 12: h12, 23: h23, 31: h31}}``
266
+ (aliases ``R0`` and ``H``; the coefficients of Hill not given are 1)."""
267
+ if isinstance(spec, Plasticity):
268
+ return spec
269
+ if not isinstance(spec, dict):
270
+ raise ValueError(
271
+ "plasticity: a mapping (yield, hardening, isotropic, kinematic, norton)"
272
+ )
273
+ allowed = {"yield", "R0", "hardening", "H", "isotropic", "kinematic", "norton", "hill"}
274
+ unknown = sorted(set(spec) - allowed)
275
+ if unknown:
276
+ raise ValueError(f"plasticity: unknown keys {unknown}; allowed: {sorted(allowed)}")
277
+ if ("yield" in spec) == ("R0" in spec):
278
+ raise ValueError("plasticity: give the yield stress (yield, or R0)")
279
+ if "hardening" in spec and "H" in spec:
280
+ raise ValueError("plasticity: give hardening or H, not both")
281
+ norton = spec.get("norton")
282
+ k = n = None
283
+ if norton is not None:
284
+ if not isinstance(norton, dict) or set(norton) != {"K", "n"}:
285
+ raise ValueError("plasticity.norton: {K: viscosity, n: exponent}")
286
+ k, n = float(norton["K"]), float(norton["n"])
287
+ return cls(
288
+ yield_stress=float(spec.get("yield", spec.get("R0"))),
289
+ hardening=float(spec.get("hardening", spec.get("H", 0.0))),
290
+ isotropic=spec.get("isotropic") or (),
291
+ kinematic=spec.get("kinematic") or (),
292
+ viscosity=k,
293
+ exponent=n,
294
+ hill=spec.get("hill"),
295
+ )
296
+
297
+
298
+ def _hill_coefficients(spec) -> tuple[float, ...]:
299
+ """Hill's coefficients in the order of :data:`HILL_COMPONENTS`, from a mapping of the
300
+ components (those not given are 1) or from six numbers in that order."""
301
+ if isinstance(spec, dict):
302
+ keys = {str(k): v for k, v in spec.items()}
303
+ unknown = sorted(set(keys) - set(HILL_COMPONENTS))
304
+ if unknown:
305
+ raise ValueError(
306
+ f"hill: unknown components {unknown}; the components are "
307
+ f"{', '.join(HILL_COMPONENTS)}"
308
+ )
309
+ values = [keys.get(c, 1.0) for c in HILL_COMPONENTS]
310
+ else:
311
+ values = list(spec)
312
+ if len(values) != 6:
313
+ raise ValueError(
314
+ f"hill: six coefficients ({', '.join(HILL_COMPONENTS)}), or a mapping of them"
315
+ )
316
+ out = tuple(float(v) for v in values)
317
+ if not all(math.isfinite(v) and v > 0.0 for v in out):
318
+ raise ValueError("hill: positive coefficients (1 everywhere: von Mises)")
319
+ return out
320
+
321
+
322
+ # -- integration kernels -----------------------------------------------------------------
323
+
324
+
325
+ @njit(cache=True, inline="always")
326
+ def _ddot(a, b):
327
+ """a : b of two symmetric tensors given by their Voigt components."""
328
+ 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])
329
+
330
+
331
+ @njit(cache=True, inline="always")
332
+ def _hardening(par, p):
333
+ """R(p) and R'(p)."""
334
+ r = par[3] * p
335
+ dr = par[3]
336
+ for i in range(MAX_ISOTROPIC):
337
+ q = par[6 + 2 * i]
338
+ if q != 0.0:
339
+ b = par[7 + 2 * i]
340
+ e = math.exp(-b * p)
341
+ r += q * (1.0 - e)
342
+ dr += q * b * e
343
+ return r, dr
344
+
345
+
346
+ @njit(cache=True, inline="always")
347
+ def _phi(par, nk, s_tr, old, dp, xi, nrm, w):
348
+ """Yield function after a plastic increment ``dp``, without the viscous stress, and
349
+ its derivative; fills ``xi`` (xi*), the flow direction ``nrm`` and ``w = sum D_k
350
+ theta_k^2 X_k^n``. Returns (phi, dphi/ddp, J(xi*))."""
351
+ mu = par[1]
352
+ csum = 0.0
353
+ c2sum = 0.0
354
+ for r in range(6):
355
+ xi[r] = s_tr[r]
356
+ w[r] = 0.0
357
+ for k in range(nk):
358
+ c = par[_KIN + 2 * k]
359
+ d = par[_KIN + 2 * k + 1]
360
+ th = 1.0 / (1.0 + d * dp)
361
+ csum += th * c
362
+ c2sum += th * th * c
363
+ base = STATE_X + 6 * k
364
+ for r in range(6):
365
+ xk = old[base + r]
366
+ xi[r] -= th * xk
367
+ w[r] += d * th * th * xk
368
+ jm = math.sqrt(max(1.5 * _ddot(xi, xi), 0.0))
369
+ inv = 1.5 / jm if jm > 0.0 else 0.0
370
+ for r in range(6):
371
+ nrm[r] = inv * xi[r]
372
+ rr, dr = _hardening(par, old[STATE_P] + dp)
373
+ phi = jm - (3.0 * mu + csum) * dp - rr - par[2]
374
+ dphi = _ddot(nrm, w) - 3.0 * mu - c2sum - dr
375
+ return phi, dphi, jm
376
+
377
+
378
+ @njit(cache=True)
379
+ def _elastic_tangent(lam, mu, tan):
380
+ for r in range(6):
381
+ for c in range(6):
382
+ tan[r, c] = 0.0
383
+ for r in range(3):
384
+ for c in range(3):
385
+ tan[r, c] = lam
386
+ tan[r, r] += 2.0 * mu
387
+ tan[3 + r, 3 + r] = mu
388
+
389
+
390
+ @njit(cache=True)
391
+ def _j2_update(par, nk, eps, eth, dt, old, new, sig, tan, buf, sym=True):
392
+ """Implicit update of a von Mises point over a step ``dt``: strain ``eps``
393
+ (engineering), thermal strain ``eth`` (tensor components). Fills the stress, the new
394
+ internal variables and the tangent (symmetrized with ``sym``); returns 1 if the local
395
+ Newton iteration fails."""
396
+ lam = par[0]
397
+ mu = par[1]
398
+ kv = par[4]
399
+ nv = par[5]
400
+ ee = buf[0]
401
+ s_tr = buf[1]
402
+ xi = buf[2]
403
+ nrm = buf[3]
404
+ w = buf[4]
405
+ d = buf[5]
406
+ dxi = buf[6]
407
+ for r in range(6):
408
+ e = eps[r] if r < 3 else 0.5 * eps[r]
409
+ ee[r] = e - eth[r] - old[r]
410
+ tr = ee[0] + ee[1] + ee[2]
411
+ for r in range(6):
412
+ sig[r] = 2.0 * mu * ee[r]
413
+ for r in range(3):
414
+ sig[r] += lam * tr
415
+ mean = (sig[0] + sig[1] + sig[2]) / 3.0
416
+ for r in range(6):
417
+ s_tr[r] = sig[r] - mean if r < 3 else sig[r]
418
+ n_state = old.shape[0]
419
+ for r in range(n_state):
420
+ new[r] = old[r]
421
+ f_tr, dphi, jm = _phi(par, nk, s_tr, old, 0.0, xi, nrm, w)
422
+ rr0, _ = _hardening(par, old[STATE_P])
423
+ scale = jm + par[2] + abs(rr0) + 1e-300
424
+ if f_tr <= 1e-13 * scale:
425
+ _elastic_tangent(lam, mu, tan)
426
+ return 0
427
+ tol = 1e-12 * scale
428
+ dp = 0.0
429
+ y = 0.0
430
+ converged = False
431
+ if kv > 0.0:
432
+ # viscoplastic: unknown y = (dp / dt)^(1/N), the viscous stress over K
433
+ lo, hi = 0.0, f_tr / kv
434
+ y = 0.5 * hi
435
+ for _ in range(200):
436
+ dp = dt * y**nv
437
+ phi, dphi, jm = _phi(par, nk, s_tr, old, dp, xi, nrm, w)
438
+ res = phi - kv * y
439
+ if abs(res) <= tol:
440
+ converged = True
441
+ break
442
+ if res > 0.0:
443
+ lo = y
444
+ else:
445
+ hi = y
446
+ der = dphi * nv * dt * y ** (nv - 1.0) - kv
447
+ step = y - res / der if der < 0.0 else 0.5 * (lo + hi)
448
+ if not (lo < step < hi):
449
+ step = 0.5 * (lo + hi)
450
+ if abs(step - y) <= 1e-15 * hi:
451
+ y = step
452
+ converged = True
453
+ break
454
+ y = step
455
+ dp = dt * y**nv
456
+ else:
457
+ # rate-independent: unknown dp, bracketed by doubling
458
+ lo, hi = 0.0, f_tr / (3.0 * mu)
459
+ for _ in range(200):
460
+ phi, dphi, jm = _phi(par, nk, s_tr, old, hi, xi, nrm, w)
461
+ if phi < 0.0:
462
+ break
463
+ lo = hi
464
+ hi *= 2.0
465
+ dp = lo + 0.5 * (hi - lo)
466
+ for _ in range(200):
467
+ phi, dphi, jm = _phi(par, nk, s_tr, old, dp, xi, nrm, w)
468
+ if abs(phi) <= tol:
469
+ converged = True
470
+ break
471
+ if phi > 0.0:
472
+ lo = dp
473
+ else:
474
+ hi = dp
475
+ step = dp - phi / dphi if dphi < 0.0 else 0.5 * (lo + hi)
476
+ if not (lo < step < hi):
477
+ step = 0.5 * (lo + hi)
478
+ if abs(step - dp) <= 1e-15 * hi:
479
+ dp = step
480
+ converged = True
481
+ break
482
+ dp = step
483
+ if not converged or not math.isfinite(dp):
484
+ return 1
485
+ phi, dphi, jm = _phi(par, nk, s_tr, old, dp, xi, nrm, w)
486
+ if jm <= 0.0:
487
+ return 1
488
+ # new state and stress
489
+ for r in range(6):
490
+ new[r] = old[r] + dp * nrm[r]
491
+ sig[r] -= 2.0 * mu * dp * nrm[r]
492
+ new[STATE_P] = old[STATE_P] + dp
493
+ for k in range(nk):
494
+ c = par[_KIN + 2 * k]
495
+ th = 1.0 / (1.0 + par[_KIN + 2 * k + 1] * dp)
496
+ base = STATE_X + 6 * k
497
+ for r in range(6):
498
+ new[base + r] = th * (old[base + r] + 2.0 / 3.0 * c * dp * nrm[r])
499
+ # consistent tangent: d dp = 2 mu / h n : d eps
500
+ h = -dphi
501
+ if kv > 0.0 and y > 0.0:
502
+ lg = (1.0 - nv) * math.log(y)
503
+ h = h + (kv / (nv * dt) * math.exp(lg) if lg < 700.0 else math.inf)
504
+ inv_h = 1.0 / h if (h > 0.0 and math.isfinite(h)) else 0.0
505
+ for j in range(6):
506
+ for r in range(6):
507
+ d[r] = 0.0
508
+ d[j] = 1.0 if j < 3 else 0.5
509
+ trd = 1.0 if j < 3 else 0.0
510
+ ddp = 2.0 * mu * _ddot(nrm, d) * inv_h
511
+ for r in range(6):
512
+ dev = d[r] - trd / 3.0 if r < 3 else d[r]
513
+ dxi[r] = 2.0 * mu * dev + w[r] * ddp
514
+ ndxi = _ddot(nrm, dxi)
515
+ for r in range(6):
516
+ dn = 1.5 / jm * (dxi[r] - 2.0 / 3.0 * nrm[r] * ndxi)
517
+ ds = 2.0 * mu * d[r] - 2.0 * mu * (ddp * nrm[r] + dp * dn)
518
+ if r < 3:
519
+ ds += lam * trd
520
+ tan[r, j] = ds
521
+ if sym:
522
+ symmetrize(tan)
523
+ return 0
524
+
525
+
526
+ # -- Hill's criterion --------------------------------------------------------------------
527
+
528
+ _SQ2 = math.sqrt(2.0)
529
+ _HILL_IT = 60 # Newton iterations of a Hill point
530
+
531
+
532
+ @njit(cache=True)
533
+ def _hill_matrix(h, a):
534
+ """``a = 3/2 P M P`` in Mandel's notation (``P``: the deviatoric projector, ``M =
535
+ diag(h)``), so that ``J_H^2 = x . a . x`` for the relative stress ``x``."""
536
+ for r in range(6):
537
+ for c in range(6):
538
+ a[r, c] = 0.0
539
+ for r in range(3):
540
+ for c in range(3):
541
+ acc = 0.0
542
+ for k in range(3):
543
+ acc += ((r == k) - 1.0 / 3.0) * h[k] * ((c == k) - 1.0 / 3.0)
544
+ a[r, c] = 1.5 * acc
545
+ for r in range(3, 6):
546
+ a[r, r] = 1.5 * h[r]
547
+
548
+
549
+ @njit(cache=True)
550
+ def _hill_system(par, nk, a, s_tr, xn, p0, de, q, dt, res, jac, sr, nrm, w, nn):
551
+ """Residuals of a Hill update ``(de, q)`` and their Jacobian (Mandel's notation):
552
+ ``de - dp n`` and ``J_H - R(p) - R0 - K q``, the unknown ``q`` being ``dp``, or the
553
+ viscous stress over K, ``(dp / dt)^(1/N)``, with a viscosity. Fills the relative stress
554
+ ``sr``, the normal ``nrm``, ``w = d sr / d dp`` and ``nn = d n / d sr``; returns
555
+ ``(J_H, dp, d dp / d q)``, or J_H = 0 where the normal is not defined."""
556
+ lam = par[0]
557
+ mu = par[1]
558
+ kv = par[4]
559
+ nv = par[5]
560
+ if kv > 0.0:
561
+ dp = dt * q**nv
562
+ ddp = nv * dt * q ** (nv - 1.0) if q > 0.0 else (dt if nv == 1.0 else 0.0)
563
+ else:
564
+ dp = q
565
+ ddp = 1.0
566
+ cb = 0.0
567
+ cdb = 0.0
568
+ for r in range(6):
569
+ sr[r] = s_tr[r]
570
+ w[r] = 0.0
571
+ for k in range(nk):
572
+ c = par[_KIN + 2 * k]
573
+ d = par[_KIN + 2 * k + 1]
574
+ th = 1.0 / (1.0 + d * dp)
575
+ cb += 2.0 / 3.0 * th * c
576
+ cdb += 2.0 / 3.0 * c * d * th * th
577
+ for r in range(6):
578
+ sr[r] -= th * xn[k, r]
579
+ w[r] += d * th * th * xn[k, r]
580
+ tr = de[0] + de[1] + de[2]
581
+ for r in range(6):
582
+ b = (2.0 * mu + cb) * de[r] + (lam * tr if r < 3 else 0.0)
583
+ sr[r] -= b
584
+ w[r] += cdb * de[r]
585
+ jj = 0.0
586
+ for r in range(6):
587
+ acc = 0.0
588
+ for c in range(6):
589
+ acc += a[r, c] * sr[c]
590
+ nrm[r] = acc
591
+ jj += acc * sr[r]
592
+ if not jj > 0.0:
593
+ return 0.0, dp, ddp
594
+ jh = math.sqrt(jj)
595
+ for r in range(6):
596
+ nrm[r] /= jh
597
+ for r in range(6):
598
+ for c in range(6):
599
+ nn[r, c] = (a[r, c] - nrm[r] * nrm[c]) / jh
600
+ rr, dr = _hardening(par, p0 + dp)
601
+ for r in range(6):
602
+ res[r] = de[r] - dp * nrm[r]
603
+ res[6] = jh - rr - par[2] - (kv * q if kv > 0.0 else 0.0)
604
+ # d res / d de = I + dp nn B, with B = (2 mu + cb) I + lam 1 1 (on the normal terms)
605
+ for r in range(6):
606
+ rows = 0.0
607
+ for c in range(3):
608
+ rows += nn[r, c]
609
+ for c in range(6):
610
+ jac[r, c] = dp * ((2.0 * mu + cb) * nn[r, c] + (lam * rows if c < 3 else 0.0))
611
+ jac[r, r] += 1.0
612
+ acc = 0.0
613
+ for c in range(6):
614
+ acc += nn[r, c] * w[c]
615
+ jac[r, 6] = (-nrm[r] - dp * acc) * ddp
616
+ ntr = nrm[0] + nrm[1] + nrm[2]
617
+ nw = 0.0
618
+ for c in range(6):
619
+ jac[6, c] = -((2.0 * mu + cb) * nrm[c] + (lam * ntr if c < 3 else 0.0))
620
+ nw += nrm[c] * w[c]
621
+ jac[6, 6] = (nw - dr) * ddp - (kv if kv > 0.0 else 0.0)
622
+ return jh, dp, ddp
623
+
624
+
625
+ @njit(cache=True)
626
+ def _solve_in_place(a, b):
627
+ """``a x = b`` for the columns of ``b``, by Gauss's elimination with partial pivoting
628
+ (``a`` and ``b`` overwritten, ``x`` left in ``b``); False if ``a`` is singular."""
629
+ n = a.shape[0]
630
+ for k in range(n):
631
+ piv = k
632
+ for r in range(k + 1, n):
633
+ if abs(a[r, k]) > abs(a[piv, k]):
634
+ piv = r
635
+ if not abs(a[piv, k]) > 0.0:
636
+ return False
637
+ if piv != k:
638
+ for c in range(n):
639
+ a[k, c], a[piv, c] = a[piv, c], a[k, c]
640
+ for c in range(b.shape[1]):
641
+ b[k, c], b[piv, c] = b[piv, c], b[k, c]
642
+ for r in range(k + 1, n):
643
+ f = a[r, k] / a[k, k]
644
+ if f != 0.0:
645
+ for c in range(k, n):
646
+ a[r, c] -= f * a[k, c]
647
+ for c in range(b.shape[1]):
648
+ b[r, c] -= f * b[k, c]
649
+ for k in range(n - 1, -1, -1):
650
+ for c in range(b.shape[1]):
651
+ acc = b[k, c]
652
+ for j in range(k + 1, n):
653
+ acc -= a[k, j] * b[j, c]
654
+ b[k, c] = acc / a[k, k]
655
+ return True
656
+
657
+
658
+ @njit(cache=True)
659
+ def _hill_works(count):
660
+ """``count`` sets of the work arrays of :func:`_hill_update`: the vectors, the
661
+ matrices of 6 x 6 and of 7 x 7, the backstresses, the residuals, the right-hand sides
662
+ of the tangent and the Newton step, with one more axis, the first one. The loops over
663
+ the points allocate a set per chunk of points before their parallel loop, and take
664
+ that of each chunk (:func:`_hill_set`): rows of arrays allocated in the loop would
665
+ count their references (:func:`morphogen.homogenization.crystal.work_block`)."""
666
+ return (
667
+ np.empty((count, 9, 6)),
668
+ np.empty((count, 3, 6, 6)),
669
+ np.empty((count, MAX_KINEMATIC, 6)),
670
+ np.empty((count, 7)),
671
+ np.empty((count, 2, 7, 7)),
672
+ np.empty((count, 7, 6)),
673
+ np.empty((count, 7, 1)),
674
+ )
675
+
676
+
677
+ @njit(cache=True)
678
+ def _hill_set(works, k):
679
+ """The set ``k`` of the work arrays of :func:`_hill_works` (views)."""
680
+ return (works[0][k], works[1][k], works[2][k], works[3][k], works[4][k], works[5][k],
681
+ works[6][k]) # fmt: skip
682
+
683
+
684
+ @njit(cache=True)
685
+ def _hill_work():
686
+ """Work arrays of :func:`_hill_update` (a set of :func:`_hill_works`)."""
687
+ return _hill_set(_hill_works(1), 0)
688
+
689
+
690
+ @njit(cache=True)
691
+ def _hill_update(par, nk, eps, eth, dt, old, new, sig, tan, wk, sym=True):
692
+ """Implicit update of a point of Hill's criterion over a step ``dt`` (see
693
+ :class:`Plasticity`): strain ``eps`` (engineering), thermal strain ``eth`` (tensor
694
+ components), work arrays ``wk`` (:func:`_hill_work`). Fills the stress, the new internal
695
+ variables and the tangent (symmetrized with ``sym``); returns 1 if the local Newton
696
+ iteration fails."""
697
+ lam = par[0]
698
+ mu = par[1]
699
+ kv = par[4]
700
+ nv = par[5]
701
+ vec, mat6, xn, res, mat7, rhs, step = wk
702
+ f = vec[0] # Mandel's factors
703
+ h = vec[1]
704
+ s_tr = vec[2]
705
+ ee = vec[3]
706
+ sr = vec[4]
707
+ nrm = vec[5]
708
+ w = vec[6]
709
+ de = vec[7]
710
+ trial_de = vec[8]
711
+ a = mat6[0]
712
+ nn = mat6[1]
713
+ cm = mat6[2]
714
+ jac = mat7[0]
715
+ work = mat7[1]
716
+ for r in range(6):
717
+ f[r] = 1.0 if r < 3 else _SQ2
718
+ h[r] = par[N_PARAMS + r]
719
+ _hill_matrix(h, a)
720
+ # the elastic trial (Mandel)
721
+ for r in range(6):
722
+ e = eps[r] if r < 3 else 0.5 * eps[r]
723
+ ee[r] = e - eth[r] - old[r]
724
+ tr = ee[0] + ee[1] + ee[2]
725
+ for r in range(6):
726
+ s_tr[r] = f[r] * (2.0 * mu * ee[r] + (lam * tr if r < 3 else 0.0))
727
+ for k in range(nk):
728
+ for r in range(6):
729
+ xn[k, r] = f[r] * old[STATE_X + 6 * k + r]
730
+ for r in range(old.shape[0]):
731
+ new[r] = old[r]
732
+ p0 = old[STATE_P]
733
+ for r in range(6):
734
+ de[r] = 0.0
735
+ jh, dp, _ddp = _hill_system(par, nk, a, s_tr, xn, p0, de, 0.0, dt, res, jac, sr, nrm, w, nn)
736
+ f_tr = res[6] if jh > 0.0 else -1.0
737
+ rr0, dr0 = _hardening(par, p0)
738
+ scale = jh + par[2] + abs(rr0) + 1e-300
739
+ if f_tr <= 1e-13 * scale:
740
+ _elastic_tangent(lam, mu, tan)
741
+ for r in range(6):
742
+ sig[r] = s_tr[r] / f[r]
743
+ return 0
744
+ # first guess: the plastic increment of the elastic predictor along its normal
745
+ stiff = 0.0
746
+ ntr = nrm[0] + nrm[1] + nrm[2]
747
+ for r in range(6):
748
+ stiff += nrm[r] * (2.0 * mu * nrm[r] + (lam * ntr if r < 3 else 0.0))
749
+ for k in range(nk):
750
+ stiff += 2.0 / 3.0 * par[_KIN + 2 * k] * (nrm @ nrm)
751
+ dp = f_tr / (stiff + max(dr0, 0.0))
752
+ q = min((dp / dt) ** (1.0 / nv), f_tr / kv) if kv > 0.0 else dp
753
+ if kv > 0.0:
754
+ dp = dt * q**nv
755
+ for r in range(6):
756
+ de[r] = dp * nrm[r]
757
+ e_scale = f_tr / (3.0 * mu) + 1e-300
758
+ jh, dp, _ddp = _hill_system(par, nk, a, s_tr, xn, p0, de, q, dt, res, jac, sr, nrm, w, nn)
759
+ if jh <= 0.0:
760
+ return 1
761
+ converged = False
762
+ for _it in range(_HILL_IT):
763
+ merit = 0.0
764
+ for r in range(6):
765
+ merit += (res[r] / e_scale) ** 2
766
+ merit += (res[6] / scale) ** 2
767
+ big = 0.0
768
+ for r in range(6):
769
+ big = max(big, abs(res[r]))
770
+ if big <= 1e-12 * e_scale and abs(res[6]) <= 1e-12 * scale:
771
+ converged = True
772
+ break
773
+ for r in range(7):
774
+ step[r, 0] = -res[r]
775
+ for c in range(7):
776
+ work[r, c] = jac[r, c]
777
+ if not _solve_in_place(work, step):
778
+ return 1
779
+ # backtracking on the scaled residuals: the system of the accepted point is that of
780
+ # the next iteration
781
+ alpha = 1.0
782
+ accepted = False
783
+ qt = q
784
+ dpt = dp
785
+ for _ls in range(16):
786
+ qt = q + alpha * step[6, 0]
787
+ if qt < 0.0:
788
+ alpha *= 0.5
789
+ continue
790
+ for r in range(6):
791
+ trial_de[r] = de[r] + alpha * step[r, 0]
792
+ jt, dpt, _ddpt = _hill_system(par, nk, a, s_tr, xn, p0, trial_de, qt, dt, res, jac,
793
+ sr, nrm, w, nn) # fmt: skip
794
+ if jt > 0.0:
795
+ m = 0.0
796
+ for r in range(6):
797
+ m += (res[r] / e_scale) ** 2
798
+ m += (res[6] / scale) ** 2
799
+ if m <= (1.0 - 1e-4 * alpha) * merit:
800
+ accepted = True
801
+ break
802
+ alpha *= 0.5
803
+ if not accepted:
804
+ return 1
805
+ q = qt
806
+ dp = dpt
807
+ for r in range(6):
808
+ de[r] = trial_de[r]
809
+ if not converged or not math.isfinite(dp):
810
+ return 1
811
+ # new state and stress (tensor components)
812
+ tr = de[0] + de[1] + de[2]
813
+ for r in range(6):
814
+ new[r] = old[r] + de[r] / f[r]
815
+ sig[r] = (s_tr[r] - (2.0 * mu * de[r] + (lam * tr if r < 3 else 0.0))) / f[r]
816
+ new[STATE_P] = p0 + dp
817
+ for k in range(nk):
818
+ th = 1.0 / (1.0 + par[_KIN + 2 * k + 1] * dp)
819
+ c = par[_KIN + 2 * k]
820
+ for r in range(6):
821
+ new[STATE_X + 6 * k + r] = th * (xn[k, r] + 2.0 / 3.0 * c * de[r]) / f[r]
822
+ # consistent tangent: jac d(de, q) = -d res / d eps_m, d sigma = C (d eps_m - d de)
823
+ for r in range(6):
824
+ for c in range(6):
825
+ cm[r, c] = (2.0 * mu if r == c else 0.0) + (lam if r < 3 and c < 3 else 0.0)
826
+ for c in range(6):
827
+ for r in range(6):
828
+ acc = 0.0
829
+ for j in range(6):
830
+ acc += nn[r, j] * cm[j, c]
831
+ rhs[r, c] = dp * acc
832
+ acc = 0.0
833
+ for j in range(6):
834
+ acc += nrm[j] * cm[j, c]
835
+ rhs[6, c] = -acc
836
+ for r in range(7):
837
+ for c in range(7):
838
+ work[r, c] = jac[r, c]
839
+ if not _solve_in_place(work, rhs):
840
+ return 1
841
+ for r in range(6):
842
+ for c in range(6):
843
+ acc = cm[r, c]
844
+ for j in range(6):
845
+ acc -= cm[r, j] * rhs[j, c]
846
+ tan[r, c] = acc / (f[r] * f[c])
847
+ if sym:
848
+ symmetrize(tan)
849
+ return 0
850
+
851
+
852
+ @njit(cache=True)
853
+ def point_chunks(n):
854
+ """Number of the chunks of consecutive points that the threads integrate, each with
855
+ work arrays of its own: 64 points or more per chunk, 128 chunks at most."""
856
+ return min(max(n // 64, 1), 128)
857
+
858
+
859
+ @njit(parallel=True, cache=True)
860
+ def update_points(kind, mat, pmat, data, eps, dtemp, dt, old, new, sigma, tangent, guess, ratio,
861
+ symmetric=True): # fmt: skip
862
+ """Stress, internal variables and tangent of every integration point for the strains
863
+ ``eps`` (engineering) at the end of a step ``dt``, from the internal variables
864
+ ``old`` at its start, at the change of temperature ``dtemp``.
865
+
866
+ ``data``: the elasticity matrices of the materials (in the axes of the sample) and
867
+ their thermal strains per unit change of temperature (engineering), the rows of the
868
+ von Mises and porous parameters and the number of backstresses, and for crystal
869
+ plasticity the
870
+ slip systems of each material (slip direction, plane normal; axes of the sample), the
871
+ parameters of each system, the interaction matrices and the numbers of systems
872
+ (:func:`morphogen.homogenization.nonlinear.behaviour_table`). Points use the material
873
+ ``mat`` and the row of parameters ``pmat`` of their behaviour ``kind``. ``guess`` and
874
+ ``ratio``: initial slips of the crystal points (:func:`morphogen.homogenization.
875
+ crystal.cp_small`). ``symmetric``: the consistent tangents symmetrized (for the
876
+ conjugate gradients), or kept whole (for a nonsymmetric solver). Returns the number of
877
+ points whose integration failed."""
878
+ matrices, eigen, params, nk, systems, cp_par, cp_h, cp_n = data
879
+ n = eps.shape[0]
880
+ n_chunks = point_chunks(n)
881
+ failed = np.zeros(n_chunks, dtype=np.int64)
882
+ # the work arrays of the laws, a set per chunk of points: allocated before the
883
+ # parallel loop, which holds them as plain memory (crystal.work_block)
884
+ blocks = work_blocks(n_chunks, cp_par.shape[1])
885
+ bufs = np.empty((n_chunks, 7, 6))
886
+ vectors = np.empty((n_chunks, 2, 6))
887
+ hws = _hill_works(n_chunks)
888
+ pws = _porous_works(n_chunks)
889
+ for ch in prange(n_chunks):
890
+ buf = bufs[ch]
891
+ mech = vectors[ch, 0]
892
+ eth = vectors[ch, 1]
893
+ work = work_block(blocks, ch)
894
+ hw = _hill_set(hws, ch)
895
+ pw = _porous_set(pws, ch)
896
+ for i in range(ch * n // n_chunks, (ch + 1) * n // n_chunks):
897
+ m = mat[i]
898
+ k = kind[i]
899
+ if k == MFRONT:
900
+ continue
901
+ if k == ELASTIC:
902
+ dm = matrices[m]
903
+ for r in range(6):
904
+ mech[r] = eps[i, r] - dtemp * eigen[m, r]
905
+ for r in range(6):
906
+ s = 0.0
907
+ for c in range(6):
908
+ s += dm[r, c] * mech[c]
909
+ tangent[i, r, c] = dm[r, c]
910
+ sigma[i, r] = s
911
+ continue
912
+ for r in range(6):
913
+ eth[r] = dtemp * eigen[m, r] * (1.0 if r < 3 else 0.5)
914
+ if k == PLASTIC:
915
+ failed[ch] += _j2_update(params[pmat[i]], nk, eps[i], eth, dt, old[i], new[i],
916
+ sigma[i], tangent[i], buf, symmetric) # fmt: skip
917
+ elif k == HILL:
918
+ failed[ch] += _hill_update(params[pmat[i]], nk, eps[i], eth, dt, old[i],
919
+ new[i], sigma[i], tangent[i], hw,
920
+ symmetric) # fmt: skip
921
+ elif k == POROUS:
922
+ failed[ch] += _porous_update(params[pmat[i]], eps[i], eth, dt, old[i], new[i],
923
+ sigma[i], tangent[i], pw, symmetric) # fmt: skip
924
+ else:
925
+ c = pmat[i]
926
+ # (the Schmid tensors of a material are kept from a point to the next)
927
+ failed[ch] += cp_small(systems[m], cp_par[c], cp_h[c], cp_n[c], matrices[m],
928
+ eps[i], eth, dt, old[i], new[i], sigma[i], tangent[i],
929
+ guess, ratio, work, symmetric, m) # fmt: skip
930
+ return int(failed.sum())
931
+
932
+
933
+ def mises(stress) -> np.ndarray:
934
+ """Von Mises equivalent stress of Voigt stress components (..., 6)."""
935
+ s = np.asarray(stress, dtype=float)
936
+ mean = s[..., :3].mean(axis=-1, keepdims=True)
937
+ dev = s[..., :3] - mean
938
+ shear = s[..., 3:]
939
+ return np.sqrt(1.5 * (np.sum(dev * dev, axis=-1) + 2.0 * np.sum(shear * shear, axis=-1)))
940
+
941
+
942
+ def state_width(n_kinematic: int) -> int:
943
+ """Number of internal variables of a point with ``n_kinematic`` backstresses."""
944
+ return STATE_X + 6 * int(n_kinematic)