Skip to content
Snippets Groups Projects
Commit ed107547 authored by Tom Fischer's avatar Tom Fischer Committed by GitHub
Browse files

Merge pull request #1879 from chleh/eigen-vec-mat-index-type

Use Eigen's index type in EigenMatrix and EigenVector
parents 1033d28a 69d28966
No related branches found
No related tags found
No related merge requests found
...@@ -39,23 +39,23 @@ public: ...@@ -39,23 +39,23 @@ public:
* @param n the number of rows (that is equal to the number of columns) * @param n the number of rows (that is equal to the number of columns)
* @param n_nonzero_columns the number of non-zero columns used for preallocation * @param n_nonzero_columns the number of non-zero columns used for preallocation
*/ */
explicit EigenMatrix(std::size_t n, std::size_t n_nonzero_columns = 0) :_mat(n, n) explicit EigenMatrix(IndexType n, IndexType n_nonzero_columns = 0) :_mat(n, n)
{ {
if (n_nonzero_columns > 0) if (n_nonzero_columns > 0)
_mat.reserve(Eigen::VectorXi::Constant(n, n_nonzero_columns)); _mat.reserve(Eigen::VectorXi::Constant(n, n_nonzero_columns));
} }
/// return the number of rows /// return the number of rows
std::size_t getNumberOfRows() const { return _mat.rows(); } IndexType getNumberOfRows() const { return _mat.rows(); }
/// return the number of columns /// return the number of columns
std::size_t getNumberOfColumns() const { return _mat.cols(); } IndexType getNumberOfColumns() const { return _mat.cols(); }
/// return a start index of the active data range /// return a start index of the active data range
std::size_t getRangeBegin() const { return 0; } IndexType getRangeBegin() const { return 0; }
/// return an end index of the active data range /// return an end index of the active data range
std::size_t getRangeEnd() const { return getNumberOfRows(); } IndexType getRangeEnd() const { return getNumberOfRows(); }
/// reset data entries to zero. /// reset data entries to zero.
void setZero() void setZero()
......
...@@ -37,19 +37,19 @@ public: ...@@ -37,19 +37,19 @@ public:
/// Constructor for initialization of the number of rows /// Constructor for initialization of the number of rows
/// @param length number of rows /// @param length number of rows
explicit EigenVector(std::size_t length) : _vec(length) {} explicit EigenVector(IndexType length) : _vec(length) {}
/// copy constructor /// copy constructor
EigenVector(EigenVector const& src) = default; EigenVector(EigenVector const& src) = default;
/// return a vector length /// return a vector length
std::size_t size() const { return _vec.size(); } IndexType size() const { return _vec.size(); }
/// return a start index of the active data range /// return a start index of the active data range
std::size_t getRangeBegin() const { return 0;} IndexType getRangeBegin() const { return 0;}
/// return an end index of the active data range /// return an end index of the active data range
std::size_t getRangeEnd() const { return size(); } IndexType getRangeEnd() const { return size(); }
// TODO preliminary // TODO preliminary
void setZero() { _vec.setZero(); } void setZero() { _vec.setZero(); }
......
...@@ -133,8 +133,8 @@ void setMatrix(EigenMatrix& m, ...@@ -133,8 +133,8 @@ void setMatrix(EigenMatrix& m,
Eigen::MatrixXd tmp(rows, cols); Eigen::MatrixXd tmp(rows, cols);
auto it = values.begin(); auto it = values.begin();
for (std::size_t r=0; r<rows; ++r) { for (GlobalIndexType r=0; r<rows; ++r) {
for (std::size_t c=0; c<cols; ++c) { for (GlobalIndexType c=0; c<cols; ++c) {
tmp(r, c) = *(it++); tmp(r, c) = *(it++);
} }
} }
...@@ -157,8 +157,8 @@ void addToMatrix(EigenMatrix& m, ...@@ -157,8 +157,8 @@ void addToMatrix(EigenMatrix& m,
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp(rows, cols); Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp(rows, cols);
auto it = values.begin(); auto it = values.begin();
for (std::size_t r=0; r<rows; ++r) { for (GlobalIndexType r=0; r<rows; ++r) {
for (std::size_t c=0; c<cols; ++c) { for (GlobalIndexType c=0; c<cols; ++c) {
tmp(r, c) = *(it++); tmp(r, c) = *(it++);
} }
} }
......
...@@ -135,8 +135,7 @@ void doProcessOutput(std::string const& file_name, ...@@ -135,8 +135,7 @@ void doProcessOutput(std::string const& file_name,
var.fcts.eval_field(x, dof_table, result_cache); var.fcts.eval_field(x, dof_table, result_cache);
// Copy result // Copy result
for (std::size_t i = 0; i < mesh.getNumberOfNodes(); ++i) for (GlobalIndexType i = 0; i < nodal_values.size(); ++i) {
{
assert(!std::isnan(nodal_values[i])); assert(!std::isnan(nodal_values[i]));
(*result)[i] = nodal_values[i]; (*result)[i] = nodal_values[i];
} }
...@@ -155,7 +154,7 @@ void doProcessOutput(std::string const& file_name, ...@@ -155,7 +154,7 @@ void doProcessOutput(std::string const& file_name,
var.fcts.eval_residuals(x, dof_table, result_cache); var.fcts.eval_residuals(x, dof_table, result_cache);
// Copy result // Copy result
for (std::size_t i = 0; i < mesh.getNumberOfElements(); ++i) for (GlobalIndexType i = 0; i < residuals.size(); ++i)
{ {
assert(!std::isnan(residuals[i])); assert(!std::isnan(residuals[i]));
(*result)[i] = residuals[i]; (*result)[i] = residuals[i];
......
...@@ -141,7 +141,7 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem) ...@@ -141,7 +141,7 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem)
// copy solution to double vector // copy solution to double vector
std::vector<double> solution(x->size()); std::vector<double> solution(x->size());
for (std::size_t i = 0; i < x->size(); ++i) for (GlobalIndexType i = 0; i < x->size(); ++i)
solution[i] = (*x)[i]; solution[i] = (*x)[i];
ASSERT_ARRAY_NEAR(&ex1.exact_solutions[0], &solution[0], ex1.dim_eqs, 1.e-5); ASSERT_ARRAY_NEAR(&ex1.exact_solutions[0], &solution[0], ex1.dim_eqs, 1.e-5);
......
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