Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldAverageItem.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Henry Weller
committed
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_MEAN
(
"Mean"
);
Henry Weller
committed
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_PRIME2MEAN
(
"Prime2Mean"
);
Henry Weller
committed
<
Foam::functionObjects::fieldAverageItem::baseType
>
Foam::functionObjects::fieldAverageItem::baseTypeNames_
{ baseType::ITER, "iteration" },
{ baseType::TIME, "time" },
const Foam::Enum
<
Foam::functionObjects::fieldAverageItem::windowType
>
Foam::functionObjects::fieldAverageItem::windowTypeNames_
{ windowType::NONE, "none" },
{ windowType::APPROXIMATE, "approximate" },
{ windowType::EXACT, "exact" },
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Henry Weller
committed
Foam::functionObjects::fieldAverageItem::fieldAverageItem()
active_(false),
Andrew Heather
committed
mean_(false),
Andrew Heather
committed
prime2Mean_(false),
prime2MeanFieldName_("unknown"),
base_(baseType::ITER),
totalIter_(0),
totalTime_(-1),
window_(-1),
windowName_(""),
windowType_(windowType::NONE),
windowTimes_(),
Andrew Heather
committed
windowFieldNames_(),
allowRestart_(true)
Henry Weller
committed
Foam::functionObjects::fieldAverageItem::fieldAverageItem
(
const fieldAverageItem& faItem
)
active_(faItem.active_),
fieldName_(faItem.fieldName_),
mean_(faItem.mean_),
meanFieldName_(faItem.meanFieldName_),
prime2Mean_(faItem.prime2Mean_),
prime2MeanFieldName_(faItem.prime2MeanFieldName_),
totalIter_(faItem.totalIter_),
totalTime_(faItem.totalTime_),
windowName_(faItem.windowName_),
windowType_(faItem.windowType_),
windowTimes_(faItem.windowTimes_),
Andrew Heather
committed
windowFieldNames_(faItem.windowFieldNames_),
allowRestart_(faItem.allowRestart_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Henry Weller
committed
Foam::functionObjects::fieldAverageItem::~fieldAverageItem()
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::fieldAverageItem::addToWindow
(
const word& fieldName,
const scalar deltaT
)
{
windowTimes_.push(deltaT);
windowFieldNames_.push(fieldName);
}
void Foam::functionObjects::fieldAverageItem::evolve(const objectRegistry& obr)
{
totalIter_++;
totalTime_ += obr.time().deltaTValue();
forAllIters(windowTimes_, timeIter)
{
timeIter() += obr.time().deltaTValue();
}
// Remove any fields that have passed out of the window
bool removeItem = true;
while (removeItem && windowTimes_.size())
{
removeItem = !(inWindow(windowTimes_.first()));
if (removeItem)
{
windowTimes_.pop();
const word fieldName = windowFieldNames_.pop();
//Info<< "evolve: removing field: " << fieldName << endl;
obr.checkOut(fieldName);
Andrew Heather
committed
void Foam::functionObjects::fieldAverageItem::clear
Andrew Heather
committed
const objectRegistry& obr,
bool fullClean
Andrew Heather
committed
{
obr.checkOut(meanFieldName_);
Andrew Heather
committed
}
Andrew Heather
committed
{
obr.checkOut(prime2MeanFieldName_);
Andrew Heather
committed
}
for (const word& fieldName : windowFieldNames_)
{
obr.checkOut(fieldName);
Andrew Heather
committed
}
if (totalTime_ < 0 || fullClean)
Andrew Heather
committed
totalTime_ = 0;
windowTimes_.clear();
windowFieldNames_.clear();
}
}
bool Foam::functionObjects::fieldAverageItem::readState(const dictionary& dict)
{
dict.readEntry("totalIter", totalIter_);
dict.readEntry("totalTime", totalTime_);
if (window_ > 0)
{
dict.readEntry("windowTimes", windowTimes_);
dict.readEntry("windowFieldNames", windowFieldNames_);
}
return true;
}
void Foam::functionObjects::fieldAverageItem::writeState
(
dictionary& dict
) const
{
dict.add("totalIter", totalIter_);
dict.add("totalTime", totalTime_);
if (window_ > 0)
{
dict.add("windowTimes", windowTimes_);
dict.add("windowFieldNames", windowFieldNames_);
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
Henry Weller
committed
void Foam::functionObjects::fieldAverageItem::operator=
(
const fieldAverageItem& rhs
)
return; // Self-assignment is a no-op
}
// Set updated values
active_ = rhs.active_;
fieldName_ = rhs.fieldName_;
mean_ = rhs.mean_;
meanFieldName_ = rhs.meanFieldName_;
prime2MeanFieldName_ = rhs.prime2MeanFieldName_;
totalIter_ = rhs.totalIter_;
totalTime_ = rhs.totalTime_;
windowType_ = rhs.windowType_;
windowTimes_ = rhs.windowTimes_;
windowFieldNames_ = rhs.windowFieldNames_;
Andrew Heather
committed
allowRestart_ = rhs.allowRestart_;
}
// ************************************************************************* //