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:
100 BoxLibLayout();
101
102 virtual ~BoxLibLayout() = default;
103
107 BoxLibLayout(const BoxLibLayout* layout_p);
108
113 BoxLibLayout(int nGridPoints, int maxGridSize);
114
122 BoxLibLayout(const AmrGeometry_t& geom,
123 const AmrProcMap_t& dmap,
124 const AmrGrid_t& ba);
125
137 const AmrProcMapContainer_t& dmap,
138 const AmrGridContainer_t& ba,
139 const AmrIntArray_t& rr);
140
141 /*
142 * Overloaded functions of ParticleAmrLayout
143 */
144
153 void setBoundingBox(double dh);
154
162 void setDomainRatio(const std::vector<double>& ratio);
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 * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
191 */
192
201 const unsigned int ip, int level) const;
202
209 AmrIntVect_t Index (SingleParticlePos_t &R, int lev) const;
210
211 /*
212 * Additional methods
213 */
214
220 void buildLevelMask(int lev, const int ncells = 1);
221
222 void clearLevelMask(int lev);
223
224 const std::unique_ptr<mask_t>& getLevelMask(int lev) const;
225
237 void resize(int maxLevel) {
238 int length = maxLevel + 1;
239 this->m_geom.resize(length);
240 this->m_dmap.resize(length);
241 this->m_ba.resize(length);
242 this->m_nlevels = length;
243 this->refRatio_m.resize(maxLevel);
244// this->m_rr.resize(maxLevel);
245 this->maxLevel_m = maxLevel;
246 }
247
254 void define(const AmrGeomContainer_t& geom) {
255 for (unsigned int i = 0; i < geom.size(); ++i)
256 this->m_geom[i] = geom[i];
257 }
258
266 for (unsigned int i = 0; i < refRatio.size(); ++i) {
267 refRatio_m[i] = refRatio[i];
268 }
269 }
270
271 /*
272 * ParGDB overwritten functions
273 */
274
280 inline bool LevelDefined (int level) const;
281
285 inline int finestLevel () const;
286
290 inline int maxLevel () const;
291
297 inline AmrIntVect_t refRatio (int level) const;
298
304 inline int MaxRefRatio (int level) const;
305
306
307private:
316 void initBaseBox_m(int nGridPoints, int maxGridSize, double dh = 0.04);
317
318
319 /*
320 * Functions from AMReX that are adjusted to work with Ippl AmrParticleBase class
321 */
322
335 const unsigned int ip,
336 int lev_min = 0, int lev_max = -1, int nGrow = 0) const;
337
350 const unsigned int ip,
351 int lev_min = 0, int lev_max = -1) const;
352
361 bool PeriodicShift (SingleParticlePos_t R) const;
362
373 const unsigned int ip,
374 int lev_min, int lev_max, int nGrow) const;
375
376
377private:
378 // don't use m_rr from ParGDB since it is the same refinement in all directions
380
381 /* mask to reduce spurious self-field forces at
382 * coarse-fine interfaces
383 */
384 std::vector<std::unique_ptr<mask_t> > masks_m;
385};
386
387#include "BoxLibLayout.hpp"
388
389#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)
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
amr::AmrVectorField_t AmrVectorField_t
ParticleAmrLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
amr::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
int maxLevel() const
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
void resize(int maxLevel)
void define(const AmrGeomContainer_t &geom)
std::vector< std::unique_ptr< mask_t > > masks_m
Refinement ratios [0:finest_level-1].
int finestLevel() const
amr::AmrProcMap_t AmrProcMap_t
virtual ~BoxLibLayout()=default
amr::AmrIntVectContainer_t AmrIntVectContainer_t
amr::AmrReal_t AmrReal_t
int MaxRefRatio(int level) const
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
int maxLevel_m
Maximum level allowed.
ParticleLayout< T, Dim >::Index_t Index_t
Definition Index.h:237