ENH: LimitRange Function1 - extended and renamed
Description Function1 wrapper that maps the input value prior to it being used by another Function1. Example usage for limiting a polynomial: \verbatim <entryName> { type inputValueMapper; mode minMax; min 0.4; max 1.4; value polynomial ( (5 1) (-2 2) (-2 3) (1 4) ); } \endverbatim Here the return value will be: - poly(0.4) for x <= 0.4; - poly(1.4) for x >= 1.4; and - poly(x) for 0.4 < x < 1.4. Example usage for supplying a patch mass flux for a table lookup: \verbatim <entryName> { type inputValueMapper; mode function; function { type functionObjectValue; functionObject surfaceFieldValue1; functionObjectResult sum(outlet,phi); } value { type table; file "<system>/fanCurve.txt"; } } \endverbatim Where: \table Property | Description | Required mode | Mapping mode (see below) | yes function | Mapping Function1 | no* min | Minimum input value | no* max | Maximum input value | no* value | Function of type Function1<Type> | yes \endtable Mapping modes include - none : the input value is simply passed to the 'value' Function1 - function : the input value is passed through the 'function' Function1 before being passed to the 'value' Function1 - minMax : limits the input value to 'min' and 'max' values before being passed to the 'value' Function1 Note Replaces the LimitRange Function1 (v2106 and earlier)
This commit is contained in:
parent
ba45fb2cba
commit
89ddc271c7
@ -41,7 +41,8 @@ inline Type Foam::Function1Types::FunctionObjectValue<Type>::value
|
|||||||
{
|
{
|
||||||
if (haveDefaultValue_)
|
if (haveDefaultValue_)
|
||||||
{
|
{
|
||||||
Info<< " Function object " << foName_
|
DebugInfo
|
||||||
|
<< " Function object " << foName_
|
||||||
<< " not found; using default value " << defaultValue_
|
<< " not found; using default value " << defaultValue_
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
@ -59,7 +60,8 @@ inline Type Foam::Function1Types::FunctionObjectValue<Type>::value
|
|||||||
{
|
{
|
||||||
if (haveDefaultValue_)
|
if (haveDefaultValue_)
|
||||||
{
|
{
|
||||||
Info<< " Function object " << foName_
|
DebugInfo
|
||||||
|
<< " Function object " << foName_
|
||||||
<< " result " << foResultName_
|
<< " result " << foResultName_
|
||||||
<< " not found; using default value " << defaultValue_
|
<< " not found; using default value " << defaultValue_
|
||||||
<< endl;
|
<< endl;
|
||||||
@ -75,9 +77,13 @@ inline Type Foam::Function1Types::FunctionObjectValue<Type>::value
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< " Using " << foName_ << " function object value" << endl;
|
Type value = props.template getObjectResult<Type>(foName_, foResultName_);
|
||||||
|
|
||||||
return props.template getObjectResult<Type>(foName_, foResultName_);
|
DebugInfo
|
||||||
|
<< " Using " << foName_ << " function object value: " << value
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,178 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2020-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 "InputValueMapper.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::Enum
|
||||||
|
<
|
||||||
|
typename Foam::Function1Types::InputValueMapper<Type>::mappingMode
|
||||||
|
>
|
||||||
|
Foam::Function1Types::InputValueMapper<Type>::mappingModeNames_
|
||||||
|
({
|
||||||
|
{ mappingMode::NONE, "none" },
|
||||||
|
{ mappingMode::FUNCTION1, "function" },
|
||||||
|
{ mappingMode::MINMAX, "minMax" },
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::Function1Types::InputValueMapper<Type>::read
|
||||||
|
(
|
||||||
|
const dictionary& coeffs
|
||||||
|
)
|
||||||
|
{
|
||||||
|
mappingMode_ = mappingModeNames_.get("mode", coeffs);
|
||||||
|
|
||||||
|
switch (mappingMode_)
|
||||||
|
{
|
||||||
|
case mappingMode::NONE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mappingMode::FUNCTION1:
|
||||||
|
{
|
||||||
|
mappingValuePtr_.reset
|
||||||
|
(
|
||||||
|
Function1<scalar>::New("function", coeffs, this->obrPtr_)
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mappingMode::MINMAX:
|
||||||
|
{
|
||||||
|
min_ = coeffs.get<scalar>("min");
|
||||||
|
max_ = coeffs.get<scalar>("max");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unhandled enumeration " << mappingModeNames_[mappingMode_]
|
||||||
|
<< ". Available options are: " << mappingModeNames_.sortedToc()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
value_ = Function1<Type>::New("value", coeffs, this->obrPtr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::InputValueMapper<Type>::InputValueMapper
|
||||||
|
(
|
||||||
|
const word& entryName,
|
||||||
|
const dictionary& dict,
|
||||||
|
const objectRegistry* obrPtr
|
||||||
|
)
|
||||||
|
:
|
||||||
|
Function1<Type>(entryName, obrPtr),
|
||||||
|
mappingMode_(mappingMode::NONE),
|
||||||
|
mappingValuePtr_(nullptr),
|
||||||
|
min_(0),
|
||||||
|
max_(0),
|
||||||
|
value_(nullptr)
|
||||||
|
{
|
||||||
|
read(dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::InputValueMapper<Type>::InputValueMapper
|
||||||
|
(
|
||||||
|
const InputValueMapper<Type>& rhs
|
||||||
|
)
|
||||||
|
:
|
||||||
|
Function1<Type>(rhs),
|
||||||
|
mappingMode_(rhs.mappingMode_),
|
||||||
|
mappingValuePtr_(rhs.mappingValuePtr_.clone()),
|
||||||
|
min_(rhs.min_),
|
||||||
|
max_(rhs.max_),
|
||||||
|
value_(rhs.value_.clone())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::Function1Types::InputValueMapper<Type>::writeEntries
|
||||||
|
(
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
os.writeEntry("mode", mappingModeNames_[mappingMode_]);
|
||||||
|
|
||||||
|
switch (mappingMode_)
|
||||||
|
{
|
||||||
|
case mappingMode::NONE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mappingMode::FUNCTION1:
|
||||||
|
{
|
||||||
|
mappingValuePtr_->writeData(os);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mappingMode::MINMAX:
|
||||||
|
{
|
||||||
|
os.writeEntry("min", min_);
|
||||||
|
os.writeEntry("max", max_);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unhandled enumeration " << mappingModeNames_[mappingMode_]
|
||||||
|
<< ". Available options are: " << mappingModeNames_.sortedToc()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
value_->writeData(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::Function1Types::InputValueMapper<Type>::writeData(Ostream& os) const
|
||||||
|
{
|
||||||
|
Function1<Type>::writeData(os);
|
||||||
|
os.endEntry();
|
||||||
|
|
||||||
|
os.beginBlock(word(this->name() + "Coeffs"));
|
||||||
|
writeEntries(os);
|
||||||
|
os.endBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
@ -24,18 +24,21 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Class
|
Class
|
||||||
Foam::Function1Types::LimitRange
|
Foam::Function1Types::InputValueMapper
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Function1 wrapper that limits the input range of another Function1
|
Function1 wrapper that maps the input value prior to it being used by
|
||||||
|
another Function1.
|
||||||
|
|
||||||
Example usage for limiting a polynomial:
|
Example usage for limiting a polynomial:
|
||||||
\verbatim
|
\verbatim
|
||||||
<entryName>
|
<entryName>
|
||||||
{
|
{
|
||||||
type limitRange;
|
type inputValueMapper;
|
||||||
min 0.4;
|
mode minMax;
|
||||||
max 1.4;
|
|
||||||
|
min 0.4;
|
||||||
|
max 1.4;
|
||||||
|
|
||||||
value polynomial
|
value polynomial
|
||||||
(
|
(
|
||||||
@ -53,18 +56,24 @@ Description
|
|||||||
- poly(x) for 0.4 < x < 1.4.
|
- poly(x) for 0.4 < x < 1.4.
|
||||||
|
|
||||||
|
|
||||||
Example usage for limiting a file-based table:
|
Example usage for supplying a patch mass flux for a table lookup:
|
||||||
\verbatim
|
\verbatim
|
||||||
<entryName>
|
<entryName>
|
||||||
{
|
{
|
||||||
type limitRange;
|
type inputValueMapper;
|
||||||
min 0.4;
|
mode function;
|
||||||
max 1.4;
|
|
||||||
|
function
|
||||||
|
{
|
||||||
|
type functionObjectValue;
|
||||||
|
functionObject surfaceFieldValue1;
|
||||||
|
functionObjectResult sum(outlet,phi);
|
||||||
|
}
|
||||||
|
|
||||||
value
|
value
|
||||||
{
|
{
|
||||||
type table;
|
type table;
|
||||||
file "<system>/fanCurve.txt";
|
file "<system>/fanCurve.txt";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\endverbatim
|
\endverbatim
|
||||||
@ -72,20 +81,34 @@ Description
|
|||||||
Where:
|
Where:
|
||||||
\table
|
\table
|
||||||
Property | Description | Required
|
Property | Description | Required
|
||||||
min | Minimum input value | yes
|
mode | Mapping mode (see below) | yes
|
||||||
max | Maximum input value | yes
|
function | Mapping Function1 | no*
|
||||||
|
min | Minimum input value | no*
|
||||||
|
max | Maximum input value | no*
|
||||||
value | Function of type Function1<Type> | yes
|
value | Function of type Function1<Type> | yes
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
|
Mapping modes include
|
||||||
|
- none : the input value is simply passed to the 'value' Function1
|
||||||
|
- function : the input value is passed through the 'function' Function1
|
||||||
|
before being passed to the 'value' Function1
|
||||||
|
- minMax : limits the input value to 'min' and 'max' values before being
|
||||||
|
passed to the 'value' Function1
|
||||||
|
|
||||||
|
Note
|
||||||
|
Replaces the LimitRange Function1 (v2106 and earlier)
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
LimitRange.C
|
InputValueMapper.C
|
||||||
|
InputValueMapperI.H
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Function1Types_LimitRange_H
|
#ifndef Function1Types_InputValueMapper_H
|
||||||
#define Function1Types_LimitRange_H
|
#define Function1Types_InputValueMapper_H
|
||||||
|
|
||||||
#include "Function1.H"
|
#include "Function1.H"
|
||||||
|
#include "Enum.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -95,24 +118,56 @@ namespace Function1Types
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class LimitRange Declaration
|
Class InputValueMapper Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
class LimitRange
|
class InputValueMapper
|
||||||
:
|
:
|
||||||
public Function1<Type>
|
public Function1<Type>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Public Enumerations
|
||||||
|
|
||||||
|
//- Input value mapping mode
|
||||||
|
enum class mappingMode
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
FUNCTION1,
|
||||||
|
MINMAX
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Names for the input value mapping modes
|
||||||
|
static const Enum<mappingMode> mappingModeNames_;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
// Private Data
|
// Private Data
|
||||||
|
|
||||||
//- Minimum input value
|
//- Mapping mode
|
||||||
scalar min_;
|
mappingMode mappingMode_;
|
||||||
|
|
||||||
//- Maximum input value
|
// Function1 mapping
|
||||||
scalar max_;
|
|
||||||
|
|
||||||
//- Value function
|
//- Input value Function1
|
||||||
autoPtr<Function1<Type>> value_;
|
autoPtr<Function1<scalar>> mappingValuePtr_;
|
||||||
|
|
||||||
|
|
||||||
|
// Min/max mapping
|
||||||
|
|
||||||
|
//- Minimum input value
|
||||||
|
scalar min_;
|
||||||
|
|
||||||
|
//- Maximum input value
|
||||||
|
scalar max_;
|
||||||
|
|
||||||
|
|
||||||
|
// Function being wrapped
|
||||||
|
|
||||||
|
//- Value function
|
||||||
|
autoPtr<Function1<Type>> value_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
@ -124,19 +179,19 @@ class LimitRange
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//- Runtime type information
|
//- Runtime type information
|
||||||
TypeName("limitRange");
|
TypeName("inputValueMapper");
|
||||||
|
|
||||||
|
|
||||||
// Generated Methods
|
// Generated Methods
|
||||||
|
|
||||||
//- No copy assignment
|
//- No copy assignment
|
||||||
void operator=(const LimitRange<Type>&) = delete;
|
void operator=(const InputValueMapper<Type>&) = delete;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from entry name, dictionary and optional registry
|
//- Construct from entry name, dictionary and optional registry
|
||||||
LimitRange
|
InputValueMapper
|
||||||
(
|
(
|
||||||
const word& entryName,
|
const word& entryName,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
@ -144,11 +199,11 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Copy construct
|
//- Copy construct
|
||||||
explicit LimitRange(const LimitRange<Type>& rhs);
|
explicit InputValueMapper(const InputValueMapper<Type>& rhs);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~LimitRange() = default;
|
virtual ~InputValueMapper() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -174,10 +229,10 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "LimitRangeI.H"
|
#include "InputValueMapperI.H"
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
#include "LimitRange.C"
|
#include "InputValueMapper.C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
@ -0,0 +1,119 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2020-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 "InputValueMapper.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
inline Type Foam::Function1Types::InputValueMapper<Type>::value
|
||||||
|
(
|
||||||
|
const scalar t
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
switch (mappingMode_)
|
||||||
|
{
|
||||||
|
case mappingMode::NONE:
|
||||||
|
{
|
||||||
|
return value_->value(t);;
|
||||||
|
}
|
||||||
|
case mappingMode::FUNCTION1:
|
||||||
|
{
|
||||||
|
return value_->value(mappingValuePtr_->value(t));
|
||||||
|
}
|
||||||
|
case mappingMode::MINMAX:
|
||||||
|
{
|
||||||
|
scalar tlim = min(max(t, min_), max_);
|
||||||
|
|
||||||
|
return value_->value(tlim);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unhandled enumeration " << mappingModeNames_[mappingMode_]
|
||||||
|
<< ". Available options are: " << mappingModeNames_.sortedToc()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pTraits<Type>::zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Type Foam::Function1Types::InputValueMapper<Type>::integrate
|
||||||
|
(
|
||||||
|
const scalar x1,
|
||||||
|
const scalar x2
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
switch (mappingMode_)
|
||||||
|
{
|
||||||
|
case mappingMode::NONE:
|
||||||
|
{
|
||||||
|
return value_->integrate(x1, x2);
|
||||||
|
}
|
||||||
|
case mappingMode::FUNCTION1:
|
||||||
|
{
|
||||||
|
scalar x1Dash = mappingValuePtr_->value(x1);
|
||||||
|
scalar x2Dash = mappingValuePtr_->value(x2);
|
||||||
|
|
||||||
|
return value_->integrate(x1Dash, x2Dash);
|
||||||
|
}
|
||||||
|
case mappingMode::MINMAX:
|
||||||
|
{
|
||||||
|
scalar xlim0 = min(max(x1, min_), max_);
|
||||||
|
scalar xlim1 = min(max(x2, min_), max_);
|
||||||
|
|
||||||
|
Type intValue = value_->integrate(xlim0, xlim1);
|
||||||
|
|
||||||
|
if (x1 < min_)
|
||||||
|
{
|
||||||
|
intValue += (min(min_, x2) - x1)*this->value(min_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x2 > max_)
|
||||||
|
{
|
||||||
|
intValue += (x2 - max(max_, x1))*this->value(max_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return intValue;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unhandled enumeration " << mappingModeNames_[mappingMode_]
|
||||||
|
<< ". Available options are: " << mappingModeNames_.sortedToc()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pTraits<Type>::zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
@ -1,88 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2020-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 "LimitRange.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
void Foam::Function1Types::LimitRange<Type>::read(const dictionary& coeffs)
|
|
||||||
{
|
|
||||||
min_ = coeffs.get<scalar>("min");
|
|
||||||
max_ = coeffs.get<scalar>("max");
|
|
||||||
value_ = Function1<Type>::New("value", coeffs, this->obrPtr_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
Foam::Function1Types::LimitRange<Type>::LimitRange
|
|
||||||
(
|
|
||||||
const word& entryName,
|
|
||||||
const dictionary& dict,
|
|
||||||
const objectRegistry* obrPtr
|
|
||||||
)
|
|
||||||
:
|
|
||||||
Function1<Type>(entryName, obrPtr)
|
|
||||||
{
|
|
||||||
read(dict);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
Foam::Function1Types::LimitRange<Type>::LimitRange(const LimitRange<Type>& rhs)
|
|
||||||
:
|
|
||||||
Function1<Type>(rhs),
|
|
||||||
min_(rhs.min_),
|
|
||||||
max_(rhs.max_),
|
|
||||||
value_(rhs.value_.clone())
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
void Foam::Function1Types::LimitRange<Type>::writeEntries(Ostream& os) const
|
|
||||||
{
|
|
||||||
os.writeEntry("min", min_);
|
|
||||||
os.writeEntry("max", max_);
|
|
||||||
value_->writeData(os);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
void Foam::Function1Types::LimitRange<Type>::writeData(Ostream& os) const
|
|
||||||
{
|
|
||||||
Function1<Type>::writeData(os);
|
|
||||||
os.endEntry();
|
|
||||||
|
|
||||||
os.beginBlock(word(this->name() + "Coeffs"));
|
|
||||||
writeEntries(os);
|
|
||||||
os.endBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
@ -1,67 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2020 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 "LimitRange.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
inline Type Foam::Function1Types::LimitRange<Type>::value(const scalar t) const
|
|
||||||
{
|
|
||||||
scalar tlim = min(max(t, min_), max_);
|
|
||||||
|
|
||||||
return value_->value(tlim);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
Type Foam::Function1Types::LimitRange<Type>::integrate
|
|
||||||
(
|
|
||||||
const scalar x1,
|
|
||||||
const scalar x2
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
scalar xlim0 = min(max(x1, min_), max_);
|
|
||||||
scalar xlim1 = min(max(x2, min_), max_);
|
|
||||||
|
|
||||||
Type intValue = value_->integrate(xlim0, xlim1);
|
|
||||||
|
|
||||||
if (x1 < min_)
|
|
||||||
{
|
|
||||||
intValue += (min(min_, x2) - x1)*this->value(min_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x2 > max_)
|
|
||||||
{
|
|
||||||
intValue += (x2 - max(max_, x1))*this->value(max_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return intValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
@ -38,7 +38,7 @@ License
|
|||||||
#include "Table.H"
|
#include "Table.H"
|
||||||
#include "TableFile.H"
|
#include "TableFile.H"
|
||||||
#include "Scale.H"
|
#include "Scale.H"
|
||||||
#include "LimitRange.H"
|
#include "InputValueMapper.H"
|
||||||
#include "FunctionObjectValue.H"
|
#include "FunctionObjectValue.H"
|
||||||
#include "fieldTypes.H"
|
#include "fieldTypes.H"
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ License
|
|||||||
makeFunction1Type(Table, Type); \
|
makeFunction1Type(Table, Type); \
|
||||||
makeFunction1Type(TableFile, Type); \
|
makeFunction1Type(TableFile, Type); \
|
||||||
makeFunction1Type(Scale, Type); \
|
makeFunction1Type(Scale, Type); \
|
||||||
makeFunction1Type(LimitRange, Type); \
|
makeFunction1Type(InputValueMapper, Type); \
|
||||||
makeFunction1Type(FunctionObjectValue, Type);
|
makeFunction1Type(FunctionObjectValue, Type);
|
||||||
|
|
||||||
#define makeFieldFunction1s(Type) \
|
#define makeFieldFunction1s(Type) \
|
||||||
|
Loading…
Reference in New Issue
Block a user