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

finished history output, added option CSV_OUT to verbose history output. history Logger still buggy


Former-commit-id: c3a02db0
parent 04697178
......@@ -20,7 +20,7 @@ class SNSolverMPI : public SNSolver
/**
* @brief Output solution to VTK file
*/
virtual void Save() const;
virtual void PrintVolumeOutput() const;
};
#endif // SNSOLVERMPI_H
......@@ -97,17 +97,17 @@ class Solver
/*! @brief Function that prepares VTK export and csv export of the current solver iteration */
virtual void WriteVolumeOutput( unsigned iteration ) = 0;
/*! @brief Save Output solution at given energy (pseudo time) to VTK file */
void Save( int currEnergy ) const;
void PrintVolumeOutput( int currEnergy ) const;
/*! @brief: Initialized the output fields and their Names for the Screenoutput */
void PrepareScreenOutput();
/*! @brief Function that Screen Output and prints to Screen/Logger */
void WriteScreenOutput( unsigned iteration );
/*! @brief Function that writes screen and history output fields */
void WriteScalarOutput( unsigned iteration );
/*! @brief Prints ScreenOutputFields to Screen and to logger */
void PrintScreen( unsigned iteration );
/*! @brief Function that writes scalar historyOutputFields to a .csv file */
void WriteHistoryOutput();
void PrintScreenOutput( unsigned iteration );
/*! @brief: Initialized the historyOutputFields and their Names for Historyoutput */
void PrepareHistoryOutput();
/*! @brief Prints HistoryOutputFields to logger */
void PrintHistoryOutput( unsigned iteration );
public:
/*! @brief Solver constructor
......@@ -125,6 +125,6 @@ class Solver
virtual void Solve();
/*! @brief Save Output solution to VTK file */
void Save() const;
void PrintVolumeOutput() const;
};
#endif // SOLVER_H
......@@ -17,9 +17,11 @@ LOG_DIR = ../result/logs
MESH_FILE = linesource.su2
%MESH_FILE = linesource_debug.su2
%
% ---- Problem description ---
%
PROBLEM = LINESOURCE
SCATTER_COEFF = 1
%
% ---- Solver specifications ----
%
% Solver type
......
......@@ -755,6 +755,7 @@ void Config::InitLogger() {
int pe;
MPI_Comm_rank( MPI_COMM_WORLD, &pe );
char cfilename[1024];
if( pe == 0 ) {
// get date and time
time_t now = time( nullptr );
......@@ -793,4 +794,59 @@ void Config::InitLogger() {
spdlog::register_logger( event_logger );
spdlog::flush_every( std::chrono::seconds( 5 ) );
}
if( spdlog::get( "tabular" ) == nullptr ) {
// create sinks if level is not off
std::vector<spdlog::sink_ptr> sinks;
if( terminalLogLvl != spdlog::level::off ) {
// create spdlog terminal sink
auto terminalSink = std::make_shared<spdlog::sinks::stdout_sink_mt>();
terminalSink->set_level( terminalLogLvl );
terminalSink->set_pattern( "%v" );
sinks.push_back( terminalSink );
}
if( fileLogLvl != spdlog::level::off ) {
// define filename on root
int pe;
MPI_Comm_rank( MPI_COMM_WORLD, &pe );
char cfilename[1024];
if( pe == 0 ) {
// get date and time
time_t now = time( nullptr );
struct tm tstruct;
char buf[80];
tstruct = *localtime( &now );
strftime( buf, sizeof( buf ), "%Y-%m-%d_%X_csv", &tstruct );
// set filename to date and time
std::string filename = buf;
// in case of existing files append '_#'
int ctr = 0;
if( std::filesystem::exists( _logDir + filename ) ) {
filename += "_" + std::to_string( ++ctr );
}
while( std::filesystem::exists( _logDir + filename ) ) {
filename.pop_back();
filename += std::to_string( ++ctr );
}
strncpy( cfilename, filename.c_str(), sizeof( cfilename ) );
cfilename[sizeof( cfilename ) - 1] = 0;
}
MPI_Bcast( &cfilename, sizeof( cfilename ), MPI_CHAR, 0, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
// create spdlog file sink
auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>( _logDir + cfilename );
fileSink->set_level( fileLogLvl );
fileSink->set_pattern( "%Y-%m-%d %H:%M:%S.%f , %v" );
sinks.push_back( fileSink );
}
// register all sinks
auto event_logger = std::make_shared<spdlog::logger>( "tabular", begin( sinks ), end( sinks ) );
spdlog::register_logger( event_logger );
spdlog::flush_every( std::chrono::seconds( 5 ) );
}
}
......@@ -39,7 +39,7 @@ int main( int argc, char** argv ) {
// Run solver and export
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
MPI_Finalize();
return EXIT_SUCCESS;
......
......@@ -144,7 +144,7 @@ void CSDSNSolver::Solve() {
// --- VTK and CSV Output ---
WriteVolumeOutput( n );
Save( n );
PrintVolumeOutput( n );
// --- Screen Output ---
dFlux = blaze::l2Norm( fluxNew - fluxOld );
......
......@@ -67,7 +67,7 @@ void SNSolverMPI::Solve() {
}*/
}
void SNSolverMPI::Save() const {
void SNSolverMPI::PrintVolumeOutput() const {
std::vector<std::string> fieldNames{ "flux" };
std::vector<std::vector<std::string>> fieldNamesWrapper{ fieldNames };
......
......@@ -79,7 +79,9 @@ void Solver::Solve() {
int rank;
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
auto log = spdlog::get( "event" );
auto log = spdlog::get( "event" );
auto logCSV = spdlog::get( "tabular" );
std::string hLine = "--";
if( rank == 0 ) {
......@@ -105,6 +107,14 @@ void Solver::Solve() {
log->info( hLine );
log->info( lineToPrint );
log->info( hLine );
std::string lineToPrintCSV = "";
for( unsigned idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
std::string tmp = _historyOutputFieldNames[idxFields];
lineToPrintCSV += tmp + ",";
}
lineToPrintCSV += _historyOutputFieldNames[_settings->GetNHistoryOutput() - 1];
logCSV->info( lineToPrintCSV );
}
// Loop over energies (pseudo-time of continuous slowing down approach)
......@@ -122,13 +132,12 @@ void Solver::Solve() {
// --- Postprocessing ---
IterPostprocessing();
// --- VTK and CSV Output ---
// --- Solver Output ---
WriteVolumeOutput( iter );
Save( iter );
// --- Screen Output ---
WriteScreenOutput( iter );
PrintScreen( iter );
WriteScalarOutput( iter );
PrintScreenOutput( iter );
PrintHistoryOutput( iter );
PrintVolumeOutput( iter );
}
if( rank == 0 ) {
log->info( hLine );
......@@ -137,9 +146,9 @@ void Solver::Solve() {
}
}
void Solver::Save() const { ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh ); }
void Solver::PrintVolumeOutput() const { ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh ); }
void Solver::Save( int currEnergy ) const {
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 );
}
......@@ -185,11 +194,12 @@ void Solver::PrepareScreenOutput() {
}
}
void Solver::WriteScreenOutput( unsigned iteration ) {
void Solver::WriteScalarOutput( unsigned iteration ) {
unsigned nFields = (unsigned)_settings->GetNScreenOutput();
double mass = 0.0;
// -- Screen Output
for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
// Prepare all Output Fields per group
// Different procedure, depending on the Group...
......@@ -216,12 +226,77 @@ void Solver::WriteScreenOutput( unsigned iteration ) {
}
break;
default: ErrorMessages::Error( "Screen Output Group not defined!", CURRENT_FUNCTION ); break;
case CSV_OUTPUT:
_screenOutputFields[idx_field] = 0;
if( ( _settings->GetHistoryOutputFrequency() != 0 && iteration % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
( iteration == _nEnergies - 1 ) /* need sol at last iteration */ ) {
_screenOutputFields[idx_field] = 1;
}
break;
default: ErrorMessages::Error( "Screen output group not defined!", CURRENT_FUNCTION ); break;
}
}
// --- History output ---
nFields = (unsigned)_settings->GetNHistoryOutput();
std::vector<SCALAR_OUTPUT> screenOutputFields = _settings->GetScreenOutput();
for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
// Check first, if the field was already filled by screenoutput writer!
std::vector<SCALAR_OUTPUT>::iterator itScreenOutput =
std::find( screenOutputFields.begin(), screenOutputFields.end(), _settings->GetHistoryOutput()[idx_field] );
// Prepare all Output Fields per group
// Different procedure, depending on the Group...
switch( _settings->GetHistoryOutput()[idx_field] ) {
case MASS:
if( screenOutputFields.end() == itScreenOutput ) {
for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
mass += _fluxNew[idx_cell] * _areas[idx_cell];
}
_historyOutputFields[idx_field] = mass;
}
else {
_historyOutputFields[idx_field] = *itScreenOutput;
}
break;
case ITER: _historyOutputFields[idx_field] = iteration; break;
case RMS_FLUX:
if( screenOutputFields.end() == itScreenOutput ) {
_screenOutputFields[idx_field] = blaze::l2Norm( _fluxNew - _flux );
_flux = _fluxNew;
}
else {
_historyOutputFields[idx_field] = *itScreenOutput;
}
break;
case VTK_OUTPUT:
_historyOutputFields[idx_field] = 0;
if( ( _settings->GetVolumeOutputFrequency() != 0 && iteration % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
( iteration == _nEnergies - 1 ) /* need sol at last iteration */ ) {
_historyOutputFields[idx_field] = 1;
}
break;
case CSV_OUTPUT:
_historyOutputFields[idx_field] = 0;
if( ( _settings->GetHistoryOutputFrequency() != 0 && iteration % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
( iteration == _nEnergies - 1 ) /* need sol at last iteration */ ) {
_historyOutputFields[idx_field] = 1;
}
break;
default: ErrorMessages::Error( "History output group not defined!", CURRENT_FUNCTION ); break;
}
}
}
void Solver::PrintScreen( unsigned iteration ) {
void Solver::PrintScreenOutput( unsigned iteration ) {
int rank;
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
auto log = spdlog::get( "event" );
......@@ -231,13 +306,14 @@ void Solver::PrintScreen( unsigned iteration ) {
// assemble the line to print
std::string lineToPrint = "| ";
std::string tmp;
for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput(); idx_field++ ) {
std::string tmp = std::to_string( _screenOutputFields[idx_field] );
tmp = std::to_string( _screenOutputFields[idx_field] );
// Format outputs correctly
std::vector<SCALAR_OUTPUT> integerFields = { ITER };
std::vector<SCALAR_OUTPUT> scientificFields = { RMS_FLUX, MASS };
std::vector<SCALAR_OUTPUT> booleanFields = { VTK_OUTPUT };
std::vector<SCALAR_OUTPUT> booleanFields = { VTK_OUTPUT, CSV_OUTPUT };
if( !( integerFields.end() == std::find( integerFields.begin(), integerFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
tmp = std::to_string( (int)_screenOutputFields[idx_field] );
......@@ -283,18 +359,43 @@ void Solver::PrepareHistoryOutput() {
// Prepare all Output Fields per group
// Different procedure, depending on the Group...
switch( _settings->GetScreenOutput()[idx_field] ) {
switch( _settings->GetHistoryOutput()[idx_field] ) {
case MASS: _historyOutputFieldNames[idx_field] = "Mass"; break;
case ITER: _historyOutputFieldNames[idx_field] = "Iter"; break;
case RMS_FLUX: _historyOutputFieldNames[idx_field] = "RMS flux"; break;
case RMS_FLUX: _historyOutputFieldNames[idx_field] = "RMS_flux"; break;
case VTK_OUTPUT: _historyOutputFieldNames[idx_field] = "VTK out"; break;
case VTK_OUTPUT: _historyOutputFieldNames[idx_field] = "VTK_out"; break;
case CSV_OUTPUT: _historyOutputFieldNames[idx_field] = "CSV out"; break;
case CSV_OUTPUT: _historyOutputFieldNames[idx_field] = "CSV_out"; break;
default: ErrorMessages::Error( "History output field not defined!", CURRENT_FUNCTION ); break;
}
}
}
void Solver::PrintHistoryOutput( unsigned iteration ) {
int rank;
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
auto log = spdlog::get( "tabular" );
// assemble the line to print
std::string lineToPrint = "";
std::string tmp;
for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput() - 1; idx_field++ ) {
tmp = std::to_string( _screenOutputFields[idx_field] );
lineToPrint += tmp + ",";
}
tmp = std::to_string( _screenOutputFields[_settings->GetNScreenOutput() - 1] );
lineToPrint += tmp; // Last element without comma
if( rank == 0 ) {
if( _settings->GetHistoryOutputFrequency() != 0 && iteration % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) {
log->info( lineToPrint );
}
if( iteration == _nEnergies - 1 ) { // Always print last iteration
log->info( lineToPrint );
}
}
}
......@@ -37,7 +37,7 @@ TEST_CASE( "checkerboard_SN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_checkerboard_SN.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/checkerboard_SN_reference.vtk" );
......@@ -55,7 +55,7 @@ TEST_CASE( "checkerboard_PN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_checkerboard_PN.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/checkerboard_PN_reference.vtk" );
......@@ -73,7 +73,7 @@ TEST_CASE( "checkerboard_MN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_checkerboard_MN.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/checkerboard_MN_reference.vtk" );
......@@ -91,7 +91,7 @@ TEST_CASE( "linesource_SN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_linesource_SN.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/linesource_SN_reference.vtk" );
......@@ -109,7 +109,7 @@ TEST_CASE( "linesource_PN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_linesource_PN.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/linesource_PN_reference.vtk" );
......@@ -130,7 +130,7 @@ TEST_CASE( "linesource_MN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_linesource_MN_Quad.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/linesource_MN_Quad_reference.vtk" );
......@@ -149,7 +149,7 @@ TEST_CASE( "linesource_MN", "[validation_tests]" ) {
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
solver->PrintVolumeOutput();
auto test = readVTKFile( std::string( TESTS_PATH ) + "../result/rtsn_test_linesource_MN_MB.vtk" );
auto reference = readVTKFile( std::string( TESTS_PATH ) + "input/linesource_MN_MB_reference.vtk" );
......
Markdown is supported
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