ENH: fieldAverage FO updated following update to use functionObjectState
This commit is contained in:
parent
868571718d
commit
f2d2ab2703
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -66,7 +66,8 @@ void Foam::fieldAverage::initialize()
|
||||
{
|
||||
resetFields();
|
||||
|
||||
Info<< type() << " " << name_ << ":" << nl;
|
||||
if (log_) Info << type() << " " << name_ << ":" << nl;
|
||||
|
||||
|
||||
// Add mean fields to the field lists
|
||||
forAll(faItems_, fieldI)
|
||||
@ -98,7 +99,7 @@ void Foam::fieldAverage::initialize()
|
||||
// ensure first averaging works unconditionally
|
||||
prevTimeIndex_ = -1;
|
||||
|
||||
Info<< endl;
|
||||
if (log_) Info << endl;
|
||||
|
||||
initialised_ = true;
|
||||
}
|
||||
@ -123,9 +124,11 @@ void Foam::fieldAverage::calcAverages()
|
||||
prevTimeIndex_ = currentTimeIndex;
|
||||
}
|
||||
|
||||
Info<< type() << " " << name_ << " output:" << nl;
|
||||
|
||||
Info<< " Calculating averages" << nl;
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << " " << name_ << " output:" << nl
|
||||
<< " Calculating averages" << nl;
|
||||
}
|
||||
|
||||
addMeanSqrToPrime2Mean<scalar, scalar>();
|
||||
addMeanSqrToPrime2Mean<vector, symmTensor>();
|
||||
@ -149,7 +152,7 @@ void Foam::fieldAverage::calcAverages()
|
||||
|
||||
void Foam::fieldAverage::writeAverages() const
|
||||
{
|
||||
Info<< " Writing average fields" << endl;
|
||||
if (log_) Info << " Writing average fields" << endl;
|
||||
|
||||
writeFields<scalar>();
|
||||
writeFields<vector>();
|
||||
@ -159,31 +162,17 @@ void Foam::fieldAverage::writeAverages() const
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldAverage::writeAveragingProperties() const
|
||||
void Foam::fieldAverage::writeAveragingProperties()
|
||||
{
|
||||
IOdictionary propsDict
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"fieldAveragingProperties",
|
||||
obr_.time().timeName(),
|
||||
"uniform",
|
||||
obr_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
forAll(faItems_, fieldI)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldI].fieldName();
|
||||
propsDict.add(fieldName, dictionary());
|
||||
propsDict.subDict(fieldName).add("totalIter", totalIter_[fieldI]);
|
||||
propsDict.subDict(fieldName).add("totalTime", totalTime_[fieldI]);
|
||||
}
|
||||
|
||||
propsDict.regIOobject::write();
|
||||
dictionary propsDict;
|
||||
propsDict.add("totalIter", totalIter_[fieldI]);
|
||||
propsDict.add("totalTime", totalTime_[fieldI]);
|
||||
setProperty(fieldName, propsDict);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -195,46 +184,41 @@ void Foam::fieldAverage::readAveragingProperties()
|
||||
totalTime_.clear();
|
||||
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
|
||||
|
||||
if (resetOnRestart_ || resetOnOutput_)
|
||||
if (log_ && (resetOnRestart_ || resetOnOutput_))
|
||||
{
|
||||
Info<< " Starting averaging at time " << obr_.time().timeName()
|
||||
<< nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
IOobject propsDictHeader
|
||||
(
|
||||
"fieldAveragingProperties",
|
||||
obr_.time().timeName(obr_.time().startTime().value()),
|
||||
"uniform",
|
||||
obr_,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
if (log_) Info << " Restarting averaging for fields:" << nl;
|
||||
|
||||
if (!propsDictHeader.headerOk())
|
||||
{
|
||||
Info<< " Starting averaging at time " << obr_.time().timeName()
|
||||
<< nl;
|
||||
return;
|
||||
}
|
||||
|
||||
IOdictionary propsDict(propsDictHeader);
|
||||
|
||||
Info<< " Restarting averaging for fields:" << nl;
|
||||
forAll(faItems_, fieldI)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldI].fieldName();
|
||||
if (propsDict.found(fieldName))
|
||||
if (foundProperty(fieldName))
|
||||
{
|
||||
dictionary fieldDict(propsDict.subDict(fieldName));
|
||||
dictionary fieldDict;
|
||||
getProperty(fieldName, fieldDict);
|
||||
|
||||
totalIter_[fieldI] = readLabel(fieldDict.lookup("totalIter"));
|
||||
totalTime_[fieldI] = readScalar(fieldDict.lookup("totalTime"));
|
||||
Info<< " " << fieldName
|
||||
<< " iters = " << totalIter_[fieldI]
|
||||
<< " time = " << totalTime_[fieldI] << nl;
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << fieldName
|
||||
<< " iters = " << totalIter_[fieldI]
|
||||
<< " time = " << totalTime_[fieldI] << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << fieldName
|
||||
<< ": starting averaging at time "
|
||||
<< obr_.time().timeName() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -251,37 +235,22 @@ Foam::fieldAverage::fieldAverage
|
||||
const bool loadFromFiles
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
functionObjectState(obr, name),
|
||||
obr_(obr),
|
||||
active_(true),
|
||||
prevTimeIndex_(-1),
|
||||
resetOnRestart_(false),
|
||||
resetOnOutput_(false),
|
||||
log_(true),
|
||||
initialised_(false),
|
||||
faItems_(),
|
||||
totalIter_(),
|
||||
totalTime_()
|
||||
{
|
||||
// Only active if a fvMesh is available
|
||||
if (isA<fvMesh>(obr_))
|
||||
if (setActive<fvMesh>())
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
else
|
||||
{
|
||||
active_ = false;
|
||||
WarningIn
|
||||
(
|
||||
"fieldAverage::fieldAverage"
|
||||
"("
|
||||
"const word&, "
|
||||
"const objectRegistry&, "
|
||||
"const dictionary&, "
|
||||
"const bool "
|
||||
")"
|
||||
) << "No fvMesh available, deactivating " << name_ << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -299,7 +268,9 @@ void Foam::fieldAverage::read(const dictionary& dict)
|
||||
{
|
||||
initialised_ = false;
|
||||
|
||||
Info<< type() << " " << name_ << ":" << nl;
|
||||
log_.readIfPresent("log", dict);
|
||||
|
||||
if (log_) Info << type() << " " << name_ << ":" << nl;
|
||||
|
||||
dict.readIfPresent("resetOnRestart", resetOnRestart_);
|
||||
dict.readIfPresent("resetOnOutput", resetOnOutput_);
|
||||
@ -307,7 +278,7 @@ void Foam::fieldAverage::read(const dictionary& dict)
|
||||
|
||||
readAveragingProperties();
|
||||
|
||||
Info<< endl;
|
||||
if (log_) Info << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +288,7 @@ void Foam::fieldAverage::execute()
|
||||
if (active_)
|
||||
{
|
||||
calcAverages();
|
||||
Info<< endl;
|
||||
if (log_) Info << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,8 +297,7 @@ void Foam::fieldAverage::end()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
calcAverages();
|
||||
Info<< endl;
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,8 +315,11 @@ void Foam::fieldAverage::write()
|
||||
|
||||
if (resetOnOutput_)
|
||||
{
|
||||
Info<< " Restarting averaging at time " << obr_.time().timeName()
|
||||
<< nl << endl;
|
||||
if (log_)
|
||||
{
|
||||
Info<< " Restarting averaging at time " << obr_.time().timeName()
|
||||
<< nl << endl;
|
||||
}
|
||||
|
||||
totalIter_.clear();
|
||||
totalIter_.setSize(faItems_.size(), 1);
|
||||
@ -357,7 +330,7 @@ void Foam::fieldAverage::write()
|
||||
initialize();
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
if (log_) Info << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -94,9 +94,10 @@ Description
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: fieldAverage | yes |
|
||||
resetOnRestart | flag to reset the averaging on restart | yes |
|
||||
resetOnRestart | flag to reset the averaging on restart | yes |
|
||||
resetOnOutput| flag to reset the averaging on output | yes |
|
||||
fields | list of fields and averaging options | yes |
|
||||
log | Log to standard output | no | yes
|
||||
\endtable
|
||||
|
||||
|
||||
@ -117,6 +118,7 @@ SourceFiles
|
||||
#ifndef fieldAverage_H
|
||||
#define fieldAverage_H
|
||||
|
||||
#include "functionObjectState.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "Switch.H"
|
||||
|
||||
@ -139,20 +141,16 @@ class mapPolyMesh;
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldAverage
|
||||
:
|
||||
public functionObjectState
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of this set of field averages.
|
||||
word name_;
|
||||
|
||||
//- Database this class is registered to
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- On/off switch
|
||||
bool active_;
|
||||
|
||||
//- Time at last call, prevents repeated averaging
|
||||
label prevTimeIndex_;
|
||||
|
||||
@ -162,6 +160,9 @@ protected:
|
||||
//- Reset the averaging process on output flag
|
||||
Switch resetOnOutput_;
|
||||
|
||||
//- Switch to send output to Info as well as to file
|
||||
Switch log_;
|
||||
|
||||
//- Initialised flag
|
||||
bool initialised_;
|
||||
|
||||
@ -251,7 +252,7 @@ protected:
|
||||
void writeFields() const;
|
||||
|
||||
//- Write averaging properties - steps and time
|
||||
void writeAveragingProperties() const;
|
||||
void writeAveragingProperties();
|
||||
|
||||
//- Read averaging properties - steps and time
|
||||
void readAveragingProperties();
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,7 +38,7 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
|
||||
const word& fieldName = faItems_[fieldI].fieldName();
|
||||
const word& meanFieldName = faItems_[fieldI].meanFieldName();
|
||||
|
||||
Info<< " Reading/initialising field " << meanFieldName << endl;
|
||||
if (log_) Info << " Reading/initialising field " << meanFieldName << endl;
|
||||
|
||||
if (obr_.foundObject<Type>(meanFieldName))
|
||||
{
|
||||
@ -46,9 +46,12 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
|
||||
}
|
||||
else if (obr_.found(meanFieldName))
|
||||
{
|
||||
Info<< " Cannot allocate average field " << meanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << endl;
|
||||
if (log_)
|
||||
{
|
||||
Info<< " Cannot allocate average field " << meanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << endl;
|
||||
}
|
||||
|
||||
faItems_[fieldI].mean() = false;
|
||||
}
|
||||
@ -107,7 +110,10 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
|
||||
const word& meanFieldName = faItems_[fieldI].meanFieldName();
|
||||
const word& prime2MeanFieldName = faItems_[fieldI].prime2MeanFieldName();
|
||||
|
||||
Info<< " Reading/initialising field " << prime2MeanFieldName << nl;
|
||||
if (log_)
|
||||
{
|
||||
Info << " Reading/initialising field " << prime2MeanFieldName << nl;
|
||||
}
|
||||
|
||||
if (obr_.foundObject<Type2>(prime2MeanFieldName))
|
||||
{
|
||||
@ -115,9 +121,12 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
|
||||
}
|
||||
else if (obr_.found(prime2MeanFieldName))
|
||||
{
|
||||
Info<< " Cannot allocate average field " << prime2MeanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << nl;
|
||||
if (log_)
|
||||
{
|
||||
Info<< " Cannot allocate average field " << prime2MeanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << nl;
|
||||
}
|
||||
|
||||
faItems_[fieldI].prime2Mean() = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user