implemeted simulation.cpp with run()

This commit is contained in:
philippun 2023-07-18 11:43:33 +02:00
parent da65be3cca
commit b93dc46aed
4 changed files with 67 additions and 5 deletions

View File

@ -1,8 +1,8 @@
#include "Boundary.hpp" #include "Boundary.hpp"
enum APPROACH { enum APPROACH {
FTCS, FTCS_APPROACH,
BTCS BTCS_APPROACH
}; };
enum CSV_OUTPUT { enum CSV_OUTPUT {
@ -21,14 +21,14 @@ class Simulation {
* @param bc * @param bc
* @param aproach * @param aproach
*/ */
Simulation(Grid grid, Boundary bc, APPROACH aproach); Simulation(Grid &grid, Boundary &bc, APPROACH approach);
/** /**
* @brief * @brief
* *
* @param csv_output * @param csv_output
*/ */
void outputCSV(CSV_OUTPUT csv_output); void setOutputCSV(CSV_OUTPUT csv_output);
/** /**
* @brief Set the Timestep object * @brief Set the Timestep object
@ -41,7 +41,7 @@ class Simulation {
* @brief Get the Timestep object * @brief Get the Timestep object
* *
*/ */
void getTimestep(); auto getTimestep();
/** /**
* @brief Set the Iterations object * @brief Set the Iterations object
@ -70,6 +70,7 @@ class Simulation {
int iterations; int iterations;
CSV_OUTPUT csv_output; CSV_OUTPUT csv_output;
Grid grid;
Boundary bc; Boundary bc;
APPROACH approach; APPROACH approach;

View File

@ -5,6 +5,7 @@
using namespace std; using namespace std;
Boundary::Boundary(Grid &grid, BC_TYPE type) : grid(grid) { Boundary::Boundary(Grid &grid, BC_TYPE type) : grid(grid) {
//probably to DEBUG assignment grid
this->type = type; this->type = type;
if (type == BC_TYPE_CONSTANT) { if (type == BC_TYPE_CONSTANT) {

View File

@ -0,0 +1,5 @@
#include <tug/Boundary.hpp>
auto FTCS(Grid &grid, Boundary &bc, double timestep) {
}

View File

@ -0,0 +1,55 @@
#include <stdexcept>
#include <tug/Simulation.hpp>
#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;
}
}
}