adjusted XTREME csv output

This commit is contained in:
philippun 2023-08-11 15:15:08 +02:00
parent f1b5138bcc
commit c9c0f02a5a
6 changed files with 33 additions and 17 deletions

View File

@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
simulation.setIterations(100); simulation.setIterations(100);
// set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON, CSV_OUTPUT_VERBOSE] // set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON, CSV_OUTPUT_VERBOSE]
simulation.setOutputCSV(CSV_OUTPUT_VERBOSE); simulation.setOutputCSV(CSV_OUTPUT_XTREME);
// **** RUN SIMULATION **** // **** RUN SIMULATION ****

View File

@ -16,7 +16,7 @@ enum CSV_OUTPUT {
CSV_OUTPUT_OFF, // do not produce csv output CSV_OUTPUT_OFF, // do not produce csv output
CSV_OUTPUT_ON, // produce csv output with last concentration matrix CSV_OUTPUT_ON, // produce csv output with last concentration matrix
CSV_OUTPUT_VERBOSE, // produce csv output with all concentration matrices CSV_OUTPUT_VERBOSE, // produce csv output with all concentration matrices
CSV_OUTPUT_XTREME // produce csv output with all concentration matrices and simulation environment CSV_OUTPUT_XTREME // produce csv output with all concentration matrices and boundary conditions at beginning
}; };
enum CONSOLE_OUTPUT { enum CONSOLE_OUTPUT {

View File

@ -115,6 +115,10 @@ VectorXd Boundary::getBoundarySideValues(BC_SIDE side) {
VectorXd values(length); VectorXd values(length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (getBoundaryElementType(side, i) == tug::bc::BC_TYPE_CLOSED) {
values(i) = -1;
continue;
}
values(i) = getBoundaryElementValue(side, i); values(i) = getBoundaryElementValue(side, i);
} }

View File

@ -150,6 +150,7 @@ string Simulation::createCSVfile() {
while (filesystem::exists(filename)) { while (filesystem::exists(filename)) {
appendIdent += 1; appendIdent += 1;
appendIdentString = to_string(appendIdent); appendIdentString = to_string(appendIdent);
// ?? TODO why double filename?
filename = filename = approachString + "_" + row + "_" + col + "_" + numIterations + "-" + appendIdentString + ".csv"; filename = filename = approachString + "_" + row + "_" + col + "_" + numIterations + "-" + appendIdentString + ".csv";
} }
@ -166,9 +167,11 @@ string Simulation::createCSVfile() {
//boundary right //boundary right
//boundary top //boundary top
//boundary bottom //boundary bottom
file << row << endl; IOFormat one_row(StreamPrecision, DontAlignCols, "", " ");
file << col << endl; file << bc.getBoundarySideValues(BC_SIDE_LEFT).format(one_row) << endl;
file << numIterations << endl; file << bc.getBoundarySideValues(BC_SIDE_RIGHT).format(one_row) << endl;
file << bc.getBoundarySideValues(BC_SIDE_TOP).format(one_row) << endl;
file << bc.getBoundarySideValues(BC_SIDE_BOTTOM).format(one_row) << endl;
// TODO // TODO
// file << to_string(bc.printBoundarySide) << endl; // file << to_string(bc.printBoundarySide) << endl;
file << endl << endl; file << endl << endl;
@ -218,7 +221,7 @@ void Simulation::run() {
if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) { if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) {
printConcentrationsConsole(); printConcentrationsConsole();
} }
if (csv_output == CSV_OUTPUT_VERBOSE) { if (csv_output >= CSV_OUTPUT_VERBOSE) {
printConcentrationsCSV(filename); printConcentrationsCSV(filename);
} }
@ -229,7 +232,7 @@ void Simulation::run() {
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin); auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
// MDL: meaningful stdout messages // MDL: meaningful stdout messages
std::cout << ":: run() finished in " << milliseconds.count() << "ms" << endl; std::cout << "\n:: run() finished in " << milliseconds.count() << "ms" << endl;
} else if (approach == BTCS_APPROACH) { } else if (approach == BTCS_APPROACH) {
@ -237,7 +240,7 @@ void Simulation::run() {
if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) { if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) {
printConcentrationsConsole(); printConcentrationsConsole();
} }
if (csv_output == CSV_OUTPUT_VERBOSE && i > 0) { if (csv_output >= CSV_OUTPUT_VERBOSE) {
printConcentrationsCSV(filename); printConcentrationsCSV(filename);
} }

View File

@ -43,5 +43,5 @@ bool checkSimilarityV2(MatrixXd a, MatrixXd b, double maxDiff) {
MatrixXd diff = a - b; MatrixXd diff = a - b;
double maxCoeff = diff.maxCoeff(); double maxCoeff = diff.maxCoeff();
return maxCoeff < maxDiff; return abs(maxCoeff) < maxDiff;
} }

View File

@ -7,7 +7,7 @@
// include the configured header file // include the configured header file
#include <testSimulation.hpp> #include <testSimulation.hpp>
static Grid setupSimulation() { static Grid setupSimulation(APPROACH approach, double timestep, int iterations) {
int row = 11; int row = 11;
int col = 11; int col = 11;
int domain_row = 10; int domain_row = 10;
@ -46,9 +46,10 @@ static Grid setupSimulation() {
// Simulation // Simulation
Simulation sim = Simulation(grid, bc, FTCS_APPROACH); Simulation sim = Simulation(grid, bc, approach);
sim.setTimestep(0.001); sim.setOutputConsole(CONSOLE_OUTPUT_ON);
sim.setIterations(7000); sim.setTimestep(timestep);
sim.setIterations(iterations);
sim.run(); sim.run();
// RUN // RUN
@ -56,21 +57,29 @@ static Grid setupSimulation() {
} }
TEST_CASE("equality to reference matrix") { TEST_CASE("equality to reference matrix with FTCS") {
// 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);
Grid grid = setupSimulation(); Grid grid = setupSimulation(FTCS_APPROACH, 0.001, 7000);
CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true); CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true);
} }
TEST_CASE("equality to reference matrix with BTCS") {
// set string from the header file
string test_path = testSimulationCSVDir;
MatrixXd reference = CSV2Eigen(test_path);
Grid grid = setupSimulation(BTCS_APPROACH, 1, 7);
CHECK(checkSimilarityV2(reference, grid.getConcentrations(), 0.01) == true);
}
TEST_CASE("Initialize environment"){ TEST_CASE("Initialize environment"){
int rc = 12; int rc = 12;
Grid grid(rc, rc); Grid grid(rc, rc);
Boundary boundary(grid); Boundary boundary(grid);
CHECK_NOTHROW(Simulation sim(grid, boundary, FTCS_APPROACH)); CHECK_NOTHROW(Simulation sim(grid, boundary, BTCS_APPROACH));
} }
TEST_CASE("Simulation environment"){ TEST_CASE("Simulation environment"){
int rc = 12; int rc = 12;