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,476 @@
|
|
|
1
|
+
"""Loading paths: macroscopic loadings that vary in time, and the responses to them.
|
|
2
|
+
|
|
3
|
+
A path gives, at increasing times, the value of each macroscopic component, prescribed
|
|
4
|
+
as a strain or as a stress (the other one is then an unknown, solved for), and the
|
|
5
|
+
change of temperature; values vary linearly in time between them. The first time is
|
|
6
|
+
the natural state: zero strain, stress and change of temperature. Uniaxial tension at
|
|
7
|
+
a strain rate, creep under a stress, relaxation, cycles or thermal histories are
|
|
8
|
+
paths.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import itertools
|
|
14
|
+
import math
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
from morphogen.homogenization.core import _ALIASES, _ALIASES_VOIGT, VOIGT_NAMES
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _index(key) -> int:
|
|
23
|
+
"""Voigt index of a component name (``"11"`` ... ``"12"``, or ``"21"`` ...)."""
|
|
24
|
+
name = _ALIASES_VOIGT.get(str(key), str(key))
|
|
25
|
+
if name not in VOIGT_NAMES:
|
|
26
|
+
raise ValueError(f"unknown component {key!r}; use {list(VOIGT_NAMES)}")
|
|
27
|
+
return VOIGT_NAMES.index(name)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _series(value, n_times: int, name: str) -> list[float]:
|
|
31
|
+
"""Values of a component at the times: a list (the first one may be omitted, it is
|
|
32
|
+
zero), or one value reached at the end of the first segment and held."""
|
|
33
|
+
if np.ndim(value) == 0:
|
|
34
|
+
v = float(value)
|
|
35
|
+
return [0.0] + [v] * (n_times - 1)
|
|
36
|
+
values = [float(v) for v in value]
|
|
37
|
+
if len(values) == n_times - 1:
|
|
38
|
+
values = [0.0, *values]
|
|
39
|
+
if len(values) != n_times:
|
|
40
|
+
raise ValueError(f"{name}: one value per time ({n_times}), or one value held")
|
|
41
|
+
return values
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class LoadingPath:
|
|
46
|
+
"""History of a macroscopic loading of elasticity.
|
|
47
|
+
|
|
48
|
+
At the ``times`` (increasing; the first one is the natural state), ``values`` gives
|
|
49
|
+
the six Voigt components (11, 22, 33, 23, 31, 12; engineering shear strains),
|
|
50
|
+
prescribed as strains where ``controls`` is true and as stresses elsewhere, and
|
|
51
|
+
``temperature`` the change of temperature. Each segment between two times is
|
|
52
|
+
divided into ``increments`` steps (the solver divides a step further when it does
|
|
53
|
+
not converge).
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
times: tuple[float, ...]
|
|
57
|
+
values: tuple[tuple[float, ...], ...]
|
|
58
|
+
controls: tuple[bool, ...]
|
|
59
|
+
temperature: tuple[float, ...] = ()
|
|
60
|
+
increments: tuple[int, ...] = ()
|
|
61
|
+
|
|
62
|
+
def __post_init__(self) -> None:
|
|
63
|
+
times = tuple(float(t) for t in self.times)
|
|
64
|
+
if len(times) < 2 or not all(math.isfinite(t) for t in times):
|
|
65
|
+
raise ValueError("times: at least two finite times")
|
|
66
|
+
if any(b <= a for a, b in itertools.pairwise(times)):
|
|
67
|
+
raise ValueError("times: strictly increasing")
|
|
68
|
+
values = np.asarray(self.values, dtype=float)
|
|
69
|
+
if values.shape != (len(times), 6) or not np.all(np.isfinite(values)):
|
|
70
|
+
raise ValueError("values: six finite components at each time")
|
|
71
|
+
if np.any(values[0] != 0):
|
|
72
|
+
raise ValueError("a path starts from the natural state: zero values at the first time")
|
|
73
|
+
controls = tuple(bool(c) for c in self.controls)
|
|
74
|
+
if len(controls) != 6:
|
|
75
|
+
raise ValueError("controls: one per component (true: strain, false: stress)")
|
|
76
|
+
temps = tuple(float(t) for t in self.temperature) or (0.0,) * len(times)
|
|
77
|
+
if len(temps) != len(times) or not all(math.isfinite(t) for t in temps):
|
|
78
|
+
raise ValueError("temperature: one finite value per time")
|
|
79
|
+
if temps[0] != 0.0:
|
|
80
|
+
raise ValueError("temperature: zero change at the first time (natural state)")
|
|
81
|
+
incs = self.increments or (10,)
|
|
82
|
+
incs = tuple(int(i) for i in (incs * (len(times) - 1) if len(incs) == 1 else incs))
|
|
83
|
+
if len(incs) != len(times) - 1 or min(incs) < 1:
|
|
84
|
+
raise ValueError("increments: a positive number per segment (or one for all)")
|
|
85
|
+
object.__setattr__(self, "times", times)
|
|
86
|
+
object.__setattr__(self, "values", tuple(tuple(row) for row in values.tolist()))
|
|
87
|
+
object.__setattr__(self, "controls", controls)
|
|
88
|
+
object.__setattr__(self, "temperature", temps)
|
|
89
|
+
object.__setattr__(self, "increments", incs)
|
|
90
|
+
|
|
91
|
+
# -- construction -------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_spec(cls, spec) -> LoadingPath:
|
|
95
|
+
"""Path of a configuration mapping: ``times``, ``increments`` (one per segment, or
|
|
96
|
+
one for all), ``strain`` and ``stress`` (component -> values at the times, or one
|
|
97
|
+
value reached at the end of the first segment and held; the first value, zero,
|
|
98
|
+
may be omitted) and ``temperature`` (likewise). Components not given are free:
|
|
99
|
+
zero stress. ``{"times": [0, 10], "strain": {"11": 0.02}}`` is a uniaxial tension
|
|
100
|
+
at the strain rate 0.002."""
|
|
101
|
+
if isinstance(spec, LoadingPath):
|
|
102
|
+
return spec
|
|
103
|
+
if not isinstance(spec, dict):
|
|
104
|
+
raise ValueError(f"a path is a mapping, got {spec!r}")
|
|
105
|
+
unknown = set(spec) - {"times", "increments", "strain", "stress", "temperature"}
|
|
106
|
+
if unknown:
|
|
107
|
+
raise ValueError(f"path: unknown keys {sorted(unknown)}")
|
|
108
|
+
if "times" not in spec:
|
|
109
|
+
raise ValueError("path: give the times")
|
|
110
|
+
times = [float(t) for t in spec["times"]]
|
|
111
|
+
n = len(times)
|
|
112
|
+
|
|
113
|
+
def series(key):
|
|
114
|
+
raw = spec.get(key) or {}
|
|
115
|
+
if not isinstance(raw, dict):
|
|
116
|
+
raise ValueError(f"path.{key}: a mapping component -> values")
|
|
117
|
+
return {_index(k): _series(v, n, f"path.{key}.{k}") for k, v in raw.items()}
|
|
118
|
+
|
|
119
|
+
strains, stresses = series("strain"), series("stress")
|
|
120
|
+
twice = sorted(set(strains) & set(stresses))
|
|
121
|
+
if twice:
|
|
122
|
+
raise ValueError(f"path: components {[VOIGT_NAMES[i] for i in twice]} given twice")
|
|
123
|
+
values = np.zeros((n, 6))
|
|
124
|
+
controls = [False] * 6
|
|
125
|
+
for i, v in strains.items():
|
|
126
|
+
values[:, i] = v
|
|
127
|
+
controls[i] = True
|
|
128
|
+
for i, v in stresses.items():
|
|
129
|
+
values[:, i] = v
|
|
130
|
+
temperature = spec.get("temperature")
|
|
131
|
+
temps = () if temperature is None else tuple(_series(temperature, n, "path.temperature"))
|
|
132
|
+
incs = spec.get("increments", 10)
|
|
133
|
+
incs = (int(incs),) if np.ndim(incs) == 0 else tuple(int(i) for i in incs)
|
|
134
|
+
return cls(times, values, controls, temps, incs)
|
|
135
|
+
|
|
136
|
+
@classmethod
|
|
137
|
+
def parse(cls, text: str) -> LoadingPath:
|
|
138
|
+
"""Path of a compact text: ``t=0,10,20 n=10 E11=0,0.02,0 S12=0 dT=0,50,50``: the
|
|
139
|
+
times ``t``, the increments ``n`` (one, or one per segment), strain ``E`` and
|
|
140
|
+
stress ``S`` components and the change of temperature ``dT`` at the times (or one
|
|
141
|
+
value reached at the end of the first segment and held); the components not given
|
|
142
|
+
are free (zero stress)."""
|
|
143
|
+
spec: dict = {}
|
|
144
|
+
for item in text.replace(";", " ").split():
|
|
145
|
+
name, _, value = item.partition("=")
|
|
146
|
+
if not value:
|
|
147
|
+
raise ValueError(f"path: expected NAME=VALUES, got {item!r}")
|
|
148
|
+
numbers = [float(v) for v in value.split(",") if v.strip()]
|
|
149
|
+
one = numbers[0] if len(numbers) == 1 else numbers
|
|
150
|
+
if name == "t":
|
|
151
|
+
spec["times"] = numbers
|
|
152
|
+
elif name == "n":
|
|
153
|
+
spec["increments"] = [int(v) for v in numbers] if len(numbers) > 1 else int(one)
|
|
154
|
+
elif name.lower() in ("dt", "temperature"):
|
|
155
|
+
spec["temperature"] = one
|
|
156
|
+
elif name[:1] in ("E", "S") and name[1:]:
|
|
157
|
+
key = "strain" if name[0] == "E" else "stress"
|
|
158
|
+
spec.setdefault(key, {})[name[1:]] = one
|
|
159
|
+
else:
|
|
160
|
+
raise ValueError(f"path: unknown item {name!r} (t, n, E11, S12, dT)")
|
|
161
|
+
return cls.from_spec(spec)
|
|
162
|
+
|
|
163
|
+
@classmethod
|
|
164
|
+
def uniaxial(
|
|
165
|
+
cls, axis: int, *, times, strain=None, stress=None, increments=10, temperature=None
|
|
166
|
+
) -> LoadingPath:
|
|
167
|
+
"""Tension (compression) along ``axis``: its strain (or stress) at the ``times``,
|
|
168
|
+
the other stress components zero."""
|
|
169
|
+
if (strain is None) == (stress is None):
|
|
170
|
+
raise ValueError("uniaxial path: give the strain or the stress along the axis")
|
|
171
|
+
name = VOIGT_NAMES[int(axis)]
|
|
172
|
+
spec = {"times": list(times), "increments": increments}
|
|
173
|
+
spec["strain" if strain is not None else "stress"] = {
|
|
174
|
+
name: strain if strain is not None else stress
|
|
175
|
+
}
|
|
176
|
+
if temperature is not None:
|
|
177
|
+
spec["temperature"] = temperature
|
|
178
|
+
return cls.from_spec(spec)
|
|
179
|
+
|
|
180
|
+
# -- evaluation --------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def strain_controlled(self) -> np.ndarray:
|
|
184
|
+
return np.array(self.controls)
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def duration(self) -> float:
|
|
188
|
+
return self.times[-1] - self.times[0]
|
|
189
|
+
|
|
190
|
+
def at(self, t: float) -> tuple[np.ndarray, float]:
|
|
191
|
+
"""Values of the components and change of temperature at the time ``t``."""
|
|
192
|
+
values = np.asarray(self.values)
|
|
193
|
+
v = np.array([np.interp(t, self.times, values[:, i]) for i in range(6)])
|
|
194
|
+
return v, float(np.interp(t, self.times, self.temperature))
|
|
195
|
+
|
|
196
|
+
def schedule(self) -> np.ndarray:
|
|
197
|
+
"""Times at the end of the planned steps."""
|
|
198
|
+
ends = [
|
|
199
|
+
np.linspace(a, b, n + 1)[1:]
|
|
200
|
+
for a, b, n in zip(self.times[:-1], self.times[1:], self.increments, strict=True)
|
|
201
|
+
]
|
|
202
|
+
return np.concatenate(ends)
|
|
203
|
+
|
|
204
|
+
def to_dict(self) -> dict:
|
|
205
|
+
series = {n: [r[i] for r in self.values] for i, n in enumerate(VOIGT_NAMES)}
|
|
206
|
+
strain = {n: v for i, (n, v) in enumerate(series.items()) if self.controls[i]}
|
|
207
|
+
stress = {n: v for i, (n, v) in enumerate(series.items()) if not self.controls[i]}
|
|
208
|
+
out = {"times": list(self.times), "increments": list(self.increments)}
|
|
209
|
+
if strain:
|
|
210
|
+
out["strain"] = strain
|
|
211
|
+
if stress:
|
|
212
|
+
out["stress"] = stress
|
|
213
|
+
if any(self.temperature):
|
|
214
|
+
out["temperature"] = list(self.temperature)
|
|
215
|
+
return out
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
@dataclass
|
|
219
|
+
class PathResult:
|
|
220
|
+
"""Macroscopic response of a volume element (or of a material point) along a path.
|
|
221
|
+
|
|
222
|
+
``times`` (n), ``strain`` and ``stress`` (n x 6, Voigt; engineering shear strains),
|
|
223
|
+
``temperature`` and ``plastic`` (the mean cumulated plastic strain of the material)
|
|
224
|
+
at each converged step, the first one the natural state; ``phases``: for each
|
|
225
|
+
phase, its mean ``stress``, ``strain`` and ``plastic`` strain at each step;
|
|
226
|
+
``iterations``: Newton iterations of each step; ``fields``: element fields at some
|
|
227
|
+
times (``time -> name -> array``) on ``support``.
|
|
228
|
+
|
|
229
|
+
In finite strains (``kinematics="finite"``), ``strain`` holds the components 11, 22,
|
|
230
|
+
33, 23, 13, 12 of the upper triangular macroscopic displacement gradient ``F - I``
|
|
231
|
+
(nominal strains and simple shears) and ``stress`` those of the mean first
|
|
232
|
+
Piola-Kirchhoff stress (nominal stresses); ``cauchy`` holds the Cauchy (true) stress
|
|
233
|
+
and ``log_strain`` the logarithmic (true) strain, and each phase its mean ``cauchy``
|
|
234
|
+
stress. With porous plastic materials, ``porosity`` holds the mean porosity of their
|
|
235
|
+
points at each step, and each porous phase its mean ``porosity``.
|
|
236
|
+
|
|
237
|
+
``series``: the other curves that a solver records at each step (name -> values:
|
|
238
|
+
the area in contact of the walls of a cell that close,
|
|
239
|
+
:class:`~morphogen.contact.periodic.ContactCell`), columns of :meth:`rows` and
|
|
240
|
+
quantities of :meth:`value` as the others.
|
|
241
|
+
|
|
242
|
+
``orientation``: for a material point that is a crystal, in finite strains or where
|
|
243
|
+
its twins turn it, the Bunge angles (degrees) of its lattice at each step (n x 3;
|
|
244
|
+
the columns ``phi1``, ``Phi`` and ``phi2`` of :meth:`rows`). The lattices of the
|
|
245
|
+
crystals of a volume element are in its ``fields`` (``orientation``):
|
|
246
|
+
:meth:`texture`.
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
name: str
|
|
250
|
+
bc: str
|
|
251
|
+
path: LoadingPath
|
|
252
|
+
times: np.ndarray
|
|
253
|
+
strain: np.ndarray
|
|
254
|
+
stress: np.ndarray
|
|
255
|
+
temperature: np.ndarray
|
|
256
|
+
plastic: np.ndarray
|
|
257
|
+
phases: dict = field(default_factory=dict)
|
|
258
|
+
iterations: np.ndarray = field(default_factory=lambda: np.zeros(0, dtype=int))
|
|
259
|
+
info: dict = field(default_factory=dict)
|
|
260
|
+
fields: dict = field(default_factory=dict, repr=False)
|
|
261
|
+
support: object | None = field(default=None, repr=False)
|
|
262
|
+
kinematics: str = "small"
|
|
263
|
+
cauchy: np.ndarray | None = None
|
|
264
|
+
log_strain: np.ndarray | None = None
|
|
265
|
+
porosity: np.ndarray | None = None
|
|
266
|
+
series: dict = field(default_factory=dict)
|
|
267
|
+
#: other scalar results of the path, by name (the fatigue of its cycle): final values
|
|
268
|
+
#: (:meth:`components`) and quantities of :meth:`value`
|
|
269
|
+
scalars: dict = field(default_factory=dict)
|
|
270
|
+
orientation: np.ndarray | None = None
|
|
271
|
+
|
|
272
|
+
@property
|
|
273
|
+
def n_steps(self) -> int:
|
|
274
|
+
return len(self.times) - 1
|
|
275
|
+
|
|
276
|
+
@property
|
|
277
|
+
def finite(self) -> bool:
|
|
278
|
+
return self.kinematics == "finite"
|
|
279
|
+
|
|
280
|
+
def _true(self, k: int) -> dict[str, float]:
|
|
281
|
+
"""Logarithmic strains ``LE11 ...`` and Cauchy stresses ``TS11 ...`` of step
|
|
282
|
+
``k`` (finite strains)."""
|
|
283
|
+
if self.log_strain is None or self.cauchy is None:
|
|
284
|
+
return {}
|
|
285
|
+
out = {f"LE{n}": float(v) for n, v in zip(VOIGT_NAMES, self.log_strain[k], strict=True)}
|
|
286
|
+
out.update({f"TS{n}": float(v) for n, v in zip(VOIGT_NAMES, self.cauchy[k], strict=True)})
|
|
287
|
+
return out
|
|
288
|
+
|
|
289
|
+
def _row(self, k: int) -> dict:
|
|
290
|
+
"""The curves at step ``k`` (see :meth:`rows`)."""
|
|
291
|
+
row = {"time": float(self.times[k])}
|
|
292
|
+
strain, stress = self.strain[k], self.stress[k]
|
|
293
|
+
row.update({f"E{n}": float(v) for n, v in zip(VOIGT_NAMES, strain, strict=True)})
|
|
294
|
+
row.update({f"S{n}": float(v) for n, v in zip(VOIGT_NAMES, stress, strict=True)})
|
|
295
|
+
row.update(self._true(k))
|
|
296
|
+
row["temperature"] = float(self.temperature[k])
|
|
297
|
+
row["p"] = float(self.plastic[k])
|
|
298
|
+
if self.porosity is not None:
|
|
299
|
+
row["f"] = float(self.porosity[k])
|
|
300
|
+
for phase, series in self.phases.items():
|
|
301
|
+
for n, v in zip(VOIGT_NAMES, series["stress"][k], strict=True):
|
|
302
|
+
row[f"S{n}_{phase}"] = float(v)
|
|
303
|
+
if "cauchy" in series:
|
|
304
|
+
for n, v in zip(VOIGT_NAMES, series["cauchy"][k], strict=True):
|
|
305
|
+
row[f"TS{n}_{phase}"] = float(v)
|
|
306
|
+
row[f"p_{phase}"] = float(series["plastic"][k])
|
|
307
|
+
if "porosity" in series:
|
|
308
|
+
row[f"f_{phase}"] = float(series["porosity"][k])
|
|
309
|
+
row.update({name: float(values[k]) for name, values in self.series.items()})
|
|
310
|
+
if self.orientation is not None:
|
|
311
|
+
angles = zip(("phi1", "Phi", "phi2"), self.orientation[k], strict=True)
|
|
312
|
+
row.update({name: float(v) for name, v in angles})
|
|
313
|
+
return row
|
|
314
|
+
|
|
315
|
+
def rows(self) -> list[dict]:
|
|
316
|
+
"""The curves, one row per step: time, ``E11 ... E12``, ``S11 ... S12``, in finite
|
|
317
|
+
strains the logarithmic strains ``LE11 ...`` and the Cauchy stresses ``TS11 ...``,
|
|
318
|
+
the change of temperature, the mean cumulated plastic strain (and porosity ``f``),
|
|
319
|
+
the mean stress (and Cauchy stress) and plastic strain (and porosity) of each
|
|
320
|
+
phase, and the other curves recorded (``series``)."""
|
|
321
|
+
return [self._row(k) for k in range(len(self.times))]
|
|
322
|
+
|
|
323
|
+
def driven(self) -> int:
|
|
324
|
+
"""The component of the loading: that whose prescribed strain varies most along
|
|
325
|
+
the path (of its prescribed stresses, without a prescribed strain)."""
|
|
326
|
+
values = np.asarray(self.path.values)
|
|
327
|
+
controls = self.path.strain_controlled
|
|
328
|
+
spans = np.ptp(values, axis=0)
|
|
329
|
+
if controls.any():
|
|
330
|
+
spans = np.where(controls, spans, -1.0)
|
|
331
|
+
return int(np.argmax(spans))
|
|
332
|
+
|
|
333
|
+
def texture(self, time: float | None = None):
|
|
334
|
+
"""The lattices of the crystals at a time of the path (the nearest of those of
|
|
335
|
+
its fields; the last one by default): their orientations (Bunge angles in
|
|
336
|
+
degrees, m x 3) and their volumes (m), for the pole figures of
|
|
337
|
+
:mod:`morphogen.texture`. The crystals are the elements of a mesh or the voxels
|
|
338
|
+
of an image whose fields have an ``orientation`` (crystals in finite strains,
|
|
339
|
+
or whose twins turn their lattices; the paths run with ``fields``), or the
|
|
340
|
+
material point of :attr:`orientation`."""
|
|
341
|
+
if self.orientation is not None and not self.fields:
|
|
342
|
+
k = len(self.times) - 1 if time is None else int(np.argmin(np.abs(self.times - time)))
|
|
343
|
+
return self.orientation[k : k + 1].copy(), np.ones(1)
|
|
344
|
+
if not self.fields:
|
|
345
|
+
raise ValueError("texture: the path kept no fields (run it with fields)")
|
|
346
|
+
at = max(self.fields) if time is None else min(self.fields, key=lambda t: abs(t - time))
|
|
347
|
+
arrays = self.fields[at]
|
|
348
|
+
if "orientation" not in arrays:
|
|
349
|
+
raise ValueError(
|
|
350
|
+
"texture: the fields have no orientation of the lattices (those of crystals "
|
|
351
|
+
"in finite strains, or whose twins turn them)"
|
|
352
|
+
)
|
|
353
|
+
euler = np.asarray(arrays["orientation"], dtype=float).reshape(-1, 3)
|
|
354
|
+
volumes = getattr(self.support, "volumes", None)
|
|
355
|
+
weights = np.asarray(volumes(), dtype=float) if callable(volumes) else np.ones(len(euler))
|
|
356
|
+
if weights.shape != (len(euler),):
|
|
357
|
+
raise ValueError("texture: the fields and their support do not match")
|
|
358
|
+
crystals = ~np.isnan(euler).any(axis=1)
|
|
359
|
+
return euler[crystals], weights[crystals]
|
|
360
|
+
|
|
361
|
+
def strength(self, component: int | None = None, upto: int | None = None) -> float:
|
|
362
|
+
"""The largest stress (in absolute value) reached along the path, up to the step
|
|
363
|
+
``upto``, of a component: by default that of the loading (:meth:`driven`). The
|
|
364
|
+
strength of a volume element that softens (damage, fracture), its flow stress
|
|
365
|
+
otherwise."""
|
|
366
|
+
c = self.driven() if component is None else int(component)
|
|
367
|
+
stop = len(self.times) if upto is None else int(upto) + 1
|
|
368
|
+
return float(np.abs(self.stress[:stop, c]).max())
|
|
369
|
+
|
|
370
|
+
def work(self, upto: int | None = None) -> float:
|
|
371
|
+
"""The work of the macroscopic stress per unit volume along the path, ``int Sigma
|
|
372
|
+
: dE`` (trapezoids over the steps; nominal stresses and strains in finite
|
|
373
|
+
strains), up to the step ``upto``: the energy stored and dissipated; at the end of a
|
|
374
|
+
path that breaks the volume element, its work of fracture."""
|
|
375
|
+
stop = len(self.times) if upto is None else int(upto) + 1
|
|
376
|
+
mean = 0.5 * (self.stress[1:stop] + self.stress[: stop - 1])
|
|
377
|
+
return float(np.einsum("ti,ti->", mean, np.diff(self.strain[:stop], axis=0)))
|
|
378
|
+
|
|
379
|
+
def value(self, name: str, time: float | None = None) -> float:
|
|
380
|
+
"""Value of a quantity of the curves (a column of :meth:`rows`: ``E11``, ``S11``,
|
|
381
|
+
``TS11``, ``p``, ``S11_1``...) at the end of the path, or at ``time``: the end of
|
|
382
|
+
one of its steps; or ``strength`` and ``work``, the largest stress of the loading
|
|
383
|
+
and the work done up to there (:meth:`strength`, :meth:`work`)."""
|
|
384
|
+
k = len(self.times) - 1
|
|
385
|
+
if time is not None:
|
|
386
|
+
hits = np.flatnonzero(np.isclose(self.times, float(time), rtol=1e-9, atol=1e-12))
|
|
387
|
+
if hits.size == 0:
|
|
388
|
+
raise ValueError(f"path {self.name!r}: no step ends at the time {time:g}")
|
|
389
|
+
k = int(hits[-1])
|
|
390
|
+
if name == "strength":
|
|
391
|
+
return self.strength(upto=k)
|
|
392
|
+
if name == "work":
|
|
393
|
+
return self.work(upto=k)
|
|
394
|
+
if name in self.scalars:
|
|
395
|
+
return float(self.scalars[name])
|
|
396
|
+
row = self._row(k)
|
|
397
|
+
if name not in row or name == "time":
|
|
398
|
+
columns = [c for c in row if c != "time"] + ["strength", "work"]
|
|
399
|
+
raise ValueError(f"path {self.name!r}: unknown quantity {name!r}; use one of {columns}")
|
|
400
|
+
return row[name]
|
|
401
|
+
|
|
402
|
+
def components(self) -> dict[str, float]:
|
|
403
|
+
"""Final values: ``E11 ... E12``, ``S11 ... S12`` (in finite strains also ``LE11
|
|
404
|
+
...`` and ``TS11 ...``), the mean cumulated plastic strain ``p`` and the other
|
|
405
|
+
curves recorded (``series``)."""
|
|
406
|
+
out = {f"E{n}": float(v) for n, v in zip(VOIGT_NAMES, self.strain[-1], strict=True)}
|
|
407
|
+
out.update({f"S{n}": float(v) for n, v in zip(VOIGT_NAMES, self.stress[-1], strict=True)})
|
|
408
|
+
out.update(self._true(len(self.times) - 1))
|
|
409
|
+
out["p"] = float(self.plastic[-1])
|
|
410
|
+
if self.porosity is not None:
|
|
411
|
+
out["f"] = float(self.porosity[-1])
|
|
412
|
+
out.update({name: float(values[-1]) for name, values in self.series.items()})
|
|
413
|
+
out.update({name: float(value) for name, value in self.scalars.items()})
|
|
414
|
+
return out
|
|
415
|
+
|
|
416
|
+
def row(self) -> dict:
|
|
417
|
+
"""Summary record (long format): final values and solver data."""
|
|
418
|
+
out = {"property": self.name, "bc": self.bc, **self.components()}
|
|
419
|
+
out["steps"] = self.n_steps
|
|
420
|
+
out["iterations"] = int(np.sum(self.iterations))
|
|
421
|
+
out.update(self.info)
|
|
422
|
+
return out
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@dataclass(frozen=True)
|
|
426
|
+
class PathQuantity:
|
|
427
|
+
"""A quantity of the curves of a loading path, for the statistics of RVE studies: a
|
|
428
|
+
column of :meth:`PathResult.rows` (``S11``, ``TS11``, ``p``, ``S11_1``...) at the end
|
|
429
|
+
of the path, or at ``time``, the end of one of its steps (the flow stress at a given
|
|
430
|
+
strain, say), under every boundary condition, or under ``bc`` only.
|
|
431
|
+
|
|
432
|
+
Written ``<path>.<quantity>`` or ``<path>.<quantity>@<time>``: ``tension.S11@5`` is
|
|
433
|
+
``S11`` of the path ``tension`` at the time 5; ``.<bc>`` follows for one boundary
|
|
434
|
+
condition (``tension.S11@5.periodic``).
|
|
435
|
+
"""
|
|
436
|
+
|
|
437
|
+
path: str
|
|
438
|
+
quantity: str
|
|
439
|
+
time: float | None = None
|
|
440
|
+
bc: str | None = None
|
|
441
|
+
|
|
442
|
+
@classmethod
|
|
443
|
+
def parse(cls, text) -> PathQuantity:
|
|
444
|
+
name = str(text).strip()
|
|
445
|
+
bc = None
|
|
446
|
+
head, dot, tail = name.rpartition(".")
|
|
447
|
+
if dot and tail.lower() in _ALIASES:
|
|
448
|
+
name, bc = head, _ALIASES[tail.lower()]
|
|
449
|
+
body, at, when = name.partition("@")
|
|
450
|
+
path, dot, quantity = body.partition(".")
|
|
451
|
+
if not (dot and path and quantity) or "." in quantity:
|
|
452
|
+
raise ValueError(
|
|
453
|
+
f"{text!r}: a quantity of a path is <path>.<quantity>[@<time>][.<bc>], "
|
|
454
|
+
"e.g. tension.S11@5"
|
|
455
|
+
)
|
|
456
|
+
time = None
|
|
457
|
+
if at:
|
|
458
|
+
try:
|
|
459
|
+
time = float(when)
|
|
460
|
+
except ValueError:
|
|
461
|
+
raise ValueError(f"{text!r}: a time after @, e.g. tension.S11@5") from None
|
|
462
|
+
return cls(path, quantity, time, bc)
|
|
463
|
+
|
|
464
|
+
@property
|
|
465
|
+
def name(self) -> str:
|
|
466
|
+
"""Name of the series of the quantity (without the boundary condition)."""
|
|
467
|
+
name = f"{self.path}.{self.quantity}"
|
|
468
|
+
return name if self.time is None else f"{name}@{self.time:.12g}"
|
|
469
|
+
|
|
470
|
+
@property
|
|
471
|
+
def key(self) -> str:
|
|
472
|
+
return self.name if self.bc is None else f"{self.name}.{self.bc}"
|
|
473
|
+
|
|
474
|
+
def of(self, result: PathResult) -> float:
|
|
475
|
+
"""The quantity in a response to the path."""
|
|
476
|
+
return result.value(self.quantity, self.time)
|