DUNE-FEM (unstable)

localmatrixwrapper.hh
1#ifndef DUNE_FEM_LOCALMATRIXWRAPPER_HH
2#define DUNE_FEM_LOCALMATRIXWRAPPER_HH
3
4#include <dune/fem/operator/common/localmatrix.hh>
5
6namespace Dune
7{
8
9 namespace Fem
10 {
11
12 // Internal Forward Declarations
13 // -----------------------------
14
15 template< class LocalMatrixStack >
16 class LocalMatrixWrapper;
17
18
19
20 // LocalMatrixWrapperTraits
21 // ------------------------
22
23 template< class LocalMatrixStack >
24 struct LocalMatrixWrapperTraits
25 {
26 typedef LocalMatrixStack LocalMatrixStackType;
27
28 typedef typename LocalMatrixStack::ObjectType WrappedLocalMatrixType;
29
30 typedef LocalMatrixWrapper< LocalMatrixStackType > LocalMatrixType;
31
32 typedef typename WrappedLocalMatrixType::RangeFieldType RangeFieldType;
33
34 typedef typename WrappedLocalMatrixType::DomainSpaceType DomainSpaceType;
35 typedef typename WrappedLocalMatrixType::RangeSpaceType RangeSpaceType;
36
37 typedef typename WrappedLocalMatrixType::LittleBlockType LittleBlockType;
38 };
39
40
41
42 // LocalMatrixWrapper
43 // ------------------
44
45 template< class LocalMatrixStack >
46 class LocalMatrixWrapper
47 : public LocalMatrixInterface< LocalMatrixWrapperTraits< LocalMatrixStack > >
48 {
49 typedef LocalMatrixWrapper< LocalMatrixStack > ThisType;
50 typedef LocalMatrixInterface< LocalMatrixWrapperTraits< LocalMatrixStack > > BaseType;
51
52 public:
54 typedef LocalMatrixStack LocalMatrixStackType;
55
57 typedef LocalMatrixWrapperTraits< LocalMatrixStackType > Traits;
58
60 typedef typename Traits::WrappedLocalMatrixType WrappedLocalMatrixType;
61
62 typedef typename Traits::RangeFieldType RangeFieldType;
63
64 typedef typename BaseType::DomainSpaceType DomainSpaceType;
65 typedef typename BaseType::RangeSpaceType RangeSpaceType;
66
67 typedef typename BaseType::DomainBasisFunctionSetType DomainBasisFunctionSetType;
68 typedef typename BaseType::RangeBasisFunctionSetType RangeBasisFunctionSetType;
69
70 typedef typename BaseType::DomainEntityType DomainEntityType;
71 typedef typename BaseType::RangeEntityType RangeEntityType;
72
73 private:
74 typedef typename LocalMatrixStackType::PointerType WrappedLocalMatrixPtrType;
75
76 // ObjectPointer to the actual local matrix
77 // (the pointer is required to keep the reference alive)
78 WrappedLocalMatrixPtrType localMatrixPtr_;
79
80 // reference to the actual local matrix
81 WrappedLocalMatrixType &localMatrix_;
82
83 public:
85 explicit LocalMatrixWrapper ( LocalMatrixStackType &stack )
86 : localMatrixPtr_( stack.getObject() ),
87 localMatrix_( *localMatrixPtr_ )
88 {}
89
91 template< class DomainEntityType, class RangeEntityType >
92 LocalMatrixWrapper( LocalMatrixStackType &stack,
93 const DomainEntityType &domainEntity,
94 const RangeEntityType &rangeEntity )
95 : localMatrixPtr_( stack.getObject() ),
96 localMatrix_( *localMatrixPtr_ )
97 {
98 // initialize the wrapped local matrix with the entities
99 localMatrix().init( domainEntity, rangeEntity );
100 }
101
106 LocalMatrixWrapper ( const ThisType &other )
107 : localMatrixPtr_( other.localMatrixPtr_ ),
108 localMatrix_( *localMatrixPtr_ )
109 {}
110
112 ~LocalMatrixWrapper ( )
113 {
114 // call finalize on local matrix implementation
115 // (e.g. needed for PETSc to add values to the real matrix)
116 localMatrix().finalize();
117 }
118
119 ThisType& operator= ( const ThisType& ) = delete;
120
122 void init ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
123 {
124 localMatrix().init( domainEntity, rangeEntity );
125 }
126
128 void add ( int localRow, int localCol, const RangeFieldType &value )
129 {
130 localMatrix().add( localRow, localCol, value );
131 }
132
134 void set ( int localRow, int localCol, const RangeFieldType &value )
135 {
136 localMatrix().set( localRow, localCol, value );
137 }
138
140 void clearRow ( const int localRow )
141 {
142 localMatrix().clearRow( localRow );
143 }
144
146 void clearCol ( const int localCol )
147 {
148 localMatrix().clearCol( localCol );
149 }
150
152 const RangeFieldType get ( const int localRow,
153 const int localCol ) const
154 {
155 return localMatrix().get( localRow, localCol );
156 }
157
159 void scale ( const RangeFieldType& scalar )
160 {
161 return localMatrix().scale( scalar );
162 }
163
165 void clear ()
166 {
167 return localMatrix().clear();
168 }
169
171 void resort ()
172 {
173 return localMatrix().resort();
174 }
175
177 int rows () const
178 {
179 return localMatrix().rows();
180 }
181
183 int columns () const
184 {
185 return localMatrix().columns();
186 }
187
189 template <class DomainLocalFunctionImp,
190 class RangeLocalFunctionImp>
191 void multiplyAdd(const DomainLocalFunctionImp& dLf,
192 RangeLocalFunctionImp& rLf)
193 {
194 localMatrix().multiplyAdd( dLf, rLf);
195 }
196
198 const DomainSpaceType &domainSpace () const
199 {
200 return localMatrix().domainSpace();
201 }
202
204 const RangeSpaceType &rangeSpace () const
205 {
206 return localMatrix().rangeSpace();
207 }
208
209 const DomainEntityType &domainEntity () const { return localMatrix().domainEntity(); }
210 const RangeEntityType &rangeEntity () const { return localMatrix().rangeEntity(); }
211
213 const DomainBasisFunctionSetType &domainBasisFunctionSet () const
214 {
215 return localMatrix().domainBasisFunctionSet();
216 }
217
219 const RangeBasisFunctionSetType &rangeBasisFunctionSet () const
220 {
221 return localMatrix().rangeBasisFunctionSet();
222 }
223
224 protected:
225 const WrappedLocalMatrixType &localMatrix () const { return localMatrix_; }
226 WrappedLocalMatrixType &localMatrix () { return localMatrix_; }
227 };
228
229 } // namespace Fem
230
231} // namespace Dune
232
233#endif // #ifndef DUNE_FEM_LOCALMATRIXWRAPPER_HH
Traits::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:54
Traits::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:57
RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType
type of base function sets within range function space
Definition: localmatrix.hh:65
DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType
type of base function sets within domain function space
Definition: localmatrix.hh:61
void multiplyAdd(const DomainLocalFunctionType &lhs, RangeLocalFunctionType &rhs) const
multiply left hand side with local matrix and add to right hand side rhs += Matrix * lhs
Definition: localmatrix.hh:165
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)