OPAL (Object Oriented Parallel Accelerator Library)  2024.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 
46 template<class T, unsigned Dim>
47 class BoxLibLayout: public ParticleAmrLayout<T, Dim>,
48  public amrex::ParGDB
49 {
50 
51 public:
56 
63 
76 
77  typedef amrex::BaseFab<int> basefab_t;
78  typedef amrex::FabArray<basefab_t> mask_t;
79 
87 
94 
95 
96 public:
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 
134  BoxLibLayout(const AmrGeomContainer_t& geom,
135  const AmrProcMapContainer_t& dmap,
136  const AmrGridContainer_t& ba,
137  const AmrIntArray_t& rr);
138 
139  /*
140  * Overloaded functions of ParticleAmrLayout
141  */
142 
151  void setBoundingBox(double dh);
152 
160  void setDomainRatio(const std::vector<double>& ratio);
161 
162  /*
163  * Functions of IpplParticleBase
164  */
165 
171  const ParticleAttrib<char>* canSwap = 0);
172 
185  int lev_min = 0, int lev_max = -1, bool isRegrid = false);
186 
187  /*
188  * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
189  */
190 
199  const unsigned int ip, int level) const;
200 
207  AmrIntVect_t Index (SingleParticlePos_t &R, int lev) const;
208 
209  /*
210  * Additional methods
211  */
212 
218  void buildLevelMask(int lev, const int ncells = 1);
219 
220  void clearLevelMask(int lev);
221 
222  const std::unique_ptr<mask_t>& getLevelMask(int lev) const;
223 
235  void resize(int maxLevel) {
236  int length = maxLevel + 1;
237  this->m_geom.resize(length);
238  this->m_dmap.resize(length);
239  this->m_ba.resize(length);
240  this->m_nlevels = length;
241  this->refRatio_m.resize(maxLevel);
242 // this->m_rr.resize(maxLevel);
243  this->maxLevel_m = maxLevel;
244  }
245 
252  void define(const AmrGeomContainer_t& geom) {
253  for (unsigned int i = 0; i < geom.size(); ++i)
254  this->m_geom[i] = geom[i];
255  }
256 
264  for (unsigned int i = 0; i < refRatio.size(); ++i) {
265  refRatio_m[i] = refRatio[i];
266  }
267  }
268 
269  /*
270  * ParGDB overwritten functions
271  */
272 
278  inline bool LevelDefined (int level) const;
279 
283  inline int finestLevel () const;
284 
288  inline int maxLevel () const;
289 
295  inline AmrIntVect_t refRatio (int level) const;
296 
302  inline int MaxRefRatio (int level) const;
303 
304 
305 private:
314  void initBaseBox_m(int nGridPoints, int maxGridSize, double dh = 0.04);
315 
316 
317  /*
318  * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
319  */
320 
333  const unsigned int ip,
334  int lev_min = 0, int lev_max = -1, int nGrow = 0) const;
335 
348  const unsigned int ip,
349  int lev_min = 0, int lev_max = -1) const;
350 
359  bool PeriodicShift (SingleParticlePos_t R) const;
360 
371  const unsigned int ip,
372  int lev_min, int lev_max, int nGrow) const;
373 
374 
375 private:
376  // don't use m_rr from ParGDB since it is the same refinement in all directions
378 
379  /* mask to reduce spurious self-field forces at
380  * coarse-fine interfaces
381  */
382  std::vector<std::unique_ptr<mask_t> > masks_m;
383 };
384 
385 #include "BoxLibLayout.hpp"
386 
387 #endif
amr::AmrIntVectContainer_t AmrIntVectContainer_t
Definition: BoxLibLayout.h:71
void clearLevelMask(int lev)
amr::AmrReal_t AmrReal_t
Definition: BoxLibLayout.h:75
amrex::Vector< AmrProcMap_t > AmrProcMapContainer_t
Definition: AmrDefs.h:45
amr::AmrGeometry_t AmrGeometry_t
Definition: BoxLibLayout.h:66
ParticleAmrLayout< T, Dim >::Index_t Index_t
Definition: BoxLibLayout.h:55
int maxLevel() const
void buildLevelMask(int lev, const int ncells=1)
ParticleAmrLayout< T, Dim >::pair_t pair_t
Definition: BoxLibLayout.h:52
AmrIntVect_t refRatio(int level) const
AmrIntVect_t Index(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int level) const
std::vector< std::unique_ptr< mask_t > > masks_m
Refinement ratios [0:finest_level-1].
Definition: BoxLibLayout.h:382
amrex::BoxArray AmrGrid_t
Definition: AmrDefs.h:40
amr::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
Definition: BoxLibLayout.h:60
amr::AmrIntArray_t AmrIntArray_t
Definition: BoxLibLayout.h:72
amrex::BaseFab< int > basefab_t
Definition: BoxLibLayout.h:77
amr::AmrProcMapContainer_t AmrProcMapContainer_t
Definition: BoxLibLayout.h:69
bool LevelDefined(int level) const
static Vector_t lowerBound
Definition: BoxLibLayout.h:86
ParticleAttrib< Index_t > ParticleIndex_t
Definition: BoxLibLayout.h:62
amrex::Vector< AmrIntVect_t > AmrIntVectContainer_t
Definition: AmrDefs.h:49
amrex::IntVect AmrIntVect_t
Definition: AmrDefs.h:48
void setBoundingBox(double dh)
amrex::DistributionMapping AmrProcMap_t
Definition: AmrDefs.h:38
amr::AmrVectorField_t AmrVectorField_t
Definition: BoxLibLayout.h:58
ParticleAmrLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
Definition: BoxLibLayout.h:54
amrex::Geometry AmrGeometry_t
Definition: AmrDefs.h:39
amrex::Vector< std::unique_ptr< AmrField_t > > AmrScalarFieldContainer_t
Definition: AmrDefs.h:41
amr::AmrGrid_t AmrGrid_t
Definition: BoxLibLayout.h:65
amrex::FabArray< basefab_t > mask_t
Definition: BoxLibLayout.h:78
amrex::Vector< int > AmrIntArray_t
Definition: AmrDefs.h:47
amrex::Real AmrReal_t
Definition: AmrDefs.h:51
amr::AmrBox_t AmrBox_t
Definition: BoxLibLayout.h:74
bool EnforcePeriodicWhere(AmrParticleBase< BoxLibLayout< T, Dim > > &prt, const unsigned int ip, int lev_min=0, int lev_max=-1) const
int finestLevel() const
amr::AmrDomain_t AmrDomain_t
Definition: BoxLibLayout.h:73
amrex::Vector< AmrGeometry_t > AmrGeomContainer_t
Definition: AmrDefs.h:43
amrex::MultiFab AmrField_t
Definition: AmrDefs.h:34
void locateParticle(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int lev_min, int lev_max, int nGrow) const
std::array< std::unique_ptr< AmrField_t >, AMREX_SPACEDIM > AmrVectorField_t
Definition: AmrDefs.h:37
void update(IpplParticleBase< BoxLibLayout< T, Dim > > &PData, const ParticleAttrib< char > *canSwap=0)
ParticleAmrLayout< T, Dim >::ParticlePos_t ParticlePos_t
Definition: BoxLibLayout.h:61
const std::unique_ptr< mask_t > & getLevelMask(int lev) const
amr::AmrIntVect_t AmrIntVect_t
Definition: BoxLibLayout.h:70
ParticleLayout< T, Dim >::Index_t Index_t
amrex::RealBox AmrDomain_t
Definition: AmrDefs.h:46
bool Where(AmrParticleBase< BoxLibLayout< T, Dim > > &p, const unsigned int ip, int lev_min=0, int lev_max=-1, int nGrow=0) const
bool PeriodicShift(SingleParticlePos_t R) const
int MaxRefRatio(int level) const
void define(const AmrIntVectContainer_t &refRatio)
Definition: BoxLibLayout.h:263
amr::AmrGeomContainer_t AmrGeomContainer_t
Definition: BoxLibLayout.h:67
amr::AmrField_t AmrField_t
Definition: BoxLibLayout.h:57
amr::AmrProcMap_t AmrProcMap_t
Definition: BoxLibLayout.h:64
int maxLevel_m
Maximum level allowed.
amrex::Vector< AmrGrid_t > AmrGridContainer_t
Definition: AmrDefs.h:44
void define(const AmrGeomContainer_t &geom)
Definition: BoxLibLayout.h:252
amrex::Vector< AmrVectorField_t > AmrVectorFieldContainer_t
Definition: AmrDefs.h:42
ParticleAmrLayout< T, Dim >::pair_iterator pair_iterator
Definition: BoxLibLayout.h:53
amr::AmrGridContainer_t AmrGridContainer_t
Definition: BoxLibLayout.h:68
void initBaseBox_m(int nGridPoints, int maxGridSize, double dh=0.04)
void setDomainRatio(const std::vector< double > &ratio)
amrex::Box AmrBox_t
Definition: AmrDefs.h:50
void resize(int maxLevel)
Definition: BoxLibLayout.h:235
static Vector_t upperBound
Definition: BoxLibLayout.h:93
AmrIntVectContainer_t refRatio_m
Definition: BoxLibLayout.h:377
amr::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
Definition: BoxLibLayout.h:59