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;
92 typedef FieldVector< double, 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;
202 inline void DGFGridFactory< YaspGrid< dim > >
203 ::generate ( std::istream &gridin, MPICommunicatorType comm )
205 dgf::IntervalBlock intervalBlock( gridin );
207 if( !intervalBlock.isactive() )
208 DUNE_THROW( DGFException,
"YaspGrid can only be created from an interval block." );
210 if( intervalBlock.numIntervals() != 1 )
211 DUNE_THROW( DGFException,
"YaspGrid can only handle 1 interval block." );
213 if( intervalBlock.dimw() != dim )
215 DUNE_THROW( DGFException,
216 "Cannot read an interval of dimension " << intervalBlock.dimw()
217 <<
" into a YaspGrid< " << dim <<
" >." );
220 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
222 FieldVector<double,dim> lang;
223 std::array<int,dim> anz;
224 for(
int i = 0; i < dim; ++i )
227 if(
std::abs( interval.p[ 0 ][ i ] ) > 1e-10 )
229 DUNE_THROW( DGFException,
230 "YaspGrid cannot handle grids with non-zero left lower corner." );
233 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
234 anz[ i ] = interval.n[ i ];
238 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
239 std::bitset< dim > per;
240 const int numTrafos = trafoBlock.numTransformations();
241 for(
int k = 0; k < numTrafos; ++k )
243 const Transformation &trafo = trafoBlock.transformation( k );
245 bool identity =
true;
246 for(
int i = 0; i < dim; ++i )
247 for(
int j = 0; j < dim; ++j )
248 identity &= (
std::abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
250 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
254 for(
int i = 0; i < dim; ++i )
256 if(
std::abs( trafo.shift[ i ] ) < 1e-10 )
261 if( (numDirs != 1) || (
std::abs(
std::abs( trafo.shift[ dir ] ) - lang[ dir ] ) >= 1e-10) )
263 std::cerr <<
"Tranformation '" << trafo
264 <<
"' does not map boundaries on boundaries." << std::endl;
271 dgf::YaspGridParameterBlock grdParam( gridin );
273 grid_ =
new YaspGrid< dim >( lang, anz, per, grdParam.overlap(), comm );
275 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
295 typedef FieldVector< double, dimension > Point;
302 generate( input, comm );
308 std::ifstream input( filename.c_str() );
309 generate( input, comm );
314 delete boundaryDomainBlock_;
322 template <
class Intersection>
328 template <
class Intersection>
331 if( boundaryDomainBlock_->isactive() )
333 std::vector< Point > corners;
334 getCorners( intersection.
geometry(), corners );
335 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
345 template<
int codim >
354 return boundaryDomainBlock_->hasParameter();
357 template<
class GG,
class II >
363 std::vector< Point > corners;
364 getCorners( intersection.
geometry(), corners );
365 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
375 template<
class Entity >
384 template<
class Geometry >
385 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
387 corners.resize( geometry.
corners() );
388 for(
int i = 0; i < geometry.
corners(); ++i )
392 corners[ i ][ j ] = corner[ j ];
397 dgf::BoundaryDomBlock *boundaryDomainBlock_;
398 std::vector<double> emptyParam;
403 inline void DGFGridFactory< YaspGrid<dim, EquidistantOffsetCoordinates<double, dim> > >
404 ::generate ( std::istream &gridin, MPICommunicatorType comm )
406 dgf::IntervalBlock intervalBlock( gridin );
408 if( !intervalBlock.isactive() )
409 DUNE_THROW( DGFException,
"YaspGrid can only be created from an interval block." );
411 if( intervalBlock.numIntervals() != 1 )
412 DUNE_THROW( DGFException,
"YaspGrid can only handle 1 interval block." );
414 if( intervalBlock.dimw() != dim )
416 DUNE_THROW( DGFException,
417 "Cannot read an interval of dimension "
418 << intervalBlock.dimw()
419 <<
" into a YaspGrid< " << dim <<
" >." );
422 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
424 FieldVector<double,dim> lower;
425 FieldVector<double,dim> upper;
426 std::array<int,dim> anz;
427 for(
int i = 0; i < dim; ++i )
429 lower[ i ] = interval.p[ 0 ][ i ];
430 upper[ i ] = interval.p[ 1 ][ i ];
431 anz[ i ] = interval.n[ i ];
435 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
436 std::bitset< dim > periodic;
437 const int numTrafos = trafoBlock.numTransformations();
438 for(
int k = 0; k < numTrafos; ++k )
440 const Transformation &trafo = trafoBlock.transformation( k );
442 bool identity =
true;
443 for(
int i = 0; i < dim; ++i )
444 for(
int j = 0; j < dim; ++j )
445 identity &= (
std::abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
447 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
451 for(
int currentDir = 0; currentDir < dim; ++currentDir )
453 if(
std::abs( trafo.shift[ currentDir ] ) > 1e-10 )
462 std::cerr <<
"Tranformation '" << trafo
463 <<
"' does not map boundaries on boundaries." << std::endl;
467 periodic[ dir ] =
true;
472 dgf::YaspGridParameterBlock grdParam( gridin );
474 grid_ =
new YaspGrid< dim, EquidistantOffsetCoordinates<double, dim> >
475 ( lower, upper, anz, periodic, grdParam.overlap(), comm );
477 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
487 #endif // #ifndef DUNE_DGFPARSERYASP_HH