From bd59f4dd059600a1ded6fbbf3641d212e12bdcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Fri, 17 Jun 2022 12:11:44 +0200 Subject: [PATCH] Add support for vector output/input --- include/diffusion/BTCSBoundaryCondition.hpp | 25 ++++++++++++++ src/BTCSBoundaryCondition.cpp | 38 +++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/diffusion/BTCSBoundaryCondition.hpp b/include/diffusion/BTCSBoundaryCondition.hpp index 1bf5c11..b4adef4 100644 --- a/include/diffusion/BTCSBoundaryCondition.hpp +++ b/include/diffusion/BTCSBoundaryCondition.hpp @@ -96,6 +96,31 @@ public: */ void setSide(uint8_t side, boundary_condition &input_bc); + /** + * Sets the boundary condition for a specific side of the grid. + * + * \param side Side for which the given boundary condition should be set. + * \param input_bc Vector of boundary conditions for specific side. + * + * \throws std::invalid_argument Indicates wrong dimensions of the grid. + * \throws std::out_of_range Indicates a out of range value for side or + * invalid size of input vector. + */ + void setSide(uint8_t side, std::vector &input_bc); + + /** + * Returns a vector of boundary conditions of given side. Can be used to set + * custom boundary conditions and set back via setSide() with vector input. + * + * \param side Side which boundary conditions should be returned + * + * \returns Vector of boundary conditions + * + * \throws std::invalid_argument If given dimension is less or equal to 1. + * \throws std::out_of_range Indicates a out of range value for side. + */ + auto getSide(uint8_t side) -> std::vector; + /** * Get both boundary conditions of a given row (left and right). * diff --git a/src/BTCSBoundaryCondition.cpp b/src/BTCSBoundaryCondition.cpp index 5b92a00..4a0b172 100644 --- a/src/BTCSBoundaryCondition.cpp +++ b/src/BTCSBoundaryCondition.cpp @@ -1,6 +1,8 @@ +#include #include #include #include +#include constexpr uint8_t DIM_1D = 2; constexpr uint8_t DIM_2D = 4; @@ -32,6 +34,42 @@ void Diffusion::BTCSBoundaryCondition::setSide( } } +void Diffusion::BTCSBoundaryCondition::setSide( + uint8_t side, std::vector &input_bc) { + if (this->dim == 1) { + throw std::invalid_argument("setSide requires at least a 2D grid"); + } + if (side > 3) { + throw std::out_of_range("Invalid range for 2D grid"); + } + if (input_bc.size() > this->maxsize) { + throw std::out_of_range( + "Input vector is greater than maximum excpected value"); + } + + for (int i = 0; i < input_bc.size(); i++) { + bc_internal[this->maxsize * side + i] = input_bc[i]; + } +} + +auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side) + -> std::vector { + if (this->dim == 1) { + throw std::invalid_argument("getSide requires at least a 2D grid"); + } + if (side > 3) { + throw std::out_of_range("Invalid range for 2D grid"); + } + + std::vector out(this->maxsize); + + for (int i = 0; i < this->maxsize; i++) { + out[i] = this->bc_internal[this->maxsize * side + i]; + } + + return out; +} + auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const -> Diffusion::bc_tuple { if (this->dim == 1) {