1#ifndef DUNE_FEM_GRIDSOLUTION_HH
2#define DUNE_FEM_GRIDSOLUTION_HH
8#include <dune/fem/function/localfunction/const.hh>
9#include <dune/fem/io/file/datawriter.hh>
10#include <dune/fem/quadrature/cachingquadrature.hh>
13#include <dune/grid/spgrid.hh>
31 template <
class Gr
idImp,
class DiscreteFunctionImp >
35 typedef GridImp GridType;
36 typedef DiscreteFunctionImp DiscreteFunctionType;
38 typedef typename DiscreteFunctionSpaceType :: RangeType RangeType ;
39 typedef typename DiscreteFunctionSpaceType :: DomainType DomainType ;
40 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType ;
41 typedef typename GridPartType :: IndexSetType IndexSetType;
44 typedef typename GridType :: template
Codim<0> :: Entity EntityType;
48 typedef std::tuple< DiscreteFunctionType* > IOTupleType;
53 GridPartType gridPart_;
54 DiscreteFunctionSpaceType space_;
55 DiscreteFunctionType discreteFunction_;
56 ConstLocalFunction< DiscreteFunctionType > lf_;
61 GridType& grid() { assert( grid_ );
return *grid_ ; }
62 const GridType& grid()
const { assert( grid_ );
return *grid_ ; }
66 const int rank = -1 ) :
71 discreteFunction_(
"grid-sol", space_),
72 lf_( discreteFunction_ ),
73 data_( &discreteFunction_ ),
74 hierarchicSearch_( grid(), gridPart_.indexSet() )
80 CheckPointerType :: restoreData( grid(), data_, checkPointFile, rank );
90 void evaluate(
const DomainType& x,
const double time, RangeType& result)
const
101 void evaluate(
const DomainType& x, RangeType& result)
const
104 EntityType entity = hierarchicSearch_.
findEntity( x );
106 typedef typename EntityType :: Geometry
Geometry;
107 const Geometry& geo = entity.geometry();
109 const DomainType local = geo.local( x );
115 assert( refElement.checkInside( local ) );
121 lf_.evaluate( local, result );
127 const DiscreteFunctionType& discreteFunction,
129 const int writeStep )
152 template <
class Gr
idImp,
class DiscreteFunctionImp >
153 class GridSolutionVector
156 typedef GridImp GridType;
160 typedef typename DiscreteFunctionSpaceType :: FunctionSpaceType
FunctionSpaceType;
161 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
167 typedef GridSolution< GridType, DiscreteFunctionType > GridSolutionType ;
170 template <
class DomainType,
class Gr
id>
173 static bool isInside(
const DomainType& x,
const Grid& grid )
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 )
183 const Entity& entity = * it ;
188 const Geometry& geo = entity.geometry();
190 if( refElement.checkInside( geo.local( geo.center() ) ) )
198 template <
class DomainType,
class ct,
int dim,
template<
int >
class Strategy ,
class Comm>
199 struct CheckDomain< DomainType, SPGrid< ct, dim, Strategy, Comm > >
201 typedef SPGrid< ct, dim, Strategy, Comm > Grid;
202 static bool isInside(
const DomainType& x,
const Grid& grid )
204 return grid.domain().contains( x );
210 std::vector< GridSolutionType* > solutions_;
212 int numProcs(
const std::string& checkPointFile)
const
214 int numProc = MPIManager :: size();
220 explicit GridSolutionVector(
const std::string checkPointFile) :
221 numProcs_( numProcs( checkPointFile ) ),
222 solutions_( numProcs_, (GridSolutionType *) 0 )
224 for(
int p=0; p<numProcs_; ++p)
227 std::cout <<
"GridSolutionVector: Reading Grid " << p <<
" from checkpoint" << std::endl;
228 solutions_[ p ] =
new GridSolutionType( checkPointFile, p );
232 ~GridSolutionVector()
234 for(
int p=0; p<numProcs_; ++p)
236 delete solutions_[ p ];
248 void evaluate(
const DomainType& x,
const double time, RangeType& result)
const
250 evaluate(x, result );
259 void evaluate(
const DomainType& x, RangeType& result)
const
261 for(
int p=0; p<numProcs_; ++p)
263 assert( solutions_[ p ] );
264 const GridSolutionType& gridSolution = *(solutions_[ p ]);
265 if( isInDomain( x, gridSolution.grid() ) )
268 gridSolution.evaluate( x, result );
273 std::cerr <<
"GridSolutionVector::evaluate: no grid found for point " << x << std::endl;
278 bool isInDomain(
const DomainType& x,
const GridType& grid )
const
280 return CheckDomain<DomainType, GridType> :: isInside( x, grid );
284 static void writeDiscreteFunction(
const GridType& grid,
287 const int writeStep = 0 )
294 assert( rank < numProcs_ );
295 return solutions_[ rank ]->discreteFunction();
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