diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index df3ad0f..c4ad577 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -2,6 +2,7 @@ #define BOUNDARY_H_ #include +#include #include "Grid.hpp" using namespace std; @@ -19,26 +20,21 @@ enum BC_SIDE { BC_SIDE_BOTTOM }; -/******************************************* -class WallElement { +class BoundaryElement { public: - WallElement() { - this->type = BC_TYPE_CLOSED; - this->value = 0; - } + // bc type closed + BoundaryElement(); - WallElement(double value) { - this->type = BC_TYPE_CONSTANT; - this->value = value; - } + // bc type constant + BoundaryElement(double value); - BC_TYPE getType() { - return this->type; - } + void setType(BC_TYPE type); - double getValue() { - return this->value; - } + void setValue(double value); + + BC_TYPE getType(); + + double getValue(); private: BC_TYPE type; @@ -47,16 +43,22 @@ class WallElement { class BoundaryWall { public: - BoundaryWall(int length) { - // create array with length many wall elements - } + BoundaryWall(int length); + + void setWall(BC_TYPE type, double value = NAN); + + vector getWall(); + + void setBoundaryElement(int index, BC_TYPE type, double value = NAN); + + BoundaryElement getBoundaryElement(); private: BC_SIDE side; int length; - vector wall; + vector wall; + }; -***********************/ class Boundary { public: @@ -67,40 +69,24 @@ class Boundary { * @param grid * @param type */ - Boundary(Grid grid, BC_TYPE type); + Boundary(Grid grid); - /** - * @brief Get the Boundary Condition Type object - * - * @return auto - */ - BC_TYPE getBoundaryConditionType(); + void setBoundarySideClosed(BC_SIDE side); - /** - * @brief Set the Boundary Condition Value object - * - * @param side - * @param values - */ - void setBoundaryConditionValue(BC_SIDE side, VectorXd values); + void setBoundarySideConstant(BC_SIDE side, double value); - /** - * @brief Get the Boundary Condition Value object - * - * @param side - * @return auto - */ - VectorXd getBoundaryConditionValue(BC_SIDE side); + void setBoundaryElementClosed(BC_SIDE side, int index); + void setBoundaryElementConstant(BC_SIDE side, int index, double value); + + vector getBoundarySide(BC_SIDE side); + + BoundaryElement getBoundaryElement(BC_SIDE side, int index); private: Grid grid; - - // need a way to save the bc type and value for each single 'boundary cell' - // perhaps an array for each side with structs containing the bc type as well as a value - // or another object that contains one boundary side - BC_TYPE type; - VectorXd left, right, top, bottom; + + vector> boundaries; }; #endif diff --git a/src/Boundary.cpp b/src/Boundary.cpp index 516c422..3c3ac04 100644 --- a/src/Boundary.cpp +++ b/src/Boundary.cpp @@ -1,68 +1,73 @@ +#include "tug/BoundaryCondition.hpp" #include +#include #include #include using namespace std; -Boundary::Boundary(Grid grid, BC_TYPE type) : grid(grid) { - //probably to DEBUG assignment grid +BoundaryElement::BoundaryElement() { + this->type = BC_TYPE_CLOSED; + this->value = NAN; +} + +BoundaryElement::BoundaryElement(double value) { + this->type = BC_TYPE_CONSTANT; + this->value = value; +} + +void BoundaryElement::setType(BC_TYPE type) { this->type = type; - - if (type == BC_TYPE_CONSTANT) { - if (grid.getDim() == 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); - 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!"); - } - } } -BC_TYPE Boundary::getBoundaryConditionType() { - return this->type; +void BoundaryElement::setValue(double value) { + this->value = value; } -void Boundary::setBoundaryConditionValue(BC_SIDE side, VectorXd values) { - if (type != BC_TYPE_CONSTANT) { - // TODO check if correct way for handling warning - cerr << "Values will not be used, wrong BC_TYPE!"; - } +BC_TYPE BoundaryElement::getType() { + return this->type; +} - switch (side) { - case BC_SIDE_LEFT: - this->left = values; - break; - case BC_SIDE_RIGHT: - this->right = values; - break; - case BC_SIDE_TOP: - this->top = values; - break; - case BC_SIDE_BOTTOM: - this->bottom = values; - break; - default: - throw invalid_argument("Invalid side given!"); +double BoundaryElement::getValue() { + return this->value; +} + +Boundary::Boundary(Grid grid) : grid(grid) { + //probably to DEBUG assignment grid + + + if (grid.getDim() == 1) { + this->boundaries[BC_SIDE_LEFT].push_back(BoundaryElement()); + this->boundaries[BC_SIDE_RIGHT].push_back(BoundaryElement()); + } else if (grid.getDim() == 2) { + this->boundaries[BC_SIDE_LEFT] = vector(grid.getRow(), BoundaryElement()); + this->boundaries[BC_SIDE_RIGHT] = vector(grid.getRow(), BoundaryElement()); + this->boundaries[BC_SIDE_TOP] = vector(grid.getCol(), BoundaryElement()); + this->boundaries[BC_SIDE_BOTTOM] = vector(grid.getCol(), BoundaryElement()); } } -VectorXd Boundary::getBoundaryConditionValue(BC_SIDE side) { - switch (side) { - case BC_SIDE_LEFT: - return this->left; - case BC_SIDE_RIGHT: - return this->right; - case BC_SIDE_TOP: - return this->top; - case BC_SIDE_BOTTOM: - return this->bottom; - default: - throw invalid_argument("Invalid side given!"); - } +void Boundary::setBoundarySideClosed(BC_SIDE side) { + this->boundaries[side] = vector(grid.getRow(), BoundaryElement()); +} + +void Boundary::setBoundarySideConstant(BC_SIDE side, double value) { + this->boundaries[side] = vector(grid.getRow(), BoundaryElement(value)); +} + +void Boundary::setBoundaryElementClosed(BC_SIDE side, int index) { + this->boundaries[side][index].setType(BC_TYPE_CLOSED); +} + +void Boundary::setBoundaryElementConstant(BC_SIDE side, int index, double value) { + this->boundaries[side][index].setType(BC_TYPE_CONSTANT); + this->boundaries[side][index].setValue(value); +} + +vector Boundary::getBoundarySide(BC_SIDE side) { + return this->boundaries[side]; +} + +BoundaryElement Boundary::getBoundaryElement(BC_SIDE side, int index) { + return this->boundaries[side][index]; } \ No newline at end of file diff --git a/src/FTCS.cpp b/src/FTCS.cpp index bb91844..1b24e5a 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -224,6 +224,19 @@ MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) { // left without corners / looping over rows int col = 0; for (int row = 1; row < rowMax-1; row++) { + // concentrations_t1(row, col) = grid.getConcentrations()(row, col); + // if (bc.getBoundaryConditionType(BC_SIDE_LEFT, row)) { + // concentrations_t1(row, col) += timestep / (deltaCol*deltaCol) + // + calcHorizontalChangeLeftBoundaryClosed(grid, row, col); + // } else { + // concentrations_t1(row, col) += timestep / (deltaCol*deltaCol) + // + calcHorizontalChangeLeftBoundaryConstant(grid, bc, row, col); + // } + // concentrations_t1(row, col) += timestep / (deltaRow*deltaRow) + // * ( + // calcVerticalChange(grid, row, col) + // ); + concentrations_t1(row, col) = grid.getConcentrations()(row,col) + timestep / (deltaCol*deltaCol) * (