OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IrregularDomain.h
Go to the documentation of this file.
1 //
2 // Class IrregularDomain
3 // Defines a common abstract interface for different types of boundaries.
4 //
5 // Copyright (c) 2008, Yves Ineichen, ETH Zürich,
6 // 2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
7 // 2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
8 // All rights reserved
9 //
10 // Implemented as part of the master thesis
11 // "A Parallel Multigrid Solver for Beam Dynamics"
12 // and the paper
13 // "A fast parallel Poisson solver on irregular domains applied to beam dynamics simulations"
14 // (https://doi.org/10.1016/j.jcp.2010.02.022)
15 //
16 // This file is part of OPAL.
17 //
18 // OPAL is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
25 //
26 #ifndef IRREGULAR_DOMAIN_H
27 #define IRREGULAR_DOMAIN_H
28 
29 #include <map>
30 #include <string>
31 #include "Algorithms/Vektor.h"
32 #include "Algorithms/Quaternion.h"
33 #include "Index/NDIndex.h"
34 
36 enum {
39  QUADRATIC
40 };
41 
42 
44 
45 public:
46 
47  template<typename T>
48  struct Stencil {
49  T center; // x, y, z
50  T west; // x-1, y, z
51  T east; // x+1, y, z
52  T north; // x, y+1, z
53  T south; // x, y-1, z
54  T front; // x, y, z-1
55  T back; // x, y, z+1
56  };
57 
61 
63  const Vector_t& hr,
64  const std::string& interpl);
65 
66 
71  virtual void compute(Vector_t hr, NDIndex<3> localId) = 0;
72 
79  void getBoundaryStencil(int x, int y, int z,
80  StencilValue_t& value,
81  double &scaleFactor) const;
82 
85  // \param values of stencil element
87  void getBoundaryStencil(int id, StencilValue_t& value,
88  double &scaleFactor) const;
89 
95  void getNeighbours(int x, int y, int z, StencilIndex_t& index) const;
96 
97  void getNeighbours(int idx, StencilIndex_t& index) const;
98 
100  virtual void getCoord(int idx, int &x, int &y, int &z) const;
101 
103  int getIdx(int x, int y, int z) const;
104 
105  virtual int getNumXY() const { return nr_m[0] * nr_m[1]; }
106 
112  virtual bool isInside(int x, int y, int z) const = 0;
113 
114  IntVector_t getNr() const { return nr_m; }
115  Vector_t getHr() const { return hr_m; }
116 
117  void setNr(IntVector_t nr) { nr_m = nr; }
118  void setHr(Vector_t hr) { hr_m = hr; }
119 
120  void setMinMaxZ(double minz, double maxz) {
121  zMin_m = minz;
122  zMax_m = maxz;
123  }
124 
125  double getMinZ() const { return zMin_m; }
126  double getMaxZ() const { return zMax_m; }
127 
128  double getXRangeMin() const { return min_m(0); }
129  double getXRangeMax() const { return max_m(0); }
130  double getYRangeMin() const { return min_m(1); }
131  double getYRangeMax() const { return max_m(1); }
132  double getZRangeMin() const { return min_m(2); }
133  double getZRangeMax() const { return max_m(2); }
134 
135  void setRangeMin(const Vector_t& min) { min_m = min; }
136  void setRangeMax(const Vector_t& max) { max_m = max; }
137 
138  bool hasGeometryChanged() const { return hasGeometryChanged_m; }
139 
140  virtual ~IrregularDomain() {};
141 
142  virtual void resizeMesh(Vector_t& origin, Vector_t& hr,
143  const Vector_t& /*rmin*/, const Vector_t& /*rmax*/,
144  double /*dh*/);
145 
146 protected:
147 
148  virtual int indexAccess(int x, int y, int z) const = 0;
149 
150  virtual int coordAccess(int idx) const = 0;
151 
153  virtual void constantInterpolation(int x, int y, int z, StencilValue_t& value,
154  double &scaleFactor) const;
155 
156  virtual void linearInterpolation(int x, int y, int z, StencilValue_t& value,
157  double &scaleFactor) const;
158 
159  virtual void quadraticInterpolation(int x, int y, int z, StencilValue_t& value,
160  double &scaleFactor) const;
161 
162 
163  // a irregular domain is always defined on a grid
168 
170  double zMin_m;
171  double zMax_m;
172 
175 
178 
181 
183  std::map<int, int> idxMap_m;
184 
186  std::map<int, int> coordMap_m;
187 
188 };
189 
190 #endif
const int nr
Definition: ClassicRandom.h:24
@ QUADRATIC
@ CONSTANT
@ LINEAR
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
IntVector_t nr_m
number of mesh points in each direction
std::map< int, int > coordMap_m
mapping idx -> (x,y,z)
virtual ~IrregularDomain()
bool hasGeometryChanged() const
virtual int coordAccess(int idx) const =0
void getBoundaryStencil(int x, int y, int z, StencilValue_t &value, double &scaleFactor) const
double getXRangeMax() const
virtual int getNumXY() const
void setRangeMin(const Vector_t &min)
double getYRangeMax() const
int interpolationMethod_m
interpolation type
int getIdx(int x, int y, int z) const
Conversion from (x,y,z) to index on the 3D grid.
virtual void resizeMesh(Vector_t &origin, Vector_t &hr, const Vector_t &, const Vector_t &, double)
bool hasGeometryChanged_m
flag indicating if geometry has changed for the current time-step
void setMinMaxZ(double minz, double maxz)
double getZRangeMin() const
virtual void quadraticInterpolation(int x, int y, int z, StencilValue_t &value, double &scaleFactor) const
Vektor< int, 3 > IntVector_t
void getNeighbours(int x, int y, int z, StencilIndex_t &index) const
IntVector_t getNr() const
double getXRangeMin() const
virtual bool isInside(int x, int y, int z) const =0
double getMaxZ() const
virtual void constantInterpolation(int x, int y, int z, StencilValue_t &value, double &scaleFactor) const
different interpolation methods for boundary points
Vector_t getHr() const
std::map< int, int > idxMap_m
mapping (x,y,z) -> idx
double getYRangeMin() const
void setNr(IntVector_t nr)
Stencil< int > StencilIndex_t
IrregularDomain(const IntVector_t &nr, const Vector_t &hr, const std::string &interpl)
virtual void linearInterpolation(int x, int y, int z, StencilValue_t &value, double &scaleFactor) const
Vector_t hr_m
mesh-spacings in each direction
virtual int indexAccess(int x, int y, int z) const =0
Stencil< double > StencilValue_t
void setRangeMax(const Vector_t &max)
double zMin_m
min/max of bunch in floor coordinates
double getZRangeMax() const
virtual void getCoord(int idx, int &x, int &y, int &z) const
Conversion from a 3D index to (x,y,z)
double getMinZ() const
void setHr(Vector_t hr)
virtual void compute(Vector_t hr, NDIndex< 3 > localId)=0