mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-function1-limit-range' into 'develop'
Feature function1 limit range See merge request Development/openfoam!414
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2012-2015 OpenFOAM Foundation
|
Copyright (C) 2012-2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2019 OpenCFD Ltd.
|
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -160,7 +160,7 @@ bool Foam::linearInterpolationWeights::integrationWeights
|
|||||||
scalarField& weights
|
scalarField& weights
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (t2 < t1-VSMALL)
|
if (t2 < t1 - ROOTVSMALL)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Integration should be in positive direction."
|
<< "Integration should be in positive direction."
|
||||||
@ -173,6 +173,20 @@ bool Foam::linearInterpolationWeights::integrationWeights
|
|||||||
//- Find lower or equal index
|
//- Find lower or equal index
|
||||||
const label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>());
|
const label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>());
|
||||||
|
|
||||||
|
if (t2 <= t1 + ROOTVSMALL)
|
||||||
|
{
|
||||||
|
// Early exit if 1 and t2 are approximately equal
|
||||||
|
|
||||||
|
bool anyChanged = (indices.size() != 1 || indices[0] != i1);
|
||||||
|
|
||||||
|
indices.setSize(1);
|
||||||
|
weights.setSize(1);
|
||||||
|
indices[0] = i1;
|
||||||
|
weights[0] = scalar(0);
|
||||||
|
|
||||||
|
return anyChanged;
|
||||||
|
}
|
||||||
|
|
||||||
//- Find lower index
|
//- Find lower index
|
||||||
const label i2 = findLower(samples_, t2);
|
const label i2 = findLower(samples_, t2);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,87 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::LimitRange<Type>::LimitRange
|
||||||
|
(
|
||||||
|
const word& entryName,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
:
|
||||||
|
Function1<Type>(entryName)
|
||||||
|
{
|
||||||
|
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 << token::END_STATEMENT << nl;
|
||||||
|
|
||||||
|
os.beginBlock(word(this->name() + "Coeffs"));
|
||||||
|
writeEntries(os);
|
||||||
|
os.endBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,179 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::Function1Types::LimitRange
|
||||||
|
|
||||||
|
Description
|
||||||
|
Function1 wrapper that limits the input range of another Function1
|
||||||
|
|
||||||
|
Example usage for limiting a polynomial:
|
||||||
|
\verbatim
|
||||||
|
limitedPolyTest limitRange;
|
||||||
|
limitedPolyTestCoeffs
|
||||||
|
{
|
||||||
|
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 limiting a table
|
||||||
|
\verbatim
|
||||||
|
limitedTableFileTest limitRange;
|
||||||
|
limitedTableFileTestCoeffs
|
||||||
|
{
|
||||||
|
min 0.4;
|
||||||
|
max 1.4;
|
||||||
|
|
||||||
|
value tableFile;
|
||||||
|
file "<system>/fanCurve.txt";
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
Where:
|
||||||
|
\table
|
||||||
|
Property | Description | Required
|
||||||
|
min | Minimum input value | yes
|
||||||
|
max | Maximum input value | yes
|
||||||
|
value | Function of type Function1<Type> | yes
|
||||||
|
\endtable
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
LimitRange.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef LimitRange_H
|
||||||
|
#define LimitRange_H
|
||||||
|
|
||||||
|
#include "Function1.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace Function1Types
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class LimitRange Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
class LimitRange
|
||||||
|
:
|
||||||
|
public Function1<Type>
|
||||||
|
{
|
||||||
|
// Private Data
|
||||||
|
|
||||||
|
//- Minimum input value
|
||||||
|
scalar min_;
|
||||||
|
|
||||||
|
//- Maximum input value
|
||||||
|
scalar max_;
|
||||||
|
|
||||||
|
//- Value function
|
||||||
|
autoPtr<Function1<Type>> value_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Read the coefficients from the given dictionary
|
||||||
|
void read(const dictionary& coeffs);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("limitRange");
|
||||||
|
|
||||||
|
|
||||||
|
// Generated Methods
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const LimitRange<Type>&) = delete;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from entry name and dictionary
|
||||||
|
LimitRange(const word& entryName, const dictionary& dict);
|
||||||
|
|
||||||
|
//- Copy construct
|
||||||
|
explicit LimitRange(const LimitRange<Type>& rhs);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~LimitRange() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Return value for time t
|
||||||
|
virtual inline Type value(const scalar t) const;
|
||||||
|
|
||||||
|
//- Integrate between two (scalar) values
|
||||||
|
virtual inline Type integrate(const scalar x1, const scalar x2) 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 "LimitRangeI.H"
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
#include "LimitRange.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -103,6 +103,12 @@ public:
|
|||||||
//- Copy constructor
|
//- Copy constructor
|
||||||
explicit Polynomial(const Polynomial& poly);
|
explicit Polynomial(const Polynomial& poly);
|
||||||
|
|
||||||
|
//- Construct and return a clone
|
||||||
|
virtual tmp<Function1<Type>> clone() const
|
||||||
|
{
|
||||||
|
return tmp<Function1<Type>>(new Polynomial<Type>(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~Polynomial() = default;
|
virtual ~Polynomial() = default;
|
||||||
|
|||||||
@ -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 "fieldTypes.H"
|
#include "fieldTypes.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -56,7 +56,8 @@ License
|
|||||||
makeFunction1Type(CSV, Type); \
|
makeFunction1Type(CSV, Type); \
|
||||||
makeFunction1Type(Table, Type); \
|
makeFunction1Type(Table, Type); \
|
||||||
makeFunction1Type(TableFile, Type); \
|
makeFunction1Type(TableFile, Type); \
|
||||||
makeFunction1Type(Scale, Type);
|
makeFunction1Type(Scale, Type); \
|
||||||
|
makeFunction1Type(LimitRange, Type);
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user