diff --git a/SU2_CFD/include/output/COutput.hpp b/SU2_CFD/include/output/COutput.hpp index ce4e29ed2c1..e33eb0d1baf 100644 --- a/SU2_CFD/include/output/COutput.hpp +++ b/SU2_CFD/include/output/COutput.hpp @@ -95,6 +95,7 @@ class COutput { ofstream histFile; /*!< \brief Output file stream for the history */ bool cauchyTimeConverged; /*! \brief: Flag indicating that solver is already converged. Needed for writing restart files. */ + bool maxTimeDelayActive; /*! \brief: Flag for delaying stop at max_time with 2nd order time stepping. */ /** \brief Enum to identify the screen output format. */ enum class ScreenOutputFormat { @@ -591,6 +592,7 @@ class COutput { * \param[in] solver_container - Container vector with all the solutions. * \param[in] iter - The current time, outer or inner iteration index. * \param[in] force_writing - If , writing of output files is forced without checking the output frequency. + * \param[in] write_restart_only - If , only restart (and CSV restart) volume files are written. * \return if output files have been written to disk. */ bool SetResultFiles(CGeometry *geometry, CConfig *config, CSolver** solver_container, diff --git a/SU2_CFD/src/output/COutput.cpp b/SU2_CFD/src/output/COutput.cpp index 0be8bfb759e..fa7a00d4a8c 100644 --- a/SU2_CFD/src/output/COutput.cpp +++ b/SU2_CFD/src/output/COutput.cpp @@ -70,6 +70,7 @@ COutput::COutput(const CConfig *config, unsigned short ndim, bool fem_output): us_units(config->GetSystemMeasurements() == US) { cauchyTimeConverged = false; + maxTimeDelayActive = false; convergenceTable = new PrintingToolbox::CTablePrinter(&std::cout); multiZoneHeaderTable = new PrintingToolbox::CTablePrinter(&std::cout); @@ -793,6 +794,7 @@ void COutput::WriteToFile(CConfig *config, CGeometry *geometry, OUTPUT_TYPE form } bool COutput::GetCauchyCorrectedTimeConvergence(const CConfig *config){ + // Handle Cauchy convergence delay for 2nd order time stepping if(!cauchyTimeConverged && TimeConvergence && config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND){ // Change flags for 2nd order Time stepping: In case of convergence, this iter and next iter gets written out. then solver stops cauchyTimeConverged = TimeConvergence; @@ -801,6 +803,25 @@ bool COutput::GetCauchyCorrectedTimeConvergence(const CConfig *config){ else if(cauchyTimeConverged){ TimeConvergence = cauchyTimeConverged; } + + // Handle max time delay for 2nd order time stepping + // Delay stopping at max_time to ensure both timestep N and N-1 are written for proper restart + if(config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND){ + const su2double cur_time = GetHistoryFieldValue("CUR_TIME"); + const su2double max_time = config->GetMax_Time(); + const bool final_time_reached = (cur_time >= max_time); + + // If max_time is reached on first detection, delay the stop + if(final_time_reached && !maxTimeDelayActive){ + maxTimeDelayActive = true; + TimeConvergence = false; // Delay stop to run one more iteration + } + else if(maxTimeDelayActive){ + TimeConvergence = true; // Now allow stop + maxTimeDelayActive = false; // Reset for next run + } + } + return TimeConvergence; }