diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C index 9d4b8400c8..40d3ff5bf6 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C @@ -79,8 +79,6 @@ void Foam::fieldValues::cellSource::setCellZoneCells() { case stCellZone: { - dict().lookup("sourceName") >> sourceName_; - label zoneId = mesh().cellZones().findZoneID(sourceName_); if (zoneId < 0) @@ -135,7 +133,8 @@ 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; @@ -145,44 +144,46 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict) volume_ = volume(); - Info<< type() << " " << name_ << ":" - << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl - << " total cells = " << nCells_ << nl - << " total volume = " << volume_ - << nl << endl; + if (log_) + { + Info<< type() << " " << name_ << ":" + << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl + << " total cells = " << nCells_ << nl + << " total volume = " << volume_ + << nl << endl; + } if (dict.readIfPresent("weightField", weightFieldName_)) { - Info<< " weight field = " << weightFieldName_; + if (log_) Info << " weight field = " << weightFieldName_; } - Info<< nl << endl; + if (log_) Info << nl << endl; } -void Foam::fieldValues::cellSource::writeFileHeader(const label i) +void Foam::fieldValues::cellSource::writeFileHeader(Ostream& os) const { - writeCommented(file(), "Source : "); - file() << sourceTypeNames_[source_] << " " << sourceName_ << endl; - writeCommented(file(), "Cells : "); - file() << nCells_ << endl; - writeCommented(file(), "Volume : "); - file() << volume_ << endl; + writeHeaderValue(os, "Source", sourceTypeNames_[source_]); + writeHeaderValue(os, "Name", sourceName_); + writeHeaderValue(os, "Cells", nCells_); + writeHeaderValue(os, "Volume", volume_); + writeHeaderValue(os, "Scale factor", scaleFactor_); - writeCommented(file(), "Time"); + + writeCommented(os, "Time"); if (writeVolume_) { - file() << tab << "Volume"; + os << tab << "Volume"; } forAll(fields_, i) { - file() - << tab << operationTypeNames_[operation_] + os << tab << operationTypeNames_[operation_] << "(" << fields_[i] << ")"; } - file() << endl; + os << endl; } @@ -204,7 +205,11 @@ Foam::fieldValues::cellSource::cellSource weightFieldName_("none"), writeVolume_(dict.lookupOrDefault("writeVolume", false)) { - read(dict); + if (active_) + { + read(dict); + writeFileHeader(file()); + } } @@ -218,11 +223,11 @@ Foam::fieldValues::cellSource::~cellSource() void Foam::fieldValues::cellSource::read(const dictionary& dict) { - fieldValue::read(dict); - if (active_) { - // no additional info to read + fieldValue::read(dict); + + // No additional info to read initialise(dict); } } @@ -234,33 +239,34 @@ void Foam::fieldValues::cellSource::write() if (active_) { - if (Pstream::master()) - { - file() << obr_.time().value(); - } + file() << obr_.time().value(); + // Construct weight field. Note: zero size indicates unweighted + scalarField weightField; + if (weightFieldName_ != "none") + { + weightField = setFieldValues(weightFieldName_, true); + } + if (writeVolume_) { volume_ = volume(); - if (Pstream::master()) - { - file() << tab << volume_; - } + file() << tab << volume_; if (log_) Info<< " total volume = " << volume_ << endl; } forAll(fields_, i) { const word& fieldName = fields_[i]; - bool processed = false; + bool ok = false; - processed = processed || writeValues(fieldName); - processed = processed || writeValues(fieldName); - processed = processed || writeValues(fieldName); - processed = processed || writeValues(fieldName); - processed = processed || writeValues(fieldName); + ok = ok || writeValues(fieldName, weightField); + ok = ok || writeValues(fieldName, weightField); + ok = ok || writeValues(fieldName, weightField); + ok = ok || writeValues(fieldName, weightField); + ok = ok || writeValues(fieldName, weightField); - if (!processed) + if (!ok) { WarningIn("void Foam::fieldValues::cellSource::write()") << "Requested field " << fieldName @@ -269,10 +275,7 @@ void Foam::fieldValues::cellSource::write() } } - if (Pstream::master()) - { - file()<< endl; - } + file()<< endl; if (log_) Info<< endl; } diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H index 42f788d884..8c59c8450d 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,11 +62,11 @@ Description 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 | - weightField | name of field to apply weighting | no | - fields | list of fields to operate on | yes | + source | Cell source: see below | yes | + sourceName | Name of cell source if required | no | + operation | Operation to perform | yes | + weightField | Name of field to apply weighting | no | + fields | List of fields to operate on | yes | \endtable \linebreak @@ -228,7 +228,7 @@ protected: ) const; //- Output file header information - virtual void writeFileHeader(const label i); + virtual void writeFileHeader(Ostream& os) const; public: @@ -272,7 +272,11 @@ public: //- Templated helper function to output field values template - bool writeValues(const word& fieldName); + bool writeValues + ( + const word& fieldName, + const scalarField& weightField + ); //- Filter a field according to cellIds template diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C index 15030ea689..2cdc0b5195 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C @@ -87,52 +87,65 @@ Type Foam::fieldValues::cellSource::processValues { case opSum: { - result = sum(values); + result = gSum(values); break; } case opSumMag: { - result = sum(cmptMag(values)); + result = gSum(cmptMag(values)); break; } case opAverage: { - result = sum(values)/values.size(); + label n = returnReduce(values.size(), sumOp