Skip to content

Octree-informed structured mesh; meshing and simulation for octree models - #28

Open
javoha wants to merge 16 commits into
mainfrom
jvh_dev_octree_mesh
Open

javoha wants to merge 16 commits into
mainfrom
jvh_dev_octree_mesh

Conversation

@javoha

@javoha javoha commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

Meshing and simulation for structural models computed on an Octree Grid. Until now every mesher refused octree models. With this PR:

  • a new component, Create Octree-Informed Structured Mesh, builds a hexahedral mesh whose cell sizes follow the octree;
  • Create Unstructured Explicit Mesh accepts octree models;
  • SfePy and GOLEM run on the new mesh;
  • the implicit and the structured explicit mesh stay blocked for octree models, now with a message that points to the two meshers that work.

Related: #5 (the geometric fault zone here is groundwork for damage zones; it will change once damage zones become part of the structural model).

Meshing changes (please review: @baes2021)

1. New component: Create Octree-Informed Structured Mesh (core/meshing_components/implicit/octree_informed.py, identifier wbgeo::meshing_create_octree_informed_structured_mesh, Meshing group, position 960)

  • Rectilinear hexahedral mesh: n_cells_x * n_cells_y * n_cells_z cells on three coordinate lists, like a regular grid but with its own non-uniform spacing per axis.
  • Spacing per axis from the octree: the share of max-level octree cells in each slab of finest cells gives an "interface density"; node positions equidistribute alpha * density + (1 - alpha) * uniform, so cells are fine
    where the octree is refined (contacts, erosion boundaries, faults) and coarse elsewhere.
  • Cell sizes are at least one finest octree cell, and neighbouring cells differ by at most max_growth.
  • Each cell takes the lithology of the octree cell at its centre (look-up in the stored result, no interpolation).
  • Parameters: n_cells_x/y/z (0 = half the finest resolution), alpha (0.7; 0 gives a uniform grid), max_growth (1.3).
  • Output: MeshResults with hexahedra grouped by lithology (cell_data["block_id"]), boundary point sets (reuses build_point_sets / classify_boundary_nodes from the unstructured mesher), new MeshType.OCTREE_INFORMED
    (also added to the Workbench dropdown string).
  • Pre-check pre_check_octree_grid (new, in pre_checks.py): only accepts models on an Octree Grid that have been computed.
  • Exodus export maps OCTREE_INFORMED to the hexahedral path of the implicit mesh (Exo_format.py, one line).

2. Unstructured mesher accepts octree models (explicit/unstructured/structural_surfaces.py, mesh_data.py)

  • The surfaces already come from the extended_masked meshes, which exist on both grids. Only two places read the regular grid layout:
    • build_grid_litho: on an Octree Grid the lithology is sampled exactly at the centres of the finest cells (to_regular), so the table looks like the one of a Regular Grid at the finest resolution.
    • The minimum surface-piece area and the B-spline step use the finest octree cell size (new helper _cell_spacing).
  • pre_check_regular_grid removed from create_unstructured_mesh_data only.
  • Check on model 2 (one fault, two groups, 40 x 16 x 16 finest cells): octree and equivalent regular grid give the same 5 volumes, tetrahedra counts within 1 %, the same element quality (median 0.80) and the same lithology
    assignment.

3. Implicit and structured explicit mesh stay blocked

pre_check_regular_grid stays on both; only its docstring and message changed. Why we did not port them:

  • Implicit mesh: it creates one hexahedron per voxel of the lithology block. On an octree that would be one hexahedron per octree cell, which gives hanging nodes at every level change, i.e. not a conforming mesh. A uniform
    hexahedral mesh of an octree model is already available: the octree-informed mesh with alpha = 0.
  • Structured explicit mesh: it builds its xy grid from marching-cubes vertices that lie on the regular grid lines. Dual-contouring surfaces on an octree have no such vertices, so this would be a rewrite of the mesher, not
    a port (and it only supports unfaulted models).

In the Workbench the block works as intended: dragging a connection from a computed octree structural model to either of the two meshers turns it red, and the pre-check message tells the user to use "Create Octree-Informed
Structured Mesh" or "Create Unstructured Explicit Mesh". The check also runs at the start of execution, so it cannot be bypassed.

Simulation changes

  • SfePy: OCTREE_INFORMED runs through the hexahedral path of the implicit mesh (MESH_TYPE_CODES).
  • GOLEM: OCTREE_INFORMED added to GOLEM_SUPPORTED_MESH_TYPES; the error messages list the supported types from that set.
  • SfePy fault zone, geometric for both grids: compute_fault_zone_cell_mask now selects the cells whose centroid lies within fault_zone_n_voxels + 0.5 structural grid cells of the fault's unmasked surface (VTK exact
    distance, per axis in structural cells, finest cells on an octree), with the same fault_activity rule as before. This replaces the voxel version (fault_trace_on_grid), which only worked on a Regular Grid.

Evaluation: octree-informed vs uniform mesh

SfePy on three models (horizontal layers, layers dipping 30°, model 2 with fault), conduction and coupled flow, strong property contrasts between units. Temperature error (RMS, K) against a uniform reference at the finest
octree resolution, at equal cell count:

Model, physics 1/4 of finest resolution: uniform / informed 1/2: uniform / informed
Horizontal layers, conduction 0.59 / 0.46 0.13 / 0.21
Horizontal layers, flow 0.52 / 0.46 0.24 / 0.24
Dipping layers, conduction 0.21 / 0.21 0.12 / 0.24
Dipping layers, flow 0.44 / 0.40 0.15 / 0.22
Model 2 with fault, conduction 0.60 / 0.55 0.43 / 0.26
Model 2 with fault, flow 0.83 / 0.83 0.60 / 0.27
  • The informed mesh pays off for models with irregularly distributed structures (the faulted model: about half the error at 1/2 resolution). For simple layered models it is about as good as a uniform mesh, sometimes worse.
  • The error follows how well the mesh places the lithology boundaries (share of volume with the wrong lithology), not the cell size near them. A possible improvement for later: force cell edges where the lithology changes
    along an axis (exact for horizontal layers; a tensor-product mesh cannot follow dipping boundaries).
  • alpha = 0.7 was the best of the tested values (0, 0.7, 1).
  • The refinement follows the geology only, not physical boundary layers.

Compatibility

  • SfePy fault zones on a Regular Grid get narrower for oblique faults. The old voxel version widened the zone along the voxel staircase (up to about 30 % for oblique faults, e.g. model 9); for faults parallel to a grid
    plane the zone is unchanged. Pinned test counts for model 2 (30 x 15 x 15) changed from 764/596 to 658/504 cells.
  • Saved pipelines are not affected: no existing identifier or type changed; MeshType gains a value.

Known issue (not caused by this PR)

With coupled flow, SfePy temperatures can exceed the boundary values on coarse meshes (e.g. 67 °C at a 60 °C boundary). This happens equally on the implicit mesh from a Regular Grid, so it is not specific to the octree mesh;
most likely the advection term without stabilization. GOLEM showed a ~1 K overshoot in the same situation. To be tracked in a separate issue.

Tests

  • New: tests/tests_meshing_components/implicit/test_octree_informed_mesh.py (pre-check, rectilinear grid with the octree's lithology, finer cells at interfaces within the size and growth limits, alpha = 0 uniform,
    parameter checks, Exodus export); unstructured octree test and updated refusal tests in test_pre_checks.py; SfePy run, builder and fault-zone tests on octree fixtures; GOLEM builder and Exodus export tests for
    OCTREE_INFORMED.
  • Full suite (branch with current main merged): 1322 passed, 1 skipped.
  • Real GOLEM run (Docker) on the octree-informed mesh: OK.
  • Workbench (local Docker with this branch): component registers and runs, unstructured mesher runs on an octree model, SfePy runs on the new mesh, implicit and structured connections turn red with the new message.

Examples and manuals

  • Model 1 and model 2 examples: new optional section 5 (commented out) runs the model on an Octree Grid: structural (and fault) model, octree-informed structured mesh, unstructured mesh, SfePy on the octree-informed mesh.
    Both sections were run uncommented. For model 2 without PETSc, linear_solver="direct" converges (about 15 minutes); "iterative" does not, because of the fault zone's permeability contrast (noted in the example).
  • Meshing manual: new step 4 for the octree-informed mesh (method, parameters, when it pays off, limits); unstructured mesh on octree models; the red connection for the implicit and structured mesh; Exodus type and
    mesh_type in the output.
  • Simulation manual: octree-informed mesh listed for SfePy and GOLEM; fault zone width in finest cells on an Octree Grid.
  • Structural modeling manual: meshing options for octree models and a pointer to the example sections.

javoha added 16 commits October 19, 2026 16:13
Create Octree-Informed Structured Mesh builds a rectilinear hexahedral
mesh for a structural model computed on an OctreeGrid: n_x * n_y * n_z
cells like a regular grid, but each axis spaced by equidistributing
alpha * (share of max-level octree cells per slab) + (1 - alpha) *
uniform, with cells at least one finest octree cell and neighbour
ratios up to max_growth. Each cell takes the lithology of the octree
cell at its center (look-up, no interpolation). octree_informed_edges
returns the coordinate lists (e.g. MOOSE CartesianMeshGenerator dx).

pre_check_octree_grid refuses models on a RegularGrid or not computed.
New MeshType.OCTREE_INFORMED; the Exodus exporter takes its hexahedral
path for it. The SfePy builder does not support it yet.

Co-Authored-By: Claude Opus 5.5
MESH_TYPE_CODES maps MeshType.OCTREE_INFORMED to "imp": hexahedra with
block ids take the implicit mesh's export and run path. Fault zones are
voxel-based (a trace in the shape of a regular lith_block), so
compute_fault_zone_cell_mask now refuses structural models on an
OctreeGrid with a clear message instead of failing inside.

Tests: octree fixtures (model 1, 16^3) and the octree-informed mesh;
builder accepts it, fault zones are refused, a real SfePy run on it.

Co-Authored-By: Claude Opus 5.5
compute_fault_zone_cell_mask now selects the mesh cells whose centroid
lies within fault_zone_n_voxels + 0.5 structural grid cells of a fault's
UNMASKED surface mesh (VTK point-to-surface distance, per axis in cells
of the structural grid; finest cells on an OctreeGrid), keeping the
fault_activity rule via each cell's block id. It works for structural
models on both grids and every mesh type, replacing the voxel trace
(fault_trace_on_grid, binary dilation, nearest-voxel look-up), which
only worked on a RegularGrid.

For a fault parallel to a grid plane the zone is the voxel version's;
oblique faults are no longer widened by the voxel staircase (model 2's
pinned counts 764 / 596 become 658 / 504). Octree models no longer
refuse fault zones.

Co-Authored-By: Claude Opus 5.5
octree_informed.py was the only module with a @wbgeo_component that used 'from __future__ import annotations'. That turns every annotation into a string, which the DSL rejects (test_component_signatures failed for all six parameters and the return type), so the component would not have registered in the Workbench.

Co-Authored-By: Claude Opus 5.5
Brings in main with MR !46 (GOLEM). Conflicts from the SfePy renames
(SfepyHydrothermalProblemBuilder, SfepyCustomBuilder, sfepy_model_builder):
kept the geometric fault zone docstrings and counts (658/504) with the new
names, kept both sides of the octree and export/petsc tests; the octree
SfePy tests use linear_solver="iterative" (default is now petsc).

Co-Authored-By: Claude Opus 5.5
Conflicts resolved by keeping both sides: the octree_informed mesh type
together with the palette colour of MeshTypeType, and the octree imports
together with the palette import in the SfePy builder.

Co-Authored-By: Claude Opus 5.5
main now requires palette constants and a positionInGroup for every
component (tests/test_workbench_palette.py): MESH colour like the other
meshers, position 960 right below Create Structured Implicit Mesh.

Co-Authored-By: Claude Opus 5.5
The octree-informed mesh is exported like the implicit mesh (hexahedra,
one block per lithology, no boundary blocks), which the GOLEM builders
already handle; it only had to be added to GOLEM_SUPPORTED_MESH_TYPES.
The error messages now list the accepted types from that set.

Tests (model 1 on an octree): the generated hydrothermal problem accepts
the mesh and passes validate_golem_input, all blocks are material blocks,
the temperature gradient is anchored to the mesh nodes, the custom builder
accepts it, and the Exodus export has one hexahedral block per mesh block.

Checked with a real GOLEM run in Docker (model 1, octree max level 4,
4,096 hexahedra, 3 steps, 67 s): pressure and temperature within the
boundary values except a ~1 K temperature overshoot in the thermal
boundary layer below the top, where the octree-informed cells are
coarsest (110-144 m); the implicit mesh (62.5 m) has none.

Co-Authored-By: Claude Opus 5.5
The unstructured mesher takes its surfaces from the extended masked meshes,
which exist on both grids. Only the lithology lookup and the cell size read
the regular grid layout:

- build_grid_litho samples the octree lithology exactly at the finest cell
  centres (to_regular), so the table matches a RegularGrid at the finest
  resolution
- the piece-area threshold and the B-spline step use the finest octree cell
  size

pre_check_regular_grid stays on the implicit and the structured explicit
mesh; its message now points to the two meshers that accept octree models.

Check on model 2 (1 fault, 2 groups, 40x16x16 finest cells): octree and
equivalent regular grid give the same 5 volumes, tetra counts within 3 %,
the same element quality and lithology purity.

Co-Authored-By: Claude Opus 5.5
- Model 1 and model 2 examples: new optional section 5 (commented out)
  runs the model on an Octree Grid: structural (and fault) model,
  octree-informed structured mesh, unstructured mesh, SfePy run on the
  octree-informed mesh. Both sections were run uncommented (model 2's
  SfePy run with linear_solver="direct"; "iterative" does not converge
  with the fault zone's permeability contrast, noted in the example).
- Meshing manual: new step 4 for Create Octree-Informed Structured Mesh
  (method, parameters, when it pays off, limits); unstructured mesh on
  octree models; red connection for the implicit and structured mesh;
  Exodus type and mesh_type in the output.
- Simulation manual: octree-informed mesh for SfePy and GOLEM; fault
  zone width in finest cells on an Octree Grid.
- Structural modeling manual: meshing options for octree models, pointer
  to the example sections.

Co-Authored-By: Claude Opus 5.5
@javoha
javoha requested review from a team as code owners December 2, 2026 10:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant