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,2061 @@
|
|
|
1
|
+
"""Viscoelasticity, hyperelasticity and damage: behaviours of the phases given in closed
|
|
2
|
+
form, integrated at all the points of a phase at once.
|
|
3
|
+
|
|
4
|
+
They follow the seam of the laws integrated outside the compiled kernels (the MFront
|
|
5
|
+
behaviours and the learned laws, :mod:`morphogen.learning.behaviour`): a material whose
|
|
6
|
+
``viscoelasticity``, ``hyperelasticity`` or ``damage`` is set has its points integrated by
|
|
7
|
+
one of the laws of this module, at a material point, by finite elements, on the voxels of
|
|
8
|
+
the FFT solver and in the bulk of the crack solvers; the rest of the solvers is unchanged
|
|
9
|
+
(the periodic element, Newton's method, the outputs). The elastic constants of the
|
|
10
|
+
material (``young``, ``poisson``) are the instantaneous ones: those of the linear
|
|
11
|
+
problems, of the reference medium of the FFT solver and of the first instant of a path.
|
|
12
|
+
|
|
13
|
+
**Viscoelasticity** (:class:`Viscoelasticity`): the generalized Maxwell model, a Prony
|
|
14
|
+
series of the shear and bulk relaxation moduli,
|
|
15
|
+
|
|
16
|
+
G(t) = G0 (1 - sum_i g_i (1 - exp(-t / tau_i))), K(t) likewise with (k_j, tau_j),
|
|
17
|
+
|
|
18
|
+
relative to the instantaneous moduli (the convention of Abaqus). The stress is ``s = 2
|
|
19
|
+
G_inf e + sum_i q_i`` (deviators), each branch relaxing as ``dq_i/dt + q_i / tau_i = 2 g_i
|
|
20
|
+
G0 de/dt``, integrated exactly for a strain that varies linearly over the step (the
|
|
21
|
+
recurrence of Taylor, Pister & Goudreau 1970): ``q_i <- exp(-x) q_i + 2 g_i G0 phi(x) de``,
|
|
22
|
+
``x = dt / tau_i``, ``phi(x) = (1 - exp(-x)) / x``; the tangent is the elasticity of the
|
|
23
|
+
moduli ``G_inf + sum_i g_i G0 phi(x_i)``. Thermo-rheologically simple materials shift
|
|
24
|
+
their times by ``a_T`` (Williams-Landel-Ferry, or Arrhenius). In finite strains the same
|
|
25
|
+
law holds in the logarithmic strain space, as the other behaviours of morphoGen; with a
|
|
26
|
+
``hyperelasticity``, it is the finite linear viscoelasticity of Simo (1987): the branches
|
|
27
|
+
relax the isochoric and volumetric second Piola-Kirchhoff stresses of the hyperelastic
|
|
28
|
+
law, ``Q_i <- exp(-x) Q_i + g_i phi(x) (S_iso^(n+1) - S_iso^n)``.
|
|
29
|
+
:meth:`Viscoelasticity.complex_moduli` gives the storage and loss moduli of a frequency
|
|
30
|
+
(the correspondence principle: :mod:`morphogen.homogenization.harmonic`).
|
|
31
|
+
|
|
32
|
+
**Hyperelasticity** (:class:`Hyperelasticity`; finite strains): a strain energy ``W =
|
|
33
|
+
psi(I1b, I2b) + U(J)`` of the isochoric invariants ``I1b = J^(-2/3) I1``, ``I2b =
|
|
34
|
+
J^(-4/3) I2`` of ``C = F^T F`` and of ``J = det F`` (neo-Hookean, the polynomial of
|
|
35
|
+
Rivlin with its forms of Mooney and Rivlin and of Yeoh, Arruda-Boyce and the eight chains,
|
|
36
|
+
Gent, van der Waals, Fung), of the isochoric principal stretches (Ogden), of the stretches
|
|
37
|
+
of families of fibres in a neo-Hookean matrix (Holzapfel, Gasser and Ogden), compressible
|
|
38
|
+
without a split (the foams of Blatz and Ko and of Ogden, Hill and Storakers), or the law
|
|
39
|
+
of Saint-Venant and Kirchhoff. The law gives the second Piola-Kirchhoff stress ``S = 2
|
|
40
|
+
dW/dC`` and its tangent ``dS/dE = 4 d2W/dC2`` (symmetric), which the points turn into the
|
|
41
|
+
first Piola-Kirchhoff stress and ``dP/dF``. Its isochoric stress may soften as the
|
|
42
|
+
rubbers of Mullins (Ogden & Roxburgh 1999). In small strains the material is elastic (its
|
|
43
|
+
tangent at the natural state: the fibres of Holzapfel do not count there).
|
|
44
|
+
:meth:`_Hyperelastic.nominal_stress` gives the tests of rubbers (uniaxial, equibiaxial
|
|
45
|
+
and planar tension, simple shear) and :func:`fit_hyperelasticity` fits a law to them.
|
|
46
|
+
|
|
47
|
+
**Damage** (:class:`Damage`): the isotropic damage of quasi-brittle solids, ``sigma =
|
|
48
|
+
(1 - d) C : eps``, the damage ``d`` a function of the largest equivalent strain ``kappa``
|
|
49
|
+
reached (the energy norm of Marigo and Lemaitre, Mazars' positive principal strains, or
|
|
50
|
+
the modified von Mises strain of de Vree et al. 1995), with a linear or exponential
|
|
51
|
+
softening. The stress may keep the stiffness of closed cracks: the bulk response in
|
|
52
|
+
compression (the volumetric split of Amor et al. 2009), or that of the negative principal
|
|
53
|
+
strains (the spectral split of Miehe et al. 2010, ``sigma = (1 - d) sigma+ + sigma-`` with
|
|
54
|
+
``sigma± = lambda <tr eps>± I + 2 mu eps±``: the unilateral effect, a crack that closes
|
|
55
|
+
carries the compression across it). Softening makes the dissipation of a local law
|
|
56
|
+
vanish with the size of the elements: the fracture energy ``G_f`` and the size ``length``
|
|
57
|
+
of the elements set the ultimate strain so that a band of one element dissipates ``G_f``
|
|
58
|
+
per unit area (the crack band of Bazant & Oh 1983), and a ``viscosity`` delays the damage
|
|
59
|
+
(``d_v <- (d_v + d dt / eta) / (1 + dt / eta)``), which keeps the incremental problems
|
|
60
|
+
well posed. The nonlocal alternative, whose bands have a width of their own, is the
|
|
61
|
+
micromorphic damage of :mod:`morphogen.micromorphic`. In finite strains the law holds in
|
|
62
|
+
the logarithmic strain space.
|
|
63
|
+
|
|
64
|
+
**Concrete** (:class:`Mazars`): the law of Mazars (1984, 1986) with a damage of tension and
|
|
65
|
+
one of compression, ``d = alpha_t^beta d_t(kappa) + alpha_c^beta d_c(kappa)``, each ``d_i =
|
|
66
|
+
1 - kappa_0 (1 - A_i) / kappa - A_i exp(-B_i (kappa - kappa_0))`` of the largest equivalent
|
|
67
|
+
strain ``kappa`` (the norm of the positive principal strains), weighted by the shares
|
|
68
|
+
``alpha_t`` and ``alpha_c = 1 - alpha_t`` of the positive strains that the tensions and
|
|
69
|
+
the compressions of the effective stress make: 1 and 0 in a uniaxial tension, 0 and 1 in
|
|
70
|
+
a uniaxial compression (which only extends the point sideways).
|
|
71
|
+
|
|
72
|
+
**Damage coupled to plasticity** (:class:`DuctileDamage`, with the ``plasticity`` of the
|
|
73
|
+
material): the elasto-(visco)plasticity of von Mises of
|
|
74
|
+
:mod:`morphogen.homogenization.behaviours` (isotropic and kinematic hardenings, Norton's
|
|
75
|
+
flow) is that of the effective stress ``sigma~ = sigma / (1 - D)`` (the strain
|
|
76
|
+
equivalence of Lemaitre & Chaboche), and the damage ``D`` follows
|
|
77
|
+
|
|
78
|
+
* ``lemaitre``: ``dD = (Y / S)^s dp`` beyond the cumulated plastic strain ``threshold``
|
|
79
|
+
(Lemaitre 1985), with ``Y`` the energy release rate of the effective stress, ``Y =
|
|
80
|
+
sigma~_eq^2 R_nu / (2 E)``, ``R_nu = 2/3 (1 + nu) + 3 (1 - 2 nu) (sigma~_m /
|
|
81
|
+
sigma~_eq)^2`` the triaxiality function; with the ``closure`` ``h`` of the microcracks
|
|
82
|
+
(Ladeveze & Lemaitre 1984), the negative principal stresses count for ``h`` of
|
|
83
|
+
themselves in ``Y`` (0.2 for metals: compression damages little). Ductile fracture,
|
|
84
|
+
and the fatigue of a few cycles: the damage of a cycle is that of its plastic strain;
|
|
85
|
+
* ``kachanov``: ``dD/dt = (chi(sigma) / A)^r (1 - D)^(-k)`` (Kachanov 1958; Rabotnov
|
|
86
|
+
1969), the damage of creep, with Hayhurst's (1972) stress ``chi = alpha sigma_I + 3
|
|
87
|
+
beta sigma_m + (1 - alpha - beta) sigma_eq`` of the largest principal stress, the mean
|
|
88
|
+
stress and von Mises' stress: under a constant stress the time to rupture is ``1 /
|
|
89
|
+
((k + 1) (chi / A)^r)`` and ``D = 1 - (1 - t / t_R)^(1 / (k + 1))``, the creep of the
|
|
90
|
+
effective stress speeding up as the section is lost (tertiary creep).
|
|
91
|
+
|
|
92
|
+
A point whose damage reaches ``critical`` is broken: it keeps the ``residual`` fraction
|
|
93
|
+
of its stress. The laws are local: once the stress falls their bands are those of the
|
|
94
|
+
elements (the micromorphic ductile damage of :mod:`morphogen.micromorphic` has a width
|
|
95
|
+
of its own), and the incremental problems of a cell lose their solution; a ``viscosity``
|
|
96
|
+
delays the damage that degrades the stress behind that of the law, ``dD/dt = (D_law -
|
|
97
|
+
D) / eta``, which keeps them well posed.
|
|
98
|
+
|
|
99
|
+
Stresses use the Voigt order 11 22 33 23 31 12, strains the engineering shears; the
|
|
100
|
+
variable ``p`` of the outputs of a damaged phase is its damage.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
from __future__ import annotations
|
|
104
|
+
|
|
105
|
+
import math
|
|
106
|
+
from dataclasses import dataclass
|
|
107
|
+
|
|
108
|
+
import numpy as np
|
|
109
|
+
from scipy.special import erf
|
|
110
|
+
|
|
111
|
+
from morphogen.homogenization.materials import isotropic_matrix
|
|
112
|
+
|
|
113
|
+
#: Hyperelastic models and their parameters (those in brackets have a default: the
|
|
114
|
+
#: shear and bulk moduli of the material)
|
|
115
|
+
HYPERELASTIC_MODELS = {
|
|
116
|
+
"neo_hookean": "psi = mu/2 (I1b - 3) [mu]",
|
|
117
|
+
"mooney_rivlin": "psi = sum cij (I1b - 3)^i (I2b - 3)^j, i + j <= 3 c10, c01, [cij]",
|
|
118
|
+
"polynomial": "psi = sum cij (I1b - 3)^i (I2b - 3)^j, i + j <= 6 cij",
|
|
119
|
+
"yeoh": "psi = c10 (I1b - 3) + c20 (I1b - 3)^2 + c30 (I1b - 3)^3 c10, [c20, c30]",
|
|
120
|
+
"arruda_boyce": "psi = mu sum_i a_i / lock^(2i-2) (I1b^i - 3^i) [mu], lock",
|
|
121
|
+
"eight_chain": "psi' = mu/6 (3 - x) / (1 - x), x = I1b / (3 lock^2) [mu], lock",
|
|
122
|
+
"gent": "psi = -mu Jm / 2 ln(1 - (I1b - 3) / Jm) [mu], lock (Jm)",
|
|
123
|
+
"van_der_waals": "psi = mu (-(lock^2 - 3) (ln(1 - e) + e) - 2a/3 ((I - 3)/2)^1.5)"
|
|
124
|
+
" [mu], lock, [a, beta]",
|
|
125
|
+
"fung": "psi = mu / (2 b) (exp(b (I1b - 3)) - 1) [mu], b",
|
|
126
|
+
"ogden": "psi = sum_p mu_p / alpha_p (l1^a + l2^a + l3^a - 3) terms",
|
|
127
|
+
"holzapfel": "psi = mu/2 (I1b - 3) + k1/(2 k2) sum_f (exp(k2 E_f^2) - 1)"
|
|
128
|
+
" [mu], k1, k2, [kappa], fibres",
|
|
129
|
+
"blatz_ko": "W = mu f/2 (I1 - 3 + (J^(-2b) - 1)/b) + mu (1-f)/2 (I2/J^2 - 3 + (J^(2b) - 1)/b)"
|
|
130
|
+
" [mu, f]",
|
|
131
|
+
"hyperfoam": "W = sum_p 2 mu_p / alpha_p^2 (l1^a + l2^a + l3^a - 3 + (J^(-a b) - 1)/b) terms",
|
|
132
|
+
"saint_venant_kirchhoff": "S = lambda tr(E) I + 2 mu E (none)",
|
|
133
|
+
}
|
|
134
|
+
#: The parameters that each model takes and those it must be given (the polynomials take
|
|
135
|
+
#: besides any coefficient ``cij`` up to their order, :data:`_ORDERS`)
|
|
136
|
+
_PARAMETERS = {
|
|
137
|
+
"neo_hookean": ({"mu"}, set()),
|
|
138
|
+
"mooney_rivlin": (set(), {"c10", "c01"}),
|
|
139
|
+
"polynomial": (set(), set()),
|
|
140
|
+
"yeoh": ({"c10", "c20", "c30"}, {"c10"}),
|
|
141
|
+
"arruda_boyce": ({"mu", "lock"}, {"lock"}),
|
|
142
|
+
"eight_chain": ({"mu", "lock"}, {"lock"}),
|
|
143
|
+
"gent": ({"mu", "lock"}, {"lock"}),
|
|
144
|
+
"van_der_waals": ({"mu", "lock", "a", "beta"}, {"lock"}),
|
|
145
|
+
"fung": ({"mu", "b"}, {"b"}),
|
|
146
|
+
"ogden": ({"terms"}, {"terms"}),
|
|
147
|
+
"holzapfel": ({"mu", "k1", "k2", "kappa", "fibres"}, {"k1", "k2", "fibres"}),
|
|
148
|
+
"blatz_ko": ({"mu", "f"}, set()),
|
|
149
|
+
"hyperfoam": ({"terms"}, {"terms"}),
|
|
150
|
+
"saint_venant_kirchhoff": (set(), set()),
|
|
151
|
+
}
|
|
152
|
+
#: The largest order ``i + j`` of the coefficients ``cij`` of the polynomials of Rivlin
|
|
153
|
+
_ORDERS = {"mooney_rivlin": 3, "polynomial": 6}
|
|
154
|
+
#: The models whose isochoric energy is a polynomial of the invariants
|
|
155
|
+
_POLYNOMIALS = ("mooney_rivlin", "polynomial", "yeoh")
|
|
156
|
+
#: The compressible laws: no split of the energy, their Poisson's ratio from the bulk
|
|
157
|
+
#: modulus
|
|
158
|
+
_COMPRESSIBLE = ("blatz_ko", "hyperfoam")
|
|
159
|
+
#: The homogeneous tests of rubbers (:meth:`_Hyperelastic.nominal_stress`)
|
|
160
|
+
TESTS = ("uniaxial", "equibiaxial", "planar", "shear")
|
|
161
|
+
#: The models that :func:`fit_hyperelasticity` fits to tests of incompressible rubbers
|
|
162
|
+
FITTED = ("neo_hookean", "mooney_rivlin", "polynomial", "yeoh", "arruda_boyce", "eight_chain",
|
|
163
|
+
"gent", "van_der_waals", "fung", "ogden") # fmt: skip
|
|
164
|
+
#: Volumetric energies ``U(J)`` of the hyperelastic laws (``K``: the bulk modulus)
|
|
165
|
+
VOLUMETRIC = ("quadratic", "logarithmic", "simo_miehe")
|
|
166
|
+
#: Equivalent strains of the damage law
|
|
167
|
+
EQUIVALENT_STRAINS = ("energy", "mazars", "mises")
|
|
168
|
+
#: Softening laws of the damage
|
|
169
|
+
SOFTENINGS = ("exponential", "linear")
|
|
170
|
+
#: Splits of the stress of a damaged point: all of it degraded, the bulk response in
|
|
171
|
+
#: compression kept (Amor, Marigo & Maurini 2009), or that of the negative principal
|
|
172
|
+
#: strains (Miehe, Hofacker & Welschinger 2010)
|
|
173
|
+
SPLITS = ("none", "volumetric", "spectral")
|
|
174
|
+
#: The laws of the damage coupled to plasticity (:class:`DuctileDamage`)
|
|
175
|
+
DUCTILE_LAWS = ("lemaitre", "kachanov")
|
|
176
|
+
|
|
177
|
+
_M = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
|
|
178
|
+
#: Tensor components of the engineering strains
|
|
179
|
+
_HALF = np.array([1.0, 1.0, 1.0, 0.5, 0.5, 0.5])
|
|
180
|
+
_PAIRS = ((0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (0, 1))
|
|
181
|
+
_I0 = np.array([i for i, _ in _PAIRS])
|
|
182
|
+
_I1 = np.array([j for _, j in _PAIRS])
|
|
183
|
+
#: The Voigt matrices of I (x) I - I_sym and of the deviatoric projector (stresses of
|
|
184
|
+
#: engineering strains)
|
|
185
|
+
_A2 = np.outer(_M, _M) - np.diag(_HALF)
|
|
186
|
+
#: Points integrated at once (the memory of the arrays of a step)
|
|
187
|
+
_CHUNK = 1 << 15
|
|
188
|
+
#: Coefficients of the series of Arruda and Boyce
|
|
189
|
+
_ARRUDA = (0.5, 1.0 / 20.0, 11.0 / 1050.0, 19.0 / 7000.0, 519.0 / 673750.0)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _phi(x):
|
|
193
|
+
"""``(1 - exp(-x)) / x`` (1 at 0)."""
|
|
194
|
+
x = np.asarray(x, dtype=float)
|
|
195
|
+
small = np.abs(x) < 1e-6
|
|
196
|
+
safe = np.where(small, 1.0, x)
|
|
197
|
+
return np.where(small, 1.0 - 0.5 * x + x * x / 6.0, -np.expm1(-safe) / safe)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _pairs(value, name: str, first: str, second: str) -> tuple[tuple[float, float], ...]:
|
|
201
|
+
"""Terms given as pairs, mappings ``{first: .., second: ..}`` or a list of them."""
|
|
202
|
+
if value is None:
|
|
203
|
+
return ()
|
|
204
|
+
items = [value] if isinstance(value, dict) else list(value)
|
|
205
|
+
if items and not isinstance(items[0], (dict, list, tuple)):
|
|
206
|
+
items = [items]
|
|
207
|
+
out = []
|
|
208
|
+
for item in items:
|
|
209
|
+
if isinstance(item, dict):
|
|
210
|
+
if set(item) != {first, second}:
|
|
211
|
+
raise ValueError(f"{name}: each term gives {first} and {second}")
|
|
212
|
+
item = (item[first], item[second])
|
|
213
|
+
if len(item) != 2:
|
|
214
|
+
raise ValueError(f"{name}: each term is a pair ({first}, {second})")
|
|
215
|
+
a, b = float(item[0]), float(item[1])
|
|
216
|
+
if not (math.isfinite(a) and math.isfinite(b)):
|
|
217
|
+
raise ValueError(f"{name}: finite terms")
|
|
218
|
+
out.append((a, b))
|
|
219
|
+
return tuple(out)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# -- viscoelasticity -----------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@dataclass(frozen=True)
|
|
226
|
+
class Viscoelasticity:
|
|
227
|
+
"""A generalized Maxwell model (see the module): ``shear`` and ``bulk``, the terms
|
|
228
|
+
``(g_i, tau_i)`` and ``(k_j, tau_j)`` of the Prony series of the shear and bulk
|
|
229
|
+
relaxation moduli, relative to the instantaneous moduli of the material (each sum
|
|
230
|
+
below 1; no ``bulk`` term: an elastic bulk response). ``wlf``: the constants ``(C1,
|
|
231
|
+
C2)`` of Williams, Landel and Ferry, ``log10 a_T = -C1 dT / (C2 + dT)`` for the change
|
|
232
|
+
of temperature ``dT`` of the loading paths from their reference state; or
|
|
233
|
+
``arrhenius``: the activation energy over the gas constant (K), ``ln a_T = arrhenius
|
|
234
|
+
(1 / T - 1 / T_ref)`` with ``reference_temperature`` (K) that of the reference state."""
|
|
235
|
+
|
|
236
|
+
shear: tuple = ()
|
|
237
|
+
bulk: tuple = ()
|
|
238
|
+
wlf: tuple | None = None
|
|
239
|
+
arrhenius: float | None = None
|
|
240
|
+
reference_temperature: float = 293.15
|
|
241
|
+
|
|
242
|
+
def __post_init__(self) -> None:
|
|
243
|
+
for name, weight in (("shear", "g"), ("bulk", "k")):
|
|
244
|
+
terms = _pairs(getattr(self, name), f"viscoelasticity.{name}", weight, "tau")
|
|
245
|
+
if any(not (w > 0 and tau > 0) for w, tau in terms):
|
|
246
|
+
raise ValueError(f"viscoelasticity.{name}: positive weights and times")
|
|
247
|
+
if sum(w for w, _ in terms) >= 1.0:
|
|
248
|
+
raise ValueError(
|
|
249
|
+
f"viscoelasticity.{name}: the weights of the terms sum to less than 1 "
|
|
250
|
+
"(a solid: its long-term modulus is positive)"
|
|
251
|
+
)
|
|
252
|
+
object.__setattr__(self, name, terms)
|
|
253
|
+
if not self.shear and not self.bulk:
|
|
254
|
+
raise ValueError("viscoelasticity: at least one term (shear or bulk)")
|
|
255
|
+
if self.wlf is not None:
|
|
256
|
+
wlf = tuple(float(v) for v in self.wlf)
|
|
257
|
+
if len(wlf) != 2 or not wlf[1] > 0:
|
|
258
|
+
raise ValueError("viscoelasticity.wlf: the constants (C1, C2), C2 positive")
|
|
259
|
+
object.__setattr__(self, "wlf", wlf)
|
|
260
|
+
if self.arrhenius is not None:
|
|
261
|
+
raise ValueError("viscoelasticity: wlf or arrhenius, not both")
|
|
262
|
+
if self.arrhenius is not None:
|
|
263
|
+
object.__setattr__(self, "arrhenius", float(self.arrhenius))
|
|
264
|
+
t = float(self.reference_temperature)
|
|
265
|
+
if not t > 0:
|
|
266
|
+
raise ValueError("viscoelasticity.reference_temperature: an absolute temperature")
|
|
267
|
+
object.__setattr__(self, "reference_temperature", t)
|
|
268
|
+
|
|
269
|
+
@classmethod
|
|
270
|
+
def from_config(cls, spec) -> Viscoelasticity:
|
|
271
|
+
"""A mapping ``shear: [{g: .., tau: ..}, ...]`` (or pairs), ``bulk: [{k: ..,
|
|
272
|
+
tau: ..}]``, ``wlf: [C1, C2]``, ``arrhenius``, ``reference_temperature``."""
|
|
273
|
+
if isinstance(spec, Viscoelasticity):
|
|
274
|
+
return spec
|
|
275
|
+
if not isinstance(spec, dict):
|
|
276
|
+
raise ValueError("viscoelasticity: a mapping (shear, bulk, wlf, arrhenius)")
|
|
277
|
+
names = {"shear", "bulk", "wlf", "arrhenius", "reference_temperature"}
|
|
278
|
+
unknown = sorted(set(spec) - names)
|
|
279
|
+
if unknown:
|
|
280
|
+
raise ValueError(f"viscoelasticity: unknown keys {unknown}; allowed: {sorted(names)}")
|
|
281
|
+
return cls(**spec)
|
|
282
|
+
|
|
283
|
+
def to_config(self) -> dict:
|
|
284
|
+
out: dict = {}
|
|
285
|
+
if self.shear:
|
|
286
|
+
out["shear"] = [{"g": g, "tau": tau} for g, tau in self.shear]
|
|
287
|
+
if self.bulk:
|
|
288
|
+
out["bulk"] = [{"k": k, "tau": tau} for k, tau in self.bulk]
|
|
289
|
+
if self.wlf is not None:
|
|
290
|
+
out["wlf"] = list(self.wlf)
|
|
291
|
+
if self.arrhenius is not None:
|
|
292
|
+
out["arrhenius"] = self.arrhenius
|
|
293
|
+
out["reference_temperature"] = self.reference_temperature
|
|
294
|
+
return out
|
|
295
|
+
|
|
296
|
+
def shift(self, dtemp: float = 0.0) -> float:
|
|
297
|
+
"""The shift factor ``a_T`` of the relaxation times at the change of temperature
|
|
298
|
+
``dtemp`` from the reference state (1 without a shift law)."""
|
|
299
|
+
dtemp = float(dtemp)
|
|
300
|
+
if self.wlf is not None:
|
|
301
|
+
c1, c2 = self.wlf
|
|
302
|
+
if c2 + dtemp <= 0:
|
|
303
|
+
raise ValueError("viscoelasticity.wlf: C2 + dT must stay positive")
|
|
304
|
+
return float(10.0 ** (-c1 * dtemp / (c2 + dtemp)))
|
|
305
|
+
if self.arrhenius is not None:
|
|
306
|
+
t0 = self.reference_temperature
|
|
307
|
+
return float(math.exp(self.arrhenius * (1.0 / (t0 + dtemp) - 1.0 / t0)))
|
|
308
|
+
return 1.0
|
|
309
|
+
|
|
310
|
+
def long_term(self, bulk: float, shear: float) -> tuple[float, float]:
|
|
311
|
+
"""The relaxed bulk and shear moduli of instantaneous moduli ``bulk``, ``shear``."""
|
|
312
|
+
return (
|
|
313
|
+
bulk * (1.0 - sum(k for k, _ in self.bulk)),
|
|
314
|
+
shear * (1.0 - sum(g for g, _ in self.shear)),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
def relaxation(self, times, bulk: float, shear: float, dtemp: float = 0.0):
|
|
318
|
+
"""The bulk and shear relaxation moduli ``K(t)``, ``G(t)`` at ``times``."""
|
|
319
|
+
t = np.asarray(times, dtype=float) / self.shift(dtemp)
|
|
320
|
+
k = bulk * (1.0 - sum(w * -np.expm1(-t / tau) for w, tau in self.bulk))
|
|
321
|
+
g = shear * (1.0 - sum(w * -np.expm1(-t / tau) for w, tau in self.shear))
|
|
322
|
+
return k + 0.0 * t, g + 0.0 * t
|
|
323
|
+
|
|
324
|
+
def complex_moduli(self, omega, bulk: float, shear: float, dtemp: float = 0.0):
|
|
325
|
+
"""The complex bulk and shear moduli ``K*``, ``G*`` at the angular frequencies
|
|
326
|
+
``omega`` (rad per unit time): ``G* = G0 (1 - sum_i g_i / (1 + i omega tau_i))``,
|
|
327
|
+
their real parts the storage moduli, their imaginary parts the loss moduli."""
|
|
328
|
+
w = np.asarray(omega, dtype=float) * self.shift(dtemp)
|
|
329
|
+
k = bulk * (1.0 - sum(c / (1.0 + 1j * w * tau) for c, tau in self.bulk))
|
|
330
|
+
g = shear * (1.0 - sum(c / (1.0 + 1j * w * tau) for c, tau in self.shear))
|
|
331
|
+
return k + 0j * w, g + 0j * w
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class _Maxwell:
|
|
335
|
+
"""The integration of a :class:`Viscoelasticity` in small strains (the law of the
|
|
336
|
+
module); without branches, isotropic elasticity."""
|
|
337
|
+
|
|
338
|
+
kind = "viscoelastic"
|
|
339
|
+
symmetric = True
|
|
340
|
+
thermal = True
|
|
341
|
+
|
|
342
|
+
def __init__(self, visco: Viscoelasticity | None, bulk: float, shear: float):
|
|
343
|
+
self.visco = visco
|
|
344
|
+
self.bulk, self.shear = float(bulk), float(shear)
|
|
345
|
+
self.g_terms = visco.shear if visco is not None else ()
|
|
346
|
+
self.k_terms = visco.bulk if visco is not None else ()
|
|
347
|
+
self.n_state = 6 * len(self.g_terms) + len(self.k_terms)
|
|
348
|
+
|
|
349
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
350
|
+
e_new = np.asarray(e_new, dtype=float)
|
|
351
|
+
n = e_new.shape[0]
|
|
352
|
+
a_t = self.visco.shift(dtemp) if self.visco is not None else 1.0
|
|
353
|
+
de = e_new - e_old
|
|
354
|
+
tr, dtr = e_new[:, :3].sum(axis=1), de[:, :3].sum(axis=1)
|
|
355
|
+
dev = (e_new - tr[:, None] / 3.0 * _M) * _HALF
|
|
356
|
+
ddev = (de - dtr[:, None] / 3.0 * _M) * _HALF
|
|
357
|
+
k_inf = self.bulk * (1.0 - sum(k for k, _ in self.k_terms))
|
|
358
|
+
g_inf = self.shear * (1.0 - sum(g for g, _ in self.g_terms))
|
|
359
|
+
h_new = np.empty((n, self.n_state))
|
|
360
|
+
s = 2.0 * g_inf * dev
|
|
361
|
+
g_alg = g_inf
|
|
362
|
+
for i, (g, tau) in enumerate(self.g_terms):
|
|
363
|
+
x = dt / (a_t * tau)
|
|
364
|
+
f = float(_phi(x))
|
|
365
|
+
q = math.exp(-x) * h_old[:, 6 * i : 6 * i + 6] + (2.0 * self.shear * g * f) * ddev
|
|
366
|
+
h_new[:, 6 * i : 6 * i + 6] = q
|
|
367
|
+
s = s + q
|
|
368
|
+
g_alg += self.shear * g * f
|
|
369
|
+
p = k_inf * tr
|
|
370
|
+
k_alg = k_inf
|
|
371
|
+
at = 6 * len(self.g_terms)
|
|
372
|
+
for j, (k, tau) in enumerate(self.k_terms):
|
|
373
|
+
x = dt / (a_t * tau)
|
|
374
|
+
f = float(_phi(x))
|
|
375
|
+
r = math.exp(-x) * h_old[:, at + j] + (self.bulk * k * f) * dtr
|
|
376
|
+
h_new[:, at + j] = r
|
|
377
|
+
p = p + r
|
|
378
|
+
k_alg += self.bulk * k * f
|
|
379
|
+
stress = s + p[:, None] * _M
|
|
380
|
+
tangent = np.broadcast_to(isotropic_matrix(k_alg - 2.0 * g_alg / 3.0, g_alg), (n, 6, 6))
|
|
381
|
+
return stress, tangent, h_new
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
# -- hyperelasticity -----------------------------------------------------------------------
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
@dataclass(frozen=True)
|
|
388
|
+
class Hyperelasticity:
|
|
389
|
+
"""A hyperelastic law (see the module): ``model`` (:data:`HYPERELASTIC_MODELS`) and
|
|
390
|
+
its ``parameters`` — ``mu`` (neo-Hookean, Arruda-Boyce, eight chains, Gent, van der
|
|
391
|
+
Waals, Fung, Holzapfel, Blatz-Ko), the coefficients ``cij`` of the polynomial of
|
|
392
|
+
Rivlin (``c10`` and ``c01`` of Mooney and Rivlin, with ``c11``, ``c20``, ``c02`` and
|
|
393
|
+
the terms of the third order for their forms of five and nine parameters; ``c10``,
|
|
394
|
+
``c20``, ``c30`` of Yeoh; any ``cij`` up to the sixth order for ``polynomial``),
|
|
395
|
+
``lock`` (the locking stretch of Arruda and Boyce, of the eight chains and of van der
|
|
396
|
+
Waals; ``Jm`` of Gent), ``a`` and ``beta`` (van der Waals: the interaction of the
|
|
397
|
+
chains, the share of the second invariant), ``b`` (Fung: the rate of the exponential),
|
|
398
|
+
``terms`` (Ogden and the hyperfoam: the pairs ``(mu_p, alpha_p)``; the shear modulus
|
|
399
|
+
is ``sum_p mu_p alpha_p / 2`` for Ogden, ``sum_p mu_p`` for the hyperfoam), ``k1``,
|
|
400
|
+
``k2``, ``kappa`` and ``fibres`` (Holzapfel: the stiffness and the rate of the
|
|
401
|
+
families of fibres, their dispersion, their directions in the axes of the sample),
|
|
402
|
+
``f`` (Blatz-Ko: the share of the first invariant) — ``bulk``, the bulk modulus of
|
|
403
|
+
the volumetric energy, and ``volumetric`` (:data:`VOLUMETRIC`: ``K/2 (J - 1)^2``,
|
|
404
|
+
``K/2 (ln J)^2`` or ``K/4 (J^2 - 1 - 2 ln J)``; the compressible laws, Blatz-Ko and
|
|
405
|
+
the hyperfoam, take their Poisson's ratio from the bulk modulus). ``mullins``: the
|
|
406
|
+
softening of Ogden and Roxburgh, ``(r, m, beta)``. The shear and bulk moduli not
|
|
407
|
+
given are those of the material (``young``, ``poisson``); given, they must agree
|
|
408
|
+
with them (:meth:`initial_moduli`), or the material takes those of the law."""
|
|
409
|
+
|
|
410
|
+
model: str = "neo_hookean"
|
|
411
|
+
parameters: tuple = ()
|
|
412
|
+
bulk: float | None = None
|
|
413
|
+
volumetric: str = "quadratic"
|
|
414
|
+
mullins: tuple | None = None
|
|
415
|
+
|
|
416
|
+
def __post_init__(self) -> None:
|
|
417
|
+
if self.model not in HYPERELASTIC_MODELS:
|
|
418
|
+
raise ValueError(
|
|
419
|
+
f"hyperelasticity.model: one of {tuple(HYPERELASTIC_MODELS)}, got {self.model!r}"
|
|
420
|
+
)
|
|
421
|
+
if self.volumetric not in VOLUMETRIC:
|
|
422
|
+
raise ValueError(f"hyperelasticity.volumetric: one of {VOLUMETRIC}")
|
|
423
|
+
params = dict(self.parameters)
|
|
424
|
+
allowed, required = _PARAMETERS[self.model]
|
|
425
|
+
order = _ORDERS.get(self.model)
|
|
426
|
+
unknown = sorted(
|
|
427
|
+
name
|
|
428
|
+
for name in params
|
|
429
|
+
if name not in allowed and not (order and 1 <= sum(_powers(name) or (9,)) <= order)
|
|
430
|
+
)
|
|
431
|
+
if unknown:
|
|
432
|
+
names = sorted(allowed) + ([f"cij (i + j <= {order})"] if order else [])
|
|
433
|
+
raise ValueError(
|
|
434
|
+
f"hyperelasticity ({self.model}): unknown parameters {unknown}; allowed: {names}"
|
|
435
|
+
)
|
|
436
|
+
missing = sorted(required - set(params))
|
|
437
|
+
if missing:
|
|
438
|
+
raise ValueError(f"hyperelasticity ({self.model}): give {missing}")
|
|
439
|
+
if order and not params:
|
|
440
|
+
raise ValueError(f"hyperelasticity ({self.model}): give its coefficients cij")
|
|
441
|
+
if "terms" in params:
|
|
442
|
+
terms = _pairs(params["terms"], "hyperelasticity.terms", "mu", "alpha")
|
|
443
|
+
if not terms or any(a == 0.0 for _, a in terms):
|
|
444
|
+
raise ValueError("hyperelasticity.terms: pairs (mu_p, alpha_p), alpha_p not zero")
|
|
445
|
+
params["terms"] = terms
|
|
446
|
+
if "fibres" in params:
|
|
447
|
+
params["fibres"] = _directions(params["fibres"])
|
|
448
|
+
for name, value in params.items():
|
|
449
|
+
if name not in ("terms", "fibres"):
|
|
450
|
+
params[name] = float(value)
|
|
451
|
+
if not math.isfinite(params[name]):
|
|
452
|
+
raise ValueError(f"hyperelasticity.{name}: a finite value")
|
|
453
|
+
if params.get("lock", 1.0) <= 0:
|
|
454
|
+
raise ValueError("hyperelasticity.lock: positive")
|
|
455
|
+
if self.model == "van_der_waals":
|
|
456
|
+
if params["lock"] ** 2 <= 3.0:
|
|
457
|
+
raise ValueError("hyperelasticity.lock (van der Waals): above the square root of 3")
|
|
458
|
+
if not 0.0 <= params.get("beta", 0.0) <= 1.0 or params.get("a", 0.0) < 0:
|
|
459
|
+
raise ValueError(
|
|
460
|
+
"hyperelasticity (van der Waals): beta from 0 to 1, a not negative"
|
|
461
|
+
)
|
|
462
|
+
if self.model == "eight_chain" and params["lock"] <= 1.0:
|
|
463
|
+
raise ValueError("hyperelasticity.lock (eight chains): above 1")
|
|
464
|
+
if self.model == "fung" and not params["b"] > 0:
|
|
465
|
+
raise ValueError("hyperelasticity.b: positive")
|
|
466
|
+
if self.model == "holzapfel":
|
|
467
|
+
if params["k1"] < 0 or not params["k2"] > 0:
|
|
468
|
+
raise ValueError("hyperelasticity (Holzapfel): k1 not negative, k2 positive")
|
|
469
|
+
if not 0.0 <= params.get("kappa", 0.0) <= 1.0 / 3.0:
|
|
470
|
+
raise ValueError(
|
|
471
|
+
"hyperelasticity.kappa: from 0 (aligned fibres) to 1/3 (isotropic)"
|
|
472
|
+
)
|
|
473
|
+
if self.model == "blatz_ko" and not 0.0 <= params.get("f", 0.0) <= 1.0:
|
|
474
|
+
raise ValueError("hyperelasticity.f: from 0 to 1")
|
|
475
|
+
object.__setattr__(self, "parameters", tuple(sorted(params.items())))
|
|
476
|
+
if self.bulk is not None:
|
|
477
|
+
if not (math.isfinite(self.bulk) and self.bulk > 0):
|
|
478
|
+
raise ValueError("hyperelasticity.bulk: a positive bulk modulus")
|
|
479
|
+
object.__setattr__(self, "bulk", float(self.bulk))
|
|
480
|
+
if self.model in _COMPRESSIBLE and self.volumetric != "quadratic":
|
|
481
|
+
raise ValueError(
|
|
482
|
+
f"hyperelasticity ({self.model}): a compressible law, without a volumetric "
|
|
483
|
+
"energy of its own to choose"
|
|
484
|
+
)
|
|
485
|
+
if self.mullins is not None:
|
|
486
|
+
try:
|
|
487
|
+
r, m, beta = (float(v) for v in self.mullins)
|
|
488
|
+
except (TypeError, ValueError):
|
|
489
|
+
raise ValueError("hyperelasticity.mullins: three numbers (r, m, beta)") from None
|
|
490
|
+
if not (r > 1.0 and m >= 0.0 and beta >= 0.0 and m + beta > 0.0):
|
|
491
|
+
raise ValueError(
|
|
492
|
+
"hyperelasticity.mullins: r above 1, m and beta not negative and not both zero"
|
|
493
|
+
)
|
|
494
|
+
if self.model == "saint_venant_kirchhoff":
|
|
495
|
+
raise ValueError("hyperelasticity.mullins: not for Saint-Venant and Kirchhoff")
|
|
496
|
+
object.__setattr__(self, "mullins", (r, m, beta))
|
|
497
|
+
|
|
498
|
+
@classmethod
|
|
499
|
+
def from_config(cls, spec) -> Hyperelasticity:
|
|
500
|
+
"""The name of a model, or a mapping ``model`` with its parameters (``mu``,
|
|
501
|
+
``c10``..., ``terms``, ``fibres``), ``bulk``, ``volumetric`` and ``mullins``."""
|
|
502
|
+
if isinstance(spec, Hyperelasticity):
|
|
503
|
+
return spec
|
|
504
|
+
if isinstance(spec, str):
|
|
505
|
+
return cls(spec)
|
|
506
|
+
if not isinstance(spec, dict):
|
|
507
|
+
raise ValueError("hyperelasticity: the name of a model, or a mapping")
|
|
508
|
+
spec = dict(spec)
|
|
509
|
+
model = spec.pop("model", "neo_hookean")
|
|
510
|
+
bulk = spec.pop("bulk", None)
|
|
511
|
+
volumetric = spec.pop("volumetric", "quadratic")
|
|
512
|
+
mullins = spec.pop("mullins", None)
|
|
513
|
+
return cls(model, tuple(spec.items()), bulk, volumetric, mullins)
|
|
514
|
+
|
|
515
|
+
def to_config(self) -> dict:
|
|
516
|
+
out: dict = {"model": self.model}
|
|
517
|
+
for name, value in self.parameters:
|
|
518
|
+
out[name] = [list(t) for t in value] if name in ("terms", "fibres") else value
|
|
519
|
+
if self.bulk is not None:
|
|
520
|
+
out["bulk"] = self.bulk
|
|
521
|
+
if self.volumetric != "quadratic":
|
|
522
|
+
out["volumetric"] = self.volumetric
|
|
523
|
+
if self.mullins is not None:
|
|
524
|
+
out["mullins"] = list(self.mullins)
|
|
525
|
+
return out
|
|
526
|
+
|
|
527
|
+
def initial_moduli(self) -> tuple[float | None, float | None]:
|
|
528
|
+
"""The bulk and shear moduli of the law at the natural state (None for those it
|
|
529
|
+
takes from the material)."""
|
|
530
|
+
p = dict(self.parameters)
|
|
531
|
+
shear = None
|
|
532
|
+
if self.model in _POLYNOMIALS:
|
|
533
|
+
shear = 2.0 * (p.get("c10", 0.0) + p.get("c01", 0.0))
|
|
534
|
+
elif self.model == "ogden":
|
|
535
|
+
shear = 0.5 * sum(m * a for m, a in p["terms"])
|
|
536
|
+
elif self.model == "hyperfoam":
|
|
537
|
+
shear = sum(m for m, _ in p["terms"])
|
|
538
|
+
elif self.model == "arruda_boyce" and "mu" in p:
|
|
539
|
+
shear = p["mu"] * _arruda_factor(p["lock"])
|
|
540
|
+
elif self.model == "eight_chain" and "mu" in p:
|
|
541
|
+
shear = p["mu"] * _chain_factor(p["lock"])
|
|
542
|
+
elif "mu" in p:
|
|
543
|
+
shear = p["mu"]
|
|
544
|
+
if shear is not None and not shear > 0:
|
|
545
|
+
raise ValueError("hyperelasticity: the shear modulus at the natural state is positive")
|
|
546
|
+
return self.bulk, shear
|
|
547
|
+
|
|
548
|
+
def law(self, bulk: float | None = None, shear: float | None = None):
|
|
549
|
+
"""The law of these parameters on its own (stresses, tangents, energies, the
|
|
550
|
+
responses to the tests of rubbers: :meth:`_Hyperelastic.nominal_stress`), with
|
|
551
|
+
the ``bulk`` and ``shear`` moduli that it does not give."""
|
|
552
|
+
own_bulk, own_shear = self.initial_moduli()
|
|
553
|
+
bulk = own_bulk if own_bulk is not None else bulk
|
|
554
|
+
shear = own_shear if own_shear is not None else shear
|
|
555
|
+
if bulk is None or shear is None:
|
|
556
|
+
raise ValueError("hyperelasticity: give the bulk and shear moduli that the law has not")
|
|
557
|
+
return _Hyperelastic(self, float(bulk), float(shear), bulk - 2.0 * shear / 3.0)
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _powers(name: str) -> tuple[int, int] | None:
|
|
561
|
+
"""The powers ``(i, j)`` of a coefficient ``cij`` of the polynomial of Rivlin."""
|
|
562
|
+
if len(name) == 3 and name[0] == "c" and name[1:].isdigit():
|
|
563
|
+
return int(name[1]), int(name[2])
|
|
564
|
+
return None
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def _directions(value) -> tuple[tuple[float, float, float], ...]:
|
|
568
|
+
"""The unit directions of families of fibres: one vector, or several."""
|
|
569
|
+
try:
|
|
570
|
+
array = np.asarray(value, dtype=float).reshape(-1, 3)
|
|
571
|
+
except (TypeError, ValueError):
|
|
572
|
+
raise ValueError("hyperelasticity.fibres: directions [x, y, z], one per family") from None
|
|
573
|
+
norms = np.linalg.norm(array, axis=1)
|
|
574
|
+
if not len(array) or not np.all(np.isfinite(array)) or np.any(norms == 0.0):
|
|
575
|
+
raise ValueError("hyperelasticity.fibres: directions [x, y, z], one per family")
|
|
576
|
+
return tuple(tuple(float(v) for v in row) for row in array / norms[:, None])
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def _arruda_factor(lock: float) -> float:
|
|
580
|
+
"""The initial shear modulus of the series of Arruda and Boyce over its ``mu``."""
|
|
581
|
+
return sum(2.0 * i * a * 3.0 ** (i - 1) / lock ** (2 * i - 2)
|
|
582
|
+
for i, a in enumerate(_ARRUDA, start=1)) # fmt: skip
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
def _chain_factor(lock: float) -> float:
|
|
586
|
+
"""The initial shear modulus of the eight chains (Cohen's approximant of the inverse
|
|
587
|
+
Langevin function) over their ``mu``."""
|
|
588
|
+
x2 = 1.0 / (lock * lock)
|
|
589
|
+
return (3.0 - x2) / (3.0 * (1.0 - x2))
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def _outer(a, b):
|
|
593
|
+
return a[:, :, None] * b[:, None, :]
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def _box(cinv):
|
|
597
|
+
"""The Voigt matrices (n, 6, 6) of ``1/2 (Cinv_ik Cinv_jl + Cinv_il Cinv_jk)``."""
|
|
598
|
+
a = cinv[:, _I0[:, None], _I0[None, :]] * cinv[:, _I1[:, None], _I1[None, :]]
|
|
599
|
+
b = cinv[:, _I0[:, None], _I1[None, :]] * cinv[:, _I1[:, None], _I0[None, :]]
|
|
600
|
+
return 0.5 * (a + b)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def _invariant_law(c6, cinv6, cinv, i1, j, w):
|
|
604
|
+
"""The second Piola-Kirchhoff stresses (n, 6) and their tangents ``dS/dE`` (n, 6, 6)
|
|
605
|
+
of an energy ``w(I1, I2, J)`` whose first and second derivatives are ``w = (w1, w2,
|
|
606
|
+
wj, w11, w12, w1j, w22, w2j, wjj)``: ``S = 2 (w1 A1 + w2 A2 + wj AJ)`` with ``A1 = I``,
|
|
607
|
+
``A2 = I1 I - C``, ``AJ = J/2 C^-1`` and ``dS/dE = 4 [sum_ab w_ab A_a (x) A_b + w2 (I
|
|
608
|
+
(x) I - I_sym) + wj (J/4 C^-1 (x) C^-1 - J/2 C^-1 (.) C^-1)]``."""
|
|
609
|
+
w1, w2, wj, w11, w12, w1j, w22, w2j, wjj = w
|
|
610
|
+
n = len(i1)
|
|
611
|
+
a1 = np.broadcast_to(_M, (n, 6))
|
|
612
|
+
a2 = i1[:, None] * _M - c6
|
|
613
|
+
aj = 0.5 * j[:, None] * cinv6
|
|
614
|
+
s = 2.0 * (w1[:, None] * a1 + w2[:, None] * a2 + wj[:, None] * aj)
|
|
615
|
+
t = w11[:, None, None] * _outer(a1, a1) + w22[:, None, None] * _outer(a2, a2)
|
|
616
|
+
t += wjj[:, None, None] * _outer(aj, aj)
|
|
617
|
+
t += w12[:, None, None] * (_outer(a1, a2) + _outer(a2, a1))
|
|
618
|
+
t += w1j[:, None, None] * (_outer(a1, aj) + _outer(aj, a1))
|
|
619
|
+
t += w2j[:, None, None] * (_outer(a2, aj) + _outer(aj, a2))
|
|
620
|
+
t += w2[:, None, None] * _A2
|
|
621
|
+
t += (wj * j)[:, None, None] * (0.25 * _outer(cinv6, cinv6) - 0.5 * _box(cinv))
|
|
622
|
+
return s, 4.0 * t
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def _spectral(vec, lam2, s_a, d):
|
|
626
|
+
"""The stresses and tangents of an isotropic law in the principal axes ``vec`` of
|
|
627
|
+
``C`` (of eigenvalues ``lam2``): ``S = sum_a S_a N_a (x) N_a`` and ``dS/dE = sum_ab
|
|
628
|
+
D_ab N_aa (x) N_bb + sum_(a<b) 4 G_ab P_ab (x) P_ab`` with ``D_ab = (1/l_b)
|
|
629
|
+
dS_a/dl_b``, ``G_ab = (S_b - S_a) / (l_b^2 - l_a^2)`` (its limit ``(D_bb - D_ab) / 2``
|
|
630
|
+
for equal stretches) and ``P_ab`` the symmetric part of ``N_a (x) N_b``."""
|
|
631
|
+
m = vec[:, _I0, :] * vec[:, _I1, :] # N_a (x) N_a in Voigt components: (n, 6, a)
|
|
632
|
+
s = np.einsum("nka,na->nk", m, s_a)
|
|
633
|
+
t = np.einsum("nia,nab,njb->nij", m, d, m)
|
|
634
|
+
for a, b in ((0, 1), (0, 2), (1, 2)):
|
|
635
|
+
gap = lam2[:, b] - lam2[:, a]
|
|
636
|
+
close = np.abs(gap) < 1e-7 * (lam2[:, a] + lam2[:, b])
|
|
637
|
+
g = np.where(close, 0.5 * (d[:, b, b] - d[:, a, b]),
|
|
638
|
+
(s_a[:, b] - s_a[:, a]) / np.where(close, 1.0, gap)) # fmt: skip
|
|
639
|
+
pab = 0.5 * (vec[:, _I0, a] * vec[:, _I1, b] + vec[:, _I0, b] * vec[:, _I1, a])
|
|
640
|
+
t += (4.0 * g)[:, None, None] * _outer(pab, pab)
|
|
641
|
+
return s, t
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
class _Hyperelastic:
|
|
645
|
+
"""The integration of a :class:`Hyperelasticity` (a law of the Green-Lagrange strain:
|
|
646
|
+
the second Piola-Kirchhoff stress and ``dS/dE``), with the branches of a
|
|
647
|
+
:class:`Viscoelasticity` on its isochoric and volumetric stresses (Simo 1987), or the
|
|
648
|
+
softening of Mullins on its isochoric stress (Ogden & Roxburgh 1999). State of a
|
|
649
|
+
viscoelastic point: the isochoric and volumetric stresses at the start of the step,
|
|
650
|
+
then those of the branches; of a point that softens: the largest isochoric energy
|
|
651
|
+
that it has reached."""
|
|
652
|
+
|
|
653
|
+
kind = "hyperelastic"
|
|
654
|
+
symmetric = True
|
|
655
|
+
thermal = True
|
|
656
|
+
|
|
657
|
+
def __init__(self, hyper: Hyperelasticity, bulk: float, shear: float, lam: float,
|
|
658
|
+
visco: Viscoelasticity | None = None): # fmt: skip
|
|
659
|
+
self.hyper, self.visco = hyper, visco
|
|
660
|
+
self.model = hyper.model
|
|
661
|
+
p = dict(hyper.parameters)
|
|
662
|
+
self.k = float(hyper.bulk if hyper.bulk is not None else bulk)
|
|
663
|
+
self.mu = float(p.get("mu", shear))
|
|
664
|
+
if "mu" not in p: # the shear modulus of the material
|
|
665
|
+
if self.model == "arruda_boyce":
|
|
666
|
+
self.mu = shear / _arruda_factor(p["lock"])
|
|
667
|
+
elif self.model == "eight_chain":
|
|
668
|
+
self.mu = shear / _chain_factor(p["lock"])
|
|
669
|
+
self.lam = float(lam)
|
|
670
|
+
self.shear = float(shear)
|
|
671
|
+
self.p = p
|
|
672
|
+
if self.model in _POLYNOMIALS: # the polynomial of Rivlin: (i, j, cij)
|
|
673
|
+
self.coefficients = tuple((*_powers(name), c) for name, c in p.items() if c != 0.0)
|
|
674
|
+
if self.model in ("blatz_ko", "hyperfoam"):
|
|
675
|
+
# their Poisson's ratio: K = mu (2/3 + 2 beta), beta = nu / (1 - 2 nu)
|
|
676
|
+
first = self.mu if self.model == "blatz_ko" else sum(m for m, _ in p["terms"])
|
|
677
|
+
self.beta = 0.5 * (self.k / first - 2.0 / 3.0)
|
|
678
|
+
if self.beta <= -1.0 / 3.0:
|
|
679
|
+
raise ValueError(f"hyperelasticity ({self.model}): a positive bulk modulus")
|
|
680
|
+
self.structure = ()
|
|
681
|
+
if self.model == "holzapfel":
|
|
682
|
+
kappa = p.get("kappa", 0.0)
|
|
683
|
+
self.structure = tuple(
|
|
684
|
+
(kappa * np.eye(3) + (1.0 - 3.0 * kappa) * np.outer(a, a))[_I0, _I1]
|
|
685
|
+
for a in np.asarray(p["fibres"])
|
|
686
|
+
)
|
|
687
|
+
self.mullins = hyper.mullins
|
|
688
|
+
if self.mullins is not None and visco is not None:
|
|
689
|
+
raise ValueError("hyperelasticity.mullins: not with a viscoelasticity")
|
|
690
|
+
self.g_terms = visco.shear if visco is not None else ()
|
|
691
|
+
self.k_terms = visco.bulk if visco is not None else ()
|
|
692
|
+
self.n_state = 6 * (2 + len(self.g_terms) + len(self.k_terms)) if visco else 0
|
|
693
|
+
if self.mullins is not None:
|
|
694
|
+
self.n_state = 1
|
|
695
|
+
|
|
696
|
+
# -- energies --------------------------------------------------------------------------
|
|
697
|
+
|
|
698
|
+
def _psi(self, i1b, i2b):
|
|
699
|
+
"""The derivatives ``(psi1, psi2, psi11, psi12, psi22)`` of the isochoric energy
|
|
700
|
+
and its value."""
|
|
701
|
+
zero = np.zeros_like(i1b)
|
|
702
|
+
p, x = self.p, i1b - 3.0
|
|
703
|
+
if self.model in ("neo_hookean", "holzapfel"):
|
|
704
|
+
return (zero + 0.5 * self.mu, zero, zero, zero, zero), 0.5 * self.mu * x
|
|
705
|
+
if self.model in _POLYNOMIALS:
|
|
706
|
+
y = i2b - 3.0
|
|
707
|
+
d1, d2, d11, d12, d22, value = (zero.copy() for _ in range(6))
|
|
708
|
+
for i, j, c in self.coefficients:
|
|
709
|
+
xi, yj = x**i, y**j
|
|
710
|
+
value += c * xi * yj
|
|
711
|
+
if i >= 1:
|
|
712
|
+
d1 += c * i * x ** (i - 1) * yj
|
|
713
|
+
if j >= 1:
|
|
714
|
+
d2 += c * j * xi * y ** (j - 1)
|
|
715
|
+
if i >= 2:
|
|
716
|
+
d11 += c * i * (i - 1) * x ** (i - 2) * yj
|
|
717
|
+
if i >= 1 and j >= 1:
|
|
718
|
+
d12 += c * i * j * x ** (i - 1) * y ** (j - 1)
|
|
719
|
+
if j >= 2:
|
|
720
|
+
d22 += c * j * (j - 1) * xi * y ** (j - 2)
|
|
721
|
+
return (d1, d2, d11, d12, d22), value
|
|
722
|
+
if self.model == "arruda_boyce":
|
|
723
|
+
lock = p["lock"]
|
|
724
|
+
d1, d11, value = zero.copy(), zero.copy(), zero.copy()
|
|
725
|
+
for i, a in enumerate(_ARRUDA, start=1):
|
|
726
|
+
c = self.mu * a / lock ** (2 * i - 2)
|
|
727
|
+
value += c * (i1b**i - 3.0**i)
|
|
728
|
+
d1 += c * i * i1b ** (i - 1)
|
|
729
|
+
if i > 1:
|
|
730
|
+
d11 += c * i * (i - 1) * i1b ** (i - 2)
|
|
731
|
+
return (d1, zero, d11, zero, zero), value
|
|
732
|
+
if self.model == "eight_chain":
|
|
733
|
+
# Cohen's approximant x (3 - x^2) / (1 - x^2) of the inverse Langevin function
|
|
734
|
+
# of the stretch of the chains over their locking stretch
|
|
735
|
+
scale = 3.0 * p["lock"] ** 2
|
|
736
|
+
u = i1b / scale
|
|
737
|
+
u = np.where(u < 1.0, u, np.nan) # beyond the locking: a failed point
|
|
738
|
+
u0 = 3.0 / scale
|
|
739
|
+
d1 = self.mu / 6.0 * (3.0 - u) / (1.0 - u)
|
|
740
|
+
d11 = self.mu / 6.0 * 2.0 / ((1.0 - u) ** 2 * scale)
|
|
741
|
+
value = self.mu * scale / 6.0 * (u - u0 - 2.0 * np.log((1.0 - u) / (1.0 - u0)))
|
|
742
|
+
return (d1, zero, d11, zero, zero), value
|
|
743
|
+
if self.model == "van_der_waals":
|
|
744
|
+
span = p["lock"] ** 2 - 3.0
|
|
745
|
+
a, beta = p.get("a", 0.0), p.get("beta", 0.0)
|
|
746
|
+
# the mixture of the invariants from 3 (its square root is not differentiable
|
|
747
|
+
# at the natural state, where the limits of the terms are those of this floor)
|
|
748
|
+
mix = np.maximum((1.0 - beta) * i1b + beta * i2b - 3.0, 1e-12)
|
|
749
|
+
eta = np.sqrt(mix / span)
|
|
750
|
+
eta = np.where(eta < 1.0, eta, np.nan) # beyond the locking: a failed point
|
|
751
|
+
root = np.sqrt(0.5 * mix)
|
|
752
|
+
rest = (1.0 - beta) * i1b + beta * i2b - 3.0 <= 1e-12 # the natural state
|
|
753
|
+
d = np.where(rest, 0.5 * self.mu, self.mu * (0.5 / (1.0 - eta) - 0.5 * a * root))
|
|
754
|
+
dd = self.mu * (0.25 / (span * eta * (1.0 - eta) ** 2) - 0.125 * a / root)
|
|
755
|
+
dd = np.where(rest, 0.0, dd)
|
|
756
|
+
value = self.mu * (-span * (np.log1p(-eta) + eta) - (2.0 / 3.0) * a * root**3)
|
|
757
|
+
return (
|
|
758
|
+
(1.0 - beta) * d,
|
|
759
|
+
beta * d,
|
|
760
|
+
(1.0 - beta) ** 2 * dd,
|
|
761
|
+
(1.0 - beta) * beta * dd,
|
|
762
|
+
beta * beta * dd,
|
|
763
|
+
), value
|
|
764
|
+
if self.model == "fung":
|
|
765
|
+
ex = np.exp(p["b"] * x)
|
|
766
|
+
return (
|
|
767
|
+
0.5 * self.mu * ex,
|
|
768
|
+
zero,
|
|
769
|
+
0.5 * self.mu * p["b"] * ex,
|
|
770
|
+
zero,
|
|
771
|
+
zero,
|
|
772
|
+
), 0.5 * self.mu / p["b"] * (ex - 1.0)
|
|
773
|
+
jm = p["lock"] # Gent
|
|
774
|
+
rest = jm - x
|
|
775
|
+
rest = np.where(rest > 0, rest, np.nan) # beyond the locking: a failed point
|
|
776
|
+
d1 = 0.5 * self.mu * jm / rest
|
|
777
|
+
return (d1, zero, d1 / rest, zero, zero), -0.5 * self.mu * jm * np.log(rest / jm)
|
|
778
|
+
|
|
779
|
+
def _volumetric(self, j):
|
|
780
|
+
"""``U'``, ``U''`` and ``U`` of the volumetric energy."""
|
|
781
|
+
k = self.k
|
|
782
|
+
if self.hyper.volumetric == "quadratic":
|
|
783
|
+
return k * (j - 1.0), k + 0.0 * j, 0.5 * k * (j - 1.0) ** 2
|
|
784
|
+
log = np.log(j)
|
|
785
|
+
if self.hyper.volumetric == "logarithmic":
|
|
786
|
+
return k * log / j, k * (1.0 - log) / (j * j), 0.5 * k * log * log
|
|
787
|
+
return (
|
|
788
|
+
0.5 * k * (j - 1.0 / j),
|
|
789
|
+
0.5 * k * (1.0 + 1.0 / (j * j)),
|
|
790
|
+
0.25 * k * (j * j - 1.0 - 2.0 * log),
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
def _blatz_ko(self, i1, i2, j):
|
|
794
|
+
"""The derivatives of the energy of Blatz and Ko with respect to ``(I1, I2, J)``
|
|
795
|
+
(the order of :func:`_invariant_law`) and its value."""
|
|
796
|
+
mu, f, beta = self.mu, self.p.get("f", 0.0), self.beta
|
|
797
|
+
zero = np.zeros_like(j)
|
|
798
|
+
if abs(beta) > 1e-9:
|
|
799
|
+
down, up = j ** (-2.0 * beta), j ** (2.0 * beta)
|
|
800
|
+
vol_down, vol_up = (down - 1.0) / beta, (up - 1.0) / beta
|
|
801
|
+
else: # no lateral contraction: the limits of the powers
|
|
802
|
+
down, up = np.ones_like(j), np.ones_like(j)
|
|
803
|
+
vol_down, vol_up = -2.0 * np.log(j), 2.0 * np.log(j)
|
|
804
|
+
j2 = j * j
|
|
805
|
+
w = (
|
|
806
|
+
zero + 0.5 * mu * f,
|
|
807
|
+
0.5 * mu * (1.0 - f) / j2,
|
|
808
|
+
-mu * f * down / j + mu * (1.0 - f) * (up / j - i2 / (j2 * j)),
|
|
809
|
+
zero,
|
|
810
|
+
zero,
|
|
811
|
+
zero,
|
|
812
|
+
zero,
|
|
813
|
+
-mu * (1.0 - f) / (j2 * j),
|
|
814
|
+
mu * f * (2.0 * beta + 1.0) * down / j2
|
|
815
|
+
+ mu * (1.0 - f) * ((2.0 * beta - 1.0) * up / j2 + 3.0 * i2 / (j2 * j2)),
|
|
816
|
+
)
|
|
817
|
+
value = 0.5 * mu * f * (i1 - 3.0 + vol_down) + 0.5 * mu * (1.0 - f) * (
|
|
818
|
+
i2 / j2 - 3.0 + vol_up
|
|
819
|
+
)
|
|
820
|
+
return w, value
|
|
821
|
+
|
|
822
|
+
def _principal(self, c, j):
|
|
823
|
+
"""The stresses, tangents and energy of the laws of the principal stretches, in
|
|
824
|
+
the principal axes of ``C`` (:func:`_spectral`): the isochoric part of Ogden's
|
|
825
|
+
law, of the stretches ``J^(-1/3) l_a``, or the whole of the hyperfoam, of the
|
|
826
|
+
stretches themselves."""
|
|
827
|
+
n = c.shape[0]
|
|
828
|
+
lam2, vec = np.linalg.eigh(c)
|
|
829
|
+
lam2 = np.maximum(lam2, 1e-300)
|
|
830
|
+
lam = np.sqrt(lam2)
|
|
831
|
+
s_a = np.zeros((n, 3))
|
|
832
|
+
d = np.zeros((n, 3, 3))
|
|
833
|
+
w = np.zeros(n)
|
|
834
|
+
diagonal = [0, 1, 2]
|
|
835
|
+
if self.model == "hyperfoam":
|
|
836
|
+
beta = self.beta
|
|
837
|
+
for mu, alpha in self.p["terms"]:
|
|
838
|
+
pw = lam**alpha
|
|
839
|
+
if abs(beta) > 1e-9:
|
|
840
|
+
jp = j ** (-alpha * beta)
|
|
841
|
+
w += 2.0 * mu / alpha**2 * (pw.sum(axis=1) - 3.0 + (jp - 1.0) / beta)
|
|
842
|
+
else:
|
|
843
|
+
jp = np.ones(n)
|
|
844
|
+
w += 2.0 * mu / alpha**2 * (pw.sum(axis=1) - 3.0 - alpha * np.log(j))
|
|
845
|
+
s_a += 2.0 * mu / alpha * (pw - jp[:, None]) / lam2
|
|
846
|
+
d += (2.0 * mu * beta * jp)[:, None, None] / (lam2[:, :, None] * lam2[:, None, :])
|
|
847
|
+
d[:, diagonal, diagonal] += 2.0 * mu * pw / (lam2 * lam2)
|
|
848
|
+
else:
|
|
849
|
+
lb = lam * (j ** (-1.0 / 3.0))[:, None]
|
|
850
|
+
for mu, alpha in self.p["terms"]:
|
|
851
|
+
pw = lb**alpha
|
|
852
|
+
mean = pw.mean(axis=1, keepdims=True)
|
|
853
|
+
w += mu / alpha * (pw.sum(axis=1) - 3.0)
|
|
854
|
+
s_a += mu * (pw - mean) / lam2
|
|
855
|
+
core = -(pw[:, :, None] + pw[:, None, :]) / 3.0 + mean[:, :, None] / 3.0
|
|
856
|
+
core[:, diagonal, diagonal] += pw
|
|
857
|
+
d += mu * alpha * core / (lam2[:, :, None] * lam2[:, None, :])
|
|
858
|
+
d[:, diagonal, diagonal] -= 2.0 * s_a / lam2
|
|
859
|
+
s, t = _spectral(vec, lam2, s_a, d)
|
|
860
|
+
return s, t, w
|
|
861
|
+
|
|
862
|
+
def _fibres(self, c6, cinv, cinv6, j):
|
|
863
|
+
"""The stresses, tangents and energy of the families of fibres of Holzapfel,
|
|
864
|
+
Gasser and Ogden: ``k1 / (2 k2) (exp(k2 E^2) - 1)`` of the strain ``E = J^(-2/3) C
|
|
865
|
+
: H - 1`` of each family, ``H = kappa I + (1 - 3 kappa) a (x) a`` its structure
|
|
866
|
+
tensor, where it is positive (the fibres carry no compression)."""
|
|
867
|
+
k1, k2 = self.p["k1"], self.p["k2"]
|
|
868
|
+
n = len(j)
|
|
869
|
+
s, t, w = np.zeros((n, 6)), np.zeros((n, 6, 6)), np.zeros(n)
|
|
870
|
+
scale = j ** (-2.0 / 3.0)
|
|
871
|
+
pairs = _outer(cinv6, cinv6)
|
|
872
|
+
box = _box(cinv)
|
|
873
|
+
for h6 in self.structure:
|
|
874
|
+
q = c6 @ (h6 / _HALF) # C : H
|
|
875
|
+
strain = np.maximum(scale * q - 1.0, 0.0)
|
|
876
|
+
ex = np.exp(k2 * strain * strain)
|
|
877
|
+
first = k1 * strain * ex
|
|
878
|
+
second = np.where(strain > 0, k1 * (1.0 + 2.0 * k2 * strain * strain) * ex, 0.0)
|
|
879
|
+
g = scale[:, None] * (h6 - (q / 3.0)[:, None] * cinv6) # dE/dC
|
|
880
|
+
h = np.broadcast_to(h6, (n, 6))
|
|
881
|
+
curvature = (
|
|
882
|
+
-(_outer(h, cinv6) + _outer(cinv6, h)) / 3.0
|
|
883
|
+
+ (q / 9.0)[:, None, None] * pairs
|
|
884
|
+
+ (q / 3.0)[:, None, None] * box
|
|
885
|
+
)
|
|
886
|
+
s += 2.0 * first[:, None] * g
|
|
887
|
+
t += second[:, None, None] * _outer(g, g)
|
|
888
|
+
t += (first * scale)[:, None, None] * curvature
|
|
889
|
+
w += 0.5 * k1 / k2 * (ex - 1.0)
|
|
890
|
+
return s, 4.0 * t, w
|
|
891
|
+
|
|
892
|
+
# -- stresses --------------------------------------------------------------------------
|
|
893
|
+
|
|
894
|
+
def _parts(self, e):
|
|
895
|
+
"""The isochoric and volumetric stresses and tangents of strains ``e`` (n, 6), and
|
|
896
|
+
the energies of both parts (the whole of the compressible laws in the first);
|
|
897
|
+
NaN where ``C`` is not positive definite."""
|
|
898
|
+
n = e.shape[0]
|
|
899
|
+
if self.model == "saint_venant_kirchhoff":
|
|
900
|
+
d = isotropic_matrix(self.lam, self.shear)
|
|
901
|
+
s = e @ d
|
|
902
|
+
zero = np.zeros((n, 6))
|
|
903
|
+
return (
|
|
904
|
+
s,
|
|
905
|
+
np.broadcast_to(d, (n, 6, 6)),
|
|
906
|
+
zero,
|
|
907
|
+
np.zeros((n, 6, 6)),
|
|
908
|
+
(
|
|
909
|
+
0.5 * np.einsum("ni,ni->n", s, e),
|
|
910
|
+
np.zeros(n),
|
|
911
|
+
),
|
|
912
|
+
)
|
|
913
|
+
c = np.empty((n, 3, 3))
|
|
914
|
+
for k, (a, b) in enumerate(_PAIRS):
|
|
915
|
+
c[:, a, b] = c[:, b, a] = e[:, k] * (2.0 if a == b else 1.0)
|
|
916
|
+
c[:, [0, 1, 2], [0, 1, 2]] += 1.0
|
|
917
|
+
det = np.linalg.det(c)
|
|
918
|
+
ok = np.isfinite(det) & (det > 0)
|
|
919
|
+
if not ok.all():
|
|
920
|
+
c = np.where(ok[:, None, None], c, np.eye(3))
|
|
921
|
+
cinv = np.linalg.inv(c)
|
|
922
|
+
j = np.sqrt(np.where(ok, det, 1.0))
|
|
923
|
+
c6, cinv6 = c[:, _I0, _I1], cinv[:, _I0, _I1]
|
|
924
|
+
i1 = c[:, 0, 0] + c[:, 1, 1] + c[:, 2, 2]
|
|
925
|
+
zero = np.zeros(n)
|
|
926
|
+
if self.model in _COMPRESSIBLE: # no split: the whole law in the first part
|
|
927
|
+
if self.model == "blatz_ko":
|
|
928
|
+
i2 = 0.5 * (i1 * i1 - np.einsum("nij,nij->n", c, c))
|
|
929
|
+
derivatives, w = self._blatz_ko(i1, i2, j)
|
|
930
|
+
s_iso, t_iso = _invariant_law(c6, cinv6, cinv, i1, j, derivatives)
|
|
931
|
+
else:
|
|
932
|
+
s_iso, t_iso, w = self._principal(c, j)
|
|
933
|
+
s_vol, t_vol, u = np.zeros((n, 6)), np.zeros((n, 6, 6)), zero
|
|
934
|
+
else:
|
|
935
|
+
du, ddu, u = self._volumetric(j)
|
|
936
|
+
vol = (zero, zero, du, zero, zero, zero, zero, zero, ddu)
|
|
937
|
+
s_vol, t_vol = _invariant_law(c6, cinv6, cinv, i1, j, vol)
|
|
938
|
+
if self.model == "ogden":
|
|
939
|
+
s_iso, t_iso, w = self._principal(c, j)
|
|
940
|
+
else:
|
|
941
|
+
i2 = 0.5 * (i1 * i1 - np.einsum("nij,nij->n", c, c))
|
|
942
|
+
a, b = j ** (-2.0 / 3.0), j ** (-4.0 / 3.0)
|
|
943
|
+
i1b, i2b = a * i1, b * i2
|
|
944
|
+
(p1, p2, p11, p12, p22), w = self._psi(i1b, i2b)
|
|
945
|
+
d1, d2 = -2.0 / 3.0 * i1b / j, -4.0 / 3.0 * i2b / j
|
|
946
|
+
iso = (
|
|
947
|
+
p1 * a,
|
|
948
|
+
p2 * b,
|
|
949
|
+
p1 * d1 + p2 * d2,
|
|
950
|
+
p11 * a * a,
|
|
951
|
+
p12 * a * b,
|
|
952
|
+
a * (p11 * d1 + p12 * d2) - 2.0 / 3.0 * p1 * a / j,
|
|
953
|
+
p22 * b * b,
|
|
954
|
+
b * (p12 * d1 + p22 * d2) - 4.0 / 3.0 * p2 * b / j,
|
|
955
|
+
p11 * d1 * d1 + 2.0 * p12 * d1 * d2 + p22 * d2 * d2
|
|
956
|
+
+ p1 * (10.0 / 9.0) * i1b / (j * j) + p2 * (28.0 / 9.0) * i2b / (j * j),
|
|
957
|
+
) # fmt: skip
|
|
958
|
+
s_iso, t_iso = _invariant_law(c6, cinv6, cinv, i1, j, iso)
|
|
959
|
+
if self.structure:
|
|
960
|
+
s_f, t_f, w_f = self._fibres(c6, cinv, cinv6, j)
|
|
961
|
+
s_iso, t_iso, w = s_iso + s_f, t_iso + t_f, w + w_f
|
|
962
|
+
if not ok.all():
|
|
963
|
+
for array in (s_iso, t_iso, s_vol, t_vol):
|
|
964
|
+
array[~ok] = np.nan
|
|
965
|
+
return s_iso, t_iso, s_vol, t_vol, (w, u)
|
|
966
|
+
|
|
967
|
+
def energy(self, e) -> np.ndarray:
|
|
968
|
+
"""The strain energy per unit reference volume of Green-Lagrange strains ``e``
|
|
969
|
+
(n, 6; engineering shears), that of the law without softening."""
|
|
970
|
+
e = np.atleast_2d(np.asarray(e, dtype=float))
|
|
971
|
+
w, u = self._parts(e)[4]
|
|
972
|
+
return w + u
|
|
973
|
+
|
|
974
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
975
|
+
e_new = np.asarray(e_new, dtype=float)
|
|
976
|
+
n = e_new.shape[0]
|
|
977
|
+
stress, tangent = np.empty((n, 6)), np.empty((n, 6, 6))
|
|
978
|
+
h_new = np.empty((n, self.n_state))
|
|
979
|
+
for lo in range(0, n, _CHUNK):
|
|
980
|
+
sl = slice(lo, min(lo + _CHUNK, n))
|
|
981
|
+
with np.errstate(invalid="ignore", divide="ignore", over="ignore"):
|
|
982
|
+
s_iso, t_iso, s_vol, t_vol, (w, _) = self._parts(e_new[sl])
|
|
983
|
+
if self.mullins is not None:
|
|
984
|
+
# the isochoric stress times eta = 1 - erf((Wm - W) / (m + beta Wm)) / r,
|
|
985
|
+
# Wm the largest isochoric energy reached: 1 while it grows
|
|
986
|
+
r, m, beta = self.mullins
|
|
987
|
+
reached = np.fmax(h_old[sl, 0], w)
|
|
988
|
+
room = m + beta * reached
|
|
989
|
+
x = (reached - w) / np.where(room > 0, room, 1.0)
|
|
990
|
+
eta = 1.0 - erf(x) / r
|
|
991
|
+
slope = np.where(reached > w, 2.0 / (r * math.sqrt(math.pi)) * np.exp(-x * x), 0.0)
|
|
992
|
+
slope = slope / np.where(room > 0, room, 1.0)
|
|
993
|
+
stress[sl] = eta[:, None] * s_iso + s_vol
|
|
994
|
+
tangent[sl] = eta[:, None, None] * t_iso + t_vol
|
|
995
|
+
tangent[sl] += slope[:, None, None] * _outer(s_iso, s_iso)
|
|
996
|
+
h_new[sl, 0] = reached
|
|
997
|
+
continue
|
|
998
|
+
if self.visco is None:
|
|
999
|
+
stress[sl], tangent[sl] = s_iso + s_vol, t_iso + t_vol
|
|
1000
|
+
continue
|
|
1001
|
+
a_t = self.visco.shift(dtemp)
|
|
1002
|
+
old = h_old[sl]
|
|
1003
|
+
new = h_new[sl]
|
|
1004
|
+
new[:, 0:6], new[:, 6:12] = s_iso, s_vol
|
|
1005
|
+
factors = []
|
|
1006
|
+
at = 12
|
|
1007
|
+
for terms, part, start in ((self.g_terms, s_iso, 0), (self.k_terms, s_vol, 6)):
|
|
1008
|
+
weight = 1.0 - sum(c for c, _ in terms)
|
|
1009
|
+
total = weight * part
|
|
1010
|
+
for c, tau in terms:
|
|
1011
|
+
x = dt / (a_t * tau)
|
|
1012
|
+
f = float(_phi(x))
|
|
1013
|
+
q = math.exp(-x) * old[:, at : at + 6] + c * f * (
|
|
1014
|
+
part - old[:, start : start + 6]
|
|
1015
|
+
)
|
|
1016
|
+
new[:, at : at + 6] = q
|
|
1017
|
+
total = total + q
|
|
1018
|
+
weight += c * f
|
|
1019
|
+
at += 6
|
|
1020
|
+
factors.append((total, weight))
|
|
1021
|
+
stress[sl] = factors[0][0] + factors[1][0]
|
|
1022
|
+
tangent[sl] = factors[0][1] * t_iso + factors[1][1] * t_vol
|
|
1023
|
+
return stress, tangent, h_new
|
|
1024
|
+
|
|
1025
|
+
# -- the tests of rubbers ----------------------------------------------------------------
|
|
1026
|
+
|
|
1027
|
+
def nominal_stress(self, mode: str, stretch, *, incompressible: bool = False) -> np.ndarray:
|
|
1028
|
+
"""The nominal stress of a homogeneous test (:data:`TESTS`) at the stretches
|
|
1029
|
+
``stretch`` (``shear``: the amounts of shear): the force over the initial section
|
|
1030
|
+
along the stretch of ``uniaxial`` tension (the two other stresses zero), of
|
|
1031
|
+
``equibiaxial`` tension (two equal stretches, the stress across them zero) and of
|
|
1032
|
+
``planar`` tension (the width held: pure shear), and the shear stress of a simple
|
|
1033
|
+
``shear``. The lateral stretches are those that cancel the lateral stresses of
|
|
1034
|
+
the law with its bulk modulus (Newton's iterations on its tangent); for an
|
|
1035
|
+
``incompressible`` solid, the closed forms of the isochoric energy (the laws of
|
|
1036
|
+
the invariants and of Ogden; isotropic laws only: the fibres of Holzapfel have
|
|
1037
|
+
their directions)."""
|
|
1038
|
+
if mode not in TESTS:
|
|
1039
|
+
raise ValueError(f"mode: one of {TESTS}")
|
|
1040
|
+
if self.structure:
|
|
1041
|
+
raise ValueError("nominal_stress: isotropic laws (the fibres have directions)")
|
|
1042
|
+
lam = np.atleast_1d(np.asarray(stretch, dtype=float))
|
|
1043
|
+
if incompressible:
|
|
1044
|
+
return self._incompressible(mode, lam)
|
|
1045
|
+
n = len(lam)
|
|
1046
|
+
e = np.zeros((n, 6))
|
|
1047
|
+
if mode == "shear": # F = 1 + g e1 (x) e2: E22 = g^2/2, 2 E12 = g
|
|
1048
|
+
e[:, 1], e[:, 5] = 0.5 * lam * lam, lam
|
|
1049
|
+
s = self._parts(e)[0] + self._parts(e)[2]
|
|
1050
|
+
return s[:, 5] + lam * s[:, 1]
|
|
1051
|
+
if np.any(lam <= 0):
|
|
1052
|
+
raise ValueError("stretch: positive")
|
|
1053
|
+
e[:, 0] = 0.5 * (lam * lam - 1.0)
|
|
1054
|
+
# the axes stretched with the first and those free of stress
|
|
1055
|
+
driven = [0, 1] if mode == "equibiaxial" else [0]
|
|
1056
|
+
free = [2] if mode in ("equibiaxial", "planar") else [1, 2]
|
|
1057
|
+
e[:, driven] = e[:, [0]]
|
|
1058
|
+
# the stretch of the free axes, from that of the incompressible solid
|
|
1059
|
+
side = lam ** {"uniaxial": -0.5, "equibiaxial": -2.0, "planar": -1.0}[mode]
|
|
1060
|
+
for _ in range(60):
|
|
1061
|
+
e[:, free] = 0.5 * (side * side - 1.0)[:, None]
|
|
1062
|
+
s_iso, t_iso, s_vol, t_vol, _ = self._parts(e)
|
|
1063
|
+
residual = (s_iso + s_vol)[:, free[0]]
|
|
1064
|
+
slope = (t_iso + t_vol)[:, free[0]][:, free].sum(axis=1) * side
|
|
1065
|
+
step = residual / slope
|
|
1066
|
+
side = np.maximum(side - step, 0.5 * side)
|
|
1067
|
+
if np.all(np.abs(step) <= 1e-13 * side):
|
|
1068
|
+
break
|
|
1069
|
+
e[:, free] = 0.5 * (side * side - 1.0)[:, None]
|
|
1070
|
+
s_iso, _, s_vol, _, _ = self._parts(e)
|
|
1071
|
+
return lam * (s_iso + s_vol)[:, 0]
|
|
1072
|
+
|
|
1073
|
+
def _incompressible(self, mode: str, lam) -> np.ndarray:
|
|
1074
|
+
"""The closed forms of the tests for an incompressible solid."""
|
|
1075
|
+
if self.model in (*_COMPRESSIBLE, "saint_venant_kirchhoff"):
|
|
1076
|
+
raise ValueError(f"nominal_stress: the {self.model} law is compressible")
|
|
1077
|
+
if self.model == "ogden":
|
|
1078
|
+
total = np.zeros_like(lam)
|
|
1079
|
+
for mu, alpha in self.p["terms"]:
|
|
1080
|
+
if mode == "uniaxial":
|
|
1081
|
+
total += mu * (lam ** (alpha - 1.0) - lam ** (-0.5 * alpha - 1.0))
|
|
1082
|
+
elif mode == "equibiaxial":
|
|
1083
|
+
total += mu * (lam ** (alpha - 1.0) - lam ** (-2.0 * alpha - 1.0))
|
|
1084
|
+
elif mode == "planar":
|
|
1085
|
+
total += mu * (lam ** (alpha - 1.0) - lam ** (-alpha - 1.0))
|
|
1086
|
+
else: # the principal stretch of the shear: l - 1/l = g
|
|
1087
|
+
top = 0.5 * lam + np.sqrt(1.0 + 0.25 * lam * lam)
|
|
1088
|
+
total += mu * (top**alpha - top**-alpha) / (top + 1.0 / top)
|
|
1089
|
+
return total
|
|
1090
|
+
l2 = lam * lam
|
|
1091
|
+
if mode == "uniaxial":
|
|
1092
|
+
i1, i2 = l2 + 2.0 / lam, 2.0 * lam + 1.0 / l2
|
|
1093
|
+
elif mode == "equibiaxial":
|
|
1094
|
+
i1, i2 = 2.0 * l2 + 1.0 / (l2 * l2), l2 * l2 + 2.0 / l2
|
|
1095
|
+
elif mode == "planar":
|
|
1096
|
+
i1 = i2 = l2 + 1.0 / l2 + 1.0
|
|
1097
|
+
else:
|
|
1098
|
+
i1 = i2 = 3.0 + l2
|
|
1099
|
+
(p1, p2, _, _, _), _ = self._psi(i1, i2)
|
|
1100
|
+
if mode == "uniaxial":
|
|
1101
|
+
return 2.0 * (lam - 1.0 / l2) * (p1 + p2 / lam)
|
|
1102
|
+
if mode == "equibiaxial":
|
|
1103
|
+
return 2.0 * (lam - 1.0 / (l2 * l2 * lam)) * (p1 + l2 * p2)
|
|
1104
|
+
if mode == "planar":
|
|
1105
|
+
return 2.0 * (lam - 1.0 / (l2 * lam)) * (p1 + p2)
|
|
1106
|
+
return 2.0 * lam * (p1 + p2)
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
def fit_hyperelasticity(
|
|
1110
|
+
model: str,
|
|
1111
|
+
tests,
|
|
1112
|
+
*,
|
|
1113
|
+
start: dict | None = None,
|
|
1114
|
+
fixed: dict | None = None,
|
|
1115
|
+
relative: bool = False,
|
|
1116
|
+
terms: int = 2,
|
|
1117
|
+
**options,
|
|
1118
|
+
) -> Hyperelasticity:
|
|
1119
|
+
"""The parameters of a hyperelastic ``model`` fitted to tests of an incompressible
|
|
1120
|
+
rubber: ``tests`` maps the modes (:data:`TESTS`) to their ``(stretches, nominal
|
|
1121
|
+
stresses)`` (``shear``: the amounts of shear and the shear stresses), fitted together
|
|
1122
|
+
by least squares on the stresses (``relative``: on their ratios to the measures, which
|
|
1123
|
+
weighs the small strains as the large ones). The polynomials of Rivlin (``mooney_rivlin``
|
|
1124
|
+
with the coefficients of ``start``, by default ``c10`` and ``c01``; ``yeoh``;
|
|
1125
|
+
``polynomial``) are linear in their coefficients: one linear solve. The others start
|
|
1126
|
+
from ``start`` (by default from the slope of the first points) and keep the
|
|
1127
|
+
parameters ``fixed``; ``ogden``: ``terms`` pairs. Returns the law (its bulk modulus,
|
|
1128
|
+
that of the material, is not fitted: the tests are those of an incompressible
|
|
1129
|
+
solid); ``options`` go to :func:`scipy.optimize.least_squares`."""
|
|
1130
|
+
from scipy.optimize import least_squares
|
|
1131
|
+
|
|
1132
|
+
if model not in FITTED:
|
|
1133
|
+
raise ValueError(f"fit_hyperelasticity: a model among {FITTED}")
|
|
1134
|
+
data = []
|
|
1135
|
+
for mode, (stretches, stresses) in dict(tests).items():
|
|
1136
|
+
if mode not in TESTS:
|
|
1137
|
+
raise ValueError(f"tests: modes among {TESTS}")
|
|
1138
|
+
x, y = np.asarray(stretches, dtype=float).ravel(), np.asarray(stresses, dtype=float).ravel()
|
|
1139
|
+
if x.shape != y.shape or not len(x):
|
|
1140
|
+
raise ValueError(f"tests[{mode!r}]: as many stretches as stresses, at least one")
|
|
1141
|
+
data.append((mode, x, y))
|
|
1142
|
+
if not data:
|
|
1143
|
+
raise ValueError("tests: at least one test")
|
|
1144
|
+
measured = np.concatenate([y for _, _, y in data])
|
|
1145
|
+
weights = 1.0 / np.abs(measured) if relative else np.ones_like(measured)
|
|
1146
|
+
if relative and not np.all(np.isfinite(weights)):
|
|
1147
|
+
raise ValueError("tests: no zero stress with relative=True")
|
|
1148
|
+
fixed = dict(fixed or {})
|
|
1149
|
+
|
|
1150
|
+
def stresses_of(parameters: dict) -> np.ndarray:
|
|
1151
|
+
law = _Hyperelastic(Hyperelasticity(model, tuple(parameters.items())), 1.0, 1.0, 1.0 / 3.0)
|
|
1152
|
+
return np.concatenate([law.nominal_stress(m, x, incompressible=True) for m, x, _ in data])
|
|
1153
|
+
|
|
1154
|
+
if model in _POLYNOMIALS: # linear in the coefficients
|
|
1155
|
+
names = sorted(start) if start else {"mooney_rivlin": ["c01", "c10"],
|
|
1156
|
+
"yeoh": ["c10", "c20", "c30"]}.get(model) # fmt: skip
|
|
1157
|
+
if not names:
|
|
1158
|
+
raise ValueError("fit_hyperelasticity (polynomial): the coefficients of start, e.g. "
|
|
1159
|
+
"{'c10': 0, 'c01': 0, 'c20': 0}") # fmt: skip
|
|
1160
|
+
names = [name for name in names if name not in fixed]
|
|
1161
|
+
every = dict.fromkeys([*names, *fixed], 0.0)
|
|
1162
|
+
basis = np.column_stack([stresses_of({**every, name: 1.0}) for name in names])
|
|
1163
|
+
offset = stresses_of({**every, **fixed}) if fixed else 0.0
|
|
1164
|
+
solution = np.linalg.lstsq(basis * weights[:, None], (measured - offset) * weights,
|
|
1165
|
+
rcond=None)[0] # fmt: skip
|
|
1166
|
+
found = {**dict(zip(names, (float(v) for v in solution), strict=True)), **fixed}
|
|
1167
|
+
return Hyperelasticity(model, tuple(found.items()))
|
|
1168
|
+
# the slope of the smallest strain of the first test: its shear modulus (three, six
|
|
1169
|
+
# and four times it in uniaxial, equibiaxial and planar tension)
|
|
1170
|
+
mode, x, y = data[0]
|
|
1171
|
+
strain = x if mode == "shear" else x - 1.0
|
|
1172
|
+
moving = np.flatnonzero((strain != 0) & (y != 0))
|
|
1173
|
+
shear = 1.0
|
|
1174
|
+
if len(moving):
|
|
1175
|
+
k = moving[np.argmin(np.abs(strain[moving]))]
|
|
1176
|
+
slope = {"uniaxial": 3.0, "equibiaxial": 6.0, "planar": 4.0, "shear": 1.0}[mode]
|
|
1177
|
+
shear = abs(float(y[k] / strain[k])) / slope
|
|
1178
|
+
top = max(1.5, *(float(np.max(np.abs(x))) for _, x, _ in data))
|
|
1179
|
+
defaults = {
|
|
1180
|
+
"neo_hookean": {"mu": shear},
|
|
1181
|
+
"arruda_boyce": {"mu": shear, "lock": 2.0 * top},
|
|
1182
|
+
"eight_chain": {"mu": shear, "lock": 2.0 * top},
|
|
1183
|
+
"gent": {"mu": shear, "lock": 10.0 * top * top},
|
|
1184
|
+
"van_der_waals": {"mu": shear, "lock": 2.0 * top, "a": 0.1},
|
|
1185
|
+
"fung": {"mu": shear, "b": 0.1},
|
|
1186
|
+
}
|
|
1187
|
+
if model == "ogden":
|
|
1188
|
+
guess = [(shear, 2.0), (0.01 * shear, 4.0), (-0.01 * shear, -2.0)][: max(1, int(terms))]
|
|
1189
|
+
initial = dict(start or {})
|
|
1190
|
+
pairs = initial.get("terms", guess)
|
|
1191
|
+
names = [f"{kind}{p}" for p in range(len(pairs)) for kind in ("mu", "alpha")]
|
|
1192
|
+
x0 = np.array([v for pair in pairs for v in pair], dtype=float)
|
|
1193
|
+
|
|
1194
|
+
def build(values):
|
|
1195
|
+
return {"terms": [[values[2 * p], values[2 * p + 1]] for p in range(len(pairs))]}
|
|
1196
|
+
|
|
1197
|
+
else:
|
|
1198
|
+
initial = {**defaults[model], **(start or {})}
|
|
1199
|
+
names = [name for name in initial if name not in fixed]
|
|
1200
|
+
x0 = np.array([initial[name] for name in names], dtype=float)
|
|
1201
|
+
|
|
1202
|
+
def build(values):
|
|
1203
|
+
return {**dict(zip(names, values, strict=True)), **fixed}
|
|
1204
|
+
|
|
1205
|
+
def residual(values):
|
|
1206
|
+
try:
|
|
1207
|
+
with np.errstate(all="ignore"):
|
|
1208
|
+
found = stresses_of(build(values))
|
|
1209
|
+
except ValueError: # parameters out of their range
|
|
1210
|
+
return np.full_like(measured, 1e6 * (1.0 + np.abs(measured).max()))
|
|
1211
|
+
found = np.where(np.isfinite(found), found, 1e6 * (1.0 + np.abs(measured).max()))
|
|
1212
|
+
return (found - measured) * weights
|
|
1213
|
+
|
|
1214
|
+
solution = least_squares(residual, x0, **{"x_scale": "jac", **options})
|
|
1215
|
+
return Hyperelasticity(model, tuple(build(solution.x).items()))
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
# -- damage --------------------------------------------------------------------------------
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
@dataclass(frozen=True)
|
|
1222
|
+
class Damage:
|
|
1223
|
+
"""An isotropic damage law (see the module): the damage starts at the equivalent
|
|
1224
|
+
strain ``threshold`` (or at the uniaxial stress ``strength``: the threshold is
|
|
1225
|
+
``strength / E``) and grows by the ``softening`` law (:data:`SOFTENINGS`) up to the
|
|
1226
|
+
equivalent strain ``ultimate`` (linear: no stress beyond it; exponential: the stress
|
|
1227
|
+
decays as ``exp(-(kappa - kappa_0) / (ultimate - kappa_0))``), or so that a band of the
|
|
1228
|
+
width ``length`` (the size of the elements) dissipates the ``fracture_energy`` per unit
|
|
1229
|
+
area. ``equivalent``: the equivalent strain (:data:`EQUIVALENT_STRAINS`), with
|
|
1230
|
+
``ratio`` the compressive strength over the tensile one of the modified von Mises
|
|
1231
|
+
strain; ``split`` (:data:`SPLITS`); ``viscosity``: the time of the delayed damage (0:
|
|
1232
|
+
none); ``residual``: the fraction of the stiffness that the damage leaves."""
|
|
1233
|
+
|
|
1234
|
+
threshold: float | None = None
|
|
1235
|
+
strength: float | None = None
|
|
1236
|
+
ultimate: float | None = None
|
|
1237
|
+
fracture_energy: float | None = None
|
|
1238
|
+
length: float | None = None
|
|
1239
|
+
softening: str = "exponential"
|
|
1240
|
+
equivalent: str = "mazars"
|
|
1241
|
+
ratio: float = 10.0
|
|
1242
|
+
split: str = "none"
|
|
1243
|
+
viscosity: float = 0.0
|
|
1244
|
+
residual: float = 1e-6
|
|
1245
|
+
|
|
1246
|
+
def __post_init__(self) -> None:
|
|
1247
|
+
if (self.threshold is None) == (self.strength is None):
|
|
1248
|
+
raise ValueError("damage: give the threshold (a strain) or the strength (a stress)")
|
|
1249
|
+
for name in ("threshold", "strength", "ultimate", "fracture_energy", "length"):
|
|
1250
|
+
value = getattr(self, name)
|
|
1251
|
+
if value is not None:
|
|
1252
|
+
if not (math.isfinite(value) and value > 0):
|
|
1253
|
+
raise ValueError(f"damage.{name}: positive")
|
|
1254
|
+
object.__setattr__(self, name, float(value))
|
|
1255
|
+
if (self.ultimate is None) == (self.fracture_energy is None):
|
|
1256
|
+
raise ValueError(
|
|
1257
|
+
"damage: give the ultimate strain, or the fracture energy and the length of "
|
|
1258
|
+
"the elements"
|
|
1259
|
+
)
|
|
1260
|
+
if self.fracture_energy is not None and self.length is None:
|
|
1261
|
+
raise ValueError(
|
|
1262
|
+
"damage.length: the size of the elements (the voxels) over which the "
|
|
1263
|
+
"fracture energy is dissipated"
|
|
1264
|
+
)
|
|
1265
|
+
if self.softening not in SOFTENINGS:
|
|
1266
|
+
raise ValueError(f"damage.softening: one of {SOFTENINGS}")
|
|
1267
|
+
if self.equivalent not in EQUIVALENT_STRAINS:
|
|
1268
|
+
raise ValueError(f"damage.equivalent: one of {EQUIVALENT_STRAINS}")
|
|
1269
|
+
if self.split not in SPLITS:
|
|
1270
|
+
raise ValueError(f"damage.split: one of {SPLITS}")
|
|
1271
|
+
if not self.ratio >= 1.0:
|
|
1272
|
+
raise ValueError("damage.ratio: the compressive strength over the tensile one (>= 1)")
|
|
1273
|
+
if not self.viscosity >= 0.0:
|
|
1274
|
+
raise ValueError("damage.viscosity: non-negative")
|
|
1275
|
+
if not 0.0 < self.residual < 1.0:
|
|
1276
|
+
raise ValueError("damage.residual: a fraction of the stiffness in (0, 1)")
|
|
1277
|
+
for name in ("ratio", "viscosity", "residual"):
|
|
1278
|
+
object.__setattr__(self, name, float(getattr(self, name)))
|
|
1279
|
+
|
|
1280
|
+
@classmethod
|
|
1281
|
+
def from_config(cls, spec) -> Damage:
|
|
1282
|
+
"""A mapping of the parameters of :class:`Damage`."""
|
|
1283
|
+
if isinstance(spec, Damage):
|
|
1284
|
+
return spec
|
|
1285
|
+
if not isinstance(spec, dict):
|
|
1286
|
+
raise ValueError("damage: a mapping of parameters")
|
|
1287
|
+
names = set(cls.__dataclass_fields__)
|
|
1288
|
+
unknown = sorted(set(spec) - names)
|
|
1289
|
+
if unknown:
|
|
1290
|
+
raise ValueError(f"damage: unknown keys {unknown}; allowed: {sorted(names)}")
|
|
1291
|
+
return cls(**spec)
|
|
1292
|
+
|
|
1293
|
+
def to_config(self) -> dict:
|
|
1294
|
+
defaults = Damage(threshold=1.0, ultimate=2.0)
|
|
1295
|
+
out = {}
|
|
1296
|
+
for name in self.__dataclass_fields__:
|
|
1297
|
+
value = getattr(self, name)
|
|
1298
|
+
keep = name in ("threshold", "strength", "ultimate", "fracture_energy", "length")
|
|
1299
|
+
if value is not None and (keep or value != getattr(defaults, name)):
|
|
1300
|
+
out[name] = value
|
|
1301
|
+
return out
|
|
1302
|
+
|
|
1303
|
+
def strains(self, young: float) -> tuple[float, float]:
|
|
1304
|
+
"""The threshold ``kappa_0`` and the ultimate strain ``kappa_f`` of the softening
|
|
1305
|
+
for the Young's modulus ``young``: those given, or from the strength and the
|
|
1306
|
+
fracture energy over the length of the elements (linear: ``kappa_f = 2 G_f / (h E
|
|
1307
|
+
kappa_0)``; exponential: ``kappa_f = kappa_0 / 2 + G_f / (h E kappa_0)``)."""
|
|
1308
|
+
k0 = self.threshold if self.threshold is not None else self.strength / young
|
|
1309
|
+
if self.ultimate is not None:
|
|
1310
|
+
kf = self.ultimate
|
|
1311
|
+
else:
|
|
1312
|
+
density = self.fracture_energy / self.length
|
|
1313
|
+
if self.softening == "linear":
|
|
1314
|
+
kf = 2.0 * density / (young * k0)
|
|
1315
|
+
else:
|
|
1316
|
+
kf = 0.5 * k0 + density / (young * k0)
|
|
1317
|
+
if not kf > k0:
|
|
1318
|
+
largest = 2.0 * (self.fracture_energy or 0.0) / (young * k0 * k0)
|
|
1319
|
+
raise ValueError(
|
|
1320
|
+
"damage: the ultimate strain must exceed the threshold; with a fracture "
|
|
1321
|
+
f"energy, elements smaller than {largest:.4g} (the stress would snap back)"
|
|
1322
|
+
)
|
|
1323
|
+
return float(k0), float(kf)
|
|
1324
|
+
|
|
1325
|
+
def damage(self, kappa, young: float):
|
|
1326
|
+
"""The damage ``d(kappa)`` and its derivative, for equivalent strains ``kappa``."""
|
|
1327
|
+
k0, kf = self.strains(young)
|
|
1328
|
+
kappa = np.asarray(kappa, dtype=float)
|
|
1329
|
+
k = np.maximum(kappa, k0)
|
|
1330
|
+
if self.softening == "linear":
|
|
1331
|
+
d = kf * (k - k0) / (k * (kf - k0))
|
|
1332
|
+
dd = kf * k0 / (k * k * (kf - k0))
|
|
1333
|
+
else:
|
|
1334
|
+
decay = np.exp(-(k - k0) / (kf - k0))
|
|
1335
|
+
d = 1.0 - k0 / k * decay
|
|
1336
|
+
dd = k0 / (k * k) * decay + k0 / k * decay / (kf - k0)
|
|
1337
|
+
top = 1.0 - self.residual
|
|
1338
|
+
growing = (kappa > k0) & (d < top)
|
|
1339
|
+
return np.where(kappa > k0, np.minimum(d, top), 0.0), np.where(growing, dd, 0.0)
|
|
1340
|
+
|
|
1341
|
+
|
|
1342
|
+
class _DamageLaw:
|
|
1343
|
+
"""The integration of a :class:`Damage` in small strains. State of a point: the
|
|
1344
|
+
largest equivalent strain reached, and the (delayed) damage."""
|
|
1345
|
+
|
|
1346
|
+
kind = "damage"
|
|
1347
|
+
thermal = False
|
|
1348
|
+
n_state = 2
|
|
1349
|
+
|
|
1350
|
+
def __init__(self, damage: Damage, young: float, poisson: float):
|
|
1351
|
+
self.damage = damage
|
|
1352
|
+
self.young, self.poisson = float(young), float(poisson)
|
|
1353
|
+
self.k = young / (3.0 * (1.0 - 2.0 * poisson))
|
|
1354
|
+
self.mu = young / (2.0 * (1.0 + poisson))
|
|
1355
|
+
self.d = isotropic_matrix(self.k - 2.0 * self.mu / 3.0, self.mu)
|
|
1356
|
+
damage.strains(young) # checked once
|
|
1357
|
+
# the tangent of a growing damage is not symmetric, but for the energy norm
|
|
1358
|
+
self.symmetric = damage.equivalent == "energy"
|
|
1359
|
+
|
|
1360
|
+
def scalar(self, h) -> np.ndarray:
|
|
1361
|
+
"""The damage of the points (the variable ``p`` of the outputs)."""
|
|
1362
|
+
return h[:, 1]
|
|
1363
|
+
|
|
1364
|
+
def _equivalent(self, e, tr, plus):
|
|
1365
|
+
"""The equivalent strains (n) and their derivatives with respect to the strains
|
|
1366
|
+
(n, 6: stress-like components, their product with engineering strains a full
|
|
1367
|
+
contraction); ``plus``: the part of the effective stress that the damage degrades."""
|
|
1368
|
+
dmg = self.damage
|
|
1369
|
+
n = e.shape[0]
|
|
1370
|
+
if dmg.equivalent == "energy":
|
|
1371
|
+
energy = np.einsum("ni,ni->n", plus, e) # twice the degraded energy density
|
|
1372
|
+
eq = np.sqrt(np.maximum(energy, 0.0) / self.young)
|
|
1373
|
+
grad = plus / (self.young * np.where(eq > 0, eq, 1.0))[:, None]
|
|
1374
|
+
return eq, np.where((eq > 0)[:, None], grad, 0.0)
|
|
1375
|
+
if dmg.equivalent == "mazars":
|
|
1376
|
+
t = np.empty((n, 3, 3))
|
|
1377
|
+
for k, (a, b) in enumerate(_PAIRS):
|
|
1378
|
+
t[:, a, b] = t[:, b, a] = e[:, k] * (1.0 if a == b else 0.5)
|
|
1379
|
+
w, v = np.linalg.eigh(t)
|
|
1380
|
+
pos = np.maximum(w, 0.0)
|
|
1381
|
+
eq = np.sqrt(np.einsum("na,na->n", pos, pos))
|
|
1382
|
+
m = v[:, _I0, :] * v[:, _I1, :]
|
|
1383
|
+
grad = np.einsum("nka,na->nk", m, pos) / np.where(eq > 0, eq, 1.0)[:, None]
|
|
1384
|
+
return eq, np.where((eq > 0)[:, None], grad, 0.0)
|
|
1385
|
+
# the modified von Mises strain (de Vree, Brekelmans & van Gils 1995)
|
|
1386
|
+
k, nu = dmg.ratio, self.poisson
|
|
1387
|
+
dev = (e - tr[:, None] / 3.0 * _M) * _HALF
|
|
1388
|
+
j2 = 0.5 * (np.einsum("ni,ni->n", dev[:, :3], dev[:, :3])
|
|
1389
|
+
+ 2.0 * np.einsum("ni,ni->n", dev[:, 3:], dev[:, 3:])) # fmt: skip
|
|
1390
|
+
a = (k - 1.0) / (2.0 * k * (1.0 - 2.0 * nu))
|
|
1391
|
+
b = (k - 1.0) / (1.0 - 2.0 * nu)
|
|
1392
|
+
c = 12.0 * k / (1.0 + nu) ** 2
|
|
1393
|
+
root = np.sqrt(b * b * tr * tr + c * j2)
|
|
1394
|
+
eq = a * tr + root / (2.0 * k)
|
|
1395
|
+
safe = np.where(root > 0, root, 1.0)
|
|
1396
|
+
grad = a * _M + ((2.0 * b * b * tr)[:, None] * _M + c * dev) / (4.0 * k * safe)[:, None]
|
|
1397
|
+
return eq, np.where((root > 0)[:, None], grad, 0.0)
|
|
1398
|
+
|
|
1399
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
1400
|
+
dmg = self.damage
|
|
1401
|
+
e = np.asarray(e_new, dtype=float)
|
|
1402
|
+
n = e.shape[0]
|
|
1403
|
+
tr = e[:, :3].sum(axis=1)
|
|
1404
|
+
if dmg.split == "volumetric": # the bulk response in compression is kept
|
|
1405
|
+
open_ = tr > 0
|
|
1406
|
+
dev = (e - tr[:, None] / 3.0 * _M) * _HALF
|
|
1407
|
+
plus = 2.0 * self.mu * dev + (self.k * np.where(open_, tr, 0.0))[:, None] * _M
|
|
1408
|
+
minus = (self.k * np.where(open_, 0.0, tr))[:, None] * _M
|
|
1409
|
+
dev_matrix = isotropic_matrix(-2.0 * self.mu / 3.0, self.mu)
|
|
1410
|
+
bulk = self.k * np.outer(_M, _M)
|
|
1411
|
+
c_plus = dev_matrix[None] + np.where(open_, 1.0, 0.0)[:, None, None] * bulk
|
|
1412
|
+
c_minus = np.where(open_, 0.0, 1.0)[:, None, None] * bulk
|
|
1413
|
+
elif dmg.split == "spectral": # the negative principal strains keep their stiffness
|
|
1414
|
+
plus, c_plus, minus, c_minus = _principal_split(e, tr, self.k, self.mu)
|
|
1415
|
+
else:
|
|
1416
|
+
plus = e @ self.d
|
|
1417
|
+
minus = 0.0
|
|
1418
|
+
c_plus = np.broadcast_to(self.d, (n, 6, 6))
|
|
1419
|
+
c_minus = 0.0
|
|
1420
|
+
eq, grad = self._equivalent(e, tr, plus)
|
|
1421
|
+
kappa_old = h_old[:, 0]
|
|
1422
|
+
loading = eq > kappa_old
|
|
1423
|
+
kappa = np.where(loading, eq, kappa_old)
|
|
1424
|
+
d, slope = dmg.damage(kappa, self.young)
|
|
1425
|
+
rate = 1.0
|
|
1426
|
+
if dmg.viscosity > 0.0 and dt > 0.0:
|
|
1427
|
+
ratio = dt / dmg.viscosity
|
|
1428
|
+
rate = ratio / (1.0 + ratio)
|
|
1429
|
+
d = (h_old[:, 1] + ratio * d) / (1.0 + ratio)
|
|
1430
|
+
elif dmg.viscosity > 0.0: # an instantaneous step: no growth of the damage
|
|
1431
|
+
rate = 0.0
|
|
1432
|
+
d = h_old[:, 1].copy()
|
|
1433
|
+
d = np.maximum(d, h_old[:, 1])
|
|
1434
|
+
stress = (1.0 - d)[:, None] * plus + minus
|
|
1435
|
+
tangent = (1.0 - d)[:, None, None] * c_plus + c_minus
|
|
1436
|
+
growth = np.where(loading, rate * slope, 0.0)
|
|
1437
|
+
tangent = tangent - growth[:, None, None] * _outer(plus, grad)
|
|
1438
|
+
return stress, tangent, np.stack([kappa, d], axis=1)
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
def _principal_strains(e):
|
|
1442
|
+
"""The principal strains (n, 3) and axes (n, 3, 3) of engineering strains (n, 6)."""
|
|
1443
|
+
t = np.empty((e.shape[0], 3, 3))
|
|
1444
|
+
for k, (a, b) in enumerate(_PAIRS):
|
|
1445
|
+
t[:, a, b] = t[:, b, a] = e[:, k] * (1.0 if a == b else 0.5)
|
|
1446
|
+
return np.linalg.eigh(t)
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
def _principal_split(e, tr, bulk: float, shear: float):
|
|
1450
|
+
"""The stresses of the positive and of the negative principal strains of an isotropic
|
|
1451
|
+
elastic point (Miehe et al. 2010), ``sigma± = lambda <tr eps>± I + 2 mu eps±``, and
|
|
1452
|
+
their tangents (see :func:`_spectral`)."""
|
|
1453
|
+
lam = bulk - 2.0 * shear / 3.0
|
|
1454
|
+
w, v = _principal_strains(e)
|
|
1455
|
+
out = []
|
|
1456
|
+
for sign in (1.0, -1.0):
|
|
1457
|
+
on = (sign * w > 0).astype(float) # the principal strains of this sign
|
|
1458
|
+
whole = (sign * tr > 0).astype(float)
|
|
1459
|
+
s_a = (lam * whole * tr)[:, None] + 2.0 * shear * on * w
|
|
1460
|
+
d = (lam * whole)[:, None, None] * np.ones((1, 3, 3)) + 2.0 * shear * (
|
|
1461
|
+
on[:, :, None] * np.eye(3)[None]
|
|
1462
|
+
)
|
|
1463
|
+
out.extend(_spectral(v, 1.0 + 2.0 * w, s_a, d))
|
|
1464
|
+
return tuple(out)
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
# -- concrete: the law of Mazars -------------------------------------------------------------
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
@dataclass(frozen=True)
|
|
1471
|
+
class Mazars:
|
|
1472
|
+
"""Mazars' law of the damage of concrete (see the module): the ``threshold`` strain
|
|
1473
|
+
``kappa_0`` (about 1e-4), the parameters ``tension`` ``(A_t, B_t)`` and ``compression``
|
|
1474
|
+
``(A_c, B_c)`` of its two damages (0.7 to 1.2 and 1e4 to 5e4; 1 to 1.5 and 1e3 to 2e3
|
|
1475
|
+
for usual concretes), the exponent ``beta`` of their shares (1; 1.06 lessens the
|
|
1476
|
+
damage in shear) and the ``residual`` fraction of the stiffness that the damage
|
|
1477
|
+
leaves."""
|
|
1478
|
+
|
|
1479
|
+
threshold: float
|
|
1480
|
+
tension: tuple[float, float]
|
|
1481
|
+
compression: tuple[float, float]
|
|
1482
|
+
beta: float = 1.0
|
|
1483
|
+
residual: float = 1e-6
|
|
1484
|
+
|
|
1485
|
+
def __post_init__(self) -> None:
|
|
1486
|
+
if not (math.isfinite(self.threshold) and self.threshold > 0):
|
|
1487
|
+
raise ValueError("damage.threshold: the strain at which the damage starts, positive")
|
|
1488
|
+
object.__setattr__(self, "threshold", float(self.threshold))
|
|
1489
|
+
for name in ("tension", "compression"):
|
|
1490
|
+
pair = getattr(self, name)
|
|
1491
|
+
try:
|
|
1492
|
+
a, b = (float(x) for x in pair)
|
|
1493
|
+
except (TypeError, ValueError):
|
|
1494
|
+
raise ValueError(f"damage.{name}: the pair (A, B) of Mazars' law") from None
|
|
1495
|
+
if not (math.isfinite(a) and math.isfinite(b) and a > 0 and b > 0):
|
|
1496
|
+
raise ValueError(f"damage.{name}: A and B positive")
|
|
1497
|
+
object.__setattr__(self, name, (a, b))
|
|
1498
|
+
if not (math.isfinite(self.beta) and self.beta >= 1.0):
|
|
1499
|
+
raise ValueError("damage.beta: the exponent of the shares, 1 or more")
|
|
1500
|
+
if not 0.0 < self.residual < 1.0:
|
|
1501
|
+
raise ValueError("damage.residual: a fraction of the stiffness in (0, 1)")
|
|
1502
|
+
object.__setattr__(self, "beta", float(self.beta))
|
|
1503
|
+
object.__setattr__(self, "residual", float(self.residual))
|
|
1504
|
+
|
|
1505
|
+
def to_config(self) -> dict:
|
|
1506
|
+
out = {"law": "mazars", "threshold": self.threshold, "tension": list(self.tension),
|
|
1507
|
+
"compression": list(self.compression)} # fmt: skip
|
|
1508
|
+
if self.beta != 1.0:
|
|
1509
|
+
out["beta"] = self.beta
|
|
1510
|
+
if self.residual != 1e-6:
|
|
1511
|
+
out["residual"] = self.residual
|
|
1512
|
+
return out
|
|
1513
|
+
|
|
1514
|
+
def strains(self, young: float) -> tuple[float, float]:
|
|
1515
|
+
"""The threshold of the damage (and no ultimate strain: the laws decay)."""
|
|
1516
|
+
return self.threshold, math.inf
|
|
1517
|
+
|
|
1518
|
+
def branch(self, kappa, pair):
|
|
1519
|
+
"""A damage of Mazars ``1 - kappa_0 (1 - A) / kappa - A exp(-B (kappa - kappa_0))``
|
|
1520
|
+
and its derivative, for strains ``kappa`` beyond the threshold."""
|
|
1521
|
+
a, b = pair
|
|
1522
|
+
k0 = self.threshold
|
|
1523
|
+
k = np.maximum(kappa, k0)
|
|
1524
|
+
decay = np.exp(-b * (k - k0))
|
|
1525
|
+
d = 1.0 - k0 * (1.0 - a) / k - a * decay
|
|
1526
|
+
return np.clip(d, 0.0, 1.0), k0 * (1.0 - a) / (k * k) + a * b * decay
|
|
1527
|
+
|
|
1528
|
+
def uniaxial(self, strain, young: float, poisson: float):
|
|
1529
|
+
"""The stress of a monotonic uniaxial tension (positive strains) or compression
|
|
1530
|
+
(negative ones), in closed form."""
|
|
1531
|
+
e = np.asarray(strain, dtype=float)
|
|
1532
|
+
kappa = np.where(e >= 0, e, -math.sqrt(2.0) * poisson * e)
|
|
1533
|
+
d_t, _ = self.branch(kappa, self.tension)
|
|
1534
|
+
d_c, _ = self.branch(kappa, self.compression)
|
|
1535
|
+
d = np.where(kappa > self.threshold, np.where(e >= 0, d_t, d_c), 0.0)
|
|
1536
|
+
return (1.0 - np.minimum(d, 1.0 - self.residual)) * young * e
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
class _MazarsLaw:
|
|
1540
|
+
"""The integration of :class:`Mazars` in small strains. State of a point: the largest
|
|
1541
|
+
equivalent strain reached, and the damage."""
|
|
1542
|
+
|
|
1543
|
+
kind = "damage"
|
|
1544
|
+
thermal = False
|
|
1545
|
+
symmetric = False
|
|
1546
|
+
n_state = 2
|
|
1547
|
+
|
|
1548
|
+
def __init__(self, damage: Mazars, young: float, poisson: float):
|
|
1549
|
+
self.damage = damage
|
|
1550
|
+
self.young, self.poisson = float(young), float(poisson)
|
|
1551
|
+
self.k = young / (3.0 * (1.0 - 2.0 * poisson))
|
|
1552
|
+
self.mu = young / (2.0 * (1.0 + poisson))
|
|
1553
|
+
self.d = isotropic_matrix(self.k - 2.0 * self.mu / 3.0, self.mu)
|
|
1554
|
+
|
|
1555
|
+
def scalar(self, h) -> np.ndarray:
|
|
1556
|
+
"""The damage of the points (the variable ``p`` of the outputs)."""
|
|
1557
|
+
return h[:, 1]
|
|
1558
|
+
|
|
1559
|
+
def _shares(self, w):
|
|
1560
|
+
"""The share ``alpha_t`` of the positive principal strains ``w`` (n, 3) that the
|
|
1561
|
+
tensions of the effective stress make, and its derivatives by the principal
|
|
1562
|
+
strains (n, 3): ``alpha_t = sum_i eps^t_i <eps_i>+ / eps_eq^2`` with ``eps^t`` the
|
|
1563
|
+
strains of the positive principal stresses."""
|
|
1564
|
+
lam = self.k - 2.0 * self.mu / 3.0
|
|
1565
|
+
young, nu = self.young, self.poisson
|
|
1566
|
+
tr = w.sum(axis=1)
|
|
1567
|
+
s = lam * tr[:, None] + 2.0 * self.mu * w # the principal effective stresses
|
|
1568
|
+
sp = np.maximum(s, 0.0)
|
|
1569
|
+
hs = (s > 0).astype(float)
|
|
1570
|
+
et = (1.0 + nu) / young * sp - nu / young * sp.sum(axis=1)[:, None]
|
|
1571
|
+
pos = np.maximum(w, 0.0)
|
|
1572
|
+
hp = (w > 0).astype(float)
|
|
1573
|
+
eq2 = np.einsum("na,na->n", pos, pos)
|
|
1574
|
+
safe = np.where(eq2 > 0, eq2, 1.0)
|
|
1575
|
+
top = np.einsum("na,na->n", et, pos)
|
|
1576
|
+
alpha = np.where(eq2 > 0, top / safe, 0.0)
|
|
1577
|
+
# d et_i / d w_j = (1 + nu)/E hs_i ds_i/dw_j - nu/E sum_k hs_k ds_k/dw_j
|
|
1578
|
+
ds = lam * np.ones((1, 3, 3)) + 2.0 * self.mu * np.eye(3)[None] # ds_i / dw_j
|
|
1579
|
+
hds = hs[:, :, None] * ds
|
|
1580
|
+
det = (1.0 + nu) / young * hds - nu / young * hds.sum(axis=1)[:, None, :]
|
|
1581
|
+
dtop = np.einsum("nij,ni->nj", det, pos) + et * hp
|
|
1582
|
+
dalpha = (dtop - 2.0 * alpha[:, None] * pos) / safe[:, None]
|
|
1583
|
+
alpha = np.clip(alpha, 0.0, 1.0)
|
|
1584
|
+
inside = ((alpha > 0.0) & (alpha < 1.0) & (eq2 > 0))[:, None]
|
|
1585
|
+
return alpha, np.where(inside, dalpha, 0.0)
|
|
1586
|
+
|
|
1587
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
1588
|
+
dmg = self.damage
|
|
1589
|
+
e = np.asarray(e_new, dtype=float)
|
|
1590
|
+
w, v = _principal_strains(e)
|
|
1591
|
+
pos = np.maximum(w, 0.0)
|
|
1592
|
+
eq = np.sqrt(np.einsum("na,na->n", pos, pos))
|
|
1593
|
+
m = v[:, _I0, :] * v[:, _I1, :] # N_a (x) N_a in Voigt components
|
|
1594
|
+
kappa_old = np.maximum(h_old[:, 0], dmg.threshold)
|
|
1595
|
+
loading = eq > kappa_old
|
|
1596
|
+
kappa = np.where(loading, eq, kappa_old)
|
|
1597
|
+
alpha, dalpha = self._shares(w)
|
|
1598
|
+
d_t, slope_t = dmg.branch(kappa, dmg.tension)
|
|
1599
|
+
d_c, slope_c = dmg.branch(kappa, dmg.compression)
|
|
1600
|
+
beta = dmg.beta
|
|
1601
|
+
a_t, a_c = alpha**beta, (1.0 - alpha) ** beta
|
|
1602
|
+
d = a_t * d_t + a_c * d_c
|
|
1603
|
+
top = 1.0 - dmg.residual
|
|
1604
|
+
d = np.where(kappa > dmg.threshold, np.minimum(d, top), 0.0)
|
|
1605
|
+
growing = (d > h_old[:, 1]) & (d < top)
|
|
1606
|
+
d = np.maximum(d, h_old[:, 1])
|
|
1607
|
+
effective = e @ self.d
|
|
1608
|
+
stress = (1.0 - d)[:, None] * effective
|
|
1609
|
+
tangent = (1.0 - d)[:, None, None] * self.d[None]
|
|
1610
|
+
# the derivative of the damage by the principal strains: by kappa (while it
|
|
1611
|
+
# grows) and by the shares of the tension and of the compression
|
|
1612
|
+
safe = np.where(eq > 0, eq, 1.0)
|
|
1613
|
+
dkappa = np.where(loading[:, None], pos / safe[:, None], 0.0)
|
|
1614
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
1615
|
+
da_t = np.where(alpha > 0, beta * alpha ** (beta - 1.0), 0.0)
|
|
1616
|
+
da_c = np.where(alpha < 1, beta * (1.0 - alpha) ** (beta - 1.0), 0.0)
|
|
1617
|
+
dd = (a_t * slope_t + a_c * slope_c)[:, None] * dkappa + (da_t * d_t - da_c * d_c)[
|
|
1618
|
+
:, None
|
|
1619
|
+
] * dalpha
|
|
1620
|
+
grad = np.einsum("nka,na->nk", m, np.where(growing[:, None], dd, 0.0))
|
|
1621
|
+
tangent = tangent - _outer(effective, grad)
|
|
1622
|
+
return stress, tangent, np.stack([kappa, d], axis=1)
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
# -- damage coupled to plasticity ----------------------------------------------------------
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
@dataclass(frozen=True)
|
|
1629
|
+
class DuctileDamage:
|
|
1630
|
+
"""A damage coupled to the von Mises plasticity of its material (see the module).
|
|
1631
|
+
|
|
1632
|
+
``law="lemaitre"``: the strength ``S`` of the damage (a stress: of the order of the
|
|
1633
|
+
energy release rate at failure) and its exponent ``s`` (1 by default), the cumulated
|
|
1634
|
+
plastic strain ``threshold`` at which it starts (0), and the ``closure`` ``h`` of the
|
|
1635
|
+
microcracks in compression (1: none; 0.2 for metals).
|
|
1636
|
+
|
|
1637
|
+
``law="kachanov"``: the resistance ``A`` (a stress), the exponents ``r`` of the
|
|
1638
|
+
stress and ``k`` of ``1 - D`` (by default ``r``), and Hayhurst's weights ``alpha`` of
|
|
1639
|
+
the largest principal stress and ``beta`` of the mean stress (0: von Mises' stress).
|
|
1640
|
+
|
|
1641
|
+
``critical``: the damage at which a point breaks (by default it grows up to ``1 -
|
|
1642
|
+
residual``); ``residual``: the fraction of its stress that a broken point keeps;
|
|
1643
|
+
``viscosity``: the time of the delayed damage (0: none)."""
|
|
1644
|
+
|
|
1645
|
+
law: str
|
|
1646
|
+
S: float | None = None
|
|
1647
|
+
s: float = 1.0
|
|
1648
|
+
threshold: float = 0.0
|
|
1649
|
+
closure: float = 1.0
|
|
1650
|
+
A: float | None = None
|
|
1651
|
+
r: float | None = None
|
|
1652
|
+
k: float | None = None
|
|
1653
|
+
alpha: float = 0.0
|
|
1654
|
+
beta: float = 0.0
|
|
1655
|
+
critical: float | None = None
|
|
1656
|
+
residual: float = 1e-6
|
|
1657
|
+
viscosity: float = 0.0
|
|
1658
|
+
|
|
1659
|
+
def __post_init__(self) -> None:
|
|
1660
|
+
if self.law not in DUCTILE_LAWS:
|
|
1661
|
+
raise ValueError(f"damage.law: one of {DUCTILE_LAWS}")
|
|
1662
|
+
|
|
1663
|
+
def positive(name, value):
|
|
1664
|
+
if value is None or not (math.isfinite(value) and value > 0):
|
|
1665
|
+
raise ValueError(f"damage.{name}: positive")
|
|
1666
|
+
return float(value)
|
|
1667
|
+
|
|
1668
|
+
own = {"lemaitre": ("S", "s", "threshold", "closure"),
|
|
1669
|
+
"kachanov": ("A", "r", "k", "alpha", "beta")} # fmt: skip
|
|
1670
|
+
defaults = {"S": None, "s": 1.0, "threshold": 0.0, "closure": 1.0, "A": None,
|
|
1671
|
+
"r": None, "k": None, "alpha": 0.0, "beta": 0.0} # fmt: skip
|
|
1672
|
+
for other in DUCTILE_LAWS:
|
|
1673
|
+
if other != self.law:
|
|
1674
|
+
given = [n for n in own[other] if getattr(self, n) != defaults[n]]
|
|
1675
|
+
if given:
|
|
1676
|
+
raise ValueError(f"damage: {given} are parameters of the law {other}")
|
|
1677
|
+
if self.law == "lemaitre":
|
|
1678
|
+
object.__setattr__(self, "S", positive("S", self.S))
|
|
1679
|
+
object.__setattr__(self, "s", positive("s", self.s))
|
|
1680
|
+
if not (math.isfinite(self.threshold) and self.threshold >= 0):
|
|
1681
|
+
raise ValueError("damage.threshold: a cumulated plastic strain, 0 or more")
|
|
1682
|
+
if not 0.0 <= self.closure <= 1.0:
|
|
1683
|
+
raise ValueError("damage.closure: the share of the compressions, in [0, 1]")
|
|
1684
|
+
object.__setattr__(self, "threshold", float(self.threshold))
|
|
1685
|
+
object.__setattr__(self, "closure", float(self.closure))
|
|
1686
|
+
else:
|
|
1687
|
+
object.__setattr__(self, "A", positive("A", self.A))
|
|
1688
|
+
object.__setattr__(self, "r", positive("r", self.r))
|
|
1689
|
+
k = self.r if self.k is None else self.k
|
|
1690
|
+
if not (math.isfinite(k) and k >= 0):
|
|
1691
|
+
raise ValueError("damage.k: the exponent of 1 - D, 0 or more")
|
|
1692
|
+
object.__setattr__(self, "k", float(k))
|
|
1693
|
+
if not (self.alpha >= 0 and self.beta >= 0 and self.alpha + self.beta <= 1.0):
|
|
1694
|
+
raise ValueError("damage: Hayhurst's weights alpha and beta, in [0, 1], add "
|
|
1695
|
+
"up to 1 at most") # fmt: skip
|
|
1696
|
+
object.__setattr__(self, "alpha", float(self.alpha))
|
|
1697
|
+
object.__setattr__(self, "beta", float(self.beta))
|
|
1698
|
+
if not 0.0 < self.residual < 1.0:
|
|
1699
|
+
raise ValueError("damage.residual: a fraction of the stress in (0, 1)")
|
|
1700
|
+
object.__setattr__(self, "residual", float(self.residual))
|
|
1701
|
+
if not (math.isfinite(self.viscosity) and self.viscosity >= 0.0):
|
|
1702
|
+
raise ValueError("damage.viscosity: non-negative")
|
|
1703
|
+
object.__setattr__(self, "viscosity", float(self.viscosity))
|
|
1704
|
+
if self.critical is not None:
|
|
1705
|
+
if not 0.0 < self.critical < 1.0:
|
|
1706
|
+
raise ValueError("damage.critical: the damage of a broken point, in (0, 1)")
|
|
1707
|
+
object.__setattr__(self, "critical", float(self.critical))
|
|
1708
|
+
|
|
1709
|
+
def to_config(self) -> dict:
|
|
1710
|
+
out: dict = {"law": self.law}
|
|
1711
|
+
if self.law == "lemaitre":
|
|
1712
|
+
out.update(S=self.S)
|
|
1713
|
+
for name, default in (("s", 1.0), ("threshold", 0.0), ("closure", 1.0)):
|
|
1714
|
+
if getattr(self, name) != default:
|
|
1715
|
+
out[name] = getattr(self, name)
|
|
1716
|
+
else:
|
|
1717
|
+
out.update(A=self.A, r=self.r)
|
|
1718
|
+
if self.k != self.r:
|
|
1719
|
+
out["k"] = self.k
|
|
1720
|
+
for name in ("alpha", "beta"):
|
|
1721
|
+
if getattr(self, name):
|
|
1722
|
+
out[name] = getattr(self, name)
|
|
1723
|
+
if self.critical is not None:
|
|
1724
|
+
out["critical"] = self.critical
|
|
1725
|
+
if self.residual != 1e-6:
|
|
1726
|
+
out["residual"] = self.residual
|
|
1727
|
+
if self.viscosity:
|
|
1728
|
+
out["viscosity"] = self.viscosity
|
|
1729
|
+
return out
|
|
1730
|
+
|
|
1731
|
+
@property
|
|
1732
|
+
def top(self) -> float:
|
|
1733
|
+
"""The largest damage of a point that is not broken."""
|
|
1734
|
+
return 1.0 - self.residual if self.critical is None else self.critical
|
|
1735
|
+
|
|
1736
|
+
def rupture_time(self, stress: float) -> float:
|
|
1737
|
+
"""Kachanov's time to rupture under a constant uniaxial stress, ``1 / ((k + 1)
|
|
1738
|
+
(stress / A)^r)`` (of the damage 1; of ``critical``: ``1 - (1 - critical)^(k + 1)``
|
|
1739
|
+
of it)."""
|
|
1740
|
+
if self.law != "kachanov":
|
|
1741
|
+
raise ValueError("rupture_time: of the law of Kachanov")
|
|
1742
|
+
whole = 1.0 / ((self.k + 1.0) * (stress / self.A) ** self.r)
|
|
1743
|
+
if self.critical is None:
|
|
1744
|
+
return whole
|
|
1745
|
+
return whole * (1.0 - (1.0 - self.critical) ** (self.k + 1.0))
|
|
1746
|
+
|
|
1747
|
+
def release_rate(self, stress, young: float, poisson: float):
|
|
1748
|
+
"""The energy release rate ``Y`` of effective stresses (n, 6) and its derivative
|
|
1749
|
+
by them (n, 6, as strains: its contraction with a stress increment is ``dY``):
|
|
1750
|
+
``(1 + nu) / (2 E) sum_i g(s_i) - nu / (2 E) g(tr s)`` with ``g(x) = <x>+^2 + h
|
|
1751
|
+
<x>-^2`` of the principal stresses."""
|
|
1752
|
+
s = np.asarray(stress, dtype=float)
|
|
1753
|
+
t = np.empty((s.shape[0], 3, 3))
|
|
1754
|
+
for k, (a, b) in enumerate(_PAIRS):
|
|
1755
|
+
t[:, a, b] = t[:, b, a] = s[:, k]
|
|
1756
|
+
w, v = np.linalg.eigh(t)
|
|
1757
|
+
h = self.closure
|
|
1758
|
+
tr = w.sum(axis=1)
|
|
1759
|
+
|
|
1760
|
+
def g(x):
|
|
1761
|
+
return np.where(x > 0, x * x, h * x * x), np.where(x > 0, 2.0 * x, 2.0 * h * x)
|
|
1762
|
+
|
|
1763
|
+
gw, dgw = g(w)
|
|
1764
|
+
gt, dgt = g(tr)
|
|
1765
|
+
a, b = (1.0 + poisson) / (2.0 * young), poisson / (2.0 * young)
|
|
1766
|
+
y = a * gw.sum(axis=1) - b * gt
|
|
1767
|
+
dy = a * dgw - (b * dgt)[:, None] # by the principal stresses
|
|
1768
|
+
m = v[:, _I0, :] * v[:, _I1, :]
|
|
1769
|
+
grad = np.einsum("nka,na->nk", m, dy)
|
|
1770
|
+
grad[:, 3:] *= 2.0 # strain-like: the shears count twice in the contraction
|
|
1771
|
+
return np.maximum(y, 0.0), grad
|
|
1772
|
+
|
|
1773
|
+
def creep_stress(self, stress):
|
|
1774
|
+
"""Hayhurst's stress ``alpha s_I + 3 beta s_m + (1 - alpha - beta) s_eq`` of
|
|
1775
|
+
stresses (n, 6), its positive part, and its derivative (n, 6, strain-like)."""
|
|
1776
|
+
s = np.asarray(stress, dtype=float)
|
|
1777
|
+
n = s.shape[0]
|
|
1778
|
+
mean = s[:, :3].mean(axis=1)
|
|
1779
|
+
dev = s - mean[:, None] * _M
|
|
1780
|
+
j2 = 0.5 * (np.einsum("ni,ni->n", dev[:, :3], dev[:, :3])
|
|
1781
|
+
+ 2.0 * np.einsum("ni,ni->n", dev[:, 3:], dev[:, 3:])) # fmt: skip
|
|
1782
|
+
seq = np.sqrt(3.0 * j2)
|
|
1783
|
+
safe = np.where(seq > 0, seq, 1.0)
|
|
1784
|
+
dseq = 1.5 * dev / safe[:, None]
|
|
1785
|
+
dseq[:, 3:] *= 2.0
|
|
1786
|
+
chi = 3.0 * self.beta * mean + (1.0 - self.alpha - self.beta) * seq
|
|
1787
|
+
grad = self.beta * _M[None] + (1.0 - self.alpha - self.beta) * np.where(
|
|
1788
|
+
(seq > 0)[:, None], dseq, 0.0
|
|
1789
|
+
)
|
|
1790
|
+
if self.alpha > 0:
|
|
1791
|
+
t = np.empty((n, 3, 3))
|
|
1792
|
+
for k, (a, b) in enumerate(_PAIRS):
|
|
1793
|
+
t[:, a, b] = t[:, b, a] = s[:, k]
|
|
1794
|
+
w, v = np.linalg.eigh(t)
|
|
1795
|
+
chi = chi + self.alpha * w[:, 2]
|
|
1796
|
+
first = v[:, _I0, 2] * v[:, _I1, 2]
|
|
1797
|
+
first[:, 3:] *= 2.0
|
|
1798
|
+
grad = grad + self.alpha * first
|
|
1799
|
+
on = chi > 0
|
|
1800
|
+
return np.where(on, chi, 0.0), np.where(on[:, None], grad, 0.0)
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
class _PlasticDamage:
|
|
1804
|
+
"""The integration of a :class:`DuctileDamage` with the plasticity of its material: the
|
|
1805
|
+
kernel of von Mises, or of Hill's criterion, on the effective stress, then the damage
|
|
1806
|
+
(see the module). State of a point: that of the plasticity (plastic strain, ``p``,
|
|
1807
|
+
backstresses), the damage of the law, and the (delayed) damage that degrades the
|
|
1808
|
+
stress."""
|
|
1809
|
+
|
|
1810
|
+
kind = "damage"
|
|
1811
|
+
thermal = False
|
|
1812
|
+
symmetric = False
|
|
1813
|
+
|
|
1814
|
+
def __init__(self, plasticity, damage: DuctileDamage, young: float, poisson: float):
|
|
1815
|
+
from morphogen.homogenization import behaviours as beh
|
|
1816
|
+
|
|
1817
|
+
if plasticity is None:
|
|
1818
|
+
raise ValueError(
|
|
1819
|
+
f"damage: the law {damage.law} is that of a plastic material (plasticity)"
|
|
1820
|
+
)
|
|
1821
|
+
if damage.law == "kachanov" and not plasticity.viscous:
|
|
1822
|
+
raise ValueError("damage: Kachanov's law is that of a viscoplastic material "
|
|
1823
|
+
"(plasticity.norton)") # fmt: skip
|
|
1824
|
+
self.damage = damage
|
|
1825
|
+
self.young, self.poisson = float(young), float(poisson)
|
|
1826
|
+
bulk = young / (3.0 * (1.0 - 2.0 * poisson))
|
|
1827
|
+
shear = young / (2.0 * (1.0 + poisson))
|
|
1828
|
+
lam = bulk - 2.0 * shear / 3.0
|
|
1829
|
+
self.nk = len(plasticity.kinematic)
|
|
1830
|
+
self.width = beh.state_width(self.nk)
|
|
1831
|
+
self.n_state = self.width + 2
|
|
1832
|
+
self._p = beh.STATE_P
|
|
1833
|
+
elastic = isotropic_matrix(lam, shear)
|
|
1834
|
+
self._data = (
|
|
1835
|
+
np.ascontiguousarray(elastic[None]),
|
|
1836
|
+
np.zeros((1, 6)),
|
|
1837
|
+
np.ascontiguousarray(plasticity.params(lam, shear)[None]),
|
|
1838
|
+
int(self.nk),
|
|
1839
|
+
np.zeros((1, 1, 6)),
|
|
1840
|
+
np.zeros((1, 1, 7)),
|
|
1841
|
+
np.zeros((1, 1, 1)),
|
|
1842
|
+
np.zeros(1, dtype=np.int64),
|
|
1843
|
+
)
|
|
1844
|
+
self._update = beh.update_points
|
|
1845
|
+
self._plastic = beh.PLASTIC if plasticity.hill is None else beh.HILL
|
|
1846
|
+
# the cumulated plastic strain of a plastic strain increment: the norm dual to the
|
|
1847
|
+
# criterion, dp² = dep . a⁺ . dep with J² = x . a . x (a = 3/2 P diag(h) P in
|
|
1848
|
+
# Mandel's components; 2/3 dep : dep for von Mises), here for tensor components
|
|
1849
|
+
h = np.ones(6)
|
|
1850
|
+
if plasticity.hill is not None:
|
|
1851
|
+
for name, value in zip(beh.HILL_COMPONENTS, plasticity.hill, strict=True):
|
|
1852
|
+
h[beh._HILL_VOIGT[name]] = value
|
|
1853
|
+
deviatoric = np.eye(3) - 1.0 / 3.0
|
|
1854
|
+
criterion = np.zeros((6, 6))
|
|
1855
|
+
criterion[:3, :3] = 1.5 * deviatoric @ np.diag(h[:3]) @ deviatoric
|
|
1856
|
+
criterion[3:, 3:] = 1.5 * np.diag(h[3:])
|
|
1857
|
+
mandel = np.diag([1.0, 1.0, 1.0, math.sqrt(2.0), math.sqrt(2.0), math.sqrt(2.0)])
|
|
1858
|
+
self._dual = mandel @ np.linalg.pinv(criterion) @ mandel
|
|
1859
|
+
# the tensor strains of a stress (the compliance), and of engineering strains
|
|
1860
|
+
self._compliance = (1.0 + poisson) / young * np.eye(6) - poisson / young * np.outer(_M, _M)
|
|
1861
|
+
|
|
1862
|
+
def scalar(self, h) -> np.ndarray:
|
|
1863
|
+
"""The damage of the points (the variable ``p`` of the outputs)."""
|
|
1864
|
+
return h[:, -1]
|
|
1865
|
+
|
|
1866
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
1867
|
+
dmg = self.damage
|
|
1868
|
+
e = np.ascontiguousarray(e_new, dtype=float)
|
|
1869
|
+
n = e.shape[0]
|
|
1870
|
+
old = np.ascontiguousarray(h_old[:, : self.width])
|
|
1871
|
+
new = np.zeros_like(old)
|
|
1872
|
+
eff = np.zeros((n, 6))
|
|
1873
|
+
c_eff = np.zeros((n, 6, 6))
|
|
1874
|
+
kind = np.full(n, self._plastic, dtype=np.int64)
|
|
1875
|
+
zero = np.zeros(n, dtype=np.int64)
|
|
1876
|
+
failed = self._update(kind, zero, zero, self._data, e, 0.0, float(dt), old, new, eff,
|
|
1877
|
+
c_eff, 0, 1.0, False) # fmt: skip
|
|
1878
|
+
if failed:
|
|
1879
|
+
raise FloatingPointError("damage: the plasticity of the effective stress failed")
|
|
1880
|
+
law_old, d_old = h_old[:, -2], h_old[:, -1]
|
|
1881
|
+
full = 1.0 - dmg.residual
|
|
1882
|
+
broken = law_old >= full # no more to lose
|
|
1883
|
+
if dmg.law == "lemaitre":
|
|
1884
|
+
grow, d_grow = self._lemaitre(e, old, new, eff, c_eff)
|
|
1885
|
+
else:
|
|
1886
|
+
grow, d_grow = self._kachanov(dt, law_old, eff, c_eff)
|
|
1887
|
+
law = np.where(broken, law_old, law_old + grow)
|
|
1888
|
+
breaks = ~broken & (law >= dmg.top) # at its critical damage the point breaks
|
|
1889
|
+
law = np.where(breaks, full, law)
|
|
1890
|
+
active = ~broken & ~breaks
|
|
1891
|
+
rate = 1.0
|
|
1892
|
+
if dmg.viscosity > 0.0: # the damage of the stress follows that of the law
|
|
1893
|
+
ratio = dt / dmg.viscosity if dt > 0.0 else 0.0
|
|
1894
|
+
rate = ratio / (1.0 + ratio)
|
|
1895
|
+
d = np.maximum(d_old + rate * (law - d_old), d_old)
|
|
1896
|
+
stress = (1.0 - d)[:, None] * eff
|
|
1897
|
+
tangent = (1.0 - d)[:, None, None] * c_eff
|
|
1898
|
+
tangent = tangent - _outer(eff, np.where(active[:, None], rate * d_grow, 0.0))
|
|
1899
|
+
return stress, tangent, np.column_stack([new, law, d])
|
|
1900
|
+
|
|
1901
|
+
def _lemaitre(self, e, old, new, eff, c_eff):
|
|
1902
|
+
"""The growth of Lemaitre's damage over a step, ``(Y / S)^s dp`` beyond the
|
|
1903
|
+
threshold, and its derivative by the strains (n, 6)."""
|
|
1904
|
+
dmg = self.damage
|
|
1905
|
+
p_old, p_new = old[:, self._p], new[:, self._p]
|
|
1906
|
+
dp = np.maximum(p_new - np.maximum(p_old, dmg.threshold), 0.0)
|
|
1907
|
+
y, dy = dmg.release_rate(eff, self.young, self.poisson)
|
|
1908
|
+
rate = (y / dmg.S) ** dmg.s
|
|
1909
|
+
grow = rate * dp
|
|
1910
|
+
# dp = sqrt(dep . a⁺ . dep) (sqrt(2/3 dep : dep) for von Mises), dep = eps - C^-1
|
|
1911
|
+
# sigma~ - ep_old (tensor components)
|
|
1912
|
+
dep = new[:, :6] - old[:, :6]
|
|
1913
|
+
whole = np.maximum(p_new - p_old, 0.0)
|
|
1914
|
+
safe = np.where(whole > 0, whole, 1.0)
|
|
1915
|
+
contract = dep @ self._dual / safe[:, None]
|
|
1916
|
+
ddep = np.diag(_HALF)[None] - np.einsum("ij,njk->nik", self._compliance, c_eff)
|
|
1917
|
+
ddp = np.einsum("ni,nik->nk", contract, ddep)
|
|
1918
|
+
ddp = np.where(((dp > 0) & (whole > 0))[:, None], ddp, 0.0)
|
|
1919
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
1920
|
+
drate = np.where(y > 0, dmg.s * rate / np.where(y > 0, y, 1.0), 0.0)
|
|
1921
|
+
dy_de = np.einsum("ni,nik->nk", dy, c_eff)
|
|
1922
|
+
return grow, (drate * dp)[:, None] * dy_de + rate[:, None] * ddp
|
|
1923
|
+
|
|
1924
|
+
def _kachanov(self, dt, d_old, eff, c_eff):
|
|
1925
|
+
"""The growth of Kachanov's damage over a step: the law integrated exactly for the
|
|
1926
|
+
stress of the end of the step, ``(1 - D)^q = (1 - D_old)^q - q (chi / A)^r dt``
|
|
1927
|
+
with ``q = k - r + 1`` (the stress ``chi`` is that of ``(1 - D) sigma~``), and its
|
|
1928
|
+
derivative by the strains (n, 6)."""
|
|
1929
|
+
dmg = self.damage
|
|
1930
|
+
chi, dchi = dmg.creep_stress(eff)
|
|
1931
|
+
q = dmg.k - dmg.r + 1.0
|
|
1932
|
+
rate = (chi / dmg.A) ** dmg.r
|
|
1933
|
+
left = 1.0 - np.minimum(d_old, 1.0 - 1e-12)
|
|
1934
|
+
if abs(q) > 1e-12:
|
|
1935
|
+
power = left**q - q * rate * dt
|
|
1936
|
+
done = power <= 0.0 if q > 0 else np.zeros_like(power, dtype=bool)
|
|
1937
|
+
new_left = np.where(done, 0.0, np.abs(np.where(done, 1.0, power)) ** (1.0 / q))
|
|
1938
|
+
else: # q = 0: ln(1 - D) falls at the rate (chi / A)^r
|
|
1939
|
+
done = np.zeros(len(left), dtype=bool)
|
|
1940
|
+
new_left = left * np.exp(-rate * dt)
|
|
1941
|
+
grow = np.maximum(left - new_left, 0.0)
|
|
1942
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
1943
|
+
safe = np.where(chi > 0, chi, 1.0)
|
|
1944
|
+
slope = np.where(
|
|
1945
|
+
(chi > 0) & ~done & (new_left > 0),
|
|
1946
|
+
dt * dmg.r * rate / safe * np.where(new_left > 0, new_left, 1.0) ** (1.0 - q),
|
|
1947
|
+
0.0,
|
|
1948
|
+
)
|
|
1949
|
+
return grow, slope[:, None] * np.einsum("ni,nik->nk", dchi, c_eff)
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
def damage_from_config(spec):
|
|
1953
|
+
"""The damage law of a mapping of a configuration: Mazars' law of concrete (``law:
|
|
1954
|
+
mazars``), a damage coupled to plasticity (``law: lemaitre`` or ``kachanov``), or the
|
|
1955
|
+
isotropic damage of quasi-brittle solids (:class:`Damage`, without ``law``)."""
|
|
1956
|
+
if isinstance(spec, (Damage, Mazars, DuctileDamage)):
|
|
1957
|
+
return spec
|
|
1958
|
+
if not isinstance(spec, dict):
|
|
1959
|
+
raise ValueError("damage: a mapping of parameters")
|
|
1960
|
+
law = spec.get("law")
|
|
1961
|
+
if law is None:
|
|
1962
|
+
return Damage.from_config(spec)
|
|
1963
|
+
values = {k: v for k, v in spec.items() if k != "law"}
|
|
1964
|
+
if law == "mazars":
|
|
1965
|
+
names = set(Mazars.__dataclass_fields__)
|
|
1966
|
+
missing = sorted({"threshold", "tension", "compression"} - set(values))
|
|
1967
|
+
if missing:
|
|
1968
|
+
raise ValueError(f"damage: Mazars' law needs {missing}")
|
|
1969
|
+
cls, kwargs = Mazars, values
|
|
1970
|
+
elif law in DUCTILE_LAWS:
|
|
1971
|
+
names = set(DuctileDamage.__dataclass_fields__) - {"law"}
|
|
1972
|
+
cls, kwargs = DuctileDamage, {"law": law, **values}
|
|
1973
|
+
else:
|
|
1974
|
+
raise ValueError(f"damage.law: mazars, or one of {DUCTILE_LAWS} with a plasticity")
|
|
1975
|
+
unknown = sorted(set(values) - names)
|
|
1976
|
+
if unknown:
|
|
1977
|
+
raise ValueError(f"damage: unknown keys {unknown}; allowed: {sorted(names)}")
|
|
1978
|
+
return cls(**kwargs)
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
# -- the laws in the solvers -----------------------------------------------------------------
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
class _Logarithmic:
|
|
1985
|
+
"""A law of small strains in the logarithmic strain space of finite strains: it sees
|
|
1986
|
+
``H = 1/2 ln C`` and gives the stress ``T`` conjugate to it, pulled back to the second
|
|
1987
|
+
Piola-Kirchhoff stress ``S = J^T T`` and its tangent (:mod:`morphogen.learning.
|
|
1988
|
+
logarithmic`), as the Hencky points of morphoGen (Miehe, Apel & Lambrecht 2002)."""
|
|
1989
|
+
|
|
1990
|
+
def __init__(self, law):
|
|
1991
|
+
self.law = law
|
|
1992
|
+
self.kind, self.symmetric, self.n_state = law.kind, law.symmetric, law.n_state
|
|
1993
|
+
self.thermal = law.thermal
|
|
1994
|
+
if hasattr(law, "scalar"):
|
|
1995
|
+
self.scalar = law.scalar
|
|
1996
|
+
|
|
1997
|
+
def step(self, e_new, e_old, h_old, dt, dtemp: float = 0.0):
|
|
1998
|
+
from morphogen.learning.logarithmic import _measures, _pullback
|
|
1999
|
+
|
|
2000
|
+
e_new = np.ascontiguousarray(e_new, dtype=float)
|
|
2001
|
+
h = _measures(e_new, 1.0)[0]
|
|
2002
|
+
h0 = _measures(np.ascontiguousarray(e_old, dtype=float), 1.0)[0]
|
|
2003
|
+
with np.errstate(invalid="ignore"):
|
|
2004
|
+
t, k, state = self.law.step(h, h0, h_old, dt, dtemp)
|
|
2005
|
+
s, c = _pullback(e_new, np.ascontiguousarray(t), np.ascontiguousarray(k), 1.0,
|
|
2006
|
+
bool(self.symmetric)) # fmt: skip
|
|
2007
|
+
return s, c, state
|
|
2008
|
+
|
|
2009
|
+
|
|
2010
|
+
@dataclass(frozen=True)
|
|
2011
|
+
class _Spec:
|
|
2012
|
+
"""What the points of the solvers ask of the law of a material (as a learned law):
|
|
2013
|
+
the laws of this module are isotropic, their axes those of the sample."""
|
|
2014
|
+
|
|
2015
|
+
oriented: bool = False
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
def analytic(material) -> bool:
|
|
2019
|
+
"""Whether a material has a behaviour of this module."""
|
|
2020
|
+
return (
|
|
2021
|
+
material.viscoelasticity is not None
|
|
2022
|
+
or material.hyperelasticity is not None
|
|
2023
|
+
or material.damage is not None
|
|
2024
|
+
)
|
|
2025
|
+
|
|
2026
|
+
|
|
2027
|
+
def analytic_model(material, *, finite: bool):
|
|
2028
|
+
"""The law of the points of a material with a ``viscoelasticity``, a
|
|
2029
|
+
``hyperelasticity`` or a ``damage``, in small strains or (``finite``) for the
|
|
2030
|
+
Green-Lagrange strain and the second Piola-Kirchhoff stress: a step ``(strain at the
|
|
2031
|
+
end, strain and state at the start, time step, change of temperature) -> (stress,
|
|
2032
|
+
tangent, state)`` of all the points at once."""
|
|
2033
|
+
bulk, shear = material.moduli()
|
|
2034
|
+
young, poisson = material.young, material.poisson
|
|
2035
|
+
lam = bulk - 2.0 * shear / 3.0
|
|
2036
|
+
visco, hyper, damage = material.viscoelasticity, material.hyperelasticity, material.damage
|
|
2037
|
+
if hyper is not None:
|
|
2038
|
+
if finite:
|
|
2039
|
+
return _Hyperelastic(hyper, bulk, shear, lam, visco)
|
|
2040
|
+
return _Maxwell(visco, bulk, shear) # its elasticity at the natural state
|
|
2041
|
+
if visco is not None:
|
|
2042
|
+
law = _Maxwell(visco, bulk, shear)
|
|
2043
|
+
elif isinstance(damage, DuctileDamage):
|
|
2044
|
+
law = _PlasticDamage(material.plasticity, damage, young, poisson)
|
|
2045
|
+
elif isinstance(damage, Mazars):
|
|
2046
|
+
law = _MazarsLaw(damage, young, poisson)
|
|
2047
|
+
else:
|
|
2048
|
+
law = _DamageLaw(damage, young, poisson)
|
|
2049
|
+
return _Logarithmic(law) if finite else law
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
def analytic_law(material, *, finite: bool, expansion=None):
|
|
2053
|
+
"""The law of the points of a material of this module for the solvers (the seam of
|
|
2054
|
+
the learned laws, :class:`~morphogen.learning.behaviour.LearnedLaw`); ``expansion``:
|
|
2055
|
+
its thermal expansion tensor, the thermal strain taken out of the strain it sees."""
|
|
2056
|
+
from morphogen.learning.behaviour import LearnedLaw
|
|
2057
|
+
|
|
2058
|
+
if expansion is not None:
|
|
2059
|
+
expansion = np.asarray(expansion, dtype=float).reshape(3, 3)
|
|
2060
|
+
expansion = 0.5 * (expansion + expansion.T) if np.any(expansion) else None
|
|
2061
|
+
return LearnedLaw(_Spec(), analytic_model(material, finite=finite), bool(finite), expansion)
|