Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
staticmatrixtools.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef STATIC_MATRIX_TOOL_HH
5#define STATIC_MATRIX_TOOL_HH
6
7#warning This header is deprecated and will be removed after 2.11.
8
15#if HAVE_DUNE_MATRIX_VECTOR
16
21
22#include <dune/matrix-vector/addtodiagonal.hh>
23#include <dune/matrix-vector/axpy.hh>
24#include <dune/matrix-vector/ldlt.hh>
25#include <dune/matrix-vector/promote.hh>
26#include <dune/matrix-vector/transformmatrix.hh>
27
28namespace StaticMatrix
29{
30 // type promotion (smallest matrix that can hold the sum of two matrices *******************
31 template<class MatrixA, class MatrixB>
32 struct Promote
33 {
34 typedef typename Dune::MatrixVector::Promote<MatrixA, MatrixB>::Type Type;
35 };
36
37 // add scalar to matrix diagonal ***********************************************************
38 template<class Matrix>
39 static void addToDiagonal(Matrix& x, const typename Matrix::field_type a)
40 {
41 Dune::MatrixVector::addToDiagonal(x, a);
42 }
43
44 // add transformed matrix A += T1^t*B*T2 ******************************************************
45 template<class MatrixA, class MatrixB, class TransformationMatrix>
46 void addTransformedMatrix(MatrixA& A, const TransformationMatrix& T1, const MatrixB& B, const TransformationMatrix& T2)
47 {
48 Dune::MatrixVector::addTransformedMatrix(A,T1,B,T2);
49 }
50
51 template<class MatrixA, class MatrixB, class TransformationMatrix>
52 void transformMatrix(MatrixA& A, const TransformationMatrix& T1, const MatrixB& B, const TransformationMatrix& T2)
53 {
54 Dune::MatrixVector::transformMatrix(A,T1,B,T2);
55 }
56
57 template<class MatrixBlockA, class MatrixB, class TransformationMatrix>
58 static void transformMatrixPattern(Dune::BCRSMatrix<MatrixBlockA>& A, const TransformationMatrix& T1, const MatrixB& B, const TransformationMatrix& T2)
59 {
60 Dune::MatrixVector::transformMatrixPattern(A,T1,B,T2);
61 }
62
63
64 // compute v^T*A*v for an edge vector e = e_i - e_j with i!=j ******************************
65 template<class Matrix>
66 static typename Matrix::field_type simplexEdgeDiagonal(const Matrix& A, int i, int j)
67 {
68 return A[i][i] - A[i][j] - A[j][i] + A[j][j];
69 }
70
71 template <typename FieldType, int n>
72 static FieldType simplexEdgeDiagonal(const Dune::DiagonalMatrix<FieldType,n>& A, int i, int j)
73 {
74 return A.diagonal(i) + A.diagonal(j);
75 }
76
77 template <typename FieldType, int n>
78 static FieldType simplexEdgeDiagonal(const Dune::ScaledIdentityMatrix<FieldType,n>& A, int i, int j)
79 {
80 return 2*A.scalar();
81 }
82
83
84
85 // compute i-th row of A*v for an edge vector e = e_i - e_j with i!=j **********************
86 template<class Matrix>
87 static typename Matrix::field_type simplexEdgeResidual(const Matrix& A, int i, int j)
88 {
89 return A[i][i] - A[i][j];
90 }
91
92 template <typename FieldType, int n>
93 static FieldType simplexEdgeResidual(const Dune::DiagonalMatrix<FieldType,n>& A, int i, int j)
94 {
95 return A.diagonal(i);
96 }
97
98 template <typename FieldType, int n>
99 static FieldType simplexEdgeResidual(const Dune::ScaledIdentityMatrix<FieldType,n>& A, int i, int j)
100 {
101 return A.scalar();
102 }
103
104
105
106
107 // compute i-th row of A*v for an edge vector e = e_i - e_j with i!=j **********************
108 template <class K>
109 static Dune::FieldMatrix<K,1,1>& toMatrix(K& x)
110 {
111 return *(reinterpret_cast< Dune::FieldMatrix<K,1,1>* > (&x));
112 }
113
114 template <class K, int n, int m>
116 {
117 return x;
118 }
119
120 template <class K, int n>
122 {
123 return x;
124 }
125
126 template <class K, int n>
128 {
129 return x;
130 }
131
132 template <class K>
134 {
135 return *(reinterpret_cast< Dune::FieldMatrix<K,1,1>* > (&x));
136 }
137
138 template <class K>
140 {
141 return *(reinterpret_cast< Dune::FieldMatrix<K,1,1>* > (&x));
142 }
143
168 template<class SymmetricMatrix, class LowerTriangularMatrix, class DiagonalMatrix>
169 static void ldlt(const SymmetricMatrix& A, LowerTriangularMatrix& L, DiagonalMatrix& D)
170 {
171 Dune::MatrixVector::ldlt(A,L,D);
172 }
173
190 template<class LowerTriangularMatrix, class DiagonalMatrix, class RhsVector, class SolVector>
191 static void ldltSolve(const LowerTriangularMatrix& L, const DiagonalMatrix& D, const RhsVector& b, SolVector& x)
192 {
193 Dune::MatrixVector::ldltSolve(L,D,b,x);
194 }
195}
196
197#endif // HAVE_DUNE_MATRIX_VECTOR
198
199#endif
200
constexpr DiagonalMatrix()=default
const K & diagonal(size_type i) const
const K & scalar() const