/usr/include/dune/grid/yaspgrid/coordinates.hh is in libdune-grid-dev 2.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GRID_YASPGRID_COORDINATES_HH
#define DUNE_GRID_YASPGRID_COORDINATES_HH
#include <array>
#include <bitset>
#include <vector>
#include <dune/common/fvector.hh>
/** \file
* \brief This provides container classes for the coordinates to be used in YaspGrid
* Upon implementation of the tensorproduct feature, the coordinate information has
* been encapsulated to keep performance for the equidistant grid. Containers for
* equidistant and tensorproduct grids are provided here.
*/
namespace Dune
{
/** \brief Container for equidistant coordinates in a YaspGrid
* @tparam ct the coordinate type
* @tparam dim the dimension of the grid
*/
template<class ct, int dim>
class EquidistantCoordinates
{
public:
//! export the coordinate type
typedef ct ctype;
//! export dimension
static const int dimension = dim;
/** \brief default constructor */
EquidistantCoordinates() {}
/** \brief construct a container with all necessary information
* \param h the meshsize in all directions
* \param s the size (in codim 0 elements) of the grid on this processor
* the size information is kept with this container, because this is the natural
* way to handle this for a tensorproduct grid.
*/
EquidistantCoordinates(const Dune::FieldVector<ct,dim>& h, const std::array<int,dim>& s)
: _h(h), _s(s) {}
/** \returns the meshsize in given direction at given position
* \param d the direction to be used
* \param i the global coordinate index where to return the meshsize
*/
inline ct meshsize(int d, int i) const
{
return _h[d];
}
/** \returns a coordinate given a direction and an index
* \param d the direction to be used
* \param i the global coordinate index
*/
inline ct coordinate(int d, int i) const
{
return i*_h[d];
}
/** \returns the size in given direction
* \param d the direction to be used
*/
inline int size(int d) const
{
return _s[d];
}
/** \returns a container that represents the same grid after one step of uniform refinement
* \param ovlp_low whether we have an overlap area at the lower processor boundary
* \param ovlp_up whether we have an overlap area at the upper processor boundary
* \param overlap the size of the overlap region
* \param keep_ovlp the refinement option parameter to be used
*/
EquidistantCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
{
//determine new size and meshsize
std::array<int,dim> news;
Dune::FieldVector<ct,dim> newh;
for (int i=0; i<dim; i++)
{
news[i] = 2 * _s[i];
if (!keep_ovlp)
{
if (ovlp_low[i])
news[i] -= overlap;
if (ovlp_up[i])
news[i] -= overlap;
}
newh[i] = _h[i] / 2.;
}
return EquidistantCoordinates<ct,dim>(newh,news);
}
/** \brief print information on this container */
void print(std::ostream& s) const
{
s << "Printing equidistant coordinate information:" << std::endl;
s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
}
private:
Dune::FieldVector<ct,dim> _h;
std::array<int,dim> _s;
};
template<class ct, int dim>
inline std::ostream& operator<< (std::ostream& s, EquidistantCoordinates<ct,dim>& c)
{
c.print(s);
return s;
}
/** \brief Container for equidistant coordinates in a YaspGrid with non-trivial origin
* @tparam ct the coordinate type
* @tparam dim the dimension of the grid
*/
template<class ct, int dim>
class EquidistantOffsetCoordinates
{
public:
//! export the coordinate type
typedef ct ctype;
//! export dimension
static const int dimension = dim;
/** \brief default constructor */
EquidistantOffsetCoordinates() {}
/** \brief construct a container with all necessary information
* \param h the meshsize in all directions
* \param s the size (in codim 0 elements) of the grid on this processor
* \param origin the coordinate of the lowerleft corner of this grid
* the size information is kept with this container, because this is the natural
* way to handle this for a tensorproduct grid.
*/
EquidistantOffsetCoordinates(const Dune::FieldVector<ct,dim>& origin, const Dune::FieldVector<ct,dim>& h, const std::array<int,dim>& s)
: _origin(origin), _h(h), _s(s) {}
/** \returns the meshsize in given direction at given position
* \param d the direction to be used
* \param i the global coordinate index where to return the meshsize
*/
inline ct meshsize(int d, int i) const
{
return _h[d];
}
/** \returns a coordinate given a direction and an index
* \param d the direction to be used
* \param i the global coordinate index
*/
inline ct coordinate(int d, int i) const
{
return _origin[d] + i*_h[d];
}
/** \returns the size in given direction
* \param d the direction to be used
*/
inline int size(int d) const
{
return _s[d];
}
/** \returns the dth component of the origin
* \param d the direction to be used
*/
inline ct origin(int d) const
{
return _origin[d];
}
/** \returns a container that represents the same grid after one step of uniform refinement
* \param ovlp_low whether we have an overlap area at the lower processor boundary
* \param ovlp_up whether we have an overlap area at the upper processor boundary
* \param overlap the size of the overlap region
* \param keep_ovlp the refinement option parameter to be used
*/
EquidistantOffsetCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
{
//determine new size and meshsize
std::array<int,dim> news;
Dune::FieldVector<ct,dim> newh;
for (int i=0; i<dim; i++)
{
news[i] = 2 * _s[i];
if (!keep_ovlp)
{
if (ovlp_low[i])
news[i] -= overlap;
if (ovlp_up[i])
news[i] -= overlap;
}
newh[i] = _h[i] / 2.;
}
return EquidistantOffsetCoordinates<ct,dim>(_origin,newh,news);
}
/** \brief print information on this container */
void print(std::ostream& s) const
{
s << "Printing equidistant coordinate information:" << std::endl;
s << "Meshsize: " << _h << std::endl << "Size: " << _s << std::endl;
s << "Offset to origin: " << _origin << std::endl;
}
private:
Dune::FieldVector<ct,dim> _origin;
Dune::FieldVector<ct,dim> _h;
std::array<int,dim> _s;
};
template<class ct, int dim>
inline std::ostream& operator<< (std::ostream& s, EquidistantOffsetCoordinates<ct,dim>& c)
{
c.print(s);
return s;
}
/** \brief Coordinate container for a tensor product YaspGrid
* @tparam ct the coordinate type
* @tparam dim the dimension of the grid
*/
template<class ct, int dim>
class TensorProductCoordinates
{
public:
//! export the coordinate type
typedef ct ctype;
//! export dimension
static const int dimension = dim;
/** \brief the default constructor */
TensorProductCoordinates() {}
/** \brief construct a container with all necessary information
* \param c the array of coordinate vectors
* \param offset the offset between global origin and processor origin
* the size information is deduced from c. Storing offset allows for use of
* global coordinates in the YaspGrid code.
*/
TensorProductCoordinates(const std::array<std::vector<ct>,dim>& c, const std::array<int,dim>& offset)
: _c(c),_offset(offset)
{}
/** \returns the meshsize in given direction at given position
* \param d the direction to be used
* \param i the global coordinate index where to return the meshsize
*/
inline ct meshsize(int d, int i) const
{
return _c[d][i+1-_offset[d]] - _c[d][i-_offset[d]];
}
/** \returns a coordinate given a direction and an index
* \param d the direction to be used
* \param i the global coordinate index
*/
inline ct coordinate(int d, int i) const
{
return _c[d][i-_offset[d]];
}
/** \returns the size in given direction
* \param d the direction to be used
*/
inline int size(int d) const
{
return _c[d].size() - 1;
}
/** \returns a container that represents the same grid after one step of uniform refinement
* \param ovlp_low whether we have an overlap area at the lower processor boundary
* \param ovlp_up whether we have an overlap area at the upper processor boundary
* \param overlap the size of the overlap region
* \param keep_ovlp the refinement option parameter to be used
*/
TensorProductCoordinates<ct,dim> refine(std::bitset<dim> ovlp_low, std::bitset<dim> ovlp_up, int overlap, bool keep_ovlp) const
{
std::array<std::vector<ct>,dim> newcoords;
std::array<int,dim> newoffset(_offset);
for (int i=0; i<dim; i++)
{
newoffset[i] *= 2;
//determine new size
int newsize = 2 * _c[i].size() - 1;
if (!keep_ovlp)
{
if (ovlp_low[i])
{
newoffset[i] += overlap;
newsize -= overlap;
}
if (ovlp_up[i])
newsize -= overlap;
}
newcoords[i].resize(newsize);
typename std::vector<ct>::const_iterator it = _c[i].begin();
typename std::vector<ct>::const_iterator end = _c[i].end()-1;
typename std::vector<ct>::iterator iit = newcoords[i].begin() - 1;
if (!keep_ovlp)
{
if (ovlp_low[i])
{
it += overlap/2;
if (overlap%2)
*(++iit) = (*it + *(++it)) / 2.;
}
if (ovlp_up[i])
end -= overlap/2;
}
for (;it!=end;)
{
*(++iit) = *it;
*(++iit) = (*it + *(++it)) / 2.;
}
if (++iit != newcoords[i].end())
*iit = *it;
}
return TensorProductCoordinates<ct,dim>(newcoords, newoffset);
}
/** \brief print information on this container */
void print(std::ostream& s) const
{
s << "Printing TensorProduct Coordinate information:" << std::endl;
for (int i=0; i<dim; i++)
{
s << "Direction " << i << ": " << _c[i].size() << " coordinates" << std::endl;
for (std::size_t j=0; j<_c[i].size(); j++)
s << _c[i][j] << std::endl;
}
}
private:
std::array<std::vector<ct>,dim> _c;
std::array<int,dim> _offset;
};
template<class ct, int dim>
inline std::ostream& operator<< (std::ostream& s, TensorProductCoordinates<ct,dim>& c)
{
c.print(s);
return s;
}
namespace Yasp {
template<class ctype, std::size_t dim>
bool checkIfMonotonous(const std::array<std::vector<ctype>, dim>& coords)
{
for (std::size_t i=0; i<dim; i++)
{
if (coords[i].size() <= 1)
return false;
for (std::size_t j=1; j<coords[i].size(); j++)
if (coords[i][j] < coords[i][j-1])
return false;
}
return true;
}
} // namespace Yasp
} // namespace Dune
#endif
|