mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-14 09:58:22 +01:00
Improve excpetion description
This commit is contained in:
parent
3d6c1e6713
commit
10a1f2757b
15
include/diffusion/BTCSUtils.hpp
Normal file
15
include/diffusion/BTCSUtils.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef BTCSUTILS_H_
|
||||||
|
#define BTCSUTILS_H_
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define throw_invalid_argument(msg) \
|
||||||
|
throw std::invalid_argument(std::string(__FILE__) + ":" + \
|
||||||
|
std::to_string(__LINE__) + ":" + \
|
||||||
|
std::string(msg))
|
||||||
|
|
||||||
|
#define throw_out_of_range(msg) \
|
||||||
|
throw std::out_of_range(std::string(__FILE__) + ":" + \
|
||||||
|
std::to_string(__LINE__) + ":" + std::string(msg))
|
||||||
|
#endif // BTCSUTILS_H_
|
||||||
@ -1,9 +1,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <bits/stdint-uintn.h>
|
#include <bits/stdint-uintn.h>
|
||||||
#include <diffusion/BTCSBoundaryCondition.hpp>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <diffusion/BTCSBoundaryCondition.hpp>
|
||||||
|
#include <diffusion/BTCSUtils.hpp>
|
||||||
|
|
||||||
constexpr uint8_t DIM_1D = 2;
|
constexpr uint8_t DIM_1D = 2;
|
||||||
constexpr uint8_t DIM_2D = 4;
|
constexpr uint8_t DIM_2D = 4;
|
||||||
|
|
||||||
@ -29,10 +30,10 @@ Diffusion::BTCSBoundaryCondition::BTCSBoundaryCondition(int x, int y) {
|
|||||||
void Diffusion::BTCSBoundaryCondition::setSide(
|
void Diffusion::BTCSBoundaryCondition::setSide(
|
||||||
uint8_t side, Diffusion::boundary_condition &input_bc) {
|
uint8_t side, Diffusion::boundary_condition &input_bc) {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw std::invalid_argument("setSide requires at least a 2D grid");
|
throw_invalid_argument("setSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
if (side > 3) {
|
if (side > 3) {
|
||||||
throw std::out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size =
|
||||||
@ -48,10 +49,10 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
void Diffusion::BTCSBoundaryCondition::setSide(
|
void Diffusion::BTCSBoundaryCondition::setSide(
|
||||||
uint8_t side, std::vector<Diffusion::boundary_condition> &input_bc) {
|
uint8_t side, std::vector<Diffusion::boundary_condition> &input_bc) {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw std::invalid_argument("setSide requires at least a 2D grid");
|
throw_invalid_argument("setSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
if (side > 3) {
|
if (side > 3) {
|
||||||
throw std::out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size =
|
||||||
@ -60,8 +61,7 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
: this->sizes[1]);
|
: this->sizes[1]);
|
||||||
|
|
||||||
if (input_bc.size() > size) {
|
if (input_bc.size() > size) {
|
||||||
throw std::out_of_range(
|
throw_out_of_range("Input vector is greater than maximum excpected value");
|
||||||
"Input vector is greater than maximum excpected value");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@ -72,10 +72,10 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
||||||
-> std::vector<Diffusion::boundary_condition> {
|
-> std::vector<Diffusion::boundary_condition> {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw std::invalid_argument("getSide requires at least a 2D grid");
|
throw_invalid_argument("getSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
if (side > 3) {
|
if (side > 3) {
|
||||||
throw std::out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size =
|
||||||
@ -95,10 +95,10 @@ auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
|||||||
auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
||||||
-> Diffusion::bc_tuple {
|
-> Diffusion::bc_tuple {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw std::invalid_argument("Access of column requires at least 2D grid");
|
throw_invalid_argument("Access of column requires at least 2D grid");
|
||||||
}
|
}
|
||||||
if (i >= this->sizes[1]) {
|
if (i >= this->sizes[1]) {
|
||||||
throw std::out_of_range("Index out of range");
|
throw_out_of_range("Index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {this->bc_internal[BC_SIDE_TOP * this->maxsize + i],
|
return {this->bc_internal[BC_SIDE_TOP * this->maxsize + i],
|
||||||
@ -108,7 +108,7 @@ auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
|||||||
auto Diffusion::BTCSBoundaryCondition::row(uint32_t i) const
|
auto Diffusion::BTCSBoundaryCondition::row(uint32_t i) const
|
||||||
-> Diffusion::bc_tuple {
|
-> Diffusion::bc_tuple {
|
||||||
if (i >= this->sizes[0]) {
|
if (i >= this->sizes[0]) {
|
||||||
throw std::out_of_range("Index out of range");
|
throw_out_of_range("Index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {this->bc_internal[BC_SIDE_LEFT * this->maxsize + i],
|
return {this->bc_internal[BC_SIDE_LEFT * this->maxsize + i],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user