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,578 @@
|
|
|
1
|
+
"""Bodies in contact: the quasi-static solver of :mod:`morphogen.fracture.cohesive` with
|
|
2
|
+
the forces of the surfaces that touch (see :mod:`morphogen.contact`)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import scipy.sparse as sp
|
|
10
|
+
from scipy.spatial import cKDTree
|
|
11
|
+
|
|
12
|
+
from morphogen.contact import kernels
|
|
13
|
+
from morphogen.contact.kernels import (
|
|
14
|
+
P_BEHIND,
|
|
15
|
+
P_DEPTH,
|
|
16
|
+
P_MU,
|
|
17
|
+
P_RIM,
|
|
18
|
+
P_SHARE,
|
|
19
|
+
P_SIZE,
|
|
20
|
+
P_STICK,
|
|
21
|
+
P_STIFF,
|
|
22
|
+
P_TOUCH,
|
|
23
|
+
RIM,
|
|
24
|
+
RIM_NODES,
|
|
25
|
+
S_FACE,
|
|
26
|
+
S_GAP,
|
|
27
|
+
S_LAMBDA,
|
|
28
|
+
S_PRESSURE,
|
|
29
|
+
S_SHARE,
|
|
30
|
+
S_TX,
|
|
31
|
+
S_WORK,
|
|
32
|
+
STATE,
|
|
33
|
+
)
|
|
34
|
+
from morphogen.contact.surfaces import Obstacle, Pair, Surface
|
|
35
|
+
from morphogen.fracture.cohesive import (
|
|
36
|
+
CohesiveProblem,
|
|
37
|
+
CohesiveResult,
|
|
38
|
+
Contact,
|
|
39
|
+
Interfaces,
|
|
40
|
+
plus,
|
|
41
|
+
)
|
|
42
|
+
from morphogen.mesh.tetra import TetMesh
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class _Pass:
|
|
46
|
+
"""The slave points of a surface against a master surface or a rigid obstacle: their
|
|
47
|
+
faces, coordinates and weights, the parameters of the contact, their state at the end
|
|
48
|
+
of the last step and that of the last evaluation."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, slave: Surface, master: Surface | None, own: bool, obstacle, nodes, par,
|
|
51
|
+
shares: int = 1, rule: str = "gauss"): # fmt: skip
|
|
52
|
+
self.slave, self.master, self.own, self.obstacle = slave.faces, None, own, obstacle
|
|
53
|
+
#: the passes of the contact: each carries its share of the pressure
|
|
54
|
+
self.shares = int(shares)
|
|
55
|
+
self.rims = np.zeros((0, 3), dtype=np.bool_)
|
|
56
|
+
if master is not None:
|
|
57
|
+
self.master = master.faces
|
|
58
|
+
self.rims = np.ascontiguousarray(master.rims())
|
|
59
|
+
self.surface = slave
|
|
60
|
+
self.reference = np.ascontiguousarray(nodes, dtype=float) # the nodes at rest
|
|
61
|
+
#: the node that each is (the images of a periodic cell: see its problem)
|
|
62
|
+
self.ident = np.arange(len(self.reference), dtype=np.int64)
|
|
63
|
+
self.face, self.xi, self.eta, self.weight = slave.points(nodes, rule)
|
|
64
|
+
self.par = par
|
|
65
|
+
self.state = self.fresh()
|
|
66
|
+
self.trial = self.state.copy()
|
|
67
|
+
self.multiplier = np.zeros(len(self.face))
|
|
68
|
+
self.pressed = np.zeros(len(self.face), dtype=bool)
|
|
69
|
+
self.resultant = np.zeros(3)
|
|
70
|
+
self.last = np.full(len(self.face), -1, dtype=np.int64) # the faces last seen
|
|
71
|
+
# the reach of the search: the deepest penetration, and the size of the faces
|
|
72
|
+
self.reach = float(par[P_DEPTH]) + 2.0 * slave.size(nodes)
|
|
73
|
+
|
|
74
|
+
def fresh(self) -> np.ndarray:
|
|
75
|
+
"""The state of points that face nothing."""
|
|
76
|
+
state = np.zeros((len(self.face), STATE))
|
|
77
|
+
state[:, S_SHARE] = 1.0
|
|
78
|
+
state[:, S_FACE] = -1.0
|
|
79
|
+
state[:, S_GAP] = np.inf
|
|
80
|
+
return state
|
|
81
|
+
|
|
82
|
+
def near(self, x: np.ndarray, neighbours: int):
|
|
83
|
+
"""The slave points that have master faces within reach, and these faces (rows:
|
|
84
|
+
the nearest by their centroids; -1: none)."""
|
|
85
|
+
points = self.surface.positions(x, self.face, self.xi, self.eta)
|
|
86
|
+
centroids = x[self.master[:, :3]].mean(axis=1)
|
|
87
|
+
count = min(int(neighbours), len(centroids))
|
|
88
|
+
# a face holds points up to its size away from its centroid
|
|
89
|
+
_, found = cKDTree(centroids).query(points, k=count, distance_upper_bound=self.reach)
|
|
90
|
+
found = np.asarray(found).reshape(len(points), count)
|
|
91
|
+
found = np.where(found >= len(centroids), -1, found)
|
|
92
|
+
index = np.flatnonzero(found[:, 0] >= 0)
|
|
93
|
+
return index, np.ascontiguousarray(found[index], dtype=np.int64)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def contact_forces(passes, x, x_old, neighbours: int, target: float, tangent: bool, predict: bool):
|
|
97
|
+
"""The forces of the passes of contacts on the dofs of the nodes at the positions
|
|
98
|
+
``x`` (``x_old``: at the end of the last step) and, with ``tangent``, their tangent
|
|
99
|
+
(None if no point presses); ``target``: the load factor, which places the obstacles;
|
|
100
|
+
``predict``: the tangent of the predictor of a step. The state of the slave points of
|
|
101
|
+
this evaluation is kept in their passes (``trial``, ``pressed``, ``resultant``,
|
|
102
|
+
``last``)."""
|
|
103
|
+
n = x.size
|
|
104
|
+
f = np.zeros(n)
|
|
105
|
+
rows, cols, values = [], [], []
|
|
106
|
+
for p in passes:
|
|
107
|
+
ns = p.slave.shape[1]
|
|
108
|
+
if p.obstacle is None:
|
|
109
|
+
index, candidates = p.near(x, neighbours)
|
|
110
|
+
nd = 3 * (ns + p.master.shape[1])
|
|
111
|
+
else:
|
|
112
|
+
index, candidates = np.arange(len(p.face)), None
|
|
113
|
+
nd = 3 * ns
|
|
114
|
+
trial = p.fresh()
|
|
115
|
+
p.pressed = np.zeros(len(p.face), dtype=bool)
|
|
116
|
+
p.resultant = np.zeros(3)
|
|
117
|
+
if not len(index):
|
|
118
|
+
p.trial = trial
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
def evaluate(index, candidates, tangent, p=p, nd=nd):
|
|
122
|
+
count = len(index)
|
|
123
|
+
fe = np.zeros((count, nd))
|
|
124
|
+
ke = np.zeros((count if tangent else 1, nd, nd))
|
|
125
|
+
new = np.zeros((count, STATE))
|
|
126
|
+
active = np.zeros(count, dtype=np.bool_)
|
|
127
|
+
old = np.ascontiguousarray(p.state[index])
|
|
128
|
+
shared = (p.face[index], p.xi[index], p.eta[index], p.weight[index])
|
|
129
|
+
if p.obstacle is None:
|
|
130
|
+
nodes = np.zeros((count, nd // 3), dtype=np.int64)
|
|
131
|
+
last = np.ascontiguousarray(p.last[index])
|
|
132
|
+
kernels.pair_forces(
|
|
133
|
+
x, x_old, p.reference, p.ident, p.slave, p.master, p.rims, *shared,
|
|
134
|
+
candidates, last, p.par, old, new, p.own, tangent, predict, fe, ke, nodes,
|
|
135
|
+
active,
|
|
136
|
+
) # fmt: skip
|
|
137
|
+
else:
|
|
138
|
+
geometry = p.obstacle.geometry(target)
|
|
139
|
+
kernels.obstacle_forces(x, p.slave, *shared, p.obstacle.kind, geometry, p.par,
|
|
140
|
+
old, new, tangent, predict, fe, ke, active) # fmt: skip
|
|
141
|
+
nodes = p.slave[p.face[index]]
|
|
142
|
+
return fe, ke, new, active, nodes
|
|
143
|
+
|
|
144
|
+
fe, ke, new, active, nodes = evaluate(index, candidates, False)
|
|
145
|
+
trial[index] = new
|
|
146
|
+
p.trial = trial
|
|
147
|
+
if not active.any():
|
|
148
|
+
continue
|
|
149
|
+
on = np.flatnonzero(active)
|
|
150
|
+
if tangent: # of the points that press (or that the predictor closes) alone
|
|
151
|
+
chosen = None if candidates is None else np.ascontiguousarray(candidates[on])
|
|
152
|
+
fe_on, ke, _, still, nodes_on = evaluate(index[on], chosen, True)
|
|
153
|
+
fe_on, ke, nodes_on = fe_on[still], ke[still], nodes_on[still]
|
|
154
|
+
else:
|
|
155
|
+
fe_on, nodes_on = fe[on], nodes[on]
|
|
156
|
+
dofs = (3 * nodes_on[:, :, None] + np.arange(3)).reshape(len(nodes_on), nd)
|
|
157
|
+
np.add.at(f, dofs.ravel(), fe_on.ravel())
|
|
158
|
+
if tangent:
|
|
159
|
+
rows.append(np.repeat(dofs, nd, axis=1).ravel())
|
|
160
|
+
cols.append(np.tile(dofs, (1, nd)).ravel())
|
|
161
|
+
values.append(ke.ravel())
|
|
162
|
+
p.pressed[index] = new[:, S_PRESSURE] > 0.0
|
|
163
|
+
# the force of the slave surface on its master, or on its obstacle
|
|
164
|
+
p.resultant = fe[on][:, : 3 * ns].reshape(len(on), ns, 3).sum(axis=(0, 1))
|
|
165
|
+
for p in passes: # the faces that the points keep at the next evaluation
|
|
166
|
+
p.last = p.trial[:, S_FACE].astype(np.int64)
|
|
167
|
+
k = None
|
|
168
|
+
if tangent and rows:
|
|
169
|
+
k = sp.csr_matrix(
|
|
170
|
+
(np.concatenate(values), (np.concatenate(rows), np.concatenate(cols))),
|
|
171
|
+
shape=(n, n),
|
|
172
|
+
)
|
|
173
|
+
return f, k
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def contact_pass(nodes, slave, master, own, obstacle, spec, stiffest: float, shares: int = 1):
|
|
177
|
+
"""A pass of a contact: the slave points of ``slave`` against ``master`` (or against
|
|
178
|
+
the ``obstacle``), with the parameters of ``spec`` (a pair or an obstacle); the two
|
|
179
|
+
passes of a symmetric pair, or the two sides of a surface that touches itself, share
|
|
180
|
+
the penalty and the stick, so that both together are those asked for."""
|
|
181
|
+
size = slave.size(nodes)
|
|
182
|
+
if master is not None: # the penalty: that of the coarser of the two surfaces
|
|
183
|
+
size = max(size, master.size(nodes))
|
|
184
|
+
stiffness = 10.0 * stiffest / size if spec.stiffness is None else float(spec.stiffness)
|
|
185
|
+
stick = stiffness if spec.tangential is None else float(spec.tangential)
|
|
186
|
+
depth = getattr(spec, "depth", None)
|
|
187
|
+
rule = getattr(spec, "points", "gauss")
|
|
188
|
+
par = np.zeros(9)
|
|
189
|
+
par[P_RIM] = RIM_NODES if rule == "nodes" else RIM
|
|
190
|
+
par[P_SHARE] = 1.0 if rule == "nodes" else 0.0
|
|
191
|
+
par[P_STIFF], par[P_STICK] = stiffness / shares, stick / shares
|
|
192
|
+
par[P_MU] = float(spec.friction)
|
|
193
|
+
par[P_DEPTH] = 0.5 * size if depth is None else float(depth)
|
|
194
|
+
par[P_TOUCH] = 1e-9 * size
|
|
195
|
+
par[P_SIZE] = size
|
|
196
|
+
# a face behind a point at rest, within two faces of it (or twice the depth looked
|
|
197
|
+
# for), is the other side of a wall of the body
|
|
198
|
+
par[P_BEHIND] = 2.0 * max(size, par[P_DEPTH])
|
|
199
|
+
return _Pass(slave, master, own, obstacle, nodes, par, shares, rule)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def stiffest_modulus(materials, phases) -> float:
|
|
203
|
+
"""The largest Young's modulus (or normal stiffness) of the materials of the phases
|
|
204
|
+
present."""
|
|
205
|
+
return max(_stiffness(m) for p, m in materials.items() if not m.void and np.any(phases == p))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@dataclass
|
|
209
|
+
class ContactResult:
|
|
210
|
+
"""The steps of a contact problem: the load factors, the reactions of the prescribed
|
|
211
|
+
sets (steps x sets x 3), the Newton iterations, the final displacement (nodes x 3),
|
|
212
|
+
with ``fields`` those of the steps, and for each contact (the pairs, then the
|
|
213
|
+
obstacles: ``names``) at each step the ``area`` in contact (reference area of the
|
|
214
|
+
slave points that press; of one of the two sides for a symmetric pair or a surface
|
|
215
|
+
that touches itself), the largest ``pressure`` (the points of the two sides then each
|
|
216
|
+
carry half of it: theirs are doubled) and the ``forces`` of the slave
|
|
217
|
+
surface on its master or on its obstacle (steps x contacts x 3); the deepest
|
|
218
|
+
``penetration`` of each step. ``work``: at each step, ``"external"`` (of the prescribed
|
|
219
|
+
displacements and forces), ``"bulk"``, ``"interfaces"`` and ``"contact"`` (of their
|
|
220
|
+
internal forces: they add up to the external work; that of the contact is the energy
|
|
221
|
+
of the penalty and of friction, less the work of the obstacles that move),
|
|
222
|
+
``"friction"`` (dissipated by friction) and ``"obstacles"`` (done by the obstacles on
|
|
223
|
+
the body). ``points``: for each contact, the slave points at the end, a dict of their
|
|
224
|
+
``position``, ``pressure``, tangential ``traction``, ``gap``, ``weight`` (reference
|
|
225
|
+
area; of the points at the nodes of the faces, the share that the other surface sees)
|
|
226
|
+
and energy ``dissipated`` by friction per unit area. ``cohesive``: the steps of
|
|
227
|
+
the cohesive interfaces of the problem, if any."""
|
|
228
|
+
|
|
229
|
+
loads: np.ndarray
|
|
230
|
+
reactions: np.ndarray
|
|
231
|
+
iterations: np.ndarray
|
|
232
|
+
displacement: np.ndarray
|
|
233
|
+
area: np.ndarray
|
|
234
|
+
pressure: np.ndarray
|
|
235
|
+
forces: np.ndarray
|
|
236
|
+
penetration: np.ndarray
|
|
237
|
+
names: list
|
|
238
|
+
points: list = field(default_factory=list, repr=False)
|
|
239
|
+
fields: list = field(default_factory=list, repr=False)
|
|
240
|
+
time_s: float = 0.0
|
|
241
|
+
work: dict = field(default_factory=dict, repr=False)
|
|
242
|
+
cohesive: CohesiveResult | None = field(default=None, repr=False)
|
|
243
|
+
|
|
244
|
+
def rows(self) -> list[dict]:
|
|
245
|
+
"""One row per step: the load factor, the reactions of each prescribed set, the
|
|
246
|
+
area, the largest pressure and the force of each contact, the deepest
|
|
247
|
+
penetration and the works."""
|
|
248
|
+
out = []
|
|
249
|
+
for k, lam in enumerate(self.loads):
|
|
250
|
+
row = {"load": float(lam)}
|
|
251
|
+
for s in range(self.reactions.shape[1]):
|
|
252
|
+
for c, name in enumerate("xyz"):
|
|
253
|
+
row[f"R{s + 1}{name}"] = float(self.reactions[k, s, c])
|
|
254
|
+
for j, name in enumerate(self.names):
|
|
255
|
+
row[f"area_{name}"] = float(self.area[k, j])
|
|
256
|
+
row[f"pressure_{name}"] = float(self.pressure[k, j])
|
|
257
|
+
for c, axis in enumerate("xyz"):
|
|
258
|
+
row[f"F{axis}_{name}"] = float(self.forces[k, j, c])
|
|
259
|
+
row["penetration"] = float(self.penetration[k])
|
|
260
|
+
for name, values in self.work.items():
|
|
261
|
+
row[f"work_{name}"] = float(values[k])
|
|
262
|
+
out.append(row)
|
|
263
|
+
return out
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class ContactProblem(CohesiveProblem):
|
|
267
|
+
"""A body, or several in one mesh (:func:`~morphogen.contact.surfaces.assemble`), whose
|
|
268
|
+
surfaces may touch each other, themselves and rigid obstacles (see
|
|
269
|
+
:mod:`morphogen.contact`): ``mesh`` (tetrahedra of 4 or 10 nodes), the ``materials`` of
|
|
270
|
+
its phases, the ``pairs`` of surfaces (:class:`~morphogen.contact.surfaces.Pair`) and
|
|
271
|
+
the ``obstacles`` (:class:`~morphogen.contact.surfaces.Obstacle`).
|
|
272
|
+
|
|
273
|
+
``kinematics`` and ``bulk``: those of :class:`~morphogen.fracture.cohesive.
|
|
274
|
+
CohesiveProblem` (the gaps are always those of the deformed surfaces; in small strains
|
|
275
|
+
the bulk alone is linear). ``interfaces`` and ``law``: cohesive interfaces of the mesh
|
|
276
|
+
as well. ``augmentations``: the largest number of updates of the multipliers of the
|
|
277
|
+
augmented Lagrangian per step (0: the penalty alone), made while a point penetrates
|
|
278
|
+
deeper than ``tolerance`` (a length; by default a hundredth of the size of the
|
|
279
|
+
smallest faces). ``neighbours``: the master faces tried for each slave point, the
|
|
280
|
+
nearest by their centroids."""
|
|
281
|
+
|
|
282
|
+
def __init__(
|
|
283
|
+
self,
|
|
284
|
+
mesh: TetMesh,
|
|
285
|
+
materials,
|
|
286
|
+
pairs=(),
|
|
287
|
+
obstacles=(),
|
|
288
|
+
*,
|
|
289
|
+
kinematics: str = "finite",
|
|
290
|
+
bulk: str = "auto",
|
|
291
|
+
interfaces: Interfaces | None = None,
|
|
292
|
+
law=None,
|
|
293
|
+
augmentations: int = 0,
|
|
294
|
+
tolerance: float | None = None,
|
|
295
|
+
neighbours: int = 12,
|
|
296
|
+
):
|
|
297
|
+
if (interfaces is None) != (law is None):
|
|
298
|
+
raise ValueError("ContactProblem: cohesive interfaces and their law together")
|
|
299
|
+
if interfaces is None:
|
|
300
|
+
empty = np.zeros((0, 3 if mesh.order == 1 else 6), dtype=np.int64)
|
|
301
|
+
interfaces = Interfaces(empty, empty, np.zeros((0, 2), dtype=np.int64))
|
|
302
|
+
law = Contact(1.0)
|
|
303
|
+
super().__init__(mesh, interfaces, materials, law, kinematics=kinematics, bulk=bulk)
|
|
304
|
+
self.pairs, self.obstacles = list(pairs), list(obstacles)
|
|
305
|
+
if not self.pairs and not self.obstacles:
|
|
306
|
+
raise ValueError("ContactProblem: at least one pair of surfaces or one obstacle")
|
|
307
|
+
if augmentations < 0 or neighbours < 1:
|
|
308
|
+
raise ValueError("ContactProblem: augmentations >= 0, neighbours >= 1")
|
|
309
|
+
self.augmentations, self.neighbours = int(augmentations), int(neighbours)
|
|
310
|
+
stiffest = stiffest_modulus(materials, mesh.phase)
|
|
311
|
+
self._passes: list[_Pass] = []
|
|
312
|
+
self._owners: list[list[tuple[int, float]]] = [] # the passes of each contact, signed
|
|
313
|
+
self.names: list[str] = []
|
|
314
|
+
sizes = []
|
|
315
|
+
for k, pair in enumerate(self.pairs):
|
|
316
|
+
if not isinstance(pair, Pair):
|
|
317
|
+
raise TypeError("ContactProblem: pairs of surfaces (Pair)")
|
|
318
|
+
self._check(pair.slave)
|
|
319
|
+
owners = [(len(self._passes), 1.0)]
|
|
320
|
+
master = pair.slave if pair.own else pair.master
|
|
321
|
+
self._check(master)
|
|
322
|
+
both = pair.symmetric and not pair.own
|
|
323
|
+
# the two passes of a symmetric pair, or the points of the two sides of a
|
|
324
|
+
# surface that touches itself, each carry half of the pressure
|
|
325
|
+
shares = 2 if both or pair.own else 1
|
|
326
|
+
self._passes.append(
|
|
327
|
+
self._pass(pair.slave, master, pair.own, None, pair, stiffest, shares)
|
|
328
|
+
)
|
|
329
|
+
if both:
|
|
330
|
+
owners.append((len(self._passes), -1.0))
|
|
331
|
+
self._passes.append(
|
|
332
|
+
self._pass(master, pair.slave, False, None, pair, stiffest, shares)
|
|
333
|
+
)
|
|
334
|
+
self._owners.append(owners)
|
|
335
|
+
self.names.append(f"pair{k + 1}")
|
|
336
|
+
sizes.append(pair.slave.size(mesh.nodes))
|
|
337
|
+
for obstacle in self.obstacles:
|
|
338
|
+
if not isinstance(obstacle, Obstacle):
|
|
339
|
+
raise TypeError("ContactProblem: obstacles (Obstacle)")
|
|
340
|
+
self._check(obstacle.surface)
|
|
341
|
+
self._owners.append([(len(self._passes), 1.0)])
|
|
342
|
+
self._passes.append(
|
|
343
|
+
self._pass(obstacle.surface, None, False, obstacle, obstacle, stiffest)
|
|
344
|
+
)
|
|
345
|
+
taken = sum(name.startswith(obstacle.name) for name in self.names)
|
|
346
|
+
self.names.append(obstacle.name + (str(taken + 1) if taken else ""))
|
|
347
|
+
sizes.append(obstacle.surface.size(mesh.nodes))
|
|
348
|
+
self.tolerance = 0.01 * min(sizes) if tolerance is None else float(tolerance)
|
|
349
|
+
if not self.tolerance > 0:
|
|
350
|
+
raise ValueError("ContactProblem: a positive tolerance")
|
|
351
|
+
self._target = 0.0
|
|
352
|
+
self._x_old = np.ascontiguousarray(mesh.nodes)
|
|
353
|
+
self._records: dict = {}
|
|
354
|
+
|
|
355
|
+
# -- set-up ----------------------------------------------------------------------------
|
|
356
|
+
|
|
357
|
+
def _check(self, surface: Surface) -> None:
|
|
358
|
+
if not isinstance(surface, Surface):
|
|
359
|
+
raise TypeError("ContactProblem: surfaces (Surface.of(mesh, ...))")
|
|
360
|
+
if surface.order != self.mesh.order:
|
|
361
|
+
raise ValueError(
|
|
362
|
+
"ContactProblem: faces of three nodes for 4-node tetrahedra, of six for "
|
|
363
|
+
"10-node ones (Surface.of on the mesh itself)"
|
|
364
|
+
)
|
|
365
|
+
if not surface.n_faces:
|
|
366
|
+
raise ValueError("ContactProblem: a surface without faces")
|
|
367
|
+
|
|
368
|
+
def _pass(self, slave, master, own, obstacle, spec, stiffest: float, shares: int = 1):
|
|
369
|
+
return contact_pass(self.mesh.nodes, slave, master, own, obstacle, spec, stiffest, shares)
|
|
370
|
+
|
|
371
|
+
# -- forces ----------------------------------------------------------------------------
|
|
372
|
+
|
|
373
|
+
def _predictor(self) -> bool:
|
|
374
|
+
return True
|
|
375
|
+
|
|
376
|
+
def _contact(self, u, tangent: bool, predict: bool):
|
|
377
|
+
"""The forces of the contacts (all the dofs) for the displacement ``u`` and, with
|
|
378
|
+
``tangent``, their tangent; the state of the slave points of this evaluation is
|
|
379
|
+
kept in their passes."""
|
|
380
|
+
x = np.ascontiguousarray(self.mesh.nodes + u.reshape(-1, 3))
|
|
381
|
+
return contact_forces(self._passes, x, self._x_old, self.neighbours, self._target,
|
|
382
|
+
tangent, predict) # fmt: skip
|
|
383
|
+
|
|
384
|
+
def _forces(self, u, hist, tangent: bool, rate: float = 0.0, predict: bool = False):
|
|
385
|
+
f, k, hist_new = super()._forces(u, hist, tangent, rate, predict)
|
|
386
|
+
if not np.all(np.isfinite(f)): # a point of the bulk failed: the step is divided
|
|
387
|
+
return f, k, hist_new
|
|
388
|
+
fc, kc = self._contact(u, tangent, predict)
|
|
389
|
+
self._parts = (*self._parts, fc)
|
|
390
|
+
if kc is not None:
|
|
391
|
+
k = kc if k is None else plus(k, kc)
|
|
392
|
+
return f + fc, k, hist_new
|
|
393
|
+
|
|
394
|
+
# -- the steps -------------------------------------------------------------------------
|
|
395
|
+
|
|
396
|
+
def _part_names(self) -> tuple:
|
|
397
|
+
return (*super()._part_names(), "contact")
|
|
398
|
+
|
|
399
|
+
def _begin(self, u, load: float) -> None:
|
|
400
|
+
"""The state of the slave points before the loading: the faces and the gaps that
|
|
401
|
+
they see, none pressing; the records of the steps."""
|
|
402
|
+
self._target = float(load)
|
|
403
|
+
self._x_old = np.ascontiguousarray(self.mesh.nodes + u.reshape(-1, 3))
|
|
404
|
+
for p in self._passes:
|
|
405
|
+
p.state = p.fresh()
|
|
406
|
+
p.multiplier = np.zeros(len(p.face))
|
|
407
|
+
self._contact(u, False, False)
|
|
408
|
+
for p in self._passes:
|
|
409
|
+
p.state = p.trial.copy()
|
|
410
|
+
p.state[:, S_PRESSURE] = 0.0
|
|
411
|
+
p.state[:, S_TX : S_TX + 3] = 0.0
|
|
412
|
+
p.state[:, S_WORK] = 0.0
|
|
413
|
+
count = len(self._owners)
|
|
414
|
+
self._records = {
|
|
415
|
+
"area": [np.zeros(count)],
|
|
416
|
+
"pressure": [np.zeros(count)],
|
|
417
|
+
"forces": [np.zeros((count, 3))],
|
|
418
|
+
"penetration": [0.0],
|
|
419
|
+
"friction": [0.0],
|
|
420
|
+
"obstacles": [0.0],
|
|
421
|
+
"resultants": [np.zeros(3) for _ in self.obstacles],
|
|
422
|
+
"load": float(load),
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
def _attempt(self, target: float) -> None:
|
|
426
|
+
"""A step is tried towards the load factor ``target``: the multipliers of the end
|
|
427
|
+
of the last one."""
|
|
428
|
+
self._target = float(target)
|
|
429
|
+
self._augmented = 0
|
|
430
|
+
for p in self._passes:
|
|
431
|
+
p.state[:, S_LAMBDA] = p.multiplier
|
|
432
|
+
p.last = p.state[:, S_FACE].astype(np.int64)
|
|
433
|
+
|
|
434
|
+
def _augment(self) -> bool:
|
|
435
|
+
"""After Newton's method: whether the multipliers are updated and the step solved
|
|
436
|
+
again (points that penetrate deeper than the tolerance)."""
|
|
437
|
+
if self._augmented >= self.augmentations:
|
|
438
|
+
return False
|
|
439
|
+
deepest = max(
|
|
440
|
+
(float(-p.trial[p.pressed, S_GAP].min()) for p in self._passes if p.pressed.any()),
|
|
441
|
+
default=0.0,
|
|
442
|
+
)
|
|
443
|
+
if deepest <= self.tolerance:
|
|
444
|
+
return False
|
|
445
|
+
for p in self._passes:
|
|
446
|
+
p.state[:, S_LAMBDA] = p.trial[:, S_PRESSURE]
|
|
447
|
+
self._augmented += 1
|
|
448
|
+
return True
|
|
449
|
+
|
|
450
|
+
def _accept(self, u) -> None:
|
|
451
|
+
"""A step converged: the state of the slave points is kept, its records made."""
|
|
452
|
+
rec = self._records
|
|
453
|
+
self._x_old = np.ascontiguousarray(self.mesh.nodes + u.reshape(-1, 3))
|
|
454
|
+
count = len(self._owners)
|
|
455
|
+
area, pressure, forces = np.zeros(count), np.zeros(count), np.zeros((count, 3))
|
|
456
|
+
deepest, rubbed = 0.0, 0.0
|
|
457
|
+
for j, owners in enumerate(self._owners):
|
|
458
|
+
for index, sign in owners:
|
|
459
|
+
p = self._passes[index]
|
|
460
|
+
area[j] += (p.weight * p.trial[:, S_SHARE])[p.pressed].sum() / p.shares
|
|
461
|
+
if p.pressed.any():
|
|
462
|
+
most = p.shares * float(p.trial[p.pressed, S_PRESSURE].max())
|
|
463
|
+
pressure[j] = max(pressure[j], most)
|
|
464
|
+
deepest = max(deepest, float(-p.trial[p.pressed, S_GAP].min()))
|
|
465
|
+
forces[j] += sign * p.resultant
|
|
466
|
+
for p in self._passes:
|
|
467
|
+
p.state = p.trial.copy()
|
|
468
|
+
p.multiplier = p.state[:, S_LAMBDA].copy()
|
|
469
|
+
rubbed += float(p.weight @ p.state[:, S_WORK])
|
|
470
|
+
work = rec["obstacles"][-1]
|
|
471
|
+
first = len(self.pairs)
|
|
472
|
+
for k, obstacle in enumerate(self.obstacles):
|
|
473
|
+
moved = obstacle.translation(self._target) - obstacle.translation(rec["load"])
|
|
474
|
+
# the obstacle pushes the body by the opposite of the force that it receives
|
|
475
|
+
work -= 0.5 * (rec["resultants"][k] + forces[first + k]) @ moved
|
|
476
|
+
rec["resultants"][k] = forces[first + k].copy()
|
|
477
|
+
rec["load"] = self._target
|
|
478
|
+
rec["area"].append(area)
|
|
479
|
+
rec["pressure"].append(pressure)
|
|
480
|
+
rec["forces"].append(forces)
|
|
481
|
+
rec["penetration"].append(max(deepest, 0.0))
|
|
482
|
+
rec["friction"].append(rubbed)
|
|
483
|
+
rec["obstacles"].append(work)
|
|
484
|
+
|
|
485
|
+
def run(self, prescribed, load: float = 1.0, **options) -> ContactResult:
|
|
486
|
+
"""Grow the prescribed displacements, the forces and the motions of the obstacles
|
|
487
|
+
to the load factor ``load``: the entries and options of
|
|
488
|
+
:meth:`~morphogen.fracture.cohesive.CohesiveProblem.run` (``steps``, ``tol``,
|
|
489
|
+
``max_newton``, ``max_cuts``, ``fields``, ``forces``, ``duration``, ``viscosity``
|
|
490
|
+
and ``history`` of the cohesive interfaces), but its ``initial`` state."""
|
|
491
|
+
if options.get("initial") is not None:
|
|
492
|
+
raise ValueError("ContactProblem.run: no initial state (the contacts have none)")
|
|
493
|
+
res = super().run(prescribed, load, **options)
|
|
494
|
+
rec = self._records
|
|
495
|
+
work = dict(res.work)
|
|
496
|
+
work.pop("friction", None)
|
|
497
|
+
if self.interfaces.n_elements == 0:
|
|
498
|
+
work.pop("interfaces", None)
|
|
499
|
+
work["friction"] = np.array(rec["friction"])
|
|
500
|
+
if self.interfaces.n_elements and "friction" in res.work:
|
|
501
|
+
work["friction"] = work["friction"] + res.work["friction"]
|
|
502
|
+
work["obstacles"] = np.array(rec["obstacles"])
|
|
503
|
+
return ContactResult(
|
|
504
|
+
res.loads,
|
|
505
|
+
res.reactions,
|
|
506
|
+
res.iterations,
|
|
507
|
+
res.displacement,
|
|
508
|
+
np.array(rec["area"]),
|
|
509
|
+
np.array(rec["pressure"]),
|
|
510
|
+
np.array(rec["forces"]),
|
|
511
|
+
np.array(rec["penetration"]),
|
|
512
|
+
list(self.names),
|
|
513
|
+
self._slave_points(res.displacement),
|
|
514
|
+
res.fields,
|
|
515
|
+
res.time_s,
|
|
516
|
+
work,
|
|
517
|
+
res if self.interfaces.n_elements else None,
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
def _slave_points(self, displacement) -> list:
|
|
521
|
+
"""The slave points of each contact at the end (see :class:`ContactResult`); those
|
|
522
|
+
of the two passes of a symmetric pair one after the other."""
|
|
523
|
+
x = self.mesh.nodes + displacement
|
|
524
|
+
out = []
|
|
525
|
+
for owners in self._owners:
|
|
526
|
+
parts = [self._passes[index] for index, _ in owners]
|
|
527
|
+
out.append(
|
|
528
|
+
{
|
|
529
|
+
"position": np.concatenate(
|
|
530
|
+
[p.surface.positions(x, p.face, p.xi, p.eta) for p in parts]
|
|
531
|
+
),
|
|
532
|
+
"pressure": np.concatenate([p.shares * p.state[:, S_PRESSURE] for p in parts]),
|
|
533
|
+
"traction": np.concatenate(
|
|
534
|
+
[p.shares * p.state[:, S_TX : S_TX + 3] for p in parts]
|
|
535
|
+
),
|
|
536
|
+
"gap": np.concatenate([p.state[:, S_GAP] for p in parts]),
|
|
537
|
+
"weight": np.concatenate([p.weight * p.state[:, S_SHARE] for p in parts]),
|
|
538
|
+
"dissipated": np.concatenate([p.state[:, S_WORK] for p in parts]),
|
|
539
|
+
}
|
|
540
|
+
)
|
|
541
|
+
return out
|
|
542
|
+
|
|
543
|
+
def nodal_pressure(self) -> np.ndarray:
|
|
544
|
+
"""The pressure of the contacts at the nodes at the end of the last step: at each
|
|
545
|
+
node of a slave surface, the mean over the faces around it, weighted by their
|
|
546
|
+
areas, of the mean pressure of their points; 0 elsewhere."""
|
|
547
|
+
total = np.zeros(self.mesh.n_nodes)
|
|
548
|
+
area = np.zeros(self.mesh.n_nodes)
|
|
549
|
+
for p in self._passes:
|
|
550
|
+
count = len(p.face) // len(p.slave)
|
|
551
|
+
weight = p.weight.reshape(-1, count)
|
|
552
|
+
carried = (p.state[:, S_SHARE] * p.state[:, S_PRESSURE]).reshape(-1, count)
|
|
553
|
+
mean = p.shares * (weight * carried).sum(axis=1)
|
|
554
|
+
for column in p.slave.T:
|
|
555
|
+
np.add.at(total, column, mean)
|
|
556
|
+
np.add.at(area, column, weight.sum(axis=1))
|
|
557
|
+
return np.divide(total, area, out=np.zeros_like(total), where=area > 0)
|
|
558
|
+
|
|
559
|
+
def write(self, path, result, step: int = -1):
|
|
560
|
+
"""The body (``<path>.vtu``: the displacement of ``step`` with ``fields``, else the
|
|
561
|
+
final one, and at the end the pressure of the contacts at the nodes); returns the
|
|
562
|
+
path."""
|
|
563
|
+
from pathlib import Path
|
|
564
|
+
|
|
565
|
+
from morphogen.io.meshes import write_vtu_tet
|
|
566
|
+
|
|
567
|
+
u = result.fields[step] if result.fields else result.displacement
|
|
568
|
+
data = {"displacement": u}
|
|
569
|
+
if not result.fields or step in (-1, len(result.fields) - 1):
|
|
570
|
+
data["contact_pressure"] = self.nodal_pressure()
|
|
571
|
+
return write_vtu_tet(Path(path).with_suffix(".vtu"), self.mesh, point_data=data)
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def _stiffness(material) -> float:
|
|
575
|
+
"""Young's modulus of a material, or the largest normal stiffness of its matrix."""
|
|
576
|
+
if material.young:
|
|
577
|
+
return float(material.young)
|
|
578
|
+
return float(np.max(np.diag(np.asarray(material.stiffness, dtype=float))[:3]))
|