Dune Core Modules (2.3.1)

dgfyasp.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_DGFPARSERYASP_HH
4#define DUNE_DGFPARSERYASP_HH
5
6#include <dune/grid/common/intersection.hh>
8#include "dgfparser.hh"
9
10namespace Dune
11{
12
13 // External Forward Declarations
14 // -----------------------------
15
16 template< class GridImp, class IntersectionImp >
17 class Intersection;
18
19
20 namespace dgf
21 {
22
37 : public GridParameterBlock
38 {
39 protected:
40 int _overlap; // overlap for YaspGrid
41
42 public:
44 YaspGridParameterBlock( std::istream &in )
45 : GridParameterBlock( in ),
46 _overlap( 0 ) // default value
47 {
48 // check overlap
49 if( findtoken( "overlap" ) )
50 {
51 int x;
52 if( getnextentry(x) ) _overlap = x;
53 else
54 {
55 dwarn << "GridParameterBlock: found keyword `overlap' but no value, defaulting to `" << _overlap <<"' !\n";
56 }
57
58 if (_overlap < 0)
59 {
60 DUNE_THROW(DGFException,"Negative overlap specified!");
61 }
62 }
63 else
64 {
65 dwarn << "YaspGridParameterBlock: Parameter 'overlap' not specified, "
66 << "defaulting to '" << _overlap << "'." << std::endl;
67 }
68
69 }
70
72 int overlap () const
73 {
74 return _overlap;
75 }
76
77 };
78
79 }
80
81 template <int dim>
82 struct DGFGridFactory< YaspGrid<dim> >
83 {
84 typedef YaspGrid<dim> Grid;
85 const static int dimension = Grid::dimension;
86 typedef MPIHelper::MPICommunicator MPICommunicatorType;
87
88 private:
89 typedef FieldVector< double, dimension > Point;
90 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
91
92 public:
93 explicit DGFGridFactory ( std::istream &input,
94 MPICommunicatorType comm = MPIHelper::getCommunicator() )
95 {
96 generate( input, comm );
97 }
98
99 explicit DGFGridFactory ( const std::string &filename,
100 MPICommunicatorType comm = MPIHelper::getCommunicator() )
101 {
102 std::ifstream input( filename.c_str() );
103 generate( input, comm );
104 }
105
106 ~DGFGridFactory ()
107 {
108 delete boundaryDomainBlock_;
109 }
110
111 Grid *grid() const
112 {
113 return grid_;
114 }
115
116 template <class Intersection>
117 bool wasInserted(const Intersection &intersection) const
118 {
119 return false;
120 }
121 template <class Intersection>
122 int boundaryId(const Intersection &intersection) const
123 {
124 if( boundaryDomainBlock_->isactive() )
125 {
126 std::vector< Point > corners;
127 getCorners( intersection.geometry(), corners );
128 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
129 if( data )
130 return data->id();
131 else
132 return intersection.indexInInside();
133 }
134 else
135 return intersection.indexInInside();
136 }
137
138 template< int codim >
139 int numParameters () const
140 {
141 return 0;
142 }
143
144 // return true if boundary parameters found
145 bool haveBoundaryParameters () const
146 {
147 return boundaryDomainBlock_->hasParameter();
148 }
149
150 template< class GG, class II >
151 const typename DGFBoundaryParameter::type &
152 boundaryParameter ( const Intersection< GG, II > & intersection ) const
153 {
154 if( haveBoundaryParameters() )
155 {
156 std::vector< Point > corners;
157 getCorners( intersection.geometry(), corners );
158 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
159 if( data )
160 return data->parameter();
161 else
163 }
164 else
166 }
167
168 template< class Entity >
169 std::vector<double> &parameter ( const Entity &entity )
170 {
171 return emptyParam;
172 }
173
174 private:
175 void generate( std::istream &gridin, MPICommunicatorType comm );
176
177 template< class Geometry >
178 static void getCorners ( const Geometry &geometry, std::vector< Point > &corners )
179 {
180 corners.resize( geometry.corners() );
181 for( int i = 0; i < geometry.corners(); ++i )
182 {
183 const typename Geometry::GlobalCoordinate corner = geometry.corner( i );
184 for( int j = 0; j < dimension; ++j )
185 corners[ i ][ j ] = corner[ j ];
186 }
187 }
188
189 Grid *grid_;
190 dgf::BoundaryDomBlock *boundaryDomainBlock_;
191 std::vector<double> emptyParam;
192 };
193
194 template< int dim >
195 inline void DGFGridFactory< YaspGrid< dim > >
196 ::generate ( std::istream &gridin, MPICommunicatorType comm )
197 {
198 dgf::IntervalBlock intervalBlock( gridin );
199
200 if( !intervalBlock.isactive() )
201 DUNE_THROW( DGFException, "YaspGrid can only be created from an interval block." );
202
203 if( intervalBlock.numIntervals() != 1 )
204 DUNE_THROW( DGFException, "YaspGrid can only handle 1 interval block." );
205
206 if( intervalBlock.dimw() != dim )
207 {
208 DUNE_THROW( DGFException,
209 "Cannot read an interval of dimension " << intervalBlock.dimw()
210 << " into a YaspGrid< " << dim << " >." );
211 }
212
213 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
214
215 FieldVector<double,dim> lang;
216 array<int,dim> anz;
217 for( int i = 0; i < dim; ++i )
218 {
219 // check that start point is 0.0
220 if( fabs( interval.p[ 0 ][ i ] ) > 1e-10 )
221 {
222 DUNE_THROW( DGFException,
223 "YaspGrid cannot handle grids with non-zero left lower corner." );
224 }
225
226 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
227 anz[ i ] = interval.n[ i ];
228 }
229
230 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
231 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
232 std::bitset< dim > per;
233 const int numTrafos = trafoBlock.numTransformations();
234 for( int k = 0; k < numTrafos; ++k )
235 {
236 const Transformation &trafo = trafoBlock.transformation( k );
237
238 bool identity = true;
239 for( int i = 0; i < dim; ++i )
240 for( int j = 0; j < dim; ++j )
241 identity &= (fabs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
242 if( !identity )
243 DUNE_THROW( DGFException, "YaspGrid can only handle shifts as periodic face transformations." );
244
245 int numDirs = 0;
246 int dir = -1;
247 for( int i = 0; i < dim; ++i )
248 {
249 if( fabs( trafo.shift[ i ] ) < 1e-10 )
250 continue;
251 dir = i;
252 ++numDirs;
253 }
254 if( (numDirs != 1) || (fabs( fabs( trafo.shift[ dir ] ) - lang[ dir ] ) >= 1e-10) )
255 {
256 std::cerr << "Tranformation '" << trafo
257 << "' does not map boundaries on boundaries." << std::endl;
258 }
259 else
260 per[ dir ] = true;
261 }
262
263 // get grid parameters
264 dgf::YaspGridParameterBlock grdParam( gridin );
265
266#if HAVE_MPI
267 grid_ = new YaspGrid< dim >( comm, lang, anz, per, grdParam.overlap() );
268#else
269 grid_ = new YaspGrid< dim >( lang, anz, per, grdParam.overlap() );
270#endif
271
272 boundaryDomainBlock_ = new dgf::BoundaryDomBlock( gridin, dimension );
273 }
274
275 template <int dim>
276 struct DGFGridInfo< YaspGrid<dim> > {
277 static int refineStepsForHalf() {return 1;}
278 static double refineWeight() {return pow(0.5,dim);}
279 };
280
281
282}
283#endif // #ifndef DUNE_DGFPARSERYASP_HH
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:14
FieldVector< ctype, cdim > GlobalCoordinate
type of the global coordinates
Definition: geometry.hh:136
@ dimension
The dimension of the grid.
Definition: grid.hh:400
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:174
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:182
Common Grid parameters.
Definition: gridparameter.hh:33
Grid parameters for YaspGrid.
Definition: dgfyasp.hh:38
YaspGridParameterBlock(std::istream &in)
constructor taking istream
Definition: dgfyasp.hh:44
int overlap() const
get dimension of world found in block
Definition: dgfyasp.hh:72
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
DWarnType dwarn(std::cerr)
Stream for warnings indicating problems.
Definition: stdstreams.hh:160
Dune namespace.
Definition: alignment.hh:14
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23
static double refineWeight()
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)