Skip to content

Commit cd5c18f

Browse files
committed
some cleanup of COutput and run the unsteady NACA0012 for 20 timesteps
1 parent f4f6298 commit cd5c18f

File tree

3 files changed

+51
-63
lines changed

3 files changed

+51
-63
lines changed

.github/workflows/regression.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
uses: docker://su2code/test-su2:20200303
9393
with:
9494
# -t <Tutorials-branch> -c <Testcases-branch>
95-
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}}
95+
args: -b ${{github.ref}} -t improve_unsteady_settings -c develop -s ${{matrix.testscript}}
9696
unit_tests:
9797
runs-on: ubuntu-latest
9898
name: Unit Tests

SU2_CFD/src/output/COutput.cpp

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,16 @@ bool COutput::GetCauchyCorrectedTimeConvergence(const CConfig *config){
924924
}
925925

926926
bool COutput::SetResult_Files(CGeometry *geometry, CConfig *config, CSolver** solver_container,
927-
unsigned long iter, bool force_writing){
927+
unsigned long iter, bool force_writing) {
928928

929-
bool isFileWrite=false;
930-
unsigned short nVolumeFiles = config->GetnVolumeOutputFiles();
931-
auto VolumeFiles = config->GetVolumeOutputFiles();
929+
bool isFileWrite = false;
930+
const auto nVolumeFiles = config->GetnVolumeOutputFiles();
931+
const auto* VolumeFiles = config->GetVolumeOutputFiles();
932932

933933
/*--- Check if the data sorters are allocated, if not, allocate them. --- */
934934
AllocateDataSorters(config, geometry);
935935

936-
for (unsigned short iFile = 0; iFile < nVolumeFiles; iFile++){
936+
for (unsigned short iFile = 0; iFile < nVolumeFiles; iFile++) {
937937

938938
/*--- Collect the volume data from the solvers.
939939
* If time-domain is enabled, we also load the data although we don't output it,
@@ -947,7 +947,7 @@ bool COutput::SetResult_Files(CGeometry *geometry, CConfig *config, CSolver** so
947947

948948
volumeDataSorter->SortOutputData();
949949

950-
if (rank == MASTER_NODE && !isFileWrite){
950+
if (rank == MASTER_NODE && !isFileWrite) {
951951
fileWritingTable->SetAlign(PrintingToolbox::CTablePrinter::CENTER);
952952
fileWritingTable->PrintHeader();
953953
fileWritingTable->SetAlign(PrintingToolbox::CTablePrinter::LEFT);
@@ -958,18 +958,18 @@ bool COutput::SetResult_Files(CGeometry *geometry, CConfig *config, CSolver** so
958958

959959
WriteToFile(config, geometry, VolumeFiles[iFile]);
960960

961-
if (rank == MASTER_NODE && !isFileWrite){
962-
fileWritingTable->PrintFooter();
963-
headerNeeded = true;
964-
}
965-
966961
/*--- Write any additonal files defined in the child class ----*/
967962

968963
WriteAdditionalFiles(config, geometry, solver_container);
969964

970965
isFileWrite = true;
971966
}
972967

968+
if (rank == MASTER_NODE && isFileWrite) {
969+
fileWritingTable->PrintFooter();
970+
headerNeeded = true;
971+
}
972+
973973
return isFileWrite;
974974
}
975975

@@ -1006,90 +1006,78 @@ void COutput::PrintConvergenceSummary(){
10061006

10071007
bool COutput::Convergence_Monitoring(CConfig *config, unsigned long Iteration) {
10081008

1009-
unsigned short iCounter;
1010-
10111009
convergence = true;
10121010

1013-
for (unsigned short iField_Conv = 0; iField_Conv < convFields.size(); iField_Conv++){
1011+
for (auto iField_Conv = 0ul; iField_Conv < convFields.size(); iField_Conv++) {
10141012

1015-
bool fieldConverged = false;
1013+
const auto& convField = convFields[iField_Conv];
1014+
const auto it = historyOutput_Map.find(convField);
10161015

1017-
const string &convField = convFields[iField_Conv];
1018-
if (historyOutput_Map.count(convField) > 0){
1019-
su2double monitor = historyOutput_Map.at(convField).value;
1016+
if (it == historyOutput_Map.end()) continue;
10201017

1021-
/*--- Stop the simulation in case a nan appears, do not save the solution ---*/
1022-
if (std::isnan(SU2_TYPE::GetValue(monitor))) {
1023-
SU2_MPI::Error("SU2 has diverged (NaN detected).", CURRENT_FUNCTION);
1024-
}
1018+
const auto& field = it->second;
1019+
const su2double monitor = field.value;
10251020

1026-
/*--- Cauchy based convergence criteria ---*/
1021+
/*--- Stop the simulation in case a nan appears, do not save the solution. ---*/
1022+
if (std::isnan(SU2_TYPE::GetValue(monitor))) {
1023+
SU2_MPI::Error("SU2 has diverged (NaN detected).", CURRENT_FUNCTION);
1024+
}
10271025

1028-
if (historyOutput_Map.at(convField).fieldType == HistoryFieldType::COEFFICIENT) {
1026+
bool fieldConverged = false;
1027+
1028+
switch (field.fieldType) {
1029+
1030+
/*--- Cauchy based convergence criteria ---*/
1031+
case HistoryFieldType::COEFFICIENT: {
10291032

1030-
if (Iteration == 0){
1031-
for (iCounter = 0; iCounter < nCauchy_Elems; iCounter++){
1033+
if (Iteration == 0) {
1034+
for (auto iCounter = 0ul; iCounter < nCauchy_Elems; iCounter++) {
10321035
cauchySerie[iField_Conv][iCounter] = 0.0;
10331036
}
10341037
newFunc[iField_Conv] = monitor;
10351038
}
10361039

10371040
oldFunc[iField_Conv] = newFunc[iField_Conv];
10381041
newFunc[iField_Conv] = monitor;
1039-
cauchyFunc = fabs(newFunc[iField_Conv] - oldFunc[iField_Conv])/fabs(monitor);
1042+
cauchyFunc = fabs(newFunc[iField_Conv] - oldFunc[iField_Conv]) / fabs(monitor);
10401043

10411044
cauchySerie[iField_Conv][Iteration % nCauchy_Elems] = cauchyFunc;
10421045
cauchyValue = 0.0;
1043-
for (iCounter = 0; iCounter < nCauchy_Elems; iCounter++)
1046+
for (auto iCounter = 0ul; iCounter < nCauchy_Elems; iCounter++)
10441047
cauchyValue += cauchySerie[iField_Conv][iCounter];
10451048

10461049
cauchyValue /= nCauchy_Elems;
10471050

1048-
if (cauchyValue >= cauchyEps) { fieldConverged = false;}
1049-
else { fieldConverged = true;}
1050-
10511051
/*--- Start monitoring only if the current iteration
1052-
* is larger than the number of cauchy elements and
1053-
* the number of start-up iterations --- */
1054-
1055-
if (Iteration < max(config->GetStartConv_Iter(), nCauchy_Elems)){
1056-
fieldConverged = false;
1057-
}
1052+
* is larger than the number of cauchy elements. --- */
1053+
fieldConverged = (cauchyValue < cauchyEps) && (Iteration >= nCauchy_Elems);
10581054

1055+
if (Iteration == 0) cauchyValue = 1.0;
10591056
SetHistoryOutputValue("CAUCHY_" + convField, cauchyValue);
10601057

1061-
if(Iteration == 0){
1062-
SetHistoryOutputValue("CAUCHY_" + convField, 1.0);
1063-
}
1064-
}
1058+
} break;
10651059

10661060

10671061
/*--- Residual based convergence criteria ---*/
1062+
case HistoryFieldType::RESIDUAL:
1063+
case HistoryFieldType::AUTO_RESIDUAL:
10681064

1069-
if (historyOutput_Map.at(convField).fieldType == HistoryFieldType::RESIDUAL ||
1070-
historyOutput_Map.at(convField).fieldType == HistoryFieldType::AUTO_RESIDUAL) {
1071-
1072-
/*--- Check the convergence ---*/
1073-
1074-
if (Iteration != 0 && (monitor <= minLogResidual)) { fieldConverged = true; }
1075-
else { fieldConverged = false; }
1076-
1077-
}
1078-
1079-
/*--- Do not apply any convergence criteria of the number
1080-
of iterations is less than a particular value ---*/
1081-
1082-
if (Iteration < config->GetStartConv_Iter()) {
1083-
fieldConverged = false;
1084-
}
1065+
fieldConverged = (Iteration != 0) && (monitor <= minLogResidual);
1066+
break;
10851067

1086-
convergence = fieldConverged && convergence;
1068+
default:
1069+
break;
10871070
}
1071+
1072+
convergence = fieldConverged && convergence;
10881073
}
10891074

1090-
if (convFields.empty()) convergence = false;
1075+
/*--- Do not apply any convergence criteria if the number
1076+
* of iterations is less than a particular value. ---*/
1077+
1078+
if (convFields.empty() || Iteration < config->GetStartConv_Iter()) convergence = false;
10911079

1092-
/*--- Apply the same convergence criteria to all the processors ---*/
1080+
/*--- Apply the same convergence criteria to all processors. ---*/
10931081

10941082
unsigned short local = convergence, global = 0;
10951083
SU2_MPI::Allreduce(&local, &global, 1, MPI_UNSIGNED_SHORT, MPI_MAX, SU2_MPI::GetComm());

TestCases/tutorials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ def main():
233233
tutorial_unst_naca0012 = TestCase('unsteady_naca0012')
234234
tutorial_unst_naca0012.cfg_dir = "../Tutorials/compressible_flow/Unsteady_NACA0012"
235235
tutorial_unst_naca0012.cfg_file = "unsteady_naca0012.cfg"
236-
tutorial_unst_naca0012.test_iter = 500
237-
tutorial_unst_naca0012.test_vals = [500, 0, 0.302003, 0.665069, -5.300141, 0.000000, 0.0000e+00, 0.0000e+00]
236+
tutorial_unst_naca0012.test_iter = 520
237+
tutorial_unst_naca0012.test_vals = [520, 0, 0.302003, 0.665069, -5.300141, 0.000000, 0.0000e+00, 0.0000e+00]
238238
tutorial_unst_naca0012.su2_exec = "mpirun -np 2 SU2_CFD"
239239
tutorial_unst_naca0012.timeout = 1600
240240
tutorial_unst_naca0012.tol = 0.00001

0 commit comments

Comments
 (0)