dune-fem  2.8-git
hierarchical/function.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
2 #define DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
3 
4 #include <dune/common/fvector.hh>
5 
6 #if HAVE_DUNE_ISTL
7 #include <dune/istl/bvector.hh>
8 #include <dune/istl/multitypeblockvector.hh>
9 #endif // #if HAVE_DUNE_ISTL
10 
17 
18 namespace Dune
19 {
20 
21  namespace Fem
22  {
23 
24  // Internal Forward Declaration
25  // ----------------------------
26 
27  template< class DiscreteFunctionSpace >
28  class HierarchicalDiscreteFunction;
29 
30 
31 
32  namespace Impl
33  {
34 
35  template< class Dof, class BlockIndices >
36  struct HierarchicalDofContainerChooser;
37 
38 #if HAVE_DUNE_ISTL
39  template< class Dof, int sz >
40  struct HierarchicalDofContainerChooser< Dof, Hybrid::IndexRange< int, sz > >
41  {
42  typedef BlockVector< FieldVector< Dof, sz > > Type;
43  };
44 
45  template< class Dof, class... SR >
46  struct HierarchicalDofContainerChooser< Dof, Hybrid::CompositeIndexRange< SR... > >
47  {
48  typedef MultiTypeBlockVector< typename HierarchicalDofContainerChooser< Dof, SR >::Type... > Type;
49  };
50 #else
51  template< class Dof, int sz >
52  struct HierarchicalDofContainerChooser< Dof, Hybrid::IndexRange< int, sz > >
53  {
54  typedef MutableBlockVector< DynamicArray< Dof >, sz > Type;
55  };
56 
57  template< class Dof, class... SR >
58  struct HierarchicalDofContainerChooser< Dof, Hybrid::CompositeIndexRange< SR... > >
59  {
60  typedef MutableBlockVector< DynamicArray< Dof >, Hybrid::CompositeIndexRange< SR... >::size() > Type;
61  };
62 #endif // #if HAVE_DUNE_ISTL
63 
64  } // namespace Impl
65 
66 
67 
68  // DiscreteFunctionTraits for HierarchicalDiscreteFunction
69  // -------------------------------------------------------
70 
71  template< class DiscreteFunctionSpace >
73  {
75 
76  typedef typename DiscreteFunctionSpaceType::RangeFieldType DofType;
77 
78  typedef typename DiscreteFunctionSpaceType::DomainType DomainType;
79  typedef typename DiscreteFunctionSpaceType::RangeType RangeType;
80 
82 
83  // fake DoF blocks, DoF block pointers and DoF iterators
85  typedef const DofType *ConstDofIteratorType;
87  typedef const DofType *ConstDofBlockType;
89  typedef const DofType **ConstDofBlockPtrType;
90 
94 
97  };
98 
99 
100  // HierarchicalDiscreteFunction
101  // ----------------------------
102 
103  template< class DiscreteFunctionSpace >
105  : public DiscreteFunctionDefault< HierarchicalDiscreteFunction< DiscreteFunctionSpace > >
106  {
109 
110  public:
113 
114  using BaseType :: name;
115 
118  {}
119 
122  {}
123 
125  : BaseType( "copy of " + other.name(), other.space() ), dofVector_( allocateDofStorage( other.space() ) )
126  {
127  dofVector_ = other.dofVector_;
128  }
129 
131  const DofVectorType &dofVector () const { return dofVector_; }
132 
134  {
135  if( memObject_ )
136  memObject_->enableDofCompression();
137  }
138 
139  protected:
141  {
142  auto memPair = allocateManagedDofStorage< DofVectorType >( space.gridPart().grid(), space.blockMapper() );
143  memObject_.reset( memPair.first );
144  return *memPair.second;
145  }
146 
147  std::unique_ptr< DofStorageInterface > memObject_;
149  };
150 
151  } // namespace Fem
152 
153 } // namespace Dune
154 
155 #endif // #ifndef DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
Definition: bindguard.hh:11
static constexpr Index size()
Definition: hybrid.hh:111
Definition: stackallocator.hh:61
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:61
Definition: common/discretefunction.hh:578
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:685
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: common/discretefunction.hh:600
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:703
Traits ::DofVectorType DofVectorType
type of DofVector
Definition: common/discretefunction.hh:625
Definition: hierarchical/dofvector.hh:131
Definition: hierarchical/function.hh:106
HierarchicalDiscreteFunction(const ThisType &other)
Definition: hierarchical/function.hh:124
HierarchicalDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector)
Definition: hierarchical/function.hh:116
BaseType::DofVectorType DofVectorType
Definition: hierarchical/function.hh:112
std::unique_ptr< DofStorageInterface > memObject_
Definition: hierarchical/function.hh:147
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: hierarchical/function.hh:111
void enableDofCompression()
Definition: hierarchical/function.hh:133
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: hierarchical/function.hh:140
HierarchicalDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Definition: hierarchical/function.hh:120
DofVectorType & dofVector()
Definition: hierarchical/function.hh:130
DofVectorType & dofVector_
Definition: hierarchical/function.hh:148
const DofVectorType & dofVector() const
Definition: hierarchical/function.hh:131
ThreadSafeValue< UninitializedObjectStack > LocalDofVectorStackType
Definition: hierarchical/function.hh:91
DiscreteFunctionSpaceType::DomainType DomainType
Definition: hierarchical/function.hh:78
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: hierarchical/function.hh:74
const DofType * ConstDofIteratorType
Definition: hierarchical/function.hh:85
DiscreteFunctionSpaceType::RangeFieldType DofType
Definition: hierarchical/function.hh:76
HierarchicalDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType
Definition: hierarchical/function.hh:95
StackAllocator< DofType, LocalDofVectorStackType * > LocalDofVectorAllocatorType
Definition: hierarchical/function.hh:92
DiscreteFunctionSpaceType::RangeType RangeType
Definition: hierarchical/function.hh:79
DynamicReferenceVector< DofType, LocalDofVectorAllocatorType > LocalDofVectorType
Definition: hierarchical/function.hh:93
HierarchicalDofVector< typename Impl::HierarchicalDofContainerChooser< DofType, typename DiscreteFunctionSpaceType::LocalBlockIndices >::Type > DofVectorType
Definition: hierarchical/function.hh:81
const DofType ** ConstDofBlockPtrType
Definition: hierarchical/function.hh:89
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: hierarchical/function.hh:96
An implementation of DenseVector which uses a std::vector of references as storage.
Definition: storage/referencevector.hh:53
discrete function space