3 #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
4 #define DUNE_ALUGRIDGEOMETRYSTORAGE_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>
40 template <
class Storage>
41 static void createGeometries(Storage& storage,
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);
61 template <
class Storage>
62 static void createGeometries(Storage& storage,
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>
85 template <
class Storage>
86 static void createGeometries(Storage& storage,
88 const bool nonConform )
90 assert ( nonConform ) ;
92 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
93 storage.template createGeometries< Grid > (type);
101 template <
class Storage>
102 static void createGeometries(Storage& storage,
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 >
142 const Dune::ReferenceElement< ctype, dimension > &refElem
143 = Dune::ReferenceElements< ctype, dimension >::general( 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 ];
247 #endif // end HAVE_ALUGRID
249 #endif // #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
Definition: alu2dinclude.hh:55
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Include standard header files.
Definition: agrid.hh:59
Definition: alu2dinclude.hh:55
Definition: topology.hh:13
Definition: topology.hh:13
Different resources needed by all grid implementations.
Provide a generic factory class for unstructured grids.
#define ALU3DSPACE
Definition: alu3dinclude.hh:26
#define ALU2DSPACE
Definition: alu2dinclude.hh:34