Dune Core Modules (2.6.0)

coordinates.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_YASPGRID_COORDINATES_HH
4 #define DUNE_GRID_YASPGRID_COORDINATES_HH
5 
6 #include <array>
7 #include <bitset>
8 #include <vector>
9 
10 #include <dune/common/fvector.hh>
11 
19 namespace Dune
20 {
25  template<class ct, int dim>
27  {
28  public:
30  typedef ct ctype;
32  static const int dimension = dim;
33 
36 
43  EquidistantCoordinates(const Dune::FieldVector<ct,dim>& h, const std::array<int,dim>& s)
44  : _h(h), _s(s) {}
45 
50  inline ct meshsize(int d, int i) const
51  {
52  return _h[d];
53  }
54 
59  inline ct coordinate(int d, int i) const
60  {
61  return i*_h[d];
62  }
63 
67  inline int size(int d) const
68  {
69  return _s[d];
70  }
71 
78  EquidistantCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
79  {
80  //determine new size and meshsize
81  std::array<int,dim> news;
83 
84  for (int i=0; i<dim; i++)
85  {
86  news[i] = 2 * _s[i];
87  if (!keep_ovlp)
88  {
89  if (ovlp_low[i])
90  news[i] -= overlap;
91  if (ovlp_up[i])
92  news[i] -= overlap;
93  }
94 
95  newh[i] = _h[i] / 2.;
96  }
97  return EquidistantCoordinates<ct,dim>(newh,news);
98  }
99 
101  void print(std::ostream& s) const
102  {
103  s << "Printing equidistant coordinate information:" << std::endl;
104  s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
105  }
106 
107  private:
109  std::array<int,dim> _s;
110  };
111 
112  template<class ct, int dim>
113  inline std::ostream& operator<< (std::ostream& s, EquidistantCoordinates<ct,dim>& c)
114  {
115  c.print(s);
116  return s;
117  }
118 
123  template<class ct, int dim>
125  {
126  public:
128  typedef ct ctype;
130  static const int dimension = dim;
131 
134 
143  : _origin(origin), _h(h), _s(s) {}
144 
149  inline ct meshsize(int d, int i) const
150  {
151  return _h[d];
152  }
153 
158  inline ct coordinate(int d, int i) const
159  {
160  return _origin[d] + i*_h[d];
161  }
162 
166  inline int size(int d) const
167  {
168  return _s[d];
169  }
170 
174  inline ct origin(int d) const
175  {
176  return _origin[d];
177  }
178 
185  EquidistantOffsetCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
186  {
187  //determine new size and meshsize
188  std::array<int,dim> news;
190 
191  for (int i=0; i<dim; i++)
192  {
193  news[i] = 2 * _s[i];
194  if (!keep_ovlp)
195  {
196  if (ovlp_low[i])
197  news[i] -= overlap;
198  if (ovlp_up[i])
199  news[i] -= overlap;
200  }
201 
202  newh[i] = _h[i] / 2.;
203  }
204  return EquidistantOffsetCoordinates<ct,dim>(_origin,newh,news);
205  }
206 
208  void print(std::ostream& s) const
209  {
210  s << "Printing equidistant coordinate information:" << std::endl;
211  s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
212  s << "Offset to origin: " << _origin << std::endl;
213  }
214 
215  private:
218  std::array<int,dim> _s;
219  };
220 
221  template<class ct, int dim>
222  inline std::ostream& operator<< (std::ostream& s, EquidistantOffsetCoordinates<ct,dim>& c)
223  {
224  c.print(s);
225  return s;
226  }
227 
232  template<class ct, int dim>
234  {
235  public:
237  typedef ct ctype;
239  static const int dimension = dim;
240 
243 
250  TensorProductCoordinates(const std::array<std::vector<ct>,dim>& c, const std::array<int,dim>& offset)
251  : _c(c),_offset(offset)
252  {}
253 
258  inline ct meshsize(int d, int i) const
259  {
260  return _c[d][i+1-_offset[d]] - _c[d][i-_offset[d]];
261  }
262 
267  inline ct coordinate(int d, int i) const
268  {
269  return _c[d][i-_offset[d]];
270  }
271 
275  inline int size(int d) const
276  {
277  return _c[d].size() - 1;
278  }
279 
286  TensorProductCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
287  {
288  std::array<std::vector<ct>,dim> newcoords;
289  std::array<int,dim> newoffset(_offset);
290  for (int i=0; i<dim; i++)
291  {
292  newoffset[i] *= 2;
293 
294  //determine new size
295  int newsize = 2 * _c[i].size() - 1;
296  if (!keep_ovlp)
297  {
298  if (ovlp_low[i])
299  {
300  newoffset[i] += overlap;
301  newsize -= overlap;
302  }
303  if (ovlp_up[i])
304  newsize -= overlap;
305  }
306  newcoords[i].resize(newsize);
307 
308  typename std::vector<ct>::const_iterator it = _c[i].begin();
309  typename std::vector<ct>::const_iterator end = _c[i].end()-1;
310  typename std::vector<ct>::iterator iit = newcoords[i].begin() - 1;
311  if (!keep_ovlp)
312  {
313  if (ovlp_low[i])
314  {
315  it += overlap/2;
316  if (overlap%2)
317  *(++iit) = (*it + *(++it)) / 2.;
318  }
319  if (ovlp_up[i])
320  end -= overlap/2;
321  }
322 
323  for (;it!=end;)
324  {
325  *(++iit) = *it;
326  *(++iit) = (*it + *(++it)) / 2.;
327  }
328 
329  if (++iit != newcoords[i].end())
330  *iit = *it;
331  }
332  return TensorProductCoordinates<ct,dim>(newcoords, newoffset);
333  }
334 
336  void print(std::ostream& s) const
337  {
338  s << "Printing TensorProduct Coordinate information:" << std::endl;
339  for (int i=0; i<dim; i++)
340  {
341  s << "Direction " << i << ": " << _c[i].size() << " coordinates" << std::endl;
342  for (std::size_t j=0; j<_c[i].size(); j++)
343  s << _c[i][j] << std::endl;
344  }
345  }
346 
347  private:
348  std::array<std::vector<ct>,dim> _c;
349  std::array<int,dim> _offset;
350  };
351 
352  template<class ct, int dim>
353  inline std::ostream& operator<< (std::ostream& s, TensorProductCoordinates<ct,dim>& c)
354  {
355  c.print(s);
356  return s;
357  }
358 
359  namespace Yasp {
360  template<class ctype, std::size_t dim>
361  bool checkIfMonotonous(const std::array<std::vector<ctype>, dim>& coords)
362  {
363  for (std::size_t i=0; i<dim; i++)
364  {
365  if (coords[i].size() <= 1)
366  return false;
367  for (std::size_t j=1; j<coords[i].size(); j++)
368  if (coords[i][j] < coords[i][j-1])
369  return false;
370  }
371  return true;
372  }
373  } // namespace Yasp
374 } // namespace Dune
375 
376 #endif
Container for equidistant coordinates in a YaspGrid.
Definition: coordinates.hh:27
EquidistantCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:78
ct coordinate(int d, int i) const
Definition: coordinates.hh:59
int size(int d) const
Definition: coordinates.hh:67
static const int dimension
export dimension
Definition: coordinates.hh:32
EquidistantCoordinates(const Dune::FieldVector< ct, dim > &h, const std::array< int, dim > &s)
construct a container with all necessary information
Definition: coordinates.hh:43
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:101
EquidistantCoordinates()
default constructor
Definition: coordinates.hh:35
ct ctype
export the coordinate type
Definition: coordinates.hh:30
ct meshsize(int d, int i) const
Definition: coordinates.hh:50
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:125
EquidistantOffsetCoordinates()
default constructor
Definition: coordinates.hh:133
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:208
EquidistantOffsetCoordinates(const Dune::FieldVector< ct, dim > &origin, const Dune::FieldVector< ct, dim > &h, const std::array< int, dim > &s)
construct a container with all necessary information
Definition: coordinates.hh:142
ct meshsize(int d, int i) const
Definition: coordinates.hh:149
ct origin(int d) const
Definition: coordinates.hh:174
int size(int d) const
Definition: coordinates.hh:166
ct ctype
export the coordinate type
Definition: coordinates.hh:128
static const int dimension
export dimension
Definition: coordinates.hh:130
ct coordinate(int d, int i) const
Definition: coordinates.hh:158
EquidistantOffsetCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:185
Coordinate container for a tensor product YaspGrid.
Definition: coordinates.hh:234
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:336
ct meshsize(int d, int i) const
Definition: coordinates.hh:258
ct coordinate(int d, int i) const
Definition: coordinates.hh:267
static const int dimension
export dimension
Definition: coordinates.hh:239
TensorProductCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:286
TensorProductCoordinates(const std::array< std::vector< ct >, dim > &c, const std::array< int, dim > &offset)
construct a container with all necessary information
Definition: coordinates.hh:250
TensorProductCoordinates()
the default constructor
Definition: coordinates.hh:242
ct ctype
export the coordinate type
Definition: coordinates.hh:237
int size(int d) const
Definition: coordinates.hh:275
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 1, 22:29, 2024)