ENH: adjustments for Function1/PatchFunction1
- additional debug information - improve support for dictionary specification of constant, polynomial and table entries. These previously only worked properly for primitiveEntry, which causes confusion. - extend table Function1 to include TableFile functionality. Simplifies switching and modifying content.
This commit is contained in:
parent
0252b4d58d
commit
399c21d76c
@ -1,15 +1,6 @@
|
||||
EXE_INC = \
|
||||
-DFULLDEBUG -g -O0 \
|
||||
-I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
|
||||
-I$(LIB_SRC)/thermophysicalModels/radiation/lnInclude \
|
||||
-I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-DFULLDEBUG -g \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude
|
||||
|
||||
EXE_LIBS = \
|
||||
-llagrangianIntermediate \
|
||||
-lradiationModels \
|
||||
-lregionModels \
|
||||
-lfiniteVolume \
|
||||
-lmeshTools \
|
||||
-lsampling
|
||||
-lmeshTools
|
||||
|
@ -32,7 +32,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvCFD.H"
|
||||
#include "argList.H"
|
||||
#include "IOstreams.H"
|
||||
#include "Function1.H"
|
||||
#include "scalarIndList.H"
|
||||
#include "scalarField.H"
|
||||
@ -40,6 +41,8 @@ Description
|
||||
#include "linearInterpolationWeights.H"
|
||||
#include "splineInterpolationWeights.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -26,11 +26,44 @@ x
|
||||
);
|
||||
|
||||
|
||||
function1 table
|
||||
constant1 constant 100;
|
||||
|
||||
table1 table
|
||||
(
|
||||
(0 0)(10 1)
|
||||
);
|
||||
|
||||
table2
|
||||
{
|
||||
type table;
|
||||
values
|
||||
(
|
||||
(0 0)(10 1)
|
||||
);
|
||||
}
|
||||
|
||||
table3
|
||||
{
|
||||
type table;
|
||||
file "<constant>/table-values";
|
||||
}
|
||||
|
||||
poly1 polynomial
|
||||
(
|
||||
(0 1)
|
||||
(1 1)
|
||||
);
|
||||
|
||||
poly2
|
||||
{
|
||||
type polynomial;
|
||||
coeffs
|
||||
(
|
||||
(0 1)
|
||||
(1 1)
|
||||
);
|
||||
}
|
||||
|
||||
function2
|
||||
{
|
||||
type expression;
|
||||
|
9
applications/test/Function1/case1/constant/table-values
Normal file
9
applications/test/Function1/case1/constant/table-values
Normal file
@ -0,0 +1,9 @@
|
||||
// -*- C++ -*-
|
||||
// Some table values
|
||||
|
||||
(
|
||||
(0 0)
|
||||
(20 1)
|
||||
);
|
||||
|
||||
// ************************************************************************* //
|
@ -53,8 +53,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef CSV_H
|
||||
#define CSV_H
|
||||
#ifndef Function1Types_CSV_H
|
||||
#define Function1Types_CSV_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "TableBase.H"
|
||||
|
@ -52,9 +52,29 @@ Foam::Function1Types::Constant<Type>::Constant
|
||||
Function1<Type>(entryName, dict),
|
||||
value_(Zero)
|
||||
{
|
||||
ITstream& is = dict.lookup(entryName);
|
||||
word entryType(is);
|
||||
is >> value_;
|
||||
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
||||
|
||||
if (eptr && eptr->isStream())
|
||||
{
|
||||
// Primitive (inline) format. Eg,
|
||||
// - key constant 1.2;
|
||||
// - key 1.2;
|
||||
|
||||
ITstream& is = eptr->stream();
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
is.skip(); // Discard leading 'constant'
|
||||
}
|
||||
is >> value_;
|
||||
dict.checkITstream(is, entryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dictionary format. Eg,
|
||||
// key { type constant; value 1.2; }
|
||||
|
||||
dict.readEntry("value", value_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,10 +91,10 @@ Foam::Function1Types::Constant<Type>::Constant
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::Constant<Type>::Constant(const Constant<Type>& cnst)
|
||||
Foam::Function1Types::Constant<Type>::Constant(const Constant<Type>& rhs)
|
||||
:
|
||||
Function1<Type>(cnst),
|
||||
value_(cnst.value_)
|
||||
Function1<Type>(rhs),
|
||||
value_(rhs.value_)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -30,18 +30,31 @@ Class
|
||||
Description
|
||||
Templated function that returns a constant value.
|
||||
|
||||
Usage - for entry \<entryName\> returning the value <value>:
|
||||
Usage - for entry \<entryName\> returning the value \<value\>,
|
||||
can be specified is different formats.
|
||||
|
||||
Inline specification:
|
||||
\verbatim
|
||||
<entryName> constant <value>
|
||||
<entryName> constant <value>
|
||||
\endverbatim
|
||||
|
||||
Dictionary format:
|
||||
\verbatim
|
||||
<entryName>
|
||||
{
|
||||
type constant;
|
||||
value <value>;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
Constant.C
|
||||
ConstantI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Constant_H
|
||||
#define Constant_H
|
||||
#ifndef Function1Types_Constant_H
|
||||
#define Function1Types_Constant_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
@ -93,7 +106,7 @@ public:
|
||||
Constant(const word& entryName, Istream& is);
|
||||
|
||||
//- Copy constructor
|
||||
explicit Constant(const Constant<Type>& cnst);
|
||||
explicit Constant(const Constant<Type>& rhs);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<Function1<Type>> clone() const
|
||||
@ -117,7 +130,7 @@ public:
|
||||
//- Return value as a function of (scalar) independent variable
|
||||
virtual tmp<Field<Type>> value(const scalarField& x) const;
|
||||
|
||||
//- Write in dictionary format
|
||||
//- Write as primitive (inline) format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
@ -96,8 +96,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef function1Types_Cosine_H
|
||||
#define function1Types_Cosine_H
|
||||
#ifndef Function1Types_Cosine_H
|
||||
#define Function1Types_Cosine_H
|
||||
|
||||
#include "Sine.H"
|
||||
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
//- Construct from entry name
|
||||
explicit Function1(const word& entryName);
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
//- Construct from entry name and dictionary (unused)
|
||||
Function1(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy construct
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -49,6 +49,10 @@ Foam::Function1<Type>::New
|
||||
{
|
||||
// Dictionary entry
|
||||
|
||||
DebugInFunction
|
||||
<< "For " << entryName << " with dictionary entries: "
|
||||
<< flatOutput(coeffs->toc()) << nl;
|
||||
|
||||
coeffs->readEntry
|
||||
(
|
||||
"type",
|
||||
@ -62,17 +66,21 @@ Foam::Function1<Type>::New
|
||||
else if (eptr)
|
||||
{
|
||||
// Primitive entry
|
||||
// - non-word : value for constant function
|
||||
// - word : the modelType
|
||||
// - non-word : value for constant function
|
||||
|
||||
DebugInFunction
|
||||
<< "For " << entryName << " with primitive entry" << nl;
|
||||
|
||||
ITstream& is = eptr->stream();
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
if (!firstToken.isWord())
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
// A value
|
||||
is.putBack(firstToken);
|
||||
modelType = is.peek().wordToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
// A value - compatibility for reading constant
|
||||
|
||||
const Type constValue = pTraits<Type>(is);
|
||||
|
||||
@ -81,10 +89,6 @@ Foam::Function1<Type>::New
|
||||
new Function1Types::Constant<Type>(entryName, constValue)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
modelType = firstToken.wordToken();
|
||||
}
|
||||
|
||||
// Fallthrough
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
//- Construct from entry name
|
||||
explicit function1Base(const word& entryName);
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
//- Construct from entry name and dictionary (unused)
|
||||
function1Base(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy construct
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,13 +31,13 @@ Description
|
||||
|
||||
Example usage for limiting a polynomial:
|
||||
\verbatim
|
||||
limitedPolyTest limitRange;
|
||||
limitedPolyTestCoeffs
|
||||
<entryName>
|
||||
{
|
||||
min 0.4;
|
||||
max 1.4;
|
||||
type limitRange;
|
||||
min 0.4;
|
||||
max 1.4;
|
||||
|
||||
value polynomial
|
||||
value polynomial
|
||||
(
|
||||
(5 1)
|
||||
(-2 2)
|
||||
@ -53,16 +53,19 @@ Description
|
||||
- poly(x) for 0.4 < x < 1.4.
|
||||
|
||||
|
||||
Example usage for limiting a table
|
||||
Example usage for limiting a file-based table:
|
||||
\verbatim
|
||||
limitedTableFileTest limitRange;
|
||||
limitedTableFileTestCoeffs
|
||||
<entryName>
|
||||
{
|
||||
min 0.4;
|
||||
max 1.4;
|
||||
type limitRange;
|
||||
min 0.4;
|
||||
max 1.4;
|
||||
|
||||
value tableFile;
|
||||
file "<system>/fanCurve.txt";
|
||||
value
|
||||
{
|
||||
type table;
|
||||
file "<system>/fanCurve.txt";
|
||||
}
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
@ -79,8 +82,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef LimitRange_H
|
||||
#define LimitRange_H
|
||||
#ifndef Function1Types_LimitRange_H
|
||||
#define Function1Types_LimitRange_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
|
@ -40,8 +40,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OneConstant_H
|
||||
#define OneConstant_H
|
||||
#ifndef Function1Types_OneConstant_H
|
||||
#define Function1Types_OneConstant_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
@ -110,7 +110,7 @@ public:
|
||||
const scalarField& x2
|
||||
) const;
|
||||
|
||||
//- Write in dictionary format
|
||||
//- Write as primitive (inline) format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,6 +28,37 @@ License
|
||||
|
||||
#include "PolynomialEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Polynomial<Type>::checkCoefficients()
|
||||
{
|
||||
if (coeffs_.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Invalid (empty) polynomial coefficients for "
|
||||
<< this->name() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
for (const auto& coeff : coeffs_)
|
||||
{
|
||||
if (mag(coeff.second() + pTraits<Type>::one) < ROOTVSMALL)
|
||||
{
|
||||
canIntegrate_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug && !canIntegrate_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Polynomial " << this->name() << " cannot be integrated"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
@ -41,37 +72,31 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
coeffs_(),
|
||||
canIntegrate_(true)
|
||||
{
|
||||
ITstream& is = dict.lookup(entryName);
|
||||
const word entryType(is);
|
||||
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
||||
|
||||
is >> coeffs_;
|
||||
|
||||
if (!coeffs_.size())
|
||||
if (eptr && eptr->isStream())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Invalid (empty) polynomial coefficients for "
|
||||
<< this->name() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
// Primitive (inline) format. Eg,
|
||||
// key polynomial ((0 0) (10 1));
|
||||
|
||||
forAll(coeffs_, i)
|
||||
{
|
||||
if (mag(coeffs_[i].second() + pTraits<Type>::one) < ROOTVSMALL)
|
||||
ITstream& is = eptr->stream();
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
canIntegrate_ = false;
|
||||
break;
|
||||
is.skip(); // Discard leading 'polynomial'
|
||||
}
|
||||
is >> this->coeffs_;
|
||||
dict.checkITstream(is, entryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dictionary format - "values" lookup. Eg,
|
||||
//
|
||||
// key { type polynomial; coeffs ((0 0) (10 1)); }
|
||||
|
||||
dict.readEntry("coeffs", this->coeffs_);
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
if (!canIntegrate_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Polynomial " << this->name() << " cannot be integrated"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
this->checkCoefficients();
|
||||
}
|
||||
|
||||
|
||||
@ -86,32 +111,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
|
||||
coeffs_(coeffs),
|
||||
canIntegrate_(true)
|
||||
{
|
||||
if (!coeffs_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Invalid (empty) polynomial coefficients for "
|
||||
<< this->name() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
forAll(coeffs_, i)
|
||||
{
|
||||
if (mag(coeffs_[i].second() + 1) < ROOTVSMALL)
|
||||
{
|
||||
canIntegrate_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
if (!canIntegrate_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Polynomial " << this->name() << " cannot be integrated"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
this->checkCoefficients();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,21 +32,35 @@ Description
|
||||
list of Tuple2's. Data is input in the form,
|
||||
e.g. for an entry \<entryName\> that describes y = x^2 + 2x^3
|
||||
|
||||
Inline specification:
|
||||
\verbatim
|
||||
<entryName> polynomial
|
||||
(
|
||||
(1 2)
|
||||
(2 3)
|
||||
(1 2)
|
||||
(2 3)
|
||||
);
|
||||
\endverbatim
|
||||
|
||||
Dictionary format:
|
||||
\verbatim
|
||||
<entryName>
|
||||
{
|
||||
type polynomial;
|
||||
coeffs
|
||||
(
|
||||
(1 2)
|
||||
(2 3)
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
PolynomialEntry.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PolynomialEntry_H
|
||||
#define PolynomialEntry_H
|
||||
#ifndef Function1Types_Polynomial_H
|
||||
#define Function1Types_Polynomial_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "Tuple2.H"
|
||||
@ -72,12 +87,15 @@ class Polynomial
|
||||
//- Polynomial coefficients - list of prefactor, exponent
|
||||
List<Tuple2<Type, Type>> coeffs_;
|
||||
|
||||
//- Flag to indicate whether poly can be integrated
|
||||
//- Flag to indicate whether polynomial can be integrated
|
||||
bool canIntegrate_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Check coefficients and if polynomial can be integrated
|
||||
void checkCoefficients();
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const Polynomial<Type>&) = delete;
|
||||
|
||||
@ -125,8 +143,7 @@ public:
|
||||
//- Integrate between two (scalar) values
|
||||
virtual Type integrate(const scalar x1, const scalar x2) const;
|
||||
|
||||
|
||||
//- Write in dictionary format
|
||||
//- Write as primitive (inline) format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
};
|
||||
|
@ -63,8 +63,8 @@ Description
|
||||
Where:
|
||||
\table
|
||||
Property | Description | Required
|
||||
value | Function of type Function1<Type> | yes
|
||||
scale | Scaling function of type Function1<scalar> | yes
|
||||
value | Function of type Function1<Type> | yes
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
@ -72,8 +72,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Scale_H
|
||||
#define Scale_H
|
||||
#ifndef Function1Types_Scale_H
|
||||
#define Function1Types_Scale_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
|
@ -98,8 +98,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef function1Types_Sine_H
|
||||
#define function1Types_Sine_H
|
||||
#ifndef Function1Types_Sine_H
|
||||
#define Function1Types_Sine_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
|
@ -101,8 +101,8 @@ Note
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef function1Types_Square_H
|
||||
#define function1Types_Square_H
|
||||
#ifndef Function1Types_Square_H
|
||||
#define Function1Types_Square_H
|
||||
|
||||
#include "Sine.H"
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,11 +37,53 @@ Foam::Function1Types::Table<Type>::Table
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
TableBase<Type>(entryName, dict)
|
||||
TableBase<Type>(entryName, dict),
|
||||
fName_()
|
||||
{
|
||||
ITstream& is = dict.lookup(entryName);
|
||||
const word entryType(is);
|
||||
is >> this->table_;
|
||||
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
||||
|
||||
if (eptr && eptr->isStream())
|
||||
{
|
||||
// Primitive (inline) format. Eg,
|
||||
// key table ((0 0) (10 1));
|
||||
|
||||
ITstream& is = eptr->stream();
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
is.skip(); // Discard leading 'table'
|
||||
}
|
||||
is >> this->table_;
|
||||
dict.checkITstream(is, entryName);
|
||||
}
|
||||
else if (dict.readIfPresent("file", fName_))
|
||||
{
|
||||
// Dictionary format - "file" lookup. Eg,
|
||||
// key { type table; file "name"; }
|
||||
|
||||
fileName expandedFile(fName_);
|
||||
expandedFile.expand();
|
||||
|
||||
autoPtr<ISstream> isPtr(fileHandler().NewIFstream(expandedFile));
|
||||
if (isPtr && isPtr->good())
|
||||
{
|
||||
*isPtr >> this->table_;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Cannot open file: " << expandedFile << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dictionary format - "values" lookup. Eg,
|
||||
//
|
||||
// key { type table; values ((0 0) (10 1)); }
|
||||
|
||||
dict.readEntry("values", this->table_);
|
||||
}
|
||||
|
||||
TableBase<Type>::check();
|
||||
}
|
||||
|
||||
@ -49,8 +91,36 @@ Foam::Function1Types::Table<Type>::Table
|
||||
template<class Type>
|
||||
Foam::Function1Types::Table<Type>::Table(const Table<Type>& tbl)
|
||||
:
|
||||
TableBase<Type>(tbl)
|
||||
TableBase<Type>(tbl),
|
||||
fName_(tbl.fName_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::Table<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os.endEntry();
|
||||
|
||||
os.beginBlock(word(this->name() + "Coeffs"));
|
||||
|
||||
// Note: for TableBase write the dictionary entries it needs but not
|
||||
// the values themselves
|
||||
TableBase<Type>::writeEntries(os);
|
||||
|
||||
if (fName_.empty())
|
||||
{
|
||||
os.writeEntry("values", this->table_);
|
||||
}
|
||||
else
|
||||
{
|
||||
os.writeEntry("file", fName_);
|
||||
}
|
||||
|
||||
os.endBlock();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -30,10 +30,12 @@ Class
|
||||
Description
|
||||
Templated table container function.
|
||||
|
||||
Items are stored in a list of Tuple2's. First column is always stored as
|
||||
scalar entries. Data is read in Tuple2 form.
|
||||
Items are stored in a list of Tuple2, with the first column always
|
||||
being a scalar and the second column (the lookup value) in
|
||||
required data type.
|
||||
|
||||
Usage:
|
||||
Inline specification.
|
||||
\verbatim
|
||||
<entryName> table
|
||||
(
|
||||
@ -42,13 +44,43 @@ Description
|
||||
);
|
||||
\endverbatim
|
||||
|
||||
Dictionary specification, external data reference.
|
||||
\verbatim
|
||||
<entryName>
|
||||
{
|
||||
type table;
|
||||
file "<case>/path/tableValues";
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Dictionary specification, embedded content
|
||||
Dictionary form.
|
||||
\verbatim
|
||||
<entryName>
|
||||
{
|
||||
type table;
|
||||
values
|
||||
(
|
||||
(0.0 (1 2 3))
|
||||
(1.0 (4 5 6))
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Note
|
||||
The external data reference (using the \c file keyword) is
|
||||
used in preference to the \c values specification.
|
||||
|
||||
See Also
|
||||
Foam::Function1Types::TableFile
|
||||
|
||||
SourceFiles
|
||||
Table.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Table_H
|
||||
#define Table_H
|
||||
#ifndef Function1Types_Table_H
|
||||
#define Function1Types_Table_H
|
||||
|
||||
#include "TableBase.H"
|
||||
|
||||
@ -68,6 +100,12 @@ class Table
|
||||
:
|
||||
public TableBase<Type>
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Input name for file-based input (optional)
|
||||
fileName fName_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
@ -81,10 +119,10 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
//- Construct from entry name and dictionary.
|
||||
Table(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
explicit Table(const Table<Type>& tbl);
|
||||
|
||||
//- Construct and return a clone
|
||||
@ -96,6 +134,12 @@ public:
|
||||
|
||||
//- Destructor
|
||||
virtual ~Table() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write coefficients in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TableBase_H
|
||||
#define TableBase_H
|
||||
#ifndef Function1Types_TableBase_H
|
||||
#define Function1Types_TableBase_H
|
||||
|
||||
#include "tableBounds.H"
|
||||
#include "Function1.H"
|
||||
|
@ -51,13 +51,16 @@ Description
|
||||
);
|
||||
\endverbatim
|
||||
|
||||
See Also
|
||||
Foam::Function1Types::Table
|
||||
|
||||
SourceFiles
|
||||
TableFile.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TableFile_H
|
||||
#define TableFile_H
|
||||
#ifndef Function1Types_TableFile_H
|
||||
#define Function1Types_TableFile_H
|
||||
|
||||
#include "TableBase.H"
|
||||
|
||||
|
@ -43,8 +43,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Uniform_H
|
||||
#define Uniform_H
|
||||
#ifndef Function1Types_Uniform_H
|
||||
#define Function1Types_Uniform_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
|
@ -31,8 +31,17 @@ Description
|
||||
Templated function that returns the corresponding 0 (zero).
|
||||
|
||||
Usage:
|
||||
Inline specification:
|
||||
\verbatim
|
||||
<entryName> zero;
|
||||
<entryName> zero;
|
||||
\endverbatim
|
||||
|
||||
In dictionary format:
|
||||
\verbatim
|
||||
<entryName>
|
||||
{
|
||||
type zero;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
@ -40,8 +49,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ZeroConstant_H
|
||||
#define ZeroConstant_H
|
||||
#ifndef Function1Types_ZeroConstant_H
|
||||
#define Function1Types_ZeroConstant_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
@ -94,7 +103,7 @@ public:
|
||||
//- Integrate between two values
|
||||
virtual inline Type integrate(const scalar x1, const scalar x2) const;
|
||||
|
||||
//- Write in dictionary format
|
||||
//- Write as primitive (inline) format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
@ -39,8 +39,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef halfCosineRamp_H
|
||||
#define halfCosineRamp_H
|
||||
#ifndef Function1Types_halfCosineRamp_H
|
||||
#define Function1Types_halfCosineRamp_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -39,8 +39,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef linearRamp_H
|
||||
#define linearRamp_H
|
||||
#ifndef Function1Types_linearRamp_H
|
||||
#define Function1Types_linearRamp_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -39,8 +39,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef quadraticRamp_H
|
||||
#define quadraticRamp_H
|
||||
#ifndef Function1Types_quadraticRamp_H
|
||||
#define Function1Types_quadraticRamp_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -39,8 +39,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef quarterCosineRamp_H
|
||||
#define quarterCosineRamp_H
|
||||
#ifndef Function1Types_quarterCosineRamp_H
|
||||
#define Function1Types_quarterCosineRamp_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -38,8 +38,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef quarterSineRamp_H
|
||||
#define quarterSineRamp_H
|
||||
#ifndef Function1Types_quarterSineRamp_H
|
||||
#define Function1Types_quarterSineRamp_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -66,8 +66,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ramp_H
|
||||
#define ramp_H
|
||||
#ifndef Function1Types_ramp_H
|
||||
#define Function1Types_ramp_H
|
||||
|
||||
#include "Function1.H"
|
||||
|
||||
|
@ -38,8 +38,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef stepFunction_H
|
||||
#define stepFunction_H
|
||||
#ifndef Function1Types_stepFunction_H
|
||||
#define Function1Types_stepFunction_H
|
||||
|
||||
#include "ramp.H"
|
||||
|
||||
|
@ -36,15 +36,14 @@ Description
|
||||
|
||||
For example,
|
||||
\verbatim
|
||||
pistonPositionTime table ( (0 0.13) (0.020 0.03) );
|
||||
pistonPositionTime table ((0 0.13) (0.020 0.03));
|
||||
\endverbatim
|
||||
|
||||
or with a tableFile
|
||||
or
|
||||
\verbatim
|
||||
pistonPositionTime tableFile;
|
||||
pistonPositionTimeCoeffs
|
||||
pistonPositionTime
|
||||
{
|
||||
fileName "data";
|
||||
type table;
|
||||
file "<constant>/pistonPosition.dat";
|
||||
outOfBounds clamp;
|
||||
interpolationScheme linear;
|
||||
}
|
||||
@ -76,7 +75,7 @@ class freePiston
|
||||
:
|
||||
public engineTime
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
autoPtr<Function1<scalar>> pistonPositionTime_;
|
||||
|
||||
|
@ -30,8 +30,6 @@ License
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "volFields.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "Tuple2.H"
|
||||
#include "PolynomialEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -71,11 +71,11 @@ Usage
|
||||
{
|
||||
type fanPressure;
|
||||
direction in;
|
||||
fanCurve tableFile;
|
||||
fanCurveCoeffs
|
||||
fanCurve
|
||||
{
|
||||
file "<constant>/fanCurve";
|
||||
outOfBounds clamp;
|
||||
type table;
|
||||
file "<constant>/fanCurve";
|
||||
outOfBounds clamp; // Optional out-of-bounds handling
|
||||
}
|
||||
p0 uniform 0;
|
||||
value uniform 0;
|
||||
|
@ -101,52 +101,43 @@ Foam::PatchFunction1Types::ConstantField<Type>::getValue
|
||||
}
|
||||
ITstream& is = eptr->stream();
|
||||
|
||||
// Read first token
|
||||
token firstToken(is);
|
||||
|
||||
if (firstToken.isWord())
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
if
|
||||
(
|
||||
firstToken.wordToken() == "uniform"
|
||||
|| firstToken.wordToken() == "constant"
|
||||
)
|
||||
const word contentType(is);
|
||||
|
||||
if (contentType == "uniform" || contentType == "constant")
|
||||
{
|
||||
is >> uniformValue;
|
||||
fld.setSize(len);
|
||||
fld.resize(len);
|
||||
fld = uniformValue;
|
||||
}
|
||||
else if (firstToken.wordToken() == "nonuniform")
|
||||
else if (contentType == "nonuniform")
|
||||
{
|
||||
List<Type>& list = fld;
|
||||
is >> list;
|
||||
isUniform = false;
|
||||
|
||||
const label currentSize = fld.size();
|
||||
if (currentSize != len)
|
||||
is >> static_cast<List<Type>&>(fld);
|
||||
const label lenRead = fld.size();
|
||||
if (len != lenRead)
|
||||
{
|
||||
if
|
||||
(
|
||||
len < currentSize
|
||||
len < lenRead
|
||||
&& FieldBase::allowConstructFromLargerSize
|
||||
)
|
||||
{
|
||||
#ifdef FULLDEBUG
|
||||
IOWarningInFunction(dict)
|
||||
<< "Sizes do not match. "
|
||||
<< "Re-sizing " << currentSize
|
||||
<< " entries to " << len
|
||||
<< endl;
|
||||
<< "Sizes do not match. Truncating " << lenRead
|
||||
<< " entries to " << len << endl;
|
||||
#endif
|
||||
|
||||
// Resize (shrink) the data
|
||||
fld.setSize(len);
|
||||
// Truncate the data
|
||||
fld.resize(len);
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "size " << fld.size()
|
||||
<< " is not equal to the given value of " << len
|
||||
<< "size " << lenRead
|
||||
<< " is not equal to the expected length " << len
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
@ -156,15 +147,15 @@ Foam::PatchFunction1Types::ConstantField<Type>::getValue
|
||||
isUniform = false;
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Expected keyword 'uniform', 'nonuniform' or 'constant'"
|
||||
<< ", found " << firstToken.wordToken()
|
||||
<< ", found " << contentType
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is.putBack(firstToken);
|
||||
// Uniform (constant) field
|
||||
is >> uniformValue;
|
||||
fld.setSize(len);
|
||||
fld.resize(len);
|
||||
fld = uniformValue;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -49,6 +49,10 @@ Foam::PatchFunction1<Type>::New
|
||||
{
|
||||
// Dictionary entry
|
||||
|
||||
DebugInFunction
|
||||
<< "For " << entryName << " with dictionary entries: "
|
||||
<< flatOutput(coeffs->toc()) << nl;
|
||||
|
||||
coeffs->readEntry
|
||||
(
|
||||
"type",
|
||||
@ -60,18 +64,21 @@ Foam::PatchFunction1<Type>::New
|
||||
else if (eptr)
|
||||
{
|
||||
// Primitive entry
|
||||
// - non-word : value for constant (uniform) function
|
||||
// - word : the modelType, or uniform/nonuniform
|
||||
// - non-word : value for constant (uniform) function
|
||||
|
||||
DebugInFunction
|
||||
<< "For " << entryName << " with primitive entry" << nl;
|
||||
|
||||
ITstream& is = eptr->stream();
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
// Compatibility for reading straight fields
|
||||
if (!firstToken.isWord())
|
||||
if (is.peek().isWord())
|
||||
{
|
||||
// A value
|
||||
is.putBack(firstToken);
|
||||
modelType = is.peek().wordToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
// A value - compatibility for reading uniform (constant) field
|
||||
|
||||
const Type constValue = pTraits<Type>(is);
|
||||
|
||||
@ -88,8 +95,6 @@ Foam::PatchFunction1<Type>::New
|
||||
);
|
||||
}
|
||||
|
||||
modelType = firstToken.wordToken();
|
||||
|
||||
// Looks like a normal field entry?
|
||||
if (modelType == "uniform" || modelType == "nonuniform")
|
||||
{
|
||||
|
@ -24,10 +24,10 @@ boundaryField
|
||||
inlet
|
||||
{
|
||||
type flowRateInletVelocity;
|
||||
massFlowRate tableFile;
|
||||
massFlowRateCoeffs
|
||||
massFlowRate
|
||||
{
|
||||
file "<constant>/massLossRate";
|
||||
type table;
|
||||
file "<constant>/massLossRate";
|
||||
}
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
|
@ -25,11 +25,10 @@ boundaryField
|
||||
{
|
||||
type fanPressure;
|
||||
direction in;
|
||||
fanCurve tableFile;
|
||||
fanCurveCoeffs
|
||||
fanCurve
|
||||
{
|
||||
file "<constant>/FluxVsdP.dat";
|
||||
// readerType openFoam; // Default
|
||||
type table;
|
||||
file "<constant>/FluxVsdP.dat";
|
||||
// outOfBounds clamp; // Default
|
||||
}
|
||||
//nonDimensional true;
|
||||
|
@ -59,8 +59,11 @@ functions
|
||||
type setTimeStep;
|
||||
libs (utilityFunctionObjects);
|
||||
enabled yes;
|
||||
deltaT tableFile;
|
||||
file "<system>/deltaTvalues";
|
||||
deltaT
|
||||
{
|
||||
type table;
|
||||
file "<system>/deltaTvalues";
|
||||
}
|
||||
}
|
||||
|
||||
minMaxp
|
||||
|
Loading…
Reference in New Issue
Block a user