From 628e3288beac165ef72a80c27c7e8a67619676c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Wed, 27 Apr 2022 12:37:43 +0200 Subject: [PATCH] Added 2D example with constant bc on left side --- app/CMakeLists.txt | 3 +++ app/main_2D_const.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 app/main_2D_const.cpp diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c92d35b..62b0bfd 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -6,3 +6,6 @@ target_link_libraries(2D PUBLIC diffusion) add_executable(Comp2D main_2D_mdl.cpp) target_link_libraries(Comp2D PUBLIC diffusion) + +add_executable(Const2D main_2D_const.cpp) +target_link_libraries(Const2D PUBLIC diffusion) diff --git a/app/main_2D_const.cpp b/app/main_2D_const.cpp new file mode 100644 index 0000000..e70f8ad --- /dev/null +++ b/app/main_2D_const.cpp @@ -0,0 +1,57 @@ +#include // for copy, max +#include +#include +#include +#include +#include // for std +#include // for vector +using namespace std; + +using namespace Diffusion; + +int main(int argc, char *argv[]) { + + // dimension of grid + int dim = 2; + + int n = 5; + int m = 5; + + // create input + diffusion coefficients for each grid cell + std::vector alpha(n * m, 1 * pow(10, -1)); + std::vector field(n * m, 1 * std::pow(10, -6)); + std::vector bc((n + 2) * (m + 2), {0, 0}); + + // create instance of diffusion module + BTCSDiffusion diffu(dim); + + diffu.setXDimensions(1, n); + diffu.setYDimensions(1, m); + + for (int i = 1; i <= n; i++) { + bc[(n + 2) * i] = {Diffusion::BC_CONSTANT, 5 * std::pow(10, -6)}; + } + // set timestep for simulation to 1 second + diffu.setTimestep(1.); + + cout << setprecision(12); + + for (int t = 0; t < 10; t++) { + diffu.simulate(field.data(), alpha.data(), bc.data()); + + cout << "Iteration: " << t << "\n\n"; + + // iterate through rows + for (int i = 0; i < m; i++) { + // iterate through columns + for (int j = 0; j < n; j++) { + cout << left << std::setw(20) << field[i * n + j]; + } + cout << "\n"; + } + + cout << "\n" << endl; + } + + return 0; +}