From 5196c36ec58ec61def4084b19065d4c1face0b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Fri, 15 Sep 2023 11:37:42 +0200 Subject: [PATCH] fix: reintroduce tug namespace --- include/tug/Boundary.hpp | 19 +++++++++++++------ include/tug/Grid.hpp | 4 +++- include/tug/Simulation.hpp | 4 +++- src/BTCS.cpp | 3 +++ src/FTCS.cpp | 3 +++ src/Schemes.hpp | 11 ++++++++--- src/Simulation.cpp | 3 +++ test/testBoundary.cpp | 2 ++ test/testGrid.cpp | 2 +- test/testSimulation.cpp | 1 + 10 files changed, 40 insertions(+), 12 deletions(-) diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index b51df24..4870ae2 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -12,6 +12,8 @@ #include #include +namespace tug { + /** * @brief Enum defining the two implemented boundary conditions. * @@ -191,7 +193,8 @@ public: void setBoundaryElemenClosed(BC_SIDE side, int index) { // tests whether the index really points to an element of the boundary side. if ((boundaries[side].size() < index) || index < 0) { - throw std::invalid_argument("Index is selected either too large or too small."); + throw std::invalid_argument( + "Index is selected either too large or too small."); } this->boundaries[side][index].setType(BC_TYPE_CLOSED); } @@ -211,7 +214,8 @@ public: void setBoundaryElementConstant(BC_SIDE side, int index, double value) { // tests whether the index really points to an element of the boundary side. if ((boundaries[side].size() < index) || index < 0) { - throw std::invalid_argument("Index is selected either too large or too small."); + throw std::invalid_argument( + "Index is selected either too large or too small."); } this->boundaries[side][index].setType(BC_TYPE_CONSTANT); this->boundaries[side][index].setValue(value); @@ -272,7 +276,8 @@ public: */ BoundaryElement getBoundaryElement(BC_SIDE side, int index) const { if ((boundaries[side].size() < index) || index < 0) { - throw std::invalid_argument("Index is selected either too large or too small."); + throw std::invalid_argument( + "Index is selected either too large or too small."); } return this->boundaries[side][index]; } @@ -289,7 +294,8 @@ public: */ BC_TYPE getBoundaryElementType(BC_SIDE side, int index) const { if ((boundaries[side].size() < index) || index < 0) { - throw std::invalid_argument("Index is selected either too large or too small."); + throw std::invalid_argument( + "Index is selected either too large or too small."); } return this->boundaries[side][index].getType(); } @@ -308,7 +314,8 @@ public: */ T getBoundaryElementValue(BC_SIDE side, int index) const { if ((boundaries[side].size() < index) || index < 0) { - throw std::invalid_argument("Index is selected either too large or too small."); + throw std::invalid_argument( + "Index is selected either too large or too small."); } if (boundaries[side][index].getType() != BC_TYPE_CONSTANT) { throw std::invalid_argument( @@ -325,5 +332,5 @@ private: std::vector>> boundaries; // Vector with Boundary Element information }; - +} // namespace tug #endif // BOUNDARY_H_ diff --git a/include/tug/Grid.hpp b/include/tug/Grid.hpp index 3d3638d..9698184 100644 --- a/include/tug/Grid.hpp +++ b/include/tug/Grid.hpp @@ -12,6 +12,8 @@ #include #include +namespace tug { + template class Grid { public: /** @@ -321,5 +323,5 @@ private: using Grid64 = Grid; using Grid32 = Grid; - +} // namespace tug #endif // GRID_H_ diff --git a/include/tug/Simulation.hpp b/include/tug/Simulation.hpp index 7ed50c4..e83d8f4 100644 --- a/include/tug/Simulation.hpp +++ b/include/tug/Simulation.hpp @@ -25,6 +25,8 @@ #define omp_get_num_procs() 1 #endif +namespace tug { + /** * @brief Enum defining the two implemented solution approaches. * @@ -343,5 +345,5 @@ private: const std::vector approach_names = {"FTCS", "BTCS", "CRNI"}; }; - +} // namespace tug #endif // SIMULATION_H_ diff --git a/src/BTCS.cpp b/src/BTCS.cpp index 7a9dc7e..e166519 100644 --- a/src/BTCS.cpp +++ b/src/BTCS.cpp @@ -22,6 +22,8 @@ #define omp_get_thread_num() 0 #endif +namespace tug { + // calculates coefficient for boundary in constant case template constexpr std::pair calcBoundaryCoeffConstant(T alpha_center, @@ -436,3 +438,4 @@ template void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads); template void BTCS_LU(Grid &grid, Boundary &bc, float timestep, int numThreads); +} // namespace tug diff --git a/src/FTCS.cpp b/src/FTCS.cpp index 5ee4657..914cc41 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -18,6 +18,8 @@ #define omp_get_thread_num() 0 #endif +namespace tug { + // calculates horizontal change on one cell independent of boundary type template static inline T calcHorizontalChange(Grid &grid, int &row, int &col) { @@ -400,3 +402,4 @@ template void FTCS(Grid &grid, Boundary &bc, double timestep, int &numThreads); template void FTCS(Grid &grid, Boundary &bc, float timestep, int &numThreads); +} // namespace tug diff --git a/src/Schemes.hpp b/src/Schemes.hpp index 771a2a4..09e6d9e 100644 --- a/src/Schemes.hpp +++ b/src/Schemes.hpp @@ -15,17 +15,22 @@ #include #include +namespace tug { + // entry point; differentiate between 1D and 2D grid template -extern void FTCS(Grid &grid, Boundary &bc, T timestep, int &numThreads); +extern void FTCS(tug::Grid &grid, tug::Boundary &bc, T timestep, + int &numThreads); // entry point for EigenLU solver; differentiate between 1D and 2D grid template -extern void BTCS_LU(Grid &grid, Boundary &bc, T timestep, int numThreads); +extern void BTCS_LU(tug::Grid &grid, tug::Boundary &bc, T timestep, + int numThreads); // entry point for Thomas algorithm solver; differentiate 1D and 2D grid template -extern void BTCS_Thomas(Grid &grid, Boundary &bc, T timestep, +extern void BTCS_Thomas(tug::Grid &grid, tug::Boundary &bc, T timestep, int numThreads); +} // namespace tug #endif // SCHEMES_H_ diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 90a1459..ca623d4 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -12,6 +12,8 @@ #include "Schemes.hpp" #include "TugUtils.hpp" +namespace tug { + template void Simulation::setTimestep(T timestep) { if (timestep <= 0) { throw_invalid_argument("Timestep has to be greater than zero."); @@ -200,3 +202,4 @@ template void Simulation::setTimestep(float timestep); template void Simulation::run(); template void Simulation::run(); +} // namespace tug diff --git a/test/testBoundary.cpp b/test/testBoundary.cpp index be91b1e..a7b2b5e 100644 --- a/test/testBoundary.cpp +++ b/test/testBoundary.cpp @@ -6,6 +6,8 @@ #include using namespace std; +using namespace tug; + TEST_CASE("BoundaryElement") { SUBCASE("Closed case") { diff --git a/test/testGrid.cpp b/test/testGrid.cpp index ba831d3..d0179dd 100644 --- a/test/testGrid.cpp +++ b/test/testGrid.cpp @@ -4,7 +4,7 @@ using namespace Eigen; using namespace std; - +using namespace tug; TEST_CASE("1D Grid, too small length") { int l = 2; diff --git a/test/testSimulation.cpp b/test/testSimulation.cpp index e1b0cf3..a7600c5 100644 --- a/test/testSimulation.cpp +++ b/test/testSimulation.cpp @@ -10,6 +10,7 @@ using namespace Eigen; using namespace std; +using namespace tug; static Grid64 setupSimulation(APPROACH approach, double timestep, int iterations) {