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,375 @@
1
+ """Architectures treated pixel by pixel: a morphology on the laser grid of a sheet.
2
+
3
+ A laser treats a sheet through its thickness by squares about the size of its spot,
4
+ the *pixel* (1 mm by default: the smallest feature a spot of 1 mm treats), over sheets
5
+ much larger than any specimen (tens of centimetres: hundreds of pixels a side). A
6
+ *design* is an integer array ``(ny, nx)`` of phases on that grid, row ``i`` at ``y =
7
+ (i + ½) pixel`` and column ``j`` at ``x = (j + ½) pixel``; phase 0 is the untreated sheet
8
+ (:class:`~morphogen.laser.cells.Phase`, the phases of :func:`~morphogen.laser.cells.wang_phases`
9
+ or :func:`~morphogen.laser.cells.contrast_phases`). Any morphology of morphoGen (a
10
+ Boolean model, a tessellation, a random field, a lattice...) becomes a design by
11
+ :func:`pixelate`, the majority phase of each pixel.
12
+
13
+ **Treatment** (:func:`treatment_measures`). Each pixel can be treated, but heat diffuses: an
14
+ untreated pixel next to a treated one sits in its heat-affected zone (tempered,
15
+ partly transformed), and an untreated pixel enclosed by treated ones may not stay
16
+ untreated at all. The measures: the treated share; the treated length drawn by raster
17
+ lines one spot wide, its time at the speed of the beam, the switches of the beam along
18
+ the lines; the connectivity of each phase (whether it spans the design along x and y);
19
+ the untreated pixels next to the treatment and those enclosed by it.
20
+
21
+ **The sheet** (:func:`sheet_tests`). A design repeated over the sheet is periodic: the
22
+ cell of ``nx x ny`` pixels (:class:`~morphogen.laser.periodic.PeriodicCell`, elements
23
+ of half a pixel by default, so that the pixels fall on the elements), each Gauss point
24
+ with the phase of its pixel (:func:`design_membrane`), pulled in several directions
25
+ (:func:`~morphogen.laser.periodic.cell_test`): the yield and tensile strengths, the
26
+ failure strain (the first of the maximum of the nominal stress and of the fracture of
27
+ a brittle phase, :func:`~morphogen.laser.cells.failure_measures`), the energy absorbed
28
+ up to it and Lankford's coefficient of the sheet in each direction, and their spreads
29
+ over the directions.
30
+
31
+ **Tracks** (:func:`track_membrane`). Smooth tracks of constant width along polylines
32
+ (corrugations, oblique families), and their periodic images over a cell
33
+ (:func:`periodic_lines`): each Gauss point mixes the flow stresses and Young's moduli of
34
+ the untreated and treated phases by the share of its region inside the tracks
35
+ (:func:`~morphogen.laser.cells.band_fractions`). Phases may differ in stiffness as well
36
+ as in strength (``young``: one modulus per phase), which separates the two contrasts.
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import math
42
+
43
+ import numpy as np
44
+ from scipy import ndimage
45
+
46
+ from morphogen.laser.cells import (
47
+ FRACTURE_RADIUS,
48
+ Phase,
49
+ band_fractions,
50
+ failure_measures,
51
+ wang_phases,
52
+ )
53
+ from morphogen.laser.mechanics import Membrane
54
+ from morphogen.laser.periodic import PeriodicCell, cell_test
55
+
56
+ __all__ = [
57
+ "design_membrane",
58
+ "periodic_lines",
59
+ "pixelate",
60
+ "sheet_tests",
61
+ "spot_opening",
62
+ "track_membrane",
63
+ "treatment_measures",
64
+ ]
65
+
66
+
67
+ def _moduli(young, count: int) -> np.ndarray:
68
+ """Young's modulus of each of ``count`` phases: one value for all, or one each."""
69
+ e = np.atleast_1d(np.asarray(young, dtype=float))
70
+ if e.size == 1:
71
+ e = np.full(count, float(e[0]))
72
+ if e.shape != (count,) or not np.all(e > 0):
73
+ raise ValueError(f"young: one positive modulus, or one for each of the {count} phases")
74
+ return e
75
+
76
+
77
+ def pixelate(image, shape) -> np.ndarray:
78
+ """The phases (integer labels) of an ``image`` on a grid of ``shape = (ny, nx)``
79
+ pixels covering the same extent: the most frequent label of the image points whose
80
+ centres fall in each pixel (the lowest label on a tie). An image coarser than the
81
+ grid is sampled at the pixel centres."""
82
+ img = np.asarray(image)
83
+ if img.ndim != 2:
84
+ raise ValueError("pixelate: a 2D image")
85
+ if not np.issubdtype(img.dtype, np.integer):
86
+ if not np.all(img == np.round(img)):
87
+ raise ValueError("pixelate: integer labels")
88
+ img = img.astype(np.int64)
89
+ ny, nx = (int(v) for v in shape)
90
+ if ny < 1 or nx < 1:
91
+ raise ValueError("pixelate: a positive shape")
92
+ if img.min() < 0:
93
+ raise ValueError("pixelate: labels from 0")
94
+ iy = np.minimum((np.arange(img.shape[0]) + 0.5) * ny // img.shape[0], ny - 1).astype(int)
95
+ ix = np.minimum((np.arange(img.shape[1]) + 0.5) * nx // img.shape[1], nx - 1).astype(int)
96
+ if img.shape[0] < ny or img.shape[1] < nx: # coarser: sample at the pixel centres
97
+ sy = np.minimum(((np.arange(ny) + 0.5) * img.shape[0] / ny).astype(int), img.shape[0] - 1)
98
+ sx = np.minimum(((np.arange(nx) + 0.5) * img.shape[1] / nx).astype(int), img.shape[1] - 1)
99
+ return img[np.ix_(sy, sx)].astype(np.int64)
100
+ labels = int(img.max()) + 1
101
+ pix = (iy[:, None] * nx + ix[None, :]).ravel()
102
+ counts = np.bincount(pix * labels + img.ravel(), minlength=ny * nx * labels)
103
+ return counts.reshape(ny, nx, labels).argmax(axis=2).astype(np.int64)
104
+
105
+
106
+ def spot_opening(design, width: int = 2, *, periodic: bool = True) -> np.ndarray:
107
+ """The part of a design (treated: phase > 0) that a square spot of ``width`` cells
108
+ draws, its morphological opening (``periodic``: through the edges of the cell;
109
+ otherwise the spot may overhang them), the treated cells keeping their phase."""
110
+ d = np.asarray(design)
111
+ treated = d > 0
112
+ if width <= 1 or not treated.any():
113
+ return d.copy()
114
+ st = np.ones((width, width), dtype=bool)
115
+ pad = np.pad(treated, width, mode="wrap" if periodic else "edge")
116
+ kept = ndimage.binary_opening(pad, structure=st)[width:-width, width:-width]
117
+ return np.where(kept, d, 0)
118
+
119
+
120
+ def _spans(mask, axis: int, periodic: bool) -> bool:
121
+ """Whether a cluster of ``mask`` (4-connected) joins the two edges normal to
122
+ ``axis`` (``periodic``: through the cell to its own image)."""
123
+ if not mask.any():
124
+ return False
125
+ if periodic: # 3 x 3 cells: a cluster that holds a pixel and its image one period on
126
+ lab, _ = ndimage.label(np.tile(mask, (3, 3)))
127
+ ny, nx = mask.shape
128
+ centre = lab[ny : 2 * ny, nx : 2 * nx]
129
+ image = lab[2 * ny :, nx : 2 * nx] if axis == 0 else lab[ny : 2 * ny, 2 * nx :]
130
+ return bool(np.any((centre > 0) & (centre == image)))
131
+ lab, _ = ndimage.label(mask)
132
+ lo = set(np.unique(lab.take(0, axis=axis))) - {0}
133
+ hi = set(np.unique(lab.take(-1, axis=axis))) - {0}
134
+ return bool(lo & hi)
135
+
136
+
137
+ def treatment_measures(
138
+ design, *, pixel: float = 1.0, spot: float = 1.0, speed: float = 10.0, periodic: bool = True
139
+ ) -> dict:
140
+ """The laser treatment of a design (see the module): ``treated`` share; ``length`` (m) of
141
+ the raster lines one ``spot`` wide that treat it, ``time`` (min) at ``speed`` (mm/s),
142
+ ``switches`` of the beam along the rows (per m² of sheet); whether the treated and
143
+ the untreated phases span the design along x and along y (``hard_spans``,
144
+ ``soft_spans``: pairs of booleans); the shares of the untreated pixels with a
145
+ treated neighbour (``heat_affected``) and with treated pixels on all four sides
146
+ (``enclosed``), among the untreated ones."""
147
+ d = np.asarray(design)
148
+ treated = d > 0
149
+ t = treated.astype(np.int8)
150
+ area = d.size * pixel**2 # mm²
151
+ length = treated.sum() * pixel**2 / spot # mm
152
+ if periodic:
153
+ switches = int(np.count_nonzero(t != np.roll(t, 1, axis=1)))
154
+ neighbours = sum(np.roll(t, s, axis=a) for a in (0, 1) for s in (1, -1))
155
+ else:
156
+ switches = int(np.count_nonzero(np.diff(np.pad(t, ((0, 0), (1, 1))), axis=1)))
157
+ p = np.pad(t, 1)
158
+ neighbours = p[:-2, 1:-1] + p[2:, 1:-1] + p[1:-1, :-2] + p[1:-1, 2:]
159
+ soft = ~treated
160
+ near = soft & (neighbours > 0)
161
+ enclosed = soft & (neighbours == 4)
162
+ nsoft = max(int(soft.sum()), 1)
163
+ return {
164
+ "treated": float(treated.mean()),
165
+ "length": float(length / 1000.0),
166
+ "time": float(length / speed / 60.0),
167
+ "switches": float(switches / (area * 1e-6)),
168
+ "hard_spans": (_spans(treated, 1, periodic), _spans(treated, 0, periodic)),
169
+ "soft_spans": (_spans(soft, 1, periodic), _spans(soft, 0, periodic)),
170
+ "heat_affected": float(near.sum() / nsoft),
171
+ "enclosed": float(enclosed.sum() / nsoft),
172
+ }
173
+
174
+
175
+ def design_membrane(
176
+ mesh,
177
+ design,
178
+ *,
179
+ pixel: float = 1.0,
180
+ phases=None,
181
+ origin=(0.0, 0.0),
182
+ young=210000.0,
183
+ poisson: float = 0.3,
184
+ thickness: float = 1.0,
185
+ fracture_radius: float | None = FRACTURE_RADIUS,
186
+ ) -> Membrane:
187
+ """The membrane of a mesh whose Gauss points take the phase of their pixel of the
188
+ design (from ``origin``, repeated beyond it), with the flow law, the critical
189
+ strain and Young's modulus of the phase (``phases``:
190
+ :func:`~morphogen.laser.cells.wang_phases` by default; ``young``: one modulus, or
191
+ one per phase)."""
192
+ phases = tuple(Phase.from_config(p) for p in (phases or wang_phases()))
193
+ d = np.asarray(design, dtype=np.int64)
194
+ if d.min() < 0 or d.max() >= len(phases):
195
+ raise ValueError("design: phases from 0 to len(phases) - 1")
196
+ pts = mesh.gauss()[0]
197
+ ny, nx = d.shape
198
+ j = np.floor((pts[..., 0] - origin[0]) / pixel).astype(np.int64) % nx
199
+ i = np.floor((pts[..., 1] - origin[1]) / pixel).astype(np.int64) % ny
200
+ ph = d[i, j]
201
+ laws = np.array([[p.law.code, p.law.sigma0, p.law.a, p.law.b] for p in phases], dtype=float)
202
+ crit = np.array([p.critical for p in phases], dtype=float)
203
+ flow = [np.ascontiguousarray(laws[ph][..., k][..., None]) for k in range(4)]
204
+ critical = np.ascontiguousarray(crit[ph][..., None])
205
+ brittle = bool(np.isfinite(critical).any())
206
+ return Membrane(
207
+ mesh,
208
+ flow,
209
+ young=_moduli(young, len(phases))[ph][..., None],
210
+ poisson=poisson,
211
+ thickness=thickness,
212
+ critical=critical if brittle else None,
213
+ fracture_radius=fracture_radius if brittle else None,
214
+ )
215
+
216
+
217
+ def sheet_tests(
218
+ design,
219
+ *,
220
+ pixel: float = 1.0,
221
+ phases=None,
222
+ angles=(0.0, 45.0, 90.0),
223
+ element: float | None = None,
224
+ max_strain: float = 0.3,
225
+ fracture_radius: float | None = FRACTURE_RADIUS,
226
+ young: float = 210000.0,
227
+ thickness: float = 1.0,
228
+ ) -> dict:
229
+ """The sheet of a periodic design pulled in each direction of ``angles`` (degrees
230
+ from x; see the module): ``{"directions": {angle: measures}, ...}`` with, for each
231
+ direction, the yield and tensile strengths (MPa), the failure strain, the energy up
232
+ to it (MJ/m³), Lankford's coefficient, whether a brittle phase broke first, and the
233
+ result of the test; and over the directions the means and spreads (max − min over
234
+ the mean) of the yield strength, the failure strain and the energy."""
235
+ d = np.asarray(design, dtype=np.int64)
236
+ ny, nx = d.shape
237
+ size = (nx * pixel, ny * pixel)
238
+ cell = PeriodicCell.build(
239
+ (size[0], 0.0),
240
+ (0.0, size[1]),
241
+ element=element or 0.5 * pixel,
242
+ centre=(0.5 * size[0], 0.5 * size[1]),
243
+ )
244
+ out = {}
245
+ for angle in angles:
246
+ mem = design_membrane(
247
+ cell.mesh,
248
+ d,
249
+ pixel=pixel,
250
+ phases=phases,
251
+ origin=cell.origin,
252
+ young=young,
253
+ thickness=thickness,
254
+ fracture_radius=fracture_radius,
255
+ )
256
+ res = cell_test(mem, cell, float(angle), max_strain=max_strain, failure_margin=0.03)
257
+ fail = res.failure_strain if math.isfinite(res.failure_strain) else math.inf
258
+ m = failure_measures(res.strain, res.stress, fail, young=young)
259
+ m["r_value"] = res.r_value()
260
+ m["broke"] = bool(fail < m["uniform_elongation"] - 1e-9)
261
+ m["result"] = res
262
+ out[float(angle)] = m
263
+
264
+ def spread(key):
265
+ v = np.array([out[a][key] for a in out], dtype=float)
266
+ return float(v.mean()), float((v.max() - v.min()) / v.mean()) if v.mean() else math.nan
267
+
268
+ summary = {"directions": out}
269
+ for key in ("yield_strength", "tensile_strength", "failure_strain", "energy", "r_value"):
270
+ summary[f"{key}_mean"], summary[f"{key}_spread"] = spread(key)
271
+ return summary
272
+
273
+
274
+ def periodic_lines(lines, a1, a2, box, reach: float = 0.0) -> list:
275
+ """The polylines ``lines`` (mm) and their images by the lattice of ``a1`` and
276
+ ``a2`` that come within ``reach`` of the box ``(x0, x1, y0, y1)``: the tracks of a
277
+ pattern repeated over the sheet, as they cross a periodic cell."""
278
+ a1, a2 = np.asarray(a1, dtype=float), np.asarray(a2, dtype=float)
279
+ area = abs(a1[0] * a2[1] - a1[1] * a2[0])
280
+ if area <= 0:
281
+ raise ValueError("periodic lines: a1 and a2 parallel")
282
+ h = area / max(np.linalg.norm(a1), np.linalg.norm(a2)) # the smaller height of the cell
283
+ x0, x1, y0, y1 = box
284
+ out = []
285
+ for line in lines:
286
+ pts = np.asarray(line, dtype=float)
287
+ lo, hi = pts.min(axis=0), pts.max(axis=0)
288
+ centre = 0.5 * np.array([x0 + x1, y0 + y1])
289
+ # enough images to reach the box from wherever the line lies
290
+ span = (
291
+ max(x1 - x0, y1 - y0)
292
+ + float(np.max(hi - lo))
293
+ + float(np.linalg.norm(0.5 * (lo + hi) - centre))
294
+ + 2.0 * reach
295
+ )
296
+ n = math.ceil(span / h) + 1
297
+ for i in range(-n, n + 1):
298
+ for j in range(-n, n + 1):
299
+ q = pts + i * a1 + j * a2
300
+ qlo, qhi = q.min(axis=0), q.max(axis=0)
301
+ if (
302
+ qhi[0] >= x0 - reach
303
+ and qlo[0] <= x1 + reach
304
+ and qhi[1] >= y0 - reach
305
+ and qlo[1] <= y1 + reach
306
+ ):
307
+ out.append(q)
308
+ return out
309
+
310
+
311
+ def track_membrane(
312
+ mesh,
313
+ lines,
314
+ width,
315
+ *,
316
+ phases=None,
317
+ kinds=None,
318
+ young=210000.0,
319
+ poisson: float = 0.3,
320
+ thickness: float = 1.0,
321
+ fracture_radius: float | None = FRACTURE_RADIUS,
322
+ subdivisions: int = 4,
323
+ ) -> Membrane:
324
+ """The membrane of a mesh crossed by tracks along the polylines ``lines`` (their
325
+ centre lines; see the module), ``width`` mm wide (one width, or one per line): the
326
+ share ``w_k`` of the region of each Gauss point inside the tracks of each treated
327
+ phase ``k`` (``kinds``: the phase of each line, 1 by default; ``phases``: the
328
+ untreated first, :func:`~morphogen.laser.cells.wang_phases` by default) mixes the
329
+ flow stress of the untreated phase with that of the treated phase of the largest
330
+ share as ``(1 − w) σ_0 + w σ_k`` (``w`` the sum of the shares), and Young's moduli
331
+ (``young``: one modulus, or one per phase) by the shares; a point mostly inside a
332
+ track takes the critical strain of that phase. Several kinds: a track whose
333
+ treatment changes along it, tracks of several treatments."""
334
+ phases = tuple(Phase.from_config(p) for p in (phases or wang_phases()))
335
+ n = len(phases)
336
+ if n < 2:
337
+ raise ValueError("track membrane: at least two phases, the untreated first")
338
+ lines = [np.asarray(line, dtype=float) for line in lines]
339
+ kinds = [1] * len(lines) if kinds is None else [int(k) for k in kinds]
340
+ widths = np.broadcast_to(np.asarray(width, dtype=float), (len(lines),))
341
+ if len(kinds) != len(lines) or any(not 1 <= k < n for k in kinds):
342
+ raise ValueError(f"kinds: one phase from 1 to {n - 1} for each line")
343
+ if np.any(widths <= 0):
344
+ raise ValueError("track membrane: positive widths")
345
+ ne = len(mesh.quads)
346
+ shares = np.zeros((ne, 4, n))
347
+ for k, w in {(k, float(w)) for k, w in zip(kinds, widths, strict=True)}:
348
+ sel = [ln for ln, kk, ww in zip(lines, kinds, widths, strict=True) if kk == k and ww == w]
349
+ part = band_fractions(mesh, sel, w, n=subdivisions)
350
+ shares[..., k] = np.maximum(shares[..., k], part)
351
+ total = shares[..., 1:].sum(axis=-1)
352
+ over = total > 1.0 # crossing tracks: their shares scaled to the region
353
+ shares[over, 1:] /= total[over, None]
354
+ total = np.minimum(total, 1.0)
355
+ shares[..., 0] = 1.0 - total
356
+ top = 1 + np.argmax(shares[..., 1:], axis=-1)
357
+ laws = np.array([[p.law.code, p.law.sigma0, p.law.a, p.law.b] for p in phases], dtype=float)
358
+ shape = (ne, 4, 1)
359
+ flow = [np.full(shape, v) for v in laws[0]]
360
+ flow += [np.ascontiguousarray(laws[top][..., k][..., None]) for k in range(4)]
361
+ flow.append(np.ascontiguousarray(total[..., None]))
362
+ e = _moduli(young, n)
363
+ moduli = np.ascontiguousarray((shares @ e)[..., None])
364
+ crit = np.array([p.critical for p in phases], dtype=float)
365
+ critical = np.where(total > 0.5, crit[top], crit[0])[..., None]
366
+ brittle = bool(np.isfinite(critical).any())
367
+ return Membrane(
368
+ mesh,
369
+ flow,
370
+ young=moduli,
371
+ poisson=poisson,
372
+ thickness=thickness,
373
+ critical=np.ascontiguousarray(critical) if brittle else None,
374
+ fracture_radius=fracture_radius if brittle else None,
375
+ )
@@ -0,0 +1,216 @@
1
+ """Three-point bending of a laser-architectured strip: fibre sections of a beam.
2
+
3
+ A strip of width ``W`` and thickness ``h`` rests on two supports ``span`` apart and is
4
+ loaded at mid-span by ``F``: the bending moment is ``M(x) = F/2 (S/2 − |x − x_c|)``
5
+ (statically determinate, small deflections, no membrane force). Each cross-section is a
6
+ grid of fibres across the width and through the thickness (the layers of the
7
+ treatment), each with the flow law of its hardness, loaded monotonically in uniaxial
8
+ stress: ``|σ| = E|ε|`` up to yield, then ``σ = σ_y(p)`` with ``|ε| = p + σ/E``. Plane
9
+ sections: ``ε = −κ (z − z_n)``, the neutral axis ``z_n`` from ``Σ σ dA = 0`` (it moves
10
+ off the mid-plane of a strip treated on one face), ``M = −Σ σ (z − z_n) dA``. The
11
+ curvature of each section follows from the moment by inverting ``M(κ)``, the deflection
12
+ under the load from the principle of virtual work, ``δ = ∫ κ(x) m(x) dx``,
13
+ ``m = (S/2 − |x − x_c|)/2`` (exact for the statically determinate beam). The limit load
14
+ ``4 M_max / S`` is reached when the weakest section near the load cannot carry more.
15
+ Checked: the elastic stiffness ``48 E I / S³`` and the limit load ``σ0 W h² / S`` of a
16
+ perfectly plastic strip.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import math
22
+ from dataclasses import dataclass, field
23
+
24
+ import numpy as np
25
+
26
+
27
+ @dataclass
28
+ class BendingResult:
29
+ """The load (N) against the deflection (mm) under it, the largest load of the tables
30
+ (the limit load of a perfectly plastic strip; of a hardening one, the load at an
31
+ outer strain of about 100 times the strain of first yield), the initial stiffness
32
+ (N/mm), the load and the energy (mJ) at the reference deflection, and the
33
+ moment-curvature tables of the sections."""
34
+
35
+ deflection: np.ndarray
36
+ load: np.ndarray
37
+ max_load: float
38
+ stiffness: float
39
+ load_at_deflection: float
40
+ energy: float
41
+ reference_deflection: float
42
+ sections: dict = field(default_factory=dict, repr=False)
43
+
44
+ def summary(self) -> dict:
45
+ return {
46
+ "bending_load": self.max_load,
47
+ "bending_stiffness": self.stiffness,
48
+ "bending_load_at_deflection": self.load_at_deflection,
49
+ "bending_energy": self.energy,
50
+ }
51
+
52
+
53
+ def _fibre_curves(kind, s0, a, b, young, strains, offset):
54
+ """Stresses of fibres (n) at the strains (m) of a common grid, monotonic uniaxial
55
+ loading: ``(n, m)``."""
56
+ kind = np.asarray(kind)[:, None]
57
+ s0, a, b = (np.asarray(v, dtype=float)[:, None] for v in (s0, a, b))
58
+ e = np.asarray(strains, dtype=float)[None, :]
59
+
60
+ def flow(p):
61
+ ludwik = s0 + a * ((p + offset) ** b - offset**b)
62
+ voce = s0 + a * (1.0 - np.exp(-b * p))
63
+ with np.errstate(invalid="ignore", divide="ignore"):
64
+ swift = a * ((s0 / a) ** (1.0 / b) + p) ** b
65
+ return np.where(kind == 0, ludwik, np.where(kind == 2, swift, voce))
66
+
67
+ elastic = young * e
68
+ plastic = elastic > s0
69
+ lo = np.zeros(np.broadcast(kind, e).shape)
70
+ hi = np.broadcast_to(e, lo.shape).copy()
71
+ for _ in range(48): # bisection on p: e = p + sigma(p)/E
72
+ mid = 0.5 * (lo + hi)
73
+ up = mid + flow(mid) / young < e
74
+ lo = np.where(up, mid, lo)
75
+ hi = np.where(up, hi, mid)
76
+ p = 0.5 * (lo + hi)
77
+ return np.where(plastic, flow(p), elastic)
78
+
79
+
80
+ def section_tables(
81
+ kind,
82
+ s0,
83
+ a,
84
+ b,
85
+ *,
86
+ width: float,
87
+ thickness: float,
88
+ young: float,
89
+ curvatures,
90
+ offset: float = 1e-4,
91
+ strains: int = 600,
92
+ ) -> dict:
93
+ """Moment-curvature tables of sections: flow laws ``(sections, ny, layers)``
94
+ (fibres across the width and through the thickness, the layer 0 at the upper
95
+ face); returns the curvatures, moments ``(sections, curvatures)`` and neutral axes."""
96
+ kind = np.asarray(kind)
97
+ ns, ny, nl = kind.shape
98
+ h = float(thickness)
99
+ z = (np.arange(nl) + 0.5) * h / nl - 0.5 * h # from the mid-plane, upwards = upper face
100
+ z = -z # layer 0 (upper face) at z = +h/2
101
+ da = width / ny * h / nl
102
+ kap = np.asarray(curvatures, dtype=float)
103
+ emax = float(np.max(kap) * h * 1.05) + 1e-12
104
+ grid = np.linspace(0.0, emax, strains)
105
+ laws = np.column_stack([kind.ravel(), np.ravel(s0), np.ravel(a), np.ravel(b)])
106
+ unique, inverse = np.unique(laws, axis=0, return_inverse=True) # the distinct laws
107
+ curves = _fibre_curves(
108
+ unique[:, 0].astype(np.int64),
109
+ unique[:, 1],
110
+ unique[:, 2],
111
+ unique[:, 3],
112
+ young,
113
+ grid,
114
+ offset,
115
+ )[inverse.ravel()].reshape(ns, ny, nl, strains)
116
+ # a section: its fibres share z; sum the stresses across the width per layer
117
+ layer_curves = curves.sum(axis=1) * da # ns x nl x strains (force per strain)
118
+ de = grid[1] - grid[0]
119
+
120
+ def force(eps): # ns x nl strains -> ns x nl forces (odd in the strain)
121
+ idx = np.clip(np.abs(eps) / de, 0.0, strains - 1.000001)
122
+ i0 = np.floor(idx).astype(np.int64)
123
+ f = idx - i0
124
+ ii = np.arange(ns)[:, None]
125
+ ll = np.arange(nl)[None, :]
126
+ v = (1.0 - f) * layer_curves[ii, ll, i0] + f * layer_curves[ii, ll, i0 + 1]
127
+ return np.sign(eps) * v
128
+
129
+ moments = np.zeros((ns, len(kap)))
130
+ axes = np.zeros((ns, len(kap)))
131
+ for j, k in enumerate(kap):
132
+ if k == 0.0:
133
+ continue
134
+ lo, hi = np.full(ns, -0.5 * h), np.full(ns, 0.5 * h)
135
+ for _ in range(50): # the neutral axis: the axial force vanishes
136
+ zn = 0.5 * (lo + hi)
137
+ n_ax = force(-k * (z[None, :] - zn[:, None])).sum(axis=1)
138
+ tension = n_ax > 0 # the force grows as the axis rises: lower it
139
+ hi = np.where(tension, zn, hi)
140
+ lo = np.where(tension, lo, zn)
141
+ zn = 0.5 * (lo + hi)
142
+ f = force(-k * (z[None, :] - zn[:, None]))
143
+ moments[:, j] = -(f * (z[None, :] - zn[:, None])).sum(axis=1)
144
+ axes[:, j] = zn
145
+ return {"curvatures": kap, "moments": moments, "axes": axes, "z": z}
146
+
147
+
148
+ def _deflection(integrand, xs) -> float:
149
+ """``∫ κ m dx`` by Simpson's rule on each half of the span (the moment has a kink
150
+ under the load, at the middle section)."""
151
+ from scipy.integrate import simpson
152
+
153
+ mid = len(xs) // 2
154
+ if len(xs) % 2 == 0 or mid < 2:
155
+ return float(np.trapezoid(integrand, xs))
156
+ left = simpson(integrand[: mid + 1], x=xs[: mid + 1])
157
+ right = simpson(integrand[mid:], x=xs[mid:])
158
+ return float(left + right)
159
+
160
+
161
+ def three_point_bending(
162
+ kind,
163
+ s0,
164
+ a,
165
+ b,
166
+ *,
167
+ span: float,
168
+ width: float,
169
+ thickness: float,
170
+ young: float = 210000.0,
171
+ deflection: float | None = None,
172
+ loads: int = 120,
173
+ ) -> BendingResult:
174
+ """Three-point bending (see the module) of a strip whose sections, equally spaced
175
+ over the span (``(sections, ny, layers)`` flow laws, the first section at the left
176
+ support, the last at the right one; an odd number puts one under the load), are
177
+ given; ``deflection``: the reference
178
+ deflection of the load and the energy (default: a fiftieth of the span)."""
179
+ kind = np.asarray(kind)
180
+ ns = kind.shape[0]
181
+ s = float(span)
182
+ xs = np.linspace(0.0, s, ns)
183
+ arm = 0.5 * s - np.abs(xs - 0.5 * s) # M = F/2 arm, m = arm/2
184
+ h, w = float(thickness), float(width)
185
+ inertia = w * h**3 / 12.0
186
+ s0_min = float(np.nanmin(s0))
187
+ k_el = 2.0 * s0_min / (young * h)
188
+ kap = np.concatenate(
189
+ [np.linspace(0.0, k_el, 20, endpoint=False), np.geomspace(k_el, 100.0 * k_el, 160)]
190
+ )
191
+ tab = section_tables(
192
+ kind, s0, a, b, width=w, thickness=h, young=young, curvatures=kap, strains=2000
193
+ )
194
+ mom = np.maximum.accumulate(tab["moments"], axis=1) # monotone tables
195
+ m_max = mom[:, -1]
196
+ with np.errstate(divide="ignore"):
197
+ f_lim = np.where(arm > 0, 2.0 * m_max / np.maximum(arm, 1e-300), np.inf)
198
+ f_max = float(f_lim.min())
199
+ forces = f_max * (1.0 - np.geomspace(1.0, 1e-3, loads)) # dense near the limit
200
+ forces = np.concatenate([[0.0], forces[forces > 0]])
201
+ defl = np.zeros(len(forces))
202
+ for i, f in enumerate(forces):
203
+ mx = 0.5 * f * arm
204
+ kx = np.array([np.interp(mx[j], mom[j], kap) for j in range(ns)])
205
+ defl[i] = _deflection(kx * 0.5 * arm, xs)
206
+ ref = float(deflection) if deflection is not None else s / 50.0
207
+ stiff = 48.0 * young * inertia / s**3
208
+ if len(forces) > 2 and defl[1] > 0:
209
+ stiff = float(forces[1] / defl[1])
210
+ reached = defl[-1] >= ref
211
+ f_ref = float(np.interp(ref, defl, forces)) if reached else math.nan
212
+ upto = defl <= ref
213
+ dd = np.append(defl[upto], ref) if reached else defl
214
+ ff = np.append(forces[upto], f_ref) if reached else forces
215
+ energy = float(np.trapezoid(ff, dd)) # N mm = mJ
216
+ return BendingResult(defl, forces, f_max, stiff, f_ref, energy, ref, sections={"x": xs, **tab})