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".
This commit is contained in:
Henry Weller
2016-05-02 16:28:24 +01:00
parent 09262f5273
commit 0534a225fd
175 changed files with 4667 additions and 4353 deletions

View File

@ -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);
}
// ************************************************************************* //

View File

@ -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);
};

View File

@ -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();

View File

@ -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();