DUNE-FEM (unstable)

gridsolution.hh
1#ifndef DUNE_FEM_GRIDSOLUTION_HH
2#define DUNE_FEM_GRIDSOLUTION_HH
3
4#include <tuple>
5
8#include <dune/fem/function/localfunction/const.hh>
9#include <dune/fem/io/file/datawriter.hh>
10#include <dune/fem/quadrature/cachingquadrature.hh>
11
12#if HAVE_DUNE_SPGRID
13#include <dune/grid/spgrid.hh>
14#endif
15
16namespace Dune
17{
18
19 namespace Fem
20 {
21
22 // GridSolution
23 //-------------
24
31 template <class GridImp, class DiscreteFunctionImp >
33 {
34 public:
35 typedef GridImp GridType;
36 typedef DiscreteFunctionImp DiscreteFunctionType;
37 typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
38 typedef typename DiscreteFunctionSpaceType :: RangeType RangeType ;
39 typedef typename DiscreteFunctionSpaceType :: DomainType DomainType ;
40 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType ;
41 typedef typename GridPartType :: IndexSetType IndexSetType;
43
44 typedef typename GridType :: template Codim<0> :: Entity EntityType;
45
47
48 typedef std::tuple< DiscreteFunctionType* > IOTupleType;
49
50 protected:
51 GridType* grid_;
52 GridPtr< GridType > gridPtr_;
53 GridPartType gridPart_;
54 DiscreteFunctionSpaceType space_;
55 DiscreteFunctionType discreteFunction_;
56 ConstLocalFunction< DiscreteFunctionType > lf_;
57 IOTupleType data_;
58 HierarchicSearchType hierarchicSearch_;
59
60 public:
61 GridType& grid() { assert( grid_ ); return *grid_ ; }
62 const GridType& grid() const { assert( grid_ ); return *grid_ ; }
63
65 explicit GridSolution(const std::string checkPointFile,
66 const int rank = -1 ) :
67 grid_( CheckPointerType :: restoreGrid( checkPointFile, rank ) ),
68 gridPtr_(),
69 gridPart_( grid() ),
70 space_( gridPart_ ),
71 discreteFunction_("grid-sol", space_),
72 lf_( discreteFunction_ ),
73 data_( &discreteFunction_ ),
74 hierarchicSearch_( grid(), gridPart_.indexSet() )
75 {
76 // store grid pointer
77 gridPtr_ = grid_;
78 DUNE_THROW(NotImplemented," GridSolution needs to be switched to DataWriter");
79 // restore data from checkpoint
80 CheckPointerType :: restoreData( grid(), data_, checkPointFile, rank );
81 }
82
90 void evaluate(const DomainType& x, const double time, RangeType& result) const
91 {
92 evaluate(x, result );
93 }
94
101 void evaluate(const DomainType& x, RangeType& result) const
102 {
103 // search entity
104 EntityType entity = hierarchicSearch_.findEntity( x );
105
106 typedef typename EntityType :: Geometry Geometry;
107 const Geometry& geo = entity.geometry();
108
109 const DomainType local = geo.local( x );
110#ifndef NDEBUG
111 {
112 // check that corners are within the reference element of the given type
114
115 assert( refElement.checkInside( local ) );
116 }
117#endif
118
119 // evaluate discrete function
120 lf_.bind( entity );
121 lf_.evaluate( local, result );
122 lf_.unbind();
123 }
124
126 static void writeDiscreteFunction(const GridType& grid,
127 const DiscreteFunctionType& discreteFunction,
128 const double time,
129 const int writeStep )
130 {
131 DUNE_THROW(NotImplemented," writeDiscreteFunction needs to be switched to DataWriter");
132 //typedef std::tuple< const DiscreteFunctionType* > OutputTuple;
133 //OutputTuple data( &discreteFunction );
134 // false means don't backup persistent objects
135 // CheckPointerType :: writeSingleCheckPoint( grid, data, time, false, writeStep );
136 }
137
138 const DiscreteFunctionType& discreteFunction() const { return discreteFunction_ ; }
139 };
140
142 //
143 //
144 //
146
152 template <class GridImp, class DiscreteFunctionImp >
153 class GridSolutionVector
154 {
155 public:
156 typedef GridImp GridType;
157 typedef DiscreteFunctionImp DiscreteFunctionType;
158
159 typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
160 typedef typename DiscreteFunctionSpaceType :: FunctionSpaceType FunctionSpaceType;
161 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
162 typedef typename FunctionSpaceType :: DomainType DomainType;
163 typedef typename FunctionSpaceType :: DomainFieldType DomainFieldType;
164 typedef typename FunctionSpaceType :: RangeType RangeType;
165 typedef typename FunctionSpaceType :: RangeFieldType RangeFieldType;
166
167 typedef GridSolution< GridType, DiscreteFunctionType > GridSolutionType ;
168
169 protected:
170 template <class DomainType, class Grid>
171 struct CheckDomain
172 {
173 static bool isInside(const DomainType& x, const Grid& grid )
174 {
175 abort();
176 typedef typename Grid :: LevelGridView MacroView ;
177 typedef typename MacroView :: template Codim< 0 > :: Iterator Iterator ;
178 typedef typename Iterator :: Entity Entity;
179 const MacroView& macroView = grid.levelGridView( 0 );
180 const Iterator end = macroView.template end< 0 > ();
181 for( Iterator it = macroView.template begin< 0 > (); it != end; ++it )
182 {
183 const Entity& entity = * it ;
184 // check that corners are within the reference element of the given type
186
187 typedef typename Entity :: Geometry Geometry;
188 const Geometry& geo = entity.geometry();
189
190 if( refElement.checkInside( geo.local( geo.center() ) ) )
191 return true ;
192 }
193 return false ;
194 }
195 };
196
197#if HAVE_DUNE_SPGRID
198 template <class DomainType, class ct, int dim, template< int > class Strategy , class Comm>
199 struct CheckDomain< DomainType, SPGrid< ct, dim, Strategy, Comm > >
200 {
201 typedef SPGrid< ct, dim, Strategy, Comm > Grid;
202 static bool isInside(const DomainType& x, const Grid& grid )
203 {
204 return grid.domain().contains( x );
205 }
206 };
207#endif
208
209 const int numProcs_;
210 std::vector< GridSolutionType* > solutions_;
211
212 int numProcs(const std::string& checkPointFile) const
213 {
214 int numProc = MPIManager :: size();
215 readParameter(checkPointFile, "NumberProcessors", numProc, Parameter::verbose () );
216 return numProc;
217 }
218 public:
220 explicit GridSolutionVector(const std::string checkPointFile) :
221 numProcs_( numProcs( checkPointFile ) ),
222 solutions_( numProcs_, (GridSolutionType *) 0 )
223 {
224 for(int p=0; p<numProcs_; ++p)
225 {
226 if( Parameter::verbose () )
227 std::cout << "GridSolutionVector: Reading Grid " << p << " from checkpoint" << std::endl;
228 solutions_[ p ] = new GridSolutionType( checkPointFile, p );
229 }
230 }
231
232 ~GridSolutionVector()
233 {
234 for(int p=0; p<numProcs_; ++p)
235 {
236 delete solutions_[ p ];
237 solutions_[ p ] = 0;
238 }
239 }
240
248 void evaluate(const DomainType& x, const double time, RangeType& result) const
249 {
250 evaluate(x, result );
251 }
252
259 void evaluate(const DomainType& x, RangeType& result) const
260 {
261 for(int p=0; p<numProcs_; ++p)
262 {
263 assert( solutions_[ p ] );
264 const GridSolutionType& gridSolution = *(solutions_[ p ]);
265 if( isInDomain( x, gridSolution.grid() ) )
266 {
267 //std::cout << "Found grid " << p << " for x = " << x << std::endl;
268 gridSolution.evaluate( x, result );
269 return ;
270 }
271 }
272
273 std::cerr << "GridSolutionVector::evaluate: no grid found for point " << x << std::endl;
274 assert( false );
275 abort();
276 }
277
278 bool isInDomain( const DomainType& x, const GridType& grid ) const
279 {
280 return CheckDomain<DomainType, GridType> :: isInside( x, grid );
281 }
282
284 static void writeDiscreteFunction(const GridType& grid,
285 const DiscreteFunctionType& discreteFunction,
286 const double time,
287 const int writeStep = 0 )
288 {
289 GridSolutionType :: writeDiscreteFunction( grid, discreteFunction, time, writeStep );
290 }
291
292 const DiscreteFunctionType& discreteFunction( const int rank ) const
293 {
294 assert( rank < numProcs_ );
295 return solutions_[ rank ]->discreteFunction();
296 }
297 };
298
299 } // namespace Fem
300
301} // namespace Dune
302
303#endif // #ifndef DUNE_FEM_GRIDSOLUTION_HH
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
Implementation of the IOInterface. This class manages checkpointing.
Definition: datawriter.hh:238
FunctionSpaceTraits::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
A vector valued function space.
Definition: functionspace.hh:60
creates a function with evaluate method from a check point
Definition: gridsolution.hh:33
void evaluate(const DomainType &x, RangeType &result) const
evaluates in a given space point
Definition: gridsolution.hh:101
void evaluate(const DomainType &x, const double time, RangeType &result) const
evaluates in a given space-time point
Definition: gridsolution.hh:90
GridSolution(const std::string checkPointFile, const int rank=-1)
Constructor.
Definition: gridsolution.hh:65
static void writeDiscreteFunction(const GridType &grid, const DiscreteFunctionType &discreteFunction, const double time, const int writeStep)
writes a discrete function
Definition: gridsolution.hh:126
static bool verbose()
obtain the cached value for fem.verbose with default verbosity level 2
Definition: parameter.hh:466
forward declaration
Definition: discretefunction.hh:51
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
Wrapper class for geometries.
Definition: geometry.hh:71
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:402
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:127
Default exception for dummy implementations.
Definition: exceptions.hh:263
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Utility class for hierarchically searching for an Entity containing a given point.
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Class for constructing grids from DGF files.
Definition: gridptr.hh:66
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)