fieldAverage: Correct handling of resetOnOutput

Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1653
Thanks to Armin Wehrfritz for proposed fixes
This commit is contained in:
Henry
2015-04-09 16:05:33 +01:00
parent 51087ad0df
commit 5dad962f44
2 changed files with 18 additions and 10 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -33,7 +33,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(fieldAverage, 0);
defineTypeNameAndDebug(fieldAverage, 0);
}
@ -50,6 +50,7 @@ void Foam::fieldAverage::resetFields()
obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
}
}
if (faItems_[i].prime2Mean())
{
if (obr_.found(faItems_[i].prime2MeanFieldName()))
@ -67,7 +68,6 @@ void Foam::fieldAverage::initialize()
Info<< type() << " " << name_ << ":" << nl;
// Add mean fields to the field lists
forAll(faItems_, fieldI)
{
@ -195,7 +195,7 @@ void Foam::fieldAverage::readAveragingProperties()
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
if (resetOnRestart_)
if (resetOnRestart_ || resetOnOutput_)
{
Info<< " Starting averaging at time " << obr_.time().timeName()
<< nl;
@ -348,10 +348,13 @@ void Foam::fieldAverage::write()
Info<< " Restarting averaging at time " << obr_.time().timeName()
<< nl << endl;
initialize();
totalIter_.clear();
totalIter_.setSize(faItems_.size(), 1);
// ensure first averaging works unconditionally
prevTimeIndex_ = -1;
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
initialize();
}
Info<< endl;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -66,7 +66,9 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
meanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
IOobject::READ_IF_PRESENT,
resetOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
1*baseField
@ -124,6 +126,7 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
const Type1& meanField = obr_.lookupObject<Type1>(meanFieldName);
// Store on registry
obr_.store
(
new Type2
@ -133,7 +136,9 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
prime2MeanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
IOobject::READ_IF_PRESENT,
resetOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
sqr(baseField) - sqr(meanField)