Skip to content

Commit 848c239

Browse files
authored
Scripting: geomechanical cell result (replaces #14952)
Make RimGeoMechResultDefinition (position, field and component) and the view's cell result scriptable, as for grid views.
1 parent 914cab9 commit 848c239

10 files changed

Lines changed: 94 additions & 14 deletions

File tree

‎ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechCellColors.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "RimViewController.h"
2525
#include "RimViewLinker.h"
2626

27+
#include "cafPdmObjectScriptingCapability.h"
28+
2729
CAF_PDM_SOURCE_INIT( RimGeoMechCellColors, "GeoMechResultSlot" );
2830

2931
//--------------------------------------------------------------------------------------------------
@@ -32,6 +34,8 @@ CAF_PDM_SOURCE_INIT( RimGeoMechCellColors, "GeoMechResultSlot" );
3234
RimGeoMechCellColors::RimGeoMechCellColors()
3335
: legendConfigChanged( this )
3436
{
37+
CAF_PDM_InitScriptableObjectWithNameAndComment( "Color Result", ":/CellResult.png", "", "", "GeoMechCellColors", "Geomechanical cell colors" );
38+
3539
CAF_PDM_InitFieldNoDefault( &legendConfig, "LegendDefinition", "Color Legend" );
3640
legendConfig = new RimRegularLegendConfig();
3741
legendConfig->changed.connect( this, &RimGeoMechCellColors::onLegendConfigChanged );

‎ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechResultDefinition.cpp‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "RimViewLinker.h"
4949
#include "RimWellPath.h"
5050

51+
#include "cafPdmFieldScriptingCapability.h"
52+
#include "cafPdmObjectScriptingCapability.h"
5153
#include "cafPdmUiDoubleValueEditor.h"
5254
#include "cafPdmUiTreeSelectionEditor.h"
5355

@@ -77,15 +79,15 @@ CAF_PDM_SOURCE_INIT( RimGeoMechResultDefinition, "GeoMechResultDefinition" );
7779
//--------------------------------------------------------------------------------------------------
7880
RimGeoMechResultDefinition::RimGeoMechResultDefinition()
7981
{
80-
CAF_PDM_InitObject( "Color Result", ":/CellResult.png" );
82+
CAF_PDM_InitScriptableObjectWithNameAndComment( "Color Result", ":/CellResult.png", "", "", "GeoMechResult", "A geomechanical result definition" );
8183

82-
CAF_PDM_InitFieldNoDefault( &m_resultPositionType, "ResultPositionType", "Result Position" );
84+
CAF_PDM_InitScriptableFieldNoDefault( &m_resultPositionType, "ResultPositionType", "Result Position" );
8385
m_resultPositionType.uiCapability()->setUiHidden( true );
8486

85-
CAF_PDM_InitField( &m_resultFieldName, "ResultFieldName", QString( "" ), "Field Name" );
87+
CAF_PDM_InitScriptableField( &m_resultFieldName, "ResultFieldName", QString( "" ), "Field Name" );
8688
m_resultFieldName.uiCapability()->setUiHidden( true );
8789

88-
CAF_PDM_InitField( &m_resultComponentName, "ResultComponentName", QString( "" ), "Component" );
90+
CAF_PDM_InitScriptableField( &m_resultComponentName, "ResultComponentName", QString( "" ), "Component" );
8991
m_resultComponentName.uiCapability()->setUiHidden( true );
9092

9193
CAF_PDM_InitField( &m_timeLapseBaseTimestep, "TimeLapseBaseTimeStep", RigFemResultAddress::noTimeLapseValue(), "Base Time Step" );
@@ -541,6 +543,14 @@ void RimGeoMechResultDefinition::initAfterRead()
541543
{
542544
if ( m_resultComponentName() == "STM" || m_resultComponentName() == "SEM" ) m_resultComponentName = "SM";
543545

546+
updateUiFieldsFromActiveResult();
547+
}
548+
549+
//--------------------------------------------------------------------------------------------------
550+
/// Sync the UI fields after the result fields are set directly, e.g. from scripting
551+
//--------------------------------------------------------------------------------------------------
552+
void RimGeoMechResultDefinition::updateUiFieldsFromActiveResult()
553+
{
544554
m_resultPositionTypeUiField = m_resultPositionType;
545555
m_resultVariableUiField = composeFieldCompString( m_resultFieldName(), m_resultComponentName() );
546556
m_compactionRefLayerUiField = m_compactionRefLayer;

‎ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechResultDefinition.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "RimCheckableObject.h"
2424
#include "RimFemResultObserver.h"
25+
#include "RimResultDefinitionInterface.h"
2526

2627
#include "RigFemResultPosEnum.h"
2728

@@ -41,7 +42,7 @@ class RimRegularLegendConfig;
4142
///
4243
///
4344
//==================================================================================================
44-
class RimGeoMechResultDefinition : public RimFemResultObserver, public RimCheckableObject
45+
class RimGeoMechResultDefinition : public RimFemResultObserver, public RimCheckableObject, public RimResultDefinitionInterface
4546
{
4647
CAF_PDM_HEADER_INIT;
4748

@@ -54,7 +55,8 @@ class RimGeoMechResultDefinition : public RimFemResultObserver, public RimChecka
5455

5556
RigGeoMechCaseData* ownerCaseData() const;
5657
bool hasResult();
57-
void loadResult();
58+
void loadResult() override;
59+
void updateUiFieldsFromActiveResult() override;
5860
void setAddWellPathDerivedResults( bool addWellPathDerivedResults );
5961

6062
RigFemResultAddress resultAddress() const;

‎ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechView.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "cafDisplayCoordTransform.h"
7777
#include "cafFrameAnimationControl.h"
7878
#include "cafOverlayScalarMapperLegend.h"
79+
#include "cafPdmFieldScriptingCapability.h"
7980
#include "cafPdmUiTreeOrdering.h"
8081
#include "cafProgressInfo.h"
8182

@@ -96,7 +97,7 @@ RimGeoMechView::RimGeoMechView()
9697
{
9798
CAF_PDM_InitScriptableObject( "Geomechanical View", ":/3DViewGeoMech16x16.png", "", "The Geomechanical 3d View" );
9899

99-
CAF_PDM_InitFieldNoDefault( &cellResult, "GridCellResult", "Color Result", ":/CellResult.png" );
100+
CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( &cellResult, "GridCellResult", "CellResult", "Color Result", ":/CellResult.png" );
100101
cellResult = new RimGeoMechCellColors();
101102

102103
CAF_PDM_InitFieldNoDefault( &m_tensorResults, "TensorResults", "Tensor Results" );

‎ApplicationLibCode/ProjectDataModel/RimEclipseResultDefinition.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "RimCheckableObject.h"
2929
#include "RimFlowDiagSolution.h"
30+
#include "RimResultDefinitionInterface.h"
3031

3132
#include "cafAppEnum.h"
3233
#include "cafPdmField.h"
@@ -49,7 +50,7 @@ class RigEclipseResultAddress;
4950
///
5051
///
5152
//==================================================================================================
52-
class RimEclipseResultDefinition : public RimCheckableObject
53+
class RimEclipseResultDefinition : public RimCheckableObject, public RimResultDefinitionInterface
5354
{
5455
CAF_PDM_HEADER_INIT;
5556

@@ -102,7 +103,7 @@ class RimEclipseResultDefinition : public RimCheckableObject
102103
int caseDiffIndex() const;
103104
QString additionalResultText() const;
104105

105-
virtual void loadResult();
106+
void loadResult() override;
106107
void setEagerResultLoadingEnabled( bool enabled );
107108
RigEclipseResultAddress eclipseResultAddress() const;
108109
void setFromEclipseResultAddress( const RigEclipseResultAddress& resultAddress );
@@ -125,7 +126,7 @@ class RimEclipseResultDefinition : public RimCheckableObject
125126
void setSelectedProducerTracers( const std::vector<QString>& selectedTracers );
126127
void setSelectedSouringTracers( const std::vector<QString>& selectedTracers );
127128

128-
void updateUiFieldsFromActiveResult();
129+
void updateUiFieldsFromActiveResult() override;
129130

130131
bool showDualPorosityLabel() const;
131132

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (C) 2026- Equinor ASA
4+
//
5+
// ResInsight is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
11+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE.
13+
//
14+
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
15+
// for more details.
16+
//
17+
/////////////////////////////////////////////////////////////////////////////////
18+
19+
#pragma once
20+
21+
//==================================================================================================
22+
// Interface implemented by result definitions (e.g. RimEclipseResultDefinition and
23+
// RimGeoMechResultDefinition) that can be updated after their active result has been changed
24+
// programmatically, e.g. from the scripting/gRPC interface.
25+
//==================================================================================================
26+
class RimResultDefinitionInterface
27+
{
28+
public:
29+
virtual ~RimResultDefinitionInterface() = default;
30+
31+
virtual void updateUiFieldsFromActiveResult() = 0;
32+
virtual void loadResult() = 0;
33+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
######################################################################
2+
# This script applies a geomechanical cell result to the first view
3+
# of the first GeoMech case in the project
4+
######################################################################
5+
import sys
6+
7+
import rips
8+
9+
resinsight = rips.Instance.find()
10+
11+
cases = resinsight.project.descendants(rips.GeoMechCase)
12+
if not cases:
13+
print("No GeoMech cases in project")
14+
sys.exit(1)
15+
16+
view = cases[0].views()[0]
17+
18+
cell_result = view.cell_result()
19+
cell_result.result_position_type = "ELEMENT_NODAL"
20+
cell_result.result_field_name = "SE"
21+
cell_result.result_component_name = "S33"
22+
cell_result.update()

‎GrpcInterface/Python/rips/pdmobject.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ def ancestor(self, class_definition: Type[PdmObjectT]) -> Optional[PdmObjectT]:
521521
)
522522
try:
523523
pb2_object = self._pdm_object_stub.GetAncestorPdmObject(request)
524+
from .generated.generated_classes import class_from_keyword
525+
526+
actual_class = class_from_keyword(pb2_object.class_keyword)
527+
if actual_class is not None and issubclass(actual_class, class_definition):
528+
class_definition = actual_class
524529
pdm_object = class_definition(pb2_object=pb2_object, channel=self.channel())
525530
return pdm_object
526531
except grpc.RpcError as e:

‎GrpcInterface/Python/rips/view.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def extract_address(address) -> int:
115115
@add_method(View)
116116
def case(self):
117117
"""Get the case the view belongs to"""
118+
if isinstance(self, GeoMechView):
119+
# Geomechanical views are children of their case
120+
return self.ancestor(rips.case.Case)
121+
118122
project = self.ancestor(rips.project.Project)
119123

120124
eclipse_case_addr = extract_address(self.eclipse_case)

‎GrpcInterface/RiaGrpcPdmObjectService.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "RiaLogging.h"
2525
#include "RiaOpenTelemetryManager.h"
2626

27-
#include "RimEclipseResultDefinition.h"
2827
#include "RimProject.h"
28+
#include "RimResultDefinitionInterface.h"
2929

3030
#include "cafPdmAbstractFieldScriptingCapability.h"
3131
#include "cafPdmObject.h"
@@ -451,9 +451,7 @@ grpc::Status RiaGrpcPdmObjectService::UpdateExistingPdmObject( grpc::ServerConte
451451
}
452452

453453
// Validation succeeded - update UI and views
454-
RimEclipseResultDefinition* resultDefinition = dynamic_cast<RimEclipseResultDefinition*>( matchingObject );
455-
// TODO: Make this more general. Perhaps we need an interface method for updating UI fields
456-
if ( resultDefinition )
454+
if ( auto resultDefinition = dynamic_cast<RimResultDefinitionInterface*>( matchingObject ) )
457455
{
458456
resultDefinition->updateUiFieldsFromActiveResult();
459457
resultDefinition->loadResult();

0 commit comments

Comments
 (0)