Dune Core Modules (2.3.1)

geostorage.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
4#define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
5
6// Dune includes
9
10#if HAVE_ALUGRID
11
12#include <dune/grid/alugrid/common/declaration.hh>
13#include <dune/grid/alugrid/3d/alu3dinclude.hh>
14#include <dune/grid/alugrid/2d/alu2dinclude.hh>
15
16namespace Dune
17{
18 template<int dim, int dimw>
19 class ALUCubeGrid;
20
21 template<int dim, int dimw>
22 class ALUSimplexGrid;
23
24 template<int dim, int dimw>
25 class ALUConformGrid;
26
27 template< class GridImp, class GeometryImpl, int nChild >
28 class ALULocalGeometryStorage
29 {
30 typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType;
31
32 // array with pointers to the geometries
34
35 // count local geometry creation
36 int count_;
37
38 // type of grid impl
39 typedef typename GridImp :: ctype ctype;
40 enum { dimension = GridImp :: dimension };
41 enum { dimensionworld = GridImp :: dimensionworld };
42
43 template <int dummy, int dim, int dimworld, int >
44 struct CreateGeometries;
45
46 template <int dummy, int dimworld>
47 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE triangle >
48 {
49 template <class Storage>
50 static void createGeometries(Storage& storage,
51 const GeometryType& type,
52 const bool nonConform )
53 {
54 if( nonConform )
55 {
56 typedef ALUGrid< 2, dimworld, simplex, nonconforming, No_Comm > Grid;
57 storage.template createGeometries< Grid > (type);
58 }
59 else
60 {
61 typedef ALUGrid< 2, dimworld, simplex, conforming, No_Comm > Grid;
62 storage.template createGeometries< Grid > (type);
63 }
64 }
65 };
66
67 template <int dummy>
68 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE tetra >
69 {
70 template <class Storage>
71 static void createGeometries(Storage& storage,
72 const GeometryType& type,
73 const bool nonConform )
74 {
75 assert ( nonConform ) ;
76 {
77 typedef ALUGrid< 3, 3, simplex, nonconforming, No_Comm > Grid;
78 storage.template createGeometries< Grid > (type);
79 }
80 /*
81 // TODO, implement this for refinement of all edges (conforming)
82 else
83 {
84 typedef ALUGrid< 3, 3, simplex, conforming, No_Comm > Grid;
85 storage.template createGeometries< Grid > (type);
86 }
87 */
88 }
89 };
90
91 template <int dummy, int dimworld>
92 struct CreateGeometries<dummy, 2, dimworld, ALU2DSPACE quadrilateral >
93 {
94 template <class Storage>
95 static void createGeometries(Storage& storage,
96 const GeometryType& type,
97 const bool nonConform )
98 {
99 assert ( nonConform ) ;
100 {
101 typedef ALUGrid< 2, dimworld, cube, nonconforming, No_Comm > Grid;
102 storage.template createGeometries< Grid > (type);
103 }
104 }
105 };
106
107 template <int dummy>
108 struct CreateGeometries<dummy, 3, 3, ALU3DSPACE hexa >
109 {
110 template <class Storage>
111 static void createGeometries(Storage& storage,
112 const GeometryType& type,
113 const bool nonConform )
114 {
115 assert( nonConform );
116 {
117 typedef ALUGrid< 3, 3, cube, nonconforming, No_Comm > Grid;
118 storage.template createGeometries< Grid > (type);
119 }
120 }
121 };
122
123 public:
124 // create empty storage
125 ALULocalGeometryStorage ( const GeometryType type, const bool nonConform )
126 : count_( 0 )
127 {
128 geoms_.fill( (GeometryImpl *) 0 );
129 // the idea is to create a grid containing the reference element,
130 // refine once and the store the father - child relations
131 CreateGeometries<0, dimension, dimensionworld, GridImp :: elementType >
132 ::createGeometries(*this, type, nonConform);
133 }
134
135 // check if geometry has been created
136 bool geomCreated(int child) const { return geoms_[child] != 0; }
137
138 // return reference to local geometry
139 const GeometryImpl & operator [] (int child) const
140 {
141 assert( geomCreated(child) );
142 return *(geoms_[child]);
143 }
144
145 template < class Grid >
146 void createGeometries(const GeometryType& type)
147 {
148 // create factory without verbosity
149 GridFactory< Grid > factory( false );
150
153
154 // insert vertices
155 FieldVector<ctype, dimensionworld> pos( 0 );
156 const int vxSize = refElem.size(dimension);
157 for(int i=0; i<vxSize; ++i)
158 {
159 FieldVector<ctype, dimension> position = refElem.position(i, dimension );
160 // copy position
161 for(int d = 0; d<dimension; ++d )
162 pos[ d ] = position[ d ];
163
164 factory.insertVertex( pos );
165 }
166
167 std::vector< unsigned int > vertices( vxSize );
168 // create grid with reference element
169 for(size_t i=0; i<vertices.size(); ++i) vertices[ i ] = i;
170 factory.insertElement(type, vertices);
171
172 // save original sbuf
173 std::streambuf* cerr_sbuf = std::cerr.rdbuf();
174 std::stringstream tempout;
175 // redirect 'cerr' to a 'fout' to avoid unnecessary output in constructors
176 std::cerr.rdbuf(tempout.rdbuf());
177
178 Grid* gridPtr = factory.createGrid();
179 Grid& grid = *gridPtr;
180
181 // restore the original stream buffer
182 std::cerr.rdbuf(cerr_sbuf);
183
184 //std::cerr = savecerr;
185
186 // refine once to get children
187 const int level = 1;
188 grid.globalRefine( level );
189
190 {
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;
194
195 Iterator it = macroView.template begin<0> ();
196
197 if( it == macroView.template end<0>() )
198 DUNE_THROW(InvalidStateException,"Empty Grid, should contain at least 1 element");
199
200 typedef typename Iterator :: Entity EntityType;
201
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 );
206
207 int childNum = 0;
208 for( HierarchicIteratorType child = entity.hbegin( level );
209 child != end; ++child, ++childNum )
210 {
211 create( geo, child->geometry(), childNum );
212 }
213 }
214
215 // delete grid
216 delete gridPtr;
217 }
218
219 // create local geometry
220 template< class Geometry >
221 void create ( const Geometry &father,
222 const Geometry &son,
223 const int child )
224 {
225 assert( !geomCreated( child ) );
226 assert( (child >= 0) && (child < nChild) );
227
228 assert( (count_ < nChild) );
229 ++count_;
230
231 geoms_[ child ] = new GeometryImpl();
232 geoms_[ child ]->buildGeomInFather( father, son );
233 }
234
235 public:
236 // desctructor deleteing geometries
237 ~ALULocalGeometryStorage ()
238 {
239 for(size_t i=0; i<geoms_.size(); ++i)
240 if(geoms_[i]) delete geoms_[i];
241 }
242
244 static const GeometryImpl& geom( const GeometryType type, const bool nonConforming, const int child )
245 {
246 // create static variable on heap
247 static ThisType instance( type, nonConforming );
248 // make sure the geometry type is the same
249 assert( type == instance[ child ].type() );
250 return instance[ child ];
251 }
252 };
253
254} // namespace Dune
255
256#endif // end HAVE_ALUGRID
257
258#endif // #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)