dune-grid  2.4.1
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 >
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,
79  bool discrete = GeoGrid::isDiscreteCoordFunctionInterface< typename CoordFunction::Interface >::value >
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
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
Intersection of a mesh entities of codimension 0 ("elements") with a "neighboring" element or with th...
Definition: albertagrid/dgfparser.hh:26
DGFCoordFunction(const Expression *expression)
Definition: dgfgeogrid.hh:53
Definition: io/file/dgfparser/blocks/projection.hh:20
static CoordFunction * create(std::istream &input, const HostGrid &hostGrid)
Definition: dgfgeogrid.hh:86
DGFGridFactory(const std::string &filename, MPICommunicator comm=MPIHelper::getCommunicator())
Definition: dgfgeogrid.hh:146
Definition: io/file/dgfparser/blocks/projection.hh:131
Wrapper class for entities.
Definition: common/entity.hh:61
const Expression * function(const std::string &name) const
Definition: io/file/dgfparser/blocks/projection.hh:90
GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: dgfgeogrid.hh:126
static const int dimension
Definition: dgfgridfactory.hh:38
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: geometrygrid/declaration.hh:10
Definition: dgfgeogrid.hh:80
DGFCoordFunctionFactory< HostGrid, CoordFunction > CoordFunctionFactory
Definition: dgfgeogrid.hh:133
const DGFBoundaryParameter::type & boundaryParameter(const Dune::Intersection< GG, II > &intersection) const
Definition: dgfgeogrid.hh:189
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:15
Base::RangeVector RangeVector
Definition: coordfunction.hh:103
virtual void evaluate(const Vector &argument, Vector &result) const =0
Base::DomainVector DomainVector
Definition: coordfunction.hh:102
static CoordFunction * create(std::istream &input, const HostGrid &hostGrid)
Definition: dgfgeogrid.hh:96
Definition: agrid.hh:66
bool wasInserted(const Intersection &intersection) const
Definition: dgfgeogrid.hh:164
std::vector< double > & parameter(const Entity &entity)
Definition: dgfgeogrid.hh:195
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
Some simple static information for a given GridType.
Definition: io/file/dgfparser/dgfparser.hh:54
G Grid
Definition: dgfgridfactory.hh:37
Base::DomainVector DomainVector
Definition: dgfgeogrid.hh:48
Definition: dgfgeogrid.hh:41
DGFGridFactory(std::istream &input, MPICommunicator comm=MPIHelper::getCommunicator())
Definition: dgfgeogrid.hh:135
void evaluate(const DomainVector &x, RangeVector &y) const
Definition: dgfgeogrid.hh:57
std::string type
type of additional boundary parameters
Definition: parser.hh:23
static CoordFunction * create(std::istream &input, const HostGrid &hostGrid)
Definition: dgfgeogrid.hh:108
DGFCoordFunction< dimD, dimR > CoordFunction
Definition: dgfgeogrid.hh:106
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
The dimension of the grid.
Definition: common/grid.hh:402
int boundaryId(const Intersection &intersection) const
Definition: dgfgeogrid.hh:170
Grid::template Codim< dimension >::Entity Vertex
Definition: dgfgeogrid.hh:131
dgf::ProjectionBlock::Expression Expression
Definition: dgfgeogrid.hh:51
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:12
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
MPIHelper::MPICommunicator MPICommunicator
Definition: dgfgeogrid.hh:129
static double refineWeight()
Definition: dgfgeogrid.hh:218
Grid::template Codim< 0 >::Entity Element
Definition: dgfgeogrid.hh:130
Base::RangeVector RangeVector
Definition: dgfgeogrid.hh:49