3#ifndef DUNE_BASISMATRIX_HH
4#define DUNE_BASISMATRIX_HH
9#include <dune/localfunctions/utility/lfematrix.hh>
10#include <dune/localfunctions/utility/monomialbasis.hh>
11#include <dune/localfunctions/utility/polynomialbasis.hh>
23 template<
class PreBasis,
class Interpolation,
27 template<
class PreBasis,
class Interpolation,
29 struct BasisMatrixBase :
public LFEMatrix<Field>
31 typedef LFEMatrix<Field> Matrix;
33 BasisMatrixBase(
const PreBasis& preBasis,
34 const Interpolation& localInterpolation )
35 : cols_(preBasis.size())
37 localInterpolation.interpolate( preBasis, *
this );
39 if ( !Matrix::invert() )
41 DUNE_THROW(MathError,
"While computing basis a singular matrix was constructed!");
44 unsigned int cols ()
const
48 unsigned int rows ()
const
50 return Matrix::rows();
56 template<
class Topology,
class F,
59 struct BasisMatrix< const MonomialBasis< Topology, F >, Interpolation, Field >
60 :
public BasisMatrixBase< const MonomialBasis< Topology, F >, Interpolation, Field >
62 typedef const MonomialBasis< Topology, F > PreBasis;
63 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
64 typedef typename Base::Matrix Matrix;
66 BasisMatrix(
const PreBasis& preBasis,
67 const Interpolation& localInterpolation )
68 : Base(preBasis, localInterpolation)
70 template <
class Vector>
71 void row(
const unsigned int row, Vector &vec )
const
73 const unsigned int N = Matrix::rows();
74 assert( Matrix::cols() == N && vec.size() == N );
77 for (
unsigned int i=0; i<N; ++i)
81 template<
int dim,
class F,
84 struct BasisMatrix< const
Dune::VirtualMonomialBasis< dim, F >, Interpolation, Field >
85 :
public BasisMatrixBase< const VirtualMonomialBasis< dim, F >, Interpolation, Field >
87 typedef const VirtualMonomialBasis< dim, F > PreBasis;
88 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
89 typedef typename Base::Matrix Matrix;
91 BasisMatrix(
const PreBasis& preBasis,
92 const Interpolation& localInterpolation )
93 : Base(preBasis, localInterpolation)
95 template <
class Vector>
96 void row(
const unsigned int row, Vector &vec )
const
98 const unsigned int N = Matrix::rows();
99 assert( Matrix::cols() == N && vec.size() == N );
102 for (
unsigned int i=0; i<N; ++i)
106 template<
class Eval,
class CM,
class D,
class R,
109 struct BasisMatrix< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
110 :
public BasisMatrixBase< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
112 typedef const PolynomialBasis<Eval,CM,D,R> PreBasis;
113 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
114 typedef typename Base::Matrix Matrix;
116 BasisMatrix(
const PreBasis& preBasis,
117 const Interpolation& localInterpolation )
118 : Base(preBasis, localInterpolation),
121 unsigned int cols()
const
123 return preBasis_.matrix().baseSize() ;
125 template <
class Vector>
126 void row(
const unsigned int row, Vector &vec )
const
128 assert( Matrix::rows() == Matrix::cols() );
129 assert( vec.size() == preBasis_.matrix().baseSize() );
130 assert( Matrix::cols() == preBasis_.size() );
131 for (
unsigned int j=0; j<Matrix::cols(); ++j)
133 for (
unsigned int i=0; i<Matrix::rows(); ++i)
135 addRow(i,Base::Matrix::operator()(i,row),vec);
138 const PreBasis& preBasis_;
140 template<
class Eval,
class CM,
143 struct BasisMatrix< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
144 :
public BasisMatrixBase< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
146 typedef const PolynomialBasisWithMatrix<Eval,CM> PreBasis;
147 typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
148 typedef typename Base::Matrix Matrix;
150 BasisMatrix(
const PreBasis& preBasis,
151 const Interpolation& localInterpolation )
152 : Base(preBasis, localInterpolation),
155 unsigned int cols()
const
157 return preBasis_.matrix().baseSize() ;
159 unsigned int rows ()
const
161 assert( Matrix::rows() == preBasis_.matrix().size() );
162 return preBasis_.matrix().size()*CM::blockSize ;
164 template <
class Vector>
165 void row(
const unsigned int row, Vector &vec )
const
167 unsigned int r = row / CM::blockSize;
168 assert( r < Matrix::rows() );
169 assert( Matrix::rows() == Matrix::cols() );
170 assert( vec.size() == preBasis_.matrix().baseSize() );
171 assert( Matrix::cols() == preBasis_.size() );
172 for (
unsigned int j=0; j<vec.size(); ++j)
174 for (
unsigned int i=0; i<Matrix::rows(); ++i)
176 addRow(i*CM::blockSize+row%CM::blockSize,Base::Matrix::operator()(i,r),vec);
179 const PreBasis& preBasis_;
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157