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 */ /* Run-time selectable functions */
primitives/functions/Function1/makeFunction1s.C primitives/functions/Function1/makeFunction1s.C
primitives/functions/Function1/ramp/ramp.C primitives/functions/Function1/ramp/ramp.C
primitives/functions/Function1/step/stepFunction.C
primitives/functions/Function1/linearRamp/linearRamp.C primitives/functions/Function1/linearRamp/linearRamp.C
primitives/functions/Function1/quadraticRamp/quadraticRamp.C primitives/functions/Function1/quadraticRamp/quadraticRamp.C
primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -33,6 +33,38 @@ Description
provide functions to return the (interpolated) value, and integral between provide functions to return the (interpolated) value, and integral between
limits. 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 SourceFiles
Function1.C Function1.C
Function1New.C Function1New.C
@ -50,10 +82,8 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class Time; class Time;
// Forward declaration of friend functions and operators
template<class Type> class Function1; template<class Type> class Function1;
template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&); template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
@ -66,19 +96,18 @@ class Function1
: :
public refCount public refCount
{ {
// Private Member Functions
//- No copy assignment
void operator=(const Function1<Type>&) = delete;
protected: protected:
// Protected data // Protected Data
//- Name of entry //- Name of entry
const word name_; const word name_;
// Protected Member Functions
//- No copy assignment
void operator=(const Function1<Type>&) = delete;
public: public:
@ -107,7 +136,7 @@ public:
explicit Function1(const word& entryName); explicit Function1(const word& entryName);
//- Copy constructor //- Copy constructor
explicit Function1(const Function1<Type>& f1); explicit Function1(const Function1<Type>& rhs);
//- Construct and return a clone //- Construct and return a clone
virtual tmp<Function1<Type>> clone() const = 0; 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

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

View File

@ -40,8 +40,8 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
coeffs_(), coeffs_(),
canIntegrate_(true) canIntegrate_(true)
{ {
Istream& is(dict.lookup(entryName)); Istream& is = dict.lookup(entryName);
word entryType(is); const word entryType(is);
is >> coeffs_; 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 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.
@ -40,7 +40,7 @@ Foam::Function1Types::Table<Type>::Table
TableBase<Type>(entryName, dict) TableBase<Type>(entryName, dict)
{ {
Istream& is = dict.lookup(entryName); Istream& is = dict.lookup(entryName);
word entryType(is); const word entryType(is);
is >> this->table_; is >> this->table_;
TableBase<Type>::check(); TableBase<Type>::check();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -68,18 +69,21 @@ class ZeroConstant
public: public:
// Runtime type information //- Runtime type information
TypeName("zero"); TypeName("zero");
// Constructors // Constructors
//- Construct from entry name
explicit ZeroConstant(const word& entryName);
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
ZeroConstant(const word& entryName, const dictionary& dict); ZeroConstant(const word& entryName, const dictionary& dict);
//- Destructor //- Destructor
virtual ~ZeroConstant(); virtual ~ZeroConstant() = default;
// Member Functions // 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -58,30 +59,20 @@ class halfCosineRamp
: :
public ramp public ramp
{ {
// Private Member Functions
//- No copy assignment
void operator=(const halfCosineRamp&) = delete;
public: public:
// Runtime type information //- Runtime type information
TypeName("halfCosineRamp"); TypeName("halfCosineRamp");
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
halfCosineRamp halfCosineRamp(const word& entryName, const dictionary& dict);
(
const word& entryName,
const dictionary& dict
);
//- Destructor //- Destructor
virtual ~halfCosineRamp(); virtual ~halfCosineRamp() = default;
// Member Functions // 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,7 +28,7 @@ Class
Foam::Function1Types::linearRamp Foam::Function1Types::linearRamp
Description 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. \c start over the \c duration and remaining at 1 thereafter.
See also See also
@ -58,12 +59,6 @@ class linearRamp
: :
public ramp public ramp
{ {
// Private Member Functions
//- No copy assignment
void operator=(const linearRamp&) = delete;
public: public:
// Runtime type information // Runtime type information
@ -73,15 +68,11 @@ public:
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
linearRamp linearRamp(const word& entryName, const dictionary& dict);
(
const word& entryName,
const dictionary& dict
);
//- Destructor //- Destructor
virtual ~linearRamp(); virtual ~linearRamp() = default;
// Member Functions // 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,7 +28,7 @@ Class
Foam::Function1Types::quadraticRamp Foam::Function1Types::quadraticRamp
Description 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. to 1 from \c t_0 over the \c duration and remaining at 1 thereafter.
See also See also
@ -58,30 +59,20 @@ class quadraticRamp
: :
public ramp public ramp
{ {
// Private Member Functions
//- No copy assignment
void operator=(const quadraticRamp&) = delete;
public: public:
// Runtime type information //- Runtime type information
TypeName("quadraticRamp"); TypeName("quadraticRamp");
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
quadraticRamp quadraticRamp(const word& entryName, const dictionary& dict);
(
const word& entryName,
const dictionary& dict
);
//- Destructor //- Destructor
virtual ~quadraticRamp(); virtual ~quadraticRamp() = default;
// Member Functions // 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -58,12 +59,6 @@ class quarterCosineRamp
: :
public ramp public ramp
{ {
// Private Member Functions
//- No copy assignment
void operator=(const quarterCosineRamp&) = delete;
public: public:
// Runtime type information // Runtime type information
@ -73,15 +68,11 @@ public:
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
quarterCosineRamp quarterCosineRamp(const word& entryName, const dictionary& dict);
(
const word& entryName,
const dictionary& dict
);
//- Destructor //- Destructor
virtual ~quarterCosineRamp(); virtual ~quarterCosineRamp() = default;
// Member Functions // 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 public ramp
{ {
// Private Member Functions
//- No copy assignment
void operator=(const quarterSineRamp&) = delete;
public: public:
// Runtime type information //- Runtime type information
TypeName("quarterSineRamp"); TypeName("quarterSineRamp");
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
quarterSineRamp quarterSineRamp(const word& entryName, const dictionary& dict);
(
const word& entryName,
const dictionary& dict
);
//- Destructor //- Destructor
virtual ~quarterSineRamp(); virtual ~quarterSineRamp() = default;
// Member Functions // Member Functions

View File

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

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,7 +88,7 @@ class ramp
{ {
protected: protected:
// Protected data // Protected Data
//- Start-time of the ramp function //- Start-time of the ramp function
scalar start_; scalar start_;
@ -96,7 +97,7 @@ protected:
scalar duration_; scalar duration_;
//- Simple linear ramp function //- 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 inline scalar linearRamp(const scalar t) const
{ {
return max(min((t - start_)/duration_, 1), 0); return max(min((t - start_)/duration_, 1), 0);
@ -127,7 +128,7 @@ public:
//- Destructor //- Destructor
virtual ~ramp(); virtual ~ramp() = default;
// Member Functions // 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 // Forward Declarations
template<int PolySize> template<int PolySize> class Polynomial;
class Polynomial;
template<int PolySize> template<int PolySize>
Ostream& operator<< Ostream& operator<<( Ostream&, const Polynomial<PolySize>&);
(
Ostream&,
const Polynomial<PolySize>&
);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class Polynomial Declaration Class Polynomial Declaration

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,24 +33,28 @@ License
template<class Type> template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1 Foam::TimeFunction1<Type>::TimeFunction1
( (
const Time& t, const Time& runTime,
const word& name, const word& entryName,
const dictionary& dict const dictionary& dict
) )
: :
time_(t), time_(runTime),
name_(name), name_(entryName),
entry_(Function1<Type>::New(name, dict)) entry_(Function1<Type>::New(entryName, dict))
{ {
entry_->convertTimeBase(t); entry_->convertTimeBase(runTime);
} }
template<class Type> 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), time_(runTime),
name_(name), name_(entryName),
entry_(nullptr) entry_(nullptr)
{} {}
@ -57,24 +62,12 @@ Foam::TimeFunction1<Type>::TimeFunction1(const Time& t, const word& name)
template<class Type> template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1 Foam::TimeFunction1<Type>::TimeFunction1
( (
const TimeFunction1<Type>& tde const TimeFunction1<Type>& rhs
) )
: :
time_(tde.time_), time_(rhs.time_),
name_(tde.name_), name_(rhs.name_),
entry_() entry_(rhs.entry_) // steal/reuse (missing clone!)
{
if (tde.entry_.valid())
{
entry_.reset(tde.entry_->clone().ptr());
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TimeFunction1<Type>::~TimeFunction1()
{} {}
@ -83,15 +76,7 @@ Foam::TimeFunction1<Type>::~TimeFunction1()
template<class Type> template<class Type>
void Foam::TimeFunction1<Type>::reset(const dictionary& dict) void Foam::TimeFunction1<Type>::reset(const dictionary& dict)
{ {
entry_.reset entry_ = Function1<Type>::New(name_, dict);
(
Function1<Type>::New
(
name_,
dict
).ptr()
);
entry_->convertTimeBase(time_); entry_->convertTimeBase(time_);
} }
@ -127,10 +112,14 @@ template<class Type>
Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<<
( (
Ostream& os, 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,15 +46,12 @@ SourceFiles
namespace Foam namespace Foam
{ {
template<class Type>
class TimeFunction1; // Forward Declarations
template<class Type> class TimeFunction1;
template<class Type> template<class Type>
Ostream& operator<< Ostream& operator<<(Ostream&, const TimeFunction1<Type>&);
(
Ostream&,
const TimeFunction1<Type>&
);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class TimeFunction1 Declaration Class TimeFunction1 Declaration
@ -62,10 +60,9 @@ Ostream& operator<<
template<class Type> template<class Type>
class TimeFunction1 class TimeFunction1
{ {
protected: protected:
// Protected data // Protected Data
//- Reference to the time database //- Reference to the time database
const Time& time_; const Time& time_;
@ -81,27 +78,27 @@ public:
// Constructor // Constructor
//- Construct from entry name //- Construct from entry name and dictionary
TimeFunction1 TimeFunction1
( (
const Time& t, const Time& runTime,
const word& name, const word& name,
const dictionary& dict const dictionary& dict
); );
//- Construct null from entry name //- Construct from entry name
TimeFunction1 TimeFunction1
( (
const Time& t, const Time& runTime,
const word& entryName const word& entryName
); );
//- Copy constructor //- Copy construct
TimeFunction1(const TimeFunction1<Type>& tde); TimeFunction1(const TimeFunction1<Type>& rhs);
//- Destructor //- Destructor
virtual ~TimeFunction1(); virtual ~TimeFunction1() = default;
// Member Functions // Member Functions