Skip to content
Merged
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
58 changes: 54 additions & 4 deletions Docs/source/PLIC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Like Godunov, MOL and BDS, the library provides spatial operators and leaves the
:math:`F`, its ghost cells and the synchronization of the levels to the solver. It requires
Cartesian coordinates and does not support embedded boundaries; ``PLIC::CheckMesh`` aborts on
either. The reconstruction is selected by name, as ``advection_type`` is in
``HydroUtils::ComputeFluxesOnBoxFromState``.
``HydroUtils::ComputeFluxesOnBoxFromState``, which also advects :math:`F` with
``advection_type = "PLIC"``.

What the solver provides
------------------------
Expand Down Expand Up @@ -124,16 +125,65 @@ The face velocities must be at :math:`t^{n+1/2}`, discretely divergence-free and
shared by boxes (as after a MAC projection), with one filled ghost layer, and the face Courant number
below 1. That is checked in every build, box by box. The check waits for the GPU, so that the boxes
of the loop do not overlap: on GPUs, check the level once with ``PLIC::CheckCourantNumber`` before
the loop and pass ``check_courant = false``. No ghost face beyond a domain face that is not periodic is read, whatever its boundary
condition (an inflow profile in those ghost faces is not seen): the faces on the domain boundary stand
in for them.
the loop and pass ``check_courant = false``. No ghost face beyond a domain face that is not periodic
is read, whatever its boundary condition (an inflow profile in those ghost faces is not seen): the
faces on the domain boundary stand in for them.

.. note::

Keep the interface on the finest level, by tagging the cells for which ``PLIC::interface_band``
holds: flux volumes do not tile across coarse/fine boundaries, which must stay in pure cells. With
subcycling, the reflux corrections then fall in pure cells too.

Through ``HydroUtils``
~~~~~~~~~~~~~~~~~~~~~~

A solver that advects its scalars with ``HydroUtils::ComputeFluxesOnBoxFromState`` can advect
:math:`F` with the same call and ``advection_type = "PLIC"``, with ``ncomp = 1``, ``iconserv = 1``
and ``is_velocity = false``. It uses the ``myc_height`` reconstruction:

- on the faces where ``u_flux`` equals ``u_mac`` bit for bit (every face, with the overloads without
``u_flux``),
it gives the edge states and the geometric fluxes of ``PLIC::ComputeEdgeStateAndFluxes``, to the
bit;
- on the faces where a corrective ``u_flux`` differs, even by round-off, the fluxes are PLIC's edge states times
``u_flux``. PLIC's edge states are upwinded by ``u_mac``: where ``u_mac`` is zero or of the other
sign, the flux takes instead the :math:`F` of the upwind cell of ``u_flux``, held to [0,1], so that
it never draws on the downwind cell, unlike the other schemes, as :math:`F` must stay in [0,1].
The face arrays keep PLIC's edge states. The choice is made face by face, so the boxes sharing a
face get the same flux. A solver that calls PLIC directly gets the same fluxes from
``PLIC::CorrectiveFluxes``;
- with ``knownFaceState``, the face arrays are the edge states (``iconserv = 1``) or the fluxes
(``iconserv = -1``, copied). Any other ``iconserv`` aborts. With edge states, the fluxes get the
same correction as above where ``u_flux`` differs from ``u_mac``, so pass the ``u_mac`` that
they were computed with. Unlike the other schemes, a corrective ``u_flux`` then needs ``u_mac``
and :math:`F` with one filled ghost cell, whatever ``iconserv``.

:math:`F` needs ``PLIC::nGrowF("myc_height")`` ghost cells, filled by ``PLIC::FillWallGhosts``,
which carry the boundary conditions in place of the ``BCRec`` arguments; ``qnph``, ``divu``, the
forcing ``fq``, the ``godunov_*`` flags, ``limiter_type`` and ``allow_inflow_on_outflow`` are not
read. The reconstruction is always ``myc_height``: a solver that advects :math:`F` this way must
pass ``"myc_height"`` to ``PLIC::FillWallGhosts`` and ``PLIC::SharpFaceDensity`` too, or the wall
ghost cells and the face density come from other normals than the fluxes (or ``F`` has too few
ghost cells). To call PLIC directly with another reconstruction, use
``PLIC::ComputeEdgeStateAndFluxes``.

On GPUs, check the Courant number of each level once with ``PLIC::CheckCourantNumber`` before the
``MFIter`` loop: optimized GPU builds do not check it box by box, as that waits for the GPU, and
neither do they check that ``iconserv`` is 1, or -1 with ``knownFaceState`` (other values are then
treated as 1). A face Courant number above 1 makes the flux volumes read beyond the data, so a GPU
solver that skips ``PLIC::CheckCourantNumber`` must bound its time step some other way. CPU builds
and debug builds check both, box by box.
``HydroUtils::ComputeConvectiveTerm`` accepts ``"PLIC"`` and adds nothing, as :math:`F` is advected
in conservative form. ``"PLIC"`` aborts with embedded boundaries, and
``HydroUtils::ExtrapVelToFaces`` does not accept it.

.. note::

With GNUmake, add the ``PLIC`` directory to the build, which defines ``HYDRO_USE_PLIC``; without
it ``"PLIC"`` aborts. The name of the build directory does not depend on it, so after adding
``PLIC`` to an existing build, run ``make clean`` to rebuild ``Utils``.

Reconstructions
---------------

Expand Down
1 change: 1 addition & 0 deletions Docs/source/Schemes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Advection schemes
^^^^^^^^^^^^^^^^^

In AMReX-Hydro, the fundamental algorithm is a Method-of-Lines (MOL), Godunov, or Bell-Dawson-Shubin (BDS) approach.
The volume fraction of a two-phase flow can also be advected with geometric PLIC fluxes, see :ref:`plic`.
Each method provides functions for two separate usages:

1. **Construct values of the normal velocity at the centroid on each cell face, termed "Pre-MAC" or
Expand Down
5 changes: 3 additions & 2 deletions Docs/source/bcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ does not change which boundary condition is applied.
Position-dependent BCs are only read by the (EB)Godunov routines. The MOL, EBMOL and BDS
routines use the single BC per face :cpp:`BCRecs` only, so
:cpp:`HydroUtils::ExtrapVelToFaces` and :cpp:`HydroUtils::ComputeFluxesOnBoxFromState`
abort if a BC MF (or Array4) is passed with ``advection_type`` set to ``"MOL"`` or ``"BDS"``,
rather than silently dropping it.
abort if a BC MF (or Array4) is passed with ``advection_type`` set to ``"MOL"``, ``"BDS"`` or
``"PLIC"``, rather than silently dropping it. With ``"PLIC"`` the boundary conditions are carried
by the ghost cells (see :ref:`plic`).


The MacProjector supports mixed boundary conditions by making use of the underlying linear solver's
Expand Down
3 changes: 3 additions & 0 deletions PLIC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ target_sources(
hydro_plic_owkes_desjardins_K.H
hydro_plic_reconstruction.cpp
)

# HydroUtils::ComputeFluxesOnBoxFromState accepts advection_type "PLIC" when PLIC is built
target_compile_definitions(amrex_hydro PRIVATE HYDRO_USE_PLIC)
3 changes: 3 additions & 0 deletions PLIC/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ CEXE_sources += hydro_plic.cpp
CEXE_sources += hydro_plic_reconstruction.cpp
CEXE_headers += hydro_plic_owkes_desjardins_K.H
CEXE_sources += hydro_plic_owkes_desjardins.cpp

# HydroUtils::ComputeFluxesOnBoxFromState accepts advection_type "PLIC" when PLIC is built
DEFINES += -DHYDRO_USE_PLIC
39 changes: 39 additions & 0 deletions PLIC/hydro_plic.H
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,45 @@ void ComputeEdgeStateAndFluxes (amrex::Box const& bx,
bool fluxes_are_area_weighted = false,
bool check_courant = true);

/**
* \brief Overwrite the fluxes from ComputeEdgeStateAndFluxes on the faces where a corrective velocity
* u_flux differs from umac (bit for bit), as in a multilevel synchronization: the edge state
* times u_flux there. The edge states are upwinded by umac: where umac is zero or of the other
* sign, the flux takes instead the F of the upwind cell of u_flux, held to [0,1], so that it
* never draws on the downwind cell. The edge states are not changed. Decided face by face, so
* that the boxes sharing a face agree on its flux; a direction whose u_flux is the umac array
* itself is skipped.
*
* \param flux_x fluxes on the x faces of bx, from ComputeEdgeStateAndFluxes, or the edge states
* times umac (likewise y, z)
* \param face_x edge states on the x faces of bx, upwinded by umac, as from ComputeEdgeStateAndFluxes
* (likewise y, z)
* \param F volume fraction at t^n, with one filled ghost cell
* \param umac the face velocity the fluxes were computed with (likewise vmac, wmac)
* \param uflux the corrective face velocity (likewise vflux, wflux)
* \param geom geometry of the level
* \param fluxes_are_area_weighted as passed to ComputeEdgeStateAndFluxes
* \param iconserv optional, on the device: where iconserv[0] is -1 (HydroUtils with
* knownFaceState) the fluxes are given and are kept
*/
void CorrectiveFluxes (amrex::Box const& bx,
AMREX_D_DECL(amrex::Array4<amrex::Real> const& flux_x,
amrex::Array4<amrex::Real> const& flux_y,
amrex::Array4<amrex::Real> const& flux_z),
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& face_x,
amrex::Array4<amrex::Real const> const& face_y,
amrex::Array4<amrex::Real const> const& face_z),
amrex::Array4<amrex::Real const> const& F,
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& umac,
amrex::Array4<amrex::Real const> const& vmac,
amrex::Array4<amrex::Real const> const& wmac),
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& uflux,
amrex::Array4<amrex::Real const> const& vflux,
amrex::Array4<amrex::Real const> const& wflux),
amrex::Geometry const& geom,
bool fluxes_are_area_weighted = false,
int const* iconserv = nullptr);

/**
* \brief Abort unless the face Courant number, |u| dt/dx, is below 1 on every face that
* ComputeEdgeStateAndFluxes reads for the boxes of the level: their faces and one ghost face
Expand Down
56 changes: 56 additions & 0 deletions PLIC/hydro_plic_owkes_desjardins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,62 @@ ComputeEdgeStateAndFluxes (amrex::Box const& bx,
});
}

void
CorrectiveFluxes (amrex::Box const& bx,
AMREX_D_DECL(amrex::Array4<amrex::Real> const& flux_x,
amrex::Array4<amrex::Real> const& flux_y,
amrex::Array4<amrex::Real> const& flux_z),
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& face_x,
amrex::Array4<amrex::Real const> const& face_y,
amrex::Array4<amrex::Real const> const& face_z),
amrex::Array4<amrex::Real const> const& F,
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& umac,
amrex::Array4<amrex::Real const> const& vmac,
amrex::Array4<amrex::Real const> const& wmac),
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& uflux,
amrex::Array4<amrex::Real const> const& vflux,
amrex::Array4<amrex::Real const> const& wflux),
amrex::Geometry const& geom,
bool fluxes_are_area_weighted,
int const* iconserv)
{
BL_PROFILE("PLIC::CorrectiveFluxes()");
const amrex::Array<amrex::Array4<amrex::Real>, AMREX_SPACEDIM> flux{AMREX_D_DECL(flux_x, flux_y, flux_z)};
const amrex::Array<amrex::Array4<amrex::Real const>, AMREX_SPACEDIM> face{AMREX_D_DECL(face_x, face_y, face_z)};
const amrex::Array<amrex::Array4<amrex::Real const>, AMREX_SPACEDIM> vel{AMREX_D_DECL(umac, vmac, wmac)};
const amrex::Array<amrex::Array4<amrex::Real const>, AMREX_SPACEDIM> corr{AMREX_D_DECL(uflux, vflux, wflux)};
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
// The same arrays: every face keeps its geometric flux
if (corr[d].dataPtr() == vel[d].dataPtr()) { continue; }
// Checked here, not only in ComputeEdgeStateAndFluxes: with knownFaceState HydroUtils calls
// this alone, where the other schemes read neither F nor umac. An empty Array4 fails too.
const amrex::Box faces = amrex::surroundingNodes(bx, d);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(detail::FaceBox(flux[d], d).contains(faces) &&
detail::FaceBox(face[d], d).contains(faces) &&
detail::FaceBox(vel[d], d).contains(faces) &&
detail::FaceBox(corr[d], d).contains(faces),
"PLIC: CorrectiveFluxes needs the fluxes, edge states, umac and u_flux on the faces of bx");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(amrex::Box(F).contains(amrex::grow(bx, d, 1)),
"PLIC: CorrectiveFluxes needs F with one filled ghost cell");
const amrex::Real area = detail::FaceArea(geom, d, fluxes_are_area_weighted);
amrex::Array4<amrex::Real> const fl = flux[d];
amrex::Array4<amrex::Real const> const fc = face[d];
amrex::Array4<amrex::Real const> const um = vel[d];
amrex::Array4<amrex::Real const> const uf = corr[d];
amrex::ParallelFor(faces, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// Read on the device, so that the boxes of an MFIter loop do not wait for the GPU
if (iconserv && iconserv[0] == -1) { return; }
const amrex::Real u = uf(i, j, k);
if (u != um(i, j, k)) {
const amrex::Real fe = (um(i, j, k) * u > 0.0_rt)
? fc(i, j, k) : upwind_fraction(F, amrex::IntVect(AMREX_D_DECL(i, j, k)), d, u);
fl(i, j, k) = fe * u * area;
}
});
}
}

void
CheckCourantNumber (AMREX_D_DECL(amrex::MultiFab const& umac,
amrex::MultiFab const& vmac,
Expand Down
6 changes: 4 additions & 2 deletions Tests/PLIC/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ Pdirs += Base
Pdirs += Boundary

Ppack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package)
Ppack += $(AMREX_HYDRO_HOME)/PLIC/Make.package
Hdirs := Utils Godunov MOL BDS PLIC

Ppack += $(foreach dir, $(Hdirs), $(AMREX_HYDRO_HOME)/$(dir)/Make.package)

include $(Ppack)

Blocs := $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir))
Blocs += $(AMREX_HYDRO_HOME)/PLIC
Blocs += $(foreach dir, $(Hdirs), $(AMREX_HYDRO_HOME)/$(dir))

INCLUDE_LOCATIONS += $(Blocs)
VPATH_LOCATIONS += $(Blocs)
Expand Down
14 changes: 9 additions & 5 deletions Tests/PLIC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ mpirun -np 4 ./main2d.gnu.MPI.ex inputs.2d.vortex
| Input | Case |
|-------------------------|-----------------------------------------------------------------|
| `inputs.kernels` | Plane geometry, normals, plane fit, wall ghost cells, face density |
| `inputs.2d.vortex` | Circle in the time-reversed single vortex, 3 levels |
| `inputs.2d.vortex` | Circle in the time-reversed single vortex, 3 levels, through `HydroUtils` |
| `inputs.2d.zalesak` | Zalesak's slotted disk, one revolution, 3 levels |
| `inputs.2d.wall_vortex` | Circle cut by a wall, in the same flow: a free contact line |
| `inputs.3d.deform` | Sphere in LeVeque's deformation field, 3 levels |
| `inputs.2d.wall_vortex` | Circle cut by a wall, in the same flow, through `HydroUtils` |
| `inputs.3d.deform` | Sphere in LeVeque's deformation field, 3 levels, through `HydroUtils` |

The advection cases return to their initial shape at `t = prob.period`, so the shape error is the L1
difference from the initial volume fraction. `plic.reconstruction` selects the reconstruction
(default `myc_height`). Set `amr.max_level = 0` and `amr.n_cell` for a uniform grid. The `test.max_*`
parameters set the checks. `test.plot_file = <name>` writes the final volume fraction as a plotfile
(component `vof`, every level), e.g. `mpirun -np 4 ./main2d.gnu.MPI.ex inputs.2d.vortex test.plot_file=plt`.
parameters set the checks. With `test.use_hydroutils = 1` the test advects F as a solver would any
other scalar, through `HydroUtils::ComputeFluxesOnBoxFromState` with `advection_type = "PLIC"`, and
checks that it gives the fluxes and edge states of `PLIC::ComputeEdgeStateAndFluxes` to the bit, on
the first step and every `test.hydroutils_int` steps (default 10; 1 checks every step).
`test.plot_file = <name>` writes the final volume fraction as a plotfile (component `vof`, every
level), e.g. `mpirun -np 4 ./main2d.gnu.MPI.ex inputs.2d.vortex test.plot_file=plt`.

`PLICTestUtils.H` holds what the test solver does around the library and a real solver would do its
own way: the prescribed velocities, the time step and the refinement tags.
Expand Down
3 changes: 3 additions & 0 deletions Tests/PLIC/inputs.2d.vortex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ amr.fixed_dt = 0.001953125
amr.stop_time = 4.0

test.max_l1 = 5.0e-4
# Advect through HydroUtils, and compare with PLIC::ComputeEdgeStateAndFluxes
test.use_hydroutils = 1

test.max_volume_change = 1.0e-13
test.max_f_excursion = 1.0e-9

Expand Down
2 changes: 2 additions & 0 deletions Tests/PLIC/inputs.2d.wall_vortex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ prob.period = 2.0
amr.fixed_dt = 0.0078125
amr.stop_time = 2.0

# Advect through HydroUtils, and compare with PLIC::ComputeEdgeStateAndFluxes
test.use_hydroutils = 1
test.max_volume_change = 1.0e-13
test.max_f_excursion = 1.0e-9

Expand Down
3 changes: 3 additions & 0 deletions Tests/PLIC/inputs.3d.deform
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ prob.period = 3.0
amr.fixed_dt = 0.001953125
amr.stop_time = 3.0

# Advect through HydroUtils, and compare with PLIC::ComputeEdgeStateAndFluxes
test.use_hydroutils = 1

test.max_volume_change = 1.0e-13
test.max_f_excursion = 1.0e-9

Expand Down
5 changes: 3 additions & 2 deletions Tests/PLIC/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// test.kind = kernels the plane geometry, the normals, the plane fit (test_geometry.cpp), the
// wall ghost cells (test_walls.cpp) and the face density (test_density.cpp)
// test.kind = advect a prescribed velocity on an AMR hierarchy (see inputs.*), advanced with
// PLIC::ComputeEdgeStateAndFluxes in the solver's own MFIter loop
// (test_advect.cpp)
// PLIC::ComputeEdgeStateAndFluxes in the solver's own MFIter loop, or with
// HydroUtils::ComputeFluxesOnBoxFromState and advection_type "PLIC" if
// test.use_hydroutils = 1 (test_advect.cpp)

#include "test_util.H"

Expand Down
Loading