Skip to content

Commit 553f9e7

Browse files
authored
Merge pull request #202 from lanl/blb/swarm_refactor
2 parents 5bc3b2e + e460ec4 commit 553f9e7

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

external/parthenon

src/pgen/advection.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
123123
const auto num_tracers_total = tracer_pkg->Param<int>("num_tracers");
124124
const int number_block = num_tracers_total;
125125

126-
ParArrayND<int> new_indices;
127-
swarm->AddEmptyParticles(number_block, new_indices);
126+
auto new_particles_context = swarm->AddEmptyParticles(number_block);
128127

129128
auto &x = swarm->Get<Real>("x").Get();
130129
auto &y = swarm->Get<Real>("y").Get();
@@ -134,7 +133,7 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
134133
auto swarm_d = swarm->GetDeviceContext();
135134

136135
const int gid = pmb->gid;
137-
const int max_active_index = swarm->GetMaxActiveIndex();
136+
const int max_active_index = new_particles_context.GetNewParticlesMaxIndex();
138137
pmb->par_for(
139138
"ProblemGenerator::Torus::DistributeTracers", 0, max_active_index,
140139
KOKKOS_LAMBDA(const int n) {

src/pgen/torus.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ void PostInitializationModifier(ParameterInput *pin, Mesh *pmesh) {
665665

666666
const int num_tracers = std::round(num_tracers_total * number_block / number_mesh);
667667

668-
ParArrayND<int> new_indices;
669-
swarm->AddEmptyParticles(num_tracers, new_indices);
668+
auto new_particles_context = swarm->AddEmptyParticles(num_tracers);
670669

671670
auto &x = swarm->Get<Real>("x").Get();
672671
auto &y = swarm->Get<Real>("y").Get();
@@ -678,7 +677,7 @@ void PostInitializationModifier(ParameterInput *pin, Mesh *pmesh) {
678677
auto swarm_d = swarm->GetDeviceContext();
679678

680679
const int gid = pmb->gid;
681-
const int max_active_index = swarm->GetMaxActiveIndex();
680+
const int max_active_index = new_particles_context.GetNewParticlesMaxIndex();
682681
pmb->par_for(
683682
"ProblemGenerator::Torus::DistributeTracers", 0, max_active_index,
684683
KOKKOS_LAMBDA(const int n) {

src/radiation/mocmc.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ void MOCMCInitSamples(T *rc) {
128128
},
129129
Kokkos::Sum<int>(nsamp_tot));
130130

131-
ParArrayND<int> new_indices;
132-
auto new_mask = swarm->AddEmptyParticles(nsamp_tot, new_indices);
131+
auto new_particles_context = swarm->AddEmptyParticles(nsamp_tot);
133132

134133
// Calculate array of starting index for each zone to compute particles
135134
ParArrayND<int> starting_index("Starting index", nx_k, nx_j, nx_i);
@@ -185,7 +184,7 @@ void MOCMCInitSamples(T *rc) {
185184
Geometry::Tetrads tetrads(ucon, trial, cov_g);
186185

187186
for (int nsamp = 0; nsamp < static_cast<int>(v(b, dn, k, j, i)); nsamp++) {
188-
const int n = new_indices(start_idx + nsamp);
187+
const int n = new_particles_context.GetNewParticleIndex(start_idx + nsamp);
189188

190189
// Create particles at zone centers
191190
x(n) = minx_i + (i - ib.s + rng_gen.drand()) * dx_i;

src/radiation/monte_carlo.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ TaskStatus MonteCarloSourceParticles(MeshBlock *pmb, MeshBlockData<Real> *rc,
282282
const auto num_emitted = rad->Param<Real>("num_emitted");
283283
rad->UpdateParam<Real>("num_emitted", num_emitted + Nstot);
284284

285-
ParArrayND<int> new_indices;
286-
const auto new_particles_mask = swarm->AddEmptyParticles(Nstot, new_indices);
285+
const auto new_particles_context = swarm->AddEmptyParticles(Nstot);
287286

288287
auto &t = swarm->Get<Real>("t").Get();
289288
auto &x = swarm->Get<Real>("x").Get();
@@ -338,8 +337,8 @@ TaskStatus MonteCarloSourceParticles(MeshBlock *pmb, MeshBlockData<Real> *rc,
338337

339338
// Loop over particles to create in this zone
340339
for (int n = 0; n < dNs; n++) {
341-
const int m =
342-
new_indices(starting_index(sidx, k - kb.s, j - jb.s, i - ib.s) + n);
340+
const int m = new_particles_context.GetNewParticleIndex(
341+
starting_index(sidx, k - kb.s, j - jb.s, i - ib.s) + n);
343342

344343
// Set particle species
345344
swarm_species(m) = static_cast<int>(s);
@@ -403,8 +402,8 @@ TaskStatus MonteCarloSourceParticles(MeshBlock *pmb, MeshBlockData<Real> *rc,
403402
int dNs = v(iNs + sidx, k, j, i);
404403
// Loop over particles to create in this zone
405404
for (int n = 0; n < static_cast<int>(dNs); n++) {
406-
const int m =
407-
new_indices(starting_index(sidx, k - kb.s, j - jb.s, i - ib.s) + n);
405+
const int m = new_particles_context.GetNewParticleIndex(
406+
starting_index(sidx, k - kb.s, j - jb.s, i - ib.s) + n);
408407
swarm_d.MarkParticleForRemoval(m);
409408
}
410409
});

0 commit comments

Comments
 (0)