Skip to content

Commit a884a44

Browse files
author
Henry Weller
committed
chtMultiRegionFoam: Added support for residual convergence controls
Patch contributed by Tobias Holzmann Resolves patch request https://bugs.openfoam.org/view.php?id=2524
1 parent d26c6c3 commit a884a44

16 files changed

Lines changed: 239 additions & 20 deletions
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Residual control used?
2+
bool resControlUsed = false;
3+
int nFluidControlled = fluidRegions.size();
4+
int nSolidControlled = solidRegions.size();
5+
6+
// Check wheater there is a single regions that uses residual control
7+
forAll(fluidRegions, i)
8+
{
9+
if (residualControlUsedFluid[i])
10+
{
11+
resControlUsed = true;
12+
}
13+
}
14+
15+
forAll(solidRegions, i)
16+
{
17+
if(residualControlUsedSolid[i])
18+
{
19+
resControlUsed = true;
20+
}
21+
}
22+
23+
if (resControlUsed)
24+
{
25+
int nFluidConv = 0;
26+
int nSolidConv = 0;
27+
28+
// Sum of all converged regions (Note: if no residual control is used
29+
// the residualReached* flag is already set to true)
30+
forAll(fluidRegions, i)
31+
{
32+
if (residualReachedFluid[i])
33+
{
34+
nFluidConv++;
35+
}
36+
}
37+
38+
forAll(solidRegions, i)
39+
{
40+
if (residualReachedSolid[i])
41+
{
42+
nSolidConv++;
43+
}
44+
}
45+
46+
if (nFluidConv == nFluidControlled && nSolidConv == nSolidControlled)
47+
{
48+
// Activate flag to go to the 'Final' loop using the 'Final'
49+
// relaxation factors
50+
allRegionsConverged = true;
51+
}
52+
}
53+
54+
if (finalIter && resControlUsed && !allRegionsConverged)
55+
{
56+
Info<< "\nRegions not converged after " << nOuterCorr
57+
<< " outer correctors" << endl;
58+
}
59+
else if (finalIter && resControlUsed && allRegionsConverged)
60+
{
61+
Info<< "\nRegions converged after " << oCorr
62+
<< " outer correctors" << endl;
63+
64+
// Leave PIMPLE loop
65+
break;
66+
}

applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionFoam.C

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration |
5-
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -86,19 +86,28 @@ int main(int argc, char *argv[])
8686
}
8787
}
8888

89+
bool allRegionsConverged = false;
90+
bool finalIter = false;
8991

9092
// --- PIMPLE loop
9193
for (int oCorr=0; oCorr<nOuterCorr; oCorr++)
9294
{
93-
bool finalIter = oCorr == nOuterCorr-1;
95+
Info<< "Pimple iteration " << oCorr << "\n";
96+
97+
if (oCorr == nOuterCorr-1 || allRegionsConverged)
98+
{
99+
finalIter = true;
100+
}
94101

95102
forAll(fluidRegions, i)
96103
{
97104
Info<< "\nSolving for fluid region "
98105
<< fluidRegions[i].name() << endl;
99106
#include "setRegionFluidFields.H"
100107
#include "readFluidMultiRegionPIMPLEControls.H"
108+
#include "readFluidMultiRegionResidualControls.H"
101109
#include "solveFluid.H"
110+
#include "residualControlsFluid.H"
102111
}
103112

104113
forAll(solidRegions, i)
@@ -107,9 +116,12 @@ int main(int argc, char *argv[])
107116
<< solidRegions[i].name() << endl;
108117
#include "setRegionSolidFields.H"
109118
#include "readSolidMultiRegionPIMPLEControls.H"
119+
#include "readSolidMultiRegionResidualControls.H"
110120
#include "solveSolid.H"
121+
#include "residualControlsSolid.H"
111122
}
112123

124+
#include "checkResidualControls.H"
113125
}
114126

115127
runTime.write();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#include "createFluidFields.H"
22
#include "createSolidFields.H"
3+
4+
SolverPerformance<vector> solvPerfU;
5+
SolverPerformance<scalar> solvPerfE;
6+
SolverPerformance<scalar> solvPerfh;
7+
SolverPerformance<scalar> solvPerfp_rgh;

applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/EEqn.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
fvOptions.constrain(EEqn);
2828

29-
EEqn.solve(mesh.solver(he.select(finalIter)));
29+
solvPerfE = EEqn.solve(mesh.solver(he.select(finalIter)));
3030

3131
fvOptions.correct(he);
3232

applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/UEqn.H

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818

1919
if (momentumPredictor)
2020
{
21-
solve
22-
(
23-
UEqn
24-
==
25-
fvc::reconstruct
21+
solvPerfU =
22+
solve
2623
(
24+
UEqn
25+
==
26+
fvc::reconstruct
2727
(
28-
- ghf*fvc::snGrad(rho)
29-
- fvc::snGrad(p_rgh)
30-
)*mesh.magSf()
31-
),
32-
mesh.solver(U.select(finalIter))
33-
);
28+
(
29+
- ghf*fvc::snGrad(rho)
30+
- fvc::snGrad(p_rgh)
31+
)*mesh.magSf()
32+
),
33+
mesh.solver(U.select(finalIter))
34+
);
3435

3536
fvOptions.correct(U);
3637
K = 0.5*magSqr(U);

applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PtrList<volScalarField> dpdtFluid(fluidRegions.size());
1515

1616
List<scalar> initialMassFluid(fluidRegions.size());
1717
List<bool> frozenFlowFluid(fluidRegions.size(), false);
18+
List<bool> residualReachedFluid(fluidRegions.size(), true);
19+
List<bool> residualControlUsedFluid(fluidRegions.size(), false);
1820

1921
PtrList<IOMRFZoneList> MRFfluid(fluidRegions.size());
2022
PtrList<fv::options> fluidFvOptions(fluidRegions.size());

applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
- fvm::laplacian(rhorAUf, p_rgh)
4646
);
4747

48-
p_rghEqn.solve
48+
solvPerfp_rgh = p_rghEqn.solve
4949
(
5050
mesh.solver
5151
(
5252
p_rgh.select
5353
(
5454
(
55-
oCorr == nOuterCorr-1
56-
&& corr == nCorr-1
57-
&& nonOrth == nNonOrthCorr
55+
oCorr == nOuterCorr-1
56+
&& corr == nCorr-1
57+
&& nonOrth == nNonOrthCorr
5858
)
5959
)
6060
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const dictionary& residualControl =
2+
mesh.solutionDict().subDict("PIMPLE").subOrEmptyDict("residualControl");
3+
4+
scalar UTol = -1.;
5+
scalar ETol = -1.;
6+
scalar p_rghTol = -1.;
7+
8+
if (!residualControl.empty())
9+
{
10+
if (!residualControl.subOrEmptyDict("U").empty())
11+
{
12+
UTol = readScalar(residualControl.subDict("U").lookup("tolerance"));
13+
}
14+
15+
if (!residualControl.subOrEmptyDict("p_rgh").empty())
16+
{
17+
p_rghTol =
18+
readScalar
19+
(
20+
residualControl.subDict("p_rgh").lookup("tolerance")
21+
);
22+
}
23+
24+
if (!residualControl.subOrEmptyDict("h").empty())
25+
{
26+
ETol = readScalar(residualControl.subDict("h").lookup("tolerance"));
27+
}
28+
29+
// Residual control used?
30+
if (UTol != -1 || ETol != -1 || p_rghTol != -1)
31+
{
32+
residualControlUsed = true;
33+
resReachedFluid = false;
34+
}
35+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Residual control used
2+
if (residualControlUsed)
3+
{
4+
bool UConv = false;
5+
bool p_rghConv = false;
6+
bool EConv = false;
7+
8+
// Check which field is not used for control
9+
{
10+
if (UTol == -1)
11+
{
12+
UConv = true;
13+
}
14+
15+
if (p_rghTol == -1)
16+
{
17+
p_rghConv = true;
18+
}
19+
20+
if (ETol == -1)
21+
{
22+
EConv = true;
23+
}
24+
}
25+
26+
// Get the last initial residual of the solvers
27+
if (momentumPredictor && !UConv)
28+
{
29+
if (UTol > cmptMax(solvPerfU.initialResidual()))
30+
{
31+
UConv = true;
32+
}
33+
}
34+
35+
if (!p_rghConv)
36+
{
37+
if (p_rghTol > solvPerfp_rgh.initialResidual())
38+
{
39+
p_rghConv = true;
40+
}
41+
}
42+
43+
if (!EConv)
44+
{
45+
if (ETol > solvPerfE.initialResidual())
46+
{
47+
EConv = true;
48+
}
49+
}
50+
51+
// Check if each field is converged
52+
if (UConv && p_rghConv && EConv)
53+
{
54+
resReachedFluid = true;
55+
}
56+
}

applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/setRegionFluidFields.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333
);
3434

3535
const bool frozenFlow = frozenFlowFluid[i];
36+
37+
bool& resReachedFluid = residualReachedFluid[i];
38+
bool& residualControlUsed = residualControlUsedFluid[i];

0 commit comments

Comments
 (0)