3#ifndef DUNE_DGFPARSERYASP_HH
4#define DUNE_DGFPARSERYASP_HH
6#include <dune/grid/common/intersection.hh>
16 template<
class Gr
idImp,
class IntersectionImp >
49 if( findtoken(
"overlap" ) )
52 if( getnextentry(x) ) _overlap = x;
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;
93 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
96 explicit DGFGridFactory ( std::istream &input,
99 generate( input, comm );
102 explicit DGFGridFactory (
const std::string &filename,
105 std::ifstream input( filename.c_str() );
106 generate( input, comm );
111 delete boundaryDomainBlock_;
119 template <
class Intersection>
120 bool wasInserted(
const Intersection &intersection)
const
125 template <
class Intersection>
128 if( boundaryDomainBlock_->isactive() )
130 std::vector< Point > corners;
131 getCorners( intersection.
geometry(), corners );
132 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
142 template<
int codim >
143 int numParameters ()
const
149 bool haveBoundaryParameters ()
const
151 return boundaryDomainBlock_->hasParameter();
154 template<
class GG,
class II >
158 if( haveBoundaryParameters() )
160 std::vector< Point > corners;
161 getCorners( intersection.
geometry(), corners );
162 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
164 return data->parameter();
172 template<
class Entity >
173 std::vector<double> ¶meter (
const Entity &entity )
179 void generate( std::istream &gridin, MPICommunicatorType comm );
181 template<
class Geometry >
182 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
184 corners.resize( geometry.
corners() );
185 for(
int i = 0; i < geometry.
corners(); ++i )
188 for(
int j = 0; j < dimension; ++j )
189 corners[ i ][ j ] = corner[ j ];
194 dgf::BoundaryDomBlock *boundaryDomainBlock_;
195 std::vector<double> emptyParam;
200 inline void DGFGridFactory<
YaspGrid< dim > >
201 ::generate ( std::istream &gridin, MPICommunicatorType comm )
203 dgf::IntervalBlock intervalBlock( gridin );
205 if( !intervalBlock.isactive() )
208 if( intervalBlock.numIntervals() != 1 )
211 if( intervalBlock.dimw() != dim )
214 "Cannot read an interval of dimension " << intervalBlock.dimw()
215 <<
" into a YaspGrid< " << dim <<
" >." );
218 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
220 FieldVector<double,dim> lang;
221 std::array<int,dim> anz;
222 for(
int i = 0; i < dim; ++i )
225 if( std::abs( interval.p[ 0 ][ i ] ) > 1e-10 )
228 "YaspGrid cannot handle grids with non-zero left lower corner." );
231 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
232 anz[ i ] = interval.n[ i ];
235 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
236 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
237 std::bitset< dim > per;
238 const int numTrafos = trafoBlock.numTransformations();
239 for(
int k = 0; k < numTrafos; ++k )
241 const Transformation &trafo = trafoBlock.transformation( k );
243 bool identity =
true;
244 for(
int i = 0; i < dim; ++i )
245 for(
int j = 0; j < dim; ++j )
246 identity &= (std::abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
248 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
252 for(
int i = 0; i < dim; ++i )
254 if( std::abs( trafo.shift[ i ] ) < 1e-10 )
259 if( (numDirs != 1) || (std::abs( std::abs( trafo.shift[ dir ] ) - lang[ dir ] ) >= 1e-10) )
261 std::cerr <<
"Tranformation '" << trafo
262 <<
"' does not map boundaries on boundaries." << std::endl;
269 dgf::YaspGridParameterBlock grdParam( gridin );
271 grid_ =
new YaspGrid< dim >( lang, anz, per, grdParam.overlap(), comm );
273 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
277 struct DGFGridInfo< YaspGrid<dim > > {
279 static double refineWeight() {
return std::pow(0.5,dim);}
294 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
297 explicit DGFGridFactory ( std::istream &input,
300 generate( input, comm );
303 explicit DGFGridFactory (
const std::string &filename,
306 std::ifstream input( filename.c_str() );
307 generate( input, comm );
312 delete boundaryDomainBlock_;
320 template <
class Intersection>
321 bool wasInserted(
const Intersection &intersection)
const
326 template <
class Intersection>
329 if( boundaryDomainBlock_->isactive() )
331 std::vector< Point > corners;
332 getCorners( intersection.
geometry(), corners );
333 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
343 template<
int codim >
344 int numParameters ()
const
350 bool haveBoundaryParameters ()
const
352 return boundaryDomainBlock_->hasParameter();
355 template<
class GG,
class II >
359 if( haveBoundaryParameters() )
361 std::vector< Point > corners;
362 getCorners( intersection.
geometry(), corners );
363 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
365 return data->parameter();
373 template<
class Entity >
374 std::vector<double> ¶meter (
const Entity &entity )
380 void generate( std::istream &gridin, MPICommunicatorType comm );
382 template<
class Geometry >
383 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
385 corners.resize( geometry.
corners() );
386 for(
int i = 0; i < geometry.
corners(); ++i )
389 for(
int j = 0; j < dimension; ++j )
390 corners[ i ][ j ] = corner[ j ];
395 dgf::BoundaryDomBlock *boundaryDomainBlock_;
396 std::vector<double> emptyParam;
401 inline void DGFGridFactory< YaspGrid<dim, EquidistantOffsetCoordinates<double, dim> > >
402 ::generate ( std::istream &gridin, MPICommunicatorType comm )
404 dgf::IntervalBlock intervalBlock( gridin );
406 if( !intervalBlock.isactive() )
409 if( intervalBlock.numIntervals() != 1 )
412 if( intervalBlock.dimw() != dim )
415 "Cannot read an interval of dimension "
416 << intervalBlock.dimw()
417 <<
" into a YaspGrid< " << dim <<
" >." );
420 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
422 FieldVector<double,dim> lower;
423 FieldVector<double,dim> upper;
424 std::array<int,dim> anz;
425 for(
int i = 0; i < dim; ++i )
427 lower[ i ] = interval.p[ 0 ][ i ];
428 upper[ i ] = interval.p[ 1 ][ i ];
429 anz[ i ] = interval.n[ i ];
432 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
433 dgf::PeriodicFaceTransformationBlock trafoBlock( gridin, dim );
434 std::bitset< dim > periodic;
435 const int numTrafos = trafoBlock.numTransformations();
436 for(
int k = 0; k < numTrafos; ++k )
438 const Transformation &trafo = trafoBlock.transformation( k );
440 bool identity =
true;
441 for(
int i = 0; i < dim; ++i )
442 for(
int j = 0; j < dim; ++j )
443 identity &= (std::abs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
445 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
449 for(
int currentDir = 0; currentDir < dim; ++currentDir )
451 if( std::abs( trafo.shift[ currentDir ] ) > 1e-10 )
458 || (std::abs( std::abs( trafo.shift[ dir ] ) - std::abs( upper[ dir ] - lower[ dir ] ) ) >= 1e-10) )
460 std::cerr <<
"Tranformation '" << trafo
461 <<
"' does not map boundaries on boundaries." << std::endl;
465 periodic[ dir ] =
true;
470 dgf::YaspGridParameterBlock grdParam( gridin );
472 grid_ =
new YaspGrid< dim, EquidistantOffsetCoordinates<double, dim> >
473 ( lower, upper, anz, periodic, grdParam.overlap(), comm );
475 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
479 struct DGFGridInfo< YaspGrid<dim, EquidistantOffsetCoordinates<double, dim> > > {
481 static double refineWeight() {
return std::pow(0.5,dim);}
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:14
Wrapper class for entities.
Definition: entity.hh:62
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:125
vector space out of a tensor product of fields.
Definition: fvector.hh:94
Wrapper class for geometries.
Definition: geometry.hh:66
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: geometry.hh:156
int corners() const
Return the number of corners of the reference element.
Definition: geometry.hh:142
@ dimension
The dimension of the grid.
Definition: grid.hh:402
Intersection of a mesh entities of codimension 0 ("elements") with a "neighboring" element or with th...
Definition: intersection.hh:161
Geometry geometry() const
geometrical information about the intersection in global coordinates.
Definition: intersection.hh:373
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: intersection.hh:393
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:173
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:181
[ provides Dune::Grid ]
Definition: yaspgrid.hh:166
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:243
DWarnType dwarn(std::cerr)
Stream for warnings indicating problems.
Definition: stdstreams.hh:159
Dune namespace.
Definition: alignment.hh:10
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