Skip to content

Commit

Permalink
enforceBC works for all levels (#566)
Browse files Browse the repository at this point in the history
* enforceBC is level-agnostic

* doc
  • Loading branch information
MaxThevenet authored Jul 20, 2021
1 parent fd43359 commit 0cf2735
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/particles/pusher/BeamParticleAdvance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "utils/Constants.H"
#include "GetAndSetPosition.H"
#include "utils/HipaceProfilerWrapper.H"
#include "GetDomainLev.H"

void
AdvanceBeamParticlesSlice (BeamParticleContainer& beam, Fields& fields, amrex::Geometry const& gm,
Expand Down Expand Up @@ -66,8 +67,9 @@ AdvanceBeamParticlesSlice (BeamParticleContainer& beam, Fields& fields, amrex::G

const auto getPosition = GetParticlePosition<BeamParticleContainer>(beam, offset);
const auto setPosition = SetParticlePosition<BeamParticleContainer>(beam, offset);
const auto enforceBC = EnforceBC<BeamParticleContainer>(beam, lev, offset);

const auto enforceBC = EnforceBC<BeamParticleContainer>(
beam, GetDomainLev(gm, box, 1, lev), GetDomainLev(gm, box, 0, lev),
gm.isPeriodicArray(), offset);
const amrex::Real zmin = xyzmin[2];

// Declare a DenseBins to pass it to doDepositionShapeN, although it will not be used.
Expand Down
14 changes: 9 additions & 5 deletions src/particles/pusher/GetAndSetPosition.H
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ struct EnforceBC

/** Constructor.
* \param a_ptile tile containing the macroparticles
* \param lev level of MR
* \param plo lower end of the physical domain where particles should stay
* \param phi upper end of the physical domain where particles should stay
* \param is_per periodicity
* \param a_offset offset to apply to the particle indices
*/
EnforceBC (T_ParTile& a_ptile, const int lev, int a_offset = 0) noexcept
EnforceBC (T_ParTile& a_ptile, const amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>& plo,
const amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>& phi,
const amrex::GpuArray<int,AMREX_SPACEDIM>& is_per, int a_offset = 0) noexcept
{

m_plo = Hipace::GetInstance().Geom(lev).ProbLoArray();
m_phi = Hipace::GetInstance().Geom(lev).ProbHiArray();
m_is_per = Hipace::GetInstance().Geom(lev).isPeriodicArray();
m_plo = plo;
m_phi = phi;
m_is_per = is_per;
AMREX_ALWAYS_ASSERT(m_is_per[0] == m_is_per[1]);

m_periodicity = {true, true, false};
Expand Down
31 changes: 31 additions & 0 deletions src/particles/pusher/GetDomainLev.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef HIPACE_GETDOMAINLEV_H_
#define HIPACE_GETDOMAINLEV_H_

#include <AMReX.H>

namespace
{
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> GetDomainLev (
const amrex::Geometry& gm, const amrex::Box& box, bool is_lo, int lev)
{
if (lev == 0) {
return is_lo ? gm.ProbLoArray() : gm.ProbHiArray();
} else {
const auto dx = gm.CellSizeArray();
const amrex::IntVect& small = box.smallEnd();
const amrex::IntVect& big = box.bigEnd();
const auto plo = gm.ProbLoArray();
if (is_lo) {
return {{AMREX_D_DECL(plo[0]+(small[0]+0.5)*dx[0],
plo[1]+(small[1]+0.5)*dx[1],
plo[2]+(small[2]+0.5)*dx[2])}};
} else {
return {{AMREX_D_DECL(plo[0]+(big[0]+0.5)*dx[0],
plo[1]+(big[1]+0.5)*dx[1],
plo[2]+(big[2]+0.5)*dx[2])}};
}
}
}
}

#endif // HIPACE_GETANDSETPOSITION_H_
5 changes: 4 additions & 1 deletion src/particles/pusher/PlasmaParticleAdvance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "PlasmaParticleAdvance.H"

#include "particles/PlasmaParticleContainer.H"
#include "GetDomainLev.H"
#include "FieldGather.H"
#include "PushPlasmaParticles.H"
#include "UpdateForceTerms.H"
Expand Down Expand Up @@ -109,7 +110,9 @@ AdvancePlasmaParticles (PlasmaParticleContainer& plasma, Fields & fields,
using PTileType = PlasmaParticleContainer::ParticleTileType;
const auto getPosition = GetParticlePosition<PTileType>(pti.GetParticleTile());
const auto SetPosition = SetParticlePosition<PTileType>(pti.GetParticleTile());
const auto enforceBC = EnforceBC<PTileType>(pti.GetParticleTile(), lev);
const auto enforceBC = EnforceBC<PTileType>(
pti.GetParticleTile(), GetDomainLev(gm, pti.tilebox(), 1, lev),
GetDomainLev(gm, pti.tilebox(), 0, lev), gm.isPeriodicArray());
const amrex::Real zmin = xyzmin[2];
const amrex::Real dz = dx[2];

Expand Down

0 comments on commit 0cf2735

Please sign in to comment.