From 602dc5ed454bddfc2caad3120698d56ff7dbdda3 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 12:07:18 +0100 Subject: [PATCH] ENH: fieldMinMax FO updated follwing changes to functionObjectFile --- .../field/fieldMinMax/fieldMinMax.C | 102 +++++++++--------- .../field/fieldMinMax/fieldMinMax.H | 28 ++--- .../field/fieldMinMax/fieldMinMaxTemplates.C | 4 +- 3 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C index dac7d8a71e..19e24273b9 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C @@ -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. @@ -49,6 +49,45 @@ const Foam::NamedEnum Foam::fieldMinMax::modeTypeNames_; +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +void Foam::fieldMinMax::writeFileHeader(Ostream& os) const +{ + writeHeader(os, "Field minima and maxima"); + writeCommented(os, "Time"); + + if (writeLocation_) + { + writeTabbed(os, "field"); + writeTabbed(os, "min"); + writeTabbed(os, "position(min)"); + + if (Pstream::parRun()) + { + writeTabbed(os, "processor"); + } + + writeTabbed(os, "max"); + writeTabbed(os, "position(max)"); + + if (Pstream::parRun()) + { + writeTabbed(os, "processor"); + } + } + else + { + forAll(fieldSet_, fieldI) + { + writeTabbed(os, "min(" + fieldSet_[fieldI] + ')'); + writeTabbed(os, "max(" + fieldSet_[fieldI] + ')'); + } + } + + os << endl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::fieldMinMax::fieldMinMax @@ -59,12 +98,11 @@ Foam::fieldMinMax::fieldMinMax const bool loadFromFiles ) : - functionObjectFile(obr, name, typeName), - name_(name), + functionObjectFile(obr, name, typeName, dict), obr_(obr), active_(true), log_(true), - location_(true), + writeLocation_(true), mode_(mdMag), fieldSet_() { @@ -85,7 +123,11 @@ Foam::fieldMinMax::fieldMinMax << endl; } - read(dict); + if (active_) + { + read(dict); + writeFileHeader(file()); + } } @@ -101,8 +143,10 @@ void Foam::fieldMinMax::read(const dictionary& dict) { if (active_) { + functionObjectFile::read(dict); + log_ = dict.lookupOrDefault("log", true); - location_ = dict.lookupOrDefault("location", true); + writeLocation_ = dict.lookupOrDefault("writeLocation", true); mode_ = modeTypeNames_[dict.lookupOrDefault("mode", "magnitude")]; dict.lookup("fields") >> fieldSet_; @@ -110,46 +154,6 @@ void Foam::fieldMinMax::read(const dictionary& dict) } -void Foam::fieldMinMax::writeFileHeader(const label i) -{ - OFstream& file = this->file(); - - writeHeader(file, "Field minima and maxima"); - writeCommented(file, "Time"); - - if (location_) - { - writeTabbed(file, "field"); - - writeTabbed(file, "min"); - writeTabbed(file, "location(min)"); - - if (Pstream::parRun()) - { - writeTabbed(file, "processor"); - } - - writeTabbed(file, "max"); - writeTabbed(file, "location(max)"); - - if (Pstream::parRun()) - { - writeTabbed(file, "processor"); - } - } - else - { - forAll(fieldSet_, fieldI) - { - writeTabbed(file, "min(" + fieldSet_[fieldI] + ')'); - writeTabbed(file, "max(" + fieldSet_[fieldI] + ')'); - } - } - - file<< endl; -} - - void Foam::fieldMinMax::execute() { // Do nothing - only valid on write @@ -172,9 +176,7 @@ void Foam::fieldMinMax::write() { if (active_) { - functionObjectFile::write(); - - if (!location_) file()<< obr_.time().value(); + if (!writeLocation_) file()<< obr_.time().value(); if (log_) Info<< type() << " " << name_ << " output:" << nl; forAll(fieldSet_, fieldI) @@ -186,7 +188,7 @@ void Foam::fieldMinMax::write() calcMinMaxFields(fieldSet_[fieldI], mode_); } - if (!location_) file()<< endl; + if (!writeLocation_) file()<< endl; if (log_) Info<< endl; } } diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H index b2246eb9b1..cd8b7f1692 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H @@ -28,7 +28,7 @@ Group grpFieldFunctionObjects Description - This function object calculates the value and location of scalar minimim + This function object calculates the value and position of scalar minimim and maximum for a list of user-specified fields. For variables with a rank greater than zero, either the min/max of a component value or the magnitude is reported. When operating in parallel, the processor owning the value @@ -41,7 +41,7 @@ Description type fieldMinMax; functionObjectLibs ("libfieldFunctionObjects.so"); ... - write yes; + writeToFile yes; log yes; location yes; mode magnitude; @@ -57,20 +57,23 @@ Description \table Property | Description | Required | Default value type | type name: fieldMinMax | yes | - write | write min/max data to file | no | yes - log | write min/max data to standard output | no | no + writeToFile | write min/max data to file | no | yes + log | write min/max data to standard output | no | yes location | write location of the min/max value | no | yes mode | calculation mode: magnitude or component | no | magnitude + fields | list of fields to process | yes | \endtable Output data is written to the file \/fieldMinMax.dat SeeAlso Foam::functionObject + Foam::functionObjectFile Foam::OutputFilterFunctionObject SourceFiles fieldMinMax.C + fieldMinMaxTemplates.C IOfieldMinMax.H \*---------------------------------------------------------------------------*/ @@ -105,8 +108,8 @@ public: enum modeType { - mdMag, - mdCmpt + mdMag, // magnitude + mdCmpt // component }; protected: @@ -122,14 +125,14 @@ protected: const objectRegistry& obr_; - //- on/off switch + //- On/off switch bool active_; - //- Switch to send output to Info as well + //- Switch to send output to Info as well as file Switch log_; //- Switch to write location of min/max values - Switch location_; + Switch writeLocation_; //- Mode for min/max - only applicable for ranks > 0 modeType mode_; @@ -154,15 +157,16 @@ protected: const Type& maxValue ); + + //- Output file header information + virtual void writeFileHeader(Ostream& os) const; + //- Disallow default bitwise copy construct fieldMinMax(const fieldMinMax&); //- Disallow default bitwise assignment void operator=(const fieldMinMax&); - //- Output file header information - virtual void writeFileHeader(const label i); - public: diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index 729500caef..f64fa135f9 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -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. @@ -43,7 +43,7 @@ void Foam::fieldMinMax::output { OFstream& file = this->file(); - if (location_) + if (writeLocation_) { file<< obr_.time().value();