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.
Files changed (381) hide show
  1. morphogen/__init__.py +60 -0
  2. morphogen/__main__.py +7 -0
  3. morphogen/_platform.py +55 -0
  4. morphogen/_public.py +153 -0
  5. morphogen/_utils.py +80 -0
  6. morphogen/_version.py +1 -0
  7. morphogen/analysis/__init__.py +174 -0
  8. morphogen/analysis/anisotropy.py +135 -0
  9. morphogen/analysis/basic.py +38 -0
  10. morphogen/analysis/cells.py +54 -0
  11. morphogen/analysis/connectivity.py +156 -0
  12. morphogen/analysis/correlation.py +195 -0
  13. morphogen/analysis/covariance.py +80 -0
  14. morphogen/analysis/fractal.py +54 -0
  15. morphogen/analysis/measures.py +188 -0
  16. morphogen/analysis/morphology.py +265 -0
  17. morphogen/analysis/particles.py +160 -0
  18. morphogen/analysis/percolation.py +2034 -0
  19. morphogen/analysis/power_laws.py +143 -0
  20. morphogen/analysis/random_sets.py +351 -0
  21. morphogen/analysis/stereology.py +289 -0
  22. morphogen/analysis/surface.py +107 -0
  23. morphogen/analysis/topology.py +92 -0
  24. morphogen/automata/__init__.py +74 -0
  25. morphogen/automata/engine.py +211 -0
  26. morphogen/automata/growth.py +686 -0
  27. morphogen/automata/lattice.py +143 -0
  28. morphogen/automata/reaction.py +255 -0
  29. morphogen/automata/rules.py +353 -0
  30. morphogen/automata/tilings.py +1715 -0
  31. morphogen/cli.py +3526 -0
  32. morphogen/config.py +2167 -0
  33. morphogen/contact/__init__.py +113 -0
  34. morphogen/contact/experiments.py +368 -0
  35. morphogen/contact/hertz.py +104 -0
  36. morphogen/contact/kernels.py +827 -0
  37. morphogen/contact/periodic.py +278 -0
  38. morphogen/contact/problem.py +578 -0
  39. morphogen/contact/surfaces.py +310 -0
  40. morphogen/coupling/__init__.py +43 -0
  41. morphogen/coupling/ageing.py +143 -0
  42. morphogen/coupling/diffusion.py +226 -0
  43. morphogen/coupling/fenicsx.py +484 -0
  44. morphogen/coupling/oxidation.py +447 -0
  45. morphogen/coupling/plates.py +247 -0
  46. morphogen/design/__init__.py +51 -0
  47. morphogen/design/csp.py +616 -0
  48. morphogen/design/frames.py +277 -0
  49. morphogen/design/search.py +287 -0
  50. morphogen/design/tiles.py +336 -0
  51. morphogen/distributions.py +312 -0
  52. morphogen/domain.py +203 -0
  53. morphogen/dynamics/__init__.py +179 -0
  54. morphogen/dynamics/model.py +638 -0
  55. morphogen/dynamics/openradioss.py +643 -0
  56. morphogen/dynamics/results.py +515 -0
  57. morphogen/fracture/__init__.py +170 -0
  58. morphogen/fracture/bulk.py +349 -0
  59. morphogen/fracture/cohesive.py +1614 -0
  60. morphogen/fracture/ductile.py +557 -0
  61. morphogen/fracture/lefm.py +1168 -0
  62. morphogen/fracture/mixed.py +1178 -0
  63. morphogen/fracture/periodic.py +733 -0
  64. morphogen/fracture/phasefield.py +714 -0
  65. morphogen/fracture/phasefield_finite.py +368 -0
  66. morphogen/fracture/surface.py +572 -0
  67. morphogen/fracture/toughness.py +566 -0
  68. morphogen/gpu.py +108 -0
  69. morphogen/gui/__init__.py +8 -0
  70. morphogen/gui/api.py +1927 -0
  71. morphogen/gui/desktop.py +387 -0
  72. morphogen/gui/icon.png +0 -0
  73. morphogen/gui/index.html +1909 -0
  74. morphogen/gui/server.py +229 -0
  75. morphogen/gui/tools/__init__.py +629 -0
  76. morphogen/gui/tools/compare.py +149 -0
  77. morphogen/gui/tools/contact.py +391 -0
  78. morphogen/gui/tools/couplings.py +1085 -0
  79. morphogen/gui/tools/crackfront.py +245 -0
  80. morphogen/gui/tools/design.py +224 -0
  81. morphogen/gui/tools/dynamics.py +824 -0
  82. morphogen/gui/tools/fracture.py +2586 -0
  83. morphogen/gui/tools/interop.py +1654 -0
  84. morphogen/gui/tools/learning.py +595 -0
  85. morphogen/gui/tools/mechanics.py +3881 -0
  86. morphogen/gui/tools/nonlocal_damage.py +1321 -0
  87. morphogen/gui/tools/phasefield.py +215 -0
  88. morphogen/gui/tools/physics.py +597 -0
  89. morphogen/gui/tools/stability.py +1756 -0
  90. morphogen/gui/tools/statistics.py +1408 -0
  91. morphogen/gui/viewer.js +1100 -0
  92. morphogen/homogenization/__init__.py +210 -0
  93. morphogen/homogenization/acoustics.py +566 -0
  94. morphogen/homogenization/amg.py +1005 -0
  95. morphogen/homogenization/apparent.py +1046 -0
  96. morphogen/homogenization/behaviours.cu +2285 -0
  97. morphogen/homogenization/behaviours.py +944 -0
  98. morphogen/homogenization/beremin.py +263 -0
  99. morphogen/homogenization/bifurcation.py +1085 -0
  100. morphogen/homogenization/bloch.py +507 -0
  101. morphogen/homogenization/bounds.py +226 -0
  102. morphogen/homogenization/core.py +458 -0
  103. morphogen/homogenization/coupled.py +1135 -0
  104. morphogen/homogenization/crystal.py +2967 -0
  105. morphogen/homogenization/dilatation.py +454 -0
  106. morphogen/homogenization/elements.py +157 -0
  107. morphogen/homogenization/fatigue.py +768 -0
  108. morphogen/homogenization/fe.py +1739 -0
  109. morphogen/homogenization/fenicsx.py +307 -0
  110. morphogen/homogenization/fft.py +499 -0
  111. morphogen/homogenization/fft_nonlinear.py +391 -0
  112. morphogen/homogenization/finite.py +613 -0
  113. morphogen/homogenization/flow.py +361 -0
  114. morphogen/homogenization/frames.py +1125 -0
  115. morphogen/homogenization/gpu.py +1241 -0
  116. morphogen/homogenization/harmonic.py +427 -0
  117. morphogen/homogenization/identification.py +579 -0
  118. morphogen/homogenization/kernels.py +760 -0
  119. morphogen/homogenization/laws.py +2061 -0
  120. morphogen/homogenization/materials.py +1080 -0
  121. morphogen/homogenization/mfront.py +589 -0
  122. morphogen/homogenization/networks.py +880 -0
  123. morphogen/homogenization/nonlinear.py +2612 -0
  124. morphogen/homogenization/ntfa.py +577 -0
  125. morphogen/homogenization/paths.py +476 -0
  126. morphogen/homogenization/photonic.py +467 -0
  127. morphogen/homogenization/poroelastic.py +212 -0
  128. morphogen/homogenization/porous.py +1120 -0
  129. morphogen/homogenization/postprocess.py +290 -0
  130. morphogen/homogenization/solvers.py +1140 -0
  131. morphogen/homogenization/tensors.py +240 -0
  132. morphogen/homogenization/voxel_fe.py +457 -0
  133. morphogen/homogenization/xfem.py +1016 -0
  134. morphogen/homogenization/zmat.py +1258 -0
  135. morphogen/iga/__init__.py +48 -0
  136. morphogen/iga/analysis.py +508 -0
  137. morphogen/iga/basis.py +214 -0
  138. morphogen/iga/geometry.py +501 -0
  139. morphogen/iga/homogenization.py +219 -0
  140. morphogen/iga/optimization.py +700 -0
  141. morphogen/iga/shapes.py +331 -0
  142. morphogen/image.py +128 -0
  143. morphogen/io/__init__.py +246 -0
  144. morphogen/io/amitex.py +741 -0
  145. morphogen/io/ebsd.py +881 -0
  146. morphogen/io/export.py +196 -0
  147. morphogen/io/geometry.py +158 -0
  148. morphogen/io/medit.py +147 -0
  149. morphogen/io/meshes.py +844 -0
  150. morphogen/io/metaimage.py +97 -0
  151. morphogen/io/mfront.py +1104 -0
  152. morphogen/io/native.py +57 -0
  153. morphogen/io/radioss.py +764 -0
  154. morphogen/io/solvers.py +371 -0
  155. morphogen/io/tables.py +278 -0
  156. morphogen/io/tiff.py +66 -0
  157. morphogen/io/vtk.py +701 -0
  158. morphogen/io/xdmf.py +200 -0
  159. morphogen/kernels/__init__.py +5 -0
  160. morphogen/kernels/annealing.py +192 -0
  161. morphogen/kernels/cells.py +69 -0
  162. morphogen/kernels/collective.py +87 -0
  163. morphogen/kernels/force_biased.py +595 -0
  164. morphogen/kernels/implicit.py +145 -0
  165. morphogen/kernels/leaves.py +132 -0
  166. morphogen/kernels/packing.py +304 -0
  167. morphogen/kernels/raster.py +279 -0
  168. morphogen/kernels/rsa.py +371 -0
  169. morphogen/kernels/union.py +135 -0
  170. morphogen/kernels/watershed.py +190 -0
  171. morphogen/laser/__init__.py +234 -0
  172. morphogen/laser/architectures.py +375 -0
  173. morphogen/laser/bending.py +216 -0
  174. morphogen/laser/cells.py +1694 -0
  175. morphogen/laser/design.py +940 -0
  176. morphogen/laser/figures.py +227 -0
  177. morphogen/laser/heat.py +804 -0
  178. morphogen/laser/materials.py +691 -0
  179. morphogen/laser/mechanics.py +1670 -0
  180. morphogen/laser/metallurgy.py +615 -0
  181. morphogen/laser/patterns.py +828 -0
  182. morphogen/laser/periodic.py +392 -0
  183. morphogen/laser/process.py +362 -0
  184. morphogen/laser/run.py +534 -0
  185. morphogen/laser/solid.py +216 -0
  186. morphogen/laser/specimen.py +200 -0
  187. morphogen/laser/structures.py +708 -0
  188. morphogen/learning/__init__.py +81 -0
  189. morphogen/learning/behaviour.py +398 -0
  190. morphogen/learning/data.py +328 -0
  191. morphogen/learning/learned.cpp +668 -0
  192. morphogen/learning/logarithmic.py +202 -0
  193. morphogen/learning/mfront.py +409 -0
  194. morphogen/learning/networks.py +767 -0
  195. morphogen/learning/run.py +212 -0
  196. morphogen/learning/standard.py +814 -0
  197. morphogen/learning/training.py +235 -0
  198. morphogen/mesh/__init__.py +29 -0
  199. morphogen/mesh/conforming.py +1423 -0
  200. morphogen/mesh/curved.py +600 -0
  201. morphogen/mesh/exact.py +1717 -0
  202. morphogen/mesh/octree.py +350 -0
  203. morphogen/mesh/polycrystal.py +1041 -0
  204. morphogen/mesh/polyhedra.py +677 -0
  205. morphogen/mesh/regularize.py +570 -0
  206. morphogen/mesh/surface.py +97 -0
  207. morphogen/mesh/tetra.py +512 -0
  208. morphogen/mesh/voxel.py +124 -0
  209. morphogen/micromorphic/__init__.py +31 -0
  210. morphogen/micromorphic/damage.py +359 -0
  211. morphogen/micromorphic/ductile.py +534 -0
  212. morphogen/micromorphic/finite.py +220 -0
  213. morphogen/micromorphic/microfoam.py +787 -0
  214. morphogen/micromorphic/space.py +341 -0
  215. morphogen/models/__init__.py +195 -0
  216. morphogen/models/affine.py +384 -0
  217. morphogen/models/automata.py +592 -0
  218. morphogen/models/base.py +500 -0
  219. morphogen/models/boolean.py +310 -0
  220. morphogen/models/bouligand.py +331 -0
  221. morphogen/models/branching.py +241 -0
  222. morphogen/models/combination.py +430 -0
  223. morphogen/models/deadleaves.py +766 -0
  224. morphogen/models/design.py +289 -0
  225. morphogen/models/ebsd.py +206 -0
  226. morphogen/models/fibers.py +1476 -0
  227. morphogen/models/foam.py +594 -0
  228. morphogen/models/gaussian.py +314 -0
  229. morphogen/models/growth.py +459 -0
  230. morphogen/models/hardcore.py +317 -0
  231. morphogen/models/hierarchical.py +269 -0
  232. morphogen/models/honeycomb.py +749 -0
  233. morphogen/models/implicit.py +177 -0
  234. morphogen/models/laminate.py +470 -0
  235. morphogen/models/lattice.py +351 -0
  236. morphogen/models/lattice_field.py +345 -0
  237. morphogen/models/levelset_foam.py +563 -0
  238. morphogen/models/nacre.py +411 -0
  239. morphogen/models/nested.py +924 -0
  240. morphogen/models/osteons.py +374 -0
  241. morphogen/models/pieces.py +167 -0
  242. morphogen/models/planar.py +126 -0
  243. morphogen/models/reconstruction.py +203 -0
  244. morphogen/models/scale_rich.py +1409 -0
  245. morphogen/models/scale_rich_3d.py +1616 -0
  246. morphogen/models/tessellation.py +735 -0
  247. morphogen/models/tiling_field.py +302 -0
  248. morphogen/models/tpms.py +197 -0
  249. morphogen/models/transparent.py +406 -0
  250. morphogen/models/union.py +141 -0
  251. morphogen/optimization/__init__.py +43 -0
  252. morphogen/optimization/cell.py +295 -0
  253. morphogen/optimization/filters.py +115 -0
  254. morphogen/optimization/mma.py +226 -0
  255. morphogen/optimization/run.py +219 -0
  256. morphogen/optimization/topology.py +632 -0
  257. morphogen/orientations.py +568 -0
  258. morphogen/parallel.py +599 -0
  259. morphogen/pipeline.py +978 -0
  260. morphogen/primitives.py +188 -0
  261. morphogen/results.py +564 -0
  262. morphogen/rve/__init__.py +73 -0
  263. morphogen/rve/report.py +627 -0
  264. morphogen/rve/scaling.py +363 -0
  265. morphogen/rve/study.py +1054 -0
  266. morphogen/rve/windows.py +345 -0
  267. morphogen/seeding.py +51 -0
  268. morphogen/settings.py +118 -0
  269. morphogen/stopping.py +48 -0
  270. morphogen/symmetry.py +384 -0
  271. morphogen/templates/activator_inhibitor.yaml +22 -0
  272. morphogen/templates/aggregation.yaml +23 -0
  273. morphogen/templates/boolean_cylinders.yaml +20 -0
  274. morphogen/templates/boolean_spheres.yaml +22 -0
  275. morphogen/templates/bouligand.yaml +28 -0
  276. morphogen/templates/cellular_automaton.yaml +25 -0
  277. morphogen/templates/coated_spheres.yaml +26 -0
  278. morphogen/templates/contact_fibers.yaml +27 -0
  279. morphogen/templates/cox_nanocomposite.yaml +22 -0
  280. morphogen/templates/cross_linked_fibers.yaml +26 -0
  281. morphogen/templates/curved_arcs.yaml +28 -0
  282. morphogen/templates/curved_fibers.yaml +24 -0
  283. morphogen/templates/dead_leaves.yaml +22 -0
  284. morphogen/templates/delaunay_network.yaml +22 -0
  285. morphogen/templates/dense_packing.yaml +22 -0
  286. morphogen/templates/diffusion.yaml +33 -0
  287. morphogen/templates/ebsd.yaml +34 -0
  288. morphogen/templates/ebsd_map.ctf +3087 -0
  289. morphogen/templates/fracture_composite.yaml +42 -0
  290. morphogen/templates/fracture_rubber.yaml +47 -0
  291. morphogen/templates/gaussian_excursion.yaml +17 -0
  292. morphogen/templates/graded_lattice.yaml +24 -0
  293. morphogen/templates/hardcore_fibers.yaml +22 -0
  294. morphogen/templates/hardcore_spheres.yaml +22 -0
  295. morphogen/templates/hierarchical_lattice.yaml +22 -0
  296. morphogen/templates/homogenization_acoustic_foam.yaml +36 -0
  297. morphogen/templates/homogenization_beremin.yaml +50 -0
  298. morphogen/templates/homogenization_cleavage.yaml +51 -0
  299. morphogen/templates/homogenization_cleavage_band.yaml +55 -0
  300. morphogen/templates/homogenization_contact.yaml +43 -0
  301. morphogen/templates/homogenization_crack_closure.yaml +49 -0
  302. morphogen/templates/homogenization_crystal_plasticity.yaml +50 -0
  303. morphogen/templates/homogenization_crystal_plasticity_fft.yaml +52 -0
  304. morphogen/templates/homogenization_crystallization.yaml +30 -0
  305. morphogen/templates/homogenization_debonding.yaml +43 -0
  306. morphogen/templates/homogenization_detwinning.yaml +58 -0
  307. morphogen/templates/homogenization_ductile_damage.yaml +47 -0
  308. morphogen/templates/homogenization_fatigue.yaml +40 -0
  309. morphogen/templates/homogenization_grain_fracture.yaml +56 -0
  310. morphogen/templates/homogenization_gyroid.yaml +30 -0
  311. morphogen/templates/homogenization_intergranular.yaml +43 -0
  312. morphogen/templates/homogenization_interphase.yaml +42 -0
  313. morphogen/templates/homogenization_mixed_loading.yaml +33 -0
  314. morphogen/templates/homogenization_ntfa.yaml +56 -0
  315. morphogen/templates/homogenization_piezoelectric.yaml +27 -0
  316. morphogen/templates/homogenization_polycrystal.yaml +30 -0
  317. morphogen/templates/homogenization_polycrystal_inclusions.yaml +30 -0
  318. morphogen/templates/homogenization_poroelastic.yaml +26 -0
  319. morphogen/templates/homogenization_rubber.yaml +40 -0
  320. morphogen/templates/homogenization_slip_cleavage.yaml +50 -0
  321. morphogen/templates/homogenization_spheres.yaml +31 -0
  322. morphogen/templates/homogenization_transport.yaml +29 -0
  323. morphogen/templates/homogenization_twinning.yaml +54 -0
  324. morphogen/templates/homogenization_viscoelastic.yaml +34 -0
  325. morphogen/templates/homogenization_viscoplastic.yaml +42 -0
  326. morphogen/templates/homogenization_voronoi.yaml +26 -0
  327. morphogen/templates/homogenization_xfem.yaml +23 -0
  328. morphogen/templates/hyperuniform_cells.yaml +24 -0
  329. morphogen/templates/laguerre.yaml +18 -0
  330. morphogen/templates/laser_bending.yaml +35 -0
  331. morphogen/templates/laser_cells.yaml +38 -0
  332. morphogen/templates/laser_corrugated.yaml +36 -0
  333. morphogen/templates/level_set_foam.yaml +29 -0
  334. morphogen/templates/menger_sponge.yaml +17 -0
  335. morphogen/templates/nacre.yaml +25 -0
  336. morphogen/templates/nucleation_growth.yaml +25 -0
  337. morphogen/templates/optimize_auxetic.yaml +29 -0
  338. morphogen/templates/optimize_auxetic_3d.yaml +27 -0
  339. morphogen/templates/optimize_bulk.yaml +23 -0
  340. morphogen/templates/optimize_conductivity.yaml +20 -0
  341. morphogen/templates/osteons.yaml +28 -0
  342. morphogen/templates/penetrable_spheres.yaml +21 -0
  343. morphogen/templates/poisson_fibers.yaml +21 -0
  344. morphogen/templates/random_laminate.yaml +26 -0
  345. morphogen/templates/random_lattice.yaml +27 -0
  346. morphogen/templates/random_walk_fibers.yaml +26 -0
  347. morphogen/templates/reaction_diffusion.yaml +22 -0
  348. morphogen/templates/reconstruction.yaml +22 -0
  349. morphogen/templates/rve_cellular_automaton.yaml +23 -0
  350. morphogen/templates/rve_crystal_plasticity_fft.yaml +51 -0
  351. morphogen/templates/rve_multiphysics.yaml +43 -0
  352. morphogen/templates/rve_poisson_fibers.yaml +22 -0
  353. morphogen/templates/rve_poisson_fibers_fe.yaml +33 -0
  354. morphogen/templates/rve_voronoi_windows.yaml +20 -0
  355. morphogen/templates/scale_rich_network.yaml +29 -0
  356. morphogen/templates/scale_rich_plates.yaml +30 -0
  357. morphogen/templates/sequential_dead_leaves.yaml +25 -0
  358. morphogen/templates/strut_lattice.yaml +21 -0
  359. morphogen/templates/tile_assembly.yaml +28 -0
  360. morphogen/templates/tpms.yaml +19 -0
  361. morphogen/templates/trabecular_bone.yaml +29 -0
  362. morphogen/templates/transparent_dead_leaves.yaml +23 -0
  363. morphogen/templates/vascular_tree.yaml +23 -0
  364. morphogen/templates/voronoi.yaml +20 -0
  365. morphogen/templates/wood.yaml +34 -0
  366. morphogen/templates/workflow.yaml +56 -0
  367. morphogen/texture.py +665 -0
  368. morphogen/theory.py +162 -0
  369. morphogen/viz/__init__.py +12 -0
  370. morphogen/viz/export.py +244 -0
  371. morphogen/viz/figures.py +707 -0
  372. morphogen/viz/png.py +148 -0
  373. morphogen/viz/sections.py +696 -0
  374. morphogen/viz/surfaces.py +1352 -0
  375. morphogen/viz/video.py +904 -0
  376. morphogen/viz/workflow.py +488 -0
  377. morphogen-1.0.0.dist-info/METADATA +2316 -0
  378. morphogen-1.0.0.dist-info/RECORD +381 -0
  379. morphogen-1.0.0.dist-info/WHEEL +4 -0
  380. morphogen-1.0.0.dist-info/entry_points.txt +5 -0
  381. morphogen-1.0.0.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,566 @@
1
+ """Acoustics of porous media: the parameters of the equivalent fluid of a rigid porous
2
+ frame from its microstructure, and the sound absorption of a layer.
3
+
4
+ Sound in the air (or any fluid) that saturates a rigid porous frame, at wavelengths much
5
+ longer than the pores, is that of an *equivalent fluid* with a complex dynamic density
6
+ ``rho(omega)`` (viscous and inertial effects) and bulk modulus ``K(omega)`` (thermal
7
+ effects). The semi-phenomenological model of Johnson, Koplik & Dashen (1987), Champoux &
8
+ Allard (1991) and Lafarge et al. (1997) — JCAL — gives them from six parameters of the
9
+ geometry of the pores, each the result of a static problem on the microstructure:
10
+
11
+ ============================ ============== =============================================
12
+ parameter symbol problem
13
+ ============================ ============== =============================================
14
+ porosity ``phi`` the volume fraction of the pores
15
+ static permeability ``k0`` Stokes flow (:mod:`~morphogen.homogenization.
16
+ flow`): Darcy's law, the resistivity
17
+ ``sigma = eta / k0``
18
+ tortuosity ``alpha_inf`` potential flow: the conduction of the pore
19
+ fluid between insulating walls, ``alpha_inf
20
+ = phi / s*`` (``s*``: its apparent
21
+ conductivity for a unit one)
22
+ viscous length ``Lambda`` the same field ``E``: ``2 int_V E^2 dV /
23
+ int_S E^2 dS``, measured by moving the walls
24
+ thermal length ``Lambda'`` ``2 V / S`` of the pores
25
+ static thermal permeability ``k0'`` ``lap(theta) = -1`` in the pores, ``theta =
26
+ 0`` on the walls: ``k0' = <theta>``
27
+ ============================ ============== =============================================
28
+
29
+ (:func:`acoustic_parameters`; lengths in the unit of the spacing of the image,
30
+ permeabilities in its square). With the time dependence ``exp(i omega t)``, the viscosity
31
+ ``eta``, density ``rho0``, Prandtl number ``Pr``, ratio of specific heats ``gamma`` and
32
+ pressure ``P0`` of the fluid,
33
+
34
+ rho(omega) = (alpha_inf rho0 / phi) [1 + (eta phi / (i omega rho0 alpha_inf k0))
35
+ sqrt(1 + i 4 alpha_inf^2 k0^2 rho0 omega / (eta Lambda^2 phi^2))],
36
+ K(omega) = (gamma P0 / phi) / (gamma - (gamma - 1) / [1 + (eta phi / (i omega rho0 Pr
37
+ k0')) sqrt(1 + i 4 k0'^2 rho0 omega Pr / (eta Lambda'^2 phi^2))])
38
+
39
+ (:func:`equivalent_fluid`; without ``k0'``, the model of Johnson, Champoux and Allard:
40
+ ``k0' = phi Lambda'^2 / 8``, the value of circular pores). The characteristic impedance
41
+ ``Z_c = sqrt(rho K)`` and the wavenumber ``k = omega sqrt(rho / K)`` give the surface
42
+ impedance ``-i Z_c cot(k d)`` of a layer of thickness ``d`` on a rigid wall and its
43
+ absorption coefficient at normal incidence, ``1 - |(Z_s - Z_0) / (Z_s + Z_0)|^2``
44
+ (:func:`absorption`). The exact responses of slits and of circular tubes
45
+ (:func:`pore_response`; Zwikker & Kosten 1949, Stinson 1991) are the references of the
46
+ model.
47
+
48
+ The static thermal permeability is also the mean survival time of a species that
49
+ diffuses in the pores and is absorbed by their walls, times its diffusivity (the trapping
50
+ constant of diffusion-controlled reactions: Torquato 2002).
51
+
52
+ References: D. L. Johnson, J. Koplik, R. Dashen, J. Fluid Mech. 176 (1987) 379; Y.
53
+ Champoux, J.-F. Allard, J. Appl. Phys. 70 (1991) 1975; D. Lafarge, P. Lemarinier, J.-F.
54
+ Allard, V. Tarnow, J. Acoust. Soc. Am. 102 (1997) 1995; J.-F. Allard, N. Atalla,
55
+ Propagation of Sound in Porous Media, 2nd ed., Wiley (2009); M. R. Stinson, J. Acoust.
56
+ Soc. Am. 89 (1991) 550; C. Perrot, F. Chevillotte, R. Panneton, J. Appl. Phys. 103
57
+ (2008) 024909.
58
+ """
59
+
60
+ from __future__ import annotations
61
+
62
+ from dataclasses import dataclass
63
+
64
+ import numpy as np
65
+ from numba import njit, prange
66
+
67
+ from morphogen.homogenization.core import VOIGT_NAMES, Loading
68
+ from morphogen.homogenization.elements import VOIGT
69
+ from morphogen.homogenization.flow import permeability_tensor, pore_mask
70
+ from morphogen.homogenization.materials import Material
71
+ from morphogen.image import VoxelImage
72
+ from morphogen.stopping import checkpoint
73
+
74
+ __all__ = [
75
+ "AIR",
76
+ "PARAMETERS",
77
+ "Fluid",
78
+ "absorption",
79
+ "acoustic_parameters",
80
+ "along_axis",
81
+ "equivalent_fluid",
82
+ "pore_response",
83
+ "thermal_permeability",
84
+ ]
85
+
86
+ #: The scalar results of :func:`acoustic_parameters` (columns of the tables of results
87
+ #: and quantities of the statistics of RVE studies)
88
+ PARAMETERS = (
89
+ "porosity",
90
+ "permeability",
91
+ "tortuosity",
92
+ "viscous_length",
93
+ "thermal_length",
94
+ "thermal_permeability",
95
+ "specific_surface",
96
+ *(f"permeability{i}" for i in (1, 2, 3)),
97
+ *(f"tortuosity{i}" for i in (1, 2, 3)),
98
+ *(f"viscous_length{i}" for i in (1, 2, 3)),
99
+ *(f"k{name}" for name in VOIGT_NAMES),
100
+ )
101
+
102
+
103
+ @dataclass(frozen=True)
104
+ class Fluid:
105
+ """The fluid that saturates the pores (SI units): ``density``, dynamic ``viscosity``,
106
+ ratio of specific heats ``heat_ratio``, Prandtl number ``prandtl`` and static
107
+ ``pressure``. The default is air at 20 °C."""
108
+
109
+ density: float = 1.204
110
+ viscosity: float = 1.81e-5
111
+ heat_ratio: float = 1.4
112
+ prandtl: float = 0.71
113
+ pressure: float = 101325.0
114
+
115
+ def __post_init__(self) -> None:
116
+ for name in ("density", "viscosity", "heat_ratio", "prandtl", "pressure"):
117
+ if not getattr(self, name) > 0.0:
118
+ raise ValueError(f"fluid.{name}: positive")
119
+ if not self.heat_ratio >= 1.0:
120
+ raise ValueError("fluid.heat_ratio: at least 1")
121
+
122
+ @property
123
+ def sound_speed(self) -> float:
124
+ """The adiabatic speed of sound, ``sqrt(gamma P0 / rho0)``."""
125
+ return float(np.sqrt(self.heat_ratio * self.pressure / self.density))
126
+
127
+ @property
128
+ def impedance(self) -> float:
129
+ """The characteristic impedance ``rho0 c0``."""
130
+ return self.density * self.sound_speed
131
+
132
+
133
+ #: Air at 20 °C and atmospheric pressure
134
+ AIR = Fluid()
135
+
136
+
137
+ @njit(cache=True, parallel=True)
138
+ def _wall_laplacian(theta, fluid, out): # pragma: no cover
139
+ """``out = sum over the six neighbours of (theta - neighbour)`` in the pores, the
140
+ value beyond a wall the mirror ``-theta`` (zero on the wall, midway)."""
141
+ nx, ny, nz = fluid.shape
142
+ for x in prange(nx):
143
+ xm, xp = (x - 1) % nx, (x + 1) % nx
144
+ for y in range(ny):
145
+ ym, yp = (y - 1) % ny, (y + 1) % ny
146
+ for z in range(nz):
147
+ if not fluid[x, y, z]:
148
+ out[x, y, z] = 0.0
149
+ continue
150
+ zm, zp = (z - 1) % nz, (z + 1) % nz
151
+ t = theta[x, y, z]
152
+ s = 0.0
153
+ s += t - theta[xm, y, z] if fluid[xm, y, z] else 2.0 * t
154
+ s += t - theta[xp, y, z] if fluid[xp, y, z] else 2.0 * t
155
+ s += t - theta[x, ym, z] if fluid[x, ym, z] else 2.0 * t
156
+ s += t - theta[x, yp, z] if fluid[x, yp, z] else 2.0 * t
157
+ s += t - theta[x, y, zm] if fluid[x, y, zm] else 2.0 * t
158
+ s += t - theta[x, y, zp] if fluid[x, y, zp] else 2.0 * t
159
+ out[x, y, z] = s
160
+
161
+
162
+ def _walls(fluid: np.ndarray) -> np.ndarray:
163
+ """The number of faces of each voxel of the pores that are walls (0 in the solid)."""
164
+ count = np.zeros(fluid.shape)
165
+ for axis in range(3):
166
+ if fluid.shape[axis] == 1:
167
+ continue # a planar image: its own neighbour along that axis
168
+ for shift in (1, -1):
169
+ count += ~np.roll(fluid, shift, axis=axis)
170
+ return np.where(fluid, count, 0.0)
171
+
172
+
173
+ def _pores(image: VoxelImage, materials, pores) -> tuple[np.ndarray, float]:
174
+ """The mask of the pores of an image of cubic voxels (the cell of a periodic medium),
175
+ and their size."""
176
+ fluid = np.ascontiguousarray(pore_mask(image, materials, pores))
177
+ spacing = np.asarray(image.spacing, dtype=float)
178
+ if not np.allclose(spacing, spacing[0], rtol=1e-9):
179
+ raise ValueError(f"acoustics: cubic voxels, got the spacing {tuple(spacing)}")
180
+ return fluid, float(spacing[0])
181
+
182
+
183
+ def thermal_permeability(
184
+ image: VoxelImage, materials=None, *, pores=None, tol: float = 1e-8, maxiter: int | None = None
185
+ ) -> float:
186
+ """The static thermal permeability ``k0'`` of the pores of a periodic image (the void
187
+ phases of ``materials``, or the phases ``pores``): the mean over the whole image of
188
+ the solution of ``lap(theta) = -1`` in the pores with ``theta = 0`` on their walls
189
+ (finite differences on the voxels, the walls midway between them, second order;
190
+ conjugate gradients). In the squared unit of the spacing. It is the permeability of the flow
191
+ along a pore of constant section (a slit of width ``H``: ``H^2 / 12``; a tube of radius
192
+ ``R``: ``R^2 / 8``), and the mean survival time of a diffusing species that the walls
193
+ absorb, times its diffusivity and the porosity."""
194
+ fluid, h = _pores(image, materials, pores)
195
+ if not fluid.any():
196
+ return 0.0
197
+ walls = _walls(fluid)
198
+ if not walls.any():
199
+ raise ValueError("thermal permeability: pores without a wall")
200
+ # the diagonal of the operator: 1 per neighbour in the pores, 2 per wall
201
+ diagonal = np.zeros(fluid.shape)
202
+ for axis in range(3):
203
+ if fluid.shape[axis] > 1:
204
+ diagonal += 2.0
205
+ diagonal = np.where(fluid, diagonal + walls, 1.0)
206
+ rhs = fluid.astype(float)
207
+ theta = np.zeros(fluid.shape)
208
+ r = rhs.copy()
209
+ z = r / diagonal
210
+ p = z.copy()
211
+ rz = float(np.vdot(r, z))
212
+ norm = float(np.linalg.norm(rhs))
213
+ ap = np.empty(fluid.shape)
214
+ limit = int(maxiter) if maxiter else 20 * max(fluid.shape) + 2000
215
+ for _ in range(limit):
216
+ checkpoint()
217
+ _wall_laplacian(p, fluid, ap)
218
+ alpha = rz / float(np.vdot(p, ap))
219
+ theta += alpha * p
220
+ r -= alpha * ap
221
+ if float(np.linalg.norm(r)) <= tol * norm:
222
+ break
223
+ z = r / diagonal
224
+ rz_new = float(np.vdot(r, z))
225
+ p = z + (rz_new / rz) * p
226
+ rz = rz_new
227
+ # the mirror of a parabola leaves theta = 1 / 8 on a plane wall instead of zero: that
228
+ # constant is taken out of the pores
229
+ return float((theta.mean() - fluid.mean() / 8.0) * h * h)
230
+
231
+
232
+ def _distance(mask: np.ndarray) -> np.ndarray:
233
+ """The distance (in voxels) of the centre of each voxel of ``mask`` to the nearest
234
+ centre outside it, on the periodic image (zero outside)."""
235
+ from scipy import ndimage
236
+
237
+ pad = [(3, 3) if n > 1 else (0, 0) for n in mask.shape]
238
+ distance = ndimage.distance_transform_edt(np.pad(mask, pad, mode="wrap"))
239
+ inner = tuple(slice(3, -3) if n > 1 else slice(None) for n in mask.shape)
240
+ return distance[inner]
241
+
242
+
243
+ def _potential_flow(image: VoxelImage, fluid: np.ndarray, tol: float):
244
+ """The tortuosity and the viscous characteristic length along each axis, and the
245
+ area of the walls per unit volume: the conduction of the pore fluid between
246
+ insulating walls.
247
+
248
+ The viscous length is ``2 int_V E^2 dV / int_S E^2 dS``; the integral over the walls
249
+ is the rate at which the conductivity ``s*`` falls when the walls move into the
250
+ pores, ``d ln s* / d delta = -2 / Lambda`` (Johnson, Koplik & Schwartz 1986), which
251
+ stairs of voxels allow to measure where they do not allow a surface integral: the
252
+ pores are dilated and eroded by one voxel (the voxels within reach of the other
253
+ phase), the mean displacement of the walls between the two is their change of
254
+ volume over the area of the walls, and ``Lambda = 2 delta / ln(s*+ / s*-)``. If the
255
+ erosion closes the pores along an axis, the dilation alone is used."""
256
+ from morphogen.analysis import specific_surface
257
+ from morphogen.homogenization.apparent import make_problem
258
+
259
+ mats = {1: Material(conductivity=1.0), 0: Material(void=True)}
260
+
261
+ def conductivities(mask):
262
+ binary = VoxelImage(mask.astype(np.uint8), image.spacing, periodic=True)
263
+ if not mask.any():
264
+ return np.zeros(3), binary
265
+ problem = make_problem(binary, mats, "thermal", tol=tol)
266
+ out = np.zeros(3)
267
+ for axis in range(3):
268
+ if mask.shape[axis] == 1: # a planar image: a uniform field along its axis
269
+ out[axis] = float(mask.mean())
270
+ continue
271
+ unit = np.zeros(3)
272
+ unit[axis] = 1.0
273
+ out[axis] = float(-problem.solve(Loading.gradient(unit)).stress[axis])
274
+ return out, binary
275
+
276
+ porosity = float(fluid.mean())
277
+ sigma, binary = conductivities(fluid)
278
+ surface = float(specific_surface(binary, 1)) # walls per unit volume (Crofton)
279
+ tortuosity, length = np.ones(3), np.full(3, np.inf)
280
+ if not surface > 0.0: # no wall: a fluid alone
281
+ return tortuosity, length, surface
282
+ dilated = fluid | (_distance(~fluid) <= 1.0)
283
+ eroded = fluid & (_distance(fluid) > 1.5)
284
+ plus, _ = conductivities(dilated)
285
+ minus, _ = conductivities(eroded)
286
+ for axis in range(3):
287
+ if not sigma[axis] > 1e-12 * porosity: # no path along this axis
288
+ tortuosity[axis], length[axis] = np.inf, 0.0
289
+ continue
290
+ tortuosity[axis] = porosity / sigma[axis]
291
+ if fluid.shape[axis] == 1:
292
+ length[axis] = 2.0 * porosity / surface
293
+ elif minus[axis] > 1e-3 * sigma[axis]:
294
+ shift = (float(dilated.mean()) - float(eroded.mean())) / surface
295
+ length[axis] = 2.0 * shift / np.log(plus[axis] / minus[axis])
296
+ else: # the erosion closes the pores
297
+ shift = (float(dilated.mean()) - porosity) / surface
298
+ length[axis] = 2.0 * shift / np.log(plus[axis] / sigma[axis])
299
+ return tortuosity, length, surface
300
+
301
+
302
+ def acoustic_parameters(
303
+ image: VoxelImage,
304
+ materials=None,
305
+ *,
306
+ pores=None,
307
+ tol: float = 1e-5,
308
+ thermal: bool = True,
309
+ **flow_options,
310
+ ) -> dict:
311
+ """The parameters of the equivalent fluid of a porous image (see the module): the
312
+ pores are the void phases of ``materials``, or the phases ``pores``; the frame is
313
+ rigid and motionless. Periodic images of cubic voxels.
314
+
315
+ Returns the ``porosity``; the static viscous ``permeability_tensor`` (3 x 3), its
316
+ diagonal ``permeability1`` ... ``3`` and their mean ``permeability``; the
317
+ ``tortuosity1`` ... ``3`` along the axes and their mean ``tortuosity``; the viscous
318
+ characteristic lengths ``viscous_length1`` ... ``3`` and their mean
319
+ ``viscous_length``; the ``thermal_length`` ``2 V / S``; the ``thermal_permeability``
320
+ (``thermal=False``: left out); the ``specific_surface`` of the walls (per unit volume
321
+ of the image). Lengths in the unit of the spacing, permeabilities in its square: an
322
+ image in metres gives SI values. ``tol``: the tolerance of the flows (their mean
323
+ velocity) and of the conduction problems; ``flow_options``: the other options of
324
+ :func:`~morphogen.homogenization.flow.stokes_flow`."""
325
+ fluid, _ = _pores(image, materials, pores)
326
+ porosity = float(fluid.mean())
327
+ if not 0.0 < porosity:
328
+ raise ValueError("acoustics: no pore in the image")
329
+ # the means: over the axes of the image (those in its plane for a planar one)
330
+ axes = tuple(a for a in range(3) if fluid.shape[a] > 1) or (0, 1, 2)
331
+ flow = permeability_tensor(image, materials, pores=pores, tol=tol, **flow_options)
332
+ tortuosity, viscous, surface = _potential_flow(image, fluid, min(tol, 1e-6))
333
+ out = {
334
+ "porosity": porosity,
335
+ "permeability_tensor": flow["tensor"],
336
+ "specific_surface": surface,
337
+ "thermal_length": float(2.0 * porosity / surface) if surface > 0.0 else float("inf"),
338
+ }
339
+ diagonal = np.diag(flow["tensor"])
340
+ for name, values in (("permeability", diagonal), ("tortuosity", tortuosity),
341
+ ("viscous_length", viscous)): # fmt: skip
342
+ out[name] = float(np.mean([values[a] for a in axes]))
343
+ out.update({f"{name}{a + 1}": float(values[a]) for a in range(3)})
344
+ if thermal:
345
+ out["thermal_permeability"] = thermal_permeability(image, materials, pores=pores)
346
+ out.update(
347
+ {f"k{n}": float(flow["tensor"][i, j]) for (i, j), n in zip(VOIGT, VOIGT_NAMES, strict=True)}
348
+ )
349
+ out["steps"] = flow["steps"]
350
+ out["error"] = flow["error"]
351
+ return out
352
+
353
+
354
+ def along_axis(parameters: dict, axis: int | None = None) -> dict:
355
+ """The six parameters of :func:`equivalent_fluid` from the results of
356
+ :func:`acoustic_parameters`: those along ``axis`` (0, 1 or 2: sound that travels
357
+ along it), or their means over the axes (an isotropic medium)."""
358
+ suffix = "" if axis is None else str(int(axis) + 1)
359
+ out = {
360
+ "porosity": parameters["porosity"],
361
+ "permeability": parameters[f"permeability{suffix}"],
362
+ "tortuosity": parameters[f"tortuosity{suffix}"],
363
+ "viscous_length": parameters[f"viscous_length{suffix}"],
364
+ "thermal_length": parameters["thermal_length"],
365
+ }
366
+ if "thermal_permeability" in parameters:
367
+ out["thermal_permeability"] = parameters["thermal_permeability"]
368
+ return out
369
+
370
+
371
+ def _hertz(frequencies) -> np.ndarray:
372
+ f = np.atleast_1d(np.asarray(frequencies, dtype=float))
373
+ if f.ndim != 1 or not f.size or np.any(~np.isfinite(f)) or np.any(f <= 0):
374
+ raise ValueError("frequencies: positive values (Hz)")
375
+ return f
376
+
377
+
378
+ def equivalent_fluid(
379
+ frequencies,
380
+ *,
381
+ porosity: float,
382
+ permeability: float,
383
+ tortuosity: float,
384
+ viscous_length: float,
385
+ thermal_length: float,
386
+ thermal_permeability: float | None = None,
387
+ fluid: Fluid = AIR,
388
+ ) -> dict:
389
+ """The equivalent fluid of a rigid porous frame at the ``frequencies`` (Hz), by the
390
+ model of Johnson, Champoux, Allard and Lafarge (see the module; SI units: lengths in
391
+ metres, permeabilities in square metres): its complex ``density`` and
392
+ ``bulk_modulus`` (time dependence ``exp(i omega t)``), its characteristic
393
+ ``impedance`` and ``wavenumber``, and the ``resistivity`` ``eta / k0`` (Pa s/m²).
394
+ Without ``thermal_permeability``, that of circular pores, ``phi Lambda'^2 / 8``."""
395
+ f = _hertz(frequencies)
396
+ for name, value in (("porosity", porosity), ("permeability", permeability),
397
+ ("tortuosity", tortuosity), ("viscous_length", viscous_length),
398
+ ("thermal_length", thermal_length)): # fmt: skip
399
+ if not (np.isfinite(value) and value > 0.0):
400
+ raise ValueError(f"{name}: a positive value")
401
+ if not porosity <= 1.0 or not tortuosity >= 1.0 - 1e-9:
402
+ raise ValueError("porosity at most 1, tortuosity at least 1")
403
+ k0p = (
404
+ porosity * thermal_length**2 / 8.0 if thermal_permeability is None else thermal_permeability
405
+ )
406
+ if not k0p > 0.0:
407
+ raise ValueError("thermal_permeability: a positive value")
408
+ omega = 2.0 * np.pi * f
409
+ eta, rho0, pr = fluid.viscosity, fluid.density, fluid.prandtl
410
+ gamma, p0 = fluid.heat_ratio, fluid.pressure
411
+ viscous = np.sqrt(
412
+ 1.0 + 4j * tortuosity**2 * permeability**2 * rho0 * omega
413
+ / (eta * viscous_length**2 * porosity**2)
414
+ ) # fmt: skip
415
+ density = (tortuosity * rho0 / porosity) * (
416
+ 1.0 + eta * porosity / (1j * omega * rho0 * tortuosity * permeability) * viscous
417
+ )
418
+ thermal = np.sqrt(
419
+ 1.0 + 4j * k0p**2 * rho0 * omega * pr / (eta * thermal_length**2 * porosity**2)
420
+ )
421
+ beta = 1.0 + eta * porosity / (1j * omega * rho0 * pr * k0p) * thermal
422
+ bulk = (gamma * p0 / porosity) / (gamma - (gamma - 1.0) / beta)
423
+ return {
424
+ "frequencies": f,
425
+ "density": density,
426
+ "bulk_modulus": bulk,
427
+ "impedance": np.sqrt(density * bulk),
428
+ "wavenumber": omega * np.sqrt(density / bulk),
429
+ "resistivity": float(eta / permeability),
430
+ }
431
+
432
+
433
+ def pore_response(frequencies, shape: str, size: float, *, fluid: Fluid = AIR) -> dict:
434
+ """The exact dynamic ``density`` and ``bulk_modulus`` of the fluid in straight pores
435
+ of constant section at the ``frequencies`` (Hz): ``shape="slit"`` between two planes
436
+ ``size`` apart, or ``"tube"`` of radius ``size`` (Zwikker & Kosten; Stinson 1991). A
437
+ frame of such pores along the sound, of porosity ``phi``, has these divided by
438
+ ``phi``; its parameters are ``k0 = k0' = phi size^2 / 12`` and ``Lambda = Lambda' =
439
+ size`` (slits), ``phi size^2 / 8`` and ``size`` (tubes), with a tortuosity of 1."""
440
+ from scipy.special import jv
441
+
442
+ f = _hertz(frequencies)
443
+ if not size > 0.0:
444
+ raise ValueError("size: positive")
445
+ omega = 2.0 * np.pi * f
446
+
447
+ def mean_profile(q): # the mean over the section of the response to a unit forcing
448
+ if shape == "slit":
449
+ s = 0.5 * size * np.sqrt(1j * q)
450
+ return 1.0 - np.tanh(s) / s
451
+ if shape == "tube":
452
+ s = size * np.sqrt(-1j * q)
453
+ return 1.0 - 2.0 * jv(1, s) / (s * jv(0, s))
454
+ raise ValueError("shape: 'slit' or 'tube'")
455
+
456
+ viscous = mean_profile(omega * fluid.density / fluid.viscosity)
457
+ thermal = mean_profile(omega * fluid.density * fluid.prandtl / fluid.viscosity)
458
+ gamma = fluid.heat_ratio
459
+ return {
460
+ "frequencies": f,
461
+ "density": fluid.density / viscous,
462
+ "bulk_modulus": gamma * fluid.pressure / (gamma - (gamma - 1.0) * thermal),
463
+ }
464
+
465
+
466
+ def surface_absorption(impedance, incidence=0.0, *, fluid: Fluid = AIR, limit: float | None = None):
467
+ """The absorption coefficient of a surface of normal ``impedance`` (a number or an
468
+ array; a locally reacting surface) for a plane wave at the angle ``incidence`` from
469
+ its normal (radians), ``1 - |(Z cos θ - Z0) / (Z cos θ + Z0)|²``, or in a diffuse
470
+ field (``incidence="diffuse"``): Paris' average ``∫ α(θ) sin 2θ dθ`` over the angles
471
+ up to ``limit`` (by default π/2), normalized. For a real impedance ``Z = ζ Z0`` it is
472
+ ``8 / ζ² (1 + ζ - 1 / (1 + ζ) - 2 ln(1 + ζ))``."""
473
+ z = np.asarray(impedance, dtype=complex) / fluid.impedance
474
+
475
+ def at(theta):
476
+ cosine = np.cos(theta)
477
+ return 1.0 - np.abs((z * cosine - 1.0) / (z * cosine + 1.0)) ** 2
478
+
479
+ if isinstance(incidence, str):
480
+ return _diffuse(at, incidence, limit)[0]
481
+ return at(_angle(incidence))
482
+
483
+
484
+ def _angle(incidence) -> float:
485
+ theta = float(incidence)
486
+ if not 0.0 <= theta < 0.5 * np.pi:
487
+ raise ValueError("incidence: an angle from the normal in [0, π/2) (radians), or 'diffuse'")
488
+ return theta
489
+
490
+
491
+ def _diffuse(at, incidence: str, limit):
492
+ """Paris' average of the absorption ``at(θ)`` over the angles of a diffuse field, the
493
+ angles of the quadrature and the absorption at each."""
494
+ if incidence != "diffuse":
495
+ raise ValueError("incidence: an angle from the normal (radians), or 'diffuse'")
496
+ top = 0.5 * np.pi if limit is None else float(limit)
497
+ if not 0.0 < top <= 0.5 * np.pi:
498
+ raise ValueError("limit: an angle in (0, π/2]")
499
+ nodes, weights = np.polynomial.legendre.leggauss(64)
500
+ angles = 0.5 * top * (nodes + 1.0)
501
+ weights = 0.5 * top * weights * np.sin(2.0 * angles)
502
+ values = np.array([at(theta) for theta in angles])
503
+ return np.tensordot(weights, values, axes=1) / weights.sum(), angles, values
504
+
505
+
506
+ def absorption(
507
+ frequencies,
508
+ thickness: float,
509
+ *,
510
+ incidence=0.0,
511
+ transverse: dict | None = None,
512
+ limit: float | None = None,
513
+ fluid: Fluid = AIR,
514
+ **parameters,
515
+ ) -> dict:
516
+ """The sound absorption of a layer of ``thickness`` (m) of a rigid porous frame on a
517
+ rigid wall, at the ``frequencies`` (Hz): its ``absorption`` coefficient,
518
+ ``surface_impedance`` and ``reflection`` coefficient, with the equivalent fluid of
519
+ :func:`equivalent_fluid` (its ``parameters``: those of :func:`along_axis` across the
520
+ layer).
521
+
522
+ ``incidence``: the angle of the plane wave from the normal of the layer (radians; 0
523
+ by default), or ``"diffuse"``: the absorption in a diffuse field, Paris' average of
524
+ the absorption over the angles up to ``limit`` (by default π/2; ``absorption`` is
525
+ then that average, with the ``angles`` of the quadrature and the
526
+ ``absorption_by_angle``). The wave is refracted in the layer: with the wavenumber
527
+ ``k0 sin θ`` along it, ``k_x² = ρ_n (ω² / K - k0² sin²θ / ρ_t)`` across it and ``Z_s =
528
+ -i ω ρ_n / (k_x tan(k_x d))``. ``transverse``: the parameters along the layer of an
529
+ anisotropic frame (those of :func:`along_axis` for an axis in its plane: its density
530
+ ``ρ_t`` there differs from ``ρ_n`` across it; fibres, layered pores), by default
531
+ those across it (an isotropic frame)."""
532
+ if not thickness > 0.0:
533
+ raise ValueError("thickness: positive")
534
+ medium = equivalent_fluid(frequencies, fluid=fluid, **parameters)
535
+ omega = 2.0 * np.pi * medium["frequencies"]
536
+ density, bulk = medium["density"], medium["bulk_modulus"]
537
+ along = density
538
+ if transverse is not None:
539
+ along = equivalent_fluid(frequencies, fluid=fluid, **transverse)["density"]
540
+
541
+ def surface(theta):
542
+ slip = (omega / fluid.sound_speed * np.sin(theta)) ** 2
543
+ across = np.sqrt(density * (omega**2 / bulk - slip / along))
544
+ return -1j * omega * density / (across * np.tan(across * thickness))
545
+
546
+ def reflection(theta):
547
+ z = surface(theta) * np.cos(theta)
548
+ return (z - fluid.impedance) / (z + fluid.impedance)
549
+
550
+ if isinstance(incidence, str):
551
+ mean, angles, values = _diffuse(
552
+ lambda theta: 1.0 - np.abs(reflection(theta)) ** 2, incidence, limit
553
+ )
554
+ return {
555
+ "frequencies": medium["frequencies"],
556
+ "absorption": mean,
557
+ "angles": angles,
558
+ "absorption_by_angle": values,
559
+ }
560
+ theta = _angle(incidence)
561
+ return {
562
+ "frequencies": medium["frequencies"],
563
+ "absorption": 1.0 - np.abs(reflection(theta)) ** 2,
564
+ "surface_impedance": surface(theta),
565
+ "reflection": reflection(theta),
566
+ }