diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index 1f25346..5bcfdb0 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -8,10 +8,11 @@ #define BOUNDARY_H_ #include "Grid.hpp" -#include + #include #include -#include +#include +#include #include namespace tug { @@ -375,6 +376,90 @@ public: } } + /** + * + * @param index Index of the inner constant boundary condition + * @param value Value of the inner constant boundary condition + */ + void setInnerBoundary(std::uint32_t index, T value) { + if (this->dim != 1) { + throw std::invalid_argument( + "This function is only available for 1D grids."); + } + if (index >= this->cols) { + throw std::invalid_argument("Index is out of bounds."); + } + + this->inner_boundary[std::make_pair(0, index)] = value; + } + + /** + * @brief Set inner constant boundary condition in 2D case. + * + * @param row Row index of the inner constant boundary condition + * @param col Column index of the inner constant boundary condition + * @param value Value of the inner constant boundary condition + */ + void setInnerBoundary(std::uint32_t row, std::uint32_t col, T value) { + if (this->dim != 2) { + throw std::invalid_argument( + "This function is only available for 2D grids."); + } + if (row >= this->rows || col >= this->cols) { + throw std::invalid_argument("Index is out of bounds."); + } + + this->inner_boundary[std::make_pair(row, col)] = value; + } + + /** + * @brief Get inner constant boundary condition in 1D case. + * + * @param index Index of the inner constant boundary condition + * @return std::pair Pair of boolean (whether constant boundary was + * set or not) and value of the inner constant boundary condition + */ + std::pair getInnerBoundary(std::uint32_t index) const { + if (this->dim != 1) { + throw std::invalid_argument( + "This function is only available for 1D grids."); + } + if (index >= this->cols) { + throw std::invalid_argument("Index is out of bounds."); + } + + auto it = this->inner_boundary.find(std::make_pair(0, index)); + if (it == this->inner_boundary.end()) { + return std::make_pair(false, -1); + } + return std::make_pair(true, it->second); + } + + /** + * @brief Get inner constant boundary condition in 2D case. + * + * @param row Row index of the inner constant boundary condition + * @param col Column index of the inner constant boundary condition + * @return std::pair Pair of boolean (whether constant boundary was + * set or not) and value of the inner constant boundary condition + */ + std::pair getInnerBoundary(std::uint32_t row, + std::uint32_t col) const { + if (this->dim != 2) { + throw std::invalid_argument( + "This function is only available for 2D grids."); + } + if (row >= this->rows || col >= this->cols) { + throw std::invalid_argument("Index is out of bounds."); + } + + auto it = this->inner_boundary.find(std::make_pair(row, col)); + if (it == this->inner_boundary.end()) { + return std::make_pair(false, -1); + } + return std::make_pair(true, it->second); + } + private: const std::uint8_t dim; const std::uint32_t cols; @@ -382,6 +467,9 @@ private: std::vector>> boundaries; // Vector with Boundary Element information + + // Inner boundary conditions for 1D and 2D grids identified by (row,col) + std::map, T> inner_boundary; }; } // namespace tug #endif // BOUNDARY_H_ diff --git a/test/testBoundary.cpp b/test/testBoundary.cpp index a7b2b5e..14bd703 100644 --- a/test/testBoundary.cpp +++ b/test/testBoundary.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std; using namespace tug; @@ -35,6 +36,10 @@ TEST_CASE("Boundary Class") { Boundary boundary2D = Boundary(grid2D); vector> boundary1DVector(1, BoundaryElement(1.0)); + constexpr double inner_condition_value = -5; + constexpr std::pair innerBoundary = + std::make_pair(true, inner_condition_value); + SUBCASE("Boundaries 1D case") { CHECK_NOTHROW(Boundary boundary(grid1D)); CHECK_EQ(boundary1D.getBoundarySide(BC_SIDE_LEFT).size(), 1); @@ -52,6 +57,11 @@ TEST_CASE("Boundary Class") { BC_TYPE_CONSTANT); CHECK_EQ(boundary1D.getBoundaryElement(BC_SIDE_LEFT, 0).getType(), boundary1DVector[0].getType()); + + CHECK_NOTHROW(boundary1D.setInnerBoundary(0, inner_condition_value)); + CHECK_THROWS(boundary1D.setInnerBoundary(0, 0, inner_condition_value)); + CHECK_EQ(boundary1D.getInnerBoundary(0), innerBoundary); + CHECK_EQ(boundary1D.getInnerBoundary(1).first, false); } SUBCASE("Boundaries 2D case") { @@ -73,5 +83,10 @@ TEST_CASE("Boundary Class") { BC_TYPE_CONSTANT); CHECK_EQ(boundary2D.getBoundaryElement(BC_SIDE_LEFT, 0).getType(), boundary1DVector[0].getType()); + + CHECK_THROWS(boundary2D.setInnerBoundary(0, inner_condition_value)); + CHECK_NOTHROW(boundary2D.setInnerBoundary(0, 1, inner_condition_value)); + CHECK_EQ(boundary2D.getInnerBoundary(0, 1), innerBoundary); + CHECK_EQ(boundary2D.getInnerBoundary(0, 2).first, false); } } diff --git a/test/testSimulation.cpp b/test/testSimulation.cpp index 2bd831e..7b66c1c 100644 --- a/test/testSimulation.cpp +++ b/test/testSimulation.cpp @@ -1,10 +1,10 @@ #include "TestUtils.hpp" +#include #include #include #include #include -#include // include the configured header file #include