3#ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
4#define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
12#include <dune/grid/alugrid/common/declaration.hh>
13#include <dune/grid/alugrid/3d/alu3dinclude.hh>
14#include <dune/grid/alugrid/2d/alu2dinclude.hh>
18 template<
class Gr
idImp,
class GeometryImpl,
int nChild >
19 class ALULocalGeometryStorage
21 typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType;
24 Dune::array< GeometryImpl *, nChild > geoms_;
30 typedef typename GridImp :: ctype ctype;
31 enum { dimension = GridImp :: dimension };
32 enum { dimensionworld = GridImp :: dimensionworld };
34 template <
int dummy,
int dim,
int dimworld,
int >
35 struct CreateGeometries;
37 template <
int dummy,
int dimworld>
38 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE triangle >
40 template <
class Storage>
41 static void createGeometries(Storage& storage,
42 const GeometryType& type,
43 const bool nonConform )
47 typedef ALUGrid< 2, dimworld, simplex, nonconforming, No_Comm > Grid;
48 storage.template createGeometries< Grid > (type);
52 typedef ALUGrid< 2, dimworld, simplex, conforming, No_Comm > Grid;
53 storage.template createGeometries< Grid > (type);
59 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE tetra >
61 template <
class Storage>
62 static void createGeometries(Storage& storage,
63 const GeometryType& type,
64 const bool nonConform )
66 assert ( nonConform ) ;
68 typedef ALUGrid< 3, 3, simplex, nonconforming, No_Comm > Grid;
69 storage.template createGeometries< Grid > (type);
82 template <
int dummy,
int dimworld>
83 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE quadrilateral >
85 template <
class Storage>
86 static void createGeometries(Storage& storage,
87 const GeometryType& type,
88 const bool nonConform )
90 assert ( nonConform ) ;
92 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
93 storage.template createGeometries< Grid > (type);
99 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE hexa >
101 template <
class Storage>
102 static void createGeometries(Storage& storage,
103 const GeometryType& type,
104 const bool nonConform )
106 assert( nonConform );
108 typedef ALUGrid< 3, 3, cube, nonconforming, No_Comm > Grid;
109 storage.template createGeometries< Grid > (type);
116 ALULocalGeometryStorage (
const GeometryType type,
const bool nonConform )
119 geoms_.fill( (GeometryImpl *) 0 );
122 CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
123 ::createGeometries(*
this, type, nonConform);
127 bool geomCreated(
int child)
const {
return geoms_[child] != 0; }
130 const GeometryImpl & operator [] (
int child)
const
132 assert( geomCreated(child) );
133 return *(geoms_[child]);
136 template <
class Gr
id >
137 void createGeometries(
const GeometryType& type)
146 FieldVector<ctype, dimensionworld> pos( 0 );
147 const int vxSize = refElem.
size(dimension);
148 for(
int i=0; i<vxSize; ++i)
150 FieldVector<ctype, dimension> position = refElem.
position(i, dimension );
152 for(
int d = 0; d<dimension; ++d )
153 pos[ d ] = position[ d ];
155 factory.insertVertex( pos );
158 std::vector< unsigned int > vertices( vxSize );
160 for(
size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
161 factory.insertElement(type, vertices);
164 std::streambuf* cerr_sbuf = std::cerr.rdbuf();
165 std::stringstream tempout;
167 std::cerr.rdbuf(tempout.rdbuf());
169 Grid* gridPtr = factory.createGrid();
170 Grid& grid = *gridPtr;
173 std::cerr.rdbuf(cerr_sbuf);
179 grid.globalRefine( level );
182 typedef typename Grid :: template Partition< All_Partition >:: LevelGridView MacroGridView;
183 MacroGridView macroView = grid.template levelView< All_Partition > ( 0 );
184 typedef typename MacroGridView :: template
Codim< 0 > :: Iterator Iterator;
186 Iterator it = macroView.template begin<0> ();
188 if( it == macroView.template end<0>() )
189 DUNE_THROW(InvalidStateException,
"Empty Grid, should contain at least 1 element");
191 typedef typename Iterator :: Entity EntityType;
193 const EntityType& entity = *it;
194 const typename EntityType :: Geometry& geo = entity.geometry();
195 typedef typename EntityType :: HierarchicIterator HierarchicIteratorType;
196 const HierarchicIteratorType end = entity.hend( level );
199 for( HierarchicIteratorType child = entity.hbegin( level );
200 child != end; ++child, ++childNum )
202 create( geo, child->geometry(), childNum );
211 template<
class Geometry >
212 void create (
const Geometry &father,
216 assert( !geomCreated( child ) );
217 assert( (child >= 0) && (child < nChild) );
219 assert( (count_ < nChild) );
222 geoms_[ child ] =
new GeometryImpl();
223 geoms_[ child ]->buildGeomInFather( father, son );
228 ~ALULocalGeometryStorage ()
230 for(
size_t i=0; i<geoms_.size(); ++i)
231 if(geoms_[i])
delete geoms_[i];
235 static const GeometryImpl& geom(
const GeometryType type,
const bool nonConforming,
const int child )
238 static ThisType instance( type, nonConforming );
240 assert( type == instance[ child ].type() );
241 return instance[ child ];
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelements.hh:55
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:82
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:150
Different resources needed by all grid implementations.
Provide a generic factory class for unstructured grids.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:484