mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-15 18:38:23 +01:00
change: all variables as pass by reference
This commit is contained in:
parent
70268f58f3
commit
d38e14d6f4
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
11
src/FTCS.cpp
11
src/FTCS.cpp
@ -239,7 +239,7 @@ MatrixXd FTCS_1D(Grid &grid, Boundary &bc, double ×tep) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MatrixXd FTCS_2D(Grid &grid, Boundary &bc, double ×tep) {
|
void FTCS_2D(Grid &grid, Boundary &bc, double ×tep) {
|
||||||
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 ×tep) {
|
|||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
grid.setConcentrations(concentrations_t1);
|
||||||
return concentrations_t1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MatrixXd FTCS(Grid &grid, Boundary &bc, double ×tep) {
|
void FTCS(Grid &grid, Boundary &bc, double ×tep) {
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user