diff --git a/MathLib/LinAlg/UnifiedMatrixSetters.cpp b/MathLib/LinAlg/UnifiedMatrixSetters.cpp index 3b762f0a985ff111dca78236e68d45f2e0e2ea2f..00dbc7ce0ab9cd56fcb7613ac58b5b9cbfb8fa1b 100644 --- a/MathLib/LinAlg/UnifiedMatrixSetters.cpp +++ b/MathLib/LinAlg/UnifiedMatrixSetters.cpp @@ -67,6 +67,12 @@ void setVector(Eigen::VectorXd& v, std::initializer_list<double> values) for (std::size_t i=0; i<values.size(); ++i) v[i] = *(it++); } +void setVector(Eigen::VectorXd& v, MatrixVectorTraits<Eigen::VectorXd>::Index const index, + double const value) +{ + v[index] = value; +} + } // namespace MathLib #endif // OGS_USE_EIGEN @@ -97,6 +103,12 @@ void setVector(PETScVector& v, v.set(idcs, vals); } +void setVector(PETScVector& v, MatrixVectorTraits<PETScVector>::Index const index, + double const value) +{ + v.set(index, value); // TODO handle negative indices +} + void setMatrix(PETScMatrix& m, std::initializer_list<double> values) { @@ -173,6 +185,13 @@ void setVector(EigenVector& v, setVector(v.getRawVector(), values); } +void setVector(EigenVector& v, MatrixVectorTraits<EigenVector>::Index const index, + double const value) +{ + v.getRawVector()[index] = value; +} + + void setMatrix(EigenMatrix& m, std::initializer_list<double> values) { diff --git a/MathLib/LinAlg/UnifiedMatrixSetters.h b/MathLib/LinAlg/UnifiedMatrixSetters.h index 4ece2dd9400627a442b4c44f95c585baee9ce50b..d7402b25139b7ade1185489fba30248b763d683e 100644 --- a/MathLib/LinAlg/UnifiedMatrixSetters.h +++ b/MathLib/LinAlg/UnifiedMatrixSetters.h @@ -13,6 +13,7 @@ #define MATHLIB_UNIFIED_MATRIX_SETTERS_H #include <initializer_list> +#include "MatrixVectorTraits.h" #ifdef OGS_USE_EIGEN @@ -35,6 +36,9 @@ double norm(Eigen::VectorXd const& x); void setVector(Eigen::VectorXd& v, std::initializer_list<double> values); +void setVector(Eigen::VectorXd& v, MatrixVectorTraits<Eigen::VectorXd>::Index const index, + double const value); + } // namespace MathLib #endif // OGS_USE_EIGEN @@ -55,6 +59,9 @@ double norm(PETScVector const& x); void setVector(PETScVector& v, std::initializer_list<double> values); +void setVector(PETScVector& v, MatrixVectorTraits<PETScVector>::Index const index, + double const value); + void setMatrix(PETScMatrix& m, Eigen::MatrixXd const& tmp); void addToMatrix(PETScMatrix& m, @@ -79,6 +86,9 @@ class EigenMatrix; void setVector(EigenVector& v, std::initializer_list<double> values); +void setVector(EigenVector& v, MatrixVectorTraits<EigenVector>::Index const index, + double const value); + void setMatrix(EigenMatrix& m, std::initializer_list<double> values);