dune-grid  3.0-git
dgfgeogrid.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DGFGEOGRID_HH
4 #define DUNE_DGFGEOGRID_HH
5 
6 #include <dune/common/typetraits.hh>
7 
13 
15 
16 
17 namespace Dune
18 {
19 
20  /************************************************************************
21  * Warning:
22  * Reading DGF files directly into a GeometryGrid is a dirty hack for
23  * two reasons:
24  * 1) The host grid and coordinate function are never deleted (dangling
25  * pointers).
26  * 2) The coordinate function has to provide a default constructor
27  ************************************************************************/
28 
29  // External Forward Declarations
30  // -----------------------------
31 
32  template< class GridImp, class IntersectionImp >
33  class Intersection;
34 
35 
36 
37  // DGFCoordFunction
38  // ----------------
39 
40  template< int dimD, int dimR >
41  class DGFCoordFunction
42  : public AnalyticalCoordFunction< double, dimD, dimR, DGFCoordFunction< dimD, dimR > >
43  {
46 
47  public:
48  typedef typename Base::DomainVector DomainVector;
49  typedef typename Base::RangeVector RangeVector;
50 
52 
53  DGFCoordFunction ( const Expression *expression )
54  : expression_( expression )
55  {}
56 
57  void evaluate ( const DomainVector &x, RangeVector &y ) const
58  {
59  std::vector< double > vx( dimD );
60  std::vector< double > vy;
61  for( int i = 0; i < dimD; ++i )
62  vx[ i ] = x[ i ];
63  expression_->evaluate( vx, vy );
64  assert( vy.size() == size_t( dimR ) );
65  for( int i = 0; i < dimR; ++i )
66  y[ i ] = vy[ i ];
67  }
68 
69  private:
70  const Expression *expression_;
71  };
72 
73 
74 
75  // DGFCoordFunctionFactory
76  // -----------------------
77 
78  template< class HostGrid, class CoordFunction,
81 
82 
83  template< class HostGrid, class CoordFunction >
84  struct DGFCoordFunctionFactory< HostGrid, CoordFunction, false >
85  {
86  static CoordFunction *create ( std::istream &input, const HostGrid &hostGrid )
87  {
88  return new CoordFunction;
89  }
90  };
91 
92 
93  template< class HostGrid, class CoordFunction >
94  struct DGFCoordFunctionFactory< HostGrid, CoordFunction, true >
95  {
96  static CoordFunction *create ( std::istream &input, const HostGrid &hostGrid )
97  {
98  return new CoordFunction( hostGrid );
99  }
100  };
101 
102 
103  template< class HostGrid, int dimD, int dimR >
104  struct DGFCoordFunctionFactory< HostGrid, DGFCoordFunction< dimD, dimR >, false >
105  {
107 
108  static CoordFunction *create ( std::istream &input, const HostGrid &hostGrid )
109  {
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 );
115  }
116  };
117 
118 
119 
120  // DGFGridFactory for GeometryGrid
121  // -------------------------------
122 
123  template< class HostGrid, class CoordFunction, class Allocator >
124  struct DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >
125  {
127 
128  const static int dimension = Grid::dimension;
129  typedef MPIHelper::MPICommunicator MPICommunicator;
130  typedef typename Grid::template Codim<0>::Entity Element;
131  typedef typename Grid::template Codim<dimension>::Entity Vertex;
132 
134 
135  explicit DGFGridFactory ( std::istream &input,
136  MPICommunicator comm = MPIHelper::getCommunicator() )
137  : dgfHostFactory_( input, comm ),
138  grid_( 0 )
139  {
140  HostGrid *hostGrid = dgfHostFactory_.grid();
141  assert( hostGrid != 0 );
142  CoordFunction *coordFunction = CoordFunctionFactory::create( input, *hostGrid );
143  grid_ = new Grid( hostGrid, coordFunction );
144  }
145 
146  explicit DGFGridFactory ( const std::string &filename,
147  MPICommunicator comm = MPIHelper::getCommunicator() )
148  : dgfHostFactory_( filename, comm ),
149  grid_( 0 )
150  {
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 );
156  }
157 
158  Grid *grid () const
159  {
160  return grid_;
161  }
162 
163  template< class Intersection >
164  bool wasInserted ( const Intersection &intersection ) const
165  {
166  return dgfHostFactory_.wasInserted( HostGridAccess< Grid >::hostIntersection( intersection ) );
167  }
168 
169  template< class Intersection >
170  int boundaryId ( const Intersection &intersection ) const
171  {
172  return dgfHostFactory_.boundaryId( HostGridAccess< Grid >::hostIntersection( intersection ) );
173  }
174 
175  template< int codim >
176  int numParameters () const
177  {
178  return dgfHostFactory_.template numParameters< codim >();
179  }
180 
181  // return true if boundary parameters found
182  bool haveBoundaryParameters () const
183  {
184  return dgfHostFactory_.haveBoundaryParameters();
185  }
186 
187  template< class GG, class II >
188  const typename DGFBoundaryParameter::type &
189  boundaryParameter ( const Dune::Intersection< GG, II > & intersection ) const
190  {
191  return dgfHostFactory_.boundaryParameter( HostGridAccess< Grid >::hostIntersection( intersection ) );
192  }
193 
194  template< class Entity >
195  std::vector< double > &parameter ( const Entity &entity )
196  {
197  return dgfHostFactory_.parameter( HostGridAccess< Grid >::hostEntity( entity ) );
198  }
199 
200  private:
201  DGFGridFactory< HostGrid > dgfHostFactory_;
202  Grid *grid_;
203  };
204 
205 
206 
207  // DGFGridInfo for GeometryGrid
208  // ----------------------------
209 
210  template< class HostGrid, class CoordFunction, class Allocator >
211  struct DGFGridInfo< GeometryGrid< HostGrid, CoordFunction, Allocator > >
212  {
213  static int refineStepsForHalf ()
214  {
216  }
217 
218  static double refineWeight ()
219  {
220  return -1.0;
221  }
222  };
223 
224 }
225 
226 #endif // #ifndef DUNE_DGFGEOGRID_HH
Dune::DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >::MPICommunicator
MPIHelper::MPICommunicator MPICommunicator
Definition: dgfgeogrid.hh:128
Dune::DGFGridInfo::refineWeight
static double refineWeight()
Dune::Intersection
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: albertagrid/dgfparser.hh:26
Dune::DGFGridInfo::refineStepsForHalf
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
Dune
Include standard header files.
Definition: agrid.hh:59
Dune::HostGridAccess
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
Dune::DGFCoordFunction::DomainVector
Base::DomainVector DomainVector
Definition: dgfgeogrid.hh:47
Dune::DGFGridFactory::numParameters
int numParameters() const
Definition: dgfgridfactory.hh:113
Dune::DGFBoundaryParameter::type
std::string type
type of additional boundary parameters
Definition: parser.hh:23
Dune::dgf::ProjectionBlock::Expression::evaluate
virtual void evaluate(const Vector &argument, Vector &result) const =0
hostgridaccess.hh
Dune::DGFGridInfo
Some simple static information for a given GridType.
Definition: io/file/dgfparser/dgfparser.hh:54
Dune::DGFGridFactory::grid
Grid * grid()
Definition: dgfgridfactory.hh:95
Dune::Entity
Wrapper class for entities.
Definition: common/entity.hh:61
Dune::DGFGridFactory::DGFGridFactory
DGFGridFactory(std::istream &input, MPICommunicatorType comm=MPIHelper::getCommunicator())
Definition: dgfgridfactory.hh:47
Dune::dgf::ProjectionBlock::function
const Expression * function(const std::string &name) const
Definition: io/file/dgfparser/blocks/projection.hh:90
dgfparser.hh
Dune::DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >::Element
Grid::template Codim< 0 >::Entity Element
Definition: dgfgeogrid.hh:129
Dune::DGFGridFactory::parameter
std::vector< double > & parameter(const Element &element)
Definition: dgfgridfactory.hh:129
projection.hh
Dune::Grid
Grid abstract base class.
Definition: common/grid.hh:373
Dune::DGFGridFactory::boundaryId
int boundaryId(const Intersection &intersection) const
Definition: dgfgridfactory.hh:107
Dune::AnalyticalCoordFunction::DomainVector
Base ::DomainVector DomainVector
Definition: coordfunction.hh:103
Dune::dgf::ProjectionBlock
Definition: io/file/dgfparser/blocks/projection.hh:20
Dune::GeoGrid::isDiscreteCoordFunctionInterface
Definition: coordfunction.hh:267
Dune::DGFCoordFunction::Expression
dgf::ProjectionBlock::Expression Expression
Definition: dgfgeogrid.hh:50
Dune::DGFGridFactory::boundaryParameter
const DGFBoundaryParameter::type & boundaryParameter(const Intersection< GG, II > &intersection) const
Definition: dgfgridfactory.hh:163
Dune::DGFCoordFunction::DGFCoordFunction
DGFCoordFunction(const Expression *expression)
Definition: dgfgeogrid.hh:52
Dune::Grid::dimension
The dimension of the grid.
Definition: common/grid.hh:387
Dune::DGFCoordFunctionFactory
Definition: dgfgeogrid.hh:79
Dune::DGFGridFactory::haveBoundaryParameters
bool haveBoundaryParameters() const
Definition: dgfgridfactory.hh:156
Dune::DGFGridFactory
Definition: agrid.hh:66
Dune::DGFGridFactory::Grid
G Grid
Definition: dgfgridfactory.hh:37
Dune::DGFGridFactory< GeometryGrid< HostGrid, CoordFunction, Allocator > >::Vertex
Grid::template Codim< dimension >::Entity Vertex
Definition: dgfgeogrid.hh:130
Dune::DGFException
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:12
Dune::DGFGridFactory::wasInserted
bool wasInserted(const Intersection &intersection) const
Definition: dgfgridfactory.hh:101
parser.hh
Dune::DGFCoordFunction
Definition: dgfgeogrid.hh:40
Dune::DGFCoordFunction::RangeVector
Base::RangeVector RangeVector
Definition: dgfgeogrid.hh:48
Dune::DGFCoordFunction::evaluate
void evaluate(const DomainVector &x, RangeVector &y) const
Definition: dgfgeogrid.hh:56
Dune::AnalyticalCoordFunction
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:15
Dune::DGFGridFactory::dimension
const static int dimension
Definition: dgfgridfactory.hh:38
Dune::AnalyticalCoordFunction::RangeVector
Base ::RangeVector RangeVector
Definition: coordfunction.hh:104
Dune::dgf::ProjectionBlock::Expression
Definition: io/file/dgfparser/blocks/projection.hh:131
geometrygrid.hh
intersection.hh
Dune::GeometryGrid
grid wrapper replacing the geometries
Definition: declaration.hh:10