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,594 @@
1
+ """Open-cell foams and trabecular bone: struts along the edges of a tessellation; fibre
2
+ networks along the edges of a Delaunay triangulation.
3
+
4
+ The struts of open-cell foams (polymer and metal foams, sponges) and of trabecular bone
5
+ (the cancellous bone of vertebrae and of the ends of long bones) lie along the edges of
6
+ cells close to those of a Voronoi tessellation; their stiffness scales as the square of
7
+ their relative density, their walls being open (Gibson and Ashby 1997). The model takes
8
+ the edges of the exact periodic Voronoi tessellation of germs (see
9
+ :func:`morphogen.mesh.polyhedra.periodic_cells`) as spherocylinders of radius ``r``,
10
+ with spheres of ``node_ratio r`` at the vertices (the thickening of the nodes, the
11
+ Plateau borders of liquid foams). The germs are
12
+
13
+ * Poisson points (``regularity`` 0): the Poisson-Voronoi foam;
14
+ * points at least ``regularity`` jamming distance of their random sequential addition
15
+ apart, for more even cells;
16
+ * moved ``relaxation`` times to the centroids of their cells (Lloyd's algorithm, on
17
+ sample points): toward a centroidal tessellation, whose regular cells are close to
18
+ those of real foams.
19
+
20
+ Trabecular bone aligns its struts with the main loads (Wolff's law): the cells are
21
+ elongated by ``anisotropy`` along ``axis`` (the tessellation of the germs is computed
22
+ in the box shortened by that factor along the axis, then stretched back), or by the
23
+ stretches of an affine anisotropy along the box axes (:mod:`morphogen.models.affine`: the
24
+ schema of the other models, here with struts of circular sections). The strut
25
+ radius is given, or solved on each realization for a relative density
26
+ (``volume_fraction``, measured on voxels a few times finer than the struts).
27
+
28
+ The edges of a Poisson-Voronoi tessellation of ``lambda`` germs per unit volume are
29
+ ``L_V = 5.832 lambda^(2/3)`` long per unit volume (Meijering 1953) and meet at ``N_V =
30
+ 24 pi^2 / 35 lambda = 6.768 lambda`` vertices; stretched by ``a`` along an axis, a length
31
+ of isotropic directions grows by ``F(a) = (a + acosh(a) / sqrt(a^2 - 1)) / 2`` (``(a +
32
+ acos(a) / sqrt(1 - a^2)) / 2`` for ``a < 1``), and thin struts take the volume fraction
33
+ ``pi r^2 L_V`` to first order.
34
+
35
+ The fibre networks of Ban et al. (2016) lie along the edges of the dual triangulation,
36
+ the Delaunay triangulation of the germs (:class:`DelaunayNetwork`): two germs are joined
37
+ when their Voronoi cells share a face, ``2 + 48 pi^2 / 35 = 15.54`` neighbours on average
38
+ for Poisson germs in space (Meijering's mean number of faces), 6 in the plane.
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+ import itertools
44
+ import math
45
+ from dataclasses import dataclass
46
+ from typing import ClassVar
47
+
48
+ import numpy as np
49
+ from scipy import optimize
50
+ from scipy.spatial import Delaunay, cKDTree
51
+
52
+ from morphogen import settings, theory
53
+ from morphogen._utils import check_fraction, check_positive, exactly_one
54
+ from morphogen.design.frames import Framework
55
+ from morphogen.domain import Domain, Grid
56
+ from morphogen.kernels.rsa import random_sequential_addition
57
+ from morphogen.models.affine import Anisotropy
58
+ from morphogen.models.base import Model, param, register
59
+ from morphogen.models.planar import hardcore_germs, jamming_distance
60
+ from morphogen.models.union import PrimitiveUnion
61
+ from morphogen.primitives import Segments, Spheres, with_periodic_images
62
+ from morphogen.seeding import SeedLike, make_rng
63
+
64
+ #: Volume fraction of spheres at the jamming limit of their random sequential addition.
65
+ RSA_JAMMING_3D = 0.384
66
+ #: Edge length per unit volume of Poisson-Voronoi tessellations, per lambda^(2/3).
67
+ VORONOI_EDGE_COEFF = 5.832
68
+ #: Vertices per unit volume of Poisson-Voronoi tessellations, per germ.
69
+ VORONOI_VERTEX_COEFF = 24.0 * math.pi**2 / 35.0
70
+
71
+
72
+ def stretch_factor(a: float) -> float:
73
+ """Mean growth of the lengths of isotropic segments stretched by ``a`` along an axis:
74
+ ``E[sqrt(1 + (a^2 - 1) cos^2 theta)]``."""
75
+ if abs(a - 1.0) < 1e-12:
76
+ return 1.0
77
+ if a > 1.0:
78
+ return 0.5 * (a + math.acosh(a) / math.sqrt(a * a - 1.0))
79
+ return 0.5 * (a + math.acos(a) / math.sqrt(1.0 - a * a))
80
+
81
+
82
+ def lloyd_step(germs: np.ndarray, size: np.ndarray, samples: int, rng) -> np.ndarray:
83
+ """Germs moved to the centroids of their periodic Voronoi cells, estimated on
84
+ ``samples`` random points of the box."""
85
+ n = len(germs)
86
+ tree = cKDTree(germs, boxsize=size)
87
+ pts = rng.random((samples, 3)) * size
88
+ _, label = tree.query(pts, k=1, workers=settings.workers())
89
+ d = pts - germs[label]
90
+ d -= size * np.round(d / size) # from the germ to the point, on the torus
91
+ count = np.bincount(label, minlength=n)
92
+ shift = np.column_stack([np.bincount(label, weights=d[:, i], minlength=n) for i in range(3)])
93
+ moved = germs + shift / np.maximum(count, 1)[:, None]
94
+ out = np.mod(moved, size)
95
+ out[out >= size] = 0.0
96
+ return out
97
+
98
+
99
+ def _voronoi_edges(germs: np.ndarray, size: np.ndarray):
100
+ """The vertices of the periodic Voronoi complex of ``germs``, its edges each once (not
101
+ their translates), and the class of each vertex on the torus with its translation."""
102
+ from morphogen.mesh.polyhedra import periodic_cells, torus_classes
103
+
104
+ cx = periodic_cells(germs, None, np.zeros(3), size)
105
+ tol = 1e-9 * float(size.max())
106
+ label, shift = torus_classes(cx.vertices, np.zeros(3), size, tol)
107
+ e = cx.edges()
108
+ a, b = label[e[:, 0]], label[e[:, 1]]
109
+ rel = shift[e[:, 1]] - shift[e[:, 0]] # the translates of an edge share (a, b, rel)
110
+ swap = a > b # one orientation: (a, b, rel) is (b, a, -rel)
111
+ rel = np.where(swap[:, None], -rel, rel)
112
+ lead = rel[np.arange(len(rel)), np.argmax(rel != 0, axis=1)]
113
+ rel[(a == b) & (lead < 0)] *= -1 # from a vertex to its own translate
114
+ keys = np.column_stack([np.where(swap, b, a), np.where(swap, a, b), rel])
115
+ _, first = np.unique(keys, axis=0, return_index=True)
116
+ return cx.vertices, e[np.sort(first)], label, shift
117
+
118
+
119
+ def _edge_ends(points, e, label, size) -> tuple[np.ndarray, np.ndarray]:
120
+ start, end = points[e[:, 0]], points[e[:, 1]]
121
+ # each edge from the end inside the box
122
+ offset = np.floor(start / size) * size
123
+ start, end = start - offset, end - offset
124
+ _, keep = np.unique(label, return_index=True)
125
+ vertices = np.mod(points[keep], size)
126
+ return np.stack([start, end], axis=1), vertices
127
+
128
+
129
+ def _edge_framework(points, e, label, shift, size) -> Framework:
130
+ _, keep = np.unique(label, return_index=True) # the first point of each class
131
+ wrap = np.floor(points[keep] / size).astype(np.int64) # its cell, brought to the box
132
+ a, b = label[e[:, 0]], label[e[:, 1]]
133
+ shifts = shift[e[:, 1]] - shift[e[:, 0]] + wrap[b] - wrap[a]
134
+ return Framework(points[keep] - wrap * size, np.column_stack([a, b]), shifts, size)
135
+
136
+
137
+ def periodic_edges(germs: np.ndarray, size: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
138
+ """Edges of the periodic Voronoi tessellation of ``germs`` in the box ``[0, size)``,
139
+ each once (not its translates): their ends, and the vertices, each once."""
140
+ points, e, label, _ = _voronoi_edges(germs, size)
141
+ return _edge_ends(points, e, label, size)
142
+
143
+
144
+ def periodic_framework(germs: np.ndarray, size: np.ndarray) -> Framework:
145
+ """The edges of the periodic Voronoi tessellation of ``germs`` in the box ``[0, size)``
146
+ as a framework: its vertices (in the box) joined by its edges, each once, from a vertex
147
+ to an image of the other (the frame of beams of the open foams,
148
+ :meth:`morphogen.homogenization.frames.SpaceFrame.from_framework`)."""
149
+ size = np.asarray(size, dtype=float)
150
+ points, e, label, shift = _voronoi_edges(germs, size)
151
+ return _edge_framework(points, e, label, shift, size)
152
+
153
+
154
+ def frame_summary(framework: Framework, radius: float, dimension: int = 3) -> dict:
155
+ """The stiffness of the frame of beams of a framework (fibres of Young's modulus 1 and
156
+ Poisson's ratio 0.3), for the summaries of the network models
157
+ (:meth:`morphogen.homogenization.networks.FrameStiffness.summary`), with the upper
158
+ triangles of its stiffness ``frame_C11`` ... and of its compliance ``frame_S11`` ...
159
+ (``S = C^-1``; Voigt order 11, 22, 33, 23, 31, 12 with engineering shears, 11, 22, 12
160
+ per unit area in the plane; in units of the modulus of the fibres)."""
161
+ from morphogen.homogenization.networks import network_stiffness
162
+ from morphogen.homogenization.postprocess import matrix_entries
163
+
164
+ stiffness = network_stiffness(framework, radius, dimension=dimension)
165
+ out = stiffness.summary()
166
+ out.update({f"frame_{k}": v for k, v in matrix_entries(stiffness.stiffness, "C").items()})
167
+ out.update({f"frame_{k}": v for k, v in matrix_entries(stiffness.compliance(), "S").items()})
168
+ return {k: float(f"{v:.8g}") for k, v in out.items()}
169
+
170
+
171
+ #: The doc of the parameter of the network models that adds the stiffness of their frame
172
+ FRAME_STIFFNESS = (
173
+ "Add the stiffness of the frame of beams of the fibres (Young's modulus 1, Poisson's "
174
+ "ratio 0.3) to the summary: E, Poisson's ratio, ratio to the affine estimate, fraction "
175
+ "of stretching energy and non-affinity under uniaxial stress, and its stiffness C_ij and "
176
+ "compliance S_ij (Voigt 11, 22, 33, 23, 31, 12, engineering shears)"
177
+ )
178
+
179
+
180
+ @register
181
+ @dataclass(frozen=True)
182
+ class OpenFoam(Model):
183
+ """Open-cell foam or trabecular bone: struts along the edges of the periodic Voronoi
184
+ tessellation of (regularized) germs, cells elongated by ``anisotropy`` along
185
+ ``axis``, with a strut radius or a relative density. The framework of the struts is
186
+ kept in the metadata (:func:`periodic_framework`), and with ``frame_stiffness`` the
187
+ stiffness of its frame of beams in the summary."""
188
+
189
+ name = "open_foam"
190
+ phases: ClassVar[dict[int, str]] = {0: "pores", 1: "struts"}
191
+ count_label = "cells"
192
+
193
+ n_cells: int | None = param(
194
+ None, doc="Number of cells: exactly in a periodic box, on average otherwise", kind="int"
195
+ )
196
+ intensity: float | None = param(None, doc="Cells per unit volume", unit="1/length^3")
197
+ strut_radius: float | None = param(None, doc="Radius of the struts", unit="length")
198
+ volume_fraction: float | None = param(
199
+ None, doc="Relative density, reached on each realization", kind="fraction"
200
+ )
201
+ node_ratio: float = param(1.0, doc="Radius of the spheres at the vertices, in strut radii")
202
+ regularity: float = param(
203
+ 0.0, doc="Least distance of the germs, in jamming distances (0: Poisson)", kind="fraction"
204
+ )
205
+ relaxation: int = param(0, doc="Lloyd iterations toward a centroidal tessellation", kind="int")
206
+ anisotropy: Anisotropy = param(
207
+ 1.0,
208
+ doc="Elongation of the cells along the axis, or an affine anisotropy {stretch: "
209
+ "[sx, sy, sz], euler: [phi1, Phi, phi2]} whose principal axes are the box axes",
210
+ kind="anisotropy",
211
+ )
212
+ axis: int = param(2, doc="Axis of the elongation (0: x, 1: y, 2: z)", kind="int")
213
+ frame_stiffness: bool = param(False, doc=FRAME_STIFFNESS, kind="bool", kw_only=True)
214
+
215
+ def _validate(self) -> None:
216
+ exactly_one("n_cells", self.n_cells, "intensity", self.intensity)
217
+ exactly_one("strut_radius", self.strut_radius, "volume_fraction", self.volume_fraction)
218
+ if self.n_cells is not None and self.n_cells < 1:
219
+ raise ValueError("n_cells: at least one cell")
220
+ if self.intensity is not None:
221
+ check_positive(self.intensity, "intensity")
222
+ if self.strut_radius is not None:
223
+ check_positive(self.strut_radius, "strut_radius")
224
+ if self.volume_fraction is not None:
225
+ check_fraction(self.volume_fraction, "volume_fraction")
226
+ if not 1.0 <= self.node_ratio < math.inf:
227
+ raise ValueError("node_ratio: at least 1 (nodes as thick as the struts), finite")
228
+ if not 0.0 <= self.regularity <= 0.9:
229
+ raise ValueError("regularity: from 0 (Poisson germs) to 0.9 (near jamming)")
230
+ if not 0 <= self.relaxation <= 200:
231
+ raise ValueError("relaxation: from 0 to 200 iterations")
232
+ if self.anisotropy is None:
233
+ raise ValueError("anisotropy: an elongation or an affine anisotropy (1: isotropic)")
234
+ if self.anisotropy.box_stretch() is None:
235
+ raise ValueError(
236
+ "anisotropy: principal axes along the box axes (the tessellation is periodic)"
237
+ )
238
+ if self.axis not in (0, 1, 2):
239
+ raise ValueError("axis: 0, 1 or 2")
240
+
241
+ def theta(self, domain: Domain | None) -> float:
242
+ """Cells per unit volume."""
243
+ if self.intensity is not None:
244
+ return float(self.intensity)
245
+ if domain is None:
246
+ raise ValueError("open_foam: the intensity of n_cells depends on the domain")
247
+ return self.n_cells / domain.volume
248
+
249
+ def _germs(self, rng, n: int, size: np.ndarray) -> np.ndarray:
250
+ if self.regularity > 0:
251
+ jamming = (6.0 * RSA_JAMMING_3D * float(np.prod(size)) / (math.pi * n)) ** (1 / 3)
252
+ distance = self.regularity * jamming
253
+ germs = random_sequential_addition(
254
+ np.full(n, 0.5 * distance), size, 0.0, rng, max_attempts=4000 * n + 100_000
255
+ )
256
+ else:
257
+ germs = rng.random((n, 3)) * size
258
+ samples = int(min(4_000_000, 300 * n))
259
+ for _ in range(self.relaxation):
260
+ germs = lloyd_step(germs, size, samples, rng)
261
+ return germs
262
+
263
+ def _union(self, domain, ends, vertices, r: float, **kwargs) -> PrimitiveUnion:
264
+ segments = Segments(ends[:, 0], ends[:, 1], np.full(len(ends), r), round_caps=True)
265
+ spheres = None
266
+ if self.node_ratio > 1.0:
267
+ spheres = Spheres(vertices, np.full(len(vertices), self.node_ratio * r))
268
+ return PrimitiveUnion(domain, spheres=spheres, segments=segments, **kwargs)
269
+
270
+ def _solve_radius(self, domain, ends, vertices, length: float) -> float:
271
+ """Radius of the struts of a realization for the relative density (voxels about
272
+ a quarter of the radius wide)."""
273
+ target = float(self.volume_fraction)
274
+ guess = math.sqrt(target * domain.volume / (math.pi * length))
275
+ h = guess / 4.0
276
+ shape = np.clip(np.ceil(domain.lengths / h), 16, 256).astype(int)
277
+ grid = Grid(domain, tuple(int(s) for s in shape))
278
+
279
+ def excess(r):
280
+ union = self._union(domain, ends, vertices, r)
281
+ return float(union.voxelize(grid=grid).data.mean()) - target
282
+
283
+ lo, hi = 0.25 * guess, 2.0 * guess
284
+ while excess(hi) < 0 and hi < 0.5 * float(domain.lengths.min()):
285
+ lo, hi = hi, 2.0 * hi
286
+ return float(optimize.brentq(excess, lo, hi, xtol=1e-3 * guess))
287
+
288
+ @property
289
+ def stretch(self) -> np.ndarray:
290
+ """The stretches of the cells along x, y and z."""
291
+ a = self.anisotropy
292
+ if a.elongation is None:
293
+ return a.box_stretch()
294
+ stretch = np.ones(3)
295
+ stretch[self.axis] = a.elongation
296
+ return stretch
297
+
298
+ def _elongation(self) -> float | None:
299
+ """The elongation of uniaxial stretches (two equal ones), None otherwise."""
300
+ t = np.sort(self.stretch)
301
+ if abs(t[0] - t[1]) <= 1e-12 * t[2]:
302
+ return float(t[2] / t[0])
303
+ if abs(t[1] - t[2]) <= 1e-12 * t[2]:
304
+ return float(t[0] / t[2])
305
+ return None
306
+
307
+ def generate(self, domain: Domain, seed: SeedLike = None) -> PrimitiveUnion:
308
+ rng, seed_info = make_rng(seed)
309
+ theta = self.theta(domain)
310
+ if domain.periodic and self.n_cells is not None:
311
+ n = int(self.n_cells)
312
+ else:
313
+ n = max(1, int(rng.poisson(theta * domain.volume)))
314
+ stretch = self.stretch
315
+ size = domain.lengths / stretch # the box of the isotropic tessellation
316
+ germs = self._germs(rng, n, size)
317
+ points, e, label, shift = _voronoi_edges(germs, size)
318
+ ends, vertices = _edge_ends(points, e, label, size)
319
+ frame = _edge_framework(points, e, label, shift, size)
320
+ frame = Framework(frame.nodes * stretch, frame.bars, frame.shifts, domain.lengths)
321
+ ends = ends * stretch + domain.lower
322
+ vertices = vertices * stretch + domain.lower
323
+ length = float(np.linalg.norm(ends[:, 1] - ends[:, 0], axis=1).sum())
324
+ if self.strut_radius is not None:
325
+ r = float(self.strut_radius)
326
+ else:
327
+ r = self._solve_radius(domain, ends, vertices, length)
328
+ summary = {"n_cells": n, "strut_radius": r, "edge_length_density": length / domain.volume}
329
+ if self.frame_stiffness:
330
+ summary.update(frame_summary(frame, r))
331
+ metadata = {"summary": summary, "framework": frame.to_dict()}
332
+ return self._union(domain, ends, vertices, r, model=self, seed=seed_info,
333
+ metadata=metadata) # fmt: skip
334
+
335
+ # -- theory ----------------------------------------------------------------------------
336
+
337
+ def expected_count(self, domain: Domain) -> float:
338
+ return self.theta(domain) * domain.volume
339
+
340
+ def theory(self, domain: Domain | None = None) -> dict[str, float]:
341
+ out: dict[str, float] = {}
342
+ if self.intensity is None and domain is None:
343
+ return out
344
+ theta = self.theta(domain)
345
+ out["intensity"] = theta
346
+ a = self._elongation()
347
+ if self.regularity == 0 and self.relaxation == 0: # Poisson-Voronoi edges
348
+ out["vertex_density"] = VORONOI_VERTEX_COEFF * theta
349
+ if self.regularity == 0 and self.relaxation == 0 and a is not None:
350
+ lv = VORONOI_EDGE_COEFF * (a * theta) ** (2 / 3) * stretch_factor(a) / a
351
+ out["edge_length_density"] = lv
352
+ if self.strut_radius is not None:
353
+ out["volume_fraction_first_order"] = math.pi * self.strut_radius**2 * lv
354
+ return out
355
+
356
+
357
+ def _circumspheres(simplices: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
358
+ """Centres and radii of the circumspheres of simplices (m x (d + 1) x d vertices)."""
359
+ p0 = simplices[:, 0]
360
+ a = 2.0 * (simplices[:, 1:] - p0[:, None])
361
+ b = np.sum(simplices[:, 1:] ** 2, axis=2) - np.sum(p0**2, axis=1)[:, None]
362
+ centre = np.linalg.solve(a, b[..., None])[..., 0]
363
+ return centre, np.linalg.norm(centre - p0, axis=1)
364
+
365
+
366
+ def periodic_delaunay(points, size) -> tuple[np.ndarray, np.ndarray]:
367
+ """The edges of the Delaunay triangulation of the periodic box ``[0, size)`` of the
368
+ ``points`` (2 or 3 coordinates), each once (not its translates): the pairs ``(i, j)``
369
+ and the shifts ``s`` of the edges from ``points[i]`` to ``points[j] + s * size``. The
370
+ points and their images within a margin of the box (three mean spacings, then doubled)
371
+ are triangulated (SciPy/Qhull) until the circumsphere of every simplex at a point of
372
+ the box lies in the margin, so that it is empty of every image: the simplices at the
373
+ points of the box are those of the periodic triangulation. The images are those of as
374
+ many periods along each axis as the margin spans (thin boxes: several across)."""
375
+ pts = np.asarray(points, dtype=float)
376
+ n, dim = pts.shape
377
+ size = np.asarray(size, dtype=float).reshape(dim)
378
+ if n < dim + 2:
379
+ raise ValueError(f"delaunay_network: at least {dim + 2} points, got {n}")
380
+ margin = 3.0 * (float(np.prod(size)) / n) ** (1.0 / dim)
381
+ while True:
382
+ reach = np.ceil(margin / size).astype(int) # the periods within the margin
383
+ shifts = np.array(list(itertools.product(*(range(-k, k + 1) for k in reach))))
384
+ shifts = shifts[np.argsort(np.abs(shifts).sum(axis=1), kind="stable")] # the box first
385
+ image, index, shift = [], [], []
386
+ for s in shifts:
387
+ q = pts + s * size
388
+ keep = np.all((q >= -margin) & (q < size + margin), axis=1)
389
+ image.append(q[keep])
390
+ index.append(np.flatnonzero(keep))
391
+ shift.append(np.repeat(s[None], int(keep.sum()), axis=0))
392
+ allp, index, shift = np.concatenate(image), np.concatenate(index), np.concatenate(shift)
393
+ tri = Delaunay(allp)
394
+ at_box = tri.simplices[np.any(tri.simplices < n, axis=1)]
395
+ centre, radius = _circumspheres(allp[at_box])
396
+ inside = np.all(centre - radius[:, None] >= -margin) and np.all(
397
+ centre + radius[:, None] <= size + margin
398
+ )
399
+ if inside:
400
+ break
401
+ if margin > 4.0 * float(size.max()):
402
+ raise ValueError("delaunay_network: too few points for a periodic triangulation")
403
+ margin *= 2.0
404
+ indptr, neighbours = tri.vertex_neighbor_vertices
405
+ i = np.repeat(np.arange(n), np.diff(indptr)[:n])
406
+ j = neighbours[: indptr[n]]
407
+ a, b, s = i, index[j], shift[j] # from the point i of the box to the image j
408
+ first = s[np.arange(len(s)), np.argmax(s != 0, axis=1)]
409
+ flip = (a > b) | ((a == b) & (first < 0)) # one orientation: (a, b, s) is (b, a, -s)
410
+ key = np.column_stack(
411
+ [np.where(flip, b, a), np.where(flip, a, b), np.where(flip[:, None], -s, s)]
412
+ )
413
+ key = np.unique(key, axis=0)
414
+ return key[:, :2], key[:, 2:]
415
+
416
+
417
+ DIMENSIONS = (2, 3)
418
+
419
+
420
+ @register
421
+ @dataclass(frozen=True)
422
+ class DelaunayNetwork(Model):
423
+ """Fibre networks along the edges of the Delaunay triangulation of random points (Ban,
424
+ Barocas, Shephard & Picu 2016), in space or in a plane.
425
+
426
+ As in Ban et al. (J. Mech. Phys. Solids 87, 38, 2016), points are drawn in the box and
427
+ fibres join the points whose Voronoi cells share a face: the edges of their Delaunay
428
+ triangulation (periodic: :func:`periodic_delaunay`), the struts of the dual of the open
429
+ foams of :class:`OpenFoam` (spherocylinders of ``radius``, spheres of ``node_ratio``
430
+ radii at the nodes), cross-linked at every node. The points are Poisson points, at
431
+ least ``regularity`` jamming distance of their random sequential addition apart
432
+ (hard-core points), or moved ``relaxation`` times to the centroids of their Voronoi
433
+ cells (space only). ``dimension: 2``: a planar network of points of the plane ``z`` in
434
+ the middle of the domain (the planar Delaunay graph; ``intensity`` per unit area).
435
+ The radius is given, or solved on each realization for a ``volume_fraction``. The
436
+ framework of the nodes and fibres (:class:`morphogen.design.frames.Framework`) is kept
437
+ in the metadata, its coordination and fibre lengths in the summary, and with
438
+ ``frame_stiffness`` the stiffness of its frame of beams
439
+ (:mod:`morphogen.homogenization.networks`).
440
+ """
441
+
442
+ name = "delaunay_network"
443
+ phases: ClassVar[dict[int, str]] = {0: "pores", 1: "fibres"}
444
+ count_label = "nodes"
445
+
446
+ n_points: int | None = param(
447
+ None, doc="Number of nodes: exactly in a periodic box, on average otherwise", kind="int"
448
+ )
449
+ intensity: float | None = param(
450
+ None, doc="Nodes per unit volume (per unit area in a plane)", unit="1/length^3"
451
+ )
452
+ radius: float | None = param(None, doc="Radius of the fibres", unit="length")
453
+ volume_fraction: float | None = param(
454
+ None, doc="Volume fraction of the fibres, reached on each realization", kind="fraction"
455
+ )
456
+ node_ratio: float = param(1.0, doc="Radius of the spheres at the nodes, in fibre radii")
457
+ regularity: float = param(
458
+ 0.0, doc="Least distance of the points, in jamming distances (0: Poisson)", kind="fraction"
459
+ )
460
+ relaxation: int = param(
461
+ 0, doc="Lloyd iterations toward a centroidal tessellation (space only)", kind="int"
462
+ )
463
+ dimension: int = param(3, doc="3, or 2: a planar network in the middle plane z", kind="int")
464
+ frame_stiffness: bool = param(False, doc=FRAME_STIFFNESS, kind="bool", kw_only=True)
465
+
466
+ # the germs and the radius of a fraction of the open foams
467
+ _germs = OpenFoam._germs
468
+ _solve_radius = OpenFoam._solve_radius
469
+
470
+ def _union(self, domain, ends, vertices, r: float, **kwargs) -> PrimitiveUnion:
471
+ """The struts of the open foams; in a box that is not periodic, with their periodic
472
+ images: the periodic network cut by the box, the fibres leaving it by a face
473
+ entering it again by the opposite one."""
474
+ union = OpenFoam._union(self, domain, ends, vertices, r, **kwargs)
475
+ if domain.periodic:
476
+ return union
477
+ spheres = with_periodic_images(union.spheres, domain)
478
+ segments = with_periodic_images(union.segments, domain)
479
+ return PrimitiveUnion(domain, spheres=spheres, segments=segments, **kwargs)
480
+
481
+ def _validate(self) -> None:
482
+ exactly_one("n_points", self.n_points, "intensity", self.intensity)
483
+ exactly_one("radius", self.radius, "volume_fraction", self.volume_fraction)
484
+ if self.dimension not in DIMENSIONS:
485
+ raise ValueError("dimension: 2 or 3")
486
+ if self.n_points is not None and self.n_points < self.dimension + 2:
487
+ raise ValueError(f"n_points: at least {self.dimension + 2}")
488
+ if self.intensity is not None:
489
+ check_positive(self.intensity, "intensity")
490
+ if self.radius is not None:
491
+ check_positive(self.radius, "radius")
492
+ if self.volume_fraction is not None:
493
+ check_fraction(self.volume_fraction, "volume_fraction")
494
+ if not 1.0 <= self.node_ratio < math.inf:
495
+ raise ValueError("node_ratio: at least 1 (nodes as thick as the fibres), finite")
496
+ if not 0.0 <= self.regularity <= 0.9:
497
+ raise ValueError("regularity: from 0 (Poisson points) to 0.9 (near jamming)")
498
+ if not 0 <= self.relaxation <= 200:
499
+ raise ValueError("relaxation: from 0 to 200 iterations")
500
+ if self.relaxation and self.dimension == 2:
501
+ raise ValueError("relaxation: networks in space only (dimension: 3)")
502
+
503
+ def _measure(self, domain: Domain) -> float:
504
+ """The volume of the domain, or the area of its plane for a planar network."""
505
+ lengths = domain.lengths
506
+ return float(np.prod(lengths[:2]) if self.dimension == 2 else np.prod(lengths))
507
+
508
+ def theta(self, domain: Domain | None) -> float:
509
+ """Nodes per unit volume (per unit area for a planar network)."""
510
+ if self.intensity is not None:
511
+ return float(self.intensity)
512
+ if domain is None:
513
+ raise ValueError("delaunay_network: the intensity of n_points depends on the domain")
514
+ return self.n_points / self._measure(domain)
515
+
516
+ def framework(self, domain: Domain, rng) -> Framework:
517
+ """The nodes (from the lower corner of the domain) and fibres of a realization."""
518
+ lengths = np.asarray(domain.lengths, dtype=float)
519
+ planar = self.dimension == 2
520
+ size = lengths[:2] if planar else lengths
521
+ if domain.periodic and self.n_points is not None:
522
+ n = int(self.n_points)
523
+ else:
524
+ n = max(
525
+ self.dimension + 2, int(rng.poisson(self.theta(domain) * self._measure(domain)))
526
+ )
527
+ if planar:
528
+ least = self.regularity * jamming_distance(n, float(np.prod(size)))
529
+ points = hardcore_germs(n, size, least, rng)
530
+ points = np.column_stack([points, np.full(n, 0.5 * lengths[2])])
531
+ else:
532
+ points = self._germs(rng, n, size)
533
+ pairs, shifts = periodic_delaunay(points[:, : self.dimension], size)
534
+ if planar:
535
+ shifts = np.column_stack([shifts, np.zeros(len(shifts), dtype=np.int64)])
536
+ return Framework(points, pairs, shifts, lengths)
537
+
538
+ def generate(self, domain: Domain, seed: SeedLike = None) -> PrimitiveUnion:
539
+ rng, seed_info = make_rng(seed)
540
+ frame = self.framework(domain, rng)
541
+ vectors = frame.vectors()
542
+ start = frame.nodes[frame.bars[:, 0]] + domain.lower
543
+ ends = np.stack([start, start + vectors], axis=1)
544
+ vertices = frame.nodes + domain.lower
545
+ lengths = np.linalg.norm(vectors, axis=1)
546
+ total = float(lengths.sum())
547
+ r = (
548
+ self.radius
549
+ if self.radius is not None
550
+ else self._solve_radius(domain, ends, vertices, total)
551
+ )
552
+ summary = {
553
+ "nodes": frame.n_nodes,
554
+ "fibres": frame.n_bars,
555
+ "coordination": round(frame.coordination(), 6),
556
+ "mean_fibre_length": float(lengths.mean()),
557
+ "fibre_length_cv": float(lengths.std() / lengths.mean()),
558
+ "fibre_length_density": total / domain.volume,
559
+ "radius": float(r),
560
+ }
561
+ if self.dimension == 2:
562
+ summary["fibre_length_per_area"] = total / self._measure(domain)
563
+ if self.frame_stiffness:
564
+ summary.update(frame_summary(frame, float(r), self.dimension))
565
+ metadata = {"summary": summary, "framework": frame.to_dict()}
566
+ return self._union(domain, ends, vertices, float(r), model=self, seed=seed_info,
567
+ metadata=metadata) # fmt: skip
568
+
569
+ def expected_count(self, domain: Domain) -> float:
570
+ return self.theta(domain) * self._measure(domain)
571
+
572
+ def theory(self, domain: Domain | None = None) -> dict[str, float]:
573
+ """The coordination of the Poisson-Delaunay graph, ``2 + 48 pi^2 / 35`` in space (the
574
+ mean number of faces of the Poisson-Voronoi cell, Meijering 1953) and 6 in the plane
575
+ (Euler), and in the plane the mean fibre length ``32 / (9 pi) lambda^(-1/2)`` (Miles
576
+ 1970) and the fibre length per unit area ``3 lambda`` times it. In space the mean
577
+ length of a fibre has no closed form: ``1.237 lambda^(-1/3)`` (Miles 1974) is that
578
+ of the edges of the typical tetrahedron, which counts each fibre once per
579
+ tetrahedron around it, and the fibres themselves are longer (1.285 on 20,000
580
+ points)."""
581
+ out: dict[str, float] = {}
582
+ if self.intensity is None and domain is None:
583
+ return out
584
+ theta = self.theta(domain)
585
+ out["intensity"] = theta
586
+ if self.regularity == 0 and self.relaxation == 0: # Poisson-Delaunay
587
+ if self.dimension == 3:
588
+ out["coordination"] = theory.VORONOI_MEAN_FACES
589
+ else:
590
+ mean = 32.0 / (9.0 * math.pi) / math.sqrt(theta)
591
+ out["coordination"] = 6.0
592
+ out["mean_fibre_length"] = mean
593
+ out["fibre_length_per_area"] = 3.0 * theta * mean
594
+ return out