Merge branch 'master' into AMI

This commit is contained in:
andy
2011-08-24 09:31:13 +01:00
20 changed files with 241 additions and 101 deletions

View File

@ -68,6 +68,7 @@ functions
mean on;
prime2Mean on;
base time;
window 0.01; // optional averaging window
}
p
@ -75,6 +76,7 @@ functions
mean on;
prime2Mean on;
base time;
window 0.01; // optional averaging window
}
);
}

View File

@ -377,8 +377,7 @@ void Foam::fieldAverage::execute()
void Foam::fieldAverage::end()
{
}
{}
void Foam::fieldAverage::write()

View File

@ -149,7 +149,7 @@ const
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const scalar dt = obr_.time().deltaTValue();
scalar dt = obr_.time().deltaTValue();
forAll(faItems_, i)
{
@ -163,17 +163,24 @@ const
obr_.lookupObject<fieldType>(meanFieldList[i])
);
scalar alpha = 0.0;
scalar beta = 0.0;
if (faItems_[i].timeBase())
scalar Dt = totalTime_[i];
if (faItems_[i].iterBase())
{
alpha = (totalTime_[i] - dt)/totalTime_[i];
beta = dt/totalTime_[i];
dt = 1.0;
Dt = scalar(totalIter_[i]);
}
else
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (faItems_[i].window() > 0)
{
alpha = scalar(totalIter_[i] - 1)/scalar(totalIter_[i]);
beta = 1.0/scalar(totalIter_[i]);
const scalar w = faItems_[i].window();
if (Dt - dt >= w)
{
alpha = (w - dt)/w;
beta = dt/w;
}
}
meanField = alpha*meanField + beta*baseField;
@ -192,7 +199,7 @@ void Foam::fieldAverage::calculatePrime2MeanFields
typedef GeometricField<Type1, fvPatchField, volMesh> fieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> fieldType2;
const scalar dt = obr_.time().deltaTValue();
scalar dt = obr_.time().deltaTValue();
forAll(faItems_, i)
{
@ -213,17 +220,24 @@ void Foam::fieldAverage::calculatePrime2MeanFields
obr_.lookupObject<fieldType2>(prime2MeanFieldList[i])
);
scalar alpha = 0.0;
scalar beta = 0.0;
if (faItems_[i].timeBase())
scalar Dt = totalTime_[i];
if (faItems_[i].iterBase())
{
alpha = (totalTime_[i] - dt)/totalTime_[i];
beta = dt/totalTime_[i];
dt = 1.0;
Dt = scalar(totalIter_[i]);
}
else
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (faItems_[i].window() > 0)
{
alpha = scalar(totalIter_[i] - 1)/scalar(totalIter_[i]);
beta = 1.0/scalar(totalIter_[i]);
const scalar w = faItems_[i].window();
if (Dt - dt >= w)
{
alpha = (w - dt)/w;
beta = dt/w;
}
}
prime2MeanField =

View File

@ -53,7 +53,8 @@ Foam::fieldAverageItem::fieldAverageItem()
fieldName_("unknown"),
mean_(0),
prime2Mean_(0),
base_(ITER)
base_(ITER),
window_(-1.0)
{}
@ -62,7 +63,8 @@ Foam::fieldAverageItem::fieldAverageItem(const fieldAverageItem& faItem)
fieldName_(faItem.fieldName_),
mean_(faItem.mean_),
prime2Mean_(faItem.prime2Mean_),
base_(faItem.base_)
base_(faItem.base_),
window_(faItem.window_)
{}
@ -91,6 +93,7 @@ void Foam::fieldAverageItem::operator=(const fieldAverageItem& rhs)
mean_ = rhs.mean_;
prime2Mean_ = rhs.prime2Mean_;
base_ = rhs.base_;
window_ = rhs.window_;
}

View File

@ -33,9 +33,13 @@ Description
mean on;
prime2Mean on;
base time; // iteration
window 200; // optional averaging window
}
\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
@ -100,6 +104,9 @@ private:
//- Averaging base type
baseType base_;
//- Averaging window - defaults to -1 for 'all iters/time'
scalar window_;
public:
@ -148,7 +155,7 @@ public:
}
//- Return true if base is ITER
Switch ITERBase() const
Switch iterBase() const
{
return base_ == ITER;
}
@ -159,6 +166,11 @@ public:
return base_ == TIME;
}
scalar window() const
{
return window_;
}
// Member Operators
@ -177,7 +189,8 @@ public:
a.fieldName_ == b.fieldName_
&& a.mean_ == b.mean_
&& a.prime2Mean_ == b.prime2Mean_
&& a.base_ == b.base_;
&& a.base_ == b.base_
&& a.window_ == b.window_;
}
friend bool operator!=

View File

@ -33,7 +33,9 @@ Foam::fieldAverageItem::fieldAverageItem(Istream& is)
:
fieldName_("unknown"),
mean_(0),
prime2Mean_(0)
prime2Mean_(0),
base_(ITER),
window_(-1.0)
{
is.check("Foam::fieldAverageItem::fieldAverageItem(Foam::Istream&)");
@ -43,6 +45,7 @@ Foam::fieldAverageItem::fieldAverageItem(Istream& is)
entry.lookup("mean") >> mean_;
entry.lookup("prime2Mean") >> prime2Mean_;
base_ = baseTypeNames_[entry.lookup("base")];
window_ = entry.lookupOrDefault<scalar>("window", -1.0);
}
@ -62,6 +65,7 @@ Foam::Istream& Foam::operator>>(Istream& is, fieldAverageItem& faItem)
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);
return is;
}
@ -80,7 +84,15 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const fieldAverageItem& faItem)
os.writeKeyword("prime2Mean") << faItem.mean_
<< token::END_STATEMENT << nl;
os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
<< token::END_STATEMENT << nl << token::END_BLOCK << nl;
<< token::END_STATEMENT << nl;
if (faItem.window_ > 0)
{
os.writeKeyword("window") << faItem.window_
<< token::END_STATEMENT << nl;
}
os << token::END_BLOCK << nl;
os.check
(

View File

@ -145,22 +145,7 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
if (operation_ == opWeightedAverage)
{
dict.lookup("weightField") >> weightFieldName_;
if
(
obr().foundObject<volScalarField>(weightFieldName_)
)
{
Info<< " weight field = " << weightFieldName_;
}
else
{
FatalErrorIn("cellSource::initialise()")
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Weight field " << weightFieldName_
<< " must be a " << volScalarField::typeName
<< nl << exit(FatalError);
}
Info<< " weight field = " << weightFieldName_;
}
Info<< nl << endl;

View File

@ -157,7 +157,8 @@ protected:
template<class Type>
tmp<Field<Type> > setFieldValues
(
const word& fieldName
const word& fieldName,
const bool mustGet = false
) const;
//- Apply the 'operation' to the values

View File

@ -45,7 +45,8 @@ bool Foam::fieldValues::cellSource::validField(const word& fieldName) const
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues
(
const word& fieldName
const word& fieldName,
const bool mustGet
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
@ -55,6 +56,20 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues
return filterField(obr_.lookupObject<vf>(fieldName));
}
if (mustGet)
{
FatalErrorIn
(
"Foam::tmp<Foam::Field<Type> > "
"Foam::fieldValues::cellSource::setFieldValues"
"("
"const word&, "
"const bool"
") const"
) << "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type> >(new Field<Type>(0.0));
}
@ -125,7 +140,13 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
scalarField V(filterField(mesh().V()));
combineFields(V);
scalarField weightField(setFieldValues<scalar>(weightFieldName_));
scalarField weightField;
if (operation_ == opWeightedAverage)
{
weightField = setFieldValues<scalar>(weightFieldName_, true);
}
combineFields(weightField);
if (Pstream::master())

View File

@ -284,23 +284,7 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
if (operation_ == opWeightedAverage)
{
dict.lookup("weightField") >> weightFieldName_;
if
(
obr().foundObject<volScalarField>(weightFieldName_)
|| obr().foundObject<surfaceScalarField>(weightFieldName_)
)
{
Info<< " weight field = " << weightFieldName_;
}
else
{
FatalErrorIn("faceSource::initialise()")
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Weight field " << weightFieldName_
<< " must be either a " << volScalarField::typeName << " or "
<< surfaceScalarField::typeName << nl << exit(FatalError);
}
Info<< " weight field = " << weightFieldName_;
}
Info<< nl << endl;

View File

@ -200,7 +200,11 @@ protected:
//- Return field values by looking up field name
template<class Type>
tmp<Field<Type> > getFieldValues(const word& fieldName) const;
tmp<Field<Type> > getFieldValues
(
const word& fieldName,
const bool mustGet = false
) const;
//- Apply the 'operation' to the values
template<class Type>

View File

@ -52,7 +52,8 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
(
const word& fieldName
const word& fieldName,
const bool mustGet
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
@ -74,6 +75,20 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
}
}
if (mustGet)
{
FatalErrorIn
(
"Foam::tmp<Foam::Field<Type> > "
"Foam::fieldValues::faceSource::getFieldValues"
"("
"const word&, "
"const bool"
") const"
) << "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type> >(new Field<Type>(0));
}
@ -139,7 +154,13 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
if (ok)
{
Field<Type> values(getFieldValues<Type>(fieldName));
scalarField weightField(getFieldValues<scalar>(weightFieldName_));
scalarField weightField;
if (operation_ == opWeightedAverage)
{
weightField = getFieldValues<scalar>(weightFieldName_, true);
}
scalarField magSf;
if (surfacePtr_.valid())