Refactoring of function calc_alpha_intercell into calcAlphaIntercell and adjusting of example parameters

This commit is contained in:
philippun 2023-07-24 15:40:30 +02:00
parent 0ebc8d30e8
commit be94e760af
3 changed files with 22 additions and 34 deletions

View File

@ -25,8 +25,8 @@ int main(int argc, char *argv[]) {
// (optional) set the concentrations, e.g.: // (optional) set the concentrations, e.g.:
// MatrixXd concentrations = MatrixXd::Constant(20,20,1000); // #row,#col,value // MatrixXd concentrations = MatrixXd::Constant(20,20,1000); // #row,#col,value
// grid.setConcentrations(concentrations); // grid.setConcentrations(concentrations);
MatrixXd concentrations = MatrixXd::Constant(20,20,20); MatrixXd concentrations = MatrixXd::Constant(20,20,0);
// concentrations(0,0) = 2000; concentrations(0,0) = 2000;
grid.setConcentrations(concentrations); grid.setConcentrations(concentrations);
// (optional) set alphas of the grid, e.g.: // (optional) set alphas of the grid, e.g.:
@ -64,10 +64,10 @@ int main(int argc, char *argv[]) {
simulation.setTimestep(0.1); // timestep simulation.setTimestep(0.1); // timestep
// (optional) set the number of iterations // (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] // (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 **** // **** RUN SIMULATION ****

View File

@ -458,7 +458,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.7" "version": "3.11.4"
}, },
"orig_nbformat": 4 "orig_nbformat": 4
}, },

View File

@ -4,7 +4,7 @@
using namespace std; 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) { if (useHarmonic) {
return 2 / ((1/alpha1) + (1/alpha2)); return 2 / ((1/alpha1) + (1/alpha2));
} else { } 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 calcHorizontalChange(Grid grid, int row, int col) {
double result = 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) * 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))
+ 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) * 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); * grid.getConcentrations()(row,col-1);
return result; return result;
@ -33,14 +33,14 @@ double calcHorizontalChange(Grid grid, int row, int col) {
double calcVerticalChange(Grid grid, int row, int col) { double calcVerticalChange(Grid grid, int row, int col) {
double result = 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) * 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))
+ 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,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); * grid.getConcentrations()(row-1,col);
return result; 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 calcHorizontalChangeLeftBoundary(Grid grid, Boundary bc, int row, int col) {
double result = 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) * 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) + 2 * grid.getAlphaX()(row,col)
) )
* grid.getConcentrations()(row,col) * grid.getConcentrations()(row,col)
@ -68,11 +68,11 @@ double calcHorizontalChangeRightBoundary(Grid grid, Boundary bc, int row, int co
double result = double result =
2 * grid.getAlphaX()(row,col) * bc.getBoundaryConditionValue(BC_SIDE_RIGHT)(row) 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) + 2 * grid.getAlphaX()(row,col)
) )
* grid.getConcentrations()(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); * grid.getConcentrations()(row,col-1);
return result; 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 calcVerticalChangeTopBoundary(Grid grid, Boundary bc, int row, int col) {
double result = 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) * 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) + 2 * grid.getAlphaY()(row, col)
) )
* grid.getConcentrations()(row, col) * grid.getConcentrations()(row, col)
@ -100,11 +100,11 @@ double calcVerticalChangeBottomBoundary(Grid grid, Boundary bc, int row, int col
double result = double result =
2 * grid.getAlphaY()(row, col) * bc.getBoundaryConditionValue(BC_SIDE_BOTTOM)(col) 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) + 2 * grid.getAlphaY()(row, col)
) )
* grid.getConcentrations()(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); * grid.getConcentrations()(row-1,col);
return result; return result;
@ -153,14 +153,6 @@ MatrixXd FTCS_1D(Grid grid, Boundary bc, double timestep) {
return concentrations_t1; 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) { MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) {
int rowMax = grid.getRow(); int rowMax = grid.getRow();
@ -311,10 +303,6 @@ MatrixXd FTCS_2D(Grid grid, Boundary bc, double timestep) {
return concentrations_t1; return concentrations_t1;
} }
// TODO
MatrixXd FTCS_closed(Grid grid, Boundary bc, double timestep) {
return MatrixXd();
}
MatrixXd FTCS(Grid grid, Boundary bc, double timestep) { MatrixXd FTCS(Grid grid, Boundary bc, double timestep) {
// inner cells // inner cells