Dune Core Modules (2.6.0)

dgfgeogrid.hh
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
7
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>
13
14#include <dune/grid/io/file/dgfparser/parser.hh>
15
16
17namespace 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 {
44 typedef DGFCoordFunction< dimD, dimR > This;
45 typedef AnalyticalCoordFunction< double, dimD, dimR, This > Base;
46
47 public:
48 typedef typename Base::DomainVector DomainVector;
49 typedef typename Base::RangeVector RangeVector;
50
51 typedef dgf::ProjectionBlock::Expression Expression;
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 >
80 struct DGFCoordFunctionFactory;
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 {
106 typedef DGFCoordFunction< dimD, dimR > CoordFunction;
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 {
126 typedef GeometryGrid< HostGrid, CoordFunction, Allocator > Grid;
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
133 typedef DGFCoordFunctionFactory< HostGrid, CoordFunction > CoordFunctionFactory;
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
@ 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:162
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:178
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:186
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
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.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)