Skip to content

Commit 376843f

Browse files
authored
Changed how the primalResTol is calculated (#587)
* Changed how primalResTol is computed. * Fixed tests.
1 parent 561f127 commit 376843f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+178
-203
lines changed

dafoam/pyDAFoam.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ def __init__(self):
704704
}
705705

706706
## number of minimal primal iterations. The primal has to run this many iterations, even the primal residual
707-
## has reduced below the tolerance. The default is a negative value (always satisfied).
708-
self.primalMinIters = -1
707+
## has reduced below the tolerance. The default is 1: the primal has to run for at least one iteration
708+
self.primalMinIters = 1
709709

710710
## tensorflow related functions
711711
self.tensorflow = {

src/adjoint/DAModel/DATurbulenceModel/DASpalartAllmaras.C

+2-5
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,8 @@ void DASpalartAllmaras::calcResiduals(const dictionary& options)
454454
// get the solver performance info such as initial
455455
// and final residuals
456456
SolverPerformance<scalar> solverNuTilda = solve(nuTildaEqn);
457-
if (printToScreen)
458-
{
459-
Info << "nuTilda Initial residual: " << solverNuTilda.initialResidual() << endl
460-
<< " Final residual: " << solverNuTilda.finalResidual() << endl;
461-
}
457+
458+
DAUtility::primalResidualControl(solverNuTilda, printToScreen, "nuTilda");
462459

463460
DAUtility::boundVar(allOptions_, nuTilda_, printToScreen);
464461
nuTilda_.correctBoundaryConditions();

src/adjoint/DAModel/DATurbulenceModel/DASpalartAllmarasFv3.C

+1-5
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,7 @@ void DASpalartAllmarasFv3::calcResiduals(const dictionary& options)
479479
// get the solver performance info such as initial
480480
// and final residuals
481481
SolverPerformance<scalar> solverNuTilda = solve(nuTildaEqn);
482-
if (printToScreen)
483-
{
484-
Info << "nuTilda Initial residual: " << solverNuTilda.initialResidual() << endl
485-
<< " Final residual: " << solverNuTilda.finalResidual() << endl;
486-
}
482+
DAUtility::primalResidualControl(solverNuTilda, printToScreen, "nuTilda");
487483

488484
DAUtility::boundVar(allOptions_, nuTilda_, printToScreen);
489485
nuTilda_.correctBoundaryConditions();

src/adjoint/DAModel/DATurbulenceModel/DASpalartAllmarasFv3FieldInversion.C

+1-5
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,7 @@ void DASpalartAllmarasFv3FieldInversion::calcResiduals(const dictionary& options
465465
// get the solver performance info such as initial
466466
// and final residuals
467467
SolverPerformance<scalar> solverNuTilda = solve(nuTildaEqn);
468-
if (printToScreen)
469-
{
470-
Info << "nuTilda Initial residual: " << solverNuTilda.initialResidual() << endl
471-
<< " Final residual: " << solverNuTilda.finalResidual() << endl;
472-
}
468+
DAUtility::primalResidualControl(solverNuTilda, printToScreen, "nuTilda");
473469

474470
DAUtility::boundVar(allOptions_, nuTilda_, printToScreen);
475471
nuTilda_.correctBoundaryConditions();

src/adjoint/DAModel/DATurbulenceModel/DAkEpsilon.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,7 @@ void DAkEpsilon::calcResiduals(const dictionary& options)
572572
// get the solver performance info such as initial
573573
// and final residuals
574574
SolverPerformance<scalar> solverEpsilon = solve(epsEqn);
575-
if (printToScreen)
576-
{
577-
Info << "epsilon Initial residual: " << solverEpsilon.initialResidual() << endl
578-
<< " Final residual: " << solverEpsilon.finalResidual() << endl;
579-
}
575+
DAUtility::primalResidualControl(solverEpsilon, printToScreen, "epsilon");
580576

581577
DAUtility::boundVar(allOptions_, epsilon_, printToScreen);
582578
}
@@ -610,11 +606,7 @@ void DAkEpsilon::calcResiduals(const dictionary& options)
610606
// get the solver performance info such as initial
611607
// and final residuals
612608
SolverPerformance<scalar> solverK = solve(kEqn);
613-
if (printToScreen)
614-
{
615-
Info << "k Initial residual: " << solverK.initialResidual() << endl
616-
<< " Final residual: " << solverK.finalResidual() << endl;
617-
}
609+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
618610

619611
DAUtility::boundVar(allOptions_, k_, printToScreen);
620612

src/adjoint/DAModel/DATurbulenceModel/DAkOmega.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,7 @@ void DAkOmega::calcResiduals(const dictionary& options)
577577
// get the solver performance info such as initial
578578
// and final residuals
579579
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
580-
if (printToScreen)
581-
{
582-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
583-
<< " Final residual: " << solverOmega.finalResidual() << endl;
584-
}
580+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
585581

586582
DAUtility::boundVar(allOptions_, omega_, printToScreen);
587583
}
@@ -614,11 +610,7 @@ void DAkOmega::calcResiduals(const dictionary& options)
614610
// get the solver performance info such as initial
615611
// and final residuals
616612
SolverPerformance<scalar> solverK = solve(kEqn);
617-
if (printToScreen)
618-
{
619-
Info << "k Initial residual: " << solverK.initialResidual() << endl
620-
<< " Final residual: " << solverK.finalResidual() << endl;
621-
}
613+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
622614

623615
DAUtility::boundVar(allOptions_, k_, printToScreen);
624616

src/adjoint/DAModel/DATurbulenceModel/DAkOmegaFieldInversionOmega.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,7 @@ void DAkOmegaFieldInversionOmega::calcResiduals(const dictionary& options)
581581
// get the solver performance info such as initial
582582
// and final residuals
583583
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
584-
if (printToScreen)
585-
{
586-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
587-
<< " Final residual: " << solverOmega.finalResidual() << endl;
588-
}
584+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
589585

590586
DAUtility::boundVar(allOptions_, omega_, printToScreen);
591587
}
@@ -618,11 +614,7 @@ void DAkOmegaFieldInversionOmega::calcResiduals(const dictionary& options)
618614
// get the solver performance info such as initial
619615
// and final residuals
620616
SolverPerformance<scalar> solverK = solve(kEqn);
621-
if (printToScreen)
622-
{
623-
Info << "k Initial residual: " << solverK.initialResidual() << endl
624-
<< " Final residual: " << solverK.finalResidual() << endl;
625-
}
617+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
626618

627619
DAUtility::boundVar(allOptions_, k_, printToScreen);
628620

src/adjoint/DAModel/DATurbulenceModel/DAkOmegaSST.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,7 @@ void DAkOmegaSST::calcResiduals(const dictionary& options)
741741
// get the solver performance info such as initial
742742
// and final residuals
743743
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
744-
if (printToScreen)
745-
{
746-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
747-
<< " Final residual: " << solverOmega.finalResidual() << endl;
748-
}
744+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
749745

750746
DAUtility::boundVar(allOptions_, omega_, printToScreen);
751747
}
@@ -782,11 +778,7 @@ void DAkOmegaSST::calcResiduals(const dictionary& options)
782778
// get the solver performance info such as initial
783779
// and final residuals
784780
SolverPerformance<scalar> solverK = solve(kEqn);
785-
if (printToScreen)
786-
{
787-
Info << "k Initial residual: " << solverK.initialResidual() << endl
788-
<< " Final residual: " << solverK.finalResidual() << endl;
789-
}
781+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
790782

791783
DAUtility::boundVar(allOptions_, k_, printToScreen);
792784

src/adjoint/DAModel/DATurbulenceModel/DAkOmegaSSTFIML.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,7 @@ void DAkOmegaSSTFIML::calcResiduals(const dictionary& options)
10471047
// get the solver performance info such as initial
10481048
// and final residuals
10491049
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
1050-
if (printToScreen)
1051-
{
1052-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
1053-
<< " Final residual: " << solverOmega.finalResidual() << endl;
1054-
}
1050+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
10551051

10561052
DAUtility::boundVar(allOptions_, omega_, printToScreen);
10571053
}
@@ -1088,11 +1084,7 @@ void DAkOmegaSSTFIML::calcResiduals(const dictionary& options)
10881084
// get the solver performance info such as initial
10891085
// and final residuals
10901086
SolverPerformance<scalar> solverK = solve(kEqn);
1091-
if (printToScreen)
1092-
{
1093-
Info << "k Initial residual: " << solverK.initialResidual() << endl
1094-
<< " Final residual: " << solverK.finalResidual() << endl;
1095-
}
1087+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
10961088

10971089
DAUtility::boundVar(allOptions_, k_, printToScreen);
10981090

src/adjoint/DAModel/DATurbulenceModel/DAkOmegaSSTFieldInversion.C

+2-10
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,7 @@ void DAkOmegaSSTFieldInversion::calcResiduals(const dictionary& options)
792792
// get the solver performance info such as initial
793793
// and final residuals
794794
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
795-
if (printToScreen)
796-
{
797-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
798-
<< " Final residual: " << solverOmega.finalResidual() << endl;
799-
}
795+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
800796

801797
DAUtility::boundVar(allOptions_, omega_, printToScreen);
802798
}
@@ -833,11 +829,7 @@ void DAkOmegaSSTFieldInversion::calcResiduals(const dictionary& options)
833829
// get the solver performance info such as initial
834830
// and final residuals
835831
SolverPerformance<scalar> solverK = solve(kEqn);
836-
if (printToScreen)
837-
{
838-
Info << "k Initial residual: " << solverK.initialResidual() << endl
839-
<< " Final residual: " << solverK.finalResidual() << endl;
840-
}
832+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
841833

842834
DAUtility::boundVar(allOptions_, k_, printToScreen);
843835

src/adjoint/DAModel/DATurbulenceModel/DAkOmegaSSTLM.C

+4-20
Original file line numberDiff line numberDiff line change
@@ -1105,11 +1105,7 @@ void DAkOmegaSSTLM::calcResiduals(const dictionary& options)
11051105
// get the solver performance info such as initial
11061106
// and final residuals
11071107
SolverPerformance<scalar> solverOmega = solve(omegaEqn);
1108-
if (printToScreen)
1109-
{
1110-
Info << "omega Initial residual: " << solverOmega.initialResidual() << endl
1111-
<< " Final residual: " << solverOmega.finalResidual() << endl;
1112-
}
1108+
DAUtility::primalResidualControl(solverOmega, printToScreen, "omega");
11131109

11141110
DAUtility::boundVar(allOptions_, omega_, printToScreen);
11151111
}
@@ -1146,11 +1142,7 @@ void DAkOmegaSSTLM::calcResiduals(const dictionary& options)
11461142
// get the solver performance info such as initial
11471143
// and final residuals
11481144
SolverPerformance<scalar> solverK = solve(kEqn);
1149-
if (printToScreen)
1150-
{
1151-
Info << "k Initial residual: " << solverK.initialResidual() << endl
1152-
<< " Final residual: " << solverK.finalResidual() << endl;
1153-
}
1145+
DAUtility::primalResidualControl(solverK, printToScreen, "k");
11541146

11551147
DAUtility::boundVar(allOptions_, k_, printToScreen);
11561148

@@ -1207,11 +1199,7 @@ void DAkOmegaSSTLM::calcResiduals(const dictionary& options)
12071199
// get the solver performance info such as initial
12081200
// and final residuals
12091201
SolverPerformance<scalar> solverReThetat = solve(ReThetatEqn);
1210-
if (printToScreen)
1211-
{
1212-
Info << "ReThetat Initial residual: " << solverReThetat.initialResidual() << endl
1213-
<< " Final residual: " << solverReThetat.finalResidual() << endl;
1214-
}
1202+
DAUtility::primalResidualControl(solverReThetat, printToScreen, "ReThetat");
12151203

12161204
DAUtility::boundVar(allOptions_, ReThetat_, printToScreen);
12171205
}
@@ -1259,11 +1247,7 @@ void DAkOmegaSSTLM::calcResiduals(const dictionary& options)
12591247
// get the solver performance info such as initial
12601248
// and final residuals
12611249
SolverPerformance<scalar> solverGammaInt = solve(gammaIntEqn);
1262-
if (printToScreen)
1263-
{
1264-
Info << "gammaInt Initial residual: " << solverGammaInt.initialResidual() << endl
1265-
<< " Final residual: " << solverGammaInt.finalResidual() << endl;
1266-
}
1250+
DAUtility::primalResidualControl(solverGammaInt, printToScreen, "gammaInt");
12671251

12681252
DAUtility::boundVar(allOptions_, gammaInt_, printToScreen);
12691253

src/adjoint/DASolver/DAHeatTransferFoam/DAHeatTransferFoam.C

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ label DAHeatTransferFoam::solvePrimal(
8282
return 1;
8383
}
8484

85-
primalMinRes_ = 1e10;
8685
label printInterval = daOptionPtr_->getOption<label>("printIntervalUnsteady");
8786
label printToScreen = 0;
8887
// main loop
8988
while (this->loop(runTime)) // using simple.loop() will have seg fault in parallel
9089
{
90+
DAUtility::primalMaxInitRes_ = -1e16;
91+
9192
printToScreen = this->isPrintTime(runTime, printInterval);
9293

9394
if (printToScreen)
@@ -102,7 +103,7 @@ label DAHeatTransferFoam::solvePrimal(
102103
// get the solver performance info such as initial
103104
// and final residuals
104105
SolverPerformance<scalar> solverT = TEqn.solve();
105-
this->primalResidualControl<scalar>(solverT, printToScreen, printInterval, "T");
106+
DAUtility::primalResidualControl(solverT, printToScreen, "T");
106107

107108
if (this->validateStates())
108109
{

src/adjoint/DASolver/DALaplacianFoam/DALaplacianFoam.C

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ label DALaplacianFoam::solvePrimal(
145145
// right after mesh.movePoints() calls.
146146
//mesh.moving(false);
147147

148-
primalMinRes_ = 1e10;
149148
label printInterval = daOptionPtr_->getOption<label>("printIntervalUnsteady");
150149
label printToScreen = 0;
151150
label timeInstanceI = 0;
152151

153152
// main loop
154153
while (this->loop(runTime)) // using simple.loop() will have seg fault in parallel
155154
{
155+
DAUtility::primalMaxInitRes_ = -1e16;
156+
156157
printToScreen = this->isPrintTime(runTime, printInterval);
157158

158159
if (printToScreen)
@@ -167,7 +168,7 @@ label DALaplacianFoam::solvePrimal(
167168
// get the solver performance info such as initial
168169
// and final residuals
169170
SolverPerformance<scalar> solverT = TEqn.solve();
170-
this->primalResidualControl<scalar>(solverT, printToScreen, printInterval, "T");
171+
DAUtility::primalResidualControl(solverT, printToScreen, "T");
171172

172173
if (this->validateStates())
173174
{

src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C

-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ label DAPimpleFoam::solvePrimal(
154154
// right after mesh.movePoints() calls.
155155
//mesh.moving(false);
156156

157-
primalMinRes_ = 1e10;
158157
label printInterval = daOptionPtr_->getOption<label>("printIntervalUnsteady");
159158
label printToScreen = 0;
160159
label timeInstanceI = 0;

src/adjoint/DASolver/DAPimpleFoam/UEqnPimple.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (pimple.momentumPredictor())
2222
// and final residuals
2323
SolverPerformance<vector> solverU = solve(UEqn == -fvc::grad(p));
2424

25-
this->primalResidualControl<vector>(solverU, pimplePrintToScreen, printInterval, "U");
25+
DAUtility::primalResidualControl(solverU, pimplePrintToScreen, "U");
2626
}
2727

2828
// bound U

src/adjoint/DASolver/DAPimpleFoam/pEqnPimple.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ while (pimple.correctNonOrthogonal())
5252
// and final residuals
5353
SolverPerformance<scalar> solverP = pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())));
5454

55-
this->primalResidualControl<scalar>(solverP, pimplePrintToScreen, printInterval, "p");
55+
DAUtility::primalResidualControl(solverP, pimplePrintToScreen, "p");
5656

5757
if (pimple.finalNonOrthogonalIter())
5858
{

src/adjoint/DASolver/DAPisoFoam/DAPisoFoam.C

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ label DAPisoFoam::solvePrimal(
169169
// right after mesh.movePoints() calls.
170170
//mesh.moving(false);
171171

172-
primalMinRes_ = 1e10;
173172
label printInterval = daOptionPtr_->getOption<label>("printIntervalUnsteady");
174173
label printToScreen = 0;
175174
label timeInstanceI = 0;
176175

177176
// main loop
178177
while (this->loop(runTime)) // using simple.loop() will have seg fault in parallel
179178
{
179+
DAUtility::primalMaxInitRes_ = -1e16;
180+
180181
printToScreen = this->isPrintTime(runTime, printInterval);
181182

182183
if (printToScreen)

src/adjoint/DASolver/DAPisoFoam/UEqnPiso.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (piso.momentumPredictor())
2020
// and final residuals
2121
SolverPerformance<vector> solverU = solve(UEqn == -fvc::grad(p));
2222

23-
this->primalResidualControl<vector>(solverU, printToScreen, printInterval, "U");
23+
DAUtility::primalResidualControl(solverU, printToScreen, "U");
2424
}
2525

2626
// bound U

src/adjoint/DASolver/DAPisoFoam/pEqnPiso.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ while (piso.correctNonOrthogonal())
2121
// and final residuals
2222
SolverPerformance<scalar> solverP = pEqn.solve(mesh.solver(p.select(piso.finalInnerIter())));
2323

24-
this->primalResidualControl<scalar>(solverP, printToScreen, printInterval, "p");
24+
DAUtility::primalResidualControl(solverP, printToScreen, "p");
2525

2626
if (piso.finalNonOrthogonalIter())
2727
{

src/adjoint/DASolver/DARhoSimpleCFoam/DARhoSimpleCFoam.C

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ label DARhoSimpleCFoam::solvePrimal(
132132
// check if the parameters are set in the Python layer
133133
daRegressionPtr_->validate();
134134

135-
primalMinRes_ = 1e10;
135+
136136
label printInterval = daOptionPtr_->getOption<label>("printInterval");
137137
label printToScreen = 0;
138138
label regModelFail = 0;
139139
while (this->loop(runTime)) // using simple.loop() will have seg fault in parallel
140140
{
141+
DAUtility::primalMaxInitRes_ = -1e16;
141142

142143
printToScreen = this->isPrintTime(runTime, printInterval);
143144

src/adjoint/DASolver/DARhoSimpleCFoam/EEqnRhoSimpleC.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// and final residuals
1515
SolverPerformance<scalar> solverE = EEqn.solve();
1616

17-
this->primalResidualControl<scalar>(solverE, printToScreen, printInterval, "he");
17+
DAUtility::primalResidualControl(solverE, printToScreen, "he");
1818

1919
// bound he
2020
DAUtility::boundVar(allOptions, he, printToScreen);

0 commit comments

Comments
 (0)