diff --git a/SU2_CFD/include/output/CFlowOutput.hpp b/SU2_CFD/include/output/CFlowOutput.hpp index 7e6264f1847..1eb33baed49 100644 --- a/SU2_CFD/include/output/CFlowOutput.hpp +++ b/SU2_CFD/include/output/CFlowOutput.hpp @@ -364,6 +364,32 @@ class CFlowOutput : public CFVMOutput{ */ void SetFixedCLScreenOutput(const CConfig *config); + /*! + * \brief Check if the fixed CL driver changed the AoA at the current iteration + * (in finite difference mode this is the start of the finite difference step). + * \return if the AoA was changed. + */ + bool FixedCLStartFD() const { + return fabs(GetHistoryFieldValue("CL_DRIVER_COMMAND")) > EPS; + } + + /*! + * \brief Check if the AoA was restored at the current iteration + * (in finite difference mode this is the end of the finite difference step). + * \return if the AoA is equal to the previous AoA. + */ + bool FixedCLEndFD() const { + return GetHistoryFieldValue("AOA") == GetHistoryFieldValue("PREV_AOA"); + } + + /*! + * \brief Store the iteration at which the finite difference step of the fixed CL driver starts and + * write the meta data file with the finite difference derivatives at its end. + * \note Called every iteration, independently of the screen output frequency. + * \param[in] config - Definition of the particular problem per zone. + */ + void SetFixedCLFiniteDifference(const CConfig *config); + /*! * \brief Compute the ratio of the stochastic energy backscatter to the turbulent energy dissipation. * \param iPoint - Index of the point. diff --git a/SU2_CFD/src/output/CFlowCompOutput.cpp b/SU2_CFD/src/output/CFlowCompOutput.cpp index fd9bd5356b0..46f3acb4688 100644 --- a/SU2_CFD/src/output/CFlowCompOutput.cpp +++ b/SU2_CFD/src/output/CFlowCompOutput.cpp @@ -470,6 +470,10 @@ void CFlowCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol SetAerodynamicCoefficients(config, flow_solver); + /*--- Fixed CL finite difference step, uses the AOA set above. ---*/ + + if (config->GetFixed_CL_Mode()) SetFixedCLFiniteDifference(config); + if (config->GetViscous()) { SetHistoryOutputValue("BUFFET", flow_solver->GetTotal_Buffet_Metric()); } diff --git a/SU2_CFD/src/output/CFlowOutput.cpp b/SU2_CFD/src/output/CFlowOutput.cpp index 2ac2693b995..50f69f85579 100644 --- a/SU2_CFD/src/output/CFlowOutput.cpp +++ b/SU2_CFD/src/output/CFlowOutput.cpp @@ -4245,7 +4245,7 @@ void CFlowOutput::LoadTimeAveragedData(unsigned long iPoint, const CVariable *No void CFlowOutput::SetFixedCLScreenOutput(const CConfig *config){ PrintingToolbox::CTablePrinter FixedCLSummary(&cout); - if (fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > 1e-16){ + if (FixedCLStartFD()){ FixedCLSummary.AddColumn("Fixed CL Mode", 40); FixedCLSummary.AddColumn("Value", 30); FixedCLSummary.SetAlign(PrintingToolbox::CTablePrinter::LEFT); @@ -4255,7 +4255,6 @@ void CFlowOutput::SetFixedCLScreenOutput(const CConfig *config){ FixedCLSummary << "Previous AOA" << historyOutput_Map["PREV_AOA"].value; if (config->GetFinite_Difference_Mode()){ FixedCLSummary << "Changed AoA by (Finite Difference step)" << historyOutput_Map["CL_DRIVER_COMMAND"].value; - lastInnerIter = curInnerIter - 1; } else FixedCLSummary << "Changed AoA by" << historyOutput_Map["CL_DRIVER_COMMAND"].value; @@ -4263,7 +4262,7 @@ void CFlowOutput::SetFixedCLScreenOutput(const CConfig *config){ SetScreenHeader(config); } - else if (config->GetFinite_Difference_Mode() && historyOutput_Map["AOA"].value == historyOutput_Map["PREV_AOA"].value){ + else if (config->GetFinite_Difference_Mode() && FixedCLEndFD()){ FixedCLSummary.AddColumn("Fixed CL Mode (Finite Difference)", 40); FixedCLSummary.AddColumn("Value", 30); FixedCLSummary.SetAlign(PrintingToolbox::CTablePrinter::LEFT); @@ -4276,6 +4275,20 @@ void CFlowOutput::SetFixedCLScreenOutput(const CConfig *config){ } FixedCLSummary << "Delta CMz / Delta CL" << config->GetdCMz_dCL(); FixedCLSummary.PrintFooter(); + } +} + +void CFlowOutput::SetFixedCLFiniteDifference(const CConfig *config){ + + /*--- This runs every iteration, independently of the screen output frequency, otherwise the finite + * difference step can end without writing dCL/dAlpha and dCX/dCL to the meta data file. ---*/ + + if (!config->GetFinite_Difference_Mode()) return; + + if (FixedCLStartFD()){ + lastInnerIter = curInnerIter - 1; + } + else if (FixedCLEndFD()){ curInnerIter = lastInnerIter; WriteMetaData(config); curInnerIter = config->GetInnerIter(); diff --git a/SU2_CFD/src/output/CNEMOCompOutput.cpp b/SU2_CFD/src/output/CNEMOCompOutput.cpp index 2105ee37899..332d4ca4093 100644 --- a/SU2_CFD/src/output/CNEMOCompOutput.cpp +++ b/SU2_CFD/src/output/CNEMOCompOutput.cpp @@ -437,6 +437,10 @@ void CNEMOCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol SetAerodynamicCoefficients(config, NEMO_solver); + /*--- Fixed CL finite difference step, uses the AOA set above. ---*/ + + if (config->GetFixed_CL_Mode()) SetFixedCLFiniteDifference(config); + SetHeatCoefficients(config, NEMO_solver); SetRotatingFrameCoefficients(NEMO_solver);