1 #ifndef ERF_PARTICLE_DATA_H_
2 #define ERF_PARTICLE_DATA_H_
4 #ifdef ERF_USE_PARTICLES
12 #include <AMReX_ParmParse.H>
13 #include <AMReX_Print.H>
14 #include <AMReX_Vector.H>
15 #include <AMReX_Gpu.H>
23 typedef std::map<std::string, ERFPC*> ParticleSpeciesMap;
24 typedef std::vector<std::string> ParticlesNamesVector;
25 typedef std::list<std::string> ParticlesNamesList;
34 BL_PROFILE(
"ParticleData::ParticleData()");
36 amrex::ParmParse
pp(
"particles");
37 m_disable_particle_op =
false;
38 pp.query(
"disable_plt", m_disable_particle_op);
40 m_particle_species.clear();
42 m_namelist_unalloc.clear();
48 BL_PROFILE(
"ParticleData::~ParticleData()");
49 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
50 auto particles( m_particle_species[m_namelist[i]] );
53 m_particle_species.clear();
55 m_namelist_unalloc.clear();
59 void writePlotFile (
const std::string& a_fname )
const
61 BL_PROFILE(
"ParticleData::writePlotFile");
62 if (!m_disable_particle_op) {
63 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
64 auto name( m_namelist[i] );
65 auto particles( m_particle_species.at(name) );
66 particles->Checkpoint( a_fname, name,
true, particles->varNames() );
72 void Checkpoint (
const std::string& a_fname )
const
74 BL_PROFILE(
"ParticleData::Checkpoint()");
75 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
76 auto name( m_namelist[i] );
77 auto particles( m_particle_species.at(name) );
78 particles->Checkpoint( a_fname, name,
true, particles->varNames() );
83 void GetMeshPlotVarNames ( amrex::Vector<std::string>& a_names )
const
85 BL_PROFILE(
"ParticleData::GetMeshPlotVarNames()");
87 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
88 auto name( m_namelist[i] );
89 auto particles( m_particle_species.at(name) );
91 auto var_names = particles->meshPlotVarNames();
92 for (
int n = 0; n < var_names.size(); n++) {
93 a_names.push_back( std::string(name+
"_"+var_names[n]) );
98 void GetMeshPlotVar (
const std::string& a_var_name,
99 amrex::MultiFab& a_mf,
102 BL_PROFILE(
"ParticleData::GetMeshPlotVar()");
103 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
104 auto particle_name( m_namelist[i] );
105 auto particles( m_particle_species.at(particle_name) );
107 auto particle_var_names = particles->meshPlotVarNames();
109 for (
int n = 0; n < particle_var_names.size(); n++) {
111 std::string var_name = particle_name+
"_"+particle_var_names[n];
112 if ( var_name == a_var_name ) {
113 particles->computeMeshVar(particle_var_names[n], a_mf, a_lev);
118 amrex::Abort(
"Requested var_name not found in ParticleData::GetMeshPlotVar");
122 inline void Redistribute ()
124 BL_PROFILE(
"ParticleData::Redistribute()");
125 for (ParticlesNamesVector::size_type i = 0; i < m_namelist.size(); i++) {
126 m_particle_species[m_namelist[i]]->Redistribute();
131 inline ERFPC* GetSpecies (
const std::string& a_name )
133 BL_PROFILE(
"ParticleData::GetSpecies()");
134 ParticleSpeciesMap::iterator it (m_particle_species.find(a_name));
135 if (it == m_particle_species.end()) {
136 amrex::Print() <<
"ERROR: unable to find particle species with name \""
145 inline ERFPC* operator[] (
const std::string& a_name )
147 BL_PROFILE(
"ParticleData::operator[]");
148 ParticleSpeciesMap::iterator it (m_particle_species.find(a_name));
149 if (it == m_particle_species.end()) {
150 amrex::Print() <<
"ERROR: unable to find particle species with name \""
159 inline const ERFPC* GetSpecies (
const std::string& a_name )
const
161 BL_PROFILE(
"ParticleData::GetSpecies()");
162 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
163 if (it == m_particle_species.end()) {
164 amrex::Print() <<
"ERROR: unable to find particle species with name \""
173 inline const ERFPC* operator[] (
const std::string& a_name )
const
175 BL_PROFILE(
"ParticleData::operator[]");
176 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
177 if (it == m_particle_species.end()) {
178 amrex::Print() <<
"ERROR: unable to find particle species with name \""
187 inline void pushBack (
const std::string& a_name,
190 BL_PROFILE(
"ParticleData::pushBack()");
191 AMREX_ASSERT(!contains(a_name));
192 m_particle_species[a_name] = a_pc;
193 m_namelist.push_back(a_name);
197 inline void addName (
const std::string& a_name )
199 BL_PROFILE(
"ParticleData::addName()");
200 m_namelist_unalloc.push_back(a_name);
204 inline const ParticlesNamesVector& getNames ()
const
206 BL_PROFILE(
"ParticleData::getNames()");
211 inline ParticlesNamesList& getNamesUnalloc ()
213 BL_PROFILE(
"ParticleData::getNamesUnalloc()");
214 return m_namelist_unalloc;
218 inline bool contains (
const std::string& a_name )
const
220 BL_PROFILE(
"ParticleData::contains()");
221 ParticleSpeciesMap::const_iterator it (m_particle_species.find(a_name));
222 return (it != m_particle_species.end());
226 inline bool isEmpty ()
const
228 BL_PROFILE(
"ParticleData::isEmpty()");
229 return (m_particle_species.size() == 0);
236 ParticleSpeciesMap m_particle_species;
238 ParticlesNamesVector m_namelist;
240 ParticlesNamesList m_namelist_unalloc;
243 bool m_disable_particle_op;
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219