Dune Core Modules (2.8.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
11
19namespace 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>& upperRight, const std::array<int,dim>& s)
44 : _s(s)
45 {
46 for (int i=0; i<dim; i++)
47 _h[i] = upperRight[i] / _s[i];
48 }
49
54 inline ct meshsize(int d, [[maybe_unused]] int i) const
55 {
56 return _h[d];
57 }
58
63 inline ct coordinate(int d, int i) const
64 {
65 return i*_h[d];
66 }
67
71 inline int size(int d) const
72 {
73 return _s[d];
74 }
75
82 EquidistantCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
83 {
84 //determine new size and meshsize
85 std::array<int,dim> news;
86 Dune::FieldVector<ct,dim> newUpperRight;
87
88 for (int i=0; i<dim; i++)
89 {
90 news[i] = 2 * _s[i];
91 if (!keep_ovlp)
92 {
93 if (ovlp_low[i])
94 news[i] -= overlap;
95 if (ovlp_up[i])
96 news[i] -= overlap;
97 }
98
99 newUpperRight[i] = (_h[i] / ct(2.)) * news[i];
100 }
101 return EquidistantCoordinates<ct,dim>(newUpperRight,news);
102 }
103
105 void print(std::ostream& s) const
106 {
107 s << "Printing equidistant coordinate information:" << std::endl;
108 s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
109 }
110
111 private:
113 std::array<int,dim> _s;
114 };
115
116 template<class ct, int dim>
117 inline std::ostream& operator<< (std::ostream& s, EquidistantCoordinates<ct,dim>& c)
118 {
119 c.print(s);
120 return s;
121 }
122
127 template<class ct, int dim>
129 {
130 public:
132 typedef ct ctype;
134 static const int dimension = dim;
135
138
147 EquidistantOffsetCoordinates(const Dune::FieldVector<ct,dim>& lowerLeft, const Dune::FieldVector<ct,dim>& upperRight, const std::array<int,dim>& s)
148 : _origin(lowerLeft), _s(s)
149 {
150 for (int i=0; i<dim; i++)
151 _h[i] = (upperRight[i] - lowerLeft[i]) / s[i];
152 }
153
158 inline ct meshsize(int d, [[maybe_unused]] int i) const
159 {
160 return _h[d];
161 }
162
167 inline ct coordinate(int d, int i) const
168 {
169 return _origin[d] + i*_h[d];
170 }
171
175 inline int size(int d) const
176 {
177 return _s[d];
178 }
179
183 inline ct origin(int d) const
184 {
185 return _origin[d];
186 }
187
194 EquidistantOffsetCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
195 {
196 //determine new size and meshsize
197 std::array<int,dim> news;
198 Dune::FieldVector<ct,dim> newUpperRight;
199
200 for (int i=0; i<dim; i++)
201 {
202 news[i] = 2 * _s[i];
203 if (!keep_ovlp)
204 {
205 if (ovlp_low[i])
206 news[i] -= overlap;
207 if (ovlp_up[i])
208 news[i] -= overlap;
209 }
210
211 newUpperRight[i] = _origin[i] + (_h[i] / ct(2.)) * news[i];
212 }
213 return EquidistantOffsetCoordinates<ct,dim>(_origin,newUpperRight,news);
214 }
215
217 void print(std::ostream& s) const
218 {
219 s << "Printing equidistant coordinate information:" << std::endl;
220 s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
221 s << "Offset to origin: " << _origin << std::endl;
222 }
223
224 private:
227 std::array<int,dim> _s;
228 };
229
230 template<class ct, int dim>
231 inline std::ostream& operator<< (std::ostream& s, EquidistantOffsetCoordinates<ct,dim>& c)
232 {
233 c.print(s);
234 return s;
235 }
236
241 template<class ct, int dim>
243 {
244 public:
246 typedef ct ctype;
248 static const int dimension = dim;
249
252
259 TensorProductCoordinates(const std::array<std::vector<ct>,dim>& c, const std::array<int,dim>& offset)
260 : _c(c),_offset(offset)
261 {}
262
267 inline ct meshsize(int d, int i) const
268 {
269 return _c[d][i+1-_offset[d]] - _c[d][i-_offset[d]];
270 }
271
276 inline ct coordinate(int d, int i) const
277 {
278 return _c[d][i-_offset[d]];
279 }
280
284 inline int size(int d) const
285 {
286 return _c[d].size() - 1;
287 }
288
295 TensorProductCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
296 {
297 std::array<std::vector<ct>,dim> newcoords;
298 std::array<int,dim> newoffset(_offset);
299 for (int i=0; i<dim; i++)
300 {
301 newoffset[i] *= 2;
302
303 //determine new size
304 int newsize = 2 * _c[i].size() - 1;
305 if (!keep_ovlp)
306 {
307 if (ovlp_low[i])
308 {
309 newoffset[i] += overlap;
310 newsize -= overlap;
311 }
312 if (ovlp_up[i])
313 newsize -= overlap;
314 }
315 newcoords[i].resize(newsize);
316
317 typename std::vector<ct>::const_iterator it = _c[i].begin();
318 typename std::vector<ct>::const_iterator end = _c[i].end()-1;
319 typename std::vector<ct>::iterator iit = newcoords[i].begin() - 1;
320 if (!keep_ovlp)
321 {
322 if (ovlp_low[i])
323 {
324 it += overlap/2;
325 if (overlap%2)
326 *(++iit) = (*it + *(++it)) / ct(2.);
327 }
328 if (ovlp_up[i])
329 end -= overlap/2;
330 }
331
332 for (;it!=end;)
333 {
334 *(++iit) = *it;
335 *(++iit) = (*it + *(++it)) / ct(2.);
336 }
337
338 if (++iit != newcoords[i].end())
339 *iit = *it;
340 }
341 return TensorProductCoordinates<ct,dim>(newcoords, newoffset);
342 }
343
345 void print(std::ostream& s) const
346 {
347 s << "Printing TensorProduct Coordinate information:" << std::endl;
348 for (int i=0; i<dim; i++)
349 {
350 s << "Direction " << i << ": " << _c[i].size() << " coordinates" << std::endl;
351 for (std::size_t j=0; j<_c[i].size(); j++)
352 s << _c[i][j] << std::endl;
353 }
354 }
355
356 private:
357 std::array<std::vector<ct>,dim> _c;
358 std::array<int,dim> _offset;
359 };
360
361 template<class ct, int dim>
362 inline std::ostream& operator<< (std::ostream& s, TensorProductCoordinates<ct,dim>& c)
363 {
364 c.print(s);
365 return s;
366 }
367
368 namespace Yasp {
369 template<class ctype, std::size_t dim>
370 bool checkIfMonotonous(const std::array<std::vector<ctype>, dim>& coords)
371 {
372 for (std::size_t i=0; i<dim; i++)
373 {
374 if (coords[i].size() <= 1)
375 return false;
376 for (std::size_t j=1; j<coords[i].size(); j++)
377 if (coords[i][j] < coords[i][j-1])
378 return false;
379 }
380 return true;
381 }
382 } // namespace Yasp
383} // namespace Dune
384
385#endif
Container for equidistant coordinates in a YaspGrid.
Definition: coordinates.hh:27
ct coordinate(int d, int i) const
Definition: coordinates.hh:63
int size(int d) const
Definition: coordinates.hh:71
static const int dimension
export dimension
Definition: coordinates.hh:32
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:105
EquidistantCoordinates()
default constructor
Definition: coordinates.hh:35
EquidistantCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:82
ct ctype
export the coordinate type
Definition: coordinates.hh:30
EquidistantCoordinates(const Dune::FieldVector< ct, dim > &upperRight, const std::array< int, dim > &s)
construct a container with all necessary information
Definition: coordinates.hh:43
ct meshsize(int d, int i) const
Definition: coordinates.hh:54
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:129
EquidistantOffsetCoordinates()
default constructor
Definition: coordinates.hh:137
EquidistantOffsetCoordinates(const Dune::FieldVector< ct, dim > &lowerLeft, const Dune::FieldVector< ct, dim > &upperRight, const std::array< int, dim > &s)
construct a container with all necessary information
Definition: coordinates.hh:147
EquidistantOffsetCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:194
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:217
ct meshsize(int d, int i) const
Definition: coordinates.hh:158
ct origin(int d) const
Definition: coordinates.hh:183
int size(int d) const
Definition: coordinates.hh:175
ct ctype
export the coordinate type
Definition: coordinates.hh:132
static const int dimension
export dimension
Definition: coordinates.hh:134
ct coordinate(int d, int i) const
Definition: coordinates.hh:167
Coordinate container for a tensor product YaspGrid.
Definition: coordinates.hh:243
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:345
ct meshsize(int d, int i) const
Definition: coordinates.hh:267
ct coordinate(int d, int i) const
Definition: coordinates.hh:276
static const int dimension
export dimension
Definition: coordinates.hh:248
TensorProductCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:295
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:259
TensorProductCoordinates()
the default constructor
Definition: coordinates.hh:251
ct ctype
export the coordinate type
Definition: coordinates.hh:246
int size(int d) const
Definition: coordinates.hh:284
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)