Repository navigation
Fixed CL: write the finite difference dCX/dCL to flow.meta regardless of the screen output frequency - #2952
Fixed CL: write the finite difference dCX/dCL to flow.meta regardless of the screen output frequency#2952nikita-ageev wants to merge 4 commits into
Conversation
…creen output frequency SetFixedCLScreenOutput stores the iteration at which the finite difference step starts and, at its end, writes flow.meta with dCD/dCL and dCMx/y/z/dCL. It is called only on screen output iterations, so when the finite difference step ended on an iteration that is not a multiple of SCREEN_WRT_FREQ_INNER the meta data file kept the values from the start of the step and the adjoint read stale derivatives. Always write the screen output at the start and the end of the finite difference step in fixed CL mode. Fixes su2code#2937
|
|
||
| if (config->GetFixed_CL_Mode() && config->GetFinite_Difference_Mode() && | ||
| !(config->GetMultizone_Problem() && !config->GetWrt_ZoneConv())) { | ||
| const bool startFD = fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > 1e-16; |
There was a problem hiding this comment.
use EPS,
| const bool startFD = fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > 1e-16; | |
| const bool startFD = fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > EPS; |
joshkellyjak
left a comment
There was a problem hiding this comment.
Nice catch, a test that catches this bug would be useful
| if (startFD || endFD) return true; | ||
| } | ||
|
|
||
| return COutput::WriteScreenOutput(config); |
There was a problem hiding this comment.
Am I correct in thinking writing the meta data file now depends on whether the screen line is printed? I'm not sure this is best way to fix this. I think the WriteMetaData call should come outside of SetFixedCLScreenOutput into code that runs every iteration e.g. SetHistoryOutput.
| if (config->GetFixed_CL_Mode() && config->GetFinite_Difference_Mode() && | ||
| !(config->GetMultizone_Problem() && !config->GetWrt_ZoneConv())) { | ||
| const bool startFD = fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > 1e-16; | ||
| const bool endFD = historyOutput_Map["AOA"].value == historyOutput_Map["PREV_AOA"].value; |
There was a problem hiding this comment.
these start and end conditions are copied from SetFixedCLScreenOutput, put them in helper functions so they can be accessed in multiple places and stay identical
| if (config->GetFixed_CL_Mode() && config->GetFinite_Difference_Mode() && | ||
| !(config->GetMultizone_Problem() && !config->GetWrt_ZoneConv())) { | ||
| const bool startFD = fabs(historyOutput_Map["CL_DRIVER_COMMAND"].value) > 1e-16; | ||
| const bool endFD = historyOutput_Map["AOA"].value == historyOutput_Map["PREV_AOA"].value; |
There was a problem hiding this comment.
you should use GetHistoryFieldValue(name) rather than historyOutput_Map["AOA"]
const bool startFD = fabs(GetHistoryFieldValue("CL_DRIVER_COMMAND")) > EPS; const bool endFD = GetHistoryFieldValue("AOA") == GetHistoryFieldValue("PREV_AOA");
Address review comments: - move the finite difference bookkeeping (start iteration and WriteMetaData at the end of the step) out of SetFixedCLScreenOutput into SetFixedCLFiniteDifference, called from LoadHistoryData every iteration; - drop the WriteScreenOutput override, screen output frequency is unchanged; - share the start/end conditions via FixedCLStartFD/FixedCLEndFD helpers, using GetHistoryFieldValue and EPS.
|
Updated in ea814ec:
On the test: would a regression case be OK as a small fixed-CL finite-difference case with a Thanks for the review! |
| * \return <TRUE> if the AoA is equal to the previous AoA. | ||
| */ | ||
| bool FixedCLEndFD() const { | ||
| return GetHistoryFieldValue("AOA") == GetHistoryFieldValue("PREV_AOA"); |
Proposed Changes
Fixes #2937.
In fixed CL mode
CFlowOutput::SetFixedCLScreenOutputstores the iteration at which the finite difference step starts and, when the step ends, prints the "Fixed CL Mode (Finite Difference)" summary and writesflow.metawithDCD_DCL_VALUEandDCMX/DCMY/DCMZ_DCL_VALUE. It is called fromSetAdditionalScreenOutput, i.e. only on screen output iterations. When the finite difference step ends on an iteration that is not a multiple ofSCREEN_WRT_FREQ_INNER(typically when it stops atITER_DCL_DALPHA), the summary and the finalWriteMetaDataare skipped.flow.metathen keeps the values written at the start of the step, and a discrete adjoint run reads stale dCX/dCL.This PR overrides
WriteScreenOutputinCFlowOutput: in fixed CL mode withFinite_Difference_Modeset, the screen output is written on the iteration where the step starts (CL_DRIVER_COMMAND != 0) and on the iteration where it ends (AOA == PREV_AOA, the same conditionSetFixedCLScreenOutputalready uses). All other iterations follow the screen frequency as before. The override applies toCFlowCompOutputandCNEMOCompOutput, both of which callSetFixedCLScreenOutput.Test:
TestCases/fixed_cl/naca0012/inv_NACA0012.cfgwith the QuickStart mesh,RESTART_SOL= NO, serial, develop at a6b7496.flow.metawritten at the end:SCREEN_WRT_FREQ_INNERDCD_DCL_VALUE/DCMZ_DCL_VALUEITERandAOAinflow.metaare the same in all runs. WithSCREEN_WRT_FREQ_INNER= 1the log,history.csvandflow.metaare identical to develop; with 10 thehistory.csvand the restart file are identical to develop, the only difference is the finite difference summary on screen and the correctedflow.meta.fixedcl_naca0012andcontadj_fixedcl_naca0012fromserial_regression.pypass with the stored values.No new regression test: the regression framework compares history values at
test_iter, and the fix only changesflow.metaand screen output. I can add a check if there is a preferred way to test meta data files.Related Work
#2937 (issue). No other open PR touches the fixed CL output.
PR Checklist
pre-commit run --allto format old commits.