Time and functionObject updated for end()

- added end() method to functionObject, functionObjectList & associated classes
- moved outputFilters from src/sampling -> src/OpenFOAM/db/functionObjects
This commit is contained in:
Mark Olesen
2009-02-17 12:48:10 +01:00
parent c2256e51f3
commit fee6e312b9
35 changed files with 255 additions and 114 deletions

View File

@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "IOOutputFilter.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class OutputFilter>
Foam::IOOutputFilter<OutputFilter>::IOOutputFilter
(
const word& outputFilterName,
const objectRegistry& obr,
const fileName& dictName,
const IOobject::readOption rOpt,
const bool readFromFiles
)
:
IOdictionary
(
IOobject
(
dictName,
obr.time().system(),
obr,
rOpt,
IOobject::NO_WRITE
)
),
OutputFilter(outputFilterName, obr, *this, readFromFiles)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class OutputFilter>
Foam::IOOutputFilter<OutputFilter>::~IOOutputFilter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class OutputFilter>
bool Foam::IOOutputFilter<OutputFilter>::read()
{
if (regIOobject::read())
{
OutputFilter::read(*this);
return true;
}
else
{
return false;
}
}
template<class OutputFilter>
void Foam::IOOutputFilter<OutputFilter>::write()
{
OutputFilter::write();
}
// ************************************************************************* //

View File

@ -0,0 +1,133 @@
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::IOOutputFilter
Description
IOdictionary wrapper around OutputFilter to allow them to read from
their associated dictionaries.
SourceFiles
IOOutputFilter.C
\*---------------------------------------------------------------------------*/
#ifndef IOOutputFilter_H
#define IOOutputFilter_H
#include "IOdictionary.H"
#include "pointFieldFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class IOOutputFilter Declaration
\*---------------------------------------------------------------------------*/
template<class OutputFilter>
class IOOutputFilter
:
public IOdictionary,
public OutputFilter
{
// Private Member Functions
// Disallow default bitwise copy construct and assignment
IOOutputFilter(const IOOutputFilter&);
void operator=(const IOOutputFilter&);
public:
// Constructors
//- Construct for given objectRegistry and dictionary
// Allow dictionary to be optional
// Allow the possibility to load fields from files
IOOutputFilter
(
const word& outputFilterName,
const objectRegistry&,
const fileName& dictName = OutputFilter::typeName() + "Dict",
const IOobject::readOption rOpt = IOobject::MUST_READ,
const bool loadFromFile = false
);
//- Destructor
virtual ~IOOutputFilter();
// Member Functions
//- Return name
virtual const word& name() const
{
return IOdictionary::name();
}
//- Read the probes
virtual bool read();
//- Sample and write
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh& mpm)
{
read();
OutputFilter::updateMesh(mpm);
}
//- Update for changes of mesh
virtual void movePoints(const pointField& points)
{
read();
OutputFilter::movePoints(points);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "IOOutputFilter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OutputFilterFunctionObject.H"
#include "IOOutputFilter.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
{
dict_.readIfPresent("region", regionName_);
dict_.readIfPresent("dictionary", dictName_);
dict_.readIfPresent("enabled", enabled_);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class OutputFilter>
Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
(
const word& name,
const Time& t,
const dictionary& dict
)
:
functionObject(),
name_(name),
time_(t),
dict_(dict),
regionName_(polyMesh::defaultRegion),
dictName_(),
enabled_(true),
outputControl_(t, dict)
{
readDict();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::on()
{
enabled_ = true;
}
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::off()
{
enabled_ = false;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
{
readDict();
if (enabled_)
{
if (dictName_.size())
{
ptr_.reset
(
new IOOutputFilter<OutputFilter>
(
name_,
time_.lookupObject<objectRegistry>(regionName_),
dictName_
)
);
}
else
{
ptr_.reset
(
new OutputFilter
(
name_,
time_.lookupObject<objectRegistry>(regionName_),
dict_
)
);
}
}
return true;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
{
if (enabled_)
{
ptr_->execute();
if (enabled_ && outputControl_.output())
{
ptr_->write();
}
}
return true;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
{
if (enabled_)
{
ptr_->end();
if (enabled_ && outputControl_.output())
{
ptr_->write();
}
}
return true;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::read
(
const dictionary& dict
)
{
if (dict != dict_)
{
dict_ = dict;
outputControl_.read(dict);
return start();
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,153 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::OutputFilterFunctionObject
Description
A functionObject wrapper around OutputFilter to allow them to be
created via the functions list within controlDict.
Note
Since the timeIndex is used directly from Foam::Time, it is unaffected
by user-time conversions. For example, Foam::engineTime might cause @a
writeInterval to be degrees crank angle, but the functionObject
execution @a interval would still be in timestep.
SourceFiles
OutputFilterFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef OutputFilterFunctionObject_H
#define OutputFilterFunctionObject_H
#include "functionObject.H"
#include "dictionary.H"
#include "outputFilterOutputControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class OutputFilterFunctionObject Declaration
\*---------------------------------------------------------------------------*/
template<class OutputFilter>
class OutputFilterFunctionObject
:
public functionObject
{
// Private data
word name_;
const Time& time_;
dictionary dict_;
word regionName_;
word dictName_;
//- Switch for the execution of the functionObject
bool enabled_;
outputFilterOutputControl outputControl_;
autoPtr<OutputFilter> ptr_;
// Private Member Functions
//- Read relevant dictionary entries
void readDict();
//- Disallow default bitwise copy construct
OutputFilterFunctionObject(const OutputFilterFunctionObject&);
//- Disallow default bitwise assignment
void operator=(const OutputFilterFunctionObject&);
public:
//- Runtime type information
TypeName(OutputFilter::typeName_());
// Constructors
//- Construct from components
OutputFilterFunctionObject
(
const word& name,
const Time&,
const dictionary&
);
// Member Functions
//- Return name
virtual const word& name() const
{
return name_;
}
//- Switch the function object on
virtual void on();
//- Switch the function object off
virtual void off();
//- Called at the start of the time-loop
virtual bool start();
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "OutputFilterFunctionObject.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,123 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "functionObject.H"
#include "dictionary.H"
#include "dlLibraryTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineRunTimeSelectionTable(Foam::functionObject, dictionary);
int Foam::functionObject::debug(Foam::debug::debugSwitch("functionObject", 0));
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObject::functionObject()
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
(
const word& name,
const Time& t,
const dictionary& functionDict
)
{
word functionType(functionDict.lookup("type"));
if (debug)
{
Info<< "Selecting function " << functionType << endl;
}
dlLibraryTable::open
(
functionDict,
"functionObjectLibs",
dictionaryConstructorTablePtr_
);
if (!dictionaryConstructorTablePtr_)
{
FatalErrorIn
(
"functionObject::New"
"(const word& name, const Time&, const dictionary&)"
) << "Unknown function type "
<< functionType << nl << nl
<< "Table of functionObjects is empty" << endl
<< exit(FatalError);
}
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(functionType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"functionObject::New"
"(const word& name, const Time&, const dictionary&)"
) << "Unknown function type "
<< functionType << nl << nl
<< "Valid functions are : " << nl
<< dictionaryConstructorTablePtr_->toc() << endl
<< exit(FatalError);
}
return autoPtr<functionObject>(cstrIter()(name, t, functionDict));
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObject::~functionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObject::end()
{
return execute();
}
Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
(
const word& name,
Istream& is
) const
{
dictionary dict(is);
return functionObject::New(name, time_, dict);
}
// ************************************************************************* //

View File

@ -0,0 +1,163 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::functionObject
Description
Abstract base-class for Time/database function objects.
See Also
Foam::OutputFilterFunctionObject
SourceFiles
functionObject.C
\*---------------------------------------------------------------------------*/
#ifndef functionObject_H
#define functionObject_H
#include "typeInfo.H"
#include "autoPtr.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Time;
/*---------------------------------------------------------------------------*\
Class functionObject Declaration
\*---------------------------------------------------------------------------*/
class functionObject
{
// Private Member Functions
//- Disallow default bitwise copy construct
functionObject(const functionObject&);
//- Disallow default bitwise assignment
void operator=(const functionObject&);
public:
//- Runtime type information
virtual const word& type() const = 0;
static int debug;
// Declare run-time constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
functionObject,
dictionary,
(const word& name, const Time& t, const dictionary& dict),
(name, t, dict)
);
// Constructors
//- Construct null
functionObject();
//- Return clone
autoPtr<functionObject> clone() const
{
notImplemented("functionObject::clone() const");
return autoPtr<functionObject>(NULL);
}
//- Return a pointer to a new functionObject created on freestore
// from Istream
class iNew
{
const Time& time_;
public:
iNew(const Time& t)
:
time_(t)
{}
autoPtr<functionObject> operator()
(
const word& name,
Istream& is
) const;
};
// Selectors
//- Select from dictionary, based on its "type" entry
static autoPtr<functionObject> New
(
const word& name,
const Time&,
const dictionary&
);
// Destructor
virtual ~functionObject();
// Member Functions
//- Called at the start of the time-loop
virtual bool start() = 0;
//- Called at each ++ or += of the time-loop
virtual bool execute() = 0;
//- Called when Time::run() determines that the time-loop exits.
// By default it simply calls execute().
virtual bool end();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,313 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "functionObjectList.H"
#include "Time.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::functionObject*
Foam::functionObjectList::remove(const word& key, label& oldIndex)
{
functionObject* ptr = 0;
// Find index of existing functionObject
HashTable<label>::iterator fnd = indices_.find(key);
if (fnd != indices_.end())
{
oldIndex = fnd();
// retrieve the pointer and remove it from the old list
ptr = this->set(oldIndex, 0).ptr();
indices_.erase(fnd);
}
else
{
oldIndex = -1;
}
return ptr;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjectList::functionObjectList
(
const Time& t,
const bool execution
)
:
PtrList<functionObject>(),
digests_(),
indices_(),
time_(t),
parentDict_(t.controlDict()),
execution_(execution),
updated_(false)
{}
Foam::functionObjectList::functionObjectList
(
const Time& t,
const dictionary& parentDict,
const bool execution
)
:
PtrList<functionObject>(),
digests_(),
indices_(),
time_(t),
parentDict_(parentDict),
execution_(execution),
updated_(false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjectList::~functionObjectList()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjectList::clear()
{
PtrList<functionObject>::clear();
digests_.clear();
indices_.clear();
updated_ = false;
}
void Foam::functionObjectList::on()
{
execution_ = true;
}
void Foam::functionObjectList::off()
{
// for safety, also force a read() when execution is turned back on
updated_ = execution_ = false;
}
bool Foam::functionObjectList::status() const
{
return execution_;
}
bool Foam::functionObjectList::start()
{
return read();
}
bool Foam::functionObjectList::execute()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAllIter
(
PtrList<functionObject>,
static_cast<PtrList<functionObject>&>(*this),
iter
)
{
ok = iter().execute() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::end()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAllIter
(
PtrList<functionObject>,
static_cast<PtrList<functionObject>&>(*this),
iter
)
{
ok = iter().end() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::read()
{
bool ok = true;
updated_ = execution_;
// avoid reading/initializing if execution is off
if (!execution_)
{
return ok;
}
// Update existing and add new functionObjects
const entry* entryPtr = parentDict_.lookupEntryPtr("functions",false,false);
if (entryPtr)
{
PtrList<functionObject> newPtrs;
List<SHA1Digest> newDigs;
HashTable<label> newIndices;
label nFunc = 0;
if (entryPtr->isDict())
{
// a dictionary of functionObjects
const dictionary& functionDicts = entryPtr->dict();
newPtrs.setSize(functionDicts.size());
newDigs.setSize(functionDicts.size());
forAllConstIter(dictionary, functionDicts, iter)
{
// safety:
if (!iter().isDict())
{
continue;
}
const word& key = iter().keyword();
const dictionary& dict = iter().dict();
newDigs[nFunc] = dict.digest();
label oldIndex;
functionObject* objPtr = remove(key, oldIndex);
if (objPtr)
{
// an existing functionObject, and dictionary changed
if (newDigs[nFunc] != digests_[oldIndex])
{
ok = objPtr->read(dict) && ok;
}
}
else
{
// new functionObject
objPtr = functionObject::New(key, time_, dict).ptr();
ok = objPtr->start() && ok;
}
newPtrs.set(nFunc, objPtr);
newIndices.insert(key, nFunc);
nFunc++;
}
}
else
{
// a list of functionObjects
PtrList<entry> functionDicts(entryPtr->stream());
newPtrs.setSize(functionDicts.size());
newDigs.setSize(functionDicts.size());
forAllIter(PtrList<entry>, functionDicts, iter)
{
// safety:
if (!iter().isDict())
{
continue;
}
const word& key = iter().keyword();
const dictionary& dict = iter().dict();
newDigs[nFunc] = dict.digest();
label oldIndex;
functionObject* objPtr = remove(key, oldIndex);
if (objPtr)
{
// an existing functionObject, and dictionary changed
if (newDigs[nFunc] != digests_[oldIndex])
{
ok = objPtr->read(dict) && ok;
}
}
else
{
// new functionObject
objPtr = functionObject::New(key, time_, dict).ptr();
ok = objPtr->start() && ok;
}
newPtrs.set(nFunc, objPtr);
newIndices.insert(key, nFunc);
nFunc++;
}
}
// safety:
newPtrs.setSize(nFunc);
newDigs.setSize(nFunc);
// updating the PtrList of functionObjects also deletes any existing,
// but unused functionObjects
PtrList<functionObject>::transfer(newPtrs);
digests_.transfer(newDigs);
indices_.transfer(newIndices);
}
else
{
PtrList<functionObject>::clear();
digests_.clear();
indices_.clear();
}
return ok;
}
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::functionObjectList
Description
List of function objects with start(), execute() and end() functions
that is called for each object.
See Also
Foam::functionObject and Foam::OutputFilterFunctionObject
SourceFiles
functionObjectList.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjectList_H
#define functionObjectList_H
#include "PtrList.H"
#include "functionObject.H"
#include "SHA1Digest.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class functionObjectList Declaration
\*---------------------------------------------------------------------------*/
class functionObjectList
:
private PtrList<functionObject>
{
// Private data
//- A list of SHA1 digests for the function object dictionaries
List<SHA1Digest> digests_;
//- Quick lookup of the index into functions/digests
HashTable<label> indices_;
const Time& time_;
//- The parent dictionary containing a "functions" entry
// This entry can either be a list or a dictionary of
// functionObject specifications.
const dictionary& parentDict_;
//- Switch for the execution of the functionObjects
bool execution_;
//- Tracks if read() was called while execution is on
bool updated_;
// Private Member Functions
//- Remove and return the function object pointer by name,
// and returns the old index via the parameter.
// Returns a NULL pointer (and index -1) if it didn't exist.
functionObject* remove(const word&, label& oldIndex);
//- Disallow default bitwise copy construct
functionObjectList(const functionObjectList&);
//- Disallow default bitwise assignment
void operator=(const functionObjectList&);
public:
// Constructors
//- Construct from Time and the execution setting
// The functionObject specifications are read from the controlDict
functionObjectList
(
const Time&,
const bool execution=true
);
//- Construct from Time, a dictionary with "functions" entry
// and the execution setting.
// @param[in] parentDict - the parent dictionary containing
// a "functions" entry, which can either be a list or a dictionary
// of functionObject specifications.
functionObjectList
(
const Time&,
const dictionary& parentDict,
const bool execution=true
);
// Destructor
virtual ~functionObjectList();
// Member Functions
//- Return the number of elements in the List.
using PtrList<functionObject>::size;
//- Return true if the List is empty (ie, size() is zero).
using PtrList<functionObject>::empty;
//- Clear the list of function objects
virtual void clear();
//- Switch the function objects on
virtual void on();
//- Switch the function objects off
virtual void off();
//- Return the execution status (on/off) of the function objects
virtual bool status() const;
//- Called at the start of the time-loop
virtual bool start();
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Read and set the function objects if their data have changed
virtual bool read();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,119 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "outputFilterOutputControl.H"
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
template<>
const char* Foam::NamedEnum
<
Foam::outputFilterOutputControl::outputControls,
2
>::names[] =
{
"timeStep",
"outputTime"
};
const Foam::NamedEnum<Foam::outputFilterOutputControl::outputControls, 2>
Foam::outputFilterOutputControl::outputControlNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::outputFilterOutputControl::outputFilterOutputControl
(
const Time& t,
const dictionary& dict
)
:
time_(t),
outputControl_(ocTimeStep),
outputInterval_(0)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::outputFilterOutputControl::~outputFilterOutputControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::outputFilterOutputControl::read(const dictionary& dict)
{
outputControl_ = outputControlNames_.read(dict.lookup("outputControl"));
switch (outputControl_)
{
case ocTimeStep:
{
dict.lookup("outputInterval") >> outputInterval_;
}
default:
{
// do nothing
}
}
}
bool Foam::outputFilterOutputControl::output() const
{
switch (outputControl_)
{
case ocTimeStep:
{
return
(
(outputInterval_ <= 1)
|| !(time_.timeIndex() % outputInterval_)
);
break;
}
case ocOutputTime:
{
return time_.outputTime();
break;
}
default:
{
FatalErrorIn("bool Foam::outputFilterOutputControl::output()")
<< "Unknown output control: "
<< outputControlNames_[outputControl_] << nl
<< abort(FatalError);
}
}
return false;
}
// ************************************************************************* //

View File

@ -0,0 +1,123 @@
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::outputFilterOutputControl
Description
SourceFiles
outputFilterOutputControl.C
\*---------------------------------------------------------------------------*/
#ifndef outputFilterOutputControl_H
#define outputFilterOutputControl_H
#include "dictionary.H"
#include "Time.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class outputFilterOutputControl Declaration
\*---------------------------------------------------------------------------*/
class outputFilterOutputControl
{
public:
enum outputControls
{
ocTimeStep,
ocOutputTime
};
private:
// Private data
//- Time object
const Time& time_;
//- String representation of outputControls enums
static const NamedEnum<outputControls, 2> outputControlNames_;
//- Type of output
outputControls outputControl_;
//- The execution interval (in time steps) when using TIMESTEP mode
// a value <= 1 means execute at every time step
label outputInterval_;
// Private Member Functions
//- Disallow default bitwise copy construct and assignment
outputFilterOutputControl(const outputFilterOutputControl&);
void operator=(const outputFilterOutputControl&);
public:
// Constructors
//- Construct from Time object and dictionary
outputFilterOutputControl(const Time&, const dictionary&);
// Destructor
~outputFilterOutputControl();
// Member Functions
//- Read from dictionary
void read(const dictionary&);
//- Return const access to the Time object
const Time& time() const
{
return time_;
}
//- Flag to indicate whether to output
bool output() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //