6#include <range/v3/view/zip.hpp>
14 const std::vector<MathLib::EigenMatrix::IndexType>& row_ids)
20 for (
auto row_id : row_ids)
22 for (SpMat::InnerIterator it(A_eigen, row_id); it; ++it)
24 if (it.col() !=
decltype(it.col())(row_id))
35 const std::vector<MathLib::EigenMatrix::IndexType>& vec_knownX_id,
36 const std::vector<double>& vec_knownX_x)
41 SpMat AT = A_eigen.transpose();
48 AT.reserve(Eigen::VectorXi::Constant(A_eigen.rows(), 1));
50 for (std::size_t ix = 0; ix < vec_knownX_id.size(); ix++)
52 SpMat::Index
const row_id = vec_knownX_id[ix];
53 auto const x = vec_knownX_x[ix];
57 for (SpMat::InnerIterator it(AT, row_id); it; ++it)
59 if (it.col() == row_id)
64 b_eigen[it.col()] -= it.value() * x;
68 auto& c = AT.coeffRef(row_id, row_id);
71 b_eigen[row_id] = x * c;
80 A_eigen = AT.transpose();
86 const std::vector<MathLib::EigenMatrix::IndexType>& vec_knownX_id,
87 const std::vector<double>& vec_knownX_x)
89 INFO(
"partial Dirichlet BC application (rhs only).");
93 Eigen::VectorXd x_known{A_eigen.rows()};
96 for (
auto const& [row_id, x] :
97 ranges::views::zip(vec_knownX_id, vec_knownX_x))
102 auto const c = A_eigen.coeff(row_id, row_id);
105 b_eigen[row_id] = x * c;
109 A_eigen.coeffRef(row_id, row_id) = 0;
117 b_eigen -= A_eigen * x_known;
125 const std::vector<EigenMatrix::IndexType>& vec_knownX_id,
126 const std::vector<double>& vec_knownX_x,
130 static_assert(SpMat::IsRowMajor,
"matrix is assumed to be row major!");
139 ::applyKnownSolutionComplete(A_eigen, b_eigen, vec_knownX_id,
143 ::applyKnownSolutionIncomplete(A_eigen, b_eigen, vec_knownX_id,
148 OGS_FATAL(
"Unhandled DirichletBCApplicationMode with integer value {}.",
149 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)