From 2810db0d526f2147b2cd7e1676b13d53cdab8cb0 Mon Sep 17 00:00:00 2001 From: philippun Date: Thu, 10 Aug 2023 14:21:00 +0200 Subject: [PATCH] added BTCSv2.cpp --- include/tug/Boundary.hpp | 1 - include/tug/Grid.hpp | 1 + src/BTCSv2.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/BTCSv2.cpp diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index 98d0181..2173180 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -7,7 +7,6 @@ #ifndef BOUNDARY_H_ #define BOUNDARY_H_ -#include #include #include "Grid.hpp" diff --git a/include/tug/Grid.hpp b/include/tug/Grid.hpp index 59f8ed0..a87325e 100644 --- a/include/tug/Grid.hpp +++ b/include/tug/Grid.hpp @@ -6,6 +6,7 @@ */ #include +#include using namespace Eigen; diff --git a/src/BTCSv2.cpp b/src/BTCSv2.cpp new file mode 100644 index 0000000..4977060 --- /dev/null +++ b/src/BTCSv2.cpp @@ -0,0 +1,51 @@ +#include "TugUtils.hpp" +#include + +using namespace Eigen; + + +// calculates arithmetic or harmonic mean of alpha between two cells +static double calcAlphaIntercell(double &alpha1, double &alpha2, bool useHarmonic = true) { + if (useHarmonic) { + return double(2) / ((double(1)/alpha1) + (double(1)/alpha2)); + } else { + return 0.5 * (alpha1 + alpha2); + } +} + + +static MatrixXd createCoeffMatrix(Grid &grid, int rowIndex, double sx) { + + // square matrix of column^2 dimension for the coefficients + int dim = grid.getCol(); + SparseMatrix cm(dim, dim); + + // top left + cm.coeffRef(0,0) = 1 + sx * (calcAlphaIntercell(grid.getAlphaX()(rowIndex,0), grid.getAlphaX()(rowIndex,1))); + + +} + + +// BTCS solution for 1D grid +static void BTCS_1D(Grid &grid, Boundary &bc, double ×tep) { + +} + + +// BTCS solution for 2D grid +static void BTCS_2D(Grid &grid, Boundary &bc, double ×tep) { + +} + + +// entry point; differentiate between 1D and 2D grid +static void BTCS(Grid &grid, Boundary &bc, double ×tep) { + if (grid.getDim() == 1) { + BTCS_1D(grid, bc, timestep); + } else if (grid.getDim() == 2) { + BTCS_2D(grid, bc, timestep); + } else { + throw_invalid_argument("Error: Only 1- and 2-dimensional grids are defined!"); + } +} \ No newline at end of file