From 7ae35dccf927c405683af1148c54546b89245a66 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 4 Apr 2024 14:09:34 +0200 Subject: [PATCH] Add functions to retrieve inner boundary rows and columns --- include/tug/Boundary.hpp | 61 ++++++++++++++++++++++++++++++++++++++++ test/testBoundary.cpp | 10 +++++++ 2 files changed, 71 insertions(+) diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index 5bcfdb0..a8c2f6d 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -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> Vector of pairs of boolean (whether + * constant boundary was set or not) and value of the inner constant boundary + * condition + */ + std::vector> 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>(this->cols, + std::make_pair(false, -1)); + } + + std::vector> 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> Vector of pairs of boolean (whether + * constant boundary was set or not) and value of the inner constant boundary + * condition + */ + std::vector> 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>(this->rows, + std::make_pair(false, -1)); + } + + std::vector> 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; diff --git a/test/testBoundary.cpp b/test/testBoundary.cpp index 14bd703..471c985 100644 --- a/test/testBoundary.cpp +++ b/test/testBoundary.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; using namespace tug; @@ -40,6 +41,12 @@ TEST_CASE("Boundary Class") { constexpr std::pair innerBoundary = std::make_pair(true, inner_condition_value); + std::vector> row_ibc(12, std::make_pair(false, -1)); + row_ibc[1] = innerBoundary; + + std::vector> 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); } }