Commit 0534a225 authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Moved into the functionObjects namespace and rationalized and...

functionObjects: Moved into the functionObjects namespace and rationalized and simplified failable construction

Rather than requiring each functionObject to handle failed construction
internally (using the active_ flag) the static member function "viable"
is provided which returns true if construction of the functionObject is
likely to be successful.  Failed construction is then handled by the
wrapper-class which constructs the functionObject,
e.g. "OutputFilterFunctionObject".
parent 09262f52
......@@ -138,7 +138,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
return;
}
dsmcFields dF
functionObjects::dsmcFields dF
(
"dsmcFieldsUtility",
mesh,
......
......@@ -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()
......
......@@ -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();
......
......@@ -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()
......
......@@ -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<OutputFilter>::IOOutputFilter
{}
template<class OutputFilter>
bool Foam::IOOutputFilter<OutputFilter>::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<class OutputFilter>
Foam::IOOutputFilter<OutputFilter>::IOOutputFilter
(
......@@ -99,6 +125,13 @@ Foam::IOOutputFilter<OutputFilter>::~IOOutputFilter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class OutputFilter>
const Foam::word& Foam::IOOutputFilter<OutputFilter>::name() const
{
return IOdictionary::name();
}
template<class OutputFilter>
bool Foam::IOOutputFilter<OutputFilter>::read()
{
......@@ -121,4 +154,20 @@ void Foam::IOOutputFilter<OutputFilter>::write()
}
template<class OutputFilter>
void Foam::IOOutputFilter<OutputFilter>::updateMesh(const mapPolyMesh& mpm)
{
read();
OutputFilter::updateMesh(mpm);
}
template<class OutputFilter>
void Foam::IOOutputFilter<OutputFilter>::movePoints(const polyMesh& mesh)
{
read();
OutputFilter::movePoints(mesh);
}
// ************************************************************************* //
......@@ -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);
};
......
......@@ -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<OutputFilter>::active() const
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::allocateFilter()
bool Foam::OutputFilterFunctionObject<OutputFilter>::allocateFilter()
{
if (dictName_.size())
{
ptr_.reset
if
(
new IOOutputFilter<OutputFilter>
IOOutputFilter<OutputFilter>::viable
(
name(),
time_.lookupObject<objectRegistry>(regionName_),
dictName_
)
);
)
{
ptr_.reset
(
new IOOutputFilter<OutputFilter>
(
name(),
time_.lookupObject<objectRegistry>(regionName_),
dictName_
)
);
}
else
{
enabled_ = false;
}
}
else
{
ptr_.reset
if
(
new OutputFilter
OutputFilter::viable
(
name(),
time_.lookupObject<objectRegistry>(regionName_),
dict_
)
);
)
{
ptr_.reset
(
new OutputFilter
(
name(),
time_.lookupObject<objectRegistry>(regionName_),
dict_
)
);
}
else
{
enabled_ = false;
}
}
return enabled_;
}
......@@ -144,10 +176,12 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
if (enabled_ && storeFilter_)
{
allocateFilter();
return allocateFilter();
}
else
{
return true;
}
return true;
}
......@@ -159,9 +193,9 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::execute
{
if (active())
{
if (!storeFilter_)
if (!storeFilter_ && !allocateFilter())
{
allocateFilter();
return false;
}
if (evaluateControl_.output())
......@@ -189,9 +223,9 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
{
if (enabled_)
{
if (!storeFilter_)
if (!storeFilter_ && !allocateFilter())
{
allocateFilter();
return false;
}
ptr_->end();
......
......@@ -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();
......
......@@ -96,7 +96,6 @@ void Foam::fv::rotorDiskSource::checkData()
}
case ifLocal:
{
// Do nothing
break;
}
default:
......
......@@ -58,8 +58,7 @@ Foam::functionObjects::partialWrite::partialWrite
}
Foam::autoPtr<Foam::functionObjects::partialWrite>
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<fvMesh>(obr))
{
return autoPtr<partialWrite>
(
new partialWrite(name, obr, dict, loadFromFiles)
);
}
else
{
return autoPtr<partialWrite>();
}
// Construction is viable if the available mesh is an fvMesh
return isA<fvMesh>(obr);
}
......
......@@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
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<partialWrite> 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&,
......
......@@ -56,8 +56,7 @@ Foam::functionObjects::removeRegisteredObject::removeRegisteredObject
}
Foam::autoPtr<Foam::functionObjects::removeRegisteredObject>
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<removeRegisteredObject>
(
new removeRegisteredObject(name, obr, dict, loadFromFiles)
);
return true;
}
......
......@@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
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<removeRegisteredObject> 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&,
......
......@@ -107,8 +107,7 @@ Foam::functionObjects::writeDictionary::writeDictionary
}
Foam::autoPtr<Foam::functionObjects::writeDictionary>
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<writeDictionary>
(
new writeDictionary(name, obr, dict, loadFromFiles)
);
return true;
}
......
......@@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
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<writeDictionary> 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&,
......
......@@ -57,8 +57,7 @@ Foam::functionObjects::writeRegisteredObject::writeRegisteredObject
}
Foam::autoPtr<Foam::functionObjects::writeRegisteredObject>
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<writeRegisteredObject>
(
new writeRegisteredObject(name, obr, dict, loadFromFiles)
);
return true;
}
......
......@@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
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<writeRegisteredObject> 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&,
......
......@@ -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>
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<cloudInfo>
(
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<< "applying to clouds:" << nl;
forAll(names(), i)
{
Info<< " " << names()[i] << nl;
}
Info<< endl;
}
else
Info<< type() << " " << name_ << ": ";
if (names().size())
{
Info<< "applying to clouds:" << nl;
forAll(names(), i)
{
Info<< "no clouds to be processed" << nl << endl;
Info<< " " << names()[i] << nl;
}
Info<< endl;