mirror of
https://github.com/OPM/opm-upscaling.git
synced 2025-02-25 18:45:23 -06:00
added: MatrixOps::extractDiagonal
extracts the diagonal of a matrix as a new matrix
This commit is contained in:
parent
12a5638ab4
commit
e4ad0d62df
@ -55,6 +55,11 @@ class MatrixOps {
|
||||
//! \param[in] symmetric If true, augment symmetrically
|
||||
static Matrix augment(const Matrix& A, const Matrix& B,
|
||||
size_t r0, size_t c0, bool symmetric);
|
||||
|
||||
//! \brief Extract the diagonal of a matrix into a new matrix
|
||||
//! \param[in] The matrix to extract the diagonal from
|
||||
//! \returns M = diag(A)
|
||||
static Matrix extractDiagonal(const Matrix& A);
|
||||
};
|
||||
|
||||
#include "matrixops_impl.hpp"
|
||||
|
@ -144,3 +144,17 @@ Matrix MatrixOps::augment(const Matrix& A, const Matrix& B,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix MatrixOps::extractDiagonal(const Matrix& A)
|
||||
{
|
||||
AdjacencyPattern adj;
|
||||
adj.resize(A.M());
|
||||
for (size_t i=0;i<A.M();++i)
|
||||
adj[i].insert(i);
|
||||
Matrix result;
|
||||
fromAdjacency(result,adj,A.M(),A.M());
|
||||
for (size_t i=0;i<A.M();++i)
|
||||
result[i][i] = A[i][i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user