OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BoxLibLayout.h
Go to the documentation of this file.
1//
2// Class BoxLibLayout
3// In contrast to AMReX, OPAL is optimized for the
4// distribution of particles to cores. In AMReX the ParGDB object
5// is responsible for the particle to core distribution. This
6// layout is derived from this object and does all important
7// bunch updates. It is the interface for AMReX and Ippl.
8//
9// In AMReX, the geometry, i.e. physical domain, is fixed
10// during the whole computation. Particles leaving the domain
11// would be deleted. In order to prevent this we map the particles
12// onto the domain [-1, 1]^3. Furthermore, it makes sure
13// that we have enougth grid points to represent the bunch
14// when its charges are scattered on the grid for the self-field
15// computation.
16//
17// The self-field computation and the particle-to-core update
18// are performed in the particle mapped domain.
19//
20// Copyright (c) 2016 - 2020, Matthias Frey, Uldis Locans, Paul Scherrer Institut, Villigen PSI, Switzerland
21// All rights reserved
22//
23// Implemented as part of the PhD thesis
24// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
25//
26// This file is part of OPAL.
27//
28// OPAL is free software: you can redistribute it and/or modify
29// it under the terms of the GNU General Public License as published by
30// the Free Software Foundation, either version 3 of the License, or
31// (at your option) any later version.
32//
33// You should have received a copy of the GNU General Public License
34// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
35//
36#ifndef BOXLIB_LAYOUT_H
37#define BOXLIB_LAYOUT_H
38
41
42#include "Amr/AmrDefs.h"
43
44#include <AMReX_ParGDB.H>
45
46template<class T, unsigned Dim>
47class BoxLibLayout : public ParticleAmrLayout<T, Dim>,
48 public amrex::ParGDB
49{
50
51public:
56
63
76
77 typedef amrex::BaseFab<int> basefab_t;
78 typedef amrex::FabArray<basefab_t> mask_t;
79
87
94
95public:
96
100 BoxLibLayout();
101
105 BoxLibLayout(const BoxLibLayout* layout_p);
106
111 BoxLibLayout(int nGridPoints, int maxGridSize);
112
120 BoxLibLayout(const AmrGeometry_t &geom,
121 const AmrProcMap_t &dmap,
122 const AmrGrid_t &ba);
123
135 const AmrProcMapContainer_t &dmap,
136 const AmrGridContainer_t &ba,
137 const AmrIntArray_t &rr);
138
139
140 /*
141 * Overloaded functions of ParticleAmrLayout
142 */
143
152 void setBoundingBox(double dh);
153
161 void setDomainRatio(const std::vector<double>& ratio);
162
163
164 /*
165 * Functions of IpplParticleBase
166 */
167
173 const ParticleAttrib<char>* canSwap = 0);
174
187 int lev_min = 0, int lev_max = -1, bool isRegrid = false);
188
189
190 /*
191 * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
192 */
193
202 const unsigned int ip, int level) const;
203
210 AmrIntVect_t Index (SingleParticlePos_t &R, int lev) const;
211
212
213 /*
214 * Additional methods
215 */
216
217
223 void buildLevelMask(int lev, const int ncells = 1);
224
225 void clearLevelMask(int lev);
226
227 const std::unique_ptr<mask_t>& getLevelMask(int lev) const;
228
229
241 void resize(int maxLevel) {
242 int length = maxLevel + 1;
243 this->m_geom.resize(length);
244 this->m_dmap.resize(length);
245 this->m_ba.resize(length);
246 this->m_nlevels = length;
247 this->refRatio_m.resize(maxLevel);
248// this->m_rr.resize(maxLevel);
249 this->maxLevel_m = maxLevel;
250 }
251
252
259 void define(const AmrGeomContainer_t& geom) {
260 for (unsigned int i = 0; i < geom.size(); ++i)
261 this->m_geom[i] = geom[i];
262 }
263
264
272 for (unsigned int i = 0; i < refRatio.size(); ++i) {
273 refRatio_m[i] = refRatio[i];
274 }
275 }
276
277 /*
278 * ParGDB overwritten functions
279 */
280
286 inline bool LevelDefined (int level) const;
287
291 inline int finestLevel () const;
292
296 inline int maxLevel () const;
297
303 inline AmrIntVect_t refRatio (int level) const;
304
310 inline int MaxRefRatio (int level) const;
311
312private:
313
322 void initBaseBox_m(int nGridPoints, int maxGridSize, double dh = 0.04);
323
324
325 /*
326 * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
327 */
328
341 const unsigned int ip,
342 int lev_min = 0, int lev_max = -1, int nGrow = 0) const;
343
356 const unsigned int ip,
357 int lev_min = 0, int lev_max = -1) const;
358
368
379 const unsigned int ip,
380 int lev_min, int lev_max, int nGrow) const;
381
382private:
383
384 // don't use m_rr from ParGDB since it is the same refinement in all directions
386
387 /* mask to reduce spurious self-field forces at
388 * coarse-fine interfaces
389 */
390 std::vector<std::unique_ptr<mask_t> > masks_m;
391};
392
393#include "BoxLibLayout.hpp"
394
395#endif
amrex::Vector< AmrVectorField_t > AmrVectorFieldContainer_t
Definition: AmrDefs.h:42
amrex::DistributionMapping AmrProcMap_t
Definition: AmrDefs.h:38
amrex::Vector< AmrIntVect_t > AmrIntVectContainer_t
Definition: AmrDefs.h:49
amrex::Geometry AmrGeometry_t
Definition: AmrDefs.h:39
amrex::RealBox AmrDomain_t
Definition: AmrDefs.h:46
amrex::Box AmrBox_t
Definition: AmrDefs.h:50
amrex::Vector< AmrGeometry_t > AmrGeomContainer_t
Definition: AmrDefs.h:43
amrex::IntVect AmrIntVect_t
Definition: AmrDefs.h:48
amrex::Real AmrReal_t
Definition: AmrDefs.h:51
std::array< std::unique_ptr< AmrField_t >, AMREX_SPACEDIM > AmrVectorField_t
Definition: AmrDefs.h:37
amrex::MultiFab AmrField_t
Definition: AmrDefs.h:34
amrex::Vector< std::unique_ptr< AmrField_t > > AmrScalarFieldContainer_t
Definition: AmrDefs.h:41
amrex::Vector< int > AmrIntArray_t
Definition: AmrDefs.h:47
amrex::BoxArray AmrGrid_t
Definition: AmrDefs.h:40
amrex::Vector< AmrGrid_t > AmrGridContainer_t
Definition: AmrDefs.h:44
amrex::Vector< AmrProcMap_t > AmrProcMapContainer_t
Definition: AmrDefs.h:45
ParticleAmrLayout< T, Dim >::Index_t Index_t
Definition: BoxLibLayout.h:55
ParticleAttrib< Index_t > ParticleIndex_t
Definition: BoxLibLayout.h:62
void setBoundingBox(double dh)
ParticleAmrLayout< T, Dim >::ParticlePos_t ParticlePos_t
Definition: BoxLibLayout.h:61
amr::AmrBox_t AmrBox_t
Definition: BoxLibLayout.h:74
void define(const AmrIntVectContainer_t &refRatio)
Definition: BoxLibLayout.h:271
amr::AmrProcMapContainer_t AmrProcMapContainer_t
Definition: BoxLibLayout.h:69
amr::AmrDomain_t AmrDomain_t
Definition: BoxLibLayout.h:73
const std::unique_ptr< mask_t > & getLevelMask(int lev) const
void setDomainRatio(const std::vector< double > &ratio)
void locateParticle(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int lev_min, int lev_max, int nGrow) const
AmrIntVectContainer_t refRatio_m
Definition: BoxLibLayout.h:385
ParticleAmrLayout< T, Dim >::pair_t pair_t
Definition: BoxLibLayout.h:52
ParticleAmrLayout< T, Dim >::pair_iterator pair_iterator
Definition: BoxLibLayout.h:53
static Vector_t lowerBound
Definition: BoxLibLayout.h:86
void buildLevelMask(int lev, const int ncells=1)
void initBaseBox_m(int nGridPoints, int maxGridSize, double dh=0.04)
bool LevelDefined(int level) const
void clearLevelMask(int lev)
amr::AmrIntVect_t AmrIntVect_t
Definition: BoxLibLayout.h:70
amr::AmrIntArray_t AmrIntArray_t
Definition: BoxLibLayout.h:72
amr::AmrGeometry_t AmrGeometry_t
Definition: BoxLibLayout.h:66
amr::AmrVectorField_t AmrVectorField_t
Definition: BoxLibLayout.h:58
ParticleAmrLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
Definition: BoxLibLayout.h:54
amr::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
Definition: BoxLibLayout.h:60
int maxLevel() const
amrex::BaseFab< int > basefab_t
Definition: BoxLibLayout.h:77
amrex::FabArray< basefab_t > mask_t
Definition: BoxLibLayout.h:78
amr::AmrGeomContainer_t AmrGeomContainer_t
Definition: BoxLibLayout.h:67
bool PeriodicShift(SingleParticlePos_t R) const
static Vector_t upperBound
Definition: BoxLibLayout.h:93
amr::AmrGrid_t AmrGrid_t
Definition: BoxLibLayout.h:65
void update(IpplParticleBase< BoxLibLayout< T, Dim > > &PData, const ParticleAttrib< char > *canSwap=0)
amr::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
Definition: BoxLibLayout.h:59
amr::AmrGridContainer_t AmrGridContainer_t
Definition: BoxLibLayout.h:68
bool EnforcePeriodicWhere(AmrParticleBase< BoxLibLayout< T, Dim > > &prt, const unsigned int ip, int lev_min=0, int lev_max=-1) const
AmrIntVect_t Index(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int level) const
void resize(int maxLevel)
Definition: BoxLibLayout.h:241
void define(const AmrGeomContainer_t &geom)
Definition: BoxLibLayout.h:259
std::vector< std::unique_ptr< mask_t > > masks_m
Refinement ratios [0:finest_level-1].
Definition: BoxLibLayout.h:390
int finestLevel() const
amr::AmrProcMap_t AmrProcMap_t
Definition: BoxLibLayout.h:64
amr::AmrIntVectContainer_t AmrIntVectContainer_t
Definition: BoxLibLayout.h:71
amr::AmrReal_t AmrReal_t
Definition: BoxLibLayout.h:75
int MaxRefRatio(int level) const
amr::AmrField_t AmrField_t
Definition: BoxLibLayout.h:57
AmrIntVect_t refRatio(int level) const
bool Where(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int lev_min=0, int lev_max=-1, int nGrow=0) const
int maxLevel_m
Maximum level allowed.
ParticleLayout< T, Dim >::Index_t Index_t