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