Function1::Table: simplified and rationalised

TableBase, TableFile and Table now combined into a single simpler Table class
which handle both the reading of embedded and file data using the generalised
TableReader.  The new EmbeddedTableReader handles the embedded data reading
providing the functionality of the original Table class within the same
structure that can read the data from separate files.

The input format defaults to 'embedded' unless the 'file' entry is present and
the Table class is added to the run-time selection table under the name 'table'
and 'tableFile' which provides complete backward comparability.  However it is
advisable to migrate cases to use the new 'table' entry and all tutorial cases
have been updated.
This commit is contained in:
Henry Weller
2020-11-16 23:48:47 +00:00
parent 37ebdfe36e
commit 4e183e33d4
43 changed files with 377 additions and 821 deletions

View File

@ -52,7 +52,7 @@ Description
\verbatim
type function1;
function tableFile;
function table;
functionCoeffs
{
file "filename.csv";

View File

@ -30,7 +30,7 @@ Description
Control settings are read from the $FOAM_CASE/system/noiseDict dictionary,
or user-specified dictionary using the -dict option. Pressure data is
read using a TableFile Function1:
read using a Table Function1:
Usage
\verbatim
@ -72,7 +72,7 @@ Usage
- one-third-octave-band pressure spectrum
See also
TableFile.H
Table.H
noiseFFT.H
\*---------------------------------------------------------------------------*/
@ -81,7 +81,7 @@ See also
#include "noiseFFT.H"
#include "argList.H"
#include "Time.H"
#include "TableFile.H"
#include "Table.H"
#include "IOdictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -134,7 +134,7 @@ int main(int argc, char *argv[])
#include "createFields.H"
Info<< "Reading data file" << endl;
Function1s::TableFile<scalar> pData
Function1s::Table<scalar> pData
(
"pressure",
dict.subDict("pressureData")

View File

@ -97,7 +97,7 @@ primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C
primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C
primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C
primitives/functions/Function1/Table/tableBase.C
primitives/functions/Function1/TableFile/TableReader/makeTableReaders.C
primitives/functions/Function1/Table/TableReader/makeTableReaders.C
primitives/functions/Function2/makeFunction2s.C

View File

@ -233,10 +233,8 @@ public:
#define makeNamedFunction1Type(SS, Type, Name) \
\
defineNamedTemplateTypeNameAndDebug(Function1s::SS<Type>, 0); \
\
Function1<Type>::adddictionaryConstructorToTable<Function1s::SS<Type>> \
addFunction1##SS##Type##ConstructorToTable_(#Name);
addFunction1##Name##Type##ConstructorToTable_(#Name);
#define makeScalarFunction1(SS) \
@ -257,7 +255,7 @@ public:
makeFunction1Type(Sine, Type); \
makeFunction1Type(Square, Type); \
makeFunction1Type(Table, Type); \
makeFunction1Type(TableFile, Type); \
makeNamedFunction1Type(Table, Type, tableFile); \
makeFunction1Type(Scale, Type); \
makeFunction1Type(Coded, Type);

View File

@ -24,40 +24,114 @@ License
\*---------------------------------------------------------------------------*/
#include "Table.H"
#include "linearInterpolationWeights.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
Foam::Function1s::Table<Type>::Table
(
const word& entryName,
const dictionary& dict
)
:
TableBase<Type, Table<Type>>(entryName, dict)
const Foam::interpolationWeights&
Foam::Function1s::Table<Type>::interpolator() const
{
if (!dict.found(entryName))
if (interpolatorPtr_.empty())
{
dict.lookup("values") >> this->table_;
}
else
{
Istream& is(dict.lookup(entryName));
word entryType(is);
if (is.eof())
// Re-work table into linear list
tableSamplesPtr_.reset(new scalarField(table_.size()));
scalarField& tableSamples = tableSamplesPtr_();
forAll(table_, i)
{
dict.lookup("values") >> this->table_;
}
else
{
is >> this->table_;
tableSamples[i] = table_[i].first();
}
interpolatorPtr_ = interpolationWeights::New
(
interpolationScheme_,
tableSamples
);
}
TableBase<Type, Table<Type>>::check();
return interpolatorPtr_();
}
template<class Type>
void Foam::Function1s::Table<Type>::check() const
{
if (!table_.size())
{
FatalErrorInFunction
<< "Table for entry " << this->name() << " is invalid (empty)"
<< nl << exit(FatalError);
}
label n = table_.size();
scalar prevValue = table_[0].first();
for (label i = 1; i < n; ++i)
{
const scalar currValue = table_[i].first();
// avoid duplicate values (divide-by-zero error)
if (currValue <= prevValue)
{
FatalErrorInFunction
<< "out-of-order value: " << currValue << " at index " << i
<< exit(FatalError);
}
prevValue = currValue;
}
}
template<class Type>
Foam::scalar Foam::Function1s::Table<Type>::bound
(
const scalar x
) const
{
const bool under = x < table_.first().first();
const bool over = x > table_.last().first();
auto errorMessage = [&]()
{
return "value (" + name(x) + ") " + (under ? "under" : "over") + "flow";
};
if (under || over)
{
switch (boundsHandling_)
{
case tableBase::boundsHandling::error:
{
FatalErrorInFunction
<< errorMessage() << nl << exit(FatalError);
break;
}
case tableBase::boundsHandling::warn:
{
WarningInFunction
<< errorMessage() << nl << endl;
break;
}
case tableBase::boundsHandling::clamp:
{
break;
}
case tableBase::boundsHandling::repeat:
{
const scalar t0 = table_.first().first();
const scalar t1 = table_.last().first();
const scalar dt = t1 - t0;
const label n = floor((x - t0)/dt);
return x - n*dt;
}
}
}
return x;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::Table<Type>::Table
(
@ -67,20 +141,52 @@ Foam::Function1s::Table<Type>::Table
const List<Tuple2<scalar, Type>>& table
)
:
TableBase<Type, Table<Type>>
(
name,
boundsHandling,
interpolationScheme,
table
)
FieldFunction1<Type, Table<Type>>(name),
boundsHandling_(boundsHandling),
interpolationScheme_(interpolationScheme),
table_(table)
{}
template<class Type>
Foam::Function1s::Table<Type>::Table
(
const word& name,
const dictionary& dict
)
:
FieldFunction1<Type, Table<Type>>(name),
boundsHandling_
(
dict.found("outOfBounds")
? tableBase::boundsHandlingNames_.read(dict.lookup("outOfBounds"))
: tableBase::boundsHandling::clamp
),
interpolationScheme_
(
dict.lookupOrDefault<word>
(
"interpolationScheme",
linearInterpolationWeights::typeName
)
),
table_(),
reader_(TableReader<Type>::New(name, dict, this->table_))
{
check();
}
template<class Type>
Foam::Function1s::Table<Type>::Table(const Table<Type>& tbl)
:
TableBase<Type, Table<Type>>(tbl)
FieldFunction1<Type, Table<Type>>(tbl),
boundsHandling_(tbl.boundsHandling_),
interpolationScheme_(tbl.interpolationScheme_),
table_(tbl.table_),
tableSamplesPtr_(tbl.tableSamplesPtr_),
interpolatorPtr_(tbl.interpolatorPtr_),
reader_(tbl.reader_, false)
{}
@ -94,14 +200,130 @@ Foam::Function1s::Table<Type>::~Table()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::Table<Type>::writeEntries
Type Foam::Function1s::Table<Type>::value
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
const scalar x
) const
{
os << indent << "values" << table
<< token::END_STATEMENT << endl;
const scalar bx = bound(x);
Type y = Zero;
interpolator().valueWeights(bx, indices_, weights_);
forAll(indices_, i)
{
y += weights_[i]*table_[indices_[i]].second();
}
return y;
}
template<class Type>
Type Foam::Function1s::Table<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
const scalar bx1 = bound(x1), bx2 = bound(x2);
Type sumY = Zero;
interpolator().integrationWeights(bx1, bx2, indices_, weights_);
forAll(indices_, i)
{
sumY += weights_[i]*table_[indices_[i]].second();
}
if (boundsHandling_ == tableBase::boundsHandling::repeat)
{
const scalar t0 = table_.first().first();
const scalar t1 = table_.last().first();
const scalar dt = t1 - t0;
const label n = floor((x2 - t0)/dt) - floor((x1 - t0)/dt);
if (n != 0)
{
Type sumY01 = Zero;
interpolator().integrationWeights(t0, t1, indices_, weights_);
forAll(indices_, i)
{
sumY01 += weights_[i]*table_[indices_[i]].second();
}
sumY += n*sumY01;
}
}
return sumY;
}
template<class Type>
Foam::tmp<Foam::scalarField>
Foam::Function1s::Table<Type>::x() const
{
tmp<scalarField> tfld(new scalarField(table_.size(), 0.0));
scalarField& fld = tfld.ref();
forAll(table_, i)
{
fld[i] = table_[i].first();
}
return tfld;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::Function1s::Table<Type>::y() const
{
tmp<Field<Type>> tfld(new Field<Type>(table_.size(), Zero));
Field<Type>& fld = tfld.ref();
forAll(table_, i)
{
fld[i] = table_[i].second();
}
return tfld;
}
template<class Type>
void Foam::Function1s::Table<Type>::writeData
(
Ostream& os
) const
{
Function1<Type>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
writeEntryIfDifferent
(
os,
"outOfBounds",
tableBase::boundsHandlingNames_[tableBase::boundsHandling::clamp],
tableBase::boundsHandlingNames_[boundsHandling_]
);
writeEntryIfDifferent
(
os,
"interpolationScheme",
linearInterpolationWeights::typeName,
interpolationScheme_
);
reader_->write(os, table_);
os << decrIndent << indent << token::END_BLOCK << endl;
}

View File

@ -25,10 +25,10 @@ Class
Foam::Function1s::Table
Description
Templated table container function.
Templated interpolated tabulated data Function1.
Items are stored in a list of Tuple2's. First column is always stored as
scalar entries. Data is read in Tuple2 form.
scalar entries. Data is read in Tuple2 form:
Usage:
\verbatim
@ -39,32 +39,93 @@ Description
);
\endverbatim
The data may be read from a separate file in either native or CSV format:
Usage:
\verbatim
<entryName> table;
file "<file path>"; // Name/path of thedata file
format foam; // data format (optional)
outOfBounds clamp; // optional out-of-bounds handling
interpolationScheme linear; // optional interpolation method
\endverbatim
SourceFiles
Table.C
See also
FoamTableReader.C
CsvTableReader.C
\*---------------------------------------------------------------------------*/
#ifndef Table_H
#define Table_H
#include "TableBase.H"
#include "tableBase.H"
#include "Function1.H"
#include "TableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class interpolationWeights;
namespace Function1s
{
/*---------------------------------------------------------------------------*\
Class Table Declaration
Class Table Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Table
:
public TableBase<Type, Table<Type>>
public tableBase,
public FieldFunction1<Type, Table<Type>>
{
// Private Data
//- Enumeration for handling out-of-bound values
const tableBase::boundsHandling boundsHandling_;
//- Interpolation type
const word interpolationScheme_;
//- Table data
List<Tuple2<scalar, Type>> table_;
//- Extracted values
mutable autoPtr<scalarField> tableSamplesPtr_;
//- Interpolator method
mutable autoPtr<interpolationWeights> interpolatorPtr_;
//- Cached indices
mutable labelList indices_;
//- Cached weights
mutable scalarField weights_;
//- Table reader
const autoPtr<TableReader<Type>> reader_;
// Protected Member Functions
//- Return (demand driven) interpolator
const interpolationWeights& interpolator() const;
//- Check the table for size and consistency
void check() const;
//- Bound the argument to the table. Errors or warns, or shifts the
// value if the table repeats. Does not clamp to the ends of the table
// as the interpolator already performs that function.
scalar bound(const scalar x) const;
public:
@ -74,9 +135,6 @@ public:
// Constructors
//- Construct from entry name and Istream
Table(const word& entryName, const dictionary& dict);
//- Construct from components
Table
(
@ -86,6 +144,9 @@ public:
const List<Tuple2<scalar, Type>>& table
);
//- Construct from entry name and dictionary
Table(const word& name, const dictionary& dict);
//- Copy constructor
Table(const Table<Type>& tbl);
@ -96,12 +157,20 @@ public:
// Member Functions
//- Write entries only in dictionary format
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
//- Return Table value as a function of scalar x
virtual Type value(const scalar x) const;
//- Integrate between two scalars
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Return the reference values
virtual tmp<scalarField> x() const;
//- Return the dependent values
virtual tmp<Field<Type>> y() const;
//- Write all table data in dictionary format
virtual void writeData(Ostream& os) const;
// Member Operators

View File

@ -1,335 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-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 "TableBase.H"
#include "linearInterpolationWeights.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type, class Function1Type>
const Foam::interpolationWeights&
Foam::Function1s::TableBase<Type, Function1Type>::interpolator() const
{
if (interpolatorPtr_.empty())
{
// Re-work table into linear list
tableSamplesPtr_.reset(new scalarField(table_.size()));
scalarField& tableSamples = tableSamplesPtr_();
forAll(table_, i)
{
tableSamples[i] = table_[i].first();
}
interpolatorPtr_ = interpolationWeights::New
(
interpolationScheme_,
tableSamples
);
}
return interpolatorPtr_();
}
template<class Type, class Function1Type>
void Foam::Function1s::TableBase<Type, Function1Type>::check() const
{
if (!table_.size())
{
FatalErrorInFunction
<< "Table for entry " << this->name_ << " is invalid (empty)"
<< nl << exit(FatalError);
}
label n = table_.size();
scalar prevValue = table_[0].first();
for (label i = 1; i < n; ++i)
{
const scalar currValue = table_[i].first();
// avoid duplicate values (divide-by-zero error)
if (currValue <= prevValue)
{
FatalErrorInFunction
<< "out-of-order value: " << currValue << " at index " << i
<< exit(FatalError);
}
prevValue = currValue;
}
}
template<class Type, class Function1Type>
Foam::scalar Foam::Function1s::TableBase<Type, Function1Type>::bound
(
const scalar x
) const
{
const bool under = x < table_.first().first();
const bool over = x > table_.last().first();
auto errorMessage = [&]()
{
return "value (" + name(x) + ") " + (under ? "under" : "over") + "flow";
};
if (under || over)
{
switch (boundsHandling_)
{
case tableBase::boundsHandling::error:
{
FatalErrorInFunction
<< errorMessage() << nl << exit(FatalError);
break;
}
case tableBase::boundsHandling::warn:
{
WarningInFunction
<< errorMessage() << nl << endl;
break;
}
case tableBase::boundsHandling::clamp:
{
break;
}
case tableBase::boundsHandling::repeat:
{
const scalar t0 = table_.first().first();
const scalar t1 = table_.last().first();
const scalar dt = t1 - t0;
const label n = floor((x - t0)/dt);
return x - n*dt;
}
}
}
return x;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type, class Function1Type>
Foam::Function1s::TableBase<Type, Function1Type>::TableBase
(
const word& name,
const dictionary& dict
)
:
tableBase(),
FieldFunction1<Type, Function1Type>(name),
name_(name),
boundsHandling_
(
dict.found("outOfBounds")
? tableBase::boundsHandlingNames_.read(dict.lookup("outOfBounds"))
: tableBase::boundsHandling::clamp
),
interpolationScheme_
(
dict.lookupOrDefault<word>
(
"interpolationScheme",
linearInterpolationWeights::typeName
)
),
table_()
{}
template<class Type, class Function1Type>
Foam::Function1s::TableBase<Type, Function1Type>::TableBase
(
const word& name,
const tableBase::boundsHandling boundsHandling,
const word& interpolationScheme,
const List<Tuple2<scalar, Type>>& table
)
:
tableBase(),
FieldFunction1<Type, Function1Type>(name),
name_(name),
boundsHandling_(boundsHandling),
interpolationScheme_(interpolationScheme),
table_(table)
{}
template<class Type, class Function1Type>
Foam::Function1s::TableBase<Type, Function1Type>::TableBase
(
const TableBase<Type, Function1Type>& tbl
)
:
tableBase(),
FieldFunction1<Type, Function1Type>(tbl),
name_(tbl.name_),
boundsHandling_(tbl.boundsHandling_),
interpolationScheme_(tbl.interpolationScheme_),
table_(tbl.table_),
tableSamplesPtr_(tbl.tableSamplesPtr_),
interpolatorPtr_(tbl.interpolatorPtr_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type, class Function1Type>
Foam::Function1s::TableBase<Type, Function1Type>::~TableBase()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class Function1Type>
Type Foam::Function1s::TableBase<Type, Function1Type>::value
(
const scalar x
) const
{
const scalar bx = bound(x);
Type y = Zero;
interpolator().valueWeights(bx, indices_, weights_);
forAll(indices_, i)
{
y += weights_[i]*table_[indices_[i]].second();
}
return y;
}
template<class Type, class Function1Type>
Type Foam::Function1s::TableBase<Type, Function1Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
const scalar bx1 = bound(x1), bx2 = bound(x2);
Type sumY = Zero;
interpolator().integrationWeights(bx1, bx2, indices_, weights_);
forAll(indices_, i)
{
sumY += weights_[i]*table_[indices_[i]].second();
}
if (boundsHandling_ == tableBase::boundsHandling::repeat)
{
const scalar t0 = table_.first().first();
const scalar t1 = table_.last().first();
const scalar dt = t1 - t0;
const label n = floor((x2 - t0)/dt) - floor((x1 - t0)/dt);
if (n != 0)
{
Type sumY01 = Zero;
interpolator().integrationWeights(t0, t1, indices_, weights_);
forAll(indices_, i)
{
sumY01 += weights_[i]*table_[indices_[i]].second();
}
sumY += n*sumY01;
}
}
return sumY;
}
template<class Type, class Function1Type>
Foam::tmp<Foam::scalarField>
Foam::Function1s::TableBase<Type, Function1Type>::x() const
{
tmp<scalarField> tfld(new scalarField(table_.size(), 0.0));
scalarField& fld = tfld.ref();
forAll(table_, i)
{
fld[i] = table_[i].first();
}
return tfld;
}
template<class Type, class Function1Type>
Foam::tmp<Foam::Field<Type>>
Foam::Function1s::TableBase<Type, Function1Type>::y() const
{
tmp<Field<Type>> tfld(new Field<Type>(table_.size(), Zero));
Field<Type>& fld = tfld.ref();
forAll(table_, i)
{
fld[i] = table_[i].second();
}
return tfld;
}
template<class Type, class Function1Type>
void Foam::Function1s::TableBase<Type, Function1Type>::writeData
(
Ostream& os
) const
{
Function1<Type>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
writeEntryIfDifferent
(
os,
"outOfBounds",
tableBase::boundsHandlingNames_[tableBase::boundsHandling::clamp],
tableBase::boundsHandlingNames_[boundsHandling_]
);
writeEntryIfDifferent
(
os,
"interpolationScheme",
linearInterpolationWeights::typeName,
interpolationScheme_
);
writeEntries(os, table_);
os << decrIndent << indent << token::END_BLOCK << endl;
}
// ************************************************************************* //

View File

@ -1,175 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-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/>.
Class
Foam::Function1s::TableBase
Description
Base class for table with bounds handling, interpolation and integration
SourceFiles
TableBase.C
\*---------------------------------------------------------------------------*/
#ifndef TableBase_H
#define TableBase_H
#include "tableBase.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class interpolationWeights;
namespace Function1s
{
/*---------------------------------------------------------------------------*\
Class TableBase Declaration
\*---------------------------------------------------------------------------*/
template<class Type, class Function1Type>
class TableBase
:
public tableBase,
public FieldFunction1<Type, Function1Type>
{
protected:
// Protected data
//- Table name
const word name_;
//- Enumeration for handling out-of-bound values
const tableBase::boundsHandling boundsHandling_;
//- Interpolation type
const word interpolationScheme_;
//- Table data
List<Tuple2<scalar, Type>> table_;
//- Extracted values
mutable autoPtr<scalarField> tableSamplesPtr_;
//- Interpolator method
mutable autoPtr<interpolationWeights> interpolatorPtr_;
//- Cached indices
mutable labelList indices_;
//- Cached weights
mutable scalarField weights_;
// Protected Member Functions
//- Return (demand driven) interpolator
const interpolationWeights& interpolator() const;
//- Check the table for size and consistency
void check() const;
//- Bound the argument to the table. Errors or warns, or shifts the
// value if the table repeats. Does not clamp to the ends of the table
// as the interpolator already performs that function.
scalar bound(const scalar x) const;
public:
// Constructors
//- Construct from dictionary. Table is not populated.
TableBase(const word& name, const dictionary& dict);
//- Construct from components
TableBase
(
const word& name,
const tableBase::boundsHandling boundsHandling,
const word& interpolationScheme,
const List<Tuple2<scalar, Type>>& table
);
//- Copy constructor. Note: Steals interpolator and tableSamples.
TableBase(const TableBase<Type, Function1Type>& tbl);
//- Destructor
virtual ~TableBase();
// Member Functions
//- Return Table value as a function of scalar x
virtual Type value(const scalar x) const;
//- Integrate between two scalars
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Return the reference values
virtual tmp<scalarField> x() const;
//- Return the dependent values
virtual tmp<Field<Type>> y() const;
//- Write entries only in dictionary format
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const = 0;
//- Write all table data in dictionary format
virtual void writeData(Ostream& os) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const TableBase<Type, Function1Type>&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "TableBase.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) 2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,16 +39,4 @@ const Foam::NamedEnum<Foam::Function1s::tableBase::boundsHandling, 4>
Foam::Function1s::tableBase::boundsHandlingNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Function1s::tableBase::tableBase()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Function1s::tableBase::~tableBase()
{}
// ************************************************************************* //

View File

@ -67,11 +67,8 @@ public:
// Constructors
//- Construct null
tableBase();
//- Destructor
virtual ~tableBase();
tableBase()
{}
};

View File

@ -1,72 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-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 "TableFile.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::TableFile<Type>::TableFile
(
const word& name,
const dictionary& dict
)
:
TableBase<Type, TableFile<Type>>(name, dict),
reader_(TableReader<Type>::New(name, dict, this->table_))
{
TableBase<Type, TableFile<Type>>::check();
}
template<class Type>
Foam::Function1s::TableFile<Type>::TableFile(const TableFile<Type>& tbl)
:
TableBase<Type, TableFile<Type>>(tbl),
reader_(tbl.reader_, false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1s::TableFile<Type>::~TableFile()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::TableFile<Type>::writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{
reader_->write(os, table);
}
// ************************************************************************* //

View File

@ -1,133 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-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/>.
Class
Foam::Function1s::TableFile
Description
Templated table container function where data is read from file. Data is
stored as a list of Tuple2's. The first column is scalar. Data is read in
the form specified by the format entry, which defaults to the native
OpenFOAM format.
Usage:
\verbatim
<entryName> tableFile;
<entryName>Coeffs
{
file dataFile; // name of data file
format foam; // data format (optional)
outOfBounds clamp; // optional out-of-bounds handling
interpolationScheme linear; // optional interpolation method
}
\endverbatim
SourceFiles
TableFile.C
See also
FoamTableReader.C
CsvTableReader.C
\*---------------------------------------------------------------------------*/
#ifndef TableFile_H
#define TableFile_H
#include "TableBase.H"
#include "TableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1s
{
/*---------------------------------------------------------------------------*\
Class TableFile Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class TableFile
:
public TableBase<Type, TableFile<Type>>
{
// Private Data
//- Table reader
const autoPtr<TableReader<Type>> reader_;
public:
//- Runtime type information
TypeName("tableFile");
// Constructors
//- Construct from entry name and dictionary
TableFile(const word& entryName, const dictionary& dict);
//- Copy constructor
TableFile(const TableFile<Type>& tbl);
//- Destructor
virtual ~TableFile();
// I/O
//- Write entries only in dictionary format
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const TableFile<Type>&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "TableFile.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -31,7 +31,6 @@ License
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "TableFile.H"
#include "Scale.H"
#include "CodedFunction1.H"

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-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,7 +29,7 @@ License
#include "pointFields.H"
#include "PointEdgeWave.H"
#include "syncTools.H"
#include "TableFile.H"
#include "Table.H"
#include "pointConstraints.H"
#include "mapPolyMesh.H"
@ -233,7 +233,7 @@ Foam::displacementLayeredMotionMotionSolver::faceZoneEvaluate
}
else if (type == "timeVaryingUniformFixedValue")
{
Function1s::TableFile<vector> timeSeries(word::null, dict);
Function1s::Table<vector> timeSeries(word::null, dict);
fld = timeSeries.value(mesh().time().timeOutputValue());
}

View File

@ -56,7 +56,6 @@ namespace solidBodyMotionFunctions
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "TableFile.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"

View File

@ -37,9 +37,9 @@ Description
pistonPositionTime table ( (0 0.13) (0.020 0.03) );
\endverbatim
or with a tableFile
or from a file
\verbatim
pistonPositionTime tableFile;
pistonPositionTime table;
pistonPositionTimeCoeffs
{
file "data";

View File

@ -40,8 +40,8 @@ Usage
inlet
{
type fanPressure;
fanCurve tableFile;
tableFileCoeffs
fanCurve table;
fanCurveCoeffs
{
file "$FOAM_CASE/constant/pressureVsQ";
format csv;
@ -61,8 +61,8 @@ Usage
outlet
{
type fanPressure;
fanCurve tableFile;
tableFileCoeffs
fanCurve table;
fanCurveCoeffs
{
file "$FOAM_CASE/constant/pressureVsQ";
format csv;
@ -96,7 +96,7 @@ SourceFiles
#define fanPressureFvPatchScalarField_H
#include "totalPressureFvPatchScalarField.H"
#include "TableFile.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -53,8 +53,8 @@ Usage
{
type fanPressureJump;
patchType cyclic;
fanCurve tableFile;
tableFileCoeffs
fanCurve table;
fanCurveCoeffs
{
file "$FOAM_CASE/constant/pressureVsQ";
format csv;

View File

@ -42,7 +42,7 @@ Usage
<patchName>
{
type fixedProfile;
profile tableFile;
profile table;
profileCoeffs
{
file "UProfile";

View File

@ -55,7 +55,6 @@ namespace fv
#include "Sine.H"
#include "Square.H"
#include "Table.H"
#include "TableFile.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"

View File

@ -177,7 +177,7 @@ bool Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::read
moment_.reset
(
new Function1s::TableFile<scalar>("moment", sDoFRBMRCoeffs_)
new Function1s::Table<scalar>("moment", sDoFRBMRCoeffs_)
);
const word angleFormat = sDoFRBMRCoeffs_.lookup("angleFormat");

View File

@ -39,7 +39,7 @@ SourceFiles
#include "sixDoFRigidBodyMotionRestraint.H"
#include "point.H"
#include "tensor.H"
#include "TableFile.H"
#include "Table.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,7 +66,7 @@ class tabulatedAxialAngularSpring
vector axis_;
//- Spring moment as a function of angle
autoPtr<Function1s::TableFile<scalar>> moment_;
autoPtr<Function1s::Table<scalar>> moment_;
//- Boolean stating whether the angle around the axis needs to
// be converted to degrees before evaluating the moment function

View File

@ -23,7 +23,7 @@ solidBodyMotionFunction sixDoFMotion;
CofG (0 0 0);
translationRotation tableFile;
translationRotation table;
// interpolationScheme spline;
file "$FOAM_CASE/constant/6DoF.dat";

View File

@ -152,7 +152,7 @@ saturation
scale 1;
value
{
type tableFile;
type table;
format csv;
nHeaderLine 1;
refColumn 1;

View File

@ -189,7 +189,7 @@ saturation
scale 1;
value
{
type tableFile;
type table;
format csv;
nHeaderLine 1;
refColumn 1;

View File

@ -235,7 +235,7 @@ saturation
scale 1;
value
{
type tableFile;
type table;
format csv;
nHeaderLine 1;
refColumn 1;

View File

@ -326,7 +326,7 @@ saturation
scale 1;
value
{
type tableFile;
type table;
format csv;
nHeaderLine 1;
refColumn 1;
@ -351,7 +351,7 @@ saturation
scale 1;
value
{
type tableFile;
type table;
format csv;
nHeaderLine 1;
refColumn 1;

View File

@ -36,7 +36,7 @@ boundaryField
wall
{
type fixedProfile;
profile tableFile;
profile table;
profileCoeffs
{

View File

@ -36,7 +36,7 @@ boundaryField
wall
{
type fixedProfile;
profile tableFile;
profile table;
profileCoeffs
{

View File

@ -36,7 +36,7 @@ boundaryField
wall
{
type fixedProfile;
profile tableFile;
profile table;
profileCoeffs
{

View File

@ -36,7 +36,7 @@ boundaryField
wall
{
type fixedProfile;
profile tableFile;
profile table;
profileCoeffs
{