1#ifndef DUNE_FEM_FIELDMATRIXCONVERTER_HH
2#define DUNE_FEM_FIELDMATRIXCONVERTER_HH
6#include <dune/common/fmatrix.hh>
17 template<
class VectorType,
class ConvertToType >
20 template<
class K,
int m >
23 template<
class K,
int n,
int m >
28 template<
class K,
int n,
int m >
29 struct DenseMatVecTraits< Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > >
32 typedef DenseMatVecTraits< FieldMatrix< K, n, m > >
Traits;
42 template<
class K,
int m >
43 struct DenseMatVecTraits< Fem::FieldMatrixConverterRow< K, m > >
51 template<
class K,
int n,
int m >
52 struct DenseMatVecTraits< Fem::FlatFieldMatrix< K, n, m > >
53 :
public DenseMatVecTraits< Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > >
63 template<
class K,
int m >
65 :
public Dune::DenseVector< FieldMatrixConverterRow< K, m > >
68 typedef Dune::DenseVector< FieldMatrixConverterRow< K, m > > Base;
73 using Base::operator=;
74 using Base::operator*;
88 for(
size_t i = 0; i <
size(); ++i )
89 ptr_[ i ] = other[ i ];
93 template<
class Impl >
96 assert( other.size() ==
size() );
97 for(
size_t i = 0; i <
size(); ++i )
98 ptr_[ i ] = other[ i ];
105 assert(
size() == x.size() );
108 result += ptr_[ i ] * x[ i ];
113 size_t size ()
const {
return m; }
115 const K &
operator[] (
size_t i )
const { assert( i <
size() );
return ptr_[ i ]; }
124 template<
typename K,
int n,
int m >
126 :
public Dune::DenseMatrix< FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > >
128 typedef Dune::DenseMatrix< FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > > Base;
162 , mutableVec_( true )
169 , mutableVec_( false )
176 , mutableVec_( other.mutableVec_ )
182 assert( mutableVec_ );
185 mutableVec_ = other.mutableVec_;
192 assert( mutableVec_ );
193 for(
int i = 0; i<rows; ++i )
195 for(
int j = 0, ij = i * cols; j<cols; ++j, ++ij )
197 (*vec_)[ ij ] = matrix[ i ][ j ];
206 assert( mutableVec_ );
207 for(
int i = 0; i<rows; ++i )
209 for(
int j = 0, ij = i * cols; j<cols; ++j, ++ij )
211 (*vec_)[ ij ] += matrix[ i ][ j ];
224 s << a[ i ][ j ] <<
" ";
253 template<
typename K,
int n,
int m >
255 :
public Dune::DenseMatrix< FlatFieldMatrix< K, n, m > >
257 typedef Dune::DenseMatrix< FlatFieldMatrix< K, n, m > > Base;
324 for(
int i = 0; i<
rows; ++i )
326 for(
int j = 0, ij = i *
cols; j<
cols; ++j, ++ij )
327 data_[ ij ] += other[ i ][ j ];
332 void assign(
const FieldMatrix< K, n, m > &other )
334 for(
int i = 0; i<
rows; ++i )
336 for(
int j = 0, ij = i *
cols; j<
cols; ++j, ++ij )
337 data_[ ij ] = other[ i ][ j ];
367 s << a[ i ][ j ] <<
" ";
383 template <
class K,
int n,
int m,
class Converter>
384 inline void toMatrix( FieldMatrix< K, n, m>& A,
const Converter& B )
386 for(
int i = 0; i < n; ++i )
387 for(
int j = 0; j < m; ++j )
388 A[ i ][ j ] = B[ i ][ j ];
393 template<
class K,
int n,
int m >
394 struct DenseMatrixAssigner< FieldMatrix< K, n, m >,
395 Fem::FieldMatrixConverter< FieldVector< K, n*m >, FieldMatrix< K, n, m > > >
397 static void apply ( FieldMatrix< K, n, m > &A,
400 detail::toMatrix( A, B );
404 template<
class K,
int n,
int m >
405 struct DenseMatrixAssigner< DenseMatrix< FieldMatrix< K, n, m > >,
406 Fem::FieldMatrixConverter< FieldVector< K, n*m >, FieldMatrix< K, n, m > > >
408 static void apply ( DenseMatrix< FieldMatrix< K, n, m > > &A,
411 detail::toMatrix( A, B );
416 template<
class K,
int n,
int m >
417 struct DenseMatrixAssigner< FieldMatrix< K, n, m >, Fem::FlatFieldMatrix< K, n, m > >
419 static void apply ( FieldMatrix< K, n, m > &A,
422 detail::toMatrix( A, B );
426 template<
class K,
int n,
int m >
427 struct DenseMatrixAssigner< DenseMatrix< FieldMatrix< K, n, m > >, Fem::FlatFieldMatrix< K, n, m > >
429 static void apply ( DenseMatrix< FieldMatrix< K, n, m > > &A,
432 detail::toMatrix( A, B );
Definition: bindguard.hh:11
OutStreamInterface< StreamTraits > & operator<<(OutStreamInterface< StreamTraits > &out, const DiscreteFunctionInterface< Impl > &df)
write a discrete function into an output stream
Definition: discretefunction_inline.hh:396
Definition: fmatrixconverter.hh:18
Definition: fmatrixconverter.hh:66
K & operator[](size_t i)
Definition: fmatrixconverter.hh:114
FieldMatrixConverterRow(const This &other)
Definition: fmatrixconverter.hh:82
Base::size_type size_type
Definition: fmatrixconverter.hh:71
FieldMatrixConverterRow & operator=(const This &other)
Definition: fmatrixconverter.hh:86
K operator*(const DenseVector< V > &x) const
Definition: fmatrixconverter.hh:103
size_t size() const
Definition: fmatrixconverter.hh:113
FieldMatrixConverterRow(K *ptr)
Definition: fmatrixconverter.hh:76
Definition: fmatrixconverter.hh:256
Base::row_type row_type
type of class return upon operator [] which behaves like a reference
Definition: fmatrixconverter.hh:264
row_reference mat_access(size_type i)
Definition: fmatrixconverter.hh:348
size_type mat_rows() const
Definition: fmatrixconverter.hh:345
size_type mat_cols() const
Definition: fmatrixconverter.hh:346
K block_type
export the type representing the components
Definition: fmatrixconverter.hh:272
FlatFieldMatrix(const K &val)
Definition: fmatrixconverter.hh:288
FlatFieldMatrix()
Definition: fmatrixconverter.hh:287
void assign(const FieldMatrix< K, n, m > &other)
Definition: fmatrixconverter.hh:332
FlatFieldMatrix & operator=(const FlatFieldMatrix &other)
Definition: fmatrixconverter.hh:304
K * data()
Definition: fmatrixconverter.hh:341
Base::const_row_reference const_row_reference
Definition: fmatrixconverter.hh:266
FlatFieldMatrix(const FlatFieldMatrix &other)
Definition: fmatrixconverter.hh:294
FlatFieldMatrix(const FieldMatrix< K, n, m > &other)
Definition: fmatrixconverter.hh:299
const_row_reference mat_access(size_type i) const
Definition: fmatrixconverter.hh:354
FieldVector< K, n *m > InteralVectorType
internal storage of matrix
Definition: fmatrixconverter.hh:261
FlatFieldMatrix & operator+=(const FieldMatrix< K, n, m > &other)
Definition: fmatrixconverter.hh:322
@ cols
The number of columns.
Definition: fmatrixconverter.hh:281
@ dimension
The total dimension.
Definition: fmatrixconverter.hh:283
@ rows
The number of rows.
Definition: fmatrixconverter.hh:279
const K * data() const
Definition: fmatrixconverter.hh:342
std::size_t size_type
The type used for the index access and size operations.
Definition: fmatrixconverter.hh:275
friend std::ostream & operator<<(std::ostream &s, const FlatFieldMatrix &a)
Sends the matrix to an output stream.
Definition: fmatrixconverter.hh:361
InteralVectorType data_
Definition: fmatrixconverter.hh:374
Base::row_reference row_reference
Definition: fmatrixconverter.hh:265
K field_type
export the type representing the field
Definition: fmatrixconverter.hh:269
Traits::size_type size_type
Definition: fmatrixconverter.hh:35
Traits::container_type container_type
Definition: fmatrixconverter.hh:33
Fem::FieldMatrixConverterRow< K, m > const_row_reference
Definition: fmatrixconverter.hh:39
Traits::row_type row_type
Definition: fmatrixconverter.hh:36
Fem::FieldMatrixConverterRow< K, m > row_reference
Definition: fmatrixconverter.hh:38
DenseMatVecTraits< FieldMatrix< K, n, m > > Traits
Definition: fmatrixconverter.hh:32
Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > derived_type
Definition: fmatrixconverter.hh:31
Traits::value_type value_type
Definition: fmatrixconverter.hh:34
size_t size_type
Definition: fmatrixconverter.hh:48
K * container_type
Definition: fmatrixconverter.hh:46
Fem::FieldMatrixConverterRow< K, m > derived_type
Definition: fmatrixconverter.hh:45
K value_type
Definition: fmatrixconverter.hh:47
FieldMatrixConverter(const FieldMatrixConverter &other)
Definition: fmatrixconverter.hh:173
K block_type
export the type representing the components
Definition: fmatrixconverter.hh:145
FieldMatrixConverter(const InteralVectorType &v)
Definition: fmatrixconverter.hh:166
bool mutableVec_
Definition: fmatrixconverter.hh:249
size_type mat_rows() const
Definition: fmatrixconverter.hh:231
const_row_reference mat_access(size_type i) const
Definition: fmatrixconverter.hh:240
InteralVectorType * vec_
Definition: fmatrixconverter.hh:247
row_reference mat_access(size_type i)
Definition: fmatrixconverter.hh:234
Base::row_reference row_reference
Definition: fmatrixconverter.hh:138
Base::const_row_reference const_row_reference
Definition: fmatrixconverter.hh:139
FieldMatrixConverter(InteralVectorType &v)
Definition: fmatrixconverter.hh:159
std::size_t size_type
The type used for the index access and size operations.
Definition: fmatrixconverter.hh:148
size_type mat_cols() const
Definition: fmatrixconverter.hh:232
K field_type
export the type representing the field
Definition: fmatrixconverter.hh:142
FieldVector< K, n *m > InteralVectorType
internal storage of matrix
Definition: fmatrixconverter.hh:132
Base::row_type row_type
type of class return upon operator [] which behaves like a reference
Definition: fmatrixconverter.hh:137
static void apply(FieldMatrix< K, n, m > &A, const Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > &B)
Definition: fmatrixconverter.hh:397
static void apply(DenseMatrix< FieldMatrix< K, n, m > > &A, const Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > &B)
Definition: fmatrixconverter.hh:408
static void apply(FieldMatrix< K, n, m > &A, const Fem::FlatFieldMatrix< K, n, m > &B)
Definition: fmatrixconverter.hh:419
static void apply(DenseMatrix< FieldMatrix< K, n, m > > &A, const Fem::FlatFieldMatrix< K, n, m > &B)
Definition: fmatrixconverter.hh:429