From e2707858c1801eee70822b61bbdc8f8cabdb0405 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 3 Feb 2022 15:10:03 +0100 Subject: [PATCH] Refactor loop of filling of matrix A. - make now use of another variable 'j' for c, bc and alpha indexing instead of always incrementing with =i= and the negation of =left_is_constant= --- src/BTCSDiffusion.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BTCSDiffusion.cpp b/src/BTCSDiffusion.cpp index 89a90b4..f4e8b4b 100644 --- a/src/BTCSDiffusion.cpp +++ b/src/BTCSDiffusion.cpp @@ -133,21 +133,21 @@ void BTCSDiffusion::simulate1D(std::vector &c, boundary_condition left, // A_matrix.insert(0, 0) = 1; // A_matrix.insert(size + 1, size + 1) = 1; - for (int i = 1; i < size - right_is_constant; i++) { - if (bc[i + !(left_is_constant)].type == BTCSDiffusion::BC_CONSTANT) { - A_matrix.insert(i,i) = 1; - b_vector[i] = bc[i + !(left_is_constant)].value; + for (int i = 1, j = i + !(left_is_constant); i < size - right_is_constant; + i++, j++) { + if (bc[j].type == BTCSDiffusion::BC_CONSTANT) { + A_matrix.insert(i, i) = 1; + b_vector[i] = bc[j].value; continue; } - - double sx = (alpha[i + !(left_is_constant)] * time_step) / (dx * dx); + double sx = (alpha[j] * time_step) / (dx * dx); A_matrix.insert(i, i) = -1. - 2. * sx; A_matrix.insert(i, i - 1) = sx; A_matrix.insert(i, i + 1) = sx; - b_vector[i] = -c[i + !(left_is_constant)]; + b_vector[i] = -c[j]; } Eigen::SparseLU, Eigen::COLAMDOrdering>