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,572 @@
|
|
|
1
|
+
"""Cracks of any surface and front in 3D: the surface swept by the successive positions of
|
|
2
|
+
a front, which advances by its own amount and kinks by its own angle at each of its
|
|
3
|
+
points.
|
|
4
|
+
|
|
5
|
+
The planar cracks of :mod:`morphogen.fracture.lefm` have a straight or circular front that
|
|
6
|
+
advances uniformly, and the kinked cracks of :mod:`morphogen.fracture.mixed` a path in a
|
|
7
|
+
plane, the same all along a straight front. A :class:`SurfaceCrack` is a grid of points,
|
|
8
|
+
``rows x stations``: each row a position of the front, from the centre of the crack (a
|
|
9
|
+
closed front: a crack inside the body, such as an ellipse) or from its mouth (an open
|
|
10
|
+
front, which leaves the body by its two ends: a through, edge or surface crack) to the
|
|
11
|
+
front, the last row; each station follows its own path across the rows. Between the rows
|
|
12
|
+
the surface is that of the triangles of the grid.
|
|
13
|
+
|
|
14
|
+
*Front.* At each station the tangent ``τ`` of the front (along the stations), the
|
|
15
|
+
direction of propagation ``d`` (that of the last move of the station, made normal to
|
|
16
|
+
``τ``) and the normal ``n = d × τ`` of the surface: the axes ``(d, n, t = d × n)`` of the
|
|
17
|
+
asymptotic fields. They are interpolated along the front, whose curvature the auxiliary
|
|
18
|
+
fields of the interaction integrals then see (Gosz & Moran 2002). A point has the
|
|
19
|
+
coordinates ``x1 = (x - f) · d`` and ``x2 = (x - f) · n`` from its nearest point ``f`` of the
|
|
20
|
+
front: ``ψ = x1`` (negative behind the front), and ``φ`` the signed distance to the
|
|
21
|
+
triangles behind the front and ``x2`` ahead of it, the surface continued along ``d``: the
|
|
22
|
+
two level sets that the conforming meshes and the opening of the lips take
|
|
23
|
+
(:func:`~morphogen.fracture.lefm.crack_mesh`, :func:`~morphogen.fracture.lefm.crack_faces`).
|
|
24
|
+
An open front is continued beyond its ends, and its surface behind its mouth.
|
|
25
|
+
|
|
26
|
+
*Growth* (:meth:`SurfaceCrack.grown`): a new row, each station moved by its advance at its
|
|
27
|
+
angle from ``d`` towards ``n``. :func:`propagate_front` solves the body on a mesh rebuilt
|
|
28
|
+
for each crack, takes the energy release rate and the stress intensity factors at
|
|
29
|
+
stations along the front (:meth:`~morphogen.fracture.mixed.CrackSolution.modes`), and
|
|
30
|
+
moves each point of the front in the direction of the largest hoop stress of its own
|
|
31
|
+
``K_I`` and ``K_II`` (Erdogan & Sih 1963), by an advance that grows with its own energy
|
|
32
|
+
release rate, ``da = Δa (G / G_max)^(m / 2)`` (Paris' law ``da/dN = C ΔK^m`` for the
|
|
33
|
+
cycles that advance the fastest point by ``Δa``): an elliptical crack in tension grows
|
|
34
|
+
towards a circle, a crack inclined to the load turns its surface towards the plane normal
|
|
35
|
+
to it, by a different angle at each point of its front.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
import math
|
|
41
|
+
from dataclasses import dataclass, field
|
|
42
|
+
|
|
43
|
+
import numpy as np
|
|
44
|
+
from numba import njit, prange
|
|
45
|
+
|
|
46
|
+
#: How far the surface of an open crack is continued beyond the ends of its front and
|
|
47
|
+
#: behind its mouth, in units of its size
|
|
48
|
+
FAR = 1e3
|
|
49
|
+
|
|
50
|
+
_COUNT = 400 # points of the front
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@njit(cache=True)
|
|
54
|
+
def _closest_on_triangle(p, a, b, c):
|
|
55
|
+
"""The barycentric coordinates of the point of the triangle ``abc`` nearest ``p``
|
|
56
|
+
(Ericson 2005)."""
|
|
57
|
+
ab, ac, ap = b - a, c - a, p - a
|
|
58
|
+
d1, d2 = ab @ ap, ac @ ap
|
|
59
|
+
if d1 <= 0.0 and d2 <= 0.0:
|
|
60
|
+
return 1.0, 0.0, 0.0
|
|
61
|
+
bp = p - b
|
|
62
|
+
d3, d4 = ab @ bp, ac @ bp
|
|
63
|
+
if d3 >= 0.0 and d4 <= d3:
|
|
64
|
+
return 0.0, 1.0, 0.0
|
|
65
|
+
vc = d1 * d4 - d3 * d2
|
|
66
|
+
if vc <= 0.0 and d1 >= 0.0 and d3 <= 0.0:
|
|
67
|
+
v = d1 / (d1 - d3)
|
|
68
|
+
return 1.0 - v, v, 0.0
|
|
69
|
+
cp = p - c
|
|
70
|
+
d5, d6 = ab @ cp, ac @ cp
|
|
71
|
+
if d6 >= 0.0 and d5 <= d6:
|
|
72
|
+
return 0.0, 0.0, 1.0
|
|
73
|
+
vb = d5 * d2 - d1 * d6
|
|
74
|
+
if vb <= 0.0 and d2 >= 0.0 and d6 <= 0.0:
|
|
75
|
+
w = d2 / (d2 - d6)
|
|
76
|
+
return 1.0 - w, 0.0, w
|
|
77
|
+
va = d3 * d6 - d5 * d4
|
|
78
|
+
if va <= 0.0 and (d4 - d3) >= 0.0 and (d5 - d6) >= 0.0:
|
|
79
|
+
w = (d4 - d3) / ((d4 - d3) + (d5 - d6))
|
|
80
|
+
return 0.0, 1.0 - w, w
|
|
81
|
+
denom = 1.0 / (va + vb + vc)
|
|
82
|
+
v, w = vb * denom, vc * denom
|
|
83
|
+
return 1.0 - v - w, v, w
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@njit(parallel=True, cache=True)
|
|
87
|
+
def _signed_distance(points, vertices, triangles, normals):
|
|
88
|
+
"""The distance of each point to the triangles (rows of three vertices), signed by
|
|
89
|
+
the normal of the surface interpolated at its nearest point (``normals``: those of
|
|
90
|
+
the vertices)."""
|
|
91
|
+
out = np.empty(len(points))
|
|
92
|
+
for i in prange(len(points)):
|
|
93
|
+
p = points[i]
|
|
94
|
+
best = np.inf
|
|
95
|
+
side = 1.0
|
|
96
|
+
for k in range(len(triangles)):
|
|
97
|
+
a = vertices[triangles[k, 0]]
|
|
98
|
+
b = vertices[triangles[k, 1]]
|
|
99
|
+
c = vertices[triangles[k, 2]]
|
|
100
|
+
u, v, w = _closest_on_triangle(p, a, b, c)
|
|
101
|
+
q = p - (u * a + v * b + w * c)
|
|
102
|
+
d2 = q @ q
|
|
103
|
+
if d2 < best:
|
|
104
|
+
best = d2
|
|
105
|
+
normal = (
|
|
106
|
+
u * normals[triangles[k, 0]]
|
|
107
|
+
+ v * normals[triangles[k, 1]]
|
|
108
|
+
+ w * normals[triangles[k, 2]]
|
|
109
|
+
)
|
|
110
|
+
side = 1.0 if q @ normal >= 0.0 else -1.0
|
|
111
|
+
out[i] = side * math.sqrt(best)
|
|
112
|
+
return out
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@njit(parallel=True, cache=True)
|
|
116
|
+
def _nearest_on_front(points, front, closed):
|
|
117
|
+
"""The segment of the front nearest each point and the position along it (0 at its
|
|
118
|
+
first station, 1 at its second; beyond them on the end segments of an open front,
|
|
119
|
+
which are continued)."""
|
|
120
|
+
m = len(front)
|
|
121
|
+
count = m if closed else m - 1
|
|
122
|
+
segment = np.empty(len(points), dtype=np.int64)
|
|
123
|
+
position = np.empty(len(points))
|
|
124
|
+
for i in prange(len(points)):
|
|
125
|
+
p = points[i]
|
|
126
|
+
best = np.inf
|
|
127
|
+
for k in range(count):
|
|
128
|
+
a = front[k]
|
|
129
|
+
e = front[(k + 1) % m] - a
|
|
130
|
+
u = ((p - a) @ e) / (e @ e)
|
|
131
|
+
low = -np.inf if (not closed and k == 0) else 0.0
|
|
132
|
+
high = np.inf if (not closed and k == count - 1) else 1.0
|
|
133
|
+
u = min(max(u, low), high)
|
|
134
|
+
q = p - a - u * e
|
|
135
|
+
d2 = q @ q
|
|
136
|
+
if d2 < best:
|
|
137
|
+
best = d2
|
|
138
|
+
segment[i] = k
|
|
139
|
+
position[i] = u
|
|
140
|
+
return segment, position
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _unit(v: np.ndarray) -> np.ndarray:
|
|
144
|
+
return v / np.maximum(np.linalg.norm(v, axis=-1, keepdims=True), 1e-300)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class SurfaceCrack:
|
|
148
|
+
"""A crack of any surface (see the module): ``points`` (rows x stations x 3), the
|
|
149
|
+
successive positions of its front from its centre (``closed``: the stations go round
|
|
150
|
+
a front inside the body; the first row may be one point repeated) or from its mouth
|
|
151
|
+
(an open front, whose first and last stations lie outside the body or on its
|
|
152
|
+
boundary); the front is the last row. With the normal ``n`` of the surface towards
|
|
153
|
+
the reader, the stations of a closed front go anticlockwise."""
|
|
154
|
+
|
|
155
|
+
curved = True # the auxiliary fields of the interaction integrals turn along the front
|
|
156
|
+
|
|
157
|
+
def __init__(self, points, closed: bool = True) -> None:
|
|
158
|
+
p = np.array(points, dtype=float)
|
|
159
|
+
if p.ndim != 3 or p.shape[2] != 3 or p.shape[0] < 2 or p.shape[1] < (3 if closed else 2):
|
|
160
|
+
raise ValueError(
|
|
161
|
+
"SurfaceCrack: points (rows x stations x 3), two rows at least, three "
|
|
162
|
+
"stations around a closed front (two along an open one)"
|
|
163
|
+
)
|
|
164
|
+
if not np.all(np.isfinite(p)):
|
|
165
|
+
raise ValueError("SurfaceCrack: finite points")
|
|
166
|
+
p.setflags(write=False)
|
|
167
|
+
self.points = p
|
|
168
|
+
self.closed = bool(closed)
|
|
169
|
+
front = p[-1]
|
|
170
|
+
step = np.roll(front, -1, axis=0) - front if self.closed else np.diff(front, axis=0)
|
|
171
|
+
lengths = np.linalg.norm(step, axis=1)
|
|
172
|
+
if np.any(lengths <= 0.0):
|
|
173
|
+
raise ValueError("SurfaceCrack: two stations of the front at the same point")
|
|
174
|
+
self._lengths = lengths
|
|
175
|
+
self._length = float(lengths.sum())
|
|
176
|
+
if self.closed: # the tangent at a station: across its two neighbours
|
|
177
|
+
tangent = _unit(np.roll(front, -1, axis=0) - np.roll(front, 1, axis=0))
|
|
178
|
+
else:
|
|
179
|
+
tangent = np.empty_like(front)
|
|
180
|
+
tangent[1:-1] = front[2:] - front[:-2]
|
|
181
|
+
tangent[0], tangent[-1] = step[0], step[-1]
|
|
182
|
+
tangent = _unit(tangent)
|
|
183
|
+
back = front - p[-2]
|
|
184
|
+
back = back - np.einsum("ij,ij->i", back, tangent)[:, None] * tangent
|
|
185
|
+
if np.any(np.linalg.norm(back, axis=1) <= 1e-12 * self._length):
|
|
186
|
+
raise ValueError("SurfaceCrack: the last two rows meet, or the front runs along them")
|
|
187
|
+
self._d = _unit(back)
|
|
188
|
+
self._n = _unit(np.cross(self._d, tangent))
|
|
189
|
+
self._t = np.cross(self._d, self._n)
|
|
190
|
+
# the coordinate of the stations: the angle of a closed front (the length along it
|
|
191
|
+
# over its whole length), the length along an open one
|
|
192
|
+
arc = np.concatenate([[0.0], np.cumsum(lengths)])
|
|
193
|
+
self._arc = arc
|
|
194
|
+
self._s = -np.pi + 2 * np.pi * arc[:-1] / self._length if self.closed else arc
|
|
195
|
+
self._surface()
|
|
196
|
+
|
|
197
|
+
# -- the surface behind the front ---------------------------------------------------
|
|
198
|
+
|
|
199
|
+
def _surface(self) -> None:
|
|
200
|
+
"""The triangles of the grid of the rows, with those that continue the surface
|
|
201
|
+
of an open crack beyond the ends of its front and behind its mouth, and the
|
|
202
|
+
normals of their vertices."""
|
|
203
|
+
grid = self.points
|
|
204
|
+
scale = float(np.ptp(grid.reshape(-1, 3), axis=0).max())
|
|
205
|
+
if not self.closed:
|
|
206
|
+
far = FAR * scale
|
|
207
|
+
first = _unit(grid[:, 1] - grid[:, 0])
|
|
208
|
+
last = _unit(grid[:, -1] - grid[:, -2])
|
|
209
|
+
grid = np.concatenate(
|
|
210
|
+
[(grid[:, 0] - far * first)[:, None], grid, (grid[:, -1] + far * last)[:, None]],
|
|
211
|
+
axis=1,
|
|
212
|
+
)
|
|
213
|
+
behind = grid[0] - far * _unit(grid[1] - grid[0])
|
|
214
|
+
grid = np.concatenate([behind[None], grid], axis=0)
|
|
215
|
+
rows, cols = grid.shape[:2]
|
|
216
|
+
index = np.arange(rows * cols).reshape(rows, cols)
|
|
217
|
+
nxt = np.roll(index, -1, axis=1)
|
|
218
|
+
if self.closed:
|
|
219
|
+
a, b, c, e = index[:-1], index[1:], nxt[:-1], nxt[1:]
|
|
220
|
+
else:
|
|
221
|
+
a, b, c, e = index[:-1, :-1], index[1:, :-1], index[:-1, 1:], index[1:, 1:]
|
|
222
|
+
triangles = np.concatenate(
|
|
223
|
+
[
|
|
224
|
+
np.stack([a, b, c], axis=-1).reshape(-1, 3),
|
|
225
|
+
np.stack([b, e, c], axis=-1).reshape(-1, 3),
|
|
226
|
+
]
|
|
227
|
+
)
|
|
228
|
+
vertices = grid.reshape(-1, 3)
|
|
229
|
+
corners = vertices[triangles]
|
|
230
|
+
cross = np.cross(corners[:, 1] - corners[:, 0], corners[:, 2] - corners[:, 0])
|
|
231
|
+
area = np.linalg.norm(cross, axis=1)
|
|
232
|
+
keep = area > 1e-14 * scale * scale # (the fan around a centre repeated)
|
|
233
|
+
triangles, cross = triangles[keep], cross[keep]
|
|
234
|
+
normals = np.zeros_like(vertices)
|
|
235
|
+
for k in range(3):
|
|
236
|
+
np.add.at(normals, triangles[:, k], cross)
|
|
237
|
+
self._vertices = np.ascontiguousarray(vertices)
|
|
238
|
+
self._triangles = np.ascontiguousarray(triangles)
|
|
239
|
+
self._normals = np.ascontiguousarray(_unit(normals))
|
|
240
|
+
self._scale = scale
|
|
241
|
+
|
|
242
|
+
# -- constructors ---------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
@classmethod
|
|
245
|
+
def ellipse(cls, centre, normal, a: float, b: float | None = None, *, major=None,
|
|
246
|
+
stations: int = 48, rows: int = 4) -> SurfaceCrack: # fmt: skip
|
|
247
|
+
"""A planar elliptical crack of semi-axes ``a`` (along ``major``, by default the
|
|
248
|
+
axis of the frame least aligned with the normal, made normal to it) and ``b`` (by
|
|
249
|
+
default ``a``: a penny), its plane through ``centre`` normal to ``normal``: rows
|
|
250
|
+
from its centre to its front."""
|
|
251
|
+
n = _unit(np.asarray(normal, dtype=float))
|
|
252
|
+
b = float(a) if b is None else float(b)
|
|
253
|
+
if not (a > 0 and b > 0) or stations < 8 or rows < 2:
|
|
254
|
+
raise ValueError("SurfaceCrack.ellipse: positive semi-axes, 8 stations, 2 rows")
|
|
255
|
+
if major is None:
|
|
256
|
+
major = np.eye(3)[int(np.argmin(np.abs(n)))]
|
|
257
|
+
e1 = np.asarray(major, dtype=float)
|
|
258
|
+
e1 = _unit(e1 - (e1 @ n) * n)
|
|
259
|
+
e2 = np.cross(n, e1)
|
|
260
|
+
angle = 2 * np.pi * np.arange(stations) / stations
|
|
261
|
+
front = float(a) * np.outer(np.cos(angle), e1) + b * np.outer(np.sin(angle), e2)
|
|
262
|
+
radii = np.linspace(0.0, 1.0, rows)
|
|
263
|
+
return cls(np.asarray(centre, dtype=float) + radii[:, None, None] * front[None], True)
|
|
264
|
+
|
|
265
|
+
@classmethod
|
|
266
|
+
def of(cls, crack, lower=None, upper=None, *, stations: int = 48, rows: int = 4):
|
|
267
|
+
"""The surface crack of a planar :class:`~morphogen.fracture.lefm.Crack` (a penny:
|
|
268
|
+
a closed front) or of a straight one or a
|
|
269
|
+
:class:`~morphogen.fracture.mixed.KinkedCrack` in the box ``[lower, upper]`` (an
|
|
270
|
+
open front, continued beyond the box)."""
|
|
271
|
+
if getattr(crack, "kind", None) == "penny":
|
|
272
|
+
return cls.ellipse(crack.point, crack.normal, crack.size, stations=stations, rows=rows)
|
|
273
|
+
from morphogen.fracture.mixed import KinkedCrack
|
|
274
|
+
|
|
275
|
+
path = crack if isinstance(crack, KinkedCrack) else KinkedCrack.of(crack)
|
|
276
|
+
if lower is None or upper is None:
|
|
277
|
+
raise ValueError("SurfaceCrack.of: the box of a crack with a straight front")
|
|
278
|
+
axis = np.asarray(path.axis)
|
|
279
|
+
corners = np.array(
|
|
280
|
+
[[(lower, upper)[i][k] for k, i in enumerate(bits)] for bits in np.ndindex(2, 2, 2)]
|
|
281
|
+
)
|
|
282
|
+
along = (corners - np.asarray(path.points[0])) @ axis
|
|
283
|
+
margin = 0.05 * (along.max() - along.min())
|
|
284
|
+
# the stations against the axis: the normal d × τ is then that of the path
|
|
285
|
+
s = np.linspace(along.max() + margin, along.min() - margin, stations)
|
|
286
|
+
base = np.asarray(path.points)
|
|
287
|
+
return cls(base[:, None, :] + s[None, :, None] * axis[None, None, :], False)
|
|
288
|
+
|
|
289
|
+
# -- the front -------------------------------------------------------------------------
|
|
290
|
+
|
|
291
|
+
@property
|
|
292
|
+
def stations(self) -> int:
|
|
293
|
+
return self.points.shape[1]
|
|
294
|
+
|
|
295
|
+
@property
|
|
296
|
+
def s(self) -> np.ndarray:
|
|
297
|
+
"""The coordinate of the stations along the front: an angle from -π for a closed
|
|
298
|
+
front (the length along it over its whole length), a length for an open one."""
|
|
299
|
+
return self._s
|
|
300
|
+
|
|
301
|
+
@property
|
|
302
|
+
def length(self) -> float:
|
|
303
|
+
"""The length of the front."""
|
|
304
|
+
return self._length
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def size(self) -> float:
|
|
308
|
+
"""The size of the crack: the mean distance of the front to its centre (a closed
|
|
309
|
+
front), or the mean length of the paths of its stations."""
|
|
310
|
+
if self.closed:
|
|
311
|
+
front = self.points[-1]
|
|
312
|
+
return float(np.linalg.norm(front - front.mean(axis=0), axis=1).mean())
|
|
313
|
+
return float(np.linalg.norm(np.diff(self.points, axis=0), axis=2).sum(axis=0).mean())
|
|
314
|
+
|
|
315
|
+
@property
|
|
316
|
+
def reach(self) -> float:
|
|
317
|
+
"""How far behind the front the surface stays in the plane of the axes ``d`` and
|
|
318
|
+
``t`` of the front, at the station where it does least: the domain of a virtual
|
|
319
|
+
advance tangent to the lips (the size of a planar crack, the last advance of a
|
|
320
|
+
kinked one)."""
|
|
321
|
+
back = self.points[::-1] - self.points[-1][None] # the rows, from the front
|
|
322
|
+
off = np.abs(np.einsum("rij,ij->ri", back, self._n))
|
|
323
|
+
behind = -np.einsum("rij,ij->ri", back, self._d)
|
|
324
|
+
planar = np.logical_and.accumulate(off <= 1e-6 * self._scale, axis=0)
|
|
325
|
+
return float(np.where(planar, behind, 0.0).max(axis=0).min())
|
|
326
|
+
|
|
327
|
+
def area(self) -> float:
|
|
328
|
+
"""The area of the surface (without its continuations)."""
|
|
329
|
+
grid = self.points
|
|
330
|
+
nxt = np.roll(grid, -1, axis=1) if self.closed else grid[:, 1:]
|
|
331
|
+
cur = grid if self.closed else grid[:, :-1]
|
|
332
|
+
a, b, c, e = cur[:-1], cur[1:], nxt[:-1], nxt[1:]
|
|
333
|
+
first = np.linalg.norm(np.cross(b - a, c - a), axis=-1)
|
|
334
|
+
second = np.linalg.norm(np.cross(e - b, c - b), axis=-1)
|
|
335
|
+
return float(0.5 * (first.sum() + second.sum()))
|
|
336
|
+
|
|
337
|
+
def _nearest(self, x):
|
|
338
|
+
"""Of points: the nearest point of the front, its axes ``d``, ``n``, ``t``
|
|
339
|
+
(interpolated between the stations) and its coordinate along the front."""
|
|
340
|
+
x = np.ascontiguousarray(np.atleast_2d(np.asarray(x, dtype=float)))
|
|
341
|
+
front = np.ascontiguousarray(self.points[-1])
|
|
342
|
+
segment, u = _nearest_on_front(x, front, self.closed)
|
|
343
|
+
after = (segment + 1) % self.stations
|
|
344
|
+
f = front[segment] + u[:, None] * (front[after] - front[segment])
|
|
345
|
+
w = np.clip(u, 0.0, 1.0)[:, None]
|
|
346
|
+
n = _unit((1.0 - w) * self._n[segment] + w * self._n[after])
|
|
347
|
+
d = (1.0 - w) * self._d[segment] + w * self._d[after]
|
|
348
|
+
d = _unit(d - np.einsum("ij,ij->i", d, n)[:, None] * n)
|
|
349
|
+
s = self._arc[segment] + u * self._lengths[segment]
|
|
350
|
+
if self.closed:
|
|
351
|
+
s = -np.pi + 2 * np.pi * s / self._length
|
|
352
|
+
return x, f, d, n, np.cross(d, n), s
|
|
353
|
+
|
|
354
|
+
def local(self, x):
|
|
355
|
+
"""The coordinates of points along the axes ``d`` and ``n`` of the front."""
|
|
356
|
+
x, f, d, n, _, _ = self._nearest(x)
|
|
357
|
+
y = x - f
|
|
358
|
+
return np.einsum("ij,ij->i", y, d), np.einsum("ij,ij->i", y, n)
|
|
359
|
+
|
|
360
|
+
def psi(self, x) -> np.ndarray:
|
|
361
|
+
"""Distance beyond the front along its direction of propagation (negative behind
|
|
362
|
+
it)."""
|
|
363
|
+
return self.local(x)[0]
|
|
364
|
+
|
|
365
|
+
def phi(self, x) -> np.ndarray:
|
|
366
|
+
"""Signed distance to the surface behind the front; ahead of it, to the surface
|
|
367
|
+
continued along the direction of propagation."""
|
|
368
|
+
x1, x2 = self.local(x)
|
|
369
|
+
x = np.ascontiguousarray(np.atleast_2d(np.asarray(x, dtype=float)))
|
|
370
|
+
behind = x1 < 0.0
|
|
371
|
+
out = x2.copy()
|
|
372
|
+
if np.any(behind):
|
|
373
|
+
out[behind] = _signed_distance(
|
|
374
|
+
x[behind], self._vertices, self._triangles, self._normals
|
|
375
|
+
)
|
|
376
|
+
return out
|
|
377
|
+
|
|
378
|
+
def frame(self, x):
|
|
379
|
+
"""As :meth:`~morphogen.fracture.lefm.Crack.frame`: the distance ``r`` to the front,
|
|
380
|
+
the axes ``n``, ``d``, ``t`` of its nearest point and the coordinate ``s`` along
|
|
381
|
+
it."""
|
|
382
|
+
x, f, d, n, t, s = self._nearest(x)
|
|
383
|
+
y = x - f
|
|
384
|
+
r = np.hypot(np.einsum("ij,ij->i", y, d), np.einsum("ij,ij->i", y, n))
|
|
385
|
+
return r, n, d, t, s
|
|
386
|
+
|
|
387
|
+
def front(self, lower, upper, count: int = _COUNT):
|
|
388
|
+
"""Points of the front inside the box ``[lower, upper]`` and the length of front
|
|
389
|
+
that each represents."""
|
|
390
|
+
front = self.points[-1]
|
|
391
|
+
ends = np.vstack([front, front[:1]]) if self.closed else front
|
|
392
|
+
at = (np.arange(count) + 0.5) * self._length / count
|
|
393
|
+
points = np.stack([np.interp(at, self._arc, ends[:, k]) for k in range(3)], axis=1)
|
|
394
|
+
inside = np.all(
|
|
395
|
+
(points >= np.asarray(lower) - 1e-9) & (points <= np.asarray(upper) + 1e-9), axis=1
|
|
396
|
+
)
|
|
397
|
+
return points[inside], np.full(int(inside.sum()), self._length / count)
|
|
398
|
+
|
|
399
|
+
# -- growth ----------------------------------------------------------------------------
|
|
400
|
+
|
|
401
|
+
def grown(self, da, angle=0.0) -> SurfaceCrack:
|
|
402
|
+
"""The crack whose stations have advanced by ``da`` at ``angle`` (radians) from
|
|
403
|
+
their direction of propagation towards the normal of the surface (numbers, or one
|
|
404
|
+
value per station): a new row. A negative ``da``, the same at all the stations
|
|
405
|
+
and shorter than the last row, moves the front back along it."""
|
|
406
|
+
da = np.broadcast_to(np.asarray(da, dtype=float), (self.stations,))
|
|
407
|
+
angle = np.broadcast_to(np.asarray(angle, dtype=float), (self.stations,))
|
|
408
|
+
if np.all(da < 0.0):
|
|
409
|
+
if np.any(angle != 0.0) or np.any(-da >= (1 - 1e-9) * self.reach):
|
|
410
|
+
raise ValueError("SurfaceCrack.grown: shortened within its last row, straight")
|
|
411
|
+
front = self.points[-1] + da[:, None] * self._d
|
|
412
|
+
return SurfaceCrack(np.concatenate([self.points[:-1], front[None]]), self.closed)
|
|
413
|
+
if np.any(da <= 0.0):
|
|
414
|
+
raise ValueError("SurfaceCrack.grown: positive advances (or the same negative one)")
|
|
415
|
+
step = np.cos(angle)[:, None] * self._d + np.sin(angle)[:, None] * self._n
|
|
416
|
+
front = np.round(self.points[-1] + da[:, None] * step, 10)
|
|
417
|
+
return SurfaceCrack(np.concatenate([self.points, front[None]]), self.closed)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
@dataclass
|
|
421
|
+
class FrontGrowth:
|
|
422
|
+
"""The steps of the growth of a :class:`SurfaceCrack`: the ``cracks``, the coordinates
|
|
423
|
+
``s`` of the stations of the interaction integrals along the front and, at them (steps
|
|
424
|
+
x stations), the energy release ``rates``, the stress intensity ``factors`` (a last
|
|
425
|
+
axis: the three modes) and the ``angles`` of kinking; the largest advance of each
|
|
426
|
+
step and the ``cycles`` (Paris), with ``keep`` the solutions."""
|
|
427
|
+
|
|
428
|
+
cracks: list
|
|
429
|
+
s: np.ndarray
|
|
430
|
+
rates: np.ndarray
|
|
431
|
+
factors: np.ndarray
|
|
432
|
+
angles: np.ndarray
|
|
433
|
+
advances: np.ndarray
|
|
434
|
+
cycles: np.ndarray
|
|
435
|
+
solutions: list = field(default_factory=list, repr=False)
|
|
436
|
+
|
|
437
|
+
def rows(self) -> list[dict]:
|
|
438
|
+
"""A row per step: the size and the area of the crack, the extremes of the energy
|
|
439
|
+
release rate and of the factors along its front, the largest angle of kinking."""
|
|
440
|
+
out = []
|
|
441
|
+
for k, crack in enumerate(self.cracks):
|
|
442
|
+
f = self.factors[k]
|
|
443
|
+
out.append(
|
|
444
|
+
{
|
|
445
|
+
"step": k,
|
|
446
|
+
"size": crack.size,
|
|
447
|
+
"area": crack.area(),
|
|
448
|
+
"front_length": crack.length,
|
|
449
|
+
"G_min": float(self.rates[k].min()),
|
|
450
|
+
"G_max": float(self.rates[k].max()),
|
|
451
|
+
"K_I_min": float(f[:, 0].min()),
|
|
452
|
+
"K_I_max": float(f[:, 0].max()),
|
|
453
|
+
"K_II_max": float(np.abs(f[:, 1]).max()),
|
|
454
|
+
"K_III_max": float(np.abs(f[:, 2]).max()),
|
|
455
|
+
"angle_max_deg": float(np.degrees(np.abs(self.angles[k]).max())),
|
|
456
|
+
"N": float(self.cycles[k]),
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
return out
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def at_stations(crack: SurfaceCrack, s, values, harmonics: int | None = None) -> np.ndarray:
|
|
463
|
+
"""Values given at the coordinates ``s`` along the front (increasing), at the stations
|
|
464
|
+
of the crack: interpolated linearly, or, around a closed front whose ``s`` are evenly
|
|
465
|
+
spaced, by their Fourier series up to ``harmonics`` (a smooth distribution, less the
|
|
466
|
+
noise of the values from station to station)."""
|
|
467
|
+
s, values = np.asarray(s, dtype=float), np.asarray(values, dtype=float)
|
|
468
|
+
if not crack.closed:
|
|
469
|
+
return np.interp(crack.s, s, values)
|
|
470
|
+
if harmonics is None:
|
|
471
|
+
return np.interp(crack.s, s, values, period=2 * np.pi)
|
|
472
|
+
count = len(s)
|
|
473
|
+
if not np.allclose(np.diff(s), 2 * np.pi / count):
|
|
474
|
+
raise ValueError("at_stations: evenly spaced stations around the front")
|
|
475
|
+
series = np.fft.rfft(values) / count
|
|
476
|
+
out = np.full(crack.stations, series[0].real)
|
|
477
|
+
for k in range(1, min(int(harmonics), (count - 1) // 2) + 1):
|
|
478
|
+
out += 2.0 * (series[k] * np.exp(1j * k * (crack.s - s[0]))).real
|
|
479
|
+
return out
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def propagate_front(
|
|
483
|
+
mesh_of,
|
|
484
|
+
crack: SurfaceCrack,
|
|
485
|
+
materials,
|
|
486
|
+
prescribed,
|
|
487
|
+
load: float = 1.0,
|
|
488
|
+
*,
|
|
489
|
+
increment: float,
|
|
490
|
+
steps: int,
|
|
491
|
+
stations: int = 12,
|
|
492
|
+
exponent: float = 2.0,
|
|
493
|
+
harmonics: int | None = None,
|
|
494
|
+
paris: tuple[float, float] | None = None,
|
|
495
|
+
kinematics: str = "small",
|
|
496
|
+
contact: float | bool | None = None,
|
|
497
|
+
domain: dict | None = None,
|
|
498
|
+
keep: bool = False,
|
|
499
|
+
**options,
|
|
500
|
+
) -> FrontGrowth:
|
|
501
|
+
"""Grow a crack of any surface, each point of its front by its own advance and at its
|
|
502
|
+
own angle (see the module): ``mesh_of(crack)`` meshes the body conforming to it
|
|
503
|
+
(:func:`~morphogen.fracture.lefm.crack_mesh`), ``prescribed`` (entries, or a function
|
|
504
|
+
of the opened mesh) and ``load`` load it (``options``: those of
|
|
505
|
+
:func:`~morphogen.fracture.mixed.solve_crack`). At each of the ``steps`` the energy
|
|
506
|
+
release rate and the factors are taken at ``stations`` along the front (at least two
|
|
507
|
+
elements apart), and the point where ``G`` is largest advances by ``increment``, the
|
|
508
|
+
others by ``increment (G / G_max)^(exponent / 2)`` (``exponent``: that of Paris' law;
|
|
509
|
+
with ``paris = (C, m)`` it is ``m``, and the cycles are counted), each in the
|
|
510
|
+
direction of the largest hoop stress of its ``K_I`` and ``K_II``; ``G`` is that of
|
|
511
|
+
the factors, ``(K_I² + K_II²) / E' + K_III² / 2μ``. ``domain``: the radii ``r_in``
|
|
512
|
+
and ``r_out`` of the domain of the interaction integrals (by default one and four
|
|
513
|
+
elements, within the last advance). Around a closed front the advances and the
|
|
514
|
+
angles are those of the Fourier series of their values at the stations up to
|
|
515
|
+
``harmonics`` (by default a third of the stations): a front that stays smooth, where
|
|
516
|
+
the noise of the factors, raised to the power of Paris' law, would scallop it."""
|
|
517
|
+
from morphogen.fracture.mixed import _isotropic_moduli, kink_angle, solve_crack
|
|
518
|
+
|
|
519
|
+
if not increment > 0:
|
|
520
|
+
raise ValueError("propagate_front: a positive increment")
|
|
521
|
+
if paris is not None:
|
|
522
|
+
exponent = float(paris[1])
|
|
523
|
+
if harmonics is None and crack.closed:
|
|
524
|
+
harmonics = max(1, int(stations) // 3)
|
|
525
|
+
cracks, rates, factors, angles, advances, cycles, solutions = [], [], [], [], [], [], []
|
|
526
|
+
n, s = 0.0, None
|
|
527
|
+
for step in range(int(steps) + 1):
|
|
528
|
+
solution = solve_crack(mesh_of(crack), crack, materials, prescribed, load,
|
|
529
|
+
kinematics=kinematics, contact=contact, **options) # fmt: skip
|
|
530
|
+
modes = solution.modes(stations=stations, **(domain or {}))
|
|
531
|
+
s = modes["s"]
|
|
532
|
+
k = np.stack([modes["K_I"], modes["K_II"], modes["K_III"]], axis=1)
|
|
533
|
+
# the energy release rate of the factors: along a front that turns sharply it is
|
|
534
|
+
# more even than that of the G-θ method, whose domain the curvature narrows
|
|
535
|
+
young, nu = _isotropic_moduli(solution.materials[solution.front_phase()])
|
|
536
|
+
e_prime, mu = young / (1 - nu**2), young / (2 * (1 + nu))
|
|
537
|
+
g = (k[:, 0] ** 2 + k[:, 1] ** 2) / e_prime + k[:, 2] ** 2 / (2 * mu)
|
|
538
|
+
turn = np.array([kink_angle(a, b) for a, b in k[:, :2]])
|
|
539
|
+
cracks.append(crack)
|
|
540
|
+
rates.append(g)
|
|
541
|
+
factors.append(k)
|
|
542
|
+
angles.append(turn)
|
|
543
|
+
cycles.append(n)
|
|
544
|
+
if keep:
|
|
545
|
+
solutions.append(solution)
|
|
546
|
+
if step == steps:
|
|
547
|
+
advances.append(0.0)
|
|
548
|
+
break
|
|
549
|
+
top = float(g.max())
|
|
550
|
+
if not top > 0:
|
|
551
|
+
raise ValueError("propagate_front: no energy is released along the front")
|
|
552
|
+
share = at_stations(crack, s, (g / top) ** (0.5 * exponent), harmonics)
|
|
553
|
+
share = share / share.max() # the fastest station advances by the increment
|
|
554
|
+
advance = increment * np.clip(share, 0.02, 1.0) # (none left behind for good)
|
|
555
|
+
advances.append(float(advance.max()))
|
|
556
|
+
if paris is not None:
|
|
557
|
+
c, m = paris
|
|
558
|
+
n += increment / (c * math.sqrt(e_prime * top) ** m)
|
|
559
|
+
# the angles through their sines and cosines: no jump from π to -π between stations
|
|
560
|
+
sine = at_stations(crack, s, np.sin(turn), harmonics)
|
|
561
|
+
cosine = at_stations(crack, s, np.cos(turn), harmonics)
|
|
562
|
+
crack = crack.grown(advance, np.arctan2(sine, cosine))
|
|
563
|
+
return FrontGrowth(
|
|
564
|
+
cracks,
|
|
565
|
+
np.asarray(s),
|
|
566
|
+
np.array(rates),
|
|
567
|
+
np.array(factors),
|
|
568
|
+
np.array(angles),
|
|
569
|
+
np.array(advances),
|
|
570
|
+
np.array(cycles),
|
|
571
|
+
solutions,
|
|
572
|
+
)
|