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
Changes from 2 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
77 changes: 77 additions & 0 deletions src/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ template <typename problem_t> class AMRSimulation : public amrex::AmrCore
amrex::Long cellUpdates_ = 0;
amrex::Vector<amrex::Long> cellUpdatesEachLevel_;

// tracer particles
#ifdef AMREX_PARTICLES
void InitParticles(); // create tracer particles
int do_tracers = 0;
std::unique_ptr<amrex::AmrTracerParticleContainer> TracerPC;
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
#endif

// external objects
#ifdef AMREX_USE_ASCENT
Ascent ascent_;
Expand Down Expand Up @@ -568,6 +575,12 @@ template <typename problem_t> void AMRSimulation<problem_t>::setInitialCondition
InitFromScratch(time);
AverageDown();

#ifdef AMREX_PARTICLES
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
InitParticles();
}
#endif

if (checkpointInterval_ > 0) {
WriteCheckpointFile();
}
Expand Down Expand Up @@ -976,6 +989,13 @@ template <typename problem_t> auto AMRSimulation<problem_t>::timeStepWithSubcycl
}
}

#ifdef AMREX_PARTICLES
// redistribute particles
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
TracerPC->Redistribute(lev);
}
#endif

// do fix-up on all levels that have been re-gridded
for (int k = lev; k <= finest_level; ++k) {
FixupState(k);
Expand Down Expand Up @@ -1057,6 +1077,8 @@ template <typename problem_t> auto AMRSimulation<problem_t>::timeStepWithSubcycl
// do hyperbolic advance over all levels
advanceSingleTimestepAtLevel(lev, time, dt_[lev], nsubsteps[lev]);

// TODO(bwibking): advect tracer particles here

++istep[lev];
cellUpdates_ += CountCells(lev); // keep track of total number of cell updates
cellUpdatesEachLevel_[lev] += CountCells(lev);
Expand Down Expand Up @@ -1097,6 +1119,21 @@ template <typename problem_t> auto AMRSimulation<problem_t>::timeStepWithSubcycl
fillpatcher_[lev + 1].reset(); // because the data on lev have changed.
}

#ifdef AMREX_PARTICLES
// redistribute particles
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
int redistribute_ngrow = 0;
if ((iteration < nsubsteps[lev]) || (lev == 0)) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
if (lev == 0) {
redistribute_ngrow = 0;
} else {
redistribute_ngrow = iteration;
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
}
TracerPC->Redistribute(lev, TracerPC->finestLevel(), redistribute_ngrow);
}
}
#endif

return stepsLeft;
}

Expand Down Expand Up @@ -1640,6 +1677,22 @@ template <typename problem_t> void AMRSimulation<problem_t>::AverageDownTo(int c
}
}

#ifdef AMREX_PARTICLES
template <typename problem_t> void AMRSimulation<problem_t>::InitParticles()
{
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
AMREX_ASSERT(TracerPC == nullptr);
TracerPC = std::make_unique<AmrTracerParticleContainer>(this);
BenWibking marked this conversation as resolved.
Show resolved Hide resolved

AmrTracerParticleContainer::ParticleInitData pdata = {{AMREX_D_DECL(0.0, 0.0, 0.0)}, {}, {}, {}};
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
BenWibking marked this conversation as resolved.
Show resolved Hide resolved

TracerPC->SetVerbose(0);
TracerPC->InitOnePerCell(0.5, 0.5, 0.5, pdata);
TracerPC->Redistribute();
}
}
#endif

// get plotfile name
template <typename problem_t> auto AMRSimulation<problem_t>::PlotFileName(int lev) const -> std::string { return amrex::Concatenate(plot_file, lev, 5); }

Expand Down Expand Up @@ -1852,11 +1905,18 @@ template <typename problem_t> void AMRSimulation<problem_t>::WritePlotFile()
amrex::Print() << "Writing plotfile " << plotfilename << "\n";

#ifdef QUOKKA_USE_OPENPMD
// TODO(bwibking): write particles using openPMD
quokka::OpenPMDOutput::WriteFile(varnames, finest_level + 1, mf_ptr, Geom(), plot_file, tNew_[0], istep[0]);
WriteMetadataFile(plotfilename + ".yaml");
#else
amrex::WriteMultiLevelPlotfile(plotfilename, finest_level + 1, mf_ptr, varnames, Geom(), tNew_[0], istep, refRatio());
WriteMetadataFile(plotfilename + "/metadata.yaml");
#ifdef AMREX_PARTICLES
// write particles
if (do_tracers) {
TracerPC->WritePlotFile(plotfilename, "particles");
}
#endif // AMREX_PARTICLES
#endif
}

Expand Down Expand Up @@ -2178,6 +2238,13 @@ template <typename problem_t> void AMRSimulation<problem_t>::WriteCheckpointFile
}
}

// write particle data
#ifdef AMREX_PARTICLES
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
TracerPC->Checkpoint(checkpointname, "particles", true);
}
#endif

// create symlink and point it at this checkpoint dir
SetLastCheckpointSymlink(checkpointname);
}
Expand Down Expand Up @@ -2331,6 +2398,16 @@ template <typename problem_t> void AMRSimulation<problem_t>::ReadCheckpointFile(
}
}
}

#ifdef AMREX_PARTICLES
// read particle data
if (do_tracers) {
BenWibking marked this conversation as resolved.
Show resolved Hide resolved
AMREX_ASSERT(TracerPC == nullptr);
TracerPC = std::make_unique<AmrTracerParticleContainer>(this);
TracerPC->Restart(restart_chkfile, "particles");
}
#endif

areInitialConditionsDefined_ = true;
}

Expand Down
Loading