fix_zero_diagonal.hpp
Go to the documentation of this file.
1/*
2 Copyright 2022-2023 SINTEF AS
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef OPM_FIXZERODIAGONAL_HEADER_INCLUDED
20#define OPM_FIXZERODIAGONAL_HEADER_INCLUDED
21
22#include <limits>
23#include <vector>
24
25namespace Opm::cuistl::detail
26{
27
38template <class Matrix>
39const Matrix
40makeMatrixWithNonzeroDiagonal(const Matrix& matrix,
41 const typename Matrix::field_type replacementValue
42 = std::numeric_limits<typename Matrix::field_type>::epsilon())
43{
44 auto newMatrix = matrix;
45 // TODO: [perf] Is this fast enough?
46 for (size_t row = 0; row < newMatrix.N(); ++row) {
47 for (size_t component = 0; component < Matrix::block_type::cols; ++component) {
48 if (newMatrix[row][row][component][component] == 0) {
49 newMatrix[row][row][component][component] = replacementValue;
50 }
51 }
52 }
53
54 return newMatrix;
55}
56} // namespace Opm::cuistl::detail
57
58#endif
Definition: cublas_safe_call.hpp:32
const Matrix makeMatrixWithNonzeroDiagonal(const Matrix &matrix, const typename Matrix::field_type replacementValue=std::numeric_limits< typename Matrix::field_type >::epsilon())
makeMatrixWithNonzeroDiagonal creates a new matrix with the zero diagonal elements (when viewed as a ...
Definition: fix_zero_diagonal.hpp:40