Add the OpenFOAM source tree

This commit is contained in:
Henry
2014-12-10 22:40:10 +00:00
parent ee487c860d
commit 446e5777f0
13379 changed files with 3983377 additions and 0 deletions

View File

@ -0,0 +1,392 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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 "functionObjectList.H"
#include "Time.H"
#include "mapPolyMesh.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;
}
Foam::label Foam::functionObjectList::findObjectID(const word& name) const
{
forAll(*this, objectI)
{
if (operator[](objectI).name() == name)
{
return objectI;
}
}
return -1;
}
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(const bool forceWrite)
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).execute(forceWrite) && ok;
}
}
return ok;
}
bool Foam::functionObjectList::end()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).end() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::timeSet()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).timeSet() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::adjustTimeStep()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).adjustTimeStep() && 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;
}
void Foam::functionObjectList::updateMesh(const mapPolyMesh& mpm)
{
if (execution_)
{
forAll(*this, objectI)
{
operator[](objectI).updateMesh(mpm);
}
}
}
void Foam::functionObjectList::movePoints(const polyMesh& mesh)
{
if (execution_)
{
forAll(*this, objectI)
{
operator[](objectI).movePoints(mesh);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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/>.
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 mapPolyMesh;
/*---------------------------------------------------------------------------*\
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;
//- Access to the functionObjects
using PtrList<functionObject>::operator[];
//- Clear the list of function objects
virtual void clear();
//- Find the ID of a given function object by name
virtual label findObjectID(const word& name) const;
//- 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. forceWrite overrides
// the usual outputControl behaviour and forces writing always
// (used in postprocessing mode)
virtual bool execute(const bool forceWrite = false);
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Called when time was set at the end of the Time::operator++
virtual bool timeSet();
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
virtual bool adjustTimeStep();
//- Read and set the function objects if their data have changed
virtual bool read();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh& mpm);
//- Update for changes of mesh
virtual void movePoints(const polyMesh& mesh);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //