/usr/include/dune/localfunctions/utility/coeffmatrix.hh is in libdune-localfunctions-dev 2.2.1-2.
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | #ifndef DUNE_COEFFMATRIX_HH
#define DUNE_COEFFMATRIX_HH
#include <cassert>
#include <iostream>
#include <vector>
#include <dune/common/fvector.hh>
#include <dune/localfunctions/utility/field.hh>
#include <dune/localfunctions/utility/tensor.hh>
namespace Dune
{
/*************************************************
* Default class for storing a coefficient matrix
* for the PolynomialBasis. Basically a simple
* CRS structure is used. The additional complexity
* is due to the storage and efficient evaluation
* of higher order derivatives. See the remarks
* in tensor.hh which also hold true for this file.
*************************************************/
template <class Field, class Field2>
struct Mult
{
typedef Field2 BasisEntry;
static void add(const Field &vec1, const BasisEntry &vec2,
BasisEntry &res)
{
res += vec1*vec2;
}
};
template <class Field,class Field2, int dimRange>
struct Mult< Field,FieldVector<Field2,dimRange> >
{
typedef FieldVector<Field2,dimRange> BasisEntry;
static void add(const Field &vec1, const BasisEntry &vec2,
BasisEntry &res)
{
res.axpy(vec1,vec2);
}
};
template< class F , unsigned int bSize >
class SparseCoeffMatrix
{
public:
typedef F Field;
static const unsigned int blockSize = bSize;
typedef SparseCoeffMatrix<Field,blockSize> This;
SparseCoeffMatrix()
: coeff_(0),
rows_(0),
skip_(0),
numRows_(0),
numCols_(0)
{}
~SparseCoeffMatrix()
{
delete [] coeff_;
delete [] rows_;
delete [] skip_;
}
const unsigned int size () const
{
return numRows_/blockSize;
}
const unsigned int baseSize () const
{
return numCols_;
}
template< class BasisIterator, class FF>
void mult ( const BasisIterator &x,
unsigned int numLsg,
FF *y ) const
{
typedef typename BasisIterator::Derivatives XDerivatives;
assert( numLsg*blockSize <= (size_t)numRows_ );
unsigned int row = 0;
Field *pos = rows_[ 0 ];
unsigned int *skipIt = skip_;
XDerivatives val;
for( size_t i = 0; i < numLsg; ++i)
{
for( unsigned int r = 0; r < blockSize; ++r, ++row )
{
val = 0;
BasisIterator itx = x;
for( ; pos != rows_[ row+1 ]; ++pos, ++skipIt )
{
itx += *skipIt;
val.axpy(*pos,*itx);
}
DerivativeAssign<XDerivatives,FF>::apply(r,val,*(y+i*XDerivatives::size*blockSize));
}
}
}
template< class BasisIterator, class Vector>
void mult ( const BasisIterator &x,
Vector &y ) const
{
typedef typename Vector::value_type YDerivatives;
typedef typename BasisIterator::Derivatives XDerivatives;
size_t numLsg = y.size();
assert( numLsg*blockSize <= (size_t)numRows_ );
unsigned int row = 0;
Field *pos = rows_[ 0 ];
unsigned int *skipIt = skip_;
XDerivatives val;
for( size_t i = 0; i < numLsg; ++i)
{
for( unsigned int r = 0; r < blockSize; ++r, ++row )
{
val = 0;
BasisIterator itx = x;
for( ; pos != rows_[ row+1 ]; ++pos, ++skipIt )
{
itx += *skipIt;
val.axpy(*pos,*itx);
}
DerivativeAssign<XDerivatives,YDerivatives>::apply(r,val,y[i]);
}
}
}
template <unsigned int deriv, class BasisIterator, class Vector>
void mult ( const BasisIterator &x,
Vector &y ) const
{
typedef typename Vector::value_type YDerivatives;
typedef typename BasisIterator::Derivatives XDerivatives;
typedef FieldVector<typename XDerivatives::Field,YDerivatives::dimension> XLFETensor;
size_t numLsg = y.size();
assert( numLsg*blockSize <= (size_t)numRows_ );
unsigned int row = 0;
Field *pos = rows_[ 0 ];
unsigned int *skipIt = skip_;
for( size_t i = 0; i < numLsg; ++i)
{
XLFETensor val(typename XDerivatives::Field(0));
for( unsigned int r = 0; r < blockSize; ++r, ++row )
{
BasisIterator itx = x;
for( ; pos != rows_[ row+1 ]; ++pos, ++skipIt )
{
itx += *skipIt;
LFETensorAxpy<XDerivatives,XLFETensor,deriv>::apply(r,*pos,*itx,val);
}
}
field_cast(val,y[i]);
}
}
template< class RowMatrix >
void fill ( const RowMatrix &mat, bool verbose=false )
{
numRows_ = mat.rows();
numCols_ = mat.cols();
unsigned int size = numRows_*numCols_;
delete [] coeff_;
delete [] rows_;
delete [] skip_;
Field* coeff = new Field[ size ];
// we always initialize the next skip entry to zero,
// including the one following the end, so allocate
// size+1 entries so we will stay within the bounds.
unsigned int *skip = new unsigned int[ size+1 ];
rows_ = new Field*[ numRows_+1 ];
std::vector<Field> row( numCols_ );
rows_[ 0 ] = coeff;
Field *cit = coeff;
unsigned int *sit = skip;
for( unsigned int r = 0; r < numRows_; ++r )
{
*sit = 0;
mat.row( r, row );
for( unsigned int c = 0; c < numCols_; ++c )
{
const Field &val = row[c];
if (val < Zero<Field>() || Zero<Field>() < val)
{
*cit = val;
++sit;
++cit;
*sit = 1;
} else
{
++(*sit);
}
}
rows_[ r+1 ] = cit;
}
assert( size_t(rows_[numRows_]-rows_[0]) <= size_t(size) );
size = rows_[numRows_]-rows_[0];
coeff_ = new Field[ size ];
skip_ = new unsigned int[ size ];
for (unsigned int i=0;i<size;++i)
{
coeff_[i] = coeff[i];
skip_[i] = skip[i];
}
for (unsigned int i=0;i<=numRows_;++i)
rows_[ i ] = coeff_ + (rows_[ i ] - coeff);
delete [] coeff;
delete [] skip;
if (verbose)
std::cout << "Entries: " << (rows_[numRows_]-rows_[0])
<< " full: " << numCols_*numRows_
<< std::endl;
}
// b += a*C[k]
template <class Vector>
void addRow( unsigned int k, const Field &a, Vector &b) const
{
assert(k<numRows_);
unsigned int j=0;
unsigned int *skipIt = skip_ + (rows_[ k ]-rows_[ 0 ]);
for( Field *pos = rows_[ k ];
pos != rows_[ k+1 ];
++pos, ++skipIt )
{
j += *skipIt;
assert( j < b.size() );
b[j] += field_cast<typename Vector::value_type>( (*pos)*a ); // field_cast
}
}
private:
SparseCoeffMatrix ( const This &other )
: numRows_( other.numRows_ ),
numCols_( other.numCols_ )
{
const unsigned int size = other.rows_[numRows_]-other.rows_[0];
coeff_ = new Field[ size ];
rows_ = new Field*[ numRows_+1 ];
skip_ = new unsigned int[ size ];
for (unsigned int i=0;i<size;++i)
{
coeff_[i] = other.coeff_[i];
skip_[i] = other.skip_[i];
}
for (unsigned int i=0;i<=numRows_;++i)
rows_[ i ] = coeff_ + (other.rows_[ i ] - other.coeff_);
}
This &operator= (const This&);
Field *coeff_;
Field **rows_;
unsigned int *skip_;
unsigned int numRows_,numCols_;
};
}
#endif // DUNE_COEFFMATRIX_HH
|