/usr/include/dune/grid/geometrygrid/cachedcoordfunction.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 | #ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
#define DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
#include <cassert>
#include <memory>
#include <dune/common/typetraits.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/grid/geometrygrid/capabilities.hh>
#include <dune/grid/geometrygrid/coordfunctioncaller.hh>
#include <dune/grid/utility/persistentcontainer.hh>
namespace Dune
{
// Internal Forward Declarations
// -----------------------------
template< class HostGrid, class CoordFunction, class Allocator >
class CachedCoordFunction;
// GeoGrid::CoordCache
// -------------------
namespace GeoGrid
{
template< class HostGrid, class Coordinate, class Allocator = std::allocator< Coordinate > >
class CoordCache
{
typedef CoordCache< HostGrid, Coordinate, Allocator > This;
static const unsigned int dimension = HostGrid::dimension;
typedef typename HostGrid::template Codim< dimension >::Entity Vertex;
typedef PersistentContainer< HostGrid, Coordinate, Allocator > DataCache;
public:
explicit CoordCache ( const HostGrid &hostGrid, const Allocator &allocator = Allocator() )
: data_( hostGrid, dimension, allocator )
{}
template< class Entity >
const Coordinate &operator() ( const Entity &entity, unsigned int corner ) const
{
return data_( entity, corner );
}
const Coordinate &operator() ( const Vertex &vertex, unsigned int corner ) const
{
assert( corner == 0 );
return data_[ vertex ];
}
template< class Entity >
Coordinate &operator() ( const Entity &entity, unsigned int corner )
{
return data_( entity,corner) ;
}
Coordinate &operator() ( const Vertex &vertex, unsigned int corner )
{
assert( corner == 0 );
return data_[ vertex ];
}
void adapt ()
{
data_.update();
}
private:
CoordCache ( const This & );
This &operator= ( const This & );
mutable DataCache data_;
};
} // namespace GeoGrid
// CachedCoordFunction
// -------------------
template< class HostGrid, class CoordFunction, class Allocator = std::allocator< void > >
class CachedCoordFunction
: public DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, CachedCoordFunction< HostGrid, CoordFunction > >
{
typedef CachedCoordFunction< HostGrid, CoordFunction > This;
typedef DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, This > Base;
public:
typedef typename Base::ctype ctype;
typedef typename Base::RangeVector RangeVector;
private:
typedef GeoGrid::CoordCache< HostGrid, RangeVector, typename Allocator::template rebind< RangeVector >::other > Cache;
public:
explicit
CachedCoordFunction ( const HostGrid &hostGrid,
const CoordFunction &coordFunction = CoordFunction(),
const Allocator &allocator = Allocator() )
: hostGrid_( hostGrid ),
coordFunction_( coordFunction ),
cache_( hostGrid, allocator )
{
buildCache();
}
void adapt ()
{
cache_.adapt();
buildCache();
}
void buildCache ();
template< class HostEntity >
void insertEntity ( const HostEntity &hostEntity );
template< class HostEntity >
void evaluate ( const HostEntity &hostEntity, unsigned int corner, RangeVector &y ) const
{
y = cache_( hostEntity, corner );
#ifndef NDEBUG
typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
CoordFunctionCaller;
RangeVector z;
CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
coordFunctionCaller.evaluate( corner, z );
assert( ((y - z).two_norm() < 1e-6) );
#endif
}
private:
const HostGrid &hostGrid_;
const CoordFunction &coordFunction_;
Cache cache_;
};
// Implementation of CachedCoordFunction
// -------------------------------------
template< class HostGrid, class CoordFunction, class Allocator >
inline void CachedCoordFunction< HostGrid, CoordFunction, Allocator >::buildCache ()
{
typedef typename HostGrid::template Codim< 0 >::Entity Element;
typedef typename HostGrid::LevelGridView MacroView;
typedef typename HostGrid::HierarchicIterator HierarchicIterator;
typedef typename MacroView::template Codim< 0 >::template Partition< All_Partition >::Iterator MacroIterator;
const MacroView macroView = hostGrid_.levelView( 0 );
const int maxLevel = hostGrid_.maxLevel();
const MacroIterator mend = macroView.template end< 0, All_Partition >();
for( MacroIterator mit = macroView.template begin< 0, All_Partition >(); mit != mend; ++mit )
{
const Element ¯oElement = *mit;
insertEntity( macroElement );
const HierarchicIterator hend = macroElement.hend( maxLevel );
for( HierarchicIterator hit = macroElement.hbegin( maxLevel ); hit != hend; ++hit )
insertEntity( *hit );
}
}
template< class HostGrid, class CoordFunction, class Allocator >
template< class HostEntity >
inline void CachedCoordFunction< HostGrid, CoordFunction, Allocator >
::insertEntity ( const HostEntity &hostEntity )
{
typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
CoordFunctionCaller;
CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
const GenericReferenceElement< ctype, HostEntity::dimension > &refElement
= GenericReferenceElements< ctype, HostEntity::dimension >::general( hostEntity.type() );
const unsigned int numCorners = refElement.size( HostEntity::dimension );
for( unsigned int i = 0; i < numCorners; ++i )
coordFunctionCaller.evaluate( i, cache_( hostEntity, i ) );
}
} // namespace Dune
#endif // #ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
|