mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
132
src/OpenFOAM/primitives/functions/Function1/None/NoneFunction1.H
Normal file
132
src/OpenFOAM/primitives/functions/Function1/None/NoneFunction1.H
Normal file
@ -0,0 +1,132 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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);
|
||||
|
||||
Reference in New Issue
Block a user