5#ifndef DUNE_DGFGEOGRID_HH
6#define DUNE_DGFGEOGRID_HH
10#include <dune/grid/geometrygrid.hh>
11#include <dune/grid/io/file/dgfparser/dgfparser.hh>
12#include <dune/grid/io/file/dgfparser/blocks/projection.hh>
13#include <dune/grid/utility/hostgridaccess.hh>
14#include <dune/grid/common/intersection.hh>
16#include <dune/grid/io/file/dgfparser/parser.hh>
34 template<
class Gr
idImp,
class IntersectionImp >
42 template<
int dimD,
int dimR >
43 class DGFCoordFunction
44 :
public AnalyticalCoordFunction< double, dimD, dimR, DGFCoordFunction< dimD, dimR > >
46 typedef DGFCoordFunction< dimD, dimR > This;
47 typedef AnalyticalCoordFunction< double, dimD, dimR, This > Base;
50 typedef typename Base::DomainVector DomainVector;
51 typedef typename Base::RangeVector RangeVector;
53 typedef dgf::ProjectionBlock::Expression Expression;
55 DGFCoordFunction (
const Expression *expression )
56 : expression_( expression )
59 void evaluate (
const DomainVector &x, RangeVector &y )
const
61 std::vector< double > vx( dimD );
62 std::vector< double > vy;
63 for(
int i = 0; i < dimD; ++i )
65 expression_->evaluate( vx, vy );
66 assert( vy.size() ==
size_t( dimR ) );
67 for(
int i = 0; i < dimR; ++i )
72 const Expression *expression_;
80 template<
class HostGrid,
class CoordFunction,
81 bool discrete = GeoGrid::isDiscreteCoordFunctionInterface< typename CoordFunction::Interface >::value >
82 struct DGFCoordFunctionFactory;
85 template<
class HostGr
id,
class CoordFunction >
86 struct DGFCoordFunctionFactory< HostGrid, CoordFunction, false >
88 static CoordFunction *create ( std::istream &,
const HostGrid & )
90 return new CoordFunction;
95 template<
class HostGr
id,
class CoordFunction >
96 struct DGFCoordFunctionFactory< HostGrid, CoordFunction, true >
98 static CoordFunction *create ( std::istream &,
const HostGrid &hostGrid )
100 return new CoordFunction( hostGrid );
105 template<
class HostGr
id,
int dimD,
int dimR >
106 struct DGFCoordFunctionFactory< HostGrid, DGFCoordFunction< dimD, dimR >, false >
108 typedef DGFCoordFunction< dimD, dimR > CoordFunction;
110 static CoordFunction *create ( std::istream &input,
const HostGrid &hostGrid )
112 dgf::ProjectionBlock projectionBlock( input, dimR );
113 const typename CoordFunction::Expression *expression = projectionBlock.function(
"coordfunction" );
114 if( expression == 0 )
115 DUNE_THROW( DGFException,
"no coordfunction specified in DGF file." );
116 return new CoordFunction( expression );
125 template<
class HostGr
id,
class CoordFunction,
class Allocator >
126 struct DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >
128 typedef GeometryGrid< HostGrid, CoordFunction, Allocator > Grid;
132 typedef typename Grid::template Codim<0>::Entity Element;
133 typedef typename Grid::template Codim<dimension>::Entity Vertex;
135 typedef DGFCoordFunctionFactory< HostGrid, CoordFunction > CoordFunctionFactory;
137 explicit DGFGridFactory ( std::istream &input,
139 : dgfHostFactory_( input, comm ),
142 auto hostGrid = std::shared_ptr<HostGrid>(dgfHostFactory_.grid());
143 assert( hostGrid != 0 );
144 auto coordFunction = std::shared_ptr<CoordFunction>(CoordFunctionFactory::create( input, *hostGrid ));
145 grid_ =
new Grid( hostGrid, coordFunction );
148 explicit DGFGridFactory (
const std::string &filename,
150 : dgfHostFactory_( filename, comm ),
153 auto hostGrid = std::shared_ptr<HostGrid>(dgfHostFactory_.grid());
154 assert( hostGrid != 0 );
155 std::ifstream input( filename.c_str() );
156 auto coordFunction = std::shared_ptr<CoordFunction>(CoordFunctionFactory::create( input, *hostGrid ));
157 grid_ =
new Grid( hostGrid, coordFunction );
165 template<
class Intersection >
166 bool wasInserted (
const Intersection &intersection )
const
168 return dgfHostFactory_.wasInserted( HostGridAccess< Grid >::hostIntersection( intersection ) );
171 template<
class Intersection >
172 int boundaryId (
const Intersection &intersection )
const
174 return dgfHostFactory_.boundaryId( HostGridAccess< Grid >::hostIntersection( intersection ) );
177 template<
int codim >
178 int numParameters ()
const
180 return dgfHostFactory_.template numParameters< codim >();
184 bool haveBoundaryParameters ()
const
186 return dgfHostFactory_.haveBoundaryParameters();
189 template<
class GG,
class II >
193 return dgfHostFactory_.boundaryParameter( HostGridAccess< Grid >::hostIntersection( intersection ) );
196 template<
class Entity >
197 std::vector< double > ¶meter (
const Entity &entity )
199 return dgfHostFactory_.parameter( HostGridAccess< Grid >::hostEntity( entity ) );
203 DGFGridFactory< HostGrid > dgfHostFactory_;
212 template<
class HostGr
id,
class CoordFunction,
class Allocator >
213 struct DGFGridInfo< GeometryGrid< HostGrid, CoordFunction, Allocator > >
static constexpr int 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:164
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:192
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:200
#define DUNE_THROW(E,...)
Definition: exceptions.hh:312
Dune namespace.
Definition: alignedallocator.hh:13
std::string type
type of additional boundary parameters
Definition: parser.hh:25
static double refineWeight()
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
Traits for type conversions and type information.