morphogen 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- morphogen/__init__.py +60 -0
- morphogen/__main__.py +7 -0
- morphogen/_platform.py +55 -0
- morphogen/_public.py +153 -0
- morphogen/_utils.py +80 -0
- morphogen/_version.py +1 -0
- morphogen/analysis/__init__.py +174 -0
- morphogen/analysis/anisotropy.py +135 -0
- morphogen/analysis/basic.py +38 -0
- morphogen/analysis/cells.py +54 -0
- morphogen/analysis/connectivity.py +156 -0
- morphogen/analysis/correlation.py +195 -0
- morphogen/analysis/covariance.py +80 -0
- morphogen/analysis/fractal.py +54 -0
- morphogen/analysis/measures.py +188 -0
- morphogen/analysis/morphology.py +265 -0
- morphogen/analysis/particles.py +160 -0
- morphogen/analysis/percolation.py +2034 -0
- morphogen/analysis/power_laws.py +143 -0
- morphogen/analysis/random_sets.py +351 -0
- morphogen/analysis/stereology.py +289 -0
- morphogen/analysis/surface.py +107 -0
- morphogen/analysis/topology.py +92 -0
- morphogen/automata/__init__.py +74 -0
- morphogen/automata/engine.py +211 -0
- morphogen/automata/growth.py +686 -0
- morphogen/automata/lattice.py +143 -0
- morphogen/automata/reaction.py +255 -0
- morphogen/automata/rules.py +353 -0
- morphogen/automata/tilings.py +1715 -0
- morphogen/cli.py +3526 -0
- morphogen/config.py +2167 -0
- morphogen/contact/__init__.py +113 -0
- morphogen/contact/experiments.py +368 -0
- morphogen/contact/hertz.py +104 -0
- morphogen/contact/kernels.py +827 -0
- morphogen/contact/periodic.py +278 -0
- morphogen/contact/problem.py +578 -0
- morphogen/contact/surfaces.py +310 -0
- morphogen/coupling/__init__.py +43 -0
- morphogen/coupling/ageing.py +143 -0
- morphogen/coupling/diffusion.py +226 -0
- morphogen/coupling/fenicsx.py +484 -0
- morphogen/coupling/oxidation.py +447 -0
- morphogen/coupling/plates.py +247 -0
- morphogen/design/__init__.py +51 -0
- morphogen/design/csp.py +616 -0
- morphogen/design/frames.py +277 -0
- morphogen/design/search.py +287 -0
- morphogen/design/tiles.py +336 -0
- morphogen/distributions.py +312 -0
- morphogen/domain.py +203 -0
- morphogen/dynamics/__init__.py +179 -0
- morphogen/dynamics/model.py +638 -0
- morphogen/dynamics/openradioss.py +643 -0
- morphogen/dynamics/results.py +515 -0
- morphogen/fracture/__init__.py +170 -0
- morphogen/fracture/bulk.py +349 -0
- morphogen/fracture/cohesive.py +1614 -0
- morphogen/fracture/ductile.py +557 -0
- morphogen/fracture/lefm.py +1168 -0
- morphogen/fracture/mixed.py +1178 -0
- morphogen/fracture/periodic.py +733 -0
- morphogen/fracture/phasefield.py +714 -0
- morphogen/fracture/phasefield_finite.py +368 -0
- morphogen/fracture/surface.py +572 -0
- morphogen/fracture/toughness.py +566 -0
- morphogen/gpu.py +108 -0
- morphogen/gui/__init__.py +8 -0
- morphogen/gui/api.py +1927 -0
- morphogen/gui/desktop.py +387 -0
- morphogen/gui/icon.png +0 -0
- morphogen/gui/index.html +1909 -0
- morphogen/gui/server.py +229 -0
- morphogen/gui/tools/__init__.py +629 -0
- morphogen/gui/tools/compare.py +149 -0
- morphogen/gui/tools/contact.py +391 -0
- morphogen/gui/tools/couplings.py +1085 -0
- morphogen/gui/tools/crackfront.py +245 -0
- morphogen/gui/tools/design.py +224 -0
- morphogen/gui/tools/dynamics.py +824 -0
- morphogen/gui/tools/fracture.py +2586 -0
- morphogen/gui/tools/interop.py +1654 -0
- morphogen/gui/tools/learning.py +595 -0
- morphogen/gui/tools/mechanics.py +3881 -0
- morphogen/gui/tools/nonlocal_damage.py +1321 -0
- morphogen/gui/tools/phasefield.py +215 -0
- morphogen/gui/tools/physics.py +597 -0
- morphogen/gui/tools/stability.py +1756 -0
- morphogen/gui/tools/statistics.py +1408 -0
- morphogen/gui/viewer.js +1100 -0
- morphogen/homogenization/__init__.py +210 -0
- morphogen/homogenization/acoustics.py +566 -0
- morphogen/homogenization/amg.py +1005 -0
- morphogen/homogenization/apparent.py +1046 -0
- morphogen/homogenization/behaviours.cu +2285 -0
- morphogen/homogenization/behaviours.py +944 -0
- morphogen/homogenization/beremin.py +263 -0
- morphogen/homogenization/bifurcation.py +1085 -0
- morphogen/homogenization/bloch.py +507 -0
- morphogen/homogenization/bounds.py +226 -0
- morphogen/homogenization/core.py +458 -0
- morphogen/homogenization/coupled.py +1135 -0
- morphogen/homogenization/crystal.py +2967 -0
- morphogen/homogenization/dilatation.py +454 -0
- morphogen/homogenization/elements.py +157 -0
- morphogen/homogenization/fatigue.py +768 -0
- morphogen/homogenization/fe.py +1739 -0
- morphogen/homogenization/fenicsx.py +307 -0
- morphogen/homogenization/fft.py +499 -0
- morphogen/homogenization/fft_nonlinear.py +391 -0
- morphogen/homogenization/finite.py +613 -0
- morphogen/homogenization/flow.py +361 -0
- morphogen/homogenization/frames.py +1125 -0
- morphogen/homogenization/gpu.py +1241 -0
- morphogen/homogenization/harmonic.py +427 -0
- morphogen/homogenization/identification.py +579 -0
- morphogen/homogenization/kernels.py +760 -0
- morphogen/homogenization/laws.py +2061 -0
- morphogen/homogenization/materials.py +1080 -0
- morphogen/homogenization/mfront.py +589 -0
- morphogen/homogenization/networks.py +880 -0
- morphogen/homogenization/nonlinear.py +2612 -0
- morphogen/homogenization/ntfa.py +577 -0
- morphogen/homogenization/paths.py +476 -0
- morphogen/homogenization/photonic.py +467 -0
- morphogen/homogenization/poroelastic.py +212 -0
- morphogen/homogenization/porous.py +1120 -0
- morphogen/homogenization/postprocess.py +290 -0
- morphogen/homogenization/solvers.py +1140 -0
- morphogen/homogenization/tensors.py +240 -0
- morphogen/homogenization/voxel_fe.py +457 -0
- morphogen/homogenization/xfem.py +1016 -0
- morphogen/homogenization/zmat.py +1258 -0
- morphogen/iga/__init__.py +48 -0
- morphogen/iga/analysis.py +508 -0
- morphogen/iga/basis.py +214 -0
- morphogen/iga/geometry.py +501 -0
- morphogen/iga/homogenization.py +219 -0
- morphogen/iga/optimization.py +700 -0
- morphogen/iga/shapes.py +331 -0
- morphogen/image.py +128 -0
- morphogen/io/__init__.py +246 -0
- morphogen/io/amitex.py +741 -0
- morphogen/io/ebsd.py +881 -0
- morphogen/io/export.py +196 -0
- morphogen/io/geometry.py +158 -0
- morphogen/io/medit.py +147 -0
- morphogen/io/meshes.py +844 -0
- morphogen/io/metaimage.py +97 -0
- morphogen/io/mfront.py +1104 -0
- morphogen/io/native.py +57 -0
- morphogen/io/radioss.py +764 -0
- morphogen/io/solvers.py +371 -0
- morphogen/io/tables.py +278 -0
- morphogen/io/tiff.py +66 -0
- morphogen/io/vtk.py +701 -0
- morphogen/io/xdmf.py +200 -0
- morphogen/kernels/__init__.py +5 -0
- morphogen/kernels/annealing.py +192 -0
- morphogen/kernels/cells.py +69 -0
- morphogen/kernels/collective.py +87 -0
- morphogen/kernels/force_biased.py +595 -0
- morphogen/kernels/implicit.py +145 -0
- morphogen/kernels/leaves.py +132 -0
- morphogen/kernels/packing.py +304 -0
- morphogen/kernels/raster.py +279 -0
- morphogen/kernels/rsa.py +371 -0
- morphogen/kernels/union.py +135 -0
- morphogen/kernels/watershed.py +190 -0
- morphogen/laser/__init__.py +234 -0
- morphogen/laser/architectures.py +375 -0
- morphogen/laser/bending.py +216 -0
- morphogen/laser/cells.py +1694 -0
- morphogen/laser/design.py +940 -0
- morphogen/laser/figures.py +227 -0
- morphogen/laser/heat.py +804 -0
- morphogen/laser/materials.py +691 -0
- morphogen/laser/mechanics.py +1670 -0
- morphogen/laser/metallurgy.py +615 -0
- morphogen/laser/patterns.py +828 -0
- morphogen/laser/periodic.py +392 -0
- morphogen/laser/process.py +362 -0
- morphogen/laser/run.py +534 -0
- morphogen/laser/solid.py +216 -0
- morphogen/laser/specimen.py +200 -0
- morphogen/laser/structures.py +708 -0
- morphogen/learning/__init__.py +81 -0
- morphogen/learning/behaviour.py +398 -0
- morphogen/learning/data.py +328 -0
- morphogen/learning/learned.cpp +668 -0
- morphogen/learning/logarithmic.py +202 -0
- morphogen/learning/mfront.py +409 -0
- morphogen/learning/networks.py +767 -0
- morphogen/learning/run.py +212 -0
- morphogen/learning/standard.py +814 -0
- morphogen/learning/training.py +235 -0
- morphogen/mesh/__init__.py +29 -0
- morphogen/mesh/conforming.py +1423 -0
- morphogen/mesh/curved.py +600 -0
- morphogen/mesh/exact.py +1717 -0
- morphogen/mesh/octree.py +350 -0
- morphogen/mesh/polycrystal.py +1041 -0
- morphogen/mesh/polyhedra.py +677 -0
- morphogen/mesh/regularize.py +570 -0
- morphogen/mesh/surface.py +97 -0
- morphogen/mesh/tetra.py +512 -0
- morphogen/mesh/voxel.py +124 -0
- morphogen/micromorphic/__init__.py +31 -0
- morphogen/micromorphic/damage.py +359 -0
- morphogen/micromorphic/ductile.py +534 -0
- morphogen/micromorphic/finite.py +220 -0
- morphogen/micromorphic/microfoam.py +787 -0
- morphogen/micromorphic/space.py +341 -0
- morphogen/models/__init__.py +195 -0
- morphogen/models/affine.py +384 -0
- morphogen/models/automata.py +592 -0
- morphogen/models/base.py +500 -0
- morphogen/models/boolean.py +310 -0
- morphogen/models/bouligand.py +331 -0
- morphogen/models/branching.py +241 -0
- morphogen/models/combination.py +430 -0
- morphogen/models/deadleaves.py +766 -0
- morphogen/models/design.py +289 -0
- morphogen/models/ebsd.py +206 -0
- morphogen/models/fibers.py +1476 -0
- morphogen/models/foam.py +594 -0
- morphogen/models/gaussian.py +314 -0
- morphogen/models/growth.py +459 -0
- morphogen/models/hardcore.py +317 -0
- morphogen/models/hierarchical.py +269 -0
- morphogen/models/honeycomb.py +749 -0
- morphogen/models/implicit.py +177 -0
- morphogen/models/laminate.py +470 -0
- morphogen/models/lattice.py +351 -0
- morphogen/models/lattice_field.py +345 -0
- morphogen/models/levelset_foam.py +563 -0
- morphogen/models/nacre.py +411 -0
- morphogen/models/nested.py +924 -0
- morphogen/models/osteons.py +374 -0
- morphogen/models/pieces.py +167 -0
- morphogen/models/planar.py +126 -0
- morphogen/models/reconstruction.py +203 -0
- morphogen/models/scale_rich.py +1409 -0
- morphogen/models/scale_rich_3d.py +1616 -0
- morphogen/models/tessellation.py +735 -0
- morphogen/models/tiling_field.py +302 -0
- morphogen/models/tpms.py +197 -0
- morphogen/models/transparent.py +406 -0
- morphogen/models/union.py +141 -0
- morphogen/optimization/__init__.py +43 -0
- morphogen/optimization/cell.py +295 -0
- morphogen/optimization/filters.py +115 -0
- morphogen/optimization/mma.py +226 -0
- morphogen/optimization/run.py +219 -0
- morphogen/optimization/topology.py +632 -0
- morphogen/orientations.py +568 -0
- morphogen/parallel.py +599 -0
- morphogen/pipeline.py +978 -0
- morphogen/primitives.py +188 -0
- morphogen/results.py +564 -0
- morphogen/rve/__init__.py +73 -0
- morphogen/rve/report.py +627 -0
- morphogen/rve/scaling.py +363 -0
- morphogen/rve/study.py +1054 -0
- morphogen/rve/windows.py +345 -0
- morphogen/seeding.py +51 -0
- morphogen/settings.py +118 -0
- morphogen/stopping.py +48 -0
- morphogen/symmetry.py +384 -0
- morphogen/templates/activator_inhibitor.yaml +22 -0
- morphogen/templates/aggregation.yaml +23 -0
- morphogen/templates/boolean_cylinders.yaml +20 -0
- morphogen/templates/boolean_spheres.yaml +22 -0
- morphogen/templates/bouligand.yaml +28 -0
- morphogen/templates/cellular_automaton.yaml +25 -0
- morphogen/templates/coated_spheres.yaml +26 -0
- morphogen/templates/contact_fibers.yaml +27 -0
- morphogen/templates/cox_nanocomposite.yaml +22 -0
- morphogen/templates/cross_linked_fibers.yaml +26 -0
- morphogen/templates/curved_arcs.yaml +28 -0
- morphogen/templates/curved_fibers.yaml +24 -0
- morphogen/templates/dead_leaves.yaml +22 -0
- morphogen/templates/delaunay_network.yaml +22 -0
- morphogen/templates/dense_packing.yaml +22 -0
- morphogen/templates/diffusion.yaml +33 -0
- morphogen/templates/ebsd.yaml +34 -0
- morphogen/templates/ebsd_map.ctf +3087 -0
- morphogen/templates/fracture_composite.yaml +42 -0
- morphogen/templates/fracture_rubber.yaml +47 -0
- morphogen/templates/gaussian_excursion.yaml +17 -0
- morphogen/templates/graded_lattice.yaml +24 -0
- morphogen/templates/hardcore_fibers.yaml +22 -0
- morphogen/templates/hardcore_spheres.yaml +22 -0
- morphogen/templates/hierarchical_lattice.yaml +22 -0
- morphogen/templates/homogenization_acoustic_foam.yaml +36 -0
- morphogen/templates/homogenization_beremin.yaml +50 -0
- morphogen/templates/homogenization_cleavage.yaml +51 -0
- morphogen/templates/homogenization_cleavage_band.yaml +55 -0
- morphogen/templates/homogenization_contact.yaml +43 -0
- morphogen/templates/homogenization_crack_closure.yaml +49 -0
- morphogen/templates/homogenization_crystal_plasticity.yaml +50 -0
- morphogen/templates/homogenization_crystal_plasticity_fft.yaml +52 -0
- morphogen/templates/homogenization_crystallization.yaml +30 -0
- morphogen/templates/homogenization_debonding.yaml +43 -0
- morphogen/templates/homogenization_detwinning.yaml +58 -0
- morphogen/templates/homogenization_ductile_damage.yaml +47 -0
- morphogen/templates/homogenization_fatigue.yaml +40 -0
- morphogen/templates/homogenization_grain_fracture.yaml +56 -0
- morphogen/templates/homogenization_gyroid.yaml +30 -0
- morphogen/templates/homogenization_intergranular.yaml +43 -0
- morphogen/templates/homogenization_interphase.yaml +42 -0
- morphogen/templates/homogenization_mixed_loading.yaml +33 -0
- morphogen/templates/homogenization_ntfa.yaml +56 -0
- morphogen/templates/homogenization_piezoelectric.yaml +27 -0
- morphogen/templates/homogenization_polycrystal.yaml +30 -0
- morphogen/templates/homogenization_polycrystal_inclusions.yaml +30 -0
- morphogen/templates/homogenization_poroelastic.yaml +26 -0
- morphogen/templates/homogenization_rubber.yaml +40 -0
- morphogen/templates/homogenization_slip_cleavage.yaml +50 -0
- morphogen/templates/homogenization_spheres.yaml +31 -0
- morphogen/templates/homogenization_transport.yaml +29 -0
- morphogen/templates/homogenization_twinning.yaml +54 -0
- morphogen/templates/homogenization_viscoelastic.yaml +34 -0
- morphogen/templates/homogenization_viscoplastic.yaml +42 -0
- morphogen/templates/homogenization_voronoi.yaml +26 -0
- morphogen/templates/homogenization_xfem.yaml +23 -0
- morphogen/templates/hyperuniform_cells.yaml +24 -0
- morphogen/templates/laguerre.yaml +18 -0
- morphogen/templates/laser_bending.yaml +35 -0
- morphogen/templates/laser_cells.yaml +38 -0
- morphogen/templates/laser_corrugated.yaml +36 -0
- morphogen/templates/level_set_foam.yaml +29 -0
- morphogen/templates/menger_sponge.yaml +17 -0
- morphogen/templates/nacre.yaml +25 -0
- morphogen/templates/nucleation_growth.yaml +25 -0
- morphogen/templates/optimize_auxetic.yaml +29 -0
- morphogen/templates/optimize_auxetic_3d.yaml +27 -0
- morphogen/templates/optimize_bulk.yaml +23 -0
- morphogen/templates/optimize_conductivity.yaml +20 -0
- morphogen/templates/osteons.yaml +28 -0
- morphogen/templates/penetrable_spheres.yaml +21 -0
- morphogen/templates/poisson_fibers.yaml +21 -0
- morphogen/templates/random_laminate.yaml +26 -0
- morphogen/templates/random_lattice.yaml +27 -0
- morphogen/templates/random_walk_fibers.yaml +26 -0
- morphogen/templates/reaction_diffusion.yaml +22 -0
- morphogen/templates/reconstruction.yaml +22 -0
- morphogen/templates/rve_cellular_automaton.yaml +23 -0
- morphogen/templates/rve_crystal_plasticity_fft.yaml +51 -0
- morphogen/templates/rve_multiphysics.yaml +43 -0
- morphogen/templates/rve_poisson_fibers.yaml +22 -0
- morphogen/templates/rve_poisson_fibers_fe.yaml +33 -0
- morphogen/templates/rve_voronoi_windows.yaml +20 -0
- morphogen/templates/scale_rich_network.yaml +29 -0
- morphogen/templates/scale_rich_plates.yaml +30 -0
- morphogen/templates/sequential_dead_leaves.yaml +25 -0
- morphogen/templates/strut_lattice.yaml +21 -0
- morphogen/templates/tile_assembly.yaml +28 -0
- morphogen/templates/tpms.yaml +19 -0
- morphogen/templates/trabecular_bone.yaml +29 -0
- morphogen/templates/transparent_dead_leaves.yaml +23 -0
- morphogen/templates/vascular_tree.yaml +23 -0
- morphogen/templates/voronoi.yaml +20 -0
- morphogen/templates/wood.yaml +34 -0
- morphogen/templates/workflow.yaml +56 -0
- morphogen/texture.py +665 -0
- morphogen/theory.py +162 -0
- morphogen/viz/__init__.py +12 -0
- morphogen/viz/export.py +244 -0
- morphogen/viz/figures.py +707 -0
- morphogen/viz/png.py +148 -0
- morphogen/viz/sections.py +696 -0
- morphogen/viz/surfaces.py +1352 -0
- morphogen/viz/video.py +904 -0
- morphogen/viz/workflow.py +488 -0
- morphogen-1.0.0.dist-info/METADATA +2316 -0
- morphogen-1.0.0.dist-info/RECORD +381 -0
- morphogen-1.0.0.dist-info/WHEEL +4 -0
- morphogen-1.0.0.dist-info/entry_points.txt +5 -0
- morphogen-1.0.0.dist-info/licenses/LICENSE +674 -0
morphogen/gui/index.html
ADDED
|
@@ -0,0 +1,1909 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>morphoGen</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light;
|
|
10
|
+
--bg: #f6f6f2; --panel: #ffffff; --ink: #1d2733; --muted: #66707a; --line: #dcdcd4;
|
|
11
|
+
--accent: #1f4e79; --accent-soft: #e3ecf5; --warn: #b5432f; --on-accent: #ffffff;
|
|
12
|
+
/* charts: surface, inks, hairlines, and three categorical slots (validated together) */
|
|
13
|
+
--surface: #fcfcfb; --c-ink: #0b0b0b; --c-secondary: #52514e; --c-muted: #898781;
|
|
14
|
+
--c-grid: #e1e0d9; --c-axis: #c3c2b7;
|
|
15
|
+
--series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --other: #898781;
|
|
16
|
+
}
|
|
17
|
+
@media (prefers-color-scheme: dark) {
|
|
18
|
+
:root:where(:not([data-theme="light"])) {
|
|
19
|
+
color-scheme: dark;
|
|
20
|
+
--bg: #0d0d0d; --panel: #1a1a19; --ink: #f0efec; --muted: #c3c2b7; --line: #2c2c2a;
|
|
21
|
+
--accent: #6da7ec; --accent-soft: #1c2a3d; --warn: #e66767; --on-accent: #0d0d0d;
|
|
22
|
+
--surface: #1a1a19; --c-ink: #f0efec; --c-secondary: #c3c2b7; --c-muted: #898781;
|
|
23
|
+
--c-grid: #2c2c2a; --c-axis: #383835;
|
|
24
|
+
--series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --other: #898781;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
:root[data-theme="dark"] {
|
|
28
|
+
color-scheme: dark;
|
|
29
|
+
--bg: #0d0d0d; --panel: #1a1a19; --ink: #f0efec; --muted: #c3c2b7; --line: #2c2c2a;
|
|
30
|
+
--accent: #6da7ec; --accent-soft: #1c2a3d; --warn: #e66767; --on-accent: #0d0d0d;
|
|
31
|
+
--surface: #1a1a19; --c-ink: #f0efec; --c-secondary: #c3c2b7; --c-muted: #898781;
|
|
32
|
+
--c-grid: #2c2c2a; --c-axis: #383835;
|
|
33
|
+
--series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --other: #898781;
|
|
34
|
+
}
|
|
35
|
+
* { box-sizing: border-box; }
|
|
36
|
+
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
37
|
+
background: var(--bg); color: var(--ink); }
|
|
38
|
+
header { display: flex; align-items: center; gap: 24px; padding: 10px 20px;
|
|
39
|
+
background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
|
|
40
|
+
header h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
|
|
41
|
+
header h1 span { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
|
|
42
|
+
nav { display: flex; gap: 4px; flex-wrap: wrap; }
|
|
43
|
+
nav#tabs { padding: 6px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
|
|
44
|
+
nav#sections button { font-size: 15px; font-weight: 600; }
|
|
45
|
+
nav#tabs button { font-size: 13px; padding: 6px 12px; }
|
|
46
|
+
.sendmore { width: auto; display: inline-block; padding: 5px 8px; }
|
|
47
|
+
#ws-menu { margin: 0 20px; }
|
|
48
|
+
nav button { border: 0; background: none; padding: 8px 14px; border-radius: 6px;
|
|
49
|
+
cursor: pointer; font: inherit; color: var(--muted); }
|
|
50
|
+
nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
|
51
|
+
main { padding: 18px 20px; }
|
|
52
|
+
.tab { display: none; gap: 18px; align-items: flex-start; }
|
|
53
|
+
.tab.active { display: flex; flex-wrap: wrap; }
|
|
54
|
+
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
|
|
55
|
+
padding: 16px; }
|
|
56
|
+
.form { width: 430px; max-width: 100%; }
|
|
57
|
+
.results { flex: 1; min-width: 320px; }
|
|
58
|
+
label { display: block; margin: 8px 0 2px; font-weight: 600; font-size: 13px; }
|
|
59
|
+
label small { font-weight: 400; color: var(--muted); }
|
|
60
|
+
input, select, textarea { width: 100%; padding: 6px 8px; border: 1px solid var(--line);
|
|
61
|
+
border-radius: 6px; font: inherit; background: var(--panel); color: var(--ink); }
|
|
62
|
+
textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: 12px; }
|
|
63
|
+
input[type=checkbox] { width: auto; margin-right: 6px; }
|
|
64
|
+
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
|
|
65
|
+
.doc { color: var(--muted); font-size: 13px; white-space: pre-line; margin: 6px 0 4px; }
|
|
66
|
+
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 0;
|
|
67
|
+
padding: 4px 12px 10px; }
|
|
68
|
+
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
|
|
69
|
+
button.go { margin-top: 14px; width: 100%; padding: 9px; border: 0; border-radius: 7px;
|
|
70
|
+
background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600;
|
|
71
|
+
cursor: pointer; }
|
|
72
|
+
button.go:disabled { opacity: .5; cursor: wait; }
|
|
73
|
+
.images { display: flex; gap: 12px; flex-wrap: wrap; }
|
|
74
|
+
.images figure { margin: 0; text-align: center; }
|
|
75
|
+
.images img { image-rendering: pixelated; border: 1px solid var(--line); border-radius: 4px;
|
|
76
|
+
width: 260px; max-width: 100%; }
|
|
77
|
+
figcaption { color: var(--muted); font-size: 12px; }
|
|
78
|
+
table { border-collapse: collapse; margin: 10px 0; font-size: 13px; }
|
|
79
|
+
td, th { padding: 3px 10px 3px 0; text-align: left; vertical-align: top; }
|
|
80
|
+
th { color: var(--muted); font-weight: 600; }
|
|
81
|
+
h3 { font-size: 14px; margin: 14px 0 4px; }
|
|
82
|
+
.error { color: var(--warn); white-space: pre-wrap; }
|
|
83
|
+
.muted { color: var(--muted); }
|
|
84
|
+
a { color: var(--accent); }
|
|
85
|
+
.player img { width: 360px; max-width: 100%; image-rendering: pixelated;
|
|
86
|
+
border: 1px solid var(--line); border-radius: 4px; }
|
|
87
|
+
svg.chart { width: 100%; max-width: 420px; height: 120px; background: var(--surface);
|
|
88
|
+
border: 1px solid var(--line); border-radius: 4px; }
|
|
89
|
+
button.plain { margin-top: 8px; padding: 6px 10px; border: 1px solid var(--line);
|
|
90
|
+
border-radius: 6px; background: var(--panel); color: var(--ink); font: inherit;
|
|
91
|
+
cursor: pointer; }
|
|
92
|
+
button.stopjob { margin: 0 0 0 10px; padding: 2px 12px; }
|
|
93
|
+
details.each { margin-top: 10px; } details.each summary { cursor: pointer; color: var(--muted); }
|
|
94
|
+
.viz { position: relative; }
|
|
95
|
+
.viz svg { display: block; background: var(--surface); border-radius: 6px; }
|
|
96
|
+
.viz .tip { position: absolute; pointer-events: none; background: var(--panel);
|
|
97
|
+
color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
|
|
98
|
+
padding: 6px 8px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
|
|
99
|
+
white-space: nowrap; display: none; }
|
|
100
|
+
.viz .tip b { font-weight: 600; }
|
|
101
|
+
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted);
|
|
102
|
+
margin: 2px 0 6px; }
|
|
103
|
+
.legend span { display: inline-flex; align-items: center; gap: 5px; }
|
|
104
|
+
.numbers td { font-variant-numeric: tabular-nums; }
|
|
105
|
+
.views { display: flex; gap: 12px; flex-wrap: wrap; }
|
|
106
|
+
.views figure { margin: 0; text-align: center; }
|
|
107
|
+
.views img, .views video { border: 1px solid var(--line); border-radius: 6px; background: #fff; }
|
|
108
|
+
.views img { width: auto; height: auto; max-width: min(100%, 640px); }
|
|
109
|
+
.views video { width: 480px; max-width: 100%; }
|
|
110
|
+
.files { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
|
|
111
|
+
.files b { color: var(--muted); font-weight: 600; margin-right: 4px; }
|
|
112
|
+
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; font-size: 12px; }
|
|
113
|
+
.steps span { padding: 2px 8px; border-radius: 10px; background: var(--accent-soft);
|
|
114
|
+
color: var(--accent); }
|
|
115
|
+
.mat label { margin-top: 4px; }
|
|
116
|
+
.workspace { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 20px;
|
|
117
|
+
background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px; }
|
|
118
|
+
#workspace { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-width: 0; }
|
|
119
|
+
#workspace > b { color: var(--muted); font-weight: 600; margin-right: 4px; }
|
|
120
|
+
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px;
|
|
121
|
+
border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
|
|
122
|
+
cursor: pointer; max-width: 320px; }
|
|
123
|
+
.chip img { width: 22px; height: 22px; border-radius: 50%; image-rendering: auto; }
|
|
124
|
+
.chip .kind { font-weight: 700; color: var(--accent); }
|
|
125
|
+
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
126
|
+
.chip.selected { border-color: var(--accent); background: var(--accent-soft); }
|
|
127
|
+
.chip.more { border-style: dashed; cursor: pointer; }
|
|
128
|
+
.source { display: flex; gap: 10px; align-items: center; margin: 8px 0 2px; padding: 8px;
|
|
129
|
+
border: 1px dashed var(--line); border-radius: 8px; font-size: 12px; }
|
|
130
|
+
.source img { width: 64px; height: 64px; border-radius: 4px; border: 1px solid var(--line); }
|
|
131
|
+
.sendto { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
|
|
132
|
+
.sendto button { padding: 6px 12px; border: 1px solid var(--accent); border-radius: 6px;
|
|
133
|
+
background: var(--accent-soft); color: var(--accent); font: inherit;
|
|
134
|
+
font-weight: 600; cursor: pointer; }
|
|
135
|
+
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
|
|
136
|
+
.checks label { font-weight: 400; margin: 4px 0; }
|
|
137
|
+
.images.smooth img { image-rendering: auto; width: 300px; }
|
|
138
|
+
.note { font-size: 12px; color: var(--muted); margin: 4px 0; }
|
|
139
|
+
[id^="toolform-"] { display: flex; flex-wrap: wrap; gap: 0 10px; }
|
|
140
|
+
[id^="toolform-"] .field { flex: 1 1 100%; min-width: 0; }
|
|
141
|
+
[id^="toolform-"] .field.half { flex: 1 1 calc(50% - 10px); }
|
|
142
|
+
.fgroup { flex: 1 1 100%; min-width: 0; box-sizing: border-box; border: 1px solid var(--line);
|
|
143
|
+
border-radius: 8px; padding: 0 10px 4px; margin: 8px 0 0; }
|
|
144
|
+
.fgrid .field select, .fgrid .field input:not([type="checkbox"]) { max-width: 100%; }
|
|
145
|
+
.fgroup > summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 6px 0;
|
|
146
|
+
color: var(--accent); }
|
|
147
|
+
.fgroup:not([open]) { padding-bottom: 0; }
|
|
148
|
+
.fgrid { display: flex; flex-wrap: wrap; gap: 0 10px; }
|
|
149
|
+
.fdoc { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
150
|
+
[hidden] { display: none !important; }
|
|
151
|
+
#help { margin: 0 20px; }
|
|
152
|
+
#help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 6px 0; }
|
|
153
|
+
#help dt { font-weight: 600; } #help dd { margin: 0; color: var(--muted); }
|
|
154
|
+
button.help { border: 1px solid var(--line); border-radius: 50%; width: 26px; height: 26px;
|
|
155
|
+
background: var(--panel); color: var(--accent); font-weight: 700; cursor: pointer;
|
|
156
|
+
padding: 0; display: inline-flex; align-items: center; justify-content: center;
|
|
157
|
+
flex: none; }
|
|
158
|
+
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden;
|
|
159
|
+
margin: 6px 0; max-width: 420px; }
|
|
160
|
+
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
|
|
161
|
+
.tablewrap { overflow-x: auto; max-width: 100%; }
|
|
162
|
+
.tablewrap table { font-variant-numeric: tabular-nums; }
|
|
163
|
+
pre.report { white-space: pre-wrap; font-size: 12px; background: var(--surface);
|
|
164
|
+
border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
|
|
165
|
+
/* the menu of a tab: its tools under their headings, or the models by family */
|
|
166
|
+
.sidemenu { width: 224px; max-width: 100%; padding: 10px; position: sticky; top: 12px;
|
|
167
|
+
max-height: calc(100vh - 24px); overflow-y: auto; }
|
|
168
|
+
.sidemenu h4 { margin: 12px 8px 4px; font-size: 11px; font-weight: 600; letter-spacing: .5px;
|
|
169
|
+
text-transform: uppercase; color: var(--muted); }
|
|
170
|
+
.sidemenu h4:first-child, .sidemenu input + h4 { margin-top: 4px; }
|
|
171
|
+
.sidemenu button { display: block; width: 100%; text-align: left; border: 0; background: none;
|
|
172
|
+
padding: 6px 8px; border-radius: 6px; cursor: pointer; font: inherit;
|
|
173
|
+
font-size: 13px; line-height: 1.3; color: var(--ink); }
|
|
174
|
+
.sidemenu button:hover { background: var(--bg); }
|
|
175
|
+
.sidemenu button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
|
176
|
+
.sidemenu button:disabled { opacity: .5; cursor: wait; }
|
|
177
|
+
.sidemenu input { margin-bottom: 6px; }
|
|
178
|
+
.sidemenu .none { margin: 6px 8px; }
|
|
179
|
+
h2.title { font-size: 16px; margin: 0 0 2px; }
|
|
180
|
+
h2.title small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
|
|
181
|
+
/* the button that runs a form stays in sight under the long ones */
|
|
182
|
+
.runbar { position: sticky; bottom: 0; z-index: 2; margin-top: 12px; padding: 10px 0 4px;
|
|
183
|
+
background: var(--panel); border-top: 1px solid var(--line); }
|
|
184
|
+
.runbar .go { margin-top: 0; }
|
|
185
|
+
/* the search of the header: tools, models, the options of their forms */
|
|
186
|
+
#search-box { position: relative; margin-left: auto; width: 320px; max-width: 100%; }
|
|
187
|
+
#search-results { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
|
|
188
|
+
width: 480px; max-width: calc(100vw - 40px); max-height: 70vh;
|
|
189
|
+
overflow-y: auto; padding: 6px; box-shadow: 0 8px 28px rgba(0,0,0,.18); }
|
|
190
|
+
.hit { display: block; width: 100%; text-align: left; border: 0; background: none;
|
|
191
|
+
padding: 7px 9px; border-radius: 6px; cursor: pointer; font: inherit; color: var(--ink); }
|
|
192
|
+
.hit.active, .hit:hover { background: var(--accent-soft); }
|
|
193
|
+
.hit .where { float: right; margin-left: 10px; font-size: 11px; color: var(--muted); }
|
|
194
|
+
.hit small { display: block; font-size: 12px; color: var(--muted); overflow: hidden;
|
|
195
|
+
text-overflow: ellipsis; white-space: nowrap; }
|
|
196
|
+
.found { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
|
|
197
|
+
#help h3 a { color: inherit; text-decoration: none; }
|
|
198
|
+
#help dd a { margin-right: 4px; white-space: nowrap; }
|
|
199
|
+
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line);
|
|
200
|
+
border-radius: 4px; background: var(--surface); color: var(--muted); }
|
|
201
|
+
@media (max-width: 900px) { /* narrow windows: the menu of a tab above its form, in lines */
|
|
202
|
+
.sidemenu { position: static; width: 100%; max-height: 250px; }
|
|
203
|
+
.sidemenu button { display: inline-block; width: auto; }
|
|
204
|
+
.sidemenu h4 { margin-top: 8px; }
|
|
205
|
+
.form { width: 100%; }
|
|
206
|
+
#search-box { order: 5; width: 100%; margin-left: 0; }
|
|
207
|
+
#theme-toggle { margin-left: auto; }
|
|
208
|
+
}
|
|
209
|
+
/* the stand-alone application (morphogen desktop): the buttons of the system's dialogs */
|
|
210
|
+
.browse { display: none; }
|
|
211
|
+
body.desktop .browse { display: inline-block; }
|
|
212
|
+
.pathrow { display: flex; gap: 6px; align-items: center; }
|
|
213
|
+
.pathrow input { flex: 1; }
|
|
214
|
+
body.desktop .pathrow button.browse { margin-top: 0; white-space: nowrap; }
|
|
215
|
+
</style>
|
|
216
|
+
</head>
|
|
217
|
+
<body>
|
|
218
|
+
<header>
|
|
219
|
+
<h1>morphoGen <span id="version"></span></h1>
|
|
220
|
+
<nav id="sections" aria-label="sections of the work"></nav>
|
|
221
|
+
<div id="search-box">
|
|
222
|
+
<input id="search" type="search" autocomplete="off" placeholder="Find a tool, a model, an option… ( / )"
|
|
223
|
+
aria-label="find a tool, a model or an option of their forms">
|
|
224
|
+
<div class="panel" id="search-results" hidden></div>
|
|
225
|
+
</div>
|
|
226
|
+
<button class="help" id="theme-toggle" title="colours: those of the system" aria-label="colours of the page"><svg width="13" height="13" viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="6.5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M8 1.5a6.5 6.5 0 0 0 0 13z" fill="currentColor"/></svg></button>
|
|
227
|
+
<button class="help" id="help-toggle" title="map of the interface: what each tab and each tool does">?</button>
|
|
228
|
+
</header>
|
|
229
|
+
<nav id="tabs" aria-label="tabs of the section"></nav>
|
|
230
|
+
<div class="panel" id="help" hidden></div>
|
|
231
|
+
<div class="workspace"><span id="workspace"><b>Workspace</b><span class="muted">empty: generate a morphology</span></span>
|
|
232
|
+
<span style="margin-left:auto"><button class="plain" id="ws-save" title="write the workspace to a folder">Save…</button>
|
|
233
|
+
<button class="plain" id="ws-open" title="add the items of a saved workspace">Open…</button></span></div>
|
|
234
|
+
<div class="panel" id="ws-menu" hidden></div>
|
|
235
|
+
<main>
|
|
236
|
+
<section class="tab active" id="tab-generate">
|
|
237
|
+
<nav class="panel sidemenu" id="gen-menu" aria-label="models by family">
|
|
238
|
+
<input id="gen-filter" type="search" autocomplete="off" placeholder="Filter the models…" aria-label="filter the models">
|
|
239
|
+
<div id="gen-list"></div>
|
|
240
|
+
</nav>
|
|
241
|
+
<div class="panel form">
|
|
242
|
+
<select id="gen-model" hidden></select>
|
|
243
|
+
<h2 class="title" id="gen-title"></h2>
|
|
244
|
+
<p class="doc" id="gen-doc"></p>
|
|
245
|
+
<div id="gen-params"></div>
|
|
246
|
+
<fieldset><legend>Domain</legend>
|
|
247
|
+
<div class="row">
|
|
248
|
+
<div><label>Size <small>(edge, or x, y, z)</small></label><input id="gen-size" value="10"></div>
|
|
249
|
+
<div><label>Seed <small>(blank: random)</small></label><input id="gen-seed" type="number" value="1"></div>
|
|
250
|
+
</div>
|
|
251
|
+
<label><input id="gen-periodic" type="checkbox" checked>periodic</label>
|
|
252
|
+
</fieldset>
|
|
253
|
+
<fieldset><legend>Views</legend>
|
|
254
|
+
<div class="row">
|
|
255
|
+
<div><label>Resolution <small>(pixels per edge, up to 2048)</small></label>
|
|
256
|
+
<input id="gen-resolution" type="number" value="512" min="8" max="2048"></div>
|
|
257
|
+
</div>
|
|
258
|
+
<p class="note">Sections of the level set, computed at this resolution without a voxel image of the volume.</p>
|
|
259
|
+
</fieldset>
|
|
260
|
+
<div class="runbar"><button class="go" id="gen-go">Generate</button></div>
|
|
261
|
+
<div id="gen-formation" hidden>
|
|
262
|
+
<fieldset><legend>Formation</legend>
|
|
263
|
+
<p class="note">This model grows by a process (automaton, reaction–diffusion, nucleation and growth, aggregation): watch its middle section from the initial state to the realization, with the same parameters, domain and seed.</p>
|
|
264
|
+
<div class="row"><div><label>Frames</label><input id="evo-frames" type="number" value="24"></div></div>
|
|
265
|
+
<button class="plain" id="evo-go">Animate the formation</button>
|
|
266
|
+
</fieldset>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
<div class="panel results" id="gen-out"><p class="muted">Choose a model and generate a realization. It is kept in the workspace, from which it can be sent to the simulation, the export or the optimization.</p></div>
|
|
270
|
+
</section>
|
|
271
|
+
|
|
272
|
+
<section class="tab" id="tab-simulate">
|
|
273
|
+
<div class="panel form">
|
|
274
|
+
<label>Morphology <small>(from the workspace)</small> <select id="sim-source"></select></label>
|
|
275
|
+
<div id="sim-card"></div>
|
|
276
|
+
<fieldset><legend>Discretization and solver</legend>
|
|
277
|
+
<div class="row">
|
|
278
|
+
<div><label>Method</label><select id="sim-method">
|
|
279
|
+
<option value="fe">finite elements: conforming mesh of the level set</option>
|
|
280
|
+
<option value="fft">FFT: voxels</option></select></div>
|
|
281
|
+
</div>
|
|
282
|
+
<div class="row">
|
|
283
|
+
<div><label>Apparent property</label><select id="sim-property">
|
|
284
|
+
<option value="shear_modulus">shear modulus (unit shear)</option>
|
|
285
|
+
<option value="bulk_modulus">bulk modulus (unit dilatation)</option></select></div>
|
|
286
|
+
</div>
|
|
287
|
+
<div class="row">
|
|
288
|
+
<div><label>Elements <small>(finite elements)</small></label><select id="sim-order">
|
|
289
|
+
<option value="2">10-node tetrahedra, curved along the interfaces</option>
|
|
290
|
+
<option value="1">4-node tetrahedra (fast; stiff)</option></select></div>
|
|
291
|
+
</div>
|
|
292
|
+
<div class="row">
|
|
293
|
+
<div><label>Element size <small>(blank: edge / 12)</small></label><input id="sim-element" placeholder="auto"></div>
|
|
294
|
+
<div><label>Voxels per edge <small>(FFT, up to 256)</small></label><input id="sim-shape" type="number" value="48"></div>
|
|
295
|
+
</div>
|
|
296
|
+
<label id="sim-gpu-row" hidden><input type="checkbox" id="sim-gpu">FFT on the GPU (CuPy, NVIDIA)</label>
|
|
297
|
+
</fieldset>
|
|
298
|
+
<fieldset><legend>Materials (isotropic elasticity)</legend><div id="sim-materials"><p class="muted">Choose a morphology.</p></div></fieldset>
|
|
299
|
+
<fieldset><legend>First view</legend>
|
|
300
|
+
<div class="row">
|
|
301
|
+
<div><label>Field</label><select id="sim-field"></select></div>
|
|
302
|
+
<div><label>Colormap</label><select id="sim-cmap"></select></div>
|
|
303
|
+
</div>
|
|
304
|
+
<p class="note">Other views, videos and files: send the result to Export. The whole stiffness tensor, the thermal expansion and the conductivity: <a href="#mechanics/tensors">Mechanics › Linear tensors</a>; the other physics: <a href="#physics/transport">Physics</a>.</p>
|
|
305
|
+
</fieldset>
|
|
306
|
+
<div class="runbar"><button class="go" id="sim-go">Simulate</button></div>
|
|
307
|
+
</div>
|
|
308
|
+
<div class="panel results" id="sim-out"><p class="muted">Generate a morphology, then simulate it here: its apparent property by finite elements on a conforming mesh of its level set (MMG), or by FFT on its voxels, with its fields. The result is kept in the workspace.</p></div>
|
|
309
|
+
</section>
|
|
310
|
+
|
|
311
|
+
<section class="tab" id="tab-export">
|
|
312
|
+
<div class="panel form">
|
|
313
|
+
<label>Item <small>(from the workspace)</small> <select id="exp-source"></select></label>
|
|
314
|
+
<div id="exp-card"></div>
|
|
315
|
+
<div id="exp-morphology" hidden>
|
|
316
|
+
<fieldset><legend>Files</legend>
|
|
317
|
+
<div class="checks">
|
|
318
|
+
<label><input type="checkbox" data-out="geometry" checked>geometry (.json)</label>
|
|
319
|
+
<label><input type="checkbox" data-out="sections" checked>sections (.png)</label>
|
|
320
|
+
<label title="its implicit function on the voxels: negative inside phase 1; for several phases, the function of each phase"><input type="checkbox" data-out="level_set">level set (.vti)</label>
|
|
321
|
+
<label><input type="checkbox" data-out="image">voxel image (.vti)</label>
|
|
322
|
+
<label title="the zero level of its implicit function, closed on the faces of the box; for several phases, the surface of each phase but the last"><input type="checkbox" data-out="surface">surface (.stl)</label>
|
|
323
|
+
<label title="tetrahedra conforming to its interfaces (MMG), every phase with its number"><input type="checkbox" data-out="mesh">conforming mesh (.vtu)</label>
|
|
324
|
+
</div>
|
|
325
|
+
<p class="note">Every model is described by implicit functions: the files follow its interfaces, not a voxel image. A morphology of several phases (coatings, inclusions, dead leaves, osteons, cells with phases) gives the function and the surface of each phase (<code>level_set_phase1.vti</code>, <code>surface_phase1.stl</code>…) and a mesh conforming to all their interfaces. Other formats (Gmsh, Abaqus, Neper, TIFF…): <a href="#interop/mesh_formats">Solvers & formats</a>.</p>
|
|
326
|
+
<div class="row">
|
|
327
|
+
<div><label>Sections <small>(pixels per edge, ≤ 2048)</small></label><input id="exp-resolution" type="number" value="1024"></div>
|
|
328
|
+
<div><label>Voxels per edge <small>(images, surface; ≤ 2048)</small></label><input id="exp-shape" type="number" value="128"></div>
|
|
329
|
+
</div>
|
|
330
|
+
<div class="row"><div><label>Element size <small>(mesh; blank: edge / 12)</small></label><input id="exp-element" placeholder="auto"></div></div>
|
|
331
|
+
</fieldset>
|
|
332
|
+
<fieldset><legend>Video</legend>
|
|
333
|
+
<div class="row">
|
|
334
|
+
<div><label>Kind</label><select id="exp-mvideo">
|
|
335
|
+
<option value="none">none</option>
|
|
336
|
+
<option value="sweep">sections of the level set sweeping it</option>
|
|
337
|
+
<option value="orthoslices">orthoslices (voxels)</option>
|
|
338
|
+
<option value="turntable">turntable (voxels)</option>
|
|
339
|
+
<option value="formation">formation (models grown by a process)</option></select></div>
|
|
340
|
+
</div>
|
|
341
|
+
</fieldset>
|
|
342
|
+
</div>
|
|
343
|
+
<div id="exp-simulation" hidden>
|
|
344
|
+
<fieldset><legend>Files</legend>
|
|
345
|
+
<div class="checks">
|
|
346
|
+
<label><input type="checkbox" data-sout="figure" checked>view of the fields</label>
|
|
347
|
+
<label><input type="checkbox" data-sout="tables" checked>tables (.csv, .txt, .xlsx)</label>
|
|
348
|
+
<label><input type="checkbox" data-sout="fields">fields (.vtu, .vti)</label>
|
|
349
|
+
<label><input type="checkbox" data-sout="mesh">mesh (.vtu)</label>
|
|
350
|
+
<label><input type="checkbox" data-sout="configuration" checked>configuration (.yaml)</label>
|
|
351
|
+
</div>
|
|
352
|
+
</fieldset>
|
|
353
|
+
<fieldset><legend>View of the fields</legend>
|
|
354
|
+
<div class="row">
|
|
355
|
+
<div><label>Field</label><select id="exp-field"></select></div>
|
|
356
|
+
<div><label>Colormap</label><select id="exp-cmap"></select></div>
|
|
357
|
+
</div>
|
|
358
|
+
<div class="row">
|
|
359
|
+
<div><label>Magnification <small>(blank: auto)</small></label><input id="exp-mag" placeholder="auto"></div>
|
|
360
|
+
<div><label>Cut <small>(plane normal to)</small></label><select id="exp-cut">
|
|
361
|
+
<option value="none">no cut</option><option>x</option><option>y</option><option>z</option></select></div>
|
|
362
|
+
</div>
|
|
363
|
+
<div class="row">
|
|
364
|
+
<div><label>at <small id="exp-frac-label">50 %</small></label>
|
|
365
|
+
<input id="exp-frac" type="range" min="0" max="1" step="0.05" value="0.5"></div>
|
|
366
|
+
</div>
|
|
367
|
+
<div class="row">
|
|
368
|
+
<div><label>Colour range <small>(blank: full)</small></label><input id="exp-lo" placeholder="min"></div>
|
|
369
|
+
<div><label> </label><input id="exp-hi" placeholder="max"></div>
|
|
370
|
+
</div>
|
|
371
|
+
</fieldset>
|
|
372
|
+
<fieldset><legend>Video</legend>
|
|
373
|
+
<div class="row">
|
|
374
|
+
<div><label>Kind</label><select id="exp-svideo">
|
|
375
|
+
<option value="field">field on the deformed mesh</option>
|
|
376
|
+
<option value="turntable">turntable</option>
|
|
377
|
+
<option value="sweep">cross-section sweeping</option>
|
|
378
|
+
<option value="orthoslices">orthoslices (FFT)</option>
|
|
379
|
+
<option value="none">none</option></select></div>
|
|
380
|
+
<div><label>Load</label><select id="exp-wave">
|
|
381
|
+
<option value="ramp">growing</option><option value="sine">oscillating</option></select></div>
|
|
382
|
+
</div>
|
|
383
|
+
</fieldset>
|
|
384
|
+
</div>
|
|
385
|
+
<fieldset id="exp-playback"><legend>Playback of the videos</legend>
|
|
386
|
+
<div class="row">
|
|
387
|
+
<div><label>Mode</label><select id="exp-mode">
|
|
388
|
+
<option value="bounce">back and forth</option><option value="loop">loop</option>
|
|
389
|
+
<option value="once">once</option></select></div>
|
|
390
|
+
<div><label>Frames</label><input id="exp-frames" type="number" value="36"></div>
|
|
391
|
+
<div><label>Frames/s</label><input id="exp-fps" type="number" value="18"></div>
|
|
392
|
+
<div><label>Axis</label><select id="exp-axis"><option>x</option><option>y</option>
|
|
393
|
+
<option selected>z</option></select></div>
|
|
394
|
+
</div>
|
|
395
|
+
</fieldset>
|
|
396
|
+
<div class="runbar"><button class="go" id="exp-go">Export</button></div>
|
|
397
|
+
</div>
|
|
398
|
+
<div class="panel results" id="exp-out"><p class="muted">Files of a morphology or a simulation of the workspace, with an archive of them all: figures, videos (the colours of a field following its load), tables, data and the configuration to rerun a simulation with <code>morphogen run</code>.</p></div>
|
|
399
|
+
</section>
|
|
400
|
+
|
|
401
|
+
<section class="tab" id="tab-optimize">
|
|
402
|
+
<div class="panel form">
|
|
403
|
+
<label>Start from <select id="opt-start"></select></label>
|
|
404
|
+
<div id="opt-card"></div>
|
|
405
|
+
<div class="row" id="opt-phase-row" hidden>
|
|
406
|
+
<div><label>Solid phase <small>(density 1)</small></label><select id="opt-phase"></select></div>
|
|
407
|
+
</div>
|
|
408
|
+
<div class="row">
|
|
409
|
+
<div><label>Objective</label><select id="opt-objective">
|
|
410
|
+
<option value="bulk_modulus">bulk modulus (max)</option>
|
|
411
|
+
<option value="shear_modulus">shear modulus (max)</option>
|
|
412
|
+
<option value="poisson_ratio">Poisson's ratio (min: auxetic)</option>
|
|
413
|
+
<option value="conductivity">conductivity (max)</option></select></div>
|
|
414
|
+
<div><label>Method</label><select id="opt-method">
|
|
415
|
+
<option value="mma">MMA</option><option value="oc">optimality criteria</option>
|
|
416
|
+
<option value="beso">BESO</option><option value="hca">hybrid cellular automaton</option></select></div>
|
|
417
|
+
</div>
|
|
418
|
+
<div class="row">
|
|
419
|
+
<div><label>Volume fraction</label><input id="opt-volume" value="0.4"></div>
|
|
420
|
+
<div><label>Grid <small>(nx, ny, nz)</small></label><input id="opt-grid" value="48, 48, 1"></div>
|
|
421
|
+
</div>
|
|
422
|
+
<div class="row">
|
|
423
|
+
<div><label>Filter radius <small>(voxels)</small></label><input id="opt-filter" value="2"></div>
|
|
424
|
+
<div><label>Projection <small>(final sharpness)</small></label><input id="opt-projection" value="32"></div>
|
|
425
|
+
</div>
|
|
426
|
+
<div class="row">
|
|
427
|
+
<div><label>Symmetry</label><select id="opt-symmetry"><option>cubic</option>
|
|
428
|
+
<option>orthotropic</option><option>none</option></select></div>
|
|
429
|
+
<div><label>Iterations</label><input id="opt-iterations" type="number" value="300"></div>
|
|
430
|
+
</div>
|
|
431
|
+
<p class="doc">Densities on a grid, from a void ball, noise, or a morphology of the workspace (the fraction of its solid phase in each voxel; from a simulation, its morphology and solid material). Planar grids (nz = 1) take the middle section of a 3D morphology; the symmetry chosen averages the start. A projection of 32 makes stiff designs black and white; auxetic designs need a softer one (8) and a filter radius of 2 to 3 voxels.</p>
|
|
432
|
+
<div class="runbar"><button class="go" id="opt-go">Optimize</button></div>
|
|
433
|
+
</div>
|
|
434
|
+
<div class="panel results" id="opt-out"><p class="muted">Inverse homogenization with the FFT solver: the cell evolves live. The design is kept in the workspace as a morphology (its level set: the densities about 1/2), to simulate on a conforming mesh or to export.</p></div>
|
|
435
|
+
</section>
|
|
436
|
+
|
|
437
|
+
<section class="tab" id="tab-tiles">
|
|
438
|
+
<div class="panel form">
|
|
439
|
+
<p class="doc">Combinatorial metamaterials: a box of tiles whose faces must match those of their neighbours (polarized blocks, after Coulais, Teomy, de Reus, Shokef & van Hecke, Nature 2016; or pipes, networks without dead ends). The exact number of compatible assemblies is counted, and one assembly is drawn by wave function collapse. To simulate such structures, generate them with the model <code>tile_assembly</code>.</p>
|
|
440
|
+
<label>Tile set <select id="des-tiles">
|
|
441
|
+
<option value="polarized">polarized blocks (combinatorial metamaterials)</option>
|
|
442
|
+
<option value="pipes">pipes (networks without dead ends)</option></select></label>
|
|
443
|
+
<label>Box <small>(tiles along x, y, z)</small><input id="des-shape" value="3, 3, 3"></label>
|
|
444
|
+
<label><input id="des-periodic" type="checkbox">periodic</label>
|
|
445
|
+
<button class="go" id="des-go">Count and assemble</button>
|
|
446
|
+
</div>
|
|
447
|
+
<div class="panel results" id="des-out"><p class="muted">Exact number of compatible assemblies, and one drawn by wave function collapse.</p></div>
|
|
448
|
+
</section>
|
|
449
|
+
|
|
450
|
+
<section class="tab" id="tab-ashby">
|
|
451
|
+
<div class="panel form">
|
|
452
|
+
<label for="db-path">Database <small>(results of runs: morphogen run --db, morphogen db add)</small></label>
|
|
453
|
+
<div class="pathrow"><input id="db-path" value="morphogen.db"><button class="plain browse" data-browse="file" data-for="db-path">Browse…</button></div>
|
|
454
|
+
<div class="row">
|
|
455
|
+
<div><label for="db-run">Add a run <small>(its output directory)</small></label>
|
|
456
|
+
<div class="pathrow"><input id="db-run" placeholder="path/to/run"><button class="plain browse" data-browse="folder" data-for="db-run">Browse…</button></div></div>
|
|
457
|
+
</div>
|
|
458
|
+
<button class="plain" id="db-add">Add the run</button>
|
|
459
|
+
<button class="plain" id="db-session" title="the simulations of the workspace, each a run">Add the simulations of the session</button>
|
|
460
|
+
<button class="plain" id="db-load">Read the database</button>
|
|
461
|
+
<label>Conditions <small>(one per line, e.g. model.type == tpms, solid_fraction < 0.3)</small></label>
|
|
462
|
+
<textarea id="db-where" rows="3"></textarea>
|
|
463
|
+
<div class="row">
|
|
464
|
+
<div><label>x</label><select id="db-x"></select></div>
|
|
465
|
+
<div><label>y</label><select id="db-y"></select></div>
|
|
466
|
+
</div>
|
|
467
|
+
<div class="row">
|
|
468
|
+
<div><label>Families</label><select id="db-by"></select></div>
|
|
469
|
+
<div><label>Lines y = x<sup>n</sup> <small>(n)</small></label><input id="db-guides" placeholder="1, 2"></div>
|
|
470
|
+
</div>
|
|
471
|
+
<label><input type="checkbox" id="db-log" checked>logarithmic axes</label>
|
|
472
|
+
<p class="doc">Normalized charts: a relative property (P / Ps) against the relative density; n = 1 is the rule of mixtures (stretching-dominated lattices), n = 2 bending-dominated foams. Three families in colour; the others are grouped.</p>
|
|
473
|
+
<button class="go" id="db-go">Draw</button>
|
|
474
|
+
</div>
|
|
475
|
+
<div class="panel results" id="db-out"><p class="muted">Read a database of results, then draw its records.</p></div>
|
|
476
|
+
</section>
|
|
477
|
+
</main>
|
|
478
|
+
|
|
479
|
+
<script src="/viewer.js"></script>
|
|
480
|
+
<script>
|
|
481
|
+
"use strict";
|
|
482
|
+
const $ = (id) => document.getElementById(id);
|
|
483
|
+
let MODELS = [];
|
|
484
|
+
let WS = []; // the workspace: morphologies and simulations of the session, newest first
|
|
485
|
+
|
|
486
|
+
function esc(s) {
|
|
487
|
+
return String(s).replace(/[&<>"]/g, (c) => ({"&": "&", "<": "<", ">": ">", '"': """}[c]));
|
|
488
|
+
}
|
|
489
|
+
async function api(path, body) {
|
|
490
|
+
const opts = body === undefined ? {} : {method: "POST", body: JSON.stringify(body),
|
|
491
|
+
headers: {"Content-Type": "application/json"}};
|
|
492
|
+
const res = await fetch(path, opts);
|
|
493
|
+
const data = await res.json();
|
|
494
|
+
if (!res.ok || data.error) throw new Error(data.error || res.statusText);
|
|
495
|
+
return data;
|
|
496
|
+
}
|
|
497
|
+
function numbers(text) {
|
|
498
|
+
return String(text).split(/[\s,;]+/).filter((s) => s.length).map(Number);
|
|
499
|
+
}
|
|
500
|
+
function table(obj) {
|
|
501
|
+
const rows = Object.entries(obj || {}).map(([k, v]) =>
|
|
502
|
+
`<tr><th>${esc(k)}</th><td>${typeof v === "number" ? +v.toPrecision(6) : esc(typeof v === "string" ? v : JSON.stringify(v))}</td></tr>`);
|
|
503
|
+
return rows.length ? `<table>${rows.join("")}</table>` : '<p class="muted">—</p>';
|
|
504
|
+
}
|
|
505
|
+
function images(list, smooth) { // sections: a click opens the large ones at full resolution
|
|
506
|
+
return `<div class="images${smooth ? " smooth" : ""}">${(list || []).map((s) => {
|
|
507
|
+
const img = `<img src="${s.png}" alt="${esc(s.title)}">`;
|
|
508
|
+
const view = s.png.startsWith("data:") ? img : `<a href="${s.png}" target="_blank" title="full resolution">${img}</a>`;
|
|
509
|
+
return `<figure>${view}<figcaption>${esc(s.title)}</figcaption></figure>`;
|
|
510
|
+
}).join("")}</div>`;
|
|
511
|
+
}
|
|
512
|
+
function wait(ms) { return new Promise((ok) => setTimeout(ok, ms)); }
|
|
513
|
+
|
|
514
|
+
// -- parameter forms built from the models' metadata -------------------------------------
|
|
515
|
+
function exampleText(v) { // a value of the example configuration, as typed in a field
|
|
516
|
+
if (Array.isArray(v) && v.every((x) => typeof x === "number")) return v.join(", ");
|
|
517
|
+
if (typeof v === "object" && v !== null) return JSON.stringify(v);
|
|
518
|
+
return String(v);
|
|
519
|
+
}
|
|
520
|
+
function exampleDomain(sizeId, periodicId, model) { // the domain of the model's example
|
|
521
|
+
const d = model.example_domain || {};
|
|
522
|
+
if (d.size !== undefined) $(sizeId).value = Array.isArray(d.size) ? d.size.join(", ") : d.size;
|
|
523
|
+
if (d.periodic !== undefined) $(periodicId).checked = !!d.periodic;
|
|
524
|
+
}
|
|
525
|
+
function buildForm(container, model) {
|
|
526
|
+
container.innerHTML = "";
|
|
527
|
+
const example = model.example || {};
|
|
528
|
+
for (const p of model.parameters) {
|
|
529
|
+
const wrap = document.createElement("div");
|
|
530
|
+
const unit = p.unit ? ` [${esc(p.unit)}]` : "";
|
|
531
|
+
const req = p.required ? " *" : "";
|
|
532
|
+
const given = Object.prototype.hasOwnProperty.call(example, p.name);
|
|
533
|
+
if (p.kind === "bool") {
|
|
534
|
+
const on = given ? !!example[p.name] : !!p.default;
|
|
535
|
+
wrap.innerHTML = `<label title="${esc(p.doc)}"><input type="checkbox" data-name="${p.name}" data-kind="bool"
|
|
536
|
+
${on ? "checked" : ""}>${esc(p.name)}</label>`;
|
|
537
|
+
} else {
|
|
538
|
+
const def = p.default === null || p.default === undefined ? "" :
|
|
539
|
+
(typeof p.default === "object" ? JSON.stringify(p.default) : p.default);
|
|
540
|
+
const value = given ? ` value="${esc(exampleText(example[p.name]))}"` : "";
|
|
541
|
+
wrap.innerHTML = `<label title="${esc(p.doc)}">${esc(p.name)}${req}<small>${unit} — ${esc(p.doc)}</small></label>
|
|
542
|
+
<input data-name="${p.name}" data-kind="${p.kind}" placeholder="${esc(def)}"${value}>`;
|
|
543
|
+
}
|
|
544
|
+
container.appendChild(wrap);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function readForm(container) {
|
|
548
|
+
const out = {};
|
|
549
|
+
for (const el of container.querySelectorAll("[data-name]")) {
|
|
550
|
+
const kind = el.dataset.kind, name = el.dataset.name;
|
|
551
|
+
if (kind === "bool") { out[name] = el.checked; continue; }
|
|
552
|
+
const v = el.value.trim();
|
|
553
|
+
if (!v) continue;
|
|
554
|
+
if (kind === "float" || kind === "fraction" || kind === "int") out[name] = Number(v);
|
|
555
|
+
else if (kind === "floats" || kind === "vector") out[name] = numbers(v).length > 1 ? numbers(v) : Number(v);
|
|
556
|
+
else if (kind === "ints") out[name] = numbers(v);
|
|
557
|
+
else if (kind === "str") out[name] = v;
|
|
558
|
+
else { try { out[name] = JSON.parse(v); } catch { out[name] = jsonless(v); } }
|
|
559
|
+
}
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
function jsonless(v) { // a value that is not JSON: numbers as typed ("0.012, 0.012"), else text
|
|
563
|
+
const list = numbers(v);
|
|
564
|
+
if (list.length > 1 && list.every(Number.isFinite)) return list;
|
|
565
|
+
return isNaN(Number(v)) ? v : Number(v);
|
|
566
|
+
}
|
|
567
|
+
function fillSelect(select, models, onChange) { // the models in groups by family
|
|
568
|
+
const families = [...new Set(models.map((m) => m.family || "Models"))];
|
|
569
|
+
select.innerHTML = families.map((f) => `<optgroup label="${esc(f)}">${models.filter((m) => (m.family || "Models") === f)
|
|
570
|
+
.map((m) => `<option value="${m.name}">${m.name} — ${esc(m.summary)}</option>`).join("")}</optgroup>`).join("");
|
|
571
|
+
select.onchange = () => onChange(models.find((m) => m.name === select.value));
|
|
572
|
+
onChange(models[0]);
|
|
573
|
+
}
|
|
574
|
+
function plainDoc(text) { // a docstring as running text: its lines joined, its paragraphs kept
|
|
575
|
+
const paragraphs = String(text).replace(/``/g, "").replace(/:\w+:`~?([^`]*)`/g, "$1").split(/\n\s*\n/);
|
|
576
|
+
return paragraphs.map((p) => p.split("\n").map((line) => line.trim()).filter(Boolean).join(" ")).join("\n\n").trim();
|
|
577
|
+
}
|
|
578
|
+
function fold(text) { // in lower case, without accents nor punctuation: the words to match
|
|
579
|
+
const plain = String(text).toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "");
|
|
580
|
+
return plain.replace(/[^a-z0-9]+/g, " ").trim();
|
|
581
|
+
}
|
|
582
|
+
function modelMenu(models) { // the models of Generate by family: the menu of its tab
|
|
583
|
+
const families = [...new Set(models.map((m) => m.family || "Models"))];
|
|
584
|
+
$("gen-list").innerHTML = families.map((f) => `<h4>${esc(f)}</h4>` + models.filter((m) => (m.family || "Models") === f)
|
|
585
|
+
.map((m) => `<button data-model="${esc(m.name)}" title="${esc(m.summary)}">${esc(m.name)}</button>`).join("")).join("") +
|
|
586
|
+
'<p class="muted none" id="gen-none" hidden>No model matches.</p>';
|
|
587
|
+
}
|
|
588
|
+
function filterModels() { // the models whose name, summary or family hold every word typed
|
|
589
|
+
const words = fold($("gen-filter").value).split(" ").filter(Boolean);
|
|
590
|
+
let heading = null, any = false, shown = 0;
|
|
591
|
+
for (const el of $("gen-list").children) {
|
|
592
|
+
if (el.tagName === "H4") {
|
|
593
|
+
if (heading) heading.hidden = !any;
|
|
594
|
+
heading = el; any = false;
|
|
595
|
+
} else if (el.tagName === "BUTTON") {
|
|
596
|
+
const m = MODELS.find((x) => x.name === el.dataset.model);
|
|
597
|
+
const text = fold(`${m.name} ${m.summary} ${m.family || ""}`);
|
|
598
|
+
el.hidden = !words.every((w) => text.includes(w));
|
|
599
|
+
if (!el.hidden) { any = true; shown += 1; }
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (heading) heading.hidden = !any;
|
|
603
|
+
$("gen-none").hidden = shown > 0;
|
|
604
|
+
}
|
|
605
|
+
function chooseModel(name) { // the model Generate shows: its form, its entry of the menu
|
|
606
|
+
const select = $("gen-model");
|
|
607
|
+
if (![...select.options].some((o) => o.value === name)) return false;
|
|
608
|
+
if (select.value !== name) { select.value = name; select.onchange(); }
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
$("gen-list").addEventListener("click", (e) => {
|
|
612
|
+
const b = e.target.closest("button[data-model]");
|
|
613
|
+
if (b) chooseModel(b.dataset.model);
|
|
614
|
+
});
|
|
615
|
+
$("gen-filter").addEventListener("input", filterModels);
|
|
616
|
+
$("gen-filter").addEventListener("keydown", (e) => { // Enter: the first model left
|
|
617
|
+
if (e.key !== "Enter") return;
|
|
618
|
+
const first = [...$("gen-list").querySelectorAll("button[data-model]")].find((b) => !b.hidden);
|
|
619
|
+
if (first) chooseModel(first.dataset.model);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
// -- menus: the sections of the work and their tabs --------------------------------------
|
|
623
|
+
const SECTIONS = [
|
|
624
|
+
{name: "create", title: "Create", doc: "make a morphology: generate a model, optimize a cell, design it inversely, assemble tiles"},
|
|
625
|
+
{name: "characterize", title: "Characterize", doc: "its statistics: measures, correlation functions, stereology, percolation, the size of its representative volume, reconstructions"},
|
|
626
|
+
{name: "simulate", title: "Simulate", doc: "its mechanics and physics: linear homogenization, loading paths and behaviours, behaviours learned from data, fracture, nonlocal damage, stability, transport and waves, couplings"},
|
|
627
|
+
{name: "share", title: "Export & compare", doc: "files of every kind, the inputs of other solvers, the curves of runs compared, Ashby charts of the results"},
|
|
628
|
+
];
|
|
629
|
+
// the tabs of the page itself; those of the tools come from the catalog with their section
|
|
630
|
+
const TABS = [
|
|
631
|
+
{name: "generate", title: "Generate", section: "create", order: 10},
|
|
632
|
+
{name: "optimize", title: "Topology optimization", section: "create", order: 70},
|
|
633
|
+
{name: "tiles", title: "Tile assemblies", section: "create", order: 90},
|
|
634
|
+
{name: "simulate", title: "Linear homogenization", section: "simulate", order: 30},
|
|
635
|
+
{name: "export", title: "Export", section: "share", order: 80},
|
|
636
|
+
{name: "ashby", title: "Ashby charts", section: "share", order: 100},
|
|
637
|
+
];
|
|
638
|
+
const LAST = {}; // the tab last shown in each section
|
|
639
|
+
function tabOf(name) { return TABS.find((t) => t.name === name); }
|
|
640
|
+
function tabTitle(name) { const t = tabOf(name); return t ? t.title : name; }
|
|
641
|
+
function shownIn(tab) { // what a tab shows among several: its tool, or the model of Generate
|
|
642
|
+
if (tab === "generate") return $("gen-model").value || "";
|
|
643
|
+
const tools = $("tools-" + tab);
|
|
644
|
+
return tools && tools.options.length > 1 ? tools.value : "";
|
|
645
|
+
}
|
|
646
|
+
function setAddress(tab) { // #tab/tool, #generate/model: kept on reload, a link to give
|
|
647
|
+
const shown = shownIn(tab), hash = "#" + tab + (shown ? "/" + shown : "");
|
|
648
|
+
if (location.hash !== hash) history.replaceState(null, "", hash);
|
|
649
|
+
}
|
|
650
|
+
function go(address) { // to a tab, to a tool of a tab (mechanics/path), to a model (generate/voronoi)
|
|
651
|
+
const [name, shown] = String(address || "").split("/");
|
|
652
|
+
const tab = tabOf(name) ? name : TABS[0].name;
|
|
653
|
+
if (shown && tab === "generate") chooseModel(shown);
|
|
654
|
+
else if (shown) chooseTool(tab, shown);
|
|
655
|
+
showTab(tab);
|
|
656
|
+
}
|
|
657
|
+
function showTab(name) {
|
|
658
|
+
const tab = tabOf(name) || TABS[0];
|
|
659
|
+
LAST[tab.section] = tab.name;
|
|
660
|
+
setAddress(tab.name);
|
|
661
|
+
$("sections").innerHTML = SECTIONS.map((s) =>
|
|
662
|
+
`<button data-section="${s.name}" class="${s.name === tab.section ? "active" : ""}" title="${esc(s.doc)}">${esc(s.title)}</button>`).join("");
|
|
663
|
+
const tabs = TABS.filter((t) => t.section === tab.section).sort((a, b) => a.order - b.order);
|
|
664
|
+
$("tabs").innerHTML = tabs.map((t) =>
|
|
665
|
+
`<button data-tab="${t.name}" class="${t.name === tab.name ? "active" : ""}">${esc(t.title)}</button>`).join("");
|
|
666
|
+
document.querySelectorAll(".tab").forEach((el) => el.classList.toggle("active", el.id === "tab-" + tab.name));
|
|
667
|
+
}
|
|
668
|
+
$("sections").addEventListener("click", (e) => {
|
|
669
|
+
const b = e.target.closest("button[data-section]");
|
|
670
|
+
if (!b) return;
|
|
671
|
+
const first = TABS.filter((t) => t.section === b.dataset.section).sort((a, c) => a.order - c.order)[0];
|
|
672
|
+
showTab(LAST[b.dataset.section] || (first && first.name));
|
|
673
|
+
});
|
|
674
|
+
$("tabs").addEventListener("click", (e) => {
|
|
675
|
+
const b = e.target.closest("button[data-tab]");
|
|
676
|
+
if (b) showTab(b.dataset.tab);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
async function busy(button, task) {
|
|
680
|
+
button.disabled = true;
|
|
681
|
+
try { await task(); } finally { button.disabled = false; }
|
|
682
|
+
}
|
|
683
|
+
// a job under way: stopped at its next step (an iteration of its solver, a step it reports)
|
|
684
|
+
const STOPPING = new Set();
|
|
685
|
+
function stopButton(job) {
|
|
686
|
+
return STOPPING.has(job) ? ' <span class="muted">stopping at its next step…</span>' :
|
|
687
|
+
` <button class="plain stopjob" data-job="${job}" title="stop it at its next step">Stop</button>`;
|
|
688
|
+
}
|
|
689
|
+
function stoppedNote(s) {
|
|
690
|
+
return `<p class="muted">Stopped after ${s.elapsed_s} s: nothing kept.</p>`;
|
|
691
|
+
}
|
|
692
|
+
document.addEventListener("click", (e) => {
|
|
693
|
+
const b = e.target.closest("button.stopjob");
|
|
694
|
+
if (!b) return;
|
|
695
|
+
STOPPING.add(b.dataset.job);
|
|
696
|
+
b.disabled = true;
|
|
697
|
+
api("/api/job/stop", {job: b.dataset.job}).catch((err) => alert(err.message));
|
|
698
|
+
});
|
|
699
|
+
const KIND = {morphology: "M", simulation: "S", behaviour: "B", result: "R"}; // B: of a material, R: the run of a tool
|
|
700
|
+
function item(key) { return WS.find((i) => i.key === key); }
|
|
701
|
+
function card(it) { // a summary of an item of the workspace
|
|
702
|
+
if (!it) return "";
|
|
703
|
+
const thumb = it.thumbnail ? `<img src="${it.thumbnail}" alt="">` : "";
|
|
704
|
+
return `<div class="source">${thumb}<div><b>${esc(it.title)}</b>${table(it.info || {})}</div></div>`;
|
|
705
|
+
}
|
|
706
|
+
function options(select, items, extra, keep) {
|
|
707
|
+
const value = keep === undefined ? select.value : keep;
|
|
708
|
+
select.innerHTML = (extra || []).map(([v, t]) => `<option value="${v}">${esc(t)}</option>`).join("") +
|
|
709
|
+
items.map((i) => `<option value="${i.key}">${KIND[i.kind]} ${esc(i.title)}</option>`).join("");
|
|
710
|
+
if ([...select.options].some((o) => o.value === value)) select.value = value;
|
|
711
|
+
}
|
|
712
|
+
const RECENT_RUNS = 4; // the runs of tools shown in the strip, the others behind a chip
|
|
713
|
+
let ALL_RUNS = false;
|
|
714
|
+
function chip(i) {
|
|
715
|
+
return `<span class="chip" data-key="${i.key}" title="${esc(i.title)}">${i.thumbnail ? `<img src="${i.thumbnail}" alt="">` : ""}<span class="kind">${KIND[i.kind]}</span><span>${esc(i.title)}</span></span>`;
|
|
716
|
+
}
|
|
717
|
+
async function refreshWorkspace(select) { // select: {tab, key} to show after the update
|
|
718
|
+
WS = await api("/api/workspace");
|
|
719
|
+
const strip = $("workspace");
|
|
720
|
+
// every morphology and simulation first; then the newest runs of tools, the earlier on demand
|
|
721
|
+
const runs = WS.filter((i) => i.kind === "result");
|
|
722
|
+
const shown = WS.filter((i) => i.kind !== "result").concat(ALL_RUNS ? runs : runs.slice(0, RECENT_RUNS));
|
|
723
|
+
const hidden = runs.length - (ALL_RUNS ? runs.length : Math.min(runs.length, RECENT_RUNS));
|
|
724
|
+
const more = hidden ? `<span class="chip more" id="ws-more" title="show the earlier runs of tools"><span class="kind">R</span><span>+${hidden} earlier runs</span></span>` :
|
|
725
|
+
(ALL_RUNS && runs.length > RECENT_RUNS ? '<span class="chip more" id="ws-more"><span>fewer runs</span></span>' : "");
|
|
726
|
+
strip.innerHTML = "<b>Workspace</b>" + (WS.length ? shown.map(chip).join("") + more :
|
|
727
|
+
'<span class="muted">empty: generate a morphology</span>');
|
|
728
|
+
for (const c of strip.querySelectorAll(".chip[data-key]")) c.onclick = () => itemMenu(c.dataset.key);
|
|
729
|
+
if ($("ws-more")) $("ws-more").onclick = () => { ALL_RUNS = !ALL_RUNS; refreshWorkspace(); };
|
|
730
|
+
const morphs = WS.filter((i) => i.kind === "morphology");
|
|
731
|
+
options($("sim-source"), morphs);
|
|
732
|
+
const inputs = WS.filter((i) => ["morphology", "simulation"].includes(i.kind)); // runs are shown, not sent
|
|
733
|
+
options($("exp-source"), inputs);
|
|
734
|
+
options($("opt-start"), inputs, [["centered_void", "a void ball (default)"], ["random", "random noise"]]);
|
|
735
|
+
refreshToolItems();
|
|
736
|
+
if (select) sendTo(select.tab, select.key);
|
|
737
|
+
else { simSource(); expSource(); optStart(); }
|
|
738
|
+
}
|
|
739
|
+
function itemMenu(key) { // a click on a chip: the item, where it can go, its removal
|
|
740
|
+
const menu = $("ws-menu"), it = item(key);
|
|
741
|
+
if (!it || (!menu.hidden && menu.dataset.key === key)) { menu.hidden = true; return; }
|
|
742
|
+
menu.dataset.key = key;
|
|
743
|
+
// a run of a tool (or the simulation a tool made): shown again in its tab, its form filled
|
|
744
|
+
const show = it.tool ? `<div class="sendto"><button id="ws-show">Show it in ${esc(tabTitle(it.tab))} →</button></div>` : "";
|
|
745
|
+
const next = sendButtons(it) + show; // a run: only to the tools that take runs
|
|
746
|
+
menu.innerHTML = card(it) + next +
|
|
747
|
+
`<button class="plain" id="ws-rename">Rename</button> <button class="plain" id="ws-remove">Remove from the workspace</button> <button class="plain" id="ws-close">Close</button>` +
|
|
748
|
+
(window.MorphoViewer && (["morphology", "simulation"].includes(it.kind) || it.view3d) ? MorphoViewer.slot(key, {label: "View in 3D"}) : "");
|
|
749
|
+
menu.hidden = false;
|
|
750
|
+
if ($("ws-show")) $("ws-show").onclick = () => busy($("ws-show"), () => showResult(key));
|
|
751
|
+
$("ws-close").onclick = () => { menu.hidden = true; };
|
|
752
|
+
$("ws-rename").onclick = () => busy($("ws-rename"), async () => {
|
|
753
|
+
const title = prompt("New title:", it.title.replace(/^#\d+ /, ""));
|
|
754
|
+
if (!title) return;
|
|
755
|
+
try { await api("/api/workspace/rename", {key, title}); } catch (e) { alert(e.message); return; }
|
|
756
|
+
menu.hidden = true;
|
|
757
|
+
await refreshWorkspace();
|
|
758
|
+
});
|
|
759
|
+
$("ws-remove").onclick = () => busy($("ws-remove"), async () => {
|
|
760
|
+
await api("/api/workspace/remove", {key});
|
|
761
|
+
menu.hidden = true;
|
|
762
|
+
await refreshWorkspace();
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
async function showResult(key) { // the run of a tool: its tab, its tool, its form, its result
|
|
766
|
+
const r = await api(`/api/result?key=${encodeURIComponent(key)}`);
|
|
767
|
+
$("ws-menu").hidden = true;
|
|
768
|
+
if (LOCKED[r.tab]) { alert("This tab is running a tool on several items: show the run when they are done."); return; }
|
|
769
|
+
showTab(r.tab);
|
|
770
|
+
$("tools-" + r.tab).value = r.tool;
|
|
771
|
+
buildToolForm(r.tab);
|
|
772
|
+
fillToolForm(r.tab, r.params || {});
|
|
773
|
+
$("toolout-" + r.tab).innerHTML = toolResult(r.result);
|
|
774
|
+
window.scrollTo({top: 0});
|
|
775
|
+
}
|
|
776
|
+
function fillToolForm(tab, params) { // the values a form sent, written back in it
|
|
777
|
+
const tool = currentTool(tab), el = (f) => document.getElementById(`tool-${tool.name}-${f.name}`);
|
|
778
|
+
const later = [];
|
|
779
|
+
for (const f of tool.fields) {
|
|
780
|
+
const v = params[f.name], input = el(f);
|
|
781
|
+
if (v === undefined || v === null || !input) continue;
|
|
782
|
+
if (f.kind === "materials") later.push([f, v]);
|
|
783
|
+
else if (f.kind === "bool") input.checked = Boolean(v);
|
|
784
|
+
else if (f.kind === "choices" || f.kind === "items") {
|
|
785
|
+
for (const c of input.querySelectorAll("input")) c.checked = [].concat(v).includes(c.value);
|
|
786
|
+
} else if (f.kind !== "item" || [...input.options].some((o) => o.value === v)) {
|
|
787
|
+
input.value = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
788
|
+
}
|
|
789
|
+
if (f.kind === "item" || f.kind === "choice") toolVisibility(tab); // the fields they open
|
|
790
|
+
}
|
|
791
|
+
toolVisibility(tab);
|
|
792
|
+
for (const [f, v] of later) { // the phases of the item, once its editor is drawn
|
|
793
|
+
for (const row of el(f).querySelectorAll(".mat")) {
|
|
794
|
+
const m = v[row.dataset.phase];
|
|
795
|
+
if (m === undefined) continue;
|
|
796
|
+
row.querySelector("[data-void]").checked = m === "void";
|
|
797
|
+
if (m !== "void") {
|
|
798
|
+
row.querySelector("[data-e]").value = m.young;
|
|
799
|
+
row.querySelector("[data-nu]").value = m.poisson;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
function sendTo(tab, key) {
|
|
805
|
+
const select = {simulate: "sim-source", export: "exp-source", optimize: "opt-start"}[tab];
|
|
806
|
+
if (select && key && [...$(select).options].some((o) => o.value === key)) $(select).value = key;
|
|
807
|
+
if (!select && key) selectInTool(tab, key);
|
|
808
|
+
simSource(); expSource(); optStart();
|
|
809
|
+
$("ws-menu").hidden = true;
|
|
810
|
+
showTab(tab);
|
|
811
|
+
window.scrollTo({top: 0});
|
|
812
|
+
}
|
|
813
|
+
function destinations(it) { // the tabs that take an item: [tab, title]
|
|
814
|
+
const out = it.kind === "morphology" ? [["simulate", tabTitle("simulate")]] : [];
|
|
815
|
+
for (const t of toolTabsFor(it)) out.push([t.name, tabTitle(t.name)]);
|
|
816
|
+
if (["morphology", "simulation"].includes(it.kind)) out.push(["optimize", tabTitle("optimize")], ["export", tabTitle("export")]);
|
|
817
|
+
return out;
|
|
818
|
+
}
|
|
819
|
+
function sendButtons(it) { // the usual next steps as buttons, the others in a menu by section
|
|
820
|
+
if (!it) return "";
|
|
821
|
+
const all = destinations(it);
|
|
822
|
+
if (!all.length) return "";
|
|
823
|
+
const main = {morphology: ["simulate", "statistics", "export"], behaviour: ["mechanics", "fracture", "compare"],
|
|
824
|
+
result: ["compare"]}[it.kind] || ["export", "optimize", "compare"];
|
|
825
|
+
const primary = all.filter(([t]) => main.includes(t));
|
|
826
|
+
const others = all.filter(([t]) => !main.includes(t));
|
|
827
|
+
const groups = SECTIONS.map((s) => {
|
|
828
|
+
const opts = others.filter(([t]) => (tabOf(t) || {}).section === s.name);
|
|
829
|
+
return opts.length ? `<optgroup label="${esc(s.title)}">${opts.map(([t, l]) => `<option value="${t}">${esc(l)}</option>`).join("")}</optgroup>` : "";
|
|
830
|
+
}).join("");
|
|
831
|
+
const more = others.length ? `<select class="sendmore" data-key="${it.key}"><option value="">Other tools…</option>${groups}</select>` : "";
|
|
832
|
+
return `<div class="sendto">${primary.map(([t, l]) => `<button data-to="${t}" data-key="${it.key}">${esc(l)} →</button>`).join("")}${more}</div>`;
|
|
833
|
+
}
|
|
834
|
+
document.addEventListener("click", (e) => {
|
|
835
|
+
const b = e.target.closest(".sendto button");
|
|
836
|
+
if (b) sendTo(b.dataset.to, b.dataset.key);
|
|
837
|
+
});
|
|
838
|
+
document.addEventListener("change", (e) => {
|
|
839
|
+
const s = e.target.closest("select.sendmore");
|
|
840
|
+
if (s && s.value) { const to = s.value; s.value = ""; sendTo(to, s.dataset.key); }
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
// -- help: what each tab does --------------------------------------------------------------
|
|
844
|
+
const FIXED_TABS = {
|
|
845
|
+
generate: "a realization of any model, chosen in the menu of the models by family: sections of the implicit functions of its phases (up to 2048 pixels per edge), its measures against theory, the animation of the formation of the models grown by a process",
|
|
846
|
+
simulate: "the apparent shear or bulk modulus of a morphology: finite elements on the conforming mesh of its level set, or FFT on its voxels (on the GPU when there is one)",
|
|
847
|
+
optimize: "topology optimization of a periodic cell, from a void ball, noise, or a morphology or simulation of the workspace; the design joins the workspace",
|
|
848
|
+
export: "the files of any item of the workspace, with an archive: of a morphology, its geometry (JSON), sections (PNG), the implicit function of each of its phases and its voxel image (VTI), the surface of each phase (STL), its conforming mesh (VTU) and videos (sweeps, turntable, formation); of a simulation, figures, videos of its fields under a growing load, tables, fields, mesh and configuration",
|
|
849
|
+
tiles: "combinatorial metamaterials: the exact number of compatible assemblies of a tile set in a box, and one drawn by wave function collapse",
|
|
850
|
+
ashby: "normalized Ashby charts of a results database, to which the simulations of the session can be added",
|
|
851
|
+
};
|
|
852
|
+
function toolLinks(tools) { // the tools of a tab as links, under the headings of its menu
|
|
853
|
+
const headings = [...new Set(tools.map((x) => x.menu || ""))];
|
|
854
|
+
return headings.map((h) => (h ? `<b>${esc(h)}:</b> ` : "") + tools.filter((x) => (x.menu || "") === h)
|
|
855
|
+
.map((x) => `<a href="#${x.tab}/${x.name}" title="${esc(shortDoc(x.doc))}">${esc(x.title)}</a>`).join(" · ")).join("<br>");
|
|
856
|
+
}
|
|
857
|
+
function showHelp() { // the map of the interface: its sections, their tabs, the tools of each
|
|
858
|
+
const html = SECTIONS.map((s) => {
|
|
859
|
+
const rows = TABS.filter((t) => t.section === s.name).sort((a, b) => a.order - b.order).map((t) => {
|
|
860
|
+
const tab = CATALOG.tabs.find((c) => c.name === t.name);
|
|
861
|
+
const tools = CATALOG.tools.filter((x) => x.tab === t.name);
|
|
862
|
+
const links = tools.length > 1 ? `<br>${toolLinks(tools)}` : "";
|
|
863
|
+
return `<dt><a href="#${t.name}">${esc(t.title)}</a></dt><dd>${esc(tab ? tab.doc : FIXED_TABS[t.name] || "")}${links}</dd>`;
|
|
864
|
+
}).join("");
|
|
865
|
+
return `<h3>${esc(s.title)} <span class="muted">— ${esc(s.doc)}</span></h3><dl>${rows}</dl>`;
|
|
866
|
+
}).join("");
|
|
867
|
+
$("help").innerHTML = `<p class="doc">The menus follow the work: create a morphology, characterize it, simulate it, export and compare. A section holds tabs; a tab lists its tools on its left, under the headings of what they do, and Generate its models by family. The search of the header (<kbd>/</kbd>) finds a tool, a model or an option of their forms (a behaviour, a law, a file format) and opens it; <kbd>Ctrl</kbd> + <kbd>Enter</kbd> runs the form shown; the address of the page (#tab/tool) is a link to what is shown.
|
|
868
|
+
Every morphology, simulation and design is kept in the workspace below the menus, from which any tab takes its input, in any order, and so is every run of a tool (R), shown again with its form filled, and every behaviour of a material (B: a material point, an import of Z-set), which the loading paths, cracks and inputs of other solvers take. Click an item of the workspace to send it on, show it again, view it in 3D or remove it; save the workspace to a folder and open it again later.</p>${html}`;
|
|
869
|
+
}
|
|
870
|
+
$("help-toggle").onclick = () => { $("help").hidden = !$("help").hidden; if (!$("help").hidden) showHelp(); };
|
|
871
|
+
$("help").addEventListener("click", (e) => { if (e.target.closest("a[href^='#']")) $("help").hidden = true; });
|
|
872
|
+
|
|
873
|
+
// -- colours: those of the system, light or dark ---------------------------------------------
|
|
874
|
+
const THEMES = {auto: "those of the system", light: "light", dark: "dark"};
|
|
875
|
+
function setTheme(theme) {
|
|
876
|
+
const t = theme in THEMES ? theme : "auto";
|
|
877
|
+
if (t === "auto") delete document.documentElement.dataset.theme;
|
|
878
|
+
else document.documentElement.dataset.theme = t;
|
|
879
|
+
$("theme-toggle").dataset.theme = t;
|
|
880
|
+
$("theme-toggle").title = `colours: ${THEMES[t]} (click to change)`;
|
|
881
|
+
try { localStorage.setItem("morphogen-theme", t); } catch (e) { /* no storage: not kept */ }
|
|
882
|
+
}
|
|
883
|
+
$("theme-toggle").onclick = () => {
|
|
884
|
+
const names = Object.keys(THEMES);
|
|
885
|
+
setTheme(names[(names.indexOf($("theme-toggle").dataset.theme) + 1) % names.length]);
|
|
886
|
+
};
|
|
887
|
+
try { setTheme(localStorage.getItem("morphogen-theme") || "auto"); } catch (e) { setTheme("auto"); }
|
|
888
|
+
|
|
889
|
+
// -- search: the tabs, the tools and the fields of their forms, the models and their parameters --
|
|
890
|
+
let INDEX = [], HITS = [], ACTIVE = 0;
|
|
891
|
+
function searchIndex(catalog, models, fixed = {}) { // fixed: the texts of the forms of the page itself, by tab
|
|
892
|
+
const entries = [];
|
|
893
|
+
// folded texts start with a space: " " + word finds the words that start with it
|
|
894
|
+
const add = (kind, title, shown, text, where, address, details) => entries.push({
|
|
895
|
+
kind, title, shown, where, address, ftitle: " " + fold(title), ftext: " " + fold(`${shown} ${text}`),
|
|
896
|
+
details: details.map((d) => ({...d, folded: " " + fold(d.text)}))});
|
|
897
|
+
const section = (tab) => SECTIONS.find((s) => s.name === tab.section).title;
|
|
898
|
+
for (const t of TABS) {
|
|
899
|
+
const tab = catalog.tabs.find((c) => c.name === t.name);
|
|
900
|
+
const details = (fixed[t.name] || []).map((text) => ({text}));
|
|
901
|
+
add("tab", t.title, tab ? tab.doc : FIXED_TABS[t.name] || "", "", section(t), t.name, details);
|
|
902
|
+
}
|
|
903
|
+
for (const x of catalog.tools) {
|
|
904
|
+
const t = tabOf(x.tab), details = [];
|
|
905
|
+
if (!t) continue;
|
|
906
|
+
for (const f of x.fields) { // each option of a choice, then the field itself
|
|
907
|
+
for (const [value, title] of f.choices || []) details.push({text: `${f.label}: ${title}`, field: f.name, value});
|
|
908
|
+
details.push({text: f.doc ? `${f.label} — ${f.doc}` : f.label, field: f.name});
|
|
909
|
+
}
|
|
910
|
+
add("tool", x.title, x.doc, x.menu || "", `${section(t)} › ${t.title}`, `${x.tab}/${x.name}`, details);
|
|
911
|
+
}
|
|
912
|
+
for (const m of models) {
|
|
913
|
+
const details = m.parameters.map((p) => ({text: `${p.name} — ${p.doc}`, field: p.name}));
|
|
914
|
+
add("model", m.name, m.summary, `${m.doc} ${m.family || ""}`, `Create › Generate › ${m.family || "Models"}`, `generate/${m.name}`, details);
|
|
915
|
+
}
|
|
916
|
+
return entries;
|
|
917
|
+
}
|
|
918
|
+
function searchMatches(index, query, limit = 12) { // the entries that hold every word, the best first
|
|
919
|
+
const words = fold(query).split(" ").filter(Boolean);
|
|
920
|
+
const out = [];
|
|
921
|
+
for (const e of words.length ? index : []) {
|
|
922
|
+
// a word of the query: the start of a word of the title, of the text, or of a field of the form
|
|
923
|
+
let score = e.ftitle === " " + words.join(" ") ? 10 : 0;
|
|
924
|
+
const loose = []; // the words that are not in the title
|
|
925
|
+
for (const w of words) {
|
|
926
|
+
if (`${e.ftitle} `.includes(` ${w} `)) score += 8;
|
|
927
|
+
else if (e.ftitle.includes(" " + w)) score += 6;
|
|
928
|
+
else if (e.ftext.includes(" " + w)) { score += 3; loose.push(w); }
|
|
929
|
+
else if (e.details.some((d) => d.folded.includes(" " + w))) { score += 2; loose.push(w); }
|
|
930
|
+
else { score = -1; break; }
|
|
931
|
+
}
|
|
932
|
+
if (score < 0) continue;
|
|
933
|
+
// the field of the form that holds them all, the earliest in its text: where the search lands
|
|
934
|
+
let detail = null, first = Infinity;
|
|
935
|
+
for (const d of loose.length ? e.details : []) {
|
|
936
|
+
const at = loose.map((w) => d.folded.indexOf(" " + w));
|
|
937
|
+
if (Math.min(...at) >= 0 && Math.max(...at) < first) { detail = d; first = Math.max(...at); }
|
|
938
|
+
}
|
|
939
|
+
out.push({entry: e, detail, score: score + (detail ? 1 : 0) + {tool: 0.3, model: 0.2, tab: 0.1}[e.kind]});
|
|
940
|
+
}
|
|
941
|
+
out.sort((a, b) => b.score - a.score); // stable: the ties in the order of the menus
|
|
942
|
+
return out.slice(0, limit);
|
|
943
|
+
}
|
|
944
|
+
function fixedLabels(tab) { // the labels, legends and options of a form of the page itself
|
|
945
|
+
const section = $("tab-" + tab);
|
|
946
|
+
if (!section || $("tools-" + tab)) return []; // the tabs of tools: from the catalog
|
|
947
|
+
// without the parameters of the model of Generate, found with the models
|
|
948
|
+
return [...section.querySelectorAll(".form label, .form legend, .form option")].filter((el) => !el.closest("#gen-params, #gen-model"));
|
|
949
|
+
}
|
|
950
|
+
function labelText(el) { return el.textContent.replace(/\s+/g, " ").trim(); }
|
|
951
|
+
function fixedTexts() { // their texts, by tab: what the search looks through
|
|
952
|
+
const out = {};
|
|
953
|
+
for (const t of TABS) out[t.name] = [...new Set(fixedLabels(t.name).map(labelText))].filter(Boolean);
|
|
954
|
+
return out;
|
|
955
|
+
}
|
|
956
|
+
function showMatches() {
|
|
957
|
+
const box = $("search-results");
|
|
958
|
+
HITS = searchMatches(INDEX, $("search").value);
|
|
959
|
+
ACTIVE = 0;
|
|
960
|
+
if (!fold($("search").value)) { box.hidden = true; return; }
|
|
961
|
+
box.innerHTML = HITS.length ? HITS.map((h, k) => `<button class="hit${k ? "" : " active"}" data-hit="${k}">
|
|
962
|
+
<span class="where">${esc(h.entry.where)}</span><b>${esc(h.entry.title)}</b>
|
|
963
|
+
<small>${esc(h.detail ? h.detail.text : shortDoc(h.entry.shown, 120))}</small></button>`).join("") :
|
|
964
|
+
'<p class="muted" style="margin:6px 9px">Nothing found: the map of the interface (?) lists every tab and tool.</p>';
|
|
965
|
+
box.hidden = false;
|
|
966
|
+
}
|
|
967
|
+
function openField(tab, tool, name, value, depth = 0) { // a field shown: the choices it depends on set, its option chosen
|
|
968
|
+
const f = tool.fields.find((x) => x.name === name);
|
|
969
|
+
if (!f || depth > 4) return;
|
|
970
|
+
for (const [k, values] of Object.entries(f.when || {})) {
|
|
971
|
+
openField(tab, tool, k, undefined, depth + 1);
|
|
972
|
+
const control = document.getElementById(`tool-${tool.name}-${k}`), allowed = values.map(String);
|
|
973
|
+
if (control && control.tagName === "SELECT" && !allowed.includes(control.value)) control.value = allowed[0];
|
|
974
|
+
else if (control && control.type === "checkbox" && !allowed.includes(String(control.checked))) control.checked = !control.checked;
|
|
975
|
+
}
|
|
976
|
+
const el = document.getElementById(`tool-${tool.name}-${name}`);
|
|
977
|
+
if (el && value !== undefined && f.kind === "choice") el.value = String(value);
|
|
978
|
+
if (el && value !== undefined && f.kind === "choices") {
|
|
979
|
+
const box = [...el.querySelectorAll("input")].find((c) => c.value === String(value));
|
|
980
|
+
if (box) box.checked = true;
|
|
981
|
+
}
|
|
982
|
+
toolVisibility(tab);
|
|
983
|
+
}
|
|
984
|
+
function reveal(hit) { // the field of a form the search found: shown, its option chosen, in sight
|
|
985
|
+
const [tab, name] = hit.entry.address.split("/");
|
|
986
|
+
let wrap = null;
|
|
987
|
+
if (hit.entry.kind === "model") {
|
|
988
|
+
const input = [...$("gen-params").querySelectorAll("[data-name]")].find((el) => el.dataset.name === hit.detail.field);
|
|
989
|
+
wrap = input ? input.closest("#gen-params > div") : null;
|
|
990
|
+
} else if (hit.entry.kind === "tool" && currentTool(tab).name === name) {
|
|
991
|
+
openField(tab, currentTool(tab), hit.detail.field, hit.detail.value);
|
|
992
|
+
wrap = [...$("toolform-" + tab).querySelectorAll(".field")].find((el) => el.dataset.name === hit.detail.field);
|
|
993
|
+
if (wrap && wrap.closest("details")) wrap.closest("details").open = true;
|
|
994
|
+
} else if (hit.entry.kind === "tab") { // a label or an option of a form of the page itself
|
|
995
|
+
const el = fixedLabels(tab).find((x) => labelText(x) === hit.detail.text);
|
|
996
|
+
wrap = el && el.tagName === "OPTION" ? el.closest("select") : el;
|
|
997
|
+
if (wrap && wrap.offsetParent === null) wrap = null; // in a part of the form that is not shown
|
|
998
|
+
}
|
|
999
|
+
if (!wrap || wrap.hidden) return false;
|
|
1000
|
+
wrap.classList.add("found");
|
|
1001
|
+
wrap.scrollIntoView({block: "center"});
|
|
1002
|
+
setTimeout(() => wrap.classList.remove("found"), 2600);
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
function openHit(k) {
|
|
1006
|
+
const hit = HITS[k];
|
|
1007
|
+
if (!hit) return;
|
|
1008
|
+
$("search-results").hidden = true;
|
|
1009
|
+
$("search").value = "";
|
|
1010
|
+
$("search").blur();
|
|
1011
|
+
$("help").hidden = true;
|
|
1012
|
+
go(hit.entry.address);
|
|
1013
|
+
if (!(hit.detail && reveal(hit))) window.scrollTo({top: 0});
|
|
1014
|
+
}
|
|
1015
|
+
$("search").addEventListener("input", showMatches);
|
|
1016
|
+
$("search").addEventListener("focus", showMatches);
|
|
1017
|
+
$("search").addEventListener("keydown", (e) => {
|
|
1018
|
+
const hits = [...$("search-results").querySelectorAll(".hit")];
|
|
1019
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
1020
|
+
e.preventDefault();
|
|
1021
|
+
if (!hits.length) return;
|
|
1022
|
+
ACTIVE = (ACTIVE + (e.key === "ArrowDown" ? 1 : hits.length - 1)) % hits.length;
|
|
1023
|
+
hits.forEach((h, k) => h.classList.toggle("active", k === ACTIVE));
|
|
1024
|
+
hits[ACTIVE].scrollIntoView({block: "nearest"});
|
|
1025
|
+
} else if (e.key === "Enter") { e.preventDefault(); openHit(ACTIVE); }
|
|
1026
|
+
else if (e.key === "Escape") { $("search").value = ""; $("search-results").hidden = true; $("search").blur(); }
|
|
1027
|
+
});
|
|
1028
|
+
$("search-results").addEventListener("click", (e) => {
|
|
1029
|
+
const b = e.target.closest(".hit");
|
|
1030
|
+
if (b) openHit(Number(b.dataset.hit));
|
|
1031
|
+
});
|
|
1032
|
+
document.addEventListener("click", (e) => { if (!e.target.closest("#search-box")) $("search-results").hidden = true; });
|
|
1033
|
+
document.addEventListener("keydown", (e) => {
|
|
1034
|
+
const typing = e.target.closest && e.target.closest("input, textarea, select, [contenteditable]");
|
|
1035
|
+
if ((e.key === "/" && !typing) || (e.key === "k" && (e.ctrlKey || e.metaKey))) { // to the search
|
|
1036
|
+
e.preventDefault();
|
|
1037
|
+
$("search").focus();
|
|
1038
|
+
$("search").select();
|
|
1039
|
+
} else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) { // run the form shown
|
|
1040
|
+
const run = document.querySelector(".tab.active button.go:not(:disabled)");
|
|
1041
|
+
if (run) { e.preventDefault(); run.click(); }
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
$("ws-save").onclick = () => busy($("ws-save"), async () => {
|
|
1046
|
+
let directory;
|
|
1047
|
+
if (DESKTOP) { // the stand-alone application: the dialog of the system
|
|
1048
|
+
directory = await DESKTOP.choose_folder("Folder to save the workspace to", "");
|
|
1049
|
+
if (!directory) return;
|
|
1050
|
+
} else {
|
|
1051
|
+
directory = prompt("Folder to save the workspace to (blank: a new one under ~/morphogen/workspaces):", "");
|
|
1052
|
+
if (directory === null) return;
|
|
1053
|
+
}
|
|
1054
|
+
try {
|
|
1055
|
+
const r = await api("/api/workspace/save", {directory});
|
|
1056
|
+
if (DESKTOP) await DESKTOP.workspace_saved();
|
|
1057
|
+
alert(`${r.saved} items saved to ${r.directory}`);
|
|
1058
|
+
} catch (e) { alert(e.message); }
|
|
1059
|
+
});
|
|
1060
|
+
$("ws-open").onclick = () => busy($("ws-open"), async () => {
|
|
1061
|
+
const directory = DESKTOP ? await DESKTOP.choose_folder("Folder of a saved workspace", "") :
|
|
1062
|
+
prompt("Folder of a saved workspace:", "");
|
|
1063
|
+
if (!directory) return;
|
|
1064
|
+
try {
|
|
1065
|
+
const r = await api("/api/workspace/open", {directory});
|
|
1066
|
+
await refreshWorkspace();
|
|
1067
|
+
alert(`${r.opened} items opened`);
|
|
1068
|
+
} catch (e) { alert(e.message); }
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
// -- the stand-alone application (morphogen desktop): the dialogs and files of the system ----
|
|
1072
|
+
let DESKTOP = null; // window.pywebview.api, in the window of the application
|
|
1073
|
+
window.addEventListener("pywebviewready", () => {
|
|
1074
|
+
DESKTOP = window.pywebview.api;
|
|
1075
|
+
document.body.classList.add("desktop");
|
|
1076
|
+
});
|
|
1077
|
+
document.addEventListener("click", async (e) => { // before the handlers of the page
|
|
1078
|
+
if (!DESKTOP) return;
|
|
1079
|
+
const browse = e.target.closest("button[data-browse]");
|
|
1080
|
+
const reveal = e.target.closest("button[data-reveal]");
|
|
1081
|
+
const link = e.target.closest("a[href^='/files/']");
|
|
1082
|
+
if (!browse && !reveal && !link) return;
|
|
1083
|
+
e.preventDefault();
|
|
1084
|
+
e.stopPropagation();
|
|
1085
|
+
try {
|
|
1086
|
+
if (browse) { // a path chosen in the dialog of the system
|
|
1087
|
+
const input = $(browse.dataset.for);
|
|
1088
|
+
const path = browse.dataset.browse === "folder" ? await DESKTOP.choose_folder("", input.value) :
|
|
1089
|
+
await DESKTOP.choose_file("", input.value);
|
|
1090
|
+
if (path) { input.value = path; input.dispatchEvent(new Event("input", {bubbles: true})); }
|
|
1091
|
+
} else if (reveal) {
|
|
1092
|
+
await DESKTOP.reveal(reveal.dataset.reveal);
|
|
1093
|
+
} else { // a file of a result: shown by its application, or saved where one chooses
|
|
1094
|
+
const href = link.getAttribute("href");
|
|
1095
|
+
if (href.includes("?inline") || link.target === "_blank") await DESKTOP.open_file(href);
|
|
1096
|
+
else await DESKTOP.save_file(href);
|
|
1097
|
+
}
|
|
1098
|
+
} catch (err) { alert(err.message || String(err)); }
|
|
1099
|
+
}, true);
|
|
1100
|
+
|
|
1101
|
+
// -- 1 generate (and formation) ------------------------------------------------------------
|
|
1102
|
+
function genRequest() {
|
|
1103
|
+
const size = numbers($("gen-size").value);
|
|
1104
|
+
return {
|
|
1105
|
+
model: $("gen-model").value, params: readForm($("gen-params")),
|
|
1106
|
+
domain: {size: size.length > 1 ? size : size[0], periodic: $("gen-periodic").checked},
|
|
1107
|
+
seed: $("gen-seed").value,
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
$("gen-go").onclick = () => busy($("gen-go"), async () => {
|
|
1111
|
+
const out = $("gen-out");
|
|
1112
|
+
out.innerHTML = '<p class="muted">Generating…</p>';
|
|
1113
|
+
try {
|
|
1114
|
+
const r = await api("/api/generate", {...genRequest(), resolution: $("gen-resolution").value});
|
|
1115
|
+
let html = (r.warnings || []).map((w) => `<p class="error">${esc(w)}</p>`).join("");
|
|
1116
|
+
const how = !r.level_set ? "sections of the phases at the pixel centres" :
|
|
1117
|
+
r.implicit_phases > 2 ? `sections of the implicit functions of its ${r.implicit_phases} phases` : "sections of the level set";
|
|
1118
|
+
html += `<h3>${esc(r.item ? r.item.title : r.model.type)} <span class="muted">— ${how}, ${r.resolution} px per edge, ${r.time_s} s</span></h3>${images(r.sections, true)}`;
|
|
1119
|
+
if (r.labels) html += `<h3>Cells</h3>${images(r.labels, true)}`;
|
|
1120
|
+
if (r.item && window.MorphoViewer) html += MorphoViewer.slot(r.item.key, {auto: true});
|
|
1121
|
+
html += sendButtons(r.item);
|
|
1122
|
+
// the frame of beams of a network model (frame_stiffness), in a table of its own
|
|
1123
|
+
const summary = r.frame ? Object.fromEntries(Object.entries(r.summary).filter(([k]) => !k.startsWith("frame_"))) : r.summary;
|
|
1124
|
+
// with its stiffness C_ij and compliance S_ij (tables of their own, with their .csv)
|
|
1125
|
+
const frame = r.frame ? `<h3>Frame of beams</h3><p class="muted">${esc(r.frame.note)}</p>${table(r.frame.values)}${(r.frame.tables || []).map(dataTable).join("")}` : "";
|
|
1126
|
+
html += `<div class="row"><div><h3>Realization</h3>${table(summary)}${frame}<h3>Measures</h3>${table(r.measures)}</div>
|
|
1127
|
+
<div><h3>Theory</h3>${table(r.theory)}</div></div>`;
|
|
1128
|
+
if (r.files) html += `<p>Download: <a href="${r.files.geometry}">geometry (.json)</a> · more in Export</p>`;
|
|
1129
|
+
out.innerHTML = html;
|
|
1130
|
+
await refreshWorkspace();
|
|
1131
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1132
|
+
});
|
|
1133
|
+
let player = null;
|
|
1134
|
+
$("evo-go").onclick = () => busy($("evo-go"), async () => {
|
|
1135
|
+
const out = $("gen-out");
|
|
1136
|
+
out.innerHTML = '<p class="muted">Simulating the formation…</p>';
|
|
1137
|
+
if (player) clearInterval(player);
|
|
1138
|
+
try {
|
|
1139
|
+
const r = await api("/api/formation", {...genRequest(), frames: Number($("evo-frames").value)});
|
|
1140
|
+
out.innerHTML = `<h3>Formation of ${esc($("gen-model").value)} <span class="muted">(middle section)</span></h3>
|
|
1141
|
+
<div class="player"><img id="evo-img"><br>
|
|
1142
|
+
<input type="range" id="evo-slider" min="0" max="${r.frames.length - 1}" value="0">
|
|
1143
|
+
<button id="evo-play">pause</button> <span class="muted" id="evo-label"></span></div>
|
|
1144
|
+
<p class="note">The share of cells that change between frames tells how fast the structure settles: automata often form their pattern in a few steps, then only refine it.</p>`;
|
|
1145
|
+
let k = 0, playing = true;
|
|
1146
|
+
const show = () => {
|
|
1147
|
+
$("evo-img").src = r.frames[k]; $("evo-slider").value = k;
|
|
1148
|
+
const change = k > 0 && r.changes ? `, ${(100 * r.changes[k - 1]).toFixed(1)} % of the cells changed` : " (initial state)";
|
|
1149
|
+
$("evo-label").textContent = `frame ${k + 1} / ${r.frames.length}${change}`;
|
|
1150
|
+
};
|
|
1151
|
+
show();
|
|
1152
|
+
player = setInterval(() => { if (playing) { k = (k + 1) % r.frames.length; show(); } }, 300);
|
|
1153
|
+
$("evo-slider").oninput = (e) => { k = Number(e.target.value); show(); };
|
|
1154
|
+
$("evo-play").onclick = (e) => { playing = !playing; e.target.textContent = playing ? "pause" : "play"; };
|
|
1155
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
// -- 2 simulate --------------------------------------------------------------------------------
|
|
1159
|
+
const SIM_FIELDS = ["von_mises", "energy_density", "displacement",
|
|
1160
|
+
...["stress", "strain"].flatMap((n) => ["11", "22", "33", "23", "31", "12"].map((c) => `${n}_${c}`))];
|
|
1161
|
+
const CMAPS = ["viridis", "plasma", "inferno", "magma", "cividis", "turbo", "coolwarm", "RdBu_r", "jet", "gray"];
|
|
1162
|
+
for (const id of ["sim-field", "exp-field"]) $(id).innerHTML = SIM_FIELDS.map((f) => `<option>${f}</option>`).join("");
|
|
1163
|
+
for (const id of ["sim-cmap", "exp-cmap"]) $(id).innerHTML = CMAPS.map((c) => `<option>${c}</option>`).join("");
|
|
1164
|
+
$("exp-frac").oninput = (e) => { $("exp-frac-label").textContent = `${Math.round(e.target.value * 100)} %`; };
|
|
1165
|
+
function simSource() {
|
|
1166
|
+
const it = item($("sim-source").value);
|
|
1167
|
+
$("sim-card").innerHTML = it ? card(it) : '<p class="muted">No morphology in the workspace yet: generate one.</p>';
|
|
1168
|
+
if (!it) { $("sim-materials").innerHTML = '<p class="muted">Choose a morphology.</p>'; return; }
|
|
1169
|
+
const phases = it.phases || {"0": "matrix", "1": "inclusions"};
|
|
1170
|
+
if ($("sim-materials").dataset.key === it.key) return;
|
|
1171
|
+
$("sim-materials").dataset.key = it.key;
|
|
1172
|
+
// conforming meshes follow a level set: the others are simulated on their voxels
|
|
1173
|
+
if (it.info && it.info["level set"] === false) $("sim-method").value = "fft";
|
|
1174
|
+
$("sim-materials").innerHTML = Object.entries(phases).map(([k, name], i) => `
|
|
1175
|
+
<div class="row mat" data-phase="${esc(k)}">
|
|
1176
|
+
<div><label title="${esc(name)}">${esc(k)}: ${esc(name)} <small>E</small></label><input data-e value="${i === 0 ? 1 : 20}"></div>
|
|
1177
|
+
<div><label><small>Poisson ν</small></label><input data-nu value="0.3"></div>
|
|
1178
|
+
<div><label> </label><label><input type="checkbox" data-void ${name === "void" ? "checked" : ""}>void</label></div>
|
|
1179
|
+
</div>`).join("");
|
|
1180
|
+
}
|
|
1181
|
+
$("sim-source").onchange = simSource;
|
|
1182
|
+
function media(list) { // the files of a result shown in the page; images given as data URLs as they are
|
|
1183
|
+
return `<div class="views">${(list || []).map((m) => {
|
|
1184
|
+
const data = m.url.startsWith("data:"), src = data ? m.url : `${m.url}?inline`;
|
|
1185
|
+
const view = m.format === "mp4" ? `<video src="${src}" controls autoplay loop muted playsinline></video>` :
|
|
1186
|
+
data ? `<img src="${src}" alt="${esc(m.title)}">` :
|
|
1187
|
+
`<a href="${src}" target="_blank"><img src="${src}" alt="${esc(m.title)}"></a>`;
|
|
1188
|
+
return `<figure>${view}<figcaption>${esc(m.title)}</figcaption></figure>`;
|
|
1189
|
+
}).join("")}</div>`;
|
|
1190
|
+
}
|
|
1191
|
+
function fileList(files) {
|
|
1192
|
+
const kinds = ["archive", "report", "data", "table", "figure", "video", "configuration"];
|
|
1193
|
+
return `<div class="files">${kinds.map((k) => {
|
|
1194
|
+
const of = (files || []).filter((f) => f.kind === k);
|
|
1195
|
+
return of.length ? `<span><b>${k}</b>${of.map((f) => `<a href="${f.url}">${esc(f.name)}</a>`).join(" · ")}</span>` : "";
|
|
1196
|
+
}).join("")}</div>`;
|
|
1197
|
+
}
|
|
1198
|
+
$("sim-go").onclick = () => busy($("sim-go"), async () => {
|
|
1199
|
+
const out = $("sim-out");
|
|
1200
|
+
const key = $("sim-source").value;
|
|
1201
|
+
if (!key) { out.innerHTML = '<p class="error">Generate a morphology first (tab 1).</p>'; return; }
|
|
1202
|
+
const materials = {};
|
|
1203
|
+
for (const row of document.querySelectorAll("#sim-materials .mat")) {
|
|
1204
|
+
materials[row.dataset.phase] = row.querySelector("[data-void]").checked ? "void" :
|
|
1205
|
+
{young: Number(row.querySelector("[data-e]").value), poisson: Number(row.querySelector("[data-nu]").value)};
|
|
1206
|
+
}
|
|
1207
|
+
out.innerHTML = '<p class="muted">Starting…</p>';
|
|
1208
|
+
try {
|
|
1209
|
+
const {job} = await api("/api/simulate", {
|
|
1210
|
+
source: key, method: $("sim-method").value, property: $("sim-property").value,
|
|
1211
|
+
element_size: $("sim-element").value.trim(), order: $("sim-order").value,
|
|
1212
|
+
shape: $("sim-shape").value, materials,
|
|
1213
|
+
field: $("sim-field").value, cmap: $("sim-cmap").value, video: "none",
|
|
1214
|
+
device: $("sim-gpu").checked && $("sim-method").value === "fft" ? "gpu" : "cpu",
|
|
1215
|
+
});
|
|
1216
|
+
for (;;) {
|
|
1217
|
+
const s = await api(`/api/job/${job}`);
|
|
1218
|
+
if (s.state === "running") {
|
|
1219
|
+
out.innerHTML = `<p class="muted">Solving: ${$("sim-method").value === "fe" ? "conforming mesh of the level set, finite elements" : "voxels, FFT"}… ${s.elapsed_s} s${stopButton(job)}</p>`;
|
|
1220
|
+
await wait(800);
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (s.state === "stopped") { out.innerHTML = stoppedNote(s); break; }
|
|
1224
|
+
if (s.error) { out.innerHTML = `<p class="error">${esc(s.error)}</p>`; break; }
|
|
1225
|
+
const r = s.result;
|
|
1226
|
+
let html = (r.warnings || []).map((w) => `<p class="error">${esc(w)}</p>`).join("");
|
|
1227
|
+
html += `<h3>${esc(r.item.title)} <span class="muted">(${r.time_s} s)</span></h3>${media(r.figures)}`;
|
|
1228
|
+
if (window.MorphoViewer) html += MorphoViewer.slot(r.item.key, {auto: true, field: $("sim-field").value, cmap: $("sim-cmap").value});
|
|
1229
|
+
html += sendButtons(r.item);
|
|
1230
|
+
html += `<h3>Results</h3>${table(r.values)}`;
|
|
1231
|
+
out.innerHTML = html;
|
|
1232
|
+
await refreshWorkspace();
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
// -- 3 export ----------------------------------------------------------------------------------
|
|
1239
|
+
function expSource() {
|
|
1240
|
+
const it = item($("exp-source").value);
|
|
1241
|
+
$("exp-card").innerHTML = it ? card(it) : '<p class="muted">The workspace is empty: generate a morphology.</p>';
|
|
1242
|
+
$("exp-morphology").hidden = !it || it.kind !== "morphology";
|
|
1243
|
+
$("exp-simulation").hidden = !it || it.kind !== "simulation";
|
|
1244
|
+
if (it && it.kind === "simulation" && $("exp-field").dataset.key !== it.key) {
|
|
1245
|
+
$("exp-field").dataset.key = it.key; // the fields of its files (plastic strains, porosity...)
|
|
1246
|
+
api(`/api/fields?key=${encodeURIComponent(it.key)}`).then((r) => {
|
|
1247
|
+
const keep = $("exp-field").value;
|
|
1248
|
+
$("exp-field").innerHTML = r.fields.map((f) => `<option>${esc(f)}</option>`).join("");
|
|
1249
|
+
if (r.fields.includes(keep)) $("exp-field").value = keep;
|
|
1250
|
+
}).catch(() => {});
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
$("exp-source").onchange = expSource;
|
|
1254
|
+
$("exp-go").onclick = () => busy($("exp-go"), async () => {
|
|
1255
|
+
const out = $("exp-out");
|
|
1256
|
+
const it = item($("exp-source").value);
|
|
1257
|
+
if (!it) { out.innerHTML = '<p class="error">Nothing to export yet: generate a morphology (tab 1).</p>'; return; }
|
|
1258
|
+
const playback = {mode: $("exp-mode").value, frames: Number($("exp-frames").value),
|
|
1259
|
+
fps: Number($("exp-fps").value), axis: $("exp-axis").value};
|
|
1260
|
+
let request;
|
|
1261
|
+
if (it.kind === "morphology") {
|
|
1262
|
+
request = {source: it.key, ...playback,
|
|
1263
|
+
outputs: [...document.querySelectorAll("#exp-morphology [data-out]")].filter((c) => c.checked).map((c) => c.dataset.out),
|
|
1264
|
+
resolution: $("exp-resolution").value, shape: $("exp-shape").value,
|
|
1265
|
+
element_size: $("exp-element").value.trim(), video: $("exp-mvideo").value};
|
|
1266
|
+
} else {
|
|
1267
|
+
request = {source: it.key, ...playback,
|
|
1268
|
+
outputs: [...document.querySelectorAll("#exp-simulation [data-sout]")].filter((c) => c.checked).map((c) => c.dataset.sout),
|
|
1269
|
+
field: $("exp-field").value, cmap: $("exp-cmap").value, magnification: $("exp-mag").value.trim(),
|
|
1270
|
+
section_axis: $("exp-cut").value, section_fraction: Number($("exp-frac").value),
|
|
1271
|
+
clim_low: $("exp-lo").value.trim(), clim_high: $("exp-hi").value.trim(),
|
|
1272
|
+
video: $("exp-svideo").value, wave: $("exp-wave").value, formats: ["png", "svg", "tex"]};
|
|
1273
|
+
}
|
|
1274
|
+
out.innerHTML = '<p class="muted">Exporting…</p>';
|
|
1275
|
+
try {
|
|
1276
|
+
const r = await api("/api/export", request);
|
|
1277
|
+
let html = `<h3>${esc(r.source.title)}</h3>`;
|
|
1278
|
+
if (r.archive) html += `<p><a href="${r.archive}"><b>Download everything (.zip)</b></a></p>`;
|
|
1279
|
+
if (r.figures.length) html += `<h3>Figures</h3>${media(r.figures)}`;
|
|
1280
|
+
if (r.videos.length) html += `<h3>Video</h3>${media(r.videos)}`;
|
|
1281
|
+
html += `<h3>Files</h3>${fileList(r.files)}`;
|
|
1282
|
+
out.innerHTML = html;
|
|
1283
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1284
|
+
});
|
|
1285
|
+
|
|
1286
|
+
// -- 4 optimize --------------------------------------------------------------------------------
|
|
1287
|
+
function optStart() {
|
|
1288
|
+
const it = item($("opt-start").value);
|
|
1289
|
+
$("opt-card").innerHTML = it ? card(it) : "";
|
|
1290
|
+
$("opt-phase-row").hidden = !it;
|
|
1291
|
+
if (!it || $("opt-card").dataset.key === it.key) return;
|
|
1292
|
+
$("opt-card").dataset.key = it.key;
|
|
1293
|
+
const phases = it.phases || {"0": "0", "1": "1"};
|
|
1294
|
+
$("opt-phase").innerHTML = Object.entries(phases).map(([k, n]) => `<option value="${k}">${esc(k)}: ${esc(n)}</option>`).join("");
|
|
1295
|
+
$("opt-phase").value = "1" in phases ? "1" : Object.keys(phases)[0];
|
|
1296
|
+
if (typeof it.fraction === "number" && isFinite(it.fraction)) $("opt-volume").value = it.fraction.toFixed(3);
|
|
1297
|
+
if (it.property) $("opt-objective").value = it.property;
|
|
1298
|
+
$("opt-grid").value = it.planar ? "48, 48, 1" : "32, 32, 32";
|
|
1299
|
+
}
|
|
1300
|
+
$("opt-start").onchange = optStart;
|
|
1301
|
+
function chart(values) {
|
|
1302
|
+
if (values.length < 2) return "";
|
|
1303
|
+
const lo = Math.min(...values), hi = Math.max(...values), span = hi - lo || 1;
|
|
1304
|
+
const pts = values.map((v, i) => `${(i / (values.length - 1)) * 400 + 10},${110 - ((v - lo) / span) * 100}`);
|
|
1305
|
+
return `<svg class="chart" viewBox="0 0 420 120"><polyline style="fill:none;stroke:var(--accent)" stroke-width="2" points="${pts.join(" ")}"/>
|
|
1306
|
+
<text x="12" y="14" font-size="11" style="fill:var(--muted)">objective ${+values[values.length - 1].toPrecision(4)}</text></svg>`;
|
|
1307
|
+
}
|
|
1308
|
+
$("opt-go").onclick = () => busy($("opt-go"), async () => {
|
|
1309
|
+
const out = $("opt-out");
|
|
1310
|
+
out.innerHTML = '<p class="muted">Starting…</p>';
|
|
1311
|
+
try {
|
|
1312
|
+
const projection = Number($("opt-projection").value);
|
|
1313
|
+
const start = $("opt-start").value;
|
|
1314
|
+
const {job} = await api("/api/optimize", {
|
|
1315
|
+
start, solid_phase: item(start) ? Number($("opt-phase").value) : undefined,
|
|
1316
|
+
grid: numbers($("opt-grid").value), volume_fraction: Number($("opt-volume").value),
|
|
1317
|
+
settings: {objective: $("opt-objective").value, method: $("opt-method").value,
|
|
1318
|
+
filter_radius: Number($("opt-filter").value), projection,
|
|
1319
|
+
symmetry: $("opt-symmetry").value, iterations: Number($("opt-iterations").value)},
|
|
1320
|
+
});
|
|
1321
|
+
for (;;) {
|
|
1322
|
+
const s = await api(`/api/job/${job}`);
|
|
1323
|
+
let html = s.png ? `<div class="player"><img src="${s.png}"></div>` : "";
|
|
1324
|
+
html += `<p class="muted">iteration ${s.iteration}${s.volume.length ? ", volume " + s.volume[s.volume.length - 1].toFixed(3) : ""}${s.state === "running" ? stopButton(job).replace("its next step", "the end of this iteration") : ""}</p>${chart(s.objective)}`;
|
|
1325
|
+
if (s.result) {
|
|
1326
|
+
if (s.result.item) html += `<h3>${esc(s.result.item.title)}</h3>` + sendButtons(s.result.item);
|
|
1327
|
+
html += `<h3>Thresholded design</h3>${table(s.result.properties)}${(s.result.tables || []).map(dataTable).join("")}
|
|
1328
|
+
<h3>On a grid twice as fine</h3>${table(s.result.refined_properties)}
|
|
1329
|
+
<p class="muted">${s.result.iterations} iterations (${s.result.converged ? "converged" : s.result.stopped ? "stopped: the design so far" : "not converged"}), ${s.result.time_s} s; volume fraction ${s.result.binary_fraction.toFixed(3)}</p>`;
|
|
1330
|
+
if (s.result.hinges) html += `<p class="error">${s.result.hinges} blocks of voxels touch only at an edge or a corner (hinges, stiff for voxel elements): trust the finer grid, or simulate the design on a conforming mesh.</p>`;
|
|
1331
|
+
}
|
|
1332
|
+
if (s.error) html += `<p class="error">${esc(s.error)}</p>`;
|
|
1333
|
+
out.innerHTML = html;
|
|
1334
|
+
if (s.state !== "running") { if (s.result) await refreshWorkspace(); break; }
|
|
1335
|
+
await wait(700);
|
|
1336
|
+
}
|
|
1337
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1338
|
+
});
|
|
1339
|
+
|
|
1340
|
+
// -- tools: tabs and forms built from the catalog of the server -------------------------------
|
|
1341
|
+
let CATALOG = {tabs: [], tools: []};
|
|
1342
|
+
function placeTab(tab, section) { // a tab of tools among the tabs of its section
|
|
1343
|
+
TABS.push({name: tab.name, title: tab.title, section: tab.section || "simulate", order: tab.order});
|
|
1344
|
+
document.querySelector("main").appendChild(section);
|
|
1345
|
+
}
|
|
1346
|
+
function toolMenu(tools) { // the tools of a tab under the headings of their menu
|
|
1347
|
+
let html = "", heading = "";
|
|
1348
|
+
for (const x of tools) {
|
|
1349
|
+
if ((x.menu || "") !== heading) {
|
|
1350
|
+
heading = x.menu || "";
|
|
1351
|
+
if (heading) html += `<h4>${esc(heading)}</h4>`;
|
|
1352
|
+
}
|
|
1353
|
+
html += `<button data-tool="${esc(x.name)}" title="${esc(shortDoc(x.doc))}">${esc(x.title)}</button>`;
|
|
1354
|
+
}
|
|
1355
|
+
return html;
|
|
1356
|
+
}
|
|
1357
|
+
const LOCKED = {}; // the tabs whose tool runs on several items: it stays until they are done
|
|
1358
|
+
function chooseTool(tab, name) { // the tool a tab shows: its form, its entry of the menu
|
|
1359
|
+
const select = $("tools-" + tab);
|
|
1360
|
+
if (!select || LOCKED[tab] || ![...select.options].some((o) => o.value === name)) return false;
|
|
1361
|
+
if (select.value !== name) { select.value = name; buildToolForm(tab); keepItem(tab); }
|
|
1362
|
+
return true;
|
|
1363
|
+
}
|
|
1364
|
+
function lockTools(tab, on) {
|
|
1365
|
+
LOCKED[tab] = on;
|
|
1366
|
+
for (const b of $("toolmenu-" + tab).querySelectorAll("button")) b.disabled = on;
|
|
1367
|
+
}
|
|
1368
|
+
function fieldHtml(tool, f) {
|
|
1369
|
+
const id = `tool-${tool.name}-${f.name}`;
|
|
1370
|
+
const unit = f.unit ? ` [${esc(f.unit)}]` : "";
|
|
1371
|
+
// the documentation on one line, all of it on hover
|
|
1372
|
+
const label = `${esc(f.label)}${f.required ? " *" : ""}<small class="fdoc" title="${esc(f.doc)}">${unit}${f.doc ? " — " + esc(f.doc) : ""}</small>`;
|
|
1373
|
+
const def = f.default === null || f.default === undefined ? "" :
|
|
1374
|
+
(Array.isArray(f.default) ? f.default.join(", ") : (typeof f.default === "object" ? JSON.stringify(f.default) : f.default));
|
|
1375
|
+
if (f.kind === "bool") {
|
|
1376
|
+
return `<label title="${esc(f.doc)}"><input type="checkbox" id="${id}" ${f.default ? "checked" : ""}>${esc(f.label)}</label>`;
|
|
1377
|
+
}
|
|
1378
|
+
let input;
|
|
1379
|
+
if (f.kind === "choice") {
|
|
1380
|
+
input = `<select id="${id}">${f.choices.map(([v, t]) => `<option value="${esc(v)}"${v === f.default ? " selected" : ""}>${esc(t)}</option>`).join("")}</select>`;
|
|
1381
|
+
} else if (f.kind === "choices") {
|
|
1382
|
+
input = `<div class="checks" id="${id}">${f.choices.map(([v, t]) => `<label><input type="checkbox" value="${esc(v)}"${(f.default || []).includes(v) ? " checked" : ""}>${esc(t)}</label>`).join("")}</div>`;
|
|
1383
|
+
} else if (f.kind === "items") {
|
|
1384
|
+
input = `<div class="checks" id="${id}" data-multi="1" data-items="${f.items.join(",")}" data-needs="${(f.needs || []).join(",")}"></div>`;
|
|
1385
|
+
} else if (f.kind === "item") {
|
|
1386
|
+
input = `<select id="${id}" data-items="${f.items.join(",")}" data-needs="${(f.needs || []).join(",")}" data-none="${esc(f.none || "")}"></select>`;
|
|
1387
|
+
} else if (f.kind === "materials") {
|
|
1388
|
+
input = `<div id="${id}" class="materials"><p class="muted">Choose the item first.</p></div>`;
|
|
1389
|
+
} else if (f.kind === "json" || f.kind === "text") {
|
|
1390
|
+
input = `<textarea id="${id}" rows="3">${esc(def)}</textarea>`;
|
|
1391
|
+
} else {
|
|
1392
|
+
input = `<input id="${id}" value="${esc(def)}"${f.required ? " placeholder=\"required\"" : ""}>`;
|
|
1393
|
+
if (f.browse) { // a path: the dialog of the system in the stand-alone application
|
|
1394
|
+
input = `<div class="pathrow">${input}<button type="button" class="plain browse" data-browse="${esc(f.browse)}" data-for="${id}">Browse…</button></div>`;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return `<label for="${id}">${label}</label>${input}`;
|
|
1398
|
+
}
|
|
1399
|
+
function buildToolTabs(catalog) {
|
|
1400
|
+
CATALOG = catalog;
|
|
1401
|
+
for (const t of catalog.tabs) {
|
|
1402
|
+
const tools = catalog.tools.filter((x) => x.tab === t.name);
|
|
1403
|
+
if (!tools.length) continue;
|
|
1404
|
+
const section = document.createElement("section");
|
|
1405
|
+
section.className = "tab"; section.id = "tab-" + t.name;
|
|
1406
|
+
// the menu of the tab (its tools under their headings), the form of the tool chosen, its results
|
|
1407
|
+
section.innerHTML = `<nav class="panel sidemenu" id="toolmenu-${t.name}" aria-label="tools of ${esc(t.title)}"${tools.length > 1 ? "" : " hidden"}>${toolMenu(tools)}</nav>
|
|
1408
|
+
<div class="panel form">
|
|
1409
|
+
<select id="tools-${t.name}" hidden>${tools.map((x) => `<option value="${x.name}">${esc(x.title)}</option>`).join("")}</select>
|
|
1410
|
+
<h2 class="title" id="tooltitle-${t.name}"></h2>
|
|
1411
|
+
<p class="doc" id="tooldoc-${t.name}"></p>
|
|
1412
|
+
<div id="toolform-${t.name}"></div>
|
|
1413
|
+
<div class="runbar"><button class="go" id="toolgo-${t.name}" title="run the form (Ctrl + Enter)">Run</button></div>
|
|
1414
|
+
<details class="each" id="toolmany-${t.name}" hidden><summary>Run on several items</summary>
|
|
1415
|
+
<p class="muted">The form above for each item checked, one after another, each run kept in the workspace.</p>
|
|
1416
|
+
<div class="checks" id="toolmanyitems-${t.name}"></div>
|
|
1417
|
+
<button class="plain" id="toolmanygo-${t.name}">Run on each</button></details>
|
|
1418
|
+
</div>
|
|
1419
|
+
<div class="panel results" id="toolout-${t.name}"><p class="muted">${esc(t.doc)}</p></div>`;
|
|
1420
|
+
placeTab(t, section);
|
|
1421
|
+
$("toolmenu-" + t.name).addEventListener("click", (e) => {
|
|
1422
|
+
const b = e.target.closest("button[data-tool]");
|
|
1423
|
+
if (b) chooseTool(t.name, b.dataset.tool);
|
|
1424
|
+
});
|
|
1425
|
+
$("toolgo-" + t.name).onclick = () => busy($("toolgo-" + t.name), () => runTool(t.name));
|
|
1426
|
+
$("toolmanygo-" + t.name).onclick = () => busy($("toolmanygo-" + t.name), () => runMany(t.name));
|
|
1427
|
+
buildToolForm(t.name);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
function currentTool(tab) { return CATALOG.tools.find((x) => x.name === $("tools-" + tab).value); }
|
|
1431
|
+
function shortDoc(doc, size = 220) { // the first sentence, or the first words, of a long text
|
|
1432
|
+
if (doc.length <= size + 60) return doc;
|
|
1433
|
+
const end = doc.search(/\.\s/);
|
|
1434
|
+
if (end > 40 && end < size) return doc.slice(0, end + 1);
|
|
1435
|
+
return doc.slice(0, doc.lastIndexOf(" ", size)) + "…";
|
|
1436
|
+
}
|
|
1437
|
+
function setDoc(el, doc) { // a long explanation shortened, the whole of it on demand
|
|
1438
|
+
const short = shortDoc(doc);
|
|
1439
|
+
if (short === doc) { el.textContent = doc; return; }
|
|
1440
|
+
el.innerHTML = `${esc(short)} <a href="#" class="more">more</a>`;
|
|
1441
|
+
el.querySelector(".more").onclick = (e) => { e.preventDefault(); el.textContent = doc; };
|
|
1442
|
+
}
|
|
1443
|
+
function buildToolForm(tab) {
|
|
1444
|
+
const tool = currentTool(tab);
|
|
1445
|
+
$("tooltitle-" + tab).textContent = tool.title;
|
|
1446
|
+
for (const b of $("toolmenu-" + tab).querySelectorAll("button")) b.classList.toggle("active", b.dataset.tool === tool.name);
|
|
1447
|
+
if ($("tab-" + tab).classList.contains("active")) setAddress(tab);
|
|
1448
|
+
setDoc($("tooldoc-" + tab), tool.doc);
|
|
1449
|
+
const form = $("toolform-" + tab);
|
|
1450
|
+
// short fields (numbers, words) two by two; the others on a line of their own
|
|
1451
|
+
const short = (f) => ["float", "int", "str", "floats", "ints", "choice", "bool"].includes(f.kind);
|
|
1452
|
+
// in the boxes of their group (specimen, material, loading...), the seldom changed folded
|
|
1453
|
+
let html = "", box = "";
|
|
1454
|
+
for (const f of tool.fields) {
|
|
1455
|
+
if ((f.group || "") !== box) {
|
|
1456
|
+
if (box) html += "</div></details>";
|
|
1457
|
+
box = f.group || "";
|
|
1458
|
+
if (box) html += `<details class="fgroup"${f.fold ? "" : " open"}><summary>${esc(box)}</summary><div class="fgrid">`;
|
|
1459
|
+
}
|
|
1460
|
+
html += `<div class="field${short(f) ? " half" : ""}" data-name="${f.name}">${fieldHtml(tool, f)}</div>`;
|
|
1461
|
+
}
|
|
1462
|
+
form.innerHTML = html + (box ? "</div></details>" : "");
|
|
1463
|
+
form.oninput = form.onchange = () => toolVisibility(tab);
|
|
1464
|
+
fillToolItems(tab);
|
|
1465
|
+
fillMany(tab);
|
|
1466
|
+
toolVisibility(tab);
|
|
1467
|
+
}
|
|
1468
|
+
function manyField(tool) { // the field of the item a tool runs on, if it can run on several
|
|
1469
|
+
return tool.fields.find((f) => f.kind === "item" && !f.none);
|
|
1470
|
+
}
|
|
1471
|
+
function fillMany(tab) { // the items the run on several items offers: those the field takes
|
|
1472
|
+
const tool = currentTool(tab), f = manyField(tool), box = $("toolmanyitems-" + tab);
|
|
1473
|
+
$("toolmany-" + tab).hidden = !f;
|
|
1474
|
+
if (!f) return;
|
|
1475
|
+
const checked = new Set([...box.querySelectorAll("input:checked")].map((c) => c.value));
|
|
1476
|
+
const its = WS.filter((i) => takes(f, i));
|
|
1477
|
+
box.innerHTML = its.length ? its.map((i) => `<label><input type="checkbox" value="${i.key}"${checked.has(i.key) ? " checked" : ""}>${KIND[i.kind]} ${esc(i.title)}</label>`).join("") :
|
|
1478
|
+
'<span class="muted">none in the workspace yet</span>';
|
|
1479
|
+
}
|
|
1480
|
+
async function runMany(tab) { // the form for each item checked, one after another
|
|
1481
|
+
const tool = currentTool(tab), keys = [...$("toolmanyitems-" + tab).querySelectorAll("input:checked")].map((c) => c.value);
|
|
1482
|
+
if (!keys.length) { $("toolout-" + tab).innerHTML = '<p class="error">Check the items to run on.</p>'; return; }
|
|
1483
|
+
const done = [];
|
|
1484
|
+
lockTools(tab, true); // the same tool for every item
|
|
1485
|
+
try {
|
|
1486
|
+
for (const [k, key] of keys.entries()) {
|
|
1487
|
+
const it = item(key);
|
|
1488
|
+
if (!it || !itemField(tool, it)) continue; // removed from the workspace meanwhile
|
|
1489
|
+
putItem(tab, tool, key);
|
|
1490
|
+
const s = await runTool(tab, `${k + 1} of ${keys.length}: ${it.title}`);
|
|
1491
|
+
if (!s || s.state !== "done") break; // stopped or failed: the others not run
|
|
1492
|
+
done.push(s.result.key);
|
|
1493
|
+
}
|
|
1494
|
+
} finally { lockTools(tab, false); }
|
|
1495
|
+
const runs = done.map((key) => item(key)).filter(Boolean);
|
|
1496
|
+
if (!runs.length) return;
|
|
1497
|
+
const curves = runs.every((it) => (it.traits || []).includes("curves"));
|
|
1498
|
+
const summary = `<h3>${runs.length} of ${keys.length} runs done</h3><p>${runs.map((it) => esc(it.title)).join("<br>")}</p>` +
|
|
1499
|
+
(curves && runs.length > 1 ? `<p><button class="plain" id="many-compare-${tab}">Compare their curves →</button></p>` : "");
|
|
1500
|
+
$("toolout-" + tab).insertAdjacentHTML("afterbegin", summary);
|
|
1501
|
+
if ($("many-compare-" + tab)) $("many-compare-" + tab).onclick = () => { for (const it of runs) sendTo("compare", it.key); };
|
|
1502
|
+
}
|
|
1503
|
+
function readField(el, f) {
|
|
1504
|
+
if (f.kind === "bool") return el.checked;
|
|
1505
|
+
if (f.kind === "choices" || f.kind === "items") return [...el.querySelectorAll("input:checked")].map((c) => c.value);
|
|
1506
|
+
if (f.kind === "materials") {
|
|
1507
|
+
const m = {};
|
|
1508
|
+
for (const row of el.querySelectorAll(".mat")) {
|
|
1509
|
+
m[row.dataset.phase] = row.querySelector("[data-void]").checked ? "void" :
|
|
1510
|
+
{young: Number(row.querySelector("[data-e]").value), poisson: Number(row.querySelector("[data-nu]").value)};
|
|
1511
|
+
}
|
|
1512
|
+
return Object.keys(m).length ? m : null;
|
|
1513
|
+
}
|
|
1514
|
+
return el.value.trim();
|
|
1515
|
+
}
|
|
1516
|
+
function toolValues(tab) {
|
|
1517
|
+
const tool = currentTool(tab), out = {};
|
|
1518
|
+
for (const f of tool.fields) {
|
|
1519
|
+
const el = document.getElementById(`tool-${tool.name}-${f.name}`);
|
|
1520
|
+
if (el) out[f.name] = readField(el, f);
|
|
1521
|
+
}
|
|
1522
|
+
return out;
|
|
1523
|
+
}
|
|
1524
|
+
function toolVisibility(tab) {
|
|
1525
|
+
const tool = currentTool(tab), values = toolValues(tab);
|
|
1526
|
+
for (const f of tool.fields) {
|
|
1527
|
+
const wrap = $("toolform-" + tab).querySelector(`.field[data-name="${f.name}"]`);
|
|
1528
|
+
wrap.hidden = !(!f.when || Object.entries(f.when).every(([k, vs]) => vs.map(String).includes(String(values[k]))));
|
|
1529
|
+
if (f.kind === "materials") materialsEditor(document.getElementById(`tool-${tool.name}-${f.name}`), values[f.of], f.default);
|
|
1530
|
+
}
|
|
1531
|
+
for (const box of $("toolform-" + tab).querySelectorAll(".fgroup")) { // no box left empty
|
|
1532
|
+
box.hidden = [...box.querySelectorAll(".field")].every((w) => w.hidden);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function materialsEditor(el, key, given) { // given: the material of the phases that are not voids
|
|
1536
|
+
const it = item(key);
|
|
1537
|
+
if (!it) { el.innerHTML = "<p class=\"muted\">Choose the item first.</p>"; el.dataset.key = ""; return; }
|
|
1538
|
+
if (el.dataset.key === key) return;
|
|
1539
|
+
el.dataset.key = key;
|
|
1540
|
+
const phases = it.phases || {"0": "0", "1": "1"};
|
|
1541
|
+
const young = (i) => (given && given.young !== undefined ? given.young : (i === 0 ? 1 : 10));
|
|
1542
|
+
const poisson = given && given.poisson !== undefined ? given.poisson : 0.3;
|
|
1543
|
+
el.innerHTML = Object.entries(phases).map(([k, name], i) => `
|
|
1544
|
+
<div class="row mat" data-phase="${esc(k)}">
|
|
1545
|
+
<div><label>${esc(k)}: ${esc(name)} <small>E</small></label><input data-e value="${young(i)}"></div>
|
|
1546
|
+
<div><label><small>Poisson ν</small></label><input data-nu value="${poisson}"></div>
|
|
1547
|
+
<div><label> </label><label><input type="checkbox" data-void ${name === "void" ? "checked" : ""}>void</label></div>
|
|
1548
|
+
</div>`).join("");
|
|
1549
|
+
}
|
|
1550
|
+
function fillToolItems(tab) { // the items each field takes: their kinds, with the traits it needs
|
|
1551
|
+
for (const sel of $("toolform-" + tab).querySelectorAll("select[data-items]")) {
|
|
1552
|
+
const f = {kind: "item", items: sel.dataset.items.split(","), needs: sel.dataset.needs.split(",").filter(Boolean)};
|
|
1553
|
+
options(sel, WS.filter((i) => takes(f, i)), sel.dataset.none ? [["", sel.dataset.none]] : []);
|
|
1554
|
+
}
|
|
1555
|
+
for (const box of $("toolform-" + tab).querySelectorAll("div[data-multi]")) { // several items
|
|
1556
|
+
const f = {kind: "items", items: box.dataset.items.split(","), needs: box.dataset.needs.split(",").filter(Boolean)};
|
|
1557
|
+
const checked = new Set([...box.querySelectorAll("input:checked")].map((c) => c.value));
|
|
1558
|
+
const its = WS.filter((i) => takes(f, i));
|
|
1559
|
+
box.innerHTML = its.length ? its.map((i) => `<label><input type="checkbox" value="${i.key}"${checked.has(i.key) ? " checked" : ""}>${KIND[i.kind]} ${esc(i.title)}</label>`).join("") :
|
|
1560
|
+
'<span class="muted">none in the workspace yet</span>';
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
function takes(f, it) { // a field of a form takes the item: its kind, the traits it needs
|
|
1564
|
+
return (f.kind === "item" || f.kind === "items") && f.items.includes(it.kind) && (f.needs || []).every((n) => (it.traits || []).includes(n));
|
|
1565
|
+
}
|
|
1566
|
+
function refreshToolItems() {
|
|
1567
|
+
for (const t of CATALOG.tabs) if ($("toolform-" + t.name)) { fillToolItems(t.name); fillMany(t.name); toolVisibility(t.name); }
|
|
1568
|
+
}
|
|
1569
|
+
function toolTabsFor(it) { // the tool tabs that take the item
|
|
1570
|
+
return CATALOG.tabs.filter((t) => CATALOG.tools.some((x) => x.tab === t.name && itemField(x, it)));
|
|
1571
|
+
}
|
|
1572
|
+
const HELD = {}; // the item last sent to each tab of tools: the tools chosen there take it too
|
|
1573
|
+
function itemField(tool, it) { // the field an item sent goes to: one that needs an item first
|
|
1574
|
+
return tool.fields.find((f) => takes(f, it) && !f.none) || tool.fields.find((f) => takes(f, it));
|
|
1575
|
+
}
|
|
1576
|
+
function selectInTool(tab, key) { // the item in the tool shown, or in the first tool taking it
|
|
1577
|
+
const it = item(key);
|
|
1578
|
+
if (!it) return;
|
|
1579
|
+
HELD[tab] = key;
|
|
1580
|
+
// first a tool whose input it is, rather than an option (a behaviour for one phase)
|
|
1581
|
+
const tools = [currentTool(tab), ...CATALOG.tools.filter((x) => x.tab === tab)];
|
|
1582
|
+
const tool = tools.find((x) => x.fields.some((f) => takes(f, it) && !f.none)) ||
|
|
1583
|
+
tools.find((x) => itemField(x, it));
|
|
1584
|
+
if (!tool || (LOCKED[tab] && tool !== currentTool(tab))) return;
|
|
1585
|
+
if ($("tools-" + tab).value !== tool.name) { $("tools-" + tab).value = tool.name; buildToolForm(tab); }
|
|
1586
|
+
putItem(tab, tool, key);
|
|
1587
|
+
}
|
|
1588
|
+
function keepItem(tab) { // another tool chosen in a tab: the item sent there, if it takes it
|
|
1589
|
+
const key = HELD[tab], it = item(key);
|
|
1590
|
+
if (it && itemField(currentTool(tab), it)) putItem(tab, currentTool(tab), key);
|
|
1591
|
+
}
|
|
1592
|
+
function putItem(tab, tool, key) {
|
|
1593
|
+
const f = itemField(tool, item(key));
|
|
1594
|
+
// the choices on which the field of the item depends (e.g. a specimen "morphology")
|
|
1595
|
+
for (const [name, values] of Object.entries(f.when || {})) {
|
|
1596
|
+
const control = document.getElementById(`tool-${tool.name}-${name}`);
|
|
1597
|
+
if (control && control.tagName === "SELECT" && !values.map(String).includes(control.value)) {
|
|
1598
|
+
control.value = String(values[0]);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
toolVisibility(tab);
|
|
1602
|
+
const sel = document.getElementById(`tool-${tool.name}-${f.name}`);
|
|
1603
|
+
if (f.kind === "items") { // checked among the others
|
|
1604
|
+
const box = [...sel.querySelectorAll("input")].find((c) => c.value === key);
|
|
1605
|
+
if (box) box.checked = true;
|
|
1606
|
+
} else if ([...sel.options].some((o) => o.value === key)) sel.value = key;
|
|
1607
|
+
toolVisibility(tab);
|
|
1608
|
+
}
|
|
1609
|
+
async function runTool(tab, note) { // its last status; note: shown above (one of several runs)
|
|
1610
|
+
const tool = currentTool(tab), out = $("toolout-" + tab);
|
|
1611
|
+
const head = note ? `<p><b>${esc(note)}</b></p>` : "";
|
|
1612
|
+
out.innerHTML = head + "<p class=\"muted\">Starting…</p>";
|
|
1613
|
+
try {
|
|
1614
|
+
const {job} = await api("/api/tool", {tool: tool.name, params: toolValues(tab)});
|
|
1615
|
+
for (;;) {
|
|
1616
|
+
const s = await api(`/api/job/${job}`);
|
|
1617
|
+
if (s.state === "running") {
|
|
1618
|
+
out.innerHTML = head + `<p class="muted">${esc(tool.title)}: ${esc(s.message || "running")}… ${s.elapsed_s} s${stopButton(job)}</p>
|
|
1619
|
+
<div class="progress"><div style="width:${Math.round(100 * (s.progress || 0))}%"></div></div>`;
|
|
1620
|
+
await wait(800);
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
if (s.state === "stopped") { out.innerHTML = head + stoppedNote(s); return s; }
|
|
1624
|
+
if (s.error) { out.innerHTML = head + `<p class="error">${esc(s.error)}</p>`; return s; }
|
|
1625
|
+
await refreshWorkspace(); // the run joined it, with the items it made
|
|
1626
|
+
out.innerHTML = head + toolResult(s.result);
|
|
1627
|
+
return s;
|
|
1628
|
+
}
|
|
1629
|
+
} catch (e) { out.innerHTML = head + `<p class="error">${esc(e.message)}</p>`; return null; }
|
|
1630
|
+
}
|
|
1631
|
+
function dataTable(t) {
|
|
1632
|
+
const more = t.count > t.rows.length ? `, ${t.count} rows` : "";
|
|
1633
|
+
const link = t.url ? ` <a class="muted" href="${t.url}">(.csv${more})</a>` : "";
|
|
1634
|
+
const cell = (v) => v === null || v === undefined ? "" : esc(typeof v === "number" ? +v.toPrecision(6) : v);
|
|
1635
|
+
return `<h3>${esc(t.title)}${link}</h3><div class="tablewrap"><table class="numbers"><tr>${t.columns.map((c) => `<th>${esc(c)}</th>`).join("")}</tr>${t.rows.map((r) => `<tr>${r.map((v) => `<td>${cell(v)}</td>`).join("")}</tr>`).join("")}</table></div>`;
|
|
1636
|
+
}
|
|
1637
|
+
function toolResult(r) {
|
|
1638
|
+
let html = (r.warnings || []).map((w) => `<p class="error">${esc(w)}</p>`).join("");
|
|
1639
|
+
html += `<h3>${esc(r.title)} <span class="muted">(${r.time_s} s)</span></h3>`;
|
|
1640
|
+
if (r.archive) html += `<p><a href="${r.archive}"><b>Download everything (.zip)</b></a></p>`;
|
|
1641
|
+
if (Object.keys(r.values || {}).length) html += table(r.values);
|
|
1642
|
+
for (const made of r.items || []) { // as the workspace has them now (their traits)
|
|
1643
|
+
const it = item(made.key) || made;
|
|
1644
|
+
html += `<p><b>${esc(it.title)}</b> joined the workspace.</p>` + sendButtons(it);
|
|
1645
|
+
}
|
|
1646
|
+
if (r.view3d && r.key && window.MorphoViewer) html += MorphoViewer.slot(r.key, {label: "View it in 3D"});
|
|
1647
|
+
if ((r.figures || []).length) html += `<h3>Figures</h3>${media(r.figures)}`;
|
|
1648
|
+
if ((r.videos || []).length) html += `<h3>Videos</h3>${media(r.videos)}`;
|
|
1649
|
+
for (const t of r.tables || []) html += dataTable(t);
|
|
1650
|
+
if (r.text) html += `<pre class="report">${esc(r.text)}</pre>`;
|
|
1651
|
+
html += `<h3>Files</h3>${fileList(r.files)}`;
|
|
1652
|
+
if (r.key) html += `<p><button class="plain browse" data-reveal="${esc(r.key)}" title="the folder of this result in the file manager">Show its folder</button></p>`;
|
|
1653
|
+
return html;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
// -- tile assemblies ---------------------------------------------------------------------------
|
|
1657
|
+
$("des-go").onclick = () => busy($("des-go"), async () => {
|
|
1658
|
+
const out = $("des-out");
|
|
1659
|
+
out.innerHTML = '<p class="muted">Counting…</p>';
|
|
1660
|
+
try {
|
|
1661
|
+
const r = await api("/api/count", {tiles: $("des-tiles").value, shape: numbers($("des-shape").value),
|
|
1662
|
+
periodic: $("des-periodic").checked, seed: 1});
|
|
1663
|
+
let html = `<h3>Compatible assemblies</h3>`;
|
|
1664
|
+
html += r.count !== undefined ? `<p><b>${esc(r.count)}</b> assemblies of ${r.n_tiles} tiles` +
|
|
1665
|
+
(r.log2_count !== null ? ` (2<sup>${r.log2_count.toFixed(2)}</sup>)` : "") + `</p>` :
|
|
1666
|
+
`<p class="error">${esc(r.count_error)}</p>`;
|
|
1667
|
+
html += r.assembly ? `<h3>One assembly (wave function collapse)</h3>${images(r.assembly)}` :
|
|
1668
|
+
`<p class="error">${esc(r.assembly_error)}</p>`;
|
|
1669
|
+
out.innerHTML = html;
|
|
1670
|
+
} catch (e) { out.innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1671
|
+
});
|
|
1672
|
+
|
|
1673
|
+
// -- Ashby charts ----------------------------------------------------------------------------
|
|
1674
|
+
const SLOTS = ["var(--series-1)", "var(--series-2)", "var(--series-3)"];
|
|
1675
|
+
let ASHBY = null;
|
|
1676
|
+
function dbRequest() {
|
|
1677
|
+
return {database: $("db-path").value.trim(), where: $("db-where").value};
|
|
1678
|
+
}
|
|
1679
|
+
function fmt(v) { return Number(Number(v).toPrecision(3)).toString(); }
|
|
1680
|
+
function markerPath(slot, x, y) {
|
|
1681
|
+
// circle, square, triangle: the shape doubles the colour of the three families
|
|
1682
|
+
if (slot === 1) return `<rect x="${x - 4.2}" y="${y - 4.2}" width="8.4" height="8.4" rx="1"/>`;
|
|
1683
|
+
if (slot === 2) return `<path d="M${x},${y - 5.6}L${x + 5.2},${y + 3.6}L${x - 5.2},${y + 3.6}Z"/>`;
|
|
1684
|
+
return `<circle cx="${x}" cy="${y}" r="4.6"/>`;
|
|
1685
|
+
}
|
|
1686
|
+
function swatch(g) {
|
|
1687
|
+
const fill = g.slot === null ? "var(--other)" : SLOTS[g.slot];
|
|
1688
|
+
return `<svg width="14" height="14" style="fill:${fill}">${markerPath(g.slot === null ? 0 : g.slot, 7, 7)}</svg>`;
|
|
1689
|
+
}
|
|
1690
|
+
function hull(points) {
|
|
1691
|
+
// monotone chain on [x, y] (transformed coordinates)
|
|
1692
|
+
const p = points.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
1693
|
+
if (p.length < 3) return null;
|
|
1694
|
+
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
1695
|
+
const lower = [], upper = [];
|
|
1696
|
+
for (const q of p) { while (lower.length > 1 && cross(lower[lower.length - 2], lower[lower.length - 1], q) <= 0) lower.pop(); lower.push(q); }
|
|
1697
|
+
for (const q of p.reverse()) { while (upper.length > 1 && cross(upper[upper.length - 2], upper[upper.length - 1], q) <= 0) upper.pop(); upper.push(q); }
|
|
1698
|
+
const h = lower.slice(0, -1).concat(upper.slice(0, -1));
|
|
1699
|
+
return h.length >= 3 ? h : null;
|
|
1700
|
+
}
|
|
1701
|
+
function ticks(lo, hi, log) {
|
|
1702
|
+
if (log) {
|
|
1703
|
+
const out = [], fine = hi - lo < 2;
|
|
1704
|
+
for (let e = Math.floor(lo); e <= Math.ceil(hi); e++)
|
|
1705
|
+
for (const m of fine ? [1, 2, 5] : [1]) {
|
|
1706
|
+
const t = e + Math.log10(m);
|
|
1707
|
+
if (t >= lo - 1e-9 && t <= hi + 1e-9) out.push(t);
|
|
1708
|
+
}
|
|
1709
|
+
return out;
|
|
1710
|
+
}
|
|
1711
|
+
const raw = (hi - lo) / 5, mag = Math.pow(10, Math.floor(Math.log10(raw)));
|
|
1712
|
+
const step = [1, 2, 5, 10].map((k) => k * mag).find((s) => s >= raw);
|
|
1713
|
+
const out = [];
|
|
1714
|
+
for (let t = Math.ceil(lo / step) * step; t <= hi + 1e-12; t += step) out.push(t);
|
|
1715
|
+
return out;
|
|
1716
|
+
}
|
|
1717
|
+
function drawAshby(d) {
|
|
1718
|
+
const out = $("db-out");
|
|
1719
|
+
const W = Math.max(360, Math.min(820, out.clientWidth - 34)), H = 440;
|
|
1720
|
+
const m = {l: 62, r: 18, t: 14, b: 46};
|
|
1721
|
+
const tf = d.log ? Math.log10 : (v) => v, inv = d.log ? (t) => Math.pow(10, t) : (t) => t;
|
|
1722
|
+
const all = d.groups.flatMap((g) => g.points);
|
|
1723
|
+
if (!all.length) { out.innerHTML = '<p class="error">No record has positive values of both keys.</p>'; return; }
|
|
1724
|
+
const ext = (vals) => {
|
|
1725
|
+
let lo = Math.min(...vals), hi = Math.max(...vals);
|
|
1726
|
+
if (hi - lo < 1e-12) { lo -= 0.5; hi += 0.5; }
|
|
1727
|
+
const pad = 0.06 * (hi - lo);
|
|
1728
|
+
return [lo - pad, hi + pad];
|
|
1729
|
+
};
|
|
1730
|
+
const [x0, x1] = ext(all.map((p) => tf(p.x))), [y0, y1] = ext(all.map((p) => tf(p.y)));
|
|
1731
|
+
const X = (t) => m.l + (t - x0) / (x1 - x0) * (W - m.l - m.r);
|
|
1732
|
+
const Y = (t) => H - m.b - (t - y0) / (y1 - y0) * (H - m.t - m.b);
|
|
1733
|
+
let svg = `<svg width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" role="img" aria-label="${esc(d.y_label)} against ${esc(d.x_label)}">`;
|
|
1734
|
+
for (const t of ticks(x0, x1, d.log)) {
|
|
1735
|
+
svg += `<line x1="${X(t)}" x2="${X(t)}" y1="${m.t}" y2="${H - m.b}" style="stroke:var(--c-grid)" stroke-width="1"/>`;
|
|
1736
|
+
svg += `<text x="${X(t)}" y="${H - m.b + 16}" text-anchor="middle" font-size="11" style="fill:var(--c-muted)">${fmt(inv(t))}</text>`;
|
|
1737
|
+
}
|
|
1738
|
+
for (const t of ticks(y0, y1, d.log)) {
|
|
1739
|
+
svg += `<line x1="${m.l}" x2="${W - m.r}" y1="${Y(t)}" y2="${Y(t)}" style="stroke:var(--c-grid)" stroke-width="1"/>`;
|
|
1740
|
+
svg += `<text x="${m.l - 6}" y="${Y(t) + 4}" text-anchor="end" font-size="11" style="fill:var(--c-muted)">${fmt(inv(t))}</text>`;
|
|
1741
|
+
}
|
|
1742
|
+
svg += `<line x1="${m.l}" x2="${W - m.r}" y1="${H - m.b}" y2="${H - m.b}" style="stroke:var(--c-axis)"/>`;
|
|
1743
|
+
svg += `<line x1="${m.l}" x2="${m.l}" y1="${m.t}" y2="${H - m.b}" style="stroke:var(--c-axis)"/>`;
|
|
1744
|
+
svg += `<text x="${(m.l + W - m.r) / 2}" y="${H - 8}" text-anchor="middle" font-size="12" style="fill:var(--c-secondary)">${esc(d.x_label)}</text>`;
|
|
1745
|
+
svg += `<text transform="translate(14 ${(m.t + H - m.b) / 2}) rotate(-90)" text-anchor="middle" font-size="12" style="fill:var(--c-secondary)">${esc(d.y_label)}</text>`;
|
|
1746
|
+
const boxes = [];
|
|
1747
|
+
const fits = (b) => b.x0 >= m.l && b.x1 <= W - m.r && b.y0 >= m.t && b.y1 <= H - m.b &&
|
|
1748
|
+
!boxes.some((o) => !(b.x1 < o.x0 || b.x0 > o.x1 || b.y1 < o.y0 || b.y0 > o.y1));
|
|
1749
|
+
const label = (text, x, y, options, style) => {
|
|
1750
|
+
const w = 6.3 * text.length, h = 12;
|
|
1751
|
+
for (const [dx, dy, anchor] of options) {
|
|
1752
|
+
const left = anchor === "end" ? x + dx - w : anchor === "middle" ? x + dx - w / 2 : x + dx;
|
|
1753
|
+
const b = {x0: left, x1: left + w, y0: y + dy - h + 2, y1: y + dy + 2};
|
|
1754
|
+
if (fits(b)) {
|
|
1755
|
+
boxes.push(b);
|
|
1756
|
+
return `<text x="${x + dx}" y="${y + dy}" text-anchor="${anchor}" font-size="11" style="${style}">${esc(text)}</text>`;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return "";
|
|
1760
|
+
};
|
|
1761
|
+
for (const n of d.guides || []) {
|
|
1762
|
+
const pts = [];
|
|
1763
|
+
for (let k = 0; k <= 64; k++) {
|
|
1764
|
+
const tx = x0 + (x1 - x0) * k / 64, ty = d.log ? n * tx : Math.pow(tx, n);
|
|
1765
|
+
if (ty >= y0 && ty <= y1) pts.push([X(tx), Y(ty)]);
|
|
1766
|
+
}
|
|
1767
|
+
if (pts.length < 2) continue;
|
|
1768
|
+
svg += `<polyline points="${pts.map((p) => p.join(",")).join(" ")}" style="fill:none;stroke:var(--c-muted)" stroke-width="1"/>`;
|
|
1769
|
+
svg += label(`n = ${n}`, pts[0][0], pts[0][1], [[4, -5, "start"], [4, 13, "start"]], "fill:var(--c-muted)");
|
|
1770
|
+
}
|
|
1771
|
+
const marks = [];
|
|
1772
|
+
for (const g of d.groups) {
|
|
1773
|
+
const fill = g.slot === null ? "var(--other)" : SLOTS[g.slot];
|
|
1774
|
+
if (g.slot !== null) {
|
|
1775
|
+
const h = hull(g.points.map((p) => [tf(p.x), tf(p.y)]));
|
|
1776
|
+
if (h) svg += `<polygon points="${h.map((q) => `${X(q[0])},${Y(q[1])}`).join(" ")}" style="fill:${fill};fill-opacity:.1"/>`;
|
|
1777
|
+
}
|
|
1778
|
+
svg += `<g style="fill:${fill};stroke:var(--surface);stroke-width:2">`;
|
|
1779
|
+
for (const p of g.points) {
|
|
1780
|
+
const px = X(tf(p.x)), py = Y(tf(p.y));
|
|
1781
|
+
svg += markerPath(g.slot === null ? 0 : g.slot, px, py);
|
|
1782
|
+
marks.push({px, py, p, g});
|
|
1783
|
+
}
|
|
1784
|
+
svg += "</g>";
|
|
1785
|
+
}
|
|
1786
|
+
if (d.groups.length > 1) {
|
|
1787
|
+
for (const g of d.groups) {
|
|
1788
|
+
if (g.slot === null) continue;
|
|
1789
|
+
const first = g.points.reduce((a, b) => (b.x < a.x ? b : a));
|
|
1790
|
+
svg += label(g.name, X(tf(first.x)), Y(tf(first.y)),
|
|
1791
|
+
[[-9, 4, "end"], [0, 18, "middle"], [0, -9, "middle"], [9, 4, "start"]], "fill:var(--c-secondary)");
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
svg += `<circle id="ashby-focus" r="8" style="fill:none;stroke:var(--c-ink);stroke-width:1.5;display:none"/></svg>`;
|
|
1795
|
+
const legend = d.groups.length > 1 ? `<div class="legend">${d.groups.map((g) =>
|
|
1796
|
+
`<span>${swatch(g)}${esc(g.slot === null ? (g.members.length === 1 ? `Other: ${g.members[0]}` :
|
|
1797
|
+
`Other (${g.members.length} families)`) : g.name || "—")} <small>(${g.points.length})</small></span>`).join("")}</div>` : "";
|
|
1798
|
+
const shown = all.length;
|
|
1799
|
+
out.innerHTML = `<h3>${esc(d.y_label)} <span class="muted">— ${shown} of ${d.matched} records${d.by ? ", families: " + esc(d.by) : ""}</span></h3>
|
|
1800
|
+
${legend}<div class="viz">${svg}<div class="tip"></div></div>
|
|
1801
|
+
<button class="plain" id="ashby-table">Show the table</button><div id="ashby-rows"></div>`;
|
|
1802
|
+
const viz = out.querySelector(".viz"), tip = viz.querySelector(".tip"), focus = viz.querySelector("#ashby-focus");
|
|
1803
|
+
viz.querySelector("svg").addEventListener("mousemove", (e) => {
|
|
1804
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1805
|
+
const mx = e.clientX - r.left, my = e.clientY - r.top;
|
|
1806
|
+
let best = null, dist = 24;
|
|
1807
|
+
for (const k of marks) {
|
|
1808
|
+
const dd = Math.hypot(k.px - mx, k.py - my);
|
|
1809
|
+
if (dd < dist) { dist = dd; best = k; }
|
|
1810
|
+
}
|
|
1811
|
+
if (!best) { tip.style.display = "none"; focus.style.display = "none"; return; }
|
|
1812
|
+
focus.setAttribute("cx", best.px); focus.setAttribute("cy", best.py); focus.style.display = "";
|
|
1813
|
+
const fam = best.g.slot === null ? "Other" : best.g.name;
|
|
1814
|
+
const run = best.p.run && best.p.run !== fam ? " · " + esc(best.p.run) : "";
|
|
1815
|
+
const real = best.p.realization !== null && best.p.realization !== undefined ? " #" + best.p.realization : "";
|
|
1816
|
+
tip.innerHTML = `<b>${esc(fam)}</b>${run}${real}<br>
|
|
1817
|
+
${esc(d.x)}: ${fmt(best.p.x)}<br>${esc(d.y)}: ${fmt(best.p.y)}`;
|
|
1818
|
+
tip.style.display = "block";
|
|
1819
|
+
tip.style.left = `${Math.min(best.px + 14, W - tip.offsetWidth - 4)}px`;
|
|
1820
|
+
tip.style.top = `${Math.max(best.py - tip.offsetHeight - 10, 0)}px`;
|
|
1821
|
+
});
|
|
1822
|
+
viz.querySelector("svg").addEventListener("mouseleave", () => { tip.style.display = "none"; focus.style.display = "none"; });
|
|
1823
|
+
$("ashby-table").onclick = () => {
|
|
1824
|
+
const rows = marks.map((k) => `<tr><td>${esc(k.g.slot === null ? "Other: " + k.g.name : k.g.name)}</td><td>${esc(k.p.run || "")}</td>
|
|
1825
|
+
<td>${k.p.realization ?? ""}</td><td>${fmt(k.p.x)}</td><td>${fmt(k.p.y)}</td></tr>`).join("");
|
|
1826
|
+
$("ashby-rows").innerHTML = $("ashby-rows").innerHTML ? "" : `<table class="numbers"><tr><th>family</th><th>run</th><th>#</th>
|
|
1827
|
+
<th>${esc(d.x)}</th><th>${esc(d.y)}</th></tr>${rows}</table>`;
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
function fillKeys(info) {
|
|
1831
|
+
const numeric = info.numeric, text = info.text;
|
|
1832
|
+
const pick = (sel, keys, preferred) => {
|
|
1833
|
+
const keep = sel.value;
|
|
1834
|
+
sel.innerHTML = keys.map((k) => `<option>${esc(k)}</option>`).join("");
|
|
1835
|
+
const want = [keep, ...preferred].find((k) => k && keys.includes(k));
|
|
1836
|
+
if (want) sel.value = want;
|
|
1837
|
+
};
|
|
1838
|
+
const relative = numeric.filter((k) => k.endsWith(".relative"));
|
|
1839
|
+
pick($("db-x"), numeric, ["solid_fraction"]);
|
|
1840
|
+
pick($("db-y"), numeric, [relative.find((k) => k.includes(".E1.")), relative[0]]);
|
|
1841
|
+
pick($("db-by"), ["(none)", ...text], ["model.type", "run_name"]);
|
|
1842
|
+
}
|
|
1843
|
+
async function loadDatabase() {
|
|
1844
|
+
const info = await api("/api/database", dbRequest());
|
|
1845
|
+
fillKeys(info);
|
|
1846
|
+
return info;
|
|
1847
|
+
}
|
|
1848
|
+
$("db-load").onclick = () => busy($("db-load"), async () => {
|
|
1849
|
+
try {
|
|
1850
|
+
const info = await loadDatabase();
|
|
1851
|
+
$("db-out").innerHTML = `<p class="muted">${info.runs.length} runs, ${info.records} records. Choose the axes and draw.</p>`;
|
|
1852
|
+
} catch (e) { $("db-out").innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1853
|
+
});
|
|
1854
|
+
$("db-add").onclick = () => busy($("db-add"), async () => {
|
|
1855
|
+
try {
|
|
1856
|
+
const r = await api("/api/database/add", {database: $("db-path").value.trim(), directory: $("db-run").value.trim()});
|
|
1857
|
+
const info = await loadDatabase();
|
|
1858
|
+
$("db-out").innerHTML = `<p class="muted">${r.added} records added; ${info.runs.length} runs in the database.</p>`;
|
|
1859
|
+
} catch (e) { $("db-out").innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1860
|
+
});
|
|
1861
|
+
$("db-session").onclick = () => busy($("db-session"), async () => {
|
|
1862
|
+
try {
|
|
1863
|
+
const r = await api("/api/database/session", {database: $("db-path").value.trim()});
|
|
1864
|
+
const info = await loadDatabase();
|
|
1865
|
+
$("db-out").innerHTML = `<p class="muted">${r.added} records of ${r.runs} simulations added; ${info.runs.length} runs in the database.</p>`;
|
|
1866
|
+
} catch (e) { $("db-out").innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1867
|
+
});
|
|
1868
|
+
$("db-go").onclick = () => busy($("db-go"), async () => {
|
|
1869
|
+
try {
|
|
1870
|
+
if (!$("db-x").value) await loadDatabase();
|
|
1871
|
+
const guides = $("db-guides").value.trim();
|
|
1872
|
+
ASHBY = await api("/api/ashby", {
|
|
1873
|
+
...dbRequest(), x: $("db-x").value, y: $("db-y").value,
|
|
1874
|
+
by: $("db-by").value === "(none)" ? "" : $("db-by").value, log: $("db-log").checked,
|
|
1875
|
+
guides: guides ? numbers(guides) : null,
|
|
1876
|
+
});
|
|
1877
|
+
drawAshby(ASHBY);
|
|
1878
|
+
} catch (e) { $("db-out").innerHTML = `<p class="error">${esc(e.message)}</p>`; }
|
|
1879
|
+
});
|
|
1880
|
+
window.addEventListener("resize", () => { if (ASHBY && $("tab-ashby").classList.contains("active")) drawAshby(ASHBY); });
|
|
1881
|
+
|
|
1882
|
+
// -- start -----------------------------------------------------------------------------------
|
|
1883
|
+
(async () => {
|
|
1884
|
+
try {
|
|
1885
|
+
const info = await api("/api/info");
|
|
1886
|
+
$("version").textContent = info.version;
|
|
1887
|
+
$("sim-gpu-row").hidden = !info.gpu;
|
|
1888
|
+
const address = location.hash.slice(1); // the tab, tool or model asked for
|
|
1889
|
+
MODELS = await api("/api/models");
|
|
1890
|
+
modelMenu(MODELS);
|
|
1891
|
+
fillSelect($("gen-model"), MODELS, (m) => {
|
|
1892
|
+
$("gen-title").innerHTML = `${esc(m.name)}<small>${esc(m.family || "")}</small>`;
|
|
1893
|
+
for (const b of $("gen-list").querySelectorAll("button")) b.classList.toggle("active", b.dataset.model === m.name);
|
|
1894
|
+
setDoc($("gen-doc"), plainDoc(m.doc)); buildForm($("gen-params"), m);
|
|
1895
|
+
exampleDomain("gen-size", "gen-periodic", m);
|
|
1896
|
+
$("gen-formation").hidden = !m.evolution;
|
|
1897
|
+
if ($("tab-generate").classList.contains("active")) setAddress("generate");
|
|
1898
|
+
});
|
|
1899
|
+
buildToolTabs(await api("/api/tools"));
|
|
1900
|
+
INDEX = searchIndex(CATALOG, MODELS, fixedTexts());
|
|
1901
|
+
if (address) go(address);
|
|
1902
|
+
else showTab("generate");
|
|
1903
|
+
window.addEventListener("hashchange", () => go(location.hash.slice(1))); // a link #tab/tool
|
|
1904
|
+
await refreshWorkspace();
|
|
1905
|
+
} catch (e) { document.body.insertAdjacentHTML("beforeend", `<p class="error">${esc(e.message)}</p>`); }
|
|
1906
|
+
})();
|
|
1907
|
+
</script>
|
|
1908
|
+
</body>
|
|
1909
|
+
</html>
|