Commit 43717bb3 authored by Mark Olesen's avatar Mark Olesen
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents 47493f50 86db6586
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -164,17 +164,22 @@ int main(int argc, char *argv[])
functionObjects::fileFieldSelection fields(mesh);
if (args.found("fields"))
{
fields.insert(args.getList<wordRe>("fields"));
fields.resetFieldFilters
(
HashSet<wordRe>(args.getList<wordRe>("fields"))
);
}
if (args.found("field"))
{
fields.insert(args.opt<wordRe>("field"));
fields.resetFieldFilters(args.opt<wordRe>("field"));
}
// Externally stored dictionary for functionObjectList
// if not constructed from runTime
dictionary functionsDict;
HashSet<wordRe> fieldFilters(fields.filters());
// Construct functionObjectList
autoPtr<functionObjectList> functionsPtr
(
......@@ -183,7 +188,7 @@ int main(int argc, char *argv[])
args,
runTime,
functionsDict,
fields
fieldFilters // include any additional command-line fields
)
);
......@@ -193,8 +198,6 @@ int main(int argc, char *argv[])
Info<< "Time = " << runTime.timeName() << endl;
fields.updateSelection();
if (mesh.readUpdate() != polyMesh::UNCHANGED)
{
// Update functionObjectList if mesh changes
......@@ -205,10 +208,14 @@ int main(int argc, char *argv[])
args,
runTime,
functionsDict,
fields
fieldFilters
);
}
fields.resetFieldFilters(fieldFilters);
fields.updateSelection();
const bool throwingIOErr = FatalIOError.throwExceptions();
try
......@@ -218,7 +225,7 @@ int main(int argc, char *argv[])
args,
runTime,
mesh,
fields.selection(),
fields.selectionNames(),
functionsPtr(),
timei == timeDirs.size()-1
);
......
......@@ -458,6 +458,15 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::functionObjectList::triggerIndex() const
{
label triggeri = labelMin;
stateDict().readIfPresent("triggerIndex", triggeri);
return triggeri;
}
void Foam::functionObjectList::resetState()
{
// Reset (re-read) the state dictionary
......
......@@ -174,6 +174,9 @@ public:
//- Access to the functionObjects
using PtrList<functionObject>::operator[];
//- Return the current trigger index (read from the stateDict)
label triggerIndex() const;
//- Reset/read state dictionary for current time
void resetState();
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -78,6 +78,34 @@ Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
}
bool Foam::functionObjects::stateFunctionObject::setTrigger
(
const label triggeri
)
{
IOdictionary& stateDict = this->stateDict();
label oldTriggeri =
stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
if (triggeri > oldTriggeri)
{
stateDict.set("triggerIndex", triggeri);
return true;
}
return false;
}
Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
{
const IOdictionary& stateDict = this->stateDict();
return stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
}
bool Foam::functionObjects::stateFunctionObject::foundProperty
(
const word& entryName
......@@ -177,8 +205,8 @@ Foam::functionObjects::stateFunctionObject::objectResultEntries() const
}
Foam::List<Foam::word> Foam::functionObjects::stateFunctionObject::
objectResultEntries
Foam::List<Foam::word>
Foam::functionObjects::stateFunctionObject::objectResultEntries
(
const word& objectName
) const
......@@ -210,5 +238,68 @@ objectResultEntries
return entries;
}
void Foam::functionObjects::stateFunctionObject::writeResultEntries
(
Ostream& os
) const
{
writeResultEntries(name(), os);
}
void Foam::functionObjects::stateFunctionObject::writeResultEntries
(
const word& objectName,
Ostream& os
) const
{
const IOdictionary& stateDict = this->stateDict();
if (stateDict.found(resultsName_))
{
const dictionary& resultsDict = stateDict.subDict(resultsName_);
if (resultsDict.found(objectName))
{
const dictionary& objectDict = resultsDict.subDict(objectName);
for (const word& dataFormat : objectDict.sortedToc())
{
os << " Type: " << dataFormat << nl;
const dictionary& resultDict = objectDict.subDict(dataFormat);
for (const word& result : resultDict.sortedToc())
{
os << " " << result << nl;
}
}
}
}
}
void Foam::functionObjects::stateFunctionObject::writeAllResultEntries
(
Ostream& os
) const
{
const IOdictionary& stateDict = this->stateDict();
if (stateDict.found(resultsName_))
{
const dictionary& resultsDict = stateDict.subDict(resultsName_);
const wordList allObjectNames = resultsDict.sortedToc();
for (const word& objectName : allObjectNames)
{
os << "Object: " << objectName << endl;
writeResultEntries(objectName, os);
}
}
}
// ************************************************************************* //
......@@ -125,6 +125,12 @@ public:
//- Return true if the property exists
bool foundProperty(const word& entryName) const;
//- Get the current trigger index
label getTrigger() const;
//- Set the current trigger index
bool setTrigger(const label triggeri);
//- Set dictionary, return true if set
bool getDict
(
......@@ -244,6 +250,15 @@ public:
//- Return result entries for named object
List<word> objectResultEntries(const word& objectName) const;
//- Write the results entries for all objects to stream
void writeResultEntries(Ostream& os) const;
//- Write the results entries for named object to stream
void writeResultEntries(const word& objectName, Ostream& os) const;
//- Write the results entries for all objects to stream
void writeAllResultEntries(Ostream& os) const;
};
......
......@@ -38,6 +38,15 @@ namespace functionObjects
}
}
const Foam::Enum<Foam::functionObjects::timeControl::controlMode>
Foam::functionObjects::timeControl::controlModeNames_
{
{ controlMode::TIME, "time" },
{ controlMode::TRIGGER, "trigger" },
{ controlMode::TIME_OR_TRIGGER, "timeOrTrigger" },
{ controlMode::TIME_AND_TRIGGER, "timeAndTrigger" }
};
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
......@@ -51,6 +60,13 @@ void Foam::functionObjects::timeControl::readControls()
{
timeEnd_ = time_.userTimeToTime(timeEnd_);
}
if (dict_.readIfPresent("triggerStart", triggerStart_))
{
dict_.readIfPresent("triggerEnd", triggerEnd_);
controlMode_ = controlModeNames_.read(dict_.lookup("controlMode"));
}
deltaTCoeff_ = GREAT;
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
{
......@@ -70,9 +86,41 @@ void Foam::functionObjects::timeControl::readControls()
bool Foam::functionObjects::timeControl::active() const
{
return
label triggeri = time_.functionObjects().triggerIndex();
bool inTime =
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
&& time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue());
bool inTrigger = triggeri >= triggerStart_ && triggeri <= triggerEnd_;
switch (controlMode_)
{
case controlMode::TIME:
{
return inTime;
}
case controlMode::TRIGGER:
{
return inTrigger;
}
case controlMode::TIME_OR_TRIGGER:
{
return inTime || inTrigger;
}
case controlMode::TIME_AND_TRIGGER:
{
return inTime && inTrigger;
}
default:
{
FatalErrorInFunction
<< "Unhandled enumeration: " << controlModeNames_[controlMode_]
<< abort(FatalError);
}
}
return false;
}
......@@ -401,8 +449,11 @@ Foam::functionObjects::timeControl::timeControl
functionObject(name),
time_(t),
dict_(dict),
controlMode_(controlMode::TIME),
timeStart_(-VGREAT),
timeEnd_(VGREAT),
triggerStart_(labelMax),
triggerEnd_(labelMax),
nStepsToStartTimeChange_(labelMax),
executeControl_(t, dict, "execute"),
writeControl_(t, dict, "write"),
......@@ -426,6 +477,8 @@ bool Foam::functionObjects::timeControl::entriesPresent(const dictionary& dict)
|| Foam::timeControl::entriesPresent(dict, "execute")
|| dict.found("timeStart")
|| dict.found("timeEnd")
|| dict.found("triggerStart")
|| dict.found("triggerEnd")
)
{
return true;
......@@ -681,7 +734,7 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
// Set time, deltaT adjustments for writeInterval purposes
// are already taken care. Hence disable auto-update
const_cast<Time&>( time_).setDeltaT(newDeltaT, false);
const_cast<Time&>(time_).setDeltaT(newDeltaT, false);
if (seriesDTCoeff_ < 1.0)
{
......@@ -746,12 +799,7 @@ bool Foam::functionObjects::timeControl::read(const dictionary& dict)
bool Foam::functionObjects::timeControl::filesModified() const
{
bool mod = false;
if (active())
{
mod = foPtr_->filesModified();
}
return mod;
return active() ? foPtr_->filesModified() : false;
}
......
......@@ -75,6 +75,25 @@ class timeControl
:
public functionObject
{
public:
// Public enumerations
//- Control mode
enum class controlMode
{
TIME,
TRIGGER,
TIME_OR_TRIGGER,
TIME_AND_TRIGGER
};
static const Enum<controlMode> controlModeNames_;
private:
// Private data
//- Reference to the time database
......@@ -86,12 +105,21 @@ class timeControl
// Optional user inputs
//- Control mode (combination of time/trigger behaviour)
controlMode controlMode_;
//- Activation time - defaults to -VGREAT
scalar timeStart_;
//- De-activation time - defaults to VGREAT
scalar timeEnd_;
//- Activation trigger index - defaults to labelMin
label triggerStart_;
//- De-activation trigger index - defaults to labelMax
label triggerEnd_;
//- Max time step change
scalar deltaTCoeff_;
......
......@@ -97,10 +97,10 @@ $(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C
functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C
functionObjects/volRegion/volRegion.C
functionObjects/fieldSelection/fieldSelection.C
functionObjects/fieldSelection/fileFieldSelection.C
functionObjects/fieldSelection/volFieldSelection.C
functionObjects/fieldSelection/solverFieldSelection.C
functionObjects/fieldSelections/fieldSelection/fieldSelection.C
functionObjects/fieldSelections/fileFieldSelection/fileFieldSelection.C
functionObjects/fieldSelections/volFieldSelection/volFieldSelection.C
functionObjects/fieldSelections/solverFieldSelection/solverFieldSelection.C
fvPatchFields = fields/fvPatchFields
$(fvPatchFields)/fvPatchField/fvPatchFields.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 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::functionObjects::fieldInfo
Description
Helper class to store a wordRe and label used by
Foam::functionObjects::fieldSelection
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldInfo_H
#define functionObjects_fieldInfo_H
#include "wordRe.H"
#include "label.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldInfo Declaration
\*---------------------------------------------------------------------------*/
class fieldInfo;
Istream& operator>>(Istream&, fieldInfo&);
Ostream& operator<<(Ostream&, const fieldInfo&);
class fieldInfo
{
// Pivate data
//- Pattern for the field name
wordRe name_;
//- Field component
label component_;
//- Found
mutable Switch found_;
public:
// Constructors
//- Null constructor
fieldInfo()
:
name_(word::null),
component_(-1),
found_(false)
{}
//- Construct from components
fieldInfo(const wordRe& name, const label component = -1)
:
name_(name),
component_(component),
found_(false)
{}
//- Construct from stream
fieldInfo(Istream& is)
:
name_(is),
component_(readLabel(is)),
found_(false)
{}
//- Destructor
~fieldInfo() = default;
// Member Functions
const wordRe& name() const
{
return name_;
}
label component() const
{
return component_;
}
Switch& found() const
{
return found_;
}
friend bool operator==(const fieldInfo& a, const fieldInfo& b)
{
return
a.name_ == b.name_
&& a.component_ == b.component_
&& a.found_ == b.found_;
}
friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
{
return !(a == b);
}
// IOstream Operators
friend Istream& operator>>(Istream& is, fieldInfo& fi)
{
is >> fi.name_ >> fi.component_ >> fi.found_;
return is;
}
friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
{
os << fi.name_ << ' ' << fi.component_ << ' ' << fi.found_;
return os;
}
};
</