From ad67980baa3190ffdd3e71e7518733d6006c072c Mon Sep 17 00:00:00 2001 From: philippun Date: Thu, 24 Aug 2023 22:46:14 +0200 Subject: [PATCH] small performance optimization, added TODOs with further optimization idea and another TODO --- src/BTCSv2.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/BTCSv2.cpp b/src/BTCSv2.cpp index 033a132..443e852 100644 --- a/src/BTCSv2.cpp +++ b/src/BTCSv2.cpp @@ -276,10 +276,10 @@ static VectorXd EigenLUAlgorithm(SparseMatrix &A, VectorXd &b) { static VectorXd ThomasAlgorithm(SparseMatrix &A, VectorXd &b) { uint32_t n = b.size(); - Eigen::VectorXd a_diag(n); - Eigen::VectorXd b_diag(n); - Eigen::VectorXd c_diag(n); - Eigen::VectorXd x_vec = b; + VectorXd a_diag(n); + VectorXd b_diag(n); + VectorXd c_diag(n); + VectorXd x_vec = b; // Fill diagonals vectors b_diag[0] = A.coeff(0, 0); @@ -365,6 +365,7 @@ static void BTCS_2D(Grid &grid, Boundary &bc, double timestep, VectorXd (*solver SparseMatrix A; VectorXd b; + // const MatrixXd &alphaX = grid.getAlphaX(); // TODO check if this helps performance MatrixXd alphaX = grid.getAlphaX(); MatrixXd alphaY = grid.getAlphaY(); vector bcLeft = bc.getBoundarySide(BC_SIDE_LEFT); @@ -382,7 +383,7 @@ static void BTCS_2D(Grid &grid, Boundary &bc, double timestep, VectorXd (*solver b = createSolutionVector(concentrations, alphaX, alphaY, bcLeft, bcRight, bcTop, bcBottom, colMax, i, sx, sy); - SparseLU> solver; + SparseLU> solver; // TODO what is this? row_t1 = solverFunc(A, b); @@ -414,10 +415,10 @@ static void BTCS_2D(Grid &grid, Boundary &bc, double timestep, VectorXd (*solver // entry point for EigenLU solver; differentiate between 1D and 2D grid static void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads) { - if (grid.getDim() == 1) { - BTCS_1D(grid, bc, timestep, EigenLUAlgorithm); - } else if (grid.getDim() == 2) { + if (grid.getDim() == 2) { BTCS_2D(grid, bc, timestep, EigenLUAlgorithm, numThreads); + } else if (grid.getDim() == 1) { + BTCS_1D(grid, bc, timestep, EigenLUAlgorithm); } else { throw_invalid_argument("Error: Only 1- and 2-dimensional grids are defined!"); } @@ -425,10 +426,10 @@ static void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads) { // entry point for Thomas algorithm solver; differentiate 1D and 2D grid static void BTCS_Thomas(Grid &grid, Boundary &bc, double timestep, int numThreads) { - if (grid.getDim() == 1) { - BTCS_1D(grid, bc, timestep, ThomasAlgorithm); - } else if (grid.getDim() == 2) { + if (grid.getDim() == 2) { BTCS_2D(grid, bc, timestep, ThomasAlgorithm, numThreads); + } else if (grid.getDim() == 1) { + BTCS_1D(grid, bc, timestep, ThomasAlgorithm); } else { throw_invalid_argument("Error: Only 1- and 2-dimensional grids are defined!"); }