5#ifndef DUNE_ISTL_SCALEDIDMATRIX_HH
6#define DUNE_ISTL_SCALEDIDMATRIX_HH
18#include <dune/common/exceptions.hh>
19#include <dune/common/fmatrix.hh>
20#include <dune/common/diagonalmatrix.hh>
21#include <dune/common/ftraits.hh>
28 template<
class K,
int n>
31 typedef DiagonalMatrixWrapper< ScaledIdentityMatrix<K,n> > WrapperType;
80 return (
this==&other);
85 typedef ContainerWrapperIterator<const WrapperType, reference, reference>
Iterator;
96 return Iterator(WrapperType(
this),0);
102 return Iterator(WrapperType(
this),n);
109 return Iterator(WrapperType(
this),n-1);
116 return Iterator(WrapperType(
this),-1);
121 typedef ContainerWrapperIterator<const WrapperType, const_reference, const_reference>
ConstIterator;
201 template <
class Scalar,
202 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
209 template <
class Scalar,
210 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
221 return p_==other.
scalar();
227 return p_!=other.
scalar();
233 template<
class X,
class Y>
234 void mv (
const X& x, Y& y)
const
236#ifdef DUNE_FMatrix_WITH_CHECKING
237 if (x.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
238 if (y.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
245 template<
class X,
class Y>
246 void mtv (
const X& x, Y& y)
const
252 template<
class X,
class Y>
253 void umv (
const X& x, Y& y)
const
255#ifdef DUNE_FMatrix_WITH_CHECKING
256 if (x.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
257 if (y.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
264 template<
class X,
class Y>
265 void umtv (
const X& x, Y& y)
const
267#ifdef DUNE_FMatrix_WITH_CHECKING
268 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
269 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
276 template<
class X,
class Y>
277 void umhv (
const X& x, Y& y)
const
279#ifdef DUNE_FMatrix_WITH_CHECKING
280 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
281 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
284 y[i] += conjugateComplex(p_)*x[i];
288 template<
class X,
class Y>
289 void mmv (
const X& x, Y& y)
const
291#ifdef DUNE_FMatrix_WITH_CHECKING
292 if (x.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
293 if (y.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
300 template<
class X,
class Y>
301 void mmtv (
const X& x, Y& y)
const
303#ifdef DUNE_FMatrix_WITH_CHECKING
304 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
305 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
312 template<
class X,
class Y>
313 void mmhv (
const X& x, Y& y)
const
315#ifdef DUNE_FMatrix_WITH_CHECKING
316 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
317 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
320 y[i] -= conjugateComplex(p_)*x[i];
324 template<
class X,
class Y>
325 void usmv (
const K& alpha,
const X& x, Y& y)
const
327#ifdef DUNE_FMatrix_WITH_CHECKING
328 if (x.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
329 if (y.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
332 y[i] += alpha * p_ * x[i];
336 template<
class X,
class Y>
337 void usmtv (
const K& alpha,
const X& x, Y& y)
const
339#ifdef DUNE_FMatrix_WITH_CHECKING
340 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
341 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
344 y[i] += alpha * p_ * x[i];
348 template<
class X,
class Y>
349 void usmhv (
const K& alpha,
const X& x, Y& y)
const
351#ifdef DUNE_FMatrix_WITH_CHECKING
352 if (x.N()!=
N()) DUNE_THROW(FMatrixError,
"index out of range");
353 if (y.N()!=
M()) DUNE_THROW(FMatrixError,
"index out of range");
356 y[i] += alpha * conjugateComplex(p_) * x[i];
364 return fvmeta::sqrt(n*p_*p_);
382 return fvmeta::absreal(p_);
392 for (
int i=0; i<n; i++)
405 return std::pow(p_,n);
427#ifdef DUNE_FMatrix_WITH_CHECKING
428 if (i<0 || i>=n) DUNE_THROW(FMatrixError,
"row index out of range");
429 if (j<0 || j>=n) DUNE_THROW(FMatrixError,
"column index out of range");
441 s << ((i==j) ? a.p_ : 0) <<
" ";
450 return reference(
const_cast<K*
>(&p_), i);
491 template <
class DenseMatrix,
class field,
int N>
493 static void apply(DenseMatrix& denseMatrix,
495 assert(denseMatrix.M() == N);
496 assert(denseMatrix.N() == N);
497 denseMatrix = field(0);
498 for (
int i = 0; i < N; ++i)
499 denseMatrix[i][i] = rhs.
scalar();
503 template<
class K,
int n>
507 using real_type =
typename FieldTraits<field_type>::real_type;
Definition allocator.hh:11
A multiple of the identity matrix of static size.
Definition scaledidmatrix.hh:30
void usmhv(const K &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition scaledidmatrix.hh:349
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition scaledidmatrix.hh:301
ScaledIdentityMatrix & operator-=(const ScaledIdentityMatrix &y)
vector space subtraction
Definition scaledidmatrix.hh:165
ConstIterator end() const
end iterator
Definition scaledidmatrix.hh:136
Iterator beforeBegin()
Definition scaledidmatrix.hh:114
bool operator!=(const ScaledIdentityMatrix &other) const
incomparison operator
Definition scaledidmatrix.hh:225
void mmv(const X &x, Y &y) const
y -= A x
Definition scaledidmatrix.hh:289
void usmv(const K &alpha, const X &x, Y &y) const
y += alpha A x
Definition scaledidmatrix.hh:325
void mv(const X &x, Y &y) const
y = A x
Definition scaledidmatrix.hh:234
void umtv(const X &x, Y &y) const
y += A^T x
Definition scaledidmatrix.hh:265
void umhv(const X &x, Y &y) const
y += A^H x
Definition scaledidmatrix.hh:277
Iterator beforeEnd()
Definition scaledidmatrix.hh:107
K determinant() const
calculates the determinant of this matrix
Definition scaledidmatrix.hh:404
K block_type
export the type representing the components
Definition scaledidmatrix.hh:40
void usmtv(const K &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition scaledidmatrix.hh:337
Iterator end()
end iterator
Definition scaledidmatrix.hh:100
const K & scalar() const
Get const reference to the scalar diagonal value.
Definition scaledidmatrix.hh:473
void umv(const X &x, Y &y) const
y += A x
Definition scaledidmatrix.hh:253
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition scaledidmatrix.hh:85
K field_type
export the type representing the field
Definition scaledidmatrix.hh:37
const K & diagonal(size_type) const
Get const reference to diagonal entry.
Definition scaledidmatrix.hh:460
@ rows
The number of rows.
Definition scaledidmatrix.hh:54
@ cols
The number of columns.
Definition scaledidmatrix.hh:56
ScaledIdentityMatrix & operator=(const K &k)
Definition scaledidmatrix.hh:71
K & diagonal(size_type)
Get reference to diagonal entry.
Definition scaledidmatrix.hh:466
row_type::Iterator ColIterator
rename the iterators for easier access
Definition scaledidmatrix.hh:91
void solve(V &x, const V &b) const
Solve system A x = b.
Definition scaledidmatrix.hh:390
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition scaledidmatrix.hh:425
ScaledIdentityMatrix()
Default constructor.
Definition scaledidmatrix.hh:62
bool operator==(const ScaledIdentityMatrix &other) const
comparison operator
Definition scaledidmatrix.hh:219
ConstIterator beforeBegin() const
Definition scaledidmatrix.hh:150
const_row_type const_reference
Definition scaledidmatrix.hh:49
ScaledIdentityMatrix & operator/=(const K &k)
vector space division by scalar
Definition scaledidmatrix.hh:192
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition scaledidmatrix.hh:46
row_type reference
Definition scaledidmatrix.hh:47
friend std::ostream & operator<<(std::ostream &s, const ScaledIdentityMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition scaledidmatrix.hh:437
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition scaledidmatrix.hh:121
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition scaledidmatrix.hh:368
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition scaledidmatrix.hh:362
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition scaledidmatrix.hh:374
ConstIterator beforeEnd() const
Definition scaledidmatrix.hh:143
size_type M() const
number of blocks in column direction
Definition scaledidmatrix.hh:417
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition scaledidmatrix.hh:454
ScaledIdentityMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition scaledidmatrix.hh:66
friend auto operator*(const ScaledIdentityMatrix &matrix, Scalar scalar)
vector space multiplication with scalar
Definition scaledidmatrix.hh:203
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition scaledidmatrix.hh:380
ScaledIdentityMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition scaledidmatrix.hh:185
bool identical(const ScaledIdentityMatrix< K, n > &other) const
Definition scaledidmatrix.hh:78
void invert()
Compute inverse.
Definition scaledidmatrix.hh:398
Iterator begin()
begin iterator
Definition scaledidmatrix.hh:94
K & scalar()
Get reference to the scalar diagonal value.
Definition scaledidmatrix.hh:480
ConstIterator const_iterator
typedef for stl compliant access
Definition scaledidmatrix.hh:123
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition scaledidmatrix.hh:125
Iterator RowIterator
rename the iterators for easier access
Definition scaledidmatrix.hh:89
Iterator iterator
typedef for stl compliant access
Definition scaledidmatrix.hh:87
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition scaledidmatrix.hh:313
ScaledIdentityMatrix & operator+=(const ScaledIdentityMatrix &y)
vector space addition
Definition scaledidmatrix.hh:158
std::size_t size_type
The type used for the index access and size operations.
Definition scaledidmatrix.hh:43
void mtv(const X &x, Y &y) const
y = A^T x
Definition scaledidmatrix.hh:246
reference operator[](size_type i)
Return reference object as row replacement.
Definition scaledidmatrix.hh:448
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition scaledidmatrix.hh:127
DiagonalRowVectorConst< K, n > const_row_type
Definition scaledidmatrix.hh:48
ConstIterator begin() const
begin iterator
Definition scaledidmatrix.hh:130
size_type N() const
number of blocks in row direction
Definition scaledidmatrix.hh:411
static void apply(DenseMatrix &denseMatrix, ScaledIdentityMatrix< field, N > const &rhs)
Definition scaledidmatrix.hh:493
typename ScaledIdentityMatrix< K, n >::field_type field_type
Definition scaledidmatrix.hh:506
typename FieldTraits< field_type >::real_type real_type
Definition scaledidmatrix.hh:507