Commit 78d2971b authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: rewritten to all be derived from 'functionObject'

  - Avoids the need for the 'OutputFilterFunctionObject' wrapper
  - Time-control for execution and writing is now provided by the
    'timeControlFunctionObject' which instantiates the processing
    'functionObject' and controls its operation.
  - Alternative time-control functionObjects can now be written and
    selected at run-time without the need to compile wrapped version of
    EVERY existing functionObject which would have been required in the
    old structure.
  - The separation of 'execute' and 'write' functions is now formalized in the
    'functionObject' base-class and all derived classes implement the
    two functions.
  - Unnecessary implementations of functions with appropriate defaults
    in the 'functionObject' base-class have been removed reducing
    clutter and simplifying implementation of new functionObjects.
  - The 'coded' 'functionObject' has also been updated, simplified and tested.
  - Further simplification is now possible by creating some general
    intermediate classes derived from 'functionObject'.
parent ce0cd351
......@@ -2,11 +2,11 @@ EXE_INC = \
-IfoamToVTK/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfoamToVTK \
-lfiniteVolume \
-ldynamicMesh \
-llagrangian \
-lgenericPatchFields \
-lmeshTools
-lgenericPatchFields
......@@ -10,6 +10,5 @@ vtkMesh.C
vtkTopo.C
writeVTK/writeVTK.C
writeVTK/writeVTKFunctionObject.C
LIB = $(FOAM_LIBBIN)/libfoamToVTK
EXE_INC = \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-ldynamicMesh \
-llagrangian \
-lgenericPatchFields \
-lmeshTools
-lgenericPatchFields
......@@ -28,6 +28,7 @@ License
#include "Time.H"
#include "vtkMesh.H"
#include "internalWriter.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -36,6 +37,7 @@ namespace Foam
namespace functionObjects
{
defineTypeNameAndDebug(writeVTK, 0);
addToRunTimeSelectionTable(functionObject, writeVTK, dictionary);
}
}
......@@ -45,16 +47,22 @@ namespace functionObjects
Foam::functionObjects::writeVTK::writeVTK
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const Time& t,
const dictionary& dict
)
:
name_(name),
obr_(obr),
functionObject(name),
time_(t),
obr_
(
time_.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
objectNames_()
{
if (!isA<fvMesh>(obr))
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
......@@ -72,27 +80,23 @@ Foam::functionObjects::writeVTK::~writeVTK()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::writeVTK::read(const dictionary& dict)
bool Foam::functionObjects::writeVTK::read(const dictionary& dict)
{
dict.lookup("objectNames") >> objectNames_;
}
void Foam::functionObjects::writeVTK::execute()
{}
void Foam::functionObjects::writeVTK::end()
{}
return true;
}
void Foam::functionObjects::writeVTK::timeSet()
{}
bool Foam::functionObjects::writeVTK::execute(const bool postProcess)
{
return true;
}
void Foam::functionObjects::writeVTK::write()
bool Foam::functionObjects::writeVTK::write(const bool postProcess)
{
Info<< type() << " " << name_ << " output:" << nl;
Info<< type() << " " << name() << " output:" << nl;
fvMesh& mesh = const_cast<fvMesh&>(refCast<const fvMesh>(obr_));
......@@ -162,6 +166,8 @@ void Foam::functionObjects::writeVTK::write()
writer.write(vsptf);
writer.write(vstf);
writer.write(vtf);
return true;
}
......
......@@ -55,7 +55,7 @@ Description
SeeAlso
Foam::functionObject
Foam::OutputFilterFunctionObject
Foam::functionObjects::timeControl
SourceFiles
writeVTK.C
......@@ -66,8 +66,8 @@ SourceFiles
#ifndef functionObjects_writeVTK_H
#define functionObjects_writeVTK_H
#include "functionObject.H"
#include "wordReList.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -75,10 +75,8 @@ namespace Foam
{
// Forward declaration of classes
class Time;
class objectRegistry;
class dictionary;
class polyMesh;
class mapPolyMesh;
namespace functionObjects
{
......@@ -88,13 +86,15 @@ namespace functionObjects
\*---------------------------------------------------------------------------*/
class writeVTK
:
public functionObject
{
// Private data
//- Name of this set of writeVTK
word name_;
//- Reference to the Time
const Time& time_;
//- Refererence to Db
//- Refererence to objectRegistry
const objectRegistry& obr_;
//- Names of objects
......@@ -121,14 +121,12 @@ public:
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
//- Construct from Time and dictionary
writeVTK
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
const Time& t,
const dictionary&
);
......@@ -138,34 +136,14 @@ public:
// Member Functions
//- Return name of the writeVTK
virtual const word& name() const
{
return name_;
}
//- Read the writeVTK data
virtual void read(const dictionary&);
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
virtual bool execute(const bool postProcess = false);
//- Write the writeVTK
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const polyMesh&)
{}
virtual bool write(const bool postProcess = false);
};
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "writeVTKFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug
(
writeVTKFunctionObject,
0
);
addToRunTimeSelectionTable
(
functionObject,
writeVTKFunctionObject,
dictionary
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::writeVTKFunctionObject
Description
FunctionObject wrapper around writeVTK to allow them to be
created via the functions entry within controlDict.
SourceFiles
writeVTKFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef writeVTKFunctionObject_H
#define writeVTKFunctionObject_H
#include "writeVTK.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<functionObjects::writeVTK>
writeVTKFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
EXE_INC = \
-I$(LIB_SRC)/postProcessing/postCalc \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/postProcessing/functionObjects/utilities/lnInclude \
-I$(LIB_SRC)/lagrangian/DSMC/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
$(FOAM_LIBBIN)/postCalc.o \
-lmeshTools \
-lfiniteVolume \
-lutilityFunctionObjects \
-llagrangian \
-lDSMC
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
dsmcFieldsCalc
Description
Calculate intensive fields (U and T) from averaged extensive fields from a
DSMC calculation.
\*---------------------------------------------------------------------------*/
#include "calc.H"
#include "fvc.H"
#include "dsmcCloud.H"
#include "dsmcFields.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
bool addFieldsToList
(
const fvMesh& mesh,
PtrList<GeometricField<Type, fvPatchField, volMesh>>& list,
const wordList& fieldNames
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
label index = 0;
forAll(fieldNames, i)
{
IOobject obj
(
fieldNames[i],
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
);
if (obj.headerOk() && obj.headerClassName() == fieldType::typeName)
{
list.set(index++, new fieldType(obj, mesh));
}
else
{
Info<< "Could not find " << fieldNames[i] << endl;
return false;
}
}
return true;
}
}
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
bool writeResults = !args.optionFound("noWrite");
wordList extensiveVSFNames
(
IStringStream
(
"( \
rhoNMean \
rhoMMean \
linearKEMean \
internalEMean \
iDofMean \
)"
)()
);
PtrList<volScalarField> extensiveVSFs(extensiveVSFNames.size());
if
(
!addFieldsToList
(
mesh,
extensiveVSFs,
extensiveVSFNames
)
)
{
return;
}
wordList extensiveVVFNames
(
IStringStream
(
"( \
momentumMean \
fDMean \
)"
)()
);
PtrList<volVectorField> extensiveVVFs(extensiveVVFNames.size());
if
(
!addFieldsToList
(
mesh,
extensiveVVFs,
extensiveVVFNames
)
)
{
return;
}
functionObjects::dsmcFields dF
(
"dsmcFieldsUtility",
mesh,
dictionary::null,
false
);
if (writeResults)
{
dF.write();
}
}
// ************************************************************************* //
......@@ -82,7 +82,7 @@ SeeAlso
#include "noiseFFT.H"
#include "argList.H"
#include "Time.H"
#include "functionObjectFiles.H"
#include "writeFiles.H"
#include "CSV.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "FilterFunctionObjectTemplate.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
extern "C"
{
// dynamicCode:
// SHA1 = ${SHA1sum}
//
// unique function name that can be checked if the correct library version
// has been loaded
void ${typeName}_${SHA1sum}(bool load)
{
if (load)
{
// code that can be explicitly executed after loading
}
else
{
// code that can be explicitly executed before unloading
}
}
}
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(${typeName}FilterFunctionObject, 0);
//addToRunTimeSelectionTable
addRemovableToRunTimeSelectionTable
(
functionObject,
${typeName}FilterFunctionObject,
dictionary
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |