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:
@ -31,13 +31,16 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(processorField, 0);
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(processorField, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::processorField::processorField
|
||||
Foam::functionObjects::processorField::processorField
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
@ -46,96 +49,85 @@ Foam::processorField::processorField
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
active_(true)
|
||||
obr_(obr)
|
||||
{
|
||||
// Check if the available mesh is an fvMesh otherise deactivate
|
||||
if (isA<fvMesh>(obr_))
|
||||
{
|
||||
read(dict);
|
||||
read(dict);
|
||||
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
|
||||
volScalarField* procFieldPtr
|
||||
volScalarField* procFieldPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
new volScalarField
|
||||
IOobject
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"processorID",
|
||||
mesh.time().timeName(),
|
||||
mesh,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
"processorID",
|
||||
mesh.time().timeName(),
|
||||
mesh,
|
||||
dimensionedScalar("0", dimless, 0.0)
|
||||
)
|
||||
);
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh,
|
||||
dimensionedScalar("0", dimless, 0.0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh.objectRegistry::store(procFieldPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
active_ = false;
|
||||
WarningInFunction
|
||||
<< "No fvMesh available, deactivating " << name_
|
||||
<< endl;
|
||||
}
|
||||
mesh.objectRegistry::store(procFieldPtr);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::processorField::viable
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles
|
||||
)
|
||||
{
|
||||
// Construction is viable if the available mesh is an fvMesh
|
||||
return isA<fvMesh>(obr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::processorField::~processorField()
|
||||
Foam::functionObjects::processorField::~processorField()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::processorField::read(const dictionary& dict)
|
||||
void Foam::functionObjects::processorField::read(const dictionary& dict)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::functionObjects::processorField::execute()
|
||||
{
|
||||
// do nothing
|
||||
const volScalarField& procField =
|
||||
obr_.lookupObject<volScalarField>("processorID");
|
||||
|
||||
const_cast<volScalarField&>(procField) ==
|
||||
dimensionedScalar("proci", dimless, Pstream::myProcNo());
|
||||
}
|
||||
|
||||
|
||||
void Foam::processorField::execute()
|
||||
void Foam::functionObjects::processorField::end()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
const volScalarField& procField =
|
||||
obr_.lookupObject<volScalarField>("processorID");
|
||||
|
||||
const_cast<volScalarField&>(procField) ==
|
||||
dimensionedScalar("proci", dimless, Pstream::myProcNo());
|
||||
}
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
void Foam::processorField::end()
|
||||
void Foam::functionObjects::processorField::timeSet()
|
||||
{}
|
||||
|
||||
|
||||
void Foam::functionObjects::processorField::write()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
execute();
|
||||
}
|
||||
}
|
||||
const volScalarField& procField =
|
||||
obr_.lookupObject<volScalarField>("processorID");
|
||||
|
||||
|
||||
void Foam::processorField::timeSet()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void Foam::processorField::write()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
const volScalarField& procField =
|
||||
obr_.lookupObject<volScalarField>("processorID");
|
||||
|
||||
procField.write();
|
||||
}
|
||||
procField.write();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::processorField
|
||||
Foam::functionObjects::processorField
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
@ -76,6 +76,9 @@ class objectRegistry;
|
||||
class dictionary;
|
||||
class mapPolyMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class processorField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -92,9 +95,6 @@ protected:
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- on/off switch
|
||||
bool active_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -125,6 +125,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 ~processorField();
|
||||
@ -165,6 +175,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<processorField>
|
||||
typedef OutputFilterFunctionObject<functionObjects::processorField>
|
||||
processorFieldFunctionObject;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user