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;
82 struct DGFGridFactory< YaspGrid<dim> >
84 typedef YaspGrid<dim> Grid;
89 typedef FieldVector< double, dimension > Point;
90 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
93 explicit DGFGridFactory ( std::istream &input,
96 generate( input, comm );
99 explicit DGFGridFactory (
const std::string &filename,
102 std::ifstream input( filename.c_str() );
103 generate( input, comm );
108 delete boundaryDomainBlock_;
116 template <
class Intersection>
117 bool wasInserted(
const Intersection &intersection)
const
121 template <
class Intersection>
122 int boundaryId(
const Intersection &intersection)
const
124 if( boundaryDomainBlock_->isactive() )
126 std::vector< Point > corners;
127 getCorners( intersection.geometry(), corners );
128 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
132 return intersection.indexInInside();
135 return intersection.indexInInside();
138 template<
int codim >
139 int numParameters ()
const
145 bool haveBoundaryParameters ()
const
147 return boundaryDomainBlock_->hasParameter();
150 template<
class GG,
class II >
152 boundaryParameter (
const Intersection< GG, II > & intersection )
const
154 if( haveBoundaryParameters() )
156 std::vector< Point > corners;
157 getCorners( intersection.geometry(), corners );
158 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
160 return data->parameter();
168 template<
class Entity >
169 std::vector<double> ¶meter (
const Entity &entity )
175 void generate( std::istream &gridin, MPICommunicatorType comm );
177 template<
class Geometry >
178 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
180 corners.resize( geometry.corners() );
181 for(
int i = 0; i < geometry.corners(); ++i )
184 for(
int j = 0; j < dimension; ++j )
185 corners[ i ][ j ] = corner[ j ];
190 dgf::BoundaryDomBlock *boundaryDomainBlock_;
191 std::vector<double> emptyParam;
195 inline void DGFGridFactory< YaspGrid< dim > >
196 ::generate ( std::istream &gridin, MPICommunicatorType comm )
198 dgf::IntervalBlock intervalBlock( gridin );
200 if( !intervalBlock.isactive() )
201 DUNE_THROW( DGFException,
"YaspGrid can only be created from an interval block." );
203 if( intervalBlock.numIntervals() != 1 )
204 DUNE_THROW( DGFException,
"YaspGrid can only handle 1 interval block." );
206 if( intervalBlock.dimw() != dim )
209 "Cannot read an interval of dimension " << intervalBlock.dimw()
210 <<
" into a YaspGrid< " << dim <<
" >." );
213 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
215 FieldVector<double,dim> lang;
217 for(
int i = 0; i < dim; ++i )
220 if( fabs( interval.p[ 0 ][ i ] ) > 1e-10 )
223 "YaspGrid cannot handle grids with non-zero left lower corner." );
226 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
227 anz[ i ] = interval.n[ i ];
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 )
236 const Transformation &trafo = trafoBlock.transformation( k );
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);
243 DUNE_THROW( DGFException,
"YaspGrid can only handle shifts as periodic face transformations." );
247 for(
int i = 0; i < dim; ++i )
249 if( fabs( trafo.shift[ i ] ) < 1e-10 )
254 if( (numDirs != 1) || (fabs( fabs( trafo.shift[ dir ] ) - lang[ dir ] ) >= 1e-10) )
256 std::cerr <<
"Tranformation '" << trafo
257 <<
"' does not map boundaries on boundaries." << std::endl;
264 dgf::YaspGridParameterBlock grdParam( gridin );
267 grid_ =
new YaspGrid< dim >( comm, lang, anz, per, grdParam.overlap() );
269 grid_ =
new YaspGrid< dim >( lang, anz, per, grdParam.overlap() );
272 boundaryDomainBlock_ =
new dgf::BoundaryDomBlock( gridin, dimension );
276 struct DGFGridInfo< YaspGrid<dim> > {
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