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,597 @@
|
|
|
1
|
+
"""The tools of the tab Physics of the interface: the physics of the homogenization
|
|
2
|
+
module beyond mechanics, on a morphology of the workspace — the transport of a scalar
|
|
3
|
+
potential (heat, electricity, dielectrics, magnetism, diffusion), the flow of a fluid
|
|
4
|
+
through its pores with the sound absorbed by a layer of it, the dynamic moduli of a
|
|
5
|
+
viscoelastic composite, and the band structure of light and of sound in a periodic
|
|
6
|
+
morphology (photonic and sonic crystals). Each runs the functions of
|
|
7
|
+
:mod:`morphogen.homogenization` that the guide to the physics (docs/physics.md)
|
|
8
|
+
describes, on the voxels of the morphology."""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from morphogen.gui.tools import Field, tab, tool
|
|
15
|
+
|
|
16
|
+
tab(
|
|
17
|
+
"physics",
|
|
18
|
+
"Physics",
|
|
19
|
+
"The other physics of a morphology of the workspace, on its voxels: its transport "
|
|
20
|
+
"properties (thermal and electrical conductivities, permittivity, permeability, "
|
|
21
|
+
"diffusivity) between their bounds, the flow through its pores (Darcy's permeability) "
|
|
22
|
+
"with the acoustic parameters and the sound absorption of a layer of it, the "
|
|
23
|
+
"storage and loss moduli of a viscoelastic composite over a range of frequencies, and "
|
|
24
|
+
"the band structures of light and of sound in a periodic morphology.",
|
|
25
|
+
order=62,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
TRANSPORTS = (
|
|
29
|
+
("thermal", "heat conduction (conductivity)"),
|
|
30
|
+
("electrical", "electrical conduction (conductivity)"),
|
|
31
|
+
("dielectric", "dielectrics (permittivity)"),
|
|
32
|
+
("magnetic", "magnetostatics (permeability)"),
|
|
33
|
+
("diffusion", "diffusion (diffusivity)"),
|
|
34
|
+
)
|
|
35
|
+
DIRECTIONS = (
|
|
36
|
+
("mean", "the mean of the axes (an isotropic medium)"),
|
|
37
|
+
("x", "sound along x"),
|
|
38
|
+
("y", "sound along y"),
|
|
39
|
+
("z", "sound along z"),
|
|
40
|
+
)
|
|
41
|
+
WAVES = (
|
|
42
|
+
("electromagnetic", "light: electromagnetic waves (the permittivities of the phases)"),
|
|
43
|
+
("acoustic", "sound: the pressure of fluids (their densities and bulk moduli)"),
|
|
44
|
+
)
|
|
45
|
+
INCIDENCES = (
|
|
46
|
+
("normal", "normal: a plane wave across the layer"),
|
|
47
|
+
("oblique", "oblique: a plane wave at an angle from the normal"),
|
|
48
|
+
("diffuse", "diffuse field: every angle (Paris' average)"),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _image(p: dict, lowest: int = 4, highest: int = 256):
|
|
53
|
+
"""The voxels of the morphology of the form."""
|
|
54
|
+
n = p["voxels"]
|
|
55
|
+
if not lowest <= n <= highest:
|
|
56
|
+
raise ValueError(f"voxels per edge: from {lowest} to {highest}")
|
|
57
|
+
return p["source"]["micro"].voxelize(shape=n)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _tensor_rows(tensor) -> list[dict]:
|
|
61
|
+
labels = ("1", "2", "3")
|
|
62
|
+
return [
|
|
63
|
+
{"": a, **{b: float(tensor[i, j]) for j, b in enumerate(labels)}}
|
|
64
|
+
for i, a in enumerate(labels)
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@tool(
|
|
69
|
+
"transport",
|
|
70
|
+
"physics",
|
|
71
|
+
"Transport properties",
|
|
72
|
+
"The apparent coefficient of a transport phenomenon of a scalar potential and its "
|
|
73
|
+
"tensor, by FFT on the voxels of a morphology (periodic conditions): heat or electrical "
|
|
74
|
+
"conduction, dielectrics, magnetostatics, diffusion — the same problem, div(a grad u) = "
|
|
75
|
+
"0, with the coefficient a of each phase. A zero coefficient makes a phase inert (an "
|
|
76
|
+
"insulator, an impermeable inclusion). Against the bounds of Wiener and of Hashin and "
|
|
77
|
+
"Shtrikman for the phase fractions.",
|
|
78
|
+
[
|
|
79
|
+
Field("source", "item", label="morphology", required=True),
|
|
80
|
+
Field("physics", "choice", "thermal", choices=TRANSPORTS),
|
|
81
|
+
Field(
|
|
82
|
+
"coefficients",
|
|
83
|
+
"floats",
|
|
84
|
+
[1.0, 10.0],
|
|
85
|
+
label="coefficients of the phases",
|
|
86
|
+
doc="one per phase of the morphology, in the order of their numbers (0: a "
|
|
87
|
+
"phase inert for this physics)",
|
|
88
|
+
),
|
|
89
|
+
Field("voxels", "int", 32, label="voxels per edge"),
|
|
90
|
+
],
|
|
91
|
+
order=1,
|
|
92
|
+
menu="Transport",
|
|
93
|
+
)
|
|
94
|
+
def transport(p: dict, ctx) -> dict:
|
|
95
|
+
from morphogen.analysis.basic import phase_fractions
|
|
96
|
+
from morphogen.homogenization import Material, bounds, homogenize
|
|
97
|
+
from morphogen.homogenization.apparent import TRANSPORT_PROPERTIES
|
|
98
|
+
from morphogen.homogenization.materials import TRANSPORT
|
|
99
|
+
|
|
100
|
+
ctx.progress(0.05, "voxels")
|
|
101
|
+
image = _image(p)
|
|
102
|
+
fractions = phase_fractions(image)
|
|
103
|
+
phases = sorted(fractions)
|
|
104
|
+
coefficients = [float(c) for c in p["coefficients"] or []]
|
|
105
|
+
if len(coefficients) != len(phases):
|
|
106
|
+
raise ValueError(
|
|
107
|
+
f"coefficients of the phases: one per phase (the phases {phases} of the voxels)"
|
|
108
|
+
)
|
|
109
|
+
if min(coefficients) < 0.0 or max(coefficients) <= 0.0:
|
|
110
|
+
raise ValueError("coefficients of the phases: non-negative, one at least positive")
|
|
111
|
+
physics = p["physics"]
|
|
112
|
+
scalar, tensor_name = TRANSPORT_PROPERTIES[physics]
|
|
113
|
+
materials = {
|
|
114
|
+
k: Material(**{TRANSPORT[physics]: c}) for k, c in zip(phases, coefficients, strict=True)
|
|
115
|
+
}
|
|
116
|
+
ctx.progress(0.2, "solving")
|
|
117
|
+
out = homogenize(image, materials, properties=[scalar, tensor_name])
|
|
118
|
+
tensor = np.asarray(out[f"{tensor_name}.periodic"]["tensor"])
|
|
119
|
+
ctx.table(_tensor_rows(tensor), tensor_name, f"{tensor_name.replace('_', ' ')} (periodic)")
|
|
120
|
+
values = {"voxels": int(np.prod(image.shape))}
|
|
121
|
+
values.update({f"fraction of phase {k}": float(f) for k, f in fractions.items()})
|
|
122
|
+
values[f"apparent {scalar.replace('_', ' ')}"] = float(out[f"{scalar}.periodic"].value)
|
|
123
|
+
values.update({f"along {'xyz'[a]}": float(tensor[a, a]) for a in range(3)})
|
|
124
|
+
try:
|
|
125
|
+
limits = bounds(fractions, materials).get(scalar, {})
|
|
126
|
+
except (ValueError, KeyError):
|
|
127
|
+
limits = {}
|
|
128
|
+
names = {
|
|
129
|
+
"reuss": "Wiener lower bound (series)",
|
|
130
|
+
"hs_lower": "Hashin-Shtrikman lower bound",
|
|
131
|
+
"hs_upper": "Hashin-Shtrikman upper bound",
|
|
132
|
+
"voigt": "Wiener upper bound (parallel)",
|
|
133
|
+
}
|
|
134
|
+
values.update({names[k]: float(limits[k]) for k in names if k in limits})
|
|
135
|
+
return {"values": values, "title": f"{scalar.replace('_', ' ')} of {p['source']['title']}"}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@tool(
|
|
139
|
+
"sound",
|
|
140
|
+
"physics",
|
|
141
|
+
"Flow and sound absorption",
|
|
142
|
+
"The flow of a fluid through the pores of a morphology and the sound in them: the "
|
|
143
|
+
"permeability of Darcy's law (a Stokes flow, by the lattice Boltzmann method on the "
|
|
144
|
+
"voxels) and the parameters of the equivalent fluid of the rigid frame — porosity, "
|
|
145
|
+
"resistivity, tortuosity, viscous and thermal characteristic lengths, thermal "
|
|
146
|
+
"permeability — then the absorption coefficient of a layer of the material on a rigid "
|
|
147
|
+
"wall, in air (the model of Johnson, Champoux, Allard and Lafarge): at normal "
|
|
148
|
+
"incidence, at an angle (the wave refracted in the layer, whose frame along it is "
|
|
149
|
+
"that of the two other axes when the sound goes along one) or in a diffuse field.",
|
|
150
|
+
[
|
|
151
|
+
Field("source", "item", label="morphology", required=True),
|
|
152
|
+
Field("pores", "int", 0, label="phase of the pores", doc="the fluid fills it"),
|
|
153
|
+
Field("voxels", "int", 40, label="voxels per edge"),
|
|
154
|
+
Field(
|
|
155
|
+
"unit",
|
|
156
|
+
"float",
|
|
157
|
+
1e-3,
|
|
158
|
+
label="unit of length of the morphology",
|
|
159
|
+
unit="m",
|
|
160
|
+
doc="in metres (1e-3: a morphology in millimetres): the parameters are given "
|
|
161
|
+
"in SI units",
|
|
162
|
+
),
|
|
163
|
+
Field("thickness", "float", 0.03, label="thickness of the layer", unit="m"),
|
|
164
|
+
Field(
|
|
165
|
+
"frequencies",
|
|
166
|
+
"floats",
|
|
167
|
+
[100.0, 6000.0],
|
|
168
|
+
label="range of frequencies",
|
|
169
|
+
unit="Hz",
|
|
170
|
+
doc="the lowest and the highest; sixty between them",
|
|
171
|
+
),
|
|
172
|
+
Field("direction", "choice", "mean", label="sound", choices=DIRECTIONS),
|
|
173
|
+
Field("incidence", "choice", "normal", choices=INCIDENCES),
|
|
174
|
+
Field(
|
|
175
|
+
"angle",
|
|
176
|
+
"float",
|
|
177
|
+
45.0,
|
|
178
|
+
unit="degree",
|
|
179
|
+
when={"incidence": "oblique"},
|
|
180
|
+
doc="of the wave from the normal of the layer",
|
|
181
|
+
),
|
|
182
|
+
],
|
|
183
|
+
order=2,
|
|
184
|
+
menu="Flow and acoustics",
|
|
185
|
+
)
|
|
186
|
+
def sound(p: dict, ctx) -> dict:
|
|
187
|
+
from matplotlib.figure import Figure
|
|
188
|
+
|
|
189
|
+
from morphogen.homogenization.acoustics import (
|
|
190
|
+
AIR,
|
|
191
|
+
absorption,
|
|
192
|
+
acoustic_parameters,
|
|
193
|
+
along_axis,
|
|
194
|
+
equivalent_fluid,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
scale = p["unit"]
|
|
198
|
+
if not scale > 0.0:
|
|
199
|
+
raise ValueError("unit of length of the morphology: positive (metres)")
|
|
200
|
+
if not p["thickness"] > 0.0:
|
|
201
|
+
raise ValueError("thickness of the layer: positive")
|
|
202
|
+
band = sorted(float(f) for f in p["frequencies"] or [])
|
|
203
|
+
if len(band) != 2 or not 0.0 < band[0] < band[1]:
|
|
204
|
+
raise ValueError("range of frequencies: the lowest and the highest, positive")
|
|
205
|
+
ctx.progress(0.05, "voxels")
|
|
206
|
+
image = _image(p)
|
|
207
|
+
if not np.any(image.data == p["pores"]):
|
|
208
|
+
raise ValueError(f"phase of the pores: no voxel of the phase {p['pores']}")
|
|
209
|
+
ctx.progress(0.15, "flow through the pores")
|
|
210
|
+
res = acoustic_parameters(image, pores=p["pores"], tol=1e-4)
|
|
211
|
+
axis = {"mean": None, "x": 0, "y": 1, "z": 2}[p["direction"]]
|
|
212
|
+
six = along_axis(res, axis)
|
|
213
|
+
if not (np.isfinite(six["tortuosity"]) and six["permeability"] > 0.0):
|
|
214
|
+
raise ValueError(
|
|
215
|
+
"the pores do not let the fluid through along this direction (no path): choose "
|
|
216
|
+
"the phase of the pores, another direction or more voxels"
|
|
217
|
+
)
|
|
218
|
+
# in SI units: lengths times the unit, permeabilities times its square
|
|
219
|
+
for name, power in (("permeability", 2), ("viscous_length", 1), ("thermal_length", 1),
|
|
220
|
+
("thermal_permeability", 2)): # fmt: skip
|
|
221
|
+
six[name] *= scale**power
|
|
222
|
+
ctx.progress(0.8, "absorption")
|
|
223
|
+
f = np.geomspace(band[0], band[1], 60)
|
|
224
|
+
normal = absorption(f, p["thickness"], **six)
|
|
225
|
+
kind = p["incidence"] or "normal"
|
|
226
|
+
if kind == "normal":
|
|
227
|
+
layer, how = normal, "normal incidence"
|
|
228
|
+
else:
|
|
229
|
+
transverse = None
|
|
230
|
+
if axis is not None: # the frame along the layer: the mean of its two other axes
|
|
231
|
+
others = [along_axis(res, a) for a in range(3) if a != axis]
|
|
232
|
+
transverse = dict(six)
|
|
233
|
+
for name, power in (("permeability", 2), ("viscous_length", 1)):
|
|
234
|
+
transverse[name] = 0.5 * (others[0][name] + others[1][name]) * scale**power
|
|
235
|
+
transverse["tortuosity"] = 0.5 * (others[0]["tortuosity"] + others[1]["tortuosity"])
|
|
236
|
+
if not (np.isfinite(transverse["tortuosity"]) and transverse["permeability"] > 0.0):
|
|
237
|
+
transverse = None # no path along the layer: as across it
|
|
238
|
+
if kind == "oblique":
|
|
239
|
+
angle = float(p["angle"])
|
|
240
|
+
if not 0.0 <= angle < 90.0:
|
|
241
|
+
raise ValueError("angle: from 0 to 90 degrees from the normal")
|
|
242
|
+
layer = absorption(f, p["thickness"], incidence=np.radians(angle),
|
|
243
|
+
transverse=transverse, **six) # fmt: skip
|
|
244
|
+
how = f"incidence at {angle:g}°"
|
|
245
|
+
else:
|
|
246
|
+
layer = absorption(f, p["thickness"], incidence="diffuse", transverse=transverse,
|
|
247
|
+
**six) # fmt: skip
|
|
248
|
+
how = "diffuse field"
|
|
249
|
+
medium = equivalent_fluid(f, **six)
|
|
250
|
+
rows = [
|
|
251
|
+
{"axis": "xyz"[a], "permeability (m²)": res[f"permeability{a + 1}"] * scale**2,
|
|
252
|
+
"tortuosity": res[f"tortuosity{a + 1}"],
|
|
253
|
+
"viscous length (m)": res[f"viscous_length{a + 1}"] * scale}
|
|
254
|
+
for a in range(3)
|
|
255
|
+
] # fmt: skip
|
|
256
|
+
ctx.table(rows, "parameters", "parameters along the axes")
|
|
257
|
+
reduced = normal["surface_impedance"] / AIR.impedance
|
|
258
|
+
ctx.table(
|
|
259
|
+
[
|
|
260
|
+
{"frequency (Hz)": float(x), "absorption": float(a),
|
|
261
|
+
"absorption at normal incidence": float(b), "Re Zs / Z0": float(z.real),
|
|
262
|
+
"Im Zs / Z0": float(z.imag)}
|
|
263
|
+
for x, a, b, z in zip(f, layer["absorption"], normal["absorption"], reduced,
|
|
264
|
+
strict=True)
|
|
265
|
+
],
|
|
266
|
+
"absorption",
|
|
267
|
+
f"absorption of the layer ({how}, rigid backing; Zs: at normal incidence)",
|
|
268
|
+
) # fmt: skip
|
|
269
|
+
fig = Figure(figsize=(5.6, 3.8), layout="constrained")
|
|
270
|
+
ax = fig.subplots()
|
|
271
|
+
ax.semilogx(f, layer["absorption"], color="C0", lw=1.6, label=how)
|
|
272
|
+
if kind != "normal":
|
|
273
|
+
ax.semilogx(f, normal["absorption"], color="0.5", lw=1.0, ls="--",
|
|
274
|
+
label="normal incidence") # fmt: skip
|
|
275
|
+
ax.legend(fontsize=8, frameon=False)
|
|
276
|
+
ax.set_xlabel("frequency (Hz)")
|
|
277
|
+
ax.set_ylabel("absorption coefficient")
|
|
278
|
+
ax.set_ylim(0.0, 1.0)
|
|
279
|
+
ax.set_xlim(band[0], band[1])
|
|
280
|
+
ax.grid(True, which="both", lw=0.4, alpha=0.5)
|
|
281
|
+
ax.set_title(f"{1e3 * p['thickness']:g} mm on a rigid wall, {how}", fontsize=10)
|
|
282
|
+
ctx.figure(fig, "absorption", "sound absorption of the layer")
|
|
283
|
+
values = {
|
|
284
|
+
"voxels": int(np.prod(image.shape)),
|
|
285
|
+
"porosity": six["porosity"],
|
|
286
|
+
"permeability (m²)": six["permeability"],
|
|
287
|
+
"resistivity (Pa s/m²)": medium["resistivity"],
|
|
288
|
+
"tortuosity": six["tortuosity"],
|
|
289
|
+
"viscous length (m)": six["viscous_length"],
|
|
290
|
+
"thermal length (m)": six["thermal_length"],
|
|
291
|
+
"thermal permeability (m²)": six["thermal_permeability"],
|
|
292
|
+
"mean absorption over the range": float(np.mean(layer["absorption"])),
|
|
293
|
+
"highest absorption": float(np.max(layer["absorption"])),
|
|
294
|
+
"at the frequency (Hz)": float(f[int(np.argmax(layer["absorption"]))]),
|
|
295
|
+
}
|
|
296
|
+
return {"values": values, "title": f"Flow and sound in {p['source']['title']}"}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
@tool(
|
|
300
|
+
"dynamic",
|
|
301
|
+
"physics",
|
|
302
|
+
"Dynamic moduli",
|
|
303
|
+
"The storage and loss moduli of a composite with a viscoelastic phase over a range of "
|
|
304
|
+
"frequencies, by the correspondence principle: the complex moduli of the Prony series "
|
|
305
|
+
"of the phase (a generalized Maxwell model) and the elastic constants of the others "
|
|
306
|
+
"give the complex stiffness of the voxels at each frequency (FFT, periodic). The "
|
|
307
|
+
"elastic constants of the viscoelastic phase are its instantaneous ones.",
|
|
308
|
+
[
|
|
309
|
+
Field("source", "item", label="morphology", required=True),
|
|
310
|
+
Field(
|
|
311
|
+
"materials",
|
|
312
|
+
"materials",
|
|
313
|
+
of="source",
|
|
314
|
+
doc="isotropic elastic constants of the phases, or voids",
|
|
315
|
+
),
|
|
316
|
+
Field(
|
|
317
|
+
"phase",
|
|
318
|
+
"int",
|
|
319
|
+
label="viscoelastic phase",
|
|
320
|
+
doc="blank: the first phase that is not a void",
|
|
321
|
+
),
|
|
322
|
+
Field(
|
|
323
|
+
"shear",
|
|
324
|
+
"floats",
|
|
325
|
+
[0.5, 0.01, 0.3, 1.0],
|
|
326
|
+
label="Prony series of the shear modulus",
|
|
327
|
+
doc="pairs g, τ: the relative moduli (their sum below 1) and the times",
|
|
328
|
+
),
|
|
329
|
+
Field(
|
|
330
|
+
"bulk",
|
|
331
|
+
"floats",
|
|
332
|
+
label="Prony series of the bulk modulus",
|
|
333
|
+
doc="pairs k, τ (blank: an elastic bulk response)",
|
|
334
|
+
),
|
|
335
|
+
Field(
|
|
336
|
+
"frequencies",
|
|
337
|
+
"floats",
|
|
338
|
+
[0.01, 1000.0],
|
|
339
|
+
label="range of angular frequencies",
|
|
340
|
+
doc="the lowest and the highest (rad per unit of time)",
|
|
341
|
+
),
|
|
342
|
+
Field("count", "int", 8, label="number of frequencies"),
|
|
343
|
+
Field("voxels", "int", 20, label="voxels per edge"),
|
|
344
|
+
],
|
|
345
|
+
order=3,
|
|
346
|
+
menu="Dynamics and waves",
|
|
347
|
+
)
|
|
348
|
+
def dynamic(p: dict, ctx) -> dict:
|
|
349
|
+
from matplotlib.figure import Figure
|
|
350
|
+
|
|
351
|
+
from morphogen.gui.tools.mechanics import _elastic
|
|
352
|
+
from morphogen.homogenization import homogenize
|
|
353
|
+
from morphogen.homogenization.materials import materials_from_config
|
|
354
|
+
|
|
355
|
+
def pairs(values, name):
|
|
356
|
+
values = [float(v) for v in values or []]
|
|
357
|
+
if len(values) % 2:
|
|
358
|
+
raise ValueError(f"Prony series of the {name} modulus: pairs (modulus, time)")
|
|
359
|
+
return [[values[i], values[i + 1]] for i in range(0, len(values), 2)]
|
|
360
|
+
|
|
361
|
+
elastic = _elastic(p["source"], p.get("materials"))
|
|
362
|
+
phase = p.get("phase")
|
|
363
|
+
if phase is None:
|
|
364
|
+
phase = next((k for k, m in elastic.items() if m != "void"), None)
|
|
365
|
+
if phase not in elastic or elastic[phase] == "void":
|
|
366
|
+
raise ValueError(f"viscoelastic phase: {phase} is a void or no phase of the morphology")
|
|
367
|
+
series = {"shear": pairs(p.get("shear"), "shear"), "bulk": pairs(p.get("bulk"), "bulk")}
|
|
368
|
+
series = {k: v for k, v in series.items() if v}
|
|
369
|
+
if not series:
|
|
370
|
+
raise ValueError("Prony series: at least one term (shear or bulk)")
|
|
371
|
+
configs = dict(elastic)
|
|
372
|
+
configs[phase] = {**elastic[phase], "viscoelasticity": series}
|
|
373
|
+
materials = materials_from_config(configs)
|
|
374
|
+
band = sorted(float(f) for f in p["frequencies"] or [])
|
|
375
|
+
if len(band) != 2 or not 0.0 < band[0] < band[1]:
|
|
376
|
+
raise ValueError("range of angular frequencies: the lowest and the highest, positive")
|
|
377
|
+
count = p["count"]
|
|
378
|
+
if not 2 <= count <= 60:
|
|
379
|
+
raise ValueError("number of frequencies: from 2 to 60")
|
|
380
|
+
ctx.progress(0.05, "voxels")
|
|
381
|
+
image = _image(p, highest=128)
|
|
382
|
+
omegas = np.geomspace(band[0], band[1], count)
|
|
383
|
+
rows = []
|
|
384
|
+
for i, omega in enumerate(omegas):
|
|
385
|
+
ctx.progress(0.1 + 0.8 * i / count, f"frequency {i + 1} of {count}")
|
|
386
|
+
res = homogenize(image, materials, properties=["dynamic_stiffness"],
|
|
387
|
+
frequencies=[float(omega)])["dynamic_stiffness.periodic"] # fmt: skip
|
|
388
|
+
rows.append({
|
|
389
|
+
"angular frequency": float(omega),
|
|
390
|
+
"bulk storage": res["bulk_storage_1"],
|
|
391
|
+
"bulk loss": res["bulk_loss_1"],
|
|
392
|
+
"shear storage": res["shear_storage_1"],
|
|
393
|
+
"shear loss": res["shear_loss_1"],
|
|
394
|
+
"tan δ (shear)": res["shear_tan_delta_1"],
|
|
395
|
+
"Young storage (x)": res["young_storage_1"],
|
|
396
|
+
"Young loss (x)": res["young_loss_1"],
|
|
397
|
+
}) # fmt: skip
|
|
398
|
+
ctx.table(rows, "moduli", "storage and loss moduli of the composite")
|
|
399
|
+
fig = Figure(figsize=(9.2, 3.6), layout="constrained")
|
|
400
|
+
left, right = fig.subplots(1, 2)
|
|
401
|
+
left.loglog(omegas, [r["shear storage"] for r in rows], "o-", label="storage G'")
|
|
402
|
+
left.loglog(omegas, [r["shear loss"] for r in rows], "s--", label="loss G''")
|
|
403
|
+
left.set_xlabel("angular frequency")
|
|
404
|
+
left.set_ylabel("shear modulus")
|
|
405
|
+
left.legend(frameon=False)
|
|
406
|
+
right.semilogx(omegas, [r["tan δ (shear)"] for r in rows], "o-", color="C3")
|
|
407
|
+
right.set_xlabel("angular frequency")
|
|
408
|
+
right.set_ylabel("loss factor tan δ")
|
|
409
|
+
for ax in (left, right):
|
|
410
|
+
ax.grid(True, which="both", lw=0.4, alpha=0.5)
|
|
411
|
+
ctx.figure(fig, "moduli", "shear moduli and loss factor of the composite")
|
|
412
|
+
peak = int(np.argmax([r["tan δ (shear)"] for r in rows]))
|
|
413
|
+
values = {
|
|
414
|
+
"voxels": int(np.prod(image.shape)),
|
|
415
|
+
"shear storage at the lowest frequency": rows[0]["shear storage"],
|
|
416
|
+
"shear storage at the highest frequency": rows[-1]["shear storage"],
|
|
417
|
+
"highest loss factor (shear)": rows[peak]["tan δ (shear)"],
|
|
418
|
+
"at the angular frequency": rows[peak]["angular frequency"],
|
|
419
|
+
}
|
|
420
|
+
return {"values": values, "title": f"Dynamic moduli of {p['source']['title']}"}
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
@tool(
|
|
424
|
+
"waves",
|
|
425
|
+
"physics",
|
|
426
|
+
"Band structure of light and sound",
|
|
427
|
+
"The Bloch waves of a periodic morphology, in three dimensions: light in a photonic "
|
|
428
|
+
"crystal (the vector waves of Maxwell's equations, by plane waves on a grid whose "
|
|
429
|
+
"cells cut by the interfaces take an averaged permittivity) or sound in a sonic "
|
|
430
|
+
"crystal (the pressure of fluids, finite elements on the voxels; a phase of zero "
|
|
431
|
+
"density is left out: rigid scatterers). The frequencies along the edges of the "
|
|
432
|
+
"Brillouin zone of the cell (Γ–X–M–Γ–R; Γ–X–M–Γ in the plane of a thin one), in units "
|
|
433
|
+
"of c / L (the speed of light for unit coefficients, or of the sound of the first "
|
|
434
|
+
"fluid, over the edge of the cell along x), and the band gaps: the ranges of "
|
|
435
|
+
"frequencies in which no wave propagates along the path.",
|
|
436
|
+
[
|
|
437
|
+
Field("source", "item", label="morphology", required=True),
|
|
438
|
+
Field("waves", "choice", "electromagnetic", choices=WAVES),
|
|
439
|
+
Field(
|
|
440
|
+
"permittivity",
|
|
441
|
+
"floats",
|
|
442
|
+
[1.0, 11.56],
|
|
443
|
+
label="permittivities of the phases",
|
|
444
|
+
when={"waves": "electromagnetic"},
|
|
445
|
+
doc="relative, in the order of their numbers (1: the vacuum, air)",
|
|
446
|
+
),
|
|
447
|
+
Field(
|
|
448
|
+
"density",
|
|
449
|
+
"floats",
|
|
450
|
+
[1.2, 0.0],
|
|
451
|
+
label="densities of the phases",
|
|
452
|
+
when={"waves": "acoustic"},
|
|
453
|
+
doc="in the order of their numbers; 0: a rigid phase, which holds no sound",
|
|
454
|
+
),
|
|
455
|
+
Field(
|
|
456
|
+
"bulk",
|
|
457
|
+
"floats",
|
|
458
|
+
[1.42e5, 1.0],
|
|
459
|
+
label="bulk moduli of the phases",
|
|
460
|
+
when={"waves": "acoustic"},
|
|
461
|
+
),
|
|
462
|
+
Field(
|
|
463
|
+
"resolution",
|
|
464
|
+
"int",
|
|
465
|
+
12,
|
|
466
|
+
label="plane waves (or voxels) per edge",
|
|
467
|
+
doc="light: the plane waves; sound: the voxels, cut into tetrahedra",
|
|
468
|
+
),
|
|
469
|
+
Field(
|
|
470
|
+
"coarsen",
|
|
471
|
+
"int",
|
|
472
|
+
3,
|
|
473
|
+
label="voxels per plane wave",
|
|
474
|
+
when={"waves": "electromagnetic"},
|
|
475
|
+
doc="the morphology is drawn that many times finer than the plane waves, and the "
|
|
476
|
+
"cells that its interfaces cut are averaged (1: none)",
|
|
477
|
+
),
|
|
478
|
+
Field(
|
|
479
|
+
"path",
|
|
480
|
+
"str",
|
|
481
|
+
doc="corners of the Brillouin zone among G (Γ), X, Y, Z, M, R (blank: G X M G R; "
|
|
482
|
+
"G X M G in the plane)",
|
|
483
|
+
),
|
|
484
|
+
Field("points", "int", 4, doc="wave vectors per segment of the path"),
|
|
485
|
+
Field("bands", "int", 8),
|
|
486
|
+
],
|
|
487
|
+
order=4,
|
|
488
|
+
menu="Dynamics and waves",
|
|
489
|
+
)
|
|
490
|
+
def waves(p: dict, ctx) -> dict:
|
|
491
|
+
from matplotlib.figure import Figure
|
|
492
|
+
|
|
493
|
+
from morphogen.gui.api import _planar
|
|
494
|
+
from morphogen.gui.tools.stability import _corners
|
|
495
|
+
from morphogen.homogenization.bloch import brillouin_path, scalar_band_structure
|
|
496
|
+
from morphogen.homogenization.photonic import electromagnetic_band_structure
|
|
497
|
+
from morphogen.image import VoxelImage
|
|
498
|
+
|
|
499
|
+
item = p["source"]
|
|
500
|
+
micro = item["micro"]
|
|
501
|
+
if not micro.domain.periodic:
|
|
502
|
+
raise ValueError(f"{item['title']} is not periodic: the Bloch waves are those of a cell")
|
|
503
|
+
light = (p["waves"] or "electromagnetic") == "electromagnetic"
|
|
504
|
+
n, coarsen = int(p["resolution"]), int(p["coarsen"] or 1) if light else 1
|
|
505
|
+
points, bands = int(p["points"]), int(p["bands"])
|
|
506
|
+
if not (4 <= n <= 32 and 1 <= coarsen <= 6):
|
|
507
|
+
raise ValueError("plane waves per edge: from 4 to 32; voxels per plane wave: from 1 to 6")
|
|
508
|
+
if not (1 <= points <= 24 and 1 <= bands <= 40):
|
|
509
|
+
raise ValueError("points: from 1 to 24 per segment; bands: from 1 to 40")
|
|
510
|
+
planar = _planar(micro)
|
|
511
|
+
corners = _corners(p["path"], planar)
|
|
512
|
+
ctx.progress(0.03, "voxels")
|
|
513
|
+
lengths = np.asarray(micro.domain.lengths, dtype=float)
|
|
514
|
+
edge = float(lengths[:2].min() if planar else lengths.min())
|
|
515
|
+
shape = np.maximum(1, np.rint(lengths / edge * n)).astype(int) * coarsen
|
|
516
|
+
if planar:
|
|
517
|
+
shape[2] = 1
|
|
518
|
+
data = np.asarray(micro.voxelize(shape=tuple(int(v) for v in shape)).data)
|
|
519
|
+
spacing = lengths / shape
|
|
520
|
+
if planar:
|
|
521
|
+
spacing[2] = spacing[0] # one layer: no wave vector across it
|
|
522
|
+
image = VoxelImage(data, tuple(spacing), periodic=True)
|
|
523
|
+
present = [int(k) for k in np.unique(data)]
|
|
524
|
+
|
|
525
|
+
def per_phase(values, name):
|
|
526
|
+
values = [float(v) for v in values or []]
|
|
527
|
+
if len(values) <= max(present):
|
|
528
|
+
raise ValueError(f"{name}: one per phase (the phases {present})")
|
|
529
|
+
return {k: values[k] for k in present}
|
|
530
|
+
|
|
531
|
+
ks, distance, labels = brillouin_path(image.size, corners, points)
|
|
532
|
+
if light:
|
|
533
|
+
eps = per_phase(p["permittivity"], "permittivities of the phases")
|
|
534
|
+
if any(not v > 0 for v in eps.values()):
|
|
535
|
+
raise ValueError("permittivities of the phases: positive (1 for the vacuum)")
|
|
536
|
+
speed = 1.0
|
|
537
|
+
else:
|
|
538
|
+
rho = per_phase(p["density"], "densities of the phases")
|
|
539
|
+
bulk = per_phase(p["bulk"], "bulk moduli of the phases")
|
|
540
|
+
if any(v < 0 for v in rho.values()) or any(not v > 0 for v in bulk.values()):
|
|
541
|
+
raise ValueError("densities: not negative (0: rigid); bulk moduli: positive")
|
|
542
|
+
fluids = [k for k in present if rho[k] > 0]
|
|
543
|
+
if not fluids:
|
|
544
|
+
raise ValueError("densities of the phases: one fluid at least")
|
|
545
|
+
a = {k: (1.0 / rho[k] if rho[k] > 0 else 0.0) for k in present}
|
|
546
|
+
b = {k: 1.0 / bulk[k] for k in present}
|
|
547
|
+
speed = float(np.sqrt(bulk[fluids[0]] / rho[fluids[0]]))
|
|
548
|
+
frequencies = []
|
|
549
|
+
from morphogen.homogenization.bloch import BandStructure
|
|
550
|
+
|
|
551
|
+
for seg in range(len(corners) - 1): # one segment at a time, for the progress
|
|
552
|
+
ctx.progress(
|
|
553
|
+
0.05 + 0.85 * seg / (len(corners) - 1), f"Bloch waves {corners[seg]}–{corners[seg + 1]}"
|
|
554
|
+
)
|
|
555
|
+
chunk = ks[(0 if seg == 0 else 1 + seg * points) : 1 + (seg + 1) * points]
|
|
556
|
+
if light:
|
|
557
|
+
part = electromagnetic_band_structure(image, eps, chunk, bands=bands, coarsen=coarsen)
|
|
558
|
+
else:
|
|
559
|
+
part = scalar_band_structure(image, a, b, chunk, bands=bands)
|
|
560
|
+
frequencies.append(part.frequencies)
|
|
561
|
+
result = BandStructure(ks, distance, np.vstack(frequencies), labels)
|
|
562
|
+
length = float(lengths[0])
|
|
563
|
+
scale = length / (2 * np.pi * speed)
|
|
564
|
+
ctx.progress(0.92, "figures")
|
|
565
|
+
fig = Figure(figsize=(5.6, 4.4), layout="constrained")
|
|
566
|
+
ax = fig.subplots()
|
|
567
|
+
result.plot(ax, scale=scale, ylabel="ω L / 2π c")
|
|
568
|
+
ax.set_title("light" if light else f"sound (c of phase {fluids[0]})", fontsize=10)
|
|
569
|
+
ctx.figure(fig, "bands", "band structure")
|
|
570
|
+
gaps = result.gaps()
|
|
571
|
+
rows = [
|
|
572
|
+
{"bands": f"{k} – {k + 1}", "from": low * scale, "to": high * scale,
|
|
573
|
+
"width (% of its middle)": 200.0 * (high - low) / (high + low)}
|
|
574
|
+
for k, low, high in gaps
|
|
575
|
+
] # fmt: skip
|
|
576
|
+
if rows:
|
|
577
|
+
ctx.table(rows, "gaps", "band gaps along the path (ω L / 2π c)")
|
|
578
|
+
table = []
|
|
579
|
+
for d, k, row in zip(distance, ks, result.frequencies, strict=True):
|
|
580
|
+
entry = {"distance": float(d), "kx": float(k[0]), "ky": float(k[1]), "kz": float(k[2])}
|
|
581
|
+
entry.update({f"band {i + 1}": float(v * scale) for i, v in enumerate(row)})
|
|
582
|
+
table.append(entry)
|
|
583
|
+
ctx.table(table, "bands", "the bands at the wave vectors (ω L / 2π c)")
|
|
584
|
+
values = {
|
|
585
|
+
"voxels": int(np.prod(shape)),
|
|
586
|
+
"wave vectors": len(ks),
|
|
587
|
+
"band gaps along the path": len(gaps),
|
|
588
|
+
"highest frequency (ω L / 2π c)": float(result.frequencies.max() * scale),
|
|
589
|
+
}
|
|
590
|
+
if gaps:
|
|
591
|
+
k, low, high = max(gaps, key=lambda g: (g[2] - g[1]) / (g[2] + g[1]))
|
|
592
|
+
values["widest gap, above the band"] = int(k)
|
|
593
|
+
values["widest gap, from (ω L / 2π c)"] = low * scale
|
|
594
|
+
values["widest gap, to (ω L / 2π c)"] = high * scale
|
|
595
|
+
values["widest gap (% of its middle)"] = 200.0 * (high - low) / (high + low)
|
|
596
|
+
kind = "Light" if light else "Sound"
|
|
597
|
+
return {"values": values, "title": f"{kind} in {item['title']}: band structure"}
|