mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Function1 and PatchFunction1 improvements (#1917)
- easier support for non-mandatory functions. In some boundary conditions it can be desirable to support additional functions, but not necessarily require them. Make this easier to support with a Function1, PatchFunction1 NewIfPresent() selector. - support for compatibility lookups - harmonize branching logic and error handling between Function1 and PatchFunction1. ENH: refactor a base class for Function1, PatchFunction1 - includes base characteristics, patch or scalar information ENH: additional creation macros - makeConcreteFunction1, makeConcretePatchFunction1Type for adding a non-templated function into the correct templated selection table. makeScalarPatchFunction1 for similarity with makeScalarFunction1
This commit is contained in:
@ -250,13 +250,8 @@ const Foam::fileName& Foam::Function1Types::CSV<Type>::fName() const
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const
|
||||
void Foam::Function1Types::CSV<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
// Note: for TableBase write the dictionary entries it needs but not
|
||||
// the values themselves
|
||||
TableBase<Type>::writeEntries(os);
|
||||
@ -273,7 +268,17 @@ void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const
|
||||
os.writeEntry("separator", string(separator_));
|
||||
os.writeEntry("mergeSeparators", mergeSeparators_);
|
||||
os.writeEntry("file", fName_);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -154,6 +154,9 @@ public:
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -49,7 +49,7 @@ Foam::Function1Types::Constant<Type>::Constant
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName),
|
||||
Function1<Type>(entryName, dict),
|
||||
value_(Zero)
|
||||
{
|
||||
Istream& is = dict.lookup(entryName);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -61,24 +61,25 @@ class Constant
|
||||
:
|
||||
public Function1<Type>
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Constant value
|
||||
Type value_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Constant<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Runtime type information
|
||||
TypeName("constant");
|
||||
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Constant<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
|
||||
@ -36,32 +36,26 @@ License
|
||||
template<class Type>
|
||||
Foam::Function1<Type>::Function1(const word& entryName)
|
||||
:
|
||||
name_(entryName)
|
||||
function1Base(entryName)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1<Type>::Function1(const word& entryName, const dictionary& dict)
|
||||
:
|
||||
function1Base(entryName, dict)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1<Type>::Function1(const Function1<Type>& rhs)
|
||||
:
|
||||
refCount(),
|
||||
name_(rhs.name_)
|
||||
function1Base(rhs)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::word& Foam::Function1<Type>::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1<Type>::convertTimeBase(const Time&)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::Function1<Type>::value(const scalar x) const
|
||||
{
|
||||
@ -71,7 +65,8 @@ Type Foam::Function1<Type>::value(const scalar x) const
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::Function1<Type>::value
|
||||
(
|
||||
const scalarField& x
|
||||
) const
|
||||
@ -90,7 +85,8 @@ Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::Function1<Type>::integrate
|
||||
(
|
||||
const scalarField& x1,
|
||||
const scalarField& x2
|
||||
@ -161,6 +157,11 @@ Foam::FieldFunction1<Function1Type>::integrate
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1<Type>::writeEntries(Ostream& os) const
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
@ -179,7 +180,7 @@ Foam::Ostream& Foam::operator<<
|
||||
{
|
||||
os.check(FUNCTION_NAME);
|
||||
|
||||
os << rhs.name_;
|
||||
os << rhs.name();
|
||||
rhs.writeData(os);
|
||||
|
||||
return os;
|
||||
|
||||
@ -74,7 +74,7 @@ SourceFiles
|
||||
#ifndef Function1_H
|
||||
#define Function1_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "function1Base.H"
|
||||
#include "Field.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -94,16 +94,23 @@ template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
|
||||
template<class Type>
|
||||
class Function1
|
||||
:
|
||||
public refCount
|
||||
public function1Base
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Selector, with alternative entry, fallback redirection, etc
|
||||
static autoPtr<Function1<Type>> New
|
||||
(
|
||||
const word& entryName, // Entry name for function
|
||||
const entry* eptr, // Eg, dict.findEntry(entryName)
|
||||
const dictionary& dict,
|
||||
const word& redirectType,
|
||||
const bool mandatory
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Name of entry
|
||||
const word name_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
@ -136,20 +143,52 @@ public:
|
||||
//- Construct from entry name
|
||||
explicit Function1(const word& entryName);
|
||||
|
||||
//- Copy constructor
|
||||
//- Construct from entry name and dictionary
|
||||
Function1(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy construct
|
||||
explicit Function1(const Function1<Type>& rhs);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<Function1<Type>> clone() const = 0;
|
||||
|
||||
|
||||
//- Selector
|
||||
static autoPtr<Function1<Type>> New
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& redirectType = word::null
|
||||
);
|
||||
// Selectors
|
||||
|
||||
//- Selector, with fallback redirection
|
||||
static autoPtr<Function1<Type>> New
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& redirectType,
|
||||
const bool mandatory = true
|
||||
);
|
||||
|
||||
//- Compatibility selector, with fallback redirection
|
||||
static autoPtr<Function1<Type>> NewCompat
|
||||
(
|
||||
const word& entryName,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
const dictionary& dict,
|
||||
const word& redirectType = word::null,
|
||||
const bool mandatory = true
|
||||
);
|
||||
|
||||
//- Selector, without fallback redirection
|
||||
static autoPtr<Function1<Type>> New
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const bool mandatory = true
|
||||
);
|
||||
|
||||
//- An optional selector
|
||||
static autoPtr<Function1<Type>> NewIfPresent
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& redirectType = word::null
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -158,18 +197,6 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the name of the entry
|
||||
const word& name() const;
|
||||
|
||||
|
||||
// Manipulation
|
||||
|
||||
//- Convert time
|
||||
virtual void convertTimeBase(const Time& t);
|
||||
|
||||
|
||||
// Evaluation
|
||||
|
||||
//- Return value as a function of (scalar) independent variable
|
||||
@ -189,17 +216,22 @@ public:
|
||||
) const;
|
||||
|
||||
|
||||
// I/O
|
||||
// I/O
|
||||
|
||||
//- Ostream Operator
|
||||
friend Ostream& operator<< <Type>
|
||||
(
|
||||
Ostream& os,
|
||||
const Function1<Type>& func
|
||||
);
|
||||
//- Ostream Operator
|
||||
friend Ostream& operator<< <Type>
|
||||
(
|
||||
Ostream& os,
|
||||
const Function1<Type>& func
|
||||
);
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write in dictionary format.
|
||||
// \note The base output is \em without an END_STATEMENT
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
@ -212,7 +244,6 @@ class FieldFunction1
|
||||
:
|
||||
public Function1Type
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename Function1Type::returnType Type;
|
||||
@ -256,6 +287,7 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Define Function1 run-time selection
|
||||
#define makeFunction1(Type) \
|
||||
\
|
||||
defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
|
||||
@ -267,6 +299,7 @@ public:
|
||||
);
|
||||
|
||||
|
||||
// Define (templated) Function1, add to (templated) run-time selection
|
||||
#define makeFunction1Type(SS, Type) \
|
||||
\
|
||||
defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
|
||||
@ -276,12 +309,20 @@ public:
|
||||
add##SS##Type##ConstructorToTable_;
|
||||
|
||||
|
||||
#define makeScalarFunction1(SS) \
|
||||
// Define a non-templated Function1 and add to (templated) run-time selection
|
||||
#define makeConcreteFunction1(SS, Type) \
|
||||
\
|
||||
defineTypeNameAndDebug(SS, 0); \
|
||||
\
|
||||
Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
|
||||
add##SS##ConstructorToTable_;
|
||||
Function1<Type>::adddictionaryConstructorToTable \
|
||||
<FieldFunction1<SS>> \
|
||||
add##SS##Type##ConstructorToTable_;
|
||||
|
||||
|
||||
// Define scalar Function1 and add to (templated) run-time selection
|
||||
#define makeScalarFunction1(SS) \
|
||||
\
|
||||
makeConcreteFunction1(SS, scalar);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -35,59 +35,43 @@ Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1<Type>::New
|
||||
(
|
||||
const word& entryName,
|
||||
const entry* eptr,
|
||||
const dictionary& dict,
|
||||
const word& redirectType
|
||||
const word& redirectType,
|
||||
const bool mandatory
|
||||
)
|
||||
{
|
||||
word modelType(redirectType);
|
||||
|
||||
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
||||
const dictionary* coeffs = (eptr ? eptr->dictPtr() : nullptr);
|
||||
|
||||
if (!eptr)
|
||||
if (coeffs)
|
||||
{
|
||||
if (modelType.empty())
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "No Function1 dictionary entry: "
|
||||
<< entryName << nl << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
else if (eptr->isDict())
|
||||
{
|
||||
const dictionary& coeffsDict = eptr->dict();
|
||||
// Dictionary entry
|
||||
|
||||
coeffsDict.readEntry
|
||||
coeffs->readEntry
|
||||
(
|
||||
"type",
|
||||
modelType,
|
||||
keyType::LITERAL,
|
||||
redirectType.empty() // mandatory when redirectType is empty
|
||||
modelType.empty() // "type" entry is mandatory if no 'redirect'
|
||||
);
|
||||
|
||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Unknown Function1 type "
|
||||
<< modelType << " for " << entryName
|
||||
<< "\n\nValid Function1 types :\n"
|
||||
<< dictionaryConstructorTablePtr_->sortedToc() << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return cstrIter()(entryName, coeffsDict);
|
||||
// Fallthrough
|
||||
}
|
||||
else
|
||||
else if (eptr)
|
||||
{
|
||||
// Primitive entry
|
||||
// - non-word : value for constant function
|
||||
// - word : the modelType
|
||||
|
||||
Istream& is = eptr->stream();
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
if (!firstToken.isWord())
|
||||
{
|
||||
// Backwards-compatibility for reading straight fields
|
||||
// A value
|
||||
is.putBack(firstToken);
|
||||
|
||||
const Type constValue = pTraits<Type>(is);
|
||||
@ -97,8 +81,40 @@ Foam::Function1<Type>::New
|
||||
new Function1Types::Constant<Type>(entryName, constValue)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
modelType = firstToken.wordToken();
|
||||
}
|
||||
|
||||
modelType = firstToken.wordToken();
|
||||
// Fallthrough
|
||||
}
|
||||
|
||||
|
||||
if (modelType.empty())
|
||||
{
|
||||
// Entry missing
|
||||
|
||||
if (mandatory)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Missing or invalid Function1 entry: "
|
||||
<< entryName << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
else if (!coeffs)
|
||||
{
|
||||
// Primitive entry. Coeffs dictionary is optional.
|
||||
// Use keyword() - not entryName - for compatibility lookup!
|
||||
|
||||
coeffs =
|
||||
&dict.optionalSubDict
|
||||
(
|
||||
eptr->keyword() + "Coeffs",
|
||||
keyType::LITERAL
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -114,12 +130,78 @@ Foam::Function1<Type>::New
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return cstrIter()
|
||||
return cstrIter()(entryName, *coeffs);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1<Type>::New
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& redirectType,
|
||||
const bool mandatory
|
||||
)
|
||||
{
|
||||
return Function1<Type>::New
|
||||
(
|
||||
entryName,
|
||||
dict.optionalSubDict(entryName + "Coeffs")
|
||||
dict.findEntry(entryName, keyType::LITERAL),
|
||||
dict,
|
||||
redirectType,
|
||||
mandatory
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1<Type>::NewCompat
|
||||
(
|
||||
const word& entryName,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
const dictionary& dict,
|
||||
const word& redirectType,
|
||||
const bool mandatory
|
||||
)
|
||||
{
|
||||
return Function1<Type>::New
|
||||
(
|
||||
entryName,
|
||||
dict.findCompat(entryName, compat, keyType::LITERAL),
|
||||
dict,
|
||||
redirectType,
|
||||
mandatory
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1<Type>::New
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const bool mandatory
|
||||
)
|
||||
{
|
||||
return Function1<Type>::New(entryName, dict, word::null, mandatory);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1<Type>::NewIfPresent
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& redirectType
|
||||
)
|
||||
{
|
||||
// mandatory = false
|
||||
return Function1<Type>::New(entryName, dict, redirectType, false);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "function1Base.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::function1Base::function1Base(const word& entryName)
|
||||
:
|
||||
refCount(),
|
||||
name_(entryName)
|
||||
{}
|
||||
|
||||
|
||||
Foam::function1Base::function1Base
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
refCount(),
|
||||
name_(entryName)
|
||||
{}
|
||||
|
||||
|
||||
Foam::function1Base::function1Base(const function1Base& rhs)
|
||||
:
|
||||
refCount(),
|
||||
name_(rhs.name_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::function1Base::convertTimeBase(const Time& t)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,121 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::function1Base
|
||||
|
||||
Description
|
||||
Top level data entry class for use in dictionaries. Provides a mechanism
|
||||
to specify a variable as a certain type, e.g. constant or time varying, and
|
||||
provide functions to return the (interpolated) value, and integral between
|
||||
limits.
|
||||
|
||||
Extends the Function1 class by adding autoMap and rMap functions
|
||||
|
||||
SourceFiles
|
||||
function1Base.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef function1Base_H
|
||||
#define function1Base_H
|
||||
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
class Time;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class function1Base Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class function1Base
|
||||
:
|
||||
public refCount
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Name of entry
|
||||
const word name_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const function1Base&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name
|
||||
explicit function1Base(const word& entryName);
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
function1Base(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy construct
|
||||
explicit function1Base(const function1Base& rhs);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~function1Base() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- The name of the entry
|
||||
const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
// Manipulation
|
||||
|
||||
//- Convert time
|
||||
virtual void convertTimeBase(const Time& t);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -43,7 +43,7 @@ Foam::Function1Types::OneConstant<Type>::OneConstant
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName)
|
||||
Function1<Type>(entryName, dict)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -61,18 +61,18 @@ class OneConstant
|
||||
:
|
||||
public Function1<Type>
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const OneConstant<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("one");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const OneConstant<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name
|
||||
|
||||
@ -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,7 +37,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName),
|
||||
Function1<Type>(entryName, dict),
|
||||
coeffs_(),
|
||||
canIntegrate_(true)
|
||||
{
|
||||
@ -48,8 +49,9 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
if (!coeffs_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Polynomial coefficients for entry " << this->name_
|
||||
<< " are invalid (empty)" << nl << exit(FatalError);
|
||||
<< "Invalid (empty) polynomial coefficients for "
|
||||
<< this->name() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
forAll(coeffs_, i)
|
||||
@ -66,7 +68,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
if (!canIntegrate_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Polynomial " << this->name_ << " cannot be integrated"
|
||||
<< "Polynomial " << this->name() << " cannot be integrated"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
@ -87,8 +89,9 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
if (!coeffs_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Polynomial coefficients for entry " << this->name_
|
||||
<< " are invalid (empty)" << nl << exit(FatalError);
|
||||
<< "Invalid (empty) polynomial coefficients for "
|
||||
<< this->name() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
forAll(coeffs_, i)
|
||||
@ -105,7 +108,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
if (!canIntegrate_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Polynomial " << this->name_ << " cannot be integrated"
|
||||
<< "Polynomial " << this->name() << " cannot be integrated"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -61,6 +62,14 @@ Foam::Function1Types::Scale<Type>::Scale(const Scale<Type>& rhs)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Scale<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
scale_->writeData(os);
|
||||
value_->writeData(os);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
@ -68,10 +77,7 @@ void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const
|
||||
os << token::END_STATEMENT << nl;
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
scale_->writeData(os);
|
||||
value_->writeData(os);
|
||||
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -106,9 +107,6 @@ class Scale
|
||||
//- Read the coefficients from the given dictionary
|
||||
void read(const dictionary& coeffs);
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Scale<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -116,6 +114,12 @@ public:
|
||||
TypeName("scale");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Scale<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
@ -140,6 +144,9 @@ public:
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ Foam::Function1Types::Sine<Type>::Sine
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName)
|
||||
Function1<Type>(entryName, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -68,6 +68,17 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Sine<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
os.writeEntry("t0", t0_);
|
||||
amplitude_->writeData(os);
|
||||
frequency_->writeData(os);
|
||||
scale_->writeData(os);
|
||||
level_->writeData(os);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
@ -75,13 +86,7 @@ void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
os.writeEntry("t0", t0_);
|
||||
amplitude_->writeData(os);
|
||||
frequency_->writeData(os);
|
||||
scale_->writeData(os);
|
||||
level_->writeData(os);
|
||||
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -118,16 +119,18 @@ class Sine
|
||||
//- Read the coefficients from the given dictionary
|
||||
void read(const dictionary& coeffs);
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Sine<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Runtime type information
|
||||
TypeName("sine");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Sine<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
@ -152,6 +155,9 @@ public:
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ Foam::Function1Types::Square<Type>::Square
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName)
|
||||
Function1<Type>(entryName, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -71,20 +71,25 @@ Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const
|
||||
void Foam::Function1Types::Square<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
os.writeEntry("t0", t0_);
|
||||
os.writeEntry("markSpace", markSpace_);
|
||||
amplitude_->writeData(os);
|
||||
frequency_->writeData(os);
|
||||
scale_->writeData(os);
|
||||
level_->writeData(os);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -125,9 +126,6 @@ class Square
|
||||
//- Read the coefficients from the given dictionary
|
||||
void read(const dictionary& coeffs);
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Square<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -135,6 +133,12 @@ public:
|
||||
TypeName("square");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Square<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
@ -159,6 +163,9 @@ public:
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -65,8 +65,7 @@ Foam::Function1Types::TableBase<Type>::TableBase
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(name),
|
||||
name_(name),
|
||||
Function1<Type>(name, dict),
|
||||
bounding_
|
||||
(
|
||||
bounds::repeatableBoundingNames.getOrDefault
|
||||
@ -91,7 +90,6 @@ template<class Type>
|
||||
Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
|
||||
:
|
||||
Function1<Type>(tbl),
|
||||
name_(tbl.name_),
|
||||
bounding_(tbl.bounding_),
|
||||
interpolationScheme_(tbl.interpolationScheme_),
|
||||
table_(tbl.table_),
|
||||
@ -115,7 +113,7 @@ void Foam::Function1Types::TableBase<Type>::check() const
|
||||
if (!table_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Table for entry " << this->name_ << " is invalid (empty)"
|
||||
<< "Table for entry " << this->name() << " is invalid (empty)"
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -65,9 +66,6 @@ protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Table name
|
||||
const word name_;
|
||||
|
||||
//- Handling for out-of-bound values
|
||||
const bounds::repeatableBounding bounding_;
|
||||
|
||||
|
||||
@ -59,9 +59,7 @@ SourceFiles
|
||||
#ifndef TableFile_H
|
||||
#define TableFile_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "TableBase.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ Foam::Function1Types::ZeroConstant<Type>::ZeroConstant
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(entryName)
|
||||
Function1<Type>(entryName, dict)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -61,18 +61,18 @@ class ZeroConstant
|
||||
:
|
||||
public Function1<Type>
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ZeroConstant<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("zero");
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ZeroConstant<Type>&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name
|
||||
|
||||
@ -29,7 +29,7 @@ Class
|
||||
|
||||
Description
|
||||
Quadratic ramp function starting from 0 and increasing quadratically
|
||||
to 1 from \c t_0 over the \c duration and remaining at 1 thereafter.
|
||||
to 1 from \c start over the \c duration and remaining at 1 thereafter.
|
||||
|
||||
See also
|
||||
Foam::Function1Types::ramp
|
||||
|
||||
@ -43,7 +43,7 @@ Foam::Function1Types::ramp::ramp
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<scalar>(entryName)
|
||||
Function1<scalar>(entryName, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -51,16 +51,20 @@ Foam::Function1Types::ramp::ramp
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::Function1Types::ramp::writeEntries(Ostream& os) const
|
||||
{
|
||||
os.writeEntry("start", start_);
|
||||
os.writeEntry("duration", duration_);
|
||||
}
|
||||
|
||||
|
||||
void Foam::Function1Types::ramp::writeData(Ostream& os) const
|
||||
{
|
||||
Function1<scalar>::writeData(os);
|
||||
os << token::END_STATEMENT << nl;
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
os.writeEntry("start", start_);
|
||||
os.writeEntry("duration", duration_);
|
||||
|
||||
writeEntries(os);
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -138,6 +138,9 @@ public:
|
||||
|
||||
//- Write in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write coefficient entries in dictionary format
|
||||
void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user