/usr/include/dune/localfunctions/utility/basismatrix.hh is in libdune-localfunctions-dev 2.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_BASISMATRIX_HH
#define DUNE_BASISMATRIX_HH
#include <fstream>
#include <dune/common/exceptions.hh>
#include <dune/localfunctions/utility/lfematrix.hh>
#include <dune/localfunctions/utility/monomialbasis.hh>
#include <dune/localfunctions/utility/polynomialbasis.hh>
namespace Dune
{
/****************************************
* A dense matrix representation of a ''polynomial''
* basis. Its represent a basis as a linear
* combination of a second basis, i.e., a
* monomial basis. It is simular to the PolynomialBasis
* but it not derived from the LocalBasis class.
* It is used to define a ''pre basis''.
****************************************/
template< class PreBasis, class Interpolation,
class Field >
struct BasisMatrix;
template< class PreBasis, class Interpolation,
class Field >
struct BasisMatrixBase : public LFEMatrix<Field>
{
typedef LFEMatrix<Field> Matrix;
BasisMatrixBase( const PreBasis& preBasis,
const Interpolation& localInterpolation )
: cols_(preBasis.size())
{
localInterpolation.interpolate( preBasis, *this );
if ( !Matrix::invert() )
{
DUNE_THROW(MathError, "While computing basis a singular matrix was constructed!");
}
}
unsigned int cols () const
{
return cols_;
}
unsigned int rows () const
{
return Matrix::rows();
}
private:
unsigned int cols_;
};
template< class Topology, class F,
class Interpolation,
class Field >
struct BasisMatrix< const MonomialBasis< Topology, F >, Interpolation, Field >
: public BasisMatrixBase< const MonomialBasis< Topology, F >, Interpolation, Field >
{
typedef const MonomialBasis< Topology, F > PreBasis;
typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
typedef typename Base::Matrix Matrix;
BasisMatrix( const PreBasis& preBasis,
const Interpolation& localInterpolation )
: Base(preBasis, localInterpolation)
{}
template <class Vector>
void row( const unsigned int row, Vector &vec ) const
{
const unsigned int N = Matrix::rows();
assert( Matrix::cols() == N && vec.size() == N );
// note: that the transposed matrix is computed,
// and is square
for (unsigned int i=0; i<N; ++i)
field_cast(Matrix::operator()(i,row),vec[i]);
}
};
template< int dim, class F,
class Interpolation,
class Field >
struct BasisMatrix< const Dune::VirtualMonomialBasis< dim, F >, Interpolation, Field >
: public BasisMatrixBase< const VirtualMonomialBasis< dim, F >, Interpolation, Field >
{
typedef const VirtualMonomialBasis< dim, F > PreBasis;
typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
typedef typename Base::Matrix Matrix;
BasisMatrix( const PreBasis& preBasis,
const Interpolation& localInterpolation )
: Base(preBasis, localInterpolation)
{}
template <class Vector>
void row( const unsigned int row, Vector &vec ) const
{
const unsigned int N = Matrix::rows();
assert( Matrix::cols() == N && vec.size() == N );
// note: that the transposed matrix is computed,
// and is square
for (unsigned int i=0; i<N; ++i)
field_cast(Matrix::operator()(i,row),vec[i]);
}
};
template< class Eval, class CM, class D, class R,
class Interpolation,
class Field >
struct BasisMatrix< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
: public BasisMatrixBase< const PolynomialBasis<Eval,CM,D,R>, Interpolation, Field >
{
typedef const PolynomialBasis<Eval,CM,D,R> PreBasis;
typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
typedef typename Base::Matrix Matrix;
BasisMatrix( const PreBasis& preBasis,
const Interpolation& localInterpolation )
: Base(preBasis, localInterpolation),
preBasis_(preBasis)
{}
unsigned int cols() const
{
return preBasis_.matrix().baseSize() ;
}
template <class Vector>
void row( const unsigned int row, Vector &vec ) const
{
assert( Matrix::rows() == Matrix::cols() );
assert( vec.size() == preBasis_.matrix().baseSize() );
assert( Matrix::cols() == preBasis_.size() );
for (unsigned int j=0; j<Matrix::cols(); ++j)
vec[j] = 0;
for (unsigned int i=0; i<Matrix::rows(); ++i)
preBasis_.matrix().
addRow(i,Base::Matrix::operator()(i,row),vec);
}
private:
const PreBasis& preBasis_;
};
template< class Eval, class CM,
class Interpolation,
class Field >
struct BasisMatrix< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
: public BasisMatrixBase< const PolynomialBasisWithMatrix<Eval,CM>, Interpolation, Field >
{
typedef const PolynomialBasisWithMatrix<Eval,CM> PreBasis;
typedef BasisMatrixBase<PreBasis,Interpolation,Field> Base;
typedef typename Base::Matrix Matrix;
BasisMatrix( const PreBasis& preBasis,
const Interpolation& localInterpolation )
: Base(preBasis, localInterpolation),
preBasis_(preBasis)
{}
unsigned int cols() const
{
return preBasis_.matrix().baseSize() ;
}
unsigned int rows () const
{
assert( Matrix::rows() == preBasis_.matrix().size() );
return preBasis_.matrix().size()*CM::blockSize ;
}
template <class Vector>
void row( const unsigned int row, Vector &vec ) const
{
unsigned int r = row / CM::blockSize;
assert( r < Matrix::rows() );
assert( Matrix::rows() == Matrix::cols() );
assert( vec.size() == preBasis_.matrix().baseSize() );
assert( Matrix::cols() == preBasis_.size() );
for (unsigned int j=0; j<vec.size(); ++j)
vec[j] = 0;
for (unsigned int i=0; i<Matrix::rows(); ++i)
preBasis_.matrix().
addRow(i*CM::blockSize+row%CM::blockSize,Base::Matrix::operator()(i,r),vec);
}
private:
const PreBasis& preBasis_;
};
}
#endif // DUNE_BASISMATRIX_HH
|