From 0dad4f93fd6cc2f43bfb6fe0b6bef409fd6b93f9 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 17 Feb 2022 16:43:04 +0100 Subject: [PATCH 1/4] Change loop index variable --- src/BTCSDiffusion.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/BTCSDiffusion.cpp b/src/BTCSDiffusion.cpp index fd1b5a7..af5907d 100644 --- a/src/BTCSDiffusion.cpp +++ b/src/BTCSDiffusion.cpp @@ -257,27 +257,26 @@ void BTCSDiffusion::fillVectorFromRowADI(Eigen::Map &c, getBCFromFlux(right, c(row, ncol - 1), alpha[ncol - 1]); } - for (int j = 1; j < offset - 1; j++) { - boundary_condition tmp_bc = this->bc(row, j-1); + for (int j = 0; j < ncol; j++) { + boundary_condition tmp_bc = this->bc(row, j); if (tmp_bc.type == BTCSDiffusion::BC_CONSTANT) { - b_vector[offset * row + j] = tmp_bc.value; + b_vector[offset * row + (j+1)] = tmp_bc.value; continue; } double y_values[3]; y_values[0] = - (row != 0 ? c(row - 1, j - 1) - : getBCFromFlux(tmp_bc, c(row, j - 1), alpha[j - 1])); - y_values[1] = c(row, j - 1); + (row != 0 ? c(row - 1, j) : getBCFromFlux(tmp_bc, c(row, j), alpha[j])); + y_values[1] = c(row, j); y_values[2] = - (row != nrow - 1 ? c(row + 1, j - 1) - : getBCFromFlux(tmp_bc, c(row, j - 1), alpha[j - 1])); + (row != nrow - 1 ? c(row + 1, j) + : getBCFromFlux(tmp_bc, c(row, j), alpha[j])); double t0_c = - alpha[j - 1] * + alpha[j] * ((y_values[0] - 2 * y_values[1] + y_values[2]) / (delta * delta)); - b_vector[offset * row + j] = -c(row, j - 1) - t0_c; + b_vector[offset * row + (j + 1)] = -c(row, j) - t0_c; } } From 78ef8c2833e9e7c0a3852fb86c3a5130e81fb647 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 17 Feb 2022 17:02:25 +0100 Subject: [PATCH 2/4] Update calculation of t0_c - Added time dependency by multiplying spacial context with current time step --- doc/ADI_scheme.org | 2 +- src/BTCSDiffusion.cpp | 9 +++++---- src/BTCSDiffusion.hpp | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/ADI_scheme.org b/doc/ADI_scheme.org index 9583783..b719c4a 100644 --- a/doc/ADI_scheme.org +++ b/doc/ADI_scheme.org @@ -93,7 +93,7 @@ c(i,N-1) & \text{else} *** Inlet -$p(i,j) = \alpha(i,j)\frac{c(i-1,j) - 2\cdot c(i,j) + c(i+1,j)}{\Delta x^2}$[fn:1] +$p(i,j) = \frac{\Delta t}{2}\alpha(i,j)\frac{c(i-1,j) - 2\cdot c(i,j) + c(i+1,j)}{\Delta x^2}$[fn:1] $b(i,j) = \begin{cases} bc(i,j).\text{value} & \text{if } bc(i,N-1) = \text{constant} \\ diff --git a/src/BTCSDiffusion.cpp b/src/BTCSDiffusion.cpp index af5907d..4f31c42 100644 --- a/src/BTCSDiffusion.cpp +++ b/src/BTCSDiffusion.cpp @@ -139,6 +139,7 @@ void BTCSDiffusion::simulate1D(Eigen::Map &c, void BTCSDiffusion::simulate2D(Eigen::Map &c, Eigen::Map &alpha) { + double local_dt = this->time_step/ 2.; DMatrixRowMajor tmp_vector; int n_cols = c.cols(); @@ -158,7 +159,7 @@ void BTCSDiffusion::simulate2D(Eigen::Map &c, fillMatrixFromRow(alpha.row(i), n_cols, i, left_constant, right_constant, deltas[0], this->time_step / 2); - fillVectorFromRowADI(c, alpha.row(i), i, deltas[0], left, right); + fillVectorFromRowADI(c, alpha.row(i), i, deltas[0], left, right, local_dt); } solveLES(); @@ -190,7 +191,7 @@ void BTCSDiffusion::simulate2D(Eigen::Map &c, fillMatrixFromRow(alpha.col(i), n_cols, i, left_constant, right_constant, deltas[1], this->time_step / 2); - fillVectorFromRowADI(c, alpha.row(i), i, deltas[1], left, right); + fillVectorFromRowADI(c, alpha.row(i), i, deltas[1], left, right, local_dt); } solveLES(); @@ -274,9 +275,9 @@ void BTCSDiffusion::fillVectorFromRowADI(Eigen::Map &c, : getBCFromFlux(tmp_bc, c(row, j), alpha[j])); double t0_c = - alpha[j] * + time_step * alpha[j] * ((y_values[0] - 2 * y_values[1] + y_values[2]) / (delta * delta)); - b_vector[offset * row + (j + 1)] = -c(row, j) - t0_c; + b_vector[offset * row + (j + 1)] = -c(row, j) - (t0_c); } } diff --git a/src/BTCSDiffusion.hpp b/src/BTCSDiffusion.hpp index ebfda26..8d12660 100644 --- a/src/BTCSDiffusion.hpp +++ b/src/BTCSDiffusion.hpp @@ -153,8 +153,9 @@ private: bool left_constant, bool right_constant, double delta, double time_step); void fillVectorFromRowADI(Eigen::Map &c, - const Eigen::VectorXd alpha, int row, double delta, - boundary_condition left, boundary_condition right); + const Eigen::VectorXd alpha, int row, double delta, + boundary_condition left, boundary_condition right, + double time_step); void simulate3D(std::vector &c); inline double getBCFromFlux(boundary_condition bc, double nearest_value, double neighbor_alpha); From 5f4d81268102f886f3931e1bd4c6ac3da9e8ce81 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 17 Feb 2022 17:39:23 +0100 Subject: [PATCH 3/4] Added CI support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit 8a0d9cea8121f62ea518a9ab2c48ffc334104ecd Author: Max Lübke Date: Tue Feb 15 20:31:32 2022 +0100 Added tidy analyzer options commit bd59a32420acb282ceba80c13e1f727d1ae3a767 Author: Max Lübke Date: Tue Feb 15 11:09:33 2022 +0100 Update .gitlab-ci.yml file commit ccfcec4f9c0c43341f3b73f2da8ac83ee67e35dc Author: Max Lübke Date: Tue Feb 15 10:55:08 2022 +0100 Update .gitlab-ci.yml file commit c2da2361e0e152a8fd51f0e89ab4fb0afbad57a1 Author: Max Lübke Date: Tue Feb 15 10:47:40 2022 +0100 Update .gitlab-ci.yml file commit 6c10f3b42ae3479f747aab012f7411d48493c426 Author: Max Lübke Date: Tue Feb 15 10:47:16 2022 +0100 Update .gitlab-ci.yml file commit 8f96ccc33556d97e5d37fd448b3f12e024777274 Author: Max Lübke Date: Tue Feb 15 10:46:25 2022 +0100 Update .gitlab-ci.yml file commit afdb0447625d35d6ca989744e94a44f90392d1c7 Author: Max Lübke Date: Tue Feb 15 10:44:56 2022 +0100 Update .gitlab-ci.yml file --- .gitlab-ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5b38c99 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,22 @@ +image: sobc/gitlab-ci + +stages: + - build + - test + +before_script: + - apt-get update && apt-get install -y libeigen3-dev + +build: + stage: build + script: + - mkdir build && cd build + - cmake .. + - make + +lint: + stage: test + script: + - mkdir build && cd build + - cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks=cppcoreguidelines-*,clang-analyzer-*,performance-*,readability-*, modernize-*" .. + - make From d2866c271f3e7604d5530a04a437ddb92b0a9e76 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 17 Feb 2022 17:43:27 +0100 Subject: [PATCH 4/4] Fix wrong function signature in implementation --- src/BTCSDiffusion.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/BTCSDiffusion.cpp b/src/BTCSDiffusion.cpp index 4f31c42..a2b414c 100644 --- a/src/BTCSDiffusion.cpp +++ b/src/BTCSDiffusion.cpp @@ -239,9 +239,10 @@ void BTCSDiffusion::fillMatrixFromRow(const DVectorRowMajor &alpha, int n_cols, } void BTCSDiffusion::fillVectorFromRowADI(Eigen::Map &c, - const Eigen::VectorXd alpha, int row, - double delta, boundary_condition left, - boundary_condition right) { + const Eigen::VectorXd alpha, int row, + double delta, boundary_condition left, + boundary_condition right, + double time_step) { int ncol = c.cols(); int nrow = c.rows();