/usr/include/dune/geometry/affinegeometry.hh is in libdune-geometry-dev 2.4.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 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GEOMETRY_AFFINEGEOMETRY_HH
#define DUNE_GEOMETRY_AFFINEGEOMETRY_HH
/** \file
* \brief An implementation of the Geometry interface for affine geometries
* \author Martin Nolte
*/
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/geometry/type.hh>
#include <dune/geometry/genericgeometry/geometrytraits.hh>
#include <dune/geometry/genericgeometry/matrixhelper.hh>
namespace Dune
{
// External Forward Declarations
// -----------------------------
template< class ctype, int dim >
class ReferenceElement;
template< class ctype, int dim >
struct ReferenceElements;
/** \brief Implementation of the Geometry interface for affine geometries
* \tparam ct Type used for coordinates
* \tparam mydim Dimension of the geometry
* \tparam cdim Dimension of the world space
*/
template< class ct, int mydim, int cdim>
class AffineGeometry
{
public:
/** \brief Type used for coordinates */
typedef ct ctype;
/** \brief Dimension of the geometry */
static const int mydimension= mydim;
/** \brief Dimension of the world space */
static const int coorddimension = cdim;
/** \brief Type for local coordinate vector */
typedef FieldVector< ctype, mydimension > LocalCoordinate;
/** \brief Type for coordinate vector in world space */
typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
/** \brief Type for the transposed Jacobian matrix */
typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
/** \brief Type for the transposed inverse Jacobian matrix */
typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
private:
//! type of reference element
typedef Dune::ReferenceElement< ctype, mydimension > ReferenceElement;
typedef Dune::ReferenceElements< ctype, mydimension > ReferenceElements;
// Helper class to compute a matrix pseudo inverse
typedef GenericGeometry::MatrixHelper< GenericGeometry::DuneCoordTraits< ct > > MatrixHelper;
public:
/** \brief Create affine geometry from reference element, one vertex, and the Jacobian matrix */
AffineGeometry ( const ReferenceElement &refElement, const GlobalCoordinate &origin,
const JacobianTransposed &jt )
: refElement_(&refElement), origin_(origin), jacobianTransposed_(jt)
{
integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
}
/** \brief Create affine geometry from GeometryType, one vertex, and the Jacobian matrix */
AffineGeometry ( Dune::GeometryType gt, const GlobalCoordinate &origin,
const JacobianTransposed &jt )
: refElement_( &ReferenceElements::general( gt ) ), origin_(origin), jacobianTransposed_( jt )
{
integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
}
/** \brief Create affine geometry from reference element and a vector of vertex coordinates */
template< class CoordVector >
AffineGeometry ( const ReferenceElement &refElement, const CoordVector &coordVector )
: refElement_(&refElement), origin_(coordVector[0])
{
for( int i = 0; i < mydimension; ++i )
jacobianTransposed_[ i ] = coordVector[ i+1 ] - origin_;
integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
}
/** \brief Create affine geometry from GeometryType and a vector of vertex coordinates */
template< class CoordVector >
AffineGeometry ( Dune::GeometryType gt, const CoordVector &coordVector )
: refElement_(&ReferenceElements::general( gt )), origin_(coordVector[0] )
{
for( int i = 0; i < mydimension; ++i )
jacobianTransposed_[ i ] = coordVector[ i+1 ] - origin_;
integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
}
/** \brief Always true: this is an affine geometry */
bool affine () const { return true; }
/** \brief Obtain the type of the reference element */
Dune::GeometryType type () const { return refElement_->type(); }
/** \brief Obtain number of corners of the corresponding reference element */
int corners () const { return refElement_->size( mydimension ); }
/** \brief Obtain coordinates of the i-th corner */
GlobalCoordinate corner ( int i ) const
{
return global( refElement_->position( i, mydimension ) );
}
/** \brief Obtain the centroid of the mapping's image */
GlobalCoordinate center () const { return global( refElement_->position( 0, 0 ) ); }
/** \brief Evaluate the mapping
*
* \param[in] local local coordinate to map
*
* \returns corresponding global coordinate
*/
GlobalCoordinate global ( const LocalCoordinate &local ) const
{
GlobalCoordinate global( origin_ );
jacobianTransposed_.umtv( local, global );
return global;
}
/** \brief Evaluate the inverse mapping
*
* \param[in] global global coordinate to map
*
* \return corresponding local coordinate
*
* The returned local coordinate y minimizes
* \code
* (global( y ) - x).two_norm()
* \endcode
* on the entire affine hull of the reference element. This degenerates
* to the inverse map if the argument y is in the range of the map.
*/
LocalCoordinate local ( const GlobalCoordinate &global ) const
{
LocalCoordinate local;
jacobianInverseTransposed_.mtv( global - origin_, local );
return local;
}
/** \brief Obtain the integration element
*
* If the Jacobian of the mapping is denoted by $J(x)$, the integration
* integration element \f$\mu(x)\f$ is given by
* \f[ \mu(x) = \sqrt{|\det (J^T(x) J(x))|}.\f]
*
* \param[in] local local coordinate to evaluate the integration element in
*
* \returns the integration element \f$\mu(x)\f$.
*/
ctype integrationElement ( const LocalCoordinate &local ) const
{
DUNE_UNUSED_PARAMETER(local);
return integrationElement_;
}
/** \brief Obtain the volume of the element */
ctype volume () const
{
return integrationElement_ * refElement_->volume();
}
/** \brief Obtain the transposed of the Jacobian
*
* \param[in] local local coordinate to evaluate Jacobian in
*
* \returns a reference to the transposed of the Jacobian
*/
const JacobianTransposed &jacobianTransposed ( const LocalCoordinate &local ) const
{
DUNE_UNUSED_PARAMETER(local);
return jacobianTransposed_;
}
/** \brief Obtain the transposed of the Jacobian's inverse
*
* The Jacobian's inverse is defined as a pseudo-inverse. If we denote
* the Jacobian by \f$J(x)\f$, the following condition holds:
* \f[J^{-1}(x) J(x) = I.\f]
*/
const JacobianInverseTransposed &jacobianInverseTransposed ( const LocalCoordinate &local ) const
{
DUNE_UNUSED_PARAMETER(local);
return jacobianInverseTransposed_;
}
private:
const ReferenceElement* refElement_;
GlobalCoordinate origin_;
JacobianTransposed jacobianTransposed_;
JacobianInverseTransposed jacobianInverseTransposed_;
ctype integrationElement_;
};
} // namespace Dune
#endif // #ifndef DUNE_GEOMETRY_AFFINEGEOMETRY_HH
|