3#ifndef DUNE_DGFGEOGRID_HH
4#define DUNE_DGFGEOGRID_HH
8#include <dune/grid/geometrygrid.hh>
9#include <dune/grid/io/file/dgfparser/dgfparser.hh>
10#include <dune/grid/io/file/dgfparser/blocks/projection.hh>
11#include <dune/grid/utility/hostgridaccess.hh>
12#include <dune/grid/common/intersection.hh>
14#include <dune/grid/io/file/dgfparser/parser.hh>
32 template<
class Gr
idImp,
class IntersectionImp >
40 template<
int dimD,
int dimR >
41 class DGFCoordFunction
42 :
public AnalyticalCoordFunction< double, dimD, dimR, DGFCoordFunction< dimD, dimR > >
44 typedef DGFCoordFunction< dimD, dimR > This;
45 typedef AnalyticalCoordFunction< double, dimD, dimR, This > Base;
48 typedef typename Base::DomainVector DomainVector;
49 typedef typename Base::RangeVector RangeVector;
51 typedef dgf::ProjectionBlock::Expression Expression;
53 DGFCoordFunction (
const Expression *expression )
54 : expression_( expression )
57 void evaluate (
const DomainVector &x, RangeVector &y )
const
59 std::vector< double > vx( dimD );
60 std::vector< double > vy;
61 for(
int i = 0; i < dimD; ++i )
63 expression_->evaluate( vx, vy );
64 assert( vy.size() ==
size_t( dimR ) );
65 for(
int i = 0; i < dimR; ++i )
70 const Expression *expression_;
78 template<
class HostGrid,
class CoordFunction,
79 bool discrete = GeoGrid::isDiscreteCoordFunctionInterface< typename CoordFunction::Interface >::value >
80 struct DGFCoordFunctionFactory;
83 template<
class HostGr
id,
class CoordFunction >
84 struct DGFCoordFunctionFactory< HostGrid, CoordFunction, false >
86 static CoordFunction *create ( std::istream &input,
const HostGrid &hostGrid )
88 return new CoordFunction;
93 template<
class HostGr
id,
class CoordFunction >
94 struct DGFCoordFunctionFactory< HostGrid, CoordFunction, true >
96 static CoordFunction *create ( std::istream &input,
const HostGrid &hostGrid )
98 return new CoordFunction( hostGrid );
103 template<
class HostGr
id,
int dimD,
int dimR >
104 struct DGFCoordFunctionFactory< HostGrid, DGFCoordFunction< dimD, dimR >, false >
106 typedef DGFCoordFunction< dimD, dimR > CoordFunction;
108 static CoordFunction *create ( std::istream &input,
const HostGrid &hostGrid )
110 dgf::ProjectionBlock projectionBlock( input, dimR );
111 const typename CoordFunction::Expression *expression = projectionBlock.function(
"coordfunction" );
112 if( expression == 0 )
113 DUNE_THROW( DGFException,
"no coordfunction specified in DGF file." );
114 return new CoordFunction( expression );
123 template<
class HostGr
id,
class CoordFunction,
class Allocator >
124 struct DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >
126 typedef GeometryGrid< HostGrid, CoordFunction, Allocator > Grid;
130 typedef typename Grid::template Codim<0>::Entity Element;
131 typedef typename Grid::template Codim<dimension>::Entity Vertex;
133 typedef DGFCoordFunctionFactory< HostGrid, CoordFunction > CoordFunctionFactory;
135 explicit DGFGridFactory ( std::istream &input,
137 : dgfHostFactory_( input, comm ),
140 HostGrid *hostGrid = dgfHostFactory_.grid();
141 assert( hostGrid != 0 );
142 CoordFunction *coordFunction = CoordFunctionFactory::create( input, *hostGrid );
143 grid_ =
new Grid( hostGrid, coordFunction );
146 explicit DGFGridFactory (
const std::string &filename,
148 : dgfHostFactory_( filename, comm ),
151 HostGrid *hostGrid = dgfHostFactory_.grid();
152 assert( hostGrid != 0 );
153 std::ifstream input( filename.c_str() );
154 CoordFunction *coordFunction = CoordFunctionFactory::create( input, *hostGrid );
155 grid_ =
new Grid( hostGrid, coordFunction );
163 template<
class Intersection >
164 bool wasInserted (
const Intersection &intersection )
const
166 return dgfHostFactory_.wasInserted( HostGridAccess< Grid >::hostIntersection( intersection ) );
169 template<
class Intersection >
170 int boundaryId (
const Intersection &intersection )
const
172 return dgfHostFactory_.boundaryId( HostGridAccess< Grid >::hostIntersection( intersection ) );
175 template<
int codim >
176 int numParameters ()
const
178 return dgfHostFactory_.template numParameters< codim >();
182 bool haveBoundaryParameters ()
const
184 return dgfHostFactory_.haveBoundaryParameters();
187 template<
class GG,
class II >
191 return dgfHostFactory_.boundaryParameter( HostGridAccess< Grid >::hostIntersection( intersection ) );
194 template<
class Entity >
195 std::vector< double > ¶meter (
const Entity &entity )
197 return dgfHostFactory_.parameter( HostGridAccess< Grid >::hostEntity( entity ) );
201 DGFGridFactory< HostGrid > dgfHostFactory_;
210 template<
class HostGr
id,
class CoordFunction,
class Allocator >
211 struct DGFGridInfo< GeometryGrid< HostGrid, CoordFunction, Allocator > >
@ dimension
The dimension of the grid.
Definition: grid.hh:400
Intersection of a mesh entities of codimension 0 ("elements") with a "neighboring" element or with th...
Definition: intersection.hh:161
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:174
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:182
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
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
Traits for type conversions and type information.