Skip to content
Snippets Groups Projects
Commit 6dbc3b9f authored by Mark Olesen's avatar Mark Olesen
Browse files

BUG: incorrect range check in interpolationLookUpTable

parent 679d23c5
No related merge requests found
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/
#include "IFstream.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
......@@ -239,7 +238,9 @@ Foam::interpolationLookUpTable<Type>::interpolationLookUpTable()
template<class Type>
Foam::interpolationLookUpTable<Type>::interpolationLookUpTable
(
const fileName& fn, const word& instance, const fvMesh& mesh
const fileName& fn,
const word& instance,
const fvMesh& mesh
)
:
List<scalarField>(),
......@@ -357,11 +358,11 @@ void Foam::interpolationLookUpTable<Type>::write
control.writeHeader(os);
os.writeKeyword("fields");
os << entries_ << token::END_STATEMENT << nl;
os.writeKeyword("fields")
<< entries_ << token::END_STATEMENT << nl;
os.writeKeyword("output");
os << output_ << token::END_STATEMENT << nl;
os.writeKeyword("output")
<< output_ << token::END_STATEMENT << nl;
if (this->size() == 0)
{
......@@ -370,8 +371,8 @@ void Foam::interpolationLookUpTable<Type>::write
"Foam::interpolationTable<Type>::write()"
) << "table is empty" << nl << exit(FatalError);
}
os.writeKeyword("values");
os << *this << token::END_STATEMENT << nl;
os.writeKeyword("values")
<< *this << token::END_STATEMENT << nl;
}
......@@ -381,8 +382,7 @@ template<class Type>
Foam::scalarField&
Foam::interpolationLookUpTable<Type>::operator[](const label i)
{
label ii = i;
label n = this->size();
const label n = this->size();
if (n <= 1)
{
......@@ -391,22 +391,22 @@ Foam::interpolationLookUpTable<Type>::operator[](const label i)
"Foam::interpolationLookUpTable<Type>::operator[](const label)"
) << "table has (" << n << ") columns" << nl << exit(FatalError);
}
else if (ii < 0)
else if (i < 0)
{
FatalErrorIn
(
"Foam::interpolationLookUpTable<Type>::operator[](const label)"
) << "index (" << ii << ") underflow" << nl << exit(FatalError);
) << "index (" << i << ") underflow" << nl << exit(FatalError);
}
else if (ii > n)
else if (i >= n)
{
FatalErrorIn
(
"Foam::interpolationLookUpTable<Type>::operator[](const label)"
) << "index (" << ii << ") overflow" << nl << exit(FatalError);
) << "index (" << i << ") overflow" << nl << exit(FatalError);
}
return List<scalarField>::operator[](ii);
return List<scalarField>::operator[](i);
}
......@@ -414,8 +414,7 @@ template<class Type>
const Foam::scalarField&
Foam::interpolationLookUpTable<Type>::operator[](const label i) const
{
label ii = i;
label n = this->size();
const label n = this->size();
if (n <= 1)
{
......@@ -425,26 +424,25 @@ Foam::interpolationLookUpTable<Type>::operator[](const label i) const
"(const label) const"
) << "table has (" << n << ") columns" << nl << exit(FatalError);
}
else if (ii < 0)
else if (i < 0)
{
FatalErrorIn
(
"Foam::interpolationLookUpTable<Type>::operator[]"
"(const label) const"
) << "index (" << ii << ") underflow" << nl << exit(FatalError);
) << "index (" << i << ") underflow" << nl << exit(FatalError);
}
else if (ii > n)
else if (i >= n)
{
FatalErrorIn
(
"Foam::interpolationLookUpTable<Type>::operator[]"
"(const label) const"
) << "index (" << ii << ") overflow" << nl
) << "index (" << i << ") overflow" << nl
<< exit(FatalError);
}
return List<scalarField>::operator[](ii);
return List<scalarField>::operator[](i);
}
......
......@@ -88,10 +88,10 @@ private:
//- Output dictionaries
List<dictionary> output_;
//- Input indices from the look up table
//- Input indices from the lookup table
List<label> entryIndices_;
//- Output Indeces from the Look Up Table
//- Output indices from the lookup Table
List<label> outputIndices_;
//- Field names and indices
......@@ -118,7 +118,7 @@ private:
//- Check range of lookup value
bool checkRange(const scalar, const label) const;
//- Interpolate function return an scalar
//- Interpolate function returning a scalar
scalar interpolate
(
const label lo,
......@@ -159,13 +159,13 @@ public:
// Member Functions
//- Return true if the filed exists in the table
//- Return true if the field exists in the table
bool found(const word& fieldName) const;
//- Return the output list given a single input scalar
const List<scalar>& lookUp(const scalar);
//- Write Look Up Table to filename.
//- Write lookup table to filename.
void write
(
Ostream&,
......
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