1 #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
2 #define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
5 #include <dune/common/misc.hh>
17 template<
int dim,
int dimw>
20 template<
int dim,
int dimw>
23 template<
int dim,
int dimw>
26 template<
class Gr
idImp,
class GeometryImpl,
int nChild >
27 class ALULocalGeometryStorage
30 Dune::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>
46 template <
class Storage>
47 static void createGeometries(Storage& storage,
49 const bool nonConform )
53 typedef ALUGrid< 2, dimworld, simplex, nonconforming, No_Comm > Grid;
54 storage.template createGeometries< Grid > (type);
58 typedef ALUGrid< 2, dimworld, simplex, conforming, No_Comm > Grid;
59 storage.template createGeometries< Grid > (type);
67 template <
class Storage>
68 static void createGeometries(Storage& storage,
70 const bool nonConform )
72 assert ( nonConform ) ;
74 typedef ALUGrid< 3, 3, simplex, nonconforming, No_Comm > Grid;
75 storage.template createGeometries< Grid > (type);
88 template <
int dummy,
int dimworld>
91 template <
class Storage>
92 static void createGeometries(Storage& storage,
94 const bool nonConform )
96 assert ( nonConform ) ;
98 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
99 storage.template createGeometries< Grid > (type);
107 template <
class Storage>
108 static void createGeometries(Storage& storage,
110 const bool nonConform )
112 assert( nonConform );
114 typedef ALUGrid< 3, 3, cube, nonconforming, No_Comm > Grid;
115 storage.template createGeometries< Grid > (type);
122 ALULocalGeometryStorage (
const GeometryType type,
const bool nonConform )
125 geoms_.fill( (GeometryImpl *) 0 );
128 CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
129 ::createGeometries(*
this, type, nonConform);
133 ~ALULocalGeometryStorage ()
135 for(
size_t i=0; i<geoms_.size(); ++i)
136 if(geoms_[i])
delete geoms_[i];
140 bool geomCreated(
int child)
const {
return geoms_[child] != 0; }
143 const GeometryImpl & operator [] (
int child)
const
145 assert( geomCreated(child) );
146 return *(geoms_[child]);
149 template <
class Gr
id >
153 GridFactory< Grid > factory(
false );
155 const Dune::GenericReferenceElement< ctype, dimension > &refElem
156 = Dune::GenericReferenceElements< ctype, dimension >::general( type );
159 FieldVector<ctype, dimensionworld> pos( 0 );
160 const int vxSize = refElem.size(dimension);
161 for(
int i=0; i<vxSize; ++i)
163 FieldVector<ctype, dimension> position = refElem.position(i, dimension );
165 for(
int d = 0; d<dimension; ++d )
166 pos[ d ] = position[ d ];
168 factory.insertVertex( pos );
171 std::vector< unsigned int > vertices( vxSize );
173 for(
size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
174 factory.insertElement(type, vertices);
177 std::streambuf* cerr_sbuf = std::cerr.rdbuf();
178 std::stringstream tempout;
180 std::cerr.rdbuf(tempout.rdbuf());
182 Grid* gridPtr = factory.createGrid();
183 Grid& grid = *gridPtr;
186 std::cerr.rdbuf(cerr_sbuf);
192 grid.globalRefine( level );
195 typedef typename Grid :: template Partition< All_Partition >:: LevelGridView MacroGridView;
196 MacroGridView macroView = grid.template levelView< All_Partition > ( 0 );
197 typedef typename MacroGridView :: template Codim< 0 > :: Iterator Iterator;
199 Iterator it = macroView.template begin<0> ();
201 if( it == macroView.template end<0>() )
202 DUNE_THROW(InvalidStateException,
"Empty Grid, should contain at least 1 element");
204 typedef typename Iterator :: Entity EntityType;
206 const EntityType& entity = *it;
207 const typename EntityType :: Geometry& geo = entity.geometry();
208 typedef typename EntityType :: HierarchicIterator HierarchicIteratorType;
209 const HierarchicIteratorType end = entity.hend( level );
212 for( HierarchicIteratorType child = entity.hbegin( level );
213 child != end; ++child, ++childNum )
215 create( geo, child->geometry(), childNum );
225 template<
class Geometry >
226 void create (
const Geometry &father,
230 assert( !geomCreated( child ) );
231 assert( (child >= 0) && (child < nChild) );
233 assert( (count_ < nChild) );
236 geoms_[ child ] =
new GeometryImpl();
237 geoms_[ child ]->buildGeomInFather( father, son );
243 #endif // end HAVE_ALUGRID
245 #endif // #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH