3 #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
4 #define DUNE_ALUGRIDGEOMETRYSTORAGE_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;
33 Dune::array< GeometryImpl *, nChild > geoms_;
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>
49 template <
class Storage>
50 static void createGeometries(Storage& storage,
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);
70 template <
class Storage>
71 static void createGeometries(Storage& storage,
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>
94 template <
class Storage>
95 static void createGeometries(Storage& storage,
97 const bool nonConform )
99 assert ( nonConform ) ;
101 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
102 storage.template createGeometries< Grid > (type);
110 template <
class Storage>
111 static void createGeometries(Storage& storage,
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 >
149 GridFactory< Grid > factory(
false );
151 const Dune::ReferenceElement< ctype, dimension > &refElem
152 = Dune::ReferenceElements< ctype, dimension >::general( 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 ];
256 #endif // end HAVE_ALUGRID
258 #endif // #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH