From 53f332bc607cf61fe477ad378e0a66a1040c8c18 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 16 Aug 2011 18:05:06 +0100 Subject: [PATCH] ENH: Updated weight field initialisation for fieldValues function object --- .../field/fieldValues/cellSource/cellSource.C | 17 +------------ .../field/fieldValues/cellSource/cellSource.H | 3 ++- .../cellSource/cellSourceTemplates.C | 25 +++++++++++++++++-- .../field/fieldValues/faceSource/faceSource.C | 18 +------------ .../field/fieldValues/faceSource/faceSource.H | 6 ++++- .../faceSource/faceSourceTemplates.C | 25 +++++++++++++++++-- 6 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C index a5021f6aa1..ebf14d47f0 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C @@ -145,22 +145,7 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict) if (operation_ == opWeightedAverage) { dict.lookup("weightField") >> weightFieldName_; - if - ( - obr().foundObject(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; diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H index a485310391..212d1730cb 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H @@ -157,7 +157,8 @@ protected: template tmp > setFieldValues ( - const word& fieldName + const word& fieldName, + const bool mustGet = false ) const; //- Apply the 'operation' to the values diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C index 5051c50ca9..6c3fe94438 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C @@ -45,7 +45,8 @@ bool Foam::fieldValues::cellSource::validField(const word& fieldName) const template Foam::tmp > Foam::fieldValues::cellSource::setFieldValues ( - const word& fieldName + const word& fieldName, + const bool mustGet ) const { typedef GeometricField vf; @@ -55,6 +56,20 @@ Foam::tmp > Foam::fieldValues::cellSource::setFieldValues return filterField(obr_.lookupObject(fieldName)); } + if (mustGet) + { + FatalErrorIn + ( + "Foam::tmp > " + "Foam::fieldValues::cellSource::setFieldValues" + "(" + "const word&, " + "const bool" + ") const" + ) << "Field " << fieldName << " not found in database" + << abort(FatalError); + } + return tmp >(new Field(0.0)); } @@ -125,7 +140,13 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName) scalarField V(filterField(mesh().V())); combineFields(V); - scalarField weightField(setFieldValues(weightFieldName_)); + scalarField weightField; + + if (operation_ == opWeightedAverage) + { + weightField = setFieldValues(weightFieldName_, true); + } + combineFields(weightField); if (Pstream::master()) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 10fb1966d7..5141604eed 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -284,23 +284,7 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) if (operation_ == opWeightedAverage) { dict.lookup("weightField") >> weightFieldName_; - if - ( - obr().foundObject(weightFieldName_) - || obr().foundObject(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; diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index d9c2bca621..8ad835e2b2 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -200,7 +200,11 @@ protected: //- Return field values by looking up field name template - tmp > getFieldValues(const word& fieldName) const; + tmp > getFieldValues + ( + const word& fieldName, + const bool mustGet = false + ) const; //- Apply the 'operation' to the values template diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index fabab09707..47fb3a61e1 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -52,7 +52,8 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const template Foam::tmp > Foam::fieldValues::faceSource::getFieldValues ( - const word& fieldName + const word& fieldName, + const bool mustGet ) const { typedef GeometricField sf; @@ -74,6 +75,20 @@ Foam::tmp > Foam::fieldValues::faceSource::getFieldValues } } + if (mustGet) + { + FatalErrorIn + ( + "Foam::tmp > " + "Foam::fieldValues::faceSource::getFieldValues" + "(" + "const word&, " + "const bool" + ") const" + ) << "Field " << fieldName << " not found in database" + << abort(FatalError); + } + return tmp >(new Field(0)); } @@ -139,7 +154,13 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) if (ok) { Field values(getFieldValues(fieldName)); - scalarField weightField(getFieldValues(weightFieldName_)); + scalarField weightField; + + if (operation_ == opWeightedAverage) + { + weightField = getFieldValues(weightFieldName_, true); + } + scalarField magSf; if (surfacePtr_.valid())