dune-fem  2.4.1-rc
localmatrixwrapper.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_LOCALMATRIXWRAPPER_HH
2 #define DUNE_FEM_LOCALMATRIXWRAPPER_HH
3 
5 
6 namespace Dune
7 {
8 
9  namespace Fem
10  {
11 
12  // Internal Forward Declarations
13  // -----------------------------
14 
15  template< class LocalMatrixStack >
17 
18 
19 
20  // LocalMatrixWrapperTraits
21  // ------------------------
22 
23  template< class LocalMatrixStack >
25  {
26  typedef LocalMatrixStack LocalMatrixStackType;
27 
28  typedef typename LocalMatrixStack::ObjectType WrappedLocalMatrixType;
29 
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  {
51 
52  public:
54  typedef LocalMatrixStack LocalMatrixStackType;
55 
58 
61 
63 
66 
69 
72 
73  private:
74  typedef typename LocalMatrixStackType::PointerType WrappedLocalMatrixPtrType;
75 
76  private:
77  // ObjectPointer to the actual local matrix
78  // (the pointer is required to keep the reference alive)
79  WrappedLocalMatrixPtrType localMatrixPtr_;
80 
81  // reference to the actual local matrix
82  WrappedLocalMatrixType &localMatrix_;
83 
84  public:
86  explicit LocalMatrixWrapper ( LocalMatrixStackType &stack )
87  : localMatrixPtr_( stack.getObject() ),
88  localMatrix_( *localMatrixPtr_ )
89  {}
90 
92  template< class DomainEntityType, class RangeEntityType >
93  LocalMatrixWrapper( LocalMatrixStackType &stack,
94  const DomainEntityType &domainEntity,
95  const RangeEntityType &rangeEntity )
96  : localMatrixPtr_( stack.getObject() ),
97  localMatrix_( *localMatrixPtr_ )
98  {
99  // initialize the wrapped local matrix with the entities
100  localMatrix().init( domainEntity, rangeEntity );
101  }
102 
107  LocalMatrixWrapper ( const ThisType &other )
108  : localMatrixPtr_( other.localMatrixPtr_ ),
109  localMatrix_( *localMatrixPtr_ )
110  {}
111 
114  {
115  // call finalize on local matrix implementation
116  // (e.g. needed for PETSc to add values to the real matrix)
117  localMatrix().finalize();
118  }
119 
120  private:
121  // prohibit assignment
122  ThisType &operator= ( const ThisType & );
123 
124  public:
126  void init ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
127  {
128  localMatrix().init( domainEntity, rangeEntity );
129  }
130 
132  void add ( int localRow, int localCol, const RangeFieldType &value )
133  {
134  localMatrix().add( localRow, localCol, value );
135  }
136 
138  void set ( int localRow, int localCol, const RangeFieldType &value )
139  {
140  localMatrix().set( localRow, localCol, value );
141  }
142 
144  void clearRow ( const int localRow )
145  {
146  localMatrix().clearRow( localRow );
147  }
148 
150  void clearCol ( const int localCol )
151  {
152  localMatrix().clearCol( localCol );
153  }
154 
156  const RangeFieldType get ( const int localRow,
157  const int localCol ) const
158  {
159  return localMatrix().get( localRow, localCol );
160  }
161 
163  void scale ( const RangeFieldType& scalar )
164  {
165  return localMatrix().scale( scalar );
166  }
167 
169  void clear ()
170  {
171  return localMatrix().clear();
172  }
173 
175  void resort ()
176  {
177  return localMatrix().resort();
178  }
179 
181  int rows () const
182  {
183  return localMatrix().rows();
184  }
185 
187  int columns () const
188  {
189  return localMatrix().columns();
190  }
191 
193  template <class DomainLocalFunctionImp,
194  class RangeLocalFunctionImp>
195  void multiplyAdd(const DomainLocalFunctionImp& dLf,
196  RangeLocalFunctionImp& rLf)
197  {
198  localMatrix().multiplyAdd( dLf, rLf);
199  }
200 
202  const DomainSpaceType &domainSpace () const
203  {
204  return localMatrix().domainSpace();
205  }
206 
208  const RangeSpaceType &rangeSpace () const
209  {
210  return localMatrix().rangeSpace();
211  }
212 
213  const DomainEntityType &domainEntity () const { return localMatrix().domainEntity(); }
214  const RangeEntityType &rangeEntity () const { return localMatrix().rangeEntity(); }
215 
217  const DomainBasisFunctionSetType &domainBasisFunctionSet () const
218  {
219  return localMatrix().domainBasisFunctionSet();
220  }
221 
223  const RangeBasisFunctionSetType &rangeBasisFunctionSet () const
224  {
225  return localMatrix().rangeBasisFunctionSet();
226  }
227 
228  protected:
229  const WrappedLocalMatrixType &localMatrix () const { return localMatrix_; }
230  WrappedLocalMatrixType &localMatrix () { return localMatrix_; }
231  };
232 
233  } // namespace Fem
234 
235 } // namespace Dune
236 
237 #endif // #ifndef DUNE_FEM_LOCALMATRIXWRAPPER_HH
Traits::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:51
WrappedLocalMatrixType::DomainSpaceType DomainSpaceType
Definition: localmatrixwrapper.hh:34
BaseType::DomainSpaceType DomainSpaceType
Definition: localmatrixwrapper.hh:64
Definition: localmatrixwrapper.hh:16
WrappedLocalMatrixType::RangeFieldType RangeFieldType
Definition: localmatrixwrapper.hh:32
RangeSpaceType::EntityType RangeEntityType
Definition: localmatrix.hh:65
LocalMatrixWrapper(LocalMatrixStackType &stack)
constructor creating an uninitialized local matrix
Definition: localmatrixwrapper.hh:86
LocalMatrixStack LocalMatrixStackType
Definition: localmatrixwrapper.hh:26
void scale(const RangeFieldType &scalar)
scale matrix with scalar value
Definition: localmatrixwrapper.hh:163
int columns() const
get number of columns within the matrix
Definition: localmatrixwrapper.hh:187
LocalMatrixWrapper(LocalMatrixStackType &stack, const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
constructor initializing the wrapped local matrix
Definition: localmatrixwrapper.hh:93
const DomainEntityType & domainEntity() const
Definition: localmatrixwrapper.hh:213
Traits::WrappedLocalMatrixType WrappedLocalMatrixType
type of the wrapped local matrix
Definition: localmatrixwrapper.hh:60
void clear()
set all entries of local matrix to zero
Definition: localmatrixwrapper.hh:169
BaseType::DomainBasisFunctionSetType DomainBasisFunctionSetType
Definition: localmatrixwrapper.hh:67
void multiplyAdd(const DomainLocalFunctionImp &dLf, RangeLocalFunctionImp &rLf)
multiply left hand side with local matrix and add to right hand side rhs += Matrix * lhs ...
Definition: localmatrixwrapper.hh:195
BaseType::RangeBasisFunctionSetType RangeBasisFunctionSetType
Definition: localmatrixwrapper.hh:68
DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType
type of base function sets within domain function space
Definition: localmatrix.hh:58
~LocalMatrixWrapper()
destructor
Definition: localmatrixwrapper.hh:113
WrappedLocalMatrixType & localMatrix()
Definition: localmatrixwrapper.hh:230
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrixwrapper.hh:126
Interface for local matrix classes.
Definition: localmatrix.hh:28
BaseType::DomainEntityType DomainEntityType
Definition: localmatrixwrapper.hh:70
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrixwrapper.hh:175
LocalMatrixWrapper(const ThisType &other)
copy constructor
Definition: localmatrixwrapper.hh:107
const RangeEntityType & rangeEntity() const
Definition: localmatrixwrapper.hh:214
RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType
type of base function sets within range function space
Definition: localmatrix.hh:62
void add(int localRow, int localCol, const RangeFieldType &value)
add value to matrix entry (row,col) where row and col are local row and local column ...
Definition: localmatrixwrapper.hh:132
LocalMatrixStack::ObjectType WrappedLocalMatrixType
Definition: localmatrixwrapper.hh:28
Definition: coordinate.hh:4
WrappedLocalMatrixType::RangeSpaceType RangeSpaceType
Definition: localmatrixwrapper.hh:35
LocalMatrixWrapper< LocalMatrixStackType > LocalMatrixType
Definition: localmatrixwrapper.hh:30
LocalMatrixWrapperTraits< LocalMatrixStackType > Traits
type of the traits
Definition: localmatrixwrapper.hh:57
const WrappedLocalMatrixType & localMatrix() const
Definition: localmatrixwrapper.hh:229
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrixwrapper.hh:208
Traits::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:54
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrixwrapper.hh:217
BaseType::RangeSpaceType RangeSpaceType
Definition: localmatrixwrapper.hh:65
WrappedLocalMatrixType::LittleBlockType LittleBlockType
Definition: localmatrixwrapper.hh:37
void clearRow(const int localRow)
set row to zero values
Definition: localmatrixwrapper.hh:144
int rows() const
get number of rows within the matrix
Definition: localmatrixwrapper.hh:181
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrixwrapper.hh:223
Traits::RangeFieldType RangeFieldType
Definition: localmatrixwrapper.hh:62
Definition: localmatrixwrapper.hh:24
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrixwrapper.hh:202
LocalMatrixStack LocalMatrixStackType
type of the local matrix stack
Definition: localmatrixwrapper.hh:54
void clearCol(const int localCol)
set row to zero values
Definition: localmatrixwrapper.hh:150
DomainSpaceType::EntityType DomainEntityType
Definition: localmatrix.hh:64
BaseType::RangeEntityType RangeEntityType
Definition: localmatrixwrapper.hh:71