Commit 3b6eb380 authored by Henry Weller's avatar Henry Weller Committed by Andrew Heather
Browse files

Function1: Optimized field evaluations

parent 2f431ffd
......@@ -89,7 +89,7 @@ primitives/septernion/septernion.C
primitives/triad/triad.C
/* Run-time selectable functions */
primitives/functions/Function1/makeDataEntries.C
primitives/functions/Function1/makeFunction1s.C
primitives/functions/Function1/ramp/ramp.C
primitives/functions/Function1/linearRamp/linearRamp.C
primitives/functions/Function1/quadraticRamp/quadraticRamp.C
......
......@@ -127,12 +127,6 @@ public:
//- Copy constructor
CSV(const CSV<Type>& tbl);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new CSV<Type>(*this));
}
//- Destructor
virtual ~CSV();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
......@@ -85,17 +85,20 @@ Foam::Function1Types::Constant<Type>::~Constant()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Function1Types::Constant<Type>::value(const scalar x) const
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::Constant<Type>::value
(
const scalarField& x
) const
{
return value_;
return tmp<Field<Type>>(new Field<Type>(x.size(), value_));
}
template<class Type>
Type Foam::Function1Types::Constant<Type>::integrate
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::Constant<Type>::integrate
(
const scalar x1,
const scalar x2
const scalarField& x1,
const scalarField& x2
) const
{
return (x2 - x1)*value_;
......
......@@ -106,16 +106,34 @@ public:
// Member Functions
//- Return constant value
Type value(const scalar) const;
virtual inline Type value(const scalar) const;
//- Integrate between two values
Type integrate(const scalar x1, const scalar x2) const;
virtual inline Type integrate(const scalar x1, const scalar x2) const;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalarField& x) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& x2
) const;
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
};
template<>
tmp<Field<label>> Function1Types::Constant<label>::integrate
(
const scalarField& x1,
const scalarField& x2
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1Types
......@@ -123,6 +141,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ConstantI.H"
#ifdef NoRepository
#include "Constant.C"
#include "Function1New.C"
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "Constant.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function1Types::Constant<Type>::value(const scalar x) const
{
return value_;
}
template<class Type>
inline Type Foam::Function1Types::Constant<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
return (x2 - x1)*value_;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -82,8 +82,9 @@ Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::value
(
const scalarField& x
) const
......@@ -93,14 +94,37 @@ Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
forAll(x, i)
{
fld[i] = this->value(x[i]);
fld[i] = Function1Type::value(x[i]);
}
return tfld;
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
template<class Function1Type>
Foam::FieldFunction1<Function1Type>::FieldFunction1
(
const word& entryName,
const dictionary& dict
)
:
Function1Type(entryName, dict)
{}
template<class Function1Type>
Foam::tmp<Foam::Function1<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::clone() const
{
return tmp<Function1<Type>>
(
new FieldFunction1<Function1Type>(*this)
);
}
template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::integrate
(
const scalarField& x1,
const scalarField& x2
......@@ -111,8 +135,9 @@ Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
forAll(x1, i)
{
fld[i] = this->integrate(x1[i], x2[i]);
fld[i] = Function1Type::integrate(x1[i], x2[i]);
}
return tfld;
}
......
......@@ -55,7 +55,7 @@ template<class Type> class Function1;
template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
/*---------------------------------------------------------------------------*\
Class Function1 Declaration
Class Function1 Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
......@@ -79,6 +79,8 @@ protected:
public:
typedef Type returnType;
//- Runtime type information
TypeName("Function1")
......@@ -96,13 +98,13 @@ public:
);
// Constructor
// Constructors
//- Construct from entry name
Function1(const word& entryName);
//- Copy constructor
Function1(const Function1<Type>& de);
Function1(const Function1<Type>& f1);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const = 0;
......@@ -140,7 +142,7 @@ public:
virtual Type value(const scalar x) const;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalarField& x) const;
virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
......@@ -150,7 +152,7 @@ public:
(
const scalarField& x1,
const scalarField& x2
) const;
) const = 0;
// I/O
......@@ -167,6 +169,54 @@ public:
};
/*---------------------------------------------------------------------------*\
Class FieldFunction1 Declaration
\*---------------------------------------------------------------------------*/
template<class Function1Type>
class FieldFunction1
:
public Function1Type
{
public:
typedef typename Function1Type::returnType Type;
// Constructors
//- Construct from entry name and dictionary
FieldFunction1(const word& entryName, const dictionary& dict);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const;
//- Destructor
virtual ~FieldFunction1()
{}
// Member Functions
// Evaluation
using Function1Type::value;
using Function1Type::integrate;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalarField& x) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& x2
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......@@ -188,7 +238,8 @@ public:
\
defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
\
Function1<Type>::adddictionaryConstructorToTable<Function1Types::SS<Type>> \
Function1<Type>::adddictionaryConstructorToTable \
<FieldFunction1<Function1Types::SS<Type>>> \
add##SS##Type##ConstructorToTable_;
......@@ -196,7 +247,7 @@ public:
\
defineTypeNameAndDebug(SS, 0); \
\
Function1<scalar>::adddictionaryConstructorToTable<SS> \
Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
add##SS##ConstructorToTable_;
......
......@@ -55,17 +55,20 @@ Foam::Function1Types::OneConstant<Type>::~OneConstant()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Function1Types::OneConstant<Type>::value(const scalar x) const
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::OneConstant<Type>::value
(
const scalarField& x
) const
{
return pTraits<Type>::one;
return tmp<Field<Type>>(new Field<Type>(x.size(), pTraits<Type>::one));
}
template<class Type>
Type Foam::Function1Types::OneConstant<Type>::integrate
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::OneConstant<Type>::integrate
(
const scalar x1,
const scalar x2
const scalarField& x1,
const scalarField& x2
) const
{
return (x2 - x1)*pTraits<Type>::one;
......
......@@ -92,10 +92,20 @@ public:
// Member Functions
//- Return constant value
Type value(const scalar) const;
virtual inline Type value(const scalar) const;
//- Integrate between two values
Type integrate(const scalar x1, const scalar x2) const;
virtual inline Type integrate(const scalar x1, const scalar x2) const;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalarField& x) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& x2
) const;
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
......@@ -109,6 +119,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "OneConstantI.H"
#ifdef NoRepository
#include "OneConstant.C"
#endif
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "OneConstant.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function1Types::OneConstant<Type>::value(const scalar x) const
{
return pTraits<Type>::one;
}
template<class Type>
inline Type Foam::Function1Types::OneConstant<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
return (x2 - x1)*pTraits<Type>::one;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -100,12 +100,6 @@ public:
//- Copy constructor
Polynomial(const Polynomial& poly);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Polynomial(*this));
}
//- Destructor
virtual ~Polynomial();
......@@ -122,10 +116,10 @@ public:
// Evaluation
//- Return Polynomial value
Type value(const scalar x) const;
virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values
Type integrate(const scalar x1, const scalar x2) const;
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Write in dictionary format
......
......@@ -66,13 +66,6 @@ Foam::Function1Types::Scale<Type>::~Scale()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Function1Types::Scale<Type>::value(const scalar t) const
{
return scale_->value(t)*value_->value(t);
}
template<class Type>
void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const
{
......
......@@ -126,12 +126,6 @@ public:
//- Copy constructor
Scale(const Scale<Type>& se);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Scale<Type>(*this));
}
//- Destructor
virtual ~Scale();
......@@ -140,7 +134,7 @@ public:
// Member Functions
//- Return value for time t
Type value(const scalar t) const;
virtual inline Type value(const scalar t) const;
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
......@@ -154,6 +148,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ScaleI.H"
#ifdef NoRepository
#include "Scale.C"
#endif
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "Scale.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function1Types::Scale<Type>::value(const scalar t) const
{
return scale_->value(t)*value_->value(t);
}
// ************************************************************************* //
......@@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "Sine.H"
#include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -73,17 +72,6 @@ Foam::Function1Types::Sine<Type>::~Sine()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //