ENH: additional step function, cleanup autoPtr use in Function1

This commit is contained in:
Mark Olesen
2020-05-22 11:39:36 +02:00
parent 09d9c5cc03
commit 51c2329f97
41 changed files with 397 additions and 312 deletions

View File

@ -107,6 +107,7 @@ primitives/triad/triad.C
/* Run-time selectable functions */
primitives/functions/Function1/makeFunction1s.C
primitives/functions/Function1/ramp/ramp.C
primitives/functions/Function1/step/stepFunction.C
primitives/functions/Function1/linearRamp/linearRamp.C
primitives/functions/Function1/quadraticRamp/quadraticRamp.C
primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,10 +41,10 @@ Foam::Function1<Type>::Function1(const word& entryName)
template<class Type>
Foam::Function1<Type>::Function1(const Function1<Type>& de)
Foam::Function1<Type>::Function1(const Function1<Type>& rhs)
:
refCount(),
name_(de.name_)
name_(rhs.name_)
{}
@ -65,10 +66,10 @@ template<class Type>
Type Foam::Function1<Type>::value(const scalar x) const
{
NotImplemented;
return Zero;
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
(
@ -84,7 +85,6 @@ template<class Type>
Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
{
NotImplemented;
return Zero;
}
@ -174,13 +174,13 @@ template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const Function1<Type>& f1
const Function1<Type>& rhs
)
{
os.check(FUNCTION_NAME);
os << f1.name_;
f1.writeData(os);
os << rhs.name_;
rhs.writeData(os);
return os;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,6 +33,38 @@ Description
provide functions to return the (interpolated) value, and integral between
limits.
The New factory method attempts to deal with varying types of input.
It accepts primitive or dictionary entries for dispatching to different
function types, but wraps unspecified types as "constant".
In the dictionary form, the coefficents are the dictionary itself.
This is arguably the more readable form.
For example,
\verbatim
<entryName>
{
type linearRamp;
start 10;
duration 20;
}
\endverbatim
In the primitive form, the coefficents are provided separately.
For example,
\verbatim
<entryName> linearRamp;
<entryName>Coeffs
{
start 10;
duration 20;
}
\endverbatim
The coeffs dictionary is optional, since it is not required by all types.
For example,
\verbatim
<entryName> zero;
\endverbatim
SourceFiles
Function1.C
Function1New.C
@ -50,10 +82,8 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class Time;
// Forward declaration of friend functions and operators
template<class Type> class Function1;
template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
@ -66,19 +96,18 @@ class Function1
:
public refCount
{
// Private Member Functions
//- No copy assignment
void operator=(const Function1<Type>&) = delete;
protected:
// Protected data
// Protected Data
//- Name of entry
const word name_;
// Protected Member Functions
//- No copy assignment
void operator=(const Function1<Type>&) = delete;
public:
@ -107,7 +136,7 @@ public:
explicit Function1(const word& entryName);
//- Copy constructor
explicit Function1(const Function1<Type>& f1);
explicit Function1(const Function1<Type>& rhs);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const = 0;

View File

@ -47,13 +47,6 @@ Foam::Function1Types::OneConstant<Type>::OneConstant
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::OneConstant<Type>::~OneConstant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -68,7 +69,7 @@ class OneConstant
public:
// Runtime type information
//- Runtime type information
TypeName("one");
@ -88,7 +89,7 @@ public:
//- Destructor
virtual ~OneConstant();
virtual ~OneConstant() = default;
// Member Functions

View File

@ -40,8 +40,8 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
coeffs_(),
canIntegrate_(true)
{
Istream& is(dict.lookup(entryName));
word entryType(is);
Istream& is = dict.lookup(entryName);
const word entryType(is);
is >> coeffs_;
@ -121,13 +121,6 @@ Foam::Function1Types::Polynomial<Type>::Polynomial(const Polynomial& poly)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Polynomial<Type>::~Polynomial()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -67,7 +67,7 @@ class Polynomial
:
public Function1<Type>
{
// Private data
// Private Data
//- Polynomial coefficients - list of prefactor, exponent
List<Tuple2<Type, Type>> coeffs_;
@ -90,13 +90,14 @@ public:
// Constructors
//- Construct from entry name and dictionary
Polynomial(const word& entryName, const dictionary& dict);
//- Construct from components
Polynomial
(
const word& entryName,
const List<Tuple2<Type, Type>>&
const List<Tuple2<Type, Type>>& coeffs
);
//- Copy constructor
@ -104,24 +105,19 @@ public:
//- Destructor
virtual ~Polynomial();
virtual ~Polynomial() = default;
// Member Functions
// Manipulation
//- Convert time
virtual void convertTimeBase(const Time& t);
//- Convert time
virtual void convertTimeBase(const Time& t);
//- Return Polynomial value
virtual Type value(const scalar x) const;
// Evaluation
//- Return Polynomial value
virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Write in dictionary format

View File

@ -51,18 +51,11 @@ Foam::Function1Types::Scale<Type>::Scale
template<class Type>
Foam::Function1Types::Scale<Type>::Scale(const Scale<Type>& se)
Foam::Function1Types::Scale<Type>::Scale(const Scale<Type>& rhs)
:
Function1<Type>(se),
scale_(se.scale_.clone()),
value_(se.value_.clone())
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Scale<Type>::~Scale()
Function1<Type>(rhs),
scale_(rhs.scale_.clone()),
value_(rhs.value_.clone())
{}

View File

@ -92,7 +92,7 @@ class Scale
:
public Function1<Type>
{
// Private data
// Private Data
//- Scalar scaling function
autoPtr<Function1<scalar>> scale_;
@ -112,7 +112,7 @@ class Scale
public:
// Runtime type information
//- Runtime type information
TypeName("scale");
@ -125,12 +125,12 @@ public:
const dictionary& dict
);
//- Copy constructor
explicit Scale(const Scale<Type>& se);
//- Copy construct
explicit Scale(const Scale<Type>& rhs);
//- Destructor
virtual ~Scale();
virtual ~Scale() = default;
// Member Functions

View File

@ -66,13 +66,6 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Sine<Type>::~Sine()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -142,7 +142,7 @@ public:
//- Destructor
virtual ~Sine();
virtual ~Sine() = default;
// Member Functions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,8 +33,8 @@ License
template<class Type>
void Foam::Function1Types::Square<Type>::read(const dictionary& coeffs)
{
t0_ = coeffs.lookupOrDefault<scalar>("t0", 0);
markSpace_ = coeffs.lookupOrDefault<scalar>("markSpace", 1);
t0_ = coeffs.getOrDefault<scalar>("t0", 0);
markSpace_ = coeffs.getOrDefault<scalar>("markSpace", 1);
amplitude_ = Function1<scalar>::New("amplitude", coeffs);
frequency_ = Function1<scalar>::New("frequency", coeffs);
scale_ = Function1<Type>::New("scale", coeffs);
@ -68,13 +68,6 @@ Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Square<Type>::~Square()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -99,7 +99,7 @@ class Square
:
public Function1<Type>
{
// Private data
// Private Data
//- Start-time for the square function
scalar t0_;
@ -145,11 +145,11 @@ public:
);
//- Copy constructor
explicit Square(const Square<Type>& se);
explicit Square(const Square<Type>& rhs);
//- Destructor
virtual ~Square();
virtual ~Square() = default;
// Member Functions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,7 +40,7 @@ Foam::Function1Types::Table<Type>::Table
TableBase<Type>(entryName, dict)
{
Istream& is = dict.lookup(entryName);
word entryType(is);
const word entryType(is);
is >> this->table_;
TableBase<Type>::check();
}

View File

@ -36,11 +36,11 @@ template<class Type>
const Foam::interpolationWeights&
Foam::Function1Types::TableBase<Type>::interpolator() const
{
if (interpolatorPtr_.empty())
if (!interpolatorPtr_)
{
// Re-work table into linear list
tableSamplesPtr_.reset(new scalarField(table_.size()));
scalarField& samples = *tableSamplesPtr_;
auto& samples = *tableSamplesPtr_;
forAll(table_, i)
{
samples[i] = table_[i].first();
@ -69,7 +69,7 @@ Foam::Function1Types::TableBase<Type>::TableBase
name_(name),
bounding_
(
bounds::repeatableBoundingNames.lookupOrDefault
bounds::repeatableBoundingNames.getOrDefault
(
"outOfBounds",
dict,
@ -79,9 +79,11 @@ Foam::Function1Types::TableBase<Type>::TableBase
),
interpolationScheme_
(
dict.lookupOrDefault<word>("interpolationScheme", "linear")
dict.getOrDefault<word>("interpolationScheme", "linear")
),
table_()
table_(),
tableSamplesPtr_(nullptr),
interpolatorPtr_(nullptr)
{}
@ -93,8 +95,8 @@ Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
bounding_(tbl.bounding_),
interpolationScheme_(tbl.interpolationScheme_),
table_(tbl.table_),
tableSamplesPtr_(tbl.tableSamplesPtr_),
interpolatorPtr_(tbl.interpolatorPtr_)
tableSamplesPtr_(tbl.tableSamplesPtr_.clone()),
interpolatorPtr_(tbl.interpolatorPtr_) // steal/reuse (missing clone!)
{}

View File

@ -46,6 +46,7 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class interpolationWeights;
namespace Function1Types

View File

@ -50,7 +50,8 @@ Foam::Function1Types::TableFile<Type>::TableFile
if (!is.good())
{
FatalIOErrorInFunction(is)
<< "Cannot open file." << exit(FatalIOError);
<< "Cannot open file." << nl
<< exit(FatalIOError);
}
is >> this->table_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,7 +35,7 @@ Description
<entryName> tableFile;
<entryName>Coeffs
{
fileName dataFile; // name of data file
file dataFile; // name of data file
outOfBounds clamp; // optional out-of-bounds handling
interpolationScheme linear; // optional interpolation method
}
@ -109,7 +109,7 @@ public:
virtual ~TableFile() = default;
// I/O
// Member Functions
//- Write in dictionary format
virtual void writeData(Ostream& os) const;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +30,13 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::ZeroConstant<Type>::ZeroConstant(const word& entryName)
:
Function1<Type>(entryName)
{}
template<class Type>
Foam::Function1Types::ZeroConstant<Type>::ZeroConstant
(
@ -40,13 +48,6 @@ Foam::Function1Types::ZeroConstant<Type>::ZeroConstant
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::ZeroConstant<Type>::~ZeroConstant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -68,18 +69,21 @@ class ZeroConstant
public:
// Runtime type information
//- Runtime type information
TypeName("zero");
// Constructors
//- Construct from entry name
explicit ZeroConstant(const word& entryName);
//- Construct from entry name and dictionary
ZeroConstant(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~ZeroConstant();
virtual ~ZeroConstant() = default;
// Member Functions

View File

@ -50,10 +50,4 @@ Foam::Function1Types::halfCosineRamp::halfCosineRamp
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::halfCosineRamp::~halfCosineRamp()
{}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,30 +59,20 @@ class halfCosineRamp
:
public ramp
{
// Private Member Functions
//- No copy assignment
void operator=(const halfCosineRamp&) = delete;
public:
// Runtime type information
//- Runtime type information
TypeName("halfCosineRamp");
// Constructors
//- Construct from entry name and dictionary
halfCosineRamp
(
const word& entryName,
const dictionary& dict
);
halfCosineRamp(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~halfCosineRamp();
virtual ~halfCosineRamp() = default;
// Member Functions

View File

@ -50,10 +50,4 @@ Foam::Function1Types::linearRamp::linearRamp
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::linearRamp::~linearRamp()
{}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +28,7 @@ Class
Foam::Function1Types::linearRamp
Description
Linear ramp function starting from 0 and increasing linearRamply to 1 from
Linear ramp function starting from 0 and increasing linearly to 1 from
\c start over the \c duration and remaining at 1 thereafter.
See also
@ -58,12 +59,6 @@ class linearRamp
:
public ramp
{
// Private Member Functions
//- No copy assignment
void operator=(const linearRamp&) = delete;
public:
// Runtime type information
@ -73,15 +68,11 @@ public:
// Constructors
//- Construct from entry name and dictionary
linearRamp
(
const word& entryName,
const dictionary& dict
);
linearRamp(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~linearRamp();
virtual ~linearRamp() = default;
// Member Functions

View File

@ -50,10 +50,4 @@ Foam::Function1Types::quadraticRamp::quadraticRamp
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::quadraticRamp::~quadraticRamp()
{}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +28,7 @@ Class
Foam::Function1Types::quadraticRamp
Description
Quadratic ramp function starting from 0 and increasing quadraticRampally
Quadratic ramp function starting from 0 and increasing quadratically
to 1 from \c t_0 over the \c duration and remaining at 1 thereafter.
See also
@ -58,30 +59,20 @@ class quadraticRamp
:
public ramp
{
// Private Member Functions
//- No copy assignment
void operator=(const quadraticRamp&) = delete;
public:
// Runtime type information
//- Runtime type information
TypeName("quadraticRamp");
// Constructors
//- Construct from entry name and dictionary
quadraticRamp
(
const word& entryName,
const dictionary& dict
);
quadraticRamp(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~quadraticRamp();
virtual ~quadraticRamp() = default;
// Member Functions

View File

@ -50,10 +50,4 @@ Foam::Function1Types::quarterCosineRamp::quarterCosineRamp
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::quarterCosineRamp::~quarterCosineRamp()
{}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,12 +59,6 @@ class quarterCosineRamp
:
public ramp
{
// Private Member Functions
//- No copy assignment
void operator=(const quarterCosineRamp&) = delete;
public:
// Runtime type information
@ -73,15 +68,11 @@ public:
// Constructors
//- Construct from entry name and dictionary
quarterCosineRamp
(
const word& entryName,
const dictionary& dict
);
quarterCosineRamp(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~quarterCosineRamp();
virtual ~quarterCosineRamp() = default;
// Member Functions

View File

@ -50,10 +50,4 @@ Foam::Function1Types::quarterSineRamp::quarterSineRamp
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::quarterSineRamp::~quarterSineRamp()
{}
// ************************************************************************* //

View File

@ -58,30 +58,20 @@ class quarterSineRamp
:
public ramp
{
// Private Member Functions
//- No copy assignment
void operator=(const quarterSineRamp&) = delete;
public:
// Runtime type information
//- Runtime type information
TypeName("quarterSineRamp");
// Constructors
//- Construct from entry name and dictionary
quarterSineRamp
(
const word& entryName,
const dictionary& dict
);
quarterSineRamp(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~quarterSineRamp();
virtual ~quarterSineRamp() = default;
// Member Functions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,7 +32,7 @@ License
void Foam::Function1Types::ramp::read(const dictionary& coeffs)
{
start_ = coeffs.lookupOrDefault<scalar>("start", 0);
start_ = coeffs.getOrDefault<scalar>("start", 0);
coeffs.readEntry("duration", duration_);
}
@ -48,12 +49,6 @@ Foam::Function1Types::ramp::ramp
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1Types::ramp::~ramp()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::Function1Types::ramp::writeData(Ostream& os) const

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,7 +88,7 @@ class ramp
{
protected:
// Protected data
// Protected Data
//- Start-time of the ramp function
scalar start_;
@ -96,7 +97,7 @@ protected:
scalar duration_;
//- Simple linear ramp function
// which form the basis of many more complex ramp functions
//- that forms the basis of many more complex ramp functions
inline scalar linearRamp(const scalar t) const
{
return max(min((t - start_)/duration_, 1), 0);
@ -127,7 +128,7 @@ public:
//- Destructor
virtual ~ramp();
virtual ~ramp() = default;
// Member Functions

View File

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "stepFunction.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1Types
{
makeScalarFunction1(stepFunction);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1Types::stepFunction::stepFunction
(
const word& entryName,
const dictionary& dict
)
:
ramp(entryName, dict)
{}
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::stepFunction
Description
A step function that is 0 before \c start changing to 1 for the
\c duration and returning to 0 thereafter.
See also
Foam::Function1Types::ramp
SourceFiles
stepFunction.C
\*---------------------------------------------------------------------------*/
#ifndef stepFunction_H
#define stepFunction_H
#include "ramp.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1Types
{
/*---------------------------------------------------------------------------*\
Class stepFunction Declaration
\*---------------------------------------------------------------------------*/
class stepFunction
:
public ramp
{
public:
//- Runtime type information
TypeName("step");
// Constructors
//- Construct from entry name and dictionary
stepFunction(const word& entryName, const dictionary& dict);
//- Destructor
virtual ~stepFunction() = default;
// Member Functions
//- Return value at time t
virtual inline scalar value(const scalar x) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1Types
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "stepFunctionI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "stepFunction.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::scalar Foam::Function1Types::stepFunction::value
(
const scalar t
) const
{
if (t < start_ || t > start_ + duration_)
{
return 0;
}
return 1;
}
// ************************************************************************* //

View File

@ -65,16 +65,10 @@ namespace Foam
{
// Forward Declarations
template<int PolySize>
class Polynomial;
template<int PolySize> class Polynomial;
template<int PolySize>
Ostream& operator<<
(
Ostream&,
const Polynomial<PolySize>&
);
Ostream& operator<<( Ostream&, const Polynomial<PolySize>&);
/*---------------------------------------------------------------------------*\
Class Polynomial Declaration

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,11 +37,12 @@ Foam::Ostream& Foam::operator<<
const Polynomial<PolySize>& poly
)
{
os << static_cast
<VectorSpace<Polynomial<PolySize>, scalar, PolySize>>(poly);
os.check(FUNCTION_NAME);
return os;
return
os <<
static_cast
<
VectorSpace<Polynomial<PolySize>, scalar, PolySize>
>(poly);
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,7 +88,7 @@ Foam::polynomialFunction::polynomialFunction(const label order)
:
scalarList(order, Zero),
logActive_(false),
logCoeff_(0.0)
logCoeff_(0)
{
if (this->empty())
{
@ -110,7 +111,7 @@ Foam::polynomialFunction::polynomialFunction(const UList<scalar>& coeffs)
:
scalarList(coeffs),
logActive_(false),
logCoeff_(0.0)
logCoeff_(0)
{
if (this->empty())
{
@ -125,7 +126,7 @@ Foam::polynomialFunction::polynomialFunction(Istream& is)
:
scalarList(is),
logActive_(false),
logCoeff_(0.0)
logCoeff_(0)
{
if (this->empty())
{
@ -136,12 +137,6 @@ Foam::polynomialFunction::polynomialFunction(Istream& is)
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::polynomialFunction::~polynomialFunction()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::polynomialFunction::logActive() const
@ -310,18 +305,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const polynomialFunction& poly)
// output like VectorSpace
os << token::BEGIN_LIST;
if (!poly.empty())
forAll(poly, i)
{
for (int i=0; i<poly.size()-1; i++)
{
os << poly[i] << token::SPACE;
}
os << poly.last();
if (i) os << token::SPACE;
os << poly[i];
}
os << token::END_LIST;
// Check state of Ostream
os.check(FUNCTION_NAME);
return os;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -63,13 +64,10 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class polynomialFunction;
// Forward declaration of friend functions
Ostream& operator<<(Ostream&, const polynomialFunction&);
/*---------------------------------------------------------------------------*\
Class polynomialFunction Declaration
\*---------------------------------------------------------------------------*/
@ -78,7 +76,7 @@ class polynomialFunction
:
private scalarList
{
// Private data
// Private Data
//- Include the log term? - only activated using integralMinus1()
bool logActive_;
@ -94,7 +92,7 @@ class polynomialFunction
static polynomialFunction cloneIntegral
(
const polynomialFunction&,
const scalar intConstant = 0.0
const scalar intConstant = 0
);
//- Return integral coefficients when lowest order is -1.
@ -102,15 +100,13 @@ class polynomialFunction
static polynomialFunction cloneIntegralMinus1
(
const polynomialFunction&,
const scalar intConstant = 0.0
const scalar intConstant = 0
);
//- No copy assignment
void operator=(const polynomialFunction&) = delete;
public:
//- Runtime type information
@ -119,26 +115,26 @@ public:
// Constructors
//- Construct a particular size, with all coefficients = 0.0
explicit polynomialFunction(const label);
//- Construct a particular size, with all coefficients as 0
explicit polynomialFunction(const label order);
//- Copy constructor
polynomialFunction(const polynomialFunction&);
polynomialFunction(const polynomialFunction& rhs);
//- Construct from a list of coefficients
explicit polynomialFunction(const UList<scalar>& coeffs);
//- Construct from Istream
polynomialFunction(Istream&);
explicit polynomialFunction(Istream& is);
//- Destructor
virtual ~polynomialFunction();
virtual ~polynomialFunction() = default;
// Member Functions
//- Return the number of coefficients
//- The number of coefficients
using scalarList::size;
//- Return coefficient

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,24 +33,28 @@ License
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const Time& t,
const word& name,
const Time& runTime,
const word& entryName,
const dictionary& dict
)
:
time_(t),
name_(name),
entry_(Function1<Type>::New(name, dict))
time_(runTime),
name_(entryName),
entry_(Function1<Type>::New(entryName, dict))
{
entry_->convertTimeBase(t);
entry_->convertTimeBase(runTime);
}
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1(const Time& t, const word& name)
Foam::TimeFunction1<Type>::TimeFunction1
(
const Time& runTime,
const word& entryName
)
:
time_(t),
name_(name),
time_(runTime),
name_(entryName),
entry_(nullptr)
{}
@ -57,24 +62,12 @@ Foam::TimeFunction1<Type>::TimeFunction1(const Time& t, const word& name)
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const TimeFunction1<Type>& tde
const TimeFunction1<Type>& rhs
)
:
time_(tde.time_),
name_(tde.name_),
entry_()
{
if (tde.entry_.valid())
{
entry_.reset(tde.entry_->clone().ptr());
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TimeFunction1<Type>::~TimeFunction1()
time_(rhs.time_),
name_(rhs.name_),
entry_(rhs.entry_) // steal/reuse (missing clone!)
{}
@ -83,15 +76,7 @@ Foam::TimeFunction1<Type>::~TimeFunction1()
template<class Type>
void Foam::TimeFunction1<Type>::reset(const dictionary& dict)
{
entry_.reset
(
Function1<Type>::New
(
name_,
dict
).ptr()
);
entry_ = Function1<Type>::New(name_, dict);
entry_->convertTimeBase(time_);
}
@ -127,10 +112,14 @@ template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const TimeFunction1<Type>& de
const TimeFunction1<Type>& rhs
)
{
return de.entry_->operator<<(os, de);
if (rhs.entry_)
{
rhs.entry_->operator<<(os, rhs);
}
return os;
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -45,15 +46,12 @@ SourceFiles
namespace Foam
{
template<class Type>
class TimeFunction1;
// Forward Declarations
template<class Type> class TimeFunction1;
template<class Type>
Ostream& operator<<
(
Ostream&,
const TimeFunction1<Type>&
);
Ostream& operator<<(Ostream&, const TimeFunction1<Type>&);
/*---------------------------------------------------------------------------*\
Class TimeFunction1 Declaration
@ -62,10 +60,9 @@ Ostream& operator<<
template<class Type>
class TimeFunction1
{
protected:
// Protected data
// Protected Data
//- Reference to the time database
const Time& time_;
@ -81,27 +78,27 @@ public:
// Constructor
//- Construct from entry name
//- Construct from entry name and dictionary
TimeFunction1
(
const Time& t,
const Time& runTime,
const word& name,
const dictionary& dict
);
//- Construct null from entry name
//- Construct from entry name
TimeFunction1
(
const Time& t,
const Time& runTime,
const word& entryName
);
//- Copy constructor
TimeFunction1(const TimeFunction1<Type>& tde);
//- Copy construct
TimeFunction1(const TimeFunction1<Type>& rhs);
//- Destructor
virtual ~TimeFunction1();
virtual ~TimeFunction1() = default;
// Member Functions