/usr/include/dune/grid/geometrygrid/geometry.hh is in libdune-grid-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 218 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GEOGRID_GEOMETRY_HH
#define DUNE_GEOGRID_GEOMETRY_HH
#include <utility>
#include <dune/common/nullptr.hh>
#include <dune/common/typetraits.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/geometry/multilineargeometry.hh>
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/geometrygrid/cornerstorage.hh>
namespace Dune
{
namespace GeoGrid
{
// InferHasSingleGeometryType
// --------------------------
template< class hasSingleGeometryType, int dim, int mydim >
struct InferHasSingleGeometryType
{
private:
static const unsigned int id = hasSingleGeometryType::topologyId;
static const unsigned int idMask = (1u << mydim) - 1u;
public:
static const bool v = hasSingleGeometryType::v && ((mydim == dim) || ((id | 1u) == 1u) || ((id | 1u) == idMask));
static const unsigned int topologyId = (v ? id & idMask : ~0u);
};
template< class hasSingleGeometryType, int dim >
struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 1 >
{
static const bool v = true;
static const unsigned int topologyId = GenericGeometry::CubeTopology< 1 >::type::id;
};
template< class hasSingleGeometryType, int dim >
struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 0 >
{
static const bool v = true;
static const unsigned int topologyId = GenericGeometry::CubeTopology< 0 >::type::id;
};
// GeometryTraits
// --------------
template< class Grid >
struct GeometryTraits
{
typedef typename remove_const< Grid >::type::Traits Traits;
typedef typename Traits::ctype ctype;
typedef GenericGeometry::MatrixHelper< GenericGeometry::DuneCoordTraits< ctype > > MatrixHelper;
static ctype tolerance () { return 16 * std::numeric_limits< ctype >::epsilon(); }
template< int mydim, int cdim >
struct CornerStorage
{
typedef GeoGrid::CornerStorage< mydim, cdim, Grid > Type;
};
template< int mydim >
struct hasSingleGeometryType
: public InferHasSingleGeometryType< Capabilities::hasSingleGeometryType< Grid >, Traits::dimension, mydim >
{};
};
// Geometry
// --------
template< int mydim, int cdim, class Grid >
class Geometry
{
typedef Geometry< mydim, cdim, Grid > This;
typedef typename remove_const< Grid >::type::Traits Traits;
template< int, int, class > friend class Geometry;
public:
typedef typename Traits::ctype ctype;
static const int mydimension = mydim;
static const int coorddimension = cdim;
static const int dimension = Traits::dimension;
static const int codimension = dimension - mydimension;
protected:
typedef CachedMultiLinearGeometry< ctype, mydimension, coorddimension, GeometryTraits< Grid > > BasicMapping;
struct Mapping
: public BasicMapping
{
template< class CoordVector >
Mapping ( const GeometryType &type, const CoordVector &coords )
: BasicMapping( type, coords ),
refCount_( 0 )
{}
void addReference () { ++refCount_; }
bool removeReference () { return (--refCount_ == 0); }
private:
unsigned int refCount_;
};
public:
typedef typename Mapping::LocalCoordinate LocalCoordinate;
typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
typedef typename Mapping::JacobianTransposed JacobianTransposed;
typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed;
Geometry () : grid_( nullptr ), mapping_( nullptr ) {}
explicit Geometry ( const Grid &grid ) : grid_( &grid ), mapping_( nullptr ) {}
template< class CoordVector >
Geometry ( const Grid &grid, const GeometryType &type, const CoordVector &coords )
: grid_( &grid )
{
assert( int( type.dim() ) == mydimension );
void *mappingStorage = grid.allocateStorage( sizeof( Mapping ) );
mapping_ = new( mappingStorage ) Mapping( type, coords );
mapping_->addReference();
}
Geometry ( const This &other )
: grid_( other.grid_ ),
mapping_( other.mapping_ )
{
if( mapping_ )
mapping_->addReference();
}
Geometry ( This&& other )
: grid_( other.grid_ ),
mapping_( other.mapping_ )
{
other.grid_ = nullptr;
other.mapping_ = nullptr;
}
~Geometry ()
{
if( mapping_ && mapping_->removeReference() )
destroyMapping();
}
const This &operator= ( const This &other )
{
if( other.mapping_ )
other.mapping_->addReference();
if( mapping_ && mapping_->removeReference() )
destroyMapping();
grid_ = other.grid_;
mapping_ = other.mapping_;
return *this;
}
const This &operator= ( This&& other )
{
using std::swap;
swap( grid_, other.grid_ );
swap( mapping_, other.mapping_ );
return *this;
}
operator bool () const { return bool( mapping_ ); }
bool affine () const { return mapping_->affine(); }
GeometryType type () const { return mapping_->type(); }
int corners () const { return mapping_->corners(); }
GlobalCoordinate corner ( const int i ) const { return mapping_->corner( i ); }
GlobalCoordinate center () const { return mapping_->center(); }
GlobalCoordinate global ( const LocalCoordinate &local ) const { return mapping_->global( local ); }
LocalCoordinate local ( const GlobalCoordinate &global ) const { return mapping_->local( global ); }
ctype integrationElement ( const LocalCoordinate &local ) const { return mapping_->integrationElement( local ); }
ctype volume () const { return mapping_->volume(); }
JacobianTransposed jacobianTransposed ( const LocalCoordinate &local ) const { return mapping_->jacobianTransposed( local ); }
JacobianInverseTransposed jacobianInverseTransposed ( const LocalCoordinate &local ) const { return mapping_->jacobianInverseTransposed( local ); }
const Grid &grid () const { assert( grid_ ); return *grid_; }
private:
void destroyMapping ()
{
mapping_->~Mapping();
grid().deallocateStorage( mapping_, sizeof( Mapping ) );
}
const Grid *grid_;
Mapping* mapping_;
};
} // namespace GeoGrid
} // namespace Dune
#endif // #ifndef DUNE_GEOGRID_GEOMETRY_HH
|