REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_ParticleData.H
Go to the documentation of this file.
1#ifndef _REMORA_PARTICLE_DATA_H_
2#define _REMORA_PARTICLE_DATA_H_
3
4#ifdef REMORA_USE_PARTICLES
5
6#include <map>
7#include <vector>
8#include <list>
9#include <string>
10#include <iostream>
11
12#include <AMReX_ParmParse.H>
13#include <AMReX_Print.H>
14#include <AMReX_Vector.H>
15#include <AMReX_Gpu.H>
16
17#include <REMORA_PC.H>
18
19/**
20 * Container holding many of the particle-related data and options
21 */
22
23typedef std::map<std::string, REMORAPC*> ParticleSpeciesMap;
24typedef std::vector<std::string> ParticlesNamesVector;
25typedef std::list<std::string> ParticlesNamesList;
26
28{
29 public:
30
31 /*! Constructor */
33 {
34 BL_PROFILE("ParticleData::ParticleData()");
35 m_particle_species.clear();
36 m_namelist.clear();
37 m_namelist_unalloc.clear();
38 }
39
40 /*! Destructor */
42 {
43 BL_PROFILE("ParticleData::~ParticleData()");
44 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
46 delete particles;
47 }
48 m_particle_species.clear();
49 m_namelist.clear();
50 m_namelist_unalloc.clear();
51 }
52
53 /*! Write checkpoint files */
54 void Checkpoint ( const std::string& a_fname ) const
55 {
56 BL_PROFILE("ParticleData::Checkpoint()");
57 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
58 auto name( m_namelist[i] );
59 auto particles( m_particle_species.at(name) );
60 particles->Checkpoint( a_fname, name, true, particles->varNames() );
61 }
62 }
63
64 /*! Write particles to a plotfile, with x and y in physical coordinates */
65 void writePlotFile ( const std::string& a_fname,
66 const amrex::Vector<amrex::MultiFab>& a_xy ) const
67 {
68 BL_PROFILE("ParticleData::writePlotFile()");
69 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
70 auto name( m_namelist[i] );
71 auto particles( m_particle_species.at(name) );
72 particles->WritePlotFile( a_fname, name, a_xy );
73 }
74 }
75
76 /*! Read from restart file */
77 void Restart ( amrex::ParGDBBase* a_gdb, const std::string& a_fname )
78 {
79 BL_PROFILE("ParticleData::Restart()");
81 for (auto it = m_namelist_unalloc.begin(); it != m_namelist_unalloc.end(); ++it) {
82 std::string species_name( *it );
84 pc->Restart(a_fname, species_name );
86 }
87 m_namelist_unalloc.clear();
88 }
89
90 /*! Get mesh plot quantities from each particle container */
91 void GetMeshPlotVarNames ( amrex::Vector<std::string>& a_names ) const
92 {
93 BL_PROFILE("ParticleData::GetMeshPlotVarNames()");
94 a_names.clear();
95 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
96 auto name( m_namelist[i] );
97 auto particles( m_particle_species.at(name) );
98
99 auto var_names = particles->meshPlotVarNames();
100 for (int n = 0; n < var_names.size(); n++) {
101 a_names.push_back( std::string(name+"_"+var_names[n]) );
102 }
103 }
104 }
105
106 void GetMeshPlotVar ( const std::string& a_var_name,
107 amrex::MultiFab& a_mf,
108 const int a_lev )
109 {
110 BL_PROFILE("ParticleData::GetMeshPlotVar()");
111 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
112 auto particle_name( m_namelist[i] );
114
115 auto particle_var_names = particles->meshPlotVarNames();
116
117 for (int n = 0; n < particle_var_names.size(); n++) {
118
119 std::string var_name = particle_name+"_"+particle_var_names[n];
120 if ( var_name == a_var_name ) {
121 particles->computeMeshVar(particle_var_names[n], a_mf, a_lev);
122 return;
123 }
124 }
125 }
126 amrex::Abort("Requested var_name not found in ParticleData::GetMeshPlotVar");
127 }
128
129 /*! Redistribute/rebalance particles data */
130 inline void Redistribute ()
131 {
132 BL_PROFILE("ParticleData::Redistribute()");
133 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
134 m_particle_species[m_namelist[i]]->Redistribute();
135 }
136 }
137
138 /*! Get species of a given name */
139 inline REMORAPC* GetSpecies ( const std::string& a_name )
140 {
141 BL_PROFILE("ParticleData::GetSpecies()");
142 ParticleSpeciesMap::iterator it (m_particle_species.find(a_name));
143 if (it == m_particle_species.end()) {
144 amrex::Print() << "ERROR: unable to find particle species with name \""
145 << a_name << "\"!";
146 return nullptr;
147 } else {
148 return it->second;
149 }
150 }
151
152 /*! accessor */
153 inline REMORAPC* operator[] ( const std::string& a_name )
154 {
155 BL_PROFILE("ParticleData::operator[]");
156 ParticleSpeciesMap::iterator it (m_particle_species.find(a_name));
157 if (it == m_particle_species.end()) {
158 amrex::Print() << "ERROR: unable to find particle species with name \""
159 << a_name << "\"!";
160 return nullptr;
161 } else {
162 return it->second;
163 }
164 }
165
166 /*! Get species of a given name (const version) */
167 inline const REMORAPC* GetSpecies ( const std::string& a_name ) const
168 {
169 BL_PROFILE("ParticleData::GetSpecies()");
170 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
171 if (it == m_particle_species.end()) {
172 amrex::Print() << "ERROR: unable to find particle species with name \""
173 << a_name << "\"!";
174 return nullptr;
175 } else {
176 return it->second;
177 }
178 }
179
180 /*! accessor */
181 inline const REMORAPC* operator[] ( const std::string& a_name ) const
182 {
183 BL_PROFILE("ParticleData::operator[]");
184 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
185 if (it == m_particle_species.end()) {
186 amrex::Print() << "ERROR: unable to find particle species with name \""
187 << a_name << "\"!";
188 return nullptr;
189 } else {
190 return it->second;
191 }
192 }
193
194 /*! Add a particle species to this container */
195 inline void pushBack (const std::string& a_name,
196 REMORAPC* const a_pc )
197 {
198 BL_PROFILE("ParticleData::pushBack()");
201 m_namelist.push_back(a_name);
202 }
203
204 /*! Add a name; particle container will be initialized later */
205 inline void addName (const std::string& a_name )
206 {
207 BL_PROFILE("ParticleData::addName()");
208 m_namelist_unalloc.push_back(a_name);
209 }
210
211 /*! Returns list of names of particle species */
212 inline const ParticlesNamesVector& getNames () const
213 {
214 BL_PROFILE("ParticleData::getNames()");
215 return m_namelist;
216 }
217
218 /*! Returns list of names of particle species that are unallocated */
220 {
221 BL_PROFILE("ParticleData::getNamesUnalloc()");
222 return m_namelist_unalloc;
223 }
224
225 /*! queries if container has species of a certain name */
226 inline bool contains ( const std::string& a_name ) const
227 {
228 BL_PROFILE("ParticleData::contains()");
229 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
230 return (it != m_particle_species.end());
231 }
232
233 /*! query if container is empty */
234 inline bool isEmpty () const
235 {
236 BL_PROFILE("ParticleData::isEmpty()");
237 return (m_particle_species.size() == 0);
238 }
239
240
241 private:
242
243 /*! Vector of all particle species */
245 /*! Vector of particle species names */
247 /*! List with names of unallocated species */
249};
250
251#endif
252#endif
253
mf_h setVal(geomdata.ProbHi(2))
std::map< std::string, REMORAPC * > ParticleSpeciesMap
std::list< std::string > ParticlesNamesList
std::vector< std::string > ParticlesNamesVector
bool contains(const std::string &a_name) const
ParticlesNamesList & getNamesUnalloc()
void pushBack(const std::string &a_name, REMORAPC *const a_pc)
ParticlesNamesList m_namelist_unalloc
const REMORAPC * GetSpecies(const std::string &a_name) const
void GetMeshPlotVar(const std::string &a_var_name, amrex::MultiFab &a_mf, const int a_lev)
bool isEmpty() const
ParticleSpeciesMap m_particle_species
void writePlotFile(const std::string &a_fname, const amrex::Vector< amrex::MultiFab > &a_xy) const
const ParticlesNamesVector & getNames() const
void addName(const std::string &a_name)
REMORAPC * GetSpecies(const std::string &a_name)
void Restart(amrex::ParGDBBase *a_gdb, const std::string &a_fname)
REMORAPC * operator[](const std::string &a_name)
void Checkpoint(const std::string &a_fname) const
void GetMeshPlotVarNames(amrex::Vector< std::string > &a_names) const
ParticlesNamesVector m_namelist