Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tracer particles #490

Merged
merged 48 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
73a2343
add tracer particle infrastructure
BenWibking Jan 9, 2024
f4b822b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2024
244329b
fix headers
BenWibking Jan 9, 2024
dc17c86
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2024
64d07b2
fix clang-tidy warnings
BenWibking Jan 9, 2024
4fa8ba2
advect particles in advanceSingleTimestepAtLevel
BenWibking Jan 9, 2024
9c66f4c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2024
41a9b2c
add runtime param
BenWibking Jan 10, 2024
970e19e
set plotfile interval in input file
BenWibking Jan 10, 2024
545d763
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
55f61bc
use face-centered velocities
BenWibking Jan 10, 2024
2dc60a0
Merge branch 'BenWibking/tracer-particles' of github.com:quokka-astro…
BenWibking Jan 10, 2024
d716ead
add commented-out TracerPC reset in hydro retries
BenWibking Jan 10, 2024
f53d15f
add ghost face to avgFaceVel
BenWibking Jan 10, 2024
289482f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
5c384ad
fix hydro retries
BenWibking Jan 10, 2024
d6e2912
add KelvinHelmholz_tracer.in
BenWibking Jan 10, 2024
f2bf8b1
use 2 ghost cells
BenWibking Jan 11, 2024
1b86203
add missing conditionals
BenWibking Jan 11, 2024
9c99917
fix var scope
BenWibking Jan 11, 2024
52468db
update param file
BenWibking Jan 11, 2024
ae2b0c8
fix face-centered AMR interp
BenWibking Jan 11, 2024
f0e5b48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2024
b5dcca7
fix boundary functor
BenWibking Jan 12, 2024
06a9953
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 12, 2024
98bd21c
fix FCQuantities test
BenWibking Jan 12, 2024
40e6403
Merge branch 'BenWibking/tracer-particles' of github.com:quokka-astro…
BenWibking Jan 12, 2024
c59529a
Merge branch 'development' into BenWibking/tracer-particles
BenWibking Jan 12, 2024
1bf237b
Update src/FCQuantities/test_fc_quantities.cpp
BenWibking Jan 12, 2024
706396e
Update src/FCQuantities/test_fc_quantities.cpp
BenWibking Jan 12, 2024
d623102
Update test_fc_quantities.cpp
BenWibking Jan 12, 2024
2e02f2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 12, 2024
0a8c549
fix template lookup
BenWibking Jan 14, 2024
7f6c84d
Merge branch 'development' into BenWibking/tracer-particles
BenWibking Jan 14, 2024
00da54e
use fixed AMReX
BenWibking Jan 15, 2024
3b60b53
Merge branch 'BenWibking/tracer-particles' of github.com:quokka-astro…
BenWibking Jan 15, 2024
28f5900
Merge branch 'development' into BenWibking/tracer-particles
BenWibking Jan 15, 2024
86cd997
only add face velocities if hydro is enabled
BenWibking Jan 15, 2024
3935c0b
Merge branch 'BenWibking/tracer-particles' of github.com:quokka-astro…
BenWibking Jan 15, 2024
8a31244
only swap fc vars if > 0
BenWibking Jan 15, 2024
cee60dc
add do_tracers to docs
BenWibking Jan 15, 2024
4d49b2b
turn on tracer particles for HydroBlast3D and SphericalCollapse
BenWibking Jan 15, 2024
6274f1c
update amrex submodule
BenWibking Jan 15, 2024
95019fd
address review comments
BenWibking Jan 16, 2024
b5a4954
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
5042981
restore HydroBlast2D/HydroKelvinHelmholz
BenWibking Jan 16, 2024
bcdccec
Merge branch 'BenWibking/tracer-particles' of github.com:quokka-astro…
BenWibking Jan 16, 2024
865ff46
restore KelvinHelmholz.in
BenWibking Jan 16, 2024
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: 4 additions & 1 deletion docs/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ These parameters are read in the `AMRSimulation<problem_t>::readParameters()` fu
- The time interval (in simulated time) between checkpoint outputs.
* - do_reflux
- Integer
- this turns on refluxing at coarse-fine boundaries (1) or turns it off (0). Except for debugging, this should always be on when AMR is used.
- This turns on refluxing at coarse-fine boundaries (1) or turns it off (0). Except for debugging, this should always be on when AMR is used.
* - do_tracers
- Integer
- This turns on tracer particles. They are initialized one-per-cell and they follow the fluid velocity. Default: 0 (off).
* - suppress_output
- Integer
- If set to 1, this disables output to stdout while the simulation is running.
Expand Down
8 changes: 8 additions & 0 deletions src/AdvectionSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ template <typename problem_t> class AdvectionSimulation : public AMRSimulation<p
auto computeExtraPhysicsTimestep(int level) -> amrex::Real override;
void preCalculateInitialConditions() override;
void setInitialConditionsOnGrid(quokka::grid grid_elem) override;
void setInitialConditionsOnGridFaceVars(quokka::grid grid_elem) override;
void advanceSingleTimestepAtLevel(int lev, amrex::Real time, amrex::Real dt_lev, int /*ncycle*/) override;
void computeAfterTimestep() override;
void computeAfterEvolve(amrex::Vector<amrex::Real> &initSumCons) override;
Expand Down Expand Up @@ -147,6 +148,13 @@ template <typename problem_t> void AdvectionSimulation<problem_t>::setInitialCon
// user should implement using problem-specific template specialization
}

template <typename problem_t> void AdvectionSimulation<problem_t>::setInitialConditionsOnGridFaceVars(quokka::grid grid_elem)
{
// default empty implementation
// user should implement using problem-specific template specialization
// note: an implementation is only required if face-centered vars are used
}

template <typename problem_t> void AdvectionSimulation<problem_t>::computeAfterTimestep()
{
// do nothing -- user should implement using problem-specific template specialization
Expand Down
51 changes: 26 additions & 25 deletions src/FCQuantities/test_fc_quantities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,33 @@ template <> void RadhydroSimulation<FCQuantities>::setInitialConditionsOnGrid(qu
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> prob_lo = grid_elem.prob_lo_;
const amrex::Array4<double> &state = grid_elem.array_;
const amrex::Box &indexRange = grid_elem.indexRange_;
const quokka::centering cen = grid_elem.cen_;
const quokka::direction dir = grid_elem.dir_;

if (cen == quokka::centering::cc) {
const int ncomp_cc = Physics_Indices<FCQuantities>::nvarTotal_cc;
// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
for (int n = 0; n < ncomp_cc; ++n) {
state(i, j, k, n) = 0; // fill unused quantities with zeros
}
computeWaveSolution(i, j, k, state, dx, prob_lo);
});
} else if (cen == quokka::centering::fc) {
if (dir == quokka::direction::x) {
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 1.0 + (i % 2);
});
} else if (dir == quokka::direction::y) {
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 2.0 + (j % 2);
});
} else if (dir == quokka::direction::z) {
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 3.0 + (k % 2);
});
const int ncomp_cc = Physics_Indices<FCQuantities>::nvarTotal_cc;
// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
for (int n = 0; n < ncomp_cc; ++n) {
state(i, j, k, n) = 0; // fill unused quantities with zeros
}
computeWaveSolution(i, j, k, state, dx, prob_lo);
});
}

template <> void RadhydroSimulation<FCQuantities>::setInitialConditionsOnGridFaceVars(quokka::grid grid_elem)
{
// extract grid information
const amrex::Array4<double> &state = grid_elem.array_;
const amrex::Box &indexRange = grid_elem.indexRange_;
const quokka::direction dir = grid_elem.dir_;

if (dir == quokka::direction::x) {
amrex::ParallelFor(
indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 1.0 + (i % 2); });
} else if (dir == quokka::direction::y) {
amrex::ParallelFor(
indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 2.0 + (j % 2); });
} else if (dir == quokka::direction::z) {
amrex::ParallelFor(
indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<FCQuantities>::bfield_index) = 3.0 + (k % 2); });
}
}

Expand Down Expand Up @@ -159,7 +160,7 @@ auto problem_main() -> int
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state_new_fc_write = sim_write.getNewMF_fc();
amrex::Print() << "\n";

RadhydroSimulation<FCQuantities> sim_restart(BCs_cc);
RadhydroSimulation<FCQuantities> sim_restart(BCs_cc, BCs_fc);
sim_restart.setChkFile("chk00000");
sim_restart.setInitialConditions();
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state_new_fc_restart = sim_restart.getNewMF_fc();
Expand Down
105 changes: 84 additions & 21 deletions src/RadhydroSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
#include <climits>
#include <filesystem>
#include <limits>
#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>

#include "AMReX.H"
#include "AMReX_Algorithm.H"
#include "AMReX_AmrParticles.H"
#include "AMReX_Arena.H"
#include "AMReX_Array.H"
#include "AMReX_Array4.H"
#include "AMReX_BCRec.H"
#include "AMReX_BC_TYPES.H"
#include "AMReX_BLassert.H"
#include "AMReX_Box.H"
#include "AMReX_FArrayBox.H"
Expand All @@ -47,6 +50,7 @@
#include "AMReX_REAL.H"
#include "AMReX_Utility.H"
#include "AMReX_YAFluxRegister.H"
#include "physics_numVars.hpp"

#ifdef AMREX_USE_ASCENT
#include "AMReX_Conduit_Blueprint.H"
Expand All @@ -73,6 +77,9 @@ template <typename problem_t> class RadhydroSimulation : public AMRSimulation<pr
using AMRSimulation<problem_t>::state_old_cc_;
using AMRSimulation<problem_t>::state_new_cc_;
using AMRSimulation<problem_t>::max_signal_speed_;
using AMRSimulation<problem_t>::state_old_fc_;
using AMRSimulation<problem_t>::state_new_fc_;
using AMRSimulation<problem_t>::TracerPC;

using AMRSimulation<problem_t>::nghost_cc_;
using AMRSimulation<problem_t>::areInitialConditionsDefined_;
Expand All @@ -92,6 +99,7 @@ template <typename problem_t> class RadhydroSimulation : public AMRSimulation<pr
using AMRSimulation<problem_t>::finest_level;
using AMRSimulation<problem_t>::finestLevel;
using AMRSimulation<problem_t>::do_reflux;
using AMRSimulation<problem_t>::do_tracers;
using AMRSimulation<problem_t>::Verbose;
using AMRSimulation<problem_t>::constantDt_;
using AMRSimulation<problem_t>::boxArray;
Expand Down Expand Up @@ -143,30 +151,19 @@ template <typename problem_t> class RadhydroSimulation : public AMRSimulation<pr
// member functions
explicit RadhydroSimulation(amrex::Vector<amrex::BCRec> &BCs_cc, amrex::Vector<amrex::BCRec> &BCs_fc) : AMRSimulation<problem_t>(BCs_cc, BCs_fc)
{
defineComponentNames();
// read in runtime parameters
readParmParse();
// set gamma
amrex::ParmParse eos("eos");
eos.add("eos_gamma", quokka::EOS_Traits<problem_t>::gamma);

// initialize Microphysics params
init_extern_parameters();
// initialize Microphysics EOS
amrex::Real small_temp = 1e-10;
amrex::Real small_dens = 1e-100;
eos_init(small_temp, small_dens);
initialize();
}

explicit RadhydroSimulation(amrex::Vector<amrex::BCRec> &BCs_cc) : AMRSimulation<problem_t>(BCs_cc)
explicit RadhydroSimulation(amrex::Vector<amrex::BCRec> &BCs_cc) : AMRSimulation<problem_t>(BCs_cc) { initialize(); }

inline void initialize()
{
defineComponentNames();
// read in runtime parameters
readParmParse();
// set gamma
amrex::ParmParse eos("eos");
eos.add("eos_gamma", quokka::EOS_Traits<problem_t>::gamma);

// initialize Microphysics params
init_extern_parameters();
// initialize Microphysics EOS
Expand All @@ -184,6 +181,7 @@ template <typename problem_t> class RadhydroSimulation : public AMRSimulation<pr
auto computeExtraPhysicsTimestep(int lev) -> amrex::Real override;
void preCalculateInitialConditions() override;
void setInitialConditionsOnGrid(quokka::grid grid_elem) override;
void setInitialConditionsOnGridFaceVars(quokka::grid grid_elem) override;
void advanceSingleTimestepAtLevel(int lev, amrex::Real time, amrex::Real dt_lev, int ncycle) override;
void computeAfterTimestep() override;
void computeAfterLevelAdvance(int lev, amrex::Real time, amrex::Real dt_lev, int /*ncycle*/);
Expand Down Expand Up @@ -313,6 +311,11 @@ template <typename problem_t> void RadhydroSimulation<problem_t>::defineComponen
}

// face-centred

// add face-centered velocities
for (int idim = 0; idim < AMREX_SPACEDIM; idim++) {
componentNames_fc_.push_back({quokka::face_dir_str[idim] + "-velocity"});
}
// add mhd state variables
if constexpr (Physics_Traits<problem_t>::is_mhd_enabled) {
for (int idim = 0; idim < AMREX_SPACEDIM; idim++) {
Expand Down Expand Up @@ -475,6 +478,13 @@ template <typename problem_t> void RadhydroSimulation<problem_t>::setInitialCond
// user should implement using problem-specific template specialization
}

template <typename problem_t> void RadhydroSimulation<problem_t>::setInitialConditionsOnGridFaceVars(quokka::grid grid_elem)
{
// default empty implementation
// user should implement using problem-specific template specialization
// note: an implementation is only required if face-centered vars are used
}

template <typename problem_t> void RadhydroSimulation<problem_t>::computeAfterTimestep()
{
// do nothing -- user should implement if desired
Expand Down Expand Up @@ -631,6 +641,9 @@ template <typename problem_t> void RadhydroSimulation<problem_t>::advanceSingleT

// since we are starting a new timestep, need to swap old and new state vectors
std::swap(state_old_cc_[lev], state_new_cc_[lev]);
if (Physics_Indices<problem_t>::nvarTotal_fc > 0) {
std::swap(state_old_fc_[lev], state_new_fc_[lev]);
}

// check hydro states before update (this can be caused by the flux register!)
CHECK_HYDRO_STATES(state_old_cc_[lev]);
Expand Down Expand Up @@ -753,9 +766,9 @@ void RadhydroSimulation<problem_t>::FillPatch(int lev, amrex::Real time, amrex::
}

if (cen == quokka::centering::cc) {
FillPatchWithData(lev, time, mf, cmf, ctime, fmf, ftime, icomp, ncomp, BCs_cc_, fptype, PreInterpState, PostInterpState);
FillPatchWithData(lev, time, mf, cmf, ctime, fmf, ftime, icomp, ncomp, BCs_cc_, cen, fptype, PreInterpState, PostInterpState);
} else if (cen == quokka::centering::fc) {
FillPatchWithData(lev, time, mf, cmf, ctime, fmf, ftime, icomp, ncomp, BCs_fc_, fptype, PreInterpState, PostInterpState);
FillPatchWithData(lev, time, mf, cmf, ctime, fmf, ftime, icomp, ncomp, BCs_fc_, cen, fptype, PreInterpState, PostInterpState);
}
}

Expand Down Expand Up @@ -857,6 +870,14 @@ void RadhydroSimulation<problem_t>::advanceHydroAtLevelWithRetries(int lev, amre
amrex::Copy(originalFineData, fineData, 0, 0, fineData.nComp(), 0);
}

#ifdef AMREX_PARTICLES
markkrumholz marked this conversation as resolved.
Show resolved Hide resolved
amrex::AmrTracerParticleContainer::ContainerLike<amrex::DefaultAllocator> originalTracerPC;
if (do_tracers != 0) {
// save the pre-advance tracer particles
originalTracerPC = TracerPC->make_alike();
}
#endif

for (int retry_count = 0; retry_count <= max_retries; ++retry_count) {
// reduce timestep by a factor of 2^retry_count
const int nsubsteps = std::pow(2, retry_count);
Expand All @@ -875,6 +896,13 @@ void RadhydroSimulation<problem_t>::advanceHydroAtLevelWithRetries(int lev, amre
if (fr_as_fine != nullptr) {
amrex::Copy(fr_as_fine->getFineData(), originalFineData, 0, 0, originalFineData.nComp(), 0);
}

#ifdef AMREX_PARTICLES
if (do_tracers != 0) {
// reset the tracer particles to their pre-advance state
TracerPC->copyParticles(originalTracerPC, true);
}
#endif
}

// create temporary multifab for old state
Expand Down Expand Up @@ -993,14 +1021,20 @@ auto RadhydroSimulation<problem_t>::advanceHydroAtLevel(amrex::MultiFab &state_o
amrex::MultiFab state_inter_cc_(grids[lev], dmap[lev], Physics_Indices<problem_t>::nvarTotal_cc, nghost_cc_);
state_inter_cc_.setVal(0); // prevent assert in fillBoundaryConditions when radiation is enabled

// create temporary multifabs for combined RK2 flux
// create temporary multifabs for combined RK2 flux and time-average face velocity
std::array<amrex::MultiFab, AMREX_SPACEDIM> flux_rk2;
std::array<amrex::MultiFab, AMREX_SPACEDIM> avgFaceVel;
const int nghost_vel = 2; // 2 ghost faces are needed for tracer particles
auto ba = grids[lev];
auto dm = dmap[lev];
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
auto ba_face = amrex::convert(ba, amrex::IntVect::TheDimensionVector(idim));
// initialize flux MultiFab
flux_rk2[idim] = amrex::MultiFab(ba_face, dm, ncompHydro_, 0);
flux_rk2[idim].setVal(0);
// initialize velocity MultiFab
avgFaceVel[idim] = amrex::MultiFab(ba_face, dm, 1, nghost_vel);
avgFaceVel[idim].setVal(0);
}

// update ghost zones [old timestep]
Expand Down Expand Up @@ -1035,6 +1069,7 @@ auto RadhydroSimulation<problem_t>::advanceHydroAtLevel(amrex::MultiFab &state_o

for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
amrex::MultiFab::Saxpy(flux_rk2[idim], 0.5, fluxArrays[idim], 0, 0, ncompHydro_, 0);
amrex::MultiFab::Saxpy(avgFaceVel[idim], 0.5, faceVel[idim], 0, 0, 1, 0);
}

amrex::MultiFab rhs(grids[lev], dmap[lev], ncompHydro_, 0);
Expand Down Expand Up @@ -1145,14 +1180,15 @@ auto RadhydroSimulation<problem_t>::advanceHydroAtLevel(amrex::MultiFab &state_o

for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
amrex::MultiFab::Saxpy(flux_rk2[idim], 0.5, fluxArrays[idim], 0, 0, ncompHydro_, 0);
amrex::MultiFab::Saxpy(avgFaceVel[idim], 0.5, faceVel[idim], 0, 0, 1, 0);
}

amrex::MultiFab rhs(grids[lev], dmap[lev], ncompHydro_, 0);
amrex::iMultiFab redoFlag(grids[lev], dmap[lev], 1, 1);
redoFlag.setVal(quokka::redoFlag::none);

HydroSystem<problem_t>::ComputeRhsFromFluxes(rhs, flux_rk2, dx, ncompHydro_);
HydroSystem<problem_t>::AddInternalEnergyPdV(rhs, stateInter, dx, faceVel, redoFlag);
HydroSystem<problem_t>::AddInternalEnergyPdV(rhs, stateOld, dx, avgFaceVel, redoFlag);
HydroSystem<problem_t>::PredictStep(stateOld, stateFinal, rhs, dt_lev, ncompHydro_, redoFlag);

// do first-order flux correction (FOFC)
Expand All @@ -1171,11 +1207,11 @@ auto RadhydroSimulation<problem_t>::advanceHydroAtLevel(amrex::MultiFab &state_o

// replace fluxes around troubled cells with Godunov fluxes
replaceFluxes(flux_rk2, FOfluxArrays, redoFlag);
replaceFluxes(faceVel, FOfaceVel, redoFlag); // needed for dual energy
replaceFluxes(avgFaceVel, FOfaceVel, redoFlag); // needed for dual energy

// re-do RK update
HydroSystem<problem_t>::ComputeRhsFromFluxes(rhs, flux_rk2, dx, ncompHydro_);
HydroSystem<problem_t>::AddInternalEnergyPdV(rhs, stateInter, dx, faceVel, redoFlag);
HydroSystem<problem_t>::AddInternalEnergyPdV(rhs, stateOld, dx, avgFaceVel, redoFlag);
HydroSystem<problem_t>::PredictStep(stateOld, stateFinal, rhs, dt_lev, ncompHydro_, redoFlag);

amrex::Gpu::streamSynchronizeAll(); // just in case
Expand Down Expand Up @@ -1213,6 +1249,33 @@ auto RadhydroSimulation<problem_t>::advanceHydroAtLevel(amrex::MultiFab &state_o
}
amrex::Gpu::streamSynchronizeAll();

// advect tracer particles using avgFaceVel
#ifdef AMREX_PARTICLES
if (do_tracers != 0) {
// copy avgFaceVel to state_new_fc_[lev]
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
amrex::Copy(state_new_fc_[lev][idim], avgFaceVel[idim], Physics_Indices<problem_t>::velFirstIndex, 0,
Physics_NumVars::numVelVars_per_dim, nghost_vel);
}

// fill ghost faces
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
fillBoundaryConditions(state_new_fc_[lev][idim], state_new_fc_[lev][idim], lev, time + 0.5 * dt_lev, quokka::centering::fc,
quokka::direction{idim}, AMRSimulation<problem_t>::InterpHookNone, AMRSimulation<problem_t>::InterpHookNone,
FillPatchType::fillpatch_function);
}

// copy state_new_fc_[lev] to avgFaceVel
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
amrex::Copy(avgFaceVel[idim], state_new_fc_[lev][idim], 0, Physics_Indices<problem_t>::velFirstIndex,
Physics_NumVars::numVelVars_per_dim, nghost_vel);
}

// advect particles
TracerPC->AdvectWithUmac(avgFaceVel.data(), lev, dt_lev);
}
#endif

// do Strang split source terms (second half-step)
addStrangSplitSourcesWithBuiltin(state_new_cc_[lev], lev, time + dt_lev, 0.5 * dt_lev);

Expand Down
9 changes: 6 additions & 3 deletions src/physics_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PHYSICS_INFO_HPP_

#include "physics_numVars.hpp"
#include <AMReX.H>

// this struct is specialized by the user application code.
template <typename problem_t> struct Physics_Traits {
Expand Down Expand Up @@ -38,9 +39,11 @@ template <typename problem_t> struct Physics_Indices {
static const int pscalarFirstIndex = Physics_NumVars::numHydroVars;
static const int radFirstIndex = pscalarFirstIndex + Physics_Traits<problem_t>::numPassiveScalars;
// face-centered
static const int nvarPerDim_fc = Physics_NumVars::numMHDVars_per_dim * static_cast<int>(Physics_Traits<problem_t>::is_mhd_enabled);
static const int nvarTotal_fc = Physics_NumVars::numMHDVars_tot * static_cast<int>(Physics_Traits<problem_t>::is_mhd_enabled);
static const int mhdFirstIndex = 0;
static const int nvarPerDim_fc = Physics_NumVars::numVelVars_per_dim * static_cast<int>(Physics_Traits<problem_t>::is_hydro_enabled) +
Physics_NumVars::numMHDVars_per_dim * static_cast<int>(Physics_Traits<problem_t>::is_mhd_enabled);
static const int nvarTotal_fc = AMREX_SPACEDIM * nvarPerDim_fc;
static const int velFirstIndex = 0;
static const int mhdFirstIndex = velFirstIndex + Physics_NumVars::numVelVars_per_dim;
};

#endif // PHYSICS_INFO_HPP_
2 changes: 2 additions & 0 deletions src/physics_numVars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ struct Physics_NumVars {
static const int numRadVars = 4;
// face-centred
static const int numMHDVars_per_dim = 1;
static const int numVelVars_per_dim = 1;
static const int numMHDVars_tot = AMREX_SPACEDIM * numMHDVars_per_dim;
static const int numVelVars_tot = AMREX_SPACEDIM * numVelVars_per_dim;
};

#endif // PHYSICS_NUMVARS_HPP_
Loading