1#ifndef DUNE_SPGRID_DGFPARSER_HH
2#define DUNE_SPGRID_DGFPARSER_HH
4#include <dune/grid/io/file/dgfparser/dgfparser.hh>
5#include <dune/grid/spgrid.hh>
17 struct SPGridParameterBlock
18 :
public GridParameterBlock
20 typedef int MultiIndex[ dim ];
22 explicit SPGridParameterBlock( std::istream &in );
24 const MultiIndex &overlap ()
const
39 inline SPGridParameterBlock< dim >::SPGridParameterBlock( std::istream &in )
40 : GridParameterBlock( in )
42 for(
int i = 0; i < dim; ++i )
45 if( findtoken(
"overlap" ) )
48 for(
int x; getnextentry( x ); ++i )
51 DUNE_THROW( DGFException,
"Negative overlap specified." );
57 dwarn <<
"GridParameterBlock: Found keyword 'overlap' without valid value, defaulting to no overlap." << std::endl;
60 for(
int i = 1; i < dim; ++i )
61 overlap_[ i ] = overlap_[ 0 ];
64 DUNE_THROW( DGFException,
"Invalid argument for parameter 'overlap' specified." );
67 dwarn <<
"GridParameterBlock: Parameter 'overlap' not specified, defaulting to no overlap." << std::endl;
77 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
78 class DGFGridFactory< SPGrid< ct, dim, Ref, Comm > >
81 typedef SPGrid< ct, dim, Ref, Comm > Grid;
83 typedef MPIHelper::MPICommunicator MPICommunicatorType;
84 typedef typename Grid::Communication Communication;
86 static const int dimension = Grid::dimension;
87 typedef typename Grid::template Codim< 0 >::Entity Element;
88 typedef typename Grid::template Codim< dimension >::Entity Vertex;
91 typedef FieldVector< double, dimension > Point;
93 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
96 explicit DGFGridFactory ( std::istream &input,
97 MPICommunicatorType comm = MPIHelper::getCommunicator() );
99 explicit DGFGridFactory (
const std::string &filename,
100 MPICommunicatorType comm = MPIHelper::getCommunicator() );
104 delete boundaryDomainBlock_;
112 template<
class Intersection >
113 bool wasInserted (
const Intersection &intersection )
const
118 template<
class Intersection >
119 int boundaryId (
const Intersection &intersection )
const
121 std::vector< Point > corners;
122 getCorners( intersection.geometry(), corners );
123 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
127 return intersection.indexInInside();
130 bool haveBoundaryParameters ()
const
132 return boundaryDomainBlock_->hasParameter();
135 template<
int codim >
136 int numParameters ()
const
141 template<
class Intersection >
142 const typename DGFBoundaryParameter::type &
143 boundaryParameter (
const Intersection &intersection )
const
145 std::vector< Point > corners;
146 getCorners( intersection.geometry(), corners );
147 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
149 return data->parameter();
151 return DGFBoundaryParameter::defaultValue();
154 template<
class Entity >
155 std::vector< double > ¶meter (
const Entity &entity )
158 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
162 void generate ( std::istream &input,
const Communication &comm );
164 template<
class Geometry >
165 static void getCorners (
const Geometry &geometry, std::vector< Point > &corners )
167 corners.resize( geometry.corners() );
168 for(
int i = 0; i < geometry.corners(); ++i )
170 const typename Geometry::GlobalCoordinate corner = geometry.corner( i );
171 for(
int j = 0; j < dimension; ++j )
172 corners[ i ][ j ] = corner[ j ];
177 BoundaryDomainBlock *boundaryDomainBlock_;
185 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
186 inline DGFGridFactory< SPGrid< ct, dim, Ref, Comm > >
187 ::DGFGridFactory ( std::istream &input, MPICommunicatorType comm )
189 generate( input, SPCommunicationTraits< Comm >::comm( comm ) );
193 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
194 inline DGFGridFactory< SPGrid< ct, dim, Ref, Comm > >
195 ::DGFGridFactory (
const std::string &filename, MPICommunicatorType comm )
197 std::ifstream input( filename.c_str() );
199 DUNE_THROW( DGFException,
"Unable to open file: " << filename <<
"." );
200 generate( input, SPCommunicationTraits< Comm >::comm( comm ) );
205 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
207 DGFGridFactory< SPGrid< ct, dim, Ref, Comm > >
208 ::generate ( std::istream &input,
const Communication &comm )
210 dgf::IntervalBlock intervalBlock( input );
212 if( !intervalBlock.isactive() )
213 DUNE_THROW( DGFException,
"DGF stream must contain an interval block to be used with SPGrid< ct, " << dim <<
" >." );
214 if( intervalBlock.numIntervals() != 1 )
215 DUNE_THROW( DGFException,
"SPGrid< ct, " << dim <<
" > can only handle 1 interval block." );
217 if( intervalBlock.dimw() != dim )
218 DUNE_THROW( DGFException,
"SPGrid< ct, " << dim <<
" cannot handle an interval of dimension " << intervalBlock.dimw() <<
"." );
219 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
223 for(
int i = 0; i < dim; ++i )
225 a[ i ] = interval.p[ 0 ][ i ];
226 b[ i ] = interval.p[ 1 ][ i ];
227 cells[ i ] = interval.n[ i ];
230 typedef dgf::PeriodicFaceTransformationBlock::AffineTransformation Transformation;
231 dgf::PeriodicFaceTransformationBlock trafoBlock( input, dim );
235 const int numTrafos = trafoBlock.numTransformations();
236 for(
int k = 0; k < numTrafos; ++k )
238 const Transformation &trafo = trafoBlock.transformation( k );
240 bool identity =
true;
241 for(
int i = 0; i < dim; ++i )
242 for(
int j = 0; j < dim; ++j )
243 identity &= (fabs( (i == j ? 1.0 : 0.0) - trafo.matrix( i, j ) ) < 1e-10);
245 DUNE_THROW( DGFException,
"SPGrid< ct, " << dim <<
" > can only handle shifts as periodic face transformations." );
249 for(
int i = 0; i < dim; ++i )
251 if( fabs( trafo.shift[ i ] ) < 1e-10 )
256 const ct shift = fabs( trafo.shift[ dir ] );
257 const ct width = fabs( a[ dir ] - b[ dir ] );
258 if( (numDirs != 1) || (fabs( shift - width ) >= 1e-10) )
260 std::cerr <<
"Tranformation '" << trafo
261 <<
"' does not map boundaries on boundaries." << std::endl;
267 dgf::SPGridParameterBlock< dim > parameter( input );
269 typedef typename Grid::Domain Domain;
270 std::vector< typename Domain::Cube > cubes;
271 cubes.push_back(
typename Domain::Cube( a, b ) );
272 Domain domain( cubes,
typename Domain::Topology(
periodic ) );
273 grid_ =
new Grid( domain, cells, parameter.overlap(), comm );
275 boundaryDomainBlock_ =
new BoundaryDomainBlock( input, dimension );
283 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
284 struct DGFGridInfo< SPGrid< ct, dim, Ref, Comm > >
286 typedef SPGrid< ct, dim, Ref, Comm > Grid;
287 typedef typename Grid::RefinementPolicy RefinementPolicy;
289 static int refineStepsForHalf (
const RefinementPolicy &policy = RefinementPolicy() )
291 const unsigned int weight = policy.weight();
292 return (dim + weight - 1) / weight;
295 static double refineWeight (
const RefinementPolicy &policy = RefinementPolicy() )
297 return 1.0 / double( 1 << policy.weight() );
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto periodic(RawPreBasisIndicator &&rawPreBasisIndicator, PIS &&periodicIndexSet)
Create a pre-basis factory that can create a periodic pre-basis.
Definition: periodicbasis.hh:191
DWarnType dwarn(std::cerr)
Stream for warnings indicating problems.
Definition: stdstreams.hh:161
Dune namespace.
Definition: alignedallocator.hh:13