/usr/include/dune/grid/alugrid/2d/geometry.hh is in libdune-grid-dev 2.2.1-2.
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 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | #ifndef DUNE_ALU2DGRIDGEOMETRY_HH
#define DUNE_ALU2DGRIDGEOMETRY_HH
// Dune includes
#include <dune/common/misc.hh>
#include <dune/grid/common/grid.hh>
#include <dune/geometry/genericgeometry/topologytypes.hh>
#include <dune/grid/alugrid/2d/alu2dinclude.hh>
#include <dune/grid/alugrid/3d/mappings.hh>
#include <dune/grid/alugrid/common/memory.hh>
namespace Dune
{
// Forward declarations
template<int cd, int dim, class GridImp>
class ALU2dGridEntity;
template<int cd, class GridImp >
class ALU2dGridEntityPointer;
template<int mydim, int cdim, class GridImp>
class ALU2dGridGeometry;
template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
class ALU2dGrid;
template< int mydim, int cdim, ALU2DSPACE ElementType eltype >
class MyALU2dGridGeometryImpl;
// geometry implementation for vertices
template< int cdim, ALU2DSPACE ElementType eltype >
class MyALU2dGridGeometryImpl< 0, cdim, eltype >
{
typedef LinearMapping< cdim, 0 > MappingType;
typedef typename MappingType::ctype ctype;
typedef typename MappingType::map_t map_t;
typedef typename MappingType::world_t world_t;
typedef typename MappingType::matrix_t matrix_t;
typedef typename MappingType::inv_t inv_t;
MappingType mapping_;
bool valid_ ;
const MappingType& mapping() const
{
assert( valid() );
return mapping_;
}
public:
MyALU2dGridGeometryImpl() : mapping_(), valid_( false ) {}
// returns true if goemetry info is valid
bool valid () const { return valid_; }
// reset geometry status
void invalidate() { valid_ = false ; }
bool affine() const
{
assert( valid() );
return mapping().affine();
}
int corners () const
{
return 1;
}
GeometryType type () const
{
return GeometryType(
(eltype == ALU2DSPACE triangle ?
GenericGeometry :: SimplexTopology< 0 > :: type :: id :
GenericGeometry :: CubeTopology < 0 > :: type :: id),
0 );
}
void map2world ( const map_t &m, world_t &w ) const
{
return mapping().map2world( m, w );
}
void world2map ( const world_t &w, map_t &m ) const
{
return mapping().world2map( w, m );
}
const matrix_t &jacobianTransposed ( const map_t &m ) const
{
return mapping().jacobianTransposed( m );
}
const inv_t &jacobianInverseTransposed ( const map_t &m ) const
{
return mapping().jacobianInverseTransposed( m );
}
ctype det ( const map_t &m ) const
{
return mapping().det( m );
}
// update geometry coordinates
template< class Vector >
void update ( const Vector &p0 )
{
mapping_.buildMapping( p0 );
valid_ = true ;
}
};
// geometry implementation for lines
template< int cdim, ALU2DSPACE ElementType eltype >
class MyALU2dGridGeometryImpl< 1, cdim, eltype >
{
static const int ncorners = 2;
typedef LinearMapping< cdim, 1 > MappingType;
typedef typename MappingType::ctype ctype;
typedef typename MappingType::map_t map_t;
typedef typename MappingType::world_t world_t;
typedef typename MappingType::matrix_t matrix_t;
typedef typename MappingType::inv_t inv_t;
MappingType mapping_;
bool valid_;
const MappingType& mapping() const
{
assert( valid() );
return mapping_;
}
public:
MyALU2dGridGeometryImpl() : mapping_(), valid_( false ) {}
// returns true if goemetry info is valid
bool valid () const { return valid_; }
// reset geometry status
void invalidate() { valid_ = false ; }
bool affine() const
{
return mapping().affine();
}
int corners () const
{
return ncorners;
}
GeometryType type () const
{
return GeometryType(
(eltype == ALU2DSPACE triangle ?
GenericGeometry :: SimplexTopology< 1 > :: type :: id :
GenericGeometry :: CubeTopology < 1 > :: type :: id),
1 );
}
void map2world ( const map_t &m, world_t &w ) const
{
return mapping().map2world( m, w );
}
void world2map ( const world_t &w, map_t &m ) const
{
return mapping().world2map( w, m );
}
const matrix_t &jacobianTransposed ( const map_t &m ) const
{
return mapping().jacobianTransposed( m );
}
const inv_t &jacobianInverseTransposed ( const map_t &m ) const
{
return mapping().jacobianInverseTransposed( m );
}
ctype det ( const map_t &m ) const
{
return mapping().det( m );
}
// update geometry in father coordinates
template< class Geo, class LocalGeo >
void updateLocal ( const Geo &geo, const LocalGeo &localGeo )
{
assert( localGeo.corners() == ncorners );
// compute the local coordinates in father refelem
FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
for( int i = 0; i < ncorners; ++i )
{
// calculate coordinate
coord[ i ] = geo.local( localGeo.corner( i ) );
// to avoid rounding errors
for( int j = 0; j < cdim; ++j )
coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
}
mapping_.buildMapping( coord[ 0 ], coord[ 1 ] );
valid_ = true ;
}
// update geometry coordinates
template< class Vector >
void update ( const Vector &p0, const Vector &p1 )
{
mapping_.buildMapping( p0, p1 );
valid_ = true ;
}
};
// geometry implementation for triangles
template< int cdim >
class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE triangle >
{
static const int ncorners = 3;
typedef LinearMapping< cdim, 2 > MappingType;
typedef typename MappingType::ctype ctype;
typedef typename MappingType::map_t map_t;
typedef typename MappingType::world_t world_t;
typedef typename MappingType::matrix_t matrix_t;
typedef typename MappingType::inv_t inv_t;
MappingType mapping_;
bool valid_;
const MappingType& mapping() const
{
assert( valid() );
return mapping_;
}
public:
MyALU2dGridGeometryImpl() : mapping_(), valid_( false ) {}
// returns true if goemetry info is valid
bool valid () const { return valid_; }
// reset geometry status
void invalidate() { valid_ = false ; }
bool affine () const
{
return mapping().affine();
}
int corners () const
{
return ncorners;
}
GeometryType type () const
{
return GeometryType( GenericGeometry :: SimplexTopology< 2 > :: type :: id , 2 );
}
void map2world ( const map_t &m, world_t &w ) const
{
return mapping().map2world( m, w );
}
void world2map ( const world_t &w, map_t &m ) const
{
return mapping().world2map( w, m );
}
const matrix_t &jacobianTransposed ( const map_t &m ) const
{
return mapping().jacobianTransposed( m );
}
const inv_t &jacobianInverseTransposed ( const map_t &m ) const
{
return mapping().jacobianInverseTransposed( m );
}
ctype det ( const map_t &m ) const
{
return mapping().det( m );
}
// update geometry in father coordinates
template< class Geo, class LocalGeo >
void updateLocal ( const Geo &geo, const LocalGeo &localGeo )
{
assert( localGeo.corners() == ncorners );
// compute the local coordinates in father refelem
FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
for( int i = 0; i < ncorners; ++i )
{
// calculate coordinate
coord[ i ] = geo.local( localGeo.corner( i ) );
// to avoid rounding errors
for( int j = 0; j < cdim; ++j )
coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
}
mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
valid_ = true ;
}
template< class HElement >
void update ( const HElement &item )
{
mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
item.getVertex( 2 )->coord() );
valid_ = true ;
}
};
// geometry implementation for quadrilaterals
template< int cdim >
class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE quadrilateral >
{
static const int ncorners = 4;
typedef BilinearMapping< cdim > MappingType;
typedef typename MappingType::ctype ctype;
typedef typename MappingType::map_t map_t;
typedef typename MappingType::world_t world_t;
typedef typename MappingType::matrix_t matrix_t;
typedef typename MappingType::inv_t inv_t;
MappingType mapping_;
bool valid_ ;
const MappingType& mapping() const
{
assert( valid() );
return mapping_;
}
public:
MyALU2dGridGeometryImpl() : mapping_(), valid_( false ) {}
// returns true if goemetry info is valid
bool valid () const { return valid_; }
// reset geometry status
void invalidate() { valid_ = false ; }
bool affine () const
{
return mapping().affine();
}
int corners () const
{
return ncorners;
}
GeometryType type () const
{
return GeometryType( GeometryType::cube, 2 );
}
void map2world ( const map_t &m, world_t &w ) const
{
return mapping().map2world( m, w );
}
void world2map ( const world_t &w, map_t &m ) const
{
return mapping().world2map( w, m );
}
const matrix_t &jacobianTransposed ( const map_t &m ) const
{
return mapping().jacobianTransposed( m );
}
const inv_t &jacobianInverseTransposed ( const map_t &m ) const
{
return mapping().jacobianInverseTransposed( m );
}
ctype det ( const map_t &m ) const
{
return mapping().det( m );
}
// update geometry in father coordinates
template< class Geo, class LocalGeo >
void updateLocal ( const Geo &geo, const LocalGeo &localGeo )
{
assert( localGeo.corners() == ncorners );
// compute the local coordinates in father refelem
FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
for( int i = 0; i < ncorners; ++i )
{
// calculate coordinate
coord[ i ] = geo.local( localGeo.corner( i ) );
// to avoid rounding errors
for( int j = 0; j < cdim; ++j )
coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
}
mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
valid_ = true ;
}
template< class HElement >
void update ( const HElement &item )
{
mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
valid_ = true ;
}
};
// geometry implementation for triangles
template< int cdim >
class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE mixed >
{
typedef Dune::LinearMapping< cdim, 2 > LinearMapping;
typedef Dune::BilinearMapping< cdim > BilinearMapping;
typedef typename LinearMapping::ctype ctype;
typedef typename LinearMapping::map_t map_t;
typedef typename LinearMapping::world_t world_t;
typedef typename LinearMapping::matrix_t matrix_t;
typedef typename LinearMapping::inv_t inv_t;
static const int lms = sizeof( LinearMapping );
static const int bms = sizeof( BilinearMapping );
char mapping_[ lms > bms ? lms : bms ];
int corners_;
bool valid_ ;
public:
MyALU2dGridGeometryImpl () : corners_( 0 ), valid_( false ) {}
MyALU2dGridGeometryImpl ( const MyALU2dGridGeometryImpl &other )
: corners_( other.corners() ), valid_( other.valid_ )
{
if( corners_ == 3 )
new( &mapping_ ) LinearMapping( other.linearMapping() );
if( corners_ == 4 )
new( &mapping_ ) BilinearMapping( other.bilinearMapping() );
}
// returns true if goemetry info is valid
bool valid () const { return valid_; }
// reset geometry status
void invalidate() { valid_ = false ; }
bool affine () const
{
return (corners() == 3 ? linearMapping().affine() : bilinearMapping().affine());
}
int corners () const
{
return corners_;
}
GeometryType type () const
{
return GeometryType( (corners_ == 3 ?
GenericGeometry :: SimplexTopology< 2 > :: type :: id :
GenericGeometry :: CubeTopology < 2 > :: type :: id), 2);
}
void map2world ( const map_t &m, world_t &w ) const
{
if( corners() == 3 )
linearMapping().map2world( m, w );
else
bilinearMapping().map2world( m, w );
}
void world2map ( const world_t &w, map_t &m ) const
{
if( corners() == 3 )
linearMapping().world2map( w, m );
else
bilinearMapping().world2map( w, m );
}
const matrix_t &jacobianTransposed ( const map_t &m ) const
{
return (corners() == 3 ? linearMapping().jacobianTransposed( m ) : bilinearMapping().jacobianTransposed( m ));
}
const inv_t &jacobianInverseTransposed ( const map_t &m ) const
{
return (corners() == 3 ? linearMapping().jacobianInverseTransposed( m ) : bilinearMapping().jacobianInverseTransposed( m ));
}
ctype det ( const map_t &m ) const
{
return (corners() == 3 ? linearMapping().det( m ) : bilinearMapping().det( m ));
}
// update geometry in father coordinates
template< class Geo, class LocalGeo >
void updateLocal ( const Geo &geo, const LocalGeo &localGeo )
{
const int corners = localGeo.corners();
// compute the local coordinates in father refelem
FieldMatrix< alu2d_ctype, 4, cdim > coord;
for( int i = 0; i < corners; ++i )
{
// calculate coordinate
coord[ i ] = geo.local( localGeo.corner( i ) );
// to avoid rounding errors
for( int j = 0; j < cdim; ++j )
coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
}
updateMapping( corners );
if( corners == 3 )
linearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
else
bilinearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
valid_ = true ;
}
template< class HElement >
void update ( const HElement &item )
{
const int corners = item.numvertices();
updateMapping( corners );
if( corners == 3 )
linearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
item.getVertex( 2 )->coord() );
else
bilinearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
valid_ = true ;
}
private:
MyALU2dGridGeometryImpl &operator= ( const MyALU2dGridGeometryImpl &other );
const LinearMapping &linearMapping () const
{
assert( valid() );
return static_cast< const LinearMapping * >( &mapping_ );
}
LinearMapping &linearMapping ()
{
assert( valid() );
return static_cast< LinearMapping * >( &mapping_ );
}
const BilinearMapping &bilinearMapping () const
{
assert( valid() );
return static_cast< const BilinearMapping * >( &mapping_ );
}
BilinearMapping &bilinearMapping ()
{
assert( valid() );
return static_cast< BilinearMapping * >( &mapping_ );
}
void updateMapping ( const int corners )
{
assert( (corners == 3) || (corners == 4) );
if( corners != corners_ )
{
destroyMapping();
corners = corners_;
if( corners == 3 )
new( &mapping_ ) LinearMapping;
else
new( &mapping_ ) BilinearMapping;
}
}
void destroyMapping ()
{
if( corners() == 3 )
linearMapping().~LinearMapping();
else if( corners() == 4 )
bilinearMapping().~BilinearMapping();
}
};
//**********************************************************************
//
// --ALU2dGridGeometry
// --Geometry
//**********************************************************************
/*!
Defines the geometry part of a mesh entity. Works for all dimensions, element types and dimensions
of world. Provides reference element and mapping between local and global coordinates.
The element may have different implementations because the mapping can be
done more efficient for structured meshes than for unstructured meshes.
dim: An element is a polygonal in a hyperplane of dimension dim. 0 <= dim <= 2 is typically
dim=0 is a point.
dimworld: Each corner is a point with dimworld coordinates.
*/
//! ALU2dGridGeometry
//! Empty definition, needs to be specialized for element type
template< int mydim, int cdim, class GridImp >
class ALU2dGridGeometry
: public GeometryDefaultImplementation< mydim, cdim, GridImp, ALU2dGridGeometry >
{
static const ALU2DSPACE ElementType eltype = GridImp::elementType;
//! type of our Geometry interface
typedef typename GridImp::template Codim<0>::Geometry Geometry;
//! type of our Geometry implementation
typedef ALU2dGridGeometry<mydim,cdim,GridImp> GeometryImp;
//! know dimension of barycentric coordinates
enum { dimbary=mydim+1};
typedef typename ALU2dImplTraits< GridImp::dimensionworld, eltype >::HElementType HElementType ;
typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, eltype >::Type VertexType;
// type of specialized geometry implementation
typedef MyALU2dGridGeometryImpl< mydim, cdim, eltype > GeometryImplType;
public:
typedef FieldVector< alu2d_ctype, cdim > GlobalCoordinate;
typedef FieldVector< alu2d_ctype, mydim > LocalCoordinate;
public:
//! for makeRefGeometry == true a Geometry with the coordinates of the
//! reference element is made
ALU2dGridGeometry();
//! return the element type identifier
//! line , triangle or tetrahedron, depends on dim
const GeometryType type () const { return geoImpl_.type(); }
//! return the number of corners of this element. Corners are numbered 0...n-1
int corners () const { return geoImpl_.corners(); }
//! access to coordinates of corners. Index is the number of the corner
const GlobalCoordinate &operator[] ( int i ) const;
//! access to coordinates of corners. Index is the number of the corner
GlobalCoordinate corner ( int i ) const;
//! maps a local coordinate within reference element to
//! global coordinate in element
GlobalCoordinate global ( const LocalCoordinate& local ) const;
//! maps a global coordinate within the element to a
//! local coordinate in its reference element
LocalCoordinate local (const GlobalCoordinate& global) const;
//! A(l) , see grid.hh
alu2d_ctype integrationElement (const LocalCoordinate& local) const;
//! return volume of geometry
alu2d_ctype volume () const;
//! return true if geometry has affine mapping
bool affine() const { return geoImpl_.affine(); }
//! jacobian inverse transposed
const FieldMatrix<alu2d_ctype,cdim,mydim>& jacobianInverseTransposed (const LocalCoordinate& local) const;
//! jacobian transposed
const FieldMatrix<alu2d_ctype,mydim,cdim>& jacobianTransposed (const LocalCoordinate& local) const;
//***********************************************************************
//! Methods that not belong to the Interface, but have to be public
//***********************************************************************
//! generate the geometry for out of given ALU2dGridElement
// method for elements
bool buildGeom(const HElementType & item);
// method for edges
bool buildGeom(const HElementType & item, const int aluFace);
// method for vertices
bool buildGeom(const VertexType & item, const int );
//! build geometry for intersectionSelfLocal and
//! intersectionNeighborLocal
template <class GeometryType, class LocalGeomType >
bool buildLocalGeom(const GeometryType & geo , const LocalGeomType & lg);
//! build local geometry given local face number
bool buildLocalGeometry(const int faceNumber, const int twist,const int coorns);
//! return non-const reference to coord vecs
GlobalCoordinate& getCoordVec (int i);
//! print internal data
void print (std::ostream& ss) const;
//! build geometry with local coords of child in reference element
inline bool buildGeomInFather(const Geometry &fatherGeom,
const Geometry & myGeom );
// returns true if geometry information is valid
inline bool valid() const { return geoImpl_.valid(); }
// invalidate geometry information
inline void invalidate() const { geoImpl_.invalidate(); }
protected:
// return reference coordinates of the alu triangle
static std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
calculateReferenceCoords ( const int corners );
// implementation of coord and mapping
mutable GeometryImplType geoImpl_;
// determinant
mutable alu2d_ctype det_;
};
} // end namespace Dune
#include "geometry_imp.cc"
#endif
|