5#ifndef DUNE_BASISMATRIX_HH
6#define DUNE_BASISMATRIX_HH
11#include <dune/localfunctions/utility/lfematrix.hh>
12#include <dune/localfunctions/utility/monomialbasis.hh>
13#include <dune/localfunctions/utility/polynomialbasis.hh>
25 template<
class PreBasis,
class Interpolation,
29 template<
class PreBasis,
class Interpolation,
31 struct BasisMatrixBase :
public LFEMatrix<Field>
33 typedef LFEMatrix<Field> Matrix;
35 BasisMatrixBase(
const PreBasis& preBasis,
36 const Interpolation& localInterpolation )
37 : cols_(preBasis.size())
39 localInterpolation.interpolate( preBasis, *
this );
41 if ( !Matrix::invert() )
43 DUNE_THROW(MathError,
"While computing basis a singular matrix was constructed!");
46 unsigned int cols ()
const
50 unsigned int rows ()
const
52 return Matrix::rows();
61 struct BasisMatrix< const MonomialBasis< geometryId, F >, Interpolation, Field >
62 :
public BasisMatrixBase< const MonomialBasis< geometryId, F >, Interpolation, Field >
64 typedef const MonomialBasis< geometryId, F > PreBasis;
65 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
66 typedef typename Base::Matrix Matrix;
68 BasisMatrix(
const PreBasis& preBasis,
69 const Interpolation& localInterpolation )
70 : Base(preBasis, localInterpolation)
72 template <
class Vector>
73 void row(
const unsigned int row, Vector &vec )
const
75 const unsigned int N = Matrix::rows();
76 assert( Matrix::cols() == N && vec.size() == N );
79 for (
unsigned int i=0; i<N; ++i)
83 template<
int dim,
class F,
86 struct BasisMatrix< const
Dune::VirtualMonomialBasis< dim, F >, Interpolation, Field >
87 :
public BasisMatrixBase< const VirtualMonomialBasis< dim, F >, Interpolation, Field >
89 typedef const VirtualMonomialBasis< dim, F > PreBasis;
90 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
91 typedef typename Base::Matrix Matrix;
93 BasisMatrix(
const PreBasis& preBasis,
94 const Interpolation& localInterpolation )
95 : Base(preBasis, localInterpolation)
97 template <
class Vector>
98 void row(
const unsigned int row, Vector &vec )
const
100 const unsigned int N = Matrix::rows();
101 assert( Matrix::cols() == N && vec.size() == N );
104 for (
unsigned int i=0; i<N; ++i)
108 template<
class Eval,
class CM,
class D,
class R,
111 struct BasisMatrix< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
112 :
public BasisMatrixBase< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
114 typedef const PolynomialBasis<Eval,CM,D,R> PreBasis;
115 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
116 typedef typename Base::Matrix Matrix;
118 BasisMatrix(
const PreBasis& preBasis,
119 const Interpolation& localInterpolation )
120 : Base(preBasis, localInterpolation),
123 unsigned int cols()
const
125 return preBasis_.matrix().baseSize() ;
127 template <
class Vector>
128 void row(
const unsigned int row, Vector &vec )
const
130 assert( Matrix::rows() == Matrix::cols() );
131 assert( vec.size() == preBasis_.matrix().baseSize() );
132 assert( Matrix::cols() == preBasis_.size() );
133 for (
unsigned int j=0; j<Matrix::cols(); ++j)
135 for (
unsigned int i=0; i<Matrix::rows(); ++i)
137 addRow(i,Base::Matrix::operator()(i,row),vec);
140 const PreBasis& preBasis_;
142 template<
class Eval,
class CM,
145 struct BasisMatrix< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
146 :
public BasisMatrixBase< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
148 typedef const PolynomialBasisWithMatrix<Eval,CM> PreBasis;
149 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
150 typedef typename Base::Matrix Matrix;
152 BasisMatrix(
const PreBasis& preBasis,
153 const Interpolation& localInterpolation )
154 : Base(preBasis, localInterpolation),
157 unsigned int cols()
const
159 return preBasis_.matrix().baseSize() ;
161 unsigned int rows ()
const
163 assert( Matrix::rows() == preBasis_.matrix().size() );
164 return preBasis_.matrix().size()*CM::blockSize ;
166 template <
class Vector>
167 void row(
const unsigned int row, Vector &vec )
const
169 unsigned int r = row / CM::blockSize;
170 assert( r < Matrix::rows() );
171 assert( Matrix::rows() == Matrix::cols() );
172 assert( vec.size() == preBasis_.matrix().baseSize() );
173 assert( Matrix::cols() == preBasis_.size() );
174 for (
unsigned int j=0; j<vec.size(); ++j)
176 for (
unsigned int i=0; i<Matrix::rows(); ++i)
178 addRow(i*CM::blockSize+row%CM::blockSize,Base::Matrix::operator()(i,r),vec);
181 const PreBasis& preBasis_;
IdType Id
An integral id representing a GeometryType.
Definition: type.hh:193
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:159