OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
95
96public:
101
105 BoxLibLayout(const BoxLibLayout* layout_p);
106
111 BoxLibLayout(int nGridPoints, int maxGridSize);
112
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 * 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
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
305private:
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
360
371 const unsigned int ip,
372 int lev_min, int lev_max, int nGrow) const;
373
374
375private:
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
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
ParticleAttrib< Index_t > ParticleIndex_t
void setBoundingBox(double dh)
ParticleAmrLayout< T, Dim >::ParticlePos_t ParticlePos_t
amr::AmrBox_t AmrBox_t
void define(const AmrIntVectContainer_t &refRatio)
amr::AmrProcMapContainer_t AmrProcMapContainer_t
amr::AmrDomain_t AmrDomain_t
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
ParticleAmrLayout< T, Dim >::pair_t pair_t
ParticleAmrLayout< T, Dim >::pair_iterator pair_iterator
static Vector_t lowerBound
void buildLevelMask(int lev, const int ncells=1)
BoxLibLayout(const BoxLibLayout *layout_p)
BoxLibLayout(const AmrGeometry_t &geom, const AmrProcMap_t &dmap, const AmrGrid_t &ba)
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
amr::AmrIntArray_t AmrIntArray_t
amr::AmrGeometry_t AmrGeometry_t
BoxLibLayout(const AmrGeomContainer_t &geom, const AmrProcMapContainer_t &dmap, const AmrGridContainer_t &ba, const AmrIntArray_t &rr)
AmrIntVect_t Index(SingleParticlePos_t &R, int lev) const
amr::AmrVectorField_t AmrVectorField_t
ParticleAmrLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
BoxLibLayout(int nGridPoints, int maxGridSize)
amr::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
amrex::BaseFab< int > basefab_t
amrex::FabArray< basefab_t > mask_t
amr::AmrGeomContainer_t AmrGeomContainer_t
bool PeriodicShift(SingleParticlePos_t R) const
static Vector_t upperBound
amr::AmrGrid_t AmrGrid_t
void update(IpplParticleBase< BoxLibLayout< T, Dim > > &PData, const ParticleAttrib< char > *canSwap=0)
amr::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
amr::AmrGridContainer_t AmrGridContainer_t
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)
void define(const AmrGeomContainer_t &geom)
std::vector< std::unique_ptr< mask_t > > masks_m
int finestLevel() const
amr::AmrProcMap_t AmrProcMap_t
amr::AmrIntVectContainer_t AmrIntVectContainer_t
amr::AmrReal_t AmrReal_t
int MaxRefRatio(int level) const
void update(AmrParticleBase< BoxLibLayout< T, Dim > > &PData, int lev_min=0, int lev_max=-1, bool isRegrid=false)
amr::AmrField_t AmrField_t
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
ParticleLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
ParticleAttrib< SingleParticlePos_t > ParticlePos_t
ParticleLayout< T, Dim >::Index_t Index_t
Vektor< double, 3 > Vector_t