mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add Function1 wrapping for functionObject trigger
Returns a 0/1 value corresponding to function object trigger levels.
Usage:
\verbatim
<entryName> functionObjectTrigger;
<entryName>Coeffs
{
triggers (1 3 5);
defaultValue false; // Default when no triggers activated
}
\endverbatim
ENH: add reset() method for Constant Function1
ENH: allow forced change of trigger index
- the triggers are normally increase only,
but can now override this optionally
This commit is contained in:
@ -509,7 +509,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
|
||||
|
||||
Foam::label Foam::functionObjectList::triggerIndex() const
|
||||
{
|
||||
return propsDict().getOrDefault<label>("triggerIndex", labelMin);
|
||||
return propsDict().getTrigger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -79,26 +79,38 @@ Foam::dictionary& Foam::functionObjects::properties::getObjectDict
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::properties::setTrigger
|
||||
(
|
||||
const label triggeri
|
||||
)
|
||||
void Foam::functionObjects::properties::clearTrigger()
|
||||
{
|
||||
label oldTriggeri = getOrDefault<label>("triggerIndex", labelMin);
|
||||
|
||||
if (triggeri > oldTriggeri)
|
||||
{
|
||||
set("triggerIndex", triggeri);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
remove("triggerIndex");
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::properties::getTrigger() const
|
||||
{
|
||||
return getOrDefault<label>("triggerIndex", labelMin);
|
||||
// Like getOrDefault, but without reporting missing entry (noisy)
|
||||
label idx = labelMin;
|
||||
readIfPresent("triggerIndex", idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::properties::setTrigger
|
||||
(
|
||||
const label triggeri,
|
||||
bool increaseOnly
|
||||
)
|
||||
{
|
||||
const label currTriggeri = getTrigger();
|
||||
|
||||
if (increaseOnly ? (triggeri > currTriggeri) : (triggeri != currTriggeri))
|
||||
{
|
||||
set("triggerIndex", triggeri);
|
||||
return true;
|
||||
}
|
||||
|
||||
// TBD: any special handling for triggeri == labelMin - eg, clearTrigger()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -117,11 +117,20 @@ public:
|
||||
const word& entryName
|
||||
) const;
|
||||
|
||||
//- Remove the trigger index from the properties
|
||||
void clearTrigger();
|
||||
|
||||
//- Get the current trigger index
|
||||
label getTrigger() const;
|
||||
|
||||
//- Set the current trigger index
|
||||
bool setTrigger(const label triggeri);
|
||||
//- Set the trigger index. Normally only if greater than current
|
||||
//
|
||||
// \param triggeri the new trigger index
|
||||
// \param increaseOnly (default) only change if new index
|
||||
// is greater than the current index.
|
||||
//
|
||||
// \return True if the index changed
|
||||
bool setTrigger(const label triggeri, bool increaseOnly = true);
|
||||
|
||||
//- Set dictionary from named object, return true if set
|
||||
bool getObjectDict
|
||||
|
||||
@ -74,12 +74,9 @@ Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::stateFunctionObject::setTrigger
|
||||
(
|
||||
const label triggeri
|
||||
)
|
||||
void Foam::functionObjects::stateFunctionObject::clearTrigger()
|
||||
{
|
||||
return stateDict().setTrigger(triggeri);
|
||||
return stateDict().clearTrigger();
|
||||
}
|
||||
|
||||
|
||||
@ -89,6 +86,16 @@ Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::stateFunctionObject::setTrigger
|
||||
(
|
||||
const label triggeri,
|
||||
bool increaseOnly
|
||||
)
|
||||
{
|
||||
return stateDict().setTrigger(triggeri, increaseOnly);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::stateFunctionObject::foundProperty
|
||||
(
|
||||
const word& entryName
|
||||
|
||||
@ -118,11 +118,20 @@ public:
|
||||
//- Return true if the property exists
|
||||
bool foundProperty(const word& entryName) const;
|
||||
|
||||
//- Remove the trigger index from the properties
|
||||
void clearTrigger();
|
||||
|
||||
//- Get the current trigger index
|
||||
label getTrigger() const;
|
||||
|
||||
//- Set the current trigger index
|
||||
bool setTrigger(const label triggeri);
|
||||
//- Set the trigger index. Normally only if greater than current
|
||||
//
|
||||
// \param triggeri the new trigger index
|
||||
// \param increaseOnly (default) only change if new index
|
||||
// is greater than the current index.
|
||||
//
|
||||
// \return True if the index changed
|
||||
bool setTrigger(const label triggeri, bool increaseOnly = true);
|
||||
|
||||
//- Set dictionary, return true if set
|
||||
bool getDict
|
||||
|
||||
@ -80,8 +80,7 @@ class timeControl
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// Public enumerations
|
||||
// Public Enumerations
|
||||
|
||||
//- Control mode
|
||||
enum class controlMode
|
||||
@ -97,7 +96,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Input dictionary
|
||||
dictionary dict_;
|
||||
@ -108,13 +107,13 @@ private:
|
||||
//- Control mode (combination of time/trigger behaviour)
|
||||
controlMode controlMode_;
|
||||
|
||||
//- Activation time - defaults to -VGREAT
|
||||
//- Activation time - defaults to -VGREAT (ie, active)
|
||||
scalar timeStart_;
|
||||
|
||||
//- De-activation time - defaults to VGREAT
|
||||
scalar timeEnd_;
|
||||
|
||||
//- Activation trigger index - defaults to labelMin
|
||||
//- Activation trigger index - defaults to labelMax (ie, inactive)
|
||||
label triggerStart_;
|
||||
|
||||
//- De-activation trigger index - defaults to labelMax
|
||||
|
||||
@ -131,6 +131,9 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Change the constant value
|
||||
inline void reset(const Type& val);
|
||||
|
||||
//- Return constant value
|
||||
virtual inline Type value(const scalar) const;
|
||||
|
||||
|
||||
@ -31,7 +31,14 @@ License
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
inline Type Foam::Function1Types::Constant<Type>::value(const scalar x) const
|
||||
inline void Foam::Function1Types::Constant<Type>::reset(const Type& val)
|
||||
{
|
||||
value_ = val;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
inline Type Foam::Function1Types::Constant<Type>::value(const scalar) const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
@ -0,0 +1,106 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "FunctionObjectTrigger.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::FunctionObjectTrigger<Type>::read
|
||||
(
|
||||
const dictionary& coeffs
|
||||
)
|
||||
{
|
||||
triggers_ = coeffs.get<labelList>("triggers", keyType::LITERAL);
|
||||
defaultValue_ =
|
||||
coeffs.getOrDefault("defaultValue", false, keyType::LITERAL);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::FunctionObjectTrigger<Type>::FunctionObjectTrigger
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const objectRegistry* obrPtr
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName, dict, obrPtr),
|
||||
triggers_(),
|
||||
defaultValue_(false)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::FunctionObjectTrigger<Type>::FunctionObjectTrigger
|
||||
(
|
||||
const FunctionObjectTrigger<Type>& rhs
|
||||
)
|
||||
:
|
||||
Function1<Type>(rhs),
|
||||
triggers_(rhs.triggers_),
|
||||
defaultValue_(rhs.defaultValue_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::FunctionObjectTrigger<Type>::writeEntries
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
os.writeKeyword("triggers");
|
||||
flatOutput(triggers_);
|
||||
os.endEntry();
|
||||
|
||||
if (defaultValue_)
|
||||
{
|
||||
os.writeEntry("default", "true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::FunctionObjectTrigger<Type>::writeData
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,178 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::Function1Types::FunctionObjectTrigger
|
||||
|
||||
Description
|
||||
Returns a 0/1 value corresponding to function object trigger levels.
|
||||
|
||||
Usage:
|
||||
\verbatim
|
||||
<entryName> functionObjectTrigger;
|
||||
<entryName>Coeffs
|
||||
{
|
||||
triggers (1 3 5);
|
||||
defaultValue false; // Optional
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where:
|
||||
\table
|
||||
Property | Description | Required
|
||||
triggers | List of active trigger states to check for | yes |
|
||||
defaultValue | Treatment for unactivated trigger state | no | false
|
||||
\endtable
|
||||
|
||||
In some circumstances, it can be useful to treat an unactivated trigger
|
||||
as being true. This is the role of the "defaultValue" keyword.
|
||||
|
||||
Note
|
||||
- does not implement integrate()
|
||||
|
||||
SourceFiles
|
||||
FunctionObjectTrigger.C
|
||||
FunctionObjectTriggerI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Function1Types_FunctionObjectTrigger_H
|
||||
#define Function1Types_FunctionObjectTrigger_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "labelList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace Function1Types
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class FunctionObjectTrigger Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class FunctionObjectTrigger
|
||||
:
|
||||
public Function1<Type>
|
||||
{
|
||||
|
||||
// Private Data
|
||||
|
||||
//- Trigger indices when it is considered active
|
||||
labelList triggers_;
|
||||
|
||||
//- Treatment for unactivated trigger state (true/false)
|
||||
bool defaultValue_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Is the trigger considered active?
|
||||
inline bool active() const;
|
||||
|
||||
//- Read the coefficients from the given dictionary
|
||||
void read(const dictionary& coeffs);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("functionObjectTrigger");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const FunctionObjectTrigger<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name, dictionary and optional registry
|
||||
FunctionObjectTrigger
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const objectRegistry* obrPtr = nullptr
|
||||
);
|
||||
|
||||
//- Copy construct
|
||||
explicit FunctionObjectTrigger(const FunctionObjectTrigger<Type>& rhs);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<Function1<Type>> clone() const
|
||||
{
|
||||
return tmp<Function1<Type>>(new FunctionObjectTrigger<Type>(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~FunctionObjectTrigger() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the trigger indices
|
||||
inline const labelList& triggers() const noexcept;
|
||||
|
||||
//- Change the trigger indices
|
||||
inline void resetTriggers(const labelUList& indices);
|
||||
|
||||
|
||||
//- Return 0/1 value at current time
|
||||
virtual inline Type value(const scalar /*unused*/) const;
|
||||
|
||||
//- Integrate between two (scalar) values. Not implemented!
|
||||
virtual inline Type integrate(const scalar, const scalar) const;
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Function1Types
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "FunctionObjectTriggerI.H"
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "FunctionObjectTrigger.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,89 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "FunctionObjectTrigger.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
inline bool Foam::Function1Types::FunctionObjectTrigger<Type>::active() const
|
||||
{
|
||||
if (triggers_.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const label idx = this->time().functionObjects().triggerIndex();
|
||||
|
||||
return
|
||||
(
|
||||
idx == labelMin ? defaultValue_ : triggers_.found(idx)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
inline const Foam::labelList&
|
||||
Foam::Function1Types::FunctionObjectTrigger<Type>::triggers() const noexcept
|
||||
{
|
||||
return triggers_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
inline void Foam::Function1Types::FunctionObjectTrigger<Type>::resetTriggers
|
||||
(
|
||||
const labelUList& indices
|
||||
)
|
||||
{
|
||||
triggers_ = indices;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
inline Type Foam::Function1Types::FunctionObjectTrigger<Type>::value
|
||||
(
|
||||
const scalar /*unused*/
|
||||
) const
|
||||
{
|
||||
return this->active() ? pTraits<Type>::one : pTraits<Type>::zero;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
inline Type Foam::Function1Types::FunctionObjectTrigger<Type>::integrate
|
||||
(
|
||||
const scalar x1,
|
||||
const scalar x2
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return pTraits<Type>::zero;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -40,12 +40,12 @@ Description
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
|
||||
Note
|
||||
- does not implement integrate()
|
||||
|
||||
SourceFiles
|
||||
FunctionObjectValue.C
|
||||
FunctionObjectValueI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -129,10 +129,10 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return value for time t
|
||||
virtual inline Type value(const scalar t) const;
|
||||
//- Return value at current time
|
||||
virtual inline Type value(const scalar /*unused*/) const;
|
||||
|
||||
//- Integrate between two (scalar) values
|
||||
//- Integrate between two (scalar) values. Not implemented!
|
||||
virtual Type integrate(const scalar x1, const scalar x2) const;
|
||||
|
||||
//- Write in dictionary format
|
||||
|
||||
@ -39,6 +39,7 @@ License
|
||||
#include "TableFile.H"
|
||||
#include "Scale.H"
|
||||
#include "InputValueMapper.H"
|
||||
#include "FunctionObjectTrigger.H"
|
||||
#include "FunctionObjectValue.H"
|
||||
#include "fieldTypes.H"
|
||||
|
||||
@ -73,6 +74,10 @@ namespace Foam
|
||||
makeFunction1(label);
|
||||
makeFunction1Type(Constant, label);
|
||||
|
||||
makeFunction1Type(FunctionObjectTrigger, label);
|
||||
makeFunction1Type(FunctionObjectTrigger, scalar);
|
||||
// Only (label/scalar) makes sense for triggers
|
||||
|
||||
makeFunction1s(scalar);
|
||||
makeFunction1s(vector);
|
||||
makeFunction1s(sphericalTensor);
|
||||
|
||||
Reference in New Issue
Block a user