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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -46,6 +46,7 @@ Foam::userTimes::engine::engine(const dictionary& controlDict)
rpm_("rpm", dimless/dimTime, 0)
{
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)
{
rpm_.read(dict(controlDict));
addUnit(dimensionedScalar(unit(), dimTime, userTimeToTime(1)));
return true;
}

View File

@ -36,6 +36,7 @@ namespace Foam
// the controlDict subDict (v.s. a reference to the subDict for e.g.
// dimensionedConstants)
dictionary* dimensionSystemsPtr_(nullptr);
HashTable<dimensionedScalar>* addedUnitsPtr_(nullptr);
HashTable<dimensionedScalar>* unitSetPtr_(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()
{
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
(
unitDict.lookupOrDefault<wordList>

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -62,7 +62,7 @@ class Constant
// Private Data
//- Constant value
Type value_;
const Type value_;
public:
@ -106,6 +106,9 @@ public:
//- Integrate between two values
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
virtual void write(Ostream& os) const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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>
Foam::Function1<Type>::Function1(const Function1<Type>& de)
Foam::Function1<Type>::Function1(const Function1<Type>& f1)
:
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>
Foam::tmp<Foam::Field<Type>> Foam::FieldFunction1<Type, Function1Type>::value
(

View File

@ -66,7 +66,7 @@ class Function1
protected:
// Protected data
// Protected Data
//- Name of entry
const word name_;
@ -76,10 +76,13 @@ public:
typedef Type returnType;
//- Runtime type information
TypeName("Function1");
//- Declare runtime constructor selection table
// Declare runtime constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
@ -92,6 +95,18 @@ public:
(name, dict)
);
declareRunTimeSelectionTable
(
autoPtr,
Function1,
Istream,
(
const word& name,
Istream& is
),
(name, is)
);
// Constructors
@ -105,13 +120,23 @@ public:
virtual tmp<Function1<Type>> clone() const = 0;
//- Selector
// Selectors
//- Select from dictionary
static autoPtr<Function1<Type>> New
(
const word& name,
const dictionary& dict
);
//- Select from Istream
static autoPtr<Function1<Type>> New
(
const word& name,
const word& Function1Type,
Istream& is
);
//- Destructor
virtual ~Function1();
@ -138,6 +163,9 @@ public:
const scalarField& x2
) const = 0;
//- Is this function guaranteed to be constant?
virtual bool constant() const;
//- Write data to dictionary stream
virtual void write(Ostream& os) const = 0;
@ -214,13 +242,14 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeFunction1(Type) \
#define defineFunction1(Type) \
\
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); \
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 SS<Type> Type##SS##Function1; \
@ -246,42 +286,13 @@ public:
)
#define makeScalarFunction1(SS) \
#define addScalarFunction1(SS) \
\
defineTypeNameAndDebug(SS, 0); \
typedef Function1<scalar> scalarFunction1; \
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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,7 @@ License
#include "Constant.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
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
)
{
// If the function is a dictionary (preferred) then read straightforwardly
if (dict.isDict(name))
{
const dictionary& coeffsDict(dict.subDict(name));
@ -56,30 +57,30 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
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);
word Function1Type;
if (!firstToken.isWord())
{
is.putBack(firstToken);
return autoPtr<Function1<Type>>
(
new Function1s::Constant<Type>(name, is)
);
}
else
// Read the type, or assume constant
const word Function1Type =
firstToken.isWord() ? word(is) : Function1s::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())
{
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);
if (cstrIter == dictionaryConstructorTablePtr_->end())
if (dictCstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function1 type "
@ -90,18 +91,18 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
<< exit(FatalError);
}
const bool haveCoeffsDict = dict.found(name + "Coeffs");
autoPtr<Function1<Type>> funcPtr
(
cstrIter()
dictCstrIter()
(
name,
dict.found(name + "Coeffs")
? dict.subDict(name + "Coeffs")
: dict
haveCoeffsDict ? dict.subDict(name + "Coeffs") : dict
)
);
if (dict.found(name + "Coeffs"))
if (haveCoeffsDict)
{
IOWarningInFunction(dict)
<< "Using deprecated "
@ -111,7 +112,49 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
}
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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,8 +39,10 @@ Foam::Function1s::NonUniformTable<Type>::NonUniformTable
high_(-great),
values_(),
delta_(great),
reader_(TableReader<Type>::New(name, dict, this->values_))
reader_(TableReader<Type>::New(name, dict))
{
values_ = reader_->read(dict);
if (values_.size() < 2)
{
FatalIOErrorInFunction(dict)

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -202,6 +202,9 @@ public:
//- Integrate between two values
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
virtual void write(Ostream& os) const;

View File

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

View File

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

View File

@ -145,8 +145,8 @@ Foam::Function1s::Table<Type>::Table
FieldFunction1<Type, Table<Type>>(name),
boundsHandling_(boundsHandling),
interpolationScheme_(interpolationScheme),
values_(table),
reader_(reader, false)
reader_(reader, false),
values_(table)
{}
@ -172,8 +172,25 @@ Foam::Function1s::Table<Type>::Table
linearInterpolationWeights::typeName
)
),
values_(),
reader_(TableReader<Type>::New(name, dict, this->values_))
reader_(TableReader<Type>::New(name, dict)),
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();
}
@ -185,10 +202,10 @@ Foam::Function1s::Table<Type>::Table(const Table<Type>& tbl)
FieldFunction1<Type, Table<Type>>(tbl),
boundsHandling_(tbl.boundsHandling_),
interpolationScheme_(tbl.interpolationScheme_),
reader_(tbl.reader_, false),
values_(tbl.values_),
tableSamplesPtr_(tbl.tableSamplesPtr_),
interpolatorPtr_(tbl.interpolatorPtr_),
reader_(tbl.reader_, false)
interpolatorPtr_(tbl.interpolatorPtr_)
{}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
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,
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
const dictionary& dict
),
(name, dict, table)
(name, dict)
);
// Constructors
//- Construct from dictionary
TableReader(const dictionary& dict);
//- Default construct
TableReader();
//- Construct and return a clone
virtual autoPtr<TableReader<Type>> clone() const = 0;
@ -86,8 +85,7 @@ public:
static autoPtr<TableReader<Type>> New
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
const dictionary& dict
);
@ -97,12 +95,18 @@ public:
// 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
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
) const = 0;
};
@ -119,22 +123,12 @@ public:
defineTemplateRunTimeSelectionTable(TableReader<Type>, dictionary);
#define makeTableReader(SS, Type) \
#define addTableReader(SS, Type) \
\
defineNamedTemplateTypeNameAndDebug(TableReaders::SS<Type>, 0); \
\
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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -32,8 +32,7 @@ template<class Type>
Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
const dictionary& dict
)
{
if (dict.found("format"))
@ -53,7 +52,7 @@ Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
<< exit(FatalError);
}
return autoPtr<TableReader<Type>>(cstrIter()(name, dict, table));
return autoPtr<TableReader<Type>>(cstrIter()(name, dict));
}
else
{
@ -61,14 +60,14 @@ Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
{
return autoPtr<TableReader<Type>>
(
new TableReaders::Foam<Type>(name, dict, table)
new TableReaders::Foam<Type>(name, dict)
);
}
else
{
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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,21 +23,14 @@ License
\*---------------------------------------------------------------------------*/
#include "TableReader.H"
#include "makeTableReaders.H"
#include "fieldTypes.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "CsvTableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makeTableReaders(scalar);
makeTableReaders(vector);
makeTableReaders(sphericalTensor);
makeTableReaders(symmTensor);
makeTableReaders(tensor);
FOR_ALL_FIELD_TYPES(makeTableReaders);
}
// ************************************************************************* //

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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -71,8 +71,14 @@ public:
// Constructors
//- Construct from name and dictionary
Uniform(const word& name, const dictionary& dict);
//- Inherit constructors
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
@ -89,12 +95,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "Uniform.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

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

View File

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

View File

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

View File

@ -23,33 +23,19 @@ License
\*---------------------------------------------------------------------------*/
#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 "Scale.H"
#include "CodedFunction1.H"
#include "makeFunction1s.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makeFunction1(label);
defineFunction1(label);
namespace Function1s
{
makeFunction1Type(None, label);
makeFunction1Type(Constant, label);
addFunction1(None, label);
addFunction1(Constant, label);
}
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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -31,7 +31,7 @@ namespace Foam
{
namespace Function1s
{
makeScalarFunction1(quadraticRamp);
addScalarFunction1(quadraticRamp);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -76,10 +76,13 @@ public:
typedef Type returnType;
//- Runtime type information
TypeName("Function2");
//- Declare runtime constructor selection table
// Declare runtime constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
@ -92,6 +95,18 @@ public:
(name, dict)
);
declareRunTimeSelectionTable
(
autoPtr,
Function2,
Istream,
(
const word& name,
Istream& is
),
(name, is)
);
// Constructors
@ -99,19 +114,29 @@ public:
Function2(const word& name);
//- Copy constructor
Function2(const Function2<Type>& f1);
Function2(const Function2<Type>& f2);
//- Construct and return a clone
virtual tmp<Function2<Type>> clone() const = 0;
//- Selector
// Selectors
//- Select from dictionary
static autoPtr<Function2<Type>> New
(
const word& name,
const dictionary& dict
);
//- Select from Istream
static autoPtr<Function2<Type>> New
(
const word& name,
const word& Function2Type,
Istream& is
);
//- Destructor
virtual ~Function2();
@ -154,7 +179,7 @@ public:
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); \
defineTemplateRunTimeSelectionTable(Function2<Type>, dictionary);
defineTemplateRunTimeSelectionTable(Function2<Type>, dictionary); \
defineTemplateRunTimeSelectionTable(Function2<Type>, Istream);
#define makeFunction2Type(SS, Type) \
#define addFunction2(SS, Type) \
\
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
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); \
typedef Function2<scalar> scalarFunction2; \

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,10 +23,11 @@ License
\*---------------------------------------------------------------------------*/
#include "Constant.H"
#include "Constant2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/*
template<class Type>
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);
}
}
*/
// * * * * * * * * * * * * * * * * 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
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -125,8 +125,7 @@ Type Foam::Function2s::UniformTable<Type>::value
template<class Type>
Type Foam::Function2s::UniformTable<Type>::
dfdp
Type Foam::Function2s::UniformTable<Type>::dfdp
(
scalar p,
scalar T
@ -154,8 +153,7 @@ dfdp
template<class Type>
Type Foam::Function2s::UniformTable<Type>::
dfdT
Type Foam::Function2s::UniformTable<Type>::dfdT
(
scalar p,
scalar T

View File

@ -23,41 +23,19 @@ License
\*---------------------------------------------------------------------------*/
#include "None2.H"
#include "Constant2.H"
#include "ZeroConstant2.H"
#include "OneConstant2.H"
#include "Scale2.H"
#include "UniformTable2.H"
#include "CodedFunction2.H"
#include "makeFunction2s.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
{
makeFunction2(label);
defineFunction2(label);
namespace Function2s
{
makeFunction2Type(None, label);
makeFunction2Type(Constant, label);
addFunction2(None, label);
addStreamConstructableFunction2(Constant, label);
}
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 "mathematicalConstants.H"
#include "makeFunction1s.H"
#include "makeTableReaders.H"
#include "addToRunTimeSelectionTable.H"
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
trvType;
@ -103,13 +89,7 @@ const trvType trvType::vsType::rootMin
namespace Foam
{
makeFunction1s(trvType, nullArg);
defineTableReader(trvType);
namespace TableReaders
{
makeTableReader(Embedded, trvType);
makeTableReader(Foam, trvType);
}
makeFoamTableReaders(trvType, nullArg);
}

View File

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

View File

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

View File

@ -26,6 +26,8 @@ License
#include "sixDoFAccelerationSource.H"
#include "fvMatrices.H"
#include "geometricOneField.H"
#include "makeFunction1s.H"
#include "makeTableReaders.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * 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;
template<>
@ -97,15 +83,8 @@ const avType avType::vsType::rootMin
namespace Foam
{
makeFunction1s(avType, nullArg);
defineTableReader(avType);
namespace TableReaders
{
makeTableReader(Embedded, avType);
makeTableReader(Foam, avType);
}
makeFoamTableReaders(avType, nullArg);
}

View File

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

View File

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

View File

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

View File

@ -36,8 +36,7 @@ Description
populated using values supplied in the constant properties.
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
InjectionModel.C
@ -51,7 +50,7 @@ SourceFiles
#include "injectionModel.H"
#include "CloudSubModelBase.H"
#include "particle.H"
#include "TimeFunction1.H"
#include "DimensionedFunction1.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -130,7 +129,7 @@ protected:
);
//- Read the mass flow rate function for continuous injections
TimeFunction1<scalar> readMassFlowRate
autoPtr<Function1<scalar>> readMassFlowRate
(
const dictionary& dict,
CloudType& owner,
@ -139,7 +138,7 @@ protected:
//- Read the number of parcels injected per second for continuous
// injections
TimeFunction1<scalar> readParcelsPerSecond
autoPtr<Function1<scalar>> readParcelsPerSecond
(
const dictionary& dict,
CloudType& owner

View File

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

View File

@ -80,7 +80,7 @@ class MomentumLookupTableInjection
const scalar duration_;
//- 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
bool randomise_;

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "PatchFlowRateInjection.H"
#include "TimeFunction1.H"
#include "distribution.H"
#include "mathematicalConstants.H"
#include "surfaceFields.H"
@ -46,10 +45,11 @@ Foam::PatchFlowRateInjection<CloudType>::PatchFlowRateInjection
duration_(this->readDuration(dict, owner)),
concentration_
(
TimeFunction1<scalar>
new Function1s::Dimensioned<scalar>
(
owner.db().time(),
"concentration",
dimTime,
dimless,
this->coeffDict()
)
),
@ -150,7 +150,7 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::nParcelsToInject
{
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;
@ -189,7 +189,7 @@ Foam::scalar Foam::PatchFlowRateInjection<CloudType>::massToInject
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();
}

View File

@ -48,7 +48,6 @@ SourceFiles
#include "InjectionModel.H"
#include "patchInjectionBase.H"
#include "TimeFunction1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -79,7 +78,7 @@ class PatchFlowRateInjection
const scalar duration_;
//- 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]
const scalar parcelConcentration_;

View File

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

View File

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

View File

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

View File

@ -79,7 +79,7 @@ class ReactingLookupTableInjection
const scalar duration_;
//- 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
bool randomise_;

View File

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

View File

@ -82,7 +82,7 @@ class ReactingMultiphaseLookupTableInjection
const scalar duration_;
//- 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
bool randomise_;

View File

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

View File

@ -78,7 +78,7 @@ class ThermoLookupTableInjection
const scalar duration_;
//- 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
bool randomise_;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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