mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-01 16:43:03 -06:00
Improves robustness for curve merging operations
- Ensures a more robust size multiplier calculation by validating the weighted mean and preventing division by zero. - Addresses a potential division by zero during curve interpolation when the X values are very close, ensuring a more robust and accurate result.
This commit is contained in:
1 parent
e455011199
commit
8dff7b46c9
2 files changed
+22
-10
No files matched your search
@@ -344,15 +344,22 @@ double RiaCurveMerger<XValueType>::interpolatedYValue( const XValueType&
|
||||
return firstValue;
|
||||
}
|
||||
|
||||
double firstDiff = fabs( XComparator::diff( interpolationXValue, xValues.at( firstI ) ) );
|
||||
double secondDiff = fabs( XComparator::diff( xValues.at( secondI ), interpolationXValue ) );
|
||||
const double firstDiff = fabs( XComparator::diff( interpolationXValue, xValues.at( firstI ) ) );
|
||||
const double secondDiff = fabs( XComparator::diff( xValues.at( secondI ), interpolationXValue ) );
|
||||
const double totalDiff = firstDiff + secondDiff;
|
||||
|
||||
double firstWeight = secondDiff / ( firstDiff + secondDiff );
|
||||
double secondWeight = firstDiff / ( firstDiff + secondDiff );
|
||||
|
||||
double val = ( firstValue * firstWeight ) + ( secondValue * secondWeight );
|
||||
|
||||
CVF_ASSERT( RiaCurveDataTools::isValidValue( val, removeInterpolatedValues ) );
|
||||
double val;
|
||||
if ( totalDiff < std::numeric_limits<double>::epsilon() )
|
||||
{
|
||||
// Points are essentially identical - use either value
|
||||
val = firstValue; // or secondValue, or average: (firstValue + secondValue) * 0.5
|
||||
}
|
||||
else
|
||||
{
|
||||
const double firstWeight = secondDiff / totalDiff;
|
||||
const double secondWeight = firstDiff / totalDiff;
|
||||
val = ( firstValue * firstWeight ) + ( secondValue * secondWeight );
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user