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,787 @@
1
+ """The microfoam model: anisotropic compressible plasticity of metallic foams in a
2
+ micromorphic continuum (Dillard, Forest & Ienny 2006, after Forest & Lorentz 2004 and
3
+ Forest et al. 2005), in small strains.
4
+
5
+ *Compressible plasticity* (Badiche et al. 2000). ``ε = ε^e + ε^p``, ``σ = C : ε^e`` with
6
+ orthotropic elasticity ``C``; the yield function ``f = σ_eq - Y(p)`` with ``σ_eq² = (3c/2)
7
+ σ' : H : σ' + F (P : σ)²`` (``σ'`` the deviator; in the axes of the sheet, ``H =
8
+ diag(H_a, H_b, H_c)`` on the normal components and ``H_d, H_e, H_f`` on the shears 12,
9
+ 23, 31, ``P = diag(P, Q, R)``): Hill's criterion when ``F = 0``, the isotropic elliptic
10
+ criterion of powder metallurgy and foams (Besson & Abouaf 1989; Deshpande & Fleck 2000)
11
+ when ``H = 1``, ``P = 1``. Associative flow ``ε̇^p = ṗ ∂σ_eq/∂σ`` (``σ : ε̇^p = σ_eq ṗ``),
12
+ hardening ``Y = σ0 + Q1 (1 - exp(-b1 p)) + Q2 (1 - exp(-b2 p)) + H p`` (at least 0.1 % of
13
+ σ0), and for fracture a
14
+ softening beyond a critical ``p_c``: ``Y`` times ``r + (1 - r) exp(-((p - p_c)/w)²)``
15
+ (the article's branch, "a parabolic and an exponential term", is not given in closed
16
+ form: ours starts with a zero slope and tends to the residual fraction ``r``). The
17
+ quadratic criterion makes the implicit update a scalar equation: with ``λ = Δp /
18
+ σ_eq`` and ``M`` the matrix of the quadratic form, ``σ = (C⁻¹ + λ M)⁻¹ : (ε - ε^p_n)``
19
+ and ``σ_eq(λ) = Y(p_n + λ σ_eq(λ))``, solved by a safeguarded Newton method; the
20
+ consistent tangent is ``Ξ - (1 - λY') (Ξn) ⊗ (Ξn) / (Y' + (1 - λY') n:Ξ:n)``, ``Ξ = (C⁻¹ +
21
+ λM)⁻¹``, ``n = M:σ / σ_eq``.
22
+
23
+ *Micromorphic continuum* (Eringen & Suhubi 1964, Mindlin 1964; Forest & Sievert 2003):
24
+ the displacement ``u`` and a full, non-symmetric microdeformation ``χ``; the strain ``ε``,
25
+ the relative deformation ``e = ∇u - χ`` and the microdeformation gradient ``K = ∇χ``
26
+ (``K_ijk = χ_ij,k``), with the power of internal forces ``σ : ε̇ + s : ė + S ⋮ K̇``; the
27
+ balance equations ``div(σ + s) = 0`` and ``div S + s = 0``, the tractions ``(σ + s) · n``
28
+ and the double tractions ``S · n``. The plasticity concerns ``σ`` only; the relative and
29
+ higher-order stresses are linear and isotropic, ``s = λ_s tr(e) 1 + 2μ_s e^sym + 2μ_c
30
+ e^skew`` and ``S_ijk = l_c² (λ δ_ij K_llk + 2μ K_ijk)``: the moduli ``λ_s, μ_s, μ_c``
31
+ penalize the departure of the microdeformation from the deformation (the model tends to
32
+ a second gradient one as they grow), ``λ, μ`` are of the order of the elastic moduli and
33
+ ``l_c`` is the characteristic length. In one dimension (``χ_22(x_2)`` only), the
34
+ microdeformation follows ``χ''' = ω² χ'`` with ``ω² = k_s E_t / ((k_s + E_t) A l_c²)``,
35
+ ``k_s = λ_s + 2μ_s``, ``A = λ + 2μ`` and ``E_t`` the tangent modulus: boundary layers of
36
+ length ``1/ω`` in hardening, sine-shaped localization bands of wavelength ``2π/|ω|``
37
+ when ``E_t < 0`` (the article's Appendix A, ``λ_s = λ = 0``, ``μ_s = μ_c = μ``).
38
+
39
+ *Elements* (:mod:`morphogen.micromorphic.space`): quadratic displacements and linear
40
+ microdeformations on tetrahedra; the article used quadratic elements with reduced
41
+ integration in plane stress. A classical continuum (no ``l_c``) has the displacements
42
+ only.
43
+
44
+ *Finite strains* (``kinematics="finite"``, total Lagrangian; :mod:`morphogen.micromorphic.
45
+ finite`, after Forest & Sievert 2003 and Forest 2009): the compressible plasticity acts on
46
+ the logarithmic strain ``ε = 1/2 ln C`` and its conjugate stress ``T`` exactly as on the
47
+ small strain and the Cauchy stress (orthotropic elasticity, the criterion, the flow and
48
+ the hardening; the plastic strain additive in ``ε``, its volume change ``tr ε^p`` the
49
+ logarithm of the plastic change of volume: the densification of the foam), pulled back to
50
+ the Piola-Kirchhoff stresses; the microdeformation ``χ = 1 + χ̃`` enters through the
51
+ objective measures ``Υ = χ⁻¹ F`` (relative, ``e = Υ - 1``) and ``K = χ⁻¹ Grad χ`` (higher
52
+ order), with the linear isotropic laws of small strains in them. The generalized degrees
53
+ of freedom remain ``χ̃`` (zero at rest), and the formulation reduces to that of small
54
+ strains for small strains. The tangent of an element is exact for the macroscopic part
55
+ and the central differences of the exact gradient of the micromorphic energy at its
56
+ points.
57
+ """
58
+
59
+ from __future__ import annotations
60
+
61
+ import math
62
+ from dataclasses import dataclass
63
+
64
+ import numpy as np
65
+ from numba import njit, prange
66
+
67
+ from morphogen.homogenization.fe import _corner_gradients, _shape_gradients
68
+ from morphogen.mesh.tetra import TetMesh
69
+ from morphogen.micromorphic.finite import N_Z, PAIRS, hencky, micro_hessian, pull_back
70
+ from morphogen.micromorphic.space import CHUNK, POINTS, WEIGHTS, MixedProblem, MixedSpace
71
+
72
+ #: Mandel components: (11, 22, 33, 23, 31, 12), shears times sqrt(2)
73
+ _PAIRS = ((0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (0, 1))
74
+ _MAP = np.array([[0, 5, 4], [5, 1, 3], [4, 3, 2]], dtype=np.int64)
75
+ _W = np.array([1.0, 1.0, 1.0, math.sqrt(2.0), math.sqrt(2.0), math.sqrt(2.0)])
76
+ #: The internal variables of a point: the plastic strain (Mandel) and p
77
+ N_STATE = 7
78
+ #: Components of the microdeformation: chi_ij is generalized degree of freedom 3 i + j
79
+ CHI = {f"chi{i + 1}{j + 1}": 3 + 3 * i + j for i in range(3) for j in range(3)}
80
+
81
+
82
+ def _mandel(voigt: np.ndarray) -> np.ndarray:
83
+ """A Voigt matrix (engineering shear strains) as a Mandel matrix."""
84
+ return _W[:, None] * np.asarray(voigt, dtype=float) * _W[None, :]
85
+
86
+
87
+ def _mandel_rotation(axes: np.ndarray) -> np.ndarray:
88
+ """The Mandel matrix of the change of axes ``A_global = R^T A_material R`` (rows of
89
+ ``R``: the material axes in the global frame)."""
90
+ r = np.asarray(axes, dtype=float)
91
+ q = np.empty((6, 6))
92
+ for j, (k, m) in enumerate(_PAIRS):
93
+ basis = np.zeros((3, 3))
94
+ basis[k, m] = basis[m, k] = 1.0 / _W[j] if k != m else 1.0
95
+ turned = r.T @ basis @ r
96
+ q[:, j] = [turned[a, b] * _W[i] for i, (a, b) in enumerate(_PAIRS)]
97
+ return q
98
+
99
+
100
+ @dataclass(frozen=True)
101
+ class Microfoam:
102
+ """A material of the microfoam model (see the module), in MPa and mm or any
103
+ consistent units: elasticity ``stiffness`` (6 x 6 Voigt matrix in the material axes,
104
+ order (11, 22, 33, 23, 31, 12), engineering shear strains) or ``young`` and
105
+ ``poisson``; the criterion ``c``, ``F``, ``H`` (``H_a, H_b, H_c, H_d, H_e, H_f``: the
106
+ normal components, then the shears 12, 23, 31, as the article) and ``P`` (``P, Q,
107
+ R``); hardening ``yield_stress`` σ0 (infinite: elastic), ``voce`` ((Q1, b1), (Q2,
108
+ b2)...) and the linear ``hardening`` H; ``softening`` (p_c, r, w) or None; the
109
+ material ``axes`` (rows, in the global frame; default: the global axes); and the
110
+ micromorphic ``length`` l_c (None: a classical continuum), the higher-order moduli
111
+ ``micro`` (λ, μ) and the relative moduli ``relative`` (λ_s, μ_s, μ_c)."""
112
+
113
+ young: float | None = None
114
+ poisson: float | None = None
115
+ stiffness: tuple | None = None
116
+ yield_stress: float = math.inf
117
+ voce: tuple = ()
118
+ hardening: float = 0.0
119
+ c: float = 1.0
120
+ F: float = 0.0
121
+ H: tuple = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
122
+ P: tuple = (1.0, 1.0, 1.0)
123
+ softening: tuple | None = None
124
+ axes: tuple | None = None
125
+ length: float | None = None
126
+ micro: tuple = (0.0, 0.0)
127
+ relative: tuple = (0.0, 0.0, 0.0)
128
+
129
+ def __post_init__(self) -> None:
130
+ if self.stiffness is None and (self.young is None or self.poisson is None):
131
+ raise ValueError("Microfoam: a stiffness, or young and poisson")
132
+ if len(self.voce) > 2:
133
+ raise ValueError("Microfoam: at most two Voce terms")
134
+ if len(self.H) != 6 or len(self.P) != 3:
135
+ raise ValueError("Microfoam: six H and three P")
136
+ if self.length is not None and not self.length >= 0:
137
+ raise ValueError("Microfoam: a non-negative length")
138
+
139
+ @classmethod
140
+ def nickel_foam(cls, length: float | None = 0.1, axes=None, softening=None) -> Microfoam:
141
+ """The nickel foam of relative density 0.035 of the article (MPa, mm; axes RD, TD,
142
+ ND): its Tables 2 (the in-plane elastic moduli of plane stress, completed by a
143
+ decoupled thickness, ``C13 = C23 = 0``) and 3 (``l_c = 0.1`` mm from the hole size
144
+ effect; 0.06 mm from the cracked panels)."""
145
+ stiffness = np.zeros((6, 6))
146
+ stiffness[0, 0], stiffness[0, 1], stiffness[1, 1] = 464.0, 172.0, 239.0
147
+ stiffness[1, 0] = 172.0
148
+ stiffness[2, 2] = 239.0
149
+ stiffness[3, 3] = stiffness[4, 4] = stiffness[5, 5] = 105.0
150
+ return cls(
151
+ stiffness=tuple(map(tuple, stiffness)),
152
+ yield_stress=0.3,
153
+ voce=((0.51, 611.0), (7442.0, 0.0013)),
154
+ c=1.0,
155
+ F=0.000682,
156
+ H=(0.41, 1.8, 1.75, 1.49, 1.0, 1.0),
157
+ P=(1.0, 36.6, 22.6),
158
+ softening=softening,
159
+ axes=axes,
160
+ length=length,
161
+ micro=(111.0, 167.0),
162
+ relative=(11000.0, 17000.0, 10000.0),
163
+ )
164
+
165
+ def elastic_matrix(self) -> np.ndarray:
166
+ """The Mandel elasticity matrix in the global axes."""
167
+ if self.stiffness is not None:
168
+ voigt = np.asarray(self.stiffness, dtype=float)
169
+ else:
170
+ lam = self.young * self.poisson / ((1 + self.poisson) * (1 - 2 * self.poisson))
171
+ mu = self.young / (2 * (1 + self.poisson))
172
+ voigt = np.zeros((6, 6))
173
+ voigt[:3, :3] = lam
174
+ voigt[np.arange(3), np.arange(3)] += 2 * mu
175
+ voigt[np.arange(3, 6), np.arange(3, 6)] = mu
176
+ c = _mandel(voigt)
177
+ if self.axes is not None:
178
+ q = _mandel_rotation(self.axes)
179
+ c = q @ c @ q.T
180
+ return c
181
+
182
+ def criterion_matrix(self) -> np.ndarray:
183
+ """The Mandel matrix ``M`` of ``σ_eq² = σ : M : σ`` in the global axes."""
184
+ ha, hb, hc, hd, he, hf = (float(v) for v in self.H)
185
+ dev = np.eye(3) - 1.0 / 3.0
186
+ m = np.zeros((6, 6))
187
+ m[:3, :3] = 1.5 * self.c * dev @ np.diag([ha, hb, hc]) @ dev
188
+ m[3, 3], m[4, 4], m[5, 5] = 1.5 * self.c * he, 1.5 * self.c * hf, 1.5 * self.c * hd
189
+ p = np.array([*map(float, self.P), 0.0, 0.0, 0.0])
190
+ m += self.F * np.outer(p, p)
191
+ if self.axes is not None:
192
+ q = _mandel_rotation(self.axes)
193
+ m = q @ m @ q.T
194
+ return m
195
+
196
+ def hardening_parameters(self) -> np.ndarray:
197
+ voce = list(self.voce) + [(0.0, 0.0)] * (2 - len(self.voce))
198
+ pc, r, w = self.softening if self.softening is not None else (0.0, 1.0, 1.0)
199
+ return np.array([self.yield_stress, voce[0][0], voce[0][1], voce[1][0], voce[1][1],
200
+ self.hardening, pc, r, w]) # fmt: skip
201
+
202
+ def micro_parameters(self) -> np.ndarray:
203
+ length = 0.0 if self.length is None else float(self.length)
204
+ return np.array([length**2, *map(float, self.micro), *map(float, self.relative)])
205
+
206
+ def flow(self, stress) -> np.ndarray:
207
+ """The direction ``∂σ_eq/∂σ`` (3 x 3, global axes) of the plastic flow at a stress
208
+ (3 x 3)."""
209
+ s = np.asarray(stress, dtype=float)
210
+ vec = np.array([s[a, b] * _W[i] for i, (a, b) in enumerate(_PAIRS)])
211
+ m = self.criterion_matrix()
212
+ n = m @ vec / math.sqrt(vec @ m @ vec)
213
+ out = np.empty((3, 3))
214
+ for i, (a, b) in enumerate(_PAIRS):
215
+ out[a, b] = out[b, a] = n[i] / _W[i]
216
+ return out
217
+
218
+ def equivalent(self, stress) -> float:
219
+ """``σ_eq`` of a stress (3 x 3)."""
220
+ s = np.asarray(stress, dtype=float)
221
+ vec = np.array([s[a, b] * _W[i] for i, (a, b) in enumerate(_PAIRS)])
222
+ return float(math.sqrt(vec @ self.criterion_matrix() @ vec))
223
+
224
+
225
+ def characteristic_length(material: Microfoam, tangent_modulus: float) -> float:
226
+ """``1/ω`` of the one-dimensional micromorphic problem (see the module) for a
227
+ tangent modulus ``E_t`` of the uniaxial response: a boundary layer (``E_t > 0``), or
228
+ ``1/|ω|`` with the wavelength ``2π/|ω|`` of a localization band (``E_t < 0``)."""
229
+ lam_h, mu_h = material.micro
230
+ lam_s, mu_s, _ = material.relative
231
+ ks, a = lam_s + 2 * mu_s, lam_h + 2 * mu_h
232
+ omega2 = ks * tangent_modulus / ((ks + tangent_modulus) * a * material.length**2)
233
+ return 1.0 / math.sqrt(abs(omega2))
234
+
235
+
236
+ # -- the point -------------------------------------------------------------------------------
237
+
238
+
239
+ @njit(cache=True)
240
+ def _yield(h, p):
241
+ """``Y(p)`` and ``Y'(p)`` (see the module), at least 0.1 % of σ0."""
242
+ yh = h[0] + h[1] * (1.0 - math.exp(-h[2] * p)) + h[3] * (1.0 - math.exp(-h[4] * p)) + h[5] * p
243
+ dyh = h[1] * h[2] * math.exp(-h[2] * p) + h[3] * h[4] * math.exp(-h[4] * p) + h[5]
244
+ if h[6] > 0.0 and p > h[6]:
245
+ z = (p - h[6]) / h[8]
246
+ ez = math.exp(-z * z)
247
+ g = h[7] + (1.0 - h[7]) * ez
248
+ dg = (1.0 - h[7]) * ez * (-2.0 * z / h[8])
249
+ yh, dyh = yh * g, dyh * g + yh * dg
250
+ if yh < 1e-3 * h[0]:
251
+ return 1e-3 * h[0], 0.0
252
+ return yh, dyh
253
+
254
+
255
+ @njit(cache=True)
256
+ def _plastic_point(cm, cinv, mm, h, eps, epsp_old, p_old, sig, epsp, tan):
257
+ """The implicit update of a point (Mandel vectors): the stress, plastic strain and
258
+ consistent tangent into ``sig``, ``epsp``, ``tan``; returns ``p``."""
259
+ de = eps - epsp_old
260
+ sig_tr = cm @ de
261
+ seq_tr = math.sqrt(max(sig_tr @ (mm @ sig_tr), 0.0))
262
+ y0, dy0 = _yield(h, p_old)
263
+ if not math.isfinite(seq_tr): # a diverging trial state: no update, the step is divided
264
+ sig[:] = np.nan
265
+ epsp[:] = epsp_old
266
+ tan[:, :] = cm
267
+ return p_old
268
+ if not seq_tr > y0 * (1.0 + 1e-12):
269
+ sig[:] = sig_tr
270
+ epsp[:] = epsp_old
271
+ tan[:, :] = cm
272
+ return p_old
273
+ n_tr = (mm @ sig_tr) / seq_tr
274
+ denom = n_tr @ (cm @ n_tr) + dy0
275
+ lam = max((seq_tr - y0) / denom, 0.0) / y0 if denom > 0.0 else 1e-6 / y0
276
+ lo, hi = 0.0, math.inf
277
+ xi = np.empty((6, 6))
278
+ s = np.empty(6)
279
+ ms = np.empty(6)
280
+ seq, dy = y0, dy0
281
+ for _ in range(100):
282
+ xi[:, :] = np.linalg.inv(cinv + lam * mm)
283
+ s[:] = xi @ de
284
+ ms[:] = mm @ s
285
+ seq = math.sqrt(max(s @ ms, 1e-300))
286
+ p = p_old + lam * seq
287
+ y, dy = _yield(h, p)
288
+ g = seq - y
289
+ if abs(g) <= 1e-12 * max(y, 1e-300):
290
+ break
291
+ if g > 0.0:
292
+ lo = lam
293
+ else:
294
+ hi = lam
295
+ dseq = -(ms @ (xi @ ms)) / seq
296
+ dg = dseq - dy * (seq + lam * dseq)
297
+ new = lam - g / dg if dg < 0.0 else -1.0
298
+ if not lo < new < hi:
299
+ new = 0.5 * (lo + hi) if hi < math.inf else 2.0 * lo + 1e-12
300
+ if abs(new - lam) <= 1e-15 * max(lam, 1e-300):
301
+ break
302
+ if not new < 1e300: # no plastic solution (an infinite flow)
303
+ sig[:] = np.nan
304
+ epsp[:] = epsp_old
305
+ tan[:, :] = cm
306
+ return p_old
307
+ lam = new
308
+ sig[:] = s
309
+ epsp[:] = epsp_old + lam * ms
310
+ n = ms / seq
311
+ xn = xi @ n
312
+ a = 1.0 - lam * dy
313
+ tan[:, :] = xi - a * np.outer(xn, xn) / (dy + a * (n @ xn))
314
+ return p_old + lam * seq
315
+
316
+
317
+ @njit(cache=True)
318
+ def plastic_update(cm, cinv, mm, h, eps, epsp_old, p_old):
319
+ """A point (Mandel vectors): returns the stress, the plastic strain, ``p`` and the
320
+ consistent tangent (for checks)."""
321
+ sig = np.empty(6)
322
+ epsp = np.empty(6)
323
+ tan = np.empty((6, 6))
324
+ p = _plastic_point(cm, cinv, mm, h, eps, epsp_old, p_old, sig, epsp, tan)
325
+ return sig, epsp, p, tan
326
+
327
+
328
+ # -- the elements ----------------------------------------------------------------------------
329
+
330
+
331
+ @njit(parallel=True, cache=True)
332
+ def _microfoam_chunk(nodes, elements, first, mat, cm, cinv, mm, hard, micro, plastic, values,
333
+ offset, n_g, gp, gw, state_old, state_new, fe, ke, tangent): # fmt: skip
334
+ """Element vectors and matrices of the elements ``first...``, the internal variables
335
+ of their points into ``state_new``."""
336
+ for ee in prange(fe.shape[0]):
337
+ e = first + ee
338
+ el = elements[e]
339
+ m = mat[e]
340
+ x = np.empty((4, 3))
341
+ for a in range(4):
342
+ x[a] = nodes[el[a]]
343
+ gl = np.empty((4, 3))
344
+ vol = abs(_corner_gradients(x, gl))
345
+ ul = np.empty((10, 3))
346
+ for a in range(10):
347
+ for i in range(3):
348
+ ul[a, i] = values[offset[el[a]] + i]
349
+ gv = np.zeros((4, 9))
350
+ for b in range(4):
351
+ for k in range(n_g):
352
+ gv[b, k] = values[offset[el[b]] + 3 + k]
353
+ l2, lam_h, mu_h = micro[m, 0], micro[m, 1], micro[m, 2]
354
+ lam_s, mu_s, mu_c = micro[m, 3], micro[m, 4], micro[m, 5]
355
+ ds = np.zeros((9, 9))
356
+ if n_g > 0:
357
+ for i in range(3):
358
+ for j in range(3):
359
+ for q in range(3):
360
+ for r in range(3):
361
+ v = 0.0
362
+ if i == j and q == r:
363
+ v += lam_s
364
+ if i == q and j == r:
365
+ v += mu_s + mu_c
366
+ if i == r and j == q:
367
+ v += mu_s - mu_c
368
+ ds[3 * i + j, 3 * q + r] = v
369
+ f = fe[ee]
370
+ f[:] = 0.0
371
+ if tangent:
372
+ ke[ee, :, :] = 0.0
373
+ grad = np.empty((10, 3))
374
+ hu = np.empty((3, 3))
375
+ eps = np.empty(6)
376
+ sig = np.empty(6)
377
+ epsp = np.empty(6)
378
+ tan = np.empty((6, 6))
379
+ t = np.empty((3, 3))
380
+ s = np.zeros((3, 3))
381
+ big_s = np.zeros((3, 3, 3))
382
+ d = np.empty((9, 9))
383
+ gmat = np.empty((3, 9))
384
+ for g in range(gp.shape[0]):
385
+ bary = gp[g]
386
+ _shape_gradients(2, gl, bary, grad)
387
+ w = gw[g] * vol
388
+ for i in range(3):
389
+ for j in range(3):
390
+ v = 0.0
391
+ for a in range(10):
392
+ v += ul[a, i] * grad[a, j]
393
+ hu[i, j] = v
394
+ r2 = math.sqrt(2.0)
395
+ eps[0], eps[1], eps[2] = hu[0, 0], hu[1, 1], hu[2, 2]
396
+ eps[3] = (hu[1, 2] + hu[2, 1]) / r2
397
+ eps[4] = (hu[2, 0] + hu[0, 2]) / r2
398
+ eps[5] = (hu[0, 1] + hu[1, 0]) / r2
399
+ so = state_old[e, g]
400
+ sn = state_new[e, g]
401
+ if plastic[m]:
402
+ p = _plastic_point(
403
+ cm[m], cinv[m], mm[m], hard[m], eps, so[:6], so[6], sig, epsp, tan
404
+ )
405
+ sn[:6] = epsp
406
+ sn[6] = p
407
+ else:
408
+ sig[:] = cm[m] @ eps
409
+ tan[:, :] = cm[m]
410
+ sn[:] = so
411
+ for i in range(3):
412
+ for j in range(3):
413
+ k6 = _MAP[i, j]
414
+ t[i, j] = sig[k6] / _W[k6]
415
+ if n_g > 0:
416
+ tr = 0.0
417
+ for i in range(3):
418
+ tr += hu[i, i]
419
+ for b in range(4):
420
+ tr -= bary[b] * gv[b, 4 * i]
421
+ for i in range(3):
422
+ for j in range(3):
423
+ eij = hu[i, j]
424
+ eji = hu[j, i]
425
+ for b in range(4):
426
+ eij -= bary[b] * gv[b, 3 * i + j]
427
+ eji -= bary[b] * gv[b, 3 * j + i]
428
+ s[i, j] = mu_s * (eij + eji) + mu_c * (eij - eji)
429
+ if i == j:
430
+ s[i, j] += lam_s * tr
431
+ t[i, j] += s[i, j]
432
+ for k in range(3):
433
+ trk = 0.0
434
+ for q in range(3):
435
+ for b in range(4):
436
+ trk += gv[b, 4 * q] * gl[b, k]
437
+ for i in range(3):
438
+ for j in range(3):
439
+ kij = 0.0
440
+ for b in range(4):
441
+ kij += gv[b, 3 * i + j] * gl[b, k]
442
+ big_s[i, j, k] = l2 * (
443
+ 2.0 * mu_h * kij + (lam_h * trk if i == j else 0.0)
444
+ )
445
+ for a in range(10):
446
+ for i in range(3):
447
+ v = 0.0
448
+ for j in range(3):
449
+ v += t[i, j] * grad[a, j]
450
+ f[3 * a + i] += w * v
451
+ if n_g > 0:
452
+ for b in range(4):
453
+ for i in range(3):
454
+ for j in range(3):
455
+ v = -s[i, j] * bary[b]
456
+ for k in range(3):
457
+ v += big_s[i, j, k] * gl[b, k]
458
+ f[30 + 9 * b + 3 * i + j] += w * v
459
+ if not tangent:
460
+ continue
461
+ kk = ke[ee]
462
+ for i in range(3):
463
+ for j in range(3):
464
+ for q in range(3):
465
+ for r in range(3):
466
+ a6 = _MAP[i, j]
467
+ b6 = _MAP[q, r]
468
+ d[3 * i + j, 3 * q + r] = (
469
+ tan[a6, b6] / (_W[a6] * _W[b6]) + ds[3 * i + j, 3 * q + r]
470
+ )
471
+ for a in range(10):
472
+ for i in range(3):
473
+ for qr in range(9):
474
+ v = 0.0
475
+ for j in range(3):
476
+ v += grad[a, j] * d[3 * i + j, qr]
477
+ gmat[i, qr] = v
478
+ for c in range(10):
479
+ for i in range(3):
480
+ for q in range(3):
481
+ v = 0.0
482
+ for r in range(3):
483
+ v += gmat[i, 3 * q + r] * grad[c, r]
484
+ kk[3 * a + i, 3 * c + q] += w * v
485
+ if n_g == 0:
486
+ continue
487
+ for a in range(10):
488
+ for i in range(3):
489
+ for qr in range(9):
490
+ v = 0.0
491
+ for j in range(3):
492
+ v += grad[a, j] * ds[3 * i + j, qr]
493
+ for b in range(4):
494
+ kk[3 * a + i, 30 + 9 * b + qr] -= w * bary[b] * v
495
+ kk[30 + 9 * b + qr, 3 * a + i] -= w * bary[b] * v
496
+ for b in range(4):
497
+ for c in range(4):
498
+ dot = gl[b, 0] * gl[c, 0] + gl[b, 1] * gl[c, 1] + gl[b, 2] * gl[c, 2]
499
+ for ij in range(9):
500
+ for qr in range(9):
501
+ v = bary[b] * bary[c] * ds[ij, qr]
502
+ if ij == qr:
503
+ v += l2 * 2.0 * mu_h * dot
504
+ if ij % 4 == 0 and qr % 4 == 0:
505
+ v += l2 * lam_h * dot
506
+ kk[30 + 9 * b + ij, 30 + 9 * c + qr] += w * v
507
+
508
+
509
+ @njit(parallel=True, cache=True)
510
+ def _microfoam_finite_chunk(nodes, elements, first, mat, cm, cinv, mm, hard, micro, plastic,
511
+ values, offset, n_g, gp, gw, state_old, state_new, fe, ke,
512
+ tangent): # fmt: skip
513
+ """The finite-strain counterpart of :func:`_microfoam_chunk` (see the module): at
514
+ each point the gradient and Hessian of the energy by ``z = (F, χ, Grad χ)``, the
515
+ macroscopic part exact, then ``Bᵀ g`` and ``Bᵀ H B`` with the linear map ``B`` of the
516
+ degrees of freedom of the element to ``z``."""
517
+ n_z = N_Z if n_g > 0 else 9
518
+ n_loc = 30 + 4 * n_g
519
+ for ee in prange(fe.shape[0]):
520
+ e = first + ee
521
+ el = elements[e]
522
+ m = mat[e]
523
+ x = np.empty((4, 3))
524
+ for a in range(4):
525
+ x[a] = nodes[el[a]]
526
+ gl = np.empty((4, 3))
527
+ vol = abs(_corner_gradients(x, gl))
528
+ ul = np.empty((10, 3))
529
+ for a in range(10):
530
+ for i in range(3):
531
+ ul[a, i] = values[offset[el[a]] + i]
532
+ gv = np.zeros((4, 9))
533
+ for b in range(4):
534
+ for k in range(n_g):
535
+ gv[b, k] = values[offset[el[b]] + 3 + k]
536
+ f = fe[ee]
537
+ f[:] = 0.0
538
+ if tangent:
539
+ ke[ee, :, :] = 0.0
540
+ grad = np.empty((10, 3))
541
+ hu = np.empty((3, 3))
542
+ mu3 = np.empty(3)
543
+ q = np.empty((3, 3))
544
+ eps = np.empty(6)
545
+ sig = np.empty(6)
546
+ epsp = np.empty(6)
547
+ tan = np.empty((6, 6))
548
+ none6 = np.zeros(6)
549
+ pk1 = np.empty((3, 3))
550
+ dpdf = np.empty((9, 9))
551
+ dp9 = np.empty(9)
552
+ z = np.empty(N_Z)
553
+ gz = np.zeros(N_Z)
554
+ hz = np.zeros((N_Z, N_Z))
555
+ g45 = np.empty(N_Z)
556
+ h45 = np.empty((N_Z, N_Z))
557
+ bmat = np.zeros((n_z, n_loc))
558
+ for g in range(gp.shape[0]):
559
+ bary = gp[g]
560
+ _shape_gradients(2, gl, bary, grad)
561
+ w = gw[g] * vol
562
+ for i in range(3):
563
+ for j in range(3):
564
+ v = 0.0
565
+ for a in range(10):
566
+ v += ul[a, i] * grad[a, j]
567
+ hu[i, j] = v
568
+ so = state_old[e, g]
569
+ sn = state_new[e, g]
570
+ if hencky(hu, mu3, q, eps) != 0: # an inverted point: the step is divided
571
+ f[:] = np.nan
572
+ sn[:] = so
573
+ continue
574
+ if plastic[m]:
575
+ p = _plastic_point(cm[m], cinv[m], mm[m], hard[m], eps, so[:6], so[6], sig, epsp,
576
+ tan) # fmt: skip
577
+ sn[:6] = epsp
578
+ sn[6] = p
579
+ else:
580
+ sig[:] = cm[m] @ eps
581
+ tan[:, :] = cm[m]
582
+ sn[:] = so
583
+ pull_back(hu, mu3, q, sig, tan, none6, pk1, dpdf, dp9)
584
+ gz[:] = 0.0
585
+ hz[:, :] = 0.0
586
+ for i in range(3):
587
+ for j in range(3):
588
+ gz[3 * i + j] = pk1[i, j]
589
+ hz[:9, :9] = dpdf
590
+ bmat[:, :] = 0.0
591
+ for i in range(3):
592
+ for j in range(3):
593
+ for a in range(10):
594
+ bmat[3 * i + j, 3 * a + i] = grad[a, j]
595
+ if n_g > 0:
596
+ for i in range(3):
597
+ for j in range(3):
598
+ z[3 * i + j] = hu[i, j] + (1.0 if i == j else 0.0)
599
+ v = 1.0 if i == j else 0.0
600
+ for b in range(4):
601
+ v += bary[b] * gv[b, 3 * i + j]
602
+ z[9 + 3 * i + j] = v
603
+ for k in range(3):
604
+ v = 0.0
605
+ for b in range(4):
606
+ v += gv[b, 3 * i + j] * gl[b, k]
607
+ z[18 + 9 * i + 3 * j + k] = v
608
+ micro_hessian(z, micro[m], g45, h45)
609
+ gz += g45
610
+ hz += h45
611
+ for ij in range(9):
612
+ for b in range(4):
613
+ bmat[9 + ij, 30 + 9 * b + ij] = bary[b]
614
+ for k in range(3):
615
+ bmat[18 + 3 * ij + k, 30 + 9 * b + ij] = gl[b, k]
616
+ bt = np.ascontiguousarray(bmat.T)
617
+ f += w * (bt @ np.ascontiguousarray(gz[:n_z]))
618
+ if tangent:
619
+ ke[ee] += w * (bt @ (np.ascontiguousarray(hz[:n_z, :n_z]) @ bmat))
620
+
621
+
622
+ @njit(parallel=True, cache=True)
623
+ def _point_fields_finite(nodes, elements, mat, cm, values, offset, n_g, gp, state, out):
624
+ """At the points of every element in finite strains: the logarithmic strain (Mandel),
625
+ the Cauchy stress (Mandel), ``p``, the microdeformation ``χ̃`` (9) and ``J`` into
626
+ ``out`` (elements x points x 23)."""
627
+ for e in prange(elements.shape[0]):
628
+ el = elements[e]
629
+ m = mat[e]
630
+ x = np.empty((4, 3))
631
+ for a in range(4):
632
+ x[a] = nodes[el[a]]
633
+ gl = np.empty((4, 3))
634
+ _corner_gradients(x, gl)
635
+ grad = np.empty((10, 3))
636
+ mu3 = np.empty(3)
637
+ q = np.empty((3, 3))
638
+ eps = np.empty(6)
639
+ pk1 = np.empty((3, 3))
640
+ dpdf = np.empty((9, 9))
641
+ dp9 = np.empty(9)
642
+ none6 = np.zeros(6)
643
+ for g in range(gp.shape[0]):
644
+ _shape_gradients(2, gl, gp[g], grad)
645
+ hu = np.zeros((3, 3))
646
+ for a in range(10):
647
+ for i in range(3):
648
+ for j in range(3):
649
+ hu[i, j] += values[offset[el[a]] + i] * grad[a, j]
650
+ o = out[e, g]
651
+ if hencky(hu, mu3, q, eps) != 0:
652
+ o[:] = np.nan
653
+ continue
654
+ sig = cm[m] @ (eps - state[e, g, :6])
655
+ pull_back(hu, mu3, q, sig, cm[m], none6, pk1, dpdf, dp9)
656
+ fm = np.eye(3) + hu
657
+ jac = np.linalg.det(fm)
658
+ cauchy = pk1 @ fm.T / jac
659
+ o[:6] = eps
660
+ for k in range(6):
661
+ o[6 + k] = cauchy[PAIRS[k, 0], PAIRS[k, 1]] * _W[k]
662
+ o[12] = state[e, g, 6]
663
+ for k in range(9):
664
+ v = 0.0
665
+ if n_g > 0:
666
+ for b in range(4):
667
+ v += gp[g, b] * values[offset[el[b]] + 3 + k]
668
+ o[13 + k] = v
669
+ o[22] = jac
670
+
671
+
672
+ @njit(parallel=True, cache=True)
673
+ def _point_fields(nodes, elements, mat, cm, values, offset, n_g, gp, state, out):
674
+ """At the points of every element: the strain (Mandel), the stress ``σ`` (Mandel),
675
+ ``p`` and the microdeformation (9) into ``out`` (elements x points x 22)."""
676
+ for e in prange(elements.shape[0]):
677
+ el = elements[e]
678
+ m = mat[e]
679
+ x = np.empty((4, 3))
680
+ for a in range(4):
681
+ x[a] = nodes[el[a]]
682
+ gl = np.empty((4, 3))
683
+ _corner_gradients(x, gl)
684
+ grad = np.empty((10, 3))
685
+ eps = np.empty(6)
686
+ r2 = math.sqrt(2.0)
687
+ for g in range(gp.shape[0]):
688
+ _shape_gradients(2, gl, gp[g], grad)
689
+ hu = np.zeros((3, 3))
690
+ for a in range(10):
691
+ for i in range(3):
692
+ for j in range(3):
693
+ hu[i, j] += values[offset[el[a]] + i] * grad[a, j]
694
+ eps[0], eps[1], eps[2] = hu[0, 0], hu[1, 1], hu[2, 2]
695
+ eps[3] = (hu[1, 2] + hu[2, 1]) / r2
696
+ eps[4] = (hu[2, 0] + hu[0, 2]) / r2
697
+ eps[5] = (hu[0, 1] + hu[1, 0]) / r2
698
+ o = out[e, g]
699
+ o[:6] = eps
700
+ o[6:12] = cm[m] @ (eps - state[e, g, :6])
701
+ o[12] = state[e, g, 6]
702
+ for k in range(9):
703
+ v = 0.0
704
+ if n_g > 0:
705
+ for b in range(4):
706
+ v += gp[g, b] * values[offset[el[b]] + 3 + k]
707
+ o[13 + k] = v
708
+
709
+
710
+ class MicrofoamProblem(MixedProblem):
711
+ """A body of microfoam materials (see the module): ``materials`` a
712
+ :class:`Microfoam` (every phase) or a dict of the phases of the mesh, all
713
+ micromorphic (with a ``length``) or all classical, in ``"small"`` or ``"finite"``
714
+ strains. The generalized degrees of freedom of a corner are the components ``chi_ij``
715
+ (:data:`CHI`: component ``3 + 3 i + j``; in finite strains those of ``χ̃ = χ - 1``);
716
+ :meth:`run` prescribes them as the displacements."""
717
+
718
+ def __init__(self, mesh: TetMesh, materials, *, kinematics: str = "small"):
719
+ if kinematics not in ("small", "finite"):
720
+ raise ValueError("kinematics: 'small' or 'finite'")
721
+ self.finite = kinematics == "finite"
722
+ if isinstance(materials, Microfoam):
723
+ materials = {int(p): materials for p in np.unique(mesh.phase)}
724
+ lengths = {m.length is None for m in materials.values()}
725
+ if len(lengths) != 1:
726
+ raise ValueError("MicrofoamProblem: every material micromorphic, or none")
727
+ self.micromorphic = not lengths.pop()
728
+ self.space = MixedSpace(mesh, 9 if self.micromorphic else 0)
729
+ self.mesh = self.space.mesh
730
+ phases = sorted(materials)
731
+ index = {p: k for k, p in enumerate(phases)}
732
+ if not np.isin(self.mesh.phase, phases).all():
733
+ raise ValueError("MicrofoamProblem: a material for every phase of the mesh")
734
+ self.materials = materials
735
+ self._mat = np.array([index[int(p)] for p in self.mesh.phase], dtype=np.int64)
736
+ mats = [materials[p] for p in phases]
737
+ self._cm = np.array([m.elastic_matrix() for m in mats])
738
+ self._cinv = np.array([np.linalg.inv(c) for c in self._cm])
739
+ self._mm = np.array([m.criterion_matrix() for m in mats])
740
+ self._hard = np.array([m.hardening_parameters() for m in mats])
741
+ self._micro = np.array([m.micro_parameters() for m in mats])
742
+ self._plastic = np.array([math.isfinite(m.yield_stress) for m in mats])
743
+
744
+ def _initial_state(self):
745
+ return np.zeros((self.mesh.n_elements, len(WEIGHTS), N_STATE))
746
+
747
+ def _assemble(self, values, state, tangent):
748
+ space = self.space
749
+ n_el = self.mesh.n_elements
750
+ rhs = np.zeros(space.n_dofs)
751
+ data = space.new_matrix_data() if tangent else np.zeros(0)
752
+ new_state = np.empty_like(state)
753
+ n_loc = space.n_local
754
+ for first in range(0, n_el, CHUNK):
755
+ count = min(CHUNK, n_el - first)
756
+ fe = np.empty((count, n_loc))
757
+ ke = np.empty((count, n_loc, n_loc)) if tangent else np.empty((count, 1, 1))
758
+ chunk = _microfoam_finite_chunk if self.finite else _microfoam_chunk
759
+ chunk(self.mesh.nodes, space.elements, first, self._mat, self._cm, self._cinv,
760
+ self._mm, self._hard, self._micro, self._plastic, values, space.offset,
761
+ space.n_g, POINTS, WEIGHTS, state, new_state, fe, ke, tangent) # fmt: skip
762
+ space.add(first, ke, fe, data, rhs)
763
+ return rhs, (data if tangent else None), new_state
764
+
765
+ def fields(self, values, state) -> dict:
766
+ """The fields of the elements (means of their points): ``strain`` and ``stress``
767
+ (elements x 3 x 3; in finite strains the logarithmic strain and the Cauchy
768
+ stress), the cumulated plastic strain ``p``, the microdeformation ``chi``
769
+ (elements x 3 x 3; ``χ̃`` in finite strains) and, in finite strains, the change of
770
+ volume ``J``."""
771
+ space = self.space
772
+ width = 23 if self.finite else 22
773
+ out = np.empty((self.mesh.n_elements, len(WEIGHTS), width))
774
+ point_fields = _point_fields_finite if self.finite else _point_fields
775
+ point_fields(self.mesh.nodes, space.elements, self._mat, self._cm, values, space.offset,
776
+ space.n_g, POINTS, state, out) # fmt: skip
777
+ mean = out.mean(axis=1)
778
+ strain = np.empty((len(mean), 3, 3))
779
+ stress = np.empty((len(mean), 3, 3))
780
+ for i, (a, b) in enumerate(_PAIRS):
781
+ strain[:, a, b] = strain[:, b, a] = mean[:, i] / _W[i]
782
+ stress[:, a, b] = stress[:, b, a] = mean[:, 6 + i] / _W[i]
783
+ fields = {"strain": strain, "stress": stress, "p": mean[:, 12],
784
+ "chi": mean[:, 13:22].reshape(-1, 3, 3)} # fmt: skip
785
+ if self.finite:
786
+ fields["J"] = mean[:, 22]
787
+ return fields