diff --git a/applications/utilities/postProcessing/miscellaneous/dsmcFieldsCalc/dsmcFieldsCalc.C b/applications/utilities/postProcessing/miscellaneous/dsmcFieldsCalc/dsmcFieldsCalc.C index 6059ebf5aa..ecd4b4f1ed 100644 --- a/applications/utilities/postProcessing/miscellaneous/dsmcFieldsCalc/dsmcFieldsCalc.C +++ b/applications/utilities/postProcessing/miscellaneous/dsmcFieldsCalc/dsmcFieldsCalc.C @@ -138,7 +138,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh) return; } - dsmcFields dF + functionObjects::dsmcFields dF ( "dsmcFieldsUtility", mesh, diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C index 91b31dda2b..cb256b9b93 100644 --- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C +++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -76,6 +76,18 @@ ${typeName}FunctionObject::${typeName}FunctionObject } +bool ${typeName}FunctionObject::viable +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool +) +{ + return true; +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // ${typeName}FunctionObject::~${typeName}FunctionObject() diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H index a139f25a8b..b1f7e7af8e 100644 --- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H +++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -102,6 +102,16 @@ public: const bool loadFromFilesUnused = false ); + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + static bool viable + ( + const word& name, + const objectRegistry& unused, + const dictionary&, + const bool loadFromFilesUnused = false + ); + //- Destructor virtual ~${typeName}FunctionObject(); diff --git a/etc/codeTemplates/functionObject/FUNCTIONOBJECT.C b/etc/codeTemplates/functionObject/FUNCTIONOBJECT.C index 68189c6d43..5c480baee4 100644 --- a/etc/codeTemplates/functionObject/FUNCTIONOBJECT.C +++ b/etc/codeTemplates/functionObject/FUNCTIONOBJECT.C @@ -71,21 +71,15 @@ void Foam::FUNCTIONOBJECT::read(const dictionary& dict) void Foam::FUNCTIONOBJECT::execute() -{ - // Do nothing - only valid on write -} +{} void Foam::FUNCTIONOBJECT::end() -{ - // Do nothing - only valid on write -} +{} void Foam::FUNCTIONOBJECT::timeSet() -{ - // Do nothing - only valid on write -} +{} void Foam::FUNCTIONOBJECT::write() diff --git a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C index 18b46f29af..e70e55a1bc 100644 --- a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C +++ b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C @@ -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-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -66,6 +66,32 @@ Foam::IOOutputFilter::IOOutputFilter {} +template +bool Foam::IOOutputFilter::viable +( + const word& outputFilterName, + const objectRegistry& obr, + const word& dictName, + const IOobject::readOption rOpt, + const bool readFromFiles +) +{ + IOdictionary dict + ( + IOobject + ( + dictName, + obr.time().system(), + obr, + rOpt, + IOobject::NO_WRITE + ) + ); + + return OutputFilter::viable(outputFilterName, obr, dict, readFromFiles); +} + + template Foam::IOOutputFilter::IOOutputFilter ( @@ -99,6 +125,13 @@ Foam::IOOutputFilter::~IOOutputFilter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +const Foam::word& Foam::IOOutputFilter::name() const +{ + return IOdictionary::name(); +} + + template bool Foam::IOOutputFilter::read() { @@ -121,4 +154,20 @@ void Foam::IOOutputFilter::write() } +template +void Foam::IOOutputFilter::updateMesh(const mapPolyMesh& mpm) +{ + read(); + OutputFilter::updateMesh(mpm); +} + + +template +void Foam::IOOutputFilter::movePoints(const polyMesh& mesh) +{ + read(); + OutputFilter::movePoints(mesh); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H index 77b248f7e8..6950b523f8 100644 --- a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H +++ b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H @@ -94,6 +94,16 @@ public: const bool loadFromFile = false ); + //- Return true if the construction of this functionObject is viable + static bool viable + ( + const word& outputFilterName, + const objectRegistry&, + const word& dictName = OutputFilter::typeName() + "Dict", + const IOobject::readOption rOpt = IOobject::MUST_READ_IF_MODIFIED, + const bool loadFromFiles = false + ); + //- Construct for given objectRegistry and dictionary // Dictionary read from full path. // Allow the possibility to load fields from files @@ -114,10 +124,7 @@ public: // Member Functions //- Return name - virtual const word& name() const - { - return IOdictionary::name(); - } + virtual const word& name() const; //- Inherit read from OutputFilter using OutputFilter::read; @@ -132,18 +139,10 @@ public: virtual void write(); //- Update for changes of mesh - virtual void updateMesh(const mapPolyMesh& mpm) - { - read(); - OutputFilter::updateMesh(mpm); - } + virtual void updateMesh(const mapPolyMesh& mpm); //- Update for changes of mesh - virtual void movePoints(const polyMesh& mesh) - { - read(); - OutputFilter::movePoints(mesh); - } + virtual void movePoints(const polyMesh& mesh); }; diff --git a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C index 100e88f27f..7c81faefc1 100644 --- a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.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-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,32 +55,64 @@ bool Foam::OutputFilterFunctionObject::active() const template -void Foam::OutputFilterFunctionObject::allocateFilter() +bool Foam::OutputFilterFunctionObject::allocateFilter() { if (dictName_.size()) { - ptr_.reset + if ( - new IOOutputFilter + IOOutputFilter::viable ( name(), time_.lookupObject(regionName_), dictName_ ) - ); + ) + { + ptr_.reset + ( + new IOOutputFilter + ( + name(), + time_.lookupObject(regionName_), + dictName_ + ) + ); + } + else + { + enabled_ = false; + } } else { - ptr_.reset + if ( - new OutputFilter + OutputFilter::viable ( name(), time_.lookupObject(regionName_), dict_ ) - ); + ) + { + ptr_.reset + ( + new OutputFilter + ( + name(), + time_.lookupObject(regionName_), + dict_ + ) + ); + } + else + { + enabled_ = false; + } } + + return enabled_; } @@ -144,10 +176,12 @@ bool Foam::OutputFilterFunctionObject::start() if (enabled_ && storeFilter_) { - allocateFilter(); + return allocateFilter(); + } + else + { + return true; } - - return true; } @@ -159,9 +193,9 @@ bool Foam::OutputFilterFunctionObject::execute { if (active()) { - if (!storeFilter_) + if (!storeFilter_ && !allocateFilter()) { - allocateFilter(); + return false; } if (evaluateControl_.output()) @@ -189,9 +223,9 @@ bool Foam::OutputFilterFunctionObject::end() { if (enabled_) { - if (!storeFilter_) + if (!storeFilter_ && !allocateFilter()) { - allocateFilter(); + return false; } ptr_->end(); diff --git a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H index cf97dc5629..5cd592ee83 100644 --- a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H @@ -111,7 +111,7 @@ class OutputFilterFunctionObject void readDict(); //- Creates most of the data associated with this object. - void allocateFilter(); + bool allocateFilter(); //- Destroys most of the data associated with this object. void destroyFilter(); diff --git a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C index 33757db420..821a6cc019 100644 --- a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C +++ b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C @@ -96,7 +96,6 @@ void Foam::fv::rotorDiskSource::checkData() } case ifLocal: { - // Do nothing break; } default: diff --git a/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.C b/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.C index c04f6eca2d..3d5faaf964 100644 --- a/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.C +++ b/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.C @@ -58,8 +58,7 @@ Foam::functionObjects::partialWrite::partialWrite } -Foam::autoPtr -Foam::functionObjects::partialWrite::New +bool Foam::functionObjects::partialWrite::viable ( const word& name, const objectRegistry& obr, @@ -67,17 +66,8 @@ Foam::functionObjects::partialWrite::New const bool loadFromFiles ) { - if (isA(obr)) - { - return autoPtr - ( - new partialWrite(name, obr, dict, loadFromFiles) - ); - } - else - { - return autoPtr(); - } + // Construction is viable if the available mesh is an fvMesh + return isA(obr); } diff --git a/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.H b/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.H index a49aabc129..76a18f5fbc 100644 --- a/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.H +++ b/src/postProcessing/functionObjects/IO/partialWrite/partialWrite.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::partialWrite + Foam::functionObjects::partialWrite Group grpIOFunctionObjects @@ -171,9 +171,9 @@ public: const bool loadFromFiles = false ); - //- Construct on free-store and return pointer if successful - // otherwise return a null-pointer - static autoPtr New + //- Return true if the construction of this functionObject is viable + // i.e. the prerequisites for construction are available + static bool viable ( const word& name, const objectRegistry&, diff --git a/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.C b/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.C index ea296544c3..9bd09cd0b6 100644 --- a/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.C +++ b/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.C @@ -56,8 +56,7 @@ Foam::functionObjects::removeRegisteredObject::removeRegisteredObject } -Foam::autoPtr -Foam::functionObjects::removeRegisteredObject::New +bool Foam::functionObjects::removeRegisteredObject::viable ( const word& name, const objectRegistry& obr, @@ -65,10 +64,7 @@ Foam::functionObjects::removeRegisteredObject::New const bool loadFromFiles ) { - return autoPtr - ( - new removeRegisteredObject(name, obr, dict, loadFromFiles) - ); + return true; } diff --git a/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.H b/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.H index 860a2e9863..5bbb16d923 100644 --- a/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.H +++ b/src/postProcessing/functionObjects/IO/removeRegisteredObject/removeRegisteredObject.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::removeRegisteredObject + Foam::functionObjects::removeRegisteredObject Group grpIOFunctionObjects @@ -128,9 +128,9 @@ public: const bool loadFromFiles = false ); - //- Construct on free-store and return pointer if successful - // otherwise return a null-pointer - static autoPtr New + //- Return true if the construction of this functionObject is viable + // i.e. the prerequisites for construction are available + static bool viable ( const word& name, const objectRegistry&, diff --git a/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.C b/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.C index 7acd2abefb..afe37cf4a3 100644 --- a/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.C +++ b/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.C @@ -107,8 +107,7 @@ Foam::functionObjects::writeDictionary::writeDictionary } -Foam::autoPtr -Foam::functionObjects::writeDictionary::New +bool Foam::functionObjects::writeDictionary::viable ( const word& name, const objectRegistry& obr, @@ -116,10 +115,7 @@ Foam::functionObjects::writeDictionary::New const bool loadFromFiles ) { - return autoPtr - ( - new writeDictionary(name, obr, dict, loadFromFiles) - ); + return true; } diff --git a/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.H b/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.H index 19d42766ef..3f822fa89a 100644 --- a/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.H +++ b/src/postProcessing/functionObjects/IO/writeDictionary/writeDictionary.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::writeDictionary + Foam::functionObjects::writeDictionary Group grpUtilitiesFunctionObjects @@ -120,9 +120,9 @@ public: const bool loadFromFiles = false ); - //- Construct on free-store and return pointer if successful - // otherwise return a null-pointer - static autoPtr New + //- Return true if the construction of this functionObject is viable + // i.e. the prerequisites for construction are available + static bool viable ( const word& name, const objectRegistry&, diff --git a/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.C b/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.C index ad68d6b9ae..6385ad89b1 100644 --- a/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.C +++ b/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.C @@ -57,8 +57,7 @@ Foam::functionObjects::writeRegisteredObject::writeRegisteredObject } -Foam::autoPtr -Foam::functionObjects::writeRegisteredObject::New +bool Foam::functionObjects::writeRegisteredObject::viable ( const word& name, const objectRegistry& obr, @@ -66,10 +65,7 @@ Foam::functionObjects::writeRegisteredObject::New const bool loadFromFiles ) { - return autoPtr - ( - new writeRegisteredObject(name, obr, dict, loadFromFiles) - ); + return true; } diff --git a/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.H b/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.H index 37bb625c4e..8fb674a883 100644 --- a/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.H +++ b/src/postProcessing/functionObjects/IO/writeRegisteredObject/writeRegisteredObject.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::writeRegisteredObject + Foam::functionObjects::writeRegisteredObject Group grpIOFunctionObjects @@ -143,9 +143,9 @@ public: const bool loadFromFiles = false ); - //- Construct on free-store and return pointer if successful - // otherwise return a null-pointer - static autoPtr New + //- Return true if the construction of this functionObject is viable + // i.e. the prerequisites for construction are available + static bool viable ( const word& name, const objectRegistry&, diff --git a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C index f17f366845..7641bf5c01 100644 --- a/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C +++ b/src/postProcessing/functionObjects/cloud/cloudInfo/cloudInfo.C @@ -62,15 +62,13 @@ Foam::functionObjects::cloudInfo::cloudInfo : functionObjectFiles(obr, name), name_(name), - obr_(obr), - active_(true) + obr_(obr) { read(dict); } -Foam::autoPtr -Foam::functionObjects::cloudInfo::New +bool Foam::functionObjects::cloudInfo::viable ( const word& name, const objectRegistry& obr, @@ -78,10 +76,7 @@ Foam::functionObjects::cloudInfo::New const bool loadFromFiles ) { - return autoPtr - ( - new cloudInfo(name, obr, dict, loadFromFiles) - ); + return true; } @@ -95,24 +90,21 @@ Foam::functionObjects::cloudInfo::~cloudInfo() void Foam::functionObjects::cloudInfo::read(const dictionary& dict) { - if (active_) - { - functionObjectFiles::resetNames(dict.lookup("clouds")); + functionObjectFiles::resetNames(dict.lookup("clouds")); - Info<< type() << " " << name_ << ": "; - if (names().size()) + Info<< type() << " " << name_ << ": "; + if (names().size()) + { + Info<< "applying to clouds:" << nl; + forAll(names(), i) { - Info<< "applying to clouds:" << nl; - forAll(names(), i) - { - Info<< " " << names()[i] << nl; - } - Info<< endl; - } - else - { - Info<< "no clouds to be processed" << nl << endl; + Info<< " " << names()[i] << nl; } + Info<< endl; + } + else + { + Info<< "no clouds to be processed" << nl << endl; } } @@ -131,29 +123,26 @@ void Foam::functionObjects::cloudInfo::timeSet() void Foam::functionObjects::cloudInfo::write() { - if (active_) + functionObjectFiles::write(); + + forAll(names(), i) { - functionObjectFiles::write(); + const word& cloudName = names()[i]; - forAll(names(), i) + const kinematicCloud& cloud = + obr_.lookupObject(cloudName); + + label nParcels = returnReduce(cloud.nParcels(), sumOp