Commit c350f695 authored by mattijs's avatar mattijs
Browse files

register averages

parent 5ce9333c
......@@ -46,26 +46,45 @@ const Foam::word Foam::fieldAverage::EXT_PRIME2MEAN = "Prime2Mean";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fieldAverage::checkoutFields(const wordList& fieldNames) const
{
forAll(fieldNames, i)
{
if (fieldNames[i] != word::null)
{
obr_.checkOut(*obr_[fieldNames[i]]);
}
}
}
void Foam::fieldAverage::resetLists(const label nItems)
{
checkoutFields(meanScalarFields_);
meanScalarFields_.clear();
meanScalarFields_.setSize(nItems);
checkoutFields(meanVectorFields_);
meanVectorFields_.clear();
meanVectorFields_.setSize(nItems);
checkoutFields(meanSphericalTensorFields_);
meanSphericalTensorFields_.clear();
meanSphericalTensorFields_.setSize(nItems);
checkoutFields(meanSymmTensorFields_);
meanSymmTensorFields_.clear();
meanSymmTensorFields_.setSize(nItems);
checkoutFields(meanTensorFields_);
meanTensorFields_.clear();
meanTensorFields_.setSize(nItems);
checkoutFields(prime2MeanScalarFields_);
prime2MeanScalarFields_.clear();
prime2MeanScalarFields_.setSize(nItems);
checkoutFields(prime2MeanSymmTensorFields_);
prime2MeanSymmTensorFields_.clear();
prime2MeanSymmTensorFields_.setSize(nItems);
......@@ -128,7 +147,7 @@ void Foam::fieldAverage::initialise()
if (obr_.foundObject<volScalarField>(fieldName))
{
addPrime2MeanField<scalar>
addPrime2MeanField<scalar, scalar>
(
i,
meanScalarFields_,
......@@ -137,7 +156,7 @@ void Foam::fieldAverage::initialise()
}
else if (obr_.foundObject<volVectorField>(fieldName))
{
addPrime2MeanField<vector>
addPrime2MeanField<vector, symmTensor>
(
i,
meanVectorFields_,
......@@ -188,12 +207,12 @@ Foam::fieldAverage::fieldAverage
active_ = false;
WarningIn
(
"fieldAverage::fieldAverage"
"("
"const word&,"
"const objectRegistry&,"
"const dictionary&,"
"const bool"
"fieldAverage::fieldAverage\n"
"(\n"
"const word&,\n"
"const objectRegistry&,\n"
"const dictionary&,\n"
"const bool\n"
")"
) << "No fvMesh available, deactivating."
<< nl << endl;
......@@ -255,12 +274,12 @@ void Foam::fieldAverage::calcAverages()
totalTime_[i] += obr_.time().deltaT().value();
}
addMeanSqrToPrime2Mean<scalar>
addMeanSqrToPrime2Mean<scalar, scalar>
(
meanScalarFields_,
prime2MeanScalarFields_
);
addMeanSqrToPrime2Mean<vector>
addMeanSqrToPrime2Mean<vector, symmTensor>
(
meanVectorFields_,
prime2MeanSymmTensorFields_
......@@ -272,12 +291,12 @@ void Foam::fieldAverage::calcAverages()
calculateMeanFields<symmTensor>(meanSymmTensorFields_);
calculateMeanFields<tensor>(meanTensorFields_);
calculatePrime2MeanFields<scalar>
calculatePrime2MeanFields<scalar, scalar>
(
meanScalarFields_,
prime2MeanScalarFields_
);
calculatePrime2MeanFields<vector>
calculatePrime2MeanFields<vector, symmTensor>
(
meanVectorFields_,
prime2MeanSymmTensorFields_
......@@ -316,7 +335,7 @@ void Foam::fieldAverage::writeAveragingProperties() const
forAll(faItems_, i)
{
const word fieldName = faItems_[i].fieldName();
const word& fieldName = faItems_[i].fieldName();
propsDict.add(fieldName, dictionary());
propsDict.subDict(fieldName).add("totalIter", totalIter_[i]);
propsDict.subDict(fieldName).add("totalTime", totalTime_[i]);
......
......@@ -121,7 +121,7 @@ protected:
//- Clean restart flag
Switch cleanRestart_;
//- List of field average items, describing waht averages to be
//- List of field average items, describing what averages to be
// calculated and output
List<fieldAverageItem> faItems_;
......@@ -137,15 +137,15 @@ protected:
// Lists of averages
// Arithmetic mean fields
PtrList<volScalarField> meanScalarFields_;
PtrList<volVectorField> meanVectorFields_;
PtrList<volSphericalTensorField> meanSphericalTensorFields_;
PtrList<volSymmTensorField> meanSymmTensorFields_;
PtrList<volTensorField> meanTensorFields_;
wordList meanScalarFields_;
wordList meanVectorFields_;
wordList meanSphericalTensorFields_;
wordList meanSymmTensorFields_;
wordList meanTensorFields_;
// Prime-squared fields - applicable to volVectorFields only
PtrList<volScalarField> prime2MeanScalarFields_;
PtrList<volSymmTensorField> prime2MeanSymmTensorFields_;
wordList prime2MeanScalarFields_;
wordList prime2MeanSymmTensorFields_;
// Counters
......@@ -161,6 +161,9 @@ protected:
// Initialisation routines
//- Checkout fields (causes deletion) from the database
void checkoutFields(const wordList&) const;
//- Reset size of lists (clear existing values)
void resetLists(const label nItems);
......@@ -170,20 +173,16 @@ protected:
//- Add mean average field to PtrList
template<class Type>
void addMeanField
(
const label,
PtrList<GeometricField<Type, fvPatchField, volMesh> >&
);
void addMeanField(const label, wordList&) const;
//- Add prime-squared average field to PtrList
template<class Type1, class Type2>
void addPrime2MeanField
(
const label,
PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
);
const wordList&,
wordList&
) const;
// Calculation functions
......@@ -193,26 +192,23 @@ protected:
//- Calculate mean average fields
template<class Type>
void calculateMeanFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh> >&
);
void calculateMeanFields(const wordList&) const;
//- Add mean-squared field value to prime-squared mean field
template<class Type1, class Type2>
void addMeanSqrToPrime2Mean
(
PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
);
const wordList&,
const wordList&
) const;
//- Calculate prime-squared average fields
template<class Type1, class Type2>
void calculatePrime2MeanFields
(
PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
);
const wordList&,
const wordList&
) const;
// I-O
......@@ -222,11 +218,7 @@ protected:
//- Write fields
template<class Type>
void writeFieldList
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
fieldList
) const;
void writeFieldList(const wordList&) const;
//- Write averaging properties - steps and time
void writeAveragingProperties() const;
......
......@@ -34,22 +34,36 @@ template<class Type>
void Foam::fieldAverage::addMeanField
(
const label fieldi,
PtrList<GeometricField<Type, fvPatchField, volMesh> >& meanFieldList
)
wordList& meanFieldList
) const
{
if (faItems_[fieldi].mean())
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const word& fieldName = faItems_[fieldi].fieldName();
const fieldType& baseField = obr_.lookupObject<fieldType>(fieldName);
const word meanFieldName = fieldName + EXT_MEAN;
Info<< "Reading/calculating field " << meanFieldName << nl << endl;
meanFieldList.set
(
fieldi,
new fieldType
if (obr_.foundObject<fieldType>(meanFieldName))
{
meanFieldList[fieldi] = meanFieldName;
}
else if (obr_.found(meanFieldName))
{
Info<< "Cannot allocate average field " << meanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging." << nl << endl;
meanFieldList[fieldi] = word::null;
}
else
{
const fieldType& baseField =
obr_.lookupObject<fieldType>(fieldName);
fieldType* fPtr = new fieldType
(
IOobject
(
......@@ -57,12 +71,16 @@ void Foam::fieldAverage::addMeanField
obr_.time().timeName(),
obr_,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
IOobject::NO_WRITE
),
baseField
)
);
);
// Store on registry
fPtr->store();
meanFieldList[fieldi] = meanFieldName;
}
}
}
......@@ -71,25 +89,39 @@ template<class Type1, class Type2>
void Foam::fieldAverage::addPrime2MeanField
(
const label fieldi,
PtrList<GeometricField<Type1, fvPatchField, volMesh> >& meanFieldList,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& prime2MeanFieldList
)
const wordList& meanFieldList,
wordList& prime2MeanFieldList
) const
{
if (faItems_[fieldi].mean() && meanFieldList.set(fieldi))
if (faItems_[fieldi].mean() && meanFieldList[fieldi] != word::null)
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
const word& fieldName = faItems_[fieldi].fieldName();
const fieldType1& baseField = obr_.lookupObject<fieldType1>(fieldName);
const fieldType1& meanField = meanFieldList[fieldi];
const word meanFieldName = fieldName + EXT_PRIME2MEAN;
Info<< "Reading/calculating field " << meanFieldName << nl << endl;
prime2MeanFieldList.set
(
fieldi,
new fieldType2
if (obr_.foundObject<fieldType2>(meanFieldName))
{
prime2MeanFieldList[fieldi] = meanFieldName;
}
else if (obr_.found(meanFieldName))
{
Info<< "Cannot allocate average field " << meanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging." << nl << endl;
prime2MeanFieldList[fieldi] = word::null;
}
else
{
const fieldType1& baseField =
obr_.lookupObject<fieldType1>(fieldName);
const fieldType1& meanField =
obr_.lookupObject<fieldType1>(meanFieldList[fieldi]);
fieldType2* fPtr = new fieldType2
(
IOobject
(
......@@ -97,21 +129,23 @@ void Foam::fieldAverage::addPrime2MeanField
obr_.time().timeName(),
obr_,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
IOobject::NO_WRITE
),
sqr(baseField) - sqr(meanField)
)
);
);
// Store on registry
fPtr->store();
prime2MeanFieldList[fieldi] = meanFieldName;
}
}
}
template<class Type>
void Foam::fieldAverage::calculateMeanFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh> >& meanFieldList
)
void Foam::fieldAverage::calculateMeanFields(const wordList& meanFieldList)
const
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
......@@ -119,12 +153,15 @@ void Foam::fieldAverage::calculateMeanFields
forAll(faItems_, i)
{
if (faItems_[i].mean() && meanFieldList.set(i))
if (faItems_[i].mean() && meanFieldList[i] != word::null)
{
const word& fieldName = faItems_[i].fieldName();
const fieldType& baseField =
obr_.lookupObject<fieldType>(fieldName);
fieldType& meanField = meanFieldList[i];
fieldType& meanField = const_cast<fieldType&>
(
obr_.lookupObject<fieldType>(meanFieldList[i])
);
scalar alpha = 0.0;
scalar beta = 0.0;
......@@ -148,9 +185,9 @@ void Foam::fieldAverage::calculateMeanFields
template<class Type1, class Type2>
void Foam::fieldAverage::calculatePrime2MeanFields
(
PtrList<GeometricField<Type1, fvPatchField, volMesh> >& meanFieldList,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& prime2MeanFieldList
)
const wordList& meanFieldList,
const wordList& prime2MeanFieldList
) const
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
......@@ -162,15 +199,19 @@ void Foam::fieldAverage::calculatePrime2MeanFields
if
(
faItems_[i].prime2Mean()
&& meanFieldList.set(i)
&& prime2MeanFieldList.set(i)
&& meanFieldList[i] != word::null
&& prime2MeanFieldList[i] != word::null
)
{
const word& fieldName = faItems_[i].fieldName();
const fieldType1& baseField =
obr_.lookupObject<fieldType1>(fieldName);
const fieldType1& meanField = meanFieldList[i];
fieldType2& prime2MeanField = prime2MeanFieldList[i];
const fieldType1& meanField =
obr_.lookupObject<fieldType1>(meanFieldList[i]);
fieldType2& prime2MeanField = const_cast<fieldType2&>
(
obr_.lookupObject<fieldType2>(prime2MeanFieldList[i])
);
scalar alpha = 0.0;
scalar beta = 0.0;
......@@ -197,9 +238,9 @@ void Foam::fieldAverage::calculatePrime2MeanFields
template<class Type1, class Type2>
void Foam::fieldAverage::addMeanSqrToPrime2Mean
(
PtrList<GeometricField<Type1, fvPatchField, volMesh> >& meanFieldList,
PtrList<GeometricField<Type2, fvPatchField, volMesh> >& prime2MeanFieldList
)
const wordList& meanFieldList,
const wordList& prime2MeanFieldList
) const
{
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
......@@ -209,12 +250,16 @@ void Foam::fieldAverage::addMeanSqrToPrime2Mean
if
(
faItems_[i].prime2Mean()
&& meanFieldList.set(i)
&& prime2MeanFieldList.set(i)
&& meanFieldList[i] != word::null
&& prime2MeanFieldList[i] != word::null
)
{
const fieldType1& meanField = meanFieldList[i];
fieldType2& prime2MeanField = prime2MeanFieldList[i];
const fieldType1& meanField =
obr_.lookupObject<fieldType1>(meanFieldList[i]);
fieldType2& prime2MeanField = const_cast<fieldType2&>
(
obr_.lookupObject<fieldType2>(prime2MeanFieldList[i])
);
prime2MeanField += sqr(meanField);
}
......@@ -223,16 +268,16 @@ void Foam::fieldAverage::addMeanSqrToPrime2Mean
template<class Type>
void Foam::fieldAverage::writeFieldList
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList
) const
void Foam::fieldAverage::writeFieldList(const wordList& fieldList) const
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
forAll(fieldList, i)
{
if (fieldList.set(i))
if (fieldList[i] != word::null)
{
fieldList[i].write();
const fieldType& f = obr_.lookupObject<fieldType>(fieldList[i]);
f.write();
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment