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,310 @@
1
+ """The surfaces that touch: faces of a tetrahedral mesh, pairs of them, rigid obstacles, and
2
+ bodies meshed apart brought into one mesh."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import math
7
+ from dataclasses import dataclass, field
8
+
9
+ import numpy as np
10
+
11
+ from morphogen.contact import kernels
12
+ from morphogen.mesh.tetra import TetMesh
13
+
14
+
15
+ @dataclass
16
+ class Surface:
17
+ """Faces of a tetrahedral mesh that may touch others: rows of three nodes (4-node
18
+ tetrahedra) or of six (10-node ones: the corners, then the middles of the edges 0-1,
19
+ 1-2 and 2-0), their normals out of the body."""
20
+
21
+ faces: np.ndarray
22
+
23
+ def __post_init__(self) -> None:
24
+ self.faces = np.ascontiguousarray(self.faces, dtype=np.int64)
25
+ if self.faces.ndim != 2 or self.faces.shape[1] not in (3, 6):
26
+ raise ValueError("Surface: rows of three or six nodes")
27
+
28
+ @classmethod
29
+ def of(cls, mesh: TetMesh, where=None, phases=None) -> Surface:
30
+ """The free faces of a mesh (those of one element only: its outside, the walls of
31
+ its pores, the lips of its cracks): all of them, those of the elements of the
32
+ ``phases`` given, those whose centroids (rows) ``where`` keeps."""
33
+ mask = mesh._free_mask()
34
+ if phases is not None:
35
+ mask = mask & np.isin(mesh.phase, np.atleast_1d(phases))[:, None]
36
+ faces = mesh._faces(mask)
37
+ if where is not None:
38
+ keep = np.asarray(where(mesh.nodes[faces[:, :3]].mean(axis=1)), dtype=bool)
39
+ if keep.shape != (len(faces),):
40
+ raise ValueError("Surface.of: where returns one value per face")
41
+ faces = faces[keep]
42
+ return cls(faces)
43
+
44
+ @property
45
+ def n_faces(self) -> int:
46
+ return len(self.faces)
47
+
48
+ @property
49
+ def order(self) -> int:
50
+ """1 for faces of three nodes, 2 for faces of six."""
51
+ return 1 if self.faces.shape[1] == 3 else 2
52
+
53
+ def subset(self, keep) -> Surface:
54
+ """The faces ``keep`` (mask or indices)."""
55
+ keep = np.asarray(keep)
56
+ return Surface(self.faces[keep if keep.dtype == bool else keep.astype(np.int64)])
57
+
58
+ def centroids(self, nodes: np.ndarray) -> np.ndarray:
59
+ """The centroids of the corners of the faces."""
60
+ return nodes[self.faces[:, :3]].mean(axis=1)
61
+
62
+ def normals(self, nodes: np.ndarray) -> np.ndarray:
63
+ """The outward unit normals of the triangles of the corners."""
64
+ x = nodes[self.faces[:, :3]]
65
+ normal = np.cross(x[:, 1] - x[:, 0], x[:, 2] - x[:, 0])
66
+ return normal / np.linalg.norm(normal, axis=1, keepdims=True)
67
+
68
+ def points(self, nodes: np.ndarray, rule: str = "gauss"):
69
+ """The integration points of the faces: their faces, coordinates (ξ, η) and
70
+ weights (their shares of the areas of the faces in the positions ``nodes``: the
71
+ area element of each on a curved face of six nodes), three per face of three
72
+ nodes, six per face of six. ``rule``: ``"gauss"``, points inside the faces, or
73
+ ``"nodes"``: the vertices of the faces of three nodes; the vertices, the middles
74
+ of the edges and the centroids of those of six (a corner or an edge of a body is
75
+ then a contact point)."""
76
+ if rule not in kernels.RULES:
77
+ raise ValueError(f"contact points: one of {kernels.RULES}, got {rule!r}")
78
+ if rule == "nodes":
79
+ rule = kernels.NODES3 if self.order == 1 else kernels.NODES6
80
+ else:
81
+ rule = kernels.POINTS3 if self.order == 1 else kernels.POINTS6
82
+ n = self.faces.shape[1]
83
+ count = len(rule)
84
+ face = np.repeat(np.arange(self.n_faces), count)
85
+ xi = np.tile(rule[:, 0], self.n_faces)
86
+ eta = np.tile(rule[:, 1], self.n_faces)
87
+ x = nodes[self.faces]
88
+ weight = np.empty((self.n_faces, count))
89
+ shape, dxi, deta = np.empty(n), np.empty(n), np.empty(n)
90
+ for g, (u, v, w) in enumerate(rule):
91
+ kernels.shapes(n, u, v, shape, dxi, deta)
92
+ a = np.einsum("i,eic->ec", dxi, x)
93
+ b = np.einsum("i,eic->ec", deta, x)
94
+ weight[:, g] = 0.5 * w * np.linalg.norm(np.cross(a, b), axis=1)
95
+ return face, xi, eta, weight.ravel()
96
+
97
+ def positions(self, nodes: np.ndarray, face, xi, eta) -> np.ndarray:
98
+ """The positions of points of the faces (rows) in the positions ``nodes``."""
99
+ n = self.faces.shape[1]
100
+ zeta = 1.0 - xi - eta
101
+ if n == 3:
102
+ shape = np.stack([zeta, xi, eta], axis=1)
103
+ else:
104
+ shape = np.stack(
105
+ [
106
+ zeta * (2 * zeta - 1),
107
+ xi * (2 * xi - 1),
108
+ eta * (2 * eta - 1),
109
+ 4 * zeta * xi,
110
+ 4 * xi * eta,
111
+ 4 * eta * zeta,
112
+ ],
113
+ axis=1,
114
+ )
115
+ return np.einsum("qi,qic->qc", shape, nodes[self.faces[face]])
116
+
117
+ def areas(self, nodes: np.ndarray) -> np.ndarray:
118
+ """The areas of the faces in the positions ``nodes``."""
119
+ return self.points(nodes)[3].reshape(self.n_faces, -1).sum(axis=1)
120
+
121
+ def rims(self) -> np.ndarray:
122
+ """Which of the edges of each face (0-1, 1-2 and 2-0 of its corners; faces x 3)
123
+ no other face of the surface shares: the rim of the surface, none on the closed
124
+ surface of a body."""
125
+ corners = self.faces[:, :3]
126
+ edges = np.sort(np.stack([corners, np.roll(corners, -1, axis=1)], axis=2), axis=2)
127
+ _, inverse, counts = np.unique(
128
+ edges.reshape(-1, 2), axis=0, return_inverse=True, return_counts=True
129
+ )
130
+ return (counts[inverse.ravel()] == 1).reshape(-1, 3)
131
+
132
+ def size(self, nodes: np.ndarray) -> float:
133
+ """The mean length of the edges of the triangles of the corners."""
134
+ x = nodes[self.faces[:, :3]]
135
+ edges = np.linalg.norm(x - np.roll(x, -1, axis=1), axis=2)
136
+ return float(edges.mean())
137
+
138
+
139
+ def _check_contact(name: str, friction, stiffness, tangential, depth, points="gauss") -> None:
140
+ if not (math.isfinite(friction) and friction >= 0):
141
+ raise ValueError(f"{name}: a coefficient of friction of 0 or more")
142
+ if points not in kernels.RULES:
143
+ raise ValueError(f"{name}: contact points among {kernels.RULES}, got {points!r}")
144
+ for value, what in ((stiffness, "stiffness"), (tangential, "tangential stiffness"),
145
+ (depth, "depth")): # fmt: skip
146
+ if value is not None and not (math.isfinite(value) and value > 0):
147
+ raise ValueError(f"{name}: a positive {what}")
148
+
149
+
150
+ @dataclass
151
+ class Pair:
152
+ """Two surfaces that may touch: the integration points of the faces of ``slave`` are
153
+ kept out of ``master`` (and those of ``master`` out of ``slave`` too with
154
+ ``symmetric``: two passes, for bodies of like stiffness and meshes). ``slave`` alone
155
+ (``master`` None): a surface that may touch itself, the walls of pores or the struts
156
+ of a lattice (every face against the others, those that share a node with it left
157
+ out).
158
+
159
+ ``friction``: Coulomb's coefficient. ``stiffness``: the penalty, a pressure per unit
160
+ of penetration (by default ten times the stiffest Young's modulus over the size of
161
+ the faces; the two passes of a symmetric pair, or the two sides of a surface that
162
+ touches itself, share it); ``tangential``: that of the stick (by default the
163
+ penalty). ``depth``: the deepest penetration looked for (by default half the size of
164
+ the faces): a point deeper behind a face is taken to be across a wall, not through
165
+ it. ``points``: the slave points, ``"gauss"`` (inside the faces) or ``"nodes"`` (at
166
+ their nodes: for a surface whose corners or edges meet the master first, which points
167
+ inside its faces would let through; the weight of a point is then the share of its
168
+ face that the master sees, the cosine of the angle of their normals, and a point of
169
+ the rim of the slave still faces the master a twentieth of a face beyond its rim)."""
170
+
171
+ slave: Surface
172
+ master: Surface | None = None
173
+ friction: float = 0.0
174
+ stiffness: float | None = None
175
+ tangential: float | None = None
176
+ depth: float | None = None
177
+ symmetric: bool = False
178
+ points: str = "gauss"
179
+
180
+ def __post_init__(self) -> None:
181
+ _check_contact("Pair", self.friction, self.stiffness, self.tangential, self.depth,
182
+ self.points) # fmt: skip
183
+ if self.master is not None and self.master.order != self.slave.order:
184
+ raise ValueError("Pair: two surfaces of the same order (three or six nodes a face)")
185
+
186
+ @property
187
+ def own(self) -> bool:
188
+ """Whether the surface touches itself."""
189
+ return self.master is None
190
+
191
+
192
+ @dataclass
193
+ class Obstacle:
194
+ """A rigid obstacle that the integration points of the faces of ``surface`` stay out
195
+ of, with Coulomb's ``friction`` on it; ``stiffness`` and ``tangential``: as for a
196
+ :class:`Pair`. ``motion``: its translation, a vector grown with the load factor
197
+ (``load factor x motion``) or a function of the load factor returning one; the force
198
+ that the body exerts on it is a result of each step.
199
+
200
+ The kinds (:meth:`plane`, :meth:`sphere`, :meth:`cylinder`, :meth:`cone`): a plane (a
201
+ point and its normal, out of the obstacle: a platen), a sphere (its centre and
202
+ radius), a cylinder without ends (a point of its axis, its axis and radius), a cone
203
+ (its apex, its axis from the apex into the cone and its half-angle, in degrees: an
204
+ indenter). ``inside``: the body is held within the sphere or the cylinder (a die).
205
+ ``points``: the points of the surface kept out of it, ``"gauss"`` or ``"nodes"`` (as
206
+ for a :class:`Pair`: a body that meets a platen by a corner or an edge)."""
207
+
208
+ kind: int
209
+ surface: Surface
210
+ point: tuple
211
+ axis: tuple = (0.0, 0.0, 1.0)
212
+ size: float = 0.0
213
+ inside: bool = False
214
+ friction: float = 0.0
215
+ stiffness: float | None = None
216
+ tangential: float | None = None
217
+ motion: object = None
218
+ name: str = field(default="", compare=False)
219
+ points: str = "gauss"
220
+
221
+ def __post_init__(self) -> None:
222
+ _check_contact("Obstacle", self.friction, self.stiffness, self.tangential, None,
223
+ self.points) # fmt: skip
224
+ self.point = tuple(float(v) for v in self.point)
225
+ axis = np.asarray(self.axis, dtype=float)
226
+ norm = float(np.linalg.norm(axis))
227
+ if len(self.point) != 3 or axis.shape != (3,) or not norm > 0:
228
+ raise ValueError("Obstacle: a point and an axis of three components")
229
+ self.axis = tuple(axis / norm)
230
+ if self.kind in (kernels.SPHERE, kernels.CYLINDER) and not self.size > 0:
231
+ raise ValueError("Obstacle: a positive radius")
232
+ if self.kind == kernels.CONE and not 0 < self.size < 0.5 * math.pi:
233
+ raise ValueError("Obstacle: a half-angle of the cone between 0 and 90 degrees")
234
+ if self.inside and self.kind not in (kernels.SPHERE, kernels.CYLINDER):
235
+ raise ValueError("Obstacle: only a sphere or a cylinder holds a body inside")
236
+ if not self.name:
237
+ self.name = ("plane", "sphere", "cylinder", "cone")[self.kind]
238
+
239
+ @classmethod
240
+ def plane(cls, surface: Surface, point, normal, **options) -> Obstacle:
241
+ return cls(kernels.PLANE, surface, point, normal, **options)
242
+
243
+ @classmethod
244
+ def sphere(cls, surface: Surface, centre, radius: float, **options) -> Obstacle:
245
+ return cls(kernels.SPHERE, surface, centre, size=float(radius), **options)
246
+
247
+ @classmethod
248
+ def cylinder(cls, surface: Surface, point, axis, radius: float, **options) -> Obstacle:
249
+ return cls(kernels.CYLINDER, surface, point, axis, float(radius), **options)
250
+
251
+ @classmethod
252
+ def cone(cls, surface: Surface, apex, axis, half_angle: float, **options) -> Obstacle:
253
+ return cls(kernels.CONE, surface, apex, axis, math.radians(float(half_angle)), **options)
254
+
255
+ def translation(self, t: float) -> np.ndarray:
256
+ """The translation of the obstacle at the load factor ``t``."""
257
+ if self.motion is None:
258
+ return np.zeros(3)
259
+ if callable(self.motion):
260
+ out = np.asarray(self.motion(t), dtype=float)
261
+ else:
262
+ out = t * np.asarray(self.motion, dtype=float)
263
+ if out.shape != (3,):
264
+ raise ValueError("Obstacle: a motion of three components")
265
+ return out
266
+
267
+ def geometry(self, t: float = 0.0) -> np.ndarray:
268
+ """The array of the kernels: the point moved to the load factor ``t``, the axis,
269
+ the size and the sign of the side."""
270
+ return np.array(
271
+ [*(np.asarray(self.point) + self.translation(t)), *self.axis, self.size,
272
+ -1.0 if self.inside else 1.0]
273
+ ) # fmt: skip
274
+
275
+ def distance(self, points: np.ndarray, t: float = 0.0) -> np.ndarray:
276
+ """The signed distances of points (rows) to the obstacle at the load factor ``t``
277
+ (positive outside it)."""
278
+ geometry, normal = self.geometry(t), np.empty(3)
279
+ points = np.atleast_2d(np.asarray(points, dtype=float))
280
+ return np.array([kernels.obstacle_distance(self.kind, geometry, p, normal) for p in points])
281
+
282
+
283
+ def assemble(meshes, phases=None) -> TetMesh:
284
+ """Bodies meshed apart as one mesh, for their contact: the nodes and elements of the
285
+ ``meshes`` one after the other (nothing is merged: nodes at the same place stay
286
+ apart), in the box of them all; ``phases``: a phase per mesh in place of their own
287
+ (by default each mesh keeps its phases)."""
288
+ meshes = list(meshes)
289
+ if not meshes:
290
+ raise ValueError("assemble: at least one mesh")
291
+ if len({m.order for m in meshes}) != 1:
292
+ raise ValueError("assemble: meshes of the same order (4- or 10-node tetrahedra)")
293
+ if phases is not None and len(phases) != len(meshes):
294
+ raise ValueError("assemble: a phase per mesh")
295
+ nodes, elements, phase, offset = [], [], [], 0
296
+ for k, m in enumerate(meshes):
297
+ nodes.append(m.nodes)
298
+ elements.append(m.elements + offset)
299
+ phase.append(m.phase if phases is None else np.full(m.n_elements, int(phases[k])))
300
+ offset += m.n_nodes
301
+ nodes = np.concatenate(nodes)
302
+ return TetMesh(
303
+ nodes,
304
+ np.concatenate(elements),
305
+ np.concatenate(phase),
306
+ nodes.min(axis=0),
307
+ nodes.max(axis=0),
308
+ periodic=False,
309
+ metadata={"bodies": [m.n_nodes for m in meshes]},
310
+ )
@@ -0,0 +1,43 @@
1
+ """Couplings of transport, chemistry and mechanics: transient diffusion in voxel images,
2
+ the thermal oxidation of polymers, properties that evolve with ageing, and hygromorph
3
+ plates."""
4
+
5
+ from morphogen.coupling.ageing import Hydrolysis, PropertyLaw, graded_materials
6
+ from morphogen.coupling.diffusion import (
7
+ DiffusionResult,
8
+ slab_profile,
9
+ slab_uptake,
10
+ transient_diffusion,
11
+ )
12
+ from morphogen.coupling.fenicsx import (
13
+ OxidationResult,
14
+ SwellingResult,
15
+ arc_curvature,
16
+ oxidation_stresses,
17
+ strip_curvature,
18
+ swelling,
19
+ )
20
+ from morphogen.coupling.oxidation import ClosedLoopOxidation, OxidationField, oxidation_field
21
+ from morphogen.coupling.plates import Layer, Multilayer, timoshenko_curvature
22
+
23
+ __all__ = [
24
+ "ClosedLoopOxidation",
25
+ "DiffusionResult",
26
+ "Hydrolysis",
27
+ "Layer",
28
+ "Multilayer",
29
+ "OxidationField",
30
+ "OxidationResult",
31
+ "PropertyLaw",
32
+ "SwellingResult",
33
+ "arc_curvature",
34
+ "graded_materials",
35
+ "oxidation_field",
36
+ "oxidation_stresses",
37
+ "slab_profile",
38
+ "slab_uptake",
39
+ "strip_curvature",
40
+ "swelling",
41
+ "timoshenko_curvature",
42
+ "transient_diffusion",
43
+ ]
@@ -0,0 +1,143 @@
1
+ """Properties that evolve with chemical ageing, and their maps in microstructures.
2
+
3
+ An ageing tracer (the amide concentration of oxidized epoxies, Ernault et al. 2019; the
4
+ degree of polymerization of cellulose in paper, Vibert et al. 2024; an absorbed amount
5
+ of oxygen or water) sets the local parameters through measured laws
6
+ (:class:`PropertyLaw`: piecewise linear tables, constant beyond them). A field of the
7
+ tracer in a microstructure (an oxidation or diffusion profile) is binned into graded
8
+ phases (:func:`graded_materials`) that the homogenization solvers and the exports take
9
+ like any other phases; a chemical shrinkage or a swelling becomes the expansion of the
10
+ graded phases under a unit change of temperature (``Loading(..., temperature=1)``).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import math
16
+ from dataclasses import dataclass, field
17
+
18
+ import numpy as np
19
+
20
+ from morphogen.analysis.basic import as_array
21
+ from morphogen.homogenization.materials import Material
22
+ from morphogen.image import VoxelImage
23
+
24
+ GAS_CONSTANT = 8.314462618
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class PropertyLaw:
29
+ """Material parameters (``young``, ``poisson``, ``conductivity``, ``expansion``...)
30
+ as piecewise linear functions of a tracer: ``values[name][i]`` at ``tracer[i]``
31
+ (increasing), constant beyond the table."""
32
+
33
+ tracer: tuple
34
+ values: dict = field(default_factory=dict)
35
+
36
+ def __post_init__(self) -> None:
37
+ x = np.asarray(self.tracer, dtype=float)
38
+ if x.ndim != 1 or len(x) < 1 or np.any(np.diff(x) <= 0):
39
+ raise ValueError("tracer: increasing values")
40
+ for name, v in self.values.items():
41
+ if len(v) != len(x):
42
+ raise ValueError(f"values[{name!r}]: one value per tracer value")
43
+ object.__setattr__(self, "tracer", tuple(float(t) for t in x))
44
+ object.__setattr__(
45
+ self, "values", {k: tuple(float(a) for a in v) for k, v in self.values.items()}
46
+ )
47
+
48
+ def __call__(self, x) -> dict[str, np.ndarray]:
49
+ x = np.asarray(x, dtype=float)
50
+ return {k: np.interp(x, self.tracer, v) for k, v in self.values.items()}
51
+
52
+ def material(self, x: float, **fixed) -> Material:
53
+ """The material at the tracer value ``x`` (``fixed``: the other parameters)."""
54
+ params = {k: float(v) for k, v in self(float(x)).items()}
55
+ params.update(fixed)
56
+ return Material(**params)
57
+
58
+
59
+ def graded_materials(
60
+ phases,
61
+ tracer,
62
+ laws: dict[int, PropertyLaw],
63
+ materials: dict[int, Material] | None = None,
64
+ *,
65
+ levels: int = 16,
66
+ first_label: int | None = None,
67
+ **fixed,
68
+ ) -> tuple[VoxelImage, dict[int, Material]]:
69
+ """Graded phases of an ageing microstructure: the voxels of each phase with a law in
70
+ ``laws`` are binned by their ``tracer`` value into ``levels`` classes of equal width,
71
+ each a new phase whose material is the law at the middle of its class (``fixed``:
72
+ parameters common to all, e.g. ``poisson=0.37``); the other phases keep their labels
73
+ and ``materials``. Returns the label image and the materials of all its labels."""
74
+ labels = np.asarray(as_array(phases)).astype(np.int64)
75
+ x = np.asarray(as_array(tracer), dtype=float)
76
+ if x.shape != labels.shape:
77
+ raise ValueError("tracer: one value per voxel of the phase image")
78
+ materials = dict(materials or {})
79
+ out = labels.copy()
80
+ table: dict[int, Material] = {
81
+ int(p): materials[int(p)] for p in np.unique(labels) if int(p) not in laws
82
+ }
83
+ missing = [int(p) for p in np.unique(labels) if int(p) not in laws and int(p) not in materials]
84
+ if missing:
85
+ raise ValueError(f"materials: none for the phases {missing}")
86
+ nxt = int(labels.max()) + 1 if first_label is None else int(first_label)
87
+ for phase, law in laws.items():
88
+ mask = labels == int(phase)
89
+ if not mask.any():
90
+ continue
91
+ lo, hi = float(x[mask].min()), float(x[mask].max())
92
+ width = (hi - lo) / levels if hi > lo else 1.0
93
+ if hi > lo:
94
+ k = np.clip(((x[mask] - lo) / width).astype(np.int64), 0, levels - 1)
95
+ else:
96
+ k = np.zeros(int(mask.sum()), dtype=np.int64)
97
+ used = np.unique(k)
98
+ lut = np.full(levels, -1, dtype=np.int64)
99
+ lut[used] = nxt + np.arange(len(used))
100
+ out[mask] = lut[k]
101
+ for b in used:
102
+ middle = lo + (b + 0.5) * width if hi > lo else lo
103
+ table[int(lut[b])] = law.material(middle, **fixed)
104
+ nxt += len(used)
105
+ if isinstance(phases, VoxelImage):
106
+ return phases.with_data(out.astype(np.int32), name="material"), table
107
+ return VoxelImage(out.astype(np.int32), name="material"), table
108
+
109
+
110
+ @dataclass(frozen=True)
111
+ class Hydrolysis:
112
+ """Chain scissions of cellulose by acid hydrolysis, Ekenstam's law:
113
+ ``1/DP(t) - 1/DP(0) = k t`` (``k`` in 1/s at ``temperature``, Arrhenius with
114
+ ``activation_energy`` J/mol). Vibert et al. (2024) found that the mechanical
115
+ properties of aged papers fall faster below a critical degree of polymerization
116
+ ``critical_dp`` (about 750), whatever the ageing (hydrolysis or oxidation): the
117
+ fibres embrittle, more than their bonds."""
118
+
119
+ dp0: float = 1500.0
120
+ rate: float = 1e-10
121
+ temperature: float = 353.15
122
+ activation_energy: float = 110e3
123
+ critical_dp: float = 750.0
124
+
125
+ def rate_at(self, temperature: float | None = None) -> float:
126
+ if temperature is None:
127
+ return self.rate
128
+ return self.rate * math.exp(
129
+ -self.activation_energy / GAS_CONSTANT * (1.0 / temperature - 1.0 / self.temperature)
130
+ )
131
+
132
+ def dp(self, t, temperature: float | None = None) -> np.ndarray:
133
+ """Degree of polymerization after the time ``t`` (s)."""
134
+ return 1.0 / (1.0 / self.dp0 + self.rate_at(temperature) * np.asarray(t, dtype=float))
135
+
136
+ def scissions(self, t, temperature: float | None = None) -> np.ndarray:
137
+ """Scissions per initial chain, ``DP(0)/DP(t) - 1``."""
138
+ return self.dp0 / self.dp(t, temperature) - 1.0
139
+
140
+ def time_to(self, dp: float | None = None, temperature: float | None = None) -> float:
141
+ """Time to reach the degree of polymerization ``dp`` (default: the critical one)."""
142
+ dp = self.critical_dp if dp is None else dp
143
+ return (1.0 / dp - 1.0 / self.dp0) / self.rate_at(temperature)