From ef3ba43cf4572b7f2a38becb4b99f1a52c7fdb6f Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 26 Apr 2015 21:35:25 +0100 Subject: [PATCH] cellSource: Writing the volume of the cellSource (sum(V)) for each time is now optional Previous behavior which may be useful for moving-mesh cases can be selected using the optional entry: writeVolume yes; The initial volume is written in the log and data file header e.g.: # Source : all # Cells : 3829 # Volume : 9.943164e-01 Also added sumMag | sum of component magnitudes --- .../field/fieldValues/cellSource/cellSource.C | 48 ++++++++++++++----- .../field/fieldValues/cellSource/cellSource.H | 19 ++++++-- .../cellSource/cellSourceTemplates.C | 10 ++-- .../field/fieldValues/fieldValue/fieldValue.C | 2 +- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C index a441189f39..dbc7ff73a5 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -41,10 +41,11 @@ namespace Foam template<> - const char* NamedEnum::names[] = + const char* NamedEnum::names[] = { "none", "sum", + "sumMag", "average", "weightedAverage", "volAverage", @@ -65,7 +66,7 @@ namespace Foam const Foam::NamedEnum Foam::fieldValues::cellSource::sourceTypeNames_; -const Foam::NamedEnum +const Foam::NamedEnum Foam::fieldValues::cellSource::operationTypeNames_; @@ -77,6 +78,8 @@ void Foam::fieldValues::cellSource::setCellZoneCells() { case stCellZone: { + dict().lookup("sourceName") >> sourceName_; + label zoneId = mesh().cellZones().findZoneID(sourceName_); if (zoneId < 0) @@ -114,6 +117,12 @@ void Foam::fieldValues::cellSource::setCellZoneCells() } +Foam::scalar Foam::fieldValues::cellSource::volume() const +{ + return gSum(filterField(mesh().V())); +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::fieldValues::cellSource::initialise(const dictionary& dict) @@ -125,8 +134,7 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict) WarningIn ( "Foam::fieldValues::cellSource::initialise(const dictionary&)" - ) - << type() << " " << name_ << ": " + ) << type() << " " << name_ << ": " << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl << " Source has no cells - deactivating" << endl; @@ -151,10 +159,18 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict) void Foam::fieldValues::cellSource::writeFileHeader(const label i) { - file() - << "# Source : " << sourceTypeNames_[source_] << " " - << sourceName_ << nl << "# Cells : " << nCells_ << nl - << "# Time" << tab << "sum(V)"; + writeCommented(file(), "Source : "); + file() << sourceTypeNames_[source_] << " " << sourceName_ << endl; + writeCommented(file(), "Cells : "); + file() << nCells_ << endl; + writeCommented(file(), "Volume : "); + file() << volume() << endl; + + writeCommented(file(), "Time"); + if (writeVolume_) + { + file() << tab << "Volume"; + } forAll(fields_, i) { @@ -182,7 +198,8 @@ Foam::fieldValues::cellSource::cellSource operation_(operationTypeNames_.read(dict.lookup("operation"))), nCells_(0), cellId_(), - weightFieldName_("none") + weightFieldName_("none"), + writeVolume_(dict.lookupOrDefault("writeVolume", false)) { read(dict); } @@ -214,10 +231,17 @@ void Foam::fieldValues::cellSource::write() if (active_) { - scalar totalVolume = gSum(filterField(mesh().V())); if (Pstream::master()) { - file() << obr_.time().value() << tab << totalVolume; + file() << obr_.time().value(); + } + + if (writeVolume_) + { + if (Pstream::master()) + { + file() << tab << volume(); + } } forAll(fields_, i) diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H index f0ad57d9ad..a945e91b97 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,9 +58,10 @@ Description \heading Function object usage \table Property | Description | Required | Default value - type | type name: cellSource | yes | - log | write data to standard output | no | no - valueOutput | write the raw output values | yes | + type | Type name: cellSource | yes | + log | Write data to standard output | no | no + valueOutput | Write the raw output values | yes | + writeVolume | Write the volume of the cellSource | no | source | cell source: see below | yes | sourceName | name of cell source if required | no | operation | operation to perform | yes | @@ -80,6 +81,7 @@ Description \plaintable none | no operation sum | sum + sumMag | sum of component magnitudes average | ensemble average weightedAverage | weighted average volAverage | volume weighted average @@ -143,6 +145,7 @@ public: { opNone, opSum, + opSumMag, opAverage, opWeightedAverage, opVolAverage, @@ -153,7 +156,7 @@ public: }; //- Operation type names - static const NamedEnum operationTypeNames_; + static const NamedEnum operationTypeNames_; private: @@ -166,6 +169,9 @@ private: //- Set cells to evaluate based on a patch void setPatchCells(); + //- Calculate and return volume of the cellSource: sum(V) + scalar volume() const; + protected: @@ -186,6 +192,9 @@ protected: //- Weight field name - only used for opWeightedAverage mode word weightFieldName_; + //- Optionally write the volume of the cellSource + bool writeVolume_; + // Protected Member Functions diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C index 1acc0876b1..1371083b4d 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,6 +90,11 @@ Type Foam::fieldValues::cellSource::processValues result = sum(values); break; } + case opSumMag: + { + result = sum(cmptMag(values)); + break; + } case opAverage: { result = sum(values)/values.size(); @@ -201,7 +206,7 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName) file()<< tab << result; Info(log_)<< " " << operationTypeNames_[operation_] - << "(" << sourceName_ << ") for " << fieldName + << "(" << sourceName_ << ") of " << fieldName << " = " << result << endl; } } @@ -221,4 +226,3 @@ Foam::tmp > Foam::fieldValues::cellSource::filterField // ************************************************************************* // - diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C index 25f2c84cbe..daf194096a 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C @@ -80,7 +80,7 @@ Foam::fieldValue::fieldValue dict_(dict), active_(true), log_(true), - sourceName_(dict.lookupOrDefault("sourceName", "sampledSurface")), + sourceName_(word::null), fields_(dict.lookup("fields")), valueOutput_(dict.lookup("valueOutput")), resultDict_(fileName("name"), dictionary::null)