Skip to content

Commit

Permalink
Merge pull request #1616 from su2code/improve_unsteady_tutorials
Browse files Browse the repository at this point in the history
Run the unsteady NACA0012 tutorial for 20 timesteps
  • Loading branch information
pcarruscag authored May 10, 2022
2 parents 6acc62f + 3fa0e2a commit fa910a0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 62 deletions.
108 changes: 48 additions & 60 deletions SU2_CFD/src/output/COutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,16 +924,16 @@ bool COutput::GetCauchyCorrectedTimeConvergence(const CConfig *config){
}

bool COutput::SetResult_Files(CGeometry *geometry, CConfig *config, CSolver** solver_container,
unsigned long iter, bool force_writing){
unsigned long iter, bool force_writing) {

bool isFileWrite=false;
unsigned short nVolumeFiles = config->GetnVolumeOutputFiles();
auto VolumeFiles = config->GetVolumeOutputFiles();
bool isFileWrite = false;
const auto nVolumeFiles = config->GetnVolumeOutputFiles();
const auto* VolumeFiles = config->GetVolumeOutputFiles();

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

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

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

volumeDataSorter->SortOutputData();

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

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

if (rank == MASTER_NODE && !isFileWrite){
fileWritingTable->PrintFooter();
headerNeeded = true;
}

/*--- Write any additonal files defined in the child class ----*/

WriteAdditionalFiles(config, geometry, solver_container);

isFileWrite = true;
}

if (rank == MASTER_NODE && isFileWrite) {
fileWritingTable->PrintFooter();
headerNeeded = true;
}

return isFileWrite;
}

Expand Down Expand Up @@ -1006,90 +1006,78 @@ void COutput::PrintConvergenceSummary(){

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

unsigned short iCounter;

convergence = true;

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

bool fieldConverged = false;
const auto& convField = convFields[iField_Conv];
const auto it = historyOutput_Map.find(convField);

const string &convField = convFields[iField_Conv];
if (historyOutput_Map.count(convField) > 0){
su2double monitor = historyOutput_Map.at(convField).value;
if (it == historyOutput_Map.end()) continue;

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

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

if (historyOutput_Map.at(convField).fieldType == HistoryFieldType::COEFFICIENT) {
bool fieldConverged = false;

switch (field.fieldType) {

/*--- Cauchy based convergence criteria ---*/
case HistoryFieldType::COEFFICIENT: {

if (Iteration == 0){
for (iCounter = 0; iCounter < nCauchy_Elems; iCounter++){
if (Iteration == 0) {
for (auto iCounter = 0ul; iCounter < nCauchy_Elems; iCounter++) {
cauchySerie[iField_Conv][iCounter] = 0.0;
}
newFunc[iField_Conv] = monitor;
}

oldFunc[iField_Conv] = newFunc[iField_Conv];
newFunc[iField_Conv] = monitor;
cauchyFunc = fabs(newFunc[iField_Conv] - oldFunc[iField_Conv])/fabs(monitor);
cauchyFunc = fabs(newFunc[iField_Conv] - oldFunc[iField_Conv]) / fabs(monitor);

cauchySerie[iField_Conv][Iteration % nCauchy_Elems] = cauchyFunc;
cauchyValue = 0.0;
for (iCounter = 0; iCounter < nCauchy_Elems; iCounter++)
for (auto iCounter = 0ul; iCounter < nCauchy_Elems; iCounter++)
cauchyValue += cauchySerie[iField_Conv][iCounter];

cauchyValue /= nCauchy_Elems;

if (cauchyValue >= cauchyEps) { fieldConverged = false;}
else { fieldConverged = true;}

/*--- Start monitoring only if the current iteration
* is larger than the number of cauchy elements and
* the number of start-up iterations --- */

if (Iteration < max(config->GetStartConv_Iter(), nCauchy_Elems)){
fieldConverged = false;
}
* is larger than the number of cauchy elements. --- */
fieldConverged = (cauchyValue < cauchyEps) && (Iteration >= nCauchy_Elems);

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

if(Iteration == 0){
SetHistoryOutputValue("CAUCHY_" + convField, 1.0);
}
}
} break;


/*--- Residual based convergence criteria ---*/
case HistoryFieldType::RESIDUAL:
case HistoryFieldType::AUTO_RESIDUAL:

if (historyOutput_Map.at(convField).fieldType == HistoryFieldType::RESIDUAL ||
historyOutput_Map.at(convField).fieldType == HistoryFieldType::AUTO_RESIDUAL) {

/*--- Check the convergence ---*/

if (Iteration != 0 && (monitor <= minLogResidual)) { fieldConverged = true; }
else { fieldConverged = false; }

}

/*--- Do not apply any convergence criteria of the number
of iterations is less than a particular value ---*/

if (Iteration < config->GetStartConv_Iter()) {
fieldConverged = false;
}
fieldConverged = (Iteration != 0) && (monitor <= minLogResidual);
break;

convergence = fieldConverged && convergence;
default:
break;
}

convergence = fieldConverged && convergence;
}

if (convFields.empty()) convergence = false;
/*--- Do not apply any convergence criteria if the number
* of iterations is less than a particular value. ---*/

if (convFields.empty() || Iteration < config->GetStartConv_Iter()) convergence = false;

/*--- Apply the same convergence criteria to all the processors ---*/
/*--- Apply the same convergence criteria to all processors. ---*/

unsigned short local = convergence, global = 0;
SU2_MPI::Allreduce(&local, &global, 1, MPI_UNSIGNED_SHORT, MPI_MAX, SU2_MPI::GetComm());
Expand Down
4 changes: 2 additions & 2 deletions TestCases/tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def main():
tutorial_unst_naca0012 = TestCase('unsteady_naca0012')
tutorial_unst_naca0012.cfg_dir = "../Tutorials/compressible_flow/Unsteady_NACA0012"
tutorial_unst_naca0012.cfg_file = "unsteady_naca0012.cfg"
tutorial_unst_naca0012.test_iter = 500
tutorial_unst_naca0012.test_vals = [500, 0, 0.302003, 0.665069, -5.300141, 0.000000, 0.0000e+00, 0.0000e+00]
tutorial_unst_naca0012.test_iter = 520
tutorial_unst_naca0012.test_vals = [520, 0, -5.301340, 0, 0.303926, 0.782462, 0.003118, 0.015962]
tutorial_unst_naca0012.su2_exec = "mpirun -np 2 SU2_CFD"
tutorial_unst_naca0012.timeout = 1600
tutorial_unst_naca0012.tol = 0.00001
Expand Down

0 comments on commit fa910a0

Please sign in to comment.