Skip to content

Commit

Permalink
fieldAverage: Correct handling of resetOnOutput
Browse files Browse the repository at this point in the history
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1653
Thanks to Armin Wehrfritz for proposed fixes
  • Loading branch information
Henry authored and Henry committed May 5, 2015
1 parent e7d58ed commit e0b2369
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 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 |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -33,7 +33,7 @@ License

namespace Foam
{
defineTypeNameAndDebug(fieldAverage, 0);
defineTypeNameAndDebug(fieldAverage, 0);
}


Expand All @@ -50,6 +50,7 @@ void Foam::fieldAverage::resetFields()
obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
}
}

if (faItems_[i].prime2Mean())
{
if (obr_.found(faItems_[i].prime2MeanFieldName()))
Expand All @@ -67,7 +68,6 @@ void Foam::fieldAverage::initialize()

Info<< type() << " " << name_ << ":" << nl;


// Add mean fields to the field lists
forAll(faItems_, fieldI)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
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 |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e0b2369

Please sign in to comment.