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,331 @@
1
+ """Geometries for isogeometric analyses: patches and assemblies with exact arcs.
2
+
3
+ A circular arc of half-angle ``a`` is a rational curve of degree 2: its ends, the point
4
+ where their tangents meet, and the weights ``(1, cos a, 1)`` (Piegl & Tiller 1997, ch.
5
+ 7); an ellipse is the image of a circle by a linear map of its control points. The
6
+ patches here are *ruled* between two such curves — linear across, of the degree of the
7
+ curves along — with positive Jacobians:
8
+
9
+ * :func:`rectangle`, :func:`box`: a rectangle or a box, of any degree;
10
+ * :func:`annulus`: a sector of a ring (a thick-walled cylinder in plane strain);
11
+ * :func:`plate_with_hole`: a quarter of a square plate with a central hole, two patches
12
+ (the benchmark of Kirsch's solution, and of shape optimization);
13
+ * :func:`cell_with_hole`: a rectangular cell with a hole, four patches around it, whose
14
+ opposite sides match: a periodic cell (porous and architectured materials), the hole
15
+ a circle, an ellipse, or any closed curve through its control points; the cell may
16
+ be a parallelogram (the rhombus of a hexagonal array of holes);
17
+ * :func:`alternating_holes`: a sheet with elongated holes at the nodes of a square
18
+ lattice, turned in turn along its two axes — the pattern of the *rotating squares*,
19
+ auxetic when its ligaments are thin (Grima & Evans 2000; Bertoldi et al. 2010;
20
+ Taylor et al. 2014);
21
+ * :func:`tiling`: cells side by side as one assembly (several holes per period);
22
+ :func:`repeated`: a cell and its neighbours along its periods;
23
+ * :func:`extruded`: a surface swept along the third axis into a solid.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import math
29
+
30
+ import numpy as np
31
+
32
+ from morphogen.iga.basis import open_knots
33
+ from morphogen.iga.geometry import Multipatch, Patch
34
+
35
+
36
+ def rectangle(lower=(0.0, 0.0), upper=(1.0, 1.0), degree: int = 1, phase: int = 0) -> Patch:
37
+ """The rectangle of corners ``lower`` and ``upper``: one element of ``degree``."""
38
+ lower, upper = np.asarray(lower, dtype=float), np.asarray(upper, dtype=float)
39
+ n = int(degree) + 1
40
+ axes = [np.linspace(lower[d], upper[d], n) for d in range(2)]
41
+ points = np.stack(np.meshgrid(*axes, indexing="ij"), axis=-1)
42
+ knots = open_knots(n, degree)
43
+ return Patch((degree, degree), (knots, knots), points, None, phase)
44
+
45
+
46
+ def box(lower=(0.0, 0.0, 0.0), upper=(1.0, 1.0, 1.0), degree: int = 1, phase: int = 0) -> Patch:
47
+ """The box of corners ``lower`` and ``upper``: one element of ``degree``."""
48
+ lower, upper = np.asarray(lower, dtype=float), np.asarray(upper, dtype=float)
49
+ n = int(degree) + 1
50
+ axes = [np.linspace(lower[d], upper[d], n) for d in range(3)]
51
+ points = np.stack(np.meshgrid(*axes, indexing="ij"), axis=-1)
52
+ knots = open_knots(n, degree)
53
+ return Patch((degree,) * 3, (knots,) * 3, points, None, phase)
54
+
55
+
56
+ def arc(
57
+ radius: float, start: float, end: float, centre=(0.0, 0.0)
58
+ ) -> tuple[np.ndarray, np.ndarray]:
59
+ """The three control points and weights of the circular arc from the angle ``start``
60
+ to ``end`` (less than a half-turn apart): exact, of degree 2."""
61
+ half = 0.5 * (end - start)
62
+ if not 0.0 < abs(half) < 0.5 * math.pi:
63
+ raise ValueError("arc: an angle between 0 and a half-turn")
64
+ middle = 0.5 * (start + end)
65
+ centre = np.asarray(centre, dtype=float)
66
+ points = np.array(
67
+ [
68
+ [radius * math.cos(start), radius * math.sin(start)],
69
+ [
70
+ radius / math.cos(half) * math.cos(middle),
71
+ radius / math.cos(half) * math.sin(middle),
72
+ ],
73
+ [radius * math.cos(end), radius * math.sin(end)],
74
+ ]
75
+ )
76
+ return points + centre, np.array([1.0, math.cos(half), 1.0])
77
+
78
+
79
+ def ruled(first, second, weights_first=None, weights_second=None, degree: int = 2,
80
+ phase: int = 0) -> Patch: # fmt: skip
81
+ """The patch between two curves of the same degree given by their control points
82
+ (``n x 2`` each, without inner knots): direction 0 along the curves, direction 1
83
+ from the first to the second (linear)."""
84
+ first, second = np.asarray(first, dtype=float), np.asarray(second, dtype=float)
85
+ n = len(first)
86
+ if first.shape != second.shape or n != int(degree) + 1:
87
+ raise ValueError("ruled: two curves of degree + 1 control points")
88
+ w1 = np.ones(n) if weights_first is None else np.asarray(weights_first, dtype=float)
89
+ w2 = np.ones(n) if weights_second is None else np.asarray(weights_second, dtype=float)
90
+ points = np.stack([first, second], axis=1)
91
+ weights = np.stack([w1, w2], axis=1)
92
+ return Patch((degree, 1), (open_knots(n, degree), open_knots(2, 1)), points, weights, phase)
93
+
94
+
95
+ def annulus(inner: float, outer: float, angle: float = 0.5 * math.pi, start: float = 0.0,
96
+ centre=(0.0, 0.0), phase: int = 0) -> Patch: # fmt: skip
97
+ """A sector of the ring between the radii ``inner`` and ``outer``, from the angle
98
+ ``start`` over ``angle`` (less than a half-turn): direction 0 along the arcs
99
+ (clockwise, so that the Jacobian is positive), direction 1 from the inner to the
100
+ outer radius."""
101
+ if not 0.0 < inner < outer:
102
+ raise ValueError("annulus: 0 < inner < outer")
103
+ p1, w1 = arc(inner, start + angle, start, centre)
104
+ p2, w2 = arc(outer, start + angle, start, centre)
105
+ return ruled(p1, p2, w1, w2, phase=phase)
106
+
107
+
108
+ def plate_with_hole(radius: float = 1.0, half_width: float = 4.0, phase: int = 0) -> Multipatch:
109
+ """A quarter (``x, y >= 0``) of a square plate of half-width ``half_width`` with a
110
+ circular hole of ``radius`` at the origin: two patches, from the right and upper
111
+ sides (direction 1 = 0) to the arcs of the hole (direction 1 = 1), along which
112
+ direction 0 turns anticlockwise."""
113
+ if not 0.0 < radius < half_width:
114
+ raise ValueError("plate_with_hole: 0 < radius < half_width")
115
+ size = float(half_width)
116
+ quarter = 0.25 * math.pi
117
+ sides = [
118
+ np.array([[size, 0.0], [size, 0.5 * size], [size, size]]),
119
+ np.array([[size, size], [0.5 * size, size], [0.0, size]]),
120
+ ]
121
+ patches = []
122
+ for k, side in enumerate(sides):
123
+ points, weights = arc(radius, k * quarter, (k + 1) * quarter)
124
+ patches.append(ruled(side, points, None, weights, phase=phase))
125
+ return Multipatch(patches)
126
+
127
+
128
+ def _ellipse(hole) -> np.ndarray:
129
+ """The linear map of the unit circle onto an ellipse: ``hole`` a radius, or ``(a,
130
+ b)`` or ``(a, b, angle)`` its half-axes and the inclination of the first."""
131
+ values = (float(hole),) * 2 if np.isscalar(hole) else tuple(float(v) for v in hole)
132
+ if len(values) not in (2, 3) or values[0] <= 0 or values[1] <= 0:
133
+ raise ValueError("hole: a radius, or the positive half-axes of an ellipse (and its angle)")
134
+ tilt = values[2] if len(values) > 2 else 0.0
135
+ rotation = np.array([[math.cos(tilt), -math.sin(tilt)], [math.sin(tilt), math.cos(tilt)]])
136
+ return rotation @ np.diag(values[:2]) @ rotation.T
137
+
138
+
139
+ def _ellipse_arc(shape: np.ndarray, centre, start: float, end: float):
140
+ """The exact arc of the ellipse that ``shape`` makes of the unit circle, between two
141
+ angles of the circle: control points and weights."""
142
+ points, weights = arc(1.0, start, end)
143
+ return points @ shape.T + np.asarray(centre, dtype=float), weights
144
+
145
+
146
+ def _hole_arcs(hole, centre: np.ndarray, corners=None) -> list[tuple[np.ndarray, np.ndarray]]:
147
+ """The four arcs (control points, weights) of a hole around ``centre``: from the
148
+ angles -45 to 45 degrees, then 45 to 135... (between the directions of the
149
+ ``corners`` of the cell, when given). ``hole``: a radius, ``(a, b)`` or ``(a, b,
150
+ angle)`` the half-axes of an ellipse and its inclination, or the 8 control points of
151
+ a closed curve of four quadratic arcs (corner points included) with their weights."""
152
+ if np.isscalar(hole) or np.ndim(hole) == 1:
153
+ shape = _ellipse(hole)
154
+ if corners is None:
155
+ angles = (2 * np.arange(5) - 1) * 0.25 * math.pi
156
+ else: # towards the corners: the angles of the circle that the ellipse is made of
157
+ directions = (np.asarray(corners) - centre) @ np.linalg.inv(shape).T
158
+ angles = np.unwrap(np.arctan2(directions[:, 1], directions[:, 0]))
159
+ angles = np.append(angles, angles[0] + 2 * math.pi)
160
+ return [_ellipse_arc(shape, centre, angles[k], angles[k + 1]) for k in range(4)]
161
+ hole = np.asarray(hole, dtype=float)
162
+ if hole.shape != (8, 3):
163
+ raise ValueError(
164
+ "hole: a radius, the half-axes (and inclination) of an ellipse, or 8 control "
165
+ "points with their weights (x, y, w), anticlockwise from the angle -45 degrees"
166
+ )
167
+ arcs = []
168
+ for k in range(4):
169
+ rows = [2 * k, 2 * k + 1, (2 * k + 2) % 8]
170
+ arcs.append((hole[rows, :2], hole[rows, 2]))
171
+ return arcs
172
+
173
+
174
+ def cell_with_hole(lengths=(1.0, 1.0), hole=0.25, elements: int = 1, origin=(0.0, 0.0),
175
+ phase: int = 0) -> Multipatch: # fmt: skip
176
+ """The rectangular cell of ``lengths`` (its lower corner at ``origin``) with a hole
177
+ at its centre (see :func:`_hole_arcs`: a radius, an ellipse, or a closed curve): four
178
+ patches, one per side of the cell, from the side (direction 1 = 0) to the arc of the
179
+ hole that faces it (direction 1 = 1), direction 0 anticlockwise; ``elements`` along
180
+ each arc. Opposite sides have matching control points: a periodic cell.
181
+
182
+ ``lengths`` may be the two vectors of a parallelogram instead (2 x 2, one per row,
183
+ anticlockwise): the cell of an oblique lattice, which the assembly then carries
184
+ (``lattice``) — ``[[1, 0], [0.5, sqrt(3) / 2]]`` for a hexagonal array of holes."""
185
+ lengths = np.asarray(lengths, dtype=float)
186
+ origin = np.asarray(origin, dtype=float)
187
+ lattice = None
188
+ if lengths.ndim == 2:
189
+ lattice = lengths
190
+ if lattice.shape != (2, 2) or np.linalg.det(lattice) <= 0:
191
+ raise ValueError("cell_with_hole: two vectors of the plane, anticlockwise")
192
+ first, second = lattice
193
+ else:
194
+ first, second = np.array([lengths[0], 0.0]), np.array([0.0, lengths[1]])
195
+ centre = origin + 0.5 * (first + second)
196
+ corners = origin + np.array([first, first + second, second, 0.0 * first])
197
+ patches = []
198
+ arcs = _hole_arcs(hole, centre, None if lattice is None else corners)
199
+ for k, (points, weights) in enumerate(arcs):
200
+ a, b = corners[k], corners[(k + 1) % 4]
201
+ side = np.array([a, 0.5 * (a + b), b])
202
+ patch = ruled(side, points, None, weights, phase=phase)
203
+ patches.append(patch.refined((int(elements), 1)) if elements > 1 else patch)
204
+ return Multipatch(patches, lattice=lattice)
205
+
206
+
207
+ def alternating_holes(spacing: float = 1.0, hole=(0.35, 0.15), elements: int = 1,
208
+ phase: int = 0) -> Multipatch: # fmt: skip
209
+ """A sheet with elliptic holes at the nodes of a square lattice of ``spacing``
210
+ along x and y, elongated in turn along x and along y: ``hole = (a, b)``, the
211
+ half-axes along and across a hole (``a + b < spacing``; a radius for circles), the
212
+ hole at the origin along x. Between four holes the sheet is a square grain, held to
213
+ its four neighbours by the ligaments left between the tip of a hole and the flank of
214
+ the next, of width ``spacing - a - b``: thin ligaments let the grains turn, and the
215
+ sheet widens when pulled (the *rotating squares*).
216
+
217
+ The assembly is two grains side by side, cut nowhere — ``[0, 2 spacing] x [0,
218
+ spacing]`` without its quarters of holes — whose periods are ``(spacing, spacing)``
219
+ and ``(spacing, -spacing)`` (its ``lattice``): two holes a period. Each grain is
220
+ eight patches around its centre, two along each of its quarters of holes, from the
221
+ arc (direction 1 = 0) to a curve between the centre of the grain and the middle of
222
+ a ligament, which it crosses squarely (direction 1 = 1), with ``elements`` along each
223
+ arc. The patches 0 and 1 are those of the hole at the origin: their arcs run from
224
+ its flank ``(0, b)`` to a point ``p``, then from ``p`` to its tip ``(a, 0)``, facing
225
+ the curves from the middle of the left ligament to the centre and from the centre
226
+ to the middle of the lower ligament; the other quarters are their images by the
227
+ symmetries of the pattern (the mirrors x = 0 and y = 0, the quarter-turn about the
228
+ centre of a grain)."""
229
+ d = float(spacing)
230
+ shape = _ellipse(hole)
231
+ a, b = float(shape[0, 0]), float(shape[1, 1])
232
+ if np.ndim(hole) == 1 and len(hole) > 2:
233
+ raise ValueError("alternating_holes: hole = (a, b), the half-axes along and across")
234
+ if not a + b < d:
235
+ raise ValueError("alternating_holes: a + b < spacing (holes apart)")
236
+ centre = np.array([0.5 * d, 0.5 * d])
237
+ middle = np.array([0.5 * (a + d - b), 0.0]) # of the ligament of the lower side
238
+ left = np.array([0.0, 0.5 * (b + d - a)]) # of that of the left side
239
+ # the point of the arc of the hole seen from the centre half-way between them
240
+ angle = math.atan2(middle[1] - centre[1], middle[0] - centre[0]) - 0.25 * math.pi
241
+ ray = np.array([math.cos(angle), math.sin(angle)])
242
+ roots = np.roots(
243
+ [
244
+ (ray[0] / a) ** 2 + (ray[1] / b) ** 2,
245
+ 2.0 * (centre[0] * ray[0] / a**2 + centre[1] * ray[1] / b**2),
246
+ (centre[0] / a) ** 2 + (centre[1] / b) ** 2 - 1.0,
247
+ ]
248
+ )
249
+ hit = centre + float(np.min(roots.real)) * ray
250
+ split = math.atan2(hit[1] / b, hit[0] / a)
251
+ flank, flank_weights = _ellipse_arc(shape, (0.0, 0.0), 0.5 * math.pi, split)
252
+ tip, tip_weights = _ellipse_arc(shape, (0.0, 0.0), split, 0.0)
253
+ # from the centre to the middle of a ligament, which the curve crosses squarely
254
+ pieces = [
255
+ (flank, flank_weights, np.array([left, [0.25 * d, left[1]], centre])),
256
+ (tip, tip_weights, np.array([centre, [middle[0], 0.25 * d], middle])),
257
+ ]
258
+ turn = np.array([[0.0, -1.0], [1.0, 0.0]])
259
+ patches = []
260
+ for mirrored in (False, True):
261
+ for k in range(4):
262
+ rotation = np.linalg.matrix_power(turn, k)
263
+ for curve, weights, line in pieces:
264
+ first = centre + (curve - centre) @ rotation.T
265
+ second = centre + (line - centre) @ rotation.T
266
+ if mirrored: # the second grain: the mirror image in the line x = spacing
267
+ first = (first * [-1.0, 1.0] + [2.0 * d, 0.0])[::-1]
268
+ second = (second * [-1.0, 1.0] + [2.0 * d, 0.0])[::-1]
269
+ weights = weights[::-1]
270
+ patch = ruled(first, second, weights, None, phase=phase)
271
+ patches.append(patch.refined((int(elements), 1)) if elements > 1 else patch)
272
+ return Multipatch(patches, lattice=[[d, d], [d, -d]])
273
+
274
+
275
+ def tiling(cells) -> Multipatch:
276
+ """The assembly of several assemblies (or patches) placed side by side: their
277
+ patches together, the control points of their common sides merged."""
278
+ patches = []
279
+ for cell in cells:
280
+ patches.extend([cell] if isinstance(cell, Patch) else cell.patches)
281
+ return Multipatch(patches)
282
+
283
+
284
+ def repeated(cell: Multipatch, counts=(2, 2)) -> Multipatch:
285
+ """A cell and its neighbours: ``counts`` copies along each of its periods (those of
286
+ its ``lattice``, or the sides of its box), as one assembly — for figures, or a
287
+ larger period."""
288
+ lattice = np.diag(cell.upper - cell.lower) if cell.lattice is None else cell.lattice
289
+ counts = (int(counts),) * cell.dim if np.isscalar(counts) else tuple(int(c) for c in counts)
290
+ if len(counts) != cell.dim or min(counts) < 1:
291
+ raise ValueError("repeated: a count of 1 or more per period")
292
+ patches = []
293
+ for index in np.ndindex(*counts):
294
+ shift = np.asarray(index, dtype=float) @ lattice
295
+ patches.extend(p.with_points(p.points + shift) for p in cell.patches)
296
+ return Multipatch(patches, cell.tolerance, lattice=np.asarray(counts)[:, None] * lattice)
297
+
298
+
299
+ def extruded(surface, height: float, degree: int = 1) -> Multipatch:
300
+ """The solid swept by a surface (a patch or an assembly in the plane) along the
301
+ third axis over ``height``: direction 2 of each patch, of ``degree``."""
302
+ surfaces = [surface] if isinstance(surface, Patch) else surface.patches
303
+ n = int(degree) + 1
304
+ levels = np.linspace(0.0, float(height), n)
305
+ patches = []
306
+ for p in surfaces:
307
+ if p.ndim != 2 or p.dim != 2:
308
+ raise ValueError("extruded: surfaces of the plane")
309
+ points = np.empty((*p.shape, n, 3))
310
+ points[..., :2] = p.points[:, :, None, :]
311
+ points[..., 2] = levels
312
+ weights = np.repeat(p.weights[:, :, None], n, axis=2)
313
+ patches.append(
314
+ Patch((*p.degrees, degree), (*p.knots, open_knots(n, degree)), points, weights, p.phase)
315
+ )
316
+ return Multipatch(patches)
317
+
318
+
319
+ __all__ = [
320
+ "alternating_holes",
321
+ "annulus",
322
+ "arc",
323
+ "box",
324
+ "cell_with_hole",
325
+ "extruded",
326
+ "plate_with_hole",
327
+ "rectangle",
328
+ "repeated",
329
+ "ruled",
330
+ "tiling",
331
+ ]
morphogen/image.py ADDED
@@ -0,0 +1,128 @@
1
+ """Voxel images: a 3D array on a regular grid with its geometry and metadata."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ import numpy as np
8
+
9
+ from morphogen._utils import as_triplet
10
+ from morphogen.domain import Domain, Grid
11
+
12
+
13
+ @dataclass
14
+ class VoxelImage:
15
+ """3D image of a microstructure.
16
+
17
+ Attributes
18
+ ----------
19
+ data
20
+ Array of shape ``(nx, ny, nz)`` indexed ``[i, j, k]`` along ``(x, y, z)``.
21
+ Typical contents: phase indices (``uint8``), cell labels (``int32``), partial
22
+ volume fractions or level-set values (``float32``).
23
+ spacing
24
+ Voxel edge lengths.
25
+ origin
26
+ Lower corner of voxel ``(0, 0, 0)`` (not its centre).
27
+ periodic
28
+ Whether the image is periodic (measurements then wrap around the faces).
29
+ name
30
+ Name of the array in exported files (e.g. ``"phase"``, ``"material"``).
31
+ metadata
32
+ JSON-able information (model, seed, version...).
33
+ """
34
+
35
+ data: np.ndarray
36
+ spacing: tuple[float, float, float] = (1.0, 1.0, 1.0)
37
+ origin: tuple[float, float, float] = (0.0, 0.0, 0.0)
38
+ periodic: bool = False
39
+ name: str = "phase"
40
+ metadata: dict = field(default_factory=dict)
41
+
42
+ def __post_init__(self) -> None:
43
+ self.data = np.asarray(self.data)
44
+ if self.data.ndim != 3:
45
+ raise ValueError(f"VoxelImage: expected a 3D array, got shape {self.data.shape}")
46
+ self.spacing = as_triplet(self.spacing, "spacing", positive=True)
47
+ self.origin = as_triplet(self.origin, "origin")
48
+ self.periodic = bool(self.periodic)
49
+
50
+ @classmethod
51
+ def from_grid(cls, data, grid: Grid, *, name: str = "phase", metadata=None) -> VoxelImage:
52
+ return cls(
53
+ data=data,
54
+ spacing=tuple(grid.spacing),
55
+ origin=tuple(grid.origin),
56
+ periodic=grid.domain.periodic,
57
+ name=name,
58
+ metadata=dict(metadata or {}),
59
+ )
60
+
61
+ @property
62
+ def shape(self) -> tuple[int, int, int]:
63
+ return tuple(int(n) for n in self.data.shape)
64
+
65
+ @property
66
+ def size(self) -> np.ndarray:
67
+ """Physical extent of the image."""
68
+ return np.array(self.shape) * np.array(self.spacing)
69
+
70
+ @property
71
+ def voxel_volume(self) -> float:
72
+ return float(np.prod(self.spacing))
73
+
74
+ @property
75
+ def volume(self) -> float:
76
+ return float(np.prod(self.size))
77
+
78
+ @property
79
+ def n_voxels(self) -> int:
80
+ return int(self.data.size)
81
+
82
+ def domain(self, unit: str = "") -> Domain:
83
+ return Domain(size=tuple(self.size), origin=self.origin, periodic=self.periodic, unit=unit)
84
+
85
+ def grid(self) -> Grid:
86
+ return Grid(self.domain(), self.shape)
87
+
88
+ def with_data(self, data, *, name: str | None = None) -> VoxelImage:
89
+ """New image on the same grid."""
90
+ return VoxelImage(
91
+ data=data,
92
+ spacing=self.spacing,
93
+ origin=self.origin,
94
+ periodic=self.periodic,
95
+ name=self.name if name is None else name,
96
+ metadata=dict(self.metadata),
97
+ )
98
+
99
+ def layer(self, axis: int = 2, index: int | None = None) -> VoxelImage:
100
+ """One layer of voxels normal to ``axis`` (the middle one by default), as an image
101
+ one voxel thick of the same voxels: a planar section of a volume, for a study in
102
+ its plane (a plane strain for the mechanics) on far fewer voxels. Periodic as the
103
+ image (the fields then do not vary across the layer)."""
104
+ if axis not in (0, 1, 2):
105
+ raise ValueError(f"layer: axis 0, 1 or 2, got {axis!r}")
106
+ n = self.shape[axis]
107
+ k = n // 2 if index is None else int(index)
108
+ if not 0 <= k < n:
109
+ raise ValueError(f"layer: index from 0 to {n - 1}, got {index!r}")
110
+ data = np.take(self.data, [k], axis=axis)
111
+ origin = list(self.origin)
112
+ origin[axis] += k * self.spacing[axis]
113
+ return VoxelImage(np.ascontiguousarray(data), self.spacing, tuple(origin), self.periodic,
114
+ self.name, dict(self.metadata)) # fmt: skip
115
+
116
+ def crop(self, start, stop) -> VoxelImage:
117
+ """Sub-image ``data[start[0]:stop[0], ...]`` (never periodic)."""
118
+ s = as_triplet(start, "start", integer=True)
119
+ e = as_triplet(stop, "stop", integer=True)
120
+ sub = self.data[s[0] : e[0], s[1] : e[1], s[2] : e[2]]
121
+ origin = tuple(o + i * h for o, i, h in zip(self.origin, s, self.spacing, strict=True))
122
+ return VoxelImage(sub, self.spacing, origin, False, self.name, dict(self.metadata))
123
+
124
+ def __repr__(self) -> str:
125
+ return (
126
+ f"VoxelImage(name={self.name!r}, shape={self.shape}, dtype={self.data.dtype}, "
127
+ f"spacing={self.spacing}, periodic={self.periodic})"
128
+ )