solutionControl: Fix repeat-write when converged at a write time

Solution controls now detect when convergence occurs at a write time and
avoid writing the final directory twice. This also resolves the issue
whereby a purgeWrite setting would remove an extra directory.

This resolves bug report https://bugs.openfoam.org/view.php?id=2904
This commit is contained in:
Will Bainbridge
2018-04-25 12:35:34 +01:00
parent 484c16a5da
commit b7d5bc98de
7 changed files with 41 additions and 32 deletions

View File

@ -556,7 +556,14 @@ bool Foam::Time::writeObject
// Does the writeTime trigger purging? // Does the writeTime trigger purging?
if (writeTime_ && purgeWrite_) if (writeTime_ && purgeWrite_)
{ {
previousWriteTimes_.push(timeName()); if
(
previousWriteTimes_.size() == 0
|| previousWriteTimes_.top() != timeName()
)
{
previousWriteTimes_.push(timeName());
}
while (previousWriteTimes_.size() > purgeWrite_) while (previousWriteTimes_.size() > purgeWrite_)
{ {

View File

@ -96,4 +96,27 @@ bool Foam::convergenceControl::converged()
} }
bool Foam::convergenceControl::endIfConverged(Time& time)
{
if (converged())
{
if (time.writeTime())
{
time.stopAt(Time::saNoWriteNow);
time.setEndTime(time);
}
else
{
time.writeAndEnd();
}
return true;
}
else
{
return false;
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -154,6 +154,9 @@ public:
//- Flag to indicate whether convergance has been reached //- Flag to indicate whether convergance has been reached
bool converged(); bool converged();
//- End the run if convergance has been reached
bool endIfConverged(Time& time);
}; };

View File

@ -103,11 +103,7 @@ bool Foam::pimpleControl::run(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
storePrevIterFields(); storePrevIterFields();
} }
@ -120,11 +116,7 @@ bool Foam::pimpleControl::loop(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
storePrevIterFields(); storePrevIterFields();
} }

View File

@ -302,11 +302,7 @@ bool Foam::pimpleMultiRegionControl::run(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
forAll(pimpleControls_, i) forAll(pimpleControls_, i)
{ {
@ -326,11 +322,7 @@ bool Foam::pimpleMultiRegionControl::loop(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
forAll(pimpleControls_, i) forAll(pimpleControls_, i)
{ {

View File

@ -66,11 +66,7 @@ bool Foam::simpleControl::run(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
storePrevIterFields(); storePrevIterFields();
} }
@ -83,11 +79,7 @@ bool Foam::simpleControl::loop(Time& time)
{ {
read(); read();
if (converged()) if (!endIfConverged(time))
{
time.writeAndEnd();
}
else
{ {
storePrevIterFields(); storePrevIterFields();
} }

View File

@ -81,7 +81,7 @@ public:
// Constructors // Constructors
//- Construct from the time, a the name of the algorithm and a registry //- Construct from the time, the name of the algorithm and a registry
solutionControl solutionControl
( (
const objectRegistry& registry, const objectRegistry& registry,