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
morphogen/rve/study.py ADDED
@@ -0,0 +1,1054 @@
1
+ """Statistical RVE analysis of apparent properties (Dirrenberger et al. 2014, sec. 4-5).
2
+
3
+ A *series* gathers the realizations of one property under one boundary condition, at
4
+ several volumes. For every series the analysis gives:
5
+
6
+ * the number of realizations, the mean and the standard deviation ``D_Z(V)`` per volume,
7
+ with the intervals ``[Zbar - 2 D_Z, Zbar + 2 D_Z]`` (Tables 3-4);
8
+ * the relative error of the sample, ``eps_rel = 2 D_Z(V) / (Zbar sqrt(n))`` (Table 8);
9
+ * the fit of ``D_Z^2(V) = K V^-gamma`` with gamma free (Table 9), and with gamma imposed
10
+ when requested, e.g. the theoretical 2/3 of Poisson fibres (Table 10);
11
+ * the RVE volume ``V_RVE = (4 K / (eps^2 Zbar^2 n))^(1/gamma)`` (eq. 87) for each pair
12
+ (eps_rel, n), its edge, the mean number of objects it contains (fibres, grains...) when
13
+ the model provides it, and bootstrap confidence intervals;
14
+ * the number of realizations of each sampled volume needed for each precision;
15
+ * the statistical isotropy criterion of the mean response per volume (eqs. 72-74).
16
+
17
+ Across boundary conditions it gives the discrepancy ``D(Z) = (Zmax - Zmin) / Zmin``
18
+ between their mean values (eq. 69) and, when the phases are known, the bounds.
19
+ ``Zbar`` in the RVE formula is the mean at the largest volume, as in the paper.
20
+
21
+ Stiffness and compliance (:class:`TensorStatistics`). When the realizations have their
22
+ apparent stiffness ``C`` (the columns ``stiffness.<bc>.C11`` ... ``C66`` of the results),
23
+ each boundary condition gets, per volume, the mean stiffness ``Cbar`` over the
24
+ realizations and the standard deviation of each of its components, and the compliance
25
+ ``S = Cbar^-1``: the inverse of the mean stiffness, so that ``S Cbar = I``, not the mean
26
+ of the compliances of the realizations ``<C^-1>`` (kept as ``mean_compliance``; larger,
27
+ ``<C^-1> >= <C>^-1`` by Jensen's inequality, by a term of the order of the relative
28
+ variance; under SUBC its inverse is Huet's lower estimate), with the standard deviation
29
+ of each component of the compliances ``C^-1`` of the realizations. Each component of
30
+ ``C`` and of the compliances is also analysed as a series (variance fit, RVE sizes, no
31
+ bootstrap), the RVE sizes kept for the diagonal components and those whose mean the
32
+ realizations of the largest volume distinguish from zero (Student's t test at the level of
33
+ the study): the couplings that vanish on average have no relative precision. Notation:
34
+ morphoGen's Voigt order 11, 22, 33, 23, 31, 12 with engineering shears
35
+ (:data:`morphogen.homogenization.postprocess.NOTATION`). The conductivity tensor (the
36
+ columns ``conductivity_tensor.<bc>.C11`` ... ``C33``) has the same statistics, its inverse
37
+ the resistivity (:data:`CONDUCTIVITY_NOTATION`), and so has the tensor of every other
38
+ transport phenomenon (:data:`TRANSPORT_TENSORS`: ``electrical_conductivity_tensor``,
39
+ ``permittivity_tensor``, ``permeability_tensor``, ``diffusivity_tensor``). By the window method
40
+ (:mod:`morphogen.rve.windows`) the windows of one realization are the realizations; with
41
+ tilings shifted around the periodic realization, those of all the tilings, their means
42
+ over all, their variances pooled within the tilings and their counts those of one tiling
43
+ (:mod:`morphogen.rve.scaling`). The squares of a planar image have areas for volumes, and
44
+ for edges their roots (``dimension`` 2).
45
+ """
46
+
47
+ from __future__ import annotations
48
+
49
+ import math
50
+ import re
51
+ from collections.abc import Callable
52
+ from dataclasses import dataclass, field, replace
53
+
54
+ import numpy as np
55
+
56
+ from morphogen.homogenization.materials import TRANSPORT, TRANSPORT_LAWS
57
+ from morphogen.rve.scaling import (
58
+ ScalingLaw,
59
+ SizeStatistics,
60
+ _moments,
61
+ _pooled_variance,
62
+ ensemble_statistics,
63
+ fit_scaling_law,
64
+ point_variance,
65
+ )
66
+
67
+ META_COLUMNS = {
68
+ "size_index",
69
+ "size",
70
+ "volume",
71
+ "realization",
72
+ "seed",
73
+ "time_s",
74
+ "n_spheres",
75
+ "n_segments",
76
+ "n_cells",
77
+ "n_modes",
78
+ }
79
+
80
+
81
+ def _is_meta(column: str) -> bool:
82
+ """Columns not analysed by default: identifiers, counts, timings, mesh data, phase
83
+ fractions of the homogenized samples and tensor components (``<p>.<bc>.<entry>``)."""
84
+ return (
85
+ column in META_COLUMNS or column.startswith(("mesh_", "fraction_")) or column.count(".") > 1
86
+ )
87
+
88
+
89
+ def _isotropy(prop: str, response: np.ndarray) -> float:
90
+ from morphogen.homogenization.apparent import bulk_isotropy, shear_isotropy, thermal_isotropy
91
+
92
+ if prop.startswith("bulk"):
93
+ return bulk_isotropy(response)
94
+ if prop.startswith("shear"):
95
+ return shear_isotropy(response)
96
+ if prop.partition(".")[0] in TRANSPORT.values(): # a flux under a gradient along x
97
+ return thermal_isotropy(response, 0)
98
+ return math.nan
99
+
100
+
101
+ @dataclass
102
+ class Series:
103
+ """Realizations of a property (under one boundary condition) at several volumes.
104
+
105
+ ``response`` optionally holds the macroscopic response of every realization: the
106
+ 3 x 3 average stress (or strain under SUBC), or the average flux vector; it is used
107
+ for the isotropy criteria.
108
+ """
109
+
110
+ property: str
111
+ bc: str
112
+ volume: np.ndarray
113
+ value: np.ndarray
114
+ response: np.ndarray | None = None
115
+
116
+ def __post_init__(self) -> None:
117
+ self.volume = np.asarray(self.volume, dtype=float)
118
+ self.value = np.asarray(self.value, dtype=float)
119
+ if self.volume.shape != self.value.shape or self.volume.ndim != 1:
120
+ raise ValueError("a series needs one volume per value")
121
+ ok = np.isfinite(self.value) & np.isfinite(self.volume) & (self.volume > 0)
122
+ if self.response is not None:
123
+ self.response = np.asarray(self.response, dtype=float)
124
+ if len(self.response) != len(self.value):
125
+ raise ValueError("a series needs one response per value")
126
+ self.response = self.response[ok]
127
+ self.volume, self.value = self.volume[ok], self.value[ok]
128
+
129
+ @property
130
+ def key(self) -> str:
131
+ return f"{self.property}.{self.bc}" if self.bc else self.property
132
+
133
+ def statistics(self) -> SizeStatistics:
134
+ return ensemble_statistics(self.volume, self.value)
135
+
136
+ def mean_response(self, volume: float) -> np.ndarray | None:
137
+ if self.response is None:
138
+ return None
139
+ sel = self.volume == volume
140
+ return self.response[sel].mean(axis=0) if np.any(sel) else None
141
+
142
+
143
+ def _parse(value):
144
+ if isinstance(value, (int, float)):
145
+ return float(value)
146
+ try:
147
+ return float(value)
148
+ except (TypeError, ValueError):
149
+ return math.nan
150
+
151
+
152
+ def _volume(row: dict, volume_column: str) -> float:
153
+ if volume_column in row and row[volume_column] not in ("", None):
154
+ return _parse(row[volume_column])
155
+ if "size" in row and row["size"] not in ("", None):
156
+ return _parse(row["size"]) ** 3
157
+ raise ValueError(f"results need a '{volume_column}' (or 'size') column")
158
+
159
+
160
+ def _responses(rows: list[dict]) -> np.ndarray | None:
161
+ tensor = [f"R{n}" for n in ("11", "22", "33", "23", "31", "12")]
162
+ vector = ["R1", "R2", "R3"]
163
+
164
+ def present(keys):
165
+ return all(k in rows[0] and math.isfinite(_parse(rows[0][k])) for k in keys)
166
+
167
+ if present(tensor):
168
+ out = np.empty((len(rows), 3, 3))
169
+ pairs = ((0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (0, 1))
170
+ for i, row in enumerate(rows):
171
+ for name, (a, b) in zip(tensor, pairs, strict=True):
172
+ out[i, a, b] = out[i, b, a] = _parse(row[name])
173
+ return out
174
+ if present(vector):
175
+ return np.array([[_parse(row[k]) for k in vector] for row in rows])
176
+ return None
177
+
178
+
179
+ def series_from_rows(
180
+ rows: list[dict], *, properties=None, group_by: str | None = None, volume_column="volume"
181
+ ) -> list[Series]:
182
+ """Series of a results table.
183
+
184
+ * Long format (columns ``property`` and ``value``, e.g. ``homogenization.csv``):
185
+ one series per (property, ``bc`` or ``group_by`` column). Rows without a value
186
+ (the summaries of the loading paths) are left out.
187
+ * Wide format: one column per property. Columns named ``<property>.<bc>`` (e.g.
188
+ ``bulk_modulus.kubc``) give one series per boundary condition; with ``group_by``
189
+ the rows are split by the values of that column instead.
190
+ """
191
+ if not rows:
192
+ raise ValueError("no results to analyse")
193
+ wanted = None if properties is None else list(properties)
194
+ series: list[Series] = []
195
+ if any("property" in r and "value" in r for r in rows):
196
+ rows = [r for r in rows if r.get("value") not in (None, "")]
197
+ if not rows:
198
+ raise ValueError("no results to analyse")
199
+ group = group_by or ("bc" if "bc" in rows[0] else None)
200
+ keys: dict[tuple, list[dict]] = {}
201
+ for row in rows:
202
+ g = str(row.get(group, "")) if group else ""
203
+ keys.setdefault((str(row["property"]), g), []).append(row)
204
+ for (prop, g), sub in keys.items():
205
+ name = f"{prop}.{g}" if g else prop
206
+ if wanted is not None and prop not in wanted and name not in wanted:
207
+ continue
208
+ series.append(
209
+ Series(
210
+ prop,
211
+ g,
212
+ [_volume(r, volume_column) for r in sub],
213
+ [_parse(r["value"]) for r in sub],
214
+ _responses(sub),
215
+ )
216
+ )
217
+ if not series:
218
+ raise ValueError(f"no rows for the properties {wanted}")
219
+ return series
220
+ columns: list[str] = []
221
+ numeric: set[str] = set()
222
+ for row in rows:
223
+ for c, v in row.items():
224
+ if c not in columns:
225
+ columns.append(c)
226
+ if isinstance(v, (int, float)) and not isinstance(v, bool):
227
+ numeric.add(c)
228
+ if wanted is None:
229
+ wanted = [
230
+ c
231
+ for c in columns
232
+ if not _is_meta(c) and c != volume_column and c != group_by and c in numeric
233
+ ]
234
+ missing = [p for p in wanted if p not in columns]
235
+ if missing:
236
+ raise ValueError(f"unknown result columns {missing}; available: {columns}")
237
+ groups: dict[str, list[dict]] = {}
238
+ for row in rows:
239
+ groups.setdefault(str(row.get(group_by, "")) if group_by else "", []).append(row)
240
+ for g, sub in groups.items():
241
+ volumes = [_volume(r, volume_column) for r in sub]
242
+ for col in wanted:
243
+ if group_by:
244
+ prop, bc = col, g
245
+ else:
246
+ prop, _, bc = col.partition(".")
247
+ series.append(Series(prop, bc, volumes, [_parse(r.get(col)) for r in sub]))
248
+ return series
249
+
250
+
251
+ @dataclass
252
+ class SeriesAnalysis:
253
+ """Results of the analysis of one series (see the module documentation)."""
254
+
255
+ series: Series
256
+ stats: SizeStatistics
257
+ reference_mean: float
258
+ free_fit: ScalingLaw | None
259
+ fit: ScalingLaw | None
260
+ rve: list[dict]
261
+ needed: list[dict]
262
+ isotropy: np.ndarray | None
263
+ bootstrap: dict | None = None
264
+ point_variance: float | None = None
265
+ integral_range: float | None = None
266
+ theory: dict = field(default_factory=dict)
267
+
268
+ @property
269
+ def key(self) -> str:
270
+ return self.series.key
271
+
272
+ def statistics_rows(self) -> list[dict]:
273
+ """The statistics of each volume (:meth:`SizeStatistics.rows`), with its edge (of a
274
+ cube, or of the square of a planar image), the standard deviation and the interval
275
+ ``Zbar +/- 2 D``."""
276
+ rows = self.stats.rows()
277
+ for i, row in enumerate(rows):
278
+ std = math.sqrt(row["variance"]) if math.isfinite(row["variance"]) else math.nan
279
+ row["edge"] = row["volume"] ** (1.0 / self.stats.dimension)
280
+ row["std"] = std
281
+ row["low"] = row["mean"] - 2.0 * std
282
+ row["high"] = row["mean"] + 2.0 * std
283
+ if self.isotropy is not None:
284
+ row["isotropy"] = float(self.isotropy[i])
285
+ return rows
286
+
287
+ def to_dict(self) -> dict:
288
+ def law(fit):
289
+ if fit is None:
290
+ return None
291
+ d = fit.to_dict()
292
+ lo, hi = fit.gamma_interval()
293
+ klo, khi = fit.k_interval()
294
+ d.update({"gamma_ci": [lo, hi], "K_ci": [klo, khi]})
295
+ return {
296
+ k: (None if isinstance(v, float) and not math.isfinite(v) else v)
297
+ for k, v in d.items()
298
+ }
299
+
300
+ out = {
301
+ "property": self.series.property,
302
+ "bc": self.series.bc,
303
+ "statistics": self.statistics_rows(),
304
+ "mean": self.reference_mean,
305
+ "free_fit": law(self.free_fit),
306
+ "fit": law(self.fit),
307
+ "rve": self.rve,
308
+ "realizations_needed": self.needed,
309
+ }
310
+ if self.bootstrap is not None:
311
+ out["bootstrap"] = self.bootstrap
312
+ if self.point_variance is not None:
313
+ out["point_variance"] = self.point_variance
314
+ out["integral_range"] = self.integral_range
315
+ if self.theory:
316
+ out["theory"] = self.theory
317
+ if self.stats.dimension != 3: # the squares of a planar image: edges A^(1/2)
318
+ out["dimension"] = self.stats.dimension
319
+ return out
320
+
321
+
322
+ def _fit(stats, gamma, volume_range, weights) -> ScalingLaw | None:
323
+ ok = np.isfinite(stats.variance) & (stats.variance > 0)
324
+ if volume_range is not None:
325
+ lo, hi = volume_range
326
+ ok &= stats.volume >= (lo if lo is not None else -np.inf)
327
+ ok &= stats.volume <= (hi if hi is not None else np.inf)
328
+ need = 1 if gamma is not None else 2
329
+ if np.count_nonzero(ok) < need or (gamma is None and np.unique(stats.volume[ok]).size < 2):
330
+ return None
331
+ w = None
332
+ if weights == "n":
333
+ w = np.maximum(stats.n - 1, 1) / 2.0
334
+ return fit_scaling_law(
335
+ stats.volume, stats.variance, gamma=gamma, volume_range=volume_range, weights=w
336
+ )
337
+
338
+
339
+ def _rve_volume(fit, eps, mean, n) -> float:
340
+ """V_RVE, or NaN when the variance does not decrease with the volume (gamma <= 0)."""
341
+ if not fit.gamma > 0:
342
+ return math.nan
343
+ with np.errstate(over="ignore"):
344
+ return float(fit.rve_volume(eps, mean, n))
345
+
346
+
347
+ def _rve_rows(fit, mean, eps, n, count, dimension: int = 3) -> list[dict]:
348
+ """The RVE volume and its edge (of a cube, or of a square in ``dimension`` 2) for each
349
+ pair (eps, n), with the count of objects that it holds."""
350
+ rows = []
351
+ for e in eps:
352
+ for k in n:
353
+ vol = _rve_volume(fit, e, mean, k)
354
+ edge = vol ** (1.0 / dimension)
355
+ row = {"eps_rel": float(e), "n": int(k), "volume": vol, "edge": edge}
356
+ if count is not None and math.isfinite(vol):
357
+ row["count"] = float(count(vol))
358
+ rows.append(row)
359
+ return rows
360
+
361
+
362
+ def _bootstrap(series, stats, options, gamma, volume_range, weights) -> dict | None:
363
+ """Percentile intervals of gamma, K and V_RVE from resampled realizations."""
364
+ n_boot = int(options.bootstrap)
365
+ if n_boot <= 0:
366
+ return None
367
+ rng = np.random.default_rng(options.seed)
368
+ groups = [series.value[series.volume == v] for v in stats.volume]
369
+ gammas, ks, volumes = [], [], []
370
+ largest = int(np.argmax(stats.volume))
371
+ for _ in range(n_boot):
372
+ means, variances = [], []
373
+ for vals in groups:
374
+ sample = vals[rng.integers(0, len(vals), len(vals))]
375
+ means.append(sample.mean())
376
+ variances.append(sample.var(ddof=1) if len(sample) > 1 else np.nan)
377
+ boot = SizeStatistics(stats.volume, stats.n, np.array(means), np.array(variances))
378
+ fit = _fit(boot, gamma, volume_range, weights)
379
+ if fit is None or means[largest] == 0 or not fit.gamma > 0:
380
+ continue
381
+ gammas.append(fit.gamma)
382
+ ks.append(fit.K)
383
+ volumes.append(
384
+ [
385
+ _rve_volume(fit, e, means[largest], k)
386
+ for e in options.relative_errors
387
+ for k in options.n_realizations
388
+ ]
389
+ )
390
+ if len(gammas) < max(10, n_boot // 10):
391
+ return None
392
+ q = [50 * (1 - options.level), 50 * (1 + options.level)]
393
+ vol = np.array(volumes, dtype=float)
394
+ vol[~np.isfinite(vol)] = np.inf
395
+ return {
396
+ "replicates": len(gammas),
397
+ "level": options.level,
398
+ "gamma": [float(x) for x in np.percentile(gammas, q)],
399
+ "K": [float(x) for x in np.percentile(ks, q)],
400
+ "volume": [
401
+ [float(a), float(b)] for a, b in np.percentile(vol, q, axis=0, method="inverted_cdf").T
402
+ ],
403
+ }
404
+
405
+
406
+ @dataclass
407
+ class StudyOptions:
408
+ """Settings of the analysis.
409
+
410
+ ``gamma``: exponent imposed for the RVE sizes (None: the fitted one). ``min_volume``
411
+ and ``max_volume`` restrict the fits (the paper keeps V >= 40^3 to avoid boundary
412
+ layer effects). ``weights="n"`` weights each size by (n - 1) / 2, the inverse
413
+ variance of ln D^2 for Gaussian data. ``bootstrap`` replicates (0: none).
414
+ """
415
+
416
+ gamma: float | None = None
417
+ min_volume: float | None = None
418
+ max_volume: float | None = None
419
+ relative_errors: tuple = (0.01, 0.05)
420
+ n_realizations: tuple = (1, 10)
421
+ bootstrap: int = 1000
422
+ seed: int = 0
423
+ weights: str = "none"
424
+ level: float = 0.95
425
+
426
+ def __post_init__(self) -> None:
427
+ if self.weights not in ("none", "n"):
428
+ raise ValueError("weights: 'none' or 'n'")
429
+ self.relative_errors = tuple(float(e) for e in self.relative_errors)
430
+ self.n_realizations = tuple(int(k) for k in self.n_realizations)
431
+ if any(e <= 0 for e in self.relative_errors) or any(k < 1 for k in self.n_realizations):
432
+ raise ValueError("relative errors must be positive and n at least 1")
433
+
434
+
435
+ def analyze_series(
436
+ series: Series,
437
+ options: StudyOptions | None = None,
438
+ *,
439
+ count: Callable[[float], float] | None = None,
440
+ theory: dict | None = None,
441
+ ) -> SeriesAnalysis:
442
+ """Analysis of one series (statistics, fits, RVE sizes, isotropy, bootstrap)."""
443
+ return _analysis(series, series.statistics(), options, count, theory, resample=True)
444
+
445
+
446
+ def analyze_statistics(
447
+ stats: SizeStatistics,
448
+ prop: str = "volume_fraction",
449
+ options: StudyOptions | None = None,
450
+ *,
451
+ theory: dict | None = None,
452
+ ) -> SeriesAnalysis:
453
+ """Analysis of precomputed statistics (e.g. the window method; no bootstrap)."""
454
+ series = Series(prop, "", [], [])
455
+ return _analysis(series, stats, options, None, theory, resample=False)
456
+
457
+
458
+ def _analysis(series, stats, options, count, theory, resample) -> SeriesAnalysis:
459
+ options = options or StudyOptions()
460
+ if stats.volume.size == 0:
461
+ raise ValueError(f"series {series.key}: no finite values")
462
+ reference = float(stats.mean[np.argmax(stats.volume)])
463
+ volume_range = (options.min_volume, options.max_volume)
464
+ free = _fit(stats, None, volume_range, options.weights)
465
+ fit = free
466
+ if options.gamma is not None:
467
+ fit = _fit(stats, options.gamma, volume_range, options.weights)
468
+ rve_rows, needed = [], []
469
+ if fit is not None and reference != 0 and fit.gamma > 0:
470
+ rve_rows = _rve_rows(fit, reference, options.relative_errors, options.n_realizations,
471
+ count, stats.dimension) # fmt: skip
472
+ for v in stats.volume:
473
+ needed.append(
474
+ {
475
+ "volume": float(v),
476
+ **{
477
+ f"eps={e:g}": float(math.ceil(fit.realizations(v, e, reference)))
478
+ for e in options.relative_errors
479
+ },
480
+ }
481
+ )
482
+ boot = None
483
+ if fit is not None and resample:
484
+ boot = _bootstrap(series, stats, options, options.gamma, volume_range, options.weights)
485
+ if boot is not None and len(rve_rows) == len(boot["volume"]):
486
+ for row, (lo, hi) in zip(rve_rows, boot["volume"], strict=True):
487
+ row["volume_ci"] = [lo, hi]
488
+ row["edge_ci"] = [lo ** (1 / stats.dimension), hi ** (1 / stats.dimension)]
489
+ iso = None
490
+ if series.response is not None and series.value.size:
491
+ iso = np.array([_isotropy(series.property, series.mean_response(v)) for v in stats.volume])
492
+ pv = ir = None
493
+ if series.property == "volume_fraction" and fit is not None and 0 < reference < 1:
494
+ pv = point_variance(reference)
495
+ ir = fit.integral_range(pv)
496
+ return SeriesAnalysis(
497
+ series=series,
498
+ stats=stats,
499
+ reference_mean=reference,
500
+ free_fit=free,
501
+ fit=fit,
502
+ rve=rve_rows,
503
+ needed=needed,
504
+ isotropy=iso,
505
+ bootstrap=boot,
506
+ point_variance=pv,
507
+ integral_range=ir,
508
+ theory={k: v for k, v in (theory or {}).items() if isinstance(v, float)},
509
+ )
510
+
511
+
512
+ def discrepancy(analyses: list[SeriesAnalysis]) -> dict[str, list[dict]]:
513
+ """D(Z) = (Zmax - Zmin) / Zmin between boundary conditions, per volume (eq. 69)."""
514
+ by_prop: dict[str, list[SeriesAnalysis]] = {}
515
+ for a in analyses:
516
+ if a.series.bc:
517
+ by_prop.setdefault(a.series.property, []).append(a)
518
+ out = {}
519
+ for prop, group in by_prop.items():
520
+ if len(group) < 2:
521
+ continue
522
+ common = set(group[0].stats.volume.tolist())
523
+ for a in group[1:]:
524
+ common &= set(a.stats.volume.tolist())
525
+ rows = []
526
+ dimension = group[0].stats.dimension
527
+ for v in sorted(common):
528
+ means = {a.series.bc: float(a.stats.mean[a.stats.volume == v][0]) for a in group}
529
+ lo, hi = min(means.values()), max(means.values())
530
+ rows.append(
531
+ {
532
+ "volume": v,
533
+ "edge": v ** (1.0 / dimension),
534
+ "means": means,
535
+ "discrepancy": (hi - lo) / lo if lo != 0 else math.nan,
536
+ }
537
+ )
538
+ out[prop] = rows
539
+ return out
540
+
541
+
542
+ #: The tensors of the transport phenomena (3 x 3, in the axes 1 2 3) and their physics:
543
+ #: the conductivity, and those of electrical conduction, dielectrics, magnetostatics and
544
+ #: diffusion
545
+ TRANSPORT_TENSORS = {f"{name}_tensor": physics for physics, name in TRANSPORT.items()}
546
+ #: The tensors of the results whose mean a study gives per volume, with its inverse: the
547
+ #: stiffness and its compliance, the conductivity and its resistivity (the tensor of each
548
+ #: transport phenomenon and its inverse)
549
+ TENSOR_PROPERTIES = ("stiffness", *TRANSPORT_TENSORS)
550
+ #: A column of the results holding a component of a tensor: <property>.<bc>.C<i><j>
551
+ _TENSOR_ENTRY = re.compile(rf"^({'|'.join(TENSOR_PROPERTIES)})\.([^.]+)\.C([1-6])([1-6])$")
552
+ #: The off-diagonal components of an orthotropic tensor in its axes (stiffnesses in space
553
+ #: and in the plane; a conductivity has none)
554
+ _ORTHOTROPIC = {
555
+ ("stiffness", 6): {(0, 1), (0, 2), (1, 2)},
556
+ ("stiffness", 3): {(0, 1)},
557
+ }
558
+ #: The notation of a conductivity tensor and of its inverse in the studies (the components
559
+ #: C11 ... C33 of the columns of results)
560
+ CONDUCTIVITY_NOTATION = (
561
+ "the matrix K_ij of the flux q_i = -K_ij dT/dx_j, i, j = 1 2 3 the axes (C_ij in the "
562
+ "columns); S = K^-1, the resistivity, in the same notation"
563
+ )
564
+ #: What the matrices of :meth:`TensorStatistics.to_dict` are, for the stiffnesses of an
565
+ #: ensemble study (``to_dict`` states those of the windows and of the conductivities)
566
+ TENSOR_DEFINITIONS = {
567
+ "stiffness": "Cbar, the mean of the apparent stiffnesses C of the realizations",
568
+ "stiffness_std": "the standard deviation of each component of C over the realizations",
569
+ "compliance": "S = Cbar^-1, the inverse of the mean stiffness (S Cbar = I), not the mean "
570
+ "of the compliances of the realizations (mean_compliance)",
571
+ "compliance_std": "the standard deviation of each component of the compliances C^-1 of "
572
+ "the realizations",
573
+ "mean_compliance": "<C^-1>, the mean of the compliances of the realizations (>= Cbar^-1)",
574
+ }
575
+ #: The names of a tensor and of its inverse, singular and plural
576
+ TENSOR_WORDS = {
577
+ "stiffness": ("stiffness", "stiffnesses", "compliance", "compliances"),
578
+ "conductivity_tensor": ("conductivity", "conductivities", "resistivity", "resistivities"),
579
+ "electrical_conductivity_tensor": (
580
+ "electrical conductivity",
581
+ "electrical conductivities",
582
+ "electrical resistivity",
583
+ "electrical resistivities",
584
+ ),
585
+ "permittivity_tensor": (
586
+ "permittivity",
587
+ "permittivities",
588
+ "dielectric impermeability",
589
+ "dielectric impermeabilities",
590
+ ),
591
+ "permeability_tensor": ("permeability", "permeabilities", "reluctivity", "reluctivities"),
592
+ "diffusivity_tensor": (
593
+ "diffusivity",
594
+ "diffusivities",
595
+ "inverse diffusivity",
596
+ "inverse diffusivities",
597
+ ),
598
+ }
599
+ #: What the window tensors are (:mod:`morphogen.rve.windows`)
600
+ _WINDOW_TENSOR = {
601
+ "stiffness": "C_kl = <eps_k : C : eps_l>_w, the window means of the mutual energy "
602
+ "densities of the solutions of the whole sample under the unit macroscopic strains E_k "
603
+ "(symmetric, positive semi-definite; tiling the sample, their mean is its apparent "
604
+ "stiffness, by Hill's lemma)",
605
+ "conductivity_tensor": "C_kl = <grad T_k . K grad T_l>_w, the window means of the mutual "
606
+ "dissipations of the solutions of the whole sample under the unit macroscopic gradients "
607
+ "G_k (symmetric, positive semi-definite; tiling the sample, their mean is its apparent "
608
+ "conductivity, by Hill's lemma)",
609
+ }
610
+ for _prop in TRANSPORT_TENSORS: # the other transports: the same tensors of their potentials
611
+ _WINDOW_TENSOR.setdefault(
612
+ _prop,
613
+ _WINDOW_TENSOR["conductivity_tensor"].replace("conductivity", TENSOR_WORDS[_prop][0]),
614
+ )
615
+
616
+
617
+ def _definitions(prop: str, method: str = "ensemble") -> dict[str, str]:
618
+ """What the matrices of :meth:`TensorStatistics.to_dict` are, for the tensors ``prop``
619
+ of the realizations of an ensemble study or of the windows of one realization."""
620
+ if prop == "stiffness" and method == "ensemble":
621
+ return dict(TENSOR_DEFINITIONS)
622
+ one, many, inverse, inverses = TENSOR_WORDS.get(prop, TENSOR_WORDS["stiffness"])
623
+ samples = "windows" if method == "windows" else "realizations"
624
+ what = f"apparent {many} C of the realizations"
625
+ if method == "windows":
626
+ what = f"tensors C of the windows, {_WINDOW_TENSOR.get(prop, _WINDOW_TENSOR['stiffness'])}"
627
+ return {
628
+ "stiffness": f"Cbar, the mean of the {what}",
629
+ "stiffness_std": f"the standard deviation of each component of C over the {samples}",
630
+ "compliance": f"S = Cbar^-1, the inverse of the mean {one} (S Cbar = I), the "
631
+ f"{inverse}, not the mean of the {inverses} of the {samples} (mean_compliance)",
632
+ "compliance_std": f"the standard deviation of each component of the {inverses} C^-1 "
633
+ f"of the {samples}",
634
+ "mean_compliance": f"<C^-1>, the mean of the {inverses} of the {samples} (>= Cbar^-1)",
635
+ }
636
+
637
+
638
+ def tensor_notation(prop: str, tensor) -> str:
639
+ """The notation of a tensor ``prop`` of the studies and of its inverse: of a stiffness
640
+ (:func:`morphogen.homogenization.postprocess.notation`: Voigt order 11 22 33 23 31 12,
641
+ engineering shears; 11 22 12 for a 3 x 3 one), of a conductivity
642
+ (:data:`CONDUCTIVITY_NOTATION`) or of the tensor of another transport phenomenon (the
643
+ same, of its flux and potential)."""
644
+ from morphogen.homogenization.postprocess import notation
645
+
646
+ if prop == "conductivity_tensor":
647
+ return CONDUCTIVITY_NOTATION
648
+ if prop in TRANSPORT_TENSORS:
649
+ potential, flux, _ = TRANSPORT_LAWS[TRANSPORT_TENSORS[prop]]
650
+ inverse = TENSOR_WORDS[prop][2]
651
+ return (
652
+ f"the matrix K_ij of the {flux} q_i = -K_ij d({potential})/dx_j, i, j = 1 2 3 the "
653
+ f"axes (C_ij in the columns); S = K^-1, the {inverse}, in the same notation"
654
+ )
655
+ return notation(tensor)
656
+
657
+
658
+ def is_tensor(name: str) -> bool:
659
+ """Whether a property asked of a study names a tensor (:data:`TENSOR_PROPERTIES`):
660
+ ``stiffness`` or ``stiffness.<bc>`` (``conductivity_tensor``, ``conductivity_tensor.<bc>``),
661
+ whereas ``stiffness.<bc>.C44`` is the series of one of its components."""
662
+ head, _, rest = str(name).partition(".")
663
+ return head in TENSOR_PROPERTIES and "." not in rest
664
+
665
+
666
+ def _matrix(m) -> list:
667
+ """A matrix for JSON: nested lists, None for undefined entries."""
668
+ return [[float(x) if math.isfinite(x) else None for x in row] for row in np.asarray(m)]
669
+
670
+
671
+ #: The relative size, to the largest diagonal component of the tensor, under which a
672
+ #: component is zero to round-off (the significance of the couplings)
673
+ _ROUND_OFF = 1e-12
674
+
675
+
676
+ def _inverse(m: np.ndarray) -> np.ndarray:
677
+ """The compliance of a stiffness (NaN when it is singular)."""
678
+ from morphogen.homogenization.postprocess import compliance
679
+
680
+ try:
681
+ return compliance(m)
682
+ except np.linalg.LinAlgError:
683
+ return np.full_like(m, np.nan)
684
+
685
+
686
+ def _inverses(c: np.ndarray) -> np.ndarray:
687
+ """The compliances of finite stiffnesses ``(k, d, d)`` at once, those of ``_inverse``:
688
+ NaN for the singular ones, exactly or to round-off (the guard of
689
+ :func:`morphogen.homogenization.postprocess.compliance`: its symmetric part not positive
690
+ definite beyond round-off; a window within a pore)."""
691
+ from morphogen.homogenization.postprocess import _ROUND_OFF as singular
692
+
693
+ w = np.linalg.eigvalsh(0.5 * (c + np.swapaxes(c, 1, 2)))
694
+ regular = w[:, 0] > singular * w[:, -1] # so invertible
695
+ s = np.full_like(c, np.nan)
696
+ if regular.any():
697
+ s[regular] = np.linalg.inv(c[regular])
698
+ return s
699
+
700
+
701
+ @dataclass
702
+ class TensorStatistics:
703
+ """The mean stiffness and compliance per volume of the realizations of one boundary
704
+ condition (see the module documentation), or of the windows of one realization
705
+ (``method="windows"``, :mod:`morphogen.rve.windows`); the conductivity and its
706
+ resistivity likewise (``property="conductivity_tensor"``).
707
+
708
+ Per volume (``volume``, sorted, with ``n`` realizations): ``mean`` the mean stiffness
709
+ ``Cbar`` and ``std`` the standard deviation of each of its components (NaN for a
710
+ single realization); ``compliance`` the inverse of the mean stiffness, ``S =
711
+ Cbar^-1`` (``compliance @ mean = I``); ``compliance_std`` the standard deviation of the
712
+ components of the compliances ``C^-1`` of the realizations and ``mean_compliance``
713
+ their mean ``<C^-1>``. Arrays ``(m, 6, 6)`` (``(m, 3, 3)`` in the plane) in morphoGen's
714
+ Voigt order 11 22 33 23 31 12 with engineering shears (:attr:`notation`; a
715
+ conductivity ``(m, 3, 3)`` in the axes 1 2 3).
716
+ ``components``: the analysis of each component of the stiffnesses (``C11`` ...
717
+ ``C66``) and of the compliances (``S11`` ... ``S66``) of the realizations as a series,
718
+ with RVE sizes for the diagonal ones and those that the realizations distinguish from
719
+ zero (:meth:`significant`). ``dimension``: that of the samples (3, cubes; 2, the
720
+ squares of a planar image, the volumes their areas), their edges ``V^(1/dimension)``
721
+ (:meth:`edges`). ``tilings``: by the window method with shifted tilings, the number of
722
+ tilings of each size, ``n`` then the windows of one tiling (the independent ones), the
723
+ means those of all the windows, the standard deviations the roots of their variances
724
+ pooled within the tilings (:mod:`morphogen.rve.scaling`); None: one tiling.
725
+ """
726
+
727
+ property: str
728
+ bc: str
729
+ volume: np.ndarray
730
+ n: np.ndarray
731
+ mean: np.ndarray
732
+ std: np.ndarray
733
+ compliance: np.ndarray
734
+ compliance_std: np.ndarray
735
+ mean_compliance: np.ndarray
736
+ components: dict[str, SeriesAnalysis] = field(default_factory=dict)
737
+ level: float = 0.95
738
+ method: str = "ensemble"
739
+ dimension: int = 3
740
+ tilings: np.ndarray | None = None
741
+
742
+ @property
743
+ def key(self) -> str:
744
+ return f"{self.property}.{self.bc}" if self.bc else self.property
745
+
746
+ def edges(self) -> np.ndarray:
747
+ """The edges of the volumes, ``V^(1/dimension)``: of cubes, of squares."""
748
+ return np.array([float(v) ** (1.0 / self.dimension) for v in self.volume])
749
+
750
+ @property
751
+ def notation(self) -> str:
752
+ """The notation of the tensor and of its inverse (:func:`tensor_notation`:
753
+ :data:`morphogen.homogenization.postprocess.NOTATION` for a stiffness)."""
754
+ return tensor_notation(self.property, self.mean[0])
755
+
756
+ @property
757
+ def samples(self) -> str:
758
+ """What its statistics are over: ``realizations`` or ``windows``."""
759
+ return "windows" if self.method == "windows" else "realizations"
760
+
761
+ @staticmethod
762
+ def index(name: str) -> tuple[int, int]:
763
+ """The row and column of a component (``C44``, ``S44``: ``(3, 3)``)."""
764
+ return int(name[1]) - 1, int(name[2]) - 1
765
+
766
+ def significant(self, name: str) -> bool:
767
+ """Whether the mean of a component is distinguished from zero: always for the
768
+ diagonal (positive, the stiffness and the compliance being positive definite); for
769
+ the others, by the realizations of the largest volume that has several, Student's
770
+ t test at the ``level`` of the study (``|Zbar| sqrt(n) / D`` above the quantile of
771
+ n - 1 degrees of freedom), and with a single realization per volume, whether it
772
+ is a component of an orthotropic stiffness in its axes (a conductivity in its axes
773
+ has none). The couplings that vanish on average have no relative precision, hence
774
+ no RVE size."""
775
+ from scipy import stats as distributions
776
+
777
+ i, j = self.index(name)
778
+ if i == j:
779
+ return True
780
+ stats = self.components[name].stats
781
+ several = np.flatnonzero(np.isfinite(stats.variance))
782
+ if not several.size:
783
+ return (i, j) in _ORTHOTROPIC.get((self.property, len(self.mean[0])), set())
784
+ k = several[-1]
785
+ mean, std, n = abs(stats.mean[k]), math.sqrt(stats.variance[k]), int(stats.n[k])
786
+ # zero to round-off (an exact symmetry, as of laminates, whose couplings are 1e-17
787
+ # of the diagonal with one sign): not distinguished from zero, whatever its t
788
+ diagonal = np.abs(np.diag((self.compliance if name[0] == "S" else self.mean)[k]))
789
+ diagonal = diagonal[np.isfinite(diagonal)]
790
+ if not (diagonal.size and mean > _ROUND_OFF * diagonal.max()):
791
+ return False
792
+ if std == 0:
793
+ return True
794
+ quantile = distributions.t.ppf(0.5 + self.level / 2.0, n - 1)
795
+ return bool(mean * math.sqrt(n) / std > quantile)
796
+
797
+ def volume_rows(self) -> list[dict]:
798
+ """One row per volume: its edge (of a cube, or of a square), its realizations
799
+ (windows, and their tilings when shifted), the components of ``Cbar``, of ``S =
800
+ Cbar^-1`` and their standard deviations (``C11_std`` ...), the rows of
801
+ ``rve_<property>.csv``."""
802
+ from morphogen.homogenization.postprocess import matrix_entries
803
+
804
+ rows = []
805
+ for k, (v, edge) in enumerate(zip(self.volume, self.edges(), strict=True)):
806
+ row = {"bc": self.bc, "volume": float(v), "edge": float(edge)}
807
+ row["n"] = int(self.n[k])
808
+ if self.tilings is not None:
809
+ row["tilings"] = int(self.tilings[k])
810
+ row.update(matrix_entries(self.mean[k], "C"))
811
+ row.update(matrix_entries(self.compliance[k], "S"))
812
+ for prefix, m in (("C", self.std[k]), ("S", self.compliance_std[k])):
813
+ row.update({f"{name}_std": x for name, x in matrix_entries(m, prefix).items()})
814
+ rows.append(row)
815
+ return rows
816
+
817
+ def to_dict(self) -> dict:
818
+ volumes = []
819
+ for k, (v, edge) in enumerate(zip(self.volume, self.edges(), strict=True)):
820
+ entry = {"volume": float(v), "edge": float(edge), "n": int(self.n[k])}
821
+ if self.tilings is not None:
822
+ entry["tilings"] = int(self.tilings[k])
823
+ entry.update(
824
+ stiffness=_matrix(self.mean[k]),
825
+ stiffness_std=_matrix(self.std[k]),
826
+ compliance=_matrix(self.compliance[k]),
827
+ compliance_std=_matrix(self.compliance_std[k]),
828
+ mean_compliance=_matrix(self.mean_compliance[k]),
829
+ )
830
+ volumes.append(entry)
831
+ out = {
832
+ "property": self.property,
833
+ "bc": self.bc,
834
+ "notation": self.notation,
835
+ "method": self.method,
836
+ "definitions": _definitions(self.property, self.method),
837
+ "volumes": volumes,
838
+ "components": {name: a.to_dict() for name, a in self.components.items()},
839
+ }
840
+ if self.dimension != 3: # the squares of a planar image: edges A^(1/2)
841
+ out["dimension"] = self.dimension
842
+ return out
843
+
844
+
845
+ def _std(a: np.ndarray, tilings: np.ndarray | None = None) -> np.ndarray:
846
+ """The standard deviation of each component of tensors ``(k, d, d)`` (NaN for one); of
847
+ the windows of shifted tilings (``tilings`` the tiling of each), the root of their
848
+ variance pooled within the tilings."""
849
+ if tilings is not None and np.unique(tilings).size > 1:
850
+ return np.sqrt(_pooled_variance(a, tilings))
851
+ return a.std(axis=0, ddof=1) if len(a) > 1 else np.full(a.shape[1:], np.nan)
852
+
853
+
854
+ def _tensor_statistics(
855
+ prop: str,
856
+ bc: str,
857
+ groups,
858
+ options: StudyOptions | None,
859
+ method: str = "ensemble",
860
+ dimension: int = 3,
861
+ ) -> TensorStatistics:
862
+ """The statistics of tensors given by volume (:class:`TensorStatistics`): ``groups`` of
863
+ (volume, finite tensors ``(k, d, d)``), the volumes increasing, one volume at a time (the
864
+ windows of a size: no series of their components is kept, only their moments), or of
865
+ (volume, tensors, the tiling of each) for the windows of shifted tilings: their means
866
+ over all the windows, their variances pooled within the tilings, the counts those of
867
+ one (:mod:`morphogen.rve.scaling`). The analysis of each component is that of a series
868
+ of its values (:func:`analyze_series`, without bootstrap): its finite values per volume,
869
+ their mean and unbiased variance. ``dimension``: that of the volumes (2: areas)."""
870
+ options = replace(options or StudyOptions(), bootstrap=0)
871
+ d = groups[0][1].shape[1]
872
+ pairs = [(i, j) for i in range(d) for j in range(i, d)]
873
+ names = [f"{x}{i + 1}{j + 1}" for x in "CS" for i, j in pairs]
874
+ moments: dict[str, list[tuple]] = {name: [] for name in names}
875
+ per_volume = []
876
+ shifted = any(len(g) > 2 and g[2] is not None for g in groups)
877
+ for v, c, *rest in groups:
878
+ tilings = rest[0] if rest else None
879
+ count = 1 if tilings is None else np.unique(tilings).size # of tilings
880
+ s = _inverses(c) # the compliances of the realizations
881
+ mean = c.mean(axis=0)
882
+ per_volume.append((v, len(c) // count, mean, _std(c, tilings), _inverse(mean),
883
+ _std(s, tilings), s.mean(axis=0), count)) # fmt: skip
884
+ for letter, values in (("C", c), ("S", s)):
885
+ for i, j in pairs:
886
+ z = np.ascontiguousarray(values[:, i, j])
887
+ finite = np.isfinite(z)
888
+ z = z[finite]
889
+ if z.size:
890
+ of = None if tilings is None else tilings[finite]
891
+ k, m, var = _moments(z, of)
892
+ tiled = 1 if of is None else np.unique(of).size
893
+ moments[f"{letter}{i + 1}{j + 1}"].append((v, k, m, var, tiled))
894
+ columns = (np.array(a) for a in zip(*per_volume, strict=True))
895
+ volume, n, mean, std, comp, comp_std, mean_comp, tiled = columns
896
+ out = TensorStatistics(
897
+ property=prop,
898
+ bc=bc,
899
+ volume=volume.astype(float),
900
+ n=n.astype(int),
901
+ mean=mean,
902
+ std=std,
903
+ compliance=comp,
904
+ compliance_std=comp_std,
905
+ mean_compliance=mean_comp,
906
+ level=options.level,
907
+ method=method,
908
+ dimension=dimension,
909
+ tilings=tiled.astype(int) if shifted else None,
910
+ )
911
+ for name in names:
912
+ if not moments[name]: # singular stiffnesses
913
+ continue
914
+ v, k, m, var, t = (np.array(a, dtype=float) for a in zip(*moments[name], strict=True))
915
+ t = t.astype(int) if shifted else None
916
+ stats = SizeStatistics(v, k.astype(int), m, var, dimension=dimension, tilings=t)
917
+ analysis = _analysis(Series(name, bc, [], []), stats, options, None, None, False)
918
+ out.components[name] = analysis
919
+ if not out.significant(name):
920
+ analysis.rve, analysis.needed = [], []
921
+ return out
922
+
923
+
924
+ def tensor_statistics(
925
+ volumes,
926
+ tensors,
927
+ prop: str = "stiffness",
928
+ bc: str = "",
929
+ options: StudyOptions | None = None,
930
+ ) -> TensorStatistics:
931
+ """The mean stiffness and compliance per volume of realizations
932
+ (:class:`TensorStatistics`): ``tensors`` their apparent stiffnesses (k x 6 x 6, or k x
933
+ 3 x 3 in the plane; Voigt order 11 22 33 23 31 12, engineering shears; or their
934
+ conductivities, k x 3 x 3, ``prop="conductivity_tensor"``) at their ``volumes``;
935
+ ``options`` those of the study (gamma, range of the fits, precisions), its components
936
+ analysed without bootstrap."""
937
+ v = np.asarray(volumes, dtype=float)
938
+ c = np.asarray(tensors, dtype=float)
939
+ if c.ndim != 3 or c.shape[1:] not in ((6, 6), (3, 3)) or len(c) != len(v):
940
+ raise ValueError("tensor_statistics: one 6 x 6 (or 3 x 3) stiffness per volume")
941
+ ok = np.isfinite(v) & (v > 0) & np.isfinite(c).all(axis=(1, 2))
942
+ v, c = v[ok], c[ok]
943
+ if not v.size:
944
+ raise ValueError(f"{prop}.{bc}: no finite stiffness")
945
+ return _tensor_statistics(prop, bc, [(x, c[v == x]) for x in np.unique(v)], options)
946
+
947
+
948
+ def tensors_from_rows(
949
+ rows: list[dict],
950
+ *,
951
+ properties=None,
952
+ volume_column: str = "volume",
953
+ options: StudyOptions | None = None,
954
+ ) -> list[TensorStatistics]:
955
+ """The mean stiffness and compliance per volume (:func:`tensor_statistics`) of each
956
+ boundary condition whose stiffness the rows of results hold, in the columns
957
+ ``stiffness.<bc>.C11`` ... ``C66`` of the runs (the upper triangle; ``C11`` ...
958
+ ``C33`` in the plane). ``properties``: the tensors kept, ``stiffness`` or
959
+ ``stiffness.<bc>`` (None: all)."""
960
+ found: dict[tuple[str, str], dict[tuple[int, int], str]] = {}
961
+ for row in rows:
962
+ for column in row:
963
+ m = _TENSOR_ENTRY.match(str(column))
964
+ if m:
965
+ found.setdefault((m[1], m[2]), {})[(int(m[3]) - 1, int(m[4]) - 1)] = column
966
+ out = []
967
+ for (prop, bc), entries in found.items():
968
+ if properties is not None and prop not in properties and f"{prop}.{bc}" not in properties:
969
+ continue
970
+ d = 6 if max(max(ij) for ij in entries) > 2 else 3
971
+ upper = [(i, j) for i in range(d) for j in range(i, d)]
972
+ if any(ij not in entries for ij in upper):
973
+ continue
974
+ tensors = np.full((len(rows), d, d), np.nan)
975
+ for k, row in enumerate(rows):
976
+ for i, j in upper:
977
+ tensors[k, i, j] = tensors[k, j, i] = _parse(row.get(entries[(i, j)]))
978
+ if not np.isfinite(tensors).all(axis=(1, 2)).any():
979
+ continue
980
+ volumes = [_volume(row, volume_column) for row in rows]
981
+ out.append(tensor_statistics(volumes, tensors, prop, bc, options))
982
+ return out
983
+
984
+
985
+ @dataclass
986
+ class StudyReport:
987
+ """Analyses of all the series of a study, with cross-series results, and the mean
988
+ stiffness and compliance per volume of each boundary condition (``tensors``)."""
989
+
990
+ analyses: list[SeriesAnalysis]
991
+ discrepancy: dict[str, list[dict]]
992
+ options: StudyOptions
993
+ bounds: dict = field(default_factory=dict)
994
+ method: str = "ensemble"
995
+ tensors: list[TensorStatistics] = field(default_factory=list)
996
+
997
+ @property
998
+ def dimension(self) -> int:
999
+ """That of its samples, whose edges the tables print: 3 (cubes), or 2 (the squares
1000
+ of a planar image, the volumes their areas)."""
1001
+ if self.analyses:
1002
+ return self.analyses[0].stats.dimension
1003
+ return self.tensors[0].dimension if self.tensors else 3
1004
+
1005
+ def __getitem__(self, key: str) -> SeriesAnalysis:
1006
+ for a in self.analyses:
1007
+ if a.key == key:
1008
+ return a
1009
+ raise KeyError(key)
1010
+
1011
+ def to_dict(self) -> dict:
1012
+ out = {
1013
+ "method": self.method,
1014
+ "options": {
1015
+ "gamma": self.options.gamma,
1016
+ "min_volume": self.options.min_volume,
1017
+ "max_volume": self.options.max_volume,
1018
+ "relative_errors": list(self.options.relative_errors),
1019
+ "n_realizations": list(self.options.n_realizations),
1020
+ "bootstrap": self.options.bootstrap,
1021
+ "weights": self.options.weights,
1022
+ "level": self.options.level,
1023
+ },
1024
+ "properties": {a.key: a.to_dict() for a in self.analyses},
1025
+ "discrepancy": self.discrepancy,
1026
+ "bounds": self.bounds,
1027
+ }
1028
+ if self.tensors:
1029
+ out["tensors"] = {t.key: t.to_dict() for t in self.tensors}
1030
+ return out
1031
+
1032
+
1033
+ def analyze_study(
1034
+ series: list[Series],
1035
+ options: StudyOptions | None = None,
1036
+ *,
1037
+ count: Callable[[float], float] | None = None,
1038
+ bounds: dict | None = None,
1039
+ theory: dict | None = None,
1040
+ method: str = "ensemble",
1041
+ tensors: list[TensorStatistics] | None = None,
1042
+ ) -> StudyReport:
1043
+ """Analyse every series and compare the boundary conditions; ``tensors``: the mean
1044
+ stiffness and compliance per volume (:func:`tensors_from_rows`) joining the report."""
1045
+ options = options or StudyOptions()
1046
+ analyses = [analyze_series(s, options, count=count, theory=theory) for s in series]
1047
+ return StudyReport(
1048
+ analyses=analyses,
1049
+ discrepancy=discrepancy(analyses),
1050
+ options=options,
1051
+ bounds=dict(bounds or {}),
1052
+ method=method,
1053
+ tensors=list(tensors or []),
1054
+ )