mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
GIT: Initial state after latest Foundation merge
This commit is contained in:
331
src/functionObjects/field/fieldAverage/fieldAverage.C
Normal file
331
src/functionObjects/field/fieldAverage/fieldAverage.C
Normal file
@ -0,0 +1,331 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 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 "fieldAverage.H"
|
||||
#include "volFields.H"
|
||||
#include "fieldAverageItem.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(fieldAverage, 0);
|
||||
addToRunTimeSelectionTable(functionObject, fieldAverage, dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldAverage::resetFields()
|
||||
{
|
||||
forAll(faItems_, i)
|
||||
{
|
||||
if (faItems_[i].mean())
|
||||
{
|
||||
if (obr_.found(faItems_[i].meanFieldName()))
|
||||
{
|
||||
obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (faItems_[i].prime2Mean())
|
||||
{
|
||||
if (obr_.found(faItems_[i].prime2MeanFieldName()))
|
||||
{
|
||||
obr_.checkOut(*obr_[faItems_[i].prime2MeanFieldName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldAverage::initialize()
|
||||
{
|
||||
resetFields();
|
||||
|
||||
Log << type() << " " << name_ << ":" << nl;
|
||||
|
||||
// Add mean fields to the field lists
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
addMeanField<scalar>(fieldi);
|
||||
addMeanField<vector>(fieldi);
|
||||
addMeanField<sphericalTensor>(fieldi);
|
||||
addMeanField<symmTensor>(fieldi);
|
||||
addMeanField<tensor>(fieldi);
|
||||
}
|
||||
|
||||
// Add prime-squared mean fields to the field lists
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
addPrime2MeanField<scalar, scalar>(fieldi);
|
||||
addPrime2MeanField<vector, symmTensor>(fieldi);
|
||||
}
|
||||
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
if (!faItems_[fieldi].active())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Field " << faItems_[fieldi].fieldName()
|
||||
<< " not found in database for averaging";
|
||||
}
|
||||
}
|
||||
|
||||
// ensure first averaging works unconditionally
|
||||
prevTimeIndex_ = -1;
|
||||
|
||||
Log << endl;
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldAverage::restart()
|
||||
{
|
||||
Log
|
||||
<< " Restarting averaging at time " << obr_.time().timeName()
|
||||
<< nl << endl;
|
||||
|
||||
totalIter_.clear();
|
||||
totalIter_.setSize(faItems_.size(), 1);
|
||||
|
||||
totalTime_.clear();
|
||||
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldAverage::calcAverages()
|
||||
{
|
||||
if (!initialised_)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
const label currentTimeIndex = obr_.time().timeIndex();
|
||||
const scalar currentTime = obr_.time().value();
|
||||
|
||||
if (prevTimeIndex_ == currentTimeIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevTimeIndex_ = currentTimeIndex;
|
||||
}
|
||||
|
||||
if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
|
||||
{
|
||||
restart();
|
||||
periodIndex_++;
|
||||
}
|
||||
|
||||
Log
|
||||
<< type() << " " << name() << " write:" << nl
|
||||
<< " Calculating averages" << nl;
|
||||
|
||||
addMeanSqrToPrime2Mean<scalar, scalar>();
|
||||
addMeanSqrToPrime2Mean<vector, symmTensor>();
|
||||
|
||||
calculateMeanFields<scalar>();
|
||||
calculateMeanFields<vector>();
|
||||
calculateMeanFields<sphericalTensor>();
|
||||
calculateMeanFields<symmTensor>();
|
||||
calculateMeanFields<tensor>();
|
||||
|
||||
calculatePrime2MeanFields<scalar, scalar>();
|
||||
calculatePrime2MeanFields<vector, symmTensor>();
|
||||
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
totalIter_[fieldi]++;
|
||||
totalTime_[fieldi] += obr_.time().deltaTValue();
|
||||
}
|
||||
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldAverage::writeAverages() const
|
||||
{
|
||||
Log << " Writing average fields" << endl;
|
||||
|
||||
writeFields<scalar>();
|
||||
writeFields<vector>();
|
||||
writeFields<sphericalTensor>();
|
||||
writeFields<symmTensor>();
|
||||
writeFields<tensor>();
|
||||
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldAverage::writeAveragingProperties()
|
||||
{
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
dictionary propsDict;
|
||||
propsDict.add("totalIter", totalIter_[fieldi]);
|
||||
propsDict.add("totalTime", totalTime_[fieldi]);
|
||||
setProperty(fieldName, propsDict);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldAverage::readAveragingProperties()
|
||||
{
|
||||
totalIter_.clear();
|
||||
totalIter_.setSize(faItems_.size(), 1);
|
||||
|
||||
totalTime_.clear();
|
||||
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
|
||||
|
||||
if ((restartOnRestart_ || restartOnOutput_) && log)
|
||||
{
|
||||
Info<< " Starting averaging at time " << obr_.time().timeName()
|
||||
<< nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << " Restarting averaging for fields:" << nl;
|
||||
|
||||
|
||||
forAll(faItems_, fieldi)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
if (foundProperty(fieldName))
|
||||
{
|
||||
dictionary fieldDict;
|
||||
getProperty(fieldName, fieldDict);
|
||||
|
||||
totalIter_[fieldi] = readLabel(fieldDict.lookup("totalIter"));
|
||||
totalTime_[fieldi] = readScalar(fieldDict.lookup("totalTime"));
|
||||
|
||||
Log
|
||||
<< " " << fieldName
|
||||
<< " iters = " << totalIter_[fieldi]
|
||||
<< " time = " << totalTime_[fieldi] << nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log
|
||||
<< " " << fieldName
|
||||
<< ": starting averaging at time "
|
||||
<< obr_.time().timeName() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldAverage::fieldAverage
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
prevTimeIndex_(-1),
|
||||
restartOnRestart_(false),
|
||||
restartOnOutput_(false),
|
||||
periodicRestart_(false),
|
||||
restartPeriod_(GREAT),
|
||||
initialised_(false),
|
||||
faItems_(),
|
||||
totalIter_(),
|
||||
totalTime_(),
|
||||
periodIndex_(1)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldAverage::~fieldAverage()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
initialised_ = false;
|
||||
|
||||
Log << type() << " " << name() << ":" << nl;
|
||||
|
||||
dict.readIfPresent("restartOnRestart", restartOnRestart_);
|
||||
dict.readIfPresent("restartOnOutput", restartOnOutput_);
|
||||
dict.readIfPresent("periodicRestart", periodicRestart_);
|
||||
dict.lookup("fields") >> faItems_;
|
||||
|
||||
if (periodicRestart_)
|
||||
{
|
||||
dict.lookup("restartPeriod") >> restartPeriod_;
|
||||
}
|
||||
|
||||
readAveragingProperties();
|
||||
|
||||
Log << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldAverage::execute()
|
||||
{
|
||||
calcAverages();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldAverage::write()
|
||||
{
|
||||
writeAverages();
|
||||
writeAveragingProperties();
|
||||
|
||||
if (restartOnOutput_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
326
src/functionObjects/field/fieldAverage/fieldAverage.H
Normal file
326
src/functionObjects/field/fieldAverage/fieldAverage.H
Normal file
@ -0,0 +1,326 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fieldAverage
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
Calculates average quantities for a user-specified selection of volumetric
|
||||
and surface fields.
|
||||
|
||||
Fields are entered as a list of sub-dictionaries, which indicate the type of
|
||||
averages to perform, and can be updated during the calculation. The current
|
||||
options include:
|
||||
- \c mean: arithmetic mean:
|
||||
\f[
|
||||
\overline{x} = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N x_i
|
||||
\f]
|
||||
- \c prime2Mean: prime-squared mean
|
||||
\f[
|
||||
\overline{x'}^2 = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N
|
||||
(x_i - \overline{x})^2
|
||||
\f]
|
||||
- base: average over 'time', or 'iteration' (\f$N\f$ in the above)
|
||||
- window: optional averaging window, specified in 'base' units
|
||||
|
||||
Average field names are constructed by concatenating the base field with
|
||||
the averaging type, e.g. when averaging field 'U', the resultant fields
|
||||
are:
|
||||
- arithmetic mean field, UMean
|
||||
- prime-squared field, UPrime2Mean
|
||||
|
||||
Information regarding the number of averaging steps, and total averaging
|
||||
time are written on a per-field basis to the
|
||||
\c "<functionObject name>Properties" dictionary, located in \<time\>/uniform
|
||||
|
||||
When restarting form a previous calculation, the averaging is continuous or
|
||||
may be restarted using the \c restartOnRestart option.
|
||||
|
||||
The averaging process may be restarted after each calculation output time
|
||||
using the \c restartOnOutput option or restarted periodically using the \c
|
||||
periodicRestart option and setting \c restartPeriod to the required
|
||||
averaging period.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
fieldAverage1
|
||||
{
|
||||
type fieldAverage;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
|
||||
writeControl writeTime;
|
||||
|
||||
restartOnRestart false;
|
||||
restartOnOutput false;
|
||||
periodicRestart false;
|
||||
restartPeriod 0.002;
|
||||
|
||||
fields
|
||||
(
|
||||
U
|
||||
{
|
||||
mean on;
|
||||
prime2Mean on;
|
||||
base time;
|
||||
window 10.0;
|
||||
windowName w1;
|
||||
}
|
||||
p
|
||||
{
|
||||
mean on;
|
||||
prime2Mean on;
|
||||
base time;
|
||||
}
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: fieldAverage | yes |
|
||||
restartOnRestart| Restart the averaging on restart | no | no
|
||||
restartOnOutput | Restart the averaging on output | no | no
|
||||
periodicRestart | Periodically restart the averaging | no | no
|
||||
restartPeriod | Periodic restart period | conditional |
|
||||
fields | list of fields and averaging options | yes |
|
||||
\endtable
|
||||
|
||||
|
||||
Note
|
||||
To employ the \c prime2Mean option, the \c mean option must be selecetd.
|
||||
|
||||
See also
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
fieldAverage.C
|
||||
fieldAverageTemplates.C
|
||||
fieldAverageItem.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldAverage_H
|
||||
#define functionObjects_fieldAverage_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class fieldAverageItem;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldAverage Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldAverage
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Time at last call, prevents repeated averaging
|
||||
label prevTimeIndex_;
|
||||
|
||||
//- Restart the averaging process on restart
|
||||
Switch restartOnRestart_;
|
||||
|
||||
//- Restart the averaging process on output
|
||||
Switch restartOnOutput_;
|
||||
|
||||
//- Periodically restart the averaging process
|
||||
Switch periodicRestart_;
|
||||
|
||||
//- Restart period
|
||||
scalar restartPeriod_;
|
||||
|
||||
//- Initialised flag
|
||||
bool initialised_;
|
||||
|
||||
//- List of field average items, describing what averages to be
|
||||
// calculated and output
|
||||
List<fieldAverageItem> faItems_;
|
||||
|
||||
// Counters
|
||||
|
||||
//- Iteration steps counter
|
||||
List<label> totalIter_;
|
||||
|
||||
//- Total time counter
|
||||
List<scalar> totalTime_;
|
||||
|
||||
//- Index for periodic restart
|
||||
label periodIndex_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
// Initialisation routines
|
||||
|
||||
//- Checkout fields (causes deletion) from the database
|
||||
// and reset lists
|
||||
void resetFields();
|
||||
|
||||
//- Reset lists (clear existing values) and initialize averaging.
|
||||
// Check requested field averages are valid, populate field lists
|
||||
void initialize();
|
||||
|
||||
//- Restart averaging for restartOnOutput
|
||||
void restart();
|
||||
|
||||
//- Add mean average field to database
|
||||
template<class Type>
|
||||
void addMeanFieldType(const label fieldi);
|
||||
|
||||
//- Add mean average field to database
|
||||
template<class Type>
|
||||
void addMeanField(const label fieldi);
|
||||
|
||||
//- Add prime-squared average field to database
|
||||
template<class Type1, class Type2>
|
||||
void addPrime2MeanFieldType(const label fieldi);
|
||||
|
||||
//- Add prime-squared average field to database
|
||||
template<class Type1, class Type2>
|
||||
void addPrime2MeanField(const label fieldi);
|
||||
|
||||
|
||||
// Calculation functions
|
||||
|
||||
//- Main calculation routine
|
||||
virtual void calcAverages();
|
||||
|
||||
//- Calculate mean average fields
|
||||
template<class Type>
|
||||
void calculateMeanFieldType(const label fieldi) const;
|
||||
|
||||
//- Calculate mean average fields
|
||||
template<class Type>
|
||||
void calculateMeanFields() const;
|
||||
|
||||
//- Calculate prime-squared average fields
|
||||
template<class Type1, class Type2>
|
||||
void calculatePrime2MeanFieldType(const label fieldi) const;
|
||||
|
||||
//- Calculate prime-squared average fields
|
||||
template<class Type1, class Type2>
|
||||
void calculatePrime2MeanFields() const;
|
||||
|
||||
//- Add mean-squared field value to prime-squared mean field
|
||||
template<class Type1, class Type2>
|
||||
void addMeanSqrToPrime2MeanType(const label fieldi) const;
|
||||
|
||||
//- Add mean-squared field value to prime-squared mean field
|
||||
template<class Type1, class Type2>
|
||||
void addMeanSqrToPrime2Mean() const;
|
||||
|
||||
|
||||
// I-O
|
||||
|
||||
//- Write averages
|
||||
virtual void writeAverages() const;
|
||||
|
||||
//- Write fields
|
||||
template<class Type>
|
||||
void writeFieldType(const word& fieldName) const;
|
||||
|
||||
//- Write fields
|
||||
template<class Type>
|
||||
void writeFields() const;
|
||||
|
||||
//- Write averaging properties - steps and time
|
||||
void writeAveragingProperties();
|
||||
|
||||
//- Read averaging properties - steps and time
|
||||
void readAveragingProperties();
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
fieldAverage(const fieldAverage&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const fieldAverage&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("fieldAverage");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
fieldAverage
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldAverage();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the field average data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the field averages
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the field averages
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldAverageTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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 * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_MEAN
|
||||
(
|
||||
"Mean"
|
||||
);
|
||||
|
||||
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_PRIME2MEAN
|
||||
(
|
||||
"Prime2Mean"
|
||||
);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldAverageItem::baseType,
|
||||
2
|
||||
>::names[] = { "iteration", "time"};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldAverageItem::baseType,
|
||||
2
|
||||
> Foam::functionObjects::fieldAverageItem::baseTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldAverageItem::fieldAverageItem()
|
||||
:
|
||||
fieldName_("unknown"),
|
||||
mean_(0),
|
||||
meanFieldName_("unknown"),
|
||||
prime2Mean_(0),
|
||||
prime2MeanFieldName_("unknown"),
|
||||
base_(ITER),
|
||||
window_(-1.0),
|
||||
windowName_("")
|
||||
{}
|
||||
|
||||
|
||||
Foam::functionObjects::fieldAverageItem::fieldAverageItem
|
||||
(
|
||||
const fieldAverageItem& faItem
|
||||
)
|
||||
:
|
||||
fieldName_(faItem.fieldName_),
|
||||
mean_(faItem.mean_),
|
||||
meanFieldName_(faItem.meanFieldName_),
|
||||
prime2Mean_(faItem.prime2Mean_),
|
||||
prime2MeanFieldName_(faItem.prime2MeanFieldName_),
|
||||
base_(faItem.base_),
|
||||
window_(faItem.window_),
|
||||
windowName_(faItem.windowName_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldAverageItem::~fieldAverageItem()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldAverageItem::operator=
|
||||
(
|
||||
const fieldAverageItem& rhs
|
||||
)
|
||||
{
|
||||
// Check for assignment to self
|
||||
if (this == &rhs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Attempted assignment to self" << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
// Set updated values
|
||||
fieldName_ = rhs.fieldName_;
|
||||
mean_ = rhs.mean_;
|
||||
meanFieldName_ = rhs.meanFieldName_;
|
||||
prime2Mean_ = rhs.prime2Mean_;
|
||||
prime2MeanFieldName_ = rhs.prime2MeanFieldName_;
|
||||
base_ = rhs.base_;
|
||||
window_ = rhs.window_;
|
||||
windowName_ = rhs.windowName_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,274 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fieldAverageItem
|
||||
|
||||
Description
|
||||
Helper class to describe what form of averaging to apply. A set will be
|
||||
applied to each base field in Foam::fieldAverage, of the form:
|
||||
|
||||
\verbatim
|
||||
{
|
||||
mean on;
|
||||
prime2Mean on;
|
||||
base time; // iteration
|
||||
window 200; // optional averaging window
|
||||
windowName w1; // optional window name (default = "")
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
The averaging window corresponds to the averaging interval (iters or time)
|
||||
If not specified, the averaging is over 'all iters/time'
|
||||
|
||||
SourceFiles
|
||||
fieldAverageItem.C
|
||||
fieldAverageItemIO.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fieldAverageItem_H
|
||||
#define fieldAverageItem_H
|
||||
|
||||
#include "NamedEnum.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class fieldAverageItem;
|
||||
Istream& operator>>(Istream&, fieldAverageItem&);
|
||||
Ostream& operator<<(Ostream&, const fieldAverageItem&);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldAverageItem Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldAverageItem
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data
|
||||
|
||||
// File and field name extensions
|
||||
|
||||
//- Mean average
|
||||
static const word EXT_MEAN;
|
||||
|
||||
//- Prime-squared average
|
||||
static const word EXT_PRIME2MEAN;
|
||||
|
||||
//- Enumeration defining the averaging base type
|
||||
enum baseType
|
||||
{
|
||||
ITER,
|
||||
TIME
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Field name
|
||||
word fieldName_;
|
||||
|
||||
//- Compute mean flag
|
||||
Switch mean_;
|
||||
|
||||
//- Name of mean field
|
||||
word meanFieldName_;
|
||||
|
||||
//- Compute prime-squared mean flag
|
||||
Switch prime2Mean_;
|
||||
|
||||
//- Name of prime-squared mean field
|
||||
word prime2MeanFieldName_;
|
||||
|
||||
//- Averaging base type names
|
||||
static const NamedEnum<baseType, 2> baseTypeNames_;
|
||||
|
||||
//- Averaging base type
|
||||
baseType base_;
|
||||
|
||||
//- Averaging window - defaults to -1 for 'all iters/time'
|
||||
scalar window_;
|
||||
|
||||
//- Averaging window name - defaults to 'window'
|
||||
word windowName_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
fieldAverageItem();
|
||||
|
||||
//- Construct from Istream
|
||||
fieldAverageItem(Istream&);
|
||||
|
||||
//- Construct as copy
|
||||
fieldAverageItem(const fieldAverageItem&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~fieldAverageItem();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return const access to the field name
|
||||
const word& fieldName() const
|
||||
{
|
||||
return fieldName_;
|
||||
}
|
||||
|
||||
//- Return const access to the mean flag
|
||||
const Switch& mean() const
|
||||
{
|
||||
return mean_;
|
||||
}
|
||||
|
||||
//- Return non-const access to the mean flag
|
||||
Switch& mean()
|
||||
{
|
||||
return mean_;
|
||||
}
|
||||
|
||||
//- Return const access to the mean field name
|
||||
const word& meanFieldName() const
|
||||
{
|
||||
return meanFieldName_;
|
||||
}
|
||||
|
||||
//- Return const access to the prime-squared mean flag
|
||||
const Switch& prime2Mean() const
|
||||
{
|
||||
return prime2Mean_;
|
||||
}
|
||||
|
||||
//- Return non-const access to the prime-squared mean flag
|
||||
Switch& prime2Mean()
|
||||
{
|
||||
return prime2Mean_;
|
||||
}
|
||||
|
||||
//- Return const access to the prime-squared mean field name
|
||||
const word& prime2MeanFieldName() const
|
||||
{
|
||||
return prime2MeanFieldName_;
|
||||
}
|
||||
|
||||
//- Return averaging base type name
|
||||
const word base() const
|
||||
{
|
||||
return baseTypeNames_[base_];
|
||||
}
|
||||
|
||||
//- Return true if base is ITER
|
||||
Switch iterBase() const
|
||||
{
|
||||
return base_ == ITER;
|
||||
}
|
||||
|
||||
//- Return true if base is time
|
||||
Switch timeBase() const
|
||||
{
|
||||
return base_ == TIME;
|
||||
}
|
||||
|
||||
scalar window() const
|
||||
{
|
||||
return window_;
|
||||
}
|
||||
|
||||
const word& windowName() const
|
||||
{
|
||||
return windowName_;
|
||||
}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
void operator=(const fieldAverageItem&);
|
||||
|
||||
|
||||
// Friend Operators
|
||||
|
||||
friend bool operator==
|
||||
(
|
||||
const fieldAverageItem& a,
|
||||
const fieldAverageItem& b
|
||||
)
|
||||
{
|
||||
return
|
||||
a.fieldName_ == b.fieldName_
|
||||
&& a.mean_ == b.mean_
|
||||
&& a.meanFieldName_ == b.meanFieldName_
|
||||
&& a.prime2Mean_ == b.prime2Mean_
|
||||
&& a.prime2MeanFieldName_ == b.prime2MeanFieldName_
|
||||
&& a.base_ == b.base_
|
||||
&& a.window_ == b.window_
|
||||
&& a.windowName_ == b.windowName_;
|
||||
}
|
||||
|
||||
friend bool operator!=
|
||||
(
|
||||
const fieldAverageItem& a,
|
||||
const fieldAverageItem& b
|
||||
)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream&, fieldAverageItem&);
|
||||
friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,149 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 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"
|
||||
#include "IOstreams.H"
|
||||
#include "dictionaryEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldAverageItem::fieldAverageItem(Istream& is)
|
||||
:
|
||||
fieldName_("unknown"),
|
||||
mean_(0),
|
||||
meanFieldName_("unknown"),
|
||||
prime2Mean_(0),
|
||||
prime2MeanFieldName_("unknown"),
|
||||
base_(ITER),
|
||||
window_(-1.0)
|
||||
{
|
||||
is.check
|
||||
(
|
||||
"Foam::functionObjects::fieldAverageItem::fieldAverageItem"
|
||||
"(Foam::Istream&)"
|
||||
);
|
||||
|
||||
const dictionaryEntry entry(dictionary::null, is);
|
||||
|
||||
fieldName_ = entry.keyword();
|
||||
entry.lookup("mean") >> mean_;
|
||||
entry.lookup("prime2Mean") >> prime2Mean_;
|
||||
base_ = baseTypeNames_[entry.lookup("base")];
|
||||
window_ = entry.lookupOrDefault<scalar>("window", -1.0);
|
||||
windowName_ = entry.lookupOrDefault<word>("windowName", "");
|
||||
|
||||
meanFieldName_ = fieldName_ + EXT_MEAN;
|
||||
prime2MeanFieldName_ = fieldName_ + EXT_PRIME2MEAN;
|
||||
if ((window_ > 0) && (windowName_ != ""))
|
||||
{
|
||||
meanFieldName_ = meanFieldName_ + "_" + windowName_;
|
||||
prime2MeanFieldName_ = prime2MeanFieldName_ + "_" + windowName_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::functionObjects::operator>>
|
||||
(
|
||||
Istream& is,
|
||||
fieldAverageItem& faItem
|
||||
)
|
||||
{
|
||||
is.check
|
||||
(
|
||||
"Foam::Istream& Foam::operator>>"
|
||||
"(Foam::Istream&, Foam::functionObjects::fieldAverageItem&)"
|
||||
);
|
||||
|
||||
const dictionaryEntry entry(dictionary::null, is);
|
||||
|
||||
faItem.fieldName_ = entry.keyword();
|
||||
entry.lookup("mean") >> faItem.mean_;
|
||||
entry.lookup("prime2Mean") >> faItem.prime2Mean_;
|
||||
faItem.base_ = faItem.baseTypeNames_[entry.lookup("base")];
|
||||
faItem.window_ = entry.lookupOrDefault<scalar>("window", -1.0);
|
||||
faItem.windowName_ = entry.lookupOrDefault<word>("windowName", "");
|
||||
|
||||
faItem.meanFieldName_ = faItem.fieldName_ + fieldAverageItem::EXT_MEAN;
|
||||
faItem.prime2MeanFieldName_ =
|
||||
faItem.fieldName_ + fieldAverageItem::EXT_PRIME2MEAN;
|
||||
|
||||
if ((faItem.window_ > 0) && (faItem.windowName_ != ""))
|
||||
{
|
||||
faItem.meanFieldName_ =
|
||||
faItem.meanFieldName_ + "_" + faItem.windowName_;
|
||||
|
||||
faItem.prime2MeanFieldName_ =
|
||||
faItem.prime2MeanFieldName_ + "_" + faItem.windowName_;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::functionObjects::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const fieldAverageItem& faItem
|
||||
)
|
||||
{
|
||||
os.check
|
||||
(
|
||||
"Foam::Ostream& Foam::operator<<"
|
||||
"(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
|
||||
);
|
||||
|
||||
os << faItem.fieldName_ << nl << token::BEGIN_BLOCK << nl;
|
||||
os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("prime2Mean") << faItem.prime2Mean_
|
||||
<< token::END_STATEMENT << nl;
|
||||
os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
|
||||
<< token::END_STATEMENT << nl;
|
||||
|
||||
if (faItem.window_ > 0)
|
||||
{
|
||||
os.writeKeyword("window") << faItem.window_
|
||||
<< token::END_STATEMENT << nl;
|
||||
|
||||
if (faItem.windowName_ != "")
|
||||
{
|
||||
os.writeKeyword("windowName") << faItem.windowName_
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
}
|
||||
|
||||
os << token::END_BLOCK << nl;
|
||||
|
||||
os.check
|
||||
(
|
||||
"Foam::Ostream& Foam::operator<<"
|
||||
"(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
|
||||
);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
411
src/functionObjects/field/fieldAverage/fieldAverageTemplates.C
Normal file
411
src/functionObjects/field/fieldAverage/fieldAverageTemplates.C
Normal file
@ -0,0 +1,411 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 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"
|
||||
#include "volFields.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::addMeanFieldType(const label fieldi)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
const word& meanFieldName = faItems_[fieldi].meanFieldName();
|
||||
|
||||
Log << " Reading/initialising field " << meanFieldName << endl;
|
||||
|
||||
if (obr_.foundObject<Type>(meanFieldName))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else if (obr_.found(meanFieldName))
|
||||
{
|
||||
Log << " Cannot allocate average field " << meanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << endl;
|
||||
|
||||
faItems_[fieldi].mean() = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const Type& baseField = obr_.lookupObject<Type>(fieldName);
|
||||
|
||||
// Store on registry
|
||||
obr_.store
|
||||
(
|
||||
new Type
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
meanFieldName,
|
||||
obr_.time().timeName(obr_.time().startTime().value()),
|
||||
obr_,
|
||||
restartOnOutput_
|
||||
? IOobject::NO_READ
|
||||
: IOobject::READ_IF_PRESENT,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
1*baseField
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::addMeanField(const label fieldi)
|
||||
{
|
||||
if (faItems_[fieldi].mean())
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh>
|
||||
VolFieldType;
|
||||
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh>
|
||||
SurfaceFieldType;
|
||||
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
if (obr_.foundObject<VolFieldType>(fieldName))
|
||||
{
|
||||
addMeanFieldType<VolFieldType>(fieldi);
|
||||
}
|
||||
else if (obr_.foundObject<SurfaceFieldType>(fieldName))
|
||||
{
|
||||
addMeanFieldType<SurfaceFieldType>(fieldi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::addPrime2MeanFieldType
|
||||
(
|
||||
const label fieldi
|
||||
)
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
const word& meanFieldName = faItems_[fieldi].meanFieldName();
|
||||
const word& prime2MeanFieldName = faItems_[fieldi].prime2MeanFieldName();
|
||||
|
||||
Log << " Reading/initialising field " << prime2MeanFieldName << nl;
|
||||
|
||||
if (obr_.foundObject<Type2>(prime2MeanFieldName))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else if (obr_.found(prime2MeanFieldName))
|
||||
{
|
||||
Log << " Cannot allocate average field " << prime2MeanFieldName
|
||||
<< " since an object with that name already exists."
|
||||
<< " Disabling averaging for field." << endl;
|
||||
|
||||
faItems_[fieldi].prime2Mean() = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
|
||||
const Type1& meanField = obr_.lookupObject<Type1>(meanFieldName);
|
||||
|
||||
// Store on registry
|
||||
obr_.store
|
||||
(
|
||||
new Type2
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
prime2MeanFieldName,
|
||||
obr_.time().timeName(obr_.time().startTime().value()),
|
||||
obr_,
|
||||
restartOnOutput_
|
||||
? IOobject::NO_READ
|
||||
: IOobject::READ_IF_PRESENT,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
sqr(baseField) - sqr(meanField)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::addPrime2MeanField(const label fieldi)
|
||||
{
|
||||
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
|
||||
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
|
||||
|
||||
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
|
||||
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
|
||||
|
||||
if (faItems_[fieldi].prime2Mean())
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
if (!faItems_[fieldi].mean())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "To calculate the prime-squared average, the "
|
||||
<< "mean average must also be selected for field "
|
||||
<< fieldName << nl << exit(FatalError);
|
||||
}
|
||||
|
||||
if (obr_.foundObject<VolFieldType1>(fieldName))
|
||||
{
|
||||
addPrime2MeanFieldType<VolFieldType1, VolFieldType2>(fieldi);
|
||||
}
|
||||
else if (obr_.foundObject<SurfaceFieldType1>(fieldName))
|
||||
{
|
||||
addPrime2MeanFieldType<SurfaceFieldType1, SurfaceFieldType2>
|
||||
(
|
||||
fieldi
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::calculateMeanFieldType
|
||||
(
|
||||
const label fieldi
|
||||
) const
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
if (obr_.foundObject<Type>(fieldName))
|
||||
{
|
||||
const Type& baseField = obr_.lookupObject<Type>(fieldName);
|
||||
|
||||
Type& meanField = const_cast<Type&>
|
||||
(
|
||||
obr_.lookupObject<Type>(faItems_[fieldi].meanFieldName())
|
||||
);
|
||||
|
||||
scalar dt = obr_.time().deltaTValue();
|
||||
scalar Dt = totalTime_[fieldi];
|
||||
|
||||
if (faItems_[fieldi].iterBase())
|
||||
{
|
||||
dt = 1.0;
|
||||
Dt = scalar(totalIter_[fieldi]);
|
||||
}
|
||||
|
||||
scalar alpha = (Dt - dt)/Dt;
|
||||
scalar beta = dt/Dt;
|
||||
|
||||
if (faItems_[fieldi].window() > 0)
|
||||
{
|
||||
const scalar w = faItems_[fieldi].window();
|
||||
|
||||
if (Dt - dt >= w)
|
||||
{
|
||||
alpha = (w - dt)/w;
|
||||
beta = dt/w;
|
||||
}
|
||||
}
|
||||
|
||||
meanField = alpha*meanField + beta*baseField;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::calculateMeanFields() const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
||||
|
||||
forAll(faItems_, i)
|
||||
{
|
||||
if (faItems_[i].mean())
|
||||
{
|
||||
calculateMeanFieldType<VolFieldType>(i);
|
||||
calculateMeanFieldType<SurfaceFieldType>(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::calculatePrime2MeanFieldType
|
||||
(
|
||||
const label fieldi
|
||||
) const
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
if (obr_.foundObject<Type1>(fieldName))
|
||||
{
|
||||
const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
|
||||
const Type1& meanField =
|
||||
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
|
||||
|
||||
Type2& prime2MeanField = const_cast<Type2&>
|
||||
(
|
||||
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
|
||||
);
|
||||
|
||||
scalar dt = obr_.time().deltaTValue();
|
||||
scalar Dt = totalTime_[fieldi];
|
||||
|
||||
if (faItems_[fieldi].iterBase())
|
||||
{
|
||||
dt = 1.0;
|
||||
Dt = scalar(totalIter_[fieldi]);
|
||||
}
|
||||
|
||||
scalar alpha = (Dt - dt)/Dt;
|
||||
scalar beta = dt/Dt;
|
||||
|
||||
if (faItems_[fieldi].window() > 0)
|
||||
{
|
||||
const scalar w = faItems_[fieldi].window();
|
||||
|
||||
if (Dt - dt >= w)
|
||||
{
|
||||
alpha = (w - dt)/w;
|
||||
beta = dt/w;
|
||||
}
|
||||
}
|
||||
|
||||
prime2MeanField =
|
||||
alpha*prime2MeanField
|
||||
+ beta*sqr(baseField)
|
||||
- sqr(meanField);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::calculatePrime2MeanFields() const
|
||||
{
|
||||
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
|
||||
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
|
||||
|
||||
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
|
||||
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
|
||||
|
||||
forAll(faItems_, i)
|
||||
{
|
||||
if (faItems_[i].prime2Mean())
|
||||
{
|
||||
calculatePrime2MeanFieldType<VolFieldType1, VolFieldType2>
|
||||
(
|
||||
i
|
||||
);
|
||||
|
||||
calculatePrime2MeanFieldType<SurfaceFieldType1, SurfaceFieldType2>
|
||||
(
|
||||
i
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2MeanType
|
||||
(
|
||||
const label fieldi
|
||||
) const
|
||||
{
|
||||
const word& fieldName = faItems_[fieldi].fieldName();
|
||||
|
||||
if (obr_.foundObject<Type1>(fieldName))
|
||||
{
|
||||
const Type1& meanField =
|
||||
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
|
||||
|
||||
Type2& prime2MeanField = const_cast<Type2&>
|
||||
(
|
||||
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
|
||||
);
|
||||
|
||||
prime2MeanField += sqr(meanField);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2Mean() const
|
||||
{
|
||||
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
|
||||
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
|
||||
|
||||
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
|
||||
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
|
||||
|
||||
forAll(faItems_, i)
|
||||
{
|
||||
if (faItems_[i].prime2Mean())
|
||||
{
|
||||
addMeanSqrToPrime2MeanType<VolFieldType1, VolFieldType2>(i);
|
||||
addMeanSqrToPrime2MeanType<SurfaceFieldType1, SurfaceFieldType2>(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::writeFieldType
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (obr_.foundObject<Type>(fieldName))
|
||||
{
|
||||
const Type& f = obr_.lookupObject<Type>(fieldName);
|
||||
f.write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldAverage::writeFields() const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
||||
|
||||
forAll(faItems_, i)
|
||||
{
|
||||
if (faItems_[i].mean())
|
||||
{
|
||||
const word& fieldName = faItems_[i].meanFieldName();
|
||||
writeFieldType<VolFieldType>(fieldName);
|
||||
writeFieldType<SurfaceFieldType>(fieldName);
|
||||
}
|
||||
if (faItems_[i].prime2Mean())
|
||||
{
|
||||
const word& fieldName = faItems_[i].prime2MeanFieldName();
|
||||
writeFieldType<VolFieldType>(fieldName);
|
||||
writeFieldType<SurfaceFieldType>(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user