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