diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 641773d3b655dc2dff6a76ece497d95a3ebff0e2..10b7ac0c9e878e0b9b93e31bc076a511c4c339e8 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C index 9807de87076ea32942c89a1dbdea93d3e1457b03..266008530c813c26ab2e2a197cee9353ada7cf5b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.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; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H index a7d0011acbef488ad792415f0bc51c9a59ce33b8..46f286ec77fb5679bbd9e30dd99ff041b714b8a0 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H @@ -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; diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C index 3410881bcf19fe757f83cc9319971a0af77d2ec2..4c121a5249a9f1436a8cfe25c0766e16e030d28f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C @@ -47,13 +47,6 @@ Foam::Function1Types::OneConstant<Type>::OneConstant {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template<class Type> -Foam::Function1Types::OneConstant<Type>::~OneConstant() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Type> diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H index 8a9a5df33ba3d4a566bcae6ae253bd743361651a..f883624b4196b4a4da9b637c1972600bdf66c9fc 100644 --- a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C index b7f5b45e644ec462495626373f357487c9c0b3dd..c82b62c628eb73931e6798f6e8303a2b8706fa52 100644 --- a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C +++ b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C @@ -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> diff --git a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H index c6091b9eebf7299b0d7597b423baf2de204e37e2..06d778c0c6cadbeaa964399368c59cf3789f7434 100644 --- a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H +++ b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C index 40dbf59bc864658a01447a9e8a77169d9e279871..a5d71d884a30f39a9eccfc205075e6a803bf89a8 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C @@ -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()) {} diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H index 87f5415657209bf25c0dbf5d578fcdff3efc9303..22efae6afd260ea9c6f727577556e49c3f98214a 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index c9b1636971051cd78696a01368d8167695ea47bf..97c0ce91deabe8c39ee5f84fa3530fcd04d49f25 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C @@ -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> diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H index 5d96ef2f8e4add137b4f06b961c56f6fff5e5972..200f9dc19db50d7343e73784b1756e384d5c863a 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H @@ -142,7 +142,7 @@ public: //- Destructor - virtual ~Sine(); + virtual ~Sine() = default; // Member Functions diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index 033070d308006fa05d69c19df2ee4a71e7267f09..93715bdfe6f563f08ca083939c0a17c652a6c140 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C @@ -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> diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.H b/src/OpenFOAM/primitives/functions/Function1/Square/Square.H index 7c9c5a80b04fc19ecdecefd90cf894c789154145..08bc6984f97bbf87fe79dcc9b679316c736fa70d 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.H +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/Table.C b/src/OpenFOAM/primitives/functions/Function1/Table/Table.C index 1ba0c5a84c64c4dfb971aab5be2e4b9977f9a88f..8e83d8e9040f76ca8e00d9be63fdcf6be2dd9d07 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/Table.C +++ b/src/OpenFOAM/primitives/functions/Function1/Table/Table.C @@ -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(); } diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C index b8c0fcffe3fc31c659519f1556d07077222370b0..c0ea5e76686f58f79b4cb7fe184bedd4cab6ab96 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C @@ -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!) {} diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H index 7746e9f8ce82b3cf22ea3b1f972713e4a0744b06..ce324b91d2895d528d2eaf3231dbcde48ed51ef5 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H @@ -46,6 +46,7 @@ SourceFiles namespace Foam { +// Forward Declarations class interpolationWeights; namespace Function1Types diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C index f22686d13b6961e1e1e8c45ac3420b479e16aec6..6695e9fb4a5e2d70ef1710e9c9412f950a01379b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C @@ -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_; diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H index 9842345eb59b69836c945fbdfbb2a6eab38fded7..2d7fb5427738a415e0519456db9b3a2d068d7b89 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H @@ -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; diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C index bc61614c55e82cd27dd05a4521b196acbfd682c5..d043ad133884f061539d22265ee42c2fb2c968ef 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C @@ -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> diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H index d8730dd5fea8eb787e19c16c393303be8c8d4822..88c79e1e4c419e0867dbc54ba04c2c0fa4cd0777 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C b/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C index 181d62610ff7a540612fea2e20caa88b5f00021d..c41dee31559cb82bd16dbdd7db7ad1aa5b245b68 100644 --- a/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C @@ -50,10 +50,4 @@ Foam::Function1Types::halfCosineRamp::halfCosineRamp {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Function1Types::halfCosineRamp::~halfCosineRamp() -{} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.H b/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.H index 1112cddd67e4553e6302a808f95bffb5385140bb..7c1a0332674d78275d485f356ef64fada2a2c534 100644 --- a/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/halfCosineRamp/halfCosineRamp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.C b/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.C index 1fe000ec1ad827ca323d141e6434e4f33b260455..de2aca2812fa0cbdef1b22e144a888a9bc433eb2 100644 --- a/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.C @@ -50,10 +50,4 @@ Foam::Function1Types::linearRamp::linearRamp {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Function1Types::linearRamp::~linearRamp() -{} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.H b/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.H index add757786d331f01c26aa32d623bb0af8b1caa87..52f2f4d73fe380c6d4c94db3b17433697e30a44e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/linearRamp/linearRamp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.C b/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.C index 7304cd3856cf4f935d45ddd90734b609b0aa9381..ad1ba81e5226fff7a7a7feac2997eda2578e82c1 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.C @@ -50,10 +50,4 @@ Foam::Function1Types::quadraticRamp::quadraticRamp {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Function1Types::quadraticRamp::~quadraticRamp() -{} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.H b/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.H index ec3e3746b6b0a946a66ab022a9ed5d13ba2fb6b3..5de2c76084024041c13c91e6bae1213fe4e1fe7d 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/quadraticRamp/quadraticRamp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C b/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C index 963aa88ffeb7016dc8a64c9427450eb2685ec6d1..c3b0b2085eedfdb4c743be5d0763aaea4683c967 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C @@ -50,10 +50,4 @@ Foam::Function1Types::quarterCosineRamp::quarterCosineRamp {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Function1Types::quarterCosineRamp::~quarterCosineRamp() -{} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.H b/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.H index 5b54c875ae58a6cf70db3bb02ac2d510c2fd1e0e..83950cc72c55b6414186b5eaec887d7c587e20df 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C b/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C index 0d6c6cfbe9b4669a98b91fc581a0768d16de9707..287c5dfd132a2ee890c1dbedbf5887dd8bfa554a 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C @@ -50,10 +50,4 @@ Foam::Function1Types::quarterSineRamp::quarterSineRamp {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Function1Types::quarterSineRamp::~quarterSineRamp() -{} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.H b/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.H index fe4fcaf02349079c374d0aadc5ca1faaa62b196c..88a41fe693d82f0086c2d92e89d195a9c84a29c7 100644 --- a/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/quarterSineRamp/quarterSineRamp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.C b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.C index d5c1be84139f199feee073ee855e646a296a1f2b..8b3999861c13cbe2bd3f57d4d7f886ae0c35e58d 100644 --- a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.C +++ b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.C @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H index 79ac093425269166c7d1328118b247bc6574e4cc..768caa21bfa3d28e8ab2ad6361f34fc860225c5b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H +++ b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.C b/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.C new file mode 100644 index 0000000000000000000000000000000000000000..4ab76010f4e0e756d11ef568055b2a17f4a0ad4d --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.C @@ -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) +{} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.H b/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.H new file mode 100644 index 0000000000000000000000000000000000000000..e4c7466f2344265ce159fe3355716e3e4dad2a69 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/step/stepFunction.H @@ -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 + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/step/stepFunctionI.H b/src/OpenFOAM/primitives/functions/Function1/step/stepFunctionI.H new file mode 100644 index 0000000000000000000000000000000000000000..c3016813892b12696cb01e724222b2c9bd6b12fe --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/step/stepFunctionI.H @@ -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; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H index 99c5c4faff99f8192e7b376a87499b04b3a771c8..2acea6d55c6846a470963c0544754a3e3095e0e7 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C b/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C index 0b76c6aec411b82434de164ec3a0d17bd5b2d064..2a75df9ec83764b1040f4eff0216fc5a21274e2e 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C +++ b/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C @@ -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); } diff --git a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C b/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C index 910e2e97e1cf07b59b95887d8801b9fbe433b87f..4054f9f3218a5ed479dff0d52d77c7ef46ac5cc8 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C +++ b/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C @@ -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; diff --git a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.H b/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.H index bff2598128cd09c72953d73ba48193550db45ccb..a4fcf8691c2aabb224b4ec24ecff3232a13bfb0a 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.H +++ b/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C index 26838c3951083d0fdc00bc9d585f93d1960ccceb..9dce633137647c3fc01ab5133d1d4097f385a4fd 100644 --- a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C +++ b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C @@ -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; } diff --git a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H index 87ba4cfbdfe006372e2b1942dd1c1f109031a1a7..49eec94b14e6a9f9d4a9497cfbd6f16dc3b7bf37 100644 --- a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H +++ b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H @@ -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