Dune Core Modules (2.4.2)

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