mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: explicit handling of fallthrough cases
This commit is contained in:
@ -943,7 +943,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fall-through: nothing to do
|
// fallthrough: nothing to do
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -123,10 +123,10 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
|
|||||||
const scalar lookupValue
|
const scalar lookupValue
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
label n = data.size();
|
const label n = data.size();
|
||||||
|
|
||||||
scalar minLimit = data.first().first();
|
const scalar minLimit = data.first().first();
|
||||||
scalar maxLimit = data.last().first();
|
const scalar maxLimit = data.last().first();
|
||||||
|
|
||||||
if (lookupValue < minLimit)
|
if (lookupValue < minLimit)
|
||||||
{
|
{
|
||||||
@ -147,7 +147,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
|
|||||||
<< "bound (" << minLimit << ")" << nl
|
<< "bound (" << minLimit << ")" << nl
|
||||||
<< " Continuing with the first entry"
|
<< " Continuing with the first entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return data.first().second();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolation2DTable::CLAMP:
|
case interpolation2DTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -175,7 +177,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
|
|||||||
<< "bound (" << maxLimit << ")" << nl
|
<< "bound (" << maxLimit << ")" << nl
|
||||||
<< " Continuing with the last entry"
|
<< " Continuing with the last entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return data.last().second();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolation2DTable::CLAMP:
|
case interpolation2DTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -251,16 +255,19 @@ Foam::label Foam::interpolation2DTable<Type>::Xi
|
|||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "value (" << valueX << ") out of bounds"
|
<< "value (" << valueX << ") out of bounds"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return limitI;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolation2DTable::CLAMP:
|
case interpolation2DTable::CLAMP:
|
||||||
{
|
{
|
||||||
return limitI;
|
return limitI;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Un-handled enumeration " << boundsHandling_
|
<< "Unhandled enumeration " << boundsHandling_
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,7 +306,7 @@ Type Foam::interpolation2DTable<Type>::operator()
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Considers all of the list in Y being equal
|
// Considers all of the list in Y being equal
|
||||||
label nX = this->size();
|
const label nX = this->size();
|
||||||
|
|
||||||
const table& t = *this;
|
const table& t = *this;
|
||||||
|
|
||||||
@ -320,8 +327,8 @@ Type Foam::interpolation2DTable<Type>::operator()
|
|||||||
// have 2-D data, interpolate
|
// have 2-D data, interpolate
|
||||||
|
|
||||||
// find low and high indices in the X range that bound valueX
|
// find low and high indices in the X range that bound valueX
|
||||||
label x0i = Xi(lessOp<scalar>(), valueX, false);
|
const label x0i = Xi(lessOp<scalar>(), valueX, false);
|
||||||
label x1i = Xi(greaterOp<scalar>(), valueX, true);
|
const label x1i = Xi(greaterOp<scalar>(), valueX, true);
|
||||||
|
|
||||||
if (x0i == x1i)
|
if (x0i == x1i)
|
||||||
{
|
{
|
||||||
@ -333,8 +340,8 @@ Type Foam::interpolation2DTable<Type>::operator()
|
|||||||
Type y1(interpolateValue(t[x1i].second(), valueY));
|
Type y1(interpolateValue(t[x1i].second(), valueY));
|
||||||
|
|
||||||
// gradient in X
|
// gradient in X
|
||||||
scalar x0 = t[x0i].first();
|
const scalar x0 = t[x0i].first();
|
||||||
scalar x1 = t[x1i].first();
|
const scalar x1 = t[x1i].first();
|
||||||
Type mX = (y1 - y0)/(x1 - x0);
|
Type mX = (y1 - y0)/(x1 - x0);
|
||||||
|
|
||||||
// interpolate
|
// interpolate
|
||||||
@ -420,7 +427,7 @@ Foam::interpolation2DTable<Type>::outOfBounds
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::interpolation2DTable<Type>::checkOrder() const
|
void Foam::interpolation2DTable<Type>::checkOrder() const
|
||||||
{
|
{
|
||||||
label n = this->size();
|
const label n = this->size();
|
||||||
const table& t = *this;
|
const table& t = *this;
|
||||||
|
|
||||||
scalar prevValue = t[0].first();
|
scalar prevValue = t[0].first();
|
||||||
@ -445,10 +452,8 @@ void Foam::interpolation2DTable<Type>::checkOrder() const
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::interpolation2DTable<Type>::write(Ostream& os) const
|
void Foam::interpolation2DTable<Type>::write(Ostream& os) const
|
||||||
{
|
{
|
||||||
os.writeKeyword("file")
|
os.writeEntry("file", fileName_);
|
||||||
<< fileName_ << token::END_STATEMENT << nl;
|
os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_));
|
||||||
os.writeKeyword("outOfBounds")
|
|
||||||
<< boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
|
|
||||||
|
|
||||||
os << *this;
|
os << *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,7 +66,7 @@ public:
|
|||||||
CLAMP //!< Clamp value to the start/end value
|
CLAMP //!< Clamp value to the start/end value
|
||||||
};
|
};
|
||||||
|
|
||||||
//- Cconvenience typedef
|
//- Convenience typedef
|
||||||
typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table;
|
typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table;
|
||||||
|
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public:
|
|||||||
const List<Tuple2<scalar, Type>>& operator[](const label) const;
|
const List<Tuple2<scalar, Type>>& operator[](const label) const;
|
||||||
|
|
||||||
//- Return an interpolated value
|
//- Return an interpolated value
|
||||||
Type operator()(const scalar, const scalar) const;
|
Type operator()(const scalar valueX, const scalar valueY) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -205,8 +205,8 @@ Foam::interpolationTable<Type>::outOfBounds
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::interpolationTable<Type>::check() const
|
void Foam::interpolationTable<Type>::check() const
|
||||||
{
|
{
|
||||||
label n = this->size();
|
const label n = this->size();
|
||||||
scalar prevValue = List<Tuple2<scalar, Type>>::operator[](0).first();
|
scalar prevValue = this->first().first();
|
||||||
|
|
||||||
for (label i=1; i<n; ++i)
|
for (label i=1; i<n; ++i)
|
||||||
{
|
{
|
||||||
@ -229,10 +229,8 @@ void Foam::interpolationTable<Type>::check() const
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::interpolationTable<Type>::write(Ostream& os) const
|
void Foam::interpolationTable<Type>::write(Ostream& os) const
|
||||||
{
|
{
|
||||||
os.writeKeyword("file")
|
os.writeEntry("file", fileName_);
|
||||||
<< fileName_ << token::END_STATEMENT << nl;
|
os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_));
|
||||||
os.writeKeyword("outOfBounds")
|
|
||||||
<< boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
|
|
||||||
if (reader_.valid())
|
if (reader_.valid())
|
||||||
{
|
{
|
||||||
reader_->write(os);
|
reader_->write(os);
|
||||||
@ -251,8 +249,8 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar minLimit = List<Tuple2<scalar, Type>>::operator[](0).first();
|
const scalar minLimit = this->first().first();
|
||||||
scalar maxLimit = List<Tuple2<scalar, Type>>::operator[](n-1).first();
|
const scalar maxLimit = this->last().first();
|
||||||
scalar lookupValue = value;
|
scalar lookupValue = value;
|
||||||
|
|
||||||
if (lookupValue < minLimit)
|
if (lookupValue < minLimit)
|
||||||
@ -272,7 +270,9 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
|
|||||||
<< "value (" << lookupValue << ") underflow" << nl
|
<< "value (" << lookupValue << ") underflow" << nl
|
||||||
<< " Zero rate of change."
|
<< " Zero rate of change."
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// behaviour as per 'CLAMP'
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -305,7 +305,9 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
|
|||||||
<< "value (" << lookupValue << ") overflow" << nl
|
<< "value (" << lookupValue << ") overflow" << nl
|
||||||
<< " Zero rate of change."
|
<< " Zero rate of change."
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -346,7 +348,7 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
|
|||||||
}
|
}
|
||||||
else if (hi == 0)
|
else if (hi == 0)
|
||||||
{
|
{
|
||||||
// this treatment should should only occur under these conditions:
|
// this treatment should only occur under these conditions:
|
||||||
// -> the 'REPEAT' treatment
|
// -> the 'REPEAT' treatment
|
||||||
// -> (0 <= value <= minLimit)
|
// -> (0 <= value <= minLimit)
|
||||||
// -> minLimit > 0
|
// -> minLimit > 0
|
||||||
@ -414,7 +416,9 @@ Foam::interpolationTable<Type>::operator[](const label i) const
|
|||||||
<< "index (" << ii << ") underflow" << nl
|
<< "index (" << ii << ") underflow" << nl
|
||||||
<< " Continuing with the first entry"
|
<< " Continuing with the first entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
ii = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -448,7 +452,9 @@ Foam::interpolationTable<Type>::operator[](const label i) const
|
|||||||
<< "index (" << ii << ") overflow" << nl
|
<< "index (" << ii << ") overflow" << nl
|
||||||
<< " Continuing with the last entry"
|
<< " Continuing with the last entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
ii = n - 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
@ -477,11 +483,11 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
|
|||||||
|
|
||||||
if (n <= 1)
|
if (n <= 1)
|
||||||
{
|
{
|
||||||
return List<Tuple2<scalar, Type>>::operator[](0).second();
|
return this->first().second();
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar minLimit = List<Tuple2<scalar, Type>>::operator[](0).first();
|
const scalar minLimit = this->first().first();
|
||||||
scalar maxLimit = List<Tuple2<scalar, Type>>::operator[](n-1).first();
|
const scalar maxLimit = this->last().first();
|
||||||
scalar lookupValue = value;
|
scalar lookupValue = value;
|
||||||
|
|
||||||
if (lookupValue < minLimit)
|
if (lookupValue < minLimit)
|
||||||
@ -501,17 +507,19 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
|
|||||||
<< "value (" << lookupValue << ") underflow" << nl
|
<< "value (" << lookupValue << ") underflow" << nl
|
||||||
<< " Continuing with the first entry"
|
<< " Continuing with the first entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return this->first().second();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
return List<Tuple2<scalar, Type>>::operator[](0).second();
|
return this->first().second();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::REPEAT:
|
case interpolationTable::REPEAT:
|
||||||
{
|
{
|
||||||
// adjust lookupValue to >= minLimit
|
// adjust lookupValue to >= minLimit
|
||||||
scalar span = maxLimit-minLimit;
|
const scalar span = maxLimit-minLimit;
|
||||||
lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
|
lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -534,17 +542,19 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
|
|||||||
<< "value (" << lookupValue << ") overflow" << nl
|
<< "value (" << lookupValue << ") overflow" << nl
|
||||||
<< " Continuing with the last entry"
|
<< " Continuing with the last entry"
|
||||||
<< endl;
|
<< endl;
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
return this->last().second();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::CLAMP:
|
case interpolationTable::CLAMP:
|
||||||
{
|
{
|
||||||
return List<Tuple2<scalar, Type>>::operator[](n-1).second();
|
return this->last().second();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case interpolationTable::REPEAT:
|
case interpolationTable::REPEAT:
|
||||||
{
|
{
|
||||||
// adjust lookupValue <= maxLimit
|
// adjust lookupValue <= maxLimit
|
||||||
scalar span = maxLimit-minLimit;
|
const scalar span = maxLimit-minLimit;
|
||||||
lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
|
lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -575,7 +585,7 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
|
|||||||
}
|
}
|
||||||
else if (hi == 0)
|
else if (hi == 0)
|
||||||
{
|
{
|
||||||
// this treatment should should only occur under these conditions:
|
// this treatment should only occur under these conditions:
|
||||||
// -> the 'REPEAT' treatment
|
// -> the 'REPEAT' treatment
|
||||||
// -> (0 <= value <= minLimit)
|
// -> (0 <= value <= minLimit)
|
||||||
// -> minLimit > 0
|
// -> minLimit > 0
|
||||||
|
|||||||
@ -195,7 +195,7 @@ void Foam::Function1Types::TableBase<Type>::check() const
|
|||||||
<< nl << exit(FatalError);
|
<< nl << exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
label n = table_.size();
|
const label n = table_.size();
|
||||||
scalar prevValue = table_[0].first();
|
scalar prevValue = table_[0].first();
|
||||||
|
|
||||||
for (label i = 1; i < n; ++i)
|
for (label i = 1; i < n; ++i)
|
||||||
@ -221,7 +221,7 @@ bool Foam::Function1Types::TableBase<Type>::checkMinBounds
|
|||||||
scalar& xDash
|
scalar& xDash
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (x < table_[0].first())
|
if (x < table_.first().first())
|
||||||
{
|
{
|
||||||
switch (boundsHandling_)
|
switch (boundsHandling_)
|
||||||
{
|
{
|
||||||
@ -238,19 +238,28 @@ bool Foam::Function1Types::TableBase<Type>::checkMinBounds
|
|||||||
<< "value (" << x << ") underflow" << nl
|
<< "value (" << x << ") underflow" << nl
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
xDash = table_.first().first();
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case CLAMP:
|
case CLAMP:
|
||||||
{
|
{
|
||||||
xDash = table_[0].first();
|
xDash = table_.first().first();
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case REPEAT:
|
case REPEAT:
|
||||||
{
|
{
|
||||||
// adjust x to >= minX
|
// adjust x to >= minX
|
||||||
scalar span = table_.last().first() - table_[0].first();
|
const scalar span =
|
||||||
xDash = fmod(x - table_[0].first(), span) + table_[0].first();
|
table_.last().first() - table_.first().first();
|
||||||
|
|
||||||
|
xDash =
|
||||||
|
(
|
||||||
|
fmod(x - table_.first().first(), span)
|
||||||
|
+ table_.first().first()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,7 +297,10 @@ bool Foam::Function1Types::TableBase<Type>::checkMaxBounds
|
|||||||
<< "value (" << x << ") overflow" << nl
|
<< "value (" << x << ") overflow" << nl
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
// fall-through to 'CLAMP'
|
// Behaviour as per 'CLAMP'
|
||||||
|
xDash = table_.last().first();
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case CLAMP:
|
case CLAMP:
|
||||||
{
|
{
|
||||||
@ -299,8 +311,14 @@ bool Foam::Function1Types::TableBase<Type>::checkMaxBounds
|
|||||||
case REPEAT:
|
case REPEAT:
|
||||||
{
|
{
|
||||||
// adjust x to >= minX
|
// adjust x to >= minX
|
||||||
scalar span = table_.last().first() - table_[0].first();
|
const scalar span =
|
||||||
xDash = fmod(x - table_[0].first(), span) + table_[0].first();
|
table_.last().first() - table_.first().first();
|
||||||
|
|
||||||
|
xDash =
|
||||||
|
(
|
||||||
|
fmod(x - table_.first().first(), span)
|
||||||
|
+ table_.first().first()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,7 +353,7 @@ Type Foam::Function1Types::TableBase<Type>::value(const scalar x) const
|
|||||||
|
|
||||||
if (checkMinBounds(x, xDash))
|
if (checkMinBounds(x, xDash))
|
||||||
{
|
{
|
||||||
return table_[0].second();
|
return table_.first().second();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkMaxBounds(xDash, xDash))
|
if (checkMaxBounds(xDash, xDash))
|
||||||
@ -411,13 +429,11 @@ void Foam::Function1Types::TableBase<Type>::writeEntries(Ostream& os) const
|
|||||||
{
|
{
|
||||||
if (boundsHandling_ != CLAMP)
|
if (boundsHandling_ != CLAMP)
|
||||||
{
|
{
|
||||||
os.writeKeyword("outOfBounds") << boundsHandlingToWord(boundsHandling_)
|
os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_));
|
||||||
<< token::END_STATEMENT << nl;
|
|
||||||
}
|
}
|
||||||
if (interpolationScheme_ != "linear")
|
if (interpolationScheme_ != "linear")
|
||||||
{
|
{
|
||||||
os.writeKeyword("interpolationScheme") << interpolationScheme_
|
os.writeEntry("interpolationScheme", interpolationScheme_);
|
||||||
<< token::END_STATEMENT << nl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user