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,375 @@
|
|
|
1
|
+
"""Architectures treated pixel by pixel: a morphology on the laser grid of a sheet.
|
|
2
|
+
|
|
3
|
+
A laser treats a sheet through its thickness by squares about the size of its spot,
|
|
4
|
+
the *pixel* (1 mm by default: the smallest feature a spot of 1 mm treats), over sheets
|
|
5
|
+
much larger than any specimen (tens of centimetres: hundreds of pixels a side). A
|
|
6
|
+
*design* is an integer array ``(ny, nx)`` of phases on that grid, row ``i`` at ``y =
|
|
7
|
+
(i + ½) pixel`` and column ``j`` at ``x = (j + ½) pixel``; phase 0 is the untreated sheet
|
|
8
|
+
(:class:`~morphogen.laser.cells.Phase`, the phases of :func:`~morphogen.laser.cells.wang_phases`
|
|
9
|
+
or :func:`~morphogen.laser.cells.contrast_phases`). Any morphology of morphoGen (a
|
|
10
|
+
Boolean model, a tessellation, a random field, a lattice...) becomes a design by
|
|
11
|
+
:func:`pixelate`, the majority phase of each pixel.
|
|
12
|
+
|
|
13
|
+
**Treatment** (:func:`treatment_measures`). Each pixel can be treated, but heat diffuses: an
|
|
14
|
+
untreated pixel next to a treated one sits in its heat-affected zone (tempered,
|
|
15
|
+
partly transformed), and an untreated pixel enclosed by treated ones may not stay
|
|
16
|
+
untreated at all. The measures: the treated share; the treated length drawn by raster
|
|
17
|
+
lines one spot wide, its time at the speed of the beam, the switches of the beam along
|
|
18
|
+
the lines; the connectivity of each phase (whether it spans the design along x and y);
|
|
19
|
+
the untreated pixels next to the treatment and those enclosed by it.
|
|
20
|
+
|
|
21
|
+
**The sheet** (:func:`sheet_tests`). A design repeated over the sheet is periodic: the
|
|
22
|
+
cell of ``nx x ny`` pixels (:class:`~morphogen.laser.periodic.PeriodicCell`, elements
|
|
23
|
+
of half a pixel by default, so that the pixels fall on the elements), each Gauss point
|
|
24
|
+
with the phase of its pixel (:func:`design_membrane`), pulled in several directions
|
|
25
|
+
(:func:`~morphogen.laser.periodic.cell_test`): the yield and tensile strengths, the
|
|
26
|
+
failure strain (the first of the maximum of the nominal stress and of the fracture of
|
|
27
|
+
a brittle phase, :func:`~morphogen.laser.cells.failure_measures`), the energy absorbed
|
|
28
|
+
up to it and Lankford's coefficient of the sheet in each direction, and their spreads
|
|
29
|
+
over the directions.
|
|
30
|
+
|
|
31
|
+
**Tracks** (:func:`track_membrane`). Smooth tracks of constant width along polylines
|
|
32
|
+
(corrugations, oblique families), and their periodic images over a cell
|
|
33
|
+
(:func:`periodic_lines`): each Gauss point mixes the flow stresses and Young's moduli of
|
|
34
|
+
the untreated and treated phases by the share of its region inside the tracks
|
|
35
|
+
(:func:`~morphogen.laser.cells.band_fractions`). Phases may differ in stiffness as well
|
|
36
|
+
as in strength (``young``: one modulus per phase), which separates the two contrasts.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from __future__ import annotations
|
|
40
|
+
|
|
41
|
+
import math
|
|
42
|
+
|
|
43
|
+
import numpy as np
|
|
44
|
+
from scipy import ndimage
|
|
45
|
+
|
|
46
|
+
from morphogen.laser.cells import (
|
|
47
|
+
FRACTURE_RADIUS,
|
|
48
|
+
Phase,
|
|
49
|
+
band_fractions,
|
|
50
|
+
failure_measures,
|
|
51
|
+
wang_phases,
|
|
52
|
+
)
|
|
53
|
+
from morphogen.laser.mechanics import Membrane
|
|
54
|
+
from morphogen.laser.periodic import PeriodicCell, cell_test
|
|
55
|
+
|
|
56
|
+
__all__ = [
|
|
57
|
+
"design_membrane",
|
|
58
|
+
"periodic_lines",
|
|
59
|
+
"pixelate",
|
|
60
|
+
"sheet_tests",
|
|
61
|
+
"spot_opening",
|
|
62
|
+
"track_membrane",
|
|
63
|
+
"treatment_measures",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _moduli(young, count: int) -> np.ndarray:
|
|
68
|
+
"""Young's modulus of each of ``count`` phases: one value for all, or one each."""
|
|
69
|
+
e = np.atleast_1d(np.asarray(young, dtype=float))
|
|
70
|
+
if e.size == 1:
|
|
71
|
+
e = np.full(count, float(e[0]))
|
|
72
|
+
if e.shape != (count,) or not np.all(e > 0):
|
|
73
|
+
raise ValueError(f"young: one positive modulus, or one for each of the {count} phases")
|
|
74
|
+
return e
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def pixelate(image, shape) -> np.ndarray:
|
|
78
|
+
"""The phases (integer labels) of an ``image`` on a grid of ``shape = (ny, nx)``
|
|
79
|
+
pixels covering the same extent: the most frequent label of the image points whose
|
|
80
|
+
centres fall in each pixel (the lowest label on a tie). An image coarser than the
|
|
81
|
+
grid is sampled at the pixel centres."""
|
|
82
|
+
img = np.asarray(image)
|
|
83
|
+
if img.ndim != 2:
|
|
84
|
+
raise ValueError("pixelate: a 2D image")
|
|
85
|
+
if not np.issubdtype(img.dtype, np.integer):
|
|
86
|
+
if not np.all(img == np.round(img)):
|
|
87
|
+
raise ValueError("pixelate: integer labels")
|
|
88
|
+
img = img.astype(np.int64)
|
|
89
|
+
ny, nx = (int(v) for v in shape)
|
|
90
|
+
if ny < 1 or nx < 1:
|
|
91
|
+
raise ValueError("pixelate: a positive shape")
|
|
92
|
+
if img.min() < 0:
|
|
93
|
+
raise ValueError("pixelate: labels from 0")
|
|
94
|
+
iy = np.minimum((np.arange(img.shape[0]) + 0.5) * ny // img.shape[0], ny - 1).astype(int)
|
|
95
|
+
ix = np.minimum((np.arange(img.shape[1]) + 0.5) * nx // img.shape[1], nx - 1).astype(int)
|
|
96
|
+
if img.shape[0] < ny or img.shape[1] < nx: # coarser: sample at the pixel centres
|
|
97
|
+
sy = np.minimum(((np.arange(ny) + 0.5) * img.shape[0] / ny).astype(int), img.shape[0] - 1)
|
|
98
|
+
sx = np.minimum(((np.arange(nx) + 0.5) * img.shape[1] / nx).astype(int), img.shape[1] - 1)
|
|
99
|
+
return img[np.ix_(sy, sx)].astype(np.int64)
|
|
100
|
+
labels = int(img.max()) + 1
|
|
101
|
+
pix = (iy[:, None] * nx + ix[None, :]).ravel()
|
|
102
|
+
counts = np.bincount(pix * labels + img.ravel(), minlength=ny * nx * labels)
|
|
103
|
+
return counts.reshape(ny, nx, labels).argmax(axis=2).astype(np.int64)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def spot_opening(design, width: int = 2, *, periodic: bool = True) -> np.ndarray:
|
|
107
|
+
"""The part of a design (treated: phase > 0) that a square spot of ``width`` cells
|
|
108
|
+
draws, its morphological opening (``periodic``: through the edges of the cell;
|
|
109
|
+
otherwise the spot may overhang them), the treated cells keeping their phase."""
|
|
110
|
+
d = np.asarray(design)
|
|
111
|
+
treated = d > 0
|
|
112
|
+
if width <= 1 or not treated.any():
|
|
113
|
+
return d.copy()
|
|
114
|
+
st = np.ones((width, width), dtype=bool)
|
|
115
|
+
pad = np.pad(treated, width, mode="wrap" if periodic else "edge")
|
|
116
|
+
kept = ndimage.binary_opening(pad, structure=st)[width:-width, width:-width]
|
|
117
|
+
return np.where(kept, d, 0)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _spans(mask, axis: int, periodic: bool) -> bool:
|
|
121
|
+
"""Whether a cluster of ``mask`` (4-connected) joins the two edges normal to
|
|
122
|
+
``axis`` (``periodic``: through the cell to its own image)."""
|
|
123
|
+
if not mask.any():
|
|
124
|
+
return False
|
|
125
|
+
if periodic: # 3 x 3 cells: a cluster that holds a pixel and its image one period on
|
|
126
|
+
lab, _ = ndimage.label(np.tile(mask, (3, 3)))
|
|
127
|
+
ny, nx = mask.shape
|
|
128
|
+
centre = lab[ny : 2 * ny, nx : 2 * nx]
|
|
129
|
+
image = lab[2 * ny :, nx : 2 * nx] if axis == 0 else lab[ny : 2 * ny, 2 * nx :]
|
|
130
|
+
return bool(np.any((centre > 0) & (centre == image)))
|
|
131
|
+
lab, _ = ndimage.label(mask)
|
|
132
|
+
lo = set(np.unique(lab.take(0, axis=axis))) - {0}
|
|
133
|
+
hi = set(np.unique(lab.take(-1, axis=axis))) - {0}
|
|
134
|
+
return bool(lo & hi)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def treatment_measures(
|
|
138
|
+
design, *, pixel: float = 1.0, spot: float = 1.0, speed: float = 10.0, periodic: bool = True
|
|
139
|
+
) -> dict:
|
|
140
|
+
"""The laser treatment of a design (see the module): ``treated`` share; ``length`` (m) of
|
|
141
|
+
the raster lines one ``spot`` wide that treat it, ``time`` (min) at ``speed`` (mm/s),
|
|
142
|
+
``switches`` of the beam along the rows (per m² of sheet); whether the treated and
|
|
143
|
+
the untreated phases span the design along x and along y (``hard_spans``,
|
|
144
|
+
``soft_spans``: pairs of booleans); the shares of the untreated pixels with a
|
|
145
|
+
treated neighbour (``heat_affected``) and with treated pixels on all four sides
|
|
146
|
+
(``enclosed``), among the untreated ones."""
|
|
147
|
+
d = np.asarray(design)
|
|
148
|
+
treated = d > 0
|
|
149
|
+
t = treated.astype(np.int8)
|
|
150
|
+
area = d.size * pixel**2 # mm²
|
|
151
|
+
length = treated.sum() * pixel**2 / spot # mm
|
|
152
|
+
if periodic:
|
|
153
|
+
switches = int(np.count_nonzero(t != np.roll(t, 1, axis=1)))
|
|
154
|
+
neighbours = sum(np.roll(t, s, axis=a) for a in (0, 1) for s in (1, -1))
|
|
155
|
+
else:
|
|
156
|
+
switches = int(np.count_nonzero(np.diff(np.pad(t, ((0, 0), (1, 1))), axis=1)))
|
|
157
|
+
p = np.pad(t, 1)
|
|
158
|
+
neighbours = p[:-2, 1:-1] + p[2:, 1:-1] + p[1:-1, :-2] + p[1:-1, 2:]
|
|
159
|
+
soft = ~treated
|
|
160
|
+
near = soft & (neighbours > 0)
|
|
161
|
+
enclosed = soft & (neighbours == 4)
|
|
162
|
+
nsoft = max(int(soft.sum()), 1)
|
|
163
|
+
return {
|
|
164
|
+
"treated": float(treated.mean()),
|
|
165
|
+
"length": float(length / 1000.0),
|
|
166
|
+
"time": float(length / speed / 60.0),
|
|
167
|
+
"switches": float(switches / (area * 1e-6)),
|
|
168
|
+
"hard_spans": (_spans(treated, 1, periodic), _spans(treated, 0, periodic)),
|
|
169
|
+
"soft_spans": (_spans(soft, 1, periodic), _spans(soft, 0, periodic)),
|
|
170
|
+
"heat_affected": float(near.sum() / nsoft),
|
|
171
|
+
"enclosed": float(enclosed.sum() / nsoft),
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def design_membrane(
|
|
176
|
+
mesh,
|
|
177
|
+
design,
|
|
178
|
+
*,
|
|
179
|
+
pixel: float = 1.0,
|
|
180
|
+
phases=None,
|
|
181
|
+
origin=(0.0, 0.0),
|
|
182
|
+
young=210000.0,
|
|
183
|
+
poisson: float = 0.3,
|
|
184
|
+
thickness: float = 1.0,
|
|
185
|
+
fracture_radius: float | None = FRACTURE_RADIUS,
|
|
186
|
+
) -> Membrane:
|
|
187
|
+
"""The membrane of a mesh whose Gauss points take the phase of their pixel of the
|
|
188
|
+
design (from ``origin``, repeated beyond it), with the flow law, the critical
|
|
189
|
+
strain and Young's modulus of the phase (``phases``:
|
|
190
|
+
:func:`~morphogen.laser.cells.wang_phases` by default; ``young``: one modulus, or
|
|
191
|
+
one per phase)."""
|
|
192
|
+
phases = tuple(Phase.from_config(p) for p in (phases or wang_phases()))
|
|
193
|
+
d = np.asarray(design, dtype=np.int64)
|
|
194
|
+
if d.min() < 0 or d.max() >= len(phases):
|
|
195
|
+
raise ValueError("design: phases from 0 to len(phases) - 1")
|
|
196
|
+
pts = mesh.gauss()[0]
|
|
197
|
+
ny, nx = d.shape
|
|
198
|
+
j = np.floor((pts[..., 0] - origin[0]) / pixel).astype(np.int64) % nx
|
|
199
|
+
i = np.floor((pts[..., 1] - origin[1]) / pixel).astype(np.int64) % ny
|
|
200
|
+
ph = d[i, j]
|
|
201
|
+
laws = np.array([[p.law.code, p.law.sigma0, p.law.a, p.law.b] for p in phases], dtype=float)
|
|
202
|
+
crit = np.array([p.critical for p in phases], dtype=float)
|
|
203
|
+
flow = [np.ascontiguousarray(laws[ph][..., k][..., None]) for k in range(4)]
|
|
204
|
+
critical = np.ascontiguousarray(crit[ph][..., None])
|
|
205
|
+
brittle = bool(np.isfinite(critical).any())
|
|
206
|
+
return Membrane(
|
|
207
|
+
mesh,
|
|
208
|
+
flow,
|
|
209
|
+
young=_moduli(young, len(phases))[ph][..., None],
|
|
210
|
+
poisson=poisson,
|
|
211
|
+
thickness=thickness,
|
|
212
|
+
critical=critical if brittle else None,
|
|
213
|
+
fracture_radius=fracture_radius if brittle else None,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def sheet_tests(
|
|
218
|
+
design,
|
|
219
|
+
*,
|
|
220
|
+
pixel: float = 1.0,
|
|
221
|
+
phases=None,
|
|
222
|
+
angles=(0.0, 45.0, 90.0),
|
|
223
|
+
element: float | None = None,
|
|
224
|
+
max_strain: float = 0.3,
|
|
225
|
+
fracture_radius: float | None = FRACTURE_RADIUS,
|
|
226
|
+
young: float = 210000.0,
|
|
227
|
+
thickness: float = 1.0,
|
|
228
|
+
) -> dict:
|
|
229
|
+
"""The sheet of a periodic design pulled in each direction of ``angles`` (degrees
|
|
230
|
+
from x; see the module): ``{"directions": {angle: measures}, ...}`` with, for each
|
|
231
|
+
direction, the yield and tensile strengths (MPa), the failure strain, the energy up
|
|
232
|
+
to it (MJ/m³), Lankford's coefficient, whether a brittle phase broke first, and the
|
|
233
|
+
result of the test; and over the directions the means and spreads (max − min over
|
|
234
|
+
the mean) of the yield strength, the failure strain and the energy."""
|
|
235
|
+
d = np.asarray(design, dtype=np.int64)
|
|
236
|
+
ny, nx = d.shape
|
|
237
|
+
size = (nx * pixel, ny * pixel)
|
|
238
|
+
cell = PeriodicCell.build(
|
|
239
|
+
(size[0], 0.0),
|
|
240
|
+
(0.0, size[1]),
|
|
241
|
+
element=element or 0.5 * pixel,
|
|
242
|
+
centre=(0.5 * size[0], 0.5 * size[1]),
|
|
243
|
+
)
|
|
244
|
+
out = {}
|
|
245
|
+
for angle in angles:
|
|
246
|
+
mem = design_membrane(
|
|
247
|
+
cell.mesh,
|
|
248
|
+
d,
|
|
249
|
+
pixel=pixel,
|
|
250
|
+
phases=phases,
|
|
251
|
+
origin=cell.origin,
|
|
252
|
+
young=young,
|
|
253
|
+
thickness=thickness,
|
|
254
|
+
fracture_radius=fracture_radius,
|
|
255
|
+
)
|
|
256
|
+
res = cell_test(mem, cell, float(angle), max_strain=max_strain, failure_margin=0.03)
|
|
257
|
+
fail = res.failure_strain if math.isfinite(res.failure_strain) else math.inf
|
|
258
|
+
m = failure_measures(res.strain, res.stress, fail, young=young)
|
|
259
|
+
m["r_value"] = res.r_value()
|
|
260
|
+
m["broke"] = bool(fail < m["uniform_elongation"] - 1e-9)
|
|
261
|
+
m["result"] = res
|
|
262
|
+
out[float(angle)] = m
|
|
263
|
+
|
|
264
|
+
def spread(key):
|
|
265
|
+
v = np.array([out[a][key] for a in out], dtype=float)
|
|
266
|
+
return float(v.mean()), float((v.max() - v.min()) / v.mean()) if v.mean() else math.nan
|
|
267
|
+
|
|
268
|
+
summary = {"directions": out}
|
|
269
|
+
for key in ("yield_strength", "tensile_strength", "failure_strain", "energy", "r_value"):
|
|
270
|
+
summary[f"{key}_mean"], summary[f"{key}_spread"] = spread(key)
|
|
271
|
+
return summary
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def periodic_lines(lines, a1, a2, box, reach: float = 0.0) -> list:
|
|
275
|
+
"""The polylines ``lines`` (mm) and their images by the lattice of ``a1`` and
|
|
276
|
+
``a2`` that come within ``reach`` of the box ``(x0, x1, y0, y1)``: the tracks of a
|
|
277
|
+
pattern repeated over the sheet, as they cross a periodic cell."""
|
|
278
|
+
a1, a2 = np.asarray(a1, dtype=float), np.asarray(a2, dtype=float)
|
|
279
|
+
area = abs(a1[0] * a2[1] - a1[1] * a2[0])
|
|
280
|
+
if area <= 0:
|
|
281
|
+
raise ValueError("periodic lines: a1 and a2 parallel")
|
|
282
|
+
h = area / max(np.linalg.norm(a1), np.linalg.norm(a2)) # the smaller height of the cell
|
|
283
|
+
x0, x1, y0, y1 = box
|
|
284
|
+
out = []
|
|
285
|
+
for line in lines:
|
|
286
|
+
pts = np.asarray(line, dtype=float)
|
|
287
|
+
lo, hi = pts.min(axis=0), pts.max(axis=0)
|
|
288
|
+
centre = 0.5 * np.array([x0 + x1, y0 + y1])
|
|
289
|
+
# enough images to reach the box from wherever the line lies
|
|
290
|
+
span = (
|
|
291
|
+
max(x1 - x0, y1 - y0)
|
|
292
|
+
+ float(np.max(hi - lo))
|
|
293
|
+
+ float(np.linalg.norm(0.5 * (lo + hi) - centre))
|
|
294
|
+
+ 2.0 * reach
|
|
295
|
+
)
|
|
296
|
+
n = math.ceil(span / h) + 1
|
|
297
|
+
for i in range(-n, n + 1):
|
|
298
|
+
for j in range(-n, n + 1):
|
|
299
|
+
q = pts + i * a1 + j * a2
|
|
300
|
+
qlo, qhi = q.min(axis=0), q.max(axis=0)
|
|
301
|
+
if (
|
|
302
|
+
qhi[0] >= x0 - reach
|
|
303
|
+
and qlo[0] <= x1 + reach
|
|
304
|
+
and qhi[1] >= y0 - reach
|
|
305
|
+
and qlo[1] <= y1 + reach
|
|
306
|
+
):
|
|
307
|
+
out.append(q)
|
|
308
|
+
return out
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def track_membrane(
|
|
312
|
+
mesh,
|
|
313
|
+
lines,
|
|
314
|
+
width,
|
|
315
|
+
*,
|
|
316
|
+
phases=None,
|
|
317
|
+
kinds=None,
|
|
318
|
+
young=210000.0,
|
|
319
|
+
poisson: float = 0.3,
|
|
320
|
+
thickness: float = 1.0,
|
|
321
|
+
fracture_radius: float | None = FRACTURE_RADIUS,
|
|
322
|
+
subdivisions: int = 4,
|
|
323
|
+
) -> Membrane:
|
|
324
|
+
"""The membrane of a mesh crossed by tracks along the polylines ``lines`` (their
|
|
325
|
+
centre lines; see the module), ``width`` mm wide (one width, or one per line): the
|
|
326
|
+
share ``w_k`` of the region of each Gauss point inside the tracks of each treated
|
|
327
|
+
phase ``k`` (``kinds``: the phase of each line, 1 by default; ``phases``: the
|
|
328
|
+
untreated first, :func:`~morphogen.laser.cells.wang_phases` by default) mixes the
|
|
329
|
+
flow stress of the untreated phase with that of the treated phase of the largest
|
|
330
|
+
share as ``(1 − w) σ_0 + w σ_k`` (``w`` the sum of the shares), and Young's moduli
|
|
331
|
+
(``young``: one modulus, or one per phase) by the shares; a point mostly inside a
|
|
332
|
+
track takes the critical strain of that phase. Several kinds: a track whose
|
|
333
|
+
treatment changes along it, tracks of several treatments."""
|
|
334
|
+
phases = tuple(Phase.from_config(p) for p in (phases or wang_phases()))
|
|
335
|
+
n = len(phases)
|
|
336
|
+
if n < 2:
|
|
337
|
+
raise ValueError("track membrane: at least two phases, the untreated first")
|
|
338
|
+
lines = [np.asarray(line, dtype=float) for line in lines]
|
|
339
|
+
kinds = [1] * len(lines) if kinds is None else [int(k) for k in kinds]
|
|
340
|
+
widths = np.broadcast_to(np.asarray(width, dtype=float), (len(lines),))
|
|
341
|
+
if len(kinds) != len(lines) or any(not 1 <= k < n for k in kinds):
|
|
342
|
+
raise ValueError(f"kinds: one phase from 1 to {n - 1} for each line")
|
|
343
|
+
if np.any(widths <= 0):
|
|
344
|
+
raise ValueError("track membrane: positive widths")
|
|
345
|
+
ne = len(mesh.quads)
|
|
346
|
+
shares = np.zeros((ne, 4, n))
|
|
347
|
+
for k, w in {(k, float(w)) for k, w in zip(kinds, widths, strict=True)}:
|
|
348
|
+
sel = [ln for ln, kk, ww in zip(lines, kinds, widths, strict=True) if kk == k and ww == w]
|
|
349
|
+
part = band_fractions(mesh, sel, w, n=subdivisions)
|
|
350
|
+
shares[..., k] = np.maximum(shares[..., k], part)
|
|
351
|
+
total = shares[..., 1:].sum(axis=-1)
|
|
352
|
+
over = total > 1.0 # crossing tracks: their shares scaled to the region
|
|
353
|
+
shares[over, 1:] /= total[over, None]
|
|
354
|
+
total = np.minimum(total, 1.0)
|
|
355
|
+
shares[..., 0] = 1.0 - total
|
|
356
|
+
top = 1 + np.argmax(shares[..., 1:], axis=-1)
|
|
357
|
+
laws = np.array([[p.law.code, p.law.sigma0, p.law.a, p.law.b] for p in phases], dtype=float)
|
|
358
|
+
shape = (ne, 4, 1)
|
|
359
|
+
flow = [np.full(shape, v) for v in laws[0]]
|
|
360
|
+
flow += [np.ascontiguousarray(laws[top][..., k][..., None]) for k in range(4)]
|
|
361
|
+
flow.append(np.ascontiguousarray(total[..., None]))
|
|
362
|
+
e = _moduli(young, n)
|
|
363
|
+
moduli = np.ascontiguousarray((shares @ e)[..., None])
|
|
364
|
+
crit = np.array([p.critical for p in phases], dtype=float)
|
|
365
|
+
critical = np.where(total > 0.5, crit[top], crit[0])[..., None]
|
|
366
|
+
brittle = bool(np.isfinite(critical).any())
|
|
367
|
+
return Membrane(
|
|
368
|
+
mesh,
|
|
369
|
+
flow,
|
|
370
|
+
young=moduli,
|
|
371
|
+
poisson=poisson,
|
|
372
|
+
thickness=thickness,
|
|
373
|
+
critical=np.ascontiguousarray(critical) if brittle else None,
|
|
374
|
+
fracture_radius=fracture_radius if brittle else None,
|
|
375
|
+
)
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""Three-point bending of a laser-architectured strip: fibre sections of a beam.
|
|
2
|
+
|
|
3
|
+
A strip of width ``W`` and thickness ``h`` rests on two supports ``span`` apart and is
|
|
4
|
+
loaded at mid-span by ``F``: the bending moment is ``M(x) = F/2 (S/2 − |x − x_c|)``
|
|
5
|
+
(statically determinate, small deflections, no membrane force). Each cross-section is a
|
|
6
|
+
grid of fibres across the width and through the thickness (the layers of the
|
|
7
|
+
treatment), each with the flow law of its hardness, loaded monotonically in uniaxial
|
|
8
|
+
stress: ``|σ| = E|ε|`` up to yield, then ``σ = σ_y(p)`` with ``|ε| = p + σ/E``. Plane
|
|
9
|
+
sections: ``ε = −κ (z − z_n)``, the neutral axis ``z_n`` from ``Σ σ dA = 0`` (it moves
|
|
10
|
+
off the mid-plane of a strip treated on one face), ``M = −Σ σ (z − z_n) dA``. The
|
|
11
|
+
curvature of each section follows from the moment by inverting ``M(κ)``, the deflection
|
|
12
|
+
under the load from the principle of virtual work, ``δ = ∫ κ(x) m(x) dx``,
|
|
13
|
+
``m = (S/2 − |x − x_c|)/2`` (exact for the statically determinate beam). The limit load
|
|
14
|
+
``4 M_max / S`` is reached when the weakest section near the load cannot carry more.
|
|
15
|
+
Checked: the elastic stiffness ``48 E I / S³`` and the limit load ``σ0 W h² / S`` of a
|
|
16
|
+
perfectly plastic strip.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import math
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class BendingResult:
|
|
29
|
+
"""The load (N) against the deflection (mm) under it, the largest load of the tables
|
|
30
|
+
(the limit load of a perfectly plastic strip; of a hardening one, the load at an
|
|
31
|
+
outer strain of about 100 times the strain of first yield), the initial stiffness
|
|
32
|
+
(N/mm), the load and the energy (mJ) at the reference deflection, and the
|
|
33
|
+
moment-curvature tables of the sections."""
|
|
34
|
+
|
|
35
|
+
deflection: np.ndarray
|
|
36
|
+
load: np.ndarray
|
|
37
|
+
max_load: float
|
|
38
|
+
stiffness: float
|
|
39
|
+
load_at_deflection: float
|
|
40
|
+
energy: float
|
|
41
|
+
reference_deflection: float
|
|
42
|
+
sections: dict = field(default_factory=dict, repr=False)
|
|
43
|
+
|
|
44
|
+
def summary(self) -> dict:
|
|
45
|
+
return {
|
|
46
|
+
"bending_load": self.max_load,
|
|
47
|
+
"bending_stiffness": self.stiffness,
|
|
48
|
+
"bending_load_at_deflection": self.load_at_deflection,
|
|
49
|
+
"bending_energy": self.energy,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _fibre_curves(kind, s0, a, b, young, strains, offset):
|
|
54
|
+
"""Stresses of fibres (n) at the strains (m) of a common grid, monotonic uniaxial
|
|
55
|
+
loading: ``(n, m)``."""
|
|
56
|
+
kind = np.asarray(kind)[:, None]
|
|
57
|
+
s0, a, b = (np.asarray(v, dtype=float)[:, None] for v in (s0, a, b))
|
|
58
|
+
e = np.asarray(strains, dtype=float)[None, :]
|
|
59
|
+
|
|
60
|
+
def flow(p):
|
|
61
|
+
ludwik = s0 + a * ((p + offset) ** b - offset**b)
|
|
62
|
+
voce = s0 + a * (1.0 - np.exp(-b * p))
|
|
63
|
+
with np.errstate(invalid="ignore", divide="ignore"):
|
|
64
|
+
swift = a * ((s0 / a) ** (1.0 / b) + p) ** b
|
|
65
|
+
return np.where(kind == 0, ludwik, np.where(kind == 2, swift, voce))
|
|
66
|
+
|
|
67
|
+
elastic = young * e
|
|
68
|
+
plastic = elastic > s0
|
|
69
|
+
lo = np.zeros(np.broadcast(kind, e).shape)
|
|
70
|
+
hi = np.broadcast_to(e, lo.shape).copy()
|
|
71
|
+
for _ in range(48): # bisection on p: e = p + sigma(p)/E
|
|
72
|
+
mid = 0.5 * (lo + hi)
|
|
73
|
+
up = mid + flow(mid) / young < e
|
|
74
|
+
lo = np.where(up, mid, lo)
|
|
75
|
+
hi = np.where(up, hi, mid)
|
|
76
|
+
p = 0.5 * (lo + hi)
|
|
77
|
+
return np.where(plastic, flow(p), elastic)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def section_tables(
|
|
81
|
+
kind,
|
|
82
|
+
s0,
|
|
83
|
+
a,
|
|
84
|
+
b,
|
|
85
|
+
*,
|
|
86
|
+
width: float,
|
|
87
|
+
thickness: float,
|
|
88
|
+
young: float,
|
|
89
|
+
curvatures,
|
|
90
|
+
offset: float = 1e-4,
|
|
91
|
+
strains: int = 600,
|
|
92
|
+
) -> dict:
|
|
93
|
+
"""Moment-curvature tables of sections: flow laws ``(sections, ny, layers)``
|
|
94
|
+
(fibres across the width and through the thickness, the layer 0 at the upper
|
|
95
|
+
face); returns the curvatures, moments ``(sections, curvatures)`` and neutral axes."""
|
|
96
|
+
kind = np.asarray(kind)
|
|
97
|
+
ns, ny, nl = kind.shape
|
|
98
|
+
h = float(thickness)
|
|
99
|
+
z = (np.arange(nl) + 0.5) * h / nl - 0.5 * h # from the mid-plane, upwards = upper face
|
|
100
|
+
z = -z # layer 0 (upper face) at z = +h/2
|
|
101
|
+
da = width / ny * h / nl
|
|
102
|
+
kap = np.asarray(curvatures, dtype=float)
|
|
103
|
+
emax = float(np.max(kap) * h * 1.05) + 1e-12
|
|
104
|
+
grid = np.linspace(0.0, emax, strains)
|
|
105
|
+
laws = np.column_stack([kind.ravel(), np.ravel(s0), np.ravel(a), np.ravel(b)])
|
|
106
|
+
unique, inverse = np.unique(laws, axis=0, return_inverse=True) # the distinct laws
|
|
107
|
+
curves = _fibre_curves(
|
|
108
|
+
unique[:, 0].astype(np.int64),
|
|
109
|
+
unique[:, 1],
|
|
110
|
+
unique[:, 2],
|
|
111
|
+
unique[:, 3],
|
|
112
|
+
young,
|
|
113
|
+
grid,
|
|
114
|
+
offset,
|
|
115
|
+
)[inverse.ravel()].reshape(ns, ny, nl, strains)
|
|
116
|
+
# a section: its fibres share z; sum the stresses across the width per layer
|
|
117
|
+
layer_curves = curves.sum(axis=1) * da # ns x nl x strains (force per strain)
|
|
118
|
+
de = grid[1] - grid[0]
|
|
119
|
+
|
|
120
|
+
def force(eps): # ns x nl strains -> ns x nl forces (odd in the strain)
|
|
121
|
+
idx = np.clip(np.abs(eps) / de, 0.0, strains - 1.000001)
|
|
122
|
+
i0 = np.floor(idx).astype(np.int64)
|
|
123
|
+
f = idx - i0
|
|
124
|
+
ii = np.arange(ns)[:, None]
|
|
125
|
+
ll = np.arange(nl)[None, :]
|
|
126
|
+
v = (1.0 - f) * layer_curves[ii, ll, i0] + f * layer_curves[ii, ll, i0 + 1]
|
|
127
|
+
return np.sign(eps) * v
|
|
128
|
+
|
|
129
|
+
moments = np.zeros((ns, len(kap)))
|
|
130
|
+
axes = np.zeros((ns, len(kap)))
|
|
131
|
+
for j, k in enumerate(kap):
|
|
132
|
+
if k == 0.0:
|
|
133
|
+
continue
|
|
134
|
+
lo, hi = np.full(ns, -0.5 * h), np.full(ns, 0.5 * h)
|
|
135
|
+
for _ in range(50): # the neutral axis: the axial force vanishes
|
|
136
|
+
zn = 0.5 * (lo + hi)
|
|
137
|
+
n_ax = force(-k * (z[None, :] - zn[:, None])).sum(axis=1)
|
|
138
|
+
tension = n_ax > 0 # the force grows as the axis rises: lower it
|
|
139
|
+
hi = np.where(tension, zn, hi)
|
|
140
|
+
lo = np.where(tension, lo, zn)
|
|
141
|
+
zn = 0.5 * (lo + hi)
|
|
142
|
+
f = force(-k * (z[None, :] - zn[:, None]))
|
|
143
|
+
moments[:, j] = -(f * (z[None, :] - zn[:, None])).sum(axis=1)
|
|
144
|
+
axes[:, j] = zn
|
|
145
|
+
return {"curvatures": kap, "moments": moments, "axes": axes, "z": z}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _deflection(integrand, xs) -> float:
|
|
149
|
+
"""``∫ κ m dx`` by Simpson's rule on each half of the span (the moment has a kink
|
|
150
|
+
under the load, at the middle section)."""
|
|
151
|
+
from scipy.integrate import simpson
|
|
152
|
+
|
|
153
|
+
mid = len(xs) // 2
|
|
154
|
+
if len(xs) % 2 == 0 or mid < 2:
|
|
155
|
+
return float(np.trapezoid(integrand, xs))
|
|
156
|
+
left = simpson(integrand[: mid + 1], x=xs[: mid + 1])
|
|
157
|
+
right = simpson(integrand[mid:], x=xs[mid:])
|
|
158
|
+
return float(left + right)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def three_point_bending(
|
|
162
|
+
kind,
|
|
163
|
+
s0,
|
|
164
|
+
a,
|
|
165
|
+
b,
|
|
166
|
+
*,
|
|
167
|
+
span: float,
|
|
168
|
+
width: float,
|
|
169
|
+
thickness: float,
|
|
170
|
+
young: float = 210000.0,
|
|
171
|
+
deflection: float | None = None,
|
|
172
|
+
loads: int = 120,
|
|
173
|
+
) -> BendingResult:
|
|
174
|
+
"""Three-point bending (see the module) of a strip whose sections, equally spaced
|
|
175
|
+
over the span (``(sections, ny, layers)`` flow laws, the first section at the left
|
|
176
|
+
support, the last at the right one; an odd number puts one under the load), are
|
|
177
|
+
given; ``deflection``: the reference
|
|
178
|
+
deflection of the load and the energy (default: a fiftieth of the span)."""
|
|
179
|
+
kind = np.asarray(kind)
|
|
180
|
+
ns = kind.shape[0]
|
|
181
|
+
s = float(span)
|
|
182
|
+
xs = np.linspace(0.0, s, ns)
|
|
183
|
+
arm = 0.5 * s - np.abs(xs - 0.5 * s) # M = F/2 arm, m = arm/2
|
|
184
|
+
h, w = float(thickness), float(width)
|
|
185
|
+
inertia = w * h**3 / 12.0
|
|
186
|
+
s0_min = float(np.nanmin(s0))
|
|
187
|
+
k_el = 2.0 * s0_min / (young * h)
|
|
188
|
+
kap = np.concatenate(
|
|
189
|
+
[np.linspace(0.0, k_el, 20, endpoint=False), np.geomspace(k_el, 100.0 * k_el, 160)]
|
|
190
|
+
)
|
|
191
|
+
tab = section_tables(
|
|
192
|
+
kind, s0, a, b, width=w, thickness=h, young=young, curvatures=kap, strains=2000
|
|
193
|
+
)
|
|
194
|
+
mom = np.maximum.accumulate(tab["moments"], axis=1) # monotone tables
|
|
195
|
+
m_max = mom[:, -1]
|
|
196
|
+
with np.errstate(divide="ignore"):
|
|
197
|
+
f_lim = np.where(arm > 0, 2.0 * m_max / np.maximum(arm, 1e-300), np.inf)
|
|
198
|
+
f_max = float(f_lim.min())
|
|
199
|
+
forces = f_max * (1.0 - np.geomspace(1.0, 1e-3, loads)) # dense near the limit
|
|
200
|
+
forces = np.concatenate([[0.0], forces[forces > 0]])
|
|
201
|
+
defl = np.zeros(len(forces))
|
|
202
|
+
for i, f in enumerate(forces):
|
|
203
|
+
mx = 0.5 * f * arm
|
|
204
|
+
kx = np.array([np.interp(mx[j], mom[j], kap) for j in range(ns)])
|
|
205
|
+
defl[i] = _deflection(kx * 0.5 * arm, xs)
|
|
206
|
+
ref = float(deflection) if deflection is not None else s / 50.0
|
|
207
|
+
stiff = 48.0 * young * inertia / s**3
|
|
208
|
+
if len(forces) > 2 and defl[1] > 0:
|
|
209
|
+
stiff = float(forces[1] / defl[1])
|
|
210
|
+
reached = defl[-1] >= ref
|
|
211
|
+
f_ref = float(np.interp(ref, defl, forces)) if reached else math.nan
|
|
212
|
+
upto = defl <= ref
|
|
213
|
+
dd = np.append(defl[upto], ref) if reached else defl
|
|
214
|
+
ff = np.append(forces[upto], f_ref) if reached else forces
|
|
215
|
+
energy = float(np.trapezoid(ff, dd)) # N mm = mJ
|
|
216
|
+
return BendingResult(defl, forces, f_max, stiff, f_ref, energy, ref, sections={"x": xs, **tab})
|