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

View File

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