From 9be9be244793bded72c13471594996e80418842c Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Mon, 5 Oct 2015 15:10:23 +0100 Subject: [PATCH 01/30] ENH: Added new functionObjectState class This new class provides function objects with a database (dictionary) to store current state information to enable smooth restart behaviour. Additionally, current results can be stored so that they can be accessed between different objects. --- .../functionObjectState/functionObjectState.C | 173 ++++++++++++ .../functionObjectState/functionObjectState.H | 255 ++++++++++++++++++ .../functionObjectStateTemplates.C | 242 +++++++++++++++++ 3 files changed, 670 insertions(+) create mode 100644 src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C create mode 100644 src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H create mode 100644 src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C new file mode 100644 index 0000000000..37d57d06f1 --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "functionObjectState.H" +#include "Time.H" + +const Foam::word Foam::functionObjectState::resultsName_ = "results"; + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjectState::functionObjectState +( + const objectRegistry& obr, + const word& name +) +: + obr_(obr), + name_(name), + active_(true), + stateDict_ + ( + const_cast(obr.time().functionObjects().stateDict()) + ) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjectState::~functionObjectState() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const Foam::word& Foam::functionObjectState::name() const +{ + return name_; +} + + +bool Foam::functionObjectState::active() const +{ + return active_; +} + + +const Foam::IOdictionary& Foam::functionObjectState::stateDict() const +{ + return stateDict_; +} + + +Foam::dictionary& Foam::functionObjectState::propertyDict() +{ + if (!stateDict_.found(name_)) + { + stateDict_.add(name_, dictionary()); + } + + return stateDict_.subDict(name_); +} + + +bool Foam::functionObjectState::foundProperty(const word& entryName) const +{ + if (stateDict_.found(name_)) + { + const dictionary& baseDict = stateDict_.subDict(name_); + return baseDict.found(entryName); + } + + return false; +} + + +Foam::word Foam::functionObjectState::resultType(const word& entryName) const +{ + return objectResultType(name_, entryName); +} + + +Foam::word Foam::functionObjectState::objectResultType +( + const word& objectName, + const word& entryName +) const +{ + word result = word::null; + + if (stateDict_.found(resultsName_)) + { + const dictionary& resultsDict = stateDict_.subDict(resultsName_); + + if (resultsDict.found(objectName)) + { + const dictionary& objectDict = resultsDict.subDict(objectName); + + forAllConstIter(dictionary, objectDict, iter) + { + const dictionary& dict = iter().dict(); + + if (dict.found(entryName)) + { + return dict.dictName(); + } + } + } + } + + return result; +} + + +Foam::List Foam::functionObjectState::objectResultEntries() const +{ + return objectResultEntries(name_); +} + + +Foam::List Foam::functionObjectState::objectResultEntries +( + const word& objectName +) const +{ + DynamicList result(2); + + if (stateDict_.found(resultsName_)) + { + const dictionary& resultsDict = stateDict_.subDict(resultsName_); + + if (resultsDict.found(objectName)) + { + const dictionary& objectDict = resultsDict.subDict(objectName); + + forAllConstIter(dictionary, objectDict, iter) + { + const dictionary& dict = iter().dict(); + result.append(dict.toc()); + } + } + } + + wordList entries; + entries.transfer(result); + + return entries; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H new file mode 100644 index 0000000000..c3c8b94c7a --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H @@ -0,0 +1,255 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjectState + +Description + Base class for function objects, adding functionality to read/write state + information (data required for smooth restart behaviour) and results + to/from the state dictionary + +See Also + Foam::functionObject + +SourceFiles + functionObjectState.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjectState_H +#define functionObjectState_H + +#include "objectRegistry.H" +#include "IOdictionary.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class functionObjectState Declaration +\*---------------------------------------------------------------------------*/ + +class functionObjectState +{ +private: + + // Private data + + //- Name of the results dictionary + static const word resultsName_; + + //- Reference to the database + const objectRegistry& obr_; + + +protected: + + // Protected data + + //- Name of model + const word name_; + + //- Flag to indicate whether the object is active + bool active_; + + //- Reference to the state dictionary + IOdictionary& stateDict_; + + +protected: + + // Protected Member Functions + + //- Disallow default bitwise copy construct + functionObjectState(const functionObjectState&); + + //- Disallow default bitwise assignment + void operator=(const functionObjectState&); + + +public: + + // Constructors + + //- Construct from components + functionObjectState + ( + const objectRegistry& obr, + const word& name + ); + + + //- Destructor + virtual ~functionObjectState(); + + + // Member Functions + + //- Return the name + const word& name() const; + + //- Return the active flag + bool active() const; + + //- Return access to the state dictionary + const IOdictionary& stateDict() const; + + //- Return access to the property dictionary + dictionary& propertyDict(); + + //- Set the active status by querying objectRegistry type + // returns new active status + template + bool setActive(); + + + // Properties + + //- Return true if the property exists + bool foundProperty(const word& entryName) const; + + //- Retrieve generic property + template + Type getProperty + ( + const word& entryName, + const Type& defaultValue = pTraits::zero + ) const; + + //- Retrieve generic property + template + void getProperty(const word& entryName, Type& value) const; + + //- Add generic property + template + void setProperty(const word& entryName, const Type& value); + + //- Retrieve generic property from named object + template + Type getObjectProperty + ( + const word& objectName, + const word& entryName, + const Type& defaultValue = pTraits::zero + ) const; + + //- Retrieve generic property from named object + template + void getObjectProperty + ( + const word& objectName, + const word& entryName, + Type& value + ) const; + + //- Add generic property from named object + template + void setObjectProperty + ( + const word& objectName, + const word& entryName, + const Type& value + ); + + + // Results + + //- Add result + template + void setResult + ( + const word& entryName, + const Type& value + ); + + //- Add result from named object + template + void setObjectResult + ( + const word& objectName, + const word& entryName, + const Type& value + ); + + //- Retrieve result + template + Type getResult + ( + const word& entryName, + const Type& defaultValue = pTraits::zero + ) const; + + //- Retrieve result from named object + template + Type getObjectResult + ( + const word& objectName, + const word& entryName, + const Type& defaultValue = pTraits::zero + ) const; + + //- Retrieve result from named object + template + void getObjectResult + ( + const word& objectName, + const word& entryName, + Type& value + ) const; + + //- Retrieve the result type + word resultType(const word& entryName) const; + + //- Return the type of result + word objectResultType + ( + const word& objectName, + const word& entryName + ) const; + + //- Retrieve the result entries + List objectResultEntries() const; + + //- Return result entries for named object + List objectResultEntries(const word& objectName) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "functionObjectStateTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C new file mode 100644 index 0000000000..fb27b2668c --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C @@ -0,0 +1,242 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +bool Foam::functionObjectState::setActive() +{ + active_ = true; + + if (!isA(obr_)) + { + WarningIn + ( + "void Foam::functionObjectState::setActive()" + ) << "No " << Type::typeName << " available, deactivating " << name_ + << endl; + + active_ = false; + } + + return active_; +} + + +template +Type Foam::functionObjectState::getProperty +( + const word& entryName, + const Type& defaultValue +) const +{ + Type result = defaultValue; + getProperty(entryName, result); + return result; +} + + +template +void Foam::functionObjectState::getProperty +( + const word& entryName, + Type& value +) const +{ + getObjectProperty(name_, entryName, value); +} + + +template +void Foam::functionObjectState::setProperty +( + const word& entryName, + const Type& value +) +{ + setObjectProperty(name_, entryName, value); +} + + +template +Type Foam::functionObjectState::getObjectProperty +( + const word& objectName, + const word& entryName, + const Type& defaultValue +) const +{ + Type result = defaultValue; + getObjectProperty(objectName, entryName, result); + return result; +} + + +template +void Foam::functionObjectState::getObjectProperty +( + const word& objectName, + const word& entryName, + Type& value +) const +{ + if (stateDict_.found(objectName)) + { + const dictionary& baseDict = stateDict_.subDict(objectName); + if (baseDict.found(entryName)) + { + if (baseDict.isDict(entryName)) + { + value = baseDict.subDict(entryName); + } + else + { + baseDict.lookup(entryName) >> value; + } + } + } +} + + +template +void Foam::functionObjectState::setObjectProperty +( + const word& objectName, + const word& entryName, + const Type& value +) +{ + if (!stateDict_.found(objectName)) + { + stateDict_.add(objectName, dictionary()); + } + + dictionary& baseDict = stateDict_.subDict(objectName); + baseDict.add(entryName, value, true); +} + + +template +void Foam::functionObjectState::setResult +( + const word& entryName, + const Type& value +) +{ + setObjectResult(name_, entryName, value); +} + + +template +void Foam::functionObjectState::setObjectResult +( + const word& objectName, + const word& entryName, + const Type& value +) +{ + if (!stateDict_.found(resultsName_)) + { + stateDict_.add(resultsName_, dictionary()); + } + + dictionary& resultsDict = stateDict_.subDict(resultsName_); + + if (!resultsDict.found(objectName)) + { + resultsDict.add(name_, dictionary()); + } + + dictionary& objectDict = resultsDict.subDict(objectName); + + const word& dictTypeName = pTraits::typeName; + + if (!objectDict.found(dictTypeName)) + { + objectDict.add(dictTypeName, dictionary()); + } + + dictionary& resultTypeDict = objectDict.subDict(dictTypeName); + + resultTypeDict.add(entryName, value, true); +} + + +template +Type Foam::functionObjectState::getResult +( + const word& entryName, + const Type& defaultValue +) const +{ + return getObjectResult(name_, entryName, defaultValue); +} + + +template +Type Foam::functionObjectState::getObjectResult +( + const word& objectName, + const word& entryName, + const Type& defaultValue +) const +{ + Type result = defaultValue; + getObjectResult(objectName, entryName, result); + return result; +} + + +template +void Foam::functionObjectState::getObjectResult +( + const word& objectName, + const word& entryName, + Type& value +) const +{ + if (stateDict_.found(resultsName_)) + { + const dictionary& resultsDict = stateDict_.subDict(resultsName_); + + if (resultsDict.found(objectName)) + { + const dictionary& objectDict = resultsDict.subDict(objectName); + + const word& dictTypeName = pTraits::typeName; + + if (objectDict.found(dictTypeName)) + { + const dictionary& resultTypeDict = + objectDict.subDict(dictTypeName); + + resultTypeDict.readIfPresent(entryName, value); + } + } + } +} + + +// ************************************************************************* // From bbc25cb4573c34795dc0caac08eacdd5dfdceb63 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Mon, 5 Oct 2015 15:11:12 +0100 Subject: [PATCH 02/30] ENH: Refactored functionObjectFile class Class now provides helper functions to generate files on-the-fly by function objects, as opposed to attempting to control all files needed by the function object (earlier implementation lead to over-complication and was error prone) --- .../functionObjectFile/functionObjectFile.C | 207 +++++------------- .../functionObjectFile/functionObjectFile.H | 61 +++--- 2 files changed, 85 insertions(+), 183 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C index 847747964d..e44f41f6ac 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,6 +39,7 @@ Foam::label Foam::functionObjectFile::addChars = 7; void Foam::functionObjectFile::initStream(Ostream& os) const { os.setf(ios_base::scientific, ios_base::floatfield); + os.precision(writePrecision_); os.width(charWidth()); } @@ -78,78 +79,44 @@ Foam::fileName Foam::functionObjectFile::baseTimeDir() const } -void Foam::functionObjectFile::createFiles() +Foam::autoPtr Foam::functionObjectFile::createFile +( + const word& name +) const { - if (Pstream::master()) + autoPtr osPtr; + + if (Pstream::master() && writeToFile_) { const word startTimeName = obr_.time().timeName(obr_.time().startTime().value()); - forAll(names_, i) + fileName outputDir(baseFileDir()/prefix_/startTimeName); + + mkDir(outputDir); + + word fName(name); + + // Check if file already exists + IFstream is(outputDir/(fName + ".dat")); + if (is.good()) { - if (!filePtrs_.set(i)) - { - fileName outputDir(baseFileDir()/prefix_/startTimeName); - mkDir(outputDir); - - word fName(names_[i]); - - // Check if file already exists - IFstream is(outputDir/(fName + ".dat")); - if (is.good()) - { - fName = fName + "_" + obr_.time().timeName(); - } - - filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat"))); - - initStream(filePtrs_[i]); - - writeFileHeader(i); - - } + fName = fName + "_" + obr_.time().timeName(); } + + osPtr.set(new OFstream(outputDir/(fName + ".dat"))); + + initStream(osPtr()); } + + return osPtr; } -void Foam::functionObjectFile::writeFileHeader(const label i) -{} - - -void Foam::functionObjectFile::write() +void Foam::functionObjectFile::resetFile(const word& fileName) { - createFiles(); -} - - -void Foam::functionObjectFile::resetNames(const wordList& names) -{ - names_.clear(); - names_.append(names); - - if (Pstream::master()) - { - filePtrs_.clear(); - filePtrs_.setSize(names_.size()); - - createFiles(); - } -} - - -void Foam::functionObjectFile::resetName(const word& name) -{ - names_.clear(); - names_.append(name); - - if (Pstream::master()) - { - filePtrs_.clear(); - filePtrs_.setSize(1); - - createFiles(); - } + fileName_ = fileName; + filePtr_ = createFile(fileName_); } @@ -169,8 +136,10 @@ Foam::functionObjectFile::functionObjectFile : obr_(obr), prefix_(prefix), - names_(), - filePtrs_() + fileName_("undefined"), + filePtr_(), + writePrecision_(IOstream::defaultPrecision()), + writeToFile_(true) {} @@ -178,46 +147,22 @@ Foam::functionObjectFile::functionObjectFile ( const objectRegistry& obr, const word& prefix, - const word& name + const word& fileName, + const dictionary& dict ) : obr_(obr), prefix_(prefix), - names_(), - filePtrs_() + fileName_(fileName), + filePtr_(), + writePrecision_(IOstream::defaultPrecision()), + writeToFile_(true) { - names_.clear(); - names_.append(name); - if (Pstream::master()) + read(dict); + + if (writeToFile_) { - filePtrs_.clear(); - filePtrs_.setSize(1); - - // Cannot create files - need to access virtual function - } -} - - -Foam::functionObjectFile::functionObjectFile -( - const objectRegistry& obr, - const word& prefix, - const wordList& names -) -: - obr_(obr), - prefix_(prefix), - names_(names), - filePtrs_() -{ - names_.clear(); - names_.append(names); - if (Pstream::master()) - { - filePtrs_.clear(); - filePtrs_.setSize(names_.size()); - - // Cannot create files - need to access virtual function + filePtr_ = createFile(fileName_); } } @@ -230,72 +175,38 @@ Foam::functionObjectFile::~functionObjectFile() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::wordList& Foam::functionObjectFile::names() const +void Foam::functionObjectFile::read(const dictionary& dict) { - return names_; + writePrecision_ = + dict.lookupOrDefault("writePrecision", IOstream::defaultPrecision()); + + // Only write on master process + writeToFile_ = dict.lookupOrDefault("writeToFile", true); + writeToFile_ = writeToFile_ && Pstream::master(); } Foam::OFstream& Foam::functionObjectFile::file() { - if (!Pstream::master()) + if (!writeToFile_) + { + return Snull; + } + + if (!filePtr_.valid()) { FatalErrorIn("Foam::OFstream& Foam::functionObjectFile::file()") - << "Request for file() can only be done by the master process" + << "File pointer not allocated" << abort(FatalError); } - if (filePtrs_.size() != 1) - { - WarningIn("Foam::Ostream& Foam::functionObjectFile::file()") - << "Requested single file, but multiple files are present" - << endl; - } - - if (!filePtrs_.set(0)) - { - FatalErrorIn("Foam::OFstream& Foam::functionObjectFile::file()") - << "File pointer at index " << 0 << " not allocated" - << abort(FatalError); - } - - return filePtrs_[0]; + return filePtr_(); } -Foam::PtrList& Foam::functionObjectFile::files() +bool Foam::functionObjectFile::writeToFile() const { - if (!Pstream::master()) - { - FatalErrorIn("Foam::OFstream& Foam::functionObjectFile::files()") - << "Request for files() can only be done by the master process" - << abort(FatalError); - } - - return filePtrs_; -} - - -Foam::OFstream& Foam::functionObjectFile::file(const label i) -{ - if (!Pstream::master()) - { - FatalErrorIn - ( - "Foam::OFstream& Foam::functionObjectFile::file(const label)" - ) - << "Request for file(i) can only be done by the master process" - << abort(FatalError); - } - - if (!filePtrs_.set(i)) - { - FatalErrorIn("Foam::OFstream& Foam::functionObjectFile::file()") - << "File pointer at index " << i << " not allocated" - << abort(FatalError); - } - - return filePtrs_[i]; + return writeToFile_; } diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H index 5b5e3597a1..6fae16cc58 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,6 +57,8 @@ namespace Foam class functionObjectFile { +private: + // Private data //- Reference to the database @@ -65,15 +67,24 @@ class functionObjectFile //- Prefix const word prefix_; - //- File names - wordList names_; + //- Name of file + word fileName_; //- File pointer - PtrList filePtrs_; + autoPtr filePtr_; + + //- Write precision + label writePrecision_; protected: + // Protected Data + + //- Flag to enable/disable writing to file + bool writeToFile_; + + // Protected Member Functions //- Initialise the output stream for writing @@ -85,20 +96,11 @@ protected: //- Return the base directory for the current time value virtual fileName baseTimeDir() const; - //- Create the output file - virtual void createFiles(); + //- Return an autoPtr to a new file + virtual autoPtr createFile(const word& name) const; - //- File header information - virtual void writeFileHeader(const label i = 0); - - //- Write function - virtual void write(); - - //- Reset the list of names from a wordList - virtual void resetNames(const wordList& names); - - //- Reset the list of names to a single name entry - virtual void resetName(const word& name); + //- Reset internal file pointer to new file with new name + virtual void resetFile(const word& name); //- Return the value width when writing to stream with optional offset virtual Omanip valueWidth(const label offset = 0) const; @@ -118,26 +120,18 @@ public: //- Additional characters for writing static label addChars; - // Constructors //- Construct null functionObjectFile(const objectRegistry& obr, const word& prefix); - //- Construct from components + //- Construct from components and read options from dictionary functionObjectFile ( const objectRegistry& obr, const word& prefix, - const word& name - ); - - //- Construct from components - functionObjectFile - ( - const objectRegistry& obr, - const word& prefix, - const wordList& names + const word& fileName, + const dictionary& dict ); @@ -147,17 +141,14 @@ public: // Member Functions - //- Return const access to the names - const wordList& names() const; + //- Read + void read(const dictionary& dict); //- Return access to the file (if only 1) OFstream& file(); - //- Return access to the files - PtrList& files(); - - //- Return file 'i' - OFstream& file(const label i); + //- Return true if can write to file + bool writeToFile() const; //- Write a commented string to stream void writeCommented From 9d8cd0b6a8a45243639e9d9222cfa79d3f54642a Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 11:47:58 +0100 Subject: [PATCH 03/30] ENH: Added state dictionary to functionObjectList Note: added as a pointer since the list operates in multiple modes, e.g. as constructed by the Time database and 'outside' by execFlowFunctionObjects --- .../functionObjectList/functionObjectList.C | 71 ++++++++++++++++++- .../functionObjectList/functionObjectList.H | 17 ++++- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 0c44dbbfbd..61df42b667 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2011-2014 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,28 @@ License // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // +void Foam::functionObjectList::createStateDict() const +{ + // Cannot set the state dictionary on construction since Time has not + // been fully initialised + stateDictPtr_.reset + ( + new IOdictionary + ( + IOobject + ( + "functionObjectProperties", + time_.timeName(), + "uniform"/word("functionObjects"), + time_, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ) + ) + ); +} + + Foam::functionObject* Foam::functionObjectList::remove ( const word& key, @@ -70,6 +92,7 @@ Foam::functionObjectList::functionObjectList indices_(), time_(t), parentDict_(t.controlDict()), + stateDictPtr_(), execution_(execution), updated_(false) {} @@ -87,6 +110,7 @@ Foam::functionObjectList::functionObjectList indices_(), time_(t), parentDict_(parentDict), + stateDictPtr_(), execution_(execution), updated_(false) {} @@ -100,6 +124,28 @@ Foam::functionObjectList::~functionObjectList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +Foam::IOdictionary& Foam::functionObjectList::stateDict() +{ + if (!stateDictPtr_.valid()) + { + createStateDict(); + } + + return stateDictPtr_(); +} + + +const Foam::IOdictionary& Foam::functionObjectList::stateDict() const +{ + if (!stateDictPtr_.valid()) + { + createStateDict(); + } + + return stateDictPtr_(); +} + + void Foam::functionObjectList::clear() { PtrList::clear(); @@ -165,6 +211,22 @@ bool Foam::functionObjectList::execute(const bool forceWrite) } } + // Force writing of state dictionary after function object execution + if (time_.outputTime()) + { + label oldPrecision = IOstream::precision_; + IOstream::precision_ = 16; + + stateDictPtr_->writeObject + ( + IOstream::ASCII, + IOstream::currentVersion, + time_.writeCompression() + ); + + IOstream::precision_ = oldPrecision; + } + return ok; } @@ -234,6 +296,11 @@ bool Foam::functionObjectList::adjustTimeStep() bool Foam::functionObjectList::read() { + if (!stateDictPtr_.valid()) + { + createStateDict(); + } + bool ok = true; updated_ = execution_; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 126a1f18bb..681e135d0f 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,7 @@ SourceFiles #include "functionObject.H" #include "SHA1Digest.H" #include "HashTable.H" +#include "IOdictionary.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -74,6 +75,9 @@ class functionObjectList // functionObject specifications. const dictionary& parentDict_; + //- Function object properties - stores state information + mutable autoPtr stateDictPtr_; + //- Switch for the execution of the functionObjects bool execution_; @@ -83,6 +87,9 @@ class functionObjectList // Private Member Functions + //- Create state dictionary + void createStateDict() const; + //- Remove and return the function object pointer by name, // and returns the old index via the parameter. // Returns a NULL pointer (and index -1) if it didn't exist. @@ -136,6 +143,12 @@ public: //- Access to the functionObjects using PtrList::operator[]; + //- Return the state dictionary + IOdictionary& stateDict(); + + //- Return const access to the state dictionary + const IOdictionary& stateDict() const; + //- Clear the list of function objects virtual void clear(); From d856ba8996db42d4782a90ce0e73aee89ac955a8 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 11:50:45 +0100 Subject: [PATCH 04/30] ENH: Added functionObjectState to Make/files (missed in commit 9f1809c) --- src/OpenFOAM/Make/files | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 6b271cfc1d..47c8dee788 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -209,6 +209,7 @@ $(dll)/codedBase/codedBase.C db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObjectList/functionObjectList.C db/functionObjects/functionObjectFile/functionObjectFile.C +db/functionObjects/functionObjectState/functionObjectState.C db/functionObjects/outputFilterOutputControl/outputFilterOutputControl.C From a440563a03988cd6e7b7ff6694160a9c32672782 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 11:53:34 +0100 Subject: [PATCH 05/30] ENH: cloudInfo FO updated follwing changes to functionObjectFile Also added output of diameter info, D10, D32 and DMax --- .../cloud/cloudInfo/cloudInfo.C | 100 +++++++++++++----- .../cloud/cloudInfo/cloudInfo.H | 15 ++- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C index 480d5fa8be..fd58741bd7 100644 --- a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C +++ b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,13 +37,16 @@ namespace Foam // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void Foam::cloudInfo::writeFileHeader(const label i) +void Foam::cloudInfo::writeFileHeader(Ostream& os) const { - writeHeader(file(), "Cloud information"); - writeCommented(file(), "Time"); - writeTabbed(file(), "nParcels"); - writeTabbed(file(), "mass"); - file() << endl; + writeHeader(os, "Cloud information"); + writeCommented(os, "Time"); + writeTabbed(os, "nParcels"); + writeTabbed(os, "mass"); + writeTabbed(os, "Dmax"); + writeTabbed(os, "D10"); + writeTabbed(os, "D32"); + os << endl; } @@ -60,7 +63,10 @@ Foam::cloudInfo::cloudInfo functionObjectFile(obr, name), name_(name), obr_(obr), - active_(true) + active_(true), + log_(true), + cloudNames_(), + filePtrs_() { read(dict); } @@ -78,47 +84,70 @@ void Foam::cloudInfo::read(const dictionary& dict) { if (active_) { - functionObjectFile::resetNames(dict.lookup("clouds")); + functionObjectFile::read(dict); - Info<< type() << " " << name_ << ": "; - if (names().size()) + log_ = dict.lookupOrDefault("log", true); + dict.lookup("clouds") >> cloudNames_; + + if (log_) { - Info<< "applying to clouds:" << nl; - forAll(names(), i) + Info<< type() << " " << name_ << ": "; + + if (cloudNames_.size()) { - Info<< " " << names()[i] << nl; + Info<< "applying to clouds:" << nl; + forAll(cloudNames_, i) + { + Info<< " " << cloudNames_[i] << nl; + } + Info<< endl; + } + else + { + Info<< "no clouds to be processed" << nl << endl; } - Info<< endl; } - else + + if (writeToFile()) { - Info<< "no clouds to be processed" << nl << endl; + filePtrs_.setSize(cloudNames_.size()); + filePtrs_.clear(); + forAll(filePtrs_, fileI) + { + const word& cloudName = cloudNames_[fileI]; + filePtrs_.set(fileI, createFile(cloudName)); + writeFileHeader(filePtrs_[fileI]); + } } } } void Foam::cloudInfo::execute() -{} +{ + // Do nothing +} void Foam::cloudInfo::end() -{} +{ + // Do nothing +} void Foam::cloudInfo::timeSet() -{} +{ + // Do nothing +} void Foam::cloudInfo::write() { if (active_) { - functionObjectFile::write(); - - forAll(names(), i) + forAll(cloudNames_, cloudI) { - const word& cloudName = names()[i]; + const word& cloudName = cloudNames_[cloudI]; const kinematicCloud& cloud = obr_.lookupObject(cloudName); @@ -127,12 +156,31 @@ void Foam::cloudInfo::write() scalar massInSystem = returnReduce(cloud.massInSystem(), sumOp()); + scalar Dmax = cloud.Dmax(); + scalar D10 = cloud.Dij(1, 0); + scalar D32 = cloud.Dij(3, 2); + if (Pstream::master()) { - file(i) + filePtrs_[cloudI] << obr_.time().value() << token::TAB << nParcels << token::TAB - << massInSystem << endl; + << massInSystem << token::TAB + << Dmax << token::TAB + << D10 << token::TAB + << D32 << token::TAB + << endl; + } + + if (log_) + { + Info<< type() << " " << name_ << " output:" << nl + << " number of parcels : " << nParcels << nl + << " mass in system : " << massInSystem << nl + << " maximum diameter : " << Dmax << nl + << " D10 diameter : " << D10 << nl + << " D32 diameter : " << D32 << nl + << endl; } } } diff --git a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.H b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.H index 9bd1761061..9e160bbab4 100644 --- a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.H +++ b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,11 +109,20 @@ protected: //- on/off switch bool active_; + //- Switch to send output to Info as well + Switch log_; + + //- List of cloud names + wordList cloudNames_; + + //- Output file per cloud + PtrList filePtrs_; + // Protected Member Functions //- File header information - virtual void writeFileHeader(const label i); + virtual void writeFileHeader(Ostream& os) const; //- Disallow default bitwise copy construct cloudInfo(const cloudInfo&); From 0bf299d07fb0f8b70819d8dbb0128c2ff7e4ba8e Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 12:06:11 +0100 Subject: [PATCH 06/30] STYLE: Updated copyright notices --- .../db/functionObjects/functionObjectFile/functionObjectFile.H | 2 +- .../db/functionObjects/functionObjectList/functionObjectList.C | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H index 6fae16cc58..2dfd5c7c11 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 61df42b667..0c93b738d2 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2011-2014 OpenCFD Ltd + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. From 751bc41650a14b7852b925b0471070b6fd8da805 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 12:07:18 +0100 Subject: [PATCH 07/30] 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(); From 466a2d5173786e0c14179f6459ab2403fdebba1a Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 12:08:07 +0100 Subject: [PATCH 08/30] ENH: regionSizeDistribution FO updated follwing changes to functionObjectFile --- .../regionSizeDistribution.C | 172 ++++++++++++------ .../regionSizeDistribution.H | 7 +- 2 files changed, 121 insertions(+), 58 deletions(-) diff --git a/src/postProcessing/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C b/src/postProcessing/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C index 6a081fd49f..da17d2be68 100644 --- a/src/postProcessing/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C +++ b/src/postProcessing/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,8 +72,11 @@ void Foam::regionSizeDistribution::writeGraph OFstream str(outputPath/formatterPtr_().getFileName(coords, valNames)); - Info<< "Writing distribution of " << valueName << " to " << str.name() - << endl; + if (log_) + { + Info<< "Writing distribution of " << valueName << " to " << str.name() + << endl; + } List valPtrs(1); valPtrs[0] = &values; @@ -149,16 +152,26 @@ void Foam::regionSizeDistribution::writeAlphaFields liquidCore.correctBoundaryConditions(); backgroundAlpha.correctBoundaryConditions(); - Info<< " Volume of liquid-core = " - << fvc::domainIntegrate(liquidCore).value() - << endl; - Info<< " Volume of background = " - << fvc::domainIntegrate(backgroundAlpha).value() - << endl; + if (log_) + { + Info<< " Volume of liquid-core = " + << fvc::domainIntegrate(liquidCore).value() + << endl; + Info<< " Volume of background = " + << fvc::domainIntegrate(backgroundAlpha).value() + << endl; + } - Info<< "Writing liquid-core field to " << liquidCore.name() << endl; + if (log_) + { + Info<< "Writing liquid-core field to " << liquidCore.name() << endl; + } liquidCore.write(); - Info<< "Writing background field to " << backgroundAlpha.name() << endl; + + if (log_) + { + Info<< "Writing background field to " << backgroundAlpha.name() << endl; + } backgroundAlpha.write(); } @@ -322,12 +335,13 @@ Foam::regionSizeDistribution::regionSizeDistribution const bool loadFromFiles ) : - functionObjectFile(obr, name, typeName), + functionObjectFile(obr, name), name_(name), obr_(obr), active_(true), alphaName_(dict.lookup("field")), - patchNames_(dict.lookup("patches")) + patchNames_(dict.lookup("patches")), + log_(true) { // Check if the available mesh is an fvMesh, otherwise deactivate if (isA(obr_)) @@ -364,6 +378,10 @@ void Foam::regionSizeDistribution::read(const dictionary& dict) { if (active_) { + functionObjectFile::read(dict); + + log_.readIfPresent("log", dict); + dict.lookup("field") >> alphaName_; dict.lookup("patches") >> patchNames_; dict.lookup("threshold") >> threshold_; @@ -380,8 +398,11 @@ void Foam::regionSizeDistribution::read(const dictionary& dict) { coordSysPtr_.reset(new coordinateSystem(obr_, dict)); - Info<< "Transforming all vectorFields with coordinate system " - << coordSysPtr_().name() << endl; + if (log_) + { + Info<< "Transforming all vectorFields with coordinate system " + << coordSysPtr_().name() << endl; + } } } } @@ -409,18 +430,18 @@ void Foam::regionSizeDistribution::write() { if (active_) { - Info<< type() << " " << name_ << " output:" << nl; + if (log_) Info << type() << " " << name_ << " output:" << nl; const fvMesh& mesh = refCast(obr_); autoPtr alphaPtr; if (obr_.foundObject(alphaName_)) { - Info<< " Looking up field " << alphaName_ << endl; + if (log_) Info << " Looking up field " << alphaName_ << endl; } else { - Info<< " Reading field " << alphaName_ << endl; + if (log_) Info << " Reading field " << alphaName_ << endl; alphaPtr.reset ( new volScalarField @@ -446,17 +467,24 @@ void Foam::regionSizeDistribution::write() : obr_.lookupObject(alphaName_) ); - Info<< " Volume of alpha = " - << fvc::domainIntegrate(alpha).value() - << endl; + if (log_) + { + Info<< " Volume of alpha = " + << fvc::domainIntegrate(alpha).value() + << endl; + } const scalar meshVol = gSum(mesh.V()); const scalar maxDropletVol = 1.0/6.0*pow(maxDiam_, 3); const scalar delta = (maxDiam_-minDiam_)/nBins_; - Info<< " Mesh volume = " << meshVol << endl; - Info<< " Maximum droplet diameter = " << maxDiam_ << endl; - Info<< " Maximum droplet volume = " << maxDropletVol << endl; + if (log_) + { + Info<< " Mesh volume = " << meshVol << nl + << " Maximum droplet diameter = " << maxDiam_ << nl + << " Maximum droplet volume = " << maxDropletVol + << endl; + } // Determine blocked faces @@ -515,8 +543,11 @@ void Foam::regionSizeDistribution::write() regionSplit regions(mesh, blockedFace); - Info<< " Determined " << regions.nRegions() - << " disconnected regions" << endl; + if (log_) + { + Info<< " Determined " << regions.nRegions() + << " disconnected regions" << endl; + } if (debug) @@ -534,8 +565,13 @@ void Foam::regionSizeDistribution::write() mesh, dimensionedScalar("zero", dimless, 0) ); - Info<< " Dumping region as volScalarField to " << region.name() - << endl; + + if (log_) + { + Info<< " Dumping region as " << volScalarField::typeName + << " to " << region.name() + << endl; + } forAll(regions, cellI) { @@ -566,11 +602,15 @@ void Foam::regionSizeDistribution::write() if (debug) { - Info<< " " << token::TAB << "Region" - << token::TAB << "Volume(mesh)" - << token::TAB << "Volume(" << alpha.name() << "):" - << token::TAB << "nCells" - << endl; + if (log_) + { + Info<< " " << token::TAB << "Region" + << token::TAB << "Volume(mesh)" + << token::TAB << "Volume(" << alpha.name() << "):" + << token::TAB << "nCells" + << endl; + } + scalar meshSumVol = 0.0; scalar alphaSumVol = 0.0; label nCells = 0; @@ -586,50 +626,61 @@ void Foam::regionSizeDistribution::write() ++vIter, ++aIter, ++numIter ) { - Info<< " " << token::TAB << vIter.key() - << token::TAB << vIter() - << token::TAB << aIter() - << token::TAB << numIter() - << endl; + if (log_) + { + Info<< " " << token::TAB << vIter.key() + << token::TAB << vIter() + << token::TAB << aIter() + << token::TAB << numIter() + << endl; + } meshSumVol += vIter(); alphaSumVol += aIter(); nCells += numIter(); } - Info<< " " << token::TAB << "Total:" - << token::TAB << meshSumVol - << token::TAB << alphaSumVol - << token::TAB << nCells - << endl; - Info<< endl; + + if (log_) + { + Info<< " " << token::TAB << "Total:" + << token::TAB << meshSumVol + << token::TAB << alphaSumVol + << token::TAB << nCells + << nl << endl; + } } - + if (log_) { - Info<< " Patch connected regions (liquid core):" << endl; - Info<< token::TAB << " Region" + Info<< " Patch connected regions (liquid core):" << nl + << token::TAB << " Region" << token::TAB << "Volume(mesh)" << token::TAB << "Volume(" << alpha.name() << "):" << endl; + forAllConstIter(Map