4#ifdef REMORA_USE_PARTICLES
8#include <AMReX_Particles.H>
10struct REMORAParticlesIntIdxAoS
18struct REMORAParticlesRealIdxAoS
25struct REMORAParticlesIntIdxSoA
32struct REMORAParticlesRealIdxSoA
43namespace REMORAParticleInitializations
46 const std::string init_box_uniform =
"box";
49namespace REMORAParticleNames
51 const std::string tracers =
"tracer_particles";
52 const std::string hydro =
"hydro_particles";
55struct REMORAParticlesAssignor
59 amrex::IntVect operator() ( P
const& p,
60 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& plo,
61 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const&
dxi,
62 const amrex::Box& domain )
const noexcept
65 AMREX_D_DECL(
int(amrex::Math::floor((p.pos(0)-plo[0])*
dxi[0])),
66 int(amrex::Math::floor((p.pos(1)-plo[1])*
dxi[1])),
67 p.idata(REMORAParticlesIntIdxAoS::k) ) );
68 iv[0] += domain.smallEnd()[0];
69 iv[1] += domain.smallEnd()[1];
75AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
76void update_location_idata ( P& a_p,
77 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& a_plo,
78 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& a_dxi,
79 const amrex::Array4<amrex::Real const>& a_height_arr )
81 amrex::IntVect iv(
int(amrex::Math::floor((a_p.pos(0)-a_plo[0])*a_dxi[0])),
82 int(amrex::Math::floor((a_p.pos(1)-a_plo[1])*a_dxi[1])),
83 a_p.idata(REMORAParticlesIntIdxAoS::k) );
86 amrex::Real lx = (a_p.pos(0)-a_plo[0])*a_dxi[0] -
static_cast<amrex::Real
>(iv[0]);
87 amrex::Real ly = (a_p.pos(1)-a_plo[1])*a_dxi[1] -
static_cast<amrex::Real
>(iv[1]);
88 auto zlo = a_height_arr(iv[0] ,iv[1] ,iv[2] ) * (
one-lx) * (
one-ly) +
89 a_height_arr(iv[0]+1,iv[1] ,iv[2] ) * lx * (
one-ly) +
90 a_height_arr(iv[0] ,iv[1]+1,iv[2] ) * (
one-lx) * ly +
91 a_height_arr(iv[0]+1,iv[1]+1,iv[2] ) * lx * ly;
92 auto zhi = a_height_arr(iv[0] ,iv[1] ,iv[2]+1) * (
one-lx) * (
one-ly) +
93 a_height_arr(iv[0]+1,iv[1] ,iv[2]+1) * lx * (
one-ly) +
94 a_height_arr(iv[0] ,iv[1]+1,iv[2]+1) * (
one-lx) * ly +
95 a_height_arr(iv[0]+1,iv[1]+1,iv[2]+1) * lx * ly;
97 if (a_p.pos(2) > zhi) {
98 a_p.idata(REMORAParticlesIntIdxAoS::k) += 1;
99 }
else if (a_p.pos(2) <= zlo) {
100 a_p.idata(REMORAParticlesIntIdxAoS::k) -= 1;
105class REMORAPC :
public amrex::ParticleContainer< REMORAParticlesRealIdxAoS::ncomps,
106 REMORAParticlesIntIdxAoS::ncomps,
107 REMORAParticlesRealIdxSoA::ncomps,
108 REMORAParticlesIntIdxSoA::ncomps,
109 amrex::DefaultAllocator,
110 REMORAParticlesAssignor >
115 REMORAPC ( amrex::ParGDBBase* a_gdb,
116 const std::string& a_name =
"particles" )
117 :
amrex::ParticleContainer< REMORAParticlesRealIdxAoS::ncomps,
118 REMORAParticlesIntIdxAoS::ncomps,
119 REMORAParticlesRealIdxSoA::ncomps,
120 REMORAParticlesIntIdxSoA::ncomps,
121 amrex::DefaultAllocator,
122 REMORAParticlesAssignor> (a_gdb)
124 BL_PROFILE(
"REMORAPCPC::REMORAPC()");
130 REMORAPC (
const amrex::Geometry& a_geom,
131 const amrex::DistributionMapping& a_dmap,
132 const amrex::BoxArray& a_ba,
133 const std::string& a_name =
"particles" )
134 :
amrex::ParticleContainer< REMORAParticlesRealIdxAoS::ncomps,
135 REMORAParticlesIntIdxAoS::ncomps,
136 REMORAParticlesRealIdxSoA::ncomps,
137 REMORAParticlesIntIdxSoA::ncomps,
138 amrex::DefaultAllocator,
139 REMORAParticlesAssignor> ( a_geom, a_dmap, a_ba )
141 BL_PROFILE(
"REMORAPCPC::REMORAPC()");
147 virtual void InitializeParticles (
const std::unique_ptr<amrex::MultiFab>& a_ptr =
nullptr);
150 virtual void EvolveParticles (
int lev,
152 amrex::Vector<amrex::MultiFab const*>& a_flow_vel,
153 const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& );
156 virtual amrex::Vector<std::string> varNames ()
const
158 BL_PROFILE(
"REMORAPCPC::varNames()");
159 return {AMREX_D_DECL(
"xvel",
"yvel",
"zvel"),
"mass"};
163 virtual amrex::Vector<std::string> meshPlotVarNames ()
const
165 BL_PROFILE(
"REMORAPCPC::varNames()");
166 return {
"mass_density"};
170 virtual void AdvectWithFlow (
int lev,
172 amrex::Vector<amrex::MultiFab const*>&,
173 const std::unique_ptr<amrex::MultiFab>& );
176 virtual void massDensity ( amrex::MultiFab&,
const int&,
const int& a_comp = 0)
const;
179 virtual void computeMeshVar(
const std::string& a_var_name,
180 amrex::MultiFab& a_mf,
181 const int a_lev)
const
183 if (a_var_name ==
"mass_density") {
184 massDensity( a_mf, a_lev );
191 inline void setAdvectWithFlow (
bool a_flag)
193 BL_PROFILE(
"REMORAPCPC::setAdvectWithFlow()");
194 m_advect_w_flow = a_flag;
201 void initializeParticlesUniformDistributionInBox (
const std::unique_ptr<amrex::MultiFab>& a_ptr,
202 const amrex::RealBox& particle_box);
206 bool m_advect_w_flow;
208 amrex::RealBox m_particle_box;
212 std::string m_initialization_type;
216 virtual void readInputs ();
220 bool place_randomly_in_cells;
constexpr amrex::Real one
constexpr amrex::Real zero