OGS
EigenMatrix.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "EigenMatrix.h"
5
6#include <fstream>
7
8namespace MathLib
9{
10
12void EigenMatrix::write(const std::string& filename) const
13{
14 std::ofstream of(filename);
15 if (of)
16 {
17 write(of);
18 }
19}
20
22void EigenMatrix::write(std::ostream& os) const
23{
24 for (int k = 0; k < mat_.outerSize(); ++k)
25 {
26 for (RawMatrixType::InnerIterator it(mat_, k); it; ++it)
27 {
28 os << it.row() << " " << it.col() << " " << it.value() << "\n";
29 }
30 }
31 os << std::endl;
32}
33
34void EigenMatrix::addToDiagonal(double const value)
35{
36 // Add value to all diagonal entries
37 for (IndexType i = 0; i < mat_.rows(); ++i)
38 {
39 mat_.coeffRef(i, i) += value;
40 }
41}
42} // namespace MathLib
RawMatrixType::Index IndexType
Definition EigenMatrix.h:25
void write(const std::string &filename) const
printout this matrix for debugging
RawMatrixType mat_
void addToDiagonal(double const value)