added basic functionality to Grid and Boundary

This commit is contained in:
philippun 2023-07-13 15:52:56 +02:00
parent 470ebbd2ab
commit 2ab924a162
4 changed files with 86 additions and 25 deletions

View File

@ -1,4 +1,5 @@
#include <Eigen/Core>
#include "Grid.hpp"
using namespace Eigen;
@ -20,24 +21,10 @@ class Boundary {
/**
* @brief Construct a new Boundary object
*
* @param dim
* @param grid
* @param type
*/
Boundary(int dim);
/**
* @brief Construct a new Boundary object
*
* @param dim
* @param type
*/
Boundary(int dim, BC_TYPE type);
/**
* @brief Set the Boundary Condition Type object
*
* @param type
*/
void setBoundaryConditionType(BC_TYPE type);
Boundary(Grid grid, BC_TYPE type);
/**
* @brief Get the Boundary Condition Type object
@ -65,7 +52,7 @@ class Boundary {
private:
int dim;
Grid grid;
BC_TYPE type;
VectorXd left, right, top, bottom;
};

View File

@ -8,17 +8,17 @@ class Grid {
/**
* @brief Construct a new Grid object
*
* @param n
* @param col
*/
Grid(int n);
Grid(int col);
/**
* @brief Construct a new Grid object
*
* @param n
* @param m
* @param row
* @param col
*/
Grid(int n, int m);
Grid(int row, int col);
/**
* @brief Set the Concentrations object
@ -49,12 +49,18 @@ class Grid {
*/
void setAlpha(Matrix2d alpha_x, Matrix2d alpha_y);
auto getDim();
auto getRow();
auto getCol();
private:
int dim;
int n;
int m;
int row;
int col;
Matrix2d concentrations;
Matrix2d alpha_x;
Matrix2d alpha_y;

View File

@ -0,0 +1,20 @@
#include <tug/Boundary.hpp>
#include <stdexcept>
using namespace std;
Boundary::Boundary(Grid grid, BC_TYPE type) {
this->type = type;
if (type == BC_TYPE_CONSTANT) {
if (grid.getDim() == 1) {
this->left = VectorXd::Constant(1, 1, 1);
this->right = VectorXd::Constant(1, 1, 1);
} else if (grid.getDim() == 2) {
this->left = VectorXd::Constant(1, 1, 1);
this->right = VectorXd::Constant(1, 1, 1);
} else {
throw invalid_argument("Dimension must be 1 or 2!");
}
}
}

View File

@ -0,0 +1,48 @@
#include <tug/Grid.hpp>
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);
}
Grid::Grid(int row, int col) {
this->row = row;
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);
}
void Grid::setConcentrations(Matrix2d concentrations) {
this->concentrations = concentrations;
}
auto Grid::getConcentrations() {
return this->concentrations;
}
void Grid::setAlpha(Matrix2d alpha) {
this->alpha_x = alpha;
}
void Grid::setAlpha(Matrix2d alpha_x, Matrix2d alpha_y) {
this->alpha_x = alpha_x;
this->alpha_y = alpha_y;
}
auto Grid::getDim() {
return dim;
}
auto Grid::getRow() {
return row;
}
auto Grid::getCol() {
return col;
}