From e675381683950f4fbd7d5729b9f8cd70a2b38261 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 20 Jan 2022 09:41:34 +0100 Subject: [PATCH] Change boundary_condition to struct instead of tuple --- src/BTCSDiffusion.cpp | 22 ++++++++++++++-------- src/BTCSDiffusion.hpp | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/BTCSDiffusion.cpp b/src/BTCSDiffusion.cpp index 2fe91ce..c9b0837 100644 --- a/src/BTCSDiffusion.cpp +++ b/src/BTCSDiffusion.cpp @@ -45,10 +45,11 @@ void BTCSDiffusion::updateInternals() { switch (grid_dim) { case 1: - bc.resize(2, std::tuple(BTCSDiffusion::BC_CLOSED, 0.)); + bc.resize(2, {BTCSDiffusion::BC_CLOSED, 0}); break; case 2: - bc.resize(2 * grid_cells[0] + 2 * grid_cells[1], std::tuple(BTCSDiffusion::BC_CLOSED, 0.)); + bc.resize(2 * grid_cells[0] + 2 * grid_cells[1], + {BTCSDiffusion::BC_CLOSED, 0}); break; case 3: // TODO @@ -154,14 +155,15 @@ void BTCSDiffusion::simulate(std::vector &c, double BTCSDiffusion::getBCFromTuple(int index, double neighbor_c, double neighbor_alpha) { double val = -1; - int type = std::get<0>(bc[index]); + int type = bc[index].type; if (type == BTCSDiffusion::BC_CLOSED) { val = neighbor_c; - // val = neighbor_c + (this->time_step / (this->deltas[0] * this->deltas[0])) * + // val = neighbor_c + (this->time_step / (this->deltas[0] * + // this->deltas[0])) * // neighbor_alpha * std::get<1>(bc[index]); - } else if (type == BTCSDiffusion::BC_CONSTANT){ - val = std::get<1>(bc[index]); + } else if (type == BTCSDiffusion::BC_CONSTANT) { + val = bc[index].value; } else { // TODO: implement error handling here. Type was set to wrong value. } @@ -170,6 +172,10 @@ double BTCSDiffusion::getBCFromTuple(int index, double neighbor_c, } void BTCSDiffusion::setBoundaryCondition(int index, double val, bctype type) { - std::get<0>(bc[index]) = type; - std::get<1>(bc[index]) = val; + + bc[index].type = type; + bc[index].value = val; + + // std::get<0>(bc[index]) = type; + // std::get<1>(bc[index]) = val; } diff --git a/src/BTCSDiffusion.hpp b/src/BTCSDiffusion.hpp index 2df15c4..21a4b37 100644 --- a/src/BTCSDiffusion.hpp +++ b/src/BTCSDiffusion.hpp @@ -42,7 +42,21 @@ public: * - Dirichlet boundary condition: type BC_DIRICHLET with the actual value of * the boundary condition */ - typedef std::vector> boundary_condition; + typedef struct boundary_condition { + bctype type; + double value; + } boundary_condition; + + /*! + * A boundary condition consists of two features. A type and the according + * value. Here we can differentiate between: + * + * - Neumann boundary conditon: type BC_NEUMANN with the value defining the + * gradient + * - Dirichlet boundary condition: type BC_DIRICHLET with the actual value of + * the boundary condition + */ + // typedef std::vector> boundary_condition; /*! * Datatype to fill the sparse matrix which is used to solve the equation @@ -117,7 +131,7 @@ private: void updateInternals(); - boundary_condition bc; + std::vector bc; Eigen::SparseMatrix A_matrix; Eigen::VectorXd b_vector;