13#include <range/v3/view/zip.hpp>
21 const std::vector<MathLib::EigenMatrix::IndexType>& row_ids)
27 for (
auto row_id : row_ids)
29 for (SpMat::InnerIterator it(A_eigen, row_id); it; ++it)
31 if (it.col() !=
decltype(it.col())(row_id))
42 const std::vector<MathLib::EigenMatrix::IndexType>& vec_knownX_id,
43 const std::vector<double>& vec_knownX_x)
48 SpMat AT = A_eigen.transpose();
55 AT.reserve(Eigen::VectorXi::Constant(A_eigen.rows(), 1));
57 for (std::size_t ix = 0; ix < vec_knownX_id.size(); ix++)
59 SpMat::Index
const row_id = vec_knownX_id[ix];
60 auto const x = vec_knownX_x[ix];
64 for (SpMat::InnerIterator it(AT, row_id); it; ++it)
66 if (it.col() == row_id)
71 b_eigen[it.col()] -= it.value() * x;
75 auto& c = AT.coeffRef(row_id, row_id);
78 b_eigen[row_id] = x * c;
87 A_eigen = AT.transpose();
93 const std::vector<MathLib::EigenMatrix::IndexType>& vec_knownX_id,
94 const std::vector<double>& vec_knownX_x)
96 INFO(
"partial Dirichlet BC application (rhs only).");
100 Eigen::VectorXd x_known{A_eigen.rows()};
103 for (
auto const& [row_id, x] :
104 ranges::views::zip(vec_knownX_id, vec_knownX_x))
109 auto const c = A_eigen.coeff(row_id, row_id);
112 b_eigen[row_id] = x * c;
116 A_eigen.coeffRef(row_id, row_id) = 0;
124 b_eigen -= A_eigen * x_known;
132 const std::vector<EigenMatrix::IndexType>& vec_knownX_id,
133 const std::vector<double>& vec_knownX_x,
137 static_assert(SpMat::IsRowMajor,
"matrix is assumed to be row major!");
146 ::applyKnownSolutionComplete(A_eigen, b_eigen, vec_knownX_id,
150 ::applyKnownSolutionIncomplete(A_eigen, b_eigen, vec_knownX_id,
155 OGS_FATAL(
"Unhandled DirichletBCApplicationMode with integer value {}.",
156 std::to_underlying(mode));
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Eigen::SparseMatrix< double, Eigen::RowMajor > RawMatrixType
RawMatrixType & getRawMatrix()
Global vector based on Eigen vector.
Eigen::VectorXd RawVectorType
RawVectorType & getRawVector()
return a raw Eigen vector object
DirichletBCApplicationMode
@ COMPLETE_MATRIX_UPDATE
Both A and b fully updated.
@ FAST_INCOMPLETE_MATRIX_UPDATE
A partially updated, b fully updated.
void applyKnownSolution(EigenMatrix &A, EigenVector &b, EigenVector &, const std::vector< EigenMatrix::IndexType > &vec_knownX_id, const std::vector< double > &vec_knownX_x, DirichletBCApplicationMode const mode)