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,768 @@
|
|
|
1
|
+
"""Multiaxial high-cycle fatigue: criteria on the stress histories of a cycle.
|
|
2
|
+
|
|
3
|
+
In the high-cycle regime a material stays elastic at the scale of the cell, and whether
|
|
4
|
+
a point lasts is read from the cycle of its stress: an amplitude of shear, which
|
|
5
|
+
initiates the cracks, and a normal or hydrostatic stress, which opens them. The criteria
|
|
6
|
+
below judge the stresses of the points of a cell along a cycle of a loading path (its
|
|
7
|
+
fields at each step: :func:`path_fatigue`), or any history of stresses (``steps x ... x
|
|
8
|
+
6``, Voigt components 11, 22, 33, 23, 31, 12).
|
|
9
|
+
|
|
10
|
+
*The amplitude of a multiaxial cycle.* The deviator of the stress describes a closed
|
|
11
|
+
path in the five-dimensional space of deviators, with the norm ``sqrt(J2) = sqrt(s : s /
|
|
12
|
+
2)``. Its amplitude is the radius of the smallest hypersphere that holds the path, and
|
|
13
|
+
its mean the centre of that hypersphere (Papadopoulos et al. 1997; the longest chord, which
|
|
14
|
+
does not see the phase of the components, is not used): half the range of a
|
|
15
|
+
proportional cycle, the larger of ``σ_a / sqrt(3)`` and ``τ_a`` for a tension and a
|
|
16
|
+
torsion a quarter of a cycle apart. The hypersphere is found by Frank and Wolfe's
|
|
17
|
+
iteration with away steps on the dual problem (Yıldırım 2008), from the two points
|
|
18
|
+
farthest apart: at once for a proportional cycle.
|
|
19
|
+
|
|
20
|
+
*Criteria* (``f``: the fatigue limit in fully reversed tension or bending, ``t``: in
|
|
21
|
+
fully reversed torsion, ``f0``: in repeated tension, the largest stress of a cycle from
|
|
22
|
+
zero; each criterion gives an equivalent stress, to be compared with its limit):
|
|
23
|
+
|
|
24
|
+
* :class:`Crossland` (1956): ``sqrt(J2)_a + α σ_H,max <= β``, ``σ_H`` the hydrostatic
|
|
25
|
+
stress; ``α = 3 t / f - sqrt(3)``, ``β = t``.
|
|
26
|
+
* :class:`Sines` (1959): ``sqrt(J2)_a + α σ_H,mean <= β``; ``α = 6 t / f0 - sqrt(3)``,
|
|
27
|
+
``β = t``.
|
|
28
|
+
* :class:`DangVan` (1973; Dang Van, Griveau & Message 1989): at each instant, Tresca's
|
|
29
|
+
shear of the deviator less its mean (the stress of a grain that has shaken down in
|
|
30
|
+
its elastic matrix) and the hydrostatic stress, ``max_t [τ(t) + α σ_H(t)] <= β``;
|
|
31
|
+
``α = 3 t / f - 3 / 2``, ``β = t``.
|
|
32
|
+
* :class:`Findley` (1959), a critical plane: ``max_n [τ_a(n) + k σ_n,max(n)] <= λ`` over
|
|
33
|
+
the planes of normal ``n``, ``τ_a`` the amplitude of the shear vector of the plane
|
|
34
|
+
(the radius of the smallest circle that holds its path) and ``σ_n,max`` its largest
|
|
35
|
+
normal stress; with ``r = f / t``, ``k = (2 - r) / (2 sqrt(r - 1))`` and ``λ = t
|
|
36
|
+
sqrt(1 + k²)``.
|
|
37
|
+
* :class:`Matake` (1977): ``τ_a + k σ_n,max <= λ`` on the plane of the largest shear
|
|
38
|
+
amplitude; ``k = 2 t / f - 1``, ``λ = t``.
|
|
39
|
+
|
|
40
|
+
The planes are searched on a spiral of normals over a hemisphere, then around the best
|
|
41
|
+
of them by grids three times finer at each of four levels.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
from __future__ import annotations
|
|
45
|
+
|
|
46
|
+
import math
|
|
47
|
+
from dataclasses import dataclass, field
|
|
48
|
+
|
|
49
|
+
import numpy as np
|
|
50
|
+
from numba import njit, prange
|
|
51
|
+
|
|
52
|
+
#: The criteria by their names in configurations
|
|
53
|
+
CRITERIA = ("crossland", "sines", "dang_van", "findley", "matake")
|
|
54
|
+
#: Normals of the first search of a critical plane (a spiral over a hemisphere)
|
|
55
|
+
PLANES = 400
|
|
56
|
+
_SQRT2 = math.sqrt(2.0)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# -- the smallest ball of a path ------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@njit(cache=True)
|
|
63
|
+
def _ball(points, tol, weights, centre):
|
|
64
|
+
"""The smallest ball that holds ``points`` (rows): its radius, to the relative
|
|
65
|
+
accuracy ``tol``, and its ``centre`` (written); ``weights``: a work array, one value
|
|
66
|
+
per point."""
|
|
67
|
+
n, d = points.shape
|
|
68
|
+
first, best = 0, -1.0
|
|
69
|
+
for i in range(n):
|
|
70
|
+
dist = 0.0
|
|
71
|
+
for c in range(d):
|
|
72
|
+
dist += (points[i, c] - points[0, c]) ** 2
|
|
73
|
+
if dist > best:
|
|
74
|
+
best, first = dist, i
|
|
75
|
+
second, best = first, -1.0
|
|
76
|
+
for i in range(n):
|
|
77
|
+
dist = 0.0
|
|
78
|
+
for c in range(d):
|
|
79
|
+
dist += (points[i, c] - points[first, c]) ** 2
|
|
80
|
+
if dist > best:
|
|
81
|
+
best, second = dist, i
|
|
82
|
+
for i in range(n):
|
|
83
|
+
weights[i] = 0.0
|
|
84
|
+
weights[first] += 0.5
|
|
85
|
+
weights[second] += 0.5
|
|
86
|
+
for c in range(d):
|
|
87
|
+
centre[c] = 0.5 * (points[first, c] + points[second, c])
|
|
88
|
+
if best <= 0.0:
|
|
89
|
+
return 0.0
|
|
90
|
+
bound = (1.0 + tol) ** 2 - 1.0
|
|
91
|
+
far_dist = 0.25 * best
|
|
92
|
+
for _ in range(100 * n + 1000):
|
|
93
|
+
gamma, far, near = 0.0, 0, -1
|
|
94
|
+
far_dist, near_dist = -1.0, math.inf
|
|
95
|
+
for i in range(n):
|
|
96
|
+
dist = 0.0
|
|
97
|
+
for c in range(d):
|
|
98
|
+
dist += (points[i, c] - centre[c]) ** 2
|
|
99
|
+
if dist > far_dist:
|
|
100
|
+
far_dist, far = dist, i
|
|
101
|
+
if weights[i] > 0.0:
|
|
102
|
+
gamma += weights[i] * dist
|
|
103
|
+
if dist < near_dist:
|
|
104
|
+
near_dist, near = dist, i
|
|
105
|
+
if gamma <= 0.0:
|
|
106
|
+
break
|
|
107
|
+
plus = far_dist / gamma - 1.0
|
|
108
|
+
minus = 1.0 - near_dist / gamma
|
|
109
|
+
if plus <= bound and minus <= bound:
|
|
110
|
+
break
|
|
111
|
+
if plus > minus: # towards the farthest point
|
|
112
|
+
step = plus / (2.0 * (1.0 + plus))
|
|
113
|
+
for i in range(n):
|
|
114
|
+
weights[i] *= 1.0 - step
|
|
115
|
+
weights[far] += step
|
|
116
|
+
for c in range(d):
|
|
117
|
+
centre[c] = (1.0 - step) * centre[c] + step * points[far, c]
|
|
118
|
+
else: # away from the nearest point of the support
|
|
119
|
+
limit = weights[near] / (1.0 - weights[near])
|
|
120
|
+
step = limit if near_dist <= 0.0 else min(limit, minus / (2.0 * (1.0 - minus)))
|
|
121
|
+
for i in range(n):
|
|
122
|
+
weights[i] *= 1.0 + step
|
|
123
|
+
weights[near] = 0.0 if step >= limit else weights[near] - step
|
|
124
|
+
for c in range(d):
|
|
125
|
+
centre[c] = (1.0 + step) * centre[c] - step * points[near, c]
|
|
126
|
+
far_dist = 0.0
|
|
127
|
+
for i in range(n):
|
|
128
|
+
dist = 0.0
|
|
129
|
+
for c in range(d):
|
|
130
|
+
dist += (points[i, c] - centre[c]) ** 2
|
|
131
|
+
if dist > far_dist:
|
|
132
|
+
far_dist = dist
|
|
133
|
+
return math.sqrt(far_dist)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@njit(parallel=True, cache=True)
|
|
137
|
+
def _amplitudes(vectors, tol, centres, radii):
|
|
138
|
+
"""The smallest balls of the paths ``vectors`` (steps x points x d) of each point."""
|
|
139
|
+
steps, n, d = vectors.shape
|
|
140
|
+
for p in prange(n):
|
|
141
|
+
path = np.empty((steps, d))
|
|
142
|
+
for t in range(steps):
|
|
143
|
+
for c in range(d):
|
|
144
|
+
path[t, c] = vectors[t, p, c]
|
|
145
|
+
centre = np.empty(d)
|
|
146
|
+
radii[p] = _ball(path, tol, np.empty(steps), centre)
|
|
147
|
+
for c in range(d):
|
|
148
|
+
centres[p, c] = centre[c]
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@njit(cache=True)
|
|
152
|
+
def _tresca(s):
|
|
153
|
+
"""Tresca's shear (half the difference of the extreme principal values) of a
|
|
154
|
+
deviator in Voigt components."""
|
|
155
|
+
j2 = 0.5 * (s[0] * s[0] + s[1] * s[1] + s[2] * s[2]) + s[3] * s[3] + s[4] * s[4] + s[5] * s[5]
|
|
156
|
+
if j2 <= 0.0:
|
|
157
|
+
return 0.0
|
|
158
|
+
j3 = (
|
|
159
|
+
s[0] * s[1] * s[2]
|
|
160
|
+
+ 2.0 * s[3] * s[4] * s[5]
|
|
161
|
+
- s[0] * s[3] * s[3]
|
|
162
|
+
- s[1] * s[4] * s[4]
|
|
163
|
+
- s[2] * s[5] * s[5]
|
|
164
|
+
)
|
|
165
|
+
cos3 = 1.5 * math.sqrt(3.0) * j3 / j2**1.5
|
|
166
|
+
cos3 = min(1.0, max(-1.0, cos3))
|
|
167
|
+
theta = math.acos(cos3) / 3.0 # Lode's angle, in [0, π/3]
|
|
168
|
+
return math.sqrt(j2) * math.sin(theta + math.pi / 3.0)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@njit(parallel=True, cache=True)
|
|
172
|
+
def _dang_van(deviators, hydro, means, alpha, out):
|
|
173
|
+
"""``max_t [τ(t) + α σ_H(t)]`` of each point, ``τ`` Tresca's shear of its deviator
|
|
174
|
+
less its mean."""
|
|
175
|
+
steps, n, _ = deviators.shape
|
|
176
|
+
for p in prange(n):
|
|
177
|
+
s = np.empty(6)
|
|
178
|
+
best = -math.inf
|
|
179
|
+
for t in range(steps):
|
|
180
|
+
for c in range(6):
|
|
181
|
+
s[c] = deviators[t, p, c] - means[p, c]
|
|
182
|
+
value = _tresca(s) + alpha * hydro[t, p]
|
|
183
|
+
if value > best:
|
|
184
|
+
best = value
|
|
185
|
+
out[p] = best
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# -- critical planes ---------------------------------------------------------------------------
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _spiral(count: int) -> np.ndarray:
|
|
192
|
+
"""Normals spread over a hemisphere (a Fibonacci spiral)."""
|
|
193
|
+
k = np.arange(count) + 0.5
|
|
194
|
+
z = 1.0 - k / count
|
|
195
|
+
angle = math.pi * (1.0 + math.sqrt(5.0)) * k
|
|
196
|
+
r = np.sqrt(1.0 - z * z)
|
|
197
|
+
return np.ascontiguousarray(np.stack([r * np.cos(angle), r * np.sin(angle), z], axis=1))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@njit(cache=True)
|
|
201
|
+
def _plane(stress, normal, tol, shear, weights, centre):
|
|
202
|
+
"""The amplitude of the shear vector and the largest normal stress of the plane of
|
|
203
|
+
``normal`` along the stresses ``stress`` (steps x 6); ``shear`` (steps x 3),
|
|
204
|
+
``weights`` and ``centre``: work arrays."""
|
|
205
|
+
steps = stress.shape[0]
|
|
206
|
+
nx, ny, nz = normal[0], normal[1], normal[2]
|
|
207
|
+
largest = -math.inf
|
|
208
|
+
for t in range(steps):
|
|
209
|
+
s = stress[t]
|
|
210
|
+
tx = s[0] * nx + s[5] * ny + s[4] * nz
|
|
211
|
+
ty = s[5] * nx + s[1] * ny + s[3] * nz
|
|
212
|
+
tz = s[4] * nx + s[3] * ny + s[2] * nz
|
|
213
|
+
sn = tx * nx + ty * ny + tz * nz
|
|
214
|
+
shear[t, 0] = tx - sn * nx
|
|
215
|
+
shear[t, 1] = ty - sn * ny
|
|
216
|
+
shear[t, 2] = tz - sn * nz
|
|
217
|
+
if sn > largest:
|
|
218
|
+
largest = sn
|
|
219
|
+
return _ball(shear, tol, weights, centre), largest
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@njit(parallel=True, cache=True)
|
|
223
|
+
def _critical_planes(stress, normals, k, matake, tol, values, planes, shears, pressures):
|
|
224
|
+
"""The critical plane of each point (``stress``: steps x points x 6): the value of
|
|
225
|
+
its criterion, its normal, its shear amplitude and its largest normal stress.
|
|
226
|
+
``matake``: the plane of the largest shear amplitude (among the planes within a
|
|
227
|
+
thousandth of it, that of the largest value); otherwise that of the largest value
|
|
228
|
+
``τ_a + k σ_n,max``."""
|
|
229
|
+
steps, n, _ = stress.shape
|
|
230
|
+
m = normals.shape[0]
|
|
231
|
+
spacing = math.sqrt(2.0 * math.pi / m)
|
|
232
|
+
starts = 6
|
|
233
|
+
for p in prange(n):
|
|
234
|
+
history = np.empty((steps, 6))
|
|
235
|
+
for t in range(steps):
|
|
236
|
+
for c in range(6):
|
|
237
|
+
history[t, c] = stress[t, p, c]
|
|
238
|
+
shear = np.empty((steps, 3))
|
|
239
|
+
weights = np.empty(steps)
|
|
240
|
+
centre = np.empty(3)
|
|
241
|
+
# the best normals of the spiral, for the objective of the search
|
|
242
|
+
top = np.full(starts, -math.inf)
|
|
243
|
+
index = np.zeros(starts, dtype=np.int64)
|
|
244
|
+
for j in range(m):
|
|
245
|
+
amplitude, largest = _plane(history, normals[j], tol, shear, weights, centre)
|
|
246
|
+
objective = amplitude if matake else amplitude + k * largest
|
|
247
|
+
worst = 0
|
|
248
|
+
for q in range(1, starts):
|
|
249
|
+
if top[q] < top[worst]:
|
|
250
|
+
worst = q
|
|
251
|
+
if objective > top[worst]:
|
|
252
|
+
top[worst], index[worst] = objective, j
|
|
253
|
+
found = np.empty((starts, 5)) # objective, amplitude, largest, and the normal below
|
|
254
|
+
found_normals = np.empty((starts, 3))
|
|
255
|
+
trial = np.empty(3)
|
|
256
|
+
e1 = np.empty(3)
|
|
257
|
+
e2 = np.empty(3)
|
|
258
|
+
for q in range(starts):
|
|
259
|
+
best = normals[index[q]].copy()
|
|
260
|
+
amplitude, largest = _plane(history, best, tol, shear, weights, centre)
|
|
261
|
+
objective = amplitude if matake else amplitude + k * largest
|
|
262
|
+
step = 0.5 * spacing
|
|
263
|
+
for _ in range(4):
|
|
264
|
+
# two tangents of the sphere at the best normal
|
|
265
|
+
a = 0 if abs(best[0]) < 0.9 else 1
|
|
266
|
+
e1[:] = 0.0
|
|
267
|
+
e1[a] = 1.0
|
|
268
|
+
dot = e1[0] * best[0] + e1[1] * best[1] + e1[2] * best[2]
|
|
269
|
+
for c in range(3):
|
|
270
|
+
e1[c] -= dot * best[c]
|
|
271
|
+
norm = math.sqrt(e1[0] ** 2 + e1[1] ** 2 + e1[2] ** 2)
|
|
272
|
+
for c in range(3):
|
|
273
|
+
e1[c] /= norm
|
|
274
|
+
e2[0] = best[1] * e1[2] - best[2] * e1[1]
|
|
275
|
+
e2[1] = best[2] * e1[0] - best[0] * e1[2]
|
|
276
|
+
e2[2] = best[0] * e1[1] - best[1] * e1[0]
|
|
277
|
+
origin = best.copy()
|
|
278
|
+
for i in range(-2, 3):
|
|
279
|
+
for j in range(-2, 3):
|
|
280
|
+
if i == 0 and j == 0:
|
|
281
|
+
continue
|
|
282
|
+
for c in range(3):
|
|
283
|
+
trial[c] = origin[c] + step * (i * e1[c] + j * e2[c])
|
|
284
|
+
norm = math.sqrt(trial[0] ** 2 + trial[1] ** 2 + trial[2] ** 2)
|
|
285
|
+
for c in range(3):
|
|
286
|
+
trial[c] /= norm
|
|
287
|
+
amp, big = _plane(history, trial, tol, shear, weights, centre)
|
|
288
|
+
value = amp if matake else amp + k * big
|
|
289
|
+
if value > objective:
|
|
290
|
+
objective, amplitude, largest = value, amp, big
|
|
291
|
+
best[:] = trial
|
|
292
|
+
step /= 3.0
|
|
293
|
+
found[q, 0], found[q, 1], found[q, 2] = objective, amplitude, largest
|
|
294
|
+
found_normals[q] = best
|
|
295
|
+
choice, chosen = 0, -math.inf
|
|
296
|
+
peak = found[:, 0].max()
|
|
297
|
+
for q in range(starts):
|
|
298
|
+
if matake and found[q, 0] < 0.999 * peak:
|
|
299
|
+
continue
|
|
300
|
+
value = found[q, 1] + k * found[q, 2]
|
|
301
|
+
if value > chosen:
|
|
302
|
+
chosen, choice = value, q
|
|
303
|
+
values[p] = chosen
|
|
304
|
+
shears[p] = found[choice, 1]
|
|
305
|
+
pressures[p] = found[choice, 2]
|
|
306
|
+
for c in range(3):
|
|
307
|
+
planes[p, c] = found_normals[choice, c]
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
# -- measures of a history ---------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _history(history) -> np.ndarray:
|
|
314
|
+
stress = np.asarray(history, dtype=float)
|
|
315
|
+
if stress.ndim < 2 or stress.shape[-1] != 6 or stress.shape[0] < 2:
|
|
316
|
+
raise ValueError(
|
|
317
|
+
"fatigue: the stresses of a cycle, steps x ... x 6 (Voigt components 11, 22, "
|
|
318
|
+
"33, 23, 31, 12), at two steps at least"
|
|
319
|
+
)
|
|
320
|
+
if not np.all(np.isfinite(stress)):
|
|
321
|
+
raise ValueError("fatigue: stresses that are not finite")
|
|
322
|
+
return stress
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def hydrostatic(history) -> np.ndarray:
|
|
326
|
+
"""The hydrostatic stress ``tr σ / 3`` of the stresses of a history (steps x ...)."""
|
|
327
|
+
return _history(history)[..., :3].mean(axis=-1)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def stress_amplitude(history, tol: float = 1e-10) -> tuple[np.ndarray, np.ndarray]:
|
|
331
|
+
"""The amplitude and the mean of the deviator of a cycle of stresses (``history``:
|
|
332
|
+
steps x ... x 6): ``sqrt(J2)_a``, the radius of the smallest hypersphere that holds
|
|
333
|
+
the path of the deviator (norm ``sqrt(s : s / 2)``; to the relative accuracy
|
|
334
|
+
``tol``), and its centre, the mean deviator (... x 6)."""
|
|
335
|
+
stress = _history(history)
|
|
336
|
+
shape = stress.shape[1:-1]
|
|
337
|
+
flat = stress.reshape(stress.shape[0], -1, 6)
|
|
338
|
+
deviator = flat.copy()
|
|
339
|
+
deviator[..., :3] -= flat[..., :3].mean(axis=-1, keepdims=True)
|
|
340
|
+
# components whose Euclidean norm is sqrt(J2)
|
|
341
|
+
scale = np.array([1.0, 1.0, 1.0, _SQRT2, _SQRT2, _SQRT2]) / _SQRT2
|
|
342
|
+
vectors = np.ascontiguousarray(deviator * scale)
|
|
343
|
+
centres = np.zeros((flat.shape[1], 6))
|
|
344
|
+
radii = np.zeros(flat.shape[1])
|
|
345
|
+
_amplitudes(vectors, float(tol), centres, radii)
|
|
346
|
+
return radii.reshape(shape), (centres / scale).reshape(*shape, 6)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
# -- criteria -------------------------------------------------------------------------------------
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _positive(name: str, **values) -> None:
|
|
353
|
+
for key, value in values.items():
|
|
354
|
+
if not (math.isfinite(value) and value > 0):
|
|
355
|
+
raise ValueError(f"{name}: a positive {key}, got {value!r}")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _ratio(name: str, bending: float, torsion: float, low: float, high: float) -> float:
|
|
359
|
+
"""The ratio of the torsion limit to the bending limit, within the bounds for which
|
|
360
|
+
the criterion has a meaning (a normal stress that lowers the limit)."""
|
|
361
|
+
_positive(name, bending=bending, torsion=torsion)
|
|
362
|
+
ratio = torsion / bending
|
|
363
|
+
if not low <= ratio <= high:
|
|
364
|
+
raise ValueError(
|
|
365
|
+
f"{name}: a torsion limit between {low:.3g} and {high:.3g} times the bending "
|
|
366
|
+
f"limit, got {ratio:.3g} times"
|
|
367
|
+
)
|
|
368
|
+
return ratio
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
@dataclass(frozen=True)
|
|
372
|
+
class Crossland:
|
|
373
|
+
"""Crossland's criterion (see the module): ``sqrt(J2)_a + alpha σ_H,max <= beta``."""
|
|
374
|
+
|
|
375
|
+
alpha: float
|
|
376
|
+
beta: float
|
|
377
|
+
name = "crossland"
|
|
378
|
+
|
|
379
|
+
def __post_init__(self) -> None:
|
|
380
|
+
_positive("Crossland", beta=self.beta)
|
|
381
|
+
if not (math.isfinite(self.alpha) and self.alpha >= 0):
|
|
382
|
+
raise ValueError("Crossland: alpha of 0 or more")
|
|
383
|
+
|
|
384
|
+
@classmethod
|
|
385
|
+
def from_limits(cls, bending: float, torsion: float) -> Crossland:
|
|
386
|
+
"""From the fatigue limits in fully reversed bending (or tension) and torsion."""
|
|
387
|
+
ratio = _ratio("Crossland", bending, torsion, 1.0 / math.sqrt(3.0), math.inf)
|
|
388
|
+
return cls(3.0 * ratio - math.sqrt(3.0), float(torsion))
|
|
389
|
+
|
|
390
|
+
@property
|
|
391
|
+
def limit(self) -> float:
|
|
392
|
+
return self.beta
|
|
393
|
+
|
|
394
|
+
def equivalent(self, history) -> np.ndarray:
|
|
395
|
+
"""The equivalent stress of each point, to be compared with :attr:`limit`."""
|
|
396
|
+
amplitude, _ = stress_amplitude(history)
|
|
397
|
+
return amplitude + self.alpha * hydrostatic(history).max(axis=0)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
@dataclass(frozen=True)
|
|
401
|
+
class Sines:
|
|
402
|
+
"""Sines' criterion (see the module): ``sqrt(J2)_a + alpha σ_H,mean <= beta``, the
|
|
403
|
+
mean of the hydrostatic stress being that of its extremes over the cycle."""
|
|
404
|
+
|
|
405
|
+
alpha: float
|
|
406
|
+
beta: float
|
|
407
|
+
name = "sines"
|
|
408
|
+
|
|
409
|
+
def __post_init__(self) -> None:
|
|
410
|
+
_positive("Sines", beta=self.beta)
|
|
411
|
+
if not (math.isfinite(self.alpha) and self.alpha >= 0):
|
|
412
|
+
raise ValueError("Sines: alpha of 0 or more")
|
|
413
|
+
|
|
414
|
+
@classmethod
|
|
415
|
+
def from_limits(cls, torsion: float, repeated: float) -> Sines:
|
|
416
|
+
"""From the fatigue limits in fully reversed torsion and in repeated tension (the
|
|
417
|
+
largest stress of a cycle from zero)."""
|
|
418
|
+
_positive("Sines", torsion=torsion, repeated=repeated)
|
|
419
|
+
alpha = 6.0 * torsion / repeated - math.sqrt(3.0)
|
|
420
|
+
if alpha < 0:
|
|
421
|
+
raise ValueError(
|
|
422
|
+
"Sines: a limit in repeated tension below 2 sqrt(3) times the torsion limit"
|
|
423
|
+
)
|
|
424
|
+
return cls(alpha, float(torsion))
|
|
425
|
+
|
|
426
|
+
@property
|
|
427
|
+
def limit(self) -> float:
|
|
428
|
+
return self.beta
|
|
429
|
+
|
|
430
|
+
def equivalent(self, history) -> np.ndarray:
|
|
431
|
+
amplitude, _ = stress_amplitude(history)
|
|
432
|
+
hydro = hydrostatic(history)
|
|
433
|
+
return amplitude + self.alpha * 0.5 * (hydro.max(axis=0) + hydro.min(axis=0))
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
@dataclass(frozen=True)
|
|
437
|
+
class DangVan:
|
|
438
|
+
"""Dang Van's criterion (see the module): ``max_t [τ(t) + alpha σ_H(t)] <= beta``."""
|
|
439
|
+
|
|
440
|
+
alpha: float
|
|
441
|
+
beta: float
|
|
442
|
+
name = "dang_van"
|
|
443
|
+
|
|
444
|
+
def __post_init__(self) -> None:
|
|
445
|
+
_positive("DangVan", beta=self.beta)
|
|
446
|
+
if not (math.isfinite(self.alpha) and self.alpha >= 0):
|
|
447
|
+
raise ValueError("DangVan: alpha of 0 or more")
|
|
448
|
+
|
|
449
|
+
@classmethod
|
|
450
|
+
def from_limits(cls, bending: float, torsion: float) -> DangVan:
|
|
451
|
+
"""From the fatigue limits in fully reversed bending (or tension) and torsion."""
|
|
452
|
+
ratio = _ratio("DangVan", bending, torsion, 0.5, math.inf)
|
|
453
|
+
return cls(3.0 * ratio - 1.5, float(torsion))
|
|
454
|
+
|
|
455
|
+
@property
|
|
456
|
+
def limit(self) -> float:
|
|
457
|
+
return self.beta
|
|
458
|
+
|
|
459
|
+
def equivalent(self, history) -> np.ndarray:
|
|
460
|
+
stress = _history(history)
|
|
461
|
+
shape = stress.shape[1:-1]
|
|
462
|
+
_, mean = stress_amplitude(stress)
|
|
463
|
+
flat = stress.reshape(stress.shape[0], -1, 6)
|
|
464
|
+
hydro = flat[..., :3].mean(axis=-1)
|
|
465
|
+
deviator = flat.copy()
|
|
466
|
+
deviator[..., :3] -= hydro[..., None]
|
|
467
|
+
out = np.zeros(flat.shape[1])
|
|
468
|
+
_dang_van(np.ascontiguousarray(deviator), np.ascontiguousarray(hydro),
|
|
469
|
+
np.ascontiguousarray(mean.reshape(-1, 6)), float(self.alpha), out) # fmt: skip
|
|
470
|
+
return out.reshape(shape)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
class _CriticalPlane:
|
|
474
|
+
"""The criteria of a critical plane: ``τ_a + k σ_n,max <= limit`` on a plane."""
|
|
475
|
+
|
|
476
|
+
k: float
|
|
477
|
+
limit: float
|
|
478
|
+
planes: int
|
|
479
|
+
_matake = False
|
|
480
|
+
|
|
481
|
+
def critical_plane(self, history) -> dict:
|
|
482
|
+
"""The critical plane of each point: the ``equivalent`` stress of the criterion,
|
|
483
|
+
the ``normal`` of the plane (... x 3), its ``shear`` amplitude and its largest
|
|
484
|
+
``normal_stress``."""
|
|
485
|
+
stress = _history(history)
|
|
486
|
+
shape = stress.shape[1:-1]
|
|
487
|
+
flat = np.ascontiguousarray(stress.reshape(stress.shape[0], -1, 6))
|
|
488
|
+
n = flat.shape[1]
|
|
489
|
+
values, shears, pressures = np.zeros(n), np.zeros(n), np.zeros(n)
|
|
490
|
+
normals = np.zeros((n, 3))
|
|
491
|
+
_critical_planes(flat, _spiral(self.planes), float(self.k), self._matake, 1e-7,
|
|
492
|
+
values, normals, shears, pressures) # fmt: skip
|
|
493
|
+
return {
|
|
494
|
+
"equivalent": values.reshape(shape),
|
|
495
|
+
"normal": normals.reshape(*shape, 3),
|
|
496
|
+
"shear": shears.reshape(shape),
|
|
497
|
+
"normal_stress": pressures.reshape(shape),
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
def equivalent(self, history) -> np.ndarray:
|
|
501
|
+
return self.critical_plane(history)["equivalent"]
|
|
502
|
+
|
|
503
|
+
def _check(self, name: str) -> None:
|
|
504
|
+
_positive(name, limit=self.limit)
|
|
505
|
+
if not (math.isfinite(self.k) and self.k >= 0):
|
|
506
|
+
raise ValueError(f"{name}: k of 0 or more")
|
|
507
|
+
if self.planes < 20:
|
|
508
|
+
raise ValueError(f"{name}: 20 planes at least for the first search")
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
@dataclass(frozen=True)
|
|
512
|
+
class Findley(_CriticalPlane):
|
|
513
|
+
"""Findley's criterion (see the module): ``max_n [τ_a(n) + k σ_n,max(n)] <= limit``;
|
|
514
|
+
``planes``: the normals of the first search."""
|
|
515
|
+
|
|
516
|
+
k: float
|
|
517
|
+
limit: float
|
|
518
|
+
planes: int = PLANES
|
|
519
|
+
name = "findley"
|
|
520
|
+
|
|
521
|
+
def __post_init__(self) -> None:
|
|
522
|
+
self._check("Findley")
|
|
523
|
+
|
|
524
|
+
@classmethod
|
|
525
|
+
def from_limits(cls, bending: float, torsion: float, planes: int = PLANES) -> Findley:
|
|
526
|
+
"""From the fatigue limits in fully reversed bending (or tension) and torsion."""
|
|
527
|
+
ratio = 1.0 / _ratio("Findley", bending, torsion, 0.5, 1.0 - 1e-12)
|
|
528
|
+
k = (2.0 - ratio) / (2.0 * math.sqrt(ratio - 1.0))
|
|
529
|
+
return cls(k, float(torsion) * math.sqrt(1.0 + k * k), planes)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
@dataclass(frozen=True)
|
|
533
|
+
class Matake(_CriticalPlane):
|
|
534
|
+
"""Matake's criterion (see the module): ``τ_a + k σ_n,max <= limit`` on the plane of
|
|
535
|
+
the largest shear amplitude; ``planes``: the normals of the first search."""
|
|
536
|
+
|
|
537
|
+
k: float
|
|
538
|
+
limit: float
|
|
539
|
+
planes: int = PLANES
|
|
540
|
+
name = "matake"
|
|
541
|
+
_matake = True
|
|
542
|
+
|
|
543
|
+
def __post_init__(self) -> None:
|
|
544
|
+
self._check("Matake")
|
|
545
|
+
|
|
546
|
+
@classmethod
|
|
547
|
+
def from_limits(cls, bending: float, torsion: float, planes: int = PLANES) -> Matake:
|
|
548
|
+
"""From the fatigue limits in fully reversed bending (or tension) and torsion."""
|
|
549
|
+
ratio = _ratio("Matake", bending, torsion, 0.5, math.inf)
|
|
550
|
+
return cls(2.0 * ratio - 1.0, float(torsion), planes)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def criterion_from_config(spec):
|
|
554
|
+
"""A criterion from a mapping: its ``criterion`` (one of :data:`CRITERIA`) and either
|
|
555
|
+
its fatigue limits (``bending`` and ``torsion``; ``torsion`` and ``repeated`` for
|
|
556
|
+
Sines) or its coefficients (``alpha`` and ``beta``; ``k`` and ``limit`` for the
|
|
557
|
+
critical planes, with their ``planes``)."""
|
|
558
|
+
if not isinstance(spec, dict):
|
|
559
|
+
raise ValueError("fatigue: a mapping of a criterion and its limits")
|
|
560
|
+
spec = dict(spec)
|
|
561
|
+
name = spec.pop("criterion", None)
|
|
562
|
+
classes = {"crossland": Crossland, "sines": Sines, "dang_van": DangVan,
|
|
563
|
+
"findley": Findley, "matake": Matake} # fmt: skip
|
|
564
|
+
if name not in classes:
|
|
565
|
+
raise ValueError(f"fatigue: the criterion is one of {list(CRITERIA)}, got {name!r}")
|
|
566
|
+
cls = classes[name]
|
|
567
|
+
plane = name in ("findley", "matake")
|
|
568
|
+
coefficients = ("k", "limit") if plane else ("alpha", "beta")
|
|
569
|
+
limits = ("torsion", "repeated") if name == "sines" else ("bending", "torsion")
|
|
570
|
+
allowed = set(coefficients) | set(limits) | ({"planes"} if plane else set())
|
|
571
|
+
unknown = sorted(set(spec) - allowed)
|
|
572
|
+
if unknown:
|
|
573
|
+
raise ValueError(
|
|
574
|
+
f"fatigue: unknown parameters {unknown} of the criterion {name!r}; use "
|
|
575
|
+
f"{list(limits)} or {list(coefficients)}" + (" and 'planes'" if plane else "")
|
|
576
|
+
)
|
|
577
|
+
try:
|
|
578
|
+
values = {key: float(value) for key, value in spec.items() if key != "planes"}
|
|
579
|
+
extra = {"planes": int(spec["planes"])} if "planes" in spec else {}
|
|
580
|
+
except (TypeError, ValueError):
|
|
581
|
+
raise ValueError(f"fatigue: the parameters of the criterion {name!r} are numbers") from None
|
|
582
|
+
if all(key in values for key in coefficients) and not any(key in values for key in limits):
|
|
583
|
+
return cls(*(values[key] for key in coefficients), **extra)
|
|
584
|
+
if all(key in values for key in limits) and not any(key in values for key in coefficients):
|
|
585
|
+
return cls.from_limits(*(values[key] for key in limits), **extra)
|
|
586
|
+
raise ValueError(
|
|
587
|
+
f"fatigue: the criterion {name!r} takes its limits {list(limits)} or its "
|
|
588
|
+
f"coefficients {list(coefficients)}"
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
# -- the fields of a loading path -----------------------------------------------------------------
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
@dataclass
|
|
596
|
+
class FatigueResult:
|
|
597
|
+
"""The fatigue of the points of a cell along a cycle: the ``equivalent`` stress of
|
|
598
|
+
the criterion of each point and its ``utilization``, the equivalent stress over the
|
|
599
|
+
limit (1: at the fatigue limit; NaN where no criterion applies), the ``amplitude``
|
|
600
|
+
``sqrt(J2)_a`` of the deviator, the largest and the mean hydrostatic stress
|
|
601
|
+
(``hydrostatic_max``, ``hydrostatic_mean``), the ``times`` of the cycle, the
|
|
602
|
+
``weights`` of the points (volumes, when their support gives them) and their
|
|
603
|
+
``support`` (mesh or image)."""
|
|
604
|
+
|
|
605
|
+
equivalent: np.ndarray
|
|
606
|
+
utilization: np.ndarray
|
|
607
|
+
amplitude: np.ndarray
|
|
608
|
+
hydrostatic_max: np.ndarray
|
|
609
|
+
hydrostatic_mean: np.ndarray
|
|
610
|
+
times: np.ndarray
|
|
611
|
+
weights: np.ndarray | None = field(default=None, repr=False)
|
|
612
|
+
support: object | None = field(default=None, repr=False)
|
|
613
|
+
|
|
614
|
+
@property
|
|
615
|
+
def largest(self) -> float:
|
|
616
|
+
"""The largest utilization of the cell (NaN when no point is judged)."""
|
|
617
|
+
judged = self.utilization[np.isfinite(self.utilization)]
|
|
618
|
+
return float(judged.max()) if judged.size else float("nan")
|
|
619
|
+
|
|
620
|
+
@property
|
|
621
|
+
def safety(self) -> float:
|
|
622
|
+
"""The factor by which the stresses of the cycle may be multiplied before a
|
|
623
|
+
point reaches its limit, for a loading that grows in proportion: the inverse of
|
|
624
|
+
the largest utilization."""
|
|
625
|
+
largest = self.largest
|
|
626
|
+
return 1.0 / largest if largest > 0 else float("inf")
|
|
627
|
+
|
|
628
|
+
def fraction(self, level: float = 1.0) -> float:
|
|
629
|
+
"""The share (of the volume, with ``weights``; of the points otherwise) of the
|
|
630
|
+
points judged whose utilization is above ``level``."""
|
|
631
|
+
judged = np.isfinite(self.utilization)
|
|
632
|
+
if not judged.any():
|
|
633
|
+
return float("nan")
|
|
634
|
+
weights = np.ones(self.utilization.shape) if self.weights is None else self.weights
|
|
635
|
+
above = judged & (self.utilization > level)
|
|
636
|
+
return float(weights[above].sum() / weights[judged].sum())
|
|
637
|
+
|
|
638
|
+
def fields(self) -> dict:
|
|
639
|
+
"""The fields of the points, by name (for the writers of fields)."""
|
|
640
|
+
return {
|
|
641
|
+
"fatigue_utilization": self.utilization,
|
|
642
|
+
"fatigue_equivalent": self.equivalent,
|
|
643
|
+
"fatigue_amplitude": self.amplitude,
|
|
644
|
+
"fatigue_hydrostatic_max": self.hydrostatic_max,
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
def components(self) -> dict:
|
|
648
|
+
"""The scalar results: the largest utilization, the safety factor and the share
|
|
649
|
+
of the points beyond their limit."""
|
|
650
|
+
return {"utilization": self.largest, "safety": self.safety, "beyond": self.fraction()}
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
def fatigue(history, criterion, *, phases=None, weights=None, times=None, support=None):
|
|
654
|
+
"""The fatigue of points along a cycle of stresses (``history``: steps x ... x 6):
|
|
655
|
+
a :class:`FatigueResult`. ``criterion``: one criterion for all the points, or a
|
|
656
|
+
mapping of the phases to their criteria (or to mappings of them:
|
|
657
|
+
:func:`criterion_from_config`), with ``phases`` the phase of each point; the points
|
|
658
|
+
of the other phases are not judged."""
|
|
659
|
+
stress = np.asarray(history, dtype=float)
|
|
660
|
+
if stress.ndim >= 2 and stress.shape[-1] == 6 and np.isnan(stress).any():
|
|
661
|
+
return _fatigue_of_the_solid(stress, criterion, phases, weights, times, support)
|
|
662
|
+
stress = _history(stress)
|
|
663
|
+
shape = stress.shape[1:-1]
|
|
664
|
+
amplitude, _ = stress_amplitude(stress)
|
|
665
|
+
hydro = hydrostatic(stress)
|
|
666
|
+
equivalent = np.full(shape, np.nan)
|
|
667
|
+
utilization = np.full(shape, np.nan)
|
|
668
|
+
if isinstance(criterion, dict) and "criterion" not in criterion:
|
|
669
|
+
if phases is None:
|
|
670
|
+
raise ValueError("fatigue: criteria by phase need the phase of each point (phases)")
|
|
671
|
+
labels = np.asarray(phases)
|
|
672
|
+
if labels.shape != shape:
|
|
673
|
+
raise ValueError(f"fatigue: one phase per point {shape}, got {labels.shape}")
|
|
674
|
+
groups = [(labels == phase, law) for phase, law in criterion.items()]
|
|
675
|
+
else:
|
|
676
|
+
groups = [(np.ones(shape, dtype=bool), criterion)]
|
|
677
|
+
for mask, law in groups:
|
|
678
|
+
law = criterion_from_config(law) if isinstance(law, dict) else law
|
|
679
|
+
if not hasattr(law, "equivalent") or not hasattr(law, "limit"):
|
|
680
|
+
raise TypeError("fatigue: a criterion (Crossland, Sines, DangVan, Findley, Matake)")
|
|
681
|
+
if not mask.any():
|
|
682
|
+
continue
|
|
683
|
+
equivalent[mask] = law.equivalent(stress[:, mask])
|
|
684
|
+
utilization[mask] = equivalent[mask] / law.limit
|
|
685
|
+
if weights is not None:
|
|
686
|
+
weights = np.asarray(weights, dtype=float)
|
|
687
|
+
if weights.shape != shape:
|
|
688
|
+
raise ValueError(f"fatigue: one weight per point {shape}, got {weights.shape}")
|
|
689
|
+
count = stress.shape[0]
|
|
690
|
+
return FatigueResult(
|
|
691
|
+
equivalent=equivalent,
|
|
692
|
+
utilization=utilization,
|
|
693
|
+
amplitude=amplitude,
|
|
694
|
+
hydrostatic_max=hydro.max(axis=0),
|
|
695
|
+
hydrostatic_mean=0.5 * (hydro.max(axis=0) + hydro.min(axis=0)),
|
|
696
|
+
times=np.arange(count, dtype=float) if times is None else np.asarray(times, dtype=float),
|
|
697
|
+
weights=weights,
|
|
698
|
+
support=support,
|
|
699
|
+
)
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def _fatigue_of_the_solid(stress, criterion, phases, weights, times, support) -> FatigueResult:
|
|
703
|
+
""":func:`fatigue` for points some of which have no stress (NaN: the voxels of the
|
|
704
|
+
pores of an image): the others are judged, and these are left out of every field."""
|
|
705
|
+
shape = stress.shape[1:-1]
|
|
706
|
+
solid = ~np.isnan(stress).any(axis=(0, -1))
|
|
707
|
+
if not solid.any():
|
|
708
|
+
raise ValueError("fatigue: stresses that are not finite")
|
|
709
|
+
labels = None if phases is None else np.asarray(phases)
|
|
710
|
+
if labels is not None and labels.shape != shape:
|
|
711
|
+
raise ValueError(f"fatigue: one phase per point {shape}, got {labels.shape}")
|
|
712
|
+
if weights is not None and np.shape(weights) != shape:
|
|
713
|
+
raise ValueError(f"fatigue: one weight per point {shape}, got {np.shape(weights)}")
|
|
714
|
+
part = fatigue(
|
|
715
|
+
stress[:, solid],
|
|
716
|
+
criterion,
|
|
717
|
+
phases=None if labels is None else labels[solid],
|
|
718
|
+
times=times,
|
|
719
|
+
)
|
|
720
|
+
|
|
721
|
+
def whole(values):
|
|
722
|
+
out = np.full(shape, np.nan)
|
|
723
|
+
out[solid] = values
|
|
724
|
+
return out
|
|
725
|
+
|
|
726
|
+
return FatigueResult(
|
|
727
|
+
equivalent=whole(part.equivalent),
|
|
728
|
+
utilization=whole(part.utilization),
|
|
729
|
+
amplitude=whole(part.amplitude),
|
|
730
|
+
hydrostatic_max=whole(part.hydrostatic_max),
|
|
731
|
+
hydrostatic_mean=whole(part.hydrostatic_mean),
|
|
732
|
+
times=part.times,
|
|
733
|
+
weights=None if weights is None else np.asarray(weights, dtype=float),
|
|
734
|
+
support=support,
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def path_fatigue(result, criterion, *, cycle=None) -> FatigueResult:
|
|
739
|
+
"""The fatigue of the points of a cell along a cycle of a loading path: ``result``, a
|
|
740
|
+
:class:`~morphogen.homogenization.paths.PathResult` that kept its fields at the
|
|
741
|
+
steps of the cycle (``fields="steps"``); ``criterion``: as for :func:`fatigue`, the
|
|
742
|
+
phases being those of the support of the fields; ``cycle``: the times of its start
|
|
743
|
+
and of its end (by default the whole path). The stresses are those of the fields
|
|
744
|
+
(Cauchy's in finite strains)."""
|
|
745
|
+
times = np.array(sorted(result.fields))
|
|
746
|
+
if cycle is not None:
|
|
747
|
+
start, end = (float(v) for v in cycle)
|
|
748
|
+
if not start < end:
|
|
749
|
+
raise ValueError("fatigue: a cycle from a time to a later one")
|
|
750
|
+
slack = 1e-9 * max(abs(start), abs(end), 1.0)
|
|
751
|
+
times = times[(times >= start - slack) & (times <= end + slack)]
|
|
752
|
+
times = np.array([t for t in times if "stress" in result.fields[t]])
|
|
753
|
+
if times.size < 2:
|
|
754
|
+
raise ValueError(
|
|
755
|
+
"fatigue: the stress fields of two steps of the cycle at least (run the path "
|
|
756
|
+
"with fields='steps')"
|
|
757
|
+
)
|
|
758
|
+
history = np.stack([np.asarray(result.fields[t]["stress"], dtype=float) for t in times])
|
|
759
|
+
support = result.support
|
|
760
|
+
phases = weights = None
|
|
761
|
+
if support is not None and hasattr(support, "volumes"): # a mesh
|
|
762
|
+
phases, weights = np.asarray(support.phase), np.abs(support.volumes())
|
|
763
|
+
elif support is not None and hasattr(support, "data"): # an image
|
|
764
|
+
phases = np.asarray(support.data)
|
|
765
|
+
if phases is not None and phases.shape != history.shape[1:-1]:
|
|
766
|
+
phases = weights = None
|
|
767
|
+
return fatigue(history, criterion, phases=phases, weights=weights, times=times,
|
|
768
|
+
support=support) # fmt: skip
|