Commit 51c2329f authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: additional step function, cleanup autoPtr use in Function1

parent 09d9c5cc
......@@ -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
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -47,13 +47,6 @@ Foam::Function1Types::OneConstant<Type>::OneConstant
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::OneConstant<Type>::~OneConstant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
......
......@@ -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
......
......@@ -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>
......
......@@ -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
......
......@@ -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())
{}
......
......@@ -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
......
......@@ -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>
......
......@@ -142,7 +142,7 @@ public:
//- Destructor
virtual ~Sine();
virtual ~Sine() = default;
// Member Functions
......
......@@ -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>
......
......@@ -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
......
......@@ -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();
}
......
......@@ -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!)
{}
......
......@@ -46,6 +46,7 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class interpolationWeights;
namespace Function1Types
......
......@@ -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_;
......
......@@ -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;
......
......@@ -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>
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment