4 #ifdef ERF_USE_PARTICLES
7 #include <AMReX_Particles.H>
9 struct ERFParticlesIntIdxAoS
17 struct ERFParticlesRealIdxAoS
24 struct ERFParticlesIntIdxSoA
31 struct ERFParticlesRealIdxSoA
42 namespace ERFParticleInitializations
45 const std::string init_box_uniform =
"box";
48 namespace ERFParticleNames
50 const std::string tracers =
"tracer_particles";
51 const std::string hydro =
"hydro_particles";
54 struct ERFParticlesAssignor
58 amrex::IntVect operator() ( P
const& p,
59 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& plo,
60 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& dxi,
61 const amrex::Box& domain )
const noexcept
64 AMREX_D_DECL(
int(amrex::Math::floor((p.pos(0)-plo[0])*dxi[0])),
65 int(amrex::Math::floor((p.pos(1)-plo[1])*dxi[1])),
66 p.idata(ERFParticlesIntIdxAoS::k) ) );
67 iv[0] += domain.smallEnd()[0];
68 iv[1] += domain.smallEnd()[1];
74 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
75 void update_location_idata ( P& a_p,
76 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& a_plo,
77 amrex::GpuArray<amrex::Real,AMREX_SPACEDIM>
const& a_dxi,
78 const amrex::Array4<amrex::Real const>& a_height_arr )
80 amrex::IntVect iv(
int(amrex::Math::floor((a_p.pos(0)-a_plo[0])*a_dxi[0])),
81 int(amrex::Math::floor((a_p.pos(1)-a_plo[1])*a_dxi[1])),
82 a_p.idata(ERFParticlesIntIdxAoS::k) );
85 amrex::Real lx = (a_p.pos(0)-a_plo[0])*a_dxi[0] -
static_cast<amrex::Real
>(iv[0]);
86 amrex::Real ly = (a_p.pos(1)-a_plo[1])*a_dxi[1] -
static_cast<amrex::Real
>(iv[1]);
87 auto zlo = a_height_arr(iv[0] ,iv[1] ,iv[2] ) * (1.0-lx) * (1.0-ly) +
88 a_height_arr(iv[0]+1,iv[1] ,iv[2] ) * lx * (1.0-ly) +
89 a_height_arr(iv[0] ,iv[1]+1,iv[2] ) * (1.0-lx) * ly +
90 a_height_arr(iv[0]+1,iv[1]+1,iv[2] ) * lx * ly;
91 auto zhi = a_height_arr(iv[0] ,iv[1] ,iv[2]+1) * (1.0-lx) * (1.0-ly) +
92 a_height_arr(iv[0]+1,iv[1] ,iv[2]+1) * lx * (1.0-ly) +
93 a_height_arr(iv[0] ,iv[1]+1,iv[2]+1) * (1.0-lx) * ly +
94 a_height_arr(iv[0]+1,iv[1]+1,iv[2]+1) * lx * ly;
96 if (a_p.pos(2) > zhi) {
97 a_p.idata(ERFParticlesIntIdxAoS::k) += 1;
98 }
else if (a_p.pos(2) <= zlo) {
99 a_p.idata(ERFParticlesIntIdxAoS::k) -= 1;
104 class ERFPC :
public amrex::ParticleContainer< ERFParticlesRealIdxAoS::ncomps,
105 ERFParticlesIntIdxAoS::ncomps,
106 ERFParticlesRealIdxSoA::ncomps,
107 ERFParticlesIntIdxSoA::ncomps,
108 amrex::DefaultAllocator,
109 ERFParticlesAssignor >
114 ERFPC ( amrex::ParGDBBase* a_gdb,
115 const std::string& a_name =
"particles" )
116 :
amrex::ParticleContainer< ERFParticlesRealIdxAoS::ncomps,
117 ERFParticlesIntIdxAoS::ncomps,
118 ERFParticlesRealIdxSoA::ncomps,
119 ERFParticlesIntIdxSoA::ncomps,
120 amrex::DefaultAllocator,
121 ERFParticlesAssignor> (a_gdb)
123 BL_PROFILE(
"ERFPCPC::ERFPC()");
129 ERFPC (
const amrex::Geometry& a_geom,
130 const amrex::DistributionMapping& a_dmap,
131 const amrex::BoxArray& a_ba,
132 const std::string& a_name =
"particles" )
133 :
amrex::ParticleContainer< ERFParticlesRealIdxAoS::ncomps,
134 ERFParticlesIntIdxAoS::ncomps,
135 ERFParticlesRealIdxSoA::ncomps,
136 ERFParticlesIntIdxSoA::ncomps,
137 amrex::DefaultAllocator,
138 ERFParticlesAssignor> ( a_geom, a_dmap, a_ba )
140 BL_PROFILE(
"ERFPCPC::ERFPC()");
146 virtual void InitializeParticles (
const std::unique_ptr<amrex::MultiFab>& a_ptr =
nullptr);
149 virtual void EvolveParticles (
int,
151 amrex::Vector<amrex::Vector<amrex::MultiFab>>&,
152 const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& );
155 virtual amrex::Vector<std::string> varNames ()
const
157 BL_PROFILE(
"ERFPCPC::varNames()");
158 return {AMREX_D_DECL(
"xvel",
"yvel",
"zvel"),
"mass"};
162 virtual amrex::Vector<std::string> meshPlotVarNames ()
const
164 BL_PROFILE(
"ERFPCPC::varNames()");
165 return {
"mass_density"};
169 virtual void AdvectWithFlow ( amrex::MultiFab*,
172 const std::unique_ptr<amrex::MultiFab>& );
175 virtual void AdvectWithGravity (
int,
177 const std::unique_ptr<amrex::MultiFab>& );
180 virtual void massDensity ( amrex::MultiFab&,
const int&,
const int& a_comp = 0)
const;
183 virtual void computeMeshVar(
const std::string& a_var_name,
184 amrex::MultiFab& a_mf,
185 const int a_lev)
const
187 if (a_var_name ==
"mass_density") {
188 massDensity( a_mf, a_lev );
195 inline void setAdvectWithFlow (
bool a_flag)
197 BL_PROFILE(
"ERFPCPC::setAdvectWithFlow()");
198 m_advect_w_flow = a_flag;
201 inline void setAdvectWithGravity (
bool a_flag)
203 BL_PROFILE(
"ERFPCPC::setAdvectWithGravity()");
204 m_advect_w_gravity = a_flag;
211 void initializeParticlesUniformDistributionInBox (
const std::unique_ptr<amrex::MultiFab>& a_ptr,
212 const amrex::RealBox& particle_box);
216 bool m_advect_w_flow;
217 bool m_advect_w_gravity;
219 amrex::RealBox m_particle_box;
223 std::string m_initialization_type;
226 bool m_stable_redistribute;
229 virtual void readInputs ();
233 bool place_randomly_in_cells;
Definition: ERF_ConsoleIO.cpp:12