Skip to content

Commit

Permalink
Minor refactor to reuse code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Nov 20, 2023
1 parent 9ad4950 commit 6efc9e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "RimGeoMechCase.h"
#include "RimWellIADataAccess.h"

#include "../cafHexInterpolator/cafHexInterpolator.h" // Use relative path, as this is a header only file not part of a library

#include <cmath>
#include <limits>

Expand Down Expand Up @@ -74,6 +72,7 @@ void RimFaultReactivationDataAccessorStress::updateResultAccessor()
};

auto femParts = m_geoMechCaseData->femPartResults();
m_femPart = femParts->parts()->part( partIndex );
m_s33Frames = loadFrameLambda( femParts, getResultAddress( "ST", "S33" ) );
m_s11Frames = loadFrameLambda( femParts, getResultAddress( "ST", "S11" ) );
m_s22Frames = loadFrameLambda( femParts, getResultAddress( "ST", "S22" ) );
Expand Down Expand Up @@ -101,7 +100,7 @@ bool RimFaultReactivationDataAccessorStress::isMatching( RimFaultReactivation::P
//--------------------------------------------------------------------------------------------------
double RimFaultReactivationDataAccessorStress::valueAtPosition( const cvf::Vec3d& position, double topDepth, double bottomDepth ) const
{
if ( !m_porFrames || !m_s11Frames || !m_s22Frames || !m_s33Frames ) return std::numeric_limits<double>::infinity();
if ( !m_porFrames || !m_s11Frames || !m_s22Frames || !m_s33Frames || !m_femPart ) return std::numeric_limits<double>::infinity();

RimWellIADataAccess iaDataAccess( m_geoMechCase );
int centerElementIdx = iaDataAccess.elementIndex( position );
Expand All @@ -123,14 +122,14 @@ double RimFaultReactivationDataAccessorStress::valueAtPosition( const cvf::Vec3d

if ( m_property == RimFaultReactivation::Property::StressTop )
{
double s33 = interpolatedResultValue( topPosition, s33Data );
double porBar = interpolatedResultValue( topPosition, porData );
double s33 = interpolatedResultValue( iaDataAccess, m_femPart, topPosition, s33Data );
double porBar = interpolatedResultValue( iaDataAccess, m_femPart, topPosition, porData );
return s33 - porBar;
}
else if ( m_property == RimFaultReactivation::Property::StressBottom )
{
double s33 = interpolatedResultValue( bottomPosition, s33Data );
double porBar = interpolatedResultValue( bottomPosition, porData );
double s33 = interpolatedResultValue( iaDataAccess, m_femPart, bottomPosition, s33Data );
double porBar = interpolatedResultValue( iaDataAccess, m_femPart, bottomPosition, porData );
return s33 - porBar;
}
else if ( m_property == RimFaultReactivation::Property::DepthTop )
Expand All @@ -143,16 +142,16 @@ double RimFaultReactivationDataAccessorStress::valueAtPosition( const cvf::Vec3d
}
else if ( m_property == RimFaultReactivation::Property::LateralStressComponentX )
{
double s11 = interpolatedResultValue( position, s11Data );
double s33 = interpolatedResultValue( position, s33Data );
double porBar = interpolatedResultValue( position, porData );
double s11 = interpolatedResultValue( iaDataAccess, m_femPart, position, s11Data );
double s33 = interpolatedResultValue( iaDataAccess, m_femPart, position, s33Data );
double porBar = interpolatedResultValue( iaDataAccess, m_femPart, position, porData );
return ( s11 - porBar ) / ( s33 - porBar );
}
else if ( m_property == RimFaultReactivation::Property::LateralStressComponentY )
{
double s22 = interpolatedResultValue( position, s22Data );
double s33 = interpolatedResultValue( position, s33Data );
double porBar = interpolatedResultValue( position, porData );
double s22 = interpolatedResultValue( iaDataAccess, m_femPart, position, s22Data );
double s33 = interpolatedResultValue( iaDataAccess, m_femPart, position, s33Data );
double porBar = interpolatedResultValue( iaDataAccess, m_femPart, position, porData );
return ( s22 - porBar ) / ( s33 - porBar );
}
}
Expand All @@ -172,28 +171,10 @@ bool RimFaultReactivationDataAccessorStress::hasValidDataAtPosition( const cvf::
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimFaultReactivationDataAccessorStress::interpolatedResultValue( const cvf::Vec3d& position, const std::vector<float>& scalarResults ) const
double RimFaultReactivationDataAccessorStress::interpolatedResultValue( RimWellIADataAccess& iaDataAccess,
const RigFemPart* femPart,
const cvf::Vec3d& position,
const std::vector<float>& scalarResults ) const
{
RimWellIADataAccess iaDataAccess( m_geoMechCase );
int elmIdx = iaDataAccess.elementIndex( position );
RigFemPart* femPart = m_geoMechCase->geoMechData()->femParts()->part( 0 );
RigElementType elmType = femPart->elementType( elmIdx );
const int* elementConn = femPart->connectivities( elmIdx );
int elmNodeCount = RigFemTypes::elementNodeCount( elmType );

std::array<double, 8> nodeResults;
std::array<cvf::Vec3d, 8> nodeCorners;

for ( int lNodeIdx = 0; lNodeIdx < elmNodeCount; ++lNodeIdx )
{
int nodeIdx = elementConn[lNodeIdx];
size_t resIdx = femPart->resultValueIdxFromResultPosType( RIG_ELEMENT_NODAL, elmIdx, lNodeIdx );
if ( resIdx >= scalarResults.size() )
nodeResults[lNodeIdx] = 0.0;
else
nodeResults[lNodeIdx] = scalarResults[resIdx];
nodeCorners[lNodeIdx] = cvf::Vec3d( femPart->nodes().coordinates[nodeIdx] );
}

return caf::HexInterpolator::interpolateHex( nodeCorners, nodeResults, position );
return iaDataAccess.interpolatedResultValue( femPart, scalarResults, RIG_ELEMENT_NODAL, position );
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class RigFemPartResultsCollection;
class RimGeoMechCase;
class RigGeoMechCaseData;
class RigFemScalarResultFrames;
class RigFemPart;
class RimWellIADataAccess;

//==================================================================================================
///
Expand All @@ -53,7 +55,10 @@ class RimFaultReactivationDataAccessorStress : public RimFaultReactivationDataAc

static RigFemResultAddress getResultAddress( const std::string& fieldName, const std::string& componentName );

double interpolatedResultValue( const cvf::Vec3d& position, const std::vector<float>& scalarResults ) const;
double interpolatedResultValue( RimWellIADataAccess& iaDataAccess,
const RigFemPart* femPart,
const cvf::Vec3d& position,
const std::vector<float>& scalarResults ) const;

RimGeoMechCase* m_geoMechCase;
RimFaultReactivation::Property m_property;
Expand All @@ -62,4 +67,5 @@ class RimFaultReactivationDataAccessorStress : public RimFaultReactivationDataAc
RigFemScalarResultFrames* m_s22Frames;
RigFemScalarResultFrames* m_s33Frames;
RigFemScalarResultFrames* m_porFrames;
const RigFemPart* m_femPart;
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,26 @@ double RimWellIADataAccess::interpolatedResultValue( QString fieldNa
{
RigFemResultAddress address( resultType, fieldName.toStdString(), componentName.toStdString() );

RigFemPart* femPart = m_caseData->femParts()->part( 0 );
const std::vector<float>& scalarResults = m_caseData->femPartResults()->resultValues( address, 0, timeStep, frameId );

return interpolatedResultValue( femPart, scalarResults, resultType, position );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimWellIADataAccess::interpolatedResultValue( const RigFemPart* femPart,
const std::vector<float>& scalarResults,
RigFemResultPosEnum resultType,
const cvf::Vec3d& position )
{
int elmIdx = elementIndex( position );

RigFemPart* femPart = m_caseData->femParts()->part( 0 );
RigElementType elmType = femPart->elementType( elmIdx );
const int* elementConn = femPart->connectivities( elmIdx );
int elmNodeCount = RigFemTypes::elementNodeCount( elmType );

const std::vector<float>& scalarResults = m_caseData->femPartResults()->resultValues( address, 0, timeStep, frameId );

std::array<double, 8> nodeResults;
std::array<cvf::Vec3d, 8> nodeCorners;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class RimGeoMechCase;
class RigGeoMechCaseData;
class RigFemPart;

//==================================================================================================
///
Expand All @@ -49,6 +50,11 @@ class RimWellIADataAccess
int timeStep,
int frameId );

double interpolatedResultValue( const RigFemPart* femPart,
const std::vector<float>& scalarResults,
RigFemResultPosEnum resultType,
const cvf::Vec3d& position );

private:
RimGeoMechCase* m_case;
RigGeoMechCaseData* m_caseData;
Expand Down

0 comments on commit 6efc9e2

Please sign in to comment.