DUNE-FEM (unstable)

temporarylocalmatrix.hh
1#ifndef DUNE_FEM_TEMPORARYLOCALMATRIX_HH
2#define DUNE_FEM_TEMPORARYLOCALMATRIX_HH
3
4#include <algorithm>
5#include <vector>
6
9
10#include <dune/fem/operator/common/localmatrix.hh>
11#include <dune/fem/storage/rowreferencevector.hh>
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 >
31 struct TemporaryLocalMatrixTraits
32 {
33 typedef DomainSpaceImp DomainSpaceType;
34 typedef RangeSpaceImp RangeSpaceType;
35
36 typedef TemporaryLocalMatrix< DomainSpaceType, RangeSpaceType >
37 LocalMatrixType;
38
39 typedef typename DomainSpaceType :: RangeFieldType DomainFieldType;
40 typedef typename RangeSpaceType :: RangeFieldType RangeFieldType;
41 typedef RangeFieldType LittleBlockType;
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 {
54 typedef Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > derived_type;
55
56 typedef typename Fem::TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp >::RangeFieldType value_type;
57 typedef int size_type;
58
59 typedef DynamicVector< value_type > row_type;
60
61 typedef Fem::RowReferenceVector< value_type > row_reference;
62 typedef Fem::RowReferenceVector< const value_type > const_row_reference;
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
105 typedef TemporaryLocalMatrixTraits< DomainSpaceType, RangeSpaceType >
106 Traits;
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;
118 typedef RangeFieldType value_type;
119
120 typedef RowReferenceVector< value_type > row_reference;
121 typedef RowReferenceVector< const value_type > const_row_reference;
122
123 typedef std::vector< RangeFieldType > MatrixEntriesType;
124 protected:
125 MatrixEntriesType fields_;
126
127 public:
130
131 inline TemporaryLocalMatrix ( const DomainSpaceType &domainSpace,
132 const RangeSpaceType &rangeSpace )
134 fields_()
135 {}
136
137 template< class DomainEntityType, class RangeEntityType >
138 inline TemporaryLocalMatrix ( const DomainSpaceType &domainSpace,
139 const RangeSpaceType &rangeSpace,
140 const DomainEntityType &domainEntity,
141 const RangeEntityType &rangeEntity )
142 : BaseType( domainSpace, rangeSpace, domainEntity, rangeEntity ),
143 fields_( rows() * columns() )
144 {}
145
147 template< class DomainEntityType, class RangeEntityType >
148 inline void init ( const DomainEntityType &domainEntity,
149 const RangeEntityType &rangeEntity )
150 {
151 bind( domainEntity, rangeEntity );
152 }
153
155 template< class DomainEntityType, class RangeEntityType >
156 inline void bind ( const DomainEntityType &domainEntity,
157 const RangeEntityType &rangeEntity )
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
231 row_reference mat_access ( size_type i )
232 {
233 const size_type cols = mat_cols();
234 return row_reference( fields_.data() + i*cols, cols );
235 }
236
237 const_row_reference mat_access ( size_type i ) const
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 void print( std::ostream& out ) const
247 {
248 out << "TLM ("<<rows ()<<","<<cols()<<"):"<<std::endl;
249 for( size_type r = 0; r<rows(); ++r )
250 {
251 for( size_type c = 0; c<cols(); ++c )
252 {
253 out << get( r , c ) << " ";
254 }
255 out << std::endl;
256 }
257 out << std::endl << std::endl;
258 }
259
260 };
261
262 } // namespace Fem
263
264} // namespace Dune
265
266#endif // #ifndef DUNE_FEM_TEMPORARYLOCALMATRIX_HH
DenseMatrix based on std::vector< std::vector< T > >
Definition: blockmatrix.hh:24
Default implementation for local matrix classes.
Definition: localmatrix.hh:287
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:352
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:394
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:385
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:361
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:382
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:388
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: temporarylocalmatrix.hh:148
void scale(const RangeFieldType &value)
scale matrix with scalar value
Definition: temporarylocalmatrix.hh:199
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:394
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
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
void clear()
set all entries of local matrix to zero
Definition: temporarylocalmatrix.hh:209
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
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:388
void clearRow(const int localRow)
set row to zero values
Definition: temporarylocalmatrix.hh:215
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
This file implements a dense vector with a dynamic size.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)