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:
Mark Olesen
2021-04-20 11:15:41 +02:00
parent 0252b4d58d
commit 399c21d76c
39 changed files with 437 additions and 223 deletions

View File

@ -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();
}
// ************************************************************************* //

View File

@ -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;
};

View File

@ -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"