Add functions to retrieve inner boundary rows and columns

This commit is contained in:
Max Luebke 2024-04-04 14:09:34 +02:00
parent cb0c21eab9
commit 7ae35dccf9
2 changed files with 71 additions and 0 deletions

View File

@ -460,6 +460,67 @@ public:
return std::make_pair(true, it->second);
}
/**
* @brief Get inner constant boundary conditions of a row as a vector. Can be
* used for 1D grids (row == 0) or 2D grids.
*
* @param row Index of the row for which the inner boundary conditions are to
* be returned.
* @return std::vector<std::pair<bool, T>> Vector of pairs of boolean (whether
* constant boundary was set or not) and value of the inner constant boundary
* condition
*/
std::vector<std::pair<bool, T>> getInnerBoundaryRow(std::uint32_t row) const {
if (row >= this->rows) {
throw std::invalid_argument("Index is out of bounds.");
}
if (inner_boundary.empty()) {
return std::vector<std::pair<bool, T>>(this->cols,
std::make_pair(false, -1));
}
std::vector<std::pair<bool, T>> row_values;
for (std::uint32_t col = 0; col < this->cols; col++) {
row_values.push_back(getInnerBoundary(row, col));
}
return row_values;
}
/**
* @brief Get inner constant boundary conditions of a column as a vector. Can
* only be used for 2D grids.
*
* @param col Index of the column for which the inner boundary conditions are
* to be returned.
* @return std::vector<std::pair<bool, T>> Vector of pairs of boolean (whether
* constant boundary was set or not) and value of the inner constant boundary
* condition
*/
std::vector<std::pair<bool, T>> getInnerBoundaryCol(std::uint32_t col) const {
if (this->dim != 2) {
throw std::invalid_argument(
"This function is only available for 2D grids.");
}
if (col >= this->cols) {
throw std::invalid_argument("Index is out of bounds.");
}
if (inner_boundary.empty()) {
return std::vector<std::pair<bool, T>>(this->rows,
std::make_pair(false, -1));
}
std::vector<std::pair<bool, T>> col_values;
for (std::uint32_t row = 0; row < this->rows; row++) {
col_values.push_back(getInnerBoundary(row, col));
}
return col_values;
}
private:
const std::uint8_t dim;
const std::uint32_t cols;

View File

@ -5,6 +5,7 @@
#include <tug/Boundary.hpp>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
using namespace tug;
@ -40,6 +41,12 @@ TEST_CASE("Boundary Class") {
constexpr std::pair<bool, double> innerBoundary =
std::make_pair(true, inner_condition_value);
std::vector<std::pair<bool, double>> row_ibc(12, std::make_pair(false, -1));
row_ibc[1] = innerBoundary;
std::vector<std::pair<bool, double>> col_ibc(10, std::make_pair(false, -1));
col_ibc[0] = innerBoundary;
SUBCASE("Boundaries 1D case") {
CHECK_NOTHROW(Boundary boundary(grid1D));
CHECK_EQ(boundary1D.getBoundarySide(BC_SIDE_LEFT).size(), 1);
@ -88,5 +95,8 @@ TEST_CASE("Boundary Class") {
CHECK_NOTHROW(boundary2D.setInnerBoundary(0, 1, inner_condition_value));
CHECK_EQ(boundary2D.getInnerBoundary(0, 1), innerBoundary);
CHECK_EQ(boundary2D.getInnerBoundary(0, 2).first, false);
CHECK_EQ(boundary2D.getInnerBoundaryRow(0), row_ibc);
CHECK_EQ(boundary2D.getInnerBoundaryCol(1), col_ibc);
}
}