Skip to content
Snippets Groups Projects
Commit 75353937 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[MaL] added: unified setting of vector values

parent 6a2bd7ee
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,12 @@ void setVector(Eigen::VectorXd& v, std::initializer_list<double> values) ...@@ -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++); 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 } // namespace MathLib
#endif // OGS_USE_EIGEN #endif // OGS_USE_EIGEN
...@@ -97,6 +103,12 @@ void setVector(PETScVector& v, ...@@ -97,6 +103,12 @@ void setVector(PETScVector& v,
v.set(idcs, vals); 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, void setMatrix(PETScMatrix& m,
std::initializer_list<double> values) std::initializer_list<double> values)
{ {
...@@ -173,6 +185,13 @@ void setVector(EigenVector& v, ...@@ -173,6 +185,13 @@ void setVector(EigenVector& v,
setVector(v.getRawVector(), values); setVector(v.getRawVector(), values);
} }
void setVector(EigenVector& v, MatrixVectorTraits<EigenVector>::Index const index,
double const value)
{
v.getRawVector()[index] = value;
}
void setMatrix(EigenMatrix& m, void setMatrix(EigenMatrix& m,
std::initializer_list<double> values) std::initializer_list<double> values)
{ {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#define MATHLIB_UNIFIED_MATRIX_SETTERS_H #define MATHLIB_UNIFIED_MATRIX_SETTERS_H
#include <initializer_list> #include <initializer_list>
#include "MatrixVectorTraits.h"
#ifdef OGS_USE_EIGEN #ifdef OGS_USE_EIGEN
...@@ -35,6 +36,9 @@ double norm(Eigen::VectorXd const& x); ...@@ -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, std::initializer_list<double> values);
void setVector(Eigen::VectorXd& v, MatrixVectorTraits<Eigen::VectorXd>::Index const index,
double const value);
} // namespace MathLib } // namespace MathLib
#endif // OGS_USE_EIGEN #endif // OGS_USE_EIGEN
...@@ -55,6 +59,9 @@ double norm(PETScVector const& x); ...@@ -55,6 +59,9 @@ double norm(PETScVector const& x);
void setVector(PETScVector& v, void setVector(PETScVector& v,
std::initializer_list<double> values); 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 setMatrix(PETScMatrix& m, Eigen::MatrixXd const& tmp);
void addToMatrix(PETScMatrix& m, void addToMatrix(PETScMatrix& m,
...@@ -79,6 +86,9 @@ class EigenMatrix; ...@@ -79,6 +86,9 @@ class EigenMatrix;
void setVector(EigenVector& v, void setVector(EigenVector& v,
std::initializer_list<double> values); std::initializer_list<double> values);
void setVector(EigenVector& v, MatrixVectorTraits<EigenVector>::Index const index,
double const value);
void setMatrix(EigenMatrix& m, void setMatrix(EigenMatrix& m,
std::initializer_list<double> values); std::initializer_list<double> values);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment