Commit 5ddda911 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

logger validation test added

parent 493ea5e5
......@@ -34,12 +34,13 @@ class Config
// --- Options ---
// File Structure
std::string _inputDir; /*!< @brief Directory for input files*/
std::string _outputDir; /*!< @brief Directory for output files*/
std::string _outputFile; /*!< @brief Name of output file*/
std::string _logDir; /*!< @brief Directory of log file*/
std::string _meshFile; /*!< @brief Name of mesh file*/
std::string _ctFile; /*!< @brief Name of CT file*/
std::string _inputDir; /*!< @brief Directory for input files*/
std::string _outputDir; /*!< @brief Directory for output files*/
std::string _outputFile; /*!< @brief Name of output file*/
std::string _logDir; /*!< @brief Directory of log file*/
std::string _logFileName; /*!< @brief Name of log file*/
std::string _meshFile; /*!< @brief Name of mesh file*/
std::string _ctFile; /*!< @brief Name of CT file*/
// Quadrature
QUAD_NAME _quadName; /*!< @brief Quadrature Name*/
......@@ -226,6 +227,7 @@ class Config
std::string inline GetCTFile() const { return std::filesystem::path( _ctFile ).lexically_normal(); }
std::string inline GetHydrogenFile() const { return std::filesystem::path( _hydrogenFile ).lexically_normal(); }
std::string inline GetLogDir() const { return std::filesystem::path( _logDir ).lexically_normal(); }
std::string inline GetLogFile() const { return std::filesystem::path( _logFileName ).lexically_normal(); }
std::string inline GetMeshFile() const { return std::filesystem::path( _meshFile ).lexically_normal(); }
std::string inline GetOutputDir() const { return std::filesystem::path( _outputDir ).lexically_normal(); }
std::string inline GetOutputFile() const { return std::filesystem::path( _outputFile ).lexically_normal(); }
......
......@@ -202,7 +202,9 @@ void Config::SetConfigOptions() {
/*! @brief OUTPUT_FILE \n DESCRIPTION: Name of output file \n DEFAULT "output" @ingroup Config.*/
AddStringOption( "OUTPUT_FILE", _outputFile, string( "output" ) );
/*! @brief LOG_DIR \n DESCRIPTION: Relative Directory of log files \n DEFAULT "/out" @ingroup Config.*/
AddStringOption( "LOG_DIR", _logDir, string( "/out" ) );
AddStringOption( "LOG_DIR", _logDir, string( "/out/logs" ) );
/*! @brief LOG_DIR \n DESCRIPTION: Name of log files \n DEFAULT "/out" @ingroup Config.*/
AddStringOption( "LOG_FILE", _logFileName, string( "use_date" ) );
/*! @brief MESH_FILE \n DESCRIPTION: Name of mesh file \n DEFAULT "" \ingroup Config.*/
AddStringOption( "MESH_FILE", _meshFile, string( "mesh.su2" ) );
/*! @brief MESH_FILE \n DESCRIPTION: Name of mesh file \n DEFAULT "" \ingroup Config.*/
......@@ -764,8 +766,12 @@ void Config::InitLogger() {
tstruct = *localtime( &now );
strftime( buf, sizeof( buf ), "%Y-%m-%d_%X", &tstruct );
// set filename to date and time
std::string filename = buf;
// set filename
std::string filename;
if( _logFileName.compare( "use_date" ) == 0 )
filename = buf; // set filename to date and time
else
filename = _logFileName;
// in case of existing files append '_#'
int ctr = 0;
......@@ -812,8 +818,12 @@ void Config::InitLogger() {
tstruct = *localtime( &now );
strftime( buf, sizeof( buf ), "%Y-%m-%d_%X_csv", &tstruct );
// set filename to date and time
std::string filename = buf;
// set filename
std::string filename;
if( _logFileName.compare( "use_date" ) == 0 )
filename = buf; // set filename to date and time
else
filename = _logFileName + "_csv";
// in case of existing files append '_#'
int ctr = 0;
......
......@@ -102,14 +102,14 @@ void Solver::Solve() {
lineToPrint += tmp + " |";
hLine += tmpLine;
}
log->info( "----------------------------- Solver Starts ----------------------------" );
log->info( "---------------------------- Solver Starts -----------------------------" );
log->info( "| The simulation will run for {} iterations.", _nEnergies );
log->info( hLine );
log->info( lineToPrint );
log->info( hLine );
std::string lineToPrintCSV = "";
for( unsigned idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
for( int idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
std::string tmp = _historyOutputFieldNames[idxFields];
lineToPrintCSV += tmp + ",";
}
......@@ -142,7 +142,7 @@ void Solver::Solve() {
if( rank == 0 ) {
log->info( hLine );
log->info( "| Postprocessing screen output goes here." );
log->info( "----------------------------- Solver Finished ---------------------------" );
log->info( "--------------------------- Solver Finished ----------------------------" );
}
}
......@@ -152,7 +152,7 @@ void Solver::PrintVolumeOutput( int currEnergy ) const {
if( _settings->GetVolumeOutputFrequency() != 0 && currEnergy % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) {
ExportVTK( _settings->GetOutputFile() + "_" + std::to_string( currEnergy ), _outputFields, _outputFieldNames, _mesh );
}
if( currEnergy == _nEnergies - 1 ) { // Last iteration write without suffix.
if( currEnergy == (int)_nEnergies - 1 ) { // Last iteration write without suffix.
ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh );
}
}
......@@ -386,7 +386,7 @@ void Solver::PrintHistoryOutput( unsigned iteration ) {
// assemble the line to print
std::string lineToPrint = "";
std::string tmp;
for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput() - 1; idx_field++ ) {
for( int idx_field = 0; idx_field < _settings->GetNScreenOutput() - 1; idx_field++ ) {
tmp = std::to_string( _screenOutputFields[idx_field] );
lineToPrint += tmp + ",";
}
......
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linesource Benchmarking File MN %
% Linesource Benchmarking File SN %
% Author <Steffen Schotthöfer> %
% Date 01.07.2020 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -17,6 +17,7 @@ SCATTER_COEFF = 1
%
% ---- Solver specifications ----
%
SOLVER = SN_SOLVER
CFL_NUMBER = 0.7
TIME_FINAL = 0.2
%
......
......@@ -31,6 +31,7 @@ std::vector<double> readVTKFile( std::string filename ) {
return data;
}
// --- Validation Tests Solver ---
TEST_CASE( "checkerboard_SN", "[validation_tests]" ) {
std::string config_file_name = std::string( TESTS_PATH ) + "input/checkerboard_SN.cfg";
......@@ -161,3 +162,54 @@ TEST_CASE( "linesource_MN", "[validation_tests]" ) {
}
}
}
// --- Validation Tests Output ---
TEST_CASE( "screen_output", "[output]" ) {
spdlog::drop_all(); // Make sure to write in own logging file
std::string config_file_name = std::string( TESTS_PATH ) + "input/validate_logger.cfg";
std::string screenLoggerReference = std::string( TESTS_PATH ) + "input/validate_screen_output_reference";
std::string screenLogger = std::string( TESTS_PATH ) + "../result/logs/validate_screen_output";
std::string historyLoggerReference = std::string( TESTS_PATH ) + "input/validate_screen_output_csv_reference";
std::string historyLogger = std::string( TESTS_PATH ) + "../result/logs/validate_screen_output_csv";
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
// --- Read and validate logger ---
std::ifstream screenLoggerReferenceStream( screenLoggerReference );
std::ifstream screenLoggerStream( screenLogger );
std::ifstream historyLoggerReferenceStream( historyLoggerReference );
std::ifstream historyLoggerStream( historyLogger );
std::string line, lineRef;
bool lineValid;
while( !screenLoggerReferenceStream.eof() && !screenLoggerStream.eof() ) {
std::getline( screenLoggerReferenceStream, lineRef );
std::getline( screenLoggerStream, line );
lineValid = lineRef.compare( line ) == 0;
if( !lineValid ) {
std::cout << lineRef << "\n" << line << "\n";
}
REQUIRE( lineValid );
}
bool eqLen = screenLoggerReferenceStream.eof() && screenLoggerStream.eof();
if( !eqLen ) {
std::cout << "Files of unequal length!\n";
}
REQUIRE( eqLen ); // Files must be of same length
while( !historyLoggerReferenceStream.eof() && !historyLoggerStream.eof() ) {
std::getline( historyLoggerReferenceStream, lineRef );
std::getline( historyLoggerStream, line );
lineValid = lineRef.compare( line ) == 0;
REQUIRE( lineValid );
}
eqLen = historyLoggerReferenceStream.eof() && historyLoggerStream.eof();
if( !eqLen ) {
std::cout << "Files of unequal length!\n";
}
REQUIRE( eqLen ); // Files must be of same length
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment