/usr/include/dune/grid/albertagrid/level.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 | #ifndef DUNE_ALBERTA_LEVEL_HH
#define DUNE_ALBERTA_LEVEL_HH
#include <cassert>
#include <cstdlib>
#include <dune/grid/albertagrid/meshpointer.hh>
#include <dune/grid/albertagrid/dofadmin.hh>
#include <dune/grid/albertagrid/dofvector.hh>
#if HAVE_ALBERTA
namespace Dune
{
// AlbertaGridLevelProvider
// ------------------------
template< int dim >
class AlbertaGridLevelProvider
{
typedef AlbertaGridLevelProvider< dim > This;
typedef unsigned char Level;
typedef Alberta::DofVectorPointer< Level > DofVectorPointer;
typedef Alberta::DofAccess< dim, 0 > DofAccess;
typedef Alberta::FillFlags< dim > FillFlags;
static const Level isNewFlag = (1 << 7);
static const Level levelMask = (1 << 7) - 1;
class SetLocal;
class CalcMaxLevel;
template< Level flags >
struct ClearFlags;
struct Interpolation;
public:
typedef Alberta::ElementInfo< dim > ElementInfo;
typedef Alberta::MeshPointer< dim > MeshPointer;
typedef Alberta::HierarchyDofNumbering< dim > DofNumbering;
Level operator() ( const Alberta::Element *element ) const
{
const Level *array = (Level *)level_;
return array[ dofAccess_( element, 0 ) ] & levelMask;
}
Level operator() ( const ElementInfo &elementInfo ) const
{
return (*this)( elementInfo.el() );
}
bool isNew ( const Alberta::Element *element ) const
{
const Level *array = (Level *)level_;
return ((array[ dofAccess_( element, 0 ) ] & isNewFlag) != 0);
}
bool isNew ( const ElementInfo &elementInfo ) const
{
return isNew( elementInfo.el() );
}
Level maxLevel () const
{
CalcMaxLevel calcFromCache;
level_.forEach( calcFromCache );
#ifndef NDEBUG
CalcMaxLevel calcFromGrid;
mesh().leafTraverse( calcFromGrid, FillFlags::nothing );
assert( calcFromCache.maxLevel() == calcFromGrid.maxLevel() );
#endif
return calcFromCache.maxLevel();;
}
MeshPointer mesh () const
{
return MeshPointer( level_.dofSpace()->mesh );
}
void markAllOld ()
{
ClearFlags< isNewFlag > clearIsNew;
level_.forEach( clearIsNew );
}
void create ( const DofNumbering &dofNumbering )
{
const Alberta::DofSpace *const dofSpace = dofNumbering.dofSpace( 0 );
dofAccess_ = DofAccess( dofSpace );
level_.create( dofSpace, "Element level" );
assert( level_ );
level_.template setupInterpolation< Interpolation >();
SetLocal setLocal( level_ );
mesh().hierarchicTraverse( setLocal, FillFlags::nothing );
}
void release ()
{
level_.release();
dofAccess_ = DofAccess();
}
private:
DofVectorPointer level_;
DofAccess dofAccess_;
};
// AlbertaGridLevelProvider::SetLocal
// ----------------------------------
template< int dim >
class AlbertaGridLevelProvider< dim >::SetLocal
{
DofVectorPointer level_;
DofAccess dofAccess_;
public:
explicit SetLocal ( const DofVectorPointer &level )
: level_( level ),
dofAccess_( level.dofSpace() )
{}
void operator() ( const Alberta::ElementInfo< dim > &elementInfo ) const
{
Level *const array = (Level *)level_;
array[ dofAccess_( elementInfo, 0 ) ] = elementInfo.level();
}
};
// AlbertaGridLevelProvider::CalcMaxLevel
// --------------------------------------
template< int dim >
class AlbertaGridLevelProvider< dim >::CalcMaxLevel
{
Level maxLevel_;
public:
CalcMaxLevel ()
: maxLevel_( 0 )
{}
void operator() ( const Level &dof )
{
maxLevel_ = std::max( maxLevel_, Level( dof & levelMask ) );
}
void operator() ( const Alberta::ElementInfo< dim > &elementInfo )
{
maxLevel_ = std::max( maxLevel_, Level( elementInfo.level() ) );
}
Level maxLevel () const
{
return maxLevel_;
}
};
// AlbertaGridLevelProvider::ClearFlags
// ------------------------------------
template< int dim >
template< typename AlbertaGridLevelProvider< dim >::Level flags >
struct AlbertaGridLevelProvider< dim >::ClearFlags
{
void operator() ( Level &dof ) const
{
dof &= ~flags;
}
};
// AlbertaGridLevelProvider::Interpolation
// ---------------------------------------
template< int dim >
struct AlbertaGridLevelProvider< dim >::Interpolation
{
static const int dimension = dim;
typedef Alberta::Patch< dimension > Patch;
static void interpolateVector ( const DofVectorPointer &dofVector,
const Patch &patch )
{
const DofAccess dofAccess( dofVector.dofSpace() );
Level *array = (Level *)dofVector;
for( int i = 0; i < patch.count(); ++i )
{
const Alberta::Element *const father = patch[ i ];
assert( (array[ dofAccess( father, 0 ) ] & levelMask) < levelMask );
const Level childLevel = (array[ dofAccess( father, 0 ) ] + 1) | isNewFlag;
for( int i = 0; i < 2; ++i )
{
const Alberta::Element *child = father->child[ i ];
array[ dofAccess( child, 0 ) ] = childLevel;
}
}
}
};
}
#endif // #if HAVE_ALBERTA
#endif
|