REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_PC.H
Go to the documentation of this file.
1#ifndef REMORA_PC_H_
2#define REMORA_PC_H_
3
4#ifdef REMORA_USE_PARTICLES
5
6#include <string>
7#include <REMORA_Constants.H>
8#include <AMReX_Particles.H>
9
11{
12 enum {
13 k = 0,
14 ncomps
15 };
16};
17
19{
20 enum {
21 ncomps = 0
22 };
23};
24
26{
27 enum {
28 ncomps = 0
29 };
30};
31
33{
34 enum {
35 vx = 0,
39 ncomps
40 };
41};
42
44{
45 /* list of particle initializations */
46 const std::string init_box_uniform = "box";
47}
48
50{
51 const std::string tracers = "tracer_particles";
52 const std::string hydro = "hydro_particles";
53}
54
56{
57 template <typename P>
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
63 {
64 amrex::IntVect iv(
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])),
68 iv[0] += domain.smallEnd()[0];
69 iv[1] += domain.smallEnd()[1];
70 return iv;
71 }
72};
73
74template <typename 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 )
80{
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])),
84
85 if (a_height_arr) {
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;
96
97 if (a_p.pos(2) > zhi) {
99 } else if (a_p.pos(2) <= zlo) {
101 }
102 }
103}
104
105class REMORAPC : public amrex::ParticleContainer< REMORAParticlesRealIdxAoS::ncomps, // AoS real attributes
106 REMORAParticlesIntIdxAoS::ncomps, // AoS integer attributes
107 REMORAParticlesRealIdxSoA::ncomps, // SoA real attributes
108 REMORAParticlesIntIdxSoA::ncomps, // SoA integer attributes
109 amrex::DefaultAllocator,
110 REMORAParticlesAssignor >
111{
112 public:
113
114 /*! Constructor */
115 REMORAPC ( amrex::ParGDBBase* a_gdb,
116 const std::string& a_name = "particles" )
117 : amrex::ParticleContainer< REMORAParticlesRealIdxAoS::ncomps, // AoS real attributes
118 REMORAParticlesIntIdxAoS::ncomps, // AoS integer attributes
119 REMORAParticlesRealIdxSoA::ncomps, // SoA real attributes
120 REMORAParticlesIntIdxSoA::ncomps, // SoA integer attributes
123 {
124 BL_PROFILE("REMORAPCPC::REMORAPC()");
125 m_name = a_name;
126 readInputs();
127 }
128
129 /*! Constructor */
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, // AoS real attributes
135 REMORAParticlesIntIdxAoS::ncomps, // AoS real attributes
136 REMORAParticlesRealIdxSoA::ncomps, // SoA real attributes
137 REMORAParticlesIntIdxSoA::ncomps, // SoA integer attributes
140 {
141 BL_PROFILE("REMORAPCPC::REMORAPC()");
142 m_name = a_name;
143 readInputs();
144 }
145
146 /*! Initialize particles in domain */
147 virtual void InitializeParticles (const std::unique_ptr<amrex::MultiFab>& a_ptr = nullptr);
148
149 /*! Evolve particles for one time step */
150 virtual void EvolveParticles ( int a_lev,
151 amrex::Real a_dt_lev,
152 amrex::Vector<amrex::MultiFab const*>& a_flow_vel,
153 const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& a_z_phys_nd );
154
155 /*! Get real-type particle attribute names */
156 virtual amrex::Vector<std::string> varNames () const
157 {
158 BL_PROFILE("REMORAPCPC::varNames()");
159 return {AMREX_D_DECL("xvel","yvel","zvel"),"mass"};
160 }
161
162 /*! Get real-type particle attribute names */
163 virtual amrex::Vector<std::string> meshPlotVarNames () const
164 {
165 BL_PROFILE("REMORAPCPC::varNames()");
166 return {"mass_density"};
167 }
168
169 /*! Uses midpoint method to advance particles using flow velocity. */
170 virtual void AdvectWithFlow ( int a_lev,
171 amrex::Real a_dt,
172 amrex::Vector<amrex::MultiFab const*>& a_umac,
173 const std::unique_ptr<amrex::MultiFab>& a_z_height );
174
175 /*! Write the particles to a plotfile with x and y in physical coordinates */
176 void WritePlotFile ( const std::string& a_fname, const std::string& a_name,
177 const amrex::Vector<amrex::MultiFab>& a_xy ) const;
178
179 /*! Compute mass density */
180 virtual void massDensity ( amrex::MultiFab& a_mf, const int& a_lev, const int& a_comp = 0) const;
181
182 /*! Compute mesh variable from particles */
183 virtual void computeMeshVar( const std::string& a_var_name,
184 amrex::MultiFab& a_mf,
185 const int a_lev) const
186 {
187 if (a_var_name == "mass_density") {
189 } else {
190 a_mf.setVal(zero);
191 }
192 }
193
194 /*! Specify if particles should advect with flow */
195 inline void setAdvectWithFlow (bool a_flag)
196 {
197 BL_PROFILE("REMORAPCPC::setAdvectWithFlow()");
199 }
200
201 // the following functions should ideally be private or protected, but need to be
202 // public due to CUDA extended lambda capture rules
203
204 /*! Default particle initialization */
205 void initializeParticlesUniformDistributionInBox (const std::unique_ptr<amrex::MultiFab>& a_ptr,
206 const amrex::RealBox& particle_box);
207
208 protected:
209
210 bool m_advect_w_flow; /*!< advect with flow velocity */
211
212 amrex::RealBox m_particle_box; /*!< box within which to place particles */
213
214 std::string m_name; /*!< name of this particle species */
215
216 std::string m_initialization_type; /*!< initial particle distribution type */
217 int m_ppc_init; /*!< initial number of particles per cell */
218
219 /*! read inputs from file */
220 virtual void readInputs ();
221
222 private:
223
224 bool place_randomly_in_cells; /*!< place particles at random positions? */
225};
226
227#endif
228#endif
constexpr amrex::Real one
constexpr amrex::Real zero
mf_h setVal(geomdata.ProbHi(2))
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void update_location_idata(P &a_p, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &a_plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &a_dxi, const amrex::Array4< amrex::Real const > &a_height_arr)
Definition REMORA_PC.H:76
virtual void EvolveParticles(int a_lev, amrex::Real a_dt_lev, amrex::Vector< amrex::MultiFab const * > &a_flow_vel, const amrex::Vector< std::unique_ptr< amrex::MultiFab > > &a_z_phys_nd)
virtual void computeMeshVar(const std::string &a_var_name, amrex::MultiFab &a_mf, const int a_lev) const
Definition REMORA_PC.H:183
virtual void massDensity(amrex::MultiFab &a_mf, const int &a_lev, const int &a_comp=0) const
void WritePlotFile(const std::string &a_fname, const std::string &a_name, const amrex::Vector< amrex::MultiFab > &a_xy) const
std::string m_initialization_type
Definition REMORA_PC.H:216
virtual void AdvectWithFlow(int a_lev, amrex::Real a_dt, amrex::Vector< amrex::MultiFab const * > &a_umac, const std::unique_ptr< amrex::MultiFab > &a_z_height)
virtual amrex::Vector< std::string > meshPlotVarNames() const
Definition REMORA_PC.H:163
int m_ppc_init
Definition REMORA_PC.H:217
REMORAPC(const amrex::Geometry &a_geom, const amrex::DistributionMapping &a_dmap, const amrex::BoxArray &a_ba, const std::string &a_name="particles")
Definition REMORA_PC.H:130
amrex::RealBox m_particle_box
Definition REMORA_PC.H:212
void setAdvectWithFlow(bool a_flag)
Definition REMORA_PC.H:195
virtual amrex::Vector< std::string > varNames() const
Definition REMORA_PC.H:156
bool m_advect_w_flow
Definition REMORA_PC.H:210
void initializeParticlesUniformDistributionInBox(const std::unique_ptr< amrex::MultiFab > &a_ptr, const amrex::RealBox &particle_box)
virtual void InitializeParticles(const std::unique_ptr< amrex::MultiFab > &a_ptr=nullptr)
virtual void readInputs()
bool place_randomly_in_cells
Definition REMORA_PC.H:224
std::string m_name
Definition REMORA_PC.H:214
REMORAPC(amrex::ParGDBBase *a_gdb, const std::string &a_name="particles")
Definition REMORA_PC.H:115
const std::string init_box_uniform
Definition REMORA_PC.H:46
const std::string tracers
Definition REMORA_PC.H:51
const std::string hydro
Definition REMORA_PC.H:52
AMREX_GPU_HOST_DEVICE amrex::IntVect operator()(P const &p, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dxi, const amrex::Box &domain) const noexcept
Definition REMORA_PC.H:59