From b93dc46aeda57c868d98f2f7fc563c12279a7d55 Mon Sep 17 00:00:00 2001 From: philippun Date: Tue, 18 Jul 2023 11:43:33 +0200 Subject: [PATCH] implemeted simulation.cpp with run() --- include/tug/Simulation.hpp | 11 ++++---- src/Boundary.cpp | 1 + src/FTCS.cpp | 5 ++++ src/Simulation.cpp | 55 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/include/tug/Simulation.hpp b/include/tug/Simulation.hpp index 17c1853..cbb8c64 100644 --- a/include/tug/Simulation.hpp +++ b/include/tug/Simulation.hpp @@ -1,8 +1,8 @@ #include "Boundary.hpp" enum APPROACH { - FTCS, - BTCS + FTCS_APPROACH, + BTCS_APPROACH }; enum CSV_OUTPUT { @@ -21,14 +21,14 @@ class Simulation { * @param bc * @param aproach */ - Simulation(Grid grid, Boundary bc, APPROACH aproach); + Simulation(Grid &grid, Boundary &bc, APPROACH approach); /** * @brief * * @param csv_output */ - void outputCSV(CSV_OUTPUT csv_output); + void setOutputCSV(CSV_OUTPUT csv_output); /** * @brief Set the Timestep object @@ -41,7 +41,7 @@ class Simulation { * @brief Get the Timestep object * */ - void getTimestep(); + auto getTimestep(); /** * @brief Set the Iterations object @@ -70,6 +70,7 @@ class Simulation { int iterations; CSV_OUTPUT csv_output; + Grid grid; Boundary bc; APPROACH approach; diff --git a/src/Boundary.cpp b/src/Boundary.cpp index 4156eb5..5b95f72 100644 --- a/src/Boundary.cpp +++ b/src/Boundary.cpp @@ -5,6 +5,7 @@ using namespace std; Boundary::Boundary(Grid &grid, BC_TYPE type) : grid(grid) { + //probably to DEBUG assignment grid this->type = type; if (type == BC_TYPE_CONSTANT) { diff --git a/src/FTCS.cpp b/src/FTCS.cpp index e69de29..94c2595 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -0,0 +1,5 @@ +#include + +auto FTCS(Grid &grid, Boundary &bc, double timestep) { + +} \ No newline at end of file diff --git a/src/Simulation.cpp b/src/Simulation.cpp index e69de29..b4cd947 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -0,0 +1,55 @@ +#include +#include + +#include "FTCS.cpp" + +using namespace std; + +Simulation::Simulation(Grid &grid, Boundary &bc, APPROACH approach) : grid(grid), bc(bc) { + //probably to DEBUG assignment of grid and bc + this->grid = grid; + this->approach = approach; + + //TODO calculate max time step + this->timestep = 0.01; + this->iterations = 1000; + this->csv_output = CSV_OUTPUT_OFF; +} + +void Simulation::setOutputCSV(CSV_OUTPUT csv_output) { + if (csv_output < CSV_OUTPUT_OFF && csv_output > CSV_OUTPUT_VERBOSE) { + throw invalid_argument("Invalid CSV output option given!"); + } + + this->csv_output = csv_output; +} + +void Simulation::setTimestep(double timestep) { + //TODO check timestep in FTCS for max value + this->timestep = timestep; +} + +auto Simulation::getTimestep() { + return this->timestep; +} + +void Simulation::setIterations(int iterations) { + this->iterations = iterations; +} + +auto Simulation::getIterations() { + return this->iterations; +} + +auto Simulation::run() { + if (approach == FTCS_APPROACH) { + for (int i = 0; i < iterations; i++) { + FTCS(grid, bc, timestep); + } + } else if (approach == BTCS_APPROACH) { + for (int i = 0; i < iterations; i++) { + //TODO + break; + } + } +} \ No newline at end of file