Skip to content

Feature/gru twophase5eq - #17

Open
ptrembli wants to merge 5 commits into
mainfrom
feature/gru-twophase5eq
Open

ptrembli wants to merge 5 commits into
mainfrom
feature/gru-twophase5eq

Conversation

@ptrembli

@ptrembli ptrembli commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Closes #6.

All-regime GRU scheme (Glimm Random Upwind, "ghost GRU", https://hal.science/hal-05315640), ported from the branch implem-gru of canoP 2.x, for the model twophase5eq: simulation.gru_enabled = 1. The gas volume fraction ag stays exactly 0 or 1.

Scheme (src/scheme/GRU.h, independent of the model)

  • First order: space_order and time_order are set to 1.
  • Upwind transport written as a positive combination of the cell and of its incoming donors. At the interface, the cell takes the state of one donor, drawn with one global sample per time step (Weyl sequences, the same on every MPI rank).
  • Transport and pressure work are conservative across AMR levels. After an AMR cycle, a coarsened cell crossed by the interface takes the state of one of its children, drawn coherently (gru_coarsen), so that straight interfaces stay straight.
  • Well-balanced gravity with walls and AMR: the ghost cells and the states moved by the AMR get the hydrostatic pressure of their position; physics.source must be none.
  • Options gru_enabled, gru_coarsen, gru_omega0, gru_omega0_amr in [simulation]. The kernels of GRU are compiled only when it is enabled.

The parts that depend on the model (interface states, end of the update, hydrostatic shifts) are pykokkos kernels. The donor update, the AMR remap and the draw need the connectivity of the mesh and the time loop, which are in C++, as the flux update of the standard scheme.

Model (physics/twophase5eq/gru.py)

  • Colour: 1 when ag >= 0.5.
  • Interface solver: all-regime acoustic solver with the impedance a = K max(mL cL, mR cR) (param.K), optional low Mach correction, hydrostatic term m* g h.
  • End of the update: sharp colour of the drawn cells, upwind transport of the colour clipped to [0, 1] elsewhere, pressure work and gravity.

Validation

  • From the same initial state (multi-mode Rayleigh-Taylor, gravity, walls), one time step gives the time derivatives of implem-gru to 1.8e-12.
  • Regression cases twophase5eq_gru_square (2D), twophase5eq_gru_square_amr (2D, AMR) and twophase5eq_gru_square_amr_3d (3D, AMR), references by canoP 2dd78eb6. They are the same with 2 and 4 threads, and with 1 and 4 MPI processes.
  • Physics check gru: the square of gas transported with AMR keeps ag exactly 0 or 1, P and V uniform to 1e-13, the area of the gas exactly, and its centroid within one cell of the exact translation.
  • Rebased on main 530f358: the 57 regression cases and the 4 physics checks (outflow, mirror, energy, gru) pass.

Differences from implem-gru

  • The colour follows c + sum_k a_k (c_k - c): a uniform colour stays exactly 0 or 1 (it drifts by a few 1e-15 in implem-gru).
  • The coherent draw in the coarse ghost cells facing finer blocks is not ported: the transport does not read them.
  • The cells outside the domain hold the mirror states without hydrostatic shift: dt differs by about 6e-5 in relative value.
  • The low Mach correction keeps the default of the model (off); implem-gru turned it on by default.

Not covered by the tests

  • The draw on coarsening (gru_coarsen): with ag_gradient, a block crossed by the interface is never coarsened.

🤖 Generated with Claude Code

ptrembli and others added 4 commits December 1, 2026 21:41
…bled)

Port of the all-regime GRU scheme (Glimm Random Upwind, "ghost GRU",
https://hal.science/hal-05315640) of the branch implem-gru (solver
godunov_five_eq of canoP 2.x: GRUUtils.h, GRUFunctors.h, GodunovImplemGRU,
the GRU parts of ConvertToPrimitivesVariablesFunctor, FillOutside and
SolverGodunovFiveEq) to the generic solver, for the models that give a
physics/<model>/gru.py. The scheme keeps the colour of a material interface
strictly 0 or 1. It is first order: space_order and time_order are set to 1.

A time step (Simulation::gru_time_step):
- ghost cells; with gravity, those copied from a coarser neighbor get the
  hydrostatic pressure of their own centre before the MPI exchange
  (gru_ghosts_kernel);
- interface states of every face (gru_faces_kernel, gru_star of the model):
  u*, p*, p* u*, g rho*, g rho* u*; at a reflective or no-slip wall, the
  mirror state with the hydrostatic pressure of its centre;
- upwind transport of every owned cell (gru::UpdateFunctor), a positive
  combination of the cell and of its incoming donors; at a face shared with
  finer blocks the donors are the fine cells adjacent to the face, each with
  the u* of its own face. When an incoming donor has the other colour, the
  cell takes the state of one donor (or keeps its own), drawn with one global
  sample per time step;
- end of the update (gru_finish_kernel, gru_finish of the model): sharp
  colour of the drawn cells, non-conservative upwind transport of the colour
  in the others, pressure work and gravity, averaged over the fine faces at
  coarse/fine faces.

After the remap of an AMR cycle (gru::RemapFunctor): a refined cell copies
its parent; with gru_coarsen a coarsened cell whose children have both
colours takes the state of one child, drawn coherently (gru::coherent_pick)
with one sample per cycle; with gravity the moved states get the hydrostatic
pressure of their new position (gru_shift_kernel). The samples are Weyl
sequences (golden ratio, sqrt(2) - 1), the same on every MPI rank.

Options ([simulation], the keys of settings_twophase5eq_gru_square.ini, which
were not read): gru_enabled, gru_coarsen (default: gru_enabled), gru_omega0,
gru_omega0_amr. physics.source must be none with GRU (the gravity is in the
scheme). The kernels of GRU are compiled only when it is enabled. The two
square_transport regression cases, which run this settings file, keep the
all-regime flux: NO_GRU.

Differences from implem-gru:
- the colour follows c + sum_k a_k (c_k - c) instead of the conservative
  transport plus c dt div(u*): a uniform colour stays exactly 0 or 1 (in
  implem-gru it drifts from 1 by a few 1e-15, accumulating);
- the coherent draw in the coarse ghost cells facing finer blocks is not
  ported: the transport does not read them;
- the cells outside the domain (time step only) hold the mirror states
  without hydrostatic shift: dt differs by about 6e-5 in relative value.

From the same initial state (multi-mode Rayleigh-Taylor, gravity, walls),
one time step gives the time derivatives of implem-gru to 1.8e-12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What the model gives to the GRU scheme (simulation.gru_enabled = 1):

- COLOUR = "ag": the colour of a cell is 1 (gas) when ag >= 0.5;
- gru_star: the all-regime acoustic solver of implem-gru (compute_star_state),
  along the normal of the face, with one impedance a = K max(mL cL, mR cR):
    u* = (uL + uR)/2 - (PR - PL - m* g h)/(2a),  m* = (mL + mR)/2
    P* = (PL + PR)/2 - theta a (uR - uL)/2,
  theta = min(|u*| / max(cL, cR), 1) with param.lowmach_correction_enabled;
  with the source dt g m* of the momentum at the faces, the discrete
  hydrostatic equilibrium PR - PL = m* g h at rest is exactly preserved;
- gru_gravity: param.gravity_x, _y, _z;
- gru_hydrostatic: P += m g.dx for a state moved by dx;
- gru_finish: a drawn state gets ag = 0 or 1 and the partial densities of
  the same density (enforce_binary_color of implem-gru); otherwise ag + the
  upwind transport of the colour, clipped to [0, 1], non-negative partial
  densities; then the pressure work and the gravity.

param.K (default 1.1), read but not used until now, is the factor of the
impedance (impedance_factor of implem-gru). The low Mach correction keeps the
default of the model (0): implem-gru turned it on by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- user guide: the GRU scheme in the models (equations of the interface
  solver, draw at the interface, AMR, well-balanced gravity, CFL condition,
  restart), gru_enabled in the section [simulation];
- physics guide: gru.py of a model and its functions, kernels of GRU
  assembled only when it is enabled;
- architecture: the time step of GRU (scheme/GRU.h);
- CHANGELOG: the GRU scheme and its options; the settings file
  settings_twophase5eq_gru_square.ini, whose gru_enabled = 1 was ignored,
  now runs with GRU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- regression cases twophase5eq_gru_square (2D, uniform mesh),
  twophase5eq_gru_square_amr (2D, AMR) and twophase5eq_gru_square_amr_3d (a
  cube, AMR), references produced by canoP 61f2e57; they are the same with
  2 and 4 threads, and with 1 and 4 MPI processes;
- physics check gru (ctest -L physics): the square of gas in liquid at a
  uniform velocity and pressure, with AMR, keeps ag exactly 0 or 1, P and V
  uniform to 1e-13, the area of the gas exactly, and its centroid within
  one cell of the exact translation (the interface moves by whole cells).

The kernels of GRU are compiled by these cases: 53 kernels in the CI cache.
The draw on coarsening (gru_coarsen) is not exercised: with ag_gradient, a
block crossed by the interface is never coarsened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptrembli
ptrembli requested a review from skokh December 3, 2026 21:26
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.

Implement GRU on twophase5eq model

2 participants