Skip to content

Commit

Permalink
convergenceControl: Simplified convergence control for multi-region c…
Browse files Browse the repository at this point in the history
…ases

In order to add convergence control to multi-region cases it is no longer
necessary to provide a residualControl entry in all region, convergence
specification can be provided for any sub-set of the region for which particular
residual levels should be met.

The tutorials/multiRegion/CHT/circuitBoardCooling case now has valid convergence
criteria to demonstrate this change.
  • Loading branch information
Henry Weller committed Sep 6, 2023
1 parent d6caf68 commit 815f0b1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -88,10 +88,12 @@ Foam::convergenceControl::~convergenceControl()

bool Foam::convergenceControl::converged()
{
const convergenceData cd(criteriaSatisfied());

if
(
control_.time().timeIndex() != control_.time().startTimeIndex()
&& criteriaSatisfied()
&& cd.checked && cd.satisfied
)
{
Info<< nl << control_.algorithmName() << " solution converged in "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -62,6 +62,13 @@ public:
scalar absTol;
};

//- Convergence data structure
struct convergenceData
{
bool checked;
bool satisfied;
};


// Static Functions

Expand Down Expand Up @@ -151,7 +158,7 @@ public:
virtual bool hasResidualControls() const = 0;

//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() const = 0;
virtual convergenceData criteriaSatisfied() const = 0;

//- Flag to indicate whether convergence has been reached
bool converged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ bool Foam::singleRegionConvergenceControl::hasResidualControls() const
}


bool Foam::singleRegionConvergenceControl::criteriaSatisfied() const
Foam::convergenceControl::convergenceData
Foam::singleRegionConvergenceControl::criteriaSatisfied() const
{
if (!hasResidualControls())
{
return false;
return {false, false};
}

bool achieved = true;
bool checked = false; // ensure that some checks were actually performed
convergenceData cs{false, true};

if (control_.debug)
{
Expand All @@ -160,8 +160,7 @@ bool Foam::singleRegionConvergenceControl::criteriaSatisfied() const
forAll(fieldNames, i)
{
const word& fieldName = fieldNames[i];
const label fieldi =
residualControlIndex(fieldName, residualControl_);
const label fieldi = residualControlIndex(fieldName, residualControl_);
if (fieldi != -1)
{
scalar residual;
Expand All @@ -174,11 +173,11 @@ bool Foam::singleRegionConvergenceControl::criteriaSatisfied() const
residual
);

checked = true;
cs.checked = true;

bool absCheck = residual < residualControl_[fieldi].absTol;
const bool absCheck = residual < residualControl_[fieldi].absTol;

achieved = achieved && absCheck;
cs.satisfied = cs.satisfied && absCheck;

if (control_.debug)
{
Expand All @@ -190,7 +189,7 @@ bool Foam::singleRegionConvergenceControl::criteriaSatisfied() const
}
}

return checked && achieved;
return cs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public:
virtual bool hasResidualControls() const;

//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() const;
virtual convergenceData criteriaSatisfied() const;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ Foam::pimpleMultiRegionControl::~pimpleMultiRegionControl()

bool Foam::pimpleMultiRegionControl::hasResidualControls() const
{
bool result = true;
bool result = false;

forAll(pimpleControls_, i)
{
result = result && pimpleControls_[i].hasResidualControls();
result = result || pimpleControls_[i].hasResidualControls();
}

return result;
Expand All @@ -141,27 +141,34 @@ bool Foam::pimpleMultiRegionControl::hasResidualControls() const

bool Foam::pimpleMultiRegionControl::hasCorrResidualControls() const
{
bool result = true;
bool result = false;

forAll(pimpleControls_, i)
{
result = result && pimpleControls_[i].hasCorrResidualControls();
result = result || pimpleControls_[i].hasCorrResidualControls();
}

return result;
}


bool Foam::pimpleMultiRegionControl::criteriaSatisfied() const
Foam::convergenceControl::convergenceData
Foam::pimpleMultiRegionControl::criteriaSatisfied() const
{
bool result = true;
convergenceData cs{false, true};

forAll(pimpleControls_, i)
{
result = pimpleControls_[i].criteriaSatisfied() && result;
const convergenceData csi(pimpleControls_[i].criteriaSatisfied());

cs.checked = csi.checked || cs.checked;
if (csi.checked)
{
cs.satisfied = csi.satisfied && cs.satisfied;
}
}

return result;
return cs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public:
virtual bool hasCorrResidualControls() const;

//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() const;
virtual convergenceData criteriaSatisfied() const;

//- Return true if all correction convergence checks are satisfied
virtual bool corrCriteriaSatisfied() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ solvers
PIMPLE
{
nNonOrthogonalCorrectors 0;

residualControl
{
e 1e-4;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ startTime 0;

stopAt endTime;

endTime 2500;
endTime 5000;

deltaT 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ solvers

PIMPLE
{
momentumPredictor no;
momentumPredictor yes;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;

residualControl
{
p_rgh 1e-3;
U 1e-4;
h 1e-4;

Expand Down

0 comments on commit 815f0b1

Please sign in to comment.