/usr/include/dune/grid/albertagrid/geometry.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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ALBERTA_GEOMETRY_HH
#define DUNE_ALBERTA_GEOMETRY_HH
#include <dune/grid/common/geometry.hh>
#include <dune/grid/albertagrid/misc.hh>
#include <dune/grid/albertagrid/elementinfo.hh>
#if HAVE_ALBERTA
namespace Dune
{
// Forward Declarations
// --------------------
template< int dim, int dimworld >
class AlbertaGrid;
// AlbertaGridCoordinateReader
// ---------------------------
template< int codim, class GridImp >
struct AlbertaGridCoordinateReader
{
typedef typename std::remove_const< GridImp >::type Grid;
static const int dimension = Grid::dimension;
static const int codimension = codim;
static const int mydimension = dimension - codimension;
static const int coorddimension = Grid::dimensionworld;
typedef Alberta::Real ctype;
typedef Alberta::ElementInfo< dimension > ElementInfo;
typedef FieldVector< ctype, coorddimension > Coordinate;
AlbertaGridCoordinateReader ( const GridImp &grid,
const ElementInfo &elementInfo,
int subEntity )
: grid_( grid ),
elementInfo_( elementInfo ),
subEntity_( subEntity )
{}
const ElementInfo &elementInfo () const
{
return elementInfo_;
}
void coordinate ( int i, Coordinate &x ) const
{
assert( !elementInfo_ == false );
assert( (i >= 0) && (i <= mydimension) );
const int k = mapVertices( subEntity_, i );
const Alberta::GlobalVector &coord = grid_.getCoord( elementInfo_, k );
for( int j = 0; j < coorddimension; ++j )
x[ j ] = coord[ j ];
}
bool hasDeterminant () const
{
return false;
}
ctype determinant () const
{
assert( hasDeterminant() );
return ctype( 0 );
}
private:
static int mapVertices ( int subEntity, int i )
{
return Alberta::MapVertices< dimension, codimension >::apply( subEntity, i );
}
const Grid &grid_;
const ElementInfo &elementInfo_;
const int subEntity_;
};
// AlbertaGridGeometry
// -------------------
/** \class AlbertaGridGeometry
* \brief geometry implementation for AlbertaGrid
*
* Defines the geometry part of a mesh entity. Works for all dimensions,
* element types and dim of world. Provides reference element and mapping
* between local and global coordinates.
*
* \tparam mydim dimension of the element (0 <= dim <= 3)
* \tparam cdim dimension of global coordinates
* \tparam GridImp grid implementation
* (always const AlbertaGrid< dim, dimworld >)
*/
template< int mydim, int cdim, class GridImp >
class AlbertaGridGeometry
{
typedef AlbertaGridGeometry< mydim, cdim, GridImp > This;
// remember type of the grid
typedef GridImp Grid;
// dimension of barycentric coordinates
static const int dimbary = mydim + 1;
public:
//! type of coordinates
typedef Alberta::Real ctype;
static const int dimension = Grid :: dimension;
static const int mydimension = mydim;
static const int codimension = dimension - mydimension;
static const int coorddimension = cdim;
typedef FieldVector< ctype, mydimension > LocalCoordinate;
typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
private:
static const int numCorners = mydimension + 1;
typedef FieldMatrix< ctype, numCorners, coorddimension > CoordMatrix;
public:
AlbertaGridGeometry ()
{
invalidate();
}
template< class CoordReader >
AlbertaGridGeometry ( const CoordReader &coordReader )
{
build( coordReader );
}
/** \brief obtain the type of reference element */
GeometryType type () const
{
typedef typename Impl::SimplexTopology< mydimension >::type Topology;
return GeometryType( Topology() );
}
//! returns always true since we only have simplices
bool affine () const { return true; }
/** \brief number of corner the geometry */
int corners () const
{
return numCorners;
}
/** \brief obtain the i-th corner of this geometry */
GlobalCoordinate corner ( const int i ) const
{
assert( (i >= 0) && (i < corners()) );
return coord_[ i ];
}
/** \brief return center of geometry */
GlobalCoordinate center () const
{
return centroid_;
}
/** \brief map a point from the refence element to the geometry */
GlobalCoordinate global ( const LocalCoordinate &local ) const;
/** \brief map a point from the geometry to the reference element */
LocalCoordinate local ( const GlobalCoordinate &global ) const;
/** \brief integration element of the geometry mapping
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
ctype integrationElement () const
{
assert( calcedDet_ );
return elDet_;
}
/** \brief integration element of the geometry mapping */
ctype integrationElement ( const LocalCoordinate &local ) const
{
return integrationElement();
}
/** \brief volume of geometry */
ctype volume () const
{
return integrationElement() / ctype( Factorial< mydimension >::factorial );
}
/** \brief transposed of the geometry mapping's Jacobian
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
const JacobianTransposed &jacobianTransposed () const;
/** \brief transposed of the geometry mapping's Jacobian */
const JacobianTransposed &
jacobianTransposed ( const LocalCoordinate &local ) const
{
return jacobianTransposed();
}
/** \brief transposed inverse of the geometry mapping's Jacobian
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
const JacobianInverseTransposed &jacobianInverseTransposed () const;
/** \brief transposed inverse of the geometry mapping's Jacobian */
const JacobianInverseTransposed &
jacobianInverseTransposed ( const LocalCoordinate &local ) const
{
return jacobianInverseTransposed();
}
//***********************************************************************
// Methods that not belong to the Interface, but have to be public
//***********************************************************************
/** \brief invalidate the geometry */
void invalidate ()
{
builtJT_ = false;
builtJTInv_ = false;
calcedDet_ = false;
}
/** \brief build the geometry from a coordinate reader */
template< class CoordReader >
void build ( const CoordReader &coordReader );
void print ( std::ostream &out ) const;
private:
// calculates the volume of the element
ctype elDeterminant () const
{
return std::abs( Alberta::determinant( jacobianTransposed() ) );
}
//! the vertex coordinates
CoordMatrix coord_;
//! the center/centroid
GlobalCoordinate centroid_;
// storage for the transposed of the jacobian
mutable JacobianTransposed jT_;
// storage for the transposed inverse of the jacboian
mutable JacobianInverseTransposed jTInv_;
// has jT_ been computed, yet?
mutable bool builtJT_;
// has jTInv_ been computed, yet?
mutable bool builtJTInv_;
mutable bool calcedDet_; //!< true if determinant was calculated
mutable ctype elDet_; //!< storage of element determinant
};
// AlbertaGridGlobalGeometry
// -------------------------
template< int mydim, int cdim, class GridImp >
class AlbertaGridGlobalGeometry
: public AlbertaGridGeometry< mydim, cdim, GridImp >
{
typedef AlbertaGridGlobalGeometry< mydim, cdim, GridImp > This;
typedef AlbertaGridGeometry< mydim, cdim, GridImp > Base;
public:
AlbertaGridGlobalGeometry ()
: Base()
{}
template< class CoordReader >
AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
: Base( coordReader )
{}
};
#if !DUNE_ALBERTA_CACHE_COORDINATES
template< int dim, int cdim >
class AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >
{
typedef AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > > This;
// remember type of the grid
typedef AlbertaGrid< dim, cdim > Grid;
// dimension of barycentric coordinates
static const int dimbary = dim + 1;
typedef Alberta::ElementInfo< dim > ElementInfo;
public:
//! type of coordinates
typedef Alberta::Real ctype;
static const int dimension = Grid::dimension;
static const int mydimension = dimension;
static const int codimension = dimension - mydimension;
static const int coorddimension = cdim;
typedef FieldVector< ctype, mydimension > LocalCoordinate;
typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
private:
static const int numCorners = mydimension + 1;
typedef FieldMatrix< ctype, numCorners, coorddimension > CoordMatrix;
public:
AlbertaGridGlobalGeometry ()
{
invalidate();
}
template< class CoordReader >
AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
{
build( coordReader );
}
/** \brief obtain the type of reference element */
GeometryType type () const
{
typedef typename Impl::SimplexTopology< mydimension >::type Topology;
return GeometryType( Topology() );
}
/** \brief number of corner the geometry */
int corners () const
{
return numCorners;
}
/** \brief obtain the i-th corner of this geometry */
GlobalCoordinate corner ( const int i ) const
{
assert( (i >= 0) && (i < corners()) );
const Alberta::GlobalCoordinate &x = elementInfo_.coordinate( i );
GlobalCoordinate y;
for( int j = 0; j < coorddimension; ++j )
y[ j ] = x[ j ];
return y;
}
/** \brief return center of geometry */
GlobalCoordinate center () const
{
GlobalCoordinate centroid_ = corner( 0 );
for( int i = 1; i < numCorners; ++i )
centroid_ += corner( i );
centroid_ *= ctype( 1 ) / ctype( numCorners );
return centroid_;
}
/** \brief map a point from the refence element to the geometry */
GlobalCoordinate global ( const LocalCoordinate &local ) const;
/** \brief map a point from the geometry to the reference element */
LocalCoordinate local ( const GlobalCoordinate &global ) const;
/** \brief integration element of the geometry mapping
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
ctype integrationElement () const
{
return elementInfo_.geometryCache().integrationElement();
}
/** \brief integration element of the geometry mapping */
ctype integrationElement ( const LocalCoordinate &local ) const
{
return integrationElement();
}
/** \brief volume of geometry */
ctype volume () const
{
return integrationElement() / ctype( Factorial< mydimension >::factorial );
}
/** \brief transposed of the geometry mapping's Jacobian
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
const JacobianTransposed &jacobianTransposed () const
{
return elementInfo_.geometryCache().jacobianTransposed();
}
/** \brief transposed of the geometry mapping's Jacobian */
const JacobianTransposed &
jacobianTransposed ( const LocalCoordinate &local ) const
{
return jacobianTransposed();
}
/** \brief transposed inverse of the geometry mapping's Jacobian
*
* \note This method is not part of the geometry interface. It is used
* internally only.
*/
const JacobianInverseTransposed &jacobianInverseTransposed () const
{
return elementInfo_.geometryCache().jacobianInverseTransposed();
}
/** \brief transposed inverse of the geometry mapping's Jacobian */
const JacobianInverseTransposed &
jacobianInverseTransposed ( const LocalCoordinate &local ) const
{
return jacobianInverseTransposed();
}
//***********************************************************************
// Methods that not belong to the Interface, but have to be public
//***********************************************************************
/** \brief invalidate the geometry */
void invalidate ()
{
elementInfo_ = ElementInfo();
}
/** \brief build the geometry from a coordinate reader */
template< class CoordReader >
void build ( const CoordReader &coordReader )
{
elementInfo_ = coordReader.elementInfo();
}
private:
ElementInfo elementInfo_;
};
#endif // #if !DUNE_ALBERTA_CACHE_COORDINATES
// AlbertaGridLocalGeometryProvider
// --------------------------------
template< class Grid >
class AlbertaGridLocalGeometryProvider
{
typedef AlbertaGridLocalGeometryProvider< Grid > This;
public:
typedef typename Grid::ctype ctype;
static const int dimension = Grid::dimension;
template< int codim >
struct Codim
{
typedef AlbertaGridGeometry< dimension-codim, dimension, Grid > LocalGeometry;
};
typedef typename Codim< 0 >::LocalGeometry LocalElementGeometry;
typedef typename Codim< 1 >::LocalGeometry LocalFaceGeometry;
static const int numChildren = 2;
static const int numFaces = dimension + 1;
static const int minFaceTwist = Alberta::Twist< dimension, dimension-1 >::minTwist;
static const int maxFaceTwist = Alberta::Twist< dimension, dimension-1 >::maxTwist;
static const int numFaceTwists = maxFaceTwist - minFaceTwist + 1;
private:
struct GeoInFatherCoordReader;
struct FaceCoordReader;
AlbertaGridLocalGeometryProvider ()
{
buildGeometryInFather();
buildFaceGeometry();
}
~AlbertaGridLocalGeometryProvider ()
{
for( int child = 0; child < numChildren; ++child )
{
delete geometryInFather_[ child ][ 0 ];
delete geometryInFather_[ child ][ 1 ];
}
for( int i = 0; i < numFaces; ++i )
{
for( int j = 0; j < numFaceTwists; ++j )
delete faceGeometry_[ i ][ j ];
}
}
void buildGeometryInFather();
void buildFaceGeometry();
public:
const LocalElementGeometry &
geometryInFather ( int child, const int orientation = 1 ) const
{
assert( (child >= 0) && (child < numChildren) );
assert( (orientation == 1) || (orientation == -1) );
return *geometryInFather_[ child ][ (orientation + 1) / 2 ];
}
const LocalFaceGeometry &
faceGeometry ( int face, int twist = 0 ) const
{
assert( (face >= 0) && (face < numFaces) );
assert( (twist >= minFaceTwist) && (twist <= maxFaceTwist) );
return *faceGeometry_[ face ][ twist - minFaceTwist ];
}
static const This &instance ()
{
static This theInstance;
return theInstance;
}
private:
template< int codim >
static int mapVertices ( int subEntity, int i )
{
return Alberta::MapVertices< dimension, codim >::apply( subEntity, i );
}
const LocalElementGeometry *geometryInFather_[ numChildren ][ 2 ];
const LocalFaceGeometry *faceGeometry_[ numFaces ][ numFaceTwists ];
};
} // namespace Dune
#endif // #if HAVE_ALBERTA
#endif // #ifndef DUNE_ALBERTA_GEOMETRY_HH
|