adding new fieldAverage function object

This commit is contained in:
andy
2008-05-12 15:33:53 +01:00
parent 75f6b64ffe
commit a6bab68565
14 changed files with 1565 additions and 3 deletions

View File

@ -0,0 +1,6 @@
fieldAverage/fieldAverage.C
fieldAverageItem/fieldAverageItem.C
fieldAverageItem/fieldAverageItemIO.C
fieldAverageFunctionObject/fieldAverageFunctionObject.C
LIB = $(FOAM_LIBBIN)/libfieldAverage

View File

@ -0,0 +1,9 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/OpenFOAM/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-lOpenFOAM \
-lsampling

View File

@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.4 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
root "";
case "";
instance "";
local "";
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application oodles;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 0.1;
deltaT 1e-05;
writeControl timeStep;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
runTimeModifiable yes;
functions
(
fieldAverage1
{
// Type of functionObject
type fieldAverage;
// Where to load it from (if not already in solver)
functionObjectLibs ("libfieldAverage.so");
// Fields to be probed. runTime modifiable!
fields
(
U
{
mean on;
prime2Mean on;
base time;
}
p
{
mean on;
prime2Mean on;
base time;
}
);
}
);
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Typedef
IOfieldAverage
Description
Instance of the generic IOOutputFilter for fieldAverage.
\*---------------------------------------------------------------------------*/
#ifndef IOfieldAverage_H
#define IOfieldAverage_H
#include "fieldAverage.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<fieldAverage> IOFieldAverage;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,339 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldAverage.H"
#include "volFields.H"
#include "dictionary.H"
#include "Time.H"
#include "IFstream.H"
#include "OFstream.H"
#include "fieldAverageItem.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(fieldAverage, 0);
}
const Foam::word Foam::fieldAverage::EXT_MEAN = "Mean";
const Foam::word Foam::fieldAverage::EXT_PRIME2MEAN = "Prime2Mean";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fieldAverage::resetLists(const label nItems)
{
meanScalarFields_.clear();
meanScalarFields_.setSize(nItems);
meanVectorFields_.clear();
meanVectorFields_.setSize(nItems);
meanSymmTensorFields_.clear();
meanSymmTensorFields_.setSize(nItems);
meanSphericalTensorFields_.clear();
meanSphericalTensorFields_.setSize(nItems);
prime2MeanScalarFields_.clear();
prime2MeanScalarFields_.setSize(nItems);
prime2MeanSymmTensorFields_.clear();
prime2MeanSymmTensorFields_.setSize(nItems);
nSteps_.clear();
nSteps_.setSize(nItems, 1);
totalTime_.clear();
totalTime_.setSize(nItems, obr_.time().deltaT().value());
}
void Foam::fieldAverage::initialise()
{
// Add mean fields to the field lists
forAll(faItems_, i)
{
const word fieldName = faItems_[i].fieldName();
if (obr_.foundObject<volScalarField>(fieldName))
{
addMeanFields<scalar>(i, meanScalarFields_);
}
else if (obr_.foundObject<volVectorField>(fieldName))
{
addMeanFields<vector>(i, meanVectorFields_);
}
else if (obr_.foundObject<volSymmTensorField>(fieldName))
{
addMeanFields<symmTensor>(i, meanSymmTensorFields_);
}
else if (obr_.foundObject<volSphericalTensorField>(fieldName))
{
addMeanFields<sphericalTensor>(i, meanSphericalTensorFields_);
}
else
{
FatalErrorIn("Foam::fieldAverage::initialise()")
<< "Requested field " << faItems_[i].fieldName()
<< " does not exist in the database" << nl
<< exit(FatalError);
}
}
// Add prime-squared mean fields to the field lists
forAll(faItems_, i)
{
if (faItems_[i].prime2Mean())
{
const word fieldName = faItems_[i].fieldName();
if (obr_.foundObject<volScalarField>(fieldName))
{
if (!faItems_[i].mean())
{
FatalErrorIn("Foam::fieldAverage::initialise()")
<< "To calculate the prime-squared average, the "
<< "mean average must also be selected for field "
<< fieldName << nl << exit(FatalError);
}
addPrime2MeanFields<scalar>(i, prime2MeanScalarFields_);
}
else if (obr_.foundObject<volVectorField>(fieldName))
{
if (!faItems_[i].mean())
{
FatalErrorIn("Foam::fieldAverage::initialise()")
<< "To calculate the prime-squared average, the "
<< "mean average must also be selected for field "
<< fieldName << nl << exit(FatalError);
}
addPrime2MeanFields<vector>
(
i,
prime2MeanSymmTensorFields_
);
}
else
{
FatalErrorIn("Foam::fieldAverage::initialise()")
<< "prime2Mean average can only be applied to "
<< "volScalarFields and volVectorFields"
<< nl << " Field: " << fieldName << nl
<< exit(FatalError);
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldAverage::fieldAverage
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
faItems_(dict.lookup("fields")),
meanScalarFields_(faItems_.size()),
meanVectorFields_(faItems_.size()),
meanSymmTensorFields_(faItems_.size()),
meanSphericalTensorFields_(faItems_.size()),
prime2MeanScalarFields_(faItems_.size()),
prime2MeanSymmTensorFields_(faItems_.size()),
nSteps_(faItems_.size(), 1),
totalTime_(faItems_.size(), obr_.time().deltaT().value())
{
// Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_))
{
active_ = false;
WarningIn
(
"fieldAverage::fieldAverage"
"("
"const word&,"
"const objectRegistry&,"
"const dictionary&,"
"const bool"
")"
) << "No fvMesh available, deactivating."
<< nl << endl;
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fieldAverage::~fieldAverage()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fieldAverage::read(const dictionary& dict)
{
if (active_)
{
faItems_.clear();
faItems_ = List<fieldAverageItem>(dict.lookup("fields"));
resetLists(faItems_.size());
initialise();
readAveragingProperties();
}
}
void Foam::fieldAverage::write()
{
if (active_)
{
calcAverages();
if (obr_.time().outputTime())
{
writeAverages();
writeAveragingProperties();
}
}
}
void Foam::fieldAverage::calcAverages()
{
Info<< "Calculating averages" << nl << endl;
forAll(faItems_, i)
{
nSteps_[i]++;
totalTime_[i] += obr_.time().deltaT().value();
}
addMeanSqrToPrime2Mean<scalar>(prime2MeanScalarFields_);
addMeanSqrToPrime2Mean<vector>(prime2MeanSymmTensorFields_);
calculateMeanFields<scalar>(meanScalarFields_);
calculateMeanFields<vector>(meanVectorFields_);
calculateMeanFields<symmTensor>(meanSymmTensorFields_);
calculateMeanFields<sphericalTensor>(meanSphericalTensorFields_);
calculatePrime2MeanFields<scalar>(prime2MeanScalarFields_);
calculatePrime2MeanFields<vector>(prime2MeanSymmTensorFields_);
}
void Foam::fieldAverage::writeAverages() const
{
writeFieldList<scalar>(meanScalarFields_);
writeFieldList<vector>(meanVectorFields_);
writeFieldList<symmTensor>(meanSymmTensorFields_);
writeFieldList<sphericalTensor>(meanSphericalTensorFields_);
writeFieldList<scalar>(prime2MeanScalarFields_);
writeFieldList<symmTensor>(prime2MeanSymmTensorFields_);
}
void Foam::fieldAverage::writeAveragingProperties() const
{
IOdictionary propsDict
(
IOobject
(
"fieldAveragingProperties",
obr_.time().timeName(),
"uniform",
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
)
);
forAll(faItems_, i)
{
const word fieldName = faItems_[i].fieldName();
propsDict.add(fieldName, dictionary());
propsDict.subDict(fieldName).add("nSteps", nSteps_[i]);
propsDict.subDict(fieldName).add("totalTime", totalTime_[i]);
}
propsDict.regIOobject::write();
}
void Foam::fieldAverage::readAveragingProperties()
{
IFstream propsFile
(
obr_.time().path()/obr_.time().timeName()
/"uniform"/"fieldAveragingProperties"
);
if (!propsFile.good())
{
return;
}
dictionary propsDict(dictionary::null, propsFile);
forAll(faItems_, i)
{
const word& fieldName = faItems_[i].fieldName();
if (propsDict.found(fieldName))
{
dictionary fieldDict(propsDict.subDict(fieldName));
nSteps_[i] = readLabel(fieldDict.lookup("nSteps"));
totalTime_[i] = readScalar(fieldDict.lookup("totalTime"));
}
}
}
void Foam::fieldAverage::updateMesh(const mapPolyMesh&)
{
// Do nothing
}
void Foam::fieldAverage::movePoints(const pointField&)
{
// Do nothing
}
// ************************************************************************* //

View File

@ -0,0 +1,293 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fieldAverage
Description
Calculates the field averages given list of fieldAverageItems, e.g.
@verbatim
fields
(
U
{
mean on;
prime2Mean on;
base time; // ensemble
}
p
{
mean on;
prime2Mean on;
base time; // ensemble
}
);
@endverbatim
Member function calcAverages() calculates the averages.
Member function fieldAverage::write() calls calcAverages(). Average
field names are constructed by concatenating the base field with the
averaging type, e.g.
- base field, U
- arithmetic mean field, UMean
- prime-squared field, UPrime2Mean
Information regarding the number of averaging steps, and total averaging
time are written on a (base) per-field basis to the
fieldAveragingProperties dictionary, located in <time>/uniform
SourceFiles
fieldAverage.C
fieldAverageTemplates.C
IOfieldAverage.H
\*---------------------------------------------------------------------------*/
#ifndef fieldAverage_H
#define fieldAverage_H
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class fieldAverageItem;
class OFstream;
template<class Type>
class List;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class fieldAverage Declaration
\*---------------------------------------------------------------------------*/
class fieldAverage
{
protected:
// Private data
//- Name of this set of field averages.
word name_;
//- Database this class is registered to
const objectRegistry& obr_;
//- On/off switch
bool active_;
//- List of field average items, describing waht averages to be
// calculated and output
List<fieldAverageItem> faItems_;
// File and field name extensions
//- Mean average
static const word EXT_MEAN;
//- Prime-squared average
static const word EXT_PRIME2MEAN;
// Lists of averages
// Arithmetic mean fields
PtrList<volScalarField> meanScalarFields_;
PtrList<volVectorField> meanVectorFields_;
PtrList<volSymmTensorField> meanSymmTensorFields_;
PtrList<volSphericalTensorField> meanSphericalTensorFields_;
// Prime-squared fields - applicable to volVectorFields only
PtrList<volScalarField> prime2MeanScalarFields_;
PtrList<volSymmTensorField> prime2MeanSymmTensorFields_;
// Counters
//- Integration steps counter
List<label> nSteps_;
//- Total time counter
List<scalar> totalTime_;
// Private Member Functions
// Initialisation routines
//- Reset size of lists (clear existing values)
void resetLists(const label nItems);
//- Intitialise averaging. Check requested field averages are
// valid, and populate field lists
void initialise();
//- Add mean average fields to PtrLists
template<class Type>
void addMeanFields
(
const label fieldi,
PtrList<GeometricField<Type, fvPatchField, volMesh> >&
fieldList
);
//- Add prime-squared average fields to PtrLists
template<class Type1, class Type2>
void addPrime2MeanFields
(
const label fieldi,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
fieldList
);
// Calculation functions
//- Main calculation routine
virtual void calcAverages();
//- Calculate mean average fields
template<class Type>
void calculateMeanFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh> >&
fieldList
);
//- Add mean-squared field value to prime-squared mean field
template<class Type1, class Type2>
void addMeanSqrToPrime2Mean
(
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
fieldList
);
//- Calculate prime-squared average fields
template<class Type1, class Type2>
void calculatePrime2MeanFields
(
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
fieldList
);
// I-O
//- Write averages
virtual void writeAverages() const;
//- Write fields
template<class Type>
void writeFieldList
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
fieldList
) const;
//- Write averaging properties - steps and time
void writeAveragingProperties() const;
//- Read averaging properties - steps and time
void readAveragingProperties();
// Functions to be over-ridden from IOoutputFilter class
//- Update mesh
virtual void updateMesh(const mapPolyMesh&);
//- Move points
virtual void movePoints(const Field<point>&);
//- Disallow default bitwise copy construct
fieldAverage(const fieldAverage&);
//- Disallow default bitwise assignment
void operator=(const fieldAverage&);
public:
//- Runtime type information
TypeName("fieldAverage");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
fieldAverage
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
);
//- Destructor
virtual ~fieldAverage();
// Member Functions
//- Return name of the set of field averages
virtual const word& name() const
{
return name_;
}
//- Read the field average data
virtual void read(const dictionary&);
//- Calculate the field average data and write
virtual void write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "fieldAverageTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,243 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2005 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldAverageItem.H"
#include "volFields.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::fieldAverage::addMeanFields
(
const label fieldi,
PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList
)
{
if (faItems_[fieldi].mean())
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const word& fieldName = faItems_[fieldi].fieldName();
const fieldType& baseField = mesh.lookupObject<fieldType>(fieldName);
const word meanFieldName = fieldName + EXT_MEAN;
Info<< "Reading/calculating field " << meanFieldName << nl << endl;
fieldList.set
(
fieldi,
new fieldType
(
IOobject
(
meanFieldName,
mesh.time().timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
baseField
)
);
}
}
template<class Type1, class Type2>
void Foam::fieldAverage::addPrime2MeanFields
(
const label fieldi,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& fieldList
)
{
if (faItems_[fieldi].mean())
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const word& fieldName = faItems_[fieldi].fieldName();
const fieldType1& baseField = mesh.lookupObject<fieldType1>(fieldName);
const fieldType1& meanField =
mesh.lookupObject<fieldType1>(fieldName + EXT_MEAN);
const word meanFieldName = fieldName + EXT_PRIME2MEAN;
Info<< "Reading/calculating field " << meanFieldName << nl << endl;
fieldList.set
(
fieldi,
new fieldType2
(
IOobject
(
meanFieldName,
mesh.time().timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
sqr(baseField) - sqr(meanField)
)
);
}
}
template<class Type>
void Foam::fieldAverage::calculateMeanFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const scalar dt = obr_.time().deltaT().value();
forAll(faItems_, i)
{
if (fieldList.set(i))
{
if (faItems_[i].mean())
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const word& fieldName = faItems_[i].fieldName();
const fieldType& baseField =
mesh.lookupObject<fieldType>(fieldName);
fieldType& meanField = fieldList[i];
scalar alpha = 0.0;
scalar beta = 0.0;
if (faItems_[i].timeBase())
{
alpha = (totalTime_[i] - dt)/totalTime_[i];
beta = dt/totalTime_[i];
}
else
{
alpha = scalar(nSteps_[i] - 1)/scalar(nSteps_[i]);
beta = 1.0/scalar(nSteps_[i]);
}
meanField = alpha*meanField + beta*baseField;
}
}
}
}
template<class Type1, class Type2>
void Foam::fieldAverage::calculatePrime2MeanFields
(
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& fieldList
)
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
const scalar dt = obr_.time().deltaT().value();
forAll(faItems_, i)
{
if (fieldList.set(i))
{
if (faItems_[i].prime2Mean())
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const word& fieldName = faItems_[i].fieldName();
const fieldType1& baseField =
mesh.lookupObject<fieldType1>(fieldName);
const fieldType1& meanField =
mesh.lookupObject<fieldType1>(fieldName + EXT_MEAN);
fieldType2& prime2MeanField = fieldList[i];
scalar alpha = 0.0;
scalar beta = 0.0;
if (faItems_[i].timeBase())
{
alpha = (totalTime_[i] - dt)/totalTime_[i];
beta = dt/totalTime_[i];
}
else
{
alpha = scalar(nSteps_[i] - 1)/scalar(nSteps_[i]);
beta = 1.0/scalar(nSteps_[i]);
}
prime2MeanField =
alpha*prime2MeanField
+ beta*sqr(baseField)
- sqr(meanField);
}
}
}
}
template<class Type1, class Type2>
void Foam::fieldAverage::addMeanSqrToPrime2Mean
(
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& fieldList
)
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
forAll(faItems_, i)
{
if (fieldList.set(i))
{
if (faItems_[i].prime2Mean())
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const word& fieldName = faItems_[i].fieldName();
const fieldType1& meanField =
mesh.lookupObject<fieldType1>(fieldName + EXT_MEAN);
fieldType2& prime2MeanField = fieldList[i];
prime2MeanField += sqr(meanField);
}
}
}
}
template<class Type>
void Foam::fieldAverage::writeFieldList
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList
) const
{
forAll(fieldList, i)
{
if (fieldList.set(i))
{
fieldList[i].write();
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldAverageFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(fieldAverageFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
fieldAverageFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Typedef
fieldAverageFunctionObject
Description
FunctionObject wrapper around fieldAverage to allow them to be created
via the functions list within controlDict.
SourceFiles
fieldAverageFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef fieldAverageFunctionObject_H
#define fieldAverageFunctionObject_H
#include "fieldAverage.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<fieldAverage>
fieldAverageFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,90 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldAverageItem.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<>
const char* Foam::NamedEnum<Foam::fieldAverageItem::baseType, 2>::names[] =
{
"ensemble",
"time"
};
const Foam::NamedEnum<Foam::fieldAverageItem::baseType, 2>
Foam::fieldAverageItem::baseTypeNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldAverageItem::fieldAverageItem()
:
fieldName_("unknown"),
mean_(0),
prime2Mean_(0),
base_(ENSEMBLE)
{}
Foam::fieldAverageItem::fieldAverageItem(const fieldAverageItem& faItem)
:
fieldName_(faItem.fieldName_),
mean_(faItem.mean_),
prime2Mean_(faItem.prime2Mean_),
base_(faItem.base_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fieldAverageItem::~fieldAverageItem()
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::fieldAverageItem::operator=(const fieldAverageItem& rhs)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorIn
(
"Foam::fieldAverageItem::operator=(const Foam::fieldAverageItem&)"
) << "Attempted assignment to self" << nl
<< abort(FatalError);
}
// Set updated values
fieldName_ = rhs.fieldName_;
mean_ = rhs.mean_;
prime2Mean_ = rhs.prime2Mean_;
base_ = rhs.base_;
}
// ************************************************************************* //

View File

@ -0,0 +1,194 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::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; // ensemble
}
@endverbatim
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;
// 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
//- Enumeration defining the averaging base type
enum baseType
{
ENSEMBLE,
TIME
};
private:
// Private data
//- Field name
word fieldName_;
//- Compute mean flag
Switch mean_;
//- Compute prime-squared mean flag
Switch prime2Mean_;
//- Averaging base type names
static const NamedEnum<baseType, 2> baseTypeNames_;
//- Averaging base type
baseType base_;
// Private Member Functions
//- Disallow default bitwise copy construct
// fieldAverageItem(const fieldAverageItem&);
//- Disallow default bitwise assignment
// void operator=(const fieldAverageItem&);
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 const access to the prime-squared mean flag
const Switch& prime2Mean() const
{
return prime2Mean_;
}
//- Return averaging base type name
const word base() const
{
return baseTypeNames_[base_];
}
//- Return true if base is ensemble
Switch ensembleBase() const
{
return base_ == ENSEMBLE;
}
//- Return true if base is time
Switch timeBase() const
{
return base_ == TIME;
}
// Member Operators
void operator=(const fieldAverageItem&);
// IOstream Operators
friend Istream& operator>>(Istream&, fieldAverageItem&);
friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldAverageItem.H"
#include "IOstreams.H"
#include "dictionaryEntry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldAverageItem::fieldAverageItem(Istream& is)
:
fieldName_("unknown"),
mean_(0),
prime2Mean_(0)
{
is.check("Foam::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")];
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, fieldAverageItem& faItem)
{
is.check
(
"Foam::Istream& Foam::operator>>"
"(Foam::Istream&, Foam::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")];
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const fieldAverageItem& faItem)
{
os.check
(
"Foam::Ostream& Foam::operator<<"
"(Foam::Ostream&, const Foam::fieldAverageItem&)"
);
os<< faItem.fieldName_ << nl;
os<< token::BEGIN_BLOCK << nl;
os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
os.writeKeyword("prime2Mean") << faItem.mean_
<< token::END_STATEMENT << nl;
os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
<< token::END_STATEMENT << nl;
os<< token::END_BLOCK << nl;
os.check
(
"Foam::Ostream& Foam::operator<<"
"(Foam::Ostream&, const Foam::fieldAverageItem&)"
);
return os;
}
// ************************************************************************* //