Skip to content

Commit 225d034

Browse files
authored
Fault distance from point (#13367)
* Add python interface for distance to closest fault * Split up some older code into multiple files. * Add python test
1 parent 4d312ec commit 225d034

17 files changed

Lines changed: 896 additions & 554 deletions

ApplicationLibCode/ReservoirDataModel/RigFault.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,28 @@ void RigFaultsPrCellAccumulator::setFaultIdx( size_t reservoirCellIndex, cvf::St
231231
{
232232
m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx;
233233
}
234+
235+
//--------------------------------------------------------------------------------------------------
236+
///
237+
//--------------------------------------------------------------------------------------------------
238+
std::pair<double, cvf::StructGridInterface::FaceType> RigFault::minimumDistanceToPoint( const cvf::Vec3d& point, const RigMainGrid* mainGrid ) const
239+
{
240+
double minDistance = std::numeric_limits<double>::max();
241+
cvf::StructGridInterface::FaceType minFace = cvf::StructGridInterface::NO_FACE;
242+
for ( const FaultFace& ff : m_faultFaces )
243+
{
244+
const RigCell& cell = mainGrid->cell( ff.m_nativeReservoirCellIndex );
245+
if ( cell.isInvalid() ) continue;
246+
247+
for ( auto& c : cell.faceCorners( ff.m_nativeFace ) )
248+
{
249+
double distance = ( c - point ).length();
250+
if ( distance < minDistance )
251+
{
252+
minDistance = distance;
253+
minFace = ff.m_nativeFace;
254+
}
255+
}
256+
}
257+
return std::make_pair( minDistance, minFace );
258+
}

ApplicationLibCode/ReservoirDataModel/RigFault.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class RigFault : public cvf::Object
9797

9898
static bool ordering( CellAndFace first, CellAndFace second );
9999

100+
std::pair<double, cvf::StructGridInterface::FaceType> minimumDistanceToPoint( const cvf::Vec3d& point, const RigMainGrid* mainGrid ) const;
101+
100102
private:
101103
QString m_name;
102104

ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,28 @@ const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace( size_t reservoir
809809
return nullptr;
810810
}
811811

812+
//--------------------------------------------------------------------------------------------------
813+
/// Returns the name of the closest fault, the distance to the fault, and the face type of the closest face
814+
//--------------------------------------------------------------------------------------------------
815+
std::tuple<QString, double, cvf::StructGridInterface::FaceType> RigMainGrid::minimumDistanceFaultToPoint( const cvf::Vec3d& point ) const
816+
{
817+
double minDistance = std::numeric_limits<double>::max();
818+
cvf::StructGridInterface::FaceType minFace = cvf::StructGridInterface::FaceType::NO_FACE;
819+
QString minFaultName;
820+
for ( const auto& fault : m_faults )
821+
{
822+
auto [faultMinDistance, faultMinFace] = fault->minimumDistanceToPoint( point, this );
823+
824+
if ( faultMinDistance < minDistance )
825+
{
826+
minDistance = faultMinDistance;
827+
minFace = faultMinFace;
828+
minFaultName = fault->name();
829+
}
830+
}
831+
return { minFaultName, minDistance, minFace };
832+
}
833+
812834
//--------------------------------------------------------------------------------------------------
813835
///
814836
//--------------------------------------------------------------------------------------------------

ApplicationLibCode/ReservoirDataModel/RigMainGrid.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "cvfBoundingBox.h"
2828
#include "cvfCollection.h"
2929

30+
#include <QString>
31+
3032
#include <vector>
3133

3234
class RigActiveCellInfo;
@@ -116,6 +118,8 @@ class RigMainGrid : public RigGridBase
116118
// invalidate all cells with I > iLimit (0 based index)
117119
void invalidateCellsAboveI( size_t iLimit );
118120

121+
std::tuple<QString, double, cvf::StructGridInterface::FaceType> minimumDistanceFaultToPoint( const cvf::Vec3d& point ) const;
122+
119123
protected: // only for use by file readers and internal services. TODO: replace with a better API
120124
friend class RigGridBase;
121125
friend class RigReservoirBuilder;
@@ -124,7 +128,7 @@ class RigMainGrid : public RigGridBase
124128
friend class RifReaderEclipseOutput;
125129
friend class RifReaderOpmCommon;
126130
friend class RiaGrpcCaseService;
127-
friend class RiaActiveCellInfoStateHandler;
131+
friend class RiaGrpcActiveCellInfoStateHandler;
128132
friend class RicCreateTemporaryLgrFeature;
129133
friend class RimCornerPointCase;
130134
std::vector<RigCell>& reservoirCells();

GrpcInterface/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ set(SOURCE_GROUP_HEADER_FILES
3939
RiaGrpcApplicationInterface.h
4040
RiaGrpcWellPathService.h
4141
RiaWellPathDataToGrpcConverter.h
42+
RiaGrpcActiveCellInfoStateHandler.h
43+
RiaGrpcSelectedCellsStateHandler.h
4244
)
4345

4446
set(SOURCE_GROUP_SOURCE_FILES
@@ -58,6 +60,8 @@ set(SOURCE_GROUP_SOURCE_FILES
5860
RiaGrpcApplicationInterface.cpp
5961
RiaGrpcWellPathService.cpp
6062
RiaWellPathDataToGrpcConverter.cpp
63+
RiaGrpcActiveCellInfoStateHandler.cpp
64+
RiaGrpcSelectedCellsStateHandler.cpp
6165
)
6266

6367
# Find Protobuf installation Looks for protobuf-config.cmake file installed by

GrpcInterface/GrpcProtos/Case.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ service Case {
2121
rpc GetCaseInfo(CaseRequest) returns (CaseInfo) {}
2222
rpc GetPdmObject(CaseRequest) returns (PdmObject) {}
2323
rpc GetReservoirBoundingBox(CaseRequest) returns (BoundingBox) {}
24+
rpc GetDistanceToClosestFault(ClosestFaultRequest) returns (ClosestFault) {}
2425
}
2526

2627
message CaseRequest { int32 id = 1; }
@@ -103,3 +104,14 @@ message SelectedCell {
103104
}
104105

105106
message SelectedCells { repeated SelectedCell cells = 1; }
107+
108+
message ClosestFaultRequest {
109+
CaseRequest case_request = 1;
110+
Vec3d point = 2;
111+
}
112+
113+
message ClosestFault {
114+
string fault_name = 1;
115+
double distance = 2;
116+
string face_name = 3;
117+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
###################################################################################
2+
# This example prints the distance to and the name of the fault closest to a point
3+
###################################################################################
4+
5+
import rips
6+
7+
resinsight = rips.Instance.find()
8+
if resinsight is None:
9+
exit(1)
10+
11+
cases = resinsight.project.cases()
12+
if len(cases) == 0:
13+
exit(1)
14+
15+
case = cases[0]
16+
print("Using case: " + case.name)
17+
18+
# random test point (positive Z for depth)
19+
point_x = 5039.84
20+
point_y = 6303.76
21+
point_z = 4144.21
22+
23+
print("Looking for closest fault to point %f, %f, %f:" % (point_x, point_y, point_z))
24+
25+
faultname, distance, facename = case.distance_to_closest_fault(
26+
point_x, point_y, point_z
27+
)
28+
29+
if facename == "":
30+
print("- No fault found!")
31+
else:
32+
print(
33+
"- Distance to closest fault %s is %f, closest face direction is %s"
34+
% (faultname, distance, facename)
35+
)

GrpcInterface/Python/rips/case.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import Case_pb2_grpc
4444
import Commands_pb2 as Cmd
4545
import PdmObject_pb2 as PdmObject_pb2
46+
import Definitions_pb2
4647

4748
import Properties_pb2
4849
import Properties_pb2_grpc
@@ -300,6 +301,17 @@ def reservoir_boundingbox(self):
300301
return self.__case_stub.GetReservoirBoundingBox(self.__request())
301302

302303

304+
@add_method(Case)
305+
def distance_to_closest_fault(self, x: float, y: float, z: float):
306+
"""Find the closest fault to the given point and return the distance, fault name and fault face"""
307+
request = Case_pb2.ClosestFaultRequest(
308+
case_request=self.__request(), point=Definitions_pb2.Vec3d(x=x, y=y, z=z)
309+
)
310+
reply = self.__case_stub.GetDistanceToClosestFault(request)
311+
312+
return (reply.fault_name, reply.distance, reply.face_name)
313+
314+
303315
@add_method(Case)
304316
def reservoir_depth_range(self) -> Tuple[float, float]:
305317
"""Get the reservoir depth range
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
import os
3+
import math
4+
import pytest
5+
6+
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
7+
import rips
8+
9+
import dataroot
10+
11+
12+
def test_faultDistance(rips_instance, initialize_test):
13+
case = rips_instance.project.load_case(
14+
dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
15+
)
16+
17+
# a test point
18+
point_x = 4817.84
19+
point_y = 5204.76
20+
point_z = 4137.21
21+
22+
faultname, distance, facename = case.distance_to_closest_fault(
23+
point_x, point_y, point_z
24+
)
25+
26+
# Fault name is unstable between grid readers, so we skip this check
27+
# assert faultname == "Undefined Grid Faults"
28+
29+
assert facename == "I+"
30+
assert math.isclose(distance, 53.84, abs_tol=0.1)

0 commit comments

Comments
 (0)