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,1085 @@
|
|
|
1
|
+
"""Post-bifurcated patterns of periodic architectured materials by group theory, after
|
|
2
|
+
Azulay & Combescure (2024) and the thesis of R. Azulay (2023), for frames of beams in the plane
|
|
3
|
+
and in space (lattices of struts) and for continua (tetrahedral meshes and voxel images).
|
|
4
|
+
|
|
5
|
+
The symmetry group ``G`` of a cell of several primitive cells (its point group and its
|
|
6
|
+
inner translations, :mod:`morphogen.symmetry`), restricted to the symmetry of the
|
|
7
|
+
macroscopic loading (``R E R^T = E``), acts on the periodic fluctuations by
|
|
8
|
+
``T(g)``: the nodes permuted, their displacements turned by ``R`` (and the rotations of
|
|
9
|
+
beams by ``det R``). Its real irreducible representations split the fluctuations into
|
|
10
|
+
isotypic subspaces ``V_μ`` (projectors ``P_μ``), in which the stiffness matrices are
|
|
11
|
+
block-diagonal. For each irrep, the isotropy subgroups ``H`` with one-dimensional
|
|
12
|
+
fixed-point subspaces (the equivariant branching lemma) are the symmetry groups of the
|
|
13
|
+
bifurcated branches; the pattern of ``H`` is the displacement of ``Fix(H) ∩ V_μ`` (the
|
|
14
|
+
projector ``P_H = (1/|H|) Σ_h T(h)`` times ``P_μ``) that minimizes the elastic energy
|
|
15
|
+
``u^T K_e u`` at unit norm: the eigenvector of the smallest eigenvalue of the reduced
|
|
16
|
+
elastic stiffness. The order of the bifurcation points along the principal path comes
|
|
17
|
+
from the linear buckling ``(K_e + λ K_g) φ = 0`` of the loading, solved in each isotypic
|
|
18
|
+
subspace (its lowest ``λ`` and multiplicity); the critical modes of a small cell are
|
|
19
|
+
also identified by their projections on the isotypic subspaces. Translations are left
|
|
20
|
+
out of every subspace.
|
|
21
|
+
|
|
22
|
+
The isotypic subspaces are found without dense projectors: their dimension is the trace
|
|
23
|
+
``Σ_g w(g) tr T(g)`` and their basis the range of ``P_μ`` applied to random vectors, so
|
|
24
|
+
that meshes of thousands of nodes stay tractable. In a continuum, the geometric stiffness
|
|
25
|
+
is the initial-stress matrix ``δ_ij ∫ ∇N_a · σ⁰ ∇N_b dV`` of the stress of the periodic
|
|
26
|
+
linear solution under the macroscopic strain, and the group of a mesh is detected: the
|
|
27
|
+
operations of the cube about the centre of the box combined with translations by
|
|
28
|
+
multiples of half a primitive cell that map the elements onto elements of the same
|
|
29
|
+
phase. A mesh must have them exactly: a conforming mesh of the level set of a symmetric
|
|
30
|
+
cell, meshed in its irreducible part and mirrored (:func:`morphogen.mesh.mirrored_mesh`,
|
|
31
|
+
whose holes and inclusions are smooth), or a voxel image, cut into six tetrahedra per
|
|
32
|
+
voxel by the Kuhn triangulation of its grid, invariant under the operations of the cube
|
|
33
|
+
and under translations by even numbers of voxels (but whose staircase interfaces bias
|
|
34
|
+
thin ligaments); an unstructured mesh of the whole box has no symmetry.
|
|
35
|
+
|
|
36
|
+
A cell of two primitive cells along some axes is first split by its translations
|
|
37
|
+
(``bloch``, by default beyond ``DENSE_LIMIT`` dofs): their characters ``±1`` are those of
|
|
38
|
+
the wave vectors ``k`` of components 0 or ``π/a`` (Γ, X, M and R of a cubic cell of edge
|
|
39
|
+
``a``), and the fluctuations of ``k``, periodic or antiperiodic on the primitive cell along
|
|
40
|
+
each axis, have the sparse orthonormal basis of the orbit sums
|
|
41
|
+
``Σ_t χ_k(t) e_{t(i)} / sqrt|T|`` over the nodes ``i`` of a primitive cell. The stiffness
|
|
42
|
+
matrices are block-diagonal in these subspaces, which the point operations fixing ``k``
|
|
43
|
+
(its little co-group ``P_k``, found by conjugating the translations in the group table)
|
|
44
|
+
split further. By Clifford's theory, each irrep of the cell's group is induced by a star
|
|
45
|
+
of wave vectors and an irrep ``σ`` of ``P_k`` (identified by Frobenius reciprocity on the
|
|
46
|
+
characters): its dimension is that of ``σ`` times the arms of the star, its multiplicity
|
|
47
|
+
that of ``σ`` among the fluctuations of ``k`` and its spectrum that of the block of ``σ``
|
|
48
|
+
there, repeated on each arm. No basis of the whole cell is formed: the blocks have the
|
|
49
|
+
size of the fluctuations of a primitive cell divided among the irreps of ``P_k``. The
|
|
50
|
+
patterns of an irrep are found in the coordinates of the blocks of the arms of its star,
|
|
51
|
+
where the group acts by the matrices of the induced representation (``P_k`` on the block
|
|
52
|
+
and the characters of ``k``), and lifted to the cell; by default those of the irreps of
|
|
53
|
+
the first bifurcation only. :func:`wave_vectors` tells which wave vectors an irrep
|
|
54
|
+
carries: its patterns double the period along the axes where ``k_i = π/a``.
|
|
55
|
+
|
|
56
|
+
Along a nonlinear loading path (:func:`path_bifurcation`), in finite strains and with
|
|
57
|
+
nonlinear behaviours, the linear buckling gives way to the stability of the principal
|
|
58
|
+
path itself: the periodic element of
|
|
59
|
+
:class:`~morphogen.homogenization.nonlinear.NonlinearFEProblem` follows the path, and at
|
|
60
|
+
each converged step its consistent tangent (``∫ ∇N · ∂P/∂F · ∇N dV`` in finite strains,
|
|
61
|
+
the initial stress of the current state included; for plasticity the tangent of the
|
|
62
|
+
loading branch, Hill's comparison solid as the steps shrink), reduced to the master nodes
|
|
63
|
+
with the macroscopic components of prescribed stress condensed (``K_ww - K_wE K_EE^-1
|
|
64
|
+
K_Ew``), is projected on the isotypic subspaces of the group restricted to the path (its
|
|
65
|
+
prescribed strains and stresses, and which components are which). On the symmetric
|
|
66
|
+
principal path the tangent commutes with the group, each block loses its positive
|
|
67
|
+
definiteness on its own, and the first block whose lowest eigenvalue changes sign marks
|
|
68
|
+
the first bifurcation (at the root of the parabola through its last three values; its
|
|
69
|
+
multiplicity: the eigenvalues that cross in the step); the patterns are the softest modes
|
|
70
|
+
of ``Fix(H) ∩ V_μ`` there. The mechanisms of the natural state are left out from the
|
|
71
|
+
start. A switch of branch perturbs the nodes along the critical pattern (those of the
|
|
72
|
+
faces of the box along these faces only: an equivariant change, which keeps the cell
|
|
73
|
+
periodic and the imperfection in the subspace of the pattern) and follows the path again.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
from __future__ import annotations
|
|
77
|
+
|
|
78
|
+
from dataclasses import dataclass, field
|
|
79
|
+
from itertools import permutations, product
|
|
80
|
+
|
|
81
|
+
import numpy as np
|
|
82
|
+
import scipy.sparse as sp
|
|
83
|
+
from numba import njit
|
|
84
|
+
from scipy.linalg import eigh
|
|
85
|
+
|
|
86
|
+
from morphogen.homogenization.fe import (
|
|
87
|
+
GAUSS,
|
|
88
|
+
_corner_gradients,
|
|
89
|
+
_product,
|
|
90
|
+
_strain,
|
|
91
|
+
periodic_map,
|
|
92
|
+
)
|
|
93
|
+
from morphogen.homogenization.frames import Frame, SpaceFrame, _buckling, positive_subspace
|
|
94
|
+
from morphogen.image import VoxelImage
|
|
95
|
+
from morphogen.mesh.tetra import TetMesh
|
|
96
|
+
from morphogen.symmetry import Group, Irrep, axial_subgroups, representation
|
|
97
|
+
|
|
98
|
+
#: Cells larger than this (dofs) skip the dense solve of the whole cell's buckling.
|
|
99
|
+
DENSE_LIMIT = 1500
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass
|
|
103
|
+
class Pattern:
|
|
104
|
+
"""A post-bifurcated pattern: its irrep (index into :attr:`Bifurcation.irreps`), the
|
|
105
|
+
class of conjugate isotropy subgroups (the first one fixes ``mode``) and its
|
|
106
|
+
description, the dimension of ``Fix(H) ∩ V_μ``, the unit displacement (dofs of the
|
|
107
|
+
cell: nodes of a frame, master nodes of a mesh) that minimizes the elastic energy
|
|
108
|
+
there and that energy, and the lowest critical load factor and buckling mode of the
|
|
109
|
+
loading in that subspace (NaN and None without loading)."""
|
|
110
|
+
|
|
111
|
+
irrep: int
|
|
112
|
+
subgroups: list
|
|
113
|
+
description: dict
|
|
114
|
+
dimension: int
|
|
115
|
+
mode: np.ndarray
|
|
116
|
+
energy: float
|
|
117
|
+
load: float
|
|
118
|
+
buckling_mode: np.ndarray | None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass
|
|
122
|
+
class Bifurcation:
|
|
123
|
+
"""The group-theoretic analysis of a cell: its symmetry group (restricted to the
|
|
124
|
+
loading), irreps, the multiplicity of each among the fluctuations, the patterns, the
|
|
125
|
+
lowest critical load factor of each irrep (NaN without loading), the first critical
|
|
126
|
+
load, its irrep and multiplicity, and the norms of the projections of the first
|
|
127
|
+
critical modes of the whole cell (unit norm) on the isotypic subspaces (rows: irreps;
|
|
128
|
+
small cells only): 1 in the irrep of the bifurcation, 0 elsewhere (several irreps when
|
|
129
|
+
their loads coincide, the multiplicity then counting all their modes). For a
|
|
130
|
+
continuum, ``mesh`` is the analysed mesh and ``lift`` maps the dofs of its master
|
|
131
|
+
nodes to all its nodes."""
|
|
132
|
+
|
|
133
|
+
group: Group
|
|
134
|
+
irreps: list[Irrep]
|
|
135
|
+
multiplicities: np.ndarray
|
|
136
|
+
patterns: list[Pattern]
|
|
137
|
+
loads: np.ndarray
|
|
138
|
+
first: tuple | None
|
|
139
|
+
projections: np.ndarray | None
|
|
140
|
+
mesh: TetMesh | None = None
|
|
141
|
+
lift: sp.spmatrix | None = field(default=None, repr=False)
|
|
142
|
+
|
|
143
|
+
def displacement(self, mode) -> np.ndarray:
|
|
144
|
+
"""The displacement of every node of the mesh (n x 3) of a mode of the cell."""
|
|
145
|
+
if self.lift is None:
|
|
146
|
+
raise ValueError("displacement: for the patterns of a continuum")
|
|
147
|
+
return np.asarray(self.lift @ np.asarray(mode, dtype=float)).reshape(-1, 3)
|
|
148
|
+
|
|
149
|
+
def write(self, path, irreps=None):
|
|
150
|
+
"""A VTK unstructured grid of the mesh with the pattern of each axial class (of all
|
|
151
|
+
the irreps, or of the indices ``irreps``) as point data ``pattern_<irrep>_<k>``."""
|
|
152
|
+
from morphogen.io.meshes import write_vtu_tet
|
|
153
|
+
|
|
154
|
+
data, counts = {}, {}
|
|
155
|
+
for p in self.patterns:
|
|
156
|
+
if irreps is not None and p.irrep not in irreps:
|
|
157
|
+
continue
|
|
158
|
+
counts[p.irrep] = counts.get(p.irrep, 0) + 1
|
|
159
|
+
data[f"pattern_{p.irrep + 1}_{counts[p.irrep]}"] = self.displacement(p.mode)
|
|
160
|
+
return write_vtu_tet(path, self.mesh, point_data=data)
|
|
161
|
+
|
|
162
|
+
def figure(self, frame, *, tiles=None, scale: float = 1.0, irreps=None):
|
|
163
|
+
"""The patterns of a frame drawn on ``tiles`` copies of the cell (3 x 3 in the
|
|
164
|
+
plane, 1 x 1 x 1 in space), one row per irrep (all, or the indices ``irreps``), as
|
|
165
|
+
the tables of Azulay & Combescure; returns the figure (``fig.savefig``)."""
|
|
166
|
+
from morphogen.viz.figures import _figure
|
|
167
|
+
|
|
168
|
+
space = isinstance(frame, SpaceFrame)
|
|
169
|
+
tiles = tiles or ((1, 1, 1) if space else (3, 3))
|
|
170
|
+
rows = [i for i in range(len(self.irreps)) if irreps is None or i in irreps]
|
|
171
|
+
rows = [i for i in rows if any(p.irrep == i for p in self.patterns)]
|
|
172
|
+
cols = max((sum(p.irrep == i for p in self.patterns) for i in rows), default=1)
|
|
173
|
+
fig = _figure(2.4 * cols, 2.4 * max(len(rows), 1))
|
|
174
|
+
n_rows = max(len(rows), 1)
|
|
175
|
+
axes = np.empty((n_rows, cols), dtype=object)
|
|
176
|
+
for k in range(n_rows * cols):
|
|
177
|
+
options = {"projection": "3d"} if space else {}
|
|
178
|
+
axes[k // cols, k % cols] = fig.add_subplot(n_rows, cols, k + 1, **options)
|
|
179
|
+
for ax in axes.ravel():
|
|
180
|
+
ax.set_axis_off()
|
|
181
|
+
for r, i in enumerate(rows):
|
|
182
|
+
for c, p in enumerate([p for p in self.patterns if p.irrep == i]):
|
|
183
|
+
ax = axes[r, c]
|
|
184
|
+
frame.plot(ax, p.mode, scale=scale, tiles=tiles, lw=0.6)
|
|
185
|
+
d = p.description
|
|
186
|
+
ax.set_title(
|
|
187
|
+
f"{i + 1}: {d['point_group']}, |H| = {d['order']} ({len(p.subgroups)})",
|
|
188
|
+
fontsize=7,
|
|
189
|
+
)
|
|
190
|
+
return fig
|
|
191
|
+
|
|
192
|
+
def wave_vectors(self, irrep: int) -> list[tuple] | None:
|
|
193
|
+
"""The wave vectors of an irrep (index), :func:`wave_vectors`: ``(0, 0, 0)`` when
|
|
194
|
+
its patterns repeat in every primitive cell."""
|
|
195
|
+
return wave_vectors(self.group, self.irreps[irrep])
|
|
196
|
+
|
|
197
|
+
def summary(self) -> list[dict]:
|
|
198
|
+
"""One row per irrep: dimension, multiplicity, critical load, wave vectors, and its
|
|
199
|
+
patterns (point group, order, translations, number of conjugates, energy, load)."""
|
|
200
|
+
rows = []
|
|
201
|
+
for i, irrep in enumerate(self.irreps):
|
|
202
|
+
rows.append(
|
|
203
|
+
{
|
|
204
|
+
"irrep": i + 1,
|
|
205
|
+
"dim": irrep.dim,
|
|
206
|
+
"multiplicity": int(self.multiplicities[i]),
|
|
207
|
+
"load": float(self.loads[i]),
|
|
208
|
+
"wave_vectors": self.wave_vectors(i),
|
|
209
|
+
"patterns": [
|
|
210
|
+
{
|
|
211
|
+
**p.description,
|
|
212
|
+
"conjugates": len(p.subgroups),
|
|
213
|
+
"energy": p.energy,
|
|
214
|
+
"load": p.load,
|
|
215
|
+
}
|
|
216
|
+
for p in self.patterns
|
|
217
|
+
if p.irrep == i
|
|
218
|
+
],
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
return rows
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def frame_representation(frame, group: Group) -> list:
|
|
225
|
+
"""The matrices ``T(g)`` (sparse) of a group on the dofs of a frame: ``(u, v, θ)`` in
|
|
226
|
+
the plane, ``(u, v, w, θx, θy, θz)`` in space."""
|
|
227
|
+
perm = group.action(frame.nodes)
|
|
228
|
+
return representation(group, perm, [frame.block(r) for r in group.rotations])
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@njit(cache=True)
|
|
232
|
+
def _initial_stress(nodes, elements, order, mat, matrices, u, gp, gw):
|
|
233
|
+
"""``∫ ∇N_a · σ ∇N_b dV`` of each element (n_el x nn x nn) for the stress ``σ = D ε(u)``
|
|
234
|
+
at the Gauss points."""
|
|
235
|
+
n_el, nn = elements.shape
|
|
236
|
+
out = np.zeros((n_el, nn, nn))
|
|
237
|
+
x = np.empty((4, 3))
|
|
238
|
+
gl = np.empty((4, 3))
|
|
239
|
+
grad = np.empty((nn, 3))
|
|
240
|
+
eps = np.empty(6)
|
|
241
|
+
sig = np.empty(6)
|
|
242
|
+
s = np.empty((3, 3))
|
|
243
|
+
for e in range(n_el):
|
|
244
|
+
for a in range(4):
|
|
245
|
+
for d in range(3):
|
|
246
|
+
x[a, d] = nodes[elements[e, a], d]
|
|
247
|
+
vol = abs(_corner_gradients(x, gl))
|
|
248
|
+
dm = matrices[mat[e]]
|
|
249
|
+
for g in range(gp.shape[0]):
|
|
250
|
+
_strain(order, gl, gp[g], elements, e, u, grad, eps)
|
|
251
|
+
_product(dm, eps, sig)
|
|
252
|
+
s[0, 0], s[1, 1], s[2, 2] = sig[0], sig[1], sig[2]
|
|
253
|
+
s[1, 2] = s[2, 1] = sig[3]
|
|
254
|
+
s[2, 0] = s[0, 2] = sig[4]
|
|
255
|
+
s[0, 1] = s[1, 0] = sig[5]
|
|
256
|
+
w = gw[g] * vol
|
|
257
|
+
for a in range(nn):
|
|
258
|
+
for b in range(nn):
|
|
259
|
+
acc = 0.0
|
|
260
|
+
for i in range(3):
|
|
261
|
+
for j in range(3):
|
|
262
|
+
acc += grad[a, i] * s[i, j] * grad[b, j]
|
|
263
|
+
out[e, a, b] += w * acc
|
|
264
|
+
return out
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def initial_stress_matrix(problem, u) -> sp.csr_matrix:
|
|
268
|
+
"""The geometric (initial-stress) stiffness ``δ_ij ∫ ∇N_a · σ ∇N_b dV`` (all dofs) of
|
|
269
|
+
the mesh of an elastic finite element problem for the displacement ``u`` (all dofs)."""
|
|
270
|
+
m = problem.mesh
|
|
271
|
+
gp, gw = GAUSS[m.order]
|
|
272
|
+
blocks = _initial_stress(
|
|
273
|
+
m.nodes,
|
|
274
|
+
m.elements,
|
|
275
|
+
m.order,
|
|
276
|
+
np.ascontiguousarray(problem.mat, dtype=np.int64),
|
|
277
|
+
np.ascontiguousarray(problem.table.matrices, dtype=float),
|
|
278
|
+
np.ascontiguousarray(u, dtype=float),
|
|
279
|
+
gp,
|
|
280
|
+
gw,
|
|
281
|
+
)
|
|
282
|
+
e = m.elements
|
|
283
|
+
nn = e.shape[1]
|
|
284
|
+
rows = np.repeat(e, nn, axis=1).ravel()
|
|
285
|
+
cols = np.tile(e, (1, nn)).ravel()
|
|
286
|
+
scalar = sp.csr_matrix((blocks.ravel(), (rows, cols)), shape=(m.n_nodes, m.n_nodes))
|
|
287
|
+
return sp.kron(scalar, sp.identity(3), format="csr")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _box_operations(size) -> list[np.ndarray]:
|
|
291
|
+
"""The signed permutations of the axes that map a box of edges ``size`` onto itself."""
|
|
292
|
+
size = np.asarray(size, dtype=float)
|
|
293
|
+
out = []
|
|
294
|
+
for perm in permutations(range(3)):
|
|
295
|
+
if not np.allclose(size[list(perm)], size, rtol=1e-9):
|
|
296
|
+
continue
|
|
297
|
+
for signs in product((1.0, -1.0), repeat=3):
|
|
298
|
+
r = np.zeros((3, 3))
|
|
299
|
+
r[np.arange(3), perm] = signs
|
|
300
|
+
out.append(r)
|
|
301
|
+
return out
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def mesh_symmetries(mesh: TetMesh, cells=(1, 1, 1), tol: float = 1e-6) -> Group:
|
|
305
|
+
"""The symmetry group of a periodic mesh made of ``cells`` primitive cells: the
|
|
306
|
+
operations of the cube about the centre of its box (those that map the box onto
|
|
307
|
+
itself) combined with translations by multiples of half a primitive cell, kept when
|
|
308
|
+
they map the elements onto elements of the same phase."""
|
|
309
|
+
from scipy.spatial import cKDTree
|
|
310
|
+
|
|
311
|
+
size, lower = np.asarray(mesh.size, float), np.asarray(mesh.lower, float)
|
|
312
|
+
centre = lower + 0.5 * size
|
|
313
|
+
centroids = mesh.nodes[mesh.elements[:, :4]].mean(axis=1)
|
|
314
|
+
|
|
315
|
+
def unit(y):
|
|
316
|
+
f = (y - lower) / size
|
|
317
|
+
f = f - np.floor(f)
|
|
318
|
+
return np.where(f >= 1.0, 0.0, f)
|
|
319
|
+
|
|
320
|
+
tree = cKDTree(unit(centroids), boxsize=1.0)
|
|
321
|
+
rng = np.random.default_rng(0)
|
|
322
|
+
probe = rng.choice(len(centroids), size=min(64, len(centroids)), replace=False)
|
|
323
|
+
steps = [np.arange(2 * int(n)) * s / (2 * int(n)) for n, s in zip(cells, size, strict=True)]
|
|
324
|
+
accepted = []
|
|
325
|
+
for r in _box_operations(size):
|
|
326
|
+
for t in product(*steps):
|
|
327
|
+
t = np.asarray(t)
|
|
328
|
+
ok = True
|
|
329
|
+
for idx in (probe, slice(None)):
|
|
330
|
+
y = (centroids[idx] - centre) @ r.T + centre + t
|
|
331
|
+
dist, near = tree.query(unit(y))
|
|
332
|
+
if np.any(dist > tol / float(size.min())) or np.any(
|
|
333
|
+
mesh.phase[near] != mesh.phase[idx]
|
|
334
|
+
):
|
|
335
|
+
ok = False
|
|
336
|
+
break
|
|
337
|
+
if ok:
|
|
338
|
+
accepted.append((r, t))
|
|
339
|
+
return Group.generate(accepted, np.diag(size), centre)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
@dataclass
|
|
343
|
+
class _Cell:
|
|
344
|
+
"""The fluctuations of a cell: master node positions, the action of a rotation on the
|
|
345
|
+
dofs of a node, the elastic and geometric stiffness (sparse) of the dofs, the
|
|
346
|
+
translations (orthonormal columns) and the map to all the nodes of a mesh."""
|
|
347
|
+
|
|
348
|
+
positions: np.ndarray
|
|
349
|
+
lattice: np.ndarray
|
|
350
|
+
centre: np.ndarray
|
|
351
|
+
block: object
|
|
352
|
+
ke: sp.spmatrix
|
|
353
|
+
kg: sp.spmatrix | None
|
|
354
|
+
translations: np.ndarray
|
|
355
|
+
mesh: TetMesh | None = None
|
|
356
|
+
lift: sp.spmatrix | None = None
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _frame_cell(frame, strain) -> _Cell:
|
|
360
|
+
kg = None
|
|
361
|
+
if strain is not None:
|
|
362
|
+
forces, _ = frame.axial_forces(strain)
|
|
363
|
+
kg = sp.csr_matrix(frame._assemble(forces)[1])
|
|
364
|
+
return _Cell(
|
|
365
|
+
frame.nodes,
|
|
366
|
+
frame.lattice,
|
|
367
|
+
frame.centre,
|
|
368
|
+
frame.block,
|
|
369
|
+
sp.csr_matrix(frame.stiffness()),
|
|
370
|
+
kg,
|
|
371
|
+
frame.translations(),
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def _continuum_cell(mesh: TetMesh, materials, strain) -> _Cell:
|
|
376
|
+
from morphogen.homogenization.elements import VOIGT
|
|
377
|
+
from morphogen.homogenization.fe import FEElasticProblem
|
|
378
|
+
|
|
379
|
+
problem = FEElasticProblem(mesh, materials, bc="periodic")
|
|
380
|
+
if problem.empty:
|
|
381
|
+
raise ValueError("post_bifurcation: no load-carrying material in the cell")
|
|
382
|
+
m = problem.mesh
|
|
383
|
+
t, masters, _ = periodic_map(m)
|
|
384
|
+
t3 = sp.kron(t, sp.identity(3), format="csr")
|
|
385
|
+
ke = (t3.T @ problem._stiffness() @ t3).tocsr()
|
|
386
|
+
kg = None
|
|
387
|
+
if strain is not None:
|
|
388
|
+
e = np.asarray(strain, dtype=float)
|
|
389
|
+
x = np.array([e[a, b] * (1.0 if a == b else 2.0) for a, b in VOIGT])
|
|
390
|
+
u, _ = problem._field(x, 0.0)
|
|
391
|
+
kg = (t3.T @ initial_stress_matrix(problem, u) @ t3).tocsr()
|
|
392
|
+
n = len(masters)
|
|
393
|
+
translations = np.zeros((3 * n, 3))
|
|
394
|
+
for c in range(3):
|
|
395
|
+
translations[c::3, c] = 1.0 / np.sqrt(n)
|
|
396
|
+
return _Cell(
|
|
397
|
+
m.nodes[masters],
|
|
398
|
+
np.diag(m.size),
|
|
399
|
+
m.lower + 0.5 * m.size,
|
|
400
|
+
lambda r: r,
|
|
401
|
+
ke,
|
|
402
|
+
kg,
|
|
403
|
+
translations,
|
|
404
|
+
m,
|
|
405
|
+
t3,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def _isotypic_basis(mats, weights, translations, rng, traces) -> np.ndarray:
|
|
410
|
+
"""Orthonormal basis of the isotypic subspace (translations removed): the range of
|
|
411
|
+
``P = Σ_g w(g) T(g)`` applied to random vectors, its dimension the trace of ``P``."""
|
|
412
|
+
rank = round(float(weights @ traces))
|
|
413
|
+
if rank <= 0:
|
|
414
|
+
return np.zeros((translations.shape[0], 0))
|
|
415
|
+
s = rng.normal(size=(translations.shape[0], rank + 8))
|
|
416
|
+
y = sum(w * (mats[g] @ s) for g, w in enumerate(weights) if w != 0.0)
|
|
417
|
+
y = y - translations @ (translations.T @ y)
|
|
418
|
+
values, vectors = eigh(y.T @ y) # the range by the Gram matrix of a random sample
|
|
419
|
+
keep = values > 1e-12 * max(float(values[-1]), 1e-300)
|
|
420
|
+
basis = y @ (vectors[:, keep] / np.sqrt(values[keep]))
|
|
421
|
+
return basis[:, ::-1][:, :rank]
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def _axial_patterns(group: Group, i: int, irrep: Irrep, kq, gq, fixed, lift, floor) -> list:
|
|
425
|
+
"""The patterns of the axial classes of an irrep (see the module) in coordinates of its
|
|
426
|
+
isotypic subspace: the stiffness ``kq`` and geometric stiffness ``gq`` there (dense or
|
|
427
|
+
sparse; None without loading), ``fixed(H)`` the matrix of the projector
|
|
428
|
+
``(1/|H|) Σ_h T(h)`` and ``lift`` the map of coordinates to the dofs of the cell."""
|
|
429
|
+
out = []
|
|
430
|
+
for cls in axial_subgroups(group, irrep):
|
|
431
|
+
p = fixed(sorted(cls.subgroups[0]))
|
|
432
|
+
p += p.T
|
|
433
|
+
p *= 0.5
|
|
434
|
+
# Fix(H) in the isotypic subspace: the eigenvectors of eigenvalue 1
|
|
435
|
+
_, c = eigh(p, subset_by_value=(0.5, np.inf), overwrite_a=True)
|
|
436
|
+
if c.shape[1] == 0:
|
|
437
|
+
continue
|
|
438
|
+
c = c @ positive_subspace(c.T @ (kq @ c)) # mechanisms are not patterns
|
|
439
|
+
if c.shape[1] == 0:
|
|
440
|
+
continue
|
|
441
|
+
kc = c.T @ (kq @ c)
|
|
442
|
+
energies, modes = eigh(0.5 * (kc + kc.T))
|
|
443
|
+
load, buckled = np.nan, None
|
|
444
|
+
if gq is not None:
|
|
445
|
+
lam, phi = _buckling(kc, c.T @ (gq @ c), c, 1, floor)
|
|
446
|
+
if lam.size:
|
|
447
|
+
load, buckled = float(lam[0]), lift(phi[:, 0])
|
|
448
|
+
out.append(
|
|
449
|
+
Pattern(i, cls.subgroups, cls.description, c.shape[1], lift(c @ modes[:, 0]),
|
|
450
|
+
float(energies[0]), load, buckled)
|
|
451
|
+
) # fmt: skip
|
|
452
|
+
return out
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def _wave_characters(group: Group):
|
|
456
|
+
"""The pure translations (element indices) of the group of a cell of one or two
|
|
457
|
+
primitive cells along each axis and the characters of its wave vectors on them: a
|
|
458
|
+
mapping of the wave vectors (components 0 or 1 in units of ``π`` over the primitive
|
|
459
|
+
edges; the first of those of the same character) to their signs; None for another
|
|
460
|
+
group."""
|
|
461
|
+
dim = group.rotations.shape[1]
|
|
462
|
+
pure = np.flatnonzero(np.abs(group.rotations - np.eye(dim)).max(axis=(1, 2)) < 1e-9)
|
|
463
|
+
halves = 2.0 * group.translations[pure] @ np.linalg.inv(group.lattice).T
|
|
464
|
+
m = np.round(halves)
|
|
465
|
+
if np.abs(halves - m).max() > 1e-6 or np.any((m != 0) & (m != 1)):
|
|
466
|
+
return None
|
|
467
|
+
chars: dict[tuple, np.ndarray] = {}
|
|
468
|
+
for k in product(*[(0, 1) if a else (0,) for a in m.any(axis=0)]):
|
|
469
|
+
c = (-1.0) ** (m @ np.array(k))
|
|
470
|
+
if not any(np.array_equal(c, other) for other in chars.values()):
|
|
471
|
+
chars[tuple(int(v) for v in k)] = c
|
|
472
|
+
return pure, chars
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def wave_vectors(group: Group, irrep: Irrep) -> list[tuple] | None:
|
|
476
|
+
"""The wave vectors (the arms of the star) that an irrep of the group of a cell of one
|
|
477
|
+
or two primitive cells along each axis carries, components 0 or 1 in units of ``π``
|
|
478
|
+
over the primitive edges: ``k_i = 1`` where its patterns change sign from a primitive
|
|
479
|
+
cell to the next along axis ``i`` (the period doubled), ``(0, 0, 0)`` for patterns
|
|
480
|
+
repeated in every primitive cell; None for another group."""
|
|
481
|
+
found = _wave_characters(group)
|
|
482
|
+
if found is None:
|
|
483
|
+
return None
|
|
484
|
+
pure, chars = found
|
|
485
|
+
return [k for k, c in chars.items() if irrep.character[pure] @ c > 0.5 * len(pure)]
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
@dataclass
|
|
489
|
+
class _Star:
|
|
490
|
+
"""A star of wave vectors of a cell split by its translations (see the module): its
|
|
491
|
+
first wave vector, the point operations (element indices) that carry it to each arm,
|
|
492
|
+
the arm to which each element of the group carries it, the sparse orthonormal basis of
|
|
493
|
+
its fluctuations (dofs of the cell x those of a primitive cell), its little co-group
|
|
494
|
+
(element index -> position) with their matrices there and their traces, the
|
|
495
|
+
translations of the cell there, its character on the translations, and the irreps of
|
|
496
|
+
the little co-group with the irreps (indices) of the cell's group that they induce."""
|
|
497
|
+
|
|
498
|
+
wave: tuple
|
|
499
|
+
arms: list
|
|
500
|
+
arm_of: np.ndarray
|
|
501
|
+
space: sp.csr_matrix
|
|
502
|
+
little: dict
|
|
503
|
+
mats: list
|
|
504
|
+
traces: np.ndarray
|
|
505
|
+
moving: np.ndarray
|
|
506
|
+
signs: np.ndarray
|
|
507
|
+
induced: list
|
|
508
|
+
|
|
509
|
+
def basis(self, j: int, seed) -> np.ndarray:
|
|
510
|
+
"""Orthonormal basis of the isotypic subspace of the ``j``-th irrep of the little
|
|
511
|
+
co-group among the fluctuations of the wave vector."""
|
|
512
|
+
weights = self.induced[j][0].projector_weights()
|
|
513
|
+
rng = np.random.default_rng(seed)
|
|
514
|
+
return _isotypic_basis(self.mats, weights, self.moving, rng, self.traces)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def _bloch_stars(group: Group, cell: _Cell):
|
|
518
|
+
"""The stars of a cell split by its translations (see the module), the point part ``p``
|
|
519
|
+
of each element ``g = t p`` (the element of the same point operation without
|
|
520
|
+
translation), the position of its translation ``t`` among the translations, and the
|
|
521
|
+
operators of the point operations on the dofs of the cell; None when the group is not
|
|
522
|
+
the product of halving translations and point operations about the centre."""
|
|
523
|
+
found = _wave_characters(group)
|
|
524
|
+
if found is None:
|
|
525
|
+
return None
|
|
526
|
+
pure, chars = found
|
|
527
|
+
scale = float(np.abs(group.lattice).max())
|
|
528
|
+
zero = np.flatnonzero(np.abs(group.translations).max(axis=1) <= 1e-9 * scale)
|
|
529
|
+
if len(zero) * len(pure) != group.order:
|
|
530
|
+
return None
|
|
531
|
+
table, inverse = group.table, group.inverse
|
|
532
|
+
by_rotation = {np.round(group.rotations[p], 6).tobytes(): int(p) for p in zero}
|
|
533
|
+
point = np.array([by_rotation.get(np.round(r, 6).tobytes(), -1) for r in group.rotations])
|
|
534
|
+
where = np.full(group.order, -1)
|
|
535
|
+
where[pure] = np.arange(len(pure))
|
|
536
|
+
shift = where[table[np.arange(group.order), inverse[np.maximum(point, 0)]]]
|
|
537
|
+
if np.any(point < 0) or np.any(shift < 0):
|
|
538
|
+
return None
|
|
539
|
+
key = {(c > 0).tobytes(): k for k, c in chars.items()}
|
|
540
|
+
|
|
541
|
+
def image(p, k): # the wave vector p k, of character t -> χ_k(p^-1 t p)
|
|
542
|
+
moved = where[table[table[inverse[p], pure], p]]
|
|
543
|
+
return key[(chars[k][moved] > 0).tobytes()]
|
|
544
|
+
|
|
545
|
+
positions = np.asarray(cell.positions, dtype=float)
|
|
546
|
+
perm = group.subgroup(pure).action(positions)
|
|
547
|
+
reps = np.unique(perm.min(axis=0)) # the orbits of the translations, by their lowest node
|
|
548
|
+
images = perm[:, reps]
|
|
549
|
+
free = np.all(np.diff(np.sort(images, axis=0), axis=0) > 0)
|
|
550
|
+
if len(reps) * len(pure) != len(positions) or not free:
|
|
551
|
+
return None
|
|
552
|
+
width = cell.ke.shape[0] // len(positions)
|
|
553
|
+
p0 = group.subgroup(zero)
|
|
554
|
+
ops = representation(p0, p0.action(positions), [cell.block(r) for r in p0.rotations])
|
|
555
|
+
operators = dict(zip(zero.tolist(), ops, strict=True))
|
|
556
|
+
|
|
557
|
+
def space(k): # the orbit sums of the character of k
|
|
558
|
+
rows = (width * images)[:, :, None] + np.arange(width)
|
|
559
|
+
cols = (width * np.arange(len(reps)))[:, None] + np.arange(width)
|
|
560
|
+
cols = np.broadcast_to(cols, rows.shape)
|
|
561
|
+
vals = np.broadcast_to((chars[k] / np.sqrt(len(pure)))[:, None, None], rows.shape)
|
|
562
|
+
shape = (cell.ke.shape[0], width * len(reps))
|
|
563
|
+
return sp.csr_matrix((vals.ravel(), (rows.ravel(), cols.ravel())), shape=shape)
|
|
564
|
+
|
|
565
|
+
irreps = group.irreps()
|
|
566
|
+
characters = np.array([r.character for r in irreps])
|
|
567
|
+
stars, seen = [], set()
|
|
568
|
+
for k0 in chars:
|
|
569
|
+
if k0 in seen:
|
|
570
|
+
continue
|
|
571
|
+
arms: dict[tuple, int] = {}
|
|
572
|
+
for p in zero:
|
|
573
|
+
arms.setdefault(image(int(p), k0), int(p))
|
|
574
|
+
seen.update(arms)
|
|
575
|
+
index = {k: a for a, k in enumerate(arms)}
|
|
576
|
+
arm_zero = {int(p): index[image(int(p), k0)] for p in zero}
|
|
577
|
+
arm_of = np.array([arm_zero[int(p)] for p in point])
|
|
578
|
+
little = [int(p) for p in zero if arm_of[p] == 0]
|
|
579
|
+
b = space(k0)
|
|
580
|
+
mats = [(b.T @ operators[p] @ b).tocsr() for p in little]
|
|
581
|
+
traces = np.array([m.diagonal().sum() for m in mats])
|
|
582
|
+
moving = np.zeros((b.shape[1], 0))
|
|
583
|
+
if not any(k0) and cell.translations.shape[1]: # the translations of the cell
|
|
584
|
+
moving = np.linalg.qr(b.T @ cell.translations)[0]
|
|
585
|
+
pairs = table[np.ix_(pure, little)] # the elements t p of the little group
|
|
586
|
+
induced = []
|
|
587
|
+
for sigma in group.subgroup(little).irreps():
|
|
588
|
+
# the irrep induced by (k, σ): Frobenius reciprocity on the little group
|
|
589
|
+
overlap = np.einsum("t,mtp,p->m", chars[k0], characters[:, pairs], sigma.character)
|
|
590
|
+
mu = int(np.argmax(overlap))
|
|
591
|
+
if irreps[mu].dim != len(arms) * sigma.dim:
|
|
592
|
+
return None
|
|
593
|
+
induced.append((sigma, mu))
|
|
594
|
+
stars.append(
|
|
595
|
+
_Star(k0, list(arms.values()), arm_of, b, {p: j for j, p in enumerate(little)},
|
|
596
|
+
mats, traces, moving, chars[k0], induced)
|
|
597
|
+
) # fmt: skip
|
|
598
|
+
if sorted(mu for star in stars for _, mu in star.induced) != list(range(len(irreps))):
|
|
599
|
+
return None # each irrep induced once
|
|
600
|
+
return stars, point, shift, operators
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def _star_patterns(group: Group, i: int, star: _Star, q, reduced, point, shift, operators,
|
|
604
|
+
floor) -> list: # fmt: skip
|
|
605
|
+
"""The patterns of the irrep ``i`` of a cell split by its translations (see the module),
|
|
606
|
+
in the coordinates of its block ``q`` on each arm of its star: an element ``h`` carries
|
|
607
|
+
the block of arm ``a`` to that of arm ``b`` by the matrix of ``g_b^-1 h g_a = t p``
|
|
608
|
+
(``p`` in the little co-group), ``χ_k(t) q^T M_p q``; ``reduced``: the stiffness
|
|
609
|
+
matrices of the fluctuations of the wave vector."""
|
|
610
|
+
s, d = len(star.arms), q.shape[1]
|
|
611
|
+
table, inverse = group.table, group.inverse
|
|
612
|
+
|
|
613
|
+
def fixed(members):
|
|
614
|
+
sums = {}
|
|
615
|
+
for h in members:
|
|
616
|
+
for a, ga in enumerate(star.arms):
|
|
617
|
+
x = table[h, ga]
|
|
618
|
+
b = int(star.arm_of[x])
|
|
619
|
+
lt = table[inverse[star.arms[b]], x]
|
|
620
|
+
term = star.signs[shift[lt]] * star.mats[star.little[int(point[lt])]]
|
|
621
|
+
sums[b, a] = sums[b, a] + term if (b, a) in sums else term
|
|
622
|
+
out = np.zeros((s * d, s * d))
|
|
623
|
+
for (b, a), m in sums.items():
|
|
624
|
+
out[b * d : (b + 1) * d, a * d : (a + 1) * d] = q.T @ (m @ q)
|
|
625
|
+
return out / len(members)
|
|
626
|
+
|
|
627
|
+
def lift(x):
|
|
628
|
+
local = star.space @ (q @ np.reshape(x, (s, d)).T)
|
|
629
|
+
return sum(operators[ga] @ local[:, a] for a, ga in enumerate(star.arms))
|
|
630
|
+
|
|
631
|
+
ke, kg = reduced
|
|
632
|
+
kq = q.T @ (ke @ q)
|
|
633
|
+
gq = None if kg is None else q.T @ (kg @ q)
|
|
634
|
+
if s > 1: # the same block on every arm
|
|
635
|
+
kq = sp.block_diag([sp.csr_matrix(kq)] * s, format="csr")
|
|
636
|
+
gq = None if gq is None else sp.block_diag([sp.csr_matrix(gq)] * s, format="csr")
|
|
637
|
+
return _axial_patterns(group, i, group.irreps()[i], kq, gq, fixed, lift, floor)
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
def _bloch_bifurcation(cell: _Cell, group: Group, decomposition, rtol, which, seed):
|
|
641
|
+
"""The analysis of a cell split by its translations (see the module): the loads and
|
|
642
|
+
multiplicities of the irreps from their blocks on the first arm of their stars (one at
|
|
643
|
+
a time), and the patterns of the irreps of the first bifurcation (``which``
|
|
644
|
+
``"critical"``) or of all those present (``"all"``)."""
|
|
645
|
+
stars, point, shift, operators = decomposition
|
|
646
|
+
irreps = group.irreps()
|
|
647
|
+
multiplicities = np.zeros(len(irreps), dtype=np.int64)
|
|
648
|
+
loads = np.full(len(irreps), np.nan)
|
|
649
|
+
floors = np.full(len(irreps), np.inf)
|
|
650
|
+
spectra, of, reduced = {}, {}, []
|
|
651
|
+
for s, star in enumerate(stars):
|
|
652
|
+
b = star.space
|
|
653
|
+
kg = None if cell.kg is None else (b.T @ cell.kg @ b).tocsr()
|
|
654
|
+
reduced.append(((b.T @ cell.ke @ b).tocsr(), kg))
|
|
655
|
+
for j, (sigma, mu) in enumerate(star.induced):
|
|
656
|
+
q = star.basis(j, [seed, s, j])
|
|
657
|
+
if q.shape[1] == 0:
|
|
658
|
+
continue
|
|
659
|
+
multiplicities[mu] = round(q.shape[1] / sigma.dim)
|
|
660
|
+
of[mu] = (s, j)
|
|
661
|
+
if kg is None:
|
|
662
|
+
continue
|
|
663
|
+
ke = reduced[s][0]
|
|
664
|
+
lam, _ = _buckling(q.T @ (ke @ q), q.T @ (kg @ q), np.eye(q.shape[1]),
|
|
665
|
+
2 * sigma.dim + 2) # fmt: skip
|
|
666
|
+
spectra[mu] = lam
|
|
667
|
+
if lam.size:
|
|
668
|
+
loads[mu], floors[mu] = lam[0], 1e-10 / lam[0]
|
|
669
|
+
first, chosen = None, sorted(of) if which == "all" else []
|
|
670
|
+
if np.isfinite(loads).any():
|
|
671
|
+
critical = float(np.nanmin(loads))
|
|
672
|
+
count = sum(
|
|
673
|
+
int(np.sum(np.abs(lam - critical) <= rtol * critical)) * len(stars[of[i][0]].arms)
|
|
674
|
+
for i, lam in spectra.items()
|
|
675
|
+
) # each eigenvalue of a block on every arm of its star
|
|
676
|
+
first = (critical, int(np.nanargmin(loads)), count)
|
|
677
|
+
if which == "critical":
|
|
678
|
+
chosen = np.flatnonzero(np.abs(loads - critical) <= rtol * critical).tolist()
|
|
679
|
+
found: list[Pattern] = []
|
|
680
|
+
for i in chosen:
|
|
681
|
+
s, j = of[i] # the basis again, with the same seed
|
|
682
|
+
q = stars[s].basis(j, [seed, s, j])
|
|
683
|
+
found += _star_patterns(group, i, stars[s], q, reduced[s], point, shift, operators,
|
|
684
|
+
floors[i]) # fmt: skip
|
|
685
|
+
return Bifurcation(group, irreps, multiplicities, found, loads, first, None, cell.mesh,
|
|
686
|
+
cell.lift) # fmt: skip
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def post_bifurcation(
|
|
690
|
+
sample,
|
|
691
|
+
strain=None,
|
|
692
|
+
*,
|
|
693
|
+
materials=None,
|
|
694
|
+
group: Group | None = None,
|
|
695
|
+
cells=(1, 1, 1),
|
|
696
|
+
order: int = 1,
|
|
697
|
+
phases=None,
|
|
698
|
+
rtol: float = 1e-6,
|
|
699
|
+
seed: int = 0,
|
|
700
|
+
bloch: bool | None = None,
|
|
701
|
+
patterns: str | None = None,
|
|
702
|
+
) -> Bifurcation:
|
|
703
|
+
"""The post-bifurcated patterns of a periodic cell (see the module): a
|
|
704
|
+
:class:`~morphogen.homogenization.frames.Frame` (plane) or
|
|
705
|
+
:class:`~morphogen.homogenization.frames.SpaceFrame`, or a continuum given by its
|
|
706
|
+
tetrahedral mesh or voxel image (six tetrahedra per voxel, keeping ``phases``; elements
|
|
707
|
+
of ``order`` 1 or 2) and ``materials``. ``strain`` is the macroscopic loading (2 x 2
|
|
708
|
+
or 3 x 3) whose symmetry restricts the group and whose linear buckling orders the
|
|
709
|
+
bifurcations; ``group`` by default that of the frame's generators, or that detected
|
|
710
|
+
on the mesh of ``cells`` primitive cells (:func:`mesh_symmetries`). ``bloch``: split
|
|
711
|
+
a cell of two primitive cells along some axes by its translations first (by default
|
|
712
|
+
beyond ``DENSE_LIMIT`` dofs); ``patterns``: those of all the irreps present
|
|
713
|
+
(``"all"``, the default without ``bloch``) or of the irreps of the first bifurcation
|
|
714
|
+
(``"critical"``, the default with it)."""
|
|
715
|
+
if patterns not in (None, "all", "critical"):
|
|
716
|
+
raise ValueError("post_bifurcation: patterns 'all' or 'critical'")
|
|
717
|
+
if isinstance(sample, (Frame, SpaceFrame)):
|
|
718
|
+
cell = _frame_cell(sample, strain)
|
|
719
|
+
if group is None:
|
|
720
|
+
group = Group.generate(sample.generators, sample.lattice, sample.centre)
|
|
721
|
+
else:
|
|
722
|
+
if materials is None:
|
|
723
|
+
raise ValueError("post_bifurcation: the materials of a continuum")
|
|
724
|
+
if isinstance(sample, VoxelImage):
|
|
725
|
+
from morphogen.homogenization.bloch import voxel_tet_mesh
|
|
726
|
+
|
|
727
|
+
sample = voxel_tet_mesh(sample, phases)
|
|
728
|
+
# straight edges: the symmetries of the mesh are those of its corners
|
|
729
|
+
mesh = sample.quadratic().straight() if int(order) == 2 else sample.linear()
|
|
730
|
+
cell = _continuum_cell(mesh, materials, strain)
|
|
731
|
+
if group is None:
|
|
732
|
+
group = mesh_symmetries(cell.mesh, cells)
|
|
733
|
+
if strain is not None:
|
|
734
|
+
group = group.subgroup(group.stabilizer_of(strain))
|
|
735
|
+
n = cell.ke.shape[0]
|
|
736
|
+
asked = bloch
|
|
737
|
+
if bloch is None: # by default for the large cells of several primitive cells
|
|
738
|
+
waves = _wave_characters(group)
|
|
739
|
+
bloch = n > DENSE_LIMIT and waves is not None and len(waves[0]) > 1
|
|
740
|
+
if bloch:
|
|
741
|
+
decomposition = _bloch_stars(group, cell)
|
|
742
|
+
if decomposition is not None:
|
|
743
|
+
which = patterns or "critical"
|
|
744
|
+
return _bloch_bifurcation(cell, group, decomposition, rtol, which, seed)
|
|
745
|
+
if asked:
|
|
746
|
+
raise ValueError(
|
|
747
|
+
"post_bifurcation: bloch for the cells of one or two primitive cells along"
|
|
748
|
+
" each axis whose group is the product of its translations and point operations"
|
|
749
|
+
)
|
|
750
|
+
which = patterns or "all"
|
|
751
|
+
perm = group.action(cell.positions)
|
|
752
|
+
mats = representation(group, perm, [cell.block(r) for r in group.rotations])
|
|
753
|
+
traces = np.array([m.diagonal().sum() for m in mats])
|
|
754
|
+
irreps = group.irreps()
|
|
755
|
+
rng = np.random.default_rng(seed)
|
|
756
|
+
multiplicities = np.zeros(len(irreps), dtype=np.int64)
|
|
757
|
+
loads = np.full(len(irreps), np.nan)
|
|
758
|
+
bases, spectra, floors = [], [], []
|
|
759
|
+
floor, whole = None, None
|
|
760
|
+
if cell.kg is not None and n <= DENSE_LIMIT: # the whole cell, for the projections
|
|
761
|
+
free = cell.translations.shape[1]
|
|
762
|
+
z = np.linalg.qr(np.hstack([cell.translations, np.eye(n)]))[0][:, free:]
|
|
763
|
+
full_ke, full_kg = z.T @ (cell.ke @ z), z.T @ (cell.kg @ z)
|
|
764
|
+
whole = _buckling(full_ke, full_kg, z, 3 * max(r.dim for r in irreps))
|
|
765
|
+
floor = 1e-8 / whole[0][0] if whole[0].size else np.inf
|
|
766
|
+
for i, irrep in enumerate(irreps):
|
|
767
|
+
weights = irrep.projector_weights()
|
|
768
|
+
q = _isotypic_basis(mats, weights, cell.translations, rng, traces)
|
|
769
|
+
bases.append(q)
|
|
770
|
+
multiplicities[i] = round(q.shape[1] / irrep.dim)
|
|
771
|
+
spectra.append(np.zeros(0))
|
|
772
|
+
floors.append(floor)
|
|
773
|
+
if q.shape[1] == 0 or cell.kg is None:
|
|
774
|
+
continue
|
|
775
|
+
kq, gq = q.T @ (cell.ke @ q), q.T @ (cell.kg @ q)
|
|
776
|
+
if floor is None: # no whole solve: the scale of this block
|
|
777
|
+
lam0, _ = _buckling(kq, gq, np.eye(q.shape[1]), 1)
|
|
778
|
+
floors[i] = 1e-10 / lam0[0] if lam0.size else np.inf
|
|
779
|
+
lam, _ = _buckling(kq, gq, np.eye(q.shape[1]), 2 * irrep.dim + 2, floors[i])
|
|
780
|
+
spectra[i] = lam
|
|
781
|
+
if lam.size:
|
|
782
|
+
loads[i] = lam[0]
|
|
783
|
+
first = projections = None
|
|
784
|
+
chosen = [i for i, q in enumerate(bases) if q.shape[1]] if which == "all" else []
|
|
785
|
+
if cell.kg is not None and np.isfinite(loads).any():
|
|
786
|
+
critical = float(np.nanmin(loads))
|
|
787
|
+
count = int(sum(np.sum(np.abs(s - critical) <= rtol * critical) for s in spectra))
|
|
788
|
+
first = (critical, int(np.nanargmin(loads)), count)
|
|
789
|
+
if which == "critical":
|
|
790
|
+
chosen = np.flatnonzero(np.abs(loads - critical) <= rtol * critical).tolist()
|
|
791
|
+
if whole is not None and whole[0].size:
|
|
792
|
+
lam_full, phi_full = whole
|
|
793
|
+
k = int(np.sum(np.abs(lam_full - critical) <= rtol * critical))
|
|
794
|
+
modes = phi_full[:, :k] / np.linalg.norm(phi_full[:, :k], axis=0)
|
|
795
|
+
projections = np.array([np.linalg.norm(q.T @ modes, axis=0) for q in bases])
|
|
796
|
+
found: list[Pattern] = []
|
|
797
|
+
for i in chosen:
|
|
798
|
+
q = bases[i]
|
|
799
|
+
kq = q.T @ (cell.ke @ q)
|
|
800
|
+
gq = None if cell.kg is None else q.T @ (cell.kg @ q)
|
|
801
|
+
|
|
802
|
+
def fixed(members, q=q):
|
|
803
|
+
return q.T @ (sum(mats[h] for h in members) @ q) / len(members)
|
|
804
|
+
|
|
805
|
+
found += _axial_patterns(group, i, irreps[i], kq, gq, fixed, lambda x, q=q: q @ x,
|
|
806
|
+
floors[i]) # fmt: skip
|
|
807
|
+
return Bifurcation(
|
|
808
|
+
group, irreps, multiplicities, found, loads, first, projections, cell.mesh, cell.lift
|
|
809
|
+
)
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
# -- along nonlinear paths ----------------------------------------------------------------------
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
@dataclass
|
|
816
|
+
class PathBifurcation(Bifurcation):
|
|
817
|
+
"""The analysis of a cell along a nonlinear loading path (:func:`path_bifurcation`).
|
|
818
|
+
Besides the fields of :class:`Bifurcation` (``loads``: the time at which the tangent of
|
|
819
|
+
each irrep loses its positive definiteness, NaN when it does not; ``first``: the
|
|
820
|
+
earliest, its irrep and the number of modes that cross within that step; the patterns:
|
|
821
|
+
the softest modes of the axial classes at that point): the times of the converged
|
|
822
|
+
steps (from the natural state) and their macroscopic strains (the six components of the
|
|
823
|
+
path), the lowest eigenvalues of the tangent in each isotypic subspace (steps x irreps
|
|
824
|
+
x k, relative to the largest diagonal entry of its block in the natural state; NaN for
|
|
825
|
+
the irreps absent from the fluctuations), the macroscopic strain at the first
|
|
826
|
+
bifurcation, the response along the principal path
|
|
827
|
+
(:class:`~morphogen.homogenization.paths.PathResult`) and, after a switch of branch,
|
|
828
|
+
the response of the cell perturbed along the critical pattern, with the times of its
|
|
829
|
+
steps and the amplitude of that pattern in its fluctuation."""
|
|
830
|
+
|
|
831
|
+
times: np.ndarray | None = None
|
|
832
|
+
strains: np.ndarray | None = None
|
|
833
|
+
spectra: np.ndarray | None = None
|
|
834
|
+
critical_strain: np.ndarray | None = None
|
|
835
|
+
principal: object = field(default=None, repr=False)
|
|
836
|
+
branch: object = field(default=None, repr=False)
|
|
837
|
+
branch_times: np.ndarray | None = None
|
|
838
|
+
amplitudes: np.ndarray | None = None
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
def _symmetric(v) -> np.ndarray:
|
|
842
|
+
"""The symmetric 3 x 3 tensor of six components (11, 22, 33, 23, 31, 12)."""
|
|
843
|
+
from morphogen.homogenization.elements import VOIGT
|
|
844
|
+
|
|
845
|
+
t = np.zeros((3, 3))
|
|
846
|
+
for k, (a, b) in enumerate(VOIGT):
|
|
847
|
+
t[a, b] = t[b, a] = v[k]
|
|
848
|
+
return t
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
def _loading_group(group: Group, path) -> Group:
|
|
852
|
+
"""The subgroup that leaves a loading path invariant: its prescribed strains and its
|
|
853
|
+
prescribed stresses at every time, and which components are strains or stresses (the
|
|
854
|
+
point operations of mesh groups are signed permutations of the axes)."""
|
|
855
|
+
controls = path.strain_controlled
|
|
856
|
+
keep = np.ones(group.order, dtype=bool)
|
|
857
|
+
for row in np.asarray(path.values):
|
|
858
|
+
for mask in (controls, ~controls):
|
|
859
|
+
keep &= group.stabilizer_of(_symmetric(np.where(mask, row, 0.0)))
|
|
860
|
+
flags = _symmetric(np.where(controls, 1.0, 2.0))
|
|
861
|
+
for g, r in enumerate(group.rotations):
|
|
862
|
+
a = np.abs(r)
|
|
863
|
+
keep[g] &= bool(np.abs(a @ flags @ a.T - flags).max() < 1e-9)
|
|
864
|
+
return group.subgroup(keep)
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
def _crossing(t, lam, k) -> float:
|
|
868
|
+
"""The time between the steps ``k - 1`` and ``k`` at which the eigenvalue ``lam``
|
|
869
|
+
changes sign: the root of the parabola through the values of the steps ``k - 2`` to
|
|
870
|
+
``k`` (of the line through the last two at the first step)."""
|
|
871
|
+
t0, t1 = float(t[k - 1]), float(t[k])
|
|
872
|
+
if k >= 2:
|
|
873
|
+
roots = np.roots(np.polyfit(t[k - 2 : k + 1] - t0, lam[k - 2 : k + 1], 2)) + t0
|
|
874
|
+
roots = roots[np.abs(roots.imag) <= 1e-12 * max(abs(t1), 1.0)].real
|
|
875
|
+
inside = roots[(roots >= t0 - 1e-12 * abs(t1)) & (roots <= t1 * (1 + 1e-12))]
|
|
876
|
+
if inside.size:
|
|
877
|
+
return float(inside.min())
|
|
878
|
+
return t0 + (t1 - t0) * float(lam[k - 1] / (lam[k - 1] - lam[k]))
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def path_bifurcation(
|
|
882
|
+
sample,
|
|
883
|
+
path,
|
|
884
|
+
*,
|
|
885
|
+
materials,
|
|
886
|
+
kinematics: str = "finite",
|
|
887
|
+
group: Group | None = None,
|
|
888
|
+
cells=(1, 1, 1),
|
|
889
|
+
order: int = 1,
|
|
890
|
+
phases=None,
|
|
891
|
+
eigenvalues: int = 3,
|
|
892
|
+
stop: bool = True,
|
|
893
|
+
branch: float | None = None,
|
|
894
|
+
rtol: float = 1e-3,
|
|
895
|
+
seed: int = 0,
|
|
896
|
+
**options,
|
|
897
|
+
) -> PathBifurcation:
|
|
898
|
+
"""The bifurcations of a periodic cell along a nonlinear loading path (see the
|
|
899
|
+
module): a tetrahedral mesh or a voxel image (six tetrahedra per voxel, keeping
|
|
900
|
+
``phases``; elements of ``order`` 1 or 2) of ``cells`` primitive cells, its
|
|
901
|
+
``materials`` (elastic, von Mises elasto-(visco)plastic, crystal or MFront behaviours),
|
|
902
|
+
the ``path`` (:class:`~morphogen.homogenization.paths.LoadingPath` or its mapping)
|
|
903
|
+
followed by :class:`~morphogen.homogenization.nonlinear.NonlinearFEProblem` with
|
|
904
|
+
periodic conditions in ``kinematics`` (``options``: its options; the tangents of the
|
|
905
|
+
points symmetrized unless they say otherwise, ``tangent="symmetric"``: the analysis is
|
|
906
|
+
that of the symmetric part). The tangent of each converged step is block-diagonalized
|
|
907
|
+
in the isotypic subspaces of the group of the cell restricted to the path; the
|
|
908
|
+
``eigenvalues`` lowest eigenvalues of each block (times the dimension of its irrep)
|
|
909
|
+
are followed, and the first that changes sign marks a bifurcation. ``stop``: the
|
|
910
|
+
principal path ends at the first bifurcation. ``branch``: the amplitude (a fraction
|
|
911
|
+
of the smallest edge of the box; about 0.01 to 0.02, a smaller one making the
|
|
912
|
+
transition so abrupt that Newton's method may fall back onto the principal branch) of
|
|
913
|
+
an imperfection of the nodes along the critical pattern, with which the path is
|
|
914
|
+
followed again onto the bifurcated branch."""
|
|
915
|
+
from morphogen.homogenization.nonlinear import NonlinearFEProblem
|
|
916
|
+
from morphogen.homogenization.paths import LoadingPath
|
|
917
|
+
|
|
918
|
+
path = LoadingPath.from_spec(path)
|
|
919
|
+
if isinstance(sample, (Frame, SpaceFrame)):
|
|
920
|
+
raise ValueError("path_bifurcation: continua (frames: post_bifurcation)")
|
|
921
|
+
if isinstance(sample, VoxelImage):
|
|
922
|
+
from morphogen.homogenization.bloch import voxel_tet_mesh
|
|
923
|
+
|
|
924
|
+
sample = voxel_tet_mesh(sample, phases)
|
|
925
|
+
mesh = sample.quadratic().straight() if int(order) == 2 else sample.linear()
|
|
926
|
+
# the blocks below are those of the symmetric part of the tangent
|
|
927
|
+
options = {"tangent": "symmetric", **options}
|
|
928
|
+
problem = NonlinearFEProblem(mesh, materials, "periodic", kinematics=kinematics, **options)
|
|
929
|
+
if problem.empty:
|
|
930
|
+
raise ValueError("path_bifurcation: no load-carrying material in the cell")
|
|
931
|
+
m = problem.mesh
|
|
932
|
+
t_nodes, masters, _ = periodic_map(m)
|
|
933
|
+
lift = sp.kron(t_nodes, sp.identity(3), format="csr")
|
|
934
|
+
group = _loading_group(mesh_symmetries(m, cells) if group is None else group, path)
|
|
935
|
+
perm = group.action(m.nodes[masters])
|
|
936
|
+
mats = representation(group, perm, list(group.rotations))
|
|
937
|
+
traces = np.array([t.diagonal().sum() for t in mats])
|
|
938
|
+
irreps = group.irreps()
|
|
939
|
+
n = 3 * len(masters)
|
|
940
|
+
translations = np.zeros((n, 3))
|
|
941
|
+
for c in range(3):
|
|
942
|
+
translations[c::3, c] = 1.0 / np.sqrt(len(masters))
|
|
943
|
+
rng = np.random.default_rng(seed)
|
|
944
|
+
bases = [
|
|
945
|
+
_isotypic_basis(mats, r.projector_weights(), translations, rng, traces) for r in irreps
|
|
946
|
+
]
|
|
947
|
+
multiplicities = np.array(
|
|
948
|
+
[round(q.shape[1] / r.dim) for q, r in zip(bases, irreps, strict=True)]
|
|
949
|
+
)
|
|
950
|
+
elastic = (lift.T @ problem._stiffness() @ lift).tocsr() # the natural state
|
|
951
|
+
# the mechanisms of the natural state (rotations of parts free of the faces...) left out
|
|
952
|
+
bases = [q if q.shape[1] == 0 else q @ positive_subspace(q.T @ (elastic @ q)) for q in bases]
|
|
953
|
+
counts = [min(q.shape[1], int(eigenvalues) * r.dim) for q, r in zip(bases, irreps, strict=True)]
|
|
954
|
+
width = max(max(counts), 1)
|
|
955
|
+
scales = [1.0] * len(irreps)
|
|
956
|
+
|
|
957
|
+
def blocks_of(k, columns=None, kee=None, reduced=False):
|
|
958
|
+
"""The tangent in each isotypic subspace, the unknown macroscopic components
|
|
959
|
+
condensed (their stresses prescribed)."""
|
|
960
|
+
k = k if reduced else (lift.T @ k @ lift).tocsr()
|
|
961
|
+
g = None if columns is None else lift.T @ columns
|
|
962
|
+
out = []
|
|
963
|
+
for q in bases:
|
|
964
|
+
if q.shape[1] == 0:
|
|
965
|
+
out.append(None)
|
|
966
|
+
continue
|
|
967
|
+
b = q.T @ (k @ q)
|
|
968
|
+
if g is not None:
|
|
969
|
+
gq = q.T @ g
|
|
970
|
+
b = b - gq @ np.linalg.solve(kee, gq.T)
|
|
971
|
+
out.append(0.5 * (b + b.T))
|
|
972
|
+
return out
|
|
973
|
+
|
|
974
|
+
def spectrum(blocks):
|
|
975
|
+
row = np.full((len(irreps), width), np.nan)
|
|
976
|
+
for i, b in enumerate(blocks):
|
|
977
|
+
if b is not None and counts[i]:
|
|
978
|
+
values = eigh(b, eigvals_only=True, subset_by_index=[0, counts[i] - 1])
|
|
979
|
+
row[i, : values.size] = values / scales[i]
|
|
980
|
+
return row
|
|
981
|
+
|
|
982
|
+
natural = blocks_of(elastic, reduced=True) # the elastic tangent of the natural state
|
|
983
|
+
scales = [1.0 if b is None else float(np.abs(np.diag(b)).max()) for b in natural]
|
|
984
|
+
record = {"t": [float(path.times[0])], "e": [np.zeros(6)], "rows": [spectrum(natural)]}
|
|
985
|
+
record.update({"blocks": [natural], "critical": None})
|
|
986
|
+
|
|
987
|
+
def monitor(state):
|
|
988
|
+
columns = kee = None
|
|
989
|
+
if state.unknown.size:
|
|
990
|
+
columns, kee = state.disc.macro_columns(state.tangent, state.wts)
|
|
991
|
+
columns, kee = columns[:, state.unknown], kee[np.ix_(state.unknown, state.unknown)]
|
|
992
|
+
blocks = blocks_of(state.disc.full_tangent(state.tangent, state.wts), columns, kee)
|
|
993
|
+
row = spectrum(blocks)
|
|
994
|
+
record["t"].append(float(state.time))
|
|
995
|
+
record["e"].append(np.asarray(state.strain, dtype=float).copy())
|
|
996
|
+
record["rows"].append(row)
|
|
997
|
+
crossed = bool(np.any(row[:, 0] < 0))
|
|
998
|
+
if crossed and record["critical"] is None:
|
|
999
|
+
record["critical"] = (record["blocks"][-1], blocks)
|
|
1000
|
+
record["blocks"] = [blocks]
|
|
1001
|
+
return stop and crossed
|
|
1002
|
+
|
|
1003
|
+
principal = problem.run(path, name="principal", monitor=monitor)
|
|
1004
|
+
times, strains = np.array(record["t"]), np.array(record["e"])
|
|
1005
|
+
spectra = np.array(record["rows"])
|
|
1006
|
+
loads = np.full(len(irreps), np.nan)
|
|
1007
|
+
steps = np.full(len(irreps), -1)
|
|
1008
|
+
for i in range(len(irreps)):
|
|
1009
|
+
negative = np.flatnonzero(spectra[:, i, 0] < 0)
|
|
1010
|
+
if negative.size and negative[0] > 0:
|
|
1011
|
+
steps[i] = negative[0]
|
|
1012
|
+
loads[i] = _crossing(times, spectra[:, i, 0], negative[0])
|
|
1013
|
+
first = critical_strain = None
|
|
1014
|
+
blocks = record["blocks"][-1]
|
|
1015
|
+
if np.isfinite(loads).any():
|
|
1016
|
+
critical = float(np.nanmin(loads))
|
|
1017
|
+
irrep = int(np.nanargmin(loads))
|
|
1018
|
+
together = np.flatnonzero(np.abs(loads - critical) <= rtol * max(abs(critical), 1e-300))
|
|
1019
|
+
count = int(sum(np.sum(spectra[steps[i], i] < 0) for i in together))
|
|
1020
|
+
first = (critical, irrep, count)
|
|
1021
|
+
k = steps[irrep]
|
|
1022
|
+
weight = (critical - times[k - 1]) / (times[k] - times[k - 1])
|
|
1023
|
+
critical_strain = (1 - weight) * strains[k - 1] + weight * strains[k]
|
|
1024
|
+
before, after = record["critical"]
|
|
1025
|
+
blocks = before if weight < 0.5 else after # the step nearer to the bifurcation
|
|
1026
|
+
patterns: list[Pattern] = []
|
|
1027
|
+
for i, irrep in enumerate(irreps):
|
|
1028
|
+
q, b = bases[i], blocks[i]
|
|
1029
|
+
if b is None:
|
|
1030
|
+
continue
|
|
1031
|
+
for cls in axial_subgroups(group, irrep):
|
|
1032
|
+
members = sorted(cls.subgroups[0])
|
|
1033
|
+
y = sum(mats[h] @ q for h in members) / len(members)
|
|
1034
|
+
values, vectors = eigh(0.5 * ((q.T @ y) + (q.T @ y).T))
|
|
1035
|
+
c = vectors[:, values > 0.5] # Fix(H) in the isotypic subspace
|
|
1036
|
+
if c.shape[1] == 0:
|
|
1037
|
+
continue
|
|
1038
|
+
energies, modes = eigh(0.5 * (c.T @ b @ c + (c.T @ b @ c).T))
|
|
1039
|
+
mode = q @ (c @ modes[:, 0])
|
|
1040
|
+
energy = float(energies[0] / scales[i])
|
|
1041
|
+
patterns.append(
|
|
1042
|
+
Pattern(i, cls.subgroups, cls.description, c.shape[1], mode, energy,
|
|
1043
|
+
float(loads[i]), None)
|
|
1044
|
+
) # fmt: skip
|
|
1045
|
+
out = PathBifurcation(group, irreps, multiplicities, patterns, loads, first, None, m, lift,
|
|
1046
|
+
times, strains, spectra, critical_strain, principal) # fmt: skip
|
|
1047
|
+
if branch and first is not None:
|
|
1048
|
+
candidates = [p for p in patterns if p.irrep == first[1]]
|
|
1049
|
+
if candidates: # the softest pattern of an axial class of the critical irrep
|
|
1050
|
+
mode = min(candidates, key=lambda p: p.energy).mode
|
|
1051
|
+
else:
|
|
1052
|
+
_, v = eigh(blocks[first[1]], subset_by_index=[0, 0])
|
|
1053
|
+
mode = bases[first[1]] @ v[:, 0]
|
|
1054
|
+
_switch_branch(out, mode, path, materials, kinematics, float(branch), masters, options)
|
|
1055
|
+
return out
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
def _switch_branch(result, mode, path, materials, kinematics, amplitude, masters, options):
|
|
1059
|
+
"""Follow the path again with the nodes perturbed along the critical ``mode``: the
|
|
1060
|
+
bifurcated branch, and the amplitude of the mode in the fluctuation at each step (into
|
|
1061
|
+
``result``)."""
|
|
1062
|
+
from dataclasses import replace
|
|
1063
|
+
|
|
1064
|
+
from morphogen.homogenization.nonlinear import NonlinearFEProblem
|
|
1065
|
+
|
|
1066
|
+
m = result.mesh
|
|
1067
|
+
span = float(np.max(m.size))
|
|
1068
|
+
# the nodes of the faces of the box move along them only: the faces stay plane and
|
|
1069
|
+
# periodic (an equivariant change, which keeps the pattern in its subspace)
|
|
1070
|
+
along = (np.abs(m.nodes - m.lower) > 1e-9 * span) & (np.abs(m.nodes - m.upper) > 1e-9 * span)
|
|
1071
|
+
u = result.displacement(mode) * along
|
|
1072
|
+
scale = amplitude * float(np.min(m.size)) / max(float(np.abs(u).max()), 1e-300)
|
|
1073
|
+
perturbed = replace(m, nodes=m.nodes + scale * u)
|
|
1074
|
+
again = NonlinearFEProblem(perturbed, materials, "periodic", kinematics=kinematics, **options)
|
|
1075
|
+
record = {"t": [], "a": []}
|
|
1076
|
+
|
|
1077
|
+
def monitor(state):
|
|
1078
|
+
w = (state.disc.t_mat @ state.q).reshape(-1, 3)[masters].ravel()
|
|
1079
|
+
record["t"].append(float(state.time))
|
|
1080
|
+
record["a"].append(float(w @ mode))
|
|
1081
|
+
return False
|
|
1082
|
+
|
|
1083
|
+
result.branch = again.run(path, name="branch", fields=True, monitor=monitor)
|
|
1084
|
+
result.branch_times = np.array(record["t"])
|
|
1085
|
+
result.amplitudes = np.array(record["a"])
|