dune-fem  2.6-git
common/discretefunction.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DISCRETEFUNCTION_HH
2 #define DUNE_FEM_DISCRETEFUNCTION_HH
3 
4 #include <cassert>
5 
6 #include <complex>
7 #include <memory>
8 #include <ostream>
9 #include <string>
10 #include <typeindex>
11 
12 #include <dune/common/dynvector.hh>
13 
22 #include <dune/fem/misc/functor.hh>
27 #include <dune/fem/version.hh>
28 
29 
30 namespace Dune
31 {
32 
33  namespace Fem
34  {
35 
52  {};
53 
56  {};
57 
58 
59  template< class DiscreteFunction >
61 
62  template< class Traits >
64 
65  //----------------------------------------------------------------------
66  //-
67  //- --DiscreteFunctionInterface
68  //-
69  //----------------------------------------------------------------------
80  template< class Impl >
82  : public Function< typename DiscreteFunctionTraits< Impl >::DiscreteFunctionSpaceType::FunctionSpaceType, Impl >,
83  public IsDiscreteFunction,
84  public HasLocalFunction
85  {
88 
89  public:
92 
94  typedef typename Traits :: DiscreteFunctionType DiscreteFunctionType;
95 
97  typedef typename Traits :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
98 
100  typedef typename DiscreteFunctionSpaceType :: FunctionSpaceType FunctionSpaceType;
101 
104 
106  typedef typename DiscreteFunctionSpaceType :: DomainFieldType DomainFieldType;
108  typedef typename DiscreteFunctionSpaceType :: RangeFieldType RangeFieldType;
110  typedef typename DiscreteFunctionSpaceType :: DomainType DomainType;
112  typedef typename DiscreteFunctionSpaceType :: RangeType RangeType;
114  typedef typename DiscreteFunctionSpaceType :: JacobianRangeType JacobianRangeType;
115 
117  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
118 
120  typedef typename DiscreteFunctionSpaceType :: GridType GridType;
121 
123  typedef typename Traits :: LocalFunctionType LocalFunctionType;
124 
126  typedef typename Traits :: DofVectorType DofVectorType;
127 
129  typedef typename Traits :: DofIteratorType DofIteratorType;
130 
132  typedef typename Traits :: ConstDofIteratorType ConstDofIteratorType;
133 
134  typedef typename Traits :: DofType DofType;
135  typedef typename Traits :: DofBlockType DofBlockType;
136  typedef typename Traits :: ConstDofBlockType ConstDofBlockType;
137  typedef typename Traits :: DofBlockPtrType DofBlockPtrType;
138  typedef typename Traits :: ConstDofBlockPtrType ConstDofBlockPtrType;
139 
142 
143  typedef typename DiscreteFunctionSpaceType::LocalBlockIndices BlockIndices;
144 
146  static constexpr std::size_t blockSize = Hybrid::size( BlockIndices() );
147 
148  template< class Operation >
150  {
151  typedef typename DiscreteFunctionSpaceType
154  };
155 
157  typedef typename DiscreteFunctionSpaceType :: EntityType EntityType;
158 
159  protected:
160  using BaseType::asImp;
161 
164 
165  DiscreteFunctionInterface ( const ThisType& ) = default;
167  public:
168  ThisType& operator= ( ThisType&& ) = delete;
169  ThisType &operator= ( const ThisType& ) = delete;
170 
172  {
173  return asImp().dofVector();
174  }
175  const DofVectorType &dofVector() const
176  {
177  return asImp().dofVector();
178  }
179 
184  const std::string &name () const
185  {
186  return asImp().name();
187  }
188 
193  std::string &name ()
194  {
195  return asImp().name();
196  }
197 
200  const std::string &order () const
201  {
202  return asImp().order();
203  }
204 
206  bool continuous() const
207  {
208  return asImp().continuous();
209  }
210 
213  {
214  return asImp().space();
215  }
216 
218  const GridPartType &gridPart () const
219  {
220  return asImp().gridPart();
221  }
222 
229  {
230  return asImp().localFunction( entity );
231  }
232 
238  const LocalFunctionType localFunction ( const EntityType &entity ) const
239  {
240  return asImp().localFunction( entity );
241  }
242 
250  {
251  return asImp().localFunction();
252  }
253 
261  {
262  return asImp().localFunction();
263  }
264 
266  void clear()
267  {
268  asImp().clear();
269  }
270 
279  int size() const
280  {
281  return asImp().size();
282  }
283 
291  int blocks() const
292  {
293  return asImp().blocks();
294  }
295 
300  DUNE_VERSION_DEPRECATED_3_0( "dofVector" ) ConstDofBlockPtrType block ( unsigned int index ) const
301  {
302  return asImp().block( index );
303  }
304 
309  DUNE_VERSION_DEPRECATED_3_0( "dofVector" ) DofBlockPtrType block ( unsigned int index )
310  {
311  return asImp().block( index );
312  }
313 
319  {
320  return asImp().dbegin ();
321  }
322 
328  {
329  return asImp().dend ();
330  }
331 
337  {
338  return asImp().dbegin ();
339  }
340 
346  {
347  return asImp().dend ();
348  }
349 
358  {
359  asImp().axpy( s, g );
360  }
361 
375  template <class DFType>
377  {
378  return asImp().scalarProductDofs( other.asImp() );
379  }
380 
392  typename Dune::FieldTraits< RangeFieldType >::real_type normSquaredDofs ( ) const
393  {
394  return asImp().normSquaredDofs( );
395  }
396 
401  void print( std :: ostream &out ) const
402  {
403  asImp().print( out );
404  }
405 
409  bool dofsValid () const
410  {
411  return asImp().dofsValid();
412  }
413 
418  template < class DFType >
420  {
421  asImp().assign( g );
422  }
423 
425  template< class Operation >
426  typename CommDataHandle< Operation >::Type dataHandle( const Operation &operation )
427  {
428  return asImp().dataHandle( operation );
429  }
430 
432  void communicate()
433  {
434  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().communicate() );
435  }
436 
443  template < class DFType >
445  {
446  return asImp().operator+=( g );
447  }
448 
455  template < class DFType >
457  {
458  return asImp().operator-=( g );
459  }
460 
468  {
469  return asImp() *= scalar;
470  }
471 
479  {
480  return asImp() /= scalar;
481  }
482 
487  template< class StreamTraits >
489  {
490  asImp().read( in );
491  }
492 
497  template< class StreamTraits >
499  {
500  asImp().write( out );
501  }
502 
508  {
509  asImp().enableDofCompression();
510  }
511 
512  //TODO: this needs to be revised, the definition should be in GridPart
515  {
516  return DefaultLoadBalanceContainsCheckType( *this );
517  }
518  };
519 
520 
521 
522  //*************************************************************************
523  //
524  // --DiscreteFunctionDefault
525  //
534  //*************************************************************************
535  template< class Impl >
537  : public DiscreteFunctionInterface< Impl > ,
538  public PersistentObject
539  {
542 
543  public:
544  typedef typename BaseType :: Traits Traits;
545 
547  typedef Impl DiscreteFunctionType;
548 
550 
551  private:
553 
554  enum { myId_ = 0 };
555 
556  protected:
558 
559  public:
562 
565 
567  typedef typename DiscreteFunctionSpaceType :: DomainType DomainType;
569  typedef typename DiscreteFunctionSpaceType :: RangeType RangeType;
571  typedef typename DiscreteFunctionSpaceType :: JacobianRangeType JacobianRangeType;
573  typedef typename DiscreteFunctionSpaceType :: HessianRangeType HessianRangeType;
574 
576  typedef typename DiscreteFunctionSpaceType :: DomainFieldType DomainFieldType;
578  typedef typename DiscreteFunctionSpaceType :: RangeFieldType RangeFieldType;
579 
581  typedef typename Traits :: DofIteratorType DofIteratorType;
583  typedef typename Traits :: ConstDofIteratorType ConstDofIteratorType;
584 
586  typedef typename Traits :: DofVectorType DofVectorType;
587 
589  typedef typename Traits :: LocalDofVectorType LocalDofVectorType;
591  typedef typename Traits :: LocalDofVectorAllocatorType LocalDofVectorAllocatorType;
592 
595  typedef typename LocalFunctionType::LocalCoordinateType LocalCoordinateType;
596 
601 
603 
604  typedef typename BaseType :: DofType DofType;
605 
607  typedef typename DofVectorType::SizeType SizeType;
608 
609  using BaseType::blockSize;
610 
611  template< class Operation >
613  : public BaseType :: template CommDataHandle< Operation >
614  {};
615 
616  protected:
617  using BaseType :: asImp;
618 
629  DiscreteFunctionDefault ( const std::string &name, const DiscreteFunctionSpaceType &dfSpace );
630 
631  DiscreteFunctionDefault ( std::string name, std::shared_ptr< const DiscreteFunctionSpaceType > dfSpace );
632 
635 
636  public:
637  ThisType& operator= ( ThisType&& ) = delete;
638  ThisType &operator= ( const ThisType& ) = delete;
639 
640  // Default Implementations
641  // -----------------------
642 
644  const std::string &name () const { return name_; }
645 
647  std::string &name () { return name_; }
648 
650  constexpr int order() const
651  {
652  return space().order();
653  }
654 
656  bool continuous() const
657  {
658  return space().continuous();
659  }
660 
662  const