DUNE-FEM (unstable)

function.hh
1#ifndef DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
2#define DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
3
5
6#if HAVE_DUNE_ISTL
8#include <dune/istl/multitypeblockvector.hh>
9#endif // #if HAVE_DUNE_ISTL
10
11#include <dune/fem/common/hybrid.hh>
12#include <dune/fem/function/blockvectors/defaultblockvectors.hh>
13#include <dune/fem/function/common/discretefunction.hh>
14#include <dune/fem/function/hierarchical/dofvector.hh>
15#include <dune/fem/function/localfunction/mutable.hh>
16#include <dune/fem/space/common/dofmanager.hh>
17
18namespace 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 >
72 struct DiscreteFunctionTraits< HierarchicalDiscreteFunction< DiscreteFunctionSpace > >
73 {
74 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
75
76 typedef typename DiscreteFunctionSpaceType::RangeFieldType DofType;
77
78 typedef typename DiscreteFunctionSpaceType::DomainType DomainType;
79 typedef typename DiscreteFunctionSpaceType::RangeType RangeType;
80
81 typedef HierarchicalDofVector< typename Impl::HierarchicalDofContainerChooser< DofType, typename DiscreteFunctionSpaceType::LocalBlockIndices >::Type > DofVectorType;
82
83 // fake DoF blocks, DoF block pointers and DoF iterators
84 typedef DofType *DofIteratorType;
85 typedef const DofType *ConstDofIteratorType;
86 typedef DofType *DofBlockType;
87 typedef const DofType *ConstDofBlockType;
88 typedef DofType **DofBlockPtrType;
89 typedef const DofType **ConstDofBlockPtrType;
90
91 typedef ThreadSafeValue< UninitializedObjectStack > LocalDofVectorStackType;
92 typedef StackAllocator< DofType, LocalDofVectorStackType * > LocalDofVectorAllocatorType;
93 typedef DynamicReferenceVector< DofType, LocalDofVectorAllocatorType > LocalDofVectorType;
94
95 typedef HierarchicalDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType;
96 typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
97 };
98
99
100 // HierarchicalDiscreteFunction
101 // ----------------------------
102
103 template< class DiscreteFunctionSpace >
104 class HierarchicalDiscreteFunction
105 : public DiscreteFunctionDefault< HierarchicalDiscreteFunction< DiscreteFunctionSpace > >
106 {
107 typedef HierarchicalDiscreteFunction< DiscreteFunctionSpace > ThisType;
108 typedef DiscreteFunctionDefault< HierarchicalDiscreteFunction< DiscreteFunctionSpace > > BaseType;
109
110 public:
111 typedef typename BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
112 typedef typename BaseType::DofVectorType DofVectorType;
113
114 using BaseType :: name;
115
116 HierarchicalDiscreteFunction ( const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector )
117 : BaseType( name, space ), dofVector_( dofVector )
118 {}
119
120 HierarchicalDiscreteFunction ( const std::string &name, const DiscreteFunctionSpaceType &space )
121 : BaseType( name, space ), dofVector_( allocateDofStorage( space ) )
122 {}
123
124 HierarchicalDiscreteFunction ( const ThisType &other )
125 : BaseType( "copy of " + other.name(), other.space() ), dofVector_( allocateDofStorage( other.space() ) )
126 {
127 dofVector_ = other.dofVector_;
128 }
129
130 DofVectorType &dofVector () { return dofVector_; }
131 const DofVectorType &dofVector () const { return dofVector_; }
132
133 void enableDofCompression ()
134 {
135 if( memObject_ )
136 memObject_->enableDofCompression();
137 }
138
139 protected:
140 DofVectorType &allocateDofStorage ( const DiscreteFunctionSpaceType &space )
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_;
148 DofVectorType &dofVector_;
149 };
150
151 } // namespace Fem
152
153} // namespace Dune
154
155#endif // #ifndef DUNE_FEM_FUNCTION_HIERARCHICAL_FUNCTION_HH
This file implements a vector space as a tensor product of a given vector space. The number of compon...
discrete function space
Traits::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:631
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
const std::string & name() const
obtain the name of the discrete function
Definition: discretefunction.hh:691
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: discretefunction.hh:606
forward declaration
Definition: discretefunction.hh:51
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)