Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ The user-visible changes of canoP, by version (see `CONTRIBUTING.md` for the ver

## Unreleased

- Model `particleflow`: a disperse phase of particles (spray) by a quadrature method of moments with
two velocity nodes, dragged by a carrier flow, ported from canoP legacy; kinetic flux, exact drag
and gravity after each time step, examples `settings/settings_particleflow_*.ini`.
- The relaxations of the physics (`physics.relaxation`) receive the time step:
`relaxation(w, qn, p, dt, dim)`.
- canoP studio in English or in French: a FR/EN switch in the top bar, saved in the settings. New
installations start in English; studios set up before keep French.
- Tutorial of canoP studio in the documentation: the build, a run of the blast example, and a
Expand Down
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ and compiled for the CPU or the GPU at run time.
- **twophase5eq**: five-equation model of two phases in mechanical equilibrium
([Padioleau 2021](https://theses.hal.science/tel-03130146));
- **twophase7eq**: seven-equation Baer-Nunziato model with pressure and velocity relaxations
([Chen 2019](https://www.theses.fr/2019AIXM0380)).
([Chen 2019](https://www.theses.fr/2019AIXM0380));
- **particleflow**: disperse phase of particles (spray) by a quadrature method of moments in
velocity with two nodes, dragged by a carrier flow.

HLL, HLLC and all-regime fluxes with non-conservative products, MUSCL reconstruction with scalar
limiters, forward Euler or SSP Runge-Kutta 2, viscous and thermal fluxes, gravity, block-based AMR
Expand Down
11 changes: 6 additions & 5 deletions docs/developer-guide/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Configure with `-DCANOP_ENABLE_TESTING=ON`, then:
cd _build
ctest -L unit # variables, limiters, settings (googletest)
ctest -L regression # short runs compared with reference outputs
ctest -L physics # physical properties: symmetry, conservation
ctest -L physics # physical properties: symmetry, conservation, exact drag
```

The regression and physics tests need `python3` with numpy and h5py.
Expand All @@ -21,9 +21,10 @@ The regression and physics tests need `python3` with numpy and h5py.

`test/regression` runs short cases and compares them cell by cell with stored reference outputs
(`test/regression/references/`). The cases cover every flux, limiter, space and time order, boundary
condition, source term and diffusion flux of each model, two-phase states, uniform and adaptive
meshes, in 2D and 3D. `test/regression/cases.py` lists them; `test/regression/README.md` explains how
to add a case and produce its reference.
condition, source term and diffusion flux of each model, the initial conditions and relaxations of
the model particleflow, two-phase states, uniform and adaptive meshes, in 2D and 3D.
`test/regression/cases.py` lists them; `test/regression/README.md` explains how to add a case and
produce its reference.

## Continuous integration

Expand All @@ -32,7 +33,7 @@ for a push that changes the documentation alone); its check, `Build and tests (O
to merge into `main` (see `CONTRIBUTING.md`). It is a build of canoP for CPUs (OpenMP) on Ubuntu
24.04 with gcc, OpenMPI and HDF5, then all the tests (unit, regression, physics), a skipped test
counting as a failure. ccache keeps the compilations from one run to the next, and the kernels of
the physics compiled by pykokkos are kept too (49 kernels, about 4 minutes to compile): a run takes a
the physics compiled by pykokkos are kept too (57 kernels, about 5 minutes to compile): a run takes a
few minutes, about 15 without these caches. A failed test is reported as an annotation of the run,
and the logs and input files of its runs of canoP are kept for 7 days as an artifact of the run
(`logs`).
Expand Down
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Models:
- **twophase5eq**: five-equation homogeneous model of two phases in mechanical equilibrium
([Padioleau 2021](https://theses.hal.science/tel-03130146));
- **twophase7eq**: seven-equation Baer-Nunziato model with pressure and velocity relaxations
([Chen 2019](https://www.theses.fr/2019AIXM0380)).
([Chen 2019](https://www.theses.fr/2019AIXM0380));
- **particleflow**: disperse phase of particles (spray) by a quadrature method of moments in
velocity with two nodes, dragged by a carrier flow.

Numerics: HLL, HLLC and all-regime fluxes with non-conservative products, MUSCL reconstruction with
scalar limiters, forward Euler or SSP Runge-Kutta 2, viscous and thermal fluxes, gravity, block-based
Expand Down
20 changes: 19 additions & 1 deletion docs/user-guide/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Models

The three models share the finite volume solver of canoP; each one is a directory of `physics/`. The
The four models share the finite volume solver of canoP; each one is a directory of `physics/`. The
{doc}`../physics-guide/reference` gives, for each model, its variables, its parameters and every value
of its options with the parameters it reads.

Expand Down Expand Up @@ -40,6 +40,24 @@ Seven-equation Baer-Nunziato model: each phase has its velocity, pressure and en
`velocity_relaxation`, `pressure_velocity_relaxation`);
- viscous and thermal fluxes, gravity.

## particleflow

Disperse phase of particles (spray), described by the moments of its velocity distribution up to
the third order and closed by two velocity nodes (quadrature method of moments, QMOM), dragged
towards the velocity of a carrier flow given in each cell (one-way coupling). Ported from the model
`particlefluid` of canoP legacy.

- conservative variables: moments `M0`, `M1_x`, `M1_y` (`M1_z`), `M2_xx`, `M2_xy`, `M2_yy` (`M2_xz`,
`M2_yz`, `M2_zz`), `M3_x`, `M3_y` (`M3_z`), carrier velocity `Uf_x`, `Uf_y` (`Uf_z`); primitive
variables: the nodes `n1`, `n2`, `V1_*`, `V2_*`;
- flux: kinetic, upwinded node by node; at second order in space only the densities of the nodes
are reconstructed (quasi-second order), which keeps the moments realizable within the CFL
condition;
- after each time step, the moments are projected on the two nodes, then the drag towards the
carrier velocity with gravity, the gravity alone or the drag with a BGK relaxation of the
velocities is integrated exactly on the moments over the time step (relaxations `reprojection`,
`drag`, `gravity`, `drag_bgk`).

## Common numerics

- MUSCL reconstruction of the primitive variables with the limiters minmod, maxmod, mc, smart,
Expand Down
8 changes: 4 additions & 4 deletions physics/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ def _kernels(self, initial, boundary):
"sources(source: int, w: Cons, q: Prim, p: Params, dt: float, dim: int) -> None",
_switch("source", {k + 1: ["source_src_%s(w, q, p, dt, dim)" % n] for k, n in enumerate(o["sources"])}))
relaxations = _function(
"relaxations(relaxation: int, w: Cons, p: Params, dim: int) -> None",
"relaxations(relaxation: int, w: Cons, p: Params, dt: float, dim: int) -> None",
["qn: Prim = cons_to_prim(w, p, dim)"]
+ _switch("relaxation", {k + 1: ["relaxation_relax_%s(w, qn, p, dim)" % n]
+ _switch("relaxation", {k + 1: ["relaxation_relax_%s(w, qn, p, dt, dim)" % n]
for k, n in enumerate(o["relaxations"])}))
indicator = _function(
"indicator(criterion: int, Ug: pk.View3D[pk.double], Qg: pk.View3D[pk.double], iOct: int, ia: int, "
Expand Down Expand Up @@ -731,10 +731,10 @@ def sources(self, Uin, Uout, num_owned, dt):
ncells=self.ncells, dim=self.dim, dt=dt, source=self.source)

def relaxations(self, Uold, Unew, num_owned, dt):
"""Apply the instantaneous relaxation to Unew in the owned octants, after the time step."""
"""Apply the relaxation of the time step dt to Unew in the owned octants, after the time step."""
if self.relaxation != 0 and num_owned > 0:
run(num_owned * self.ncells, self.K["relaxations_kernel"], Unew=view(Unew), par=self.par,
ncells=self.ncells, dim=self.dim, relaxation=self.relaxation)
ncells=self.ncells, dim=self.dim, relaxation=self.relaxation, dt=dt)

def refine_flags(self, Ug, Qg, flags, num_owned, level_min, level_max):
"""Compute the refinement flags of the owned octants: -1 coarsen, 0 keep, 1 refine.
Expand Down
6 changes: 3 additions & 3 deletions physics/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ def sources_kernel(i: int, Uin: pk.View3D[pk.double], Uout: pk.View3D[pk.double]

@pk.workunit
def relaxations_kernel(i: int, Unew: pk.View3D[pk.double], par: pk.View1D[pk.double], ncells: int, dim: int,
relaxation: int) -> None:
"""Apply the instantaneous relaxation to the cell i of Unew, after the time step."""
relaxation: int, dt: float) -> None:
"""Apply the relaxation to the cell i of Unew, once after the time step dt."""
iOct: int = i // ncells
ic: int = i % ncells
mp: ModelParameters = model_parameters(par)
p: Params = make_params(mp)
w: Cons = load_cons(Unew, iOct, ic, dim)
relaxations(relaxation, w, p, dim)
relaxations(relaxation, w, p, dt, dim)
store_cons(Unew, iOct, ic, dim, w)


Expand Down
9 changes: 5 additions & 4 deletions physics/onephase/relaxations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# SPDX-FileCopyrightText: 2025 canoP authors
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Instantaneous relaxations: one file per value of ``physics.relaxation`` (or ``none``).
"""Relaxations: one file per value of ``physics.relaxation`` (or ``none``).

A relaxation file defines:

- ``relaxation(w, qn, p, dim)``: replaces the conservative state ``w`` of a cell by its projection
on the equilibrium, ``qn`` being the primitive state of ``w``. It applies once per time step,
after the time integration.
- ``relaxation(w, qn, p, dt, dim)``: replaces the conservative state ``w`` of a cell by its state
after a relaxation during the time step ``dt`` (its projection on the equilibrium for an
instantaneous relaxation), ``qn`` being the primitive state of ``w``. It applies once per time
step, after the time integration (after the average of the stages at ``time_order = 2``).
"""
119 changes: 119 additions & 0 deletions physics/particleflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# SPDX-FileCopyrightText: 2026 canoP authors
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Model particleflow: a disperse phase of particles (spray), quadrature method of moments (QMOM).

The particles of a cell are described by moments of their velocity distribution f(v), up to the
third order: the mass ``M0``, the momentum ``M1``, the full second-order tensor ``M2`` and the
diagonal third-order moments ``M3_i = int v_i^3 f``. The closure approximates f by two weighted
velocity nodes (quadrature with two nodes)::

f(v) = n1 delta(v - V1) + n2 delta(v - V2)

The moments are those of the kinetic equation of the particles, transported at their velocity,
dragged towards the velocity ``Uf`` of a carrier fluid (given in each cell, constant in time:
one-way coupling) with the relaxation time ``tau`` and accelerated by the gravity ``g``::

d_t f + v.grad_x f + div_v(f ((Uf - v) / tau + g)) = 0

for example ``d_t M0 + div(M1) = 0`` and ``d_t M1 + div(M2) = (M0 Uf - M1) / tau + M0 g``; the
fluxes of the highest moments are those of the two nodes (``hyperbolic_fluxes/kinetic.py``). Each
time step:

- the face fluxes are the kinetic fluxes of the nodes, upwinded node by node; at second order in
space, only the densities n1, n2 of the nodes are reconstructed at the faces, the velocities of the
cell being kept (quasi-second order, Vikas et al. 2011), which keeps the moments realizable;
- after the time integration (after the average of the stages at ``time_order = 2``), the moments
are projected on the two-node closure, then the drag and the gravity are integrated exactly over
the time step (``physics.relaxation``: ``reprojection`` alone, ``drag``, ``gravity`` or
``drag_bgk``): they move every velocity of the distribution by the same affine map, so the moments
stay on the two nodes. The drag is split from the transport (Lie splitting).

The time step is ``cfl h / max(sum_d |V1_d|, sum_d |V2_d|, cfl_velocity)``. In a stage, with the
velocities at its start, the outflow of a node from a cell stays below its density (the moments stay
realizable) for ``cfl <= 1`` at first order in space, ``cfl <= 2/3`` with the minmod limiter and
``cfl <= 1/2`` with the other limiters; the second stage of ``time_order = 2`` keeps the time step of
the first, so take a margin.

canoP legacy applied the drag in each stage, before the average of the stages: the average of two
distributions whose velocities differ changes the weights of the nodes after the reprojection, and
the drag is exact only to first order in ``dt / tau``. Applied once after the time step, it is exact
for a uniform state at any order in time and for any ``dt / tau``.

Ported from the model ``particlefluid`` of canoP legacy (branch
``48-temporary-spray-model-implementation-as-an-independent-model``).

Variables, in the order of the arrays of canoP (names of the outputs and checkpoints), d being the
dimension and ``M2`` stored as its lower triangle (``xx, xy, yy`` in 2D, ``xx, xy, yy, xz, yz, zz``
in 3D)::

conservative M0, M1_<i>, M2_<ij>, M3_<i>, Uf_<i>
primitive n1, n2, V1_<i>, V2_<i>, Uf_<i>
derived Up_<i> (mean velocity), a_<ij> (covariance of the velocity),
a_<iii> (third-order central moments)

The nodes are labelled so that ``n1 >= n2``.

Parameters (section ``[param]``):

- ``tau``: relaxation time of the drag (``relaxations/drag.py``, ``relaxations/drag_bgk.py``);
- ``tau_BGK``: relaxation time of the velocities to their mean (``relaxations/drag_bgk.py``);
- ``gravity_x``, ``gravity_y``, ``gravity_z``: gravity (``relaxations/drag.py``,
``relaxations/drag_bgk.py``, ``relaxations/gravity.py``);
- ``cfl_velocity``: lower bound of the velocity of the time step, for particles at rest at the start
(in a carrier flow, take its maximum ``sum_d |Uf_d|``);
- ``energy_preserving``: 1: replace the cross correlation ``a_ij`` by ``sign(a_ij) sqrt(a_ii a_jj)``
in the inversion, which keeps the energy of the moments (experimental);
- ``thresh_rho``: densities below it are vacuum;
- ``thresh_var``: below this trace of the covariance, the cell has a single node.
"""
from physics.common import AXES, get_int, get_real


def sym_names(dim):
"""Return the suffixes of the components of a symmetric tensor, in the order of the arrays.

Lower triangle, row by row: ``xx, xy, yy`` in 2D, ``xx, xy, yy, xz, yz, zz`` in 3D.
"""
return [AXES[j] + AXES[i] for i in range(dim) for j in range(i + 1)]


def variables(dim):
"""Return the variables of the model.

``conservative`` and ``primitive``: the variables in the order of the arrays of canoP, also the
names of the outputs and checkpoints; ``derived``: the derived output fields (``derived_field``
of ``model.py``); ``nonconservative``: whether the left and right fluxes of a face differ
(non-conservative products).
"""
axes = AXES[:dim]
return {"conservative": (["M0"] + ["M1_" + a for a in axes] + ["M2_" + s for s in sym_names(dim)]
+ ["M3_" + a for a in axes] + ["Uf_" + a for a in axes]),
"primitive": ["n1", "n2"] + ["V1_" + a for a in axes] + ["V2_" + a for a in axes]
+ ["Uf_" + a for a in axes],
"derived": (["Up_" + a for a in axes] + ["a_" + s for s in sym_names(dim)]
+ ["a_" + a * 3 for a in axes]),
"nonconservative": False}


def params(dim):
"""Return the parameters of the model, ``{name: value}``.

The kernels read them through the class ``ModelParameters`` (``make_params`` of ``model.py``).
"""
res = {}

res["tau"] = get_real("param", "tau", 1.0)
res["tau_BGK"] = get_real("param", "tau_BGK", 1.0)

res["gravity_x"] = get_real("param", "gravity_x", 0.0)
res["gravity_y"] = get_real("param", "gravity_y", 0.0)
res["gravity_z"] = get_real("param", "gravity_z", 0.0)

res["cfl_velocity"] = get_real("param", "cfl_velocity", 0.0)
res["energy_preserving"] = get_int("param", "energy_preserving", 0)

res["thresh_rho"] = get_real("param", "thresh_rho", 1e-12)
res["thresh_var"] = get_real("param", "thresh_var", 1e-9)

return res
24 changes: 24 additions & 0 deletions physics/particleflow/boundary_conditions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2025 canoP authors
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Boundary conditions: one file per value of ``physics.boundary_condition``.

The faces of the domain are numbered ``face = 2 d + s`` for the direction ``d`` (0 x, 1 y, 2 z) and
the side ``s`` (0 lower, 1 upper): 0 xmin, 1 xmax, 2 ymin, 3 ymax, 4 zmin, 5 zmax. A boundary
condition file defines:

- ``params(dim)``: the parameters of the option, a dictionary ``{name: value}`` read from the input
file. The kernels read them as ``bp.<name>`` (class ``BCParameters``); the names must not depend
on the input file.
- ``ghost_state(face, xout, xa, ya, za, h, uadj, umirror, bp, p, dim) -> Cons``: the conservative
state of a cell of an octant outside the domain, across ``face``. ``xout`` is the x coordinate of
the outside cell; ``(xa, ya, za)`` and ``h`` are the centre and size of the inside cell adjacent
to the face and ``uadj`` its state; ``umirror`` is the state of the inside cell mirrored through
the face.
- ``wall_kind(face, x, y, z, h, bp, dim) -> int``: the treatment of the face of the domain next to
the inside cell of centre ``(x, y, z)`` and size ``h``. It applies to the face states of the
hyperbolic flux (``wall_face_state`` of ``model.py``) and to the gradients of the diffusion flux
(``wall_gradient``): 0 none (the ghost cells act as inner cells), 1 reflective wall, 2 no-slip
wall, 3 outflow, 4 imposed state (the state of the ghost cell), 5 imposed pressure (the
reconstructed face state of the ghost cell).
"""
Loading
Loading