Dune Core Modules (2.9.0)

coordinates.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_GRID_YASPGRID_COORDINATES_HH
6#define DUNE_GRID_YASPGRID_COORDINATES_HH
7
8#include <array>
9#include <bitset>
10#include <vector>
11
13
21namespace Dune
22{
27 template<class ct, int dim>
29 {
30 public:
32 typedef ct ctype;
34 static const int dimension = dim;
35
38
45 EquidistantCoordinates(const Dune::FieldVector<ct,dim>& upperRight, const std::array<int,dim>& s)
46 : _s(s)
47 {
48 for (int i=0; i<dim; i++)
49 _h[i] = upperRight[i] / _s[i];
50 }
51
56 inline ct meshsize(int d, [[maybe_unused]] int i) const
57 {
58 return _h[d];
59 }
60
65 inline ct coordinate(int d, int i) const
66 {
67 return i*_h[d];
68 }
69
73 inline int size(int d) const
74 {
75 return _s[d];
76 }
77
84 EquidistantCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
85 {
86 //determine new size and meshsize
87 std::array<int,dim> news;
88 Dune::FieldVector<ct,dim> newUpperRight;
89
90 for (int i=0; i<dim; i++)
91 {
92 news[i] = 2 * _s[i];
93 if (!keep_ovlp)
94 {
95 if (ovlp_low[i])
96 news[i] -= overlap;
97 if (ovlp_up[i])
98 news[i] -= overlap;
99 }
100
101 newUpperRight[i] = (_h[i] / ct(2.)) * news[i];
102 }
103 return EquidistantCoordinates<ct,dim>(newUpperRight,news);
104 }
105
107 void print(std::ostream& s) const
108 {
109 s << "Printing equidistant coordinate information:" << std::endl;
110 s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
111 }
112
113 private:
115 std::array<int,dim> _s;
116 };
117
118 template<class ct, int dim>
119 inline std::ostream& operator<< (std::ostream& s, EquidistantCoordinates<ct,dim>& c)
120 {
121 c.print(s);
122 return s;
123 }
124
129 template<class ct, int dim>
131 {
132 public:
134 typedef ct ctype;
136 static const int dimension = dim;
137
140
149 EquidistantOffsetCoordinates(const Dune::FieldVector<ct,dim>& lowerLeft, const Dune::FieldVector<ct,dim>& upperRight, const std::array<int,dim>& s)
150 : _origin(lowerLeft), _s(s)
151 {
152 for (int i=0; i<dim; i++)
153 _h[i] = (upperRight[i] - lowerLeft[i]) / s[i];
154 }
155
160 inline ct meshsize(int d, [[maybe_unused]] int i) const
161 {
162 return _h[d];
163 }
164
169 inline ct coordinate(int d, int i) const
170 {
171 return _origin[d] + i*_h[d];
172 }
173
177 inline int size(int d) const
178 {
179 return _s[d];
180 }
181
185 inline ct origin(int d) const
186 {
187 return _origin[d];
188 }
189
196 EquidistantOffsetCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
197 {
198 //determine new size and meshsize
199 std::array<int,dim> news;
200 Dune::FieldVector<ct,dim> newUpperRight;
201
202 for (int i=0; i<dim; i++)
203 {
204 news[i] = 2 * _s[i];
205 if (!keep_ovlp)
206 {
207 if (ovlp_low[i])
208 news[i] -= overlap;
209 if (ovlp_up[i])
210 news[i] -= overlap;
211 }
212
213 newUpperRight[i] = _origin[i] + (_h[i] / ct(2.)) * news[i];
214 }
215 return EquidistantOffsetCoordinates<ct,dim>(_origin,newUpperRight,news);
216 }
217
219 void print(std::ostream& s) const
220 {
221 s << "Printing equidistant coordinate information:" << std::endl;
222 s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
223 s << "Offset to origin: " << _origin << std::endl;
224 }
225
226 private:
229 std::array<int,dim> _s;
230 };
231
232 template<class ct, int dim>
233 inline std::ostream& operator<< (std::ostream& s, EquidistantOffsetCoordinates<ct,dim>& c)
234 {
235 c.print(s);
236 return s;
237 }
238
243 template<class ct, int dim>
245 {
246 public:
248 typedef ct ctype;
250 static const int dimension = dim;
251
254
261 TensorProductCoordinates(const std::array<std::vector<ct>,dim>& c, const std::array<int,dim>& offset)
262 : _c(c),_offset(offset)
263 {}
264
269 inline ct meshsize(int d, int i) const
270 {
271 return _c[d][i+1-_offset[d]] - _c[d][i-_offset[d]];
272 }
273
278 inline ct coordinate(int d, int i) const
279 {
280 return _c[d][i-_offset[d]];
281 }
282
286 inline int size(int d) const
287 {
288 return _c[d].size() - 1;
289 }
290
297 TensorProductCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
298 {
299 std::array<std::vector<ct>,dim> newcoords;
300 std::array<int,dim> newoffset(_offset);
301 for (int i=0; i<dim; i++)
302 {
303 newoffset[i] *= 2;
304
305 //determine new size
306 int newsize = 2 * _c[i].size() - 1;
307 if (!keep_ovlp)
308 {
309 if (ovlp_low[i])
310 {
311 newoffset[i] += overlap;
312 newsize -= overlap;
313 }
314 if (ovlp_up[i])
315 newsize -= overlap;
316 }
317 newcoords[i].resize(newsize);
318
319 typename std::vector<ct>::const_iterator it = _c[i].begin();
320 typename std::vector<ct>::const_iterator end = _c[i].end()-1;
321 typename std::vector<ct>::iterator iit = newcoords[i].begin() - 1;
322 if (!keep_ovlp)
323 {
324 if (ovlp_low[i])
325 {
326 it += overlap/2;
327 if (overlap%2)
328 *(++iit) = (*it + *(++it)) / ct(2.);
329 }
330 if (ovlp_up[i])
331 end -= overlap/2;
332 }
333
334 for (;it!=end;)
335 {
336 *(++iit) = *it;
337 *(++iit) = (*it + *(++it)) / ct(2.);
338 }
339
340 if (++iit != newcoords[i].end())
341 *iit = *it;
342 }
343 return TensorProductCoordinates<ct,dim>(newcoords, newoffset);
344 }
345
347 void print(std::ostream& s) const
348 {
349 s << "Printing TensorProduct Coordinate information:" << std::endl;
350 for (int i=0; i<dim; i++)
351 {
352 s << "Direction " << i << ": " << _c[i].size() << " coordinates" << std::endl;
353 for (std::size_t j=0; j<_c[i].size(); j++)
354 s << _c[i][j] << std::endl;
355 }
356 }
357
358 private:
359 std::array<std::vector<ct>,dim> _c;
360 std::array<int,dim> _offset;
361 };
362
363 template<class ct, int dim>
364 inline std::ostream& operator<< (std::ostream& s, TensorProductCoordinates<ct,dim>& c)
365 {
366 c.print(s);
367 return s;
368 }
369
370 namespace Yasp {
371 template<class ctype, std::size_t dim>
372 bool checkIfMonotonous(const std::array<std::vector<ctype>, dim>& coords)
373 {
374 for (std::size_t i=0; i<dim; i++)
375 {
376 if (coords[i].size() <= 1)
377 return false;
378 for (std::size_t j=1; j<coords[i].size(); j++)
379 if (coords[i][j] < coords[i][j-1])
380 return false;
381 }
382 return true;
383 }
384 } // namespace Yasp
385} // namespace Dune
386
387#endif
Container for equidistant coordinates in a YaspGrid.
Definition: coordinates.hh:29
ct coordinate(int d, int i) const
Definition: coordinates.hh:65
int size(int d) const
Definition: coordinates.hh:73
static const int dimension
export dimension
Definition: coordinates.hh:34
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:107
EquidistantCoordinates()
default constructor
Definition: coordinates.hh:37
EquidistantCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:84
ct ctype
export the coordinate type
Definition: coordinates.hh:32
EquidistantCoordinates(const Dune::FieldVector< ct, dim > &upperRight, const std::array< int, dim > &s)
construct a container with all necessary information
Definition: coordinates.hh:45
ct meshsize(int d, int i) const
Definition: coordinates.hh:56
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:131
EquidistantOffsetCoordinates()
default constructor
Definition: coordinates.hh:139
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:149
EquidistantOffsetCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:196
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:219
ct meshsize(int d, int i) const
Definition: coordinates.hh:160
ct origin(int d) const
Definition: coordinates.hh:185
int size(int d) const
Definition: coordinates.hh:177
ct ctype
export the coordinate type
Definition: coordinates.hh:134
static const int dimension
export dimension
Definition: coordinates.hh:136
ct coordinate(int d, int i) const
Definition: coordinates.hh:169
Coordinate container for a tensor product YaspGrid.
Definition: coordinates.hh:245
void print(std::ostream &s) const
print information on this container
Definition: coordinates.hh:347
ct meshsize(int d, int i) const
Definition: coordinates.hh:269
ct coordinate(int d, int i) const
Definition: coordinates.hh:278
static const int dimension
export dimension
Definition: coordinates.hh:250
TensorProductCoordinates< ct, dim > refine(std::bitset< dim > ovlp_low, std::bitset< dim > ovlp_up, int overlap, bool keep_ovlp) const
Definition: coordinates.hh:297
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:261
TensorProductCoordinates()
the default constructor
Definition: coordinates.hh:253
ct ctype
export the coordinate type
Definition: coordinates.hh:248
int size(int d) const
Definition: coordinates.hh:286
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)