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,638 @@
|
|
|
1
|
+
"""The model of an explicit dynamic simulation of a morphology: the unit system of its
|
|
2
|
+
inputs (:class:`UnitSystem`), the materials of its phases (:class:`ExplicitMaterial`),
|
|
3
|
+
its loading (:class:`ExplicitLoading`), its mesh (:func:`explicit_mesh`) and the stable
|
|
4
|
+
time step of that mesh (:func:`critical_time_step`), from which the cost of a run is
|
|
5
|
+
known before it starts.
|
|
6
|
+
|
|
7
|
+
OpenRadioss has no unit system of its own: the values are given in a consistent system,
|
|
8
|
+
which the Starter input names (``/BEGIN``) so that the solver knows it, e.g. Mg, mm and
|
|
9
|
+
s: stresses in MPa, densities in Mg/mm³ (7.85e-9 for a steel), velocities in mm/s,
|
|
10
|
+
forces in N and energies in mJ. :meth:`UnitSystem.from_si` converts values given in SI
|
|
11
|
+
units (a density of 7850 kg/m³, a speed of 10 m/s) into the system."""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import math
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
#: The units of mass, length and time that the Starter of Radioss names (``/BEGIN``),
|
|
21
|
+
#: by their value in kg, m and s
|
|
22
|
+
MASS_UNITS = {"Mg": 1e3, "kg": 1.0, "g": 1e-3, "mg": 1e-6, "ug": 1e-9}
|
|
23
|
+
LENGTH_UNITS = {"m": 1.0, "dm": 1e-1, "cm": 1e-2, "mm": 1e-3, "um": 1e-6, "nm": 1e-9}
|
|
24
|
+
TIME_UNITS = {"s": 1.0, "ms": 1e-3, "us": 1e-6, "ns": 1e-9}
|
|
25
|
+
#: The names of the derived units of the usual systems, by their value in SI units
|
|
26
|
+
_NAMES = {
|
|
27
|
+
"stress": {1.0: "Pa", 1e3: "kPa", 1e6: "MPa", 1e9: "GPa", 1e12: "TPa"},
|
|
28
|
+
"force": {1e-6: "µN", 1e-3: "mN", 1.0: "N", 1e3: "kN", 1e6: "MN"},
|
|
29
|
+
"energy": {1e-9: "nJ", 1e-6: "µJ", 1e-3: "mJ", 1.0: "J", 1e3: "kJ"},
|
|
30
|
+
"velocity": {1e-6: "µm/s", 1e-3: "mm/s", 1.0: "m/s", 1e3: "km/s"},
|
|
31
|
+
}
|
|
32
|
+
#: The kinds of loading of :class:`ExplicitLoading`
|
|
33
|
+
LOADINGS = ("compression", "tension", "shear", "impact")
|
|
34
|
+
AXES = "xyz"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True)
|
|
38
|
+
class UnitSystem:
|
|
39
|
+
"""A consistent system of units of mass, length and time, named as Radioss names
|
|
40
|
+
them (:data:`MASS_UNITS`, :data:`LENGTH_UNITS`, :data:`TIME_UNITS`): every value of
|
|
41
|
+
the inputs is given in it, stresses in mass / (length time²), densities in mass /
|
|
42
|
+
length³, velocities in length / time."""
|
|
43
|
+
|
|
44
|
+
mass: str = "Mg"
|
|
45
|
+
length: str = "mm"
|
|
46
|
+
time: str = "s"
|
|
47
|
+
|
|
48
|
+
def __post_init__(self) -> None:
|
|
49
|
+
for name, value, known in (
|
|
50
|
+
("mass", self.mass, MASS_UNITS),
|
|
51
|
+
("length", self.length, LENGTH_UNITS),
|
|
52
|
+
("time", self.time, TIME_UNITS),
|
|
53
|
+
):
|
|
54
|
+
if value not in known:
|
|
55
|
+
raise ValueError(f"units: the {name} in {', '.join(known)}, got {value!r}")
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def parse(cls, value) -> UnitSystem:
|
|
59
|
+
"""A system from three names (``"Mg mm s"``, ``("kg", "mm", "ms")``) or itself."""
|
|
60
|
+
if isinstance(value, UnitSystem):
|
|
61
|
+
return value
|
|
62
|
+
if value in (None, ""):
|
|
63
|
+
return cls()
|
|
64
|
+
names = value.replace(",", " ").split() if isinstance(value, str) else list(value)
|
|
65
|
+
if len(names) != 3:
|
|
66
|
+
raise ValueError(f"units: the units of mass, length and time, got {value!r}")
|
|
67
|
+
return cls(*[str(n) for n in names])
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def names(self) -> tuple[str, str, str]:
|
|
71
|
+
return (self.mass, self.length, self.time)
|
|
72
|
+
|
|
73
|
+
def si(self, quantity: str) -> float:
|
|
74
|
+
"""The value in SI units of the unit of ``quantity`` in this system: ``mass``,
|
|
75
|
+
``length``, ``time``, ``density``, ``stress``, ``velocity``, ``force``,
|
|
76
|
+
``energy`` or ``strain_rate``."""
|
|
77
|
+
m, l, t = MASS_UNITS[self.mass], LENGTH_UNITS[self.length], TIME_UNITS[self.time]
|
|
78
|
+
values = {
|
|
79
|
+
"mass": m,
|
|
80
|
+
"length": l,
|
|
81
|
+
"time": t,
|
|
82
|
+
"density": m / l**3,
|
|
83
|
+
"stress": m / (l * t * t),
|
|
84
|
+
"velocity": l / t,
|
|
85
|
+
"force": m * l / (t * t),
|
|
86
|
+
"energy": m * l * l / (t * t),
|
|
87
|
+
"strain_rate": 1.0 / t,
|
|
88
|
+
}
|
|
89
|
+
if quantity not in values:
|
|
90
|
+
raise ValueError(f"quantity: one of {', '.join(values)}")
|
|
91
|
+
return values[quantity]
|
|
92
|
+
|
|
93
|
+
def from_si(self, value, quantity: str):
|
|
94
|
+
"""``value`` given in SI units, in this system (a number or an array)."""
|
|
95
|
+
factor = self.si(quantity)
|
|
96
|
+
return np.asarray(value, dtype=float) / factor if np.ndim(value) else float(value) / factor
|
|
97
|
+
|
|
98
|
+
def to_si(self, value, quantity: str):
|
|
99
|
+
"""``value`` given in this system, in SI units (a number or an array)."""
|
|
100
|
+
factor = self.si(quantity)
|
|
101
|
+
return np.asarray(value, dtype=float) * factor if np.ndim(value) else float(value) * factor
|
|
102
|
+
|
|
103
|
+
def unit(self, quantity: str) -> str:
|
|
104
|
+
"""The name of the unit of ``quantity`` (e.g. ``"MPa"``; ``"Mg/mm³"``)."""
|
|
105
|
+
if quantity in ("mass", "length", "time"):
|
|
106
|
+
return getattr(self, quantity)
|
|
107
|
+
if quantity == "density":
|
|
108
|
+
return f"{self.mass}/{self.length}³"
|
|
109
|
+
if quantity == "strain_rate":
|
|
110
|
+
return f"1/{self.time}"
|
|
111
|
+
value = self.si(quantity)
|
|
112
|
+
for known, name in _NAMES.get(quantity, {}).items():
|
|
113
|
+
if math.isclose(value, known, rel_tol=1e-9):
|
|
114
|
+
return name
|
|
115
|
+
return {
|
|
116
|
+
"stress": f"{self.mass}/({self.length} {self.time}²)",
|
|
117
|
+
"velocity": f"{self.length}/{self.time}",
|
|
118
|
+
"force": f"{self.mass} {self.length}/{self.time}²",
|
|
119
|
+
"energy": f"{self.mass} {self.length}²/{self.time}²",
|
|
120
|
+
}[quantity]
|
|
121
|
+
|
|
122
|
+
def describe(self) -> str:
|
|
123
|
+
"""The system and its derived units, in words."""
|
|
124
|
+
return (
|
|
125
|
+
f"{self.mass}, {self.length}, {self.time}: stresses in {self.unit('stress')}, "
|
|
126
|
+
f"densities in {self.unit('density')}, velocities in {self.unit('velocity')}, "
|
|
127
|
+
f"forces in {self.unit('force')}, energies in {self.unit('energy')}"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# -- materials -----------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@dataclass(frozen=True)
|
|
135
|
+
class JohnsonCook:
|
|
136
|
+
"""The yield stress of Johnson and Cook, ``(a + b p^n) (1 + c ln(ṗ / ṗ0))`` (p the
|
|
137
|
+
plastic strain), Radioss's LAW2 without its terms of temperature: ``a`` the yield
|
|
138
|
+
stress, ``b`` and ``n`` the hardening, ``c`` the sensitivity to the strain rate above
|
|
139
|
+
the reference rate ``rate`` (ṗ0, in 1 / time), ``max_stress`` a cap of the yield
|
|
140
|
+
stress (none by default)."""
|
|
141
|
+
|
|
142
|
+
a: float
|
|
143
|
+
b: float = 0.0
|
|
144
|
+
n: float = 1.0
|
|
145
|
+
c: float = 0.0
|
|
146
|
+
rate: float = 1.0
|
|
147
|
+
max_stress: float | None = None
|
|
148
|
+
|
|
149
|
+
def __post_init__(self) -> None:
|
|
150
|
+
values = {"a": self.a, "b": self.b, "n": self.n, "c": self.c, "rate": self.rate}
|
|
151
|
+
for name, value in values.items():
|
|
152
|
+
if not (math.isfinite(float(value)) and float(value) >= 0.0):
|
|
153
|
+
raise ValueError(f"johnson_cook: {name} >= 0, got {value!r}")
|
|
154
|
+
object.__setattr__(self, name, float(value))
|
|
155
|
+
if self.a <= 0.0:
|
|
156
|
+
raise ValueError("johnson_cook: a, the yield stress, > 0")
|
|
157
|
+
if self.n <= 0.0:
|
|
158
|
+
raise ValueError("johnson_cook: n > 0")
|
|
159
|
+
if self.c > 0.0 and self.rate <= 0.0:
|
|
160
|
+
raise ValueError("johnson_cook: a reference strain rate > 0 with c > 0")
|
|
161
|
+
if self.max_stress is not None:
|
|
162
|
+
if not float(self.max_stress) > self.a:
|
|
163
|
+
raise ValueError("johnson_cook: max_stress above a")
|
|
164
|
+
object.__setattr__(self, "max_stress", float(self.max_stress))
|
|
165
|
+
|
|
166
|
+
def yield_stress(self, strain, rate: float = 0.0) -> np.ndarray:
|
|
167
|
+
"""The yield stress at the plastic strains ``strain`` and the strain rate."""
|
|
168
|
+
p = np.asarray(strain, dtype=float)
|
|
169
|
+
out = self.a + self.b * p**self.n
|
|
170
|
+
if self.c > 0.0 and rate > self.rate:
|
|
171
|
+
out = out * (1.0 + self.c * math.log(rate / self.rate))
|
|
172
|
+
if self.max_stress is not None:
|
|
173
|
+
out = np.minimum(out, self.max_stress)
|
|
174
|
+
return out
|
|
175
|
+
|
|
176
|
+
@classmethod
|
|
177
|
+
def from_config(cls, spec) -> JohnsonCook:
|
|
178
|
+
"""``{a, b, n, c, rate, max_stress}`` (aliases A, B, C, ``reference_rate``)."""
|
|
179
|
+
if isinstance(spec, JohnsonCook):
|
|
180
|
+
return spec
|
|
181
|
+
if not isinstance(spec, dict):
|
|
182
|
+
raise ValueError("johnson_cook: a mapping {a, b, n, c, rate}")
|
|
183
|
+
aliases = {"A": "a", "B": "b", "C": "c", "N": "n", "reference_rate": "rate"}
|
|
184
|
+
spec = {aliases.get(k, k): v for k, v in spec.items()}
|
|
185
|
+
unknown = sorted(set(spec) - {"a", "b", "n", "c", "rate", "max_stress"})
|
|
186
|
+
if unknown:
|
|
187
|
+
raise ValueError(f"johnson_cook: unknown keys {unknown}")
|
|
188
|
+
if "a" not in spec:
|
|
189
|
+
raise ValueError("johnson_cook: a, the yield stress")
|
|
190
|
+
return cls(**spec)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
#: The strain rates (in 1 / time) of the yield curves of a viscoplastic material (Norton's
|
|
194
|
+
#: overstress tabulated at each, LAW36 interpolating between them)
|
|
195
|
+
NORTON_RATES = (0.0, *(10.0**k for k in range(-4, 7)))
|
|
196
|
+
#: The plastic strains of the tabulated yield curves (denser near 0, where the
|
|
197
|
+
#: saturating terms bend)
|
|
198
|
+
CURVE_STRAINS = tuple(round(2.0 * (k / 40.0) ** 2, 10) for k in range(41))
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@dataclass(frozen=True)
|
|
202
|
+
class ExplicitMaterial:
|
|
203
|
+
"""The material of a phase in an explicit dynamic simulation: isotropic elasticity
|
|
204
|
+
(``young``, ``poisson``) and its ``density`` (mass / length³), elastic (Radioss's
|
|
205
|
+
LAW1), or elastoplastic: von Mises with the isotropic hardening of morphoGen's
|
|
206
|
+
:class:`~morphogen.homogenization.behaviours.Plasticity` (the yield stress R0, the
|
|
207
|
+
linear hardening H, the terms Q (1 - exp(-b p)); Norton's viscosity K ṗ^(1/n) as
|
|
208
|
+
yield curves at several strain rates, :data:`NORTON_RATES`), tabulated in LAW36, or
|
|
209
|
+
the law of Johnson and Cook (:class:`JohnsonCook`, LAW2). ``failure_strain``: the
|
|
210
|
+
plastic strain at which an element fails and is deleted (none by default)."""
|
|
211
|
+
|
|
212
|
+
young: float
|
|
213
|
+
poisson: float
|
|
214
|
+
density: float
|
|
215
|
+
plasticity: object | None = None
|
|
216
|
+
johnson_cook: JohnsonCook | None = None
|
|
217
|
+
failure_strain: float | None = None
|
|
218
|
+
|
|
219
|
+
def __post_init__(self) -> None:
|
|
220
|
+
e, nu, rho = float(self.young), float(self.poisson), float(self.density)
|
|
221
|
+
if not (math.isfinite(e) and e > 0):
|
|
222
|
+
raise ValueError(f"young: > 0, got {self.young!r}")
|
|
223
|
+
if not -1.0 < nu < 0.5:
|
|
224
|
+
raise ValueError(f"poisson: in (-1, 0.5), got {self.poisson!r}")
|
|
225
|
+
if not (math.isfinite(rho) and rho > 0):
|
|
226
|
+
raise ValueError(
|
|
227
|
+
f"density: > 0, got {self.density!r} (explicit dynamics needs the mass)"
|
|
228
|
+
)
|
|
229
|
+
object.__setattr__(self, "young", e)
|
|
230
|
+
object.__setattr__(self, "poisson", nu)
|
|
231
|
+
object.__setattr__(self, "density", rho)
|
|
232
|
+
if self.plasticity is not None:
|
|
233
|
+
from morphogen.homogenization.behaviours import Plasticity
|
|
234
|
+
|
|
235
|
+
plastic = Plasticity.from_config(self.plasticity)
|
|
236
|
+
if plastic.kinematic:
|
|
237
|
+
raise ValueError(
|
|
238
|
+
"plasticity: kinematic hardening has no equivalent among the laws "
|
|
239
|
+
"written for OpenRadioss (isotropic hardening only)"
|
|
240
|
+
)
|
|
241
|
+
if plastic.hill is not None:
|
|
242
|
+
raise ValueError("plasticity: Hill's criterion is not written for OpenRadioss")
|
|
243
|
+
object.__setattr__(self, "plasticity", plastic)
|
|
244
|
+
if self.johnson_cook is not None:
|
|
245
|
+
object.__setattr__(self, "johnson_cook", JohnsonCook.from_config(self.johnson_cook))
|
|
246
|
+
if self.plasticity is not None:
|
|
247
|
+
raise ValueError("give plasticity or johnson_cook, not both")
|
|
248
|
+
if self.failure_strain is not None:
|
|
249
|
+
eps = float(self.failure_strain)
|
|
250
|
+
if not (math.isfinite(eps) and eps > 0):
|
|
251
|
+
raise ValueError(f"failure_strain: > 0, got {self.failure_strain!r}")
|
|
252
|
+
if self.plasticity is None and self.johnson_cook is None:
|
|
253
|
+
raise ValueError("failure_strain: a plastic strain, which needs a plastic law")
|
|
254
|
+
object.__setattr__(self, "failure_strain", eps)
|
|
255
|
+
|
|
256
|
+
@property
|
|
257
|
+
def law(self) -> str:
|
|
258
|
+
"""The law of Radioss that it is written as: LAW1, LAW2 or LAW36."""
|
|
259
|
+
if self.johnson_cook is not None:
|
|
260
|
+
return "LAW2"
|
|
261
|
+
return "LAW36" if self.plasticity is not None else "LAW1"
|
|
262
|
+
|
|
263
|
+
@property
|
|
264
|
+
def wave_speed(self) -> float:
|
|
265
|
+
"""The speed of the longitudinal (dilatational) waves, sqrt(M / ρ), M the
|
|
266
|
+
P-wave modulus."""
|
|
267
|
+
e, nu = self.young, self.poisson
|
|
268
|
+
modulus = e * (1.0 - nu) / ((1.0 + nu) * (1.0 - 2.0 * nu))
|
|
269
|
+
return math.sqrt(modulus / self.density)
|
|
270
|
+
|
|
271
|
+
def yield_curve(self, strains=None, rate: float = 0.0) -> np.ndarray:
|
|
272
|
+
"""The yield stress at the plastic strains ``strains`` (by default
|
|
273
|
+
:data:`CURVE_STRAINS`) and the plastic strain rate ``rate`` (its plastic law)."""
|
|
274
|
+
p = np.asarray(CURVE_STRAINS if strains is None else strains, dtype=float)
|
|
275
|
+
if self.johnson_cook is not None:
|
|
276
|
+
return self.johnson_cook.yield_stress(p, rate)
|
|
277
|
+
plastic = self.plasticity
|
|
278
|
+
if plastic is None:
|
|
279
|
+
raise ValueError("an elastic material has no yield curve")
|
|
280
|
+
out = plastic.yield_stress + plastic.hardening * p
|
|
281
|
+
for q, b in plastic.isotropic:
|
|
282
|
+
out = out + q * (1.0 - np.exp(-b * p))
|
|
283
|
+
if plastic.viscous and rate > 0.0:
|
|
284
|
+
out = out + plastic.viscosity * rate ** (1.0 / plastic.exponent)
|
|
285
|
+
return out
|
|
286
|
+
|
|
287
|
+
def rates(self) -> tuple[float, ...]:
|
|
288
|
+
"""The strain rates of its tabulated yield curves: several for a viscoplastic
|
|
289
|
+
material, one (0) otherwise."""
|
|
290
|
+
viscous = self.plasticity is not None and self.plasticity.viscous
|
|
291
|
+
return NORTON_RATES if viscous else (0.0,)
|
|
292
|
+
|
|
293
|
+
def to_config(self) -> dict:
|
|
294
|
+
out: dict = {"young": self.young, "poisson": self.poisson, "density": self.density}
|
|
295
|
+
if self.plasticity is not None:
|
|
296
|
+
out["plasticity"] = self.plasticity.to_config()
|
|
297
|
+
if self.johnson_cook is not None:
|
|
298
|
+
jc = self.johnson_cook
|
|
299
|
+
out["johnson_cook"] = {"a": jc.a, "b": jc.b, "n": jc.n, "c": jc.c, "rate": jc.rate}
|
|
300
|
+
if jc.max_stress is not None:
|
|
301
|
+
out["johnson_cook"]["max_stress"] = jc.max_stress
|
|
302
|
+
if self.failure_strain is not None:
|
|
303
|
+
out["failure_strain"] = self.failure_strain
|
|
304
|
+
return out
|
|
305
|
+
|
|
306
|
+
@classmethod
|
|
307
|
+
def from_config(cls, spec, *, density: float | None = None) -> ExplicitMaterial | None:
|
|
308
|
+
"""A material from its configuration: the keys of morphoGen's materials
|
|
309
|
+
(:meth:`~morphogen.homogenization.Material.from_config`: ``young`` and ``poisson``
|
|
310
|
+
or ``bulk`` and ``shear``, ``density``, ``plasticity``), ``johnson_cook``
|
|
311
|
+
(:meth:`JohnsonCook.from_config`) and ``failure_strain``; ``"void"`` (or a void
|
|
312
|
+
material) gives None. ``density``: the density of a material that gives none.
|
|
313
|
+
Its thermal properties are not used."""
|
|
314
|
+
from morphogen.homogenization.materials import Material
|
|
315
|
+
|
|
316
|
+
if isinstance(spec, ExplicitMaterial):
|
|
317
|
+
return spec
|
|
318
|
+
extra: dict = {}
|
|
319
|
+
if isinstance(spec, dict):
|
|
320
|
+
spec = dict(spec)
|
|
321
|
+
for key in ("johnson_cook", "failure_strain"):
|
|
322
|
+
if key in spec:
|
|
323
|
+
extra[key] = spec.pop(key)
|
|
324
|
+
material = Material.from_config(spec)
|
|
325
|
+
if material.void:
|
|
326
|
+
if extra:
|
|
327
|
+
raise ValueError("a void has no plastic law nor failure")
|
|
328
|
+
return None
|
|
329
|
+
if material.young is None:
|
|
330
|
+
raise ValueError(
|
|
331
|
+
"explicit dynamics: isotropic elasticity (young and poisson, or bulk and shear)"
|
|
332
|
+
)
|
|
333
|
+
for name in ("crystal_plasticity", "porous_plasticity", "mfront", "learned"):
|
|
334
|
+
if getattr(material, name) is not None:
|
|
335
|
+
raise ValueError(f"{name}: not written for OpenRadioss")
|
|
336
|
+
rho = material.density if material.density is not None else density
|
|
337
|
+
if rho is None:
|
|
338
|
+
raise ValueError("density: explicit dynamics needs the density of each material")
|
|
339
|
+
return cls(material.young, material.poisson, rho, plasticity=material.plasticity, **extra)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def explicit_materials(spec, *, density: float | None = None) -> dict[int, ExplicitMaterial | None]:
|
|
343
|
+
"""The material of each phase (None for the voids) from a mapping phase -> material
|
|
344
|
+
(:meth:`ExplicitMaterial.from_config`; the phases may be strings)."""
|
|
345
|
+
if not isinstance(spec, dict) or not spec:
|
|
346
|
+
raise ValueError("materials: a mapping phase -> material")
|
|
347
|
+
out: dict[int, ExplicitMaterial | None] = {}
|
|
348
|
+
for key, value in spec.items():
|
|
349
|
+
try:
|
|
350
|
+
phase = int(key)
|
|
351
|
+
except (TypeError, ValueError):
|
|
352
|
+
raise ValueError(f"materials: phases are integers, got {key!r}") from None
|
|
353
|
+
try:
|
|
354
|
+
out[phase] = ExplicitMaterial.from_config(value, density=density)
|
|
355
|
+
except ValueError as exc:
|
|
356
|
+
raise ValueError(f"materials[{phase}]: {exc}") from None
|
|
357
|
+
return out
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
# -- loading -------------------------------------------------------------------------------
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _axis(value, name: str = "axis") -> int:
|
|
364
|
+
if isinstance(value, str) and value.lower() in AXES:
|
|
365
|
+
return AXES.index(value.lower())
|
|
366
|
+
try:
|
|
367
|
+
axis = int(value)
|
|
368
|
+
except (TypeError, ValueError):
|
|
369
|
+
raise ValueError(f"{name}: x, y, z (or 0, 1, 2), got {value!r}") from None
|
|
370
|
+
if axis not in (0, 1, 2):
|
|
371
|
+
raise ValueError(f"{name}: x, y, z (or 0, 1, 2), got {value!r}")
|
|
372
|
+
return axis
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
@dataclass(frozen=True)
|
|
376
|
+
class ExplicitLoading:
|
|
377
|
+
"""The loading of a morphology in an explicit dynamic simulation.
|
|
378
|
+
|
|
379
|
+
* ``compression`` and ``tension``: the lower face normal to ``axis`` held along it,
|
|
380
|
+
the upper face driven along it at the nominal strain rate ``strain_rate`` (in
|
|
381
|
+
1 / time) up to the nominal ``strain``;
|
|
382
|
+
* ``shear``: the lower face held, the upper face driven along ``shear_axis`` (by
|
|
383
|
+
default the next axis) at the rate ``strain_rate`` up to the engineering shear
|
|
384
|
+
``strain``, held along the other axes;
|
|
385
|
+
* ``impact``: the morphology thrown at ``velocity`` (length / time) along -``axis``
|
|
386
|
+
against a fixed rigid wall at its lower face, for ``duration`` (by default the
|
|
387
|
+
time to travel ``strain`` times its length at that velocity).
|
|
388
|
+
|
|
389
|
+
The driven velocities grow smoothly from 0 over the share ``ramp`` of the duration,
|
|
390
|
+
which tempers the first waves. ``lateral``: ``fixed`` (the loaded faces held across
|
|
391
|
+
the axis, as by bonded platens) or ``free`` (they slide freely across it, a node of
|
|
392
|
+
the lower face held against drifting); ``contact``: the self
|
|
393
|
+
contact of the outer surface of the solid (folding struts, cells closing; Radioss's
|
|
394
|
+
TYPE24) with the ``friction`` coefficient."""
|
|
395
|
+
|
|
396
|
+
kind: str = "compression"
|
|
397
|
+
axis: int = 2
|
|
398
|
+
strain: float = 0.2
|
|
399
|
+
strain_rate: float = 100.0
|
|
400
|
+
shear_axis: int | None = None
|
|
401
|
+
velocity: float = 0.0
|
|
402
|
+
duration: float | None = None
|
|
403
|
+
ramp: float = 0.05
|
|
404
|
+
lateral: str = "fixed"
|
|
405
|
+
contact: bool = True
|
|
406
|
+
friction: float = 0.0
|
|
407
|
+
|
|
408
|
+
def __post_init__(self) -> None:
|
|
409
|
+
if self.kind not in LOADINGS:
|
|
410
|
+
raise ValueError(f"loading: one of {', '.join(LOADINGS)}, got {self.kind!r}")
|
|
411
|
+
object.__setattr__(self, "axis", _axis(self.axis))
|
|
412
|
+
shear = self.shear_axis
|
|
413
|
+
if self.kind == "shear":
|
|
414
|
+
shear = (self.axis + 1) % 3 if shear is None else _axis(shear, "shear_axis")
|
|
415
|
+
if shear == self.axis:
|
|
416
|
+
raise ValueError("shear_axis: another axis than the normal of the faces")
|
|
417
|
+
object.__setattr__(self, "shear_axis", shear)
|
|
418
|
+
strain = float(self.strain)
|
|
419
|
+
if not (math.isfinite(strain) and strain > 0.0):
|
|
420
|
+
raise ValueError(f"strain: > 0, got {self.strain!r}")
|
|
421
|
+
if self.kind == "compression" and strain >= 1.0:
|
|
422
|
+
raise ValueError("strain: a nominal compression below 1")
|
|
423
|
+
object.__setattr__(self, "strain", strain)
|
|
424
|
+
rate = float(self.strain_rate)
|
|
425
|
+
if self.kind != "impact" and not (math.isfinite(rate) and rate > 0.0):
|
|
426
|
+
raise ValueError(f"strain_rate: > 0, got {self.strain_rate!r}")
|
|
427
|
+
object.__setattr__(self, "strain_rate", rate)
|
|
428
|
+
v = float(self.velocity)
|
|
429
|
+
if self.kind == "impact" and not (math.isfinite(v) and v > 0.0):
|
|
430
|
+
raise ValueError("velocity: the speed of the impact, > 0")
|
|
431
|
+
object.__setattr__(self, "velocity", v)
|
|
432
|
+
if self.duration is not None:
|
|
433
|
+
t = float(self.duration)
|
|
434
|
+
if not (math.isfinite(t) and t > 0.0):
|
|
435
|
+
raise ValueError(f"duration: > 0, got {self.duration!r}")
|
|
436
|
+
object.__setattr__(self, "duration", t)
|
|
437
|
+
ramp = float(self.ramp)
|
|
438
|
+
if not 0.0 <= ramp < 1.0:
|
|
439
|
+
raise ValueError(f"ramp: a share of the duration in [0, 1), got {self.ramp!r}")
|
|
440
|
+
object.__setattr__(self, "ramp", ramp)
|
|
441
|
+
if self.lateral not in ("free", "fixed"):
|
|
442
|
+
raise ValueError("lateral: free or fixed")
|
|
443
|
+
friction = float(self.friction)
|
|
444
|
+
if not (math.isfinite(friction) and friction >= 0.0):
|
|
445
|
+
raise ValueError("friction: >= 0")
|
|
446
|
+
object.__setattr__(self, "friction", friction)
|
|
447
|
+
object.__setattr__(self, "contact", bool(self.contact))
|
|
448
|
+
|
|
449
|
+
@property
|
|
450
|
+
def driven(self) -> int:
|
|
451
|
+
"""The axis along which the upper face is driven."""
|
|
452
|
+
return self.shear_axis if self.kind == "shear" else self.axis
|
|
453
|
+
|
|
454
|
+
def speed(self, lengths) -> float:
|
|
455
|
+
"""The speed of the upper face once the ramp is over (that of the impact)."""
|
|
456
|
+
if self.kind == "impact":
|
|
457
|
+
return self.velocity
|
|
458
|
+
return self.strain_rate * float(np.asarray(lengths, dtype=float)[self.axis])
|
|
459
|
+
|
|
460
|
+
def sign(self) -> float:
|
|
461
|
+
"""The direction of the motion along :attr:`driven`: -1 for a compression and
|
|
462
|
+
an impact (toward the lower face), +1 otherwise."""
|
|
463
|
+
return -1.0 if self.kind in ("compression", "impact") else 1.0
|
|
464
|
+
|
|
465
|
+
def end_time(self, lengths) -> float:
|
|
466
|
+
"""The duration of the simulation: the nominal strain reached at the rate after
|
|
467
|
+
the ramp (whose smooth step travels half as far as at full speed)."""
|
|
468
|
+
if self.duration is not None:
|
|
469
|
+
return self.duration
|
|
470
|
+
length = float(np.asarray(lengths, dtype=float)[self.axis])
|
|
471
|
+
if self.kind == "impact":
|
|
472
|
+
return self.strain * length / self.velocity
|
|
473
|
+
return self.strain / (self.strain_rate * (1.0 - 0.5 * self.ramp))
|
|
474
|
+
|
|
475
|
+
def velocity_function(self, end_time: float, points: int = 11) -> np.ndarray:
|
|
476
|
+
"""The velocity of the upper face over time, a share of :meth:`speed`: the smooth
|
|
477
|
+
step 3 s² - 2 s³ (s = t / t_ramp) over the ramp, then 1 (to ten times the end,
|
|
478
|
+
so that the solver never extrapolates); rows (t, share)."""
|
|
479
|
+
t_ramp = self.ramp * end_time
|
|
480
|
+
if t_ramp <= 0.0:
|
|
481
|
+
return np.array([[0.0, 1.0], [10.0 * end_time, 1.0]])
|
|
482
|
+
s = np.linspace(0.0, 1.0, points)
|
|
483
|
+
rows = [(t_ramp * x, 3.0 * x**2 - 2.0 * x**3) for x in s]
|
|
484
|
+
rows.append((10.0 * end_time, 1.0))
|
|
485
|
+
return np.array(rows, dtype=float)
|
|
486
|
+
|
|
487
|
+
def displacement(self, times, lengths) -> np.ndarray:
|
|
488
|
+
"""The displacement of the upper face along :attr:`driven` at ``times`` (signed;
|
|
489
|
+
the impact: the distance travelled at the initial velocity)."""
|
|
490
|
+
t = np.asarray(times, dtype=float)
|
|
491
|
+
v = self.sign() * self.speed(lengths)
|
|
492
|
+
if self.kind == "impact":
|
|
493
|
+
return v * t
|
|
494
|
+
t_ramp = self.ramp * self.end_time(lengths)
|
|
495
|
+
if t_ramp <= 0.0:
|
|
496
|
+
return v * t
|
|
497
|
+
s = np.clip(t / t_ramp, 0.0, 1.0)
|
|
498
|
+
within = t_ramp * (s**3 - 0.5 * s**4) # the integral of 3 s² - 2 s³
|
|
499
|
+
return v * np.where(t <= t_ramp, within, 0.5 * t_ramp + (t - t_ramp))
|
|
500
|
+
|
|
501
|
+
def to_config(self) -> dict:
|
|
502
|
+
out = {"kind": self.kind, "axis": AXES[self.axis]}
|
|
503
|
+
if self.kind == "impact":
|
|
504
|
+
out["velocity"] = self.velocity
|
|
505
|
+
else:
|
|
506
|
+
out["strain_rate"] = self.strain_rate
|
|
507
|
+
out["strain"] = self.strain
|
|
508
|
+
if self.kind == "shear":
|
|
509
|
+
out["shear_axis"] = AXES[self.shear_axis]
|
|
510
|
+
if self.duration is not None:
|
|
511
|
+
out["duration"] = self.duration
|
|
512
|
+
out.update(
|
|
513
|
+
ramp=self.ramp, lateral=self.lateral, contact=self.contact, friction=self.friction
|
|
514
|
+
)
|
|
515
|
+
return out
|
|
516
|
+
|
|
517
|
+
@classmethod
|
|
518
|
+
def from_config(cls, spec) -> ExplicitLoading:
|
|
519
|
+
"""A loading from its configuration (the fields, axes as x, y, z)."""
|
|
520
|
+
if isinstance(spec, ExplicitLoading):
|
|
521
|
+
return spec
|
|
522
|
+
if spec in (None, ""):
|
|
523
|
+
return cls()
|
|
524
|
+
if isinstance(spec, str):
|
|
525
|
+
return cls(kind=spec)
|
|
526
|
+
if not isinstance(spec, dict):
|
|
527
|
+
raise ValueError("loading: a mapping {kind, axis, strain, strain_rate, ...}")
|
|
528
|
+
known = {
|
|
529
|
+
"kind",
|
|
530
|
+
"axis",
|
|
531
|
+
"strain",
|
|
532
|
+
"strain_rate",
|
|
533
|
+
"shear_axis",
|
|
534
|
+
"velocity",
|
|
535
|
+
"duration",
|
|
536
|
+
"ramp",
|
|
537
|
+
"lateral",
|
|
538
|
+
"contact",
|
|
539
|
+
"friction",
|
|
540
|
+
}
|
|
541
|
+
unknown = sorted(set(spec) - known)
|
|
542
|
+
if unknown:
|
|
543
|
+
raise ValueError(f"loading: unknown keys {unknown} (known: {', '.join(sorted(known))})")
|
|
544
|
+
return cls(**spec)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
# -- meshes and time steps -----------------------------------------------------------------
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def explicit_mesh(
|
|
551
|
+
micro,
|
|
552
|
+
materials: dict,
|
|
553
|
+
*,
|
|
554
|
+
mesh: str = "voxels",
|
|
555
|
+
resolution: int = 24,
|
|
556
|
+
element_size: float | None = None,
|
|
557
|
+
order: int = 1,
|
|
558
|
+
):
|
|
559
|
+
"""The mesh of a morphology for an explicit simulation, of its phases that are not
|
|
560
|
+
voids (``materials``: phase -> :class:`ExplicitMaterial` or None): ``"voxels"``,
|
|
561
|
+
8-node hexahedra of its voxel image of ``resolution`` voxels along its longest edge
|
|
562
|
+
(:func:`morphogen.mesh.voxel.voxel_mesh`), or ``"conforming"``, tetrahedra of
|
|
563
|
+
``order`` 1 or 2 conforming to its level set, ``element_size`` the largest
|
|
564
|
+
(:func:`morphogen.mesh.conforming_mesh`; 1/12 of the longest edge by default)."""
|
|
565
|
+
voids = {int(q) for q, m in materials.items() if m is None}
|
|
566
|
+
if mesh == "voxels":
|
|
567
|
+
from morphogen.mesh.voxel import voxel_mesh
|
|
568
|
+
|
|
569
|
+
image = micro.voxelize(shape=int(resolution))
|
|
570
|
+
present = {int(q) for q in np.unique(image.data)}
|
|
571
|
+
missing = sorted(present - set(materials))
|
|
572
|
+
if missing:
|
|
573
|
+
raise ValueError(f"phases {missing}: no material (give theirs, or 'void')")
|
|
574
|
+
solid = sorted(present - voids)
|
|
575
|
+
if not solid:
|
|
576
|
+
raise ValueError("every phase of the image is void")
|
|
577
|
+
labels = micro.labels(grid=image.grid()) if getattr(micro, "has_labels", False) else None
|
|
578
|
+
return voxel_mesh(image, solid if voids & present else None, labels=labels)
|
|
579
|
+
if mesh != "conforming":
|
|
580
|
+
raise ValueError("mesh: voxels or conforming")
|
|
581
|
+
from morphogen.mesh import conforming_mesh
|
|
582
|
+
|
|
583
|
+
edge = float(np.max(micro.domain.lengths))
|
|
584
|
+
size = float(element_size) if element_size else edge / 12.0
|
|
585
|
+
phases = "solid" if 0 in voids and 1 not in voids else "all"
|
|
586
|
+
tets = conforming_mesh(micro, size=size, order=int(order), phases=phases)
|
|
587
|
+
present = {int(q) for q in np.unique(tets.phase)}
|
|
588
|
+
missing = sorted(present - set(materials))
|
|
589
|
+
if missing:
|
|
590
|
+
raise ValueError(f"phases {missing}: no material (give theirs, or 'void')")
|
|
591
|
+
if present & voids:
|
|
592
|
+
if not present - voids:
|
|
593
|
+
raise ValueError("every phase of the mesh is void")
|
|
594
|
+
tets = tets.subset(sorted(present - voids))
|
|
595
|
+
return tets
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def element_lengths(mesh) -> np.ndarray:
|
|
599
|
+
"""The characteristic length of each element of a mesh: the smallest edge of the
|
|
600
|
+
voxels of a voxel mesh; the smallest altitude (3 V / the largest face) of the
|
|
601
|
+
tetrahedra, halved for the quadratic ones (whose nodes lie twice as close)."""
|
|
602
|
+
elements = np.asarray(mesh.elements)
|
|
603
|
+
if elements.shape[1] == 8:
|
|
604
|
+
return np.full(len(elements), float(np.min(mesh.spacing)))
|
|
605
|
+
nodes = np.asarray(mesh.nodes, dtype=float)
|
|
606
|
+
x = nodes[elements[:, :4]]
|
|
607
|
+
volume = (
|
|
608
|
+
np.abs(
|
|
609
|
+
np.einsum("ij,ij->i", np.cross(x[:, 1] - x[:, 0], x[:, 2] - x[:, 0]), x[:, 3] - x[:, 0])
|
|
610
|
+
)
|
|
611
|
+
/ 6.0
|
|
612
|
+
)
|
|
613
|
+
faces = ((0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3))
|
|
614
|
+
area = np.max(
|
|
615
|
+
[
|
|
616
|
+
0.5 * np.linalg.norm(np.cross(x[:, b] - x[:, a], x[:, c] - x[:, a]), axis=1)
|
|
617
|
+
for a, b, c in faces
|
|
618
|
+
],
|
|
619
|
+
axis=0,
|
|
620
|
+
)
|
|
621
|
+
lengths = 3.0 * volume / np.maximum(area, 1e-300)
|
|
622
|
+
return lengths if elements.shape[1] == 4 else 0.5 * lengths
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def critical_time_step(mesh, materials: dict, *, scale: float = 0.9) -> float:
|
|
626
|
+
"""The stable time step of an explicit integration of a mesh, about: ``scale`` times
|
|
627
|
+
the smallest time of a longitudinal wave across an element (its characteristic
|
|
628
|
+
length, :func:`element_lengths`, over the wave speed of its material). Radioss
|
|
629
|
+
computes its own, a little smaller with its bulk viscosity."""
|
|
630
|
+
lengths = element_lengths(mesh)
|
|
631
|
+
phase = np.asarray(mesh.phase)
|
|
632
|
+
speed = np.zeros(len(phase))
|
|
633
|
+
for q in np.unique(phase):
|
|
634
|
+
material = materials.get(int(q))
|
|
635
|
+
if material is None:
|
|
636
|
+
raise ValueError(f"phase {int(q)}: no material")
|
|
637
|
+
speed[phase == q] = material.wave_speed
|
|
638
|
+
return float(scale * np.min(lengths / speed))
|