Make primal residual for adjoint like normal screen output.#1371
Make primal residual for adjoint like normal screen output.#1371TobiKattmann merged 12 commits intodevelopfrom
Conversation
So far only for SingleZoneDriver. Using the PrintingToolbox. Multizone should be adapted as well. Prob it is best to use the normal output routines but this is just a first step.
pcarruscag
left a comment
There was a problem hiding this comment.
👍 I think with some tweaks it would be no worse code-wise and much better for functionality.
Essentially addressing review comments. Still, only SingleZoneDriver was changed.
Co-authored-by: Pedro Gomes <[email protected]>
Similar to the SingleZone version this also prints the direct residuals using the Table Printer. And now all residuals instead of just the first of each solver.
| config_container, iZone, INST_0); | ||
| AD::Push_TapePosition(); /// leave_zone | ||
| } | ||
| Print_DirectResidual(kind_recording); |
There was a problem hiding this comment.
I made that bit a function for Multizone just as there is for SingleZone. Using the same function for both is maybe possible without to much effort. But I did not do that for now
| /*--- Helper lambda func to return lenghty [iVar][iZone] string. ---*/ | ||
| auto iVar_iZone2string = [](unsigned short ivar, unsigned short izone) { | ||
| return "[" + std::to_string(ivar) + "][" + std::to_string(izone) + "]"; | ||
| }; |
There was a problem hiding this comment.
Here one would need to have the iZone part only for GetMultizoneProblem()
| case DISC_ADJ_INC_EULER: case DISC_ADJ_INC_NAVIER_STOKES: | ||
| cout << " Zone " << iZone << " (flow) - log10[U(0)] : " | ||
| << log10(solvers[FLOW_SOL]->GetRes_RMS(0)) << endl; | ||
| if (config_container[iZone]->AddRadiation()) { | ||
| for (unsigned short iZone = 0; iZone < nZone; iZone++) { | ||
|
|
||
| cout << " Zone " << iZone << " (radiation) - log10[Rad(0)] : " | ||
| << log10(solvers[RAD_SOL]->GetRes_RMS(0)) << endl; | ||
| } | ||
| break; | ||
| auto solvers = solver_container[iZone][INST_0][MESH_0]; | ||
| auto configs = config_container[iZone]; |
There was a problem hiding this comment.
I am not sure whether one can easily swap those containers for singlezone and Multizone on this level
There was a problem hiding this comment.
Well I guess this works out as is ...
| case DISC_ADJ_EULER: case DISC_ADJ_NAVIER_STOKES: | ||
| case DISC_ADJ_INC_EULER: case DISC_ADJ_INC_NAVIER_STOKES: | ||
| cout << " Zone " << iZone << " (flow) - log10[U(0)] : " | ||
| << log10(solvers[FLOW_SOL]->GetRes_RMS(0)) << endl; | ||
| if (config_container[iZone]->AddRadiation()) { | ||
| for (unsigned short iZone = 0; iZone < nZone; iZone++) { | ||
|
|
||
| cout << " Zone " << iZone << " (radiation) - log10[Rad(0)] : " | ||
| << log10(solvers[RAD_SOL]->GetRes_RMS(0)) << endl; |
There was a problem hiding this comment.
I am not sure why there is this separation of the laminar and turbulence cases, i.e. having the same stuff for flow and radiation twice. So did that together like in the singlezone
| if (rank == MASTER_NODE && kind_recording == RECORDING::SOLUTION_VARIABLES) { | ||
|
|
||
| auto solvers = solver_container[iZone][INST_0][MESH_0]; | ||
| const unsigned short fieldWidth = 15; |
There was a problem hiding this comment.
Unfortunately I had to increase to a min of 14 to fit e.g. rms_Flow[0][0] into the table. The fixed screen output size for the primal is currently 12... that is not ideal but better than before imo
Namely the Single and Multizone version are now consolidated in CDriver which has to use minor specific things to accomodate for both. The function is protected.
Co-authored-by: Pedro Gomes <[email protected]>
It might be double (only the screen output) for multizone for the secondaries.
And not in PrintDirectRes. This is consistent with the multizone driver.
| if (rank == MASTER_NODE) { | ||
| cout << "\n-------------------------------------------------------------------------\n"; | ||
| switch(kind_recording) { | ||
| case RECORDING::CLEAR_INDICES: cout << "Clearing the computational graph." << endl; break; | ||
| case RECORDING::MESH_COORDS: cout << "Storing computational graph wrt MESH COORDINATES." << endl; break; | ||
| case RECORDING::SOLUTION_VARIABLES: | ||
| cout << "Direct iteration to store the primal computational graph." << endl; | ||
| cout << "Compute residuals to check the convergence of the direct problem." << endl; break; | ||
| default: break; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
This is now consistent/similar with the handling in the CDiscAdjMultizoneDriver. This allows the early return in Print_DirectResiduals
| void CDriver::Print_DirectResidual(RECORDING kind_recording) { | ||
|
|
||
| if (!(rank == MASTER_NODE && kind_recording == RECORDING::SOLUTION_VARIABLES)) return; |
|
Thanks for the review and the helpful comments @pcarruscag . |
Hi all,
lately I was fixing restarts. Making sure the adjoint also has a correct primal restart is somewhat annoying due to the way the residuals are printed to screen
I want to change that to look like a normal screen output of all residuals. Here the old variant on top and the new below (field names need to be adapted to usual screen output)

The code as of today only changes this for single zone and does not use the usual output routines (and is a bit hacky). I want to add multizone and use the output routines instead of this handwritten PrintDirectResidual routine. I'll look into both
Let me know if there are reasons against this or any other comments
Related Work
The printing tool box of Tim
PR Checklist