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() );
108 generate( input, comm );
113 delete boundaryDomainBlock_;
121 template <
class Intersection>
122 bool wasInserted(
const Intersection &intersection)
const
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 >
145 int numParameters ()
const
151 bool haveBoundaryParameters ()
const
153 return boundaryDomainBlock_->hasParameter();
156 template<
class GG,
class II >
160 if( haveBoundaryParameters() )
162 std::vector< Point > corners;
163 getCorners( intersection.
geometry(), corners );
164 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
166 return data->parameter();
174 template<
class Entity >
175 std::vector<double> ¶meter (
const Entity &entity )
181 void generate( std::istream &gridin, MPICommunicatorType comm );
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 )
190 for(
int j = 0; j < dimension; ++j )
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() )
210 if( intervalBlock.numIntervals() != 1 )
213 if( intervalBlock.dimw() != dim )
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 )
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 ];
237 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
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 );
279 struct DGFGridInfo< YaspGrid<dim > > {
281 static double refineWeight() {
return std::pow(0.5,dim);}
296 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
299 explicit DGFGridFactory ( std::istream &input,
302 generate( input, comm );
305 explicit DGFGridFactory (
const std::string &filename,
308 std::ifstream input( filename.c_str() );
309 generate( input, comm );
314 delete boundaryDomainBlock_;
322 template <
class Intersection>
323 bool wasInserted(
const Intersection &intersection)
const
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 >
346 int numParameters ()
const
352 bool haveBoundaryParameters ()
const
354 return boundaryDomainBlock_->hasParameter();
357 template<
class GG,
class II >
361 if( haveBoundaryParameters() )
363 std::vector< Point > corners;
364 getCorners( intersection.
geometry(), corners );
365 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
367 return data->parameter();
375 template<
class Entity >
376 std::vector<double> ¶meter (
const Entity &entity )
382 void generate( std::istream &gridin, MPICommunicatorType comm );
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 )
391 for(
int j = 0; j < dimension; ++j )
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() )
411 if( intervalBlock.numIntervals() != 1 )
414 if( intervalBlock.dimw() != dim )
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 ];
434 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
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 )
460 || (std::abs( std::abs( trafo.shift[ dir ] ) - std::abs( upper[ dir ] - lower[ dir ] ) ) >= 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 );
481 struct DGFGridInfo< YaspGrid<dim, EquidistantOffsetCoordinates<double, dim> > > {
483 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:65
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:93
Wrapper class for geometries.
Definition: geometry.hh:66
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: geometry.hh:148
int corners() const
Return the number of corners of the reference element.
Definition: geometry.hh:134
@ dimension
The dimension of the grid.
Definition: grid.hh:387
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: intersection.hh:162
Geometry geometry() const
geometrical information about the intersection in global coordinates.
Definition: intersection.hh:351
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: intersection.hh:374
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:165
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:216
DWarnType dwarn(std::cerr)
Stream for warnings indicating problems.
Definition: stdstreams.hh:159
Dune namespace.
Definition: alignment.hh:11
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