mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Updated weight field initialisation for fieldValues function object
This commit is contained in:
@ -145,23 +145,8 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
|
|||||||
if (operation_ == opWeightedAverage)
|
if (operation_ == opWeightedAverage)
|
||||||
{
|
{
|
||||||
dict.lookup("weightField") >> weightFieldName_;
|
dict.lookup("weightField") >> weightFieldName_;
|
||||||
if
|
|
||||||
(
|
|
||||||
obr().foundObject<volScalarField>(weightFieldName_)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Info<< " weight field = " << 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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())
|
||||||
|
|||||||
@ -284,24 +284,8 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
|
|||||||
if (operation_ == opWeightedAverage)
|
if (operation_ == opWeightedAverage)
|
||||||
{
|
{
|
||||||
dict.lookup("weightField") >> weightFieldName_;
|
dict.lookup("weightField") >> weightFieldName_;
|
||||||
if
|
|
||||||
(
|
|
||||||
obr().foundObject<volScalarField>(weightFieldName_)
|
|
||||||
|| obr().foundObject<surfaceScalarField>(weightFieldName_)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Info<< " weight field = " << 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
@ -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())
|
||||||
|
|||||||
Reference in New Issue
Block a user