Commit c9a2f492 authored by Andrew Heather's avatar Andrew Heather
Browse files

templated uniformInterpolationTable

parent 7e34048c
......@@ -72,7 +72,7 @@ protected:
word invertedTableName_;
//- Inverted table
uniformInterpolationTable invertedTable_;
uniformInterpolationTable<scalar> invertedTable_;
public:
......@@ -121,7 +121,8 @@ public:
inline const word& invertedTableName() const;
//- Return the inverted table
inline const uniformInterpolationTable& invertedTable() const;
inline const uniformInterpolationTable<scalar>&
invertedTable() const;
// I-O
......
......@@ -35,7 +35,7 @@ Foam::tabulatedWallFunctions::tabulatedWallFunction::invertedTableName() const
}
inline const Foam::uniformInterpolationTable&
inline const Foam::uniformInterpolationTable<Foam::scalar>&
Foam::tabulatedWallFunctions::tabulatedWallFunction::invertedTable() const
{
return invertedTable_;
......
......@@ -509,7 +509,6 @@ meshes/preservePatchTypes/preservePatchTypes.C
interpolations = interpolations
interpolation = $(interpolations)/interpolation
$(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C
$(interpolations)/uniformInterpolationTable/uniformInterpolationTable.C
algorithms/MeshWave/MeshWaveName.C
algorithms/MeshWave/FaceCellWaveName.C
......
......@@ -27,20 +27,14 @@ License
#include "uniformInterpolationTable.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(uniformInterpolationTable, 0);
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::uniformInterpolationTable::checkTable() const
template <class Type>
void Foam::uniformInterpolationTable<Type>::checkTable() const
{
if (size() < 2)
{
FatalErrorIn("uniformInterpolationTable::checkTable()")
FatalErrorIn("uniformInterpolationTable<Type>::checkTable()")
<< "Table " << name() << ": must have at least 2 values." << nl
<< "Table size = " << size() << nl
<< " min, interval width = " << x0_ << ", " << dx_ << nl
......@@ -51,7 +45,8 @@ void Foam::uniformInterpolationTable::checkTable() const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::uniformInterpolationTable::uniformInterpolationTable
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const IOobject& io,
bool readFields
......@@ -79,7 +74,8 @@ Foam::uniformInterpolationTable::uniformInterpolationTable
}
Foam::uniformInterpolationTable::uniformInterpolationTable
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const word& tableName,
const objectRegistry& db,
......@@ -106,7 +102,7 @@ Foam::uniformInterpolationTable::uniformInterpolationTable
{
scalar xMax = readScalar(dict.lookup("xMax"));
label nIntervals = static_cast<label>(xMax - x0_)/dx_ + 1;
setSize(nIntervals);
this->setSize(nIntervals);
}
else
{
......@@ -117,7 +113,11 @@ Foam::uniformInterpolationTable::uniformInterpolationTable
}
Foam::uniformInterpolationTable::uniformInterpolationTable(const uniformInterpolationTable& uit)
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const uniformInterpolationTable& uit
)
:
IOobject(uit),
List<scalar>(uit),
......@@ -132,13 +132,15 @@ Foam::uniformInterpolationTable::uniformInterpolationTable(const uniformInterpol
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::uniformInterpolationTable::~uniformInterpolationTable()
template <class Type>
Foam::uniformInterpolationTable<Type>::~uniformInterpolationTable()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::scalar Foam::uniformInterpolationTable::interpolate(scalar x) const
template <class Type>
Type Foam::uniformInterpolationTable<Type>::interpolate(scalar x) const
{
if (bound_)
{
......@@ -148,16 +150,20 @@ Foam::scalar Foam::uniformInterpolationTable::interpolate(scalar x) const
{
if (x < x0_)
{
FatalErrorIn("uniformInterpolationTable::interpolate(scalar x)")
<< "Supplied value is less than minimum table value:" << nl
FatalErrorIn
(
"uniformInterpolationTable<Type>::interpolate(scalar x)"
) << "Supplied value is less than minimum table value:" << nl
<< "xMin=" << x0_ << ", xMax=" << xMax() << ", x=" << x << nl
<< exit(FatalError);
}
if (x > xMax())
{
FatalErrorIn("uniformInterpolationTable::interpolate(scalar x)")
<< "Supplied value is greater than maximum table value:" << nl
FatalErrorIn
(
"uniformInterpolationTable<Type>::interpolate(scalar x)"
) << "Supplied value is greater than maximum table value:" << nl
<< "xMin=" << x0_ << ", xMax=" << xMax() << ", x=" << x << nl
<< exit(FatalError);
}
......@@ -167,7 +173,7 @@ Foam::scalar Foam::uniformInterpolationTable::interpolate(scalar x) const
scalar xLo = x0_ + i*dx_;
scalar fx = (x - xLo)/dx_*(operator[](i+1) - operator[](i)) + operator[](i);
Type fx = (x - xLo)/dx_*(operator[](i+1) - operator[](i)) + operator[](i);
if (debug)
{
......@@ -181,7 +187,11 @@ Foam::scalar Foam::uniformInterpolationTable::interpolate(scalar x) const
}
Foam::scalar Foam::uniformInterpolationTable::interpolateLog10(scalar x) const
template <class Type>
Type Foam::uniformInterpolationTable<Type>::interpolateLog10
(
scalar x
) const
{
if (log10_)
{
......@@ -197,7 +207,7 @@ Foam::scalar Foam::uniformInterpolationTable::interpolateLog10(scalar x) const
{
FatalErrorIn
(
"uniformInterpolationTable::interpolateLog10(scalar x)"
"uniformInterpolationTable<Type>::interpolateLog10(scalar x)"
) << "Table " << name() << nl
<< "Supplied value must be greater than 0 when in log10 mode"
<< nl << "x=" << x << nl << exit(FatalError);
......@@ -208,7 +218,8 @@ Foam::scalar Foam::uniformInterpolationTable::interpolateLog10(scalar x) const
}
void Foam::uniformInterpolationTable::write() const
template <class Type>
void Foam::uniformInterpolationTable<Type>::write() const
{
IOdictionary dict(*this);
......
......@@ -29,7 +29,7 @@ Description
Table with uniform interval in independant variable, with linear
interpolation
Values specified in a dictionary:
Example usage (scalar): values specified in a dictionary:
{
x0 0; // lower limit
......@@ -66,10 +66,11 @@ namespace Foam
Class uniformInterpolationTable Declaration
\*---------------------------------------------------------------------------*/
template <class Type>
class uniformInterpolationTable
:
public IOobject,
public List<scalar>
public List<Type>
{
// Private data
......@@ -99,10 +100,6 @@ class uniformInterpolationTable
public:
//- Runtime type information
TypeName("uniformInterpolationTable");
// Constructors
//- Construct from IOobject and readFields flag. Creates a null object
......@@ -169,10 +166,10 @@ public:
inline scalar xMax() const;
//- Interpolate
scalar interpolate(scalar x) const;
Type interpolate(scalar x) const;
//- Interpolate - takes log10 flag into account
scalar interpolateLog10(scalar x) const;
Type interpolateLog10(scalar x) const;
// Override ancestor size() function and [] operator
......@@ -180,19 +177,19 @@ public:
//- Return the size of the table
label size() const
{
return List<scalar>::size();
return List<Type>::size();
}
//- Use List[] operator for read access
scalar operator[](label x) const
Type operator[](label x) const
{
return List<scalar>::operator[](x);
return List<Type>::operator[](x);
}
//- Use List[] operator for write access
scalar& operator[](label x)
Type& operator[](label x)
{
return List<scalar>::operator[](x);
return List<Type>::operator[](x);
}
......@@ -213,6 +210,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "uniformInterpolationTable.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -24,63 +24,73 @@ License
\*---------------------------------------------------------------------------*/
Foam::scalar Foam::uniformInterpolationTable::x0() const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::x0() const
{
return x0_;
}
Foam::scalar Foam::uniformInterpolationTable::dx() const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::dx() const
{
return dx_;
}
const Foam::Switch& Foam::uniformInterpolationTable::log10() const
template <class Type>
const Foam::Switch& Foam::uniformInterpolationTable<Type>::log10() const
{
return log10_;
}
const Foam::Switch& Foam::uniformInterpolationTable::bound() const
template <class Type>
const Foam::Switch& Foam::uniformInterpolationTable<Type>::bound() const
{
return bound_;
}
Foam::scalar& Foam::uniformInterpolationTable::x0()
template <class Type>
Foam::scalar& Foam::uniformInterpolationTable<Type>::x0()
{
return x0_;
}
Foam::scalar& Foam::uniformInterpolationTable::dx()
template <class Type>
Foam::scalar& Foam::uniformInterpolationTable<Type>::dx()
{
return dx_;
}
Foam::Switch& Foam::uniformInterpolationTable::log10()
template <class Type>
Foam::Switch& Foam::uniformInterpolationTable<Type>::log10()
{
return log10_;
}
Foam::Switch& Foam::uniformInterpolationTable::bound()
template <class Type>
Foam::Switch& Foam::uniformInterpolationTable<Type>::bound()
{
return bound_;
}
Foam::scalar Foam::uniformInterpolationTable::xMin() const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::xMin() const
{
return x0_;
}
Foam::scalar Foam::uniformInterpolationTable::xMax() const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::xMax() const
{
return x0_ + (size()-1)*dx_;
return x0_ + dx_*(size() - 1);
}
......
......@@ -68,7 +68,7 @@ protected:
word uPlusTableName_;
//- U+ table
uniformInterpolationTable uPlusTable_;
uniformInterpolationTable<scalar> uPlusTable_;
// Protected member functions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment