mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 09:28:23 +01:00
adjusted XTREME csv output
This commit is contained in:
parent
f1b5138bcc
commit
c9c0f02a5a
@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
|
||||
simulation.setIterations(100);
|
||||
|
||||
// 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 ****
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ enum CSV_OUTPUT {
|
||||
CSV_OUTPUT_OFF, // do not produce csv output
|
||||
CSV_OUTPUT_ON, // produce csv output with last concentration matrix
|
||||
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 {
|
||||
|
||||
@ -115,6 +115,10 @@ VectorXd Boundary::getBoundarySideValues(BC_SIDE side) {
|
||||
VectorXd values(length);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -150,6 +150,7 @@ string Simulation::createCSVfile() {
|
||||
while (filesystem::exists(filename)) {
|
||||
appendIdent += 1;
|
||||
appendIdentString = to_string(appendIdent);
|
||||
// ?? TODO why double filename?
|
||||
filename = filename = approachString + "_" + row + "_" + col + "_" + numIterations + "-" + appendIdentString + ".csv";
|
||||
}
|
||||
|
||||
@ -166,9 +167,11 @@ string Simulation::createCSVfile() {
|
||||
//boundary right
|
||||
//boundary top
|
||||
//boundary bottom
|
||||
file << row << endl;
|
||||
file << col << endl;
|
||||
file << numIterations << endl;
|
||||
IOFormat one_row(StreamPrecision, DontAlignCols, "", " ");
|
||||
file << bc.getBoundarySideValues(BC_SIDE_LEFT).format(one_row) << 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
|
||||
// file << to_string(bc.printBoundarySide) << endl;
|
||||
file << endl << endl;
|
||||
@ -218,7 +221,7 @@ void Simulation::run() {
|
||||
if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) {
|
||||
printConcentrationsConsole();
|
||||
}
|
||||
if (csv_output == CSV_OUTPUT_VERBOSE) {
|
||||
if (csv_output >= CSV_OUTPUT_VERBOSE) {
|
||||
printConcentrationsCSV(filename);
|
||||
}
|
||||
|
||||
@ -229,7 +232,7 @@ void Simulation::run() {
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
|
||||
|
||||
// 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) {
|
||||
|
||||
@ -237,7 +240,7 @@ void Simulation::run() {
|
||||
if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) {
|
||||
printConcentrationsConsole();
|
||||
}
|
||||
if (csv_output == CSV_OUTPUT_VERBOSE && i > 0) {
|
||||
if (csv_output >= CSV_OUTPUT_VERBOSE) {
|
||||
printConcentrationsCSV(filename);
|
||||
}
|
||||
|
||||
|
||||
@ -43,5 +43,5 @@ bool checkSimilarityV2(MatrixXd a, MatrixXd b, double maxDiff) {
|
||||
|
||||
MatrixXd diff = a - b;
|
||||
double maxCoeff = diff.maxCoeff();
|
||||
return maxCoeff < maxDiff;
|
||||
return abs(maxCoeff) < maxDiff;
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
// include the configured header file
|
||||
#include <testSimulation.hpp>
|
||||
|
||||
static Grid setupSimulation() {
|
||||
static Grid setupSimulation(APPROACH approach, double timestep, int iterations) {
|
||||
int row = 11;
|
||||
int col = 11;
|
||||
int domain_row = 10;
|
||||
@ -46,9 +46,10 @@ static Grid setupSimulation() {
|
||||
|
||||
|
||||
// Simulation
|
||||
Simulation sim = Simulation(grid, bc, FTCS_APPROACH);
|
||||
sim.setTimestep(0.001);
|
||||
sim.setIterations(7000);
|
||||
Simulation sim = Simulation(grid, bc, approach);
|
||||
sim.setOutputConsole(CONSOLE_OUTPUT_ON);
|
||||
sim.setTimestep(timestep);
|
||||
sim.setIterations(iterations);
|
||||
sim.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
|
||||
string test_path = testSimulationCSVDir;
|
||||
MatrixXd reference = CSV2Eigen(test_path);
|
||||
Grid grid = setupSimulation();
|
||||
Grid grid = setupSimulation(FTCS_APPROACH, 0.001, 7000);
|
||||
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"){
|
||||
int rc = 12;
|
||||
Grid grid(rc, rc);
|
||||
Boundary boundary(grid);
|
||||
|
||||
CHECK_NOTHROW(Simulation sim(grid, boundary, FTCS_APPROACH));
|
||||
}
|
||||
CHECK_NOTHROW(Simulation sim(grid, boundary, BTCS_APPROACH));
|
||||
}
|
||||
|
||||
TEST_CASE("Simulation environment"){
|
||||
int rc = 12;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user