From be94e760afbb275882b13ff3e9e595bfb98fd7b2 Mon Sep 17 00:00:00 2001 From: philippun Date: Mon, 24 Jul 2023 15:40:30 +0200 Subject: [PATCH] Refactoring of function calc_alpha_intercell into calcAlphaIntercell and adjusting of example parameters --- examples/FTCS_2D_proto_example.cpp | 8 +++--- proto/FTCS.ipynb | 2 +- src/FTCS.cpp | 46 +++++++++++------------------- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/examples/FTCS_2D_proto_example.cpp b/examples/FTCS_2D_proto_example.cpp index b31759e..0e1c0a1 100644 --- a/examples/FTCS_2D_proto_example.cpp +++ b/examples/FTCS_2D_proto_example.cpp @@ -25,8 +25,8 @@ int main(int argc, char *argv[]) { // (optional) set the concentrations, e.g.: // MatrixXd concentrations = MatrixXd::Constant(20,20,1000); // #row,#col,value // grid.setConcentrations(concentrations); - MatrixXd concentrations = MatrixXd::Constant(20,20,20); - // concentrations(0,0) = 2000; + MatrixXd concentrations = MatrixXd::Constant(20,20,0); + concentrations(0,0) = 2000; grid.setConcentrations(concentrations); // (optional) set alphas of the grid, e.g.: @@ -64,10 +64,10 @@ int main(int argc, char *argv[]) { simulation.setTimestep(0.1); // timestep // (optional) set the number of iterations - simulation.setIterations(100); + simulation.setIterations(1000); // (optional) set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON, CSV_OUTPUT_VERBOSE] - simulation.setOutputCSV(CSV_OUTPUT_OFF); + simulation.setOutputCSV(CSV_OUTPUT_VERBOSE); // **** RUN SIMULATION **** diff --git a/proto/FTCS.ipynb b/proto/FTCS.ipynb index b64c934..4708428 100644 --- a/proto/FTCS.ipynb +++ b/proto/FTCS.ipynb @@ -458,7 +458,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.11.4" }, "orig_nbformat": 4 }, diff --git a/src/FTCS.cpp b/src/FTCS.cpp index 1ec110d..984294e 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -4,7 +4,7 @@ using namespace std; -double calc_alpha_intercell(double alpha1, double alpha2, bool useHarmonic = false) { +double calcAlphaIntercell(double alpha1, double alpha2, bool useHarmonic = false) { if (useHarmonic) { return 2 / ((1/alpha1) + (1/alpha2)); } else { @@ -16,14 +16,14 @@ double calc_alpha_intercell(double alpha1, double alpha2, bool useHarmonic = fal double calcHorizontalChange(Grid grid, int row, int col) { double result = - calc_alpha_intercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) + calcAlphaIntercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) * grid.getConcentrations()(row,col+1) - ( - calc_alpha_intercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) - + calc_alpha_intercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) + calcAlphaIntercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) + + calcAlphaIntercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) ) * grid.getConcentrations()(row,col) - + calc_alpha_intercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) + + calcAlphaIntercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) * grid.getConcentrations()(row,col-1); return result; @@ -33,14 +33,14 @@ double calcHorizontalChange(Grid grid, int row, int col) { double calcVerticalChange(Grid grid, int row, int col) { double result = - calc_alpha_intercell(grid.getAlphaY()(row+1,col), grid.getAlphaY()(row,col)) + calcAlphaIntercell(grid.getAlphaY()(row+1,col), grid.getAlphaY()(row,col)) * grid.getConcentrations()(row+1,col) - ( - calc_alpha_intercell(grid.getAlphaY()(row+1,col), grid.getAlphaY()(row,col)) - + calc_alpha_intercell(grid.getAlphaY()(row-1,col), grid.getAlphaY()(row,col)) + calcAlphaIntercell(grid.getAlphaY()(row+1,col), grid.getAlphaY()(row,col)) + + calcAlphaIntercell(grid.getAlphaY()(row-1,col), grid.getAlphaY()(row,col)) ) * grid.getConcentrations()(row,col) - + calc_alpha_intercell(grid.getAlphaY()(row-1,col), grid.getAlphaY()(row,col)) + + calcAlphaIntercell(grid.getAlphaY()(row-1,col), grid.getAlphaY()(row,col)) * grid.getConcentrations()(row-1,col); return result; @@ -50,10 +50,10 @@ double calcVerticalChange(Grid grid, int row, int col) { double calcHorizontalChangeLeftBoundary(Grid grid, Boundary bc, int row, int col) { double result = - calc_alpha_intercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) + calcAlphaIntercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) * grid.getConcentrations()(row,col+1) - ( - calc_alpha_intercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) + calcAlphaIntercell(grid.getAlphaX()(row,col+1), grid.getAlphaX()(row,col)) + 2 * grid.getAlphaX()(row,col) ) * grid.getConcentrations()(row,col) @@ -68,11 +68,11 @@ double calcHorizontalChangeRightBoundary(Grid grid, Boundary bc, int row, int co double result = 2 * grid.getAlphaX()(row,col) * bc.getBoundaryConditionValue(BC_SIDE_RIGHT)(row) - ( - calc_alpha_intercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) + calcAlphaIntercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) + 2 * grid.getAlphaX()(row,col) ) * grid.getConcentrations()(row,col) - + calc_alpha_intercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) + + calcAlphaIntercell(grid.getAlphaX()(row,col-1), grid.getAlphaX()(row,col)) * grid.getConcentrations()(row,col-1); return result; @@ -82,10 +82,10 @@ double calcHorizontalChangeRightBoundary(Grid grid, Boundary bc, int row, int co double calcVerticalChangeTopBoundary(Grid grid, Boundary bc, int row, int col) { double result = - calc_alpha_intercell(grid.getAlphaY()(row+1, col), grid.getAlphaY()(row, col)) + calcAlphaIntercell(grid.getAlphaY()(row+1, col), grid.getAlphaY()(row, col)) * grid.getConcentrations()(row+1,col) - ( - calc_alpha_intercell(grid.getAlphaY()(row+1, col), grid.getAlphaY()(row, col)) + calcAlphaIntercell(grid.getAlphaY()(row+1, col), grid.getAlphaY()(row, col)) + 2 * grid.getAlphaY()(row, col) ) * grid.getConcentrations()(row, col) @@ -100,11 +100,11 @@ double calcVerticalChangeBottomBoundary(Grid grid, Boundary bc, int row, int col double result = 2 * grid.getAlphaY()(row, col) * bc.getBoundaryConditionValue(BC_SIDE_BOTTOM)(col) - ( - calc_alpha_intercell(grid.getAlphaY()(row, col), grid.getAlphaY()(row-1, col)) + calcAlphaIntercell(grid.getAlphaY()(row, col), grid.getAlphaY()(row-1, col)) + 2 * grid.getAlphaY()(row, col) ) * grid.getConcentrations()(row, col) - + calc_alpha_intercell(grid.getAlphaY()(row, col), grid.getAlphaY()(row-1, col)) + + calcAlphaIntercell(grid.getAlphaY()(row, col), grid.getAlphaY()(row-1, col)) * grid.getConcentrations()(row-1,col); return result; @@ -153,14 +153,6 @@ MatrixXd FTCS_1D(Grid grid, Boundary bc, double timestep) { return concentrations_t1; } -// IN PROGRESS -// MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) { -// int rowMax = grid.getRow(); -// int colMax = grid.getCol(); -// double deltaRow = grid.getDeltaRow(); -// double deltaCol = grid.getDeltaCol(); - -// } MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) { int rowMax = grid.getRow(); @@ -311,10 +303,6 @@ MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) { return concentrations_t1; } -// TODO -MatrixXd FTCS_closed(Grid grid, Boundary bc, double timestep) { - return MatrixXd(); -} MatrixXd FTCS(Grid grid, Boundary bc, double timestep) { // inner cells