diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C index 76c1ac9515c7ee3d849cd333e2d32687bf32ca83..710e346ed5dc236baba9ab65fb11a6df968bd94e 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C @@ -50,10 +50,13 @@ namespace Foam fieldValues::faceSource::sourceTypeNames_; template<> - const char* NamedEnum<fieldValues::faceSource::operationType, 4>:: - names[] = {"none", "sum", "areaAverage", "areaIntegrate"}; + const char* NamedEnum<fieldValues::faceSource::operationType, 5>:: + names[] = + { + "none", "sum", "areaAverage", "areaIntegrate", "weightedAverage" + }; - const NamedEnum<fieldValues::faceSource::operationType, 4> + const NamedEnum<fieldValues::faceSource::operationType, 5> fieldValues::faceSource::operationTypeNames_; } @@ -68,7 +71,9 @@ void Foam::fieldValues::faceSource::setFaceZoneFaces() if (zoneId < 0) { FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()") - << "Unknown face zone name: " << sourceName_ + << type() << " " << name_ << ": " + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl + << " Unknown face zone name: " << sourceName_ << ". Valid face zones are: " << mesh().faceZones().names() << nl << exit(FatalError); } @@ -164,7 +169,9 @@ void Foam::fieldValues::faceSource::setPatchFaces() if (patchId < 0) { FatalErrorIn("faceSource::constructFaceAddressing()") - << "Unknown patch name: " << sourceName_ + << type() << " " << name_ << ": " + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl + << " Unknown patch name: " << sourceName_ << ". Valid patch names are: " << mesh().boundaryMesh().names() << nl << exit(FatalError); @@ -197,7 +204,7 @@ void Foam::fieldValues::faceSource::setPatchFaces() // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void Foam::fieldValues::faceSource::initialise() +void Foam::fieldValues::faceSource::initialise(const dictionary& dict) { switch (source_) { @@ -214,15 +221,40 @@ void Foam::fieldValues::faceSource::initialise() default: { FatalErrorIn("faceSource::constructFaceAddressing()") - << "Unknown source type. Valid source types are:" + << type() << " " << name_ << ": " + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" + << nl << " Unknown source type. Valid source types are:" << sourceTypeNames_ << nl << exit(FatalError); } } Info<< type() << " " << name_ << ":" << nl - << " total faces = " << faceId_.size() << nl - << " total area = " << sum(filterField(mesh().magSf())) - << nl << endl; + << " total faces = " << faceId_.size() << nl + << " total area = " << sum(filterField(mesh().magSf())) << nl; + + if (operation_ == opWeightedAverage) + { + dict.lookup("weightField") >> weightFieldName_; + if + ( + obr().foundObject<volScalarField>(weightFieldName_) + || obr().foundObject<surfaceScalarField>(weightFieldName_) + ) + { + Info<< " weight field = " << weightFieldName_; + } + else + { + FatalErrorIn("faceSource::constructFaceAddressing()") + << type() << " " << name_ << ": " + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" + << nl << " Weight field " << weightFieldName_ + << " must be either a " << volScalarField::typeName << " or " + << surfaceScalarField::typeName << nl << exit(FatalError); + } + } + + Info<< nl << endl; } @@ -302,12 +334,13 @@ Foam::fieldValues::faceSource::faceSource faceId_(), facePatchId_(), flipMap_(), - outputFilePtr_(NULL) + outputFilePtr_(NULL), + weightFieldName_("undefinedWeightedFieldName") { - initialise(); - if (active_) { + initialise(dict); + // Create the output file if not already created makeFile(); } @@ -327,7 +360,7 @@ void Foam::fieldValues::faceSource::read(const dictionary& dict) if (active_) { fieldValue::read(dict); - initialise(); + initialise(dict); } } diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H index fa89fcdd6c58db55621872a90e47f3444fe9c8d3..3509d733cd0f61388dfb649f0c5de68735fc32c4 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H @@ -39,7 +39,7 @@ Description valueOutput true; // Write values at run-time output times? source faceZone; // Type of face source: faceZone, patch sourceName f0; - operation sum; // none, sum, areaAverage, areaIntegrate + operation sum; fields ( p @@ -48,6 +48,13 @@ Description ); } + where operation is one of: + - none + - sum + - areaAverage + - areaIntegrate + - weightedAverage + SourceFiles faceSource.C @@ -100,11 +107,12 @@ public: opNone, opSum, opAreaAverage, - opAreaIntegrate + opAreaIntegrate, + opWeightedAverage }; //- Operation type names - static const NamedEnum<operationType, 4> operationTypeNames_; + static const NamedEnum<operationType, 5> operationTypeNames_; private: @@ -143,11 +151,14 @@ protected: //- Output file pointer autoPtr<OFstream> outputFilePtr_; + //- Weight field name - only used for opWeightedAverage mode + word weightFieldName_; + // Protected member functions //- Initialise, e.g. face addressing - void initialise(); + void initialise(const dictionary& dict); //- Insert field values into values list template<class Type> diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C index ced2ee82eed1841f7dfd3c02fa8a2d99895348a2..d7609573a72cb18d4b7cbeb6c0cee65e67459654 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C @@ -129,6 +129,47 @@ Type Foam::fieldValues::faceSource::processValues result = sum(values*filterField(mesh().magSf())); break; } + case opWeightedAverage: + { + if (mesh().foundObject<volScalarField>(weightFieldName_)) + { + tmp<scalarField> wField = + filterField + ( + mesh().lookupObject<volScalarField>(weightFieldName_) + ); + result = sum(values*wField())/sum(wField()); + } + else if (mesh().foundObject<surfaceScalarField>(weightFieldName_)) + { + tmp<scalarField> wField = + filterField + ( + mesh().lookupObject<surfaceScalarField> + ( + weightFieldName_ + ) + ); + result = sum(values*wField())/sum(wField()); + } + else + { + FatalErrorIn + ( + "fieldValues::faceSource::processValues" + "(" + "List<Type>&" + ") const" + ) << type() << " " << name_ << ": " + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" + << nl + << " Weight field " << weightFieldName_ + << " must be either a " << volScalarField::typeName + << " or " << surfaceScalarField::typeName << nl + << abort(FatalError); + } + break; + } default: { // Do nothing diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H index cdedaae131a9f65b5a03971f02a193bf876b4d2d..3d862b1f6be9303ec7ba21fb5d524943ad93ba04 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H @@ -137,7 +137,7 @@ public: //- Return the output field values flag const Switch& valueOutput() const; - //- Helper funvction to return the reference to the mesh + //- Helper function to return the reference to the mesh const fvMesh& mesh() const;