dune-fem  2.4.1-rc
rannacherturek/space.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SPACE_RANNACHERTUREK_HH
2 #define DUNE_FEM_SPACE_RANNACHERTUREK_HH
3 
4 // ------------------------------------------------------------------------
5 // !!! RannacherTurekDiscreteFunctionSpace requires dune-localfunctions !!!
6 // ------------------------------------------------------------------------
7 #if HAVE_DUNE_LOCALFUNCTIONS
8 
9 // C++ includes
10 #include <cassert>
11 #include <vector>
12 
13 // dune-common includes
14 #include <dune/common/deprecated.hh>
15 
16 // dune-geometry types
17 #include <dune/geometry/type.hh>
18 
19 // dune-localfunctions includes
20 #include <dune/localfunctions/rannacherturek.hh>
21 
22 // dune-fem includes
33 
34 // local includes
39 
47 namespace Dune
48 {
49 
50  namespace Fem
51  {
52 
53  // RannacherTurekDiscreteFunctionSpaceTraits
54  // -----------------------------------------
55 
56  template< class FunctionSpace, class GridPart, template< class > class Storage >
57  struct RannacherTurekDiscreteFunctionSpaceTraits
58  {
60  "GridPart has more than one geometry type." );
61 
62  typedef RannacherTurekDiscreteFunctionSpace< FunctionSpace, GridPart, Storage > DiscreteFunctionSpaceType;
63 
64  typedef FunctionSpace FunctionSpaceType;
65  typedef GridPart GridPartType;
66 
67  static const int codimension = 0;
68 
69  private:
70  typedef typename GridPartType::template Codim< codimension >::EntityType EntityType;
71 
72  typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
73  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
74  static const int dimLocal = GridPartType::dimension;
75 
76  public:
77  typedef Dune::RannacherTurekLocalFiniteElement< DomainFieldType, RangeFieldType, dimLocal > LocalFiniteElementType;
78  typedef typename LocalFiniteElementType::Traits::LocalBasisType LocalBasisType;
79  typedef typename LocalFiniteElementType::Traits::LocalCoefficientsType LocalCoefficientsType;
80  typedef typename LocalFiniteElementType::Traits::LocalInterpolationType LocalInterpolationType;
81 
82  typedef RannacherTurekBlockMapperFactory< GridPartType, LocalCoefficientsType > BlockMapperFactoryType;
83  typedef typename BlockMapperFactoryType::BlockMapperType BlockMapperType;
84 
85  static const int localBlockSize = FunctionSpaceType::dimRange;
86 
87  typedef LocalFunctionsShapeFunctionSet< LocalBasisType > LocalFunctionsShapeFunctionSetType;
88  typedef SelectCachingShapeFunctionSet< LocalFunctionsShapeFunctionSetType, Storage > ScalarShapeFunctionSetType;
89 
90  struct ScalarShapeFunctionSetFactory
91  {
92  static ScalarShapeFunctionSetType *createObject ( const GeometryType &type )
93  {
94  assert( type.isCube() );
95  return new ScalarShapeFunctionSetType( type, LocalFunctionsShapeFunctionSetType( LocalBasisType() ) );
96  }
97 
98  static void deleteObject ( ScalarShapeFunctionSetType *object ) { delete object; }
99  };
100 
101  typedef ScalarShapeFunctionSetFactory ScalarShapeFunctionSetFactoryType;
102 
103  typedef ShapeFunctionSetProxy< ScalarShapeFunctionSetType > ScalarShapeFunctionSetProxyType;
104  typedef VectorialShapeFunctionSet< ScalarShapeFunctionSetProxyType, typename FunctionSpaceType::RangeType > ShapeFunctionSetType;
105 
106  typedef DefaultBasisFunctionSet< EntityType, ShapeFunctionSetType > BasisFunctionSetType;
107 
108  template< class DiscreteFunction, class Operation = DFCommunicationOperation::Add >
109  struct CommDataHandle
110  {
111  typedef DefaultCommunicationHandler< DiscreteFunction, Operation > Type;
112  typedef Operation OperationType;
113  };
114  };
115 
116 
117 
118  // RannacherTurekDiscreteFunctionSpace
119  // -----------------------------------
120 
130  template< class FunctionSpace, class GridPart, template< class > class Storage = CachingStorage >
131  struct RannacherTurekDiscreteFunctionSpace
132  : public DiscreteFunctionSpaceDefault< RannacherTurekDiscreteFunctionSpaceTraits< FunctionSpace, GridPart, Storage > >
133  {
134  typedef RannacherTurekDiscreteFunctionSpace< FunctionSpace, GridPart, Storage > ThisType;
135  typedef DiscreteFunctionSpaceDefault< RannacherTurekDiscreteFunctionSpaceTraits< FunctionSpace, GridPart, Storage > > BaseType;
136 
137  static const InterfaceType defaultInterface = InteriorBorder_All_Interface;
138  static const CommunicationDirection defaultDirection = ForwardCommunication;
139 
140  public:
141  static const int polynomialOrder = 1;
142 
143  typedef typename BaseType::Traits Traits;
144 
145  typedef typename BaseType::FunctionSpaceType FunctionSpaceType;
146 
147  typedef typename BaseType::GridPartType GridPartType;
148  typedef typename BaseType::EntityType EntityType;
149  typedef typename BaseType::IntersectionType IntersectionType;
150 
151  typedef typename BaseType::Traits::ShapeFunctionSetType ShapeFunctionSetType;
152  typedef typename BaseType::BasisFunctionSetType BasisFunctionSetType;
153 
154  typedef typename BaseType::BlockMapperType BlockMapperType;
155 
156  typedef RannacherTurekLocalInterpolation< BasisFunctionSetType, typename Traits::LocalInterpolationType > InterpolationType;
157 
158  private:
159  typedef typename Traits::ScalarShapeFunctionSetType ScalarShapeFunctionSetType;
160  typedef SingletonList< GeometryType, ScalarShapeFunctionSetType, typename Traits::ScalarShapeFunctionSetFactoryType > ScalarShapeFunctionSetProviderType;
161 
162  typedef RannacherTurekBlockMapperSingletonKey< GridPartType > BlockMapperSingletonKeyType;
163  typedef typename Traits::BlockMapperFactoryType BlockMapperFactoryType;
164  typedef SingletonList< BlockMapperSingletonKeyType, BlockMapperType, BlockMapperFactoryType > BlockMapperProviderType;
165 
166  public:
167  using BaseType::order;
168 
169  explicit RannacherTurekDiscreteFunctionSpace ( GridPartType &gridPart,
170  const InterfaceType commInterface = defaultInterface,
171  const CommunicationDirection commDirection = defaultDirection )
172  : BaseType( gridPart, commInterface, commDirection ),
173  scalarShapeFunctionSet_( nullptr ),
174  blockMapper_( nullptr )
175  {
176  // create scalar shape function set
177  GeometryType type = GeometryType( Dune::Fem::GridPartCapabilities::hasSingleGeometryType< GridPartType >::topologyId, GridPartType::dimension );
178  scalarShapeFunctionSet_ = &( ScalarShapeFunctionSetProviderType::getObject( type ) );
179 
180  // create block mapper
181  BlockMapperSingletonKeyType key( gridPart );
182  blockMapper_ = &( BlockMapperProviderType::getObject( key ) );
183  }
184 
185  ~RannacherTurekDiscreteFunctionSpace ()
186  {
187  if( blockMapper_ )
188  BlockMapperProviderType::removeObject( *blockMapper_ );
189  blockMapper_ = nullptr;
190 
191  if( scalarShapeFunctionSet_ )
192  ScalarShapeFunctionSetProviderType::removeObject( *scalarShapeFunctionSet_ );
193  scalarShapeFunctionSet_ = nullptr;
194  }
195 
197  DFSpaceIdentifier type () const { return RannacherTurekSpace_id; }
198 
200  BasisFunctionSetType basisFunctionSet ( const EntityType &entity ) const
201  {
202  return BasisFunctionSetType( entity, shapeFunctionSet( entity ) );
203  }
204 
212  ShapeFunctionSetType shapeFunctionSet ( const EntityType &entity ) const
213  {
214  assert( scalarShapeFunctionSet_);
215  return ShapeFunctionSetType( scalarShapeFunctionSet_ );
216  }
217 
219  bool continuous () const { return false; }
220 
222  bool continuous ( const IntersectionType &intersection ) const { return false; }
223 
225  int order () const { return polynomialOrder; }
226 
228  inline bool multipleGeometryTypes () const { return false; }
229 
231  BlockMapperType &blockMapper () const
232  {
233  assert( blockMapper_ );
234  return *blockMapper_;
235  }
236 
241  InterpolationType interpolation ( const EntityType &entity ) const
242  {
243  return InterpolationType( basisFunctionSet( entity ) );
244  }
245 
251  template< class LocalFunction, class LocalDofVector >
252  DUNE_DEPRECATED
253  void interpolate ( const LocalFunction &localFunction, LocalDofVector &dofs ) const
254  {
255  const EntityType &entity = localFunction.entity();
256  InterpolationType interpolation = this->interpolation( entity );
257  interpolation( localFunction, dofs );
258  }
259 
260  private:
261  RannacherTurekDiscreteFunctionSpace ( const ThisType & );
262  ThisType &operator= ( const ThisType & );
263 
264  ScalarShapeFunctionSetType *scalarShapeFunctionSet_;
265  BlockMapperType *blockMapper_;
266  };
267 
268  } // namespace Fem
269 
270 } // end namespace Dune
271 
272 #endif // #if HAVE_DUNE_LOCALFUNCTIONS
273 
274 #endif // #ifndef DUNE_FEM_SPACE_RANNACHERTUREK_HH
DFSpaceIdentifier
enumerator for identification of spaces
Definition: discretefunctionspace.hh:88
id for Rannacher-Turek space
Definition: discretefunctionspace.hh:96
Definition: coordinate.hh:4
specialize with &#39;true&#39; for if the codimension 0 entity of the grid part has only one possible geometr...
Definition: gridpart/common/capabilities.hh:28
Provides a proxy class for pointers to a shape function set.
static void interpolate(const GridFunction &u, DiscreteFunction &v)
perform native interpolation of a discrete function space
Definition: interpolate.hh:41