From 99925dbd4f3770570765e2d3f34e87e348bc27f3 Mon Sep 17 00:00:00 2001 From: Hannes Signer Date: Wed, 19 Jul 2023 00:35:51 +0200 Subject: [PATCH] remove bug because of Matrix2d and Vector2d --- examples/FTCS_2D_proto_example.cpp | 6 +++++- include/tug/Grid.hpp | 18 +++++++++--------- src/Boundary.cpp | 13 +++++++------ src/FTCS.cpp | 4 ++-- src/Grid.cpp | 24 +++++++++++++----------- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/examples/FTCS_2D_proto_example.cpp b/examples/FTCS_2D_proto_example.cpp index 2819334..fba5876 100644 --- a/examples/FTCS_2D_proto_example.cpp +++ b/examples/FTCS_2D_proto_example.cpp @@ -1,11 +1,15 @@ #include +#include int main(int argc, char *argv[]) { + Grid grid = Grid(20,20); Boundary bc = Boundary(grid, BC_TYPE_CONSTANT); Simulation simulation = Simulation(grid, bc, FTCS_APPROACH); - + simulation.run(); + + } \ No newline at end of file diff --git a/include/tug/Grid.hpp b/include/tug/Grid.hpp index 0f828f3..3da1ee7 100644 --- a/include/tug/Grid.hpp +++ b/include/tug/Grid.hpp @@ -25,21 +25,21 @@ class Grid { * * @param concentrations */ - void setConcentrations(Matrix2d concentrations); + void setConcentrations(MatrixXd concentrations); /** * @brief Get the Concentrations object * * @return auto */ - Matrix2d getConcentrations(); + MatrixXd getConcentrations(); /** * @brief Set the Alpha object * * @param alpha */ - void setAlpha(Matrix2d alpha); + void setAlpha(MatrixXd alpha); /** * @brief Set the Alpha object @@ -47,11 +47,11 @@ class Grid { * @param alpha_x * @param alpha_y */ - void setAlpha(Matrix2d alpha_x, Matrix2d alpha_y); + void setAlpha(MatrixXd alpha_x, MatrixXd alpha_y); - Matrix2d getAlphaX(); + MatrixXd getAlphaX(); - Matrix2d getAlphaY(); + MatrixXd getAlphaY(); int getDim(); @@ -77,7 +77,7 @@ class Grid { int domain_row; double delta_col; double delta_row; - Matrix2d concentrations; - Matrix2d alpha_x; - Matrix2d alpha_y; + MatrixXd concentrations; + MatrixXd alpha_x; + MatrixXd alpha_y; }; \ No newline at end of file diff --git a/src/Boundary.cpp b/src/Boundary.cpp index 03e5216..311a439 100644 --- a/src/Boundary.cpp +++ b/src/Boundary.cpp @@ -10,13 +10,14 @@ Boundary::Boundary(Grid &grid, BC_TYPE type) : grid(grid) { if (type == BC_TYPE_CONSTANT) { if (grid.getDim() == 1) { - this->left = VectorXd::Constant(1, 1, 1); - this->right = VectorXd::Constant(1, 1, 1); + this->left = VectorXd::Constant(1, 1); + this->right = VectorXd::Constant(1, 1); } else if (grid.getDim() == 2) { - this->left = VectorXd::Constant(grid.getRow(), 1, 1); - this->right = VectorXd::Constant(grid.getRow(), 1, 1); - this->top = VectorXd::Constant(1, grid.getCol(), 1); - this->bottom = VectorXd::Constant(1, grid.getCol(), 1); + this->left = VectorXd::Constant(grid.getRow(), 1); + this->right = VectorXd::Constant(grid.getRow(), 1); + this->top = VectorXd::Constant(grid.getCol(), 1); + this->bottom = VectorXd::Constant(grid.getCol(), 1); + } else { throw invalid_argument("Dimension must be 1 or 2!"); } diff --git a/src/FTCS.cpp b/src/FTCS.cpp index c32ca97..695cd1d 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -1,5 +1,5 @@ #include - +#include auto calc_alpha_intercell(double alpha1, double alpha2, bool useHarmonic = false) { if (useHarmonic) { @@ -17,7 +17,7 @@ auto FTCS_constant(Grid &grid, Boundary &bc, double timestep) { // Matrix with concentrations at time t+1 // TODO profiler / only use 2 matrices - Matrix2d concentrations_t1 = Matrix2d(rowMax, colMax); + MatrixXd concentrations_t1 = MatrixXd(rowMax, colMax); // inner cells for (int row = 1; row < rowMax-1; row++) { diff --git a/src/Grid.cpp b/src/Grid.cpp index 55ea4f9..83b44c7 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -1,11 +1,12 @@ #include +#include Grid::Grid(int col) { this->col = col; this->dim = 1; - this->concentrations = Matrix2d::Constant(1, col, 1); - this->alpha_x = Matrix2d::Constant(1, col, 1); + this->concentrations = MatrixXd::Constant(1, col, 1); + this->alpha_x = MatrixXd::Constant(1, col, 1); } Grid::Grid(int row, int col) { @@ -13,33 +14,34 @@ Grid::Grid(int row, int col) { this->col = col; this->dim = 2; - this->concentrations = Matrix2d::Constant(row, col, 1); - this->alpha_x = Matrix2d::Constant(row, col, 1); - this->alpha_y = Matrix2d::Constant(row, col, 1); + this->concentrations = MatrixXd::Constant(row, col, 1); + this->alpha_x = MatrixXd::Constant(row, col, 1); + this->alpha_y = MatrixXd::Constant(row, col, 1); + } -void Grid::setConcentrations(Matrix2d concentrations) { +void Grid::setConcentrations(MatrixXd concentrations) { this->concentrations = concentrations; } -Matrix2d Grid::getConcentrations() { +MatrixXd Grid::getConcentrations() { return this->concentrations; } -void Grid::setAlpha(Matrix2d alpha) { +void Grid::setAlpha(MatrixXd alpha) { this->alpha_x = alpha; } -void Grid::setAlpha(Matrix2d alpha_x, Matrix2d alpha_y) { +void Grid::setAlpha(MatrixXd alpha_x, MatrixXd alpha_y) { this->alpha_x = alpha_x; this->alpha_y = alpha_y; } -Matrix2d Grid::getAlphaX() { +MatrixXd Grid::getAlphaX() { return this->alpha_x; } -Matrix2d Grid::getAlphaY() { +MatrixXd Grid::getAlphaY() { return this->alpha_y; }