Commit f7c7fa94 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add Function1 constant() member

- marks if the value is considered to be independent of 'x'.
  Propagate into PatchFunction1 instead ad hoc checks there.

- adjust method name in PatchFunction1 to 'whichDb()' to reflect
  final changes in Function1 method names.

ENH: add a Function1 'none' placeholder function

- This is principally useful for interfaces that expect a Function1
  but where it is not necessarily used by a particular submodel.

TUT: update Function1 creation to use objectRegistry
parent b96cef13
......@@ -129,12 +129,6 @@ public:
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<${TemplateType}>> value(const scalar x) const;
//- Is value constant (i.e. independent of x)
virtual bool constant() const
{
return false;
}
//- Is value uniform (i.e. independent of coordinate)
virtual bool uniform() const
{
......
......@@ -117,7 +117,8 @@ void Foam::Function1Types::Constant<Type>::writeData(Ostream& os) const
{
Function1<Type>::writeData(os);
os << token::SPACE << value_ << token::END_STATEMENT << nl;
os << token::SPACE << value_;
os.endEntry();
}
......
......@@ -134,6 +134,9 @@ public:
//- Change the constant value
inline void reset(const Type& val);
//- Value is independent of x
virtual inline bool constant() const { return true; }
//- Return constant value
virtual inline Type value(const scalar) const;
......
......@@ -240,23 +240,30 @@ public:
// Member Functions
// Evaluation
//- Is value constant (i.e. independent of x)
virtual bool constant() const
{
return false;
}
//- Return value as a function of (scalar) independent variable
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;
// Evaluation
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& 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 Type integrate(const scalar x1, const scalar x2) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& x2
) const;
// I/O
......@@ -312,20 +319,18 @@ public:
// Member Functions
// Evaluation
using Function1Type::value;
using Function1Type::integrate;
using Function1Type::value;
using Function1Type::integrate;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalarField& x) 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;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(
const scalarField& x1,
const scalarField& x2
) const;
};
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 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 "NoneFunction1.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::None<Type>::None
(
const word& entryName,
const dictionary& dict,
const objectRegistry* obrPtr
)
:
Function1<Type>(entryName, dict, obrPtr),
context_(dict.relativeName())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Function1Types::None<Type>::value(const scalar) const
{
FatalErrorInFunction
<< "Function " << this->name() << " is 'none' in " << context_ << nl
<< exit(FatalError);
return pTraits<Type>::zero;
}
template<class Type>
Type Foam::Function1Types::None<Type>::integral
(
const scalar x1,
const scalar x2
)
const
{
FatalErrorInFunction
<< "Function " << this->name() << " is 'none' in " << context_ << nl
<< exit(FatalError);
return pTraits<Type>::zero;
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::None<Type>::value
(
const scalarField& x
) const
{
FatalErrorInFunction
<< "Function " << this->name() << " is 'none' in " << context_ << nl
<< exit(FatalError);
return nullptr;
}
template<class Type>
void Foam::Function1Types::None<Type>::writeData(Ostream& os) const
{
// OR: os.writeEntry(this->name(), this->type());
Function1<Type>::writeData(os);
os.endEntry();
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 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::None
Description
Templated placeholder function that returns an error message if called.
This is principally useful for interfaces that expect a Function1
but where it is not necessarily used by a particular submodel.
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_None_H
#define Function1Types_None_H
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1Types
{
/*---------------------------------------------------------------------------*\
Class None Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class None
:
public Function1<Type>
{
// Private Member Data
//- Context (eg, dictionary name) for the function
string context_;
public:
//- Runtime type information
TypeName("none");
// Generated Methods
//- Default copy constructor
None(const None<Type>& rhs) = default;
//- No copy assignment
void operator=(const None<Type>&) = delete;
// Constructors
//- Construct from entry name, dictionary and optional registry
None
(
const word& entryName,
const dictionary& dict,
const objectRegistry* obrPtr = nullptr
);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new None<Type>(*this));
}
//- Destructor
virtual ~None() = default;
// Member Functions
//- Value is independent of x
virtual inline bool constant() const { return true; }
//- Placeholder: generates an error if called
virtual Type value(const scalar x) const;
//- Placeholder: generates an error if called
virtual Type integral(const scalar x1, const scalar x2) const;
//- Placeholder: generates an error if called
virtual tmp<Field<Type>> value(const scalarField& x) const;
//- Write as primitive (inline) format
virtual void writeData(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1Types
} // End namespace Foam
#ifdef NoRepository
#include "NoneFunction1.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -103,6 +103,9 @@ public:
// Member Functions
//- Value is independent of x
virtual inline bool constant() const { return true; }
//- Return constant value
virtual inline Type value(const scalar) const;
......
......@@ -90,7 +90,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
}
else
{
// Dictionary format - "values" lookup. Eg,
// Dictionary format - "coeffs" lookup. Eg,
//
// key { type polynomial; coeffs ((0 0) (10 1)); }
......@@ -203,7 +203,8 @@ void Foam::Function1Types::Polynomial<Type>::writeData(Ostream& os) const
{
Function1<Type>::writeData(os);
os << nl << indent << coeffs_ << token::END_STATEMENT << nl;
os << nl << indent << coeffs_;
os.endEntry();
}
......
......@@ -369,7 +369,10 @@ template<class Type>
void Foam::Function1Types::TableBase<Type>::writeData(Ostream& os) const
{
Function1<Type>::writeData(os);
os << nl << indent << table_ << token::END_STATEMENT << nl;
os << nl << indent << table_;
os.endEntry();
writeEntries(os);
}
......
......@@ -106,6 +106,9 @@ public:
// Member Functions
//- Value is independent of x
virtual inline bool constant() const { return true; }
//- Return constant value
virtual inline Type value(const scalar) const;
......
......@@ -30,6 +30,7 @@ License
#include "Uniform.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "NoneFunction1.H"
#include "PolynomialEntry.H"
#include "Sine.H"
#include "Cosine.H"
......@@ -49,6 +50,7 @@ License
makeFunction1(Type); \
makeFunction1Type(Constant, Type); \
makeFunction1Type(Uniform, Type); \
makeFunction1Type(None, Type); \
makeFunction1Type(ZeroConstant, Type); \
makeFunction1Type(OneConstant, Type); \
makeFunction1Type(Polynomial, Type); \
......@@ -73,6 +75,7 @@ namespace Foam
{
makeFunction1(label);
makeFunction1Type(Constant, label);
makeFunction1Type(None, label);
makeFunction1Type(FunctionObjectTrigger, label);
makeFunction1Type(FunctionObjectTrigger, scalar);
......
......@@ -291,8 +291,8 @@ void Foam::PatchFunction1Types::ConstantField<Type>::writeData
if (isUniform_)
{
os.writeKeyword(this->name())
<< word("constant") << token::SPACE << uniformValue_
<< token::END_STATEMENT << nl;
<< word("constant") << token::SPACE << uniformValue_;
os.endEntry();
}
else
{
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -170,23 +170,24 @@ public:
// Member Functions
//- Value is independent of x
virtual inline bool constant() const
{
return true;
}
//- Is value uniform (i.e. independent of coordinate)
virtual inline bool uniform() const
{
return isUniform_ && PatchFunction1<Type>::uniform();
}
// Evaluation
//- Return constant value
virtual inline tmp<Field<Type>> value(const scalar x) const;
//- Is value constant (i.e. independent of x)
virtual inline bool constant() const
{
return true;
}
//- Is value uniform (i.e. independent of coordinate)
virtual inline bool uniform() const
{
return isUniform_ && PatchFunction1<Type>::uniform();
}
//- Integrate between two values
virtual inline tmp<Field<Type>> integrate
(
......
......@@ -64,8 +64,8 @@ SourceFiles
#define PatchFunction1Types_MappedFile_H
#include "PatchFunction1.H"
#include "pointToPointPlanarInterpolation.H"
#include "Function1.H"
#include "pointToPointPlanarInterpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -204,23 +204,24 @@ public:
// Member Functions
//- Value is independent of x if there is only a single sample time
virtual bool constant() const
{
return sampleTimes_.size() == 1;
}
//- Is value uniform (i.e. independent of coordinate)
virtual inline bool uniform() const
{
return PatchFunction1<Type>::uniform();
}
// Evaluation
//- Return MappedFile value
virtual tmp<Field<Type>> value(const scalar) const;
//- Is value constant (i.e. independent of x)
virtual bool constant() const
{
return sampleTimes_.size() == 1;
}
//- Is value uniform (i.e. independent of coordinate)
virtual bool uniform() const
{
return PatchFunction1<Type>::uniform();
}
//- Integrate between two values
virtual tmp<Field<Type>> integrate
(
......
......@@ -79,6 +79,13 @@ Foam::PatchFunction1<Type>::PatchFunction1
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::PatchFunction1<Type>::uniform() const
{
return !coordSys_.active();
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
(
......@@ -89,12 +96,6 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
return nullptr;
}
template<class Type>
bool Foam::PatchFunction1<Type>::uniform() const
{
return !coordSys_.active();
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::integrate
......
......@@ -90,7 +90,7 @@ protected:
// Protected Data
//- Optional local co-ordinate system and scaling
//- Optional local coordinate system and scaling
coordinateScaling<Type> coordSys_;
......
......@@ -84,7 +84,7 @@ Foam::patchFunction1Base::patchFunction1Base
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::objectRegistry* Foam::patchFunction1Base::obrPtr() const
const Foam::objectRegistry* Foam::patchFunction1Base::whichDb() const
{
return &(patch_.boundaryMesh().mesh()); // mesh registry
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -78,9 +78,6 @@ protected:
// Protected Member Functions
//- Return the object registry (ie, the mesh) as pointer
const objectRegistry* obrPtr() const;
//- No copy assignment
void operator=(const patchFunction1Base&) = delete;
......@@ -149,16 +146,14 @@ public:
return (faceValues_ ? patch_.size() : patch_.nPoints());
}
//- Has an associated objectRegistry (ie, from mesh)
/// bool hasDb() const noexcept
/// {
/// return true;
/// }