1 #ifndef DUNE_FEM_DENSEMATRIX_HH 2 #define DUNE_FEM_DENSEMATRIX_HH 60 const Field &
operator() (
const unsigned int row,
const unsigned int col )
const 62 assert( (row <
rows()) && (col <
cols()) );
63 return fields_[ row*
cols() + col ];
66 Field &
operator() (
const unsigned int row,
const unsigned int col )
68 assert( (row <
rows()) && (col <
cols()) );
69 return fields_[ row*
cols() + col ];
72 void add(
const unsigned int row,
const unsigned int col,
const Field& value )
74 assert( (row <
rows()) && (col <
cols()) );
75 fields_[ row*
cols() + col ] += value;
78 Row< const Field >
operator[] (
const unsigned int row )
const 80 assert( row <
rows() );
81 return Row< const Field >(
cols(), fields_ + row*
cols() );
86 assert( row <
rows() );
87 return Row< Field >(
cols(), fields_ + row*
cols() );
92 Field *end = fields_ + (rows_*cols_);
93 for( Field *it = fields_; it != end; ++it )
97 void multiply (
const Field *x, Field *y )
const 99 for(
unsigned int row = 0; row <
rows(); ++row )
101 const Field *fields = fields_ + row*
cols();
102 y[ row ] =
Field( 0 );
103 for(
unsigned int col = 0; col <
cols(); ++col )
104 y[ row ] += fields[ col ] * x[ col ];
110 if( (rows != rows_) || (cols != cols_) )
113 fields_ =
new Field[ rows*
cols ];
124 for(
unsigned int row = 0; row <
rows(); ++row )
126 const Field *fields = fields_ + row*
cols();
127 for(
unsigned int col = 0; col <
cols(); ++col )
128 s << fields[ col ] <<
" ";
151 template<
class >
friend class Row;
160 : cols_( row.cols_ ),
161 fields_( row.fields_ )
166 assert( col < size() );
167 return fields_[ col ];
172 assert( col < size() );
173 return fields_[ col ];
178 Field *
const end = fields_ + size();
179 for(
Field *it = fields_; it != end; ++it )
198 template<
class DomainSpace,
class RangeSpace >
208 typedef typename RangeSpaceType::RangeFieldType
Field;
210 typedef typename DomainSpace::GridType::template Codim< 0 >::Entity
ColEntityType;
211 typedef typename RangeSpace::GridType::template Codim< 0 >::Entity
RowEntityType;
226 const RangeSpaceType &rangeSpace )
227 : domainSpace_( domainSpace ),
228 rangeSpace_( rangeSpace ),
229 domainSequence_( -1 ),
230 rangeSequence_( -1 ),
231 localMatrixFactory_( *this ),
232 localMatrixStack_( localMatrixFactory_ )
241 const ColEntityType &colEntity )
243 return LocalMatrixType( localMatrixStack_, rowEntity, colEntity );
251 template<
class Stencil >
254 if( (domainSequence_ != domainSpace().sequence()) || (rangeSequence_ != rangeSpace().sequence()) )
256 matrix_.reserve( rangeSpace().size(), domainSpace().size() );
257 domainSequence_ = domainSpace().sequence();
258 rangeSequence_ = rangeSpace().sequence();
262 template<
class DomainFunction,
class RangeFunction >
263 void apply (
const DomainFunction &u, RangeFunction &w )
const 265 matrix_.multiply( u.leakPointer(), w.leakPointer() );
266 rangeSpace().communicate( w );
269 Field
ddotOEM (
const Field *v,
const Field *w )
const 272 RangeFunction vFunction(
"v (ddotOEM)", rangeSpace(), v );
273 RangeFunction wFunction(
"w (ddotOEM)", rangeSpace(), w );
274 return vFunction.scalarProductDofs( wFunction );
277 void multOEM (
const Field *u, Field *w )
const 279 matrix_.multiply( u, w );
282 RangeFunction wFunction(
"w (multOEM)", rangeSpace(), w );
283 rangeSpace().communicate( wFunction );
297 const DomainSpaceType &domainSpace_;
298 const RangeSpaceType &rangeSpace_;
306 mutable LocalMatrixStack localMatrixStack_;
314 template<
class DomainSpace,
class RangeSpace >
334 template<
class DomainSpace,
class RangeSpace >
355 : BaseType( domainSpace, rangeSpace ),
361 ThisType &operator= (
const ThisType & );
366 BaseType::init( rowEntity, colEntity );
368 map( rangeSpace().mapper(), rowEntity, rowIndices_ );
369 map( domainSpace().mapper(), colEntity, colIndices_ );
374 return rowIndices_.size();
379 return colIndices_.size();
382 void add (
const int row,
const int col,
const DofType &value )
384 assert( (row >= 0) && (row <
rows()) );
385 assert( (col >= 0) && (col <
cols()) );
386 matrix_( rowIndices_[ row ], colIndices_[ col ] ) += value;
389 const DofType &
get (
const int row,
const int col )
const 391 assert( (row >= 0) && (row <
rows()) );
392 assert( (col >= 0) && (col <
cols()) );
393 return matrix_( rowIndices_[ row ], colIndices_[ col ] );
396 void set (
const int row,
const int col,
const DofType &value )
398 assert( (row >= 0) && (row <
rows()) );
399 assert( (col >= 0) && (col <
cols()) );
400 matrix_( rowIndices_[ row ], colIndices_[ col ] ) = value;
405 assert( (row >= 0) && (row <
rows()) );
406 const unsigned int rowIndex = rowIndices_[ row ];
407 matrix_[ rowIndex ].clear();
413 set( row, row, DofType( 1 ) );
418 typedef std::vector< unsigned int >::const_iterator Iterator;
419 const Iterator rowEnd = rowIndices_.end();
420 for( Iterator rowIt = rowIndices_.begin(); rowIt != rowEnd; ++rowIt )
422 const Iterator colEnd = colIndices_.end();
423 for( Iterator colIt = colIndices_.begin(); colIt != colEnd; ++colIt )
424 matrix_( *rowIt, *colIt ) = DofType( 0 );
430 typedef std::vector< unsigned int >::const_iterator Iterator;
431 const Iterator rowEnd = rowIndices_.end();
432 for( Iterator rowIt = rowIndices_.begin(); rowIt != rowEnd; ++rowIt )
434 const Iterator colEnd = colIndices_.end();
435 for( Iterator colIt = colIndices_.begin(); colIt != colEnd; ++colIt )
436 matrix_( *rowIt, *colIt ) *= value;
441 template<
class Mapper,
class Entity >
442 void map (
const Mapper &mapper,
const Entity &entity, std::vector< unsigned int > &indices )
444 indices.resize( mapper.numDofs( entity ) );
445 mapper.mapEach( entity,
Fem::AssignFunctor< std::vector< unsigned int > >( indices ) );
449 using BaseType::domainSpace_;
450 using BaseType::rangeSpace_;
455 std::vector< unsigned int > rowIndices_;
456 std::vector< unsigned int > colIndices_;
464 template<
class DomainSpace,
class RangeSpace >
473 : matrixObject_( &matrixObject )
478 return new ObjectType( matrixObject_->matrix_, matrixObject_->domainSpace_, matrixObject_->rangeSpace_ );
482 MatrixObject *matrixObject_;
489 #endif // #ifndef DUNE_FEM_DENSEMATRIX_HH Traits::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:51
DenseRowMatrix< Field > MatrixType
Definition: densematrix.hh:213
RangeSpace RangeSpaceType
Definition: densematrix.hh:206
const DomainSpace & domainSpace() const
Definition: densematrix.hh:286
MatrixObject::LocalMatrix LocalMatrixType
Definition: densematrix.hh:326
Definition: localmatrixwrapper.hh:16
LocalMatrix(MatrixType &matrix, const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition: densematrix.hh:352
Row(const Row< F > &row)
Definition: densematrix.hh:159
ObjectType * newObject() const
Definition: densematrix.hh:476
Definition: densematrix.hh:21
LocalMatrix ObjectType
Definition: densematrix.hh:470
DenseRowMatrix(unsigned int rows, unsigned int cols)
Definition: densematrix.hh:37
RangeFieldType DofType
Definition: densematrix.hh:350
LocalMatrixWrapper< LocalMatrixStack > LocalMatrixType
Definition: densematrix.hh:223
default implementation for a general operator stencil
Definition: stencil.hh:31
Traits::LittleBlockType LittleBlockType
Definition: densematrix.hh:349
RangeSpace::GridType::template Codim< 0 >::Entity RowEntityType
Definition: densematrix.hh:211
Traits::RangeFieldType RangeFieldType
Definition: densematrix.hh:348
Definition: adaptivefunction/adaptivefunction.hh:34
void add(const int row, const int col, const DofType &value)
Definition: densematrix.hh:382
void clear()
Definition: densematrix.hh:90
MatrixObject::MatrixType MatrixType
Definition: densematrix.hh:346
Default implementation for local matrix classes.
Definition: localmatrix.hh:266
const RangeSpace & rangeSpace() const
Definition: densematrix.hh:291
void apply(const DomainFunction &u, RangeFunction &w) const
Definition: densematrix.hh:263
void print(std::ostream &s) const
Definition: densematrix.hh:121
Interface for local matrix classes.
Definition: localmatrix.hh:28
void clearRow(const int row)
Definition: densematrix.hh:403
Definition: misc/functor.hh:30
LocalMatrixFactory(MatrixObject &matrixObject)
Definition: densematrix.hh:472
int rows() const
Definition: densematrix.hh:372
~DenseRowMatrix()
Definition: densematrix.hh:45
MatrixObject::RangeSpaceType RangeSpaceType
Definition: densematrix.hh:321
void init(const RowEntityType &rowEntity, const ColEntityType &colEntity)
Definition: densematrix.hh:364
LocalMatrixTraits Traits
Definition: densematrix.hh:344
F Field
Definition: densematrix.hh:26
RangeSpaceType::RangeFieldType Field
Definition: densematrix.hh:208
const Field & operator()(const unsigned int row, const unsigned int col) const
Definition: densematrix.hh:60
void reserve(const Stencil &stencil, bool verbose=false)
Definition: densematrix.hh:252
void clear()
Definition: densematrix.hh:416
void reserve(unsigned int rows, unsigned int cols)
Definition: densematrix.hh:108
Definition: coordinate.hh:4
Definition: densematrix.hh:335
unsigned int cols() const
Definition: densematrix.hh:55
Definition: densematrix.hh:29
RangeFieldType LittleBlockType
Definition: densematrix.hh:324
LocalMatrixType localMatrix(const RowEntityType &rowEntity, const ColEntityType &colEntity)
Definition: densematrix.hh:240
DomainSpace DomainSpaceType
Definition: densematrix.hh:205
Row(unsigned int cols, RF *fields)
Definition: densematrix.hh:154
Traits::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:54
MatrixObject::Field RangeFieldType
Definition: densematrix.hh:323
MatrixObject::DomainSpaceType DomainSpaceType
Definition: densematrix.hh:320
unsigned int size() const
Definition: densematrix.hh:183
interface for matrices to be used with OEM sovlers
Definition: oemsolver/oemsolver.hh:31
Definition: densematrix.hh:465
void scale(const DofType &value)
Definition: densematrix.hh:428
Row< const Field > operator[](const unsigned int row) const
Definition: densematrix.hh:78
DomainSpace::GridType::template Codim< 0 >::Entity ColEntityType
Definition: densematrix.hh:210
Definition: densematrix.hh:199
Field ddotOEM(const Field *v, const Field *w) const
Definition: densematrix.hh:269
Definition: densematrix.hh:315
DenseRowMatrix()
Definition: densematrix.hh:31
MatrixType & matrix()
Definition: densematrix.hh:235
void multiply(const Field *x, Field *y) const
Definition: densematrix.hh:97
void unitRow(const int row)
Definition: densematrix.hh:410
void add(const unsigned int row, const unsigned int col, const Field &value)
Definition: densematrix.hh:72
void clear()
Definition: densematrix.hh:246
DenseRowMatrixObject(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition: densematrix.hh:225
void multOEM(const Field *u, Field *w) const
Definition: densematrix.hh:277
void clear()
Definition: densematrix.hh:176
Definition: bartonnackmaninterface.hh:15
unsigned int rows() const
Definition: densematrix.hh:50
int cols() const
Definition: densematrix.hh:377