Add support for vector output/input

This commit is contained in:
Max Lübke 2022-06-17 12:11:44 +02:00
parent c3a0188dac
commit bd59f4dd05
2 changed files with 63 additions and 0 deletions

View File

@ -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<boundary_condition> &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<boundary_condition>;
/**
* Get both boundary conditions of a given row (left and right).
*

View File

@ -1,6 +1,8 @@
#include <algorithm>
#include <bits/stdint-uintn.h>
#include <diffusion/BTCSBoundaryCondition.hpp>
#include <stdexcept>
#include <vector>
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<Diffusion::boundary_condition> &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<Diffusion::boundary_condition> {
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<Diffusion::boundary_condition> 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) {