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

View File

@ -27,16 +27,16 @@ Class
Description
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
of bounding.
The handling of out-of-bounds values depends on the current setting
of @a outOfBounds.
If @a REPEAT bounding is in effect, the final time value is treated
as being equivalent to time=0 for the following periods.
If @a REPEAT is chosen for the out-of-bounds handling, the final time
value is treated as being equivalent to time=0 for the following periods.
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.
SourceFiles
@ -71,7 +71,7 @@ public:
// Public data types
//- Enumeration for handling out-of-bound values
enum boundActions
enum boundsHandling
{
ERROR, /*!< Exit with a FatalError */
WARN, /*!< Issue warning and clamp value (default) */
@ -84,11 +84,8 @@ private:
// Private data
//- Parent dictionary
const dictionary& dict_;
//- Enumeration for handling out-of-bound values
boundActions boundAction_;
boundsHandling boundsHandling_;
//- File name
fileName fileName_;
@ -122,11 +119,11 @@ public:
return List<Tuple2<scalar, Type> >::size();
}
//- Return the out-of-bounds treatment as a word
word boundActionToWord(const boundActions& bound) const;
//- Return the out-of-bounds handling as a word
word boundsHandlingToWord(const boundsHandling& bound) const;
//- Return the out-of-bounds treatment as an enumeration
boundActions wordToBoundAction(const word& bound) const;
//- Return the out-of-bounds handling as an enumeration
boundsHandling wordToBoundsHandling(const word& bound) const;
// Check
@ -138,9 +135,9 @@ public:
// Edit
//- Set the out-of-bounds treatment from enum, return previous
// setting
boundActions boundAction(const boundActions& bound);
//- Set the out-of-bounds handling from enum,
// return previous setting
boundsHandling outOfBounds(const boundsHandling& bound);
// Member Operators