Skip to content

Commit

Permalink
Minor refactoring of refined injection for AddPlasmaFlux
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiLehe committed Sep 15, 2024
1 parent 01a6d18 commit 89c684f
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,23 +1450,23 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector,
amrex::ParallelForRNG(overlap_box, [=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept
{
const IntVect iv(AMREX_D_DECL(i, j, k));
amrex::ignore_unused(j,k);

auto lo = getCellCoords(overlap_corner, dx, {0._rt, 0._rt, 0._rt}, iv);
auto hi = getCellCoords(overlap_corner, dx, {1._rt, 1._rt, 1._rt}, iv);

const int num_ppc_int = static_cast<int>(num_ppc_real + amrex::Random(engine));
// Skip cells that do not overlap with the injection plane
if (!flux_pos->overlapsWith(lo, hi)) return;

if (flux_pos->overlapsWith(lo, hi))
{
auto index = overlap_box.index(iv);
int r;
if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) {
r = compute_area_weights(lrrfac, flux_normal_axis);
} else {
r = 1;
}
pcounts[index] = num_ppc_int*r;
// Determine how many particles to inject in this cell
auto index = overlap_box.index(iv);
const int num_ppc_int = static_cast<int>(num_ppc_real + amrex::Random(engine));
// Take into account refined injection region
int r = 1;
if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) {
r = compute_area_weights(lrrfac, flux_normal_axis);
}
amrex::ignore_unused(j,k);
pcounts[index] = num_ppc_int*r;
});

// Max number of new particles. All of them are created,
Expand Down Expand Up @@ -1533,24 +1533,18 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector,
[=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept
{
const IntVect iv = IntVect(AMREX_D_DECL(i, j, k));
amrex::ignore_unused(j,k);
const auto index = overlap_box.index(iv);

Real scale_fac = compute_scale_fac_area(dx, num_ppc_real, flux_normal_axis);

auto lo = getCellCoords(overlap_corner, dx, {0._rt, 0._rt, 0._rt}, iv);
auto hi = getCellCoords(overlap_corner, dx, {1._rt, 1._rt, 1._rt}, iv);

if (flux_pos->overlapsWith(lo, hi))
{
int r;
if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) {
r = compute_area_weights(lrrfac, flux_normal_axis);
} else {
r = 1;
}
if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) {
int r = compute_area_weights(lrrfac, flux_normal_axis);
scale_fac /= r;
}
amrex::ignore_unused(j,k);

for (int i_part = 0; i_part < pcounts[index]; ++i_part)
{
Expand Down

0 comments on commit 89c684f

Please sign in to comment.