change: all variables as pass by reference

This commit is contained in:
Hannes Signer 2023-08-03 14:57:44 +02:00
parent 70268f58f3
commit d38e14d6f4
6 changed files with 22 additions and 22 deletions

View File

@ -1,5 +1,8 @@
#include <tug/Simulation.hpp> #include <tug/Simulation.hpp>
#include "Eigen/Core" #include "Eigen/Core"
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int row = 11; int row = 11;
@ -50,4 +53,6 @@ int main(int argc, char *argv[]) {
// RUN // RUN
sim.run(); sim.run();
cout << grid.getConcentrations() << endl;
} }

View File

@ -37,7 +37,7 @@ class Simulation {
* @param bc * @param bc
* @param aproach * @param aproach
*/ */
Simulation(Grid grid, Boundary bc, APPROACH approach); Simulation(Grid &grid, Boundary &bc, APPROACH approach);
/** /**
* @brief * @brief
@ -107,7 +107,7 @@ class Simulation {
* *
* @return Grid * @return Grid
*/ */
Grid run(); void run();
private: private:
@ -117,8 +117,8 @@ class Simulation {
CONSOLE_OUTPUT console_output; CONSOLE_OUTPUT console_output;
TIME_MEASURE time_measure; TIME_MEASURE time_measure;
Grid grid; Grid &grid;
Boundary bc; Boundary &bc;
APPROACH approach; APPROACH approach;
}; };

View File

@ -239,7 +239,7 @@ MatrixXd FTCS_1D(Grid &grid, Boundary &bc, double &timestep) {
} }
MatrixXd FTCS_2D(Grid &grid, Boundary &bc, double &timestep) { void FTCS_2D(Grid &grid, Boundary &bc, double &timestep) {
int rowMax = grid.getRow(); int rowMax = grid.getRow();
int colMax = grid.getCol(); int colMax = grid.getCol();
double deltaRow = grid.getDeltaRow(); double deltaRow = grid.getDeltaRow();
@ -384,17 +384,16 @@ MatrixXd FTCS_2D(Grid &grid, Boundary &bc, double &timestep) {
) )
; ;
grid.setConcentrations(concentrations_t1);
return concentrations_t1;
} }
MatrixXd FTCS(Grid &grid, Boundary &bc, double &timestep) { void FTCS(Grid &grid, Boundary &bc, double &timestep) {
if (grid.getDim() == 1) { if (grid.getDim() == 1) {
return FTCS_1D(grid, bc, timestep); FTCS_1D(grid, bc, timestep);
} else { } else {
return FTCS_2D(grid, bc, timestep); FTCS_2D(grid, bc, timestep);
} }
} }

View File

@ -10,9 +10,7 @@
using namespace std; using namespace std;
Simulation::Simulation(Grid grid, Boundary bc, APPROACH approach) : grid(grid), bc(bc) { 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; this->approach = approach;
//TODO calculate max time step //TODO calculate max time step
@ -146,7 +144,7 @@ void Simulation::printConcentrationsCSV(string filename) {
file.close(); file.close();
} }
Grid Simulation::run() { void Simulation::run() {
string filename; string filename;
if (this->console_output > CONSOLE_OUTPUT_OFF) { if (this->console_output > CONSOLE_OUTPUT_OFF) {
printConcentrationsConsole(); printConcentrationsConsole();
@ -165,7 +163,7 @@ Grid Simulation::run() {
printConcentrationsCSV(filename); printConcentrationsCSV(filename);
} }
grid.setConcentrations(FTCS(grid, bc, timestep)); FTCS(grid, bc, timestep);
} }
} else if (approach == BTCS_APPROACH) { } else if (approach == BTCS_APPROACH) {
@ -191,5 +189,5 @@ Grid Simulation::run() {
printConcentrationsCSV(filename); printConcentrationsCSV(filename);
} }
return grid;
} }

View File

@ -11,7 +11,7 @@ if(NOT DOCTEST_LIB)
FetchContent_MakeAvailable(DocTest) FetchContent_MakeAvailable(DocTest)
endif() endif()
add_executable(testTug setup.cpp testBoundaryCondition.cpp testDiffusion.cpp testSimulation.cpp) add_executable(testTug setup.cpp testSimulation.cpp) # testBoundaryCondition.cpp testDiffusion.cpp
target_link_libraries(testTug doctest tug) target_link_libraries(testTug doctest tug)
# get relative path of the CSV file # get relative path of the CSV file

View File

@ -49,19 +49,17 @@ static Grid setupSimulation() {
Simulation sim = Simulation(grid, bc, FTCS_APPROACH); Simulation sim = Simulation(grid, bc, FTCS_APPROACH);
sim.setTimestep(0.001); sim.setTimestep(0.001);
sim.setIterations(7000); sim.setIterations(7000);
// sim.setOutputCSV(CSV_OUTPUT_ON); sim.run();
// sim.setOutputConsole(CONSOLE_OUTPUT_ON);
// RUN // RUN
return sim.run(); return grid;
} }
TEST_CASE("equality to reference matrix") { TEST_CASE("equality to reference matrix") {
// set string from the header file // set string from the header file
string test_path = testSimulationCSVDir; string test_path = testSimulationCSVDir;
MatrixXd reference = CSV2Eigen(test_path); MatrixXd reference = CSV2Eigen(test_path);
cout << test_path << endl;
Grid grid = setupSimulation(); Grid grid = setupSimulation();
CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true); CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true);
} }