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.
- morphogen/__init__.py +60 -0
- morphogen/__main__.py +7 -0
- morphogen/_platform.py +55 -0
- morphogen/_public.py +153 -0
- morphogen/_utils.py +80 -0
- morphogen/_version.py +1 -0
- morphogen/analysis/__init__.py +174 -0
- morphogen/analysis/anisotropy.py +135 -0
- morphogen/analysis/basic.py +38 -0
- morphogen/analysis/cells.py +54 -0
- morphogen/analysis/connectivity.py +156 -0
- morphogen/analysis/correlation.py +195 -0
- morphogen/analysis/covariance.py +80 -0
- morphogen/analysis/fractal.py +54 -0
- morphogen/analysis/measures.py +188 -0
- morphogen/analysis/morphology.py +265 -0
- morphogen/analysis/particles.py +160 -0
- morphogen/analysis/percolation.py +2034 -0
- morphogen/analysis/power_laws.py +143 -0
- morphogen/analysis/random_sets.py +351 -0
- morphogen/analysis/stereology.py +289 -0
- morphogen/analysis/surface.py +107 -0
- morphogen/analysis/topology.py +92 -0
- morphogen/automata/__init__.py +74 -0
- morphogen/automata/engine.py +211 -0
- morphogen/automata/growth.py +686 -0
- morphogen/automata/lattice.py +143 -0
- morphogen/automata/reaction.py +255 -0
- morphogen/automata/rules.py +353 -0
- morphogen/automata/tilings.py +1715 -0
- morphogen/cli.py +3526 -0
- morphogen/config.py +2167 -0
- morphogen/contact/__init__.py +113 -0
- morphogen/contact/experiments.py +368 -0
- morphogen/contact/hertz.py +104 -0
- morphogen/contact/kernels.py +827 -0
- morphogen/contact/periodic.py +278 -0
- morphogen/contact/problem.py +578 -0
- morphogen/contact/surfaces.py +310 -0
- morphogen/coupling/__init__.py +43 -0
- morphogen/coupling/ageing.py +143 -0
- morphogen/coupling/diffusion.py +226 -0
- morphogen/coupling/fenicsx.py +484 -0
- morphogen/coupling/oxidation.py +447 -0
- morphogen/coupling/plates.py +247 -0
- morphogen/design/__init__.py +51 -0
- morphogen/design/csp.py +616 -0
- morphogen/design/frames.py +277 -0
- morphogen/design/search.py +287 -0
- morphogen/design/tiles.py +336 -0
- morphogen/distributions.py +312 -0
- morphogen/domain.py +203 -0
- morphogen/dynamics/__init__.py +179 -0
- morphogen/dynamics/model.py +638 -0
- morphogen/dynamics/openradioss.py +643 -0
- morphogen/dynamics/results.py +515 -0
- morphogen/fracture/__init__.py +170 -0
- morphogen/fracture/bulk.py +349 -0
- morphogen/fracture/cohesive.py +1614 -0
- morphogen/fracture/ductile.py +557 -0
- morphogen/fracture/lefm.py +1168 -0
- morphogen/fracture/mixed.py +1178 -0
- morphogen/fracture/periodic.py +733 -0
- morphogen/fracture/phasefield.py +714 -0
- morphogen/fracture/phasefield_finite.py +368 -0
- morphogen/fracture/surface.py +572 -0
- morphogen/fracture/toughness.py +566 -0
- morphogen/gpu.py +108 -0
- morphogen/gui/__init__.py +8 -0
- morphogen/gui/api.py +1927 -0
- morphogen/gui/desktop.py +387 -0
- morphogen/gui/icon.png +0 -0
- morphogen/gui/index.html +1909 -0
- morphogen/gui/server.py +229 -0
- morphogen/gui/tools/__init__.py +629 -0
- morphogen/gui/tools/compare.py +149 -0
- morphogen/gui/tools/contact.py +391 -0
- morphogen/gui/tools/couplings.py +1085 -0
- morphogen/gui/tools/crackfront.py +245 -0
- morphogen/gui/tools/design.py +224 -0
- morphogen/gui/tools/dynamics.py +824 -0
- morphogen/gui/tools/fracture.py +2586 -0
- morphogen/gui/tools/interop.py +1654 -0
- morphogen/gui/tools/learning.py +595 -0
- morphogen/gui/tools/mechanics.py +3881 -0
- morphogen/gui/tools/nonlocal_damage.py +1321 -0
- morphogen/gui/tools/phasefield.py +215 -0
- morphogen/gui/tools/physics.py +597 -0
- morphogen/gui/tools/stability.py +1756 -0
- morphogen/gui/tools/statistics.py +1408 -0
- morphogen/gui/viewer.js +1100 -0
- morphogen/homogenization/__init__.py +210 -0
- morphogen/homogenization/acoustics.py +566 -0
- morphogen/homogenization/amg.py +1005 -0
- morphogen/homogenization/apparent.py +1046 -0
- morphogen/homogenization/behaviours.cu +2285 -0
- morphogen/homogenization/behaviours.py +944 -0
- morphogen/homogenization/beremin.py +263 -0
- morphogen/homogenization/bifurcation.py +1085 -0
- morphogen/homogenization/bloch.py +507 -0
- morphogen/homogenization/bounds.py +226 -0
- morphogen/homogenization/core.py +458 -0
- morphogen/homogenization/coupled.py +1135 -0
- morphogen/homogenization/crystal.py +2967 -0
- morphogen/homogenization/dilatation.py +454 -0
- morphogen/homogenization/elements.py +157 -0
- morphogen/homogenization/fatigue.py +768 -0
- morphogen/homogenization/fe.py +1739 -0
- morphogen/homogenization/fenicsx.py +307 -0
- morphogen/homogenization/fft.py +499 -0
- morphogen/homogenization/fft_nonlinear.py +391 -0
- morphogen/homogenization/finite.py +613 -0
- morphogen/homogenization/flow.py +361 -0
- morphogen/homogenization/frames.py +1125 -0
- morphogen/homogenization/gpu.py +1241 -0
- morphogen/homogenization/harmonic.py +427 -0
- morphogen/homogenization/identification.py +579 -0
- morphogen/homogenization/kernels.py +760 -0
- morphogen/homogenization/laws.py +2061 -0
- morphogen/homogenization/materials.py +1080 -0
- morphogen/homogenization/mfront.py +589 -0
- morphogen/homogenization/networks.py +880 -0
- morphogen/homogenization/nonlinear.py +2612 -0
- morphogen/homogenization/ntfa.py +577 -0
- morphogen/homogenization/paths.py +476 -0
- morphogen/homogenization/photonic.py +467 -0
- morphogen/homogenization/poroelastic.py +212 -0
- morphogen/homogenization/porous.py +1120 -0
- morphogen/homogenization/postprocess.py +290 -0
- morphogen/homogenization/solvers.py +1140 -0
- morphogen/homogenization/tensors.py +240 -0
- morphogen/homogenization/voxel_fe.py +457 -0
- morphogen/homogenization/xfem.py +1016 -0
- morphogen/homogenization/zmat.py +1258 -0
- morphogen/iga/__init__.py +48 -0
- morphogen/iga/analysis.py +508 -0
- morphogen/iga/basis.py +214 -0
- morphogen/iga/geometry.py +501 -0
- morphogen/iga/homogenization.py +219 -0
- morphogen/iga/optimization.py +700 -0
- morphogen/iga/shapes.py +331 -0
- morphogen/image.py +128 -0
- morphogen/io/__init__.py +246 -0
- morphogen/io/amitex.py +741 -0
- morphogen/io/ebsd.py +881 -0
- morphogen/io/export.py +196 -0
- morphogen/io/geometry.py +158 -0
- morphogen/io/medit.py +147 -0
- morphogen/io/meshes.py +844 -0
- morphogen/io/metaimage.py +97 -0
- morphogen/io/mfront.py +1104 -0
- morphogen/io/native.py +57 -0
- morphogen/io/radioss.py +764 -0
- morphogen/io/solvers.py +371 -0
- morphogen/io/tables.py +278 -0
- morphogen/io/tiff.py +66 -0
- morphogen/io/vtk.py +701 -0
- morphogen/io/xdmf.py +200 -0
- morphogen/kernels/__init__.py +5 -0
- morphogen/kernels/annealing.py +192 -0
- morphogen/kernels/cells.py +69 -0
- morphogen/kernels/collective.py +87 -0
- morphogen/kernels/force_biased.py +595 -0
- morphogen/kernels/implicit.py +145 -0
- morphogen/kernels/leaves.py +132 -0
- morphogen/kernels/packing.py +304 -0
- morphogen/kernels/raster.py +279 -0
- morphogen/kernels/rsa.py +371 -0
- morphogen/kernels/union.py +135 -0
- morphogen/kernels/watershed.py +190 -0
- morphogen/laser/__init__.py +234 -0
- morphogen/laser/architectures.py +375 -0
- morphogen/laser/bending.py +216 -0
- morphogen/laser/cells.py +1694 -0
- morphogen/laser/design.py +940 -0
- morphogen/laser/figures.py +227 -0
- morphogen/laser/heat.py +804 -0
- morphogen/laser/materials.py +691 -0
- morphogen/laser/mechanics.py +1670 -0
- morphogen/laser/metallurgy.py +615 -0
- morphogen/laser/patterns.py +828 -0
- morphogen/laser/periodic.py +392 -0
- morphogen/laser/process.py +362 -0
- morphogen/laser/run.py +534 -0
- morphogen/laser/solid.py +216 -0
- morphogen/laser/specimen.py +200 -0
- morphogen/laser/structures.py +708 -0
- morphogen/learning/__init__.py +81 -0
- morphogen/learning/behaviour.py +398 -0
- morphogen/learning/data.py +328 -0
- morphogen/learning/learned.cpp +668 -0
- morphogen/learning/logarithmic.py +202 -0
- morphogen/learning/mfront.py +409 -0
- morphogen/learning/networks.py +767 -0
- morphogen/learning/run.py +212 -0
- morphogen/learning/standard.py +814 -0
- morphogen/learning/training.py +235 -0
- morphogen/mesh/__init__.py +29 -0
- morphogen/mesh/conforming.py +1423 -0
- morphogen/mesh/curved.py +600 -0
- morphogen/mesh/exact.py +1717 -0
- morphogen/mesh/octree.py +350 -0
- morphogen/mesh/polycrystal.py +1041 -0
- morphogen/mesh/polyhedra.py +677 -0
- morphogen/mesh/regularize.py +570 -0
- morphogen/mesh/surface.py +97 -0
- morphogen/mesh/tetra.py +512 -0
- morphogen/mesh/voxel.py +124 -0
- morphogen/micromorphic/__init__.py +31 -0
- morphogen/micromorphic/damage.py +359 -0
- morphogen/micromorphic/ductile.py +534 -0
- morphogen/micromorphic/finite.py +220 -0
- morphogen/micromorphic/microfoam.py +787 -0
- morphogen/micromorphic/space.py +341 -0
- morphogen/models/__init__.py +195 -0
- morphogen/models/affine.py +384 -0
- morphogen/models/automata.py +592 -0
- morphogen/models/base.py +500 -0
- morphogen/models/boolean.py +310 -0
- morphogen/models/bouligand.py +331 -0
- morphogen/models/branching.py +241 -0
- morphogen/models/combination.py +430 -0
- morphogen/models/deadleaves.py +766 -0
- morphogen/models/design.py +289 -0
- morphogen/models/ebsd.py +206 -0
- morphogen/models/fibers.py +1476 -0
- morphogen/models/foam.py +594 -0
- morphogen/models/gaussian.py +314 -0
- morphogen/models/growth.py +459 -0
- morphogen/models/hardcore.py +317 -0
- morphogen/models/hierarchical.py +269 -0
- morphogen/models/honeycomb.py +749 -0
- morphogen/models/implicit.py +177 -0
- morphogen/models/laminate.py +470 -0
- morphogen/models/lattice.py +351 -0
- morphogen/models/lattice_field.py +345 -0
- morphogen/models/levelset_foam.py +563 -0
- morphogen/models/nacre.py +411 -0
- morphogen/models/nested.py +924 -0
- morphogen/models/osteons.py +374 -0
- morphogen/models/pieces.py +167 -0
- morphogen/models/planar.py +126 -0
- morphogen/models/reconstruction.py +203 -0
- morphogen/models/scale_rich.py +1409 -0
- morphogen/models/scale_rich_3d.py +1616 -0
- morphogen/models/tessellation.py +735 -0
- morphogen/models/tiling_field.py +302 -0
- morphogen/models/tpms.py +197 -0
- morphogen/models/transparent.py +406 -0
- morphogen/models/union.py +141 -0
- morphogen/optimization/__init__.py +43 -0
- morphogen/optimization/cell.py +295 -0
- morphogen/optimization/filters.py +115 -0
- morphogen/optimization/mma.py +226 -0
- morphogen/optimization/run.py +219 -0
- morphogen/optimization/topology.py +632 -0
- morphogen/orientations.py +568 -0
- morphogen/parallel.py +599 -0
- morphogen/pipeline.py +978 -0
- morphogen/primitives.py +188 -0
- morphogen/results.py +564 -0
- morphogen/rve/__init__.py +73 -0
- morphogen/rve/report.py +627 -0
- morphogen/rve/scaling.py +363 -0
- morphogen/rve/study.py +1054 -0
- morphogen/rve/windows.py +345 -0
- morphogen/seeding.py +51 -0
- morphogen/settings.py +118 -0
- morphogen/stopping.py +48 -0
- morphogen/symmetry.py +384 -0
- morphogen/templates/activator_inhibitor.yaml +22 -0
- morphogen/templates/aggregation.yaml +23 -0
- morphogen/templates/boolean_cylinders.yaml +20 -0
- morphogen/templates/boolean_spheres.yaml +22 -0
- morphogen/templates/bouligand.yaml +28 -0
- morphogen/templates/cellular_automaton.yaml +25 -0
- morphogen/templates/coated_spheres.yaml +26 -0
- morphogen/templates/contact_fibers.yaml +27 -0
- morphogen/templates/cox_nanocomposite.yaml +22 -0
- morphogen/templates/cross_linked_fibers.yaml +26 -0
- morphogen/templates/curved_arcs.yaml +28 -0
- morphogen/templates/curved_fibers.yaml +24 -0
- morphogen/templates/dead_leaves.yaml +22 -0
- morphogen/templates/delaunay_network.yaml +22 -0
- morphogen/templates/dense_packing.yaml +22 -0
- morphogen/templates/diffusion.yaml +33 -0
- morphogen/templates/ebsd.yaml +34 -0
- morphogen/templates/ebsd_map.ctf +3087 -0
- morphogen/templates/fracture_composite.yaml +42 -0
- morphogen/templates/fracture_rubber.yaml +47 -0
- morphogen/templates/gaussian_excursion.yaml +17 -0
- morphogen/templates/graded_lattice.yaml +24 -0
- morphogen/templates/hardcore_fibers.yaml +22 -0
- morphogen/templates/hardcore_spheres.yaml +22 -0
- morphogen/templates/hierarchical_lattice.yaml +22 -0
- morphogen/templates/homogenization_acoustic_foam.yaml +36 -0
- morphogen/templates/homogenization_beremin.yaml +50 -0
- morphogen/templates/homogenization_cleavage.yaml +51 -0
- morphogen/templates/homogenization_cleavage_band.yaml +55 -0
- morphogen/templates/homogenization_contact.yaml +43 -0
- morphogen/templates/homogenization_crack_closure.yaml +49 -0
- morphogen/templates/homogenization_crystal_plasticity.yaml +50 -0
- morphogen/templates/homogenization_crystal_plasticity_fft.yaml +52 -0
- morphogen/templates/homogenization_crystallization.yaml +30 -0
- morphogen/templates/homogenization_debonding.yaml +43 -0
- morphogen/templates/homogenization_detwinning.yaml +58 -0
- morphogen/templates/homogenization_ductile_damage.yaml +47 -0
- morphogen/templates/homogenization_fatigue.yaml +40 -0
- morphogen/templates/homogenization_grain_fracture.yaml +56 -0
- morphogen/templates/homogenization_gyroid.yaml +30 -0
- morphogen/templates/homogenization_intergranular.yaml +43 -0
- morphogen/templates/homogenization_interphase.yaml +42 -0
- morphogen/templates/homogenization_mixed_loading.yaml +33 -0
- morphogen/templates/homogenization_ntfa.yaml +56 -0
- morphogen/templates/homogenization_piezoelectric.yaml +27 -0
- morphogen/templates/homogenization_polycrystal.yaml +30 -0
- morphogen/templates/homogenization_polycrystal_inclusions.yaml +30 -0
- morphogen/templates/homogenization_poroelastic.yaml +26 -0
- morphogen/templates/homogenization_rubber.yaml +40 -0
- morphogen/templates/homogenization_slip_cleavage.yaml +50 -0
- morphogen/templates/homogenization_spheres.yaml +31 -0
- morphogen/templates/homogenization_transport.yaml +29 -0
- morphogen/templates/homogenization_twinning.yaml +54 -0
- morphogen/templates/homogenization_viscoelastic.yaml +34 -0
- morphogen/templates/homogenization_viscoplastic.yaml +42 -0
- morphogen/templates/homogenization_voronoi.yaml +26 -0
- morphogen/templates/homogenization_xfem.yaml +23 -0
- morphogen/templates/hyperuniform_cells.yaml +24 -0
- morphogen/templates/laguerre.yaml +18 -0
- morphogen/templates/laser_bending.yaml +35 -0
- morphogen/templates/laser_cells.yaml +38 -0
- morphogen/templates/laser_corrugated.yaml +36 -0
- morphogen/templates/level_set_foam.yaml +29 -0
- morphogen/templates/menger_sponge.yaml +17 -0
- morphogen/templates/nacre.yaml +25 -0
- morphogen/templates/nucleation_growth.yaml +25 -0
- morphogen/templates/optimize_auxetic.yaml +29 -0
- morphogen/templates/optimize_auxetic_3d.yaml +27 -0
- morphogen/templates/optimize_bulk.yaml +23 -0
- morphogen/templates/optimize_conductivity.yaml +20 -0
- morphogen/templates/osteons.yaml +28 -0
- morphogen/templates/penetrable_spheres.yaml +21 -0
- morphogen/templates/poisson_fibers.yaml +21 -0
- morphogen/templates/random_laminate.yaml +26 -0
- morphogen/templates/random_lattice.yaml +27 -0
- morphogen/templates/random_walk_fibers.yaml +26 -0
- morphogen/templates/reaction_diffusion.yaml +22 -0
- morphogen/templates/reconstruction.yaml +22 -0
- morphogen/templates/rve_cellular_automaton.yaml +23 -0
- morphogen/templates/rve_crystal_plasticity_fft.yaml +51 -0
- morphogen/templates/rve_multiphysics.yaml +43 -0
- morphogen/templates/rve_poisson_fibers.yaml +22 -0
- morphogen/templates/rve_poisson_fibers_fe.yaml +33 -0
- morphogen/templates/rve_voronoi_windows.yaml +20 -0
- morphogen/templates/scale_rich_network.yaml +29 -0
- morphogen/templates/scale_rich_plates.yaml +30 -0
- morphogen/templates/sequential_dead_leaves.yaml +25 -0
- morphogen/templates/strut_lattice.yaml +21 -0
- morphogen/templates/tile_assembly.yaml +28 -0
- morphogen/templates/tpms.yaml +19 -0
- morphogen/templates/trabecular_bone.yaml +29 -0
- morphogen/templates/transparent_dead_leaves.yaml +23 -0
- morphogen/templates/vascular_tree.yaml +23 -0
- morphogen/templates/voronoi.yaml +20 -0
- morphogen/templates/wood.yaml +34 -0
- morphogen/templates/workflow.yaml +56 -0
- morphogen/texture.py +665 -0
- morphogen/theory.py +162 -0
- morphogen/viz/__init__.py +12 -0
- morphogen/viz/export.py +244 -0
- morphogen/viz/figures.py +707 -0
- morphogen/viz/png.py +148 -0
- morphogen/viz/sections.py +696 -0
- morphogen/viz/surfaces.py +1352 -0
- morphogen/viz/video.py +904 -0
- morphogen/viz/workflow.py +488 -0
- morphogen-1.0.0.dist-info/METADATA +2316 -0
- morphogen-1.0.0.dist-info/RECORD +381 -0
- morphogen-1.0.0.dist-info/WHEEL +4 -0
- morphogen-1.0.0.dist-info/entry_points.txt +5 -0
- 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)
|