remove bug because of Matrix2d and Vector2d

This commit is contained in:
Hannes Signer 2023-07-19 00:35:51 +02:00
parent 542601fdcd
commit 99925dbd4f
5 changed files with 36 additions and 29 deletions

View File

@ -1,11 +1,15 @@
#include <tug/Simulation.hpp> #include <tug/Simulation.hpp>
#include <iostream>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Grid grid = Grid(20,20); Grid grid = Grid(20,20);
Boundary bc = Boundary(grid, BC_TYPE_CONSTANT); Boundary bc = Boundary(grid, BC_TYPE_CONSTANT);
Simulation simulation = Simulation(grid, bc, FTCS_APPROACH); Simulation simulation = Simulation(grid, bc, FTCS_APPROACH);
simulation.run(); simulation.run();
} }

View File

@ -25,21 +25,21 @@ class Grid {
* *
* @param concentrations * @param concentrations
*/ */
void setConcentrations(Matrix2d concentrations); void setConcentrations(MatrixXd concentrations);
/** /**
* @brief Get the Concentrations object * @brief Get the Concentrations object
* *
* @return auto * @return auto
*/ */
Matrix2d getConcentrations(); MatrixXd getConcentrations();
/** /**
* @brief Set the Alpha object * @brief Set the Alpha object
* *
* @param alpha * @param alpha
*/ */
void setAlpha(Matrix2d alpha); void setAlpha(MatrixXd alpha);
/** /**
* @brief Set the Alpha object * @brief Set the Alpha object
@ -47,11 +47,11 @@ class Grid {
* @param alpha_x * @param alpha_x
* @param alpha_y * @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(); int getDim();
@ -77,7 +77,7 @@ class Grid {
int domain_row; int domain_row;
double delta_col; double delta_col;
double delta_row; double delta_row;
Matrix2d concentrations; MatrixXd concentrations;
Matrix2d alpha_x; MatrixXd alpha_x;
Matrix2d alpha_y; MatrixXd alpha_y;
}; };

View File

@ -10,13 +10,14 @@ Boundary::Boundary(Grid &grid, BC_TYPE type) : grid(grid) {
if (type == BC_TYPE_CONSTANT) { if (type == BC_TYPE_CONSTANT) {
if (grid.getDim() == 1) { if (grid.getDim() == 1) {
this->left = VectorXd::Constant(1, 1, 1); this->left = VectorXd::Constant(1, 1);
this->right = VectorXd::Constant(1, 1, 1); this->right = VectorXd::Constant(1, 1);
} else if (grid.getDim() == 2) { } else if (grid.getDim() == 2) {
this->left = VectorXd::Constant(grid.getRow(), 1, 1); this->left = VectorXd::Constant(grid.getRow(), 1);
this->right = VectorXd::Constant(grid.getRow(), 1, 1); this->right = VectorXd::Constant(grid.getRow(), 1);
this->top = VectorXd::Constant(1, grid.getCol(), 1); this->top = VectorXd::Constant(grid.getCol(), 1);
this->bottom = VectorXd::Constant(1, grid.getCol(), 1); this->bottom = VectorXd::Constant(grid.getCol(), 1);
} else { } else {
throw invalid_argument("Dimension must be 1 or 2!"); throw invalid_argument("Dimension must be 1 or 2!");
} }

View File

@ -1,5 +1,5 @@
#include <tug/Boundary.hpp> #include <tug/Boundary.hpp>
#include <iostream>
auto calc_alpha_intercell(double alpha1, double alpha2, bool useHarmonic = false) { auto calc_alpha_intercell(double alpha1, double alpha2, bool useHarmonic = false) {
if (useHarmonic) { if (useHarmonic) {
@ -17,7 +17,7 @@ auto FTCS_constant(Grid &grid, Boundary &bc, double timestep) {
// Matrix with concentrations at time t+1 // Matrix with concentrations at time t+1
// TODO profiler / only use 2 matrices // TODO profiler / only use 2 matrices
Matrix2d concentrations_t1 = Matrix2d(rowMax, colMax); MatrixXd concentrations_t1 = MatrixXd(rowMax, colMax);
// inner cells // inner cells
for (int row = 1; row < rowMax-1; row++) { for (int row = 1; row < rowMax-1; row++) {

View File

@ -1,11 +1,12 @@
#include <tug/Grid.hpp> #include <tug/Grid.hpp>
#include <iostream>
Grid::Grid(int col) { Grid::Grid(int col) {
this->col = col; this->col = col;
this->dim = 1; this->dim = 1;
this->concentrations = Matrix2d::Constant(1, col, 1); this->concentrations = MatrixXd::Constant(1, col, 1);
this->alpha_x = Matrix2d::Constant(1, col, 1); this->alpha_x = MatrixXd::Constant(1, col, 1);
} }
Grid::Grid(int row, int col) { Grid::Grid(int row, int col) {
@ -13,33 +14,34 @@ Grid::Grid(int row, int col) {
this->col = col; this->col = col;
this->dim = 2; this->dim = 2;
this->concentrations = Matrix2d::Constant(row, col, 1); this->concentrations = MatrixXd::Constant(row, col, 1);
this->alpha_x = Matrix2d::Constant(row, col, 1); this->alpha_x = MatrixXd::Constant(row, col, 1);
this->alpha_y = Matrix2d::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; this->concentrations = concentrations;
} }
Matrix2d Grid::getConcentrations() { MatrixXd Grid::getConcentrations() {
return this->concentrations; return this->concentrations;
} }
void Grid::setAlpha(Matrix2d alpha) { void Grid::setAlpha(MatrixXd alpha) {
this->alpha_x = 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_x = alpha_x;
this->alpha_y = alpha_y; this->alpha_y = alpha_y;
} }
Matrix2d Grid::getAlphaX() { MatrixXd Grid::getAlphaX() {
return this->alpha_x; return this->alpha_x;
} }
Matrix2d Grid::getAlphaY() { MatrixXd Grid::getAlphaY() {
return this->alpha_y; return this->alpha_y;
} }