/usr/include/dune/grid/alugrid/2d/geometry_imp.cc 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 | #ifndef DUNE_ALU2DGRID_GEOMETRYIMP_CC
#define DUNE_ALU2DGRID_GEOMETRYIMP_CC
#include <dune/geometry/genericgeometry/conversion.hh>
#include <dune/geometry/referenceelements.hh>
namespace Dune
{
// implementation of methods
//**********************************************************************
//
// --ALU2dGridGeometry
// --Geometry
//**********************************************************************
template< int mydim, int cdim, class GridImp >
inline ALU2dGridGeometry< mydim, cdim, GridImp >::ALU2dGridGeometry ()
: geoImpl_(),
det_( 1.0 )
{}
//! print the GeometryInformation
template< int mydim, int cdim, class GridImp >
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::print ( std::ostream &out ) const
{
out << "ALU2dGridGeometry< " << mydim << ", " << cdim << " > = ";
char c = '{';
for( int i = 0; i < corners(); ++i )
{
out << c << " (" << corner( i ) << ")";
c = ',';
}
out << " }" << std::endl;
}
///////////////////////////////////////////////////////////////////////
//! access to coordinates of corners. Index is the number of the corner
template <int mydim, int cdim, class GridImp>
inline const typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate &
ALU2dGridGeometry< mydim, cdim, GridImp >::operator[] ( int i ) const
{
typedef GenericGeometry::MapNumberingProvider< mydim > Numbering;
const unsigned int tid = type().id();
static GlobalCoordinate c;
return (c = corner( Numbering::template dune2generic< mydim >( tid, i ) ));
}
//! access to coordinates of corners. Index is the number of the corner
template< int mydim, int cdim, class GridImp >
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
ALU2dGridGeometry< mydim, cdim, GridImp >::corner ( int i ) const
{
const GenericReferenceElement< alu2d_ctype, mydim > &refElement
= GenericReferenceElements< alu2d_ctype, mydim >::general( type() );
return global( refElement.position( i, mydim ) );
}
//! maps a local coordinate within reference element to
//! global coordinate in element
template< int mydim, int cdim, class GridImp >
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
ALU2dGridGeometry< mydim, cdim, GridImp >::global ( const LocalCoordinate &local ) const
{
GlobalCoordinate global;
geoImpl_.map2world( local, global );
return global;
}
//! maps a global coordinate within the element to a
//! local coordinate in its reference element
template< int mydim, int cdim, class GridImp >
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::LocalCoordinate
ALU2dGridGeometry< mydim, cdim, GridImp >::local ( const GlobalCoordinate &global ) const
{
if( mydim == 0 )
return LocalCoordinate( 1 );
LocalCoordinate local;
geoImpl_.world2map( global, local );
return local;
}
template< int mydim, int cdim, class GridImp >
inline alu2d_ctype
ALU2dGridGeometry< mydim, cdim, GridImp >::integrationElement ( const LocalCoordinate &local ) const
{
if ( eltype == ALU2DSPACE triangle || mydim < 2 )
{
assert( geoImpl_.valid() );
return (mydim == 0 ? 1.0 : det_);
}
else
return geoImpl_.det(local);
}
template< int mydim, int cdim, class GridImp >
inline alu2d_ctype ALU2dGridGeometry< mydim, cdim, GridImp >::volume () const
{
assert( geoImpl_.valid() );
if( mydim == 2 )
{
switch( GridImp::elementType )
{
case ALU2DSPACE triangle:
return 0.5 * det_;
case ALU2DSPACE quadrilateral:
return det_;
case ALU2DSPACE mixed:
DUNE_THROW( NotImplemented, "Geometry::volume() not implemented for ElementType mixed." );
}
}
else
return (mydim == 0 ? 1.0 : det_);
}
template< int mydim, int cdim, class GridImp >
inline const FieldMatrix<alu2d_ctype,mydim,cdim>&
ALU2dGridGeometry< mydim, cdim, GridImp>::jacobianTransposed ( const LocalCoordinate &local ) const
{
return geoImpl_.jacobianTransposed( local );
}
template< int mydim, int cdim, class GridImp >
inline const FieldMatrix<alu2d_ctype,cdim,mydim>&
ALU2dGridGeometry< mydim, cdim, GridImp >::jacobianInverseTransposed ( const LocalCoordinate &local ) const
{
return geoImpl_.jacobianInverseTransposed( local );
}
//! built Geometry for triangles
template< int mydim, int cdim, class GridImp >
inline bool
ALU2dGridGeometry< mydim, cdim, GridImp >::buildGeom( const HElementType &item )
{
// check item
assert( &item );
assert( mydim == 2 );
// update geometry impl
geoImpl_.update( item );
// store volume
det_ = (geoImpl_.corners() == 3 ? 2 * item.area() : item.area());
// geometry built
return true;
}
//! built Geometry for edges
template <int mydim, int cdim, class GridImp>
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
buildGeom(const HElementType & item, const int aluFace)
{
assert( mydim == 1 );
// face 1 is twisted
const int nf = item.numfaces();
// for triangles face 1 is twisted and for quatrilaterals faces 1 and 2
const int twist = (nf == 3) ? (aluFace % 2) : (aluFace>>1)^(aluFace&1);
// std::cout << nf << " " << aluFace << " " << twist << std::endl;
// << " ( " item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
// << " , " item.getVertex( (aluFace + 2 - twist ) % nf )->coord()
// << " ) " << std::endl;
// check item
assert( &item );
// update geometry impl
geoImpl_.update( item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
item.getVertex( (aluFace + 2 - twist ) % nf )->coord() );
// store volume
det_ = item.sidelength( aluFace );
//assert( std::abs( det_ - geoImpl_.det( LocalCoordinate(0.5) ) ) < 1e-14 );
// geometry built
return true;
}
//! built Geometry for vertices
template <int mydim, int cdim, class GridImp>
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
buildGeom(const VertexType & item , const int )
{
assert( mydim == 0 );
assert( &item );
// update geometry impl
geoImpl_.update( item.coord() );
// volume is already 1.0
return true;
}
// built Geometry
template <int mydim, int cdim, class GridImp>
template <class GeometryType, class LocalGeometryType >
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
buildLocalGeom(const GeometryType &geo, const LocalGeometryType & localGeom)
{
// update geometry
geoImpl_.updateLocal( geo, localGeom );
// calculate volume
LocalCoordinate local( 0.25 );
det_ = geoImpl_.det( local );
// geometry built
return true;
}
// built Geometry (faceNumber is in generic numbering)
template< int mydim, int cdim, class GridImp >
inline std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
ALU2dGridGeometry< mydim, cdim, GridImp >::calculateReferenceCoords ( const int corners )
{
// calculate reference coordinates of aLUGrid reference triangle
FieldMatrix< alu2d_ctype, 4, 2 > refCoord( 0. );
FieldVector< alu2d_ctype, 4 > lengths( 1. );
// point 1
refCoord[1][0] = 1.0;
// point (corners-1)
refCoord[corners-1][1] = 1.0;
if( corners == 3 )
{
lengths[0] = M_SQRT2;
}
else
{
// point 2
refCoord[2][0] = 1.0;
refCoord[2][1] = 1.0;
}
return std::make_pair( refCoord, lengths );
}
// built Geometry (faceNumber is in generic numbering)
template <int mydim, int cdim, class GridImp>
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
buildLocalGeometry(const int aluFace, const int twist, const int corners)
{
assert( twist == 0 || twist == 1 );
assert( mydim == 1 );
// get coordinates of reference element
typedef std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > > RefCoord;
RefCoord refCoord( calculateReferenceCoords( corners ) );
geoImpl_.update( refCoord.first[ ( aluFace + 1+twist ) % corners ],
refCoord.first[ ( aluFace + 2-twist ) % corners ] );
// get length of faces
det_ = refCoord.second[ aluFace ];
// geometry built
return true;
}
// built Geometry
template <int mydim, int cdim, class GridImp >
inline bool ALU2dGridGeometry<mydim, cdim,GridImp>::
buildGeomInFather(const Geometry & fatherGeom ,
const Geometry & myGeom)
{
// update geometry
geoImpl_.updateLocal( fatherGeom, myGeom );
// store volume which is a part of one
det_ = myGeom.volume() / fatherGeom.volume();
assert( (det_ > 0.0) && (det_ < 1.0) );
return true;
}
} //end namespace Dune
#endif // #ifndef DUNE_ALU2DGRID_GEOMETRYIMP_CC
|