mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 09:28:23 +01:00
Merge branch 'boundaries-closed-case' into dynamic-boundary-conditions-functionality
This commit is contained in:
commit
9703dba718
@ -2,6 +2,7 @@
|
||||
#define BOUNDARY_H_
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <cstddef>
|
||||
#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<BoundaryElement> getWall();
|
||||
|
||||
void setBoundaryElement(int index, BC_TYPE type, double value = NAN);
|
||||
|
||||
BoundaryElement getBoundaryElement();
|
||||
|
||||
private:
|
||||
BC_SIDE side;
|
||||
int length;
|
||||
vector<WallElement> wall;
|
||||
vector<BoundaryElement> wall;
|
||||
|
||||
};
|
||||
***********************/
|
||||
|
||||
class Boundary {
|
||||
public:
|
||||
@ -67,40 +69,29 @@ 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<BoundaryElement> getBoundarySide(BC_SIDE side);
|
||||
|
||||
BoundaryElement getBoundaryElement(BC_SIDE side, int index);
|
||||
|
||||
BC_TYPE getBoundaryElementType(BC_SIDE side, int index);
|
||||
|
||||
double getBoundaryElementValue(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<vector<BoundaryElement>> boundaries;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
120
src/Boundary.cpp
120
src/Boundary.cpp
@ -1,68 +1,82 @@
|
||||
#include "tug/BoundaryCondition.hpp"
|
||||
#include <iostream>
|
||||
#include <omp.h>
|
||||
#include <tug/Boundary.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
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<BoundaryElement>(grid.getRow(), BoundaryElement());
|
||||
this->boundaries[BC_SIDE_RIGHT] = vector<BoundaryElement>(grid.getRow(), BoundaryElement());
|
||||
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) {
|
||||
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<BoundaryElement>(grid.getRow(), BoundaryElement());
|
||||
}
|
||||
|
||||
void Boundary::setBoundarySideConstant(BC_SIDE side, double value) {
|
||||
this->boundaries[side] = vector<BoundaryElement>(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<BoundaryElement> Boundary::getBoundarySide(BC_SIDE side) {
|
||||
return this->boundaries[side];
|
||||
}
|
||||
|
||||
BoundaryElement Boundary::getBoundaryElement(BC_SIDE side, int index) {
|
||||
return this->boundaries[side][index];
|
||||
}
|
||||
|
||||
BC_TYPE Boundary::getBoundaryElementType(BC_SIDE side, int index) {
|
||||
return this->boundaries[side][index].getType();
|
||||
}
|
||||
|
||||
double Boundary::getBoundaryElementValue(BC_SIDE side, int index) {
|
||||
return this->boundaries[side][index].getValue();
|
||||
}
|
||||
|
||||
|
||||
13
src/FTCS.cpp
13
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)
|
||||
* (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user