feat: reimplented Boundary to incorporate different types for each boundary element

This commit is contained in:
philippun 2023-07-28 12:57:09 +02:00
parent 16d3663909
commit 4680e9823f
3 changed files with 104 additions and 100 deletions

View File

@ -2,6 +2,7 @@
#define BOUNDARY_H_ #define BOUNDARY_H_
#include <Eigen/Core> #include <Eigen/Core>
#include <cstddef>
#include "Grid.hpp" #include "Grid.hpp"
using namespace std; using namespace std;
@ -19,26 +20,21 @@ enum BC_SIDE {
BC_SIDE_BOTTOM BC_SIDE_BOTTOM
}; };
/******************************************* class BoundaryElement {
class WallElement {
public: public:
WallElement() { // bc type closed
this->type = BC_TYPE_CLOSED; BoundaryElement();
this->value = 0;
}
WallElement(double value) { // bc type constant
this->type = BC_TYPE_CONSTANT; BoundaryElement(double value);
this->value = value;
}
BC_TYPE getType() { void setType(BC_TYPE type);
return this->type;
}
double getValue() { void setValue(double value);
return this->value;
} BC_TYPE getType();
double getValue();
private: private:
BC_TYPE type; BC_TYPE type;
@ -47,16 +43,22 @@ class WallElement {
class BoundaryWall { class BoundaryWall {
public: public:
BoundaryWall(int length) { BoundaryWall(int length);
// create array with length many wall elements
} void setWall(BC_TYPE type, double value = NAN);
vector<BoundaryElement> getWall();
void setBoundaryElement(int index, BC_TYPE type, double value = NAN);
BoundaryElement getBoundaryElement();
private: private:
BC_SIDE side; BC_SIDE side;
int length; int length;
vector<WallElement> wall; vector<BoundaryElement> wall;
}; };
***********************/
class Boundary { class Boundary {
public: public:
@ -67,40 +69,24 @@ class Boundary {
* @param grid * @param grid
* @param type * @param type
*/ */
Boundary(Grid grid, BC_TYPE type); Boundary(Grid grid);
/** void setBoundarySideClosed(BC_SIDE side);
* @brief Get the Boundary Condition Type object
*
* @return auto
*/
BC_TYPE getBoundaryConditionType();
/** void setBoundarySideConstant(BC_SIDE side, double value);
* @brief Set the Boundary Condition Value object
*
* @param side
* @param values
*/
void setBoundaryConditionValue(BC_SIDE side, VectorXd values);
/** void setBoundaryElementClosed(BC_SIDE side, int index);
* @brief Get the Boundary Condition Value object
*
* @param side
* @return auto
*/
VectorXd getBoundaryConditionValue(BC_SIDE side);
void setBoundaryElementConstant(BC_SIDE side, int index, double value);
vector<BoundaryElement> getBoundarySide(BC_SIDE side);
BoundaryElement getBoundaryElement(BC_SIDE side, int index);
private: private:
Grid grid; Grid grid;
// need a way to save the bc type and value for each single 'boundary cell' vector<vector<BoundaryElement>> boundaries;
// 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;
}; };
#endif #endif

View File

@ -1,68 +1,73 @@
#include "tug/BoundaryCondition.hpp"
#include <iostream> #include <iostream>
#include <omp.h>
#include <tug/Boundary.hpp> #include <tug/Boundary.hpp>
#include <stdexcept> #include <stdexcept>
using namespace std; using namespace std;
Boundary::Boundary(Grid grid, BC_TYPE type) : grid(grid) { BoundaryElement::BoundaryElement() {
//probably to DEBUG assignment grid 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; 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() { void BoundaryElement::setValue(double value) {
return this->type; this->value = value;
} }
void Boundary::setBoundaryConditionValue(BC_SIDE side, VectorXd values) { BC_TYPE BoundaryElement::getType() {
if (type != BC_TYPE_CONSTANT) { return this->type;
// TODO check if correct way for handling warning }
cerr << "Values will not be used, wrong BC_TYPE!";
}
switch (side) { double BoundaryElement::getValue() {
case BC_SIDE_LEFT: return this->value;
this->left = values; }
break;
case BC_SIDE_RIGHT: Boundary::Boundary(Grid grid) : grid(grid) {
this->right = values; //probably to DEBUG assignment grid
break;
case BC_SIDE_TOP:
this->top = values; if (grid.getDim() == 1) {
break; this->boundaries[BC_SIDE_LEFT].push_back(BoundaryElement());
case BC_SIDE_BOTTOM: this->boundaries[BC_SIDE_RIGHT].push_back(BoundaryElement());
this->bottom = values; } else if (grid.getDim() == 2) {
break; this->boundaries[BC_SIDE_LEFT] = vector<BoundaryElement>(grid.getRow(), BoundaryElement());
default: this->boundaries[BC_SIDE_RIGHT] = vector<BoundaryElement>(grid.getRow(), BoundaryElement());
throw invalid_argument("Invalid side given!"); this->boundaries[BC_SIDE_TOP] = vector<BoundaryElement>(grid.getCol(), BoundaryElement());
this->boundaries[BC_SIDE_BOTTOM] = vector<BoundaryElement>(grid.getCol(), BoundaryElement());
} }
} }
VectorXd Boundary::getBoundaryConditionValue(BC_SIDE side) { void Boundary::setBoundarySideClosed(BC_SIDE side) {
switch (side) { this->boundaries[side] = vector<BoundaryElement>(grid.getRow(), BoundaryElement());
case BC_SIDE_LEFT: }
return this->left;
case BC_SIDE_RIGHT: void Boundary::setBoundarySideConstant(BC_SIDE side, double value) {
return this->right; this->boundaries[side] = vector<BoundaryElement>(grid.getRow(), BoundaryElement(value));
case BC_SIDE_TOP: }
return this->top;
case BC_SIDE_BOTTOM: void Boundary::setBoundaryElementClosed(BC_SIDE side, int index) {
return this->bottom; this->boundaries[side][index].setType(BC_TYPE_CLOSED);
default: }
throw invalid_argument("Invalid side given!");
} 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<BoundaryElement> Boundary::getBoundarySide(BC_SIDE side) {
return this->boundaries[side];
}
BoundaryElement Boundary::getBoundaryElement(BC_SIDE side, int index) {
return this->boundaries[side][index];
} }

View File

@ -224,6 +224,19 @@ MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) {
// left without corners / looping over rows // left without corners / looping over rows
int col = 0; int col = 0;
for (int row = 1; row < rowMax-1; row++) { 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) concentrations_t1(row, col) = grid.getConcentrations()(row,col)
+ timestep / (deltaCol*deltaCol) + timestep / (deltaCol*deltaCol)
* ( * (