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,454 @@
|
|
|
1
|
+
"""Selective reduced integration of the 10-node tetrahedra: the volume change of each
|
|
2
|
+
element taken as its mean (``integration="bbar"`` of the finite element problems).
|
|
3
|
+
|
|
4
|
+
A displacement element whose strain is integrated at every point enforces, as a phase
|
|
5
|
+
becomes incompressible (Poisson's ratio near 1/2: elastomers; plastic flow), ``div u =
|
|
6
|
+
0`` at each of its points: four constraints per 10-node tetrahedron, as many as the mesh
|
|
7
|
+
has degrees of freedom to spare, and the element *locks* — its stresses oscillate and
|
|
8
|
+
its displacements fall short. Integrating the volumetric part of the energy at one point
|
|
9
|
+
(the mean over the element) and the rest fully leaves one constraint per element
|
|
10
|
+
(Nagtegaal, Parks & Rice 1974; the mean dilatation, or ``B``-bar, of Hughes 1980;
|
|
11
|
+
equivalent to a mixed element with a pressure and a dilatation uniform in each element,
|
|
12
|
+
Simo, Taylor & Pister 1985).
|
|
13
|
+
|
|
14
|
+
Small strains: the trace of the strain of each point is replaced by its mean over the
|
|
15
|
+
element, ``eps_bar = eps + (theta_bar - tr eps) 1 / 3``, ``theta_bar = sum_g w_g tr
|
|
16
|
+
eps_g / V``. Finite strains (``F``-bar, de Souza Neto, Peric, Dutko & Owen 1996): the
|
|
17
|
+
gradient of each point is scaled to the geometric mean of the Jacobians of the element,
|
|
18
|
+
``F_bar = alpha F``, ``alpha = (J_bar / J)^(1/3)``, ``ln J_bar = sum_g w_g ln J_g / V``.
|
|
19
|
+
The behaviours are integrated with these measures, and the forces are the derivatives
|
|
20
|
+
of their energy, so that the tangent is symmetric whenever those of the points are: the
|
|
21
|
+
stresses of the points are replaced by their conjugates, ``s + (p_bar - p) 1`` (the
|
|
22
|
+
deviator of the point and the mean pressure of the element) and ``alpha P + (tau_bar -
|
|
23
|
+
tau) F^-T`` (``tau = alpha P : F / 3``), as the voxels of the FFT solver do
|
|
24
|
+
(:mod:`morphogen.homogenization.kernels`).
|
|
25
|
+
|
|
26
|
+
The tangent of an element is ``sum_g w_g G_g^T M_g G_g + q_L c^T + c q_R^T + k c c^T``:
|
|
27
|
+
the usual sum over the points with modified moduli ``M_g``, and a term of rank two
|
|
28
|
+
through the mean operator ``c = sum_g w_g G_g^T f_g / V`` of the volume change (``f = 1``
|
|
29
|
+
in small strains, ``F^-T`` in finite strains; ``G`` the strain or gradient operator of a
|
|
30
|
+
point). Small strains, ``P = I - 1 (x) 1 / 3``: ``M = P C P``, ``q_L = sum w G^T (C 1 - k
|
|
31
|
+
1 / 3) / 3``, ``k = 1 . C 1``. Finite strains, with ``a = A F``, ``b = A^T F``, ``s = F .
|
|
32
|
+
a`` (``A = dP/dF`` at ``F_bar``, ``9 x 9``): ``M = alpha^2 (A - a (x) f / 3 - f (x) b / 3
|
|
33
|
+
+ s f (x) f / 9) - alpha (f (x) P + P (x) f) / 3 + tau f (x) f / 3 + (tau - tau_bar) B``,
|
|
34
|
+
``B_(ci)(ab) = f_ai f_cb`` (the second derivative of ``-ln J``), ``q_L = sum w G^T
|
|
35
|
+
(alpha^2 (a - s f / 3) / 3 + alpha P / 3 - tau f / 3)`` and ``k = sum w (alpha^2 s / 9 +
|
|
36
|
+
tau / 3)``.
|
|
37
|
+
|
|
38
|
+
A 4-node tetrahedron has one point: its strain is its mean, and these measures change
|
|
39
|
+
nothing.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
from __future__ import annotations
|
|
43
|
+
|
|
44
|
+
import math
|
|
45
|
+
|
|
46
|
+
import numpy as np
|
|
47
|
+
from numba import njit, prange
|
|
48
|
+
|
|
49
|
+
from morphogen.homogenization.fe import (
|
|
50
|
+
CHUNKS,
|
|
51
|
+
INTEGRATIONS,
|
|
52
|
+
_geometry,
|
|
53
|
+
_point_gradients,
|
|
54
|
+
integration_of,
|
|
55
|
+
nearly_incompressible,
|
|
56
|
+
)
|
|
57
|
+
from morphogen.homogenization.kernels import _det3, _inverse_transpose
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@njit(parallel=True, cache=True)
|
|
61
|
+
def mean_strains(eps, wts, ng):
|
|
62
|
+
"""``B``-bar: the trace of the strains of the points (points x 6) replaced, in place,
|
|
63
|
+
by its mean over each element (``ng`` points, weights ``wts``)."""
|
|
64
|
+
for e in prange(eps.shape[0] // ng):
|
|
65
|
+
vol = 0.0
|
|
66
|
+
mean = 0.0
|
|
67
|
+
for g in range(ng):
|
|
68
|
+
i = e * ng + g
|
|
69
|
+
vol += wts[i]
|
|
70
|
+
mean += wts[i] * (eps[i, 0] + eps[i, 1] + eps[i, 2])
|
|
71
|
+
mean /= vol
|
|
72
|
+
for g in range(ng):
|
|
73
|
+
i = e * ng + g
|
|
74
|
+
shift = (mean - (eps[i, 0] + eps[i, 1] + eps[i, 2])) / 3.0
|
|
75
|
+
for r in range(3):
|
|
76
|
+
eps[i, r] += shift
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@njit(parallel=True, cache=True)
|
|
80
|
+
def mean_gradients(hg, wts, ng, base):
|
|
81
|
+
"""``F``-bar: the displacement gradients of the points (points x 9) kept in ``base``
|
|
82
|
+
and replaced, in place, by ``alpha F - 1``, the gradients scaled to the geometric
|
|
83
|
+
mean of the Jacobians of each element. An element with an inverted point keeps its
|
|
84
|
+
gradients (the behaviours fail there, and the step is divided)."""
|
|
85
|
+
for e in prange(hg.shape[0] // ng):
|
|
86
|
+
f = np.empty((3, 3))
|
|
87
|
+
logs = np.empty(ng)
|
|
88
|
+
vol = 0.0
|
|
89
|
+
mean = 0.0
|
|
90
|
+
valid = True
|
|
91
|
+
for g in range(ng):
|
|
92
|
+
i = e * ng + g
|
|
93
|
+
for k in range(9):
|
|
94
|
+
base[i, k] = hg[i, k]
|
|
95
|
+
f[k // 3, k % 3] = hg[i, k] + (1.0 if k % 4 == 0 else 0.0)
|
|
96
|
+
det = _det3(f)
|
|
97
|
+
if det <= 0.0:
|
|
98
|
+
valid = False
|
|
99
|
+
break
|
|
100
|
+
logs[g] = math.log(det)
|
|
101
|
+
vol += wts[i]
|
|
102
|
+
mean += wts[i] * logs[g]
|
|
103
|
+
if not valid:
|
|
104
|
+
for g in range(ng):
|
|
105
|
+
i = e * ng + g
|
|
106
|
+
for k in range(9):
|
|
107
|
+
base[i, k] = hg[i, k]
|
|
108
|
+
continue
|
|
109
|
+
mean /= vol
|
|
110
|
+
for g in range(ng):
|
|
111
|
+
i = e * ng + g
|
|
112
|
+
alpha = math.exp((mean - logs[g]) / 3.0)
|
|
113
|
+
for k in range(9):
|
|
114
|
+
one = 1.0 if k % 4 == 0 else 0.0
|
|
115
|
+
hg[i, k] = alpha * (base[i, k] + one) - one
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@njit(parallel=True, cache=True)
|
|
119
|
+
def conjugate_stresses(sigma, wts, ng):
|
|
120
|
+
"""The stresses of the points (points x 6) replaced, in place, by those conjugate to
|
|
121
|
+
the strains of ``B``-bar: their deviator and the mean pressure of the element."""
|
|
122
|
+
for e in prange(sigma.shape[0] // ng):
|
|
123
|
+
vol = 0.0
|
|
124
|
+
mean = 0.0
|
|
125
|
+
for g in range(ng):
|
|
126
|
+
i = e * ng + g
|
|
127
|
+
vol += wts[i]
|
|
128
|
+
mean += wts[i] * (sigma[i, 0] + sigma[i, 1] + sigma[i, 2])
|
|
129
|
+
mean /= 3.0 * vol
|
|
130
|
+
for g in range(ng):
|
|
131
|
+
i = e * ng + g
|
|
132
|
+
shift = mean - (sigma[i, 0] + sigma[i, 1] + sigma[i, 2]) / 3.0
|
|
133
|
+
for r in range(3):
|
|
134
|
+
sigma[i, r] += shift
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@njit(cache=True, inline="always")
|
|
138
|
+
def _element_scales(base, wts, ng, e, f, fit, alpha, finv):
|
|
139
|
+
"""The factors ``alpha`` of the points of element ``e`` and their ``F^-T`` (``finv``,
|
|
140
|
+
points x 9), from the gradients ``base``; false for an inverted element."""
|
|
141
|
+
vol = 0.0
|
|
142
|
+
mean = 0.0
|
|
143
|
+
for g in range(ng):
|
|
144
|
+
i = e * ng + g
|
|
145
|
+
for k in range(9):
|
|
146
|
+
f[k // 3, k % 3] = base[i, k] + (1.0 if k % 4 == 0 else 0.0)
|
|
147
|
+
det = _det3(f)
|
|
148
|
+
if det <= 0.0:
|
|
149
|
+
return False
|
|
150
|
+
_inverse_transpose(f, det, fit)
|
|
151
|
+
for k in range(9):
|
|
152
|
+
finv[g, k] = fit[k // 3, k % 3]
|
|
153
|
+
alpha[g] = math.log(det)
|
|
154
|
+
vol += wts[i]
|
|
155
|
+
mean += wts[i] * alpha[g]
|
|
156
|
+
mean /= vol
|
|
157
|
+
for g in range(ng):
|
|
158
|
+
alpha[g] = math.exp((mean - alpha[g]) / 3.0)
|
|
159
|
+
return True
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@njit(parallel=True, cache=True)
|
|
163
|
+
def conjugate_piola(pk1, wts, ng, base, kept):
|
|
164
|
+
"""The first Piola-Kirchhoff stresses of the points (points x 9, those of the
|
|
165
|
+
behaviours at ``F_bar``) kept in ``kept`` and replaced, in place, by those conjugate
|
|
166
|
+
to the gradients ``base`` of the points: ``alpha P + (tau_bar - tau) F^-T``."""
|
|
167
|
+
for e in prange(pk1.shape[0] // ng):
|
|
168
|
+
f = np.empty((3, 3))
|
|
169
|
+
fit = np.empty((3, 3))
|
|
170
|
+
alpha = np.empty(ng)
|
|
171
|
+
tau = np.empty(ng)
|
|
172
|
+
finv = np.empty((ng, 9))
|
|
173
|
+
for g in range(ng):
|
|
174
|
+
i = e * ng + g
|
|
175
|
+
for k in range(9):
|
|
176
|
+
kept[i, k] = pk1[i, k]
|
|
177
|
+
if not _element_scales(base, wts, ng, e, f, fit, alpha, finv):
|
|
178
|
+
continue
|
|
179
|
+
vol = 0.0
|
|
180
|
+
mean = 0.0
|
|
181
|
+
for g in range(ng):
|
|
182
|
+
i = e * ng + g
|
|
183
|
+
pf = 0.0
|
|
184
|
+
for k in range(9):
|
|
185
|
+
pf += pk1[i, k] * (base[i, k] + (1.0 if k % 4 == 0 else 0.0))
|
|
186
|
+
tau[g] = alpha[g] * pf / 3.0
|
|
187
|
+
vol += wts[i]
|
|
188
|
+
mean += wts[i] * tau[g]
|
|
189
|
+
mean /= vol
|
|
190
|
+
for g in range(ng):
|
|
191
|
+
i = e * ng + g
|
|
192
|
+
for k in range(9):
|
|
193
|
+
pk1[i, k] = alpha[g] * pk1[i, k] + (mean - tau[g]) * finv[g, k]
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@njit(parallel=True, cache=True)
|
|
197
|
+
def bar_moduli(tangent, moduli, vl, vr, kappa):
|
|
198
|
+
"""Small strains: the moduli ``P C P`` of the points, the vectors ``(C 1 - k 1 / 3) /
|
|
199
|
+
3`` (``vl``) and ``(C^T 1 - k 1 / 3) / 3`` (``vr``) and ``k / 9`` (see the module)."""
|
|
200
|
+
for i in prange(tangent.shape[0]):
|
|
201
|
+
d = tangent[i]
|
|
202
|
+
cm = np.empty(6)
|
|
203
|
+
mc = np.empty(6)
|
|
204
|
+
k = 0.0
|
|
205
|
+
for r in range(6):
|
|
206
|
+
cm[r] = d[r, 0] + d[r, 1] + d[r, 2]
|
|
207
|
+
mc[r] = d[0, r] + d[1, r] + d[2, r]
|
|
208
|
+
k = cm[0] + cm[1] + cm[2]
|
|
209
|
+
for r in range(6):
|
|
210
|
+
mr = 1.0 if r < 3 else 0.0
|
|
211
|
+
vl[i, r] = (cm[r] - k * mr / 3.0) / 3.0
|
|
212
|
+
vr[i, r] = (mc[r] - k * mr / 3.0) / 3.0
|
|
213
|
+
for s in range(6):
|
|
214
|
+
ms = 1.0 if s < 3 else 0.0
|
|
215
|
+
moduli[i, r, s] = d[r, s] - (cm[r] * ms + mr * mc[s]) / 3.0 + k * mr * ms / 9.0
|
|
216
|
+
kappa[i] = k / 9.0
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@njit(parallel=True, cache=True)
|
|
220
|
+
def bar_moduli_finite(tangent, wts, ng, base, kept, moduli, vl, vr, kappa, fvec):
|
|
221
|
+
"""Finite strains: the moduli ``M`` of the points, the vectors of the terms of rank
|
|
222
|
+
two, their scalar and ``F^-T`` (``fvec``), from the tangents ``dP/dF`` at ``F_bar``,
|
|
223
|
+
the gradients ``base`` and the stresses ``kept`` of the behaviours (see the module).
|
|
224
|
+
An inverted element keeps the moduli of its points (and no term of rank two)."""
|
|
225
|
+
for e in prange(tangent.shape[0] // ng):
|
|
226
|
+
f = np.empty((3, 3))
|
|
227
|
+
fit = np.empty((3, 3))
|
|
228
|
+
alpha = np.empty(ng)
|
|
229
|
+
tau = np.empty(ng)
|
|
230
|
+
finv = np.empty((ng, 9))
|
|
231
|
+
fv = np.empty(9)
|
|
232
|
+
a = np.empty(9)
|
|
233
|
+
b = np.empty(9)
|
|
234
|
+
if not _element_scales(base, wts, ng, e, f, fit, alpha, finv):
|
|
235
|
+
for g in range(ng):
|
|
236
|
+
i = e * ng + g
|
|
237
|
+
kappa[i] = 0.0
|
|
238
|
+
for r in range(9):
|
|
239
|
+
vl[i, r] = 0.0
|
|
240
|
+
vr[i, r] = 0.0
|
|
241
|
+
fvec[i, r] = 0.0
|
|
242
|
+
for s in range(9):
|
|
243
|
+
moduli[i, r, s] = tangent[i, r, s]
|
|
244
|
+
continue
|
|
245
|
+
vol = 0.0
|
|
246
|
+
mean = 0.0
|
|
247
|
+
for g in range(ng):
|
|
248
|
+
i = e * ng + g
|
|
249
|
+
pf = 0.0
|
|
250
|
+
for k in range(9):
|
|
251
|
+
pf += kept[i, k] * (base[i, k] + (1.0 if k % 4 == 0 else 0.0))
|
|
252
|
+
tau[g] = alpha[g] * pf / 3.0
|
|
253
|
+
vol += wts[i]
|
|
254
|
+
mean += wts[i] * tau[g]
|
|
255
|
+
mean /= vol
|
|
256
|
+
for g in range(ng):
|
|
257
|
+
i = e * ng + g
|
|
258
|
+
al = alpha[g]
|
|
259
|
+
t = tau[g]
|
|
260
|
+
d = tangent[i]
|
|
261
|
+
fi = finv[g]
|
|
262
|
+
for k in range(9):
|
|
263
|
+
fv[k] = base[i, k] + (1.0 if k % 4 == 0 else 0.0)
|
|
264
|
+
s = 0.0
|
|
265
|
+
for r in range(9):
|
|
266
|
+
acc_a = 0.0
|
|
267
|
+
acc_b = 0.0
|
|
268
|
+
for c in range(9):
|
|
269
|
+
acc_a += d[r, c] * fv[c]
|
|
270
|
+
acc_b += d[c, r] * fv[c]
|
|
271
|
+
a[r] = acc_a
|
|
272
|
+
b[r] = acc_b
|
|
273
|
+
for r in range(9):
|
|
274
|
+
s += fv[r] * a[r]
|
|
275
|
+
for r in range(9):
|
|
276
|
+
fvec[i, r] = fi[r]
|
|
277
|
+
vl[i, r] = al * al * (a[r] - s * fi[r] / 3.0) / 3.0 + al * kept[i, r] / 3.0
|
|
278
|
+
vl[i, r] -= t * fi[r] / 3.0
|
|
279
|
+
vr[i, r] = al * al * (b[r] - s * fi[r] / 3.0) / 3.0 + al * kept[i, r] / 3.0
|
|
280
|
+
vr[i, r] -= t * fi[r] / 3.0
|
|
281
|
+
for c in range(9):
|
|
282
|
+
value = (
|
|
283
|
+
al
|
|
284
|
+
* al
|
|
285
|
+
* (
|
|
286
|
+
d[r, c]
|
|
287
|
+
- a[r] * fi[c] / 3.0
|
|
288
|
+
- fi[r] * b[c] / 3.0
|
|
289
|
+
+ s * fi[r] * fi[c] / 9.0
|
|
290
|
+
)
|
|
291
|
+
)
|
|
292
|
+
value -= al * (fi[r] * kept[i, c] + kept[i, r] * fi[c]) / 3.0
|
|
293
|
+
value += t * fi[r] * fi[c] / 3.0
|
|
294
|
+
# B_(ci)(ab) = f_ai f_cb, with r = (c, i) and the column (a, b)
|
|
295
|
+
value += (t - mean) * fi[3 * (c // 3) + r % 3] * fi[3 * (r // 3) + c % 3]
|
|
296
|
+
moduli[i, r, c] = value
|
|
297
|
+
kappa[i] = al * al * s / 9.0 + t / 3.0
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
@njit(cache=True, inline="always")
|
|
301
|
+
def _operator(finite, grad, nn, gop):
|
|
302
|
+
"""The strain operator (6 x 3 nn: Voigt, engineering shears) or the gradient
|
|
303
|
+
operator (9 x 3 nn: rows ``3 i + j``) of a point, by columns: ``gop[b, k, :]``."""
|
|
304
|
+
for b in range(nn):
|
|
305
|
+
gx, gy, gz = grad[b, 0], grad[b, 1], grad[b, 2]
|
|
306
|
+
for k in range(3):
|
|
307
|
+
for r in range(gop.shape[2]):
|
|
308
|
+
gop[b, k, r] = 0.0
|
|
309
|
+
if finite:
|
|
310
|
+
for k in range(3):
|
|
311
|
+
gop[b, k, 3 * k] = gx
|
|
312
|
+
gop[b, k, 3 * k + 1] = gy
|
|
313
|
+
gop[b, k, 3 * k + 2] = gz
|
|
314
|
+
else:
|
|
315
|
+
gop[b, 0, 0] = gx
|
|
316
|
+
gop[b, 0, 4] = gz
|
|
317
|
+
gop[b, 0, 5] = gy
|
|
318
|
+
gop[b, 1, 1] = gy
|
|
319
|
+
gop[b, 1, 3] = gz
|
|
320
|
+
gop[b, 1, 5] = gx
|
|
321
|
+
gop[b, 2, 2] = gz
|
|
322
|
+
gop[b, 2, 3] = gy
|
|
323
|
+
gop[b, 2, 4] = gx
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
@njit(parallel=True, cache=True)
|
|
327
|
+
def fill_bar(nodes, elements, order, gp, wts, finite, moduli, vl, vr, kappa, fvec, indptr_n,
|
|
328
|
+
indices_n, by_colour, colours, data): # fmt: skip
|
|
329
|
+
"""CSR values of the tangent of ``B``-bar or ``F``-bar (node-level pattern): for
|
|
330
|
+
each element, ``sum_g w_g G_g^T M_g G_g + q_L c^T + c q_R^T + k c c^T`` (see the
|
|
331
|
+
module; ``fvec``: the vectors ``f`` of the points in finite strains, unused in small
|
|
332
|
+
strains, where ``f = 1``), the elements of a colour in parallel (``by_colour``,
|
|
333
|
+
``colours``: :func:`~morphogen.homogenization.fe.element_colours`)."""
|
|
334
|
+
nn = elements.shape[1]
|
|
335
|
+
ng = gp.shape[0]
|
|
336
|
+
nc = 9 if finite else 6
|
|
337
|
+
nd = 3 * nn
|
|
338
|
+
for i in prange(data.size):
|
|
339
|
+
data[i] = 0.0
|
|
340
|
+
xs = np.empty((CHUNKS, 4, 3))
|
|
341
|
+
gls = np.empty((CHUNKS, 4, 3))
|
|
342
|
+
devs = np.empty((CHUNKS, 6, 3))
|
|
343
|
+
grads = np.empty((CHUNKS, nn, 3))
|
|
344
|
+
gops = np.empty((CHUNKS, nn, 3, nc))
|
|
345
|
+
mgs = np.empty((CHUNKS, nn, 3, nc))
|
|
346
|
+
kes = np.empty((CHUNKS, nd, nd))
|
|
347
|
+
cs = np.empty((CHUNKS, nd))
|
|
348
|
+
qls = np.empty((CHUNKS, nd))
|
|
349
|
+
qrs = np.empty((CHUNKS, nd))
|
|
350
|
+
places = np.empty((CHUNKS, nn, nn), dtype=np.int64)
|
|
351
|
+
for colour in range(colours.size - 1):
|
|
352
|
+
first = colours[colour]
|
|
353
|
+
count = colours[colour + 1] - first
|
|
354
|
+
chunks = min(count, CHUNKS)
|
|
355
|
+
for chunk in prange(chunks):
|
|
356
|
+
x = xs[chunk]
|
|
357
|
+
gl = gls[chunk]
|
|
358
|
+
dev = devs[chunk]
|
|
359
|
+
grad = grads[chunk]
|
|
360
|
+
gop = gops[chunk]
|
|
361
|
+
mg = mgs[chunk]
|
|
362
|
+
ke = kes[chunk]
|
|
363
|
+
c = cs[chunk]
|
|
364
|
+
ql = qls[chunk]
|
|
365
|
+
qr = qrs[chunk]
|
|
366
|
+
pos = places[chunk]
|
|
367
|
+
for j in range(first + chunk * count // chunks, first + (chunk + 1) * count // chunks):
|
|
368
|
+
e = by_colour[j]
|
|
369
|
+
_, curved = _geometry(nodes, elements, e, x, gl, dev)
|
|
370
|
+
ke[:, :] = 0.0
|
|
371
|
+
c[:] = 0.0
|
|
372
|
+
ql[:] = 0.0
|
|
373
|
+
qr[:] = 0.0
|
|
374
|
+
kap = 0.0
|
|
375
|
+
vol = 0.0
|
|
376
|
+
for g in range(ng):
|
|
377
|
+
_point_gradients(order, curved, gl, dev, gp[g], grad)
|
|
378
|
+
_operator(finite, grad, nn, gop)
|
|
379
|
+
i = e * ng + g
|
|
380
|
+
w = wts[i]
|
|
381
|
+
m = moduli[i]
|
|
382
|
+
vol += w
|
|
383
|
+
kap += w * kappa[i]
|
|
384
|
+
for b in range(nn):
|
|
385
|
+
for k in range(3):
|
|
386
|
+
col = gop[b, k]
|
|
387
|
+
fc = 0.0
|
|
388
|
+
fl = 0.0
|
|
389
|
+
fr = 0.0
|
|
390
|
+
for r in range(nc):
|
|
391
|
+
if finite:
|
|
392
|
+
fc += col[r] * fvec[i, r]
|
|
393
|
+
elif r < 3:
|
|
394
|
+
fc += col[r]
|
|
395
|
+
fl += col[r] * vl[i, r]
|
|
396
|
+
fr += col[r] * vr[i, r]
|
|
397
|
+
acc = 0.0
|
|
398
|
+
for s in range(nc):
|
|
399
|
+
acc += m[r, s] * col[s]
|
|
400
|
+
mg[b, k, r] = acc
|
|
401
|
+
c[3 * b + k] += w * fc
|
|
402
|
+
ql[3 * b + k] += w * fl
|
|
403
|
+
qr[3 * b + k] += w * fr
|
|
404
|
+
for a in range(nn):
|
|
405
|
+
for k in range(3):
|
|
406
|
+
row = gop[a, k]
|
|
407
|
+
for b in range(nn):
|
|
408
|
+
for k2 in range(3):
|
|
409
|
+
acc = 0.0
|
|
410
|
+
for r in range(nc):
|
|
411
|
+
acc += row[r] * mg[b, k2, r]
|
|
412
|
+
ke[3 * a + k, 3 * b + k2] += w * acc
|
|
413
|
+
for a in range(nd):
|
|
414
|
+
c[a] /= vol
|
|
415
|
+
for a in range(nd):
|
|
416
|
+
for b in range(nd):
|
|
417
|
+
ke[a, b] += ql[a] * c[b] + c[a] * qr[b] + kap * c[a] * c[b]
|
|
418
|
+
for a in range(nn):
|
|
419
|
+
na = elements[e, a]
|
|
420
|
+
lo = indptr_n[na]
|
|
421
|
+
hi = indptr_n[na + 1]
|
|
422
|
+
for b in range(nn):
|
|
423
|
+
nb = elements[e, b]
|
|
424
|
+
left, right = lo, hi
|
|
425
|
+
while left < right:
|
|
426
|
+
mid = (left + right) // 2
|
|
427
|
+
if indices_n[mid] < nb:
|
|
428
|
+
left = mid + 1
|
|
429
|
+
else:
|
|
430
|
+
right = mid
|
|
431
|
+
pos[a, b] = left - lo
|
|
432
|
+
for a in range(nn):
|
|
433
|
+
na = elements[e, a]
|
|
434
|
+
length = indptr_n[na + 1] - indptr_n[na]
|
|
435
|
+
for k in range(3):
|
|
436
|
+
start = 9 * indptr_n[na] + k * 3 * length
|
|
437
|
+
for b in range(nn):
|
|
438
|
+
p = pos[a, b]
|
|
439
|
+
for k2 in range(3):
|
|
440
|
+
data[start + p * 3 + k2] += ke[3 * a + k, 3 * b + k2]
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
__all__ = [
|
|
444
|
+
"INTEGRATIONS",
|
|
445
|
+
"bar_moduli",
|
|
446
|
+
"bar_moduli_finite",
|
|
447
|
+
"conjugate_piola",
|
|
448
|
+
"conjugate_stresses",
|
|
449
|
+
"fill_bar",
|
|
450
|
+
"integration_of",
|
|
451
|
+
"mean_gradients",
|
|
452
|
+
"mean_strains",
|
|
453
|
+
"nearly_incompressible",
|
|
454
|
+
]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Trilinear hexahedra (Q1) on a regular voxel grid.
|
|
2
|
+
|
|
3
|
+
Every voxel is one 8-node element. The corners follow the VTK/Abaqus order of
|
|
4
|
+
:data:`morphogen.mesh.voxel.HEX_CORNERS`; the degrees of freedom of an elastic element
|
|
5
|
+
are ordered node by node, ``(u1, u2, u3)`` at corner 0, then corner 1, etc.
|
|
6
|
+
|
|
7
|
+
Strains and stresses use the Voigt order ``(11, 22, 33, 23, 31, 12)`` with engineering
|
|
8
|
+
shear strains (``gamma_23 = 2 eps_23``) and tensor shear stresses, so that
|
|
9
|
+
``sigma = D eps`` and ``sigma . eps`` is the energy density.
|
|
10
|
+
|
|
11
|
+
All the matrices are integrated exactly with 2 x 2 x 2 Gauss points: the integrands are
|
|
12
|
+
polynomials of degree at most 2 in each coordinate on a rectangular voxel.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from functools import lru_cache
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from morphogen.mesh.voxel import HEX_CORNERS
|
|
23
|
+
|
|
24
|
+
VOIGT = ((0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (0, 1))
|
|
25
|
+
VOIGT_NAMES = ("11", "22", "33", "23", "31", "12")
|
|
26
|
+
#: m in D = lambda m m^T + mu diag(2, 2, 2, 1, 1, 1)
|
|
27
|
+
VOIGT_TRACE = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
|
|
28
|
+
SHEAR_WEIGHTS = np.array([2.0, 2.0, 2.0, 1.0, 1.0, 1.0])
|
|
29
|
+
|
|
30
|
+
_GAUSS_1D = (0.5 - 0.5 / np.sqrt(3.0), 0.5 + 0.5 / np.sqrt(3.0))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def gauss_points() -> np.ndarray:
|
|
34
|
+
"""The 8 Gauss points of the reference cube [0, 1]^3."""
|
|
35
|
+
g = _GAUSS_1D
|
|
36
|
+
return np.array([[a, b, c] for c in g for b in g for a in g])
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def shape_gradients(xi: np.ndarray, spacing) -> np.ndarray:
|
|
40
|
+
"""Gradients (3 x 8) of the 8 shape functions at the local point ``xi`` in [0, 1]^3."""
|
|
41
|
+
h = np.asarray(spacing, dtype=float)
|
|
42
|
+
grad = np.empty((3, 8))
|
|
43
|
+
for a, corner in enumerate(HEX_CORNERS):
|
|
44
|
+
phi = np.where(corner == 1, xi, 1.0 - xi)
|
|
45
|
+
dphi = np.where(corner == 1, 1.0, -1.0)
|
|
46
|
+
for d in range(3):
|
|
47
|
+
others = [phi[e] for e in range(3) if e != d]
|
|
48
|
+
grad[d, a] = dphi[d] / h[d] * others[0] * others[1]
|
|
49
|
+
return grad
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def strain_matrix(grad: np.ndarray) -> np.ndarray:
|
|
53
|
+
"""Strain-displacement matrix B (6 x 24) built from the shape gradients (3 x 8)."""
|
|
54
|
+
b = np.zeros((6, 24))
|
|
55
|
+
for a in range(8):
|
|
56
|
+
gx, gy, gz = grad[:, a]
|
|
57
|
+
c = 3 * a
|
|
58
|
+
b[0, c] = gx
|
|
59
|
+
b[1, c + 1] = gy
|
|
60
|
+
b[2, c + 2] = gz
|
|
61
|
+
b[3, c + 1], b[3, c + 2] = gz, gy
|
|
62
|
+
b[4, c], b[4, c + 2] = gz, gx
|
|
63
|
+
b[5, c], b[5, c + 1] = gy, gx
|
|
64
|
+
return b
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def isotropic_stiffness(lam: float, mu: float) -> np.ndarray:
|
|
68
|
+
"""Elasticity matrix D (6 x 6, Voigt, engineering shear strains)."""
|
|
69
|
+
return lam * np.outer(VOIGT_TRACE, VOIGT_TRACE) + mu * np.diag(SHEAR_WEIGHTS)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True)
|
|
73
|
+
class HexElement:
|
|
74
|
+
"""Reference matrices of one voxel element of edge lengths ``spacing``.
|
|
75
|
+
|
|
76
|
+
The stiffness of an isotropic element is ``lam * k_lambda + mu * k_mu``; the
|
|
77
|
+
conductance of a conducting element is ``k * k_thermal``.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
spacing: tuple[float, float, float]
|
|
81
|
+
volume: float
|
|
82
|
+
weight: float
|
|
83
|
+
b_gauss: np.ndarray
|
|
84
|
+
b_mean: np.ndarray
|
|
85
|
+
k_lambda: np.ndarray
|
|
86
|
+
k_mu: np.ndarray
|
|
87
|
+
g_gauss: np.ndarray
|
|
88
|
+
g_mean: np.ndarray
|
|
89
|
+
k_thermal: np.ndarray
|
|
90
|
+
|
|
91
|
+
def stiffness(self, lam: float, mu: float) -> np.ndarray:
|
|
92
|
+
return lam * self.k_lambda + mu * self.k_mu
|
|
93
|
+
|
|
94
|
+
def affine_displacement(self, strain_voigt) -> np.ndarray:
|
|
95
|
+
"""Nodal displacements (24) of the affine field E x, x measured from corner 0."""
|
|
96
|
+
e = voigt_to_tensor(strain_voigt, strain=True)
|
|
97
|
+
x = HEX_CORNERS * np.asarray(self.spacing)
|
|
98
|
+
return (x @ e.T).ravel()
|
|
99
|
+
|
|
100
|
+
def affine_temperature(self, gradient) -> np.ndarray:
|
|
101
|
+
"""Nodal temperatures (8) of the affine field G . x, x measured from corner 0."""
|
|
102
|
+
return HEX_CORNERS * np.asarray(self.spacing) @ np.asarray(gradient, dtype=float)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@lru_cache(maxsize=32)
|
|
106
|
+
def hex_element(spacing: tuple[float, float, float]) -> HexElement:
|
|
107
|
+
"""Matrices of the voxel element (cached by spacing)."""
|
|
108
|
+
h = tuple(float(s) for s in spacing)
|
|
109
|
+
volume = h[0] * h[1] * h[2]
|
|
110
|
+
weight = volume / 8.0
|
|
111
|
+
grads = np.array([shape_gradients(xi, h) for xi in gauss_points()])
|
|
112
|
+
b_gauss = np.array([strain_matrix(g) for g in grads])
|
|
113
|
+
m = np.outer(VOIGT_TRACE, VOIGT_TRACE)
|
|
114
|
+
s = np.diag(SHEAR_WEIGHTS)
|
|
115
|
+
k_lambda = weight * sum(b.T @ m @ b for b in b_gauss)
|
|
116
|
+
k_mu = weight * sum(b.T @ s @ b for b in b_gauss)
|
|
117
|
+
k_thermal = weight * sum(g.T @ g for g in grads)
|
|
118
|
+
for mat in (k_lambda, k_mu, k_thermal, b_gauss, grads):
|
|
119
|
+
mat.setflags(write=False)
|
|
120
|
+
b_mean = b_gauss.mean(axis=0)
|
|
121
|
+
g_mean = grads.mean(axis=0)
|
|
122
|
+
b_mean.setflags(write=False)
|
|
123
|
+
g_mean.setflags(write=False)
|
|
124
|
+
return HexElement(
|
|
125
|
+
spacing=h,
|
|
126
|
+
volume=volume,
|
|
127
|
+
weight=weight,
|
|
128
|
+
b_gauss=b_gauss,
|
|
129
|
+
b_mean=b_mean,
|
|
130
|
+
k_lambda=0.5 * (k_lambda + k_lambda.T),
|
|
131
|
+
k_mu=0.5 * (k_mu + k_mu.T),
|
|
132
|
+
g_gauss=grads,
|
|
133
|
+
g_mean=g_mean,
|
|
134
|
+
k_thermal=0.5 * (k_thermal + k_thermal.T),
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def voigt_to_tensor(v, *, strain: bool) -> np.ndarray:
|
|
139
|
+
"""3 x 3 tensor of a Voigt vector (engineering shear components if ``strain``)."""
|
|
140
|
+
v = np.asarray(v, dtype=float)
|
|
141
|
+
t = np.empty((3, 3))
|
|
142
|
+
f = 0.5 if strain else 1.0
|
|
143
|
+
for i, (a, b) in enumerate(VOIGT):
|
|
144
|
+
val = v[i] if i < 3 else f * v[i]
|
|
145
|
+
t[a, b] = t[b, a] = val
|
|
146
|
+
return t
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def tensor_to_voigt(t, *, strain: bool) -> np.ndarray:
|
|
150
|
+
"""Voigt vector of a symmetric 3 x 3 tensor (engineering shears if ``strain``)."""
|
|
151
|
+
t = np.asarray(t, dtype=float)
|
|
152
|
+
if t.shape != (3, 3):
|
|
153
|
+
raise ValueError(f"expected a 3 x 3 tensor, got shape {t.shape}")
|
|
154
|
+
if not np.allclose(t, t.T, rtol=1e-12, atol=1e-14 * max(1.0, float(np.abs(t).max()))):
|
|
155
|
+
raise ValueError("the tensor must be symmetric")
|
|
156
|
+
f = 2.0 if strain else 1.0
|
|
157
|
+
return np.array([t[a, b] if i < 3 else f * t[a, b] for i, (a, b) in enumerate(VOIGT)])
|