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,880 @@
|
|
|
1
|
+
"""The effective stiffness of random periodic frameworks (fibre networks, open foams,
|
|
2
|
+
lattices with defects) as periodic frames of Euler–Bernoulli beams (or of Timoshenko beams,
|
|
3
|
+
the option of :mod:`morphogen.homogenization.frames`), and the softening of networks of
|
|
4
|
+
non-identical beams (Ban, Barocas, Shephard & Picu 2016).
|
|
5
|
+
|
|
6
|
+
A framework (:class:`morphogen.design.frames.Framework`: nodes in a periodic box, bars from
|
|
7
|
+
a node to an image of another; ``delaunay_network``, ``open_foam`` and ``random_lattice``
|
|
8
|
+
keep theirs in their metadata, of which :func:`network_frame` makes the frame of a
|
|
9
|
+
realization) becomes a frame of beams of circular sections,
|
|
10
|
+
:meth:`SpaceFrame.from_framework <morphogen.homogenization.frames.SpaceFrame.from_framework>`
|
|
11
|
+
(:meth:`Frame.from_framework <morphogen.homogenization.frames.Frame.from_framework>` in the
|
|
12
|
+
plane). The displacement of a node is ``E X + w`` and its rotation ``θ``, ``w`` and ``θ``
|
|
13
|
+
periodic, so that a beam from node ``i`` to the image of node ``j`` (vector ``d``) moves
|
|
14
|
+
its second end by ``E d + w_j - w_i`` and ``θ_j - θ_i`` relative to its first. The periodic
|
|
15
|
+
problem of each macroscopic strain is solved on the sparse stiffness of the fluctuations
|
|
16
|
+
(SuperLU, the translations held at the first node; without bending and torsion the
|
|
17
|
+
rotations are left out: a pin-jointed truss), for the strains of morphoGen's Voigt order
|
|
18
|
+
``11, 22, 33, 23, 31, 12`` with engineering shears (``11, 22, 12`` in the plane), that of
|
|
19
|
+
:func:`morphogen.homogenization.postprocess.engineering_constants` (the Mandel form is ``W
|
|
20
|
+
C W``, ``W = diag(1, 1, 1, √2, √2, √2)``). The effective stiffness is the energy of the
|
|
21
|
+
solutions ``u_I`` per unit volume (per unit area in the plane),
|
|
22
|
+
|
|
23
|
+
C_IJ = (1 / V) Σ_beams u_I · K_e u_J,
|
|
24
|
+
|
|
25
|
+
the sum of the parts stored in the stretching, bending and torsion of the beams, each
|
|
26
|
+
positive semi-definite: the energy split of any macroscopic strain. The bending of a
|
|
27
|
+
Timoshenko beam is a uniform curvature (``EI (θ1 - θ2)² / l``, no shear force) and the
|
|
28
|
+
rotation of its chord ``a = (θ1 + θ2) / 2 - (v2 - v1) / l``, of stiffness ``k_a = 12 EI / l
|
|
29
|
+
(1 + Φ)``, the bending and shear compliances in series, whose energy is split between
|
|
30
|
+
bending and transverse shear as ``1 : Φ`` (the part ``shear``). The affine estimate is
|
|
31
|
+
the stretching of affinely deformed fibres (Cox 1952), ``C_aff = (1 / V) Σ E A L N Nᵀ``,
|
|
32
|
+
``N = (n1², n2², n3², n2 n3, n3 n1, n1 n2)`` for a fibre along ``n``: for isotropic
|
|
33
|
+
orientations ``E = φ E_s / 6`` and ``ν = 1/4`` in space, ``φ E_s / 3`` and ``1/3`` in the
|
|
34
|
+
plane, ``φ = Σ A L / V`` the fibre volume fraction (the fibre volume per unit area in the
|
|
35
|
+
plane). The non-affinity of a macroscopic strain ``E`` is the mean square non-affine
|
|
36
|
+
motion of the ends of the beams over their mean square length, ``Γ = Σ |w_j - w_i|² / (|E|²
|
|
37
|
+
Σ l²)``: the measure of Head, Levine & MacKintosh (2003) and Hatami-Marbini & Picu (2008)
|
|
38
|
+
at the scale of the segments, zero for an affine deformation (that of the nodes
|
|
39
|
+
themselves, ``⟨|w - w̄|²⟩``, grows with the size of a plane cell, as the fluctuations of a
|
|
40
|
+
random medium in two dimensions, and the motions relative to the length of each beam are
|
|
41
|
+
dominated by the shortest); and the ratio of the Young's modulus to that of the affine
|
|
42
|
+
estimate. Beam by beam, the axial force and the energy of each part under a uniaxial
|
|
43
|
+
stress (:func:`beam_forces`) show the force chains and the beams that bend.
|
|
44
|
+
|
|
45
|
+
Networks of non-identical beams (Ban et al. 2016). The stiffness ``k_i`` of a mode of the
|
|
46
|
+
beams (``axial``, ``bending``, or ``modulus``: all of them, the Young's modulus of each
|
|
47
|
+
fibre) is drawn with mean ``k_0`` and coefficient of variation ``CV``. The Young's modulus
|
|
48
|
+
of the network ``E(k)`` is the minimum, over the fluctuations and the free macroscopic
|
|
49
|
+
strains (the lateral contraction of a uniaxial stress), of an energy linear in each
|
|
50
|
+
``k_i``: it is concave in each, so that the network softens on average, and to second
|
|
51
|
+
order in ``CV``
|
|
52
|
+
|
|
53
|
+
(E_0 - ⟨E⟩) / E_0 = s CV², s = -(k_0² / 2 E_0) Σ_i ∂²E/∂k_i²,
|
|
54
|
+
σ_E² / E_0² = v CV², v = (k_0 / E_0)² Σ_i (∂E/∂k_i)²,
|
|
55
|
+
|
|
56
|
+
with ``∂E/∂k_i = U · K_i' U / V`` (``U`` the solution of the uniaxial stress, ``K_i'``
|
|
57
|
+
the stiffness of the mode of beam ``i`` per unit ``k``) and ``∂²E/∂k_i² = -(2 / V k_0²)
|
|
58
|
+
(f_i · K⁻¹ f_i + g_i · (V C')⁻¹ g_i)``, ``f_i = k_0 K_i' U`` the force of the beam on the
|
|
59
|
+
fluctuations, ``g_iJ = u_J · f_i`` on the free strains and ``C'`` their stiffness, plus
|
|
60
|
+
``U · K_i'' U / V`` where the stiffness of the beam is not linear in its factor (the ``EI``
|
|
61
|
+
and ``κGA`` of Timoshenko beams, concave: ``k_a'' = -2 k_a Φ / (1 + Φ)²``): computed
|
|
62
|
+
exactly for a frame (:func:`softening_coefficients`) and against replicas of the stiffness
|
|
63
|
+
(:func:`softening`). The mode ``area`` scales ``EA`` and ``κGA`` together, the area of the
|
|
64
|
+
general sections of Ban et al.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
from __future__ import annotations
|
|
68
|
+
|
|
69
|
+
import dataclasses
|
|
70
|
+
from dataclasses import dataclass
|
|
71
|
+
|
|
72
|
+
import numpy as np
|
|
73
|
+
import scipy.sparse as sp
|
|
74
|
+
import scipy.sparse.linalg as spla
|
|
75
|
+
from scipy.sparse.csgraph import connected_components
|
|
76
|
+
|
|
77
|
+
from morphogen.homogenization.elements import VOIGT
|
|
78
|
+
from morphogen.homogenization.frames import Frame, SpaceFrame
|
|
79
|
+
from morphogen.seeding import SeedLike, make_rng
|
|
80
|
+
|
|
81
|
+
#: The modes of the beams whose stiffness varies among them: ``axial`` (EA), ``bending``
|
|
82
|
+
#: (EI), ``modulus`` (the Young's modulus: EA, EI, GJ and κGA alike) or ``area`` (the
|
|
83
|
+
#: area of a general section: EA and the shear stiffness κGA of Timoshenko beams)
|
|
84
|
+
MODES = ("axial", "bending", "modulus", "area")
|
|
85
|
+
#: The laws of the stiffness of the beams, of mean 1 and coefficient of variation CV:
|
|
86
|
+
#: ``normal`` (truncated at 1e-3), ``lognormal`` and ``bimodal`` (1 ± CV, equally likely)
|
|
87
|
+
LAWS = ("normal", "lognormal", "bimodal")
|
|
88
|
+
#: The Voigt order of the strains in the plane (engineering shear)
|
|
89
|
+
PLANE_VOIGT = ((0, 0), (1, 1), (0, 1))
|
|
90
|
+
#: Beams whose fluctuation forces are solved together (the second derivatives)
|
|
91
|
+
BATCH = 256
|
|
92
|
+
#: The smallest pivot of the factored stiffness of a truss, relative to the largest,
|
|
93
|
+
#: without mechanisms (the zero-energy modes of a Voronoi truss: 5e-19). Beams with rigid
|
|
94
|
+
#: joints have none when connected; the short edges of Poisson-Voronoi foams stiffen
|
|
95
|
+
#: some dofs by 1e16 times.
|
|
96
|
+
MECHANISM = 1e-12
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _hermite(lengths: np.ndarray) -> np.ndarray:
|
|
100
|
+
"""The bending stiffness per unit ``EI`` of Euler–Bernoulli beams of ``lengths`` on
|
|
101
|
+
``(v1, θ1, v2, θ2)`` (m x 4 x 4)."""
|
|
102
|
+
base = np.array([[12, 6, -12, 6], [6, 4, -6, 2], [-12, -6, 12, -6], [6, 2, -6, 4]], float)
|
|
103
|
+
powers = np.array([[0, 1, 0, 1], [1, 2, 1, 2], [0, 1, 0, 1], [1, 2, 1, 2]])
|
|
104
|
+
length = lengths[:, None, None]
|
|
105
|
+
return base * length**powers / length**3
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _timoshenko(lengths: np.ndarray) -> dict[str, np.ndarray]:
|
|
109
|
+
"""The two parts of the bending of beams of ``lengths`` on ``(v1, θ1, v2, θ2)`` (m x 4
|
|
110
|
+
x 4): the ``curvature`` ``(θ1 - θ2)² / L`` per unit ``EI`` (uniform moment, no shear
|
|
111
|
+
force) and the ``chord`` rotation ``a = (θ1 + θ2) / 2 - (v2 - v1) / L``, ``a²``, per
|
|
112
|
+
unit of its stiffness ``k_a = 12 EI / L(1 + Φ)``, the bending ``l / 12 EI`` and the
|
|
113
|
+
shear ``1 / κGA l`` compliances in series: ``EI curvature + (12 EI / L) chord`` is the
|
|
114
|
+
Hermite stiffness of :func:`_hermite`."""
|
|
115
|
+
m = len(lengths)
|
|
116
|
+
c = np.array([0.0, 1.0, 0.0, -1.0])
|
|
117
|
+
a = np.empty((m, 4))
|
|
118
|
+
a[:, 0], a[:, 1], a[:, 2], a[:, 3] = 1.0 / lengths, 0.5, -1.0 / lengths, 0.5
|
|
119
|
+
return {
|
|
120
|
+
"curvature": np.outer(c, c)[None] / lengths[:, None, None],
|
|
121
|
+
"chord": np.einsum("mi,mj->mij", a, a),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _plane_units(d: np.ndarray, timoshenko: bool = False) -> dict[str, np.ndarray]:
|
|
126
|
+
"""The stiffness of plane beams of vectors ``d`` per unit ``EA`` and ``EI`` in global
|
|
127
|
+
axes (m x 6 x 6, dofs ``u1 v1 θ1 u2 v2 θ2``), as :func:`frames.beam_matrices`, and for
|
|
128
|
+
Timoshenko beams the ``curvature`` and ``chord`` parts of the bending
|
|
129
|
+
(:func:`_timoshenko`)."""
|
|
130
|
+
length = np.hypot(d[:, 0], d[:, 1])
|
|
131
|
+
c, s = d[:, 0] / length, d[:, 1] / length
|
|
132
|
+
m = len(d)
|
|
133
|
+
b = np.zeros((m, 6))
|
|
134
|
+
b[:, 0], b[:, 1], b[:, 3], b[:, 4] = -c, -s, c, s
|
|
135
|
+
p = np.zeros((m, 4, 6)) # (v1, θ1, v2, θ2) of the local axes
|
|
136
|
+
p[:, 0, 0], p[:, 0, 1], p[:, 1, 2] = -s, c, 1.0
|
|
137
|
+
p[:, 2, 3], p[:, 2, 4], p[:, 3, 5] = -s, c, 1.0
|
|
138
|
+
out = {
|
|
139
|
+
"axial": np.einsum("ma,mb->mab", b, b) / length[:, None, None],
|
|
140
|
+
"bending": np.einsum("mia,mij,mjb->mab", p, _hermite(length), p),
|
|
141
|
+
}
|
|
142
|
+
if timoshenko:
|
|
143
|
+
for key, local in _timoshenko(length).items():
|
|
144
|
+
out[key] = np.einsum("mia,mij,mjb->mab", p, local, p)
|
|
145
|
+
return out
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _space_units(d: np.ndarray, timoshenko: bool = False) -> dict[str, np.ndarray]:
|
|
149
|
+
"""The stiffness of beams in space of vectors ``d`` per unit ``EA``, ``EI`` and ``GJ``
|
|
150
|
+
in global axes (m x 12 x 12, dofs ``u v w θx θy θz`` of each end), as
|
|
151
|
+
:func:`frames.space_beam_matrices` (the bending, the same about both axes of the
|
|
152
|
+
section, does not depend on their choice), and for Timoshenko beams the ``curvature``
|
|
153
|
+
and ``chord`` parts of the bending in both planes (:func:`_timoshenko`)."""
|
|
154
|
+
length = np.linalg.norm(d, axis=1)
|
|
155
|
+
ex = d / length[:, None]
|
|
156
|
+
helper = np.where((np.abs(ex[:, 2]) < 0.9)[:, None], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0])
|
|
157
|
+
ey = np.cross(helper, ex)
|
|
158
|
+
ey /= np.linalg.norm(ey, axis=1)[:, None]
|
|
159
|
+
ez = np.cross(ex, ey)
|
|
160
|
+
m = len(d)
|
|
161
|
+
stretch, twist = np.zeros((m, 12)), np.zeros((m, 12))
|
|
162
|
+
stretch[:, 0:3], stretch[:, 6:9] = -ex, ex
|
|
163
|
+
twist[:, 3:6], twist[:, 9:12] = -ex, ex
|
|
164
|
+
plane_y, plane_z = np.zeros((m, 4, 12)), np.zeros((m, 4, 12))
|
|
165
|
+
for row, start in enumerate((0, 3, 6, 9)): # (v, θz) and (w, -θy) of both ends
|
|
166
|
+
rotation = start in (3, 9)
|
|
167
|
+
plane_y[:, row, start : start + 3] = ez if rotation else ey
|
|
168
|
+
plane_z[:, row, start : start + 3] = -ey if rotation else ez
|
|
169
|
+
hermite = _hermite(length)
|
|
170
|
+
inv = 1.0 / length[:, None, None]
|
|
171
|
+
out = {
|
|
172
|
+
"axial": np.einsum("ma,mb->mab", stretch, stretch) * inv,
|
|
173
|
+
"bending": np.einsum("mia,mij,mjb->mab", plane_y, hermite, plane_y)
|
|
174
|
+
+ np.einsum("mia,mij,mjb->mab", plane_z, hermite, plane_z),
|
|
175
|
+
"torsion": np.einsum("ma,mb->mab", twist, twist) * inv,
|
|
176
|
+
}
|
|
177
|
+
if timoshenko:
|
|
178
|
+
for key, local in _timoshenko(length).items():
|
|
179
|
+
out[key] = np.einsum("mia,mij,mjb->mab", plane_y, local, plane_y) + np.einsum(
|
|
180
|
+
"mia,mij,mjb->mab", plane_z, local, plane_z
|
|
181
|
+
)
|
|
182
|
+
return out
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _rigid_arms(axes: np.ndarray, rigid: np.ndarray) -> np.ndarray:
|
|
186
|
+
"""The motion of the ends of the flexible parts of beams of unit ``axes`` with rigid
|
|
187
|
+
ends of lengths ``rigid`` (m x 2) from the dofs of their nodes (m x n x n): ``u + θ ×
|
|
188
|
+
a₁ e`` at the first, ``u - θ × a₂ e`` at the second, the rotations unchanged."""
|
|
189
|
+
m, dim = axes.shape
|
|
190
|
+
per_node = 6 if dim == 3 else 3
|
|
191
|
+
out = np.broadcast_to(np.eye(2 * per_node), (m, 2 * per_node, 2 * per_node)).copy()
|
|
192
|
+
for end, sign in ((0, -1.0), (1, 1.0)):
|
|
193
|
+
arm = sign * rigid[:, end]
|
|
194
|
+
u, t = end * per_node, end * per_node + dim
|
|
195
|
+
if dim == 3: # θ × (-arm e) = arm [e]x θ
|
|
196
|
+
ex, ey, ez = axes.T
|
|
197
|
+
skew = np.zeros((m, 3, 3))
|
|
198
|
+
skew[:, 0, 1], skew[:, 0, 2], skew[:, 1, 2] = -ez, ey, -ex
|
|
199
|
+
skew[:, 1, 0], skew[:, 2, 0], skew[:, 2, 1] = ez, -ey, ex
|
|
200
|
+
out[:, u : u + 3, t : t + 3] = arm[:, None, None] * skew
|
|
201
|
+
else: # θ z × (-arm e) = -arm θ (-e2, e1)
|
|
202
|
+
out[:, u, t] = arm * axes[:, 1]
|
|
203
|
+
out[:, u + 1, t] = -arm * axes[:, 0]
|
|
204
|
+
return out
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class _Periodic:
|
|
208
|
+
"""The periodic problem of a frame: its beams (vectors, lengths, dofs), their stiffness
|
|
209
|
+
per unit of each mode, the affine motion of the unit strains and the sparse assembly.
|
|
210
|
+
Beams with rigid ends take the stiffness of their flexible part (``flexible`` long),
|
|
211
|
+
moved by the rigid arms of their nodes."""
|
|
212
|
+
|
|
213
|
+
def __init__(self, frame) -> None:
|
|
214
|
+
if not isinstance(frame, (Frame, SpaceFrame)):
|
|
215
|
+
raise TypeError("frame_stiffness: a Frame or a SpaceFrame")
|
|
216
|
+
self.frame = frame
|
|
217
|
+
self.space = isinstance(frame, SpaceFrame)
|
|
218
|
+
self.dim = 3 if self.space else 2
|
|
219
|
+
self.vectors = np.asarray(frame.vectors(), dtype=float)
|
|
220
|
+
self.lengths = np.linalg.norm(self.vectors, axis=1)
|
|
221
|
+
if len(self.lengths) == 0 or np.any(self.lengths <= 0):
|
|
222
|
+
raise ValueError("frame_stiffness: beams of positive length")
|
|
223
|
+
self.dofs = frame._dofs()
|
|
224
|
+
self.n_dofs = int(frame.n_dofs)
|
|
225
|
+
self.volume = float(abs(np.linalg.det(frame.lattice)))
|
|
226
|
+
self.timoshenko = getattr(frame, "shear", None) is not None
|
|
227
|
+
units = _space_units if self.space else _plane_units
|
|
228
|
+
rigid = getattr(frame, "rigid", None)
|
|
229
|
+
if rigid is None:
|
|
230
|
+
self.flexible = self.lengths
|
|
231
|
+
self.units = units(self.vectors, self.timoshenko)
|
|
232
|
+
else:
|
|
233
|
+
rigid = np.asarray(rigid, dtype=float).reshape(len(self.lengths), 2)
|
|
234
|
+
self.flexible = self.lengths - rigid.sum(axis=1)
|
|
235
|
+
if np.any(rigid < 0) or np.any(self.flexible <= 0):
|
|
236
|
+
raise ValueError("frame_stiffness: rigid ends non-negative, shorter than the beams")
|
|
237
|
+
shortened = self.vectors * (self.flexible / self.lengths)[:, None]
|
|
238
|
+
flexible = units(shortened, self.timoshenko)
|
|
239
|
+
arms = _rigid_arms(self.vectors / self.lengths[:, None], rigid)
|
|
240
|
+
self.units = {
|
|
241
|
+
k: np.einsum("mia,mij,mjb->mab", arms, v, arms) for k, v in flexible.items()
|
|
242
|
+
}
|
|
243
|
+
self.strains = VOIGT if self.space else PLANE_VOIGT
|
|
244
|
+
per_node = 6 if self.space else 3
|
|
245
|
+
m, n = self.dofs.shape
|
|
246
|
+
self.affine = np.zeros((m, n, len(self.strains)))
|
|
247
|
+
for j, (a, b) in enumerate(self.strains):
|
|
248
|
+
e = np.zeros((self.dim, self.dim))
|
|
249
|
+
e[a, b] = e[b, a] = 1.0 if a == b else 0.5
|
|
250
|
+
self.affine[:, per_node : per_node + self.dim, j] = self.vectors @ e.T
|
|
251
|
+
self.rows = np.repeat(self.dofs, n, axis=1).ravel()
|
|
252
|
+
self.cols = np.tile(self.dofs, (1, n)).ravel()
|
|
253
|
+
graph = sp.coo_matrix(
|
|
254
|
+
(np.ones(len(self.dofs)), (frame.beams[:, 0], frame.beams[:, 1])),
|
|
255
|
+
shape=(len(frame.nodes),) * 2,
|
|
256
|
+
)
|
|
257
|
+
if connected_components(graph, directed=False)[0] > 1:
|
|
258
|
+
raise ValueError("frame_stiffness: the frame has disconnected parts")
|
|
259
|
+
free = np.ones(self.n_dofs, dtype=bool)
|
|
260
|
+
free[: self.dim] = False # the translations of the first node
|
|
261
|
+
torsion = frame.torsion if self.space else np.zeros(1)
|
|
262
|
+
self.truss = not np.any(frame.bending) and not np.any(torsion)
|
|
263
|
+
if self.truss: # pin joints: the rotations are left out
|
|
264
|
+
free[np.arange(self.n_dofs) % per_node >= self.dim] = False
|
|
265
|
+
self.free = free
|
|
266
|
+
|
|
267
|
+
def chord(self, bending, shear) -> tuple[np.ndarray, np.ndarray]:
|
|
268
|
+
"""The shear parameter ``Φ = 12 EI / (κGA l²)`` and the stiffness ``k_a = 12 EI /
|
|
269
|
+
l(1 + Φ)`` of the chord rotation of Timoshenko beams (m each), ``l`` their flexible
|
|
270
|
+
length."""
|
|
271
|
+
bending = np.asarray(bending, dtype=float)
|
|
272
|
+
phi = 12.0 * bending / (np.asarray(shear, dtype=float) * self.flexible**2)
|
|
273
|
+
return phi, 12.0 * bending / (self.flexible * (1.0 + phi))
|
|
274
|
+
|
|
275
|
+
def stiffness(self, axial, bending, torsion=None, shear=None) -> dict[str, np.ndarray]:
|
|
276
|
+
"""The element stiffness of each mode (m x n x n) for these beam stiffnesses: for
|
|
277
|
+
Timoshenko beams (``shear`` the ``κGA`` of each), the energy of the chord rotation
|
|
278
|
+
``k_a a² / 2`` split between ``bending`` and ``shear`` as their compliances in
|
|
279
|
+
series, ``1 : Φ``."""
|
|
280
|
+
out = {"axial": np.asarray(axial, dtype=float)[:, None, None] * self.units["axial"]}
|
|
281
|
+
if shear is None:
|
|
282
|
+
out["bending"] = np.asarray(bending, dtype=float)[:, None, None] * self.units["bending"]
|
|
283
|
+
else:
|
|
284
|
+
phi, k = self.chord(bending, shear)
|
|
285
|
+
chord = self.units["chord"]
|
|
286
|
+
out["bending"] = (
|
|
287
|
+
np.asarray(bending, dtype=float)[:, None, None] * self.units["curvature"]
|
|
288
|
+
+ (k / (1.0 + phi))[:, None, None] * chord
|
|
289
|
+
)
|
|
290
|
+
out["shear"] = (k * phi / (1.0 + phi))[:, None, None] * chord
|
|
291
|
+
if self.space:
|
|
292
|
+
out["torsion"] = np.asarray(torsion, dtype=float)[:, None, None] * self.units["torsion"]
|
|
293
|
+
return out
|
|
294
|
+
|
|
295
|
+
def values(self) -> dict:
|
|
296
|
+
"""The stiffness of the beams of the frame (the arguments of :meth:`stiffness`)."""
|
|
297
|
+
f = self.frame
|
|
298
|
+
return {
|
|
299
|
+
"axial": f.axial,
|
|
300
|
+
"bending": f.bending,
|
|
301
|
+
"torsion": f.torsion if self.space else None,
|
|
302
|
+
"shear": f.shear if self.timoshenko else None,
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
def of_frame(self) -> dict[str, np.ndarray]:
|
|
306
|
+
return self.stiffness(**self.values())
|
|
307
|
+
|
|
308
|
+
def derivatives(self, modes: dict, mode: str):
|
|
309
|
+
"""The first and second derivatives of the element stiffness in the factor of a
|
|
310
|
+
mode of each beam (m x n x n; the second None where it is linear in the factor):
|
|
311
|
+
the first is the stiffness of the parts of the energy that the mode carries; the
|
|
312
|
+
chord stiffness ``k_a`` of a Timoshenko beam, the bending and shear compliances in
|
|
313
|
+
series, is concave in the factor of either, ``k_a'' = -2 k_a Φ / (1 + Φ)²``."""
|
|
314
|
+
if mode == "axial":
|
|
315
|
+
return modes["axial"], None
|
|
316
|
+
if mode == "modulus":
|
|
317
|
+
return sum(modes.values()), None
|
|
318
|
+
first = modes["bending"] if mode == "bending" else modes["axial"]
|
|
319
|
+
if not self.timoshenko:
|
|
320
|
+
return first, None
|
|
321
|
+
if mode == "area":
|
|
322
|
+
first = first + modes["shear"]
|
|
323
|
+
phi, k = self.chord(self.frame.bending, self.frame.shear)
|
|
324
|
+
return first, (-2.0 * k * phi / (1.0 + phi) ** 2)[:, None, None] * self.units["chord"]
|
|
325
|
+
|
|
326
|
+
def factor(self, ke: np.ndarray):
|
|
327
|
+
"""The LU factors of the stiffness of the free fluctuations; for a truss, a pivot at
|
|
328
|
+
round-off relative to the largest (a zero-energy mode) refused."""
|
|
329
|
+
k = sp.coo_matrix((ke.ravel(), (self.rows, self.cols)), shape=(self.n_dofs,) * 2)
|
|
330
|
+
k = k.tocsr()[self.free][:, self.free].tocsc()
|
|
331
|
+
message = (
|
|
332
|
+
"frame_stiffness: the frame has mechanisms (a truss below rigidity, "
|
|
333
|
+
"disconnected parts or beams without stiffness)"
|
|
334
|
+
)
|
|
335
|
+
try:
|
|
336
|
+
lu = spla.splu(k)
|
|
337
|
+
except RuntimeError as exc: # exactly singular
|
|
338
|
+
raise ValueError(message) from exc
|
|
339
|
+
pivots = np.abs(lu.U.diagonal())
|
|
340
|
+
if self.truss and pivots.min() <= MECHANISM * pivots.max():
|
|
341
|
+
raise ValueError(message)
|
|
342
|
+
return lu
|
|
343
|
+
|
|
344
|
+
def scatter(self, forces: np.ndarray) -> np.ndarray:
|
|
345
|
+
"""Element forces (m x n x k) assembled on the free dofs (free x k)."""
|
|
346
|
+
out = np.zeros((self.n_dofs, forces.shape[2]))
|
|
347
|
+
np.add.at(out, self.dofs, forces)
|
|
348
|
+
return out[self.free]
|
|
349
|
+
|
|
350
|
+
def solve(self, ke: np.ndarray):
|
|
351
|
+
"""The element displacements of the unit strains (m x n x strains), the periodic
|
|
352
|
+
fluctuations (dofs x strains) and the LU factors."""
|
|
353
|
+
lu = self.factor(ke)
|
|
354
|
+
rhs = self.scatter(np.einsum("mab,mbj->maj", ke, self.affine))
|
|
355
|
+
w = np.zeros((self.n_dofs, len(self.strains)))
|
|
356
|
+
w[self.free] = -lu.solve(rhs)
|
|
357
|
+
return w[self.dofs] + self.affine, w, lu
|
|
358
|
+
|
|
359
|
+
def energy(self, u: np.ndarray, ke: np.ndarray) -> np.ndarray:
|
|
360
|
+
"""``(1 / V) Σ u_I · K_e u_J`` (strains x strains, symmetrized)."""
|
|
361
|
+
out = np.einsum("mai,mab,mbj->ij", u, ke, u) / self.volume
|
|
362
|
+
return 0.5 * (out + out.T)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _strain_norm(strain: np.ndarray, dim: int) -> float:
|
|
366
|
+
"""The norm of a strain tensor given by its Voigt components (engineering shears)."""
|
|
367
|
+
normal = strain[:dim]
|
|
368
|
+
shear = strain[dim:]
|
|
369
|
+
return float(np.sqrt(normal @ normal + 0.5 * shear @ shear))
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
@dataclass
|
|
373
|
+
class FrameStiffness:
|
|
374
|
+
"""The effective stiffness of a periodic frame (:func:`frame_stiffness`): the
|
|
375
|
+
``stiffness`` (6 x 6, Voigt order 11, 22, 33, 23, 31, 12 with engineering shears; 3 x 3,
|
|
376
|
+
11, 22, 12, per unit area in the plane) and its parts stored in the ``stretching``,
|
|
377
|
+
``bending`` and ``torsion`` of the beams (their sum), the ``affine`` estimate (the
|
|
378
|
+
stretching of affinely deformed beams), the sums over the beams of the products of
|
|
379
|
+
the non-affine motions of their ends under the unit strains over that of the squares
|
|
380
|
+
of their lengths (``gram``), the periodic ``fluctuations`` themselves (dofs x
|
|
381
|
+
strains), the mean length of the beams, the fibre volume fraction (fibre volume per
|
|
382
|
+
unit area in the plane; None when the sections are unknown), the dimension and, for
|
|
383
|
+
Timoshenko beams, the part stored in their transverse ``shear`` (None for
|
|
384
|
+
Euler–Bernoulli beams)."""
|
|
385
|
+
|
|
386
|
+
stiffness: np.ndarray
|
|
387
|
+
stretching: np.ndarray
|
|
388
|
+
bending: np.ndarray
|
|
389
|
+
torsion: np.ndarray
|
|
390
|
+
affine: np.ndarray
|
|
391
|
+
gram: np.ndarray
|
|
392
|
+
fluctuations: np.ndarray
|
|
393
|
+
mean_length: float
|
|
394
|
+
density: float | None
|
|
395
|
+
dimension: int
|
|
396
|
+
shear: np.ndarray | None = None
|
|
397
|
+
|
|
398
|
+
def compliance(self) -> np.ndarray:
|
|
399
|
+
return np.linalg.inv(self.stiffness)
|
|
400
|
+
|
|
401
|
+
def uniaxial(self, axis: int = 0) -> np.ndarray:
|
|
402
|
+
"""The macroscopic strain (Voigt) of a uniaxial stress along ``axis``, its normal
|
|
403
|
+
component along the axis equal to 1."""
|
|
404
|
+
s = self.compliance()
|
|
405
|
+
return s[:, axis] / s[axis, axis]
|
|
406
|
+
|
|
407
|
+
def young(self, axis: int = 0) -> float:
|
|
408
|
+
"""The Young's modulus along ``axis``."""
|
|
409
|
+
return float(1.0 / self.compliance()[axis, axis])
|
|
410
|
+
|
|
411
|
+
def poisson(self, axis: int = 0, lateral: int = 1) -> float:
|
|
412
|
+
"""The Poisson's ratio: the contraction along ``lateral`` under a stress along
|
|
413
|
+
``axis``."""
|
|
414
|
+
s = self.compliance()
|
|
415
|
+
return float(-s[axis, lateral] / s[axis, axis])
|
|
416
|
+
|
|
417
|
+
def engineering(self) -> dict[str, float]:
|
|
418
|
+
"""Young's moduli, Poisson's ratios and shear moduli (as
|
|
419
|
+
:func:`morphogen.homogenization.postprocess.engineering_constants`)."""
|
|
420
|
+
if self.dimension == 3:
|
|
421
|
+
from morphogen.homogenization.postprocess import engineering_constants
|
|
422
|
+
|
|
423
|
+
return engineering_constants(self.stiffness)
|
|
424
|
+
s = self.compliance()
|
|
425
|
+
return {
|
|
426
|
+
"E1": float(1.0 / s[0, 0]),
|
|
427
|
+
"E2": float(1.0 / s[1, 1]),
|
|
428
|
+
"nu12": float(-s[0, 1] / s[0, 0]),
|
|
429
|
+
"nu21": float(-s[0, 1] / s[1, 1]),
|
|
430
|
+
"G12": float(1.0 / s[2, 2]),
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
def _strain(self, strain) -> np.ndarray:
|
|
434
|
+
if strain is None:
|
|
435
|
+
return self.uniaxial(0)
|
|
436
|
+
e = np.asarray(strain, dtype=float)
|
|
437
|
+
if e.shape == (self.dimension, self.dimension):
|
|
438
|
+
order = VOIGT if self.dimension == 3 else PLANE_VOIGT
|
|
439
|
+
e = np.array([e[a, b] * (1.0 if a == b else 2.0) for a, b in order])
|
|
440
|
+
if e.shape != (len(self.stiffness),):
|
|
441
|
+
raise ValueError("strain: Voigt components (engineering shears) or a tensor")
|
|
442
|
+
return e
|
|
443
|
+
|
|
444
|
+
def split(self, strain=None) -> dict[str, float]:
|
|
445
|
+
"""The fractions of the energy of a macroscopic strain (Voigt components with
|
|
446
|
+
engineering shears, or a tensor; by default that of a uniaxial stress along x)
|
|
447
|
+
stored in the stretching, bending and torsion of the beams (and their transverse
|
|
448
|
+
shear for Timoshenko beams)."""
|
|
449
|
+
e = self._strain(strain)
|
|
450
|
+
total = float(e @ self.stiffness @ e)
|
|
451
|
+
parts = {"stretching": self.stretching, "bending": self.bending}
|
|
452
|
+
if self.dimension == 3:
|
|
453
|
+
parts["torsion"] = self.torsion
|
|
454
|
+
if self.shear is not None:
|
|
455
|
+
parts["shear"] = self.shear
|
|
456
|
+
return {k: float(e @ v @ e) / total for k, v in parts.items()}
|
|
457
|
+
|
|
458
|
+
def nonaffinity(self, strain=None) -> float:
|
|
459
|
+
"""The mean square non-affine motion of the ends of the beams over their mean
|
|
460
|
+
square length under a macroscopic strain ``E`` (by default that of a uniaxial stress
|
|
461
|
+
along x), ``Σ |w_j - w_i|² / (|E|² Σ l²)``: zero for an affine deformation."""
|
|
462
|
+
e = self._strain(strain)
|
|
463
|
+
return float(e @ self.gram @ e) / _strain_norm(e, self.dimension) ** 2
|
|
464
|
+
|
|
465
|
+
def affinity(self, axis: int = 0) -> float:
|
|
466
|
+
"""The Young's modulus along ``axis`` over that of the affine estimate (1 for an
|
|
467
|
+
affine deformation of slender beams)."""
|
|
468
|
+
try:
|
|
469
|
+
affine = 1.0 / np.linalg.inv(self.affine)[axis, axis]
|
|
470
|
+
except np.linalg.LinAlgError: # beams along too few directions
|
|
471
|
+
return float("nan")
|
|
472
|
+
return self.young(axis) / float(affine)
|
|
473
|
+
|
|
474
|
+
def by_axis(self) -> list[dict]:
|
|
475
|
+
"""The values of a uniaxial stress along each axis: the ``axis`` (x, y, z), the
|
|
476
|
+
Young's modulus, the Poisson's ratio (the contraction along the next axis), the
|
|
477
|
+
ratio to the affine estimate (``affinity``), the fractions of the energy of
|
|
478
|
+
:meth:`split` and the ``nonaffinity``."""
|
|
479
|
+
dim = self.dimension
|
|
480
|
+
out = []
|
|
481
|
+
for a in range(dim):
|
|
482
|
+
strain = self.uniaxial(a)
|
|
483
|
+
out.append(
|
|
484
|
+
{
|
|
485
|
+
"axis": "xyz"[a],
|
|
486
|
+
"young": self.young(a),
|
|
487
|
+
"poisson": self.poisson(a, (a + 1) % dim),
|
|
488
|
+
"affinity": self.affinity(a),
|
|
489
|
+
**self.split(strain),
|
|
490
|
+
"nonaffinity": self.nonaffinity(strain),
|
|
491
|
+
}
|
|
492
|
+
)
|
|
493
|
+
return out
|
|
494
|
+
|
|
495
|
+
def summary(self, young: float = 1.0) -> dict[str, float]:
|
|
496
|
+
"""The main values, the moduli relative to the Young's modulus ``young`` of the
|
|
497
|
+
beams (the mean over the axes of :meth:`by_axis` for the moduli, Poisson's ratios,
|
|
498
|
+
stretching fractions and non-affinity)."""
|
|
499
|
+
rows = self.by_axis()
|
|
500
|
+
|
|
501
|
+
def mean(key: str) -> float:
|
|
502
|
+
return float(np.mean([row[key] for row in rows]))
|
|
503
|
+
|
|
504
|
+
out = {
|
|
505
|
+
"frame_young": mean("young") / young,
|
|
506
|
+
"frame_poisson": mean("poisson"),
|
|
507
|
+
"frame_affinity": mean("affinity"),
|
|
508
|
+
"frame_stretching": mean("stretching"),
|
|
509
|
+
"frame_nonaffinity": mean("nonaffinity"),
|
|
510
|
+
}
|
|
511
|
+
if self.density:
|
|
512
|
+
out["frame_young_per_density"] = out["frame_young"] / self.density
|
|
513
|
+
return out
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def frame_stiffness(frame) -> FrameStiffness:
|
|
517
|
+
"""The effective stiffness of a periodic frame (:class:`Frame` or :class:`SpaceFrame`)
|
|
518
|
+
by its sparse periodic problem, its split into stretching, bending and torsion and the
|
|
519
|
+
fluctuations of the nodes (the module docstring gives the conventions)."""
|
|
520
|
+
problem = _Periodic(frame)
|
|
521
|
+
modes = problem.of_frame()
|
|
522
|
+
ke = sum(modes.values())
|
|
523
|
+
u, w, _ = problem.solve(ke)
|
|
524
|
+
parts = {k: problem.energy(u, v) for k, v in modes.items()}
|
|
525
|
+
dim = problem.dim
|
|
526
|
+
per_node = 6 if problem.space else 3
|
|
527
|
+
ends = w[problem.dofs] # beams x dofs x strains
|
|
528
|
+
jump = ends[:, per_node : per_node + dim] - ends[:, :dim]
|
|
529
|
+
gram = np.einsum("mai,maj->ij", jump, jump) / np.sum(problem.lengths**2)
|
|
530
|
+
n = problem.vectors / problem.lengths[:, None]
|
|
531
|
+
voigt = np.column_stack([n[:, a] * n[:, b] for a, b in problem.strains])
|
|
532
|
+
# EA L N Nᵀ, the extension of a beam carried by its flexible part: EA L² / l
|
|
533
|
+
stretch = frame.axial * problem.lengths**2 / problem.flexible
|
|
534
|
+
affine = np.einsum("m,mi,mj->ij", stretch, voigt, voigt)
|
|
535
|
+
area = getattr(frame, "area", None)
|
|
536
|
+
density = None if area is None else float(np.sum(area * problem.lengths) / problem.volume)
|
|
537
|
+
return FrameStiffness(
|
|
538
|
+
stiffness=sum(parts.values()),
|
|
539
|
+
stretching=parts["axial"],
|
|
540
|
+
bending=parts["bending"],
|
|
541
|
+
torsion=parts.get("torsion", np.zeros_like(parts["axial"])),
|
|
542
|
+
affine=affine / problem.volume,
|
|
543
|
+
gram=gram,
|
|
544
|
+
fluctuations=w,
|
|
545
|
+
mean_length=float(problem.lengths.mean()),
|
|
546
|
+
density=density,
|
|
547
|
+
dimension=dim,
|
|
548
|
+
shear=parts.get("shear"),
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
#: The parts of the energy of the beams (:func:`beam_forces`), as named by
|
|
553
|
+
#: :meth:`FrameStiffness.split`, from the modes of the element stiffness
|
|
554
|
+
PARTS = {"axial": "stretching", "bending": "bending", "torsion": "torsion", "shear": "shear"}
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def beam_forces(frame, axis: int = 0, *, strain=None) -> dict:
|
|
558
|
+
"""The axial force of each beam of a frame and the energy stored in each part of each
|
|
559
|
+
beam under a uniaxial stress of 1 along ``axis`` (the lateral stresses free) or under
|
|
560
|
+
a macroscopic ``strain`` (Voigt components with engineering shears, or a tensor), by
|
|
561
|
+
the sparse periodic problem: the ``strain`` (Voigt), the ``force`` ``N = EA δ / l``
|
|
562
|
+
of each beam (positive in tension; ``δ`` the extension of its flexible part ``l``,
|
|
563
|
+
which its rigid ends do not change) and its energy per unit volume (per unit area in
|
|
564
|
+
the plane) stored in its ``stretching``, ``bending``, ``torsion`` (in space) and
|
|
565
|
+
transverse ``shear`` (Timoshenko beams), whose sum over the beams and the parts is
|
|
566
|
+
``E · C E / 2``: the fractions of :meth:`FrameStiffness.split` beam by beam. They show
|
|
567
|
+
the force chains of a network and the beams that bend, as
|
|
568
|
+
:func:`morphogen.viz.figures.frame_figure` draws them."""
|
|
569
|
+
problem = _Periodic(frame)
|
|
570
|
+
modes = problem.of_frame()
|
|
571
|
+
ke = sum(modes.values())
|
|
572
|
+
u, _, _ = problem.solve(ke)
|
|
573
|
+
c = problem.energy(u, ke)
|
|
574
|
+
dim = problem.dim
|
|
575
|
+
if strain is None:
|
|
576
|
+
if not 0 <= int(axis) < dim:
|
|
577
|
+
raise ValueError(f"axis: from 0 to {dim - 1}")
|
|
578
|
+
e = np.linalg.inv(c)[:, int(axis)] # Σ = 1 along the axis
|
|
579
|
+
else:
|
|
580
|
+
e = np.asarray(strain, dtype=float)
|
|
581
|
+
if e.shape == (dim, dim):
|
|
582
|
+
e = np.array([e[a, b] * (1.0 if a == b else 2.0) for a, b in problem.strains])
|
|
583
|
+
if e.shape != (len(c),):
|
|
584
|
+
raise ValueError("strain: Voigt components (engineering shears) or a tensor")
|
|
585
|
+
uu = u @ e # element displacements (m x n)
|
|
586
|
+
per_node = 6 if problem.space else 3
|
|
587
|
+
axes = problem.vectors / problem.lengths[:, None]
|
|
588
|
+
extension = np.einsum("mi,mi->m", axes, uu[:, per_node : per_node + dim] - uu[:, :dim])
|
|
589
|
+
force = np.asarray(frame.axial, dtype=float) * extension / problem.flexible
|
|
590
|
+
out = {"strain": e, "force": force}
|
|
591
|
+
for mode, k in modes.items():
|
|
592
|
+
out[PARTS[mode]] = 0.5 * np.einsum("ma,mab,mb->m", uu, k, uu) / problem.volume
|
|
593
|
+
return out
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def network_stiffness(
|
|
597
|
+
framework, radius, *, young=1.0, poisson=0.3, dimension: int = 3, shear_coefficient=None,
|
|
598
|
+
rigid_joints=None,
|
|
599
|
+
): # fmt: skip
|
|
600
|
+
""":func:`frame_stiffness` of the frame of beams of circular sections of a periodic
|
|
601
|
+
framework (or of its dictionary, as kept in the metadata of the network models):
|
|
602
|
+
``radius``, ``young`` and ``poisson`` one value or one per bar; Timoshenko beams with
|
|
603
|
+
a ``shear_coefficient`` (``"cowper"``, a value or one per bar), Euler–Bernoulli beams
|
|
604
|
+
without; with ``rigid_joints``, beams rigid over that many radii from each node (the
|
|
605
|
+
struts merged in the joints of a continuum)."""
|
|
606
|
+
options = {
|
|
607
|
+
"young": young,
|
|
608
|
+
"poisson": poisson,
|
|
609
|
+
"shear_coefficient": shear_coefficient,
|
|
610
|
+
"rigid_joints": rigid_joints,
|
|
611
|
+
}
|
|
612
|
+
if dimension == 2:
|
|
613
|
+
return frame_stiffness(Frame.from_framework(framework, radius, **options))
|
|
614
|
+
if dimension != 3:
|
|
615
|
+
raise ValueError("dimension: 2 or 3")
|
|
616
|
+
return frame_stiffness(SpaceFrame.from_framework(framework, radius, **options))
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
#: The radius of the fibres of a realization of a network model: the first of these keys
|
|
620
|
+
#: in its summary (``delaunay_network``, ``open_foam``: the radius solved for a volume
|
|
621
|
+
#: fraction), else of the parameters of its model (``random_lattice``)
|
|
622
|
+
RADII = ("radius", "strut_radius")
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def network_frame(micro, *, young=1.0, poisson=0.3, shear_coefficient=None, rigid_joints=None):
|
|
626
|
+
"""The frame of beams of a realization of a network model, whose metadata keeps its
|
|
627
|
+
framework (``delaunay_network``, ``open_foam``, ``random_lattice``: that of the
|
|
628
|
+
periodic box, or of the larger periodic lattice of a window): beams of circular
|
|
629
|
+
sections of the radius of its fibres (:data:`RADII`), with the options of
|
|
630
|
+
:func:`network_stiffness`; a plane :class:`Frame` when the framework lies in a plane
|
|
631
|
+
(its nodes at one height, no bar across the box along z: a planar Delaunay network),
|
|
632
|
+
else a :class:`SpaceFrame`. A microstructure without a framework is refused."""
|
|
633
|
+
from morphogen.design.frames import Framework
|
|
634
|
+
|
|
635
|
+
metadata = getattr(micro, "metadata", None) or {}
|
|
636
|
+
model = getattr(micro, "model", None)
|
|
637
|
+
name = model.name if model is not None else type(micro).__name__
|
|
638
|
+
framework = metadata.get("framework")
|
|
639
|
+
if framework is None:
|
|
640
|
+
raise ValueError(
|
|
641
|
+
f"{name} has no framework of fibres or struts, hence no frame of beams: the "
|
|
642
|
+
"realizations of delaunay_network, open_foam and random_lattice keep theirs"
|
|
643
|
+
)
|
|
644
|
+
if isinstance(framework, dict):
|
|
645
|
+
framework = Framework.from_dict(framework)
|
|
646
|
+
summary = metadata.get("summary") or {}
|
|
647
|
+
radii = [summary.get(k) for k in RADII] + [getattr(model, k, None) for k in RADII]
|
|
648
|
+
radius = next((float(r) for r in radii if r is not None), None)
|
|
649
|
+
if radius is None:
|
|
650
|
+
raise ValueError(f"{name}: no radius of the fibres in its summary or its model")
|
|
651
|
+
options = {
|
|
652
|
+
"young": young,
|
|
653
|
+
"poisson": poisson,
|
|
654
|
+
"shear_coefficient": shear_coefficient,
|
|
655
|
+
"rigid_joints": rigid_joints,
|
|
656
|
+
}
|
|
657
|
+
nodes, shifts = np.asarray(framework.nodes), np.asarray(framework.shifts)
|
|
658
|
+
if np.ptp(nodes[:, 2]) == 0 and not np.any(shifts[:, 2]):
|
|
659
|
+
return Frame.from_framework(framework, radius, **options)
|
|
660
|
+
return SpaceFrame.from_framework(framework, radius, **options)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
# -- networks of non-identical beams (Ban et al. 2016) -----------------------------------
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
def fibre_scales(count: int, cv: float, law: str = "normal", seed: SeedLike = None):
|
|
667
|
+
"""``count`` factors of mean 1 and coefficient of variation ``cv``: ``normal`` (draws
|
|
668
|
+
below 1e-3 raised to it), ``lognormal`` or ``bimodal`` (1 - cv or 1 + cv, equally
|
|
669
|
+
likely)."""
|
|
670
|
+
if law not in LAWS:
|
|
671
|
+
raise ValueError(f"law: one of {LAWS}")
|
|
672
|
+
if not 0.0 <= cv < (1.0 if law == "bimodal" else np.inf):
|
|
673
|
+
raise ValueError("cv: non-negative (below 1 for the bimodal law)")
|
|
674
|
+
rng, _ = make_rng(seed)
|
|
675
|
+
if law == "normal":
|
|
676
|
+
return np.maximum(1.0 + cv * rng.standard_normal(count), 1e-3)
|
|
677
|
+
if law == "lognormal":
|
|
678
|
+
sigma2 = np.log1p(cv * cv)
|
|
679
|
+
return np.exp(np.sqrt(sigma2) * rng.standard_normal(count) - 0.5 * sigma2)
|
|
680
|
+
return 1.0 + cv * rng.choice((-1.0, 1.0), size=count)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def _scaled(frame, scale, mode: str) -> dict:
|
|
684
|
+
"""The stiffnesses of the beams that a factor ``scale`` (one per beam) of ``mode``
|
|
685
|
+
changes, scaled."""
|
|
686
|
+
if mode not in MODES:
|
|
687
|
+
raise ValueError(f"mode: one of {MODES}")
|
|
688
|
+
s = np.broadcast_to(np.asarray(scale, dtype=float), (len(frame.beams),))
|
|
689
|
+
shear = getattr(frame, "shear", None)
|
|
690
|
+
if mode == "bending":
|
|
691
|
+
return {"bending": frame.bending * s}
|
|
692
|
+
changes = {"axial": frame.axial * s}
|
|
693
|
+
if mode == "axial":
|
|
694
|
+
return changes
|
|
695
|
+
if shear is not None:
|
|
696
|
+
changes["shear"] = shear * s
|
|
697
|
+
if mode == "modulus":
|
|
698
|
+
changes["bending"] = frame.bending * s
|
|
699
|
+
if isinstance(frame, SpaceFrame):
|
|
700
|
+
changes["torsion"] = frame.torsion * s
|
|
701
|
+
return changes
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def scaled_frame(frame, scale, mode: str = "modulus"):
|
|
705
|
+
"""The frame with the stiffness of a mode of its beams multiplied by ``scale`` (one
|
|
706
|
+
factor per beam): ``axial`` (EA), ``bending`` (EI), ``area`` (the area of a general
|
|
707
|
+
section: EA and the shear stiffness κGA of Timoshenko beams, EI and GJ kept) or
|
|
708
|
+
``modulus`` (all of them: the Young's modulus of each beam)."""
|
|
709
|
+
return dataclasses.replace(frame, **_scaled(frame, scale, mode))
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def softening_coefficients(frame, mode: str = "modulus", axis: int = 0) -> dict:
|
|
713
|
+
"""The Young's modulus ``E_0`` of a frame along ``axis`` and the coefficients of its
|
|
714
|
+
softening and scatter when the stiffness of a mode of its beams varies independently
|
|
715
|
+
from beam to beam, with mean the present one and coefficient of variation ``CV``:
|
|
716
|
+
``(E_0 - ⟨E⟩) / E_0 = s CV²`` and ``σ_E² / E_0² = v CV²`` to second order (Ban et al.
|
|
717
|
+
2016, eqs. 22 and 25, computed exactly: the module docstring), with the derivatives
|
|
718
|
+
``dE`` and ``d2E`` per beam of ``E`` relative to its factor. The modes are those of
|
|
719
|
+
:func:`scaled_frame`; the stiffness of a Timoshenko beam is not linear in its ``EI``
|
|
720
|
+
or ``κGA`` (``bending``, ``area``), whose second derivative adds ``U · K_i'' U / V``."""
|
|
721
|
+
if mode not in MODES:
|
|
722
|
+
raise ValueError(f"mode: one of {MODES}")
|
|
723
|
+
problem = _Periodic(frame)
|
|
724
|
+
modes = problem.of_frame()
|
|
725
|
+
ke = sum(modes.values())
|
|
726
|
+
u, _, lu = problem.solve(ke)
|
|
727
|
+
c = problem.energy(u, ke)
|
|
728
|
+
s = np.linalg.inv(c)
|
|
729
|
+
e0 = 1.0 / s[axis, axis]
|
|
730
|
+
strain = s[:, axis] / s[axis, axis] # uniaxial stress, unit strain along the axis
|
|
731
|
+
uu = u @ strain # element displacements of the uniaxial stress (m x n)
|
|
732
|
+
km, curvature = problem.derivatives(modes, mode)
|
|
733
|
+
force = np.einsum("mab,mb->ma", km, uu) # the force of a unit factor on each beam
|
|
734
|
+
first = np.einsum("ma,ma->m", uu, force) / problem.volume
|
|
735
|
+
others = [j for j in range(len(c)) if j != axis]
|
|
736
|
+
g = np.einsum("maj,ma->mj", u[:, :, others], force)
|
|
737
|
+
relaxed = np.einsum("mj,jk,mk->m", g, np.linalg.inv(problem.volume * c[np.ix_(others, others)]),
|
|
738
|
+
g) # fmt: skip
|
|
739
|
+
fluct = np.empty(len(force))
|
|
740
|
+
for start in range(0, len(force), BATCH):
|
|
741
|
+
part = slice(start, start + BATCH)
|
|
742
|
+
k = len(force[part])
|
|
743
|
+
local = np.zeros((k, force.shape[1], k))
|
|
744
|
+
local[np.arange(k), :, np.arange(k)] = force[part]
|
|
745
|
+
rhs = np.zeros((problem.n_dofs, k))
|
|
746
|
+
np.add.at(rhs, problem.dofs[part], local)
|
|
747
|
+
rhs = rhs[problem.free]
|
|
748
|
+
fluct[part] = np.einsum("ij,ij->j", rhs, lu.solve(rhs))
|
|
749
|
+
second = -2.0 / problem.volume * (fluct + relaxed)
|
|
750
|
+
if curvature is not None: # the element stiffness itself concave in the factor
|
|
751
|
+
second = second + np.einsum("ma,mab,mb->m", uu, curvature, uu) / problem.volume
|
|
752
|
+
return {
|
|
753
|
+
"young": float(e0),
|
|
754
|
+
"mean": float(-second.sum() / (2.0 * e0)),
|
|
755
|
+
"variance": float(np.sum(first**2) / e0**2),
|
|
756
|
+
"dE": first,
|
|
757
|
+
"d2E": second,
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
@dataclass
|
|
762
|
+
class Softening:
|
|
763
|
+
"""Replicas of the stiffness of the beams of a frame (:func:`softening`): the
|
|
764
|
+
coefficients of variation ``cv`` and, for each, the mean and standard deviation of the
|
|
765
|
+
Young's modulus over the replicas relative to that of the identical beams ``young``,
|
|
766
|
+
the mean corrected by its first-order part (a control variate of zero mean, which
|
|
767
|
+
removes most of the scatter of the replicas) and its standard error, the
|
|
768
|
+
coefficients ``s`` and ``v`` of :func:`softening_coefficients`, and the study: the
|
|
769
|
+
``mode`` varied, the ``law`` of its factors, the number of ``replicas`` per CV and the
|
|
770
|
+
``axis`` of the uniaxial stress."""
|
|
771
|
+
|
|
772
|
+
young: float
|
|
773
|
+
cv: np.ndarray
|
|
774
|
+
mean: np.ndarray
|
|
775
|
+
std: np.ndarray
|
|
776
|
+
corrected: np.ndarray
|
|
777
|
+
error: np.ndarray
|
|
778
|
+
coefficients: dict
|
|
779
|
+
mode: str = "modulus"
|
|
780
|
+
law: str = "normal"
|
|
781
|
+
replicas: int = 0
|
|
782
|
+
axis: int = 0
|
|
783
|
+
|
|
784
|
+
def softening(self) -> np.ndarray:
|
|
785
|
+
"""``(E_0 - ⟨E⟩) / E_0`` of the corrected means."""
|
|
786
|
+
return 1.0 - self.corrected
|
|
787
|
+
|
|
788
|
+
def predicted(self) -> np.ndarray:
|
|
789
|
+
"""``s CV²``, the second-order softening."""
|
|
790
|
+
return self.coefficients["mean"] * self.cv**2
|
|
791
|
+
|
|
792
|
+
def scatter(self) -> np.ndarray:
|
|
793
|
+
"""``σ_E² / E_0²`` of the replicas."""
|
|
794
|
+
return self.std**2
|
|
795
|
+
|
|
796
|
+
def predicted_scatter(self) -> np.ndarray:
|
|
797
|
+
"""``v CV²``, the second-order scatter."""
|
|
798
|
+
return self.coefficients["variance"] * self.cv**2
|
|
799
|
+
|
|
800
|
+
def rows(self) -> list[dict]:
|
|
801
|
+
"""A row per coefficient of variation: the study (``mode``, ``law``, ``cv``,
|
|
802
|
+
``replicas``), the plain ``mean`` of ``E / E_0`` over the replicas and its standard
|
|
803
|
+
error ``σ / √n`` (``mean_error``), the ``corrected`` mean and its standard error,
|
|
804
|
+
the second-order mean ``1 - s CV²`` (``theory``), the standard deviation ``std``
|
|
805
|
+
of ``E / E_0``, the ``scatter`` ``σ_E² / E_0²`` with its standard error for normal
|
|
806
|
+
draws, ``σ² √(2 / (n - 1))``, and ``v CV²`` (``theory_scatter``)."""
|
|
807
|
+
n = max(int(self.replicas), 2)
|
|
808
|
+
rows = zip(self.cv, self.mean, self.std, self.corrected, self.error,
|
|
809
|
+
1.0 - self.predicted(), self.predicted_scatter(), strict=True) # fmt: skip
|
|
810
|
+
return [
|
|
811
|
+
{
|
|
812
|
+
"mode": self.mode,
|
|
813
|
+
"law": self.law,
|
|
814
|
+
"cv": float(cv),
|
|
815
|
+
"replicas": int(self.replicas),
|
|
816
|
+
"mean": float(mean),
|
|
817
|
+
"mean_error": float(std / np.sqrt(n)),
|
|
818
|
+
"corrected": float(corrected),
|
|
819
|
+
"corrected_error": float(error),
|
|
820
|
+
"theory": float(theory),
|
|
821
|
+
"std": float(std),
|
|
822
|
+
"scatter": float(std**2),
|
|
823
|
+
"scatter_error": float(std**2 * np.sqrt(2.0 / (n - 1))),
|
|
824
|
+
"theory_scatter": float(scatter),
|
|
825
|
+
}
|
|
826
|
+
for cv, mean, std, corrected, error, theory, scatter in rows
|
|
827
|
+
]
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
def softening(
|
|
831
|
+
frame,
|
|
832
|
+
mode: str = "modulus",
|
|
833
|
+
cvs=(0.1, 0.2, 0.3),
|
|
834
|
+
*,
|
|
835
|
+
replicas: int = 100,
|
|
836
|
+
law: str = "normal",
|
|
837
|
+
axis: int = 0,
|
|
838
|
+
seed: SeedLike = None,
|
|
839
|
+
callback=None,
|
|
840
|
+
) -> Softening:
|
|
841
|
+
"""The softening of a network of non-identical beams (Ban et al. 2016): ``replicas``
|
|
842
|
+
draws of the stiffness of a mode of the beams (:func:`fibre_scales` of each ``cv``
|
|
843
|
+
and ``law``; :func:`scaled_frame`) on the same geometry, the Young's modulus along
|
|
844
|
+
``axis`` of each, against the second-order theory. ``callback(done, total)`` follows
|
|
845
|
+
the replicas (one solve each)."""
|
|
846
|
+
if replicas < 2:
|
|
847
|
+
raise ValueError("replicas: at least 2")
|
|
848
|
+
if law not in LAWS:
|
|
849
|
+
raise ValueError(f"law: one of {LAWS}")
|
|
850
|
+
cvs = np.atleast_1d(np.asarray(cvs, dtype=float))
|
|
851
|
+
if cvs.size == 0:
|
|
852
|
+
raise ValueError("cvs: at least one coefficient of variation")
|
|
853
|
+
if np.any(cvs < 0) or (law == "bimodal" and np.any(cvs >= 1.0)):
|
|
854
|
+
raise ValueError("cv: non-negative (below 1 for the bimodal law)")
|
|
855
|
+
coefficients = softening_coefficients(frame, mode, axis)
|
|
856
|
+
e0, slope = coefficients["young"], coefficients["dE"]
|
|
857
|
+
rng, _ = make_rng(seed)
|
|
858
|
+
problem = _Periodic(frame)
|
|
859
|
+
base = problem.values()
|
|
860
|
+
rows = []
|
|
861
|
+
total, done = cvs.size * int(replicas), 0
|
|
862
|
+
for cv in cvs:
|
|
863
|
+
values, linear = [], []
|
|
864
|
+
for _ in range(int(replicas)):
|
|
865
|
+
scale = fibre_scales(len(frame.beams), float(cv), law, rng)
|
|
866
|
+
ke = sum(problem.stiffness(**{**base, **_scaled(frame, scale, mode)}).values())
|
|
867
|
+
u, _, _ = problem.solve(ke)
|
|
868
|
+
s = np.linalg.inv(problem.energy(u, ke))
|
|
869
|
+
values.append(1.0 / s[axis, axis])
|
|
870
|
+
linear.append(float(slope @ (scale - 1.0)))
|
|
871
|
+
done += 1
|
|
872
|
+
if callback is not None:
|
|
873
|
+
callback(done, total)
|
|
874
|
+
values, linear = np.array(values) / e0, np.array(linear) / e0
|
|
875
|
+
corrected = values - linear
|
|
876
|
+
rows.append((cv, values.mean(), values.std(ddof=1), corrected.mean(),
|
|
877
|
+
corrected.std(ddof=1) / np.sqrt(len(values)))) # fmt: skip
|
|
878
|
+
cv, mean, std, corrected, error = (np.array(col) for col in zip(*rows, strict=True))
|
|
879
|
+
return Softening(e0, cv, mean, std, corrected, error, coefficients, mode, law,
|
|
880
|
+
int(replicas), int(axis)) # fmt: skip
|