dune-fem 2.8.0
Loading...
Searching...
No Matches
temporarylocalmatrix.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_TEMPORARYLOCALMATRIX_HH
2#define DUNE_FEM_TEMPORARYLOCALMATRIX_HH
3
4#include <algorithm>
5#include <vector>
6
7#include <dune/common/densematrix.hh>
8#include <dune/common/dynvector.hh>
9
12
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 // Internal Forward Declarations
20 // -----------------------------
21
22 template< class DomainSpaceImp, class RangeSpaceImp >
23 class TemporaryLocalMatrix;
24
25
26
27 // TemporaryLocalMatrixTraits
28 // --------------------------
29
30 template< class DomainSpaceImp, class RangeSpaceImp >
32 {
33 typedef DomainSpaceImp DomainSpaceType;
34 typedef RangeSpaceImp RangeSpaceType;
35
38
39 typedef typename DomainSpaceType :: RangeFieldType DomainFieldType;
40 typedef typename RangeSpaceType :: RangeFieldType RangeFieldType;
42 };
43
44 } // namespace Fem
45
46
47
48 // DenseMatVecTraits for TemporaryLocalMatrix
49 // ------------------------------------------
50
51 template< class DomainSpaceImp, class RangeSpaceImp >
52 struct DenseMatVecTraits< Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >
53 {
55
57 typedef int size_type;
58
59 typedef DynamicVector< value_type > row_type;
60
63 };
64
65
66
67 // FieldTraits for TemporaryLocalMatrix
68 // ------------------------------------
69
70 template< class DomainSpaceImp, class RangeSpaceImp >
71 struct FieldTraits< Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >
72 : public FieldTraits< typename Fem::TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp >::RangeFieldType >
73 {};
74
75
76
77 namespace Fem
78 {
79
80 // TemporaryLocalMatrix
81 // --------------------
82
96 template< class DomainSpaceImp, class RangeSpaceImp >
98 : public DenseMatrix< TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >,
99 public LocalMatrixDefault< TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp > >
100 {
101 public:
102 typedef DomainSpaceImp DomainSpaceType;
103 typedef RangeSpaceImp RangeSpaceType;
104
107
108 private:
110 ThisType;
112
113 public:
114 typedef typename Traits :: DomainFieldType DomainFieldType;
115 typedef typename Traits :: RangeFieldType RangeFieldType;
116
117 typedef int size_type;
119
122
123 typedef std::vector< RangeFieldType > MatrixEntriesType;
124 protected:
126
127 public:
130
134 fields_()
135 {}
136
137 template< class DomainEntityType, class RangeEntityType >
143 fields_( rows() * columns() )
144 {}
145
147 template< class DomainEntityType, class RangeEntityType >
148 inline void init ( const DomainEntityType &domainEntity,
150 {
152 }
153
155 template< class DomainEntityType, class RangeEntityType >
156 inline void bind ( const DomainEntityType &domainEntity,
158 {
159 BaseType :: bind( domainEntity, rangeEntity );
160 fields_.resize( rows() * columns() );
161 }
162
164 inline void unbind ()
165 {
167 }
168
170 inline void add ( const int localRow,
171 const int localCol,
172 const RangeFieldType &value )
173 {
174 assert( (localRow >= 0) && (localRow < rows()) );
175 assert( (localCol >= 0) && (localCol < columns()) );
176 fields_[ localRow * columns() + localCol ] += value;
177 }
178
180 inline void set ( const int localRow,
181 const int localCol,
182 const RangeFieldType &value )
183 {
184 assert( (localRow >= 0) && (localRow < rows()) );
185 assert( (localCol >= 0) && (localCol < columns()) );
186 fields_[ localRow * columns() + localCol ] = value;
187 }
188
190 inline const RangeFieldType get ( const int localRow,
191 const int localCol ) const
192 {
193 assert( (localRow >= 0) && (localRow < rows()) );
194 assert( (localCol >= 0) && (localCol < columns()) );
195 return fields_[ localRow * columns() + localCol ];
196 }
197
199 inline void scale( const RangeFieldType &value )
200 {
201 const std::size_t size = fields_.size();
202 for( std::size_t i=0; i<size; ++i )
203 {
204 fields_[ i ] *= value;
205 }
206 }
207
209 inline void clear ()
210 {
211 std::fill( fields_.begin() , fields_.end() , 0 );
212 }
213
215 void clearRow( const int localRow )
216 {
217 const int col = columns();
218 auto start = fields_.begin() + localRow * col;
219 auto end = start + col;
220 std::fill( start, end, 0 );
221 }
222
223 size_type rows () const { return mat_rows(); }
224 size_type cols () const { return mat_cols(); }
225 size_type columns () const { return mat_cols(); }
226
227 // make this thing a dense matrix
228 size_type mat_rows () const { return rangeBasisFunctionSet().size(); }
229 size_type mat_cols () const { return domainBasisFunctionSet().size(); }
230
232 {
233 const size_type cols = mat_cols();
234 return row_reference( fields_.data() + i*cols, cols );
235 }
236
238 {
239 const size_type cols = mat_cols();
240 return const_row_reference( fields_.data() + i*cols, cols );
241 }
242
243 // return pointer to data array for PetscLinearOperator to avoid copying.
244 const RangeFieldType* data() const { return fields_.data(); }
245 };
246
247 } // namespace Fem
248
249} // namespace Dune
250
251#endif // #ifndef DUNE_FEM_TEMPORARYLOCALMATRIX_HH
Definition: bindguard.hh:11
Default implementation for local matrix classes.
Definition: localmatrix.hh:285
const RangeEntityType & rangeEntity() const
Definition: localmatrix.hh:398
const DomainEntityType & domainEntity() const
Definition: localmatrix.hh:397
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:392
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:383
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:359
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:380
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:386
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
const RangeFieldType * data() const
Definition: temporarylocalmatrix.hh:244
RangeFieldType value_type
Definition: temporarylocalmatrix.hh:118
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: temporarylocalmatrix.hh:148
MatrixEntriesType fields_
Definition: temporarylocalmatrix.hh:125
void scale(const RangeFieldType &value)
scale matrix with scalar value
Definition: temporarylocalmatrix.hh:199
RowReferenceVector< value_type > row_reference
Definition: temporarylocalmatrix.hh:120
RangeSpaceImp RangeSpaceType
Definition: temporarylocalmatrix.hh:103
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:392
void add(const int localRow, const int localCol, const RangeFieldType &value)
add value to matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:170
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: temporarylocalmatrix.hh:156
size_type cols() const
Definition: temporarylocalmatrix.hh:224
size_type mat_rows() const
Definition: temporarylocalmatrix.hh:228
DomainSpaceImp DomainSpaceType
Definition: temporarylocalmatrix.hh:102
size_type columns() const
Definition: temporarylocalmatrix.hh:225
void set(const int localRow, const int localCol, const RangeFieldType &value)
set value of matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:180
void unbind()
clear local matrix from entities
Definition: temporarylocalmatrix.hh:164
const_row_reference mat_access(size_type i) const
Definition: temporarylocalmatrix.hh:237
RowReferenceVector< const value_type > const_row_reference
Definition: temporarylocalmatrix.hh:121
TemporaryLocalMatrix(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition: temporarylocalmatrix.hh:131
TemporaryLocalMatrixTraits< DomainSpaceType, RangeSpaceType > Traits
Definition: temporarylocalmatrix.hh:106
void clear()
set all entries of local matrix to zero
Definition: temporarylocalmatrix.hh:209
Traits::DomainFieldType DomainFieldType
Definition: temporarylocalmatrix.hh:114
const RangeFieldType get(const int localRow, const int localCol) const
get value of matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:190
int size_type
Definition: temporarylocalmatrix.hh:117
std::vector< RangeFieldType > MatrixEntriesType
Definition: temporarylocalmatrix.hh:123
size_type rows() const
Definition: temporarylocalmatrix.hh:223
Traits::RangeFieldType RangeFieldType
Definition: temporarylocalmatrix.hh:115
row_reference mat_access(size_type i)
Definition: temporarylocalmatrix.hh:231
TemporaryLocalMatrix(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
Definition: temporarylocalmatrix.hh:138
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:386
void clearRow(const int localRow)
set row to zero values
Definition: temporarylocalmatrix.hh:215
size_type mat_cols() const
Definition: temporarylocalmatrix.hh:229
Definition: temporarylocalmatrix.hh:32
RangeFieldType LittleBlockType
Definition: temporarylocalmatrix.hh:41
RangeSpaceImp RangeSpaceType
Definition: temporarylocalmatrix.hh:34
TemporaryLocalMatrix< DomainSpaceType, RangeSpaceType > LocalMatrixType
Definition: temporarylocalmatrix.hh:37
DomainSpaceImp DomainSpaceType
Definition: temporarylocalmatrix.hh:33
DomainSpaceType::RangeFieldType DomainFieldType
Definition: temporarylocalmatrix.hh:39
RangeSpaceType::RangeFieldType RangeFieldType
Definition: temporarylocalmatrix.hh:40
Fem::TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp >::RangeFieldType value_type
Definition: temporarylocalmatrix.hh:56
Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > derived_type
Definition: temporarylocalmatrix.hh:54
DynamicVector< value_type > row_type
Definition: temporarylocalmatrix.hh:59
Fem::RowReferenceVector< const value_type > const_row_reference
Definition: temporarylocalmatrix.hh:62
Fem::RowReferenceVector< value_type > row_reference
Definition: temporarylocalmatrix.hh:61
DenseMatrix based on std::vector< std::vector< T > >
Definition: blockmatrix.hh:24
Definition: rowreferencevector.hh:56