Skip to content

Commit 29bfb46

Browse files
author
fournier2
committed
tracer multigroup
1 parent 592b5b8 commit 29bfb46

3 files changed

Lines changed: 586 additions & 446 deletions

File tree

src/pgen/turbulence.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,20 @@ void ProblemInitTracerData(ParameterInput * /*pin*/,
204204
// (though it should probably not be changeable for restarts)
205205
tracer_pkg->AddParam("turbulence/n_lookback", n_lookback);
206206

207-
const auto swarm_name = tracer_pkg->Param<std::string>("swarm_name");
208-
// Using a vector to reduce code duplication.
209-
Metadata vreal_swarmvalue_metadata(
210-
{Metadata::Real, Metadata::Vector, Metadata::Restart},
211-
std::vector<int>{n_lookback});
212-
tracer_pkg->AddSwarmValue("s", swarm_name, vreal_swarmvalue_metadata);
213-
tracer_pkg->AddSwarmValue("sdot", swarm_name, vreal_swarmvalue_metadata);
207+
// Getting the number of populations and looping
208+
auto n_populations = tracer_pkg->Param<int>("n_populations");
209+
210+
for (int i = 0; i < n_populations; ++i) {
211+
212+
const auto swarm_name =
213+
tracer_pkg->Param<std::string>("swarm_name" + std::to_string(i));
214+
// Using a vector to reduce code duplication.
215+
Metadata vreal_swarmvalue_metadata(
216+
{Metadata::Real, Metadata::Vector, Metadata::Restart},
217+
std::vector<int>{n_lookback});
218+
tracer_pkg->AddSwarmValue("s", swarm_name, vreal_swarmvalue_metadata);
219+
tracer_pkg->AddSwarmValue("sdot", swarm_name, vreal_swarmvalue_metadata);
220+
}
214221
// Timestamps for the lookback entries
215222
tracer_pkg->AddParam<>("turbulence/t_lookback", std::vector<Real>(n_lookback),
216223
Params::Mutability::Restart);
@@ -513,12 +520,14 @@ TaskStatus ProblemFillTracers(MeshData<Real> *md, const parthenon::SimTime &tm,
513520
const Real dt) {
514521
const auto current_cycle = tm.ncycle;
515522

516-
auto tracers_pkg = md->GetParentPointer()->packages.Get("tracers");
517-
const auto n_lookback = tracers_pkg->Param<int>("turbulence/n_lookback");
523+
auto tracer_pkg = md->GetParentPointer()->packages.Get("tracers");
524+
const auto n_lookback = tracer_pkg->Param<int>("turbulence/n_lookback");
525+
const auto n_populations = tracer_pkg->Param<int>("n_populations");
526+
518527
// Params (which is storing t_lookback) is shared across all blocks so we update it
519528
// outside the block loop. Note, that this is a standard vector, so it cannot be used
520529
// in the kernel (but also don't need to be used as can directly update it)
521-
auto t_lookback = tracers_pkg->Param<std::vector<Real>>("turbulence/t_lookback");
530+
auto t_lookback = tracer_pkg->Param<std::vector<Real>>("turbulence/t_lookback");
522531
auto dncycle = static_cast<int>(Kokkos::pow(2, n_lookback - 2));
523532
auto idx = n_lookback - 1;
524533
while (dncycle > 0) {
@@ -530,20 +539,23 @@ TaskStatus ProblemFillTracers(MeshData<Real> *md, const parthenon::SimTime &tm,
530539
}
531540
t_lookback[0] = tm.time;
532541
// Write data back to Params dict
533-
tracers_pkg->UpdateParam("turbulence/t_lookback", t_lookback);
542+
tracer_pkg->UpdateParam("turbulence/t_lookback", t_lookback);
534543

535544
// TODO(pgrete) Benchmark atomic and potentially update to proper reduction instead of
536545
// atomics.
537546
// Used for the parallel reduction. Could be reused but this way it's initalized to
538547
// 0.
539548
// n_lookback + 1 as it also carries <s> and <sdot>
549+
550+
// Only doing it for the first population (can be expanded if necessary)
551+
540552
parthenon::ParArray2D<Real> corr("tracer correlations", 2, n_lookback + 1);
541553
int64_t num_particles_total = 0;
542554

543555
for (int b = 0; b < md->NumBlocks(); b++) {
544556
auto *pmb = md->GetBlockData(b)->GetBlockPointer();
545557
auto &sd = pmb->meshblock_data.Get()->GetSwarmData();
546-
auto &swarm = sd->Get("tracers");
558+
auto &swarm = sd->Get("tracers0");
547559

548560
// TODO(pgrete) cleanup once get swarm packs (currently in development upstream)
549561
// pull swarm vars

0 commit comments

Comments
 (0)