From 154091e405f40ddd67280b082b4658d985b9b0c5 Mon Sep 17 00:00:00 2001 From: Hannes Signer Date: Fri, 4 Aug 2023 15:39:02 +0200 Subject: [PATCH] add user input validation --- include/tug/Boundary.hpp | 28 +++++++--------------------- src/Boundary.cpp | 3 +++ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index f865cef..98d0181 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -1,3 +1,9 @@ +/** + * @file Boundary.hpp + * @brief + * + * + */ #ifndef BOUNDARY_H_ #define BOUNDARY_H_ @@ -43,7 +49,7 @@ class BoundaryElement { * @param value Value of the constant concentration to be assumed at the * corresponding boundary element. */ - BoundaryElement(double value); // TODO negative concentration allowed? + BoundaryElement(double value); /** * @brief Allows changing the boundary type of a corresponding @@ -84,26 +90,6 @@ class BoundaryElement { }; -// TODO can be deleted? -// class BoundaryWall { -// public: -// BoundaryWall(int length); - -// void setWall(BC_TYPE type, double value = NAN); - -// vector getWall(); - -// void setBoundaryElement(int index, BC_TYPE type, double value = NAN); - -// BoundaryElement getBoundaryElement(); - -// private: -// BC_SIDE side; -// int length; -// vector wall; - -// }; - /** * This class implements the functionality and management of the boundary * conditions in the grid to be simulated. diff --git a/src/Boundary.cpp b/src/Boundary.cpp index 2abc938..18f3daf 100644 --- a/src/Boundary.cpp +++ b/src/Boundary.cpp @@ -23,6 +23,9 @@ void BoundaryElement::setType(BC_TYPE type) { } void BoundaryElement::setValue(double value) { + if(value < 0){ + throw_invalid_argument("No negative concentration allowed."); + } this->value = value; }