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<
int dim,
int dimw>
21 template<
int dim,
int dimw>
24 template<
int dim,
int dimw>
27 template<
class Gr
idImp,
class GeometryImpl,
int nChild >
28 class ALULocalGeometryStorage
30 typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType;
39 typedef typename GridImp :: ctype ctype;
40 enum { dimension = GridImp :: dimension };
41 enum { dimensionworld = GridImp :: dimensionworld };
43 template <
int dummy,
int dim,
int dimworld,
int >
44 struct CreateGeometries;
46 template <
int dummy,
int dimworld>
47 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE triangle >
49 template <
class Storage>
50 static void createGeometries(Storage& storage,
51 const GeometryType& type,
52 const bool nonConform )
56 typedef ALUGrid< 2, dimworld, simplex, nonconforming, No_Comm > Grid;
57 storage.template createGeometries< Grid > (type);
61 typedef ALUGrid< 2, dimworld, simplex, conforming, No_Comm > Grid;
62 storage.template createGeometries< Grid > (type);
68 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE tetra >
70 template <
class Storage>
71 static void createGeometries(Storage& storage,
72 const GeometryType& type,
73 const bool nonConform )
75 assert ( nonConform ) ;
77 typedef ALUGrid< 3, 3, simplex, nonconforming, No_Comm > Grid;
78 storage.template createGeometries< Grid > (type);
91 template <
int dummy,
int dimworld>
92 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE quadrilateral >
94 template <
class Storage>
95 static void createGeometries(Storage& storage,
96 const GeometryType& type,
97 const bool nonConform )
99 assert ( nonConform ) ;
101 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
102 storage.template createGeometries< Grid > (type);
108 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE hexa >
110 template <
class Storage>
111 static void createGeometries(Storage& storage,
112 const GeometryType& type,
113 const bool nonConform )
115 assert( nonConform );
117 typedef ALUGrid< 3, 3, cube, nonconforming, No_Comm > Grid;
118 storage.template createGeometries< Grid > (type);
125 ALULocalGeometryStorage (
const GeometryType type,
const bool nonConform )
128 geoms_.
fill( (GeometryImpl *) 0 );
131 CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
132 ::createGeometries(*
this, type, nonConform);
136 bool geomCreated(
int child)
const {
return geoms_[child] != 0; }
139 const GeometryImpl & operator [] (
int child)
const
141 assert( geomCreated(child) );
142 return *(geoms_[child]);
145 template <
class Gr
id >
146 void createGeometries(
const GeometryType& type)
155 FieldVector<ctype, dimensionworld> pos( 0 );
156 const int vxSize = refElem.
size(dimension);
157 for(
int i=0; i<vxSize; ++i)
159 FieldVector<ctype, dimension> position = refElem.
position(i, dimension );
161 for(
int d = 0; d<dimension; ++d )
162 pos[ d ] = position[ d ];
164 factory.insertVertex( pos );
167 std::vector< unsigned int > vertices( vxSize );
169 for(
size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
170 factory.insertElement(type, vertices);
173 std::streambuf* cerr_sbuf = std::cerr.rdbuf();
174 std::stringstream tempout;
176 std::cerr.rdbuf(tempout.rdbuf());
178 Grid* gridPtr = factory.createGrid();
179 Grid& grid = *gridPtr;
182 std::cerr.rdbuf(cerr_sbuf);
188 grid.globalRefine( level );
191 typedef typename Grid :: template Partition< All_Partition >:: LevelGridView MacroGridView;
192 MacroGridView macroView = grid.template levelView< All_Partition > ( 0 );
193 typedef typename MacroGridView :: template Codim< 0 > :: Iterator Iterator;
195 Iterator it = macroView.template begin<0> ();
197 if( it == macroView.template end<0>() )
198 DUNE_THROW(InvalidStateException,
"Empty Grid, should contain at least 1 element");
200 typedef typename Iterator :: Entity EntityType;
202 const EntityType& entity = *it;
203 const typename EntityType :: Geometry& geo = entity.geometry();
204 typedef typename EntityType :: HierarchicIterator HierarchicIteratorType;
205 const HierarchicIteratorType end = entity.hend( level );
208 for( HierarchicIteratorType child = entity.hbegin( level );
209 child != end; ++child, ++childNum )
211 create( geo, child->geometry(), childNum );
220 template<
class Geometry >
221 void create (
const Geometry &father,
225 assert( !geomCreated( child ) );
226 assert( (child >= 0) && (child < nChild) );
228 assert( (count_ < nChild) );
231 geoms_[ child ] =
new GeometryImpl();
232 geoms_[ child ]->buildGeomInFather( father, son );
237 ~ALULocalGeometryStorage ()
239 for(
size_t i=0; i<geoms_.
size(); ++i)
240 if(geoms_[i])
delete geoms_[i];
244 static const GeometryImpl& geom(
const GeometryType type,
const bool nonConforming,
const int child )
247 static ThisType instance( type, nonConforming );
249 assert( type == instance[ child ].type() );
250 return instance[ child ];
This class provides access to geometric and topological properties of a reference element....
Definition: referenceelements.hh:58
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:86
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:154
Simple fixed size array class. This replaces std::array, if that is not available.
Definition: array.hh:40
size_type size() const
Return array size.
Definition: array.hh:71
void fill(const T &t)
Assign value to all entries (according to C++0x the fill method is to be prefered)
Definition: array.hh:87
Different resources needed by all grid implementations.
Provide a generic factory class for unstructured grids.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:568