OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
AmrParticleBase.h
Go to the documentation of this file.
1//
2// Class AmrParticleBase
3// Ippl interface for AMR particles.
4// The derived classes need to extend the base class by subsequent methods.
5//
6// template <class FT, unsigned Dim, class PT>
7// void scatter(const ParticleAttrib<FT>& attrib, AmrField_t& f,
8// const ParticleAttrib<Vektor<PT, Dim> >& pp,
9// int lbase = 0, int lfine = -1) const;
10//
11//
12// gather the data from the given Field into the given attribute, using
13// the given Position attribute
14//
15// template <class FT, unsigned Dim, class PT>
16// void gather(ParticleAttrib<FT>& attrib, const AmrField_t& f,
17// const ParticleAttrib<Vektor<PT, Dim> >& pp,
18// int lbase = 0, int lfine = -1) const;
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 AMR_PARTICLE_BASE_H
37#define AMR_PARTICLE_BASE_H
38
39#include "Ippl.h"
40
42
44
45template<class PLayout>
46class AmrParticleBase : public IpplParticleBase<PLayout> {
47
48public:
49 typedef typename PLayout::ParticlePos_t ParticlePos_t;
50 typedef typename PLayout::ParticleIndex_t ParticleIndex_t;
56
57 typedef long SortListIndex_t;
58 typedef std::vector<SortListIndex_t> SortList_t;
59 typedef std::vector<ParticleAttribBase *> attrib_container_t;
60
63
65
66public:
67
69
70 AmrParticleBase(PLayout* layout);
71
73
74 //initialize AmrParticleBase class - add level and grid variables to attribute list
76 this->addAttribute(Level);
77 this->addAttribute(Grid);
78 }
79
81
83
84 void setLocalNumPerLevel(const ParticleLevelCounter_t& LocalNumPerLevel);
85
86 /* Functions of IpplParticleBase<PLayout> adpated to
87 * work with AmrParticleLevelCounter:
88 * - createWithID()
89 * - create()
90 * - destroy()
91 * - performDestroy()
92 */
93
94 void createWithID(unsigned id);
95
96 void create(size_t M);
97
98 void destroy(size_t M, size_t I, bool doNow = false);
99
100 void performDestroy(bool updateLocalNum = false);
101
102 // Update the particle object after a timestep. This routine will change
103 // our local, total, create particle counts properly.
104 void update();
105
113 void update(int lev_min, int lev_max, bool isRegrid = false);
114
115 // Update the particle object after a timestep. This routine will change
116 // our local, total, create particle counts properly.
117 void update(const ParticleAttrib<char>& canSwap);
118
119 // sort particles based on the grid and level that they belong to
120 void sort();
121
122 // sort the particles given a sortlist
123 void sort(SortList_t &sortlist);
124
125 PLayout& getAmrLayout() { return this->getLayout(); }
126 const PLayout& getAmrLayout() const { return this->getLayout(); }
127
136 inline void setForbidTransform(bool forbidTransform);
137
142 inline bool isForbidTransform() const;
143
153 const double& domainMapping(bool inverse = false);
154
159 inline const double& getScalingFactor() const;
160
161
162 void setLorentzFactor(const Vector_t& lorentzFactor);
163
164// void lorentzTransform(bool inverse = false);
165
166private:
167 void getLocalBounds_m(Vector_t &rmin, Vector_t &rmax);
168 void getGlobalBounds_m(Vector_t &rmin, Vector_t &rmax);
169
170protected:
174
176
181 double scale_m;
182
189
190// bool isLorentzTransformed_m;
191
192
193private:
195};
196
197#include "AmrParticleBase.hpp"
198
199#endif
amr::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
Definition: PBunchDefs.h:35
amr::AmrField_t AmrField_t
Definition: PBunchDefs.h:34
amr::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
Definition: PBunchDefs.h:36
std::array< std::unique_ptr< AmrField_t >, AMREX_SPACEDIM > AmrVectorField_t
Definition: AmrDefs.h:37
PLayout::ParticlePos_t ParticlePos_t
void setLorentzFactor(const Vector_t &lorentzFactor)
bool isForbidTransform() const
const double & getScalingFactor() const
const PLayout & getAmrLayout() const
std::vector< SortListIndex_t > SortList_t
void getGlobalBounds_m(Vector_t &rmin, Vector_t &rmax)
AmrParticleLevelCounter< size_t, size_t > ParticleLevelCounter_t
void performDestroy(bool updateLocalNum=false)
ParticleLevelCounter_t LocalNumPerLevel_m
ParticleIndex_t Grid
bool forbidTransform_m
To avoid multiple transformations during regrid.
IpplTimings::TimerRef sortParticlesTimer_m
PLayout::AmrVectorField_t AmrVectorField_t
const ParticleLevelCounter_t & getLocalNumPerLevel() const
void getLocalBounds_m(Vector_t &rmin, Vector_t &rmax)
void setLocalNumPerLevel(const ParticleLevelCounter_t &LocalNumPerLevel)
IpplTimings::TimerRef domainMappingTimer_m
Vector_t lorentzFactor_m
PLayout::AmrField_t AmrField_t
void createWithID(unsigned id)
std::vector< ParticleAttribBase * > attrib_container_t
PLayout::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
void create(size_t M)
ParticleIndex_t Level
PLayout::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
PLayout & getAmrLayout()
IpplTimings::TimerRef updateParticlesTimer_m
PLayout::SingleParticlePos_t SingleParticlePos_t
PLayout::ParticleIndex_t ParticleIndex_t
void destroy(size_t M, size_t I, bool doNow=false)
void setForbidTransform(bool forbidTransform)
const double & domainMapping(bool inverse=false)
PLayout & getLayout()
void addAttribute(ParticleAttribBase &pa)
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176