1#ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
2#define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
12#include <dune/alugrid/common/declaration.hh>
13#include <dune/alugrid/3d/alu3dinclude.hh>
17 template<
class Gr
id >
18 class ReferenceGridFactory;
21 template<
class Gr
idImp,
class GeometryImpl,
int nChild >
22 class ALULocalGeometryStorage
24 typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType;
27 std::array< GeometryImpl, nChild > geoms_;
36 typedef typename GridImp :: ctype ctype;
37 enum{ dimension = GridImp :: dimension };
38 enum{ dimensionworld = GridImp :: dimensionworld };
40 template <
int dummy,
int dim,
int dimworld,
int >
41 struct CreateGeometries;
43 template <
int dummy,
int dimworld>
44 struct CreateGeometries<dummy, 2, dimworld, ALU3DSPACE
triangle >
46 template <
class Storage>
47 static inline void createGeometries(Storage& storage,
48 const GeometryType& type,
49 const bool nonConform )
53 typedef ALUGrid< 2, dimworld, simplex, nonconforming, ALUGridNoComm > Grid;
54 storage.template createGeometries< Grid > (type);
58 typedef ALUGrid< 2, dimworld, simplex, conforming, ALUGridNoComm > Grid;
59 storage.template createGeometries< Grid > (type);
64 template <
int dummy,
int dimworld>
65 struct CreateGeometries<dummy, 2, dimworld, ALU3DSPACE tetra >
67 template <
class Storage>
68 static inline void createGeometries(Storage& storage,
69 const GeometryType& type,
70 const bool nonConform )
74 typedef ALUGrid< 2, dimworld, simplex, nonconforming, ALUGridNoComm > Grid;
75 storage.template createGeometries< Grid > (type);
79 typedef ALUGrid< 2, dimworld, simplex, conforming, ALUGridNoComm > Grid;
80 storage.template createGeometries< Grid > (type);
86 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE tetra >
88 template <
class Storage>
89 static inline void createGeometries(Storage& storage,
90 const GeometryType& type,
91 const bool nonConform )
93 alugrid_assert ( nonConform ) ;
95 typedef ALUGrid< 3, 3, simplex, nonconforming, ALUGridNoComm > Grid;
96 storage.template createGeometries< Grid > (type);
109 template <
int dummy,
int dimworld>
110 struct CreateGeometries<dummy, 2, dimworld, ALU3DSPACE
quadrilateral >
112 template <
class Storage>
113 static void createGeometries(Storage& storage,
114 const GeometryType& type,
115 const bool nonConform )
117 alugrid_assert ( nonConform ) ;
119 typedef ALUGrid< 2, dimworld, cube, nonconforming, ALUGridNoComm > Grid;
120 storage.template createGeometries< Grid > (type);
125 template <
int dummy,
int dimworld>
126 struct CreateGeometries<dummy, 2, dimworld, ALU3DSPACE hexa >
128 template <
class Storage>
129 static void createGeometries(Storage& storage,
130 const GeometryType& type,
131 const bool nonConform )
133 alugrid_assert ( nonConform ) ;
135 typedef ALUGrid< 2, dimworld, cube, nonconforming, ALUGridNoComm > Grid;
136 storage.template createGeometries< Grid > (type);
142 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE hexa >
144 template <
class Storage>
145 static void createGeometries(Storage& storage,
146 const GeometryType& type,
147 const bool nonConform )
149 alugrid_assert ( nonConform );
151 typedef ALUGrid< 3, 3, cube, nonconforming, ALUGridNoComm > Grid;
152 storage.template createGeometries< Grid > (type);
159 inline ALULocalGeometryStorage (
const GeometryType type,
const bool nonConform )
160 : count_( 0 ), initialized_( false )
163 initialize( type, nonConform );
167 inline ALULocalGeometryStorage ()
168 : count_( 0 ), initialized_( false )
173 inline const GeometryImpl& operator [] (
int child)
const
175 alugrid_assert ( geomCreated(
child) );
177 return geoms_[
child];
181 static inline const ThisType& storage(
const GeometryType type,
const bool nonConforming )
183 if( type.isSimplex() )
186 static ThisType simplexGeoms( type, nonConforming );
187 return simplexGeoms ;
192 alugrid_assert( type.isCube() );
195 static ThisType cubeGeoms( type, nonConforming );
202 inline bool geomCreated(
int child)
const {
return geoms_[
child].valid(); }
205 inline bool initialize(
const GeometryType type,
const bool nonConform )
211 initialized_ = true ;
215 CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
216 ::createGeometries(*
this, type, nonConform);
222 template <
class Gr
id >
223 inline void createGeometries(
const GeometryType& type)
225 static bool firstCall = true ;
231 ReferenceGridFactory< Grid > factory;
233 const auto& refElem =
237 FieldVector<ctype, dimensionworld> pos( 0 );
238 const int vxSize = refElem.size(dimension);
239 for(
int i=0; i<vxSize; ++i)
241 FieldVector<ctype, dimension> position = refElem.position(i, dimension );
243 for(
int d = 0; d<dimension; ++d )
244 pos[ d ] = position[ d ];
246 factory.insertVertex( pos );
249 std::vector< unsigned int > vertices( vxSize );
251 for(
size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
252 factory.insertElement(type, vertices);
254 std::unique_ptr< Grid > gridPtr( factory.createGrid() );
255 Grid& grid = *gridPtr;
259 grid.globalRefine( level );
262 typedef typename Grid :: MacroGridView MacroGridView;
263 MacroGridView macroView = grid.template macroGridView< All_Partition > ();
264 typedef typename MacroGridView :: template
Codim< 0 > :: Iterator Iterator;
266 Iterator it = macroView.template begin<0> ();
268 if( it == macroView.template end<0>() )
269 DUNE_THROW(InvalidStateException,
"Empty Grid, should contain at least 1 element");
271 typedef typename Iterator :: Entity EntityType;
273 const EntityType& entity = *it;
274 const typename EntityType :: Geometry& geo = entity.geometry();
275 typedef typename EntityType :: HierarchicIterator HierarchicIteratorType;
276 const HierarchicIteratorType end = entity.hend( level );
279 for( HierarchicIteratorType
child = entity.hbegin( level );
282 create( geo,
child->geometry(), childNum );
289 template<
class Geometry >
290 inline void create (
const Geometry &father,
294 alugrid_assert ( !geomCreated(
child ) );
295 alugrid_assert ( (
child >= 0) && (
child < nChild) );
297 alugrid_assert ( (count_ < nChild) );
300 geoms_[
child ].buildGeomInFather( father, son );
A few common exception classes.
Different resources needed by all grid implementations.
Provide a generic factory class for unstructured grids.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr GeometryType triangle
GeometryType representing a triangle.
Definition: type.hh:518
constexpr GeometryType quadrilateral
GeometryType representing a quadrilateral (a square).
Definition: type.hh:524
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:198