/usr/include/dune/grid/alugrid/common/geostorage.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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
#define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
// Dune includes
#include <dune/common/misc.hh>
#include <dune/grid/common/grid.hh>
#include <dune/grid/common/gridfactory.hh>
#if HAVE_ALUGRID
#include <dune/grid/alugrid/common/declaration.hh>
#include <dune/grid/alugrid/3d/alu3dinclude.hh>
#include <dune/grid/alugrid/2d/alu2dinclude.hh>
namespace Dune
{
template<int dim, int dimw>
class ALUCubeGrid;
template<int dim, int dimw>
class ALUSimplexGrid;
template<int dim, int dimw>
class ALUConformGrid;
template< class GridImp, class GeometryImpl, int nChild >
class ALULocalGeometryStorage
{
// array with pointers to the geometries
Dune::array< GeometryImpl *, nChild > geoms_;
// count local geometry creation
int count_;
// type of grid impl
typedef typename GridImp :: ctype ctype;
enum{ dimension = GridImp :: dimension };
enum{ dimensionworld = GridImp :: dimensionworld };
template <int dummy, int dim, int dimworld, int >
struct CreateGeometries;
template <int dummy, int dimworld>
struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE triangle >
{
template <class Storage>
static void createGeometries(Storage& storage,
const GeometryType& type,
const bool nonConform )
{
if( nonConform )
{
typedef ALUGrid< 2, dimworld, simplex, nonconforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
else
{
typedef ALUGrid< 2, dimworld, simplex, conforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
}
};
template <int dummy>
struct CreateGeometries<dummy, 3, 3, ALU3DSPACE tetra >
{
template <class Storage>
static void createGeometries(Storage& storage,
const GeometryType& type,
const bool nonConform )
{
assert ( nonConform ) ;
{
typedef ALUGrid< 3, 3, simplex, nonconforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
/*
// TODO, implement this for refinement of all edges (conforming)
else
{
typedef ALUGrid< 3, 3, simplex, conforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
*/
}
};
template <int dummy, int dimworld>
struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE quadrilateral >
{
template <class Storage>
static void createGeometries(Storage& storage,
const GeometryType& type,
const bool nonConform )
{
assert ( nonConform ) ;
{
typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
}
};
template <int dummy>
struct CreateGeometries<dummy, 3, 3, ALU3DSPACE hexa >
{
template <class Storage>
static void createGeometries(Storage& storage,
const GeometryType& type,
const bool nonConform )
{
assert( nonConform );
{
typedef ALUGrid< 3, 3, cube, nonconforming, No_Comm > Grid;
storage.template createGeometries< Grid > (type);
}
}
};
public:
// create empty storage
ALULocalGeometryStorage ( const GeometryType type, const bool nonConform )
: count_( 0 )
{
geoms_.fill( (GeometryImpl *) 0 );
// the idea is to create a grid containing the reference element,
// refine once and the store the father - child relations
CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
::createGeometries(*this, type, nonConform);
}
// desctructor deleteing geometries
~ALULocalGeometryStorage ()
{
for(size_t i=0; i<geoms_.size(); ++i)
if(geoms_[i]) delete geoms_[i];
}
// check if geometry has been created
bool geomCreated(int child) const { return geoms_[child] != 0; }
// return reference to local geometry
const GeometryImpl & operator [] (int child) const
{
assert( geomCreated(child) );
return *(geoms_[child]);
}
template < class Grid >
void createGeometries(const GeometryType& type)
{
// create factory without verbosity
GridFactory< Grid > factory( false );
const Dune::GenericReferenceElement< ctype, dimension > &refElem
= Dune::GenericReferenceElements< ctype, dimension >::general( type );
// insert vertices
FieldVector<ctype, dimensionworld> pos( 0 );
const int vxSize = refElem.size(dimension);
for(int i=0; i<vxSize; ++i)
{
FieldVector<ctype, dimension> position = refElem.position(i, dimension );
// copy position
for(int d = 0; d<dimension; ++d )
pos[ d ] = position[ d ];
factory.insertVertex( pos );
}
std::vector< unsigned int > vertices( vxSize );
// create grid with reference element
for(size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
factory.insertElement(type, vertices);
// save original sbuf
std::streambuf* cerr_sbuf = std::cerr.rdbuf();
std::stringstream tempout;
// redirect 'cerr' to a 'fout' to avoid unnecessary output in constructors
std::cerr.rdbuf(tempout.rdbuf());
Grid* gridPtr = factory.createGrid();
Grid& grid = *gridPtr;
// restore the original stream buffer
std::cerr.rdbuf(cerr_sbuf);
//std::cerr = savecerr;
// refine once to get children
const int level = 1;
grid.globalRefine( level );
{
typedef typename Grid :: template Partition< All_Partition >:: LevelGridView MacroGridView;
MacroGridView macroView = grid.template levelView< All_Partition > ( 0 );
typedef typename MacroGridView :: template Codim< 0 > :: Iterator Iterator;
Iterator it = macroView.template begin<0> ();
if( it == macroView.template end<0>() )
DUNE_THROW(InvalidStateException,"Empty Grid, should contain at least 1 element");
typedef typename Iterator :: Entity EntityType;
const EntityType& entity = *it;
const typename EntityType :: Geometry& geo = entity.geometry();
typedef typename EntityType :: HierarchicIterator HierarchicIteratorType;
const HierarchicIteratorType end = entity.hend( level );
int childNum = 0;
for( HierarchicIteratorType child = entity.hbegin( level );
child != end; ++child, ++childNum )
{
create( geo, child->geometry(), childNum );
}
}
// delete grid
delete gridPtr;
}
protected:
// create local geometry
template< class Geometry >
void create ( const Geometry &father,
const Geometry &son,
const int child )
{
assert( !geomCreated( child ) );
assert( (child >= 0) && (child < nChild) );
assert( (count_ < nChild) );
++count_;
geoms_[ child ] = new GeometryImpl();
geoms_[ child ]->buildGeomInFather( father, son );
}
};
} // namespace Dune
#endif // end HAVE_ALUGRID
#endif // #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
|