3 #ifndef DUNE_DGFPARSERYASP_HH
4 #define DUNE_DGFPARSERYASP_HH
16 template<
class Gr
idImp,
class IntersectionImp >
55 dwarn <<
"GridParameterBlock: found keyword `overlap' but no value, defaulting to `" <<
_overlap <<
"' !\n";
65 dwarn <<
"YaspGridParameterBlock: Parameter 'overlap' not specified, "
66 <<
"defaulting to '" <<
_overlap <<
"'." << std::endl;
84 template <
typename ctype,
int dim>
92 typedef FieldVector< ctype, dimension > Point;
99 generate( input, comm );
105 std::ifstream input( filename.c_str() );
107 DUNE_THROW(
DGFException,
"Error: Macrofile '" << filename <<
"' not found" );
108 generate( input, comm );
113 delete boundaryDomainBlock_;
121 template <
class Intersection>
127 template <
class Intersection>
130 if( boundaryDomainBlock_->isactive() )
132 std::vector< Point > corners;
133 getCorners( intersection.
geometry(), corners );
134 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
144 template<
int codim >
153 return boundaryDomainBlock_->hasParameter();
156 template<
class GG,
class II >
162 std::vector< Point > corners;
163 getCorners( intersection.
geometry(), corners );
164 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
174 template<
class Entity >
183 template<
class Geometry >
184 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
186 corners.resize( geometry.
corners() );
187 for(
int i = 0; i < geometry.
corners(); ++i )
191 corners[ i ][ j ] = corner[ j ];
196 dgf::BoundaryDomBlock *boundaryDomainBlock_;
197 std::vector<double> emptyParam;
201 template<
typename ctype,
int dim >
202 inline void DGFGridFactory< YaspGrid< dim , EquidistantCoordinates<ctype, dim> > >
203 ::generate ( std::istream &gridin, MPICommunicatorType comm )
206 dgf::IntervalBlock intervalBlock( gridin );
208 if( !intervalBlock.isactive() )
209 DUNE_THROW( DGFException,
"YaspGrid can only be created from an interval block." );
211 if( intervalBlock.numIntervals() != 1 )
212 DUNE_THROW( DGFException,
"YaspGrid can only handle 1 interval block." );
214 if( intervalBlock.dimw() != dim )
216 DUNE_THROW( DGFException,
217 "Cannot read an interval of dimension " << intervalBlock.dimw()
218 <<
" into a YaspGrid< " << dim <<
" >." );
221 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
223 FieldVector<ctype, dim> lang;
224 std::array<int,dim> anz;
225 for(
int i = 0; i < dim; ++i )
228 if( abs( interval.p[ 0 ][ i ] ) > 1e-10 )
230 DUNE_THROW( DGFException,
231 "YaspGrid cannot handle grids with non-zero left lower corner." );
234 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
235 anz[ i ] = interval.n[ i ];
238 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
239 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
240 std::bitset< dim > per;
241 const int numTrafos = trafoBlock.numTransformations();
242 for(
int k = 0; k < numTrafos; ++k )
244 const Transformation &trafo = trafoBlock.transformation( k );
246 bool identity =
true;
247 for(
int i = 0; i < dim; ++i )
248 for(
int j = 0; j < dim; ++j )
249 identity &= (abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
251 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
255 for(
int i = 0; i < dim; ++i )
257 if( abs( trafo.shift[ i ] ) < 1e-10 )
262 if( (numDirs != 1) || (abs( abs( trafo.shift[ dir ] ) - lang[ dir ] ) >= 1e-10) )
264 std::cerr <<
"Tranformation '" << trafo
265 <<
"' does not map boundaries on boundaries." << std::endl;
272 dgf::YaspGridParameterBlock grdParam( gridin );
274 grid_ =
new YaspGrid< dim , EquidistantCoordinates<ctype, dim> >( lang, anz, per, grdParam.overlap(), comm );
276 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
279 template <
typename ctype,
int dim>
288 template <
typename ctype,
int dim>
296 typedef FieldVector< ctype, dimension > Point;
303 generate( input, comm );
309 std::ifstream input( filename.c_str() );
310 generate( input, comm );
315 delete boundaryDomainBlock_;
323 template <
class Intersection>
329 template <
class Intersection>
332 if( boundaryDomainBlock_->isactive() )
334 std::vector< Point > corners;
335 getCorners( intersection.
geometry(), corners );
336 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
346 template<
int codim >
355 return boundaryDomainBlock_->hasParameter();
358 template<
class GG,
class II >
364 std::vector< Point > corners;
365 getCorners( intersection.
geometry(), corners );
366 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
376 template<
class Entity >
385 template<
class Geometry >
386 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
388 corners.resize( geometry.
corners() );
389 for(
int i = 0; i < geometry.
corners(); ++i )
393 corners[ i ][ j ] = corner[ j ];
398 dgf::BoundaryDomBlock *boundaryDomainBlock_;
399 std::vector<double> emptyParam;
403 template<
typename ctype,
int dim >
404 inline void DGFGridFactory< YaspGrid<dim, EquidistantOffsetCoordinates<ctype, dim> > >
405 ::generate ( std::istream &gridin, MPICommunicatorType comm )
408 dgf::IntervalBlock intervalBlock( gridin );
410 if( !intervalBlock.isactive() )
411 DUNE_THROW( DGFException,
"YaspGrid can only be created from an interval block." );
413 if( intervalBlock.numIntervals() != 1 )
414 DUNE_THROW( DGFException,
"YaspGrid can only handle 1 interval block." );
416 if( intervalBlock.dimw() != dim )
418 DUNE_THROW( DGFException,
419 "Cannot read an interval of dimension "
420 << intervalBlock.dimw()
421 <<
" into a YaspGrid< " << dim <<
" >." );
424 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
426 FieldVector<ctype, dim> lower;
427 FieldVector<ctype, dim> upper;
428 std::array<int,dim> anz;
429 for(
int i = 0; i < dim; ++i )
431 lower[ i ] = interval.p[ 0 ][ i ];
432 upper[ i ] = interval.p[ 1 ][ i ];
433 anz[ i ] = interval.n[ i ];
436 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
437 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
438 std::bitset< dim > periodic;
439 const int numTrafos = trafoBlock.numTransformations();
440 for(
int k = 0; k < numTrafos; ++k )
442 const Transformation &trafo = trafoBlock.transformation( k );
444 bool identity =
true;
445 for(
int i = 0; i < dim; ++i )
446 for(
int j = 0; j < dim; ++j )
447 identity &= (abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
449 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
453 for(
int currentDir = 0; currentDir < dim; ++currentDir )
455 if( abs( trafo.shift[ currentDir ] ) > 1e-10 )
462 || (abs( abs( trafo.shift[ dir ] ) - abs( upper[ dir ] - lower[ dir ] ) ) >= 1e-10) )
464 std::cerr <<
"Tranformation '" << trafo
465 <<
"' does not map boundaries on boundaries." << std::endl;
469 periodic[ dir ] =
true;
474 dgf::YaspGridParameterBlock grdParam( gridin );
476 grid_ =
new YaspGrid< dim, EquidistantOffsetCoordinates<ctype, dim> >
477 ( lower, upper, anz, periodic, grdParam.overlap(), comm );
479 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
482 template <
typename ctype,
int dim>
489 #endif // #ifndef DUNE_DGFPARSERYASP_HH