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