DimensionedFunction1: Function1 with dimensions

This can be used identically to a standard Function1. In addition, it
also permits specification of the dimensions. This allows the dimensions
to be checked. It also permits unit conversions. For example:

    <name>
    {
        type        table;

        // Dimensions
        xDimensions [CAD];  // Optional. Argument dimensions/units.
                            // Here, this specifies coordinates are in
                            // crank angle degrees (available if using
                            // engine time).
        dimensions  [mm];   // Optional. Value dimensions/units.
                            // Here, values are in mm.

        // Tablulated data
        values
        (
            (0 0)
            (60 12)         // <-- i.e., 12 mm at 60 degrees
            (180 20)
            (240 8)
            (360 0)
        );
        outOfBounds repeat;
    }

This replaces TimeFunction1, as it allows per-function control over
whether the function is considered to be one of real-time or user-time.
This commit is contained in:
Will Bainbridge
2023-07-27 15:48:23 +01:00
parent 3a52ee2ac5
commit bf044f5c47
89 changed files with 1514 additions and 1018 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -46,6 +46,7 @@ Foam::userTimes::engine::engine(const dictionary& controlDict)
rpm_("rpm", dimless/dimTime, 0) rpm_("rpm", dimless/dimTime, 0)
{ {
read(controlDict); read(controlDict);
addUnit(dimensionedScalar(unit(), dimTime, userTimeToTime(1)));
} }
@ -87,6 +88,7 @@ Foam::word Foam::userTimes::engine::unit() const
bool Foam::userTimes::engine::read(const dictionary& controlDict) bool Foam::userTimes::engine::read(const dictionary& controlDict)
{ {
rpm_.read(dict(controlDict)); rpm_.read(dict(controlDict));
addUnit(dimensionedScalar(unit(), dimTime, userTimeToTime(1)));
return true; return true;
} }

View File

@ -36,6 +36,7 @@ namespace Foam
// the controlDict subDict (v.s. a reference to the subDict for e.g. // the controlDict subDict (v.s. a reference to the subDict for e.g.
// dimensionedConstants) // dimensionedConstants)
dictionary* dimensionSystemsPtr_(nullptr); dictionary* dimensionSystemsPtr_(nullptr);
HashTable<dimensionedScalar>* addedUnitsPtr_(nullptr);
HashTable<dimensionedScalar>* unitSetPtr_(nullptr); HashTable<dimensionedScalar>* unitSetPtr_(nullptr);
dimensionSets* writeUnitSetPtr_(nullptr); dimensionSets* writeUnitSetPtr_(nullptr);
@ -74,6 +75,20 @@ Foam::dictionary& Foam::dimensionSystems()
} }
void Foam::addUnit(const dimensionedScalar& unit)
{
deleteDemandDrivenData(unitSetPtr_);
deleteDemandDrivenData(writeUnitSetPtr_);
if (!addedUnitsPtr_)
{
addedUnitsPtr_ = new HashTable<dimensionedScalar>();
}
addedUnitsPtr_->insert(unit.name(), unit);
}
const Foam::HashTable<Foam::dimensionedScalar>& Foam::unitSet() const Foam::HashTable<Foam::dimensionedScalar>& Foam::unitSet()
{ {
if (!unitSetPtr_) if (!unitSetPtr_)
@ -116,6 +131,14 @@ const Foam::HashTable<Foam::dimensionedScalar>& Foam::unitSet()
} }
} }
if (addedUnitsPtr_)
{
forAllConstIter(HashTable<dimensionedScalar>, *addedUnitsPtr_, iter)
{
unitSetPtr_->insert(iter.key(), iter());
}
}
const wordList writeUnitNames const wordList writeUnitNames
( (
unitDict.lookupOrDefault<wordList> unitDict.lookupOrDefault<wordList>

View File

@ -32,7 +32,6 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef dimensionSets_H #ifndef dimensionSets_H
#define dimensionSets_H #define dimensionSets_H
@ -132,6 +131,9 @@ public:
//- Top level dictionary //- Top level dictionary
dictionary& dimensionSystems(); dictionary& dimensionSystems();
//- Add a unit
void addUnit(const dimensionedScalar& unit);
//- Set of all dimensions //- Set of all dimensions
const HashTable<dimensionedScalar>& unitSet(); const HashTable<dimensionedScalar>& unitSet();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,27 +47,8 @@ Foam::Function1s::Constant<Type>::Constant
) )
: :
FieldFunction1<Type, Constant<Type>>(name), FieldFunction1<Type, Constant<Type>>(name),
value_(Zero) value_(dict.lookup<Type>("value"))
{ {}
if (name == "value" || !dict.found(name))
{
dict.lookup("value") >> value_;
}
else
{
Istream& is(dict.lookup(name));
word entryType(is);
if (is.eof())
{
dict.lookup("value") >> value_;
}
else
{
is >> value_;
}
}
}
template<class Type> template<class Type>

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,7 +62,7 @@ class Constant
// Private Data // Private Data
//- Constant value //- Constant value
Type value_; const Type value_;
public: public:
@ -106,6 +106,9 @@ public:
//- Integrate between two values //- Integrate between two values
virtual inline Type integral(const scalar x1, const scalar x2) const; virtual inline Type integral(const scalar x1, const scalar x2) const;
//- Is this function guaranteed to be constant?
virtual inline bool constant() const;
//- Write in dictionary format //- Write in dictionary format
virtual void write(Ostream& os) const; virtual void write(Ostream& os) const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -45,4 +45,11 @@ inline Type Foam::Function1s::Constant<Type>::integral
} }
template<class Type>
inline bool Foam::Function1s::Constant<Type>::constant() const
{
return true;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,213 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 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 "DimensionedFunction1.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::Dimensioned<Type>::read
(
const word& name,
const dictionary& dict
)
{
// Read units from the given stream
auto readUnits = []
(
Istream& is,
const word& prefix,
dimensionedScalar& units
)
{
units.name() =
prefix + (prefix.empty() ? 'u' : 'U') + "nits";
dimensionSet d(dimless);
d.read(is, units.value());
if (d != units.dimensions())
{
FatalIOErrorInFunction(is)
<< "The " << prefix << (prefix.empty() ? "" : "-")
<< "dimensions " << d << " provided do not match the required "
<< "dimensions " << units.dimensions()
<< exit(FatalIOError);
}
};
// Read units if present in the given dictionary
auto lookupUnitsIfPresent = [&readUnits]
(
const dictionary& dict,
const word& prefix,
dimensionedScalar& units
)
{
const word unitsKey =
prefix + (prefix.empty() ? 'u' : 'U') + "nits";
const word dimsKey =
prefix + (prefix.empty() ? 'd' : 'D') + "imensions";
const bool haveUnits = dict.found(unitsKey);
const bool haveDims = dict.found(dimsKey);
if (haveUnits && haveDims)
{
FatalIOErrorInFunction(dict)
<< "Both " << unitsKey << " and " << dimsKey
<< " are specified. Only one is permitted."
<< exit(FatalError);
}
if (haveUnits)
{
units = dimensionedScalar(unitsKey, units.dimensions(), dict);
}
if (haveDims)
{
readUnits(dict.lookup(dimsKey), prefix, units);
}
};
// If the function is a dictionary (preferred) then read straightforwardly
if (dict.isDict(name))
{
const dictionary& coeffsDict(dict.subDict(name));
lookupUnitsIfPresent(coeffsDict, "x", xUnits_);
lookupUnitsIfPresent(coeffsDict, "", units_);
value_.reset(Function1<Type>::New(name, dict).ptr());
return;
}
// Find the entry
Istream& is(dict.lookup(name));
// Peek at the first token
token firstToken(is);
is.putBack(firstToken);
// Read the type, or assume constant
const word Function1Type =
firstToken.isWord() ? word(is) : Constant<Type>::typeName;
// If the entry is not a type followed by a end statement then
// construct the function from the stream
if (!firstToken.isWord() || !is.eof())
{
// Peek at the next token
token nextToken(is);
is.putBack(nextToken);
// Read dimensions if they are provided
if (nextToken == token::BEGIN_SQR)
{
readUnits(is, "", units_);
}
// Construct from a stream
value_.reset(Function1<Type>::New(name, Function1Type, is).ptr());
return;
}
// Otherwise, construct from the current or coeffs dictionary
const dictionary& coeffsDict =
dict.optionalSubDict(name + "Coeffs");
lookupUnitsIfPresent(coeffsDict, "x", xUnits_);
lookupUnitsIfPresent(coeffsDict, "", units_);
value_.reset(Function1<Type>::New(name, dict).ptr());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::Dimensioned<Type>::Dimensioned
(
const word& name,
const dimensionSet& xDimensions,
const dimensionSet& dimensions,
const dictionary& dict
)
:
FieldFunction1<Type, Dimensioned<Type>>(name),
xUnits_(word::null, xDimensions, scalar(1)),
units_(word::null, dimensions, scalar(1)),
value_(nullptr)
{
read(name, dict);
}
template<class Type>
Foam::Function1s::Dimensioned<Type>::Dimensioned(const Dimensioned<Type>& df1)
:
FieldFunction1<Type, Dimensioned<Type>>(df1),
xUnits_(df1.xUnits_),
units_(df1.units_),
value_(df1.value_, false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::Dimensioned<Type>::~Dimensioned()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::Dimensioned<Type>::write(Ostream& os) const
{
if (xUnits_.name() != word::null)
{
writeKeyword(os, xUnits_.name());
writeEntry(os, xUnits_.dimensions());
os << token::SPACE;
writeEntry(os, xUnits_.value());
os << token::END_STATEMENT << endl;
}
if (units_.name() != word::null)
{
writeKeyword(os, units_.name());
writeEntry(os, units_.dimensions());
os << token::SPACE;
writeEntry(os, units_.value());
os << token::END_STATEMENT << endl;
}
value_().write(os);
}
// ************************************************************************* //

View File

@ -0,0 +1,193 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 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/>.
Class
Foam::Function1s::Dimensioned
Description
Function1 with dimensions.
The dimensions are specified in the constructing code, in much the same way
as for a dimensioned constant, except that both argument (x) and value
dimensions must be specified.
This can be used identically to a standard Function1. In addition, it also
permits specification of the dimensions. This allows the dimensions to be
checked. It also permits unit conversions.
Usage
<name>
{
type table;
// Dimensions
xDimensions [CAD]; // Optional. Argument dimensions/units.
// Here, this specifies coordinates are in
// crank angle degrees (available if using
// engine time).
dimensions [mm]; // Optional. Value dimensions/units.
// Here, values are in mm.
// Tabulated data
values
(
(0 0)
(60 12) // <-- i.e., 12 mm at 60 degrees
(180 20)
(240 8)
(360 0)
);
outOfBounds repeat;
}
SourceFiles
DimensionedFunction1.C
DimensionedFunction1I.H
\*---------------------------------------------------------------------------*/
#ifndef DimensionedFunction1_H
#define DimensionedFunction1_H
#include "Function1.H"
#include "dimensionedType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1s
{
/*---------------------------------------------------------------------------*\
Class Dimensioned Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Dimensioned
:
public FieldFunction1<Type, Dimensioned<Type>>
{
// Private Data
//- Argument dimensions
dimensionedScalar xUnits_;
//- Value dimensions
dimensionedScalar units_;
//- Value function
autoPtr<Function1<Type>> value_;
// Private Member Functions
//- Read the coefficients from the given dictionary. Note that this is
// the outer dictionary, not the coefficients dictionary, as is the
// case for most/all other Function1-s.
void read(const word& name, const dictionary& dict);
public:
// Runtime type information
virtual const word& type() const
{
return value_->type();
}
// Constructors
//- Construct from name and dictionary. Note that this is the outer
// dictionary, not the coefficients dictionary, as is the case for
// most/all other Function1-s.
Dimensioned
(
const word& name,
const dimensionSet& xDimensions,
const dimensionSet& dimensions,
const dictionary& dict
);
//- Copy constructor
Dimensioned(const Dimensioned<Type>& se);
//- Destructor
virtual ~Dimensioned();
// Member Functions
//- Return a value
virtual inline Type value(const scalar x) const;
//- Integrate between two values
virtual inline Type integral(const scalar x1, const scalar x2) const;
//- Return a dimensioned value
virtual inline dimensioned<Type> value
(
const dimensionedScalar& x
) const;
//- Integrate between two dimensioned values
virtual inline dimensioned<Type> integral
(
const dimensionedScalar& x1,
const dimensionedScalar& x2
) const;
//- Is this function guaranteed to be constant?
virtual inline bool constant() const;
//- Write data to dictionary stream
virtual void write(Ostream& os) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const Dimensioned<Type>&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DimensionedFunction1I.H"
#ifdef NoRepository
#include "DimensionedFunction1.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 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 "DimensionedFunction1.H"
#include "dimensionedType.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function1s::Dimensioned<Type>::value(const scalar x) const
{
return
value_->value(x/xUnits_.value())
*units_.value();
}
template<class Type>
inline Type Foam::Function1s::Dimensioned<Type>::integral
(
const scalar x1,
const scalar x2
) const
{
return
value_->integral(x1/xUnits_.value(), x2/xUnits_.value())
*xUnits_.value()*units_.value();
}
template<class Type>
inline Foam::dimensioned<Type> Foam::Function1s::Dimensioned<Type>::value
(
const dimensionedScalar& x
) const
{
x.dimensions() = xUnits_.dimensions();
return
dimensioned<Type>
(
units_.dimensions(),
value(x.value())
);
}
template<class Type>
inline Foam::dimensioned<Type> Foam::Function1s::Dimensioned<Type>::integral
(
const dimensionedScalar& x1,
const dimensionedScalar& x2
) const
{
x1.dimensions() = xUnits_.dimensions();
x2.dimensions() = xUnits_.dimensions();
return
dimensioned<Type>
(
units_.dimensions()*xUnits_.dimensions(),
integral(x1.value(), x2.value())
);
}
template<class Type>
inline bool Foam::Function1s::Dimensioned<Type>::constant() const
{
return value_->constant();
}
// ************************************************************************* //

View File

@ -36,10 +36,10 @@ Foam::Function1<Type>::Function1(const word& name)
template<class Type> template<class Type>
Foam::Function1<Type>::Function1(const Function1<Type>& de) Foam::Function1<Type>::Function1(const Function1<Type>& f1)
: :
tmp<Function1<Type>>::refCount(), tmp<Function1<Type>>::refCount(),
name_(de.name_) name_(f1.name_)
{} {}
@ -85,6 +85,13 @@ const Foam::word& Foam::Function1<Type>::name() const
} }
template<class Type>
bool Foam::Function1<Type>::constant() const
{
return false;
}
template<class Type, class Function1Type> template<class Type, class Function1Type>
Foam::tmp<Foam::Field<Type>> Foam::FieldFunction1<Type, Function1Type>::value Foam::tmp<Foam::Field<Type>> Foam::FieldFunction1<Type, Function1Type>::value
( (

View File

@ -66,7 +66,7 @@ class Function1
protected: protected:
// Protected data // Protected Data
//- Name of entry //- Name of entry
const word name_; const word name_;
@ -76,10 +76,13 @@ public:
typedef Type returnType; typedef Type returnType;
//- Runtime type information //- Runtime type information
TypeName("Function1"); TypeName("Function1");
//- Declare runtime constructor selection table
// Declare runtime constructor selection tables
declareRunTimeSelectionTable declareRunTimeSelectionTable
( (
autoPtr, autoPtr,
@ -92,6 +95,18 @@ public:
(name, dict) (name, dict)
); );
declareRunTimeSelectionTable
(
autoPtr,
Function1,
Istream,
(
const word& name,
Istream& is
),
(name, is)
);
// Constructors // Constructors
@ -105,13 +120,23 @@ public:
virtual tmp<Function1<Type>> clone() const = 0; virtual tmp<Function1<Type>> clone() const = 0;
//- Selector // Selectors
//- Select from dictionary
static autoPtr<Function1<Type>> New static autoPtr<Function1<Type>> New
( (
const word& name, const word& name,
const dictionary& dict const dictionary& dict
); );
//- Select from Istream
static autoPtr<Function1<Type>> New
(
const word& name,
const word& Function1Type,
Istream& is
);
//- Destructor //- Destructor
virtual ~Function1(); virtual ~Function1();
@ -138,6 +163,9 @@ public:
const scalarField& x2 const scalarField& x2
) const = 0; ) const = 0;
//- Is this function guaranteed to be constant?
virtual bool constant() const;
//- Write data to dictionary stream //- Write data to dictionary stream
virtual void write(Ostream& os) const = 0; virtual void write(Ostream& os) const = 0;
@ -214,13 +242,14 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction1(Type) \ #define defineFunction1(Type) \
\ \
defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
defineTemplateRunTimeSelectionTable(Function1<Type>, dictionary); defineTemplateRunTimeSelectionTable(Function1<Type>, dictionary); \
defineTemplateRunTimeSelectionTable(Function1<Type>, Istream);
#define makeFunction1Type(SS, Type) \ #define addFunction1(SS, Type) \
\ \
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
typedef Function1<Type> Type##Function1; \ typedef Function1<Type> Type##Function1; \
@ -233,7 +262,18 @@ public:
) )
#define makeNamedFunction1Type(SS, Type, Name) \ #define addStreamConstructableFunction1(SS, Type) \
\
addFunction1(SS, Type); \
addToRunTimeSelectionTable \
( \
Type##Function1, \
Type##SS##Function1, \
Istream \
)
#define addNamedFunction1(SS, Type, Name) \
\ \
typedef Function1<Type> Type##Function1; \ typedef Function1<Type> Type##Function1; \
typedef SS<Type> Type##SS##Function1; \ typedef SS<Type> Type##SS##Function1; \
@ -246,42 +286,13 @@ public:
) )
#define makeScalarFunction1(SS) \ #define addScalarFunction1(SS) \
\ \
defineTypeNameAndDebug(SS, 0); \ defineTypeNameAndDebug(SS, 0); \
typedef Function1<scalar> scalarFunction1; \ typedef Function1<scalar> scalarFunction1; \
addToRunTimeSelectionTable(scalarFunction1, SS, dictionary) addToRunTimeSelectionTable(scalarFunction1, SS, dictionary)
#define makeFunction1s(Type, nullArg) \
\
template<> \
const char* const Foam::Tuple2<Foam::scalar, Type>::typeName \
( \
"Tuple2<scalar," #Type ">" \
); \
\
makeFunction1(Type); \
\
namespace Function1s \
{ \
makeFunction1Type(None, Type); \
makeFunction1Type(Constant, Type); \
makeFunction1Type(Uniform, Type); \
makeFunction1Type(ZeroConstant, Type); \
makeFunction1Type(OneConstant, Type); \
makeFunction1Type(Polynomial, Type); \
makeFunction1Type(Sine, Type); \
makeFunction1Type(Square, Type); \
makeFunction1Type(Table, Type); \
makeFunction1Type(UniformTable, Type); \
makeFunction1Type(NonUniformTable, Type); \
makeNamedFunction1Type(Table, Type, tableFile); \
makeFunction1Type(Scale, Type); \
makeFunction1Type(Coded, Type); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,7 +25,7 @@ License
#include "Constant.H" #include "Constant.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
@ -34,6 +34,7 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
const dictionary& dict const dictionary& dict
) )
{ {
// If the function is a dictionary (preferred) then read straightforwardly
if (dict.isDict(name)) if (dict.isDict(name))
{ {
const dictionary& coeffsDict(dict.subDict(name)); const dictionary& coeffsDict(dict.subDict(name));
@ -56,30 +57,30 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
return cstrIter()(name, coeffsDict); return cstrIter()(name, coeffsDict);
} }
else
{
Istream& is(dict.lookup(name, false));
// Find the entry
Istream& is(dict.lookup(name));
// Peek at the first token
token firstToken(is); token firstToken(is);
word Function1Type;
if (!firstToken.isWord())
{
is.putBack(firstToken); is.putBack(firstToken);
return autoPtr<Function1<Type>>
( // Read the type, or assume constant
new Function1s::Constant<Type>(name, is) const word Function1Type =
); firstToken.isWord() ? word(is) : Function1s::Constant<Type>::typeName;
}
else // If the entry is not a type followed by a end statement then
// construct the function from the stream
if (!firstToken.isWord() || !is.eof())
{ {
Function1Type = firstToken.wordToken(); return New(name, Function1Type, is);
} }
typename dictionaryConstructorTable::iterator cstrIter = // Otherwise, construct from the current or coeffs dictionary
typename dictionaryConstructorTable::iterator dictCstrIter =
dictionaryConstructorTablePtr_->find(Function1Type); dictionaryConstructorTablePtr_->find(Function1Type);
if (cstrIter == dictionaryConstructorTablePtr_->end()) if (dictCstrIter == dictionaryConstructorTablePtr_->end())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unknown Function1 type " << "Unknown Function1 type "
@ -90,18 +91,18 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
<< exit(FatalError); << exit(FatalError);
} }
const bool haveCoeffsDict = dict.found(name + "Coeffs");
autoPtr<Function1<Type>> funcPtr autoPtr<Function1<Type>> funcPtr
( (
cstrIter() dictCstrIter()
( (
name, name,
dict.found(name + "Coeffs") haveCoeffsDict ? dict.subDict(name + "Coeffs") : dict
? dict.subDict(name + "Coeffs")
: dict
) )
); );
if (dict.found(name + "Coeffs")) if (haveCoeffsDict)
{ {
IOWarningInFunction(dict) IOWarningInFunction(dict)
<< "Using deprecated " << "Using deprecated "
@ -111,7 +112,49 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
} }
return funcPtr; return funcPtr;
}
template<class Type>
Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
(
const word& name,
const word& Function1Type,
Istream& is
)
{
typename dictionaryConstructorTable::iterator dictCstrIter =
dictionaryConstructorTablePtr_->find(Function1Type);
const bool haveDictCstrIter =
dictCstrIter != dictionaryConstructorTablePtr_->end();
typename IstreamConstructorTable::iterator isCstrIter =
IstreamConstructorTablePtr_->find(Function1Type);
const bool haveIstreamCstrIter =
isCstrIter != IstreamConstructorTablePtr_->end();
if (!haveDictCstrIter && !haveIstreamCstrIter)
{
FatalErrorInFunction
<< "Unknown Function1 type "
<< Function1Type << " for Function1 "
<< name << nl << nl
<< "Valid Function1 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
} }
if (!haveIstreamCstrIter)
{
FatalErrorInFunction
<< "Function1 type "
<< Function1Type << " for Function1 "
<< name << " cannot be specified inline" << nl << nl
<< "Make " << name << " a sub-dictionary"
<< exit(FatalError);
}
return isCstrIter()(name, is);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -39,8 +39,10 @@ Foam::Function1s::NonUniformTable<Type>::NonUniformTable
high_(-great), high_(-great),
values_(), values_(),
delta_(great), delta_(great),
reader_(TableReader<Type>::New(name, dict, this->values_)) reader_(TableReader<Type>::New(name, dict))
{ {
values_ = reader_->read(dict);
if (values_.size() < 2) if (values_.size() < 2)
{ {
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -92,6 +92,7 @@ class NonUniformTable
//- Increment derived from low_, high_ and values_.size() //- Increment derived from low_, high_ and values_.size()
scalar delta_; scalar delta_;
//- The jump table
List<label> jumpTable_; List<label> jumpTable_;
//- Table reader //- Table reader

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,32 +31,13 @@ template<class Type>
Foam::Function1s::Polynomial<Type>::Polynomial Foam::Function1s::Polynomial<Type>::Polynomial
( (
const word& name, const word& name,
const dictionary& dict const List<Tuple2<Type, Type>>& coeffs
) )
: :
FieldFunction1<Type, Polynomial<Type>>(name), FieldFunction1<Type, Polynomial<Type>>(name),
coeffs_(), coeffs_(coeffs),
canIntegrate_(true) integrable_(true)
{ {
if (!dict.found(name))
{
dict.lookup("coeffs") >> coeffs_;
}
else
{
Istream& is(dict.lookup(name));
word entryType(is);
if (is.eof())
{
dict.lookup("coeffs") >> coeffs_;
}
else
{
is >> coeffs_;
}
}
if (!coeffs_.size()) if (!coeffs_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
@ -68,14 +49,14 @@ Foam::Function1s::Polynomial<Type>::Polynomial
{ {
if (mag(coeffs_[i].second() + pTraits<Type>::one) < rootVSmall) if (mag(coeffs_[i].second() + pTraits<Type>::one) < rootVSmall)
{ {
canIntegrate_ = false; integrable_ = false;
break; break;
} }
} }
if (debug) if (debug)
{ {
if (!canIntegrate_) if (!integrable_)
{ {
WarningInFunction WarningInFunction
<< "Polynomial " << this->name_ << " cannot be integrald" << "Polynomial " << this->name_ << " cannot be integrald"
@ -89,39 +70,22 @@ template<class Type>
Foam::Function1s::Polynomial<Type>::Polynomial Foam::Function1s::Polynomial<Type>::Polynomial
( (
const word& name, const word& name,
const List<Tuple2<Type, Type>>& coeffs const dictionary& dict
) )
: :
FieldFunction1<Type, Polynomial<Type>>(name), Polynomial<Type>(name, dict.lookup("coeffs"))
coeffs_(coeffs), {}
canIntegrate_(true)
{
if (!coeffs_.size())
{
FatalErrorInFunction
<< "Polynomial coefficients for entry " << this->name_
<< " are invalid (empty)" << nl << exit(FatalError);
}
forAll(coeffs_, i)
{
if (mag(coeffs_[i].second() + 1) < rootVSmall)
{
canIntegrate_ = false;
break;
}
}
if (debug) template<class Type>
{ Foam::Function1s::Polynomial<Type>::Polynomial
if (!canIntegrate_) (
{ const word& name,
WarningInFunction Istream& is
<< "Polynomial " << this->name_ << " cannot be integrald" )
<< endl; :
} Polynomial<Type>(name, List<Tuple2<Type, Type>>(is))
} {}
}
template<class Type> template<class Type>
@ -129,7 +93,7 @@ Foam::Function1s::Polynomial<Type>::Polynomial(const Polynomial& poly)
: :
FieldFunction1<Type, Polynomial<Type>>(poly), FieldFunction1<Type, Polynomial<Type>>(poly),
coeffs_(poly.coeffs_), coeffs_(poly.coeffs_),
canIntegrate_(poly.canIntegrate_) integrable_(poly.integrable_)
{} {}
@ -168,7 +132,7 @@ Type Foam::Function1s::Polynomial<Type>::integral
{ {
Type intx(Zero); Type intx(Zero);
if (canIntegrate_) if (integrable_)
{ {
forAll(coeffs_, i) forAll(coeffs_, i)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -70,8 +70,11 @@ class Polynomial
//- Polynomial coefficients - list of prefactor, exponent //- Polynomial coefficients - list of prefactor, exponent
List<Tuple2<Type, Type>> coeffs_; List<Tuple2<Type, Type>> coeffs_;
//- Flag to indicate whether poly can be integrald //- Flag to indicate whether the function can be integrated
bool canIntegrate_; bool integrable_;
// Private member functions
public: public:
@ -82,9 +85,6 @@ public:
// Constructors // Constructors
//- Construct from name and dictionary
Polynomial(const word& name, const dictionary& dict);
//- Construct from components //- Construct from components
Polynomial Polynomial
( (
@ -92,6 +92,12 @@ public:
const List<Tuple2<Type, Type>>& const List<Tuple2<Type, Type>>&
); );
//- Construct from name and dictionary
Polynomial(const word& name, const dictionary& dict);
//- Construct from name and Istream
Polynomial(const word& name, Istream& is);
//- Copy constructor //- Copy constructor
Polynomial(const Polynomial& poly); Polynomial(const Polynomial& poly);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -37,13 +37,8 @@ void Foam::Function1s::Scale<Type>::read(const dictionary& dict)
: autoPtr<Function1<scalar>>(new Constant<scalar>("xScale", 1)); : autoPtr<Function1<scalar>>(new Constant<scalar>("xScale", 1));
value_ = Function1<Type>::New("value", dict); value_ = Function1<Type>::New("value", dict);
integrableScale_ = integrableScale_ = xScale_->constant() && scale_->constant();
isA<Constant<scalar>>(xScale_()) integrableValue_ = xScale_->constant() && value_->constant();
&& isA<Constant<scalar>>(scale_());
integrableValue_ =
isA<Constant<scalar>>(xScale_())
&& isA<Constant<Type>>(value_());
} }
@ -62,16 +57,8 @@ Foam::Function1s::Scale<Type>::Scale
scale_(scale.clone().ptr()), scale_(scale.clone().ptr()),
xScale_(xScale.clone().ptr()), xScale_(xScale.clone().ptr()),
value_(value.clone().ptr()), value_(value.clone().ptr()),
integrableScale_ integrableScale_(xScale_->constant() && scale_->constant()),
( integrableValue_(xScale_->constant() && value_->constant())
isA<Constant<scalar>>(xScale_())
&& isA<Constant<scalar>>(scale_())
),
integrableValue_
(
isA<Constant<scalar>>(xScale_())
&& isA<Constant<Type>>(value_())
)
{} {}

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -202,6 +202,9 @@ public:
//- Integrate between two values //- Integrate between two values
virtual inline Type integral(const scalar x1, const scalar x2) const; virtual inline Type integral(const scalar x1, const scalar x2) const;
//- Is this function guaranteed to be constant?
virtual inline bool constant() const;
//- Write data to dictionary stream //- Write data to dictionary stream
virtual void write(Ostream& os) const; virtual void write(Ostream& os) const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -64,4 +64,11 @@ inline Type Foam::Function1s::Scale<Type>::integral
} }
template<class Type>
inline bool Foam::Function1s::Scale<Type>::constant() const
{
return value_->constant();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,9 +35,7 @@ void Foam::Function1s::Sine<Type>::read(const dictionary& dict)
start_ = dict.lookupOrDefault<scalar>("start", 0); start_ = dict.lookupOrDefault<scalar>("start", 0);
level_ = Function1<Type>::New("level", dict); level_ = Function1<Type>::New("level", dict);
integrable_ = integrable_ = amplitude_->constant() && level_->constant();
isA<Constant<Type>>(amplitude_())
&& isA<Constant<Type>>(level_());
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -36,9 +36,7 @@ void Foam::Function1s::Square<Type>::read(const dictionary& dict)
level_ = Function1<Type>::New("level", dict); level_ = Function1<Type>::New("level", dict);
markSpace_ = dict.lookupOrDefault<scalar>("markSpace", 1); markSpace_ = dict.lookupOrDefault<scalar>("markSpace", 1);
integrable_ = integrable_ = amplitude_->constant() && level_->constant();
isA<Constant<Type>>(amplitude_())
&& isA<Constant<Type>>(level_());
} }

View File

@ -145,8 +145,8 @@ Foam::Function1s::Table<Type>::Table
FieldFunction1<Type, Table<Type>>(name), FieldFunction1<Type, Table<Type>>(name),
boundsHandling_(boundsHandling), boundsHandling_(boundsHandling),
interpolationScheme_(interpolationScheme), interpolationScheme_(interpolationScheme),
values_(table), reader_(reader, false),
reader_(reader, false) values_(table)
{} {}
@ -172,8 +172,25 @@ Foam::Function1s::Table<Type>::Table
linearInterpolationWeights::typeName linearInterpolationWeights::typeName
) )
), ),
values_(), reader_(TableReader<Type>::New(name, dict)),
reader_(TableReader<Type>::New(name, dict, this->values_)) values_(reader_->read(dict))
{
check();
}
template<class Type>
Foam::Function1s::Table<Type>::Table
(
const word& name,
Istream& is
)
:
FieldFunction1<Type, Table<Type>>(name),
boundsHandling_(tableBase::boundsHandling::clamp),
interpolationScheme_(linearInterpolationWeights::typeName),
reader_(new TableReaders::Embedded<Type>()),
values_(is)
{ {
check(); check();
} }
@ -185,10 +202,10 @@ Foam::Function1s::Table<Type>::Table(const Table<Type>& tbl)
FieldFunction1<Type, Table<Type>>(tbl), FieldFunction1<Type, Table<Type>>(tbl),
boundsHandling_(tbl.boundsHandling_), boundsHandling_(tbl.boundsHandling_),
interpolationScheme_(tbl.interpolationScheme_), interpolationScheme_(tbl.interpolationScheme_),
reader_(tbl.reader_, false),
values_(tbl.values_), values_(tbl.values_),
tableSamplesPtr_(tbl.tableSamplesPtr_), tableSamplesPtr_(tbl.tableSamplesPtr_),
interpolatorPtr_(tbl.interpolatorPtr_), interpolatorPtr_(tbl.interpolatorPtr_)
reader_(tbl.reader_, false)
{} {}

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -129,8 +129,11 @@ class Table
//- Interpolation scheme //- Interpolation scheme
const word interpolationScheme_; const word interpolationScheme_;
//- Table reader
const autoPtr<TableReader<Type>> reader_;
//- Table data //- Table data
List<Tuple2<scalar, Type>> values_; const List<Tuple2<scalar, Type>> values_;
//- Extracted values //- Extracted values
mutable autoPtr<scalarField> tableSamplesPtr_; mutable autoPtr<scalarField> tableSamplesPtr_;
@ -144,9 +147,6 @@ class Table
//- Cached weights //- Cached weights
mutable scalarField weights_; mutable scalarField weights_;
//- Table reader
const autoPtr<TableReader<Type>> reader_;
// Private Member Functions // Private Member Functions
@ -183,6 +183,9 @@ public:
//- Construct from name and dictionary //- Construct from name and dictionary
Table(const word& name, const dictionary& dict); Table(const word& name, const dictionary& dict);
//- Construct from name and Istream
Table(const word& name, Istream& dict);
//- Copy constructor //- Copy constructor
Table(const Table<Type>& tbl); Table(const Table<Type>& tbl);
@ -205,12 +208,6 @@ public:
return interpolationScheme_; return interpolationScheme_;
} }
//- Return the reader
const autoPtr<TableReader<Type>>& reader() const
{
return reader_;
}
//- Return table data //- Return table data
const List<Tuple2<scalar, Type>>& values() const const List<Tuple2<scalar, Type>>& values() const
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -204,8 +204,7 @@ template<class Type>
Foam::TableReaders::Csv<Type>::Csv Foam::TableReaders::Csv<Type>::Csv
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
) )
: :
TableFileReader<Type>(dict), TableFileReader<Type>(dict),
@ -222,8 +221,6 @@ Foam::TableReaders::Csv<Type>::Csv
<< pTraits<Type>::nComponents << endl << pTraits<Type>::nComponents << endl
<< exit(FatalError); << exit(FatalError);
} }
TableFileReader<Type>::read(dict, table);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -102,13 +102,8 @@ public:
// Constructors // Constructors
//- Construct from dictionary //- Construct from name and dictionary
Csv Csv(const word& name, const dictionary& dict);
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy //- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const virtual autoPtr<TableReader<Type>> clone() const
@ -123,7 +118,7 @@ public:
// Member Functions // Member Functions
//- Write the CSV parameters //- Write settings and values
virtual void write virtual void write
( (
Ostream& os, Ostream& os,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,34 +27,22 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReaders::Embedded<Type>::Embedded()
:
TableReader<Type>()
{}
template<class Type> template<class Type>
Foam::TableReaders::Embedded<Type>::Embedded Foam::TableReaders::Embedded<Type>::Embedded
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
) )
: :
TableReader<Type>(dict) TableReader<Type>()
{ {}
if (!dict.found(name))
{
dict.lookup("values") >> table;
}
else
{
Istream& is(dict.lookup(name));
word entryType(is);
if (is.eof())
{
dict.lookup("values") >> table;
}
else
{
is >> table;
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -66,6 +54,14 @@ Foam::TableReaders::Embedded<Type>::~Embedded()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::List<Foam::Tuple2<Foam::scalar, Type>>
Foam::TableReaders::Embedded<Type>::read(const dictionary& dict) const
{
return dict.lookup<List<Tuple2<scalar, Type>>>("values");
}
template<class Type> template<class Type>
void Foam::TableReaders::Embedded<Type>::write void Foam::TableReaders::Embedded<Type>::write
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -74,13 +74,11 @@ public:
// Constructors // Constructors
//- Construct from dictionary //- Default construct
Embedded Embedded();
(
const word& name, //- Construct from name and dictionary
const dictionary &dict, Embedded(const word& name, const dictionary& dict);
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy //- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const virtual autoPtr<TableReader<Type>> clone() const
@ -95,7 +93,10 @@ public:
// Member Functions // Member Functions
//- Write the table values //- Read values
virtual List<Tuple2<scalar, Type>> read(const dictionary& dict) const;
//- Write settings and values
virtual void write virtual void write
( (
Ostream& os, Ostream& os,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -44,14 +44,11 @@ template<class Type>
Foam::TableReaders::Foam<Type>::Foam Foam::TableReaders::Foam<Type>::Foam
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
) )
: :
TableFileReader<Type>(dict) TableFileReader<Type>(dict)
{ {}
TableFileReader<Type>::read(dict, table);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -77,13 +77,8 @@ public:
// Constructors // Constructors
//- Construct from dictionary //- Construct from name and dictionary
Foam Foam(const word& name, const dictionary& dict);
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy //- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const virtual autoPtr<TableReader<Type>> clone() const

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -65,12 +65,9 @@ void Foam::TableFileReader<Type>::read
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::TableFileReader<Type>::TableFileReader Foam::TableFileReader<Type>::TableFileReader(const dictionary& dict)
(
const dictionary& dict
)
: :
TableReader<Type>(dict), TableReader<Type>(),
fName_(dict.lookup("file")) fName_(dict.lookup("file"))
{} {}
@ -84,6 +81,16 @@ Foam::TableFileReader<Type>::~TableFileReader()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::List<Foam::Tuple2<Foam::scalar, Type>>
Foam::TableFileReader<Type>::read(const dictionary& dict) const
{
List<Tuple2<scalar, Type>> data;
read(dict, data);
return data;
}
template<class Type> template<class Type>
void Foam::TableFileReader<Type>::write void Foam::TableFileReader<Type>::write
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -65,6 +65,8 @@ class TableFileReader
protected: protected:
// Protected Member Functions
//- Read a 1D table //- Read a 1D table
void read(const dictionary& dict, List<Tuple2<scalar, Type>>&) const; void read(const dictionary& dict, List<Tuple2<scalar, Type>>&) const;
@ -83,6 +85,9 @@ public:
// Member Functions // Member Functions
//- Read values
virtual List<Tuple2<scalar, Type>> read(const dictionary& dict) const;
//- Write additional information //- Write additional information
virtual void write virtual void write
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::TableReader<Type>::TableReader(const dictionary& dict) Foam::TableReader<Type>::TableReader()
{} {}
@ -39,15 +39,4 @@ Foam::TableReader<Type>::~TableReader()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TableReader<Type>::write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -66,17 +66,16 @@ public:
dictionary, dictionary,
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
), ),
(name, dict, table) (name, dict)
); );
// Constructors // Constructors
//- Construct from dictionary //- Default construct
TableReader(const dictionary& dict); TableReader();
//- Construct and return a clone //- Construct and return a clone
virtual autoPtr<TableReader<Type>> clone() const = 0; virtual autoPtr<TableReader<Type>> clone() const = 0;
@ -86,8 +85,7 @@ public:
static autoPtr<TableReader<Type>> New static autoPtr<TableReader<Type>> New
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
); );
@ -97,12 +95,18 @@ public:
// Member Functions // Member Functions
//- Write additional information //- Read values
virtual List<Tuple2<scalar, Type>> read
(
const dictionary& dict
) const = 0;
//- Write settings and values
virtual void write virtual void write
( (
Ostream& os, Ostream& os,
const List<Tuple2<scalar, Type>>& table const List<Tuple2<scalar, Type>>& table
) const; ) const = 0;
}; };
@ -119,22 +123,12 @@ public:
defineTemplateRunTimeSelectionTable(TableReader<Type>, dictionary); defineTemplateRunTimeSelectionTable(TableReader<Type>, dictionary);
#define makeTableReader(SS, Type) \ #define addTableReader(SS, Type) \
\ \
defineNamedTemplateTypeNameAndDebug(TableReaders::SS<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(TableReaders::SS<Type>, 0); \
\ \
addTemplatedToRunTimeSelectionTable(TableReader, SS, Type, dictionary) addTemplatedToRunTimeSelectionTable(TableReader, SS, Type, dictionary)
#define makeTableReaders(Type) \
defineTableReader(Type); \
\
namespace TableReaders \
{ \
makeTableReader(Embedded, Type); \
makeTableReader(Foam, Type); \
makeTableReader(Csv, Type); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -32,8 +32,7 @@ template<class Type>
Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict
List<Tuple2<scalar, Type>>& table
) )
{ {
if (dict.found("format")) if (dict.found("format"))
@ -53,7 +52,7 @@ Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
<< exit(FatalError); << exit(FatalError);
} }
return autoPtr<TableReader<Type>>(cstrIter()(name, dict, table)); return autoPtr<TableReader<Type>>(cstrIter()(name, dict));
} }
else else
{ {
@ -61,14 +60,14 @@ Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
{ {
return autoPtr<TableReader<Type>> return autoPtr<TableReader<Type>>
( (
new TableReaders::Foam<Type>(name, dict, table) new TableReaders::Foam<Type>(name, dict)
); );
} }
else else
{ {
return autoPtr<TableReader<Type>> return autoPtr<TableReader<Type>>
( (
new TableReaders::Embedded<Type>(name, dict, table) new TableReaders::Embedded<Type>(name, dict)
); );
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,21 +23,14 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "TableReader.H" #include "makeTableReaders.H"
#include "fieldTypes.H" #include "fieldTypes.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "CsvTableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
makeTableReaders(scalar); FOR_ALL_FIELD_TYPES(makeTableReaders);
makeTableReaders(vector);
makeTableReaders(sphericalTensor);
makeTableReaders(symmTensor);
makeTableReaders(tensor);
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 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/>.
Class
Foam::TableReader
Description
Macros for creating standard TableReader-s
\*---------------------------------------------------------------------------*/
#ifndef makeTableReaders_H
#define makeTableReaders_H
#include "TableReader.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "CsvTableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFoamTableReaders(Type, nullArg) \
\
defineTableReader(Type); \
\
namespace TableReaders \
{ \
addTableReader(Embedded, Type); \
addTableReader(Foam, Type); \
}
#define makeTableReaders(Type, nullArg) \
\
makeFoamTableReaders(Type, nullArg); \
\
namespace TableReaders \
{ \
addTableReader(Csv, Type); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,41 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 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 "Uniform.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::Uniform<Type>::Uniform
(
const word& name,
const dictionary& dict
)
:
Constant<Type>(name, dict)
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -71,8 +71,14 @@ public:
// Constructors // Constructors
//- Construct from name and dictionary //- Inherit constructors
Uniform(const word& name, const dictionary& dict); using Constant<Type>::Constant;
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Uniform<Type>(*this));
}
// Member Operators // Member Operators
@ -89,12 +95,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "Uniform.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(exponentialSqrRamp); addScalarFunction1(exponentialSqrRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(halfCosineRamp); addScalarFunction1(halfCosineRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(linearRamp); addScalarFunction1(linearRamp);
} }
} }

View File

@ -23,33 +23,19 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "None.H" #include "makeFunction1s.H"
#include "Constant.H"
#include "Uniform.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "Polynomial1.H"
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "UniformTable1.H"
#include "NonUniformTable1.H"
#include "Scale.H"
#include "CodedFunction1.H"
#include "fieldTypes.H" #include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
makeFunction1(label); defineFunction1(label);
namespace Function1s namespace Function1s
{ {
makeFunction1Type(None, label); addFunction1(None, label);
makeFunction1Type(Constant, label); addFunction1(Constant, label);
} }
FOR_ALL_FIELD_TYPES(makeFunction1s); FOR_ALL_FIELD_TYPES(makeFunction1s);

View File

@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 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/>.
Class
Foam::Function1
Description
Macros for creating standard Function1-s
\*---------------------------------------------------------------------------*/
#ifndef makeFunction1s_H
#define makeFunction1s_H
#include "None.H"
#include "Constant.H"
#include "Uniform.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "Polynomial1.H"
#include "Scale.H"
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "UniformTable1.H"
#include "NonUniformTable1.H"
#include "CodedFunction1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction1s(Type, nullArg) \
\
template<> \
const char* const Foam::Tuple2<Foam::scalar, Type>::typeName \
( \
"Tuple2<scalar," #Type ">" \
); \
\
defineFunction1(Type); \
\
namespace Function1s \
{ \
addFunction1(None, Type); \
addStreamConstructableFunction1(Constant, Type); \
addStreamConstructableFunction1(Uniform, Type); \
addFunction1(ZeroConstant, Type); \
addFunction1(OneConstant, Type); \
addStreamConstructableFunction1(Polynomial, Type); \
addFunction1(Scale, Type); \
addFunction1(Sine, Type); \
addFunction1(Square, Type); \
addStreamConstructableFunction1(Table, Type); \
addNamedFunction1(Table, Type, tableFile); \
addFunction1(UniformTable, Type); \
addFunction1(NonUniformTable, Type); \
addFunction1(Coded, Type); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(quadraticRamp); addScalarFunction1(quadraticRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(quarterCosineRamp); addScalarFunction1(quarterCosineRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(quarterSineRamp); addScalarFunction1(quarterSineRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2019-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(reverseRamp); addScalarFunction1(reverseRamp);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation \\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(squarePulse); addScalarFunction1(squarePulse);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,26 +47,8 @@ Foam::Function2s::Constant<Type>::Constant
) )
: :
FieldFunction2<Type, Constant<Type>>(name), FieldFunction2<Type, Constant<Type>>(name),
value_(Zero) value_(dict.lookup<Type>("value"))
{ {}
if (!dict.found(name))
{
dict.lookup("value") >> value_;
}
else
{
Istream& is(dict.lookup(name));
word entryType(is);
if (is.eof())
{
dict.lookup("value") >> value_;
}
else
{
is >> value_;
}
}
}
template<class Type> template<class Type>

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -68,7 +68,7 @@ class Constant
// Private Data // Private Data
//- Constant value //- Constant value
Type value_; const Type value_;
public: public:

View File

@ -35,10 +35,10 @@ Foam::Function2<Type>::Function2(const word& name)
template<class Type> template<class Type>
Foam::Function2<Type>::Function2(const Function2<Type>& de) Foam::Function2<Type>::Function2(const Function2<Type>& f2)
: :
tmp<Function2<Type>>::refCount(), tmp<Function2<Type>>::refCount(),
name_(de.name_) name_(f2.name_)
{} {}

View File

@ -76,10 +76,13 @@ public:
typedef Type returnType; typedef Type returnType;
//- Runtime type information //- Runtime type information
TypeName("Function2"); TypeName("Function2");
//- Declare runtime constructor selection table
// Declare runtime constructor selection tables
declareRunTimeSelectionTable declareRunTimeSelectionTable
( (
autoPtr, autoPtr,
@ -92,6 +95,18 @@ public:
(name, dict) (name, dict)
); );
declareRunTimeSelectionTable
(
autoPtr,
Function2,
Istream,
(
const word& name,
Istream& is
),
(name, is)
);
// Constructors // Constructors
@ -99,19 +114,29 @@ public:
Function2(const word& name); Function2(const word& name);
//- Copy constructor //- Copy constructor
Function2(const Function2<Type>& f1); Function2(const Function2<Type>& f2);
//- Construct and return a clone //- Construct and return a clone
virtual tmp<Function2<Type>> clone() const = 0; virtual tmp<Function2<Type>> clone() const = 0;
//- Selector // Selectors
//- Select from dictionary
static autoPtr<Function2<Type>> New static autoPtr<Function2<Type>> New
( (
const word& name, const word& name,
const dictionary& dict const dictionary& dict
); );
//- Select from Istream
static autoPtr<Function2<Type>> New
(
const word& name,
const word& Function2Type,
Istream& is
);
//- Destructor //- Destructor
virtual ~Function2(); virtual ~Function2();
@ -154,7 +179,7 @@ public:
template<class Type> template<class Type>
void writeEntry(Ostream& os, const Function2<Type>& f1); void writeEntry(Ostream& os, const Function2<Type>& f2);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -202,13 +227,14 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction2(Type) \ #define defineFunction2(Type) \
\ \
defineNamedTemplateTypeNameAndDebug(Function2<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(Function2<Type>, 0); \
defineTemplateRunTimeSelectionTable(Function2<Type>, dictionary); defineTemplateRunTimeSelectionTable(Function2<Type>, dictionary); \
defineTemplateRunTimeSelectionTable(Function2<Type>, Istream);
#define makeFunction2Type(SS, Type) \ #define addFunction2(SS, Type) \
\ \
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
typedef Function2<Type> Type##Function2; \ typedef Function2<Type> Type##Function2; \
@ -221,7 +247,18 @@ public:
) )
#define makeScalarFunction2(SS) \ #define addStreamConstructableFunction2(SS, Type) \
\
addFunction2(SS, Type); \
addToRunTimeSelectionTable \
( \
Type##Function2, \
Type##SS##Function2, \
Istream \
)
#define addScalarFunction2(SS) \
\ \
defineTypeNameAndDebug(SS, 0); \ defineTypeNameAndDebug(SS, 0); \
typedef Function2<scalar> scalarFunction2; \ typedef Function2<scalar> scalarFunction2; \

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,10 +23,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Constant.H" #include "Constant2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/*
template<class Type> template<class Type>
Foam::autoPtr<Foam::Function2<Type>> Foam::Function2<Type>::New Foam::autoPtr<Foam::Function2<Type>> Foam::Function2<Type>::New
( (
@ -93,6 +94,119 @@ Foam::autoPtr<Foam::Function2<Type>> Foam::Function2<Type>::New
return cstrIter()(name, dict); return cstrIter()(name, dict);
} }
} }
*/
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::Function2<Type>> Foam::Function2<Type>::New
(
const word& name,
const dictionary& dict
)
{
// If the function is a dictionary (preferred) then read straightforwardly
if (dict.isDict(name))
{
const dictionary& coeffsDict(dict.subDict(name));
const word Function2Type(coeffsDict.lookup("type"));
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(Function2Type);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function2 type "
<< Function2Type << " for Function2 "
<< name << nl << nl
<< "Valid Function2 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
return cstrIter()(name, coeffsDict);
}
// Find the entry
Istream& is(dict.lookup(name));
// Peek at the first token
token firstToken(is);
is.putBack(firstToken);
// Read the type, or assume constant
const word Function2Type =
firstToken.isWord() ? word(is) : Function2s::Constant<Type>::typeName;
// If the entry is not a type followed by a end statement then
// construct the function from the stream
if (!firstToken.isWord() || !is.eof())
{
return New(name, Function2Type, is);
}
// Otherwise, construct from the current dictionary
typename dictionaryConstructorTable::iterator dictCstrIter =
dictionaryConstructorTablePtr_->find(Function2Type);
if (dictCstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function2 type "
<< Function2Type << " for Function2 "
<< name << nl << nl
<< "Valid Function2 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
return dictCstrIter()(name, dict);
}
template<class Type>
Foam::autoPtr<Foam::Function2<Type>> Foam::Function2<Type>::New
(
const word& name,
const word& Function2Type,
Istream& is
)
{
typename dictionaryConstructorTable::iterator dictCstrIter =
dictionaryConstructorTablePtr_->find(Function2Type);
const bool haveDictCstrIter =
dictCstrIter != dictionaryConstructorTablePtr_->end();
typename IstreamConstructorTable::iterator isCstrIter =
IstreamConstructorTablePtr_->find(Function2Type);
const bool haveIstreamCstrIter =
isCstrIter != IstreamConstructorTablePtr_->end();
if (!haveDictCstrIter && !haveIstreamCstrIter)
{
FatalErrorInFunction
<< "Unknown Function2 type "
<< Function2Type << " for Function2 "
<< name << nl << nl
<< "Valid Function2 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
if (!haveIstreamCstrIter)
{
FatalErrorInFunction
<< "Function2 type "
<< name << " cannot be specified inline" << nl << nl
<< "Make " << name << " a sub-dictionary"
<< exit(FatalError);
}
return isCstrIter()(name, is);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -125,8 +125,7 @@ Type Foam::Function2s::UniformTable<Type>::value
template<class Type> template<class Type>
Type Foam::Function2s::UniformTable<Type>:: Type Foam::Function2s::UniformTable<Type>::dfdp
dfdp
( (
scalar p, scalar p,
scalar T scalar T
@ -154,8 +153,7 @@ dfdp
template<class Type> template<class Type>
Type Foam::Function2s::UniformTable<Type>:: Type Foam::Function2s::UniformTable<Type>::dfdT
dfdT
( (
scalar p, scalar p,
scalar T scalar T

View File

@ -23,41 +23,19 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "None2.H" #include "makeFunction2s.H"
#include "Constant2.H"
#include "ZeroConstant2.H"
#include "OneConstant2.H"
#include "Scale2.H"
#include "UniformTable2.H"
#include "CodedFunction2.H"
#include "fieldTypes.H" #include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction2s(Type, nullArg) \
\
makeFunction2(Type); \
\
namespace Function2s \
{ \
makeFunction2Type(None, Type); \
makeFunction2Type(Constant, Type); \
makeFunction2Type(ZeroConstant, Type); \
makeFunction2Type(OneConstant, Type); \
makeFunction2Type(Scale, Type); \
makeFunction2Type(UniformTable, Type); \
makeFunction2Type(Coded, Type); \
}
namespace Foam namespace Foam
{ {
makeFunction2(label); defineFunction2(label);
namespace Function2s namespace Function2s
{ {
makeFunction2Type(None, label); addFunction2(None, label);
makeFunction2Type(Constant, label); addStreamConstructableFunction2(Constant, label);
} }
FOR_ALL_FIELD_TYPES(makeFunction2s); FOR_ALL_FIELD_TYPES(makeFunction2s);

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020-2023 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/>.
Class
Foam::Function2
Description
Macros for creating standard Function2-s
\*---------------------------------------------------------------------------*/
#ifndef makeFunction2s_H
#define makeFunction2s_H
#include "None2.H"
#include "Constant2.H"
#include "ZeroConstant2.H"
#include "OneConstant2.H"
#include "Scale2.H"
#include "UniformTable2.H"
#include "CodedFunction2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction2s(Type, nullArg) \
\
defineFunction2(Type); \
\
namespace Function2s \
{ \
addFunction2(None, Type); \
addStreamConstructableFunction2(Constant, Type); \
addFunction2(ZeroConstant, Type); \
addFunction2(OneConstant, Type); \
addFunction2(Scale, Type); \
addFunction2(UniformTable, Type); \
addFunction2(Coded, Type); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,142 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2023 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 "TimeFunction1.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const Time& time,
const word& name,
const dictionary& dict
)
:
time_(time),
name_(name),
function_(Function1<Type>::New(name, dict))
{}
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const Time& time,
const Function1<Type>& function
)
:
time_(time),
name_(function.name()),
function_(function.clone().ptr())
{}
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const Time& time,
const word& name
)
:
time_(time),
name_(name),
function_(nullptr)
{}
template<class Type>
Foam::TimeFunction1<Type>::TimeFunction1
(
const TimeFunction1<Type>& tf
)
:
time_(tf.time_),
name_(tf.name_),
function_(tf.function_, false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TimeFunction1<Type>::~TimeFunction1()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TimeFunction1<Type>::reset(const dictionary& dict)
{
function_.reset(Function1<Type>::New(name_, dict).ptr());
}
template<class Type>
Type Foam::TimeFunction1<Type>::value(const scalar x) const
{
return function_->value(time_.timeToUserTime(x));
}
template<class Type>
Type Foam::TimeFunction1<Type>::integral
(
const scalar x1,
const scalar x2
) const
{
return
time_.userTimeToTime(1)
*function_->integral
(
time_.timeToUserTime(x1),
time_.timeToUserTime(x2)
);
}
template<class Type>
void Foam::TimeFunction1<Type>::write(Ostream& os) const
{
writeEntry(os, function_());
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const TimeFunction1<Type>& tf
)
{
return os << tf.function_();
}
// ************************************************************************* //

View File

@ -1,156 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2023 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/>.
Class
Foam::TimeFunction1
Description
Light wrapper around Function1 to provide a mechanism to update time-based
entries.
SourceFiles
TimeFunction1.C
\*---------------------------------------------------------------------------*/
#ifndef TimeFunction1_H
#define TimeFunction1_H
#include "Function1.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class TimeFunction1;
template<class Type>
Ostream& operator<<
(
Ostream&,
const TimeFunction1<Type>&
);
/*---------------------------------------------------------------------------*\
Class TimeFunction1 Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class TimeFunction1
{
protected:
// Protected data
//- Reference to the time database
const Time& time_;
//- Name of the data entry
const word name_;
//- The function
autoPtr<Function1<Type>> function_;
public:
// Constructor
//- Construct from time, name and dictionary
TimeFunction1
(
const Time& time,
const word& name,
const dictionary& dict
);
//- Construct from time and Function1
TimeFunction1
(
const Time& time,
const Function1<Type>& function
);
//- Construct null from time and name
TimeFunction1
(
const Time& time,
const word& name
);
//- Copy constructor
TimeFunction1(const TimeFunction1<Type>& tde);
//- Destructor
virtual ~TimeFunction1();
// Member Functions
// Access
//- Reset entry by re-reading from dictionary
void reset(const dictionary& dict);
// Evaluation
//- Return value as a function of scalar x
virtual Type value(const scalar x) const;
//- Integrate between two scalars
virtual Type integral(const scalar x1, const scalar x2) const;
// I/O
//- Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream& os,
const TimeFunction1<Type>& de
);
//- Write in dictionary format
virtual void write(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "TimeFunction1.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -25,6 +25,8 @@ License
#include "sixDoFMotion.H" #include "sixDoFMotion.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "makeFunction1s.H"
#include "makeTableReaders.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
using namespace Foam::constant::mathematical; using namespace Foam::constant::mathematical;
@ -48,22 +50,6 @@ namespace solidBodyMotionFunctions
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "None.H"
#include "Constant.H"
#include "Uniform.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "Polynomial1.H"
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "UniformTable1.H"
#include "NonUniformTable1.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"
#include "CodedFunction1.H"
typedef Foam::solidBodyMotionFunctions::sixDoFMotion::translationRotationVectors typedef Foam::solidBodyMotionFunctions::sixDoFMotion::translationRotationVectors
trvType; trvType;
@ -103,13 +89,7 @@ const trvType trvType::vsType::rootMin
namespace Foam namespace Foam
{ {
makeFunction1s(trvType, nullArg); makeFunction1s(trvType, nullArg);
makeFoamTableReaders(trvType, nullArg);
defineTableReader(trvType);
namespace TableReaders
{
makeTableReader(Embedded, trvType);
makeTableReader(Foam, trvType);
}
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(laminarBL); addScalarFunction1(laminarBL);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,7 +31,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(turbulentBL); addScalarFunction1(turbulentBL);
} }
} }

View File

@ -26,6 +26,8 @@ License
#include "sixDoFAccelerationSource.H" #include "sixDoFAccelerationSource.H"
#include "fvMatrices.H" #include "fvMatrices.H"
#include "geometricOneField.H" #include "geometricOneField.H"
#include "makeFunction1s.H"
#include "makeTableReaders.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -47,22 +49,6 @@ namespace fv
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "None.H"
#include "Constant.H"
#include "Uniform.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "Polynomial1.H"
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "UniformTable1.H"
#include "NonUniformTable1.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"
#include "CodedFunction1.H"
typedef Foam::fv::sixDoFAccelerationSource::accelerationVectors avType; typedef Foam::fv::sixDoFAccelerationSource::accelerationVectors avType;
template<> template<>
@ -97,15 +83,8 @@ const avType avType::vsType::rootMin
namespace Foam namespace Foam
{ {
makeFunction1s(avType, nullArg); makeFunction1s(avType, nullArg);
makeFoamTableReaders(avType, nullArg);
defineTableReader(avType);
namespace TableReaders
{
makeTableReader(Embedded, avType);
makeTableReader(Foam, avType);
}
} }

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ConeInjection.H" #include "ConeInjection.H"
#include "TimeFunction1.H"
#include "Constant.H" #include "Constant.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "unitConversion.H" #include "unitConversion.H"
@ -79,13 +78,31 @@ void Foam::ConeInjection<CloudType>::setFlowType()
{ {
flowType_ = ftConstantVelocity; flowType_ = ftConstantVelocity;
Umag_.reset(this->coeffDict()); Umag_.reset
(
new Function1s::Dimensioned<scalar>
(
"Umag",
dimTime,
dimVelocity,
this->coeffDict()
)
);
} }
else if (flowType == "pressureDrivenVelocity") else if (flowType == "pressureDrivenVelocity")
{ {
flowType_ = ftPressureDrivenVelocity; flowType_ = ftPressureDrivenVelocity;
Pinj_.reset(this->coeffDict()); Pinj_.reset
(
new Function1s::Dimensioned<scalar>
(
"Pinj",
dimTime,
dimPressure,
this->coeffDict()
)
);
} }
else if (flowType == "flowRateAndDischarge") else if (flowType == "flowRateAndDischarge")
{ {
@ -94,7 +111,16 @@ void Foam::ConeInjection<CloudType>::setFlowType()
this->coeffDict().lookup("dInner") >> dInner_; this->coeffDict().lookup("dInner") >> dInner_;
this->coeffDict().lookup("dOuter") >> dOuter_; this->coeffDict().lookup("dOuter") >> dOuter_;
Cd_.reset(this->coeffDict()); Cd_.reset
(
new Function1s::Dimensioned<scalar>
(
"Cd",
dimTime,
dimless,
this->coeffDict()
)
);
} }
else else
{ {
@ -121,20 +147,21 @@ Foam::ConeInjection<CloudType>::ConeInjection
flowType_(ftConstantVelocity), flowType_(ftConstantVelocity),
position_ position_
( (
TimeFunction1<vector> new Function1s::Dimensioned<vector>
( (
owner.db().time(),
"position", "position",
dimTime,
dimLength,
this->coeffDict() this->coeffDict()
) )
), ),
positionIsConstant_(isA<Function1s::Constant<vector>>(position_)),
direction_ direction_
( (
TimeFunction1<vector> new Function1s::Dimensioned<vector>
( (
owner.db().time(),
"direction", "direction",
dimTime,
dimless,
this->coeffDict() this->coeffDict()
) )
), ),
@ -147,19 +174,21 @@ Foam::ConeInjection<CloudType>::ConeInjection
parcelsPerSecond_(this->readParcelsPerSecond(dict, owner)), parcelsPerSecond_(this->readParcelsPerSecond(dict, owner)),
thetaInner_ thetaInner_
( (
TimeFunction1<scalar> new Function1s::Dimensioned<scalar>
( (
owner.db().time(),
"thetaInner", "thetaInner",
dimTime,
dimless,
this->coeffDict() this->coeffDict()
) )
), ),
thetaOuter_ thetaOuter_
( (
TimeFunction1<scalar> new Function1s::Dimensioned<scalar>
( (
owner.db().time(),
"thetaOuter", "thetaOuter",
dimTime,
dimless,
this->coeffDict() this->coeffDict()
) )
), ),
@ -174,9 +203,9 @@ Foam::ConeInjection<CloudType>::ConeInjection
), ),
dInner_(vGreat), dInner_(vGreat),
dOuter_(vGreat), dOuter_(vGreat),
Umag_(owner.db().time(), "Umag"), Umag_(nullptr),
Cd_(owner.db().time(), "Cd"), Cd_(nullptr),
Pinj_(owner.db().time(), "Pinj") Pinj_(nullptr)
{ {
setInjectionMethod(); setInjectionMethod();
@ -195,24 +224,23 @@ Foam::ConeInjection<CloudType>::ConeInjection
InjectionModel<CloudType>(im), InjectionModel<CloudType>(im),
injectionMethod_(im.injectionMethod_), injectionMethod_(im.injectionMethod_),
flowType_(im.flowType_), flowType_(im.flowType_),
position_(im.position_), position_(im.position_, false),
positionIsConstant_(im.positionIsConstant_), direction_(im.direction_, false),
direction_(im.direction_),
injectorCoordinates_(im.injectorCoordinates_), injectorCoordinates_(im.injectorCoordinates_),
injectorCell_(im.injectorCell_), injectorCell_(im.injectorCell_),
injectorTetFace_(im.injectorTetFace_), injectorTetFace_(im.injectorTetFace_),
injectorTetPt_(im.injectorTetPt_), injectorTetPt_(im.injectorTetPt_),
duration_(im.duration_), duration_(im.duration_),
massFlowRate_(im.massFlowRate_), massFlowRate_(im.massFlowRate_, false),
parcelsPerSecond_(im.parcelsPerSecond_), parcelsPerSecond_(im.parcelsPerSecond_, false),
thetaInner_(im.thetaInner_), thetaInner_(im.thetaInner_, false),
thetaOuter_(im.thetaOuter_), thetaOuter_(im.thetaOuter_, false),
sizeDistribution_(im.sizeDistribution_().clone().ptr()), sizeDistribution_(im.sizeDistribution_().clone().ptr()),
dInner_(im.dInner_), dInner_(im.dInner_),
dOuter_(im.dOuter_), dOuter_(im.dOuter_),
Umag_(im.Umag_), Umag_(im.Umag_, false),
Cd_(im.Cd_), Cd_(im.Cd_, false),
Pinj_(im.Pinj_) Pinj_(im.Pinj_, false)
{} {}
@ -228,9 +256,9 @@ Foam::ConeInjection<CloudType>::~ConeInjection()
template<class CloudType> template<class CloudType>
void Foam::ConeInjection<CloudType>::topoChange() void Foam::ConeInjection<CloudType>::topoChange()
{ {
if (injectionMethod_ == imPoint && positionIsConstant_) if (injectionMethod_ == imPoint && position_->constant())
{ {
vector position = position_.value(0); vector position = position_->value(0);
this->findCellAtPosition this->findCellAtPosition
( (
position, position,
@ -260,13 +288,13 @@ Foam::label Foam::ConeInjection<CloudType>::nParcelsToInject
if (time0 >= 0 && time0 < duration_) if (time0 >= 0 && time0 < duration_)
{ {
//// Standard calculation //// Standard calculation
//return floor(parcelsPerSecond_.integral(time0, time1)); //return floor(parcelsPerSecond_->integral(time0, time1));
// Modified calculation to make numbers exact // Modified calculation to make numbers exact
return return
floor floor
( (
parcelsPerSecond_.integral(0, time1) parcelsPerSecond_->integral(0, time1)
- this->parcelsAddedTotal() - this->parcelsAddedTotal()
); );
} }
@ -286,7 +314,7 @@ Foam::scalar Foam::ConeInjection<CloudType>::massToInject
{ {
if (time0 >= 0 && time0 < duration_) if (time0 >= 0 && time0 < duration_)
{ {
return massFlowRate_.integral(time0, time1); return massFlowRate_->integral(time0, time1);
} }
else else
{ {
@ -316,8 +344,8 @@ void Foam::ConeInjection<CloudType>::setPositionAndCell
{ {
case imPoint: case imPoint:
{ {
const point pos = position_.value(t); const point pos = position_->value(t);
if (positionIsConstant_) if (position_->constant())
{ {
coordinates = injectorCoordinates_; coordinates = injectorCoordinates_;
celli = injectorCell_; celli = injectorCell_;
@ -342,12 +370,12 @@ void Foam::ConeInjection<CloudType>::setPositionAndCell
{ {
const scalar beta = twoPi*rndGen.globalScalar01(); const scalar beta = twoPi*rndGen.globalScalar01();
const scalar frac = rndGen.globalScalar01(); const scalar frac = rndGen.globalScalar01();
const vector n = normalised(direction_.value(t)); const vector n = normalised(direction_->value(t));
const vector t1 = normalised(perpendicular(n)); const vector t1 = normalised(perpendicular(n));
const vector t2 = normalised(n ^ t1); const vector t2 = normalised(n ^ t1);
const vector tanVec = t1*cos(beta) + t2*sin(beta); const vector tanVec = t1*cos(beta) + t2*sin(beta);
const scalar d = sqrt((1 - frac)*sqr(dInner_) + frac*sqr(dOuter_)); const scalar d = sqrt((1 - frac)*sqr(dInner_) + frac*sqr(dOuter_));
const point pos = position_.value(t) + d/2*tanVec; const point pos = position_->value(t) + d/2*tanVec;
this->findCellAtPosition this->findCellAtPosition
( (
pos, pos,
@ -395,7 +423,7 @@ void Foam::ConeInjection<CloudType>::setProperties
{ {
const scalar beta = twoPi*rndGen.scalar01(); const scalar beta = twoPi*rndGen.scalar01();
const scalar frac = rndGen.scalar01(); const scalar frac = rndGen.scalar01();
const vector n = normalised(direction_.value(t)); const vector n = normalised(direction_->value(t));
const vector t1 = normalised(perpendicular(n)); const vector t1 = normalised(perpendicular(n));
const vector t2 = normalised(n ^ t1); const vector t2 = normalised(n ^ t1);
tanVec = t1*cos(beta) + t2*sin(beta); tanVec = t1*cos(beta) + t2*sin(beta);
@ -404,22 +432,22 @@ void Foam::ConeInjection<CloudType>::setProperties
( (
sqrt sqrt
( (
(1 - frac)*sqr(thetaInner_.value(t)) (1 - frac)*sqr(thetaInner_->value(t))
+ frac*sqr(thetaOuter_.value(t)) + frac*sqr(thetaOuter_->value(t))
) )
); );
break; break;
} }
case imDisc: case imDisc:
{ {
const scalar r = mag(parcel.position(mesh) - position_.value(t)); const scalar r = mag(parcel.position(mesh) - position_->value(t));
const scalar frac = (2*r - dInner_)/(dOuter_ - dInner_); const scalar frac = (2*r - dInner_)/(dOuter_ - dInner_);
tanVec = normalised(parcel.position(mesh) - position_.value(t)); tanVec = normalised(parcel.position(mesh) - position_->value(t));
theta = theta =
degToRad degToRad
( (
(1 - frac)*thetaInner_.value(t) (1 - frac)*thetaInner_->value(t)
+ frac*thetaOuter_.value(t) + frac*thetaOuter_->value(t)
); );
break; break;
} }
@ -433,7 +461,7 @@ void Foam::ConeInjection<CloudType>::setProperties
const vector dirVec = const vector dirVec =
normalised normalised
( (
cos(theta)*normalised(direction_.value(t)) cos(theta)*normalised(direction_->value(t))
+ sin(theta)*tanVec + sin(theta)*tanVec
); );
@ -442,14 +470,14 @@ void Foam::ConeInjection<CloudType>::setProperties
{ {
case ftConstantVelocity: case ftConstantVelocity:
{ {
parcel.U() = Umag_.value(t)*dirVec; parcel.U() = Umag_->value(t)*dirVec;
break; break;
} }
case ftPressureDrivenVelocity: case ftPressureDrivenVelocity:
{ {
const scalar pAmbient = this->owner().pAmbient(); const scalar pAmbient = this->owner().pAmbient();
const scalar rho = parcel.rho(); const scalar rho = parcel.rho();
const scalar Umag = ::sqrt(2*(Pinj_.value(t) - pAmbient)/rho); const scalar Umag = ::sqrt(2*(Pinj_->value(t) - pAmbient)/rho);
parcel.U() = Umag*dirVec; parcel.U() = Umag*dirVec;
break; break;
} }
@ -457,7 +485,7 @@ void Foam::ConeInjection<CloudType>::setProperties
{ {
const scalar A = 0.25*pi*(sqr(dOuter_) - sqr(dInner_)); const scalar A = 0.25*pi*(sqr(dOuter_) - sqr(dInner_));
const scalar Umag = const scalar Umag =
massFlowRate_.value(t)/(parcel.rho()*Cd_.value(t)*A); massFlowRate_->value(t)/(parcel.rho()*Cd_->value(t)*A);
parcel.U() = Umag*dirVec; parcel.U() = Umag*dirVec;
break; break;
} }

View File

@ -145,7 +145,7 @@ SourceFiles
#include "InjectionModel.H" #include "InjectionModel.H"
#include "distribution.H" #include "distribution.H"
#include "TimeFunction1.H" #include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -190,13 +190,10 @@ private:
flowType flowType_; flowType flowType_;
//- Position of the injector //- Position of the injector
const TimeFunction1<vector> position_; const autoPtr<Function1<vector>> position_;
//- Is the position constant?
const bool positionIsConstant_;
//- Centreline direction in which to inject //- Centreline direction in which to inject
const TimeFunction1<vector> direction_; const autoPtr<Function1<vector>> direction_;
//- Coordinates corresponding to the injector position //- Coordinates corresponding to the injector position
barycentric injectorCoordinates_; barycentric injectorCoordinates_;
@ -214,16 +211,16 @@ private:
const scalar duration_; const scalar duration_;
//- Mass flow rate relative to SOI [] //- Mass flow rate relative to SOI []
const TimeFunction1<scalar> massFlowRate_; const autoPtr<Function1<scalar>> massFlowRate_;
//- Number of parcels to introduce per second //- Number of parcels to introduce per second
const TimeFunction1<scalar> parcelsPerSecond_; const autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Inner half-cone angle relative to SOI [deg] //- Inner half-cone angle relative to SOI [deg]
const TimeFunction1<scalar> thetaInner_; const autoPtr<Function1<scalar>> thetaInner_;
//- Outer half-cone angle relative to SOI [deg] //- Outer half-cone angle relative to SOI [deg]
const TimeFunction1<scalar> thetaOuter_; const autoPtr<Function1<scalar>> thetaOuter_;
//- Parcel size distribution model //- Parcel size distribution model
const autoPtr<distribution> sizeDistribution_; const autoPtr<distribution> sizeDistribution_;
@ -241,13 +238,13 @@ private:
// Velocity model coefficients // Velocity model coefficients
//- Parcel velocity [m/s] //- Parcel velocity [m/s]
TimeFunction1<scalar> Umag_; autoPtr<Function1<scalar>> Umag_;
//- Discharge coefficient [] //- Discharge coefficient []
TimeFunction1<scalar> Cd_; autoPtr<Function1<scalar>> Cd_;
//- Injection pressure [Pa] //- Injection pressure [Pa]
TimeFunction1<scalar> Pinj_; autoPtr<Function1<scalar>> Pinj_;
// Private Member Functions // Private Member Functions

View File

@ -62,7 +62,7 @@ Foam::scalar Foam::InjectionModel<CloudType>::readMassTotal
return NaN; return NaN;
} }
return dict.lookup<scalar>("massTotal"); return dimensionedScalar("massTotal", dimMass, dict).value();
} }
@ -73,23 +73,17 @@ Foam::scalar Foam::InjectionModel<CloudType>::readDuration
CloudType& owner CloudType& owner
) )
{ {
const Time& time = owner.mesh().time();
if (owner.solution().steadyState()) if (owner.solution().steadyState())
{ {
return vGreat; return vGreat;
} }
return return dimensionedScalar("duration", dimTime, dict).value();
time.userTimeToTime
(
this->coeffDict().template lookup<scalar>("duration")
);
} }
template<class CloudType> template<class CloudType>
Foam::TimeFunction1<Foam::scalar> Foam::autoPtr<Foam::Function1<Foam::scalar>>
Foam::InjectionModel<CloudType>::readMassFlowRate Foam::InjectionModel<CloudType>::readMassFlowRate
( (
const dictionary& dict, const dictionary& dict,
@ -97,8 +91,6 @@ Foam::InjectionModel<CloudType>::readMassFlowRate
const scalar duration const scalar duration
) )
{ {
const Time& time = owner.mesh().time();
const bool haveMassFlowRate = dict.found("massFlowRate"); const bool haveMassFlowRate = dict.found("massFlowRate");
const bool haveMassTotal = dict.found("massTotal"); const bool haveMassTotal = dict.found("massTotal");
@ -112,10 +104,9 @@ Foam::InjectionModel<CloudType>::readMassFlowRate
} }
return return
TimeFunction1<scalar> autoPtr<Function1<scalar>>
( (
time, new Function1s::Constant<scalar>("NaN", NaN)
Function1s::Constant<scalar>("NaN", NaN)
); );
} }
@ -135,32 +126,52 @@ Foam::InjectionModel<CloudType>::readMassFlowRate
if (owner.solution().steadyState() || haveMassFlowRate) if (owner.solution().steadyState() || haveMassFlowRate)
{ {
return TimeFunction1<scalar>(time, "massFlowRate", dict); return
autoPtr<Function1<scalar>>
(
new Function1s::Dimensioned<scalar>
(
"massFlowRate",
dimTime,
dimMass/dimTime,
dict
)
);
} }
const scalar massTotal = dict.lookup<scalar>("massTotal"); const scalar massTotal =
dimensionedScalar("massTotal", dimMass, dict).value();
if (!dict.found("flowRateProfile")) if (!dict.found("flowRateProfile"))
{ {
return return
TimeFunction1<scalar> autoPtr<Function1<scalar>>
( (
time, new Function1s::Constant<scalar>
Function1s::Constant<scalar>("massFlowRate", massTotal/duration) (
"massFlowRate",
massTotal/duration
)
); );
} }
autoPtr<Function1<scalar>> flowRateProfile = autoPtr<Function1<scalar>> flowRateProfile
Function1<scalar>::New("flowRateProfile", dict); (
new Function1s::Dimensioned<scalar>
(
"flowRateProfile",
dimTime,
dimless,
dict
)
);
const scalar sumFlowRateProfile = const scalar sumFlowRateProfile = flowRateProfile->integral(0, duration);
TimeFunction1<scalar>(time, flowRateProfile).integral(0, duration);
return return
TimeFunction1<scalar> autoPtr<Function1<scalar>>
( (
time, new Function1s::Scale<scalar>
Function1s::Scale<scalar>
( (
"massFlowRate", "massFlowRate",
Function1s::Constant<scalar>("m", massTotal/sumFlowRateProfile), Function1s::Constant<scalar>("m", massTotal/sumFlowRateProfile),
@ -172,16 +183,24 @@ Foam::InjectionModel<CloudType>::readMassFlowRate
template<class CloudType> template<class CloudType>
Foam::TimeFunction1<Foam::scalar> Foam::autoPtr<Foam::Function1<Foam::scalar>>
Foam::InjectionModel<CloudType>::readParcelsPerSecond Foam::InjectionModel<CloudType>::readParcelsPerSecond
( (
const dictionary& dict, const dictionary& dict,
CloudType& owner CloudType& owner
) )
{ {
const Time& time = owner.mesh().time(); return
autoPtr<Function1<scalar>>
return TimeFunction1<scalar>(time, "parcelsPerSecond", dict); (
new Function1s::Dimensioned<scalar>
(
"parcelsPerSecond",
dimTime,
dimless/dimTime,
dict
)
);
} }
@ -515,11 +534,7 @@ Foam::InjectionModel<CloudType>::InjectionModel
if (owner.solution().transient()) if (owner.solution().transient())
{ {
SOI_ = SOI_ = dimensionedScalar("SOI", dimTime, dict).value();
owner.db().time().userTimeToTime
(
this->coeffDict().template lookup<scalar>("SOI")
);
} }
} }

View File

@ -36,8 +36,7 @@ Description
populated using values supplied in the constant properties. populated using values supplied in the constant properties.
If, however, all of a parcel's properties are described in the model, the If, however, all of a parcel's properties are described in the model, the
fullDescribed() flag should be set to 1 (true). fullyDescribed() flag should be set to 1 (true).
SourceFiles SourceFiles
InjectionModel.C InjectionModel.C
@ -51,7 +50,7 @@ SourceFiles
#include "injectionModel.H" #include "injectionModel.H"
#include "CloudSubModelBase.H" #include "CloudSubModelBase.H"
#include "particle.H" #include "particle.H"
#include "TimeFunction1.H" #include "DimensionedFunction1.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -130,7 +129,7 @@ protected:
); );
//- Read the mass flow rate function for continuous injections //- Read the mass flow rate function for continuous injections
TimeFunction1<scalar> readMassFlowRate autoPtr<Function1<scalar>> readMassFlowRate
( (
const dictionary& dict, const dictionary& dict,
CloudType& owner, CloudType& owner,
@ -139,7 +138,7 @@ protected:
//- Read the number of parcels injected per second for continuous //- Read the number of parcels injected per second for continuous
// injections // injections
TimeFunction1<scalar> readParcelsPerSecond autoPtr<Function1<scalar>> readParcelsPerSecond
( (
const dictionary& dict, const dictionary& dict,
CloudType& owner CloudType& owner

View File

@ -132,7 +132,7 @@ Foam::label Foam::MomentumLookupTableInjection<CloudType>::nParcelsToInject
floor floor
( (
injectorCells_.size() injectorCells_.size()
*parcelsPerSecond_.integral(time0, time1) *parcelsPerSecond_->integral(time0, time1)
); );
} }
else else

View File

@ -80,7 +80,7 @@ class MomentumLookupTableInjection
const scalar duration_; const scalar duration_;
//- Number of parcels per injector - common to all injection sources //- Number of parcels per injector - common to all injection sources
const TimeFunction1<scalar> parcelsPerSecond_; autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Flag to indicate to randomise injection positions //- Flag to indicate to randomise injection positions
bool randomise_; bool randomise_;

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "PatchFlowRateInjection.H" #include "PatchFlowRateInjection.H"
#include "TimeFunction1.H"
#include "distribution.H" #include "distribution.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "surfaceFields.H" #include "surfaceFields.H"
@ -46,10 +45,11 @@ Foam::PatchFlowRateInjection<CloudType>::PatchFlowRateInjection
duration_(this->readDuration(dict, owner)), duration_(this->readDuration(dict, owner)),
concentration_ concentration_
( (
TimeFunction1<scalar> new Function1s::Dimensioned<scalar>
( (
owner.db().time(),
"concentration", "concentration",
dimTime,
dimless,
this->coeffDict() this->coeffDict()
) )
), ),
@ -150,7 +150,7 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::nParcelsToInject
{ {
scalar dt = time1 - time0; scalar dt = time1 - time0;
scalar c = concentration_.value(0.5*(time0 + time1)); scalar c = concentration_->value(0.5*(time0 + time1));
scalar nParcels = parcelConcentration_*c*flowRate()*dt; scalar nParcels = parcelConcentration_*c*flowRate()*dt;
@ -189,7 +189,7 @@ Foam::scalar Foam::PatchFlowRateInjection<CloudType>::massToInject
if (time0 >= 0 && time0 < duration_) if (time0 >= 0 && time0 < duration_)
{ {
scalar c = concentration_.value(0.5*(time0 + time1)); scalar c = concentration_->value(0.5*(time0 + time1));
volume = c*(time1 - time0)*flowRate(); volume = c*(time1 - time0)*flowRate();
} }

View File

@ -48,7 +48,6 @@ SourceFiles
#include "InjectionModel.H" #include "InjectionModel.H"
#include "patchInjectionBase.H" #include "patchInjectionBase.H"
#include "TimeFunction1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -79,7 +78,7 @@ class PatchFlowRateInjection
const scalar duration_; const scalar duration_;
//- Concentration profile of particle volume to carrier volume [-] //- Concentration profile of particle volume to carrier volume [-]
const TimeFunction1<scalar> concentration_; autoPtr<Function1<scalar>> concentration_;
//- Parcels to introduce per unit volume flow rate m3 [n/m^3] //- Parcels to introduce per unit volume flow rate m3 [n/m^3]
const scalar parcelConcentration_; const scalar parcelConcentration_;

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "PatchInjection.H" #include "PatchInjection.H"
#include "TimeFunction1.H"
#include "distribution.H" #include "distribution.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -103,7 +102,7 @@ Foam::label Foam::PatchInjection<CloudType>::nParcelsToInject
{ {
if (time0 >= 0 && time0 < duration_) if (time0 >= 0 && time0 < duration_)
{ {
scalar nParcels = parcelsPerSecond_.integral(time0, time1); scalar nParcels = parcelsPerSecond_->integral(time0, time1);
Random& rnd = this->owner().rndGen(); Random& rnd = this->owner().rndGen();
@ -138,7 +137,7 @@ Foam::scalar Foam::PatchInjection<CloudType>::massToInject
{ {
if (time0 >= 0 && time0 < duration_) if (time0 >= 0 && time0 < duration_)
{ {
return massFlowRate_.integral(time0, time1); return massFlowRate_->integral(time0, time1);
} }
else else
{ {

View File

@ -47,6 +47,7 @@ SourceFiles
#define PatchInjection_H #define PatchInjection_H
#include "InjectionModel.H" #include "InjectionModel.H"
#include "Function1.H"
#include "patchInjectionBase.H" #include "patchInjectionBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,9 +55,6 @@ SourceFiles
namespace Foam namespace Foam
{ {
template<class Type>
class TimeFunction1;
class distribution; class distribution;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -74,11 +72,11 @@ class PatchInjection
//- Injection duration [s] //- Injection duration [s]
const scalar duration_; const scalar duration_;
//- Mass flow rate relative to SOI [] //- Mass flow rate relative to SOI [kg/s]
const TimeFunction1<scalar> massFlowRate_; autoPtr<Function1<scalar>> massFlowRate_;
//- Number of parcels to introduce per second [] //- Number of parcels to introduce per second [1/s]
const TimeFunction1<scalar> parcelsPerSecond_; autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Initial parcel velocity [m/s] //- Initial parcel velocity [m/s]
const vector U0_; const vector U0_;

View File

@ -132,7 +132,7 @@ Foam::label Foam::ReactingLookupTableInjection<CloudType>::nParcelsToInject
floor floor
( (
injectorCells_.size() injectorCells_.size()
*parcelsPerSecond_.integral(time0, time1) *parcelsPerSecond_->integral(time0, time1)
); );
} }
else else

View File

@ -79,7 +79,7 @@ class ReactingLookupTableInjection
const scalar duration_; const scalar duration_;
//- Number of parcels per injector - common to all injection sources //- Number of parcels per injector - common to all injection sources
const TimeFunction1<scalar> parcelsPerSecond_; autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Flag to indicate to randomise injection positions //- Flag to indicate to randomise injection positions
bool randomise_; bool randomise_;

View File

@ -137,7 +137,7 @@ Foam::ReactingMultiphaseLookupTableInjection<CloudType>::nParcelsToInject
floor floor
( (
injectorCells_.size() injectorCells_.size()
*parcelsPerSecond_.integral(time0, time1) *parcelsPerSecond_->integral(time0, time1)
); );
} }
else else

View File

@ -82,7 +82,7 @@ class ReactingMultiphaseLookupTableInjection
const scalar duration_; const scalar duration_;
//- Number of parcels per injector - common to all injection sources //- Number of parcels per injector - common to all injection sources
const TimeFunction1<scalar> parcelsPerSecond_; autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Flag to indicate to randomise injection positions //- Flag to indicate to randomise injection positions
bool randomise_; bool randomise_;

View File

@ -133,7 +133,7 @@ Foam::label Foam::ThermoLookupTableInjection<CloudType>::nParcelsToInject
floor floor
( (
injectorCells_.size() injectorCells_.size()
*parcelsPerSecond_.integral(time0, time1) *parcelsPerSecond_->integral(time0, time1)
); );
} }
else else

View File

@ -78,7 +78,7 @@ class ThermoLookupTableInjection
const scalar duration_; const scalar duration_;
//- Number of parcels per injector - common to all injection sources //- Number of parcels per injector - common to all injection sources
const TimeFunction1<scalar> parcelsPerSecond_; autoPtr<Function1<scalar>> parcelsPerSecond_;
//- Flag to indicate to randomise injection positions //- Flag to indicate to randomise injection positions
bool randomise_; bool randomise_;

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function2s namespace Function2s
{ {
makeScalarFunction2(APIdiffCoef); addScalarFunction2(APIdiffCoef);
} }
} }

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS0); addScalarFunction1(NSRDS0);
} }
} }

View File

@ -32,10 +32,11 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS1); addScalarFunction1(NSRDS1);
} }
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1s::NSRDS1::NSRDS1 Foam::Function1s::NSRDS1::NSRDS1

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS14); addScalarFunction1(NSRDS14);
} }
} }

View File

@ -32,10 +32,11 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS2); addScalarFunction1(NSRDS2);
} }
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1s::NSRDS2::NSRDS2 Foam::Function1s::NSRDS2::NSRDS2

View File

@ -32,10 +32,11 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS3); addScalarFunction1(NSRDS3);
} }
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1s::NSRDS3::NSRDS3 Foam::Function1s::NSRDS3::NSRDS3

View File

@ -32,10 +32,11 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS4); addScalarFunction1(NSRDS4);
} }
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1s::NSRDS4::NSRDS4 Foam::Function1s::NSRDS4::NSRDS4

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS5); addScalarFunction1(NSRDS5);
} }
} }

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS6); addScalarFunction1(NSRDS6);
} }
} }

View File

@ -32,7 +32,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(NSRDS7); addScalarFunction1(NSRDS7);
} }
} }

View File

@ -33,7 +33,7 @@ namespace Foam
{ {
namespace Function1s namespace Function1s
{ {
makeScalarFunction1(integratedNonUniformTable); addScalarFunction1(integratedNonUniformTable);
} }
} }