From 4efc0c89ec0cb8f714d0ae081c09191b752e654f Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Thu, 20 Aug 2020 10:58:08 +0200 Subject: [PATCH] #6301 Mud weight window: reorder code to guard against division by zero. --- ...FemPartResultCalculatorMudWeightWindow.cpp | 73 +++++++++---------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorMudWeightWindow.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorMudWeightWindow.cpp index e9f5bbd8ad..506df49363 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorMudWeightWindow.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorMudWeightWindow.cpp @@ -210,55 +210,54 @@ RigFemScalarResultFrames* RigFemPartResultCalculatorMudWeightWindow::calculate( for ( int elmIdx = 0; elmIdx < elementCount; ++elmIdx ) { bool isHexahedron = femPart->isHexahedron( elmIdx ); + int elmNodeCount = RigFemTypes::elementNodeCount( femPart->elementType( elmIdx ) ); - double wellPathDeviation = getValueForElement( RimMudWeightWindowParameters::ParameterType::WELL_DEVIATION, + // Use hydrostatic pressure from cell centroid. + // Use centroid to avoid intra-element differences + cvf::Vec3d cellCentroid = femPartGrid->cellCentroid( elmIdx ); + double cellCentroidTvdRKB = -cellCentroid.z() + airGap; + double waterDensityGCM3 = 1.03; + double cellCenterHydroStaticPressure = + RigGeoMechWellLogExtractor::hydroStaticPorePressureAtDepth( cellCentroidTvdRKB, waterDensityGCM3 ); + + if ( isHexahedron && cellCenterHydroStaticPressure != 0.0 ) + { + double wellPathDeviation = getValueForElement( RimMudWeightWindowParameters::ParameterType::WELL_DEVIATION, + parameterFrameData, + parameterValues, + elmIdx ); + + double wellPathAzimuth = getValueForElement( RimMudWeightWindowParameters::ParameterType::WELL_AZIMUTH, + parameterFrameData, + parameterValues, + elmIdx ); + + double ucsBar = getValueForElement( RimMudWeightWindowParameters::ParameterType::UCS, + parameterFrameData, + parameterValues, + elmIdx ); + + double poissonsRatio = getValueForElement( RimMudWeightWindowParameters::ParameterType::POISSONS_RATIO, parameterFrameData, parameterValues, elmIdx ); - double wellPathAzimuth = getValueForElement( RimMudWeightWindowParameters::ParameterType::WELL_AZIMUTH, - parameterFrameData, - parameterValues, - elmIdx ); + double K0_FG = getValueForElement( RimMudWeightWindowParameters::ParameterType::K0_FG, + parameterFrameData, + parameterValues, + elmIdx ); - double ucsBar = getValueForElement( RimMudWeightWindowParameters::ParameterType::UCS, - parameterFrameData, - parameterValues, - elmIdx ); - - double poissonsRatio = getValueForElement( RimMudWeightWindowParameters::ParameterType::POISSONS_RATIO, - parameterFrameData, - parameterValues, - elmIdx ); - - double K0_FG = getValueForElement( RimMudWeightWindowParameters::ParameterType::K0_FG, + double OBG0 = 0.0; + if ( !OBG0FromGrid ) + { + OBG0 = getValueForElement( RimMudWeightWindowParameters::ParameterType::OBG0, parameterFrameData, parameterValues, elmIdx ); + } - double OBG0 = 0.0; - if ( !OBG0FromGrid ) - { - OBG0 = getValueForElement( RimMudWeightWindowParameters::ParameterType::OBG0, - parameterFrameData, - parameterValues, - elmIdx ); - } - - int elmNodeCount = RigFemTypes::elementNodeCount( femPart->elementType( elmIdx ) ); - - if ( isHexahedron ) - { for ( int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx ) { - // Use hydrostatic pressure from cell centroid. - // Use centroid to avoid intra-element differences - cvf::Vec3d cellCentroid = femPartGrid->cellCentroid( elmIdx ); - double cellCentroidTvdRKB = -cellCentroid.z() + airGap; - double waterDensityGCM3 = 1.03; - double cellCenterHydroStaticPressure = - RigGeoMechWellLogExtractor::hydroStaticPorePressureAtDepth( cellCentroidTvdRKB, waterDensityGCM3 ); - size_t elmNodResIdx = femPart->elementNodeResultIdx( elmIdx, elmNodIdx ); if ( elmNodResIdx < stressFrameData.size() ) {