Files
OpenFOAM-12/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
Henry Weller 3a269eb3d7 #includeModel, #includeConstraint: New dictionary directives
#includeModel includes an fvModel configuration file into the fvModels file
 #includeConstraint includes an fvModel configuration file into the fvConstraints file

These operate in the same manner as #includeFunc does for functionObjects and
search the etc/caseDicts/fvModels and etc/caseDicts/fvConstraints directories
for configuration files and apply optional argument substitution.

Class
    Foam::functionEntries::includeFvModelEntry

Description
    Specify a fvModel dictionary file to include, expects the
    fvModel name to follow with option arguments (without quotes).

    Searches for fvModel dictionary file in user/group/shipped
    directories allowing for version-specific and version-independent files
    using the following hierarchy:
    - \b user settings:
      - ~/.OpenFOAM/\<VERSION\>/caseDicts/fvModels
      - ~/.OpenFOAM/caseDicts/fvModels
    - \b group (site) settings (when $WM_PROJECT_SITE is set):
      - $WM_PROJECT_SITE/\<VERSION\>/etc/caseDicts/fvModels
      - $WM_PROJECT_SITE/etc/caseDicts/fvModels
    - \b group (site) settings (when $WM_PROJECT_SITE is not set):
      - $WM_PROJECT_INST_DIR/site/\<VERSION\>/etc/caseDicts/fvModels
      - $WM_PROJECT_INST_DIR/site/etc/caseDicts/fvModels
    - \b other (shipped) settings:
      - $WM_PROJECT_DIR/etc/caseDicts/fvModels

    The optional field arguments included in the name are inserted in 'field' or
    'fields' entries in the fvModel dictionary and included in the name
    of the fvModel entry to avoid conflict.

    Examples:
    \verbatim
        #includeModel clouds
        #includeModel surfaceFilms
    \endverbatim

    Other dictionary entries may also be specified using named arguments.

See also
    Foam::includeFvConstraintEntry
    Foam::includeFuncEntry

Class
    Foam::functionEntries::includeFvConstraintEntry

Description
    Specify a fvConstraint dictionary file to include, expects the
    fvConstraint name to follow with option arguments (without quotes).

    Searches for fvConstraint dictionary file in user/group/shipped
    directories allowing for version-specific and version-independent files
    using the following hierarchy:
    - \b user settings:
      - ~/.OpenFOAM/\<VERSION\>/caseDicts/fvConstraints
      - ~/.OpenFOAM/caseDicts/fvConstraints
    - \b group (site) settings (when $WM_PROJECT_SITE is set):
      - $WM_PROJECT_SITE/\<VERSION\>/etc/caseDicts/fvConstraints
      - $WM_PROJECT_SITE/etc/caseDicts/fvConstraints
    - \b group (site) settings (when $WM_PROJECT_SITE is not set):
      - $WM_PROJECT_INST_DIR/site/\<VERSION\>/etc/caseDicts/fvConstraints
      - $WM_PROJECT_INST_DIR/site/etc/caseDicts/fvConstraints
    - \b other (shipped) settings:
      - $WM_PROJECT_DIR/etc/caseDicts/fvConstraints

    The optional field arguments included in the name are inserted in 'field' or
    'fields' entries in the fvConstraint dictionary and included in the name
    of the fvConstraint entry to avoid conflict.

    Examples:
    \verbatim
        #includeConstraint limitPressure(minFactor=0.1, maxFactor=2)
        #includeConstraint limitTemperature(min=101, max=1000)
    \endverbatim
    or for a multiphase case:
    \verbatim
        #includeConstraint limitLowPressure(min=1e4)
        #includeConstraint limitTemperature(phase=steam, min=270, max=2000)
        #includeConstraint limitTemperature(phase=water, min=270, max=2000)
    \endverbatim

    Other dictionary entries may also be specified using named arguments.

See also
    Foam::includeFvModelEntry
    Foam::includeFuncEntry
2023-01-30 18:59:07 +00:00

515 lines
11 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 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 "argList.H"
#include "timeControlFunctionObject.H"
#include "dictionaryEntry.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)
{}
Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
(
const argList& args,
const Time& runTime,
dictionary& controlDict
)
{
autoPtr<functionObjectList> functionsPtr;
controlDict.add
(
dictionaryEntry("functions", controlDict, dictionary::null)
);
dictionary& functionsDict = controlDict.subDict("functions");
word region = word::null;
// Set the region name if specified
if (args.optionFound("region"))
{
region = args["region"];
}
if
(
args.optionFound("dict")
|| args.optionFound("func")
|| args.optionFound("funcs")
)
{
if (args.optionFound("dict"))
{
controlDict.merge
(
IOdictionary
(
IOobject
(
args["dict"],
runTime,
IOobject::MUST_READ_IF_MODIFIED
)
)
);
}
if (args.optionFound("func"))
{
readConfigFile
(
args["func"],
functionsDict,
functionEntries::includeFuncEntry::functionObjectDictPath,
{"command", args.commandLine()},
region
);
}
if (args.optionFound("funcs"))
{
wordList funcs(args.optionLookup("funcs")());
forAll(funcs, i)
{
readConfigFile
(
funcs[i],
functionsDict,
functionEntries::includeFuncEntry::functionObjectDictPath,
{"command", args.commandLine()},
region
);
}
}
functionsPtr.reset(new functionObjectList(runTime, controlDict));
}
else
{
functionsPtr.reset(new functionObjectList(runTime));
}
functionsPtr->read();
return functionsPtr;
}
// * * * * * * * * * * * * * * * * 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, oi)
{
if (operator[](oi).name() == name)
{
return oi;
}
}
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()
{
bool ok = read();
if (execution_)
{
forAll(*this, oi)
{
if (operator[](oi).executeAtStart())
{
ok = operator[](oi).execute() && ok;
ok = operator[](oi).write() && ok;
}
}
}
return ok;
}
bool Foam::functionObjectList::execute()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, oi)
{
ok = operator[](oi).execute() && ok;
ok = operator[](oi).write() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::end()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, oi)
{
ok = operator[](oi).end() && ok;
}
}
return ok;
}
Foam::scalar Foam::functionObjectList::timeToNextWrite()
{
scalar result = vGreat;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, oi)
{
result = min(result, operator[](oi).timeToNextWrite());
}
}
return result;
}
bool Foam::functionObjectList::read()
{
bool ok = true;
updated_ = execution_;
// Avoid reading/initialising if execution is off
if (!execution_)
{
return true;
}
// 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())
{
FatalIOErrorInFunction(parentDict_)
<< "'functions' entry is not a dictionary"
<< exit(FatalIOError);
}
const dictionary& functionsDict = entryPtr->dict();
libs.open
(
functionsDict,
"libs",
functionObject::dictionaryConstructorTablePtr_
);
newPtrs.setSize(functionsDict.size());
newDigs.setSize(functionsDict.size());
forAllConstIter(dictionary, functionsDict, iter)
{
const word& key = iter().keyword();
if (!iter().isDict())
{
if (key != "libs")
{
IOWarningInFunction(parentDict_)
<< "Entry " << key << " is not a dictionary" << endl;
}
continue;
}
const dictionary& dict = iter().dict();
const bool enabled = dict.lookupOrDefault("enabled", true);
newDigs[nFunc] = dict.digest();
label oldIndex;
functionObject* objPtr = remove(key, oldIndex);
if (objPtr)
{
if (enabled)
{
// Dictionary changed for an existing functionObject
if (newDigs[nFunc] != digests_[oldIndex])
{
ok = objPtr->read(dict) && ok;
}
}
else
{
// Delete the disabled functionObject
delete objPtr;
objPtr = nullptr;
continue;
}
}
else if (enabled)
{
autoPtr<functionObject> foPtr;
if
(
dict.found("executeControl")
|| dict.found("writeControl")
|| dict.found("outputControl")
)
{
foPtr.set
(
new functionObjects::timeControl(key, time_, dict)
);
}
else
{
foPtr = functionObject::New(key, time_, dict);
}
if (foPtr.valid())
{
objPtr = foPtr.ptr();
}
else
{
ok = false;
}
}
// Insert active functionObjects into the list
if (objPtr)
{
newPtrs.set(nFunc, objPtr);
newIndices.insert(key, nFunc);
nFunc++;
}
}
newPtrs.setSize(nFunc);
newDigs.setSize(nFunc);
// Updating the PtrList of functionObjects deletes any
// existing 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::movePoints(const polyMesh& mesh)
{
if (execution_)
{
forAll(*this, oi)
{
operator[](oi).movePoints(mesh);
}
}
}
void Foam::functionObjectList::topoChange(const polyTopoChangeMap& map)
{
if (execution_)
{
forAll(*this, oi)
{
operator[](oi).topoChange(map);
}
}
}
void Foam::functionObjectList::mapMesh(const polyMeshMap& map)
{
if (execution_)
{
forAll(*this, oi)
{
operator[](oi).mapMesh(map);
}
}
}
void Foam::functionObjectList::distribute(const polyDistributionMap& map)
{
if (execution_)
{
forAll(*this, oi)
{
operator[](oi).distribute(map);
}
}
}
// ************************************************************************* //