ENH: Updated weight field initialisation for fieldValues function object

This commit is contained in:
andy
2011-08-16 18:05:06 +01:00
parent c2dd153a14
commit 53f332bc60
6 changed files with 55 additions and 39 deletions

View File

@ -145,22 +145,7 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
if (operation_ == opWeightedAverage) if (operation_ == opWeightedAverage)
{ {
dict.lookup("weightField") >> weightFieldName_; dict.lookup("weightField") >> weightFieldName_;
if Info<< " weight field = " << weightFieldName_;
(
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<< nl << endl; Info<< nl << endl;

View File

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

View File

@ -45,7 +45,8 @@ bool Foam::fieldValues::cellSource::validField(const word& fieldName) const
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues
( (
const word& fieldName const word& fieldName,
const bool mustGet
) const ) const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> vf; 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)); 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)); 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())); scalarField V(filterField(mesh().V()));
combineFields(V); combineFields(V);
scalarField weightField(setFieldValues<scalar>(weightFieldName_)); scalarField weightField;
if (operation_ == opWeightedAverage)
{
weightField = setFieldValues<scalar>(weightFieldName_, true);
}
combineFields(weightField); combineFields(weightField);
if (Pstream::master()) if (Pstream::master())

View File

@ -284,23 +284,7 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
if (operation_ == opWeightedAverage) if (operation_ == opWeightedAverage)
{ {
dict.lookup("weightField") >> weightFieldName_; dict.lookup("weightField") >> weightFieldName_;
if Info<< " weight field = " << weightFieldName_;
(
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<< nl << endl; Info<< nl << endl;

View File

@ -200,7 +200,11 @@ protected:
//- Return field values by looking up field name //- Return field values by looking up field name
template<class Type> 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 //- Apply the 'operation' to the values
template<class Type> template<class Type>

View File

@ -52,7 +52,8 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
( (
const word& fieldName const word& fieldName,
const bool mustGet
) const ) const
{ {
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf; 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)); return tmp<Field<Type> >(new Field<Type>(0));
} }
@ -139,7 +154,13 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
if (ok) if (ok)
{ {
Field<Type> values(getFieldValues<Type>(fieldName)); Field<Type> values(getFieldValues<Type>(fieldName));
scalarField weightField(getFieldValues<scalar>(weightFieldName_)); scalarField weightField;
if (operation_ == opWeightedAverage)
{
weightField = getFieldValues<scalar>(weightFieldName_, true);
}
scalarField magSf; scalarField magSf;
if (surfacePtr_.valid()) if (surfacePtr_.valid())