Schnek
domainsubdivision.hpp
Go to the documentation of this file.
1 /*
2  * domainsubdivision.hpp
3  *
4  * Created on: 27 Sep 2012
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
35 #ifndef SCHNEK_DOMAINSUBDIVISION_HPP
36 #define SCHNEK_DOMAINSUBDIVISION_HPP
37 
38 #include "boundary.hpp"
39 
40 #include <memory>
41 
42 namespace schnek {
43 
50 template<class GridType>
52  public:
53  enum {Rank = GridType::Rank};
54 
55  typedef typename GridType::IndexType LimitType;
56  typedef typename GridType::value_type value_type;
57  typedef typename GridType::CheckingPolicyType CheckingPolicyType;
58  typedef typename GridType::StoragePolicyType StoragePolicyType;
59 
60  //typedef Grid<unsigned char, 1, GridAssertCheck, LazyArrayGridStorage> BufferType;
62 
65  typedef std::shared_ptr<BoundaryType> pBoundaryType;
66 
67  protected:
68  pBoundaryType bounds;
69  public:
70 
73 
78  virtual ~DomainSubdivision() {}
79 
80  int getDelta() { return bounds->getDelta(); }
81 
88  virtual void init(const LimitType &low, const LimitType &high, int delta) = 0;
89 
93  void init(const DomainType &domain, int delta)
94  {
95  init(domain.getLo(), domain.getHi(), delta);
96  }
97 
101  void init(const GridType &grid, int delta)
102  {
103  init(grid.getLo(), grid.getHi(), delta);
104  }
105 
109  void init(const LimitType &size, int delta)
110  {
111  LimitType sizem(size);
112  for (size_t i=0; i<Rank; ++i) --sizem[i];
113  init(LimitType(0), sizem, delta);
114  }
115 
117  virtual const DomainType &getGlobalDomain() const = 0;
118 
120  const DomainType &getDomain() const { return bounds->getDomain(); }
122  const LimitType &getLo() const {return bounds->getDomain().getLo();}
124  const LimitType &getHi() const {return bounds->getDomain().getHi();}
125 
127  DomainType getInnerDomain() const { return bounds->getInnerDomain(); }
129  LimitType getInnerLo() const {return bounds->getInnerDomain().getLo();}
131  LimitType getInnerHi() const {return bounds->getInnerDomain().getHi();}
132 
133 
135  template<typename T, template<size_t> class CheckingPolicy>
137  {
138  const DomainType &globalGridSize = this->getGlobalDomain();
139  typename Range<T, Rank, CheckingPolicy>::LimitType localDomainMin, localDomainMax;
140  for (size_t i=0; i<Rank; ++i)
141  {
142  const T &lo = globalExtent.getLo()[i];
143  T dx = (globalExtent.getHi()[i]-lo) / (T)(globalGridSize.getHi()[i] - globalGridSize.getLo()[i] + 1);
144  localDomainMin[i] = lo + this->getInnerLo()[i]*dx;
145  localDomainMax[i] = lo + (this->getInnerHi()[i] + 1)*dx;
146  }
147  return Range<T, Rank, CheckingPolicy>(localDomainMin,localDomainMax);
148  }
149 
154  template<typename T, template<size_t> class CheckingPolicy>
156  {
157  return this->getInnerExtent(
159  }
160 
164  virtual void exchange(GridType &grid, size_t dim) = 0;
165 
169  virtual void accumulate(GridType &grid, size_t dim) = 0;
170 
171  virtual void exchangeData(size_t dim, int orientation, BufferType &in, BufferType &out) = 0;
172 
174  virtual double avgReduce(double) const = 0;
175 
177  virtual int avgReduce(int) const = 0;
178 
180  virtual double sumReduce(double) const = 0;
181 
183  virtual int sumReduce(int) const = 0;
184 
186  virtual double maxReduce(double) const = 0;
187 
189  virtual int maxReduce(int) const = 0;
190 
192  virtual double minReduce(double) const = 0;
193 
195  virtual int minReduce(int) const = 0;
196 
197 
199  virtual bool master() const = 0;
200 
202  virtual int procnum() const = 0;
203 
205  virtual int procCount() const = 0;
206 
208  virtual int getUniqueId() const = 0;
209 
217  virtual bool isBoundLo(size_t dim) = 0;
218 
226  virtual bool isBoundHi(size_t dim) = 0;
227 
228  void exchange(GridType &grid) {
229  for (size_t i=0; i<Rank; ++i) exchange(grid,i);
230  }
231 
232  void accumulate(GridType &grid) {
233  for (size_t i=0; i<Rank; ++i) accumulate(grid,i);
234  }
235 };
236 
237 template<class GridType>
238 class SerialSubdivision : public DomainSubdivision<GridType>
239 {
240  public:
241  typedef typename Boundary<GridType::Rank>::LimitType LimitType;
242  typedef typename GridType::value_type value_type;
246 
247  private:
249  LimitType Low;
250 
252  LimitType High;
253  public:
256 
258 
260 
267  void init(const LimitType &low, const LimitType &high, int delta);
268 
270  const DomainType &getGlobalDomain() const { return this->bounds->getDomain(); }
271 
277  void exchange(GridType &grid, size_t dim);
278 
282  void accumulate(GridType &grid, size_t dim);
283 
284  void exchangeData(size_t dim, int orientation, BufferType &in, BufferType &out);
285 
287  double avgReduce(double val) const { return val; }
288 
290  int avgReduce(int val) const { return val; }
291 
293  double maxReduce(double val) const { return val; }
294 
296  int maxReduce(int val) const { return val; }
297 
299  double minReduce(double val) const { return val; }
300 
302  int minReduce(int val) const { return val; }
303 
305  double sumReduce(double val) const { return val; }
306 
308  int sumReduce(int val) const { return val; }
309 
311  bool master() const { return true; }
312 
314  int procnum() const { return 0; }
315 
317  int procCount() const { return 1; }
318 
320  int getUniqueId() const { return 0; }
321 
332  bool isBoundLo(size_t) { return true; }
333 
344  bool isBoundHi(size_t) { return true; }
345 
346 };
347 
348 
349 //DomainSubdivision
350 
351 } // namespace schnek
352 
353 #include "domainsubdivision.t"
354 
355 #endif // SCHNEK_DOMAINSUBDIVISION_HPP
356 
Definition: domainsubdivision.hpp:238
virtual bool master() const =0
Return true if this is the master process and false otherwise.
double sumReduce(double val) const
The sum of a single value is the value.
Definition: domainsubdivision.hpp:305
Interface for wrapping and exchanging boundaries .
Definition: domainsubdivision.hpp:51
Definition: boundary.hpp:44
int procnum() const
Returns the comm rank as given by mpi.
Definition: domainsubdivision.hpp:314
virtual double maxReduce(double) const =0
Return the maximum of a single value over all the processes.
int minReduce(int val) const
Return the minimum of a single value over all the processes.
Definition: domainsubdivision.hpp:302
virtual int procnum() const =0
Return the process number.
virtual bool isBoundHi(size_t dim)=0
int getUniqueId() const
returns an ID, which consists of the Dimensions and coordinates
Definition: domainsubdivision.hpp:320
virtual void exchange(GridType &grid, size_t dim)=0
Exchange the boundaries of a field function in the direction given by dim.
virtual bool isBoundLo(size_t dim)=0
double maxReduce(double val) const
The maximum of a single value is the value.
Definition: domainsubdivision.hpp:293
virtual ~DomainSubdivision()
Virtual destructor.
Definition: domainsubdivision.hpp:78
const DomainType & getDomain() const
Return the local domain size.
Definition: domainsubdivision.hpp:120
Definition: range.hpp:43
DomainType getInnerDomain() const
Return the local inner domain size.
Definition: domainsubdivision.hpp:127
Range< T, Rank, CheckingPolicy > getInnerExtent(const Range< T, Rank, CheckingPolicy > &globalExtent) const
Return the local inner physical extent.
Definition: domainsubdivision.hpp:136
int procCount() const
Return the total number of processes.
Definition: domainsubdivision.hpp:317
void init(const GridType &grid, int delta)
Definition: domainsubdivision.hpp:101
virtual void init(const LimitType &low, const LimitType &high, int delta)=0
SCHNEK_INLINE const LimitType & getLo() const
Return rectangle minimum.
Definition: range.hpp:74
Definition: algo.hpp:30
void init(const DomainType &domain, int delta)
Definition: domainsubdivision.hpp:93
virtual double avgReduce(double) const =0
Return the average of a single value over all the processes.
double minReduce(double val) const
Return the minimum of a single value over all the processes.
Definition: domainsubdivision.hpp:299
virtual const DomainType & getGlobalDomain() const =0
Return the global domain size excluding ghost cells.
bool isBoundLo(size_t)
Definition: domainsubdivision.hpp:332
int sumReduce(int val) const
The sum of a single value is the value.
Definition: domainsubdivision.hpp:308
void init(const LimitType &size, int delta)
Definition: domainsubdivision.hpp:109
virtual void accumulate(GridType &grid, size_t dim)=0
Exchange the boundaries of a field function summing the data from ghost cells and inner cells...
LimitType getInnerHi() const
Return the maximum of the local inner domain.
Definition: domainsubdivision.hpp:131
bool master() const
The process with the rank zero is designated master process.
Definition: domainsubdivision.hpp:311
const DomainType & getGlobalDomain() const
Return the global domain size excluding ghost cells.
Definition: domainsubdivision.hpp:270
bool isBoundHi(size_t)
Definition: domainsubdivision.hpp:344
virtual int getUniqueId() const =0
get a unique Id
virtual double sumReduce(double) const =0
Return the average of a single value over all the processes.
double avgReduce(double val) const
The average of a single value is the value.
Definition: domainsubdivision.hpp:287
Range< T, Rank, CheckingPolicy > getInnerExtent(const Array< T, Rank, CheckingPolicy > &globalExtent) const
Definition: domainsubdivision.hpp:155
int avgReduce(int val) const
The average of a single value is the value.
Definition: domainsubdivision.hpp:290
virtual int procCount() const =0
Return the total number of processes.
LimitType getInnerLo() const
Return the minimum of the local inner domain.
Definition: domainsubdivision.hpp:129
virtual double minReduce(double) const =0
Return the minimum of a single value over all the processes.
const LimitType & getLo() const
Return the minimum of the local domain.
Definition: domainsubdivision.hpp:122
int maxReduce(int val) const
The maximum of a single value is the value.
Definition: domainsubdivision.hpp:296
SCHNEK_INLINE const LimitType & getHi() const
Return rectangle maximum.
Definition: range.hpp:76
const LimitType & getHi() const
Return the maximum of the local domain.
Definition: domainsubdivision.hpp:124
DomainSubdivision()
Default constructor.
Definition: domainsubdivision.hpp:72