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,1085 @@
|
|
|
1
|
+
"""The tools of the tab Couplings: transport, chemistry and mechanics
|
|
2
|
+
(:mod:`morphogen.coupling`): the transient diffusion of a species (moisture, oxygen, a
|
|
3
|
+
solvent) into a morphology of the workspace, with its effective diffusivity; the thermal
|
|
4
|
+
oxidation of an epoxy limited by the diffusion of oxygen (the closed-loop scheme of Colin
|
|
5
|
+
and Verdu with the constants of Ernault et al. 2019), with the properties of its
|
|
6
|
+
oxidized layer, through the thickness of a plate or in the volume of a morphology
|
|
7
|
+
(around its fibres or fillers); and the bending of hygromorph multilayers as moisture
|
|
8
|
+
enters them (Mou, Dirrenberger & Le Duigou 2025), whose layers may be homogenized from
|
|
9
|
+
morphologies of the workspace (:meth:`~morphogen.coupling.Layer.from_microstructure`).
|
|
10
|
+
|
|
11
|
+
The FEniCSx solvers of :mod:`morphogen.coupling.fenicsx` (meshes swelling in 3D) need
|
|
12
|
+
dolfinx, which runs on Linux (or WSL) only; these tools use the voxel and plate solvers,
|
|
13
|
+
which run everywhere."""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import math
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from morphogen.gui.tools import Field, tab, tool
|
|
22
|
+
|
|
23
|
+
tab(
|
|
24
|
+
"couplings",
|
|
25
|
+
"Couplings",
|
|
26
|
+
"Couplings of transport, chemistry and mechanics: transient diffusion in a morphology "
|
|
27
|
+
"of the workspace and its effective diffusivity, the thermal oxidation of an epoxy "
|
|
28
|
+
"and its oxidized layer (a plate, or the volume of a morphology), the bending and "
|
|
29
|
+
"twisting of hygromorph multilayers whose "
|
|
30
|
+
"layers may be homogenized from morphologies of the workspace.",
|
|
31
|
+
order=65,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
FACES = ("x-", "x+", "y-", "y+", "z-", "z+")
|
|
35
|
+
#: The diffusion properties of the phases when the form gives none (phase 1: a slower
|
|
36
|
+
#: and more soluble phase, as the fibre walls of templates/diffusion.yaml)
|
|
37
|
+
DEFAULT_PHASES = {
|
|
38
|
+
"0": {"diffusivity": 1.0, "solubility": 1.0},
|
|
39
|
+
"1": {"diffusivity": 0.1, "solubility": 3.0},
|
|
40
|
+
}
|
|
41
|
+
#: Output times of the diffusion (blank form): from the time the species takes to cross
|
|
42
|
+
#: a few voxels, at least this fraction of the time scale L² / D, to the time scale
|
|
43
|
+
FIRST_TIME = 1e-3
|
|
44
|
+
TIMES = 10
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _plot(
|
|
48
|
+
curves: dict,
|
|
49
|
+
xlabel: str,
|
|
50
|
+
ylabel: str,
|
|
51
|
+
title: str = "",
|
|
52
|
+
*,
|
|
53
|
+
logx=False,
|
|
54
|
+
logy=False,
|
|
55
|
+
ax=None,
|
|
56
|
+
styles=None,
|
|
57
|
+
):
|
|
58
|
+
"""Curves name -> (x, y) on an axis (a new figure when none is given)."""
|
|
59
|
+
from matplotlib.figure import Figure
|
|
60
|
+
|
|
61
|
+
fig = None
|
|
62
|
+
if ax is None:
|
|
63
|
+
fig = Figure(figsize=(5.4, 3.8), layout="constrained")
|
|
64
|
+
ax = fig.subplots()
|
|
65
|
+
for name, (x, y) in curves.items():
|
|
66
|
+
ax.plot(x, y, (styles or {}).get(name, "-"), lw=1.5, ms=3, label=name)
|
|
67
|
+
if logx:
|
|
68
|
+
ax.set_xscale("log")
|
|
69
|
+
if logy:
|
|
70
|
+
ax.set_yscale("log")
|
|
71
|
+
ax.set_xlabel(xlabel)
|
|
72
|
+
ax.set_ylabel(ylabel)
|
|
73
|
+
ax.set_title(title, fontsize=10)
|
|
74
|
+
ax.grid(alpha=0.3)
|
|
75
|
+
if len(curves) > 1:
|
|
76
|
+
ax.legend(fontsize=8, frameon=False)
|
|
77
|
+
return fig
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _phase_table(value, name: str, keys: tuple, required: tuple) -> dict[int, dict]:
|
|
81
|
+
"""A mapping phase -> properties of the form (a JSON object), checked."""
|
|
82
|
+
if not isinstance(value, dict) or not value:
|
|
83
|
+
raise ValueError(f"{name}: a mapping phase -> {{{', '.join(keys)}}}")
|
|
84
|
+
out = {}
|
|
85
|
+
for phase, props in value.items():
|
|
86
|
+
if not isinstance(props, dict):
|
|
87
|
+
raise ValueError(f"{name}: the properties of phase {phase}, a mapping")
|
|
88
|
+
unknown = sorted(set(props) - set(keys))
|
|
89
|
+
missing = [k for k in required if k not in props]
|
|
90
|
+
if unknown or missing:
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f"{name}, phase {phase}: "
|
|
93
|
+
+ (f"unknown {unknown}" if unknown else f"give {', '.join(missing)}")
|
|
94
|
+
)
|
|
95
|
+
try:
|
|
96
|
+
out[int(phase)] = {k: float(v) for k, v in props.items()}
|
|
97
|
+
except (TypeError, ValueError):
|
|
98
|
+
raise ValueError(f"{name}, phase {phase}: numbers") from None
|
|
99
|
+
return out
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _voxel_image(item: dict, resolution: int):
|
|
103
|
+
from morphogen.gui.api import _voxels
|
|
104
|
+
|
|
105
|
+
n = int(resolution)
|
|
106
|
+
if not 4 <= n <= 256:
|
|
107
|
+
raise ValueError("voxels per edge: from 4 to 256")
|
|
108
|
+
micro = item["micro"]
|
|
109
|
+
_voxels(micro.domain, n, 64.0, "diffusion") # the operator and its factors
|
|
110
|
+
image = micro.voxelize(shape=n)
|
|
111
|
+
if np.asarray(image.data).dtype.kind not in "iub":
|
|
112
|
+
raise ValueError(f"{item['title']} gives no phase image")
|
|
113
|
+
return image
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# -- transient diffusion ---------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@tool(
|
|
120
|
+
"diffusion",
|
|
121
|
+
"couplings",
|
|
122
|
+
"Transient diffusion",
|
|
123
|
+
"A species (moisture, oxygen, a solvent) diffusing into a morphology of the workspace "
|
|
124
|
+
"from its exposed faces: each phase holds the concentration c = S u of the activity u "
|
|
125
|
+
"(continuous across the interfaces) with its diffusivity D, solubility S and "
|
|
126
|
+
"first-order consumption k, S du/dt = div(D S grad u) - k S u (finite volumes on the "
|
|
127
|
+
"voxels, implicit Euler steps). The uptake curve, against Fick's √t at short times and "
|
|
128
|
+
"Crank's slab with the effective diffusivity fitted to it; the concentration fields at "
|
|
129
|
+
"the times and their video; the steady effective diffusivity of the homogenized "
|
|
130
|
+
"permeability over the mean solubility, between its bounds.",
|
|
131
|
+
[
|
|
132
|
+
Field("source", "item", label="morphology", required=True),
|
|
133
|
+
Field("resolution", "int", 32, label="voxels per edge"),
|
|
134
|
+
Field(
|
|
135
|
+
"phases",
|
|
136
|
+
"json",
|
|
137
|
+
DEFAULT_PHASES,
|
|
138
|
+
label="properties of the phases",
|
|
139
|
+
doc="phase -> diffusivity, solubility (default 1), consumption (default 0)",
|
|
140
|
+
),
|
|
141
|
+
Field(
|
|
142
|
+
"exposed",
|
|
143
|
+
"choices",
|
|
144
|
+
["x-", "x+"],
|
|
145
|
+
choices=FACES,
|
|
146
|
+
doc="the faces held at the activity; the others impermeable, or periodic",
|
|
147
|
+
),
|
|
148
|
+
Field(
|
|
149
|
+
"activity", "float", 1.0, doc="on the exposed faces (1: equilibrium with the outside)"
|
|
150
|
+
),
|
|
151
|
+
Field("initial", "float", 0.0, doc="initial activity"),
|
|
152
|
+
Field(
|
|
153
|
+
"times",
|
|
154
|
+
"floats",
|
|
155
|
+
doc="output times (blank: ten, from the time to cross three voxels to the time "
|
|
156
|
+
"scale L² / D, L the distance between the exposed faces)",
|
|
157
|
+
),
|
|
158
|
+
Field("steps", "int", 20, doc="implicit Euler steps between two times"),
|
|
159
|
+
Field(
|
|
160
|
+
"field",
|
|
161
|
+
"choice",
|
|
162
|
+
"concentration",
|
|
163
|
+
choices=(("concentration", "concentration c = S u"), ("activity", "activity u")),
|
|
164
|
+
),
|
|
165
|
+
Field(
|
|
166
|
+
"homogenize",
|
|
167
|
+
"bool",
|
|
168
|
+
True,
|
|
169
|
+
label="steady effective diffusivity",
|
|
170
|
+
doc="the homogenized permeability (FFT) over the mean solubility",
|
|
171
|
+
),
|
|
172
|
+
Field("video", "bool", True),
|
|
173
|
+
],
|
|
174
|
+
order=1,
|
|
175
|
+
menu="Diffusion",
|
|
176
|
+
)
|
|
177
|
+
def diffusion(p: dict, ctx) -> dict:
|
|
178
|
+
from morphogen.coupling import slab_uptake, transient_diffusion
|
|
179
|
+
|
|
180
|
+
item = p["source"]
|
|
181
|
+
image = _voxel_image(item, p["resolution"])
|
|
182
|
+
labels = np.asarray(image.data).astype(np.int64)
|
|
183
|
+
table = _phase_table(
|
|
184
|
+
p["phases"] or DEFAULT_PHASES,
|
|
185
|
+
"properties of the phases",
|
|
186
|
+
("diffusivity", "solubility", "consumption"),
|
|
187
|
+
("diffusivity",),
|
|
188
|
+
)
|
|
189
|
+
present = [int(v) for v in np.unique(labels)]
|
|
190
|
+
missing = [k for k in present if k not in table]
|
|
191
|
+
if missing:
|
|
192
|
+
raise ValueError(
|
|
193
|
+
f"properties of the phases: none for the phases {missing} of {item['title']}"
|
|
194
|
+
)
|
|
195
|
+
d = {k: table[k]["diffusivity"] for k in present}
|
|
196
|
+
s = {k: table[k].get("solubility", 1.0) for k in present}
|
|
197
|
+
k_ = {k: table[k].get("consumption", 0.0) for k in present}
|
|
198
|
+
if any(v <= 0 for v in s.values()) or any(v < 0 for v in [*d.values(), *k_.values()]):
|
|
199
|
+
raise ValueError(
|
|
200
|
+
"properties of the phases: positive solubilities, non-negative "
|
|
201
|
+
"diffusivities and consumptions"
|
|
202
|
+
)
|
|
203
|
+
exposed = list(p["exposed"] or ["x-", "x+"])
|
|
204
|
+
axes = sorted({"xyz".index(f[0]) for f in exposed})
|
|
205
|
+
lengths = np.asarray(image.size, dtype=float)
|
|
206
|
+
fractions = {k: float(np.mean(labels == k)) for k in present}
|
|
207
|
+
mean_s = sum(fractions[k] * s[k] for k in present)
|
|
208
|
+
voigt = sum(fractions[k] * d[k] * s[k] for k in present) / mean_s
|
|
209
|
+
reuss = 0.0
|
|
210
|
+
if all(d[k] > 0 for k in present):
|
|
211
|
+
reuss = 1.0 / sum(fractions[k] / (d[k] * s[k]) for k in present) / mean_s
|
|
212
|
+
if not voigt > 0:
|
|
213
|
+
raise ValueError("properties of the phases: no phase lets the species through")
|
|
214
|
+
# the distance the species travels: between two opposite exposed faces, else twice
|
|
215
|
+
# the length from one face (half of a slab exposed on both faces)
|
|
216
|
+
one_axis = len(axes) == 1
|
|
217
|
+
span = []
|
|
218
|
+
for a in axes:
|
|
219
|
+
both = f"{'xyz'[a]}-" in exposed and f"{'xyz'[a]}+" in exposed
|
|
220
|
+
span.append(lengths[a] if both else 2.0 * lengths[a])
|
|
221
|
+
distance = float(min(span))
|
|
222
|
+
scale = distance**2 / voigt
|
|
223
|
+
if p["times"]:
|
|
224
|
+
times = np.asarray(p["times"], dtype=float)
|
|
225
|
+
else: # from the time to cross three voxels: the first voxels resolve the √t start
|
|
226
|
+
voxel = max(float(image.spacing[a]) for a in axes)
|
|
227
|
+
first = max(FIRST_TIME, (1.5 * voxel / distance) ** 2)
|
|
228
|
+
times = np.geomspace(first, 1.0, TIMES) * scale
|
|
229
|
+
if np.any(times <= 0) or np.any(np.diff(times) <= 0):
|
|
230
|
+
raise ValueError("times: positive and increasing")
|
|
231
|
+
ctx.progress(0.1, f"diffusion in {labels.size} voxels")
|
|
232
|
+
res = transient_diffusion(
|
|
233
|
+
image,
|
|
234
|
+
d,
|
|
235
|
+
times,
|
|
236
|
+
solubility=s,
|
|
237
|
+
exposed=exposed,
|
|
238
|
+
boundary=float(p["activity"]),
|
|
239
|
+
initial=float(p["initial"]),
|
|
240
|
+
consumption=k_,
|
|
241
|
+
steps=int(p["steps"]),
|
|
242
|
+
)
|
|
243
|
+
# the fraction of the change of the content, (M - M0) / (M∞ - M0): the relative uptake
|
|
244
|
+
# from a dry start, the fraction desorbed when drying
|
|
245
|
+
start = mean_s * float(p["initial"])
|
|
246
|
+
change = res.saturation - start
|
|
247
|
+
relative = (res.uptake - start) / change if change else np.full_like(res.uptake, np.nan)
|
|
248
|
+
rows = []
|
|
249
|
+
for i, t in enumerate(res.times):
|
|
250
|
+
row = {"time": float(t), "uptake": float(res.uptake[i]), "fraction": float(relative[i])}
|
|
251
|
+
for k in present:
|
|
252
|
+
row[f"c_{k}"] = float(res.fields[i][labels == k].mean())
|
|
253
|
+
rows.append(row)
|
|
254
|
+
ctx.table(rows, "uptake", "uptake curve (fraction: (M - M0) / (M∞ - M0))")
|
|
255
|
+
values = {
|
|
256
|
+
"saturation M∞ (mean S times the activity)": res.saturation,
|
|
257
|
+
"final fraction (M - M0) / (M∞ - M0)": float(relative[-1]),
|
|
258
|
+
"time scale L² / D (Voigt)": scale,
|
|
259
|
+
"diffusivity, Voigt bound <D S> / <S>": voigt,
|
|
260
|
+
"diffusivity, Reuss bound": reuss,
|
|
261
|
+
}
|
|
262
|
+
consuming = any(v > 0 for v in k_.values())
|
|
263
|
+
early = np.flatnonzero((relative > 0) & (relative < 0.4))
|
|
264
|
+
if len(early) >= 2 and not consuming:
|
|
265
|
+
(t0, t1), (m0, m1) = res.times[early[:2]], relative[early[:2]]
|
|
266
|
+
values["early slope of log M against log t (Fick: 1/2)"] = math.log(m1 / m0) / math.log(
|
|
267
|
+
t1 / t0
|
|
268
|
+
)
|
|
269
|
+
fitted = None
|
|
270
|
+
if one_axis and not consuming and change:
|
|
271
|
+
from scipy.optimize import minimize_scalar
|
|
272
|
+
|
|
273
|
+
def misfit(log_d):
|
|
274
|
+
return float(np.sum((slab_uptake(res.times, distance, 10.0**log_d) - relative) ** 2))
|
|
275
|
+
|
|
276
|
+
guess = math.log10(voigt)
|
|
277
|
+
best = minimize_scalar(misfit, bounds=(guess - 6.0, guess + 2.0), method="bounded")
|
|
278
|
+
fitted = 10.0**best.x
|
|
279
|
+
values["effective diffusivity of the uptake (Crank)"] = fitted
|
|
280
|
+
if 0 < relative[0] < 0.4:
|
|
281
|
+
values["diffusivity of the short times, π (L M/M∞)² / 16 t"] = (
|
|
282
|
+
math.pi * (distance * relative[0]) ** 2 / (16.0 * res.times[0])
|
|
283
|
+
)
|
|
284
|
+
if p["homogenize"]:
|
|
285
|
+
ctx.progress(0.6, "homogenized permeability")
|
|
286
|
+
from morphogen.homogenization.apparent import homogenize
|
|
287
|
+
from morphogen.homogenization.materials import Material
|
|
288
|
+
|
|
289
|
+
top = max(d[k] * s[k] for k in present)
|
|
290
|
+
materials = {k: Material(conductivity=max(d[k] * s[k], 1e-9 * top)) for k in present}
|
|
291
|
+
out = homogenize(image, materials, properties=("conductivity_tensor",))
|
|
292
|
+
tensor = np.asarray(out["conductivity_tensor.periodic"]["tensor"])
|
|
293
|
+
for a in axes:
|
|
294
|
+
values[f"steady effective diffusivity along {'xyz'[a]}"] = float(tensor[a, a]) / mean_s
|
|
295
|
+
ctx.progress(0.75, "figures")
|
|
296
|
+
from matplotlib.figure import Figure
|
|
297
|
+
|
|
298
|
+
fig = Figure(figsize=(9.6, 3.8), layout="constrained")
|
|
299
|
+
left, right = fig.subplots(1, 2)
|
|
300
|
+
curves = {"computed": (res.times, relative)}
|
|
301
|
+
styles = {"computed": "o-", "Fick, √t": "k:", "Crank, fitted D": "--"}
|
|
302
|
+
if len(early): # √t through the first point of the short times, up to M / M∞ = 0.6
|
|
303
|
+
i = int(early[0])
|
|
304
|
+
fick = relative[i] * np.sqrt(res.times / res.times[i])
|
|
305
|
+
curves["Fick, √t"] = (res.times[fick < 0.6], fick[fick < 0.6])
|
|
306
|
+
if fitted is not None:
|
|
307
|
+
dense = np.geomspace(res.times[0], res.times[-1], 120)
|
|
308
|
+
curves["Crank, fitted D"] = (dense, slab_uptake(dense, distance, fitted))
|
|
309
|
+
_plot(
|
|
310
|
+
curves,
|
|
311
|
+
"time",
|
|
312
|
+
"M / M∞",
|
|
313
|
+
"uptake (log scales)",
|
|
314
|
+
logx=True,
|
|
315
|
+
logy=True,
|
|
316
|
+
ax=left,
|
|
317
|
+
styles=styles,
|
|
318
|
+
)
|
|
319
|
+
_plot(curves, "time", "M / M∞", "uptake", ax=right, styles=styles)
|
|
320
|
+
right.set_ylim(0.0, max(1.05, float(np.max(relative)) * 1.05))
|
|
321
|
+
ctx.figure(fig, "uptake", "uptake curve")
|
|
322
|
+
shown = list(res.fields)
|
|
323
|
+
if p["field"] == "activity": # u = c / S
|
|
324
|
+
table_s = np.zeros(max(present) + 1)
|
|
325
|
+
table_s[present] = [s[k] for k in present]
|
|
326
|
+
shown = [f / table_s[labels] for f in shown]
|
|
327
|
+
k = labels.shape[2] // 2
|
|
328
|
+
chosen = np.unique(np.linspace(0, len(times) - 1, min(len(times), 6)).round().astype(int))
|
|
329
|
+
fig = Figure(figsize=(2.6 * len(chosen) + 0.8, 3.0), layout="constrained")
|
|
330
|
+
axes_ = np.atleast_1d(fig.subplots(1, len(chosen)))
|
|
331
|
+
lo = min(float(np.min(f)) for f in shown)
|
|
332
|
+
hi = max(float(np.max(f)) for f in shown)
|
|
333
|
+
extent = (0.0, lengths[0], 0.0, lengths[1])
|
|
334
|
+
for ax, i in zip(axes_, chosen, strict=True):
|
|
335
|
+
im = ax.imshow(
|
|
336
|
+
shown[i][:, :, k].T,
|
|
337
|
+
origin="lower",
|
|
338
|
+
extent=extent,
|
|
339
|
+
cmap="viridis",
|
|
340
|
+
vmin=lo,
|
|
341
|
+
vmax=hi,
|
|
342
|
+
interpolation="nearest",
|
|
343
|
+
)
|
|
344
|
+
ax.set_title(f"t = {times[i]:.3g}", fontsize=9)
|
|
345
|
+
ax.set_xticks([])
|
|
346
|
+
ax.set_yticks([])
|
|
347
|
+
fig.colorbar(im, ax=list(axes_), shrink=0.85, label=p["field"])
|
|
348
|
+
ctx.figure(fig, "fields", f"{p['field']} in the middle section (x-y) at the times")
|
|
349
|
+
if p["video"]:
|
|
350
|
+
from morphogen.viz.video import time_section_frames
|
|
351
|
+
|
|
352
|
+
frames = time_section_frames(
|
|
353
|
+
shown,
|
|
354
|
+
2,
|
|
355
|
+
k,
|
|
356
|
+
size=420,
|
|
357
|
+
cmap="viridis",
|
|
358
|
+
vmin=lo,
|
|
359
|
+
vmax=hi,
|
|
360
|
+
captions=[f"t = {t:.3g}" for t in times],
|
|
361
|
+
label=p["field"][:13],
|
|
362
|
+
)
|
|
363
|
+
ctx.video(frames, "diffusion", f"{p['field']} along the uptake", fps=3, mode="once")
|
|
364
|
+
return {"values": values, "title": f"Transient diffusion in {item['title']}"}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
# -- thermal oxidation -----------------------------------------------------------------------
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@tool(
|
|
371
|
+
"oxidation",
|
|
372
|
+
"couplings",
|
|
373
|
+
"Thermal oxidation",
|
|
374
|
+
"The thermal oxidation of an epoxy plate exposed on both faces (the closed-loop scheme "
|
|
375
|
+
"of Colin, Verdu and co-workers with the rate constants that Ernault et al. 2019 "
|
|
376
|
+
"identified on a DGEBA/IPDA at 110 °C in air): oxygen enters by Fick's law at the "
|
|
377
|
+
"concentration S p and is consumed by the radical chain, so that the oxidation "
|
|
378
|
+
"(traced by the amides P=O) stays in a layer a few hundred micrometres thick. The "
|
|
379
|
+
"profiles of the species through the thickness at the times, the thickness of the "
|
|
380
|
+
"oxidized layer against time, the homogeneous oxidation of a thin film, and the "
|
|
381
|
+
"profiles of the properties of an ageing law of the amide concentration (a modulus, a "
|
|
382
|
+
"shrinkage).",
|
|
383
|
+
[
|
|
384
|
+
Field("thickness", "float", 3e-3, unit="m", doc="of the plate, exposed on both faces"),
|
|
385
|
+
Field("times", "floats", [50.0, 111.0, 240.0, 400.0, 800.0], unit="h"),
|
|
386
|
+
Field(
|
|
387
|
+
"pressure", "float", unit="Pa", doc="partial pressure of oxygen (blank: air, 0.21 atm)"
|
|
388
|
+
),
|
|
389
|
+
Field(
|
|
390
|
+
"constants",
|
|
391
|
+
"json",
|
|
392
|
+
label="constants of the scheme",
|
|
393
|
+
doc="changes of the defaults of Ernault et al. (2019): k1...k6 (s⁻¹, l/mol/s), "
|
|
394
|
+
"gamma6, ph0, pooh0 (mol/l), solubility (mol/l/Pa), diffusivity (m²/s)",
|
|
395
|
+
),
|
|
396
|
+
Field("nodes", "int", 61, doc="through half the plate (method of lines)"),
|
|
397
|
+
Field(
|
|
398
|
+
"fraction",
|
|
399
|
+
"float",
|
|
400
|
+
0.1,
|
|
401
|
+
doc="the oxidized layer ends where the amides fall to "
|
|
402
|
+
"this fraction of their value at the surface",
|
|
403
|
+
),
|
|
404
|
+
Field(
|
|
405
|
+
"law",
|
|
406
|
+
"json",
|
|
407
|
+
label="ageing law",
|
|
408
|
+
doc="properties against the amide concentration (mol/l), piecewise linear, e.g. "
|
|
409
|
+
'{"tracer": [0, 1], "young": [2400, 3200], "expansion": [0, -0.01]} (blank: none)',
|
|
410
|
+
),
|
|
411
|
+
],
|
|
412
|
+
order=2,
|
|
413
|
+
menu="Oxidation",
|
|
414
|
+
)
|
|
415
|
+
def oxidation(p: dict, ctx) -> dict:
|
|
416
|
+
import dataclasses
|
|
417
|
+
|
|
418
|
+
from morphogen.coupling import ClosedLoopOxidation, PropertyLaw
|
|
419
|
+
|
|
420
|
+
changes = dict(p["constants"] or {})
|
|
421
|
+
if not isinstance(changes, dict):
|
|
422
|
+
raise ValueError("constants of the scheme: a mapping name -> value")
|
|
423
|
+
known = {f.name for f in dataclasses.fields(ClosedLoopOxidation)}
|
|
424
|
+
unknown = sorted(set(changes) - known)
|
|
425
|
+
if unknown:
|
|
426
|
+
raise ValueError(f"constants of the scheme: unknown {unknown}; among {sorted(known)}")
|
|
427
|
+
if p["pressure"] is not None:
|
|
428
|
+
changes["pressure"] = float(p["pressure"])
|
|
429
|
+
model = ClosedLoopOxidation(**{k: float(v) for k, v in changes.items()})
|
|
430
|
+
hours = np.asarray(p["times"] or [], dtype=float)
|
|
431
|
+
if not len(hours) or np.any(hours <= 0) or np.any(np.diff(hours) <= 0):
|
|
432
|
+
raise ValueError("times: positive and increasing")
|
|
433
|
+
thickness = float(p["thickness"])
|
|
434
|
+
nodes = int(p["nodes"])
|
|
435
|
+
if not (thickness > 0 and 11 <= nodes <= 801):
|
|
436
|
+
raise ValueError("thickness: positive; nodes: from 11 to 801")
|
|
437
|
+
times = hours * 3600.0
|
|
438
|
+
ctx.progress(0.05, "thin film")
|
|
439
|
+
film = model.thin_film(times)
|
|
440
|
+
ctx.progress(0.2, "profiles through the thickness")
|
|
441
|
+
plate = model.profile(thickness, times, nodes=nodes)
|
|
442
|
+
depth = plate["depth"]
|
|
443
|
+
fraction = float(p["fraction"])
|
|
444
|
+
layers = [model.oxidized_layer(depth, a, fraction) for a in plate["PO"]]
|
|
445
|
+
ctx.progress(0.8, "figures")
|
|
446
|
+
um = depth * 1e6
|
|
447
|
+
rows = []
|
|
448
|
+
for k, t in enumerate(hours):
|
|
449
|
+
rows.append(
|
|
450
|
+
{
|
|
451
|
+
"time_h": float(t),
|
|
452
|
+
"oxidized_layer_um": layers[k] * 1e6,
|
|
453
|
+
"amide_surface": float(plate["PO"][k][0]),
|
|
454
|
+
"amide_core": float(plate["PO"][k][-1]),
|
|
455
|
+
"oxygen_core": float(plate["O2"][k][-1]),
|
|
456
|
+
"amide_thin_film": float(film["PO"][k]),
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
ctx.table(rows, "oxidized_layer", "the oxidized layer at the times")
|
|
460
|
+
profile_rows = []
|
|
461
|
+
for i, z in enumerate(um):
|
|
462
|
+
row = {"depth_um": float(z)}
|
|
463
|
+
row.update({f"amide_{t:g}h": float(plate["PO"][k][i]) for k, t in enumerate(hours)})
|
|
464
|
+
profile_rows.append(row)
|
|
465
|
+
ctx.table(profile_rows, "amide_profiles", "amide profiles (mol/l) through the thickness")
|
|
466
|
+
from matplotlib.figure import Figure
|
|
467
|
+
|
|
468
|
+
fig = Figure(figsize=(9.6, 3.8), layout="constrained")
|
|
469
|
+
left, right = fig.subplots(1, 2)
|
|
470
|
+
_plot(
|
|
471
|
+
{f"{t:g} h": (um, plate["PO"][k]) for k, t in enumerate(hours)},
|
|
472
|
+
"depth (µm)",
|
|
473
|
+
"amides P=O (mol/l)",
|
|
474
|
+
"oxidation profiles",
|
|
475
|
+
ax=left,
|
|
476
|
+
)
|
|
477
|
+
for k, layer in enumerate(layers):
|
|
478
|
+
left.axvline(layer * 1e6, color=left.lines[k].get_color(), ls=":", lw=1)
|
|
479
|
+
_plot(
|
|
480
|
+
{f"{t:g} h": (um, plate["O2"][k] * 1e3) for k, t in enumerate(hours)},
|
|
481
|
+
"depth (µm)",
|
|
482
|
+
"oxygen (mmol/l)",
|
|
483
|
+
"dissolved oxygen",
|
|
484
|
+
ax=right,
|
|
485
|
+
)
|
|
486
|
+
reach = min(float(um[-1]), 4e6 * max(layers)) # the core is not oxidized
|
|
487
|
+
for ax in (left, right):
|
|
488
|
+
ax.set_xlim(0.0, reach)
|
|
489
|
+
ctx.figure(fig, "profiles", "profiles through the thickness")
|
|
490
|
+
fig = Figure(figsize=(9.6, 3.8), layout="constrained")
|
|
491
|
+
left, right = fig.subplots(1, 2)
|
|
492
|
+
dense = np.linspace(0.0, times[-1], 200)
|
|
493
|
+
kinetics = model.thin_film(dense[1:])
|
|
494
|
+
_plot(
|
|
495
|
+
{
|
|
496
|
+
"thin film": (dense[1:] / 3600.0, kinetics["PO"]),
|
|
497
|
+
"surface of the plate": (hours, plate["PO"][:, 0]),
|
|
498
|
+
"core of the plate": (hours, plate["PO"][:, -1]),
|
|
499
|
+
},
|
|
500
|
+
"time (h)",
|
|
501
|
+
"amides P=O (mol/l)",
|
|
502
|
+
"kinetics",
|
|
503
|
+
ax=left,
|
|
504
|
+
styles={"surface of the plate": "o-", "core of the plate": "s-"},
|
|
505
|
+
)
|
|
506
|
+
_plot(
|
|
507
|
+
{"oxidized layer": (hours, np.asarray(layers) * 1e6)},
|
|
508
|
+
"time (h)",
|
|
509
|
+
"thickness (µm)",
|
|
510
|
+
f"oxidized layer (amides > {fraction:g} of the surface)",
|
|
511
|
+
ax=right,
|
|
512
|
+
styles={"oxidized layer": "o-"},
|
|
513
|
+
)
|
|
514
|
+
ctx.figure(fig, "kinetics", "kinetics and the oxidized layer")
|
|
515
|
+
values = {
|
|
516
|
+
"oxygen at the surface S p (mol/l)": model.surface_oxygen,
|
|
517
|
+
"final oxidized layer (µm)": layers[-1] * 1e6,
|
|
518
|
+
"final amides at the surface (mol/l)": float(plate["PO"][-1][0]),
|
|
519
|
+
"final amides in the core (mol/l)": float(plate["PO"][-1][-1]),
|
|
520
|
+
"final amides of a thin film (mol/l)": float(film["PO"][-1]),
|
|
521
|
+
}
|
|
522
|
+
if p["law"]:
|
|
523
|
+
spec = dict(p["law"])
|
|
524
|
+
if "tracer" not in spec:
|
|
525
|
+
raise ValueError('ageing law: {"tracer": [...], "<property>": [...]}')
|
|
526
|
+
law = PropertyLaw(tracer=tuple(spec.pop("tracer")), values=spec)
|
|
527
|
+
names = sorted(law.values)
|
|
528
|
+
fig = Figure(figsize=(4.0 * len(names) + 0.8, 3.6), layout="constrained")
|
|
529
|
+
axes = np.atleast_1d(fig.subplots(1, len(names)))
|
|
530
|
+
for ax, name in zip(axes, names, strict=True):
|
|
531
|
+
_plot(
|
|
532
|
+
{f"{t:g} h": (um, law(plate["PO"][k])[name]) for k, t in enumerate(hours)},
|
|
533
|
+
"depth (µm)",
|
|
534
|
+
name,
|
|
535
|
+
f"{name} through the thickness",
|
|
536
|
+
ax=ax,
|
|
537
|
+
)
|
|
538
|
+
ctx.figure(fig, "properties", "properties of the ageing law through the thickness")
|
|
539
|
+
surface = law(plate["PO"][-1][0])
|
|
540
|
+
core = law(plate["PO"][-1][-1])
|
|
541
|
+
for name in names:
|
|
542
|
+
values[f"final {name} at the surface"] = float(surface[name])
|
|
543
|
+
values[f"final {name} in the core"] = float(core[name])
|
|
544
|
+
return {"values": values, "title": f"Thermal oxidation of a plate of {thickness * 1e3:g} mm"}
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
# -- thermal oxidation of a morphology -------------------------------------------------------
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
@tool(
|
|
551
|
+
"oxidation_morphology",
|
|
552
|
+
"couplings",
|
|
553
|
+
"Thermal oxidation of a morphology",
|
|
554
|
+
"The thermal oxidation of the phases of a morphology of the workspace, in its volume: "
|
|
555
|
+
"the closed-loop scheme in every voxel of the phases that oxidize, oxygen diffusing "
|
|
556
|
+
"between the voxels from the exposed faces, around the phases that bar its way "
|
|
557
|
+
"(fibres, fillers) and through the inert phases that let it pass. The oxidation "
|
|
558
|
+
"products (amides P=O) in the volume at the times, their mean profile from the exposed "
|
|
559
|
+
"face against that of a plate of the polymer alone, and the depth of the oxidized "
|
|
560
|
+
"layer.",
|
|
561
|
+
[
|
|
562
|
+
Field("source", "item", label="morphology", required=True),
|
|
563
|
+
Field("resolution", "int", 24, label="voxels per edge"),
|
|
564
|
+
Field(
|
|
565
|
+
"edge",
|
|
566
|
+
"float",
|
|
567
|
+
0.6e-3,
|
|
568
|
+
label="length of the morphology along x",
|
|
569
|
+
unit="m",
|
|
570
|
+
doc="its unit of length follows (the oxidized layer is a hundred micrometres thick)",
|
|
571
|
+
),
|
|
572
|
+
Field(
|
|
573
|
+
"oxidizing",
|
|
574
|
+
"ints",
|
|
575
|
+
[0],
|
|
576
|
+
label="phases that oxidize",
|
|
577
|
+
doc="with the constants of the scheme",
|
|
578
|
+
),
|
|
579
|
+
Field(
|
|
580
|
+
"permeable",
|
|
581
|
+
"ints",
|
|
582
|
+
label="inert phases that let oxygen through",
|
|
583
|
+
doc="with the transport of oxygen of the scheme and no reactive site (blank: "
|
|
584
|
+
"none); the other phases are impermeable and inert",
|
|
585
|
+
),
|
|
586
|
+
Field(
|
|
587
|
+
"exposed",
|
|
588
|
+
"choices",
|
|
589
|
+
["x-"],
|
|
590
|
+
choices=FACES,
|
|
591
|
+
doc="the faces in the atmosphere; the others impermeable, or periodic",
|
|
592
|
+
),
|
|
593
|
+
Field("times", "floats", [111.0, 400.0], unit="h"),
|
|
594
|
+
Field(
|
|
595
|
+
"pressure", "float", unit="Pa", doc="partial pressure of oxygen (blank: air, 0.21 atm)"
|
|
596
|
+
),
|
|
597
|
+
Field(
|
|
598
|
+
"constants",
|
|
599
|
+
"json",
|
|
600
|
+
label="constants of the scheme",
|
|
601
|
+
doc="changes of the defaults of Ernault et al. (2019): k1...k6 (s⁻¹, l/mol/s), "
|
|
602
|
+
"gamma6, ph0, pooh0 (mol/l), solubility (mol/l/Pa), diffusivity (m²/s)",
|
|
603
|
+
),
|
|
604
|
+
Field(
|
|
605
|
+
"fraction",
|
|
606
|
+
"float",
|
|
607
|
+
0.1,
|
|
608
|
+
doc="the oxidized layer ends where the mean amides fall to this fraction of "
|
|
609
|
+
"their value under the exposed face",
|
|
610
|
+
),
|
|
611
|
+
],
|
|
612
|
+
order=3,
|
|
613
|
+
menu="Oxidation",
|
|
614
|
+
)
|
|
615
|
+
def oxidation_morphology(p: dict, ctx) -> dict:
|
|
616
|
+
import dataclasses
|
|
617
|
+
|
|
618
|
+
from morphogen.coupling import ClosedLoopOxidation, oxidation_field
|
|
619
|
+
|
|
620
|
+
item = p["source"]
|
|
621
|
+
n = int(p["resolution"])
|
|
622
|
+
if not 4 <= n <= 64:
|
|
623
|
+
raise ValueError("voxels per edge: from 4 to 64")
|
|
624
|
+
image = _voxel_image(item, n)
|
|
625
|
+
labels = np.asarray(image.data).astype(np.int64)
|
|
626
|
+
present = [int(v) for v in np.unique(labels)]
|
|
627
|
+
changes = dict(p["constants"] or {})
|
|
628
|
+
known = {f.name for f in dataclasses.fields(ClosedLoopOxidation)}
|
|
629
|
+
unknown = sorted(set(changes) - known)
|
|
630
|
+
if unknown:
|
|
631
|
+
raise ValueError(f"constants of the scheme: unknown {unknown}; among {sorted(known)}")
|
|
632
|
+
if p["pressure"] is not None:
|
|
633
|
+
changes["pressure"] = float(p["pressure"])
|
|
634
|
+
model = ClosedLoopOxidation(**{k: float(v) for k, v in changes.items()})
|
|
635
|
+
oxidizing = sorted({int(k) for k in p["oxidizing"] or []})
|
|
636
|
+
permeable = sorted({int(k) for k in p["permeable"] or []})
|
|
637
|
+
if not set(oxidizing) & set(present):
|
|
638
|
+
raise ValueError(f"phases that oxidize: one at least among the phases {present}")
|
|
639
|
+
if set(oxidizing) & set(permeable):
|
|
640
|
+
raise ValueError("a phase oxidizes or is inert, not both")
|
|
641
|
+
inert = dataclasses.replace(model, ph0=0.0, pooh0=0.0)
|
|
642
|
+
schemes = {k: model if k in oxidizing else inert if k in permeable else None for k in present}
|
|
643
|
+
hours = np.asarray(p["times"] or [], dtype=float)
|
|
644
|
+
if not len(hours) or np.any(hours <= 0) or np.any(np.diff(hours) <= 0):
|
|
645
|
+
raise ValueError("times: positive and increasing")
|
|
646
|
+
edge = float(p["edge"])
|
|
647
|
+
if not edge > 0:
|
|
648
|
+
raise ValueError("length of the morphology along x: positive")
|
|
649
|
+
unit = edge / float(image.size[0])
|
|
650
|
+
exposed = list(p["exposed"] or ["x-"])
|
|
651
|
+
ctx.progress(0.05, f"oxidation in {labels.size} voxels")
|
|
652
|
+
found = oxidation_field(
|
|
653
|
+
image,
|
|
654
|
+
schemes,
|
|
655
|
+
hours * 3600.0,
|
|
656
|
+
exposed=exposed,
|
|
657
|
+
unit=unit,
|
|
658
|
+
progress=lambda f: ctx.progress(0.05 + 0.8 * f, f"oxidation in {labels.size} voxels"),
|
|
659
|
+
)
|
|
660
|
+
amide = found.fields["PO"]
|
|
661
|
+
reactive = np.isin(labels, oxidizing)
|
|
662
|
+
# the mean profile of the phases that oxidize, from the first exposed face
|
|
663
|
+
axis = "xyz".index(exposed[0][0])
|
|
664
|
+
other = tuple(a for a in range(3) if a != axis)
|
|
665
|
+
count = reactive.sum(axis=other)
|
|
666
|
+
profiles = (amide * reactive).sum(axis=tuple(a + 1 for a in other)) / np.maximum(count, 1)
|
|
667
|
+
if exposed[0][1] == "+":
|
|
668
|
+
profiles, count = profiles[:, ::-1], count[::-1]
|
|
669
|
+
both = f"{'xyz'[axis]}-" in exposed and f"{'xyz'[axis]}+" in exposed
|
|
670
|
+
length = float(image.size[axis]) * unit
|
|
671
|
+
depth = (np.arange(labels.shape[axis]) + 0.5) * length / labels.shape[axis]
|
|
672
|
+
keep = (depth <= 0.5 * length if both else np.ones(len(depth), bool)) & (count > 0)
|
|
673
|
+
fraction = float(p["fraction"])
|
|
674
|
+
layers = [model.oxidized_layer(depth[keep], a[keep], fraction) for a in profiles]
|
|
675
|
+
ctx.progress(0.88, "the plate of the polymer alone")
|
|
676
|
+
plate = model.profile(length if both else 2.0 * length, hours * 3600.0, nodes=121)
|
|
677
|
+
plate_layers = [model.oxidized_layer(plate["depth"], a, fraction) for a in plate["PO"]]
|
|
678
|
+
rows = []
|
|
679
|
+
for k, t in enumerate(hours):
|
|
680
|
+
rows.append(
|
|
681
|
+
{
|
|
682
|
+
"time_h": float(t),
|
|
683
|
+
"amide_mean": float(amide[k][reactive].mean()),
|
|
684
|
+
"amide_max": float(amide[k][reactive].max()),
|
|
685
|
+
"oxidized_layer_um": layers[k] * 1e6,
|
|
686
|
+
"oxidized_layer_plate_um": plate_layers[k] * 1e6,
|
|
687
|
+
"oxygen_mean": float(found.fields["O2"][k][reactive].mean()),
|
|
688
|
+
}
|
|
689
|
+
)
|
|
690
|
+
ctx.table(rows, "oxidation", "the oxidation of the phases that oxidize at the times")
|
|
691
|
+
um = depth[keep] * 1e6
|
|
692
|
+
profile_rows = []
|
|
693
|
+
for i, z in enumerate(um):
|
|
694
|
+
row = {"depth_um": float(z)}
|
|
695
|
+
row.update({f"amide_{t:g}h": float(profiles[k][keep][i]) for k, t in enumerate(hours)})
|
|
696
|
+
profile_rows.append(row)
|
|
697
|
+
ctx.table(profile_rows, "amide_profiles", "mean amide profiles (mol/l) from the exposed face")
|
|
698
|
+
ctx.progress(0.92, "figures")
|
|
699
|
+
from matplotlib.figure import Figure
|
|
700
|
+
|
|
701
|
+
curves, styles = {}, {}
|
|
702
|
+
for k, t in enumerate(hours):
|
|
703
|
+
curves[f"{t:g} h"] = (um, profiles[k][keep])
|
|
704
|
+
curves[f"{t:g} h, plate"] = (plate["depth"] * 1e6, plate["PO"][k])
|
|
705
|
+
styles[f"{t:g} h"], styles[f"{t:g} h, plate"] = "o-", "k:"
|
|
706
|
+
fig = _plot(
|
|
707
|
+
curves,
|
|
708
|
+
"depth (µm)",
|
|
709
|
+
"amides P=O (mol/l)",
|
|
710
|
+
"mean profiles (dotted: a plate of the polymer alone)",
|
|
711
|
+
styles=styles,
|
|
712
|
+
)
|
|
713
|
+
fig.axes[0].set_xlim(0.0, float(um[-1]))
|
|
714
|
+
ctx.figure(fig, "profiles", "mean oxidation profiles from the exposed face")
|
|
715
|
+
k = labels.shape[2] // 2
|
|
716
|
+
lengths = np.asarray(image.size, dtype=float) * unit * 1e6
|
|
717
|
+
fig = Figure(figsize=(2.8 * len(hours) + 0.8, 3.0), layout="constrained")
|
|
718
|
+
axes_ = np.atleast_1d(fig.subplots(1, len(hours)))
|
|
719
|
+
top = float(amide.max())
|
|
720
|
+
for ax, i in zip(axes_, range(len(hours)), strict=True):
|
|
721
|
+
shown = np.where(reactive[:, :, k], amide[i][:, :, k], np.nan)
|
|
722
|
+
im = ax.imshow(
|
|
723
|
+
shown.T,
|
|
724
|
+
origin="lower",
|
|
725
|
+
extent=(0.0, lengths[0], 0.0, lengths[1]),
|
|
726
|
+
cmap="inferno",
|
|
727
|
+
vmin=0.0,
|
|
728
|
+
vmax=top,
|
|
729
|
+
interpolation="nearest",
|
|
730
|
+
)
|
|
731
|
+
ax.set_title(f"{hours[i]:g} h", fontsize=9)
|
|
732
|
+
ax.set_xlabel("x (µm)")
|
|
733
|
+
fig.colorbar(im, ax=list(axes_), shrink=0.85, label="amides (mol/l)")
|
|
734
|
+
ctx.figure(fig, "fields", "amides in the middle section (x-y) at the times")
|
|
735
|
+
values = {
|
|
736
|
+
"voxels": int(labels.size),
|
|
737
|
+
"time steps": int(found.steps),
|
|
738
|
+
"fraction of the phases that oxidize": float(reactive.mean()),
|
|
739
|
+
"oxygen at the surface S p (mol/l)": model.surface_oxygen,
|
|
740
|
+
"final mean amides (mol/l)": float(amide[-1][reactive].mean()),
|
|
741
|
+
"final oxidized layer (µm)": layers[-1] * 1e6,
|
|
742
|
+
"final oxidized layer of a plate of the polymer alone (µm)": plate_layers[-1] * 1e6,
|
|
743
|
+
"voxels across the final oxidized layer (four at least resolve it)": layers[-1]
|
|
744
|
+
/ (length / labels.shape[axis]),
|
|
745
|
+
}
|
|
746
|
+
return {"values": values, "title": f"Thermal oxidation of {item['title']}"}
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
# -- hygromorph multilayers ------------------------------------------------------------------
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
#: The layers of the default hygromorph: an active layer that swells, more along y, under a
|
|
753
|
+
#: passive one (test_coupling's hygromorph; SI units and MPa)
|
|
754
|
+
LAYERS = {
|
|
755
|
+
"bottom": (
|
|
756
|
+
"constants",
|
|
757
|
+
0.5e-3,
|
|
758
|
+
{
|
|
759
|
+
"young": 2000.0,
|
|
760
|
+
"poisson": 0.35,
|
|
761
|
+
"beta_x": 0.2,
|
|
762
|
+
"beta_y": 0.3,
|
|
763
|
+
"diffusivity": 4e-12,
|
|
764
|
+
"solubility": 0.1,
|
|
765
|
+
},
|
|
766
|
+
),
|
|
767
|
+
"middle": (
|
|
768
|
+
"none",
|
|
769
|
+
0.25e-3,
|
|
770
|
+
{"young": 3000.0, "poisson": 0.35, "diffusivity": 2e-12, "solubility": 0.05},
|
|
771
|
+
),
|
|
772
|
+
"top": (
|
|
773
|
+
"constants",
|
|
774
|
+
0.5e-3,
|
|
775
|
+
{"young": 3500.0, "poisson": 0.35, "diffusivity": 1e-12, "solubility": 0.01},
|
|
776
|
+
),
|
|
777
|
+
}
|
|
778
|
+
#: The properties of the phases of a homogenized layer: a hygroscopic polymer matrix that
|
|
779
|
+
#: swells, and stiff fibres that hardly do (they restrain the swelling along them)
|
|
780
|
+
PHASES = {
|
|
781
|
+
"0": {
|
|
782
|
+
"young": 2000.0,
|
|
783
|
+
"poisson": 0.35,
|
|
784
|
+
"swelling": 0.2,
|
|
785
|
+
"diffusivity": 4e-12,
|
|
786
|
+
"solubility": 0.1,
|
|
787
|
+
},
|
|
788
|
+
"1": {
|
|
789
|
+
"young": 30000.0,
|
|
790
|
+
"poisson": 0.3,
|
|
791
|
+
"swelling": 0.0,
|
|
792
|
+
"diffusivity": 1e-12,
|
|
793
|
+
"solubility": 0.01,
|
|
794
|
+
},
|
|
795
|
+
}
|
|
796
|
+
LAYER_KEYS = ("young", "poisson", "beta_x", "beta_y", "beta_xy", "diffusivity", "solubility")
|
|
797
|
+
PHASE_KEYS = ("young", "poisson", "swelling", "diffusivity", "solubility")
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
def _layer_fields(name: str) -> list[Field]:
|
|
801
|
+
kind, thickness, constants = LAYERS[name]
|
|
802
|
+
choices = [("constants", "properties given"), ("morphology", "homogenized from a morphology")]
|
|
803
|
+
if name == "middle":
|
|
804
|
+
choices.insert(0, ("none", "no middle layer"))
|
|
805
|
+
on = {name: "morphology"}
|
|
806
|
+
return [
|
|
807
|
+
Field(name, "choice", kind, label=f"{name} layer", choices=tuple(choices)),
|
|
808
|
+
Field(
|
|
809
|
+
f"{name}_thickness",
|
|
810
|
+
"float",
|
|
811
|
+
thickness,
|
|
812
|
+
label="thickness",
|
|
813
|
+
unit="m",
|
|
814
|
+
when={name: ["constants", "morphology"]},
|
|
815
|
+
),
|
|
816
|
+
Field(
|
|
817
|
+
f"{name}_properties",
|
|
818
|
+
"json",
|
|
819
|
+
constants,
|
|
820
|
+
label="properties",
|
|
821
|
+
when={name: "constants"},
|
|
822
|
+
doc="young, poisson, beta_x, beta_y, beta_xy (swelling per unit concentration), "
|
|
823
|
+
"diffusivity, solubility",
|
|
824
|
+
),
|
|
825
|
+
Field(f"{name}_morphology", "item", label="morphology", required=True, when=on),
|
|
826
|
+
Field(
|
|
827
|
+
f"{name}_phases",
|
|
828
|
+
"json",
|
|
829
|
+
PHASES,
|
|
830
|
+
label="properties of its phases",
|
|
831
|
+
when=on,
|
|
832
|
+
doc="phase -> young, poisson, swelling, diffusivity, solubility",
|
|
833
|
+
),
|
|
834
|
+
]
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
@tool(
|
|
838
|
+
"hygromorph",
|
|
839
|
+
"couplings",
|
|
840
|
+
"Hygromorph multilayer",
|
|
841
|
+
"A free plate of two or three layers bending and twisting as moisture enters it "
|
|
842
|
+
"(pine cone scales, 4D-printed hygromorphs; Mou, Dirrenberger & Le Duigou 2025): the "
|
|
843
|
+
"moisture diffuses through the thickness (the activity continuous between layers), "
|
|
844
|
+
"each layer swells by β c (orthotropic, with a shear for twisting layers) and the "
|
|
845
|
+
"laminate theory gives the curvatures κx, κy and the twist κxy of the free plate at "
|
|
846
|
+
"every time (positive: bending towards its lower face). A layer is given by its "
|
|
847
|
+
"properties, or homogenized from a morphology of the workspace (its apparent "
|
|
848
|
+
"stiffness, swelling and permeability, periodic FFT homogenization): stiff fibres "
|
|
849
|
+
"aligned in a swelling matrix restrain it along them, and the layer bends across them.",
|
|
850
|
+
[
|
|
851
|
+
*_layer_fields("bottom"),
|
|
852
|
+
*_layer_fields("middle"),
|
|
853
|
+
*_layer_fields("top"),
|
|
854
|
+
Field(
|
|
855
|
+
"resolution", "int", 16, label="voxels per edge", doc="of the morphologies homogenized"
|
|
856
|
+
),
|
|
857
|
+
Field(
|
|
858
|
+
"normal",
|
|
859
|
+
"choice",
|
|
860
|
+
"z",
|
|
861
|
+
choices=("x", "y", "z"),
|
|
862
|
+
doc="the axis of the morphologies along the thickness of their layers",
|
|
863
|
+
),
|
|
864
|
+
Field(
|
|
865
|
+
"exposed",
|
|
866
|
+
"choice",
|
|
867
|
+
"bottom",
|
|
868
|
+
choices=(("bottom", "the bottom face"), ("top", "the top face"), ("both", "both")),
|
|
869
|
+
),
|
|
870
|
+
Field("activity", "float", 1.0, doc="on the exposed faces"),
|
|
871
|
+
Field("initial", "float", 0.0, doc="initial activity (1 and an activity 0: drying)"),
|
|
872
|
+
Field(
|
|
873
|
+
"times",
|
|
874
|
+
"floats",
|
|
875
|
+
unit="s",
|
|
876
|
+
doc="blank: up to three times the diffusion time of the stack",
|
|
877
|
+
),
|
|
878
|
+
Field("steps", "int", 100, doc="implicit Euler steps between two times"),
|
|
879
|
+
],
|
|
880
|
+
order=4,
|
|
881
|
+
groups=(
|
|
882
|
+
("Bottom layer", "bottom"),
|
|
883
|
+
("Middle layer", "middle"),
|
|
884
|
+
("Top layer", "top"),
|
|
885
|
+
("Morphologies of the layers", "resolution", True),
|
|
886
|
+
("Moisture and time", "exposed"),
|
|
887
|
+
),
|
|
888
|
+
menu="Moisture",
|
|
889
|
+
)
|
|
890
|
+
def hygromorph(p: dict, ctx) -> dict:
|
|
891
|
+
from morphogen.coupling import Layer, Multilayer, timoshenko_curvature
|
|
892
|
+
from morphogen.homogenization.materials import Material
|
|
893
|
+
|
|
894
|
+
names = [n for n in ("bottom", "middle", "top") if p[n] != "none"]
|
|
895
|
+
layers, rows = [], []
|
|
896
|
+
for k, name in enumerate(names):
|
|
897
|
+
thickness = float(p[f"{name}_thickness"])
|
|
898
|
+
if not thickness > 0:
|
|
899
|
+
raise ValueError(f"{name} layer: a positive thickness")
|
|
900
|
+
if p[name] == "constants":
|
|
901
|
+
props = _phase_table(
|
|
902
|
+
{"0": p[f"{name}_properties"] or {}}, f"{name} layer", LAYER_KEYS, ("young",)
|
|
903
|
+
)[0]
|
|
904
|
+
layer = Layer(thickness, **props)
|
|
905
|
+
origin = "properties given"
|
|
906
|
+
else:
|
|
907
|
+
item = p[f"{name}_morphology"]
|
|
908
|
+
ctx.progress(0.05 + 0.5 * k / len(names), f"homogenizing the {name} layer")
|
|
909
|
+
image = _voxel_image(item, p["resolution"])
|
|
910
|
+
phases = _phase_table(
|
|
911
|
+
p[f"{name}_phases"] or PHASES, f"{name} layer", PHASE_KEYS, ("young", "poisson")
|
|
912
|
+
)
|
|
913
|
+
present = [int(v) for v in np.unique(image.data)]
|
|
914
|
+
missing = [v for v in present if v not in phases]
|
|
915
|
+
if missing:
|
|
916
|
+
raise ValueError(f"{name} layer: no properties for the phases {missing}")
|
|
917
|
+
perm = {
|
|
918
|
+
v: phases[v].get("diffusivity", 0.0) * phases[v].get("solubility", 1.0)
|
|
919
|
+
for v in present
|
|
920
|
+
}
|
|
921
|
+
top = max(perm.values()) or 1.0
|
|
922
|
+
materials = {
|
|
923
|
+
v: Material(
|
|
924
|
+
young=phases[v]["young"],
|
|
925
|
+
poisson=phases[v]["poisson"],
|
|
926
|
+
conductivity=max(perm[v], 1e-9 * top),
|
|
927
|
+
expansion=phases[v].get("swelling", 0.0),
|
|
928
|
+
)
|
|
929
|
+
for v in present
|
|
930
|
+
}
|
|
931
|
+
layer = Layer.from_microstructure(
|
|
932
|
+
thickness,
|
|
933
|
+
image,
|
|
934
|
+
materials,
|
|
935
|
+
normal="xyz".index(p["normal"]),
|
|
936
|
+
solubility={v: phases[v].get("solubility", 1.0) for v in present},
|
|
937
|
+
)
|
|
938
|
+
origin = f"homogenized from {item['title']}"
|
|
939
|
+
layers.append(layer)
|
|
940
|
+
q = layer.plane_stiffness()
|
|
941
|
+
s = np.linalg.inv(q) # its plane-stress compliance, in the same notation
|
|
942
|
+
rows.append(
|
|
943
|
+
{
|
|
944
|
+
"layer": name,
|
|
945
|
+
"origin": origin,
|
|
946
|
+
"thickness": thickness,
|
|
947
|
+
"Q_xx": q[0, 0],
|
|
948
|
+
"Q_yy": q[1, 1],
|
|
949
|
+
"Q_xy": q[0, 1],
|
|
950
|
+
"Q_ss": q[2, 2],
|
|
951
|
+
"Q_xs": q[0, 2],
|
|
952
|
+
"Q_ys": q[1, 2],
|
|
953
|
+
"S_xx": s[0, 0],
|
|
954
|
+
"S_yy": s[1, 1],
|
|
955
|
+
"S_xy": s[0, 1],
|
|
956
|
+
"S_ss": s[2, 2],
|
|
957
|
+
"S_xs": s[0, 2],
|
|
958
|
+
"S_ys": s[1, 2],
|
|
959
|
+
"beta_x": layer.beta_x,
|
|
960
|
+
"beta_y": layer.beta_y,
|
|
961
|
+
"beta_xy": layer.beta_xy,
|
|
962
|
+
"diffusivity": layer.diffusivity,
|
|
963
|
+
"solubility": layer.solubility,
|
|
964
|
+
}
|
|
965
|
+
)
|
|
966
|
+
if len(layers) < 2:
|
|
967
|
+
raise ValueError("a hygromorph needs two layers at least")
|
|
968
|
+
ctx.table(rows, "layers", "the layers, from the bottom face: their plane-stress stiffness "
|
|
969
|
+
"Q_ij and compliance S_ij = Q⁻¹ (Voigt xx, yy, xy = s, engineering shear; units of "
|
|
970
|
+
"the moduli and their inverse)") # fmt: skip
|
|
971
|
+
plate = Multilayer(layers)
|
|
972
|
+
total = plate.thickness
|
|
973
|
+
diffusivities = [lay.diffusivity for lay in layers]
|
|
974
|
+
if not all(v > 0 for v in diffusivities):
|
|
975
|
+
raise ValueError("every layer needs a positive diffusivity (the moisture crosses them)")
|
|
976
|
+
series = total / sum(lay.thickness / lay.diffusivity for lay in layers)
|
|
977
|
+
scale = total**2 / series
|
|
978
|
+
times = np.asarray(p["times"] or np.geomspace(1e-3, 3.0, 16) * scale, dtype=float)
|
|
979
|
+
if np.any(times <= 0) or np.any(np.diff(times) <= 0):
|
|
980
|
+
raise ValueError("times: positive and increasing")
|
|
981
|
+
ctx.progress(0.6, "moisture and curvatures")
|
|
982
|
+
activity, initial = float(p["activity"]), float(p["initial"])
|
|
983
|
+
c = plate.moisture(
|
|
984
|
+
times, exposed=p["exposed"], activity=activity, initial=initial, steps=int(p["steps"])
|
|
985
|
+
)
|
|
986
|
+
strains, curvatures = plate.deformation(c, full=True)
|
|
987
|
+
# at equilibrium every layer holds S times the activity (the reference: dry, c = 0)
|
|
988
|
+
equilibrium = np.array([layers[i].solubility for i in plate.index]) * activity
|
|
989
|
+
_, final = plate.deformation(equilibrium, full=True)
|
|
990
|
+
history = []
|
|
991
|
+
for i, t in enumerate(times):
|
|
992
|
+
history.append(
|
|
993
|
+
{
|
|
994
|
+
"time": float(t),
|
|
995
|
+
"kappa_x": curvatures[i, 0],
|
|
996
|
+
"kappa_y": curvatures[i, 1],
|
|
997
|
+
"kappa_xy": curvatures[i, 2],
|
|
998
|
+
"strain_x": strains[i, 0],
|
|
999
|
+
"strain_y": strains[i, 1],
|
|
1000
|
+
"mean_concentration": float(np.sum(c[i] * plate.dz) / total),
|
|
1001
|
+
}
|
|
1002
|
+
)
|
|
1003
|
+
ctx.table(history, "curvatures", "curvatures and mid-plane strains along the uptake")
|
|
1004
|
+
ctx.progress(0.85, "figures")
|
|
1005
|
+
from matplotlib.figure import Figure
|
|
1006
|
+
|
|
1007
|
+
fig = Figure(figsize=(9.6, 3.8), layout="constrained")
|
|
1008
|
+
left, right = fig.subplots(1, 2)
|
|
1009
|
+
twist = np.abs(curvatures[:, 2]).max() > 1e-9 * np.abs(curvatures[:, :2]).max()
|
|
1010
|
+
curves = {"κx": (times, curvatures[:, 0]), "κy": (times, curvatures[:, 1])}
|
|
1011
|
+
if twist:
|
|
1012
|
+
curves["κxy (twist)"] = (times, curvatures[:, 2])
|
|
1013
|
+
_plot(
|
|
1014
|
+
curves,
|
|
1015
|
+
"time",
|
|
1016
|
+
"curvature (1/length)",
|
|
1017
|
+
"curvatures of the free plate",
|
|
1018
|
+
logx=True,
|
|
1019
|
+
ax=left,
|
|
1020
|
+
styles=dict.fromkeys(curves, "o-"),
|
|
1021
|
+
)
|
|
1022
|
+
for k, value in enumerate(final[: 3 if twist else 2]):
|
|
1023
|
+
left.axhline(value, color=left.lines[k].get_color(), ls=":", lw=1)
|
|
1024
|
+
shown = np.unique(np.linspace(0, len(times) - 1, min(len(times), 6)).round().astype(int))
|
|
1025
|
+
_plot(
|
|
1026
|
+
{f"t = {times[i]:.3g}": (c[i], plate.z) for i in shown},
|
|
1027
|
+
"concentration",
|
|
1028
|
+
"height z",
|
|
1029
|
+
"moisture through the thickness",
|
|
1030
|
+
ax=right,
|
|
1031
|
+
)
|
|
1032
|
+
for edge in np.cumsum([lay.thickness for lay in layers])[:-1]:
|
|
1033
|
+
right.axhline(edge, color="0.5", lw=0.8)
|
|
1034
|
+
ctx.figure(fig, "curvatures", "curvatures and moisture profiles")
|
|
1035
|
+
fig = Figure(figsize=(5.4, 3.8), layout="constrained")
|
|
1036
|
+
ax = fig.subplots()
|
|
1037
|
+
# a strip seen from its side (x-z), long enough to turn by 1.5 radians at the end
|
|
1038
|
+
bent = float(np.abs(curvatures[:, 0]).max())
|
|
1039
|
+
span = float(np.clip(1.5 / bent if bent > 0 else 0.0, 10.0 * total, 200.0 * total))
|
|
1040
|
+
s = np.linspace(-span / 2, span / 2, 101)
|
|
1041
|
+
for i in shown:
|
|
1042
|
+
k = curvatures[i, 0]
|
|
1043
|
+
x, z = (
|
|
1044
|
+
(s, -k * s**2 / 2)
|
|
1045
|
+
if abs(k * span) < 1e-6
|
|
1046
|
+
else (np.sin(k * s) / k, (np.cos(k * s) - 1.0) / k)
|
|
1047
|
+
)
|
|
1048
|
+
ax.plot(x, z, lw=1.5, label=f"t = {times[i]:.3g}")
|
|
1049
|
+
ax.set_aspect("equal", adjustable="datalim")
|
|
1050
|
+
ax.set_xlabel("x")
|
|
1051
|
+
ax.set_ylabel("z")
|
|
1052
|
+
ax.set_title("a strip along x bending (side view)", fontsize=10)
|
|
1053
|
+
ax.legend(fontsize=7, frameon=False)
|
|
1054
|
+
ax.grid(alpha=0.3)
|
|
1055
|
+
ctx.figure(fig, "strip", "a strip along x bending")
|
|
1056
|
+
values = {
|
|
1057
|
+
"final κx": float(curvatures[-1, 0]),
|
|
1058
|
+
"final κy": float(curvatures[-1, 1]),
|
|
1059
|
+
"final κxy (twist)": float(curvatures[-1, 2]),
|
|
1060
|
+
"equilibrium κx": float(final[0]),
|
|
1061
|
+
"equilibrium κy": float(final[1]),
|
|
1062
|
+
"equilibrium κxy": float(final[2]),
|
|
1063
|
+
"diffusion time of the stack H² / D": scale,
|
|
1064
|
+
}
|
|
1065
|
+
if np.abs(final[:2]).max() > 0:
|
|
1066
|
+
values["equilibrium radius of curvature"] = 1.0 / float(np.abs(final[:2]).max())
|
|
1067
|
+
if len(layers) == 2 and _isotropic_pair(layers): # Timoshenko's bilayer (1925)
|
|
1068
|
+
low, up = layers
|
|
1069
|
+
swell = (up.beta_x * up.solubility - low.beta_x * low.solubility) * activity
|
|
1070
|
+
values["Timoshenko's curvature of the bilayer"] = timoshenko_curvature(
|
|
1071
|
+
swell, low.thickness, up.thickness, low.young, up.young
|
|
1072
|
+
)
|
|
1073
|
+
return {"values": values, "title": f"Hygromorph of {len(layers)} layers"}
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
def _isotropic_pair(layers) -> bool:
|
|
1077
|
+
"""Whether two layers are isotropic, of one Poisson's ratio and with isotropic
|
|
1078
|
+
swellings (Timoshenko's formula is then exact)."""
|
|
1079
|
+
a, b = layers
|
|
1080
|
+
return (
|
|
1081
|
+
a.stiffness is None
|
|
1082
|
+
and b.stiffness is None
|
|
1083
|
+
and math.isclose(a.poisson, b.poisson)
|
|
1084
|
+
and all(math.isclose(x.beta_x, x.beta_y) and x.beta_xy == 0.0 for x in layers)
|
|
1085
|
+
)
|