add: Implementation of max time step

This commit is contained in:
Hannes Signer 2023-08-01 16:56:25 +02:00
parent a72217f6a2
commit f4924ac8b2
2 changed files with 19 additions and 3 deletions

View File

@ -40,8 +40,8 @@ int main(int argc, char *argv[]) {
// Simulation
Simulation sim = Simulation(grid, bc, FTCS_APPROACH);
sim.setTimestep(0.001);
sim.setIterations(7000);
//sim.setTimestep(0.001);
sim.setIterations(2);
sim.setOutputCSV(CSV_OUTPUT_VERBOSE);

View File

@ -13,7 +13,23 @@ Simulation::Simulation(Grid grid, Boundary bc, APPROACH approach) : grid(grid),
this->approach = approach;
//TODO calculate max time step
this->timestep = 0.01;
double deltaRowSquare = grid.getDeltaRow() * grid.getDeltaRow();
double deltaColSquare = grid.getDeltaCol() * grid.getDeltaCol();
double minDelta = (deltaRowSquare < deltaColSquare) ? deltaRowSquare : deltaColSquare;
double maxAlphaX = grid.getAlphaX().maxCoeff();
double maxAlphaY = grid.getAlphaY().maxCoeff();
double maxAlpha = (maxAlphaX > maxAlphaY) ? maxAlphaX : maxAlphaY;
//double maxStableTimestep = minDelta / (2*maxAlpha); // Formula from Marco --> seems to be unstable
double maxStableTimestep = 1 / (4 * maxAlpha * ((1/deltaRowSquare) + (1/deltaColSquare))); // Formula from Wikipedia
cout << maxStableTimestep << endl;
this->timestep = maxStableTimestep;
this->iterations = 1000;
this->csv_output = CSV_OUTPUT_OFF;
}