Skip to content

Commit 80027e8

Browse files
committed
Improve readability of direct residual in adjoint problems
1 parent 49de8bb commit 80027e8

1 file changed

Lines changed: 80 additions & 84 deletions

File tree

SU2_CFD/src/drivers/CDriver.cpp

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,112 +2738,108 @@ void CDriver::PrintDirectResidual(RECORDING kind_recording) {
27382738
if (rank != MASTER_NODE || kind_recording != RECORDING::SOLUTION_VARIABLES) return;
27392739

27402740
const bool multizone = config_container[ZONE_0]->GetMultizone_Problem();
2741+
const unsigned short fieldWidth = 25;
27412742

2742-
/*--- Helper lambda func to return lenghty [iVar][iZone] string. ---*/
2743-
auto iVar_iZone2string = [&](unsigned short ivar, unsigned short izone) {
2744-
if (multizone)
2745-
return "[" + std::to_string(ivar) + "][" + std::to_string(izone) + "]";
2746-
return "[" + std::to_string(ivar) + "]";
2747-
};
2748-
2749-
/*--- Print residuals in the first iteration ---*/
2743+
/*--- Table for Residual Values ---*/
2744+
PrintingToolbox::CTablePrinter ResidualTable(&std::cout);
2745+
ResidualTable.SetPrecision(config_container[ZONE_0]->GetOutput_Precision());
2746+
ResidualTable.SetAlign(PrintingToolbox::CTablePrinter::RIGHT);
27502747

2751-
const unsigned short fieldWidth = 15;
2752-
PrintingToolbox::CTablePrinter RMSTable(&std::cout);
2753-
RMSTable.SetPrecision(config_container[ZONE_0]->GetOutput_Precision());
2748+
std::cout << "\n-- Direct Residual Summary:" << std::endl;
27542749

2755-
/*--- The CTablePrinter requires two sweeps:
2756-
*--- 0. Add the colum names (addVals=0=false) plus CTablePrinter.PrintHeader()
2757-
*--- 1. Add the RMS-residual values (addVals=1=true) plus CTablePrinter.PrintFooter() ---*/
2758-
for (int addVals = 0; addVals < 2; addVals++) {
2750+
/*--- Setup table columns ---*/
2751+
ResidualTable.AddColumn("Residual", fieldWidth);
2752+
ResidualTable.AddColumn("log10(RMS)", fieldWidth);
2753+
ResidualTable.PrintHeader();
27592754

2760-
for (unsigned short iZone = 0; iZone < nZone; iZone++) {
2755+
/*--- Loop through each zone ---*/
2756+
for (unsigned short iZone = 0; iZone < nZone; iZone++) {
27612757

2762-
auto solvers = solver_container[iZone][INST_0][MESH_0];
2763-
auto configs = config_container[iZone];
2758+
auto solvers = solver_container[iZone][INST_0][MESH_0];
2759+
auto configs = config_container[iZone];
27642760

2765-
/*--- Note: the FEM-Flow solvers are availalbe for disc. adjoint runs only for SingleZone. ---*/
2766-
if (configs->GetFluidProblem() || configs->GetFEMSolver()) {
2761+
/*--- Print zone header ---*/
2762+
if (multizone) {
2763+
ResidualTable << "ZONE " + std::to_string(iZone) << "";
2764+
ResidualTable.PrintFooter();
2765+
}
27672766

2768-
for (unsigned short iVar = 0; iVar < solvers[FLOW_SOL]->GetnVar(); iVar++) {
2769-
if (!addVals)
2770-
RMSTable.AddColumn("rms_Flow" + iVar_iZone2string(iVar, iZone), fieldWidth);
2771-
else
2772-
RMSTable << log10(solvers[FLOW_SOL]->GetRes_RMS(iVar));
2773-
}
2767+
/*--- Fluid or FEM-Flow Problems ---*/
2768+
if (configs->GetFluidProblem() || configs->GetFEMSolver()) {
27742769

2775-
if (configs->GetKind_Turb_Model() != TURB_MODEL::NONE && !configs->GetFrozen_Visc_Disc()) {
2776-
for (unsigned short iVar = 0; iVar < solvers[TURB_SOL]->GetnVar(); iVar++) {
2777-
if (!addVals)
2778-
RMSTable.AddColumn("rms_Turb" + iVar_iZone2string(iVar, iZone), fieldWidth);
2779-
else
2780-
RMSTable << log10(solvers[TURB_SOL]->GetRes_RMS(iVar));
2781-
}
2782-
}
2770+
/*--- Flow residuals ---*/
2771+
for (unsigned short iVar = 0; iVar < solvers[FLOW_SOL]->GetnVar(); iVar++) {
2772+
std::string varName = "rms_Flow[" + std::to_string(iVar) + "]";
2773+
ResidualTable << varName << log10(solvers[FLOW_SOL]->GetRes_RMS(iVar));
2774+
}
27832775

2784-
if (configs->GetKind_Species_Model() != SPECIES_MODEL::NONE) {
2785-
for (unsigned short iVar = 0; iVar < solvers[SPECIES_SOL]->GetnVar(); iVar++) {
2786-
if (!addVals)
2787-
RMSTable.AddColumn("rms_Spec" + iVar_iZone2string(iVar, iZone), fieldWidth);
2788-
else
2789-
RMSTable << log10(solvers[SPECIES_SOL]->GetRes_RMS(iVar));
2790-
}
2776+
/*--- Turbulence residuals ---*/
2777+
if (configs->GetKind_Turb_Model() != TURB_MODEL::NONE && !configs->GetFrozen_Visc_Disc()) {
2778+
for (unsigned short iVar = 0; iVar < solvers[TURB_SOL]->GetnVar(); iVar++) {
2779+
std::string varName = "rms_Turb[" + std::to_string(iVar) + "]";
2780+
ResidualTable << varName << log10(solvers[TURB_SOL]->GetRes_RMS(iVar));
27912781
}
2782+
}
27922783

2793-
if (!multizone && configs->GetWeakly_Coupled_Heat()){
2794-
if (!addVals) RMSTable.AddColumn("rms_Heat" + iVar_iZone2string(0, iZone), fieldWidth);
2795-
else RMSTable << log10(solvers[HEAT_SOL]->GetRes_RMS(0));
2784+
/*--- Species residuals ---*/
2785+
if (configs->GetKind_Species_Model() != SPECIES_MODEL::NONE) {
2786+
for (unsigned short iVar = 0; iVar < solvers[SPECIES_SOL]->GetnVar(); iVar++) {
2787+
std::string varName = "rms_Spec[" + std::to_string(iVar) + "]";
2788+
ResidualTable << varName << log10(solvers[SPECIES_SOL]->GetRes_RMS(iVar));
27962789
}
2790+
}
27972791

2798-
if (configs->AddRadiation()) {
2799-
if (!addVals) RMSTable.AddColumn("rms_Rad" + iVar_iZone2string(0, iZone), fieldWidth);
2800-
else RMSTable << log10(solvers[RAD_SOL]->GetRes_RMS(0));
2801-
}
2792+
/*--- Heat residuals (weakly coupled) ---*/
2793+
if (!multizone && configs->GetWeakly_Coupled_Heat()) {
2794+
ResidualTable << "rms_Heat[0]" << log10(solvers[HEAT_SOL]->GetRes_RMS(0));
2795+
}
28022796

2797+
/*--- Radiation residuals ---*/
2798+
if (configs->AddRadiation()) {
2799+
ResidualTable << "rms_Rad[0]" << log10(solvers[RAD_SOL]->GetRes_RMS(0));
28032800
}
2804-
else if (configs->GetStructuralProblem()) {
28052801

2806-
if (configs->GetGeometricConditions() == STRUCT_DEFORMATION::LARGE){
2807-
if (!addVals) {
2808-
RMSTable.AddColumn("UTOL-A", fieldWidth);
2809-
RMSTable.AddColumn("RTOL-A", fieldWidth);
2810-
RMSTable.AddColumn("ETOL-A", fieldWidth);
2811-
}
2812-
else {
2813-
RMSTable << log10(solvers[FEA_SOL]->GetRes_FEM(0))
2814-
<< log10(solvers[FEA_SOL]->GetRes_FEM(1))
2815-
<< log10(solvers[FEA_SOL]->GetRes_FEM(2));
2816-
}
2817-
}
2818-
else{
2819-
if (!addVals) {
2820-
RMSTable.AddColumn("log10[RMS Ux]", fieldWidth);
2821-
RMSTable.AddColumn("log10[RMS Uy]", fieldWidth);
2822-
if (nDim == 3) RMSTable.AddColumn("log10[RMS Uz]", fieldWidth);
2823-
}
2824-
else {
2825-
RMSTable << log10(solvers[FEA_SOL]->GetRes_FEM(0))
2826-
<< log10(solvers[FEA_SOL]->GetRes_FEM(1));
2827-
if (nDim == 3) RMSTable << log10(solvers[FEA_SOL]->GetRes_FEM(2));
2828-
}
2829-
}
2802+
}
2803+
/*--- Structural Problems ---*/
2804+
else if (configs->GetStructuralProblem()) {
28302805

2806+
if (configs->GetGeometricConditions() == STRUCT_DEFORMATION::LARGE) {
2807+
ResidualTable << "UTOL-A" << log10(solvers[FEA_SOL]->GetRes_FEM(0));
2808+
ResidualTable << "RTOL-A" << log10(solvers[FEA_SOL]->GetRes_FEM(1));
2809+
ResidualTable << "ETOL-A" << log10(solvers[FEA_SOL]->GetRes_FEM(2));
28312810
}
2832-
else if (configs->GetHeatProblem()) {
2833-
2834-
if (!addVals) RMSTable.AddColumn("rms_Heat" + iVar_iZone2string(0, iZone), fieldWidth);
2835-
else RMSTable << log10(solvers[HEAT_SOL]->GetRes_RMS(0));
2836-
} else {
2837-
SU2_MPI::Error("Invalid KindSolver for CDiscAdj-MultiZone/SingleZone-Driver.", CURRENT_FUNCTION);
2811+
else {
2812+
ResidualTable << "RMS Ux" << log10(solvers[FEA_SOL]->GetRes_FEM(0));
2813+
ResidualTable << "RMS Uy" << log10(solvers[FEA_SOL]->GetRes_FEM(1));
2814+
if (nDim == 3) {
2815+
ResidualTable << "RMS Uz" << log10(solvers[FEA_SOL]->GetRes_FEM(2));
2816+
}
28382817
}
2839-
} // loop iZone
28402818

2841-
if (!addVals) RMSTable.PrintHeader();
2842-
else RMSTable.PrintFooter();
2819+
}
2820+
/*--- Heat Problems ---*/
2821+
else if (configs->GetHeatProblem()) {
2822+
2823+
ResidualTable << "rms_Heat[0]" << log10(solvers[HEAT_SOL]->GetRes_RMS(0));
28432824

2844-
} // for addVals
2825+
}
2826+
else {
2827+
SU2_MPI::Error("Invalid KindSolver for CDiscAdj-MultiZone/SingleZone-Driver.", CURRENT_FUNCTION);
2828+
}
2829+
2830+
/*--- Print zone footer ---*/
2831+
if (multizone) {
2832+
ResidualTable.PrintFooter();
2833+
}
2834+
2835+
}
2836+
2837+
/*--- Print final footer for single zone ---*/
2838+
if (!multizone) {
2839+
ResidualTable.PrintFooter();
2840+
}
28452841

2846-
cout << "\n-------------------------------------------------------------------------\n" << endl;
2842+
std::cout << "\n-------------------------------------------------------------------------\n" << std::endl;
28472843

28482844
}
28492845

0 commit comments

Comments
 (0)