From c798c61706070f4f38660cab7fdc5af384afa278 Mon Sep 17 00:00:00 2001 From: philippun Date: Tue, 6 Jun 2023 10:10:12 +0200 Subject: [PATCH] additional example --- examples/CMakeLists.txt | 4 +++- examples/boundary_example1D.cpp | 35 +++++++++++++++++++++++++++++++ include/tug/BoundaryCondition.hpp | 7 +++++-- src/BoundaryCondition.cpp | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 examples/boundary_example1D.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c51ac9f..9723c76 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,7 @@ add_executable(first_example first_example.cpp) add_executable(second_example second_example.cpp) +add_executable(boundary_example1D boundary_example1D.cpp) target_link_libraries(first_example tug) -target_link_libraries(second_example tug) \ No newline at end of file +target_link_libraries(second_example tug) +target_link_libraries(boundary_example1D tug) \ No newline at end of file diff --git a/examples/boundary_example1D.cpp b/examples/boundary_example1D.cpp new file mode 100644 index 0000000..4237f11 --- /dev/null +++ b/examples/boundary_example1D.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +using namespace std; +using namespace tug::bc; +using namespace tug::diffusion; + +int main(int argc, char *argv[]) { + TugInput input; + + BoundaryCondition example(10); + + uint8_t side = BC_SIDE_LEFT; + boundary_condition bc; + bc.type = BC_TYPE_CONSTANT; + bc.value = 1; + input.setBoundaryCondition(example); + BoundaryCondition returnedBC = input.getBoundaryCondition(); + + // example.setSide(side, bc); + vector result_left = example.getSide(side); + // vector result_top = example.getSide(BC_SIDE_TOP); + + for (auto i : result_left) { + cout << i.value << " "; + } + cout << endl; + // for (auto i : result_top) { + // cout << i.value << " "; + // } + // cout << endl; +} \ No newline at end of file diff --git a/include/tug/BoundaryCondition.hpp b/include/tug/BoundaryCondition.hpp index 498d519..2d2e110 100644 --- a/include/tug/BoundaryCondition.hpp +++ b/include/tug/BoundaryCondition.hpp @@ -13,7 +13,8 @@ namespace tug { namespace bc { enum { - BC_TYPE_CLOSED, /**< Defines a closed/Neumann boundary condition. */ + // flux = Neumann? Cauchy combination of Neumann and Dirichlet? + BC_TYPE_CLOSED, /**< Defines a closed boundary condition (special case of Neumann condition). */ BC_TYPE_FLUX, /**< Defines a flux/Cauchy boundary condition. */ BC_TYPE_CONSTANT, /**< Defines a constant/Dirichlet boundary condition. */ BC_UNSET /**< Indicates undefined boundary condition*/ @@ -66,9 +67,11 @@ public: * elements than needed and no exception is thrown if some index exceeding * grid limits. * + * QUESTION: why not use non-squared grids with the correct size? + * * \param x Number of grid cells in x-direction * \param y Number of grid cells in y-direction - * + * */ BoundaryCondition(int x, int y); diff --git a/src/BoundaryCondition.cpp b/src/BoundaryCondition.cpp index 6aa2026..63f5bc8 100644 --- a/src/BoundaryCondition.cpp +++ b/src/BoundaryCondition.cpp @@ -32,6 +32,7 @@ tug::bc::BoundaryCondition::BoundaryCondition(int x, int y) { void tug::bc::BoundaryCondition::setSide( uint8_t side, tug::bc::boundary_condition &input_bc) { + // QUESTION: why cant the BC be changed for dim = 1? if (this->dim == 1) { throw_invalid_argument("setSide requires at least a 2D grid"); }