mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -39,7 +39,8 @@ Description
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef IOOutputFilter<timeActivatedFileUpdate> IOtimeActivatedFileUpdate;
|
||||
typedef IOOutputFilter<functionObjects::timeActivatedFileUpdate>
|
||||
IOtimeActivatedFileUpdate;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,14 +31,17 @@ License
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(timeActivatedFileUpdate, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::timeActivatedFileUpdate::updateFile()
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
|
||||
{
|
||||
label i = lastIndex_;
|
||||
while
|
||||
@ -63,7 +66,7 @@ void Foam::timeActivatedFileUpdate::updateFile()
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::timeActivatedFileUpdate::timeActivatedFileUpdate
|
||||
Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
@ -73,7 +76,6 @@ Foam::timeActivatedFileUpdate::timeActivatedFileUpdate
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
active_(true),
|
||||
fileToUpdate_(dict.lookup("fileToUpdate")),
|
||||
timeVsFile_(),
|
||||
lastIndex_(-1)
|
||||
@ -82,73 +84,75 @@ Foam::timeActivatedFileUpdate::timeActivatedFileUpdate
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::timeActivatedFileUpdate::viable
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::timeActivatedFileUpdate::~timeActivatedFileUpdate()
|
||||
Foam::functionObjects::timeActivatedFileUpdate::~timeActivatedFileUpdate()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::timeActivatedFileUpdate::read(const dictionary& dict)
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
if (active_)
|
||||
dict.lookup("fileToUpdate") >> fileToUpdate_;
|
||||
dict.lookup("timeVsFile") >> timeVsFile_;
|
||||
|
||||
lastIndex_ = -1;
|
||||
fileToUpdate_.expand();
|
||||
|
||||
Info<< type() << ": time vs file list:" << nl;
|
||||
forAll(timeVsFile_, i)
|
||||
{
|
||||
dict.lookup("fileToUpdate") >> fileToUpdate_;
|
||||
dict.lookup("timeVsFile") >> timeVsFile_;
|
||||
|
||||
lastIndex_ = -1;
|
||||
fileToUpdate_.expand();
|
||||
|
||||
Info<< type() << ": time vs file list:" << nl;
|
||||
forAll(timeVsFile_, i)
|
||||
timeVsFile_[i].second() = timeVsFile_[i].second().expand();
|
||||
if (!isFile(timeVsFile_[i].second()))
|
||||
{
|
||||
timeVsFile_[i].second() = timeVsFile_[i].second().expand();
|
||||
if (!isFile(timeVsFile_[i].second()))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "File: " << timeVsFile_[i].second() << " not found"
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
Info<< " " << timeVsFile_[i].first() << tab
|
||||
<< timeVsFile_[i].second() << endl;
|
||||
FatalErrorInFunction
|
||||
<< "File: " << timeVsFile_[i].second() << " not found"
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
updateFile();
|
||||
Info<< " " << timeVsFile_[i].first() << tab
|
||||
<< timeVsFile_[i].second() << endl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
updateFile();
|
||||
}
|
||||
|
||||
|
||||
void Foam::timeActivatedFileUpdate::execute()
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::execute()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
updateFile();
|
||||
}
|
||||
updateFile();
|
||||
}
|
||||
|
||||
|
||||
void Foam::timeActivatedFileUpdate::end()
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::end()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
execute();
|
||||
}
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
void Foam::timeActivatedFileUpdate::timeSet()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::timeSet()
|
||||
{}
|
||||
|
||||
|
||||
void Foam::timeActivatedFileUpdate::write()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::write()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -22,7 +22,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::timeActivatedFileUpdate
|
||||
Foam::functionObjects::timeActivatedFileUpdate
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
@ -73,6 +73,9 @@ class dictionary;
|
||||
class polyMesh;
|
||||
class mapPolyMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class timeActivatedFileUpdate Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -87,9 +90,6 @@ class timeActivatedFileUpdate
|
||||
//- Owner database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- On/off switch
|
||||
bool active_;
|
||||
|
||||
//- Name of file to update
|
||||
fileName fileToUpdate_;
|
||||
|
||||
@ -130,6 +130,16 @@ public:
|
||||
const bool loadFromFiles = false
|
||||
);
|
||||
|
||||
//- 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&,
|
||||
const dictionary&,
|
||||
const bool loadFromFiles = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~timeActivatedFileUpdate();
|
||||
@ -170,6 +180,7 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -43,7 +43,7 @@ SourceFiles
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef OutputFilterFunctionObject<timeActivatedFileUpdate>
|
||||
typedef OutputFilterFunctionObject<functionObjects::timeActivatedFileUpdate>
|
||||
timeActivatedFileUpdateFunctionObject;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user