minor changes to interpolationTable

- use 'outOfBounds' dictionary keyword
 - avoid fileName expansion
 - removed unnecessary dictionary reference
This commit is contained in:
Mark Olesen
2008-07-07 12:51:16 +02:00
parent d7f85054e8
commit c8887472f8
2 changed files with 46 additions and 49 deletions

View File

@ -34,9 +34,8 @@ template<class Type>
Foam::interpolationTable<Type>::interpolationTable() Foam::interpolationTable<Type>::interpolationTable()
: :
List<Tuple2<scalar, Type> >(), List<Tuple2<scalar, Type> >(),
dict_(dictionary::null), boundsHandling_(interpolationTable::WARN),
boundAction_(interpolationTable::WARN), fileName_("fileNameIsUndefined")
fileName_("undefined_fileName")
{} {}
@ -48,20 +47,23 @@ Foam::interpolationTable<Type>::interpolationTable
) )
: :
List<Tuple2<scalar, Type> >(), List<Tuple2<scalar, Type> >(),
dict_(dict), boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))),
boundAction_(wordToBoundAction(dict.lookup("boundAction"))),
fileName_(dict.lookup("fileName")) fileName_(dict.lookup("fileName"))
{ {
fileName_.expand(); // preserve the original (unexpanded) fileName to avoid absolute paths
// appearing in the write() method
fileName fName(fileName_);
fName.expand();
// Correct for relative path // Correct for relative path
if (fileName_[0] != '/') if (fName[0] != '/')
{ {
fileName_ = obr.db().path()/fileName_; fName = obr.db().path()/fName;
} }
// Read data from file // Read data from file
IFstream(fileName_)() >> *this; IFstream(fName)() >> *this;
// Check that the data is okay // Check that the data is okay
check(); check();
@ -71,7 +73,7 @@ Foam::interpolationTable<Type>::interpolationTable
FatalErrorIn FatalErrorIn
( (
"Foam::interpolationTable<Type>::interpolationTable" "Foam::interpolationTable<Type>::interpolationTable"
"(const dictionary& dict)" "(const dictionary&)"
) << "table is empty" << nl ) << "table is empty" << nl
<< exit(FatalError); << exit(FatalError);
} }
@ -85,8 +87,7 @@ Foam::interpolationTable<Type>::interpolationTable
) )
: :
List<Tuple2<scalar, Type> >(interpTable), List<Tuple2<scalar, Type> >(interpTable),
dict_(interpTable.dict_), boundsHandling_(interpTable.boundsHandling_),
boundAction_(interpTable.boundAction_),
fileName_(interpTable.fileName_) fileName_(interpTable.fileName_)
{} {}
@ -101,9 +102,9 @@ Foam::interpolationTable<Type>::~interpolationTable()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::word Foam::interpolationTable<Type>::boundActionToWord Foam::word Foam::interpolationTable<Type>::boundsHandlingToWord
( (
const boundActions& bound const boundsHandling& bound
) const ) const
{ {
word enumName("warn"); word enumName("warn");
@ -137,8 +138,8 @@ Foam::word Foam::interpolationTable<Type>::boundActionToWord
template<class Type> template<class Type>
typename Foam::interpolationTable<Type>::boundActions typename Foam::interpolationTable<Type>::boundsHandling
Foam::interpolationTable<Type>::wordToBoundAction Foam::interpolationTable<Type>::wordToBoundsHandling
( (
const word& bound const word& bound
) const ) const
@ -163,8 +164,8 @@ Foam::interpolationTable<Type>::wordToBoundAction
{ {
WarningIn WarningIn
( (
"Foam::interpolationTable<Type>::wordToBoundAction(const word&)" "Foam::interpolationTable<Type>::wordToBoundsHandling(const word&)"
) << "bad bounding specifier " << bound << " using 'warn'" << endl; ) << "bad outOfBounds specifier " << bound << " using 'warn'" << endl;
return interpolationTable::WARN; return interpolationTable::WARN;
} }
@ -198,14 +199,14 @@ void Foam::interpolationTable<Type>::check() const
template<class Type> template<class Type>
typename Foam::interpolationTable<Type>::boundActions typename Foam::interpolationTable<Type>::boundsHandling
Foam::interpolationTable<Type>::boundAction Foam::interpolationTable<Type>::outOfBounds
( (
const boundActions& bound const boundsHandling& bound
) )
{ {
boundActions prev = boundAction_; boundsHandling prev = boundsHandling_;
boundAction_ = bound; boundsHandling_ = bound;
return prev; return prev;
} }
@ -215,8 +216,8 @@ void Foam::interpolationTable<Type>::write(Ostream& os) const
{ {
os.writeKeyword("fileName") os.writeKeyword("fileName")
<< fileName_ << token::END_STATEMENT << nl; << fileName_ << token::END_STATEMENT << nl;
os.writeKeyword("boundAction") os.writeKeyword("outOfBounds")
<< boundActionToWord(boundAction_) << token::END_STATEMENT << nl; << boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
} }
@ -235,7 +236,7 @@ Foam::interpolationTable<Type>::operator[](const label i) const
} }
else if (ii < 0) else if (ii < 0)
{ {
switch (boundAction_) switch (boundsHandling_)
{ {
case interpolationTable::ERROR: case interpolationTable::ERROR:
{ {
@ -275,7 +276,7 @@ Foam::interpolationTable<Type>::operator[](const label i) const
} }
else if (ii >= n) else if (ii >= n)
{ {
switch (boundAction_) switch (boundsHandling_)
{ {
case interpolationTable::ERROR: case interpolationTable::ERROR:
{ {
@ -334,7 +335,7 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
if (lookupValue < minLimit) if (lookupValue < minLimit)
{ {
switch (boundAction_) switch (boundsHandling_)
{ {
case interpolationTable::ERROR: case interpolationTable::ERROR:
{ {
@ -375,7 +376,7 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
} }
else if (lookupValue >= maxLimit) else if (lookupValue >= maxLimit)
{ {
switch (boundAction_) switch (boundsHandling_)
{ {
case interpolationTable::ERROR: case interpolationTable::ERROR:
{ {
@ -478,5 +479,4 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
} }
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -27,16 +27,16 @@ Class
Description Description
A list of times and values. A list of times and values.
The time values must be positive and monotonically increasing. The time values must be positive monotonically increasing.
The treatment of out-of-bounds values depends on the current setting The handling of out-of-bounds values depends on the current setting
of bounding. of @a outOfBounds.
If @a REPEAT bounding is in effect, the final time value is treated If @a REPEAT is chosen for the out-of-bounds handling, the final time
as being equivalent to time=0 for the following periods. value is treated as being equivalent to time=0 for the following periods.
Note Note
- Accessing an empty list will result in an error. - Accessing an empty list results in an error.
- Accessing a list with a single element will always return the same value. - Accessing a list with a single element will always return the same value.
SourceFiles SourceFiles
@ -58,7 +58,7 @@ namespace Foam
class objectRegistry; class objectRegistry;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class interpolationTable Declaration Class interpolationTable Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type> template<class Type>
@ -71,7 +71,7 @@ public:
// Public data types // Public data types
//- Enumeration for handling out-of-bound values //- Enumeration for handling out-of-bound values
enum boundActions enum boundsHandling
{ {
ERROR, /*!< Exit with a FatalError */ ERROR, /*!< Exit with a FatalError */
WARN, /*!< Issue warning and clamp value (default) */ WARN, /*!< Issue warning and clamp value (default) */
@ -84,11 +84,8 @@ private:
// Private data // Private data
//- Parent dictionary
const dictionary& dict_;
//- Enumeration for handling out-of-bound values //- Enumeration for handling out-of-bound values
boundActions boundAction_; boundsHandling boundsHandling_;
//- File name //- File name
fileName fileName_; fileName fileName_;
@ -122,11 +119,11 @@ public:
return List<Tuple2<scalar, Type> >::size(); return List<Tuple2<scalar, Type> >::size();
} }
//- Return the out-of-bounds treatment as a word //- Return the out-of-bounds handling as a word
word boundActionToWord(const boundActions& bound) const; word boundsHandlingToWord(const boundsHandling& bound) const;
//- Return the out-of-bounds treatment as an enumeration //- Return the out-of-bounds handling as an enumeration
boundActions wordToBoundAction(const word& bound) const; boundsHandling wordToBoundsHandling(const word& bound) const;
// Check // Check
@ -138,9 +135,9 @@ public:
// Edit // Edit
//- Set the out-of-bounds treatment from enum, return previous //- Set the out-of-bounds handling from enum,
// setting // return previous setting
boundActions boundAction(const boundActions& bound); boundsHandling outOfBounds(const boundsHandling& bound);
// Member Operators // Member Operators