Skip to content

Commit

Permalink
Fix segfault in WellStateglobalConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed May 28, 2024
1 parent 43bae3c commit a2bc01d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/resdata/well/well_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def hasGlobalConnections(self):
def globalConnections(self):
"""@rtype: list of WellConnection"""
global_connections = self._get_global_connections()
if global_connections is None:
return []
count = self._global_connections_size(global_connections)

values = []
Expand Down
37 changes: 37 additions & 0 deletions python/tests/well_tests/test_well_missing_ICON.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from tests import ResdataTest
from resdata.grid import GridGenerator
from resdata.resfile import ResdataFile
from resdata.well import (
WellInfo,
WellConnection,
Expand All @@ -24,10 +25,46 @@ def check_connections(self, well_info, expected):
well = well_info["B-2H"]
well_state = well[0]
self.assertEqual(well_state.hasGlobalConnections(), expected)
if not expected:
self.assertEqual(well_state.globalConnections(), [])
else:
self.assertGreater(len(well_state.globalConnections()), 0)
self.assertEqual(well_state.wellType(), WellType.PRODUCER)
self.assertEqual(well_state.name(), "B-2H")
self.assertTrue(well_state.isOpen())
self.assertEqual(well_state.wellHead().ijk(), (14, 30, 8))
self.assertEqual(well_state.wellNumber(), 1)
self.assertEqual(well_state.reportNumber(), 27)
self.assertEqual(
well_state.simulationTime().datetime(),
datetime.datetime(1998, 10, 13, 0, 0),
)
self.assertEqual(len(well_state), 0)
self.assertEqual(well_state.numSegments(), 0)
self.assertEqual(well_state.segments(), [])
self.assertFalse(well_state.isMultiSegmentWell())
self.assertFalse(well_state.hasSegmentData())
self.assertEqual(well_state.gasRate(), 0)
self.assertEqual(well_state.waterRate(), 0)
self.assertEqual(well_state.oilRate(), 0)
self.assertEqual(well_state.volumeRate(), 0)
self.assertEqual(well_state.gasRateSI(), 0)
self.assertEqual(well_state.oilRateSI(), 0)
self.assertEqual(well_state.waterRateSI(), 0)
self.assertEqual(well_state.volumeRateSI(), 0)

def test_missing_icon(self):
well_info_ICON0 = WellInfo(self.grid, self.rst_file_ICON0)
well_info_ICON1 = WellInfo(self.grid, self.rst_file_ICON1)
assert len(well_info_ICON0) == 8

time_line = well_info_ICON0[0]
self.assertEqual(time_line.getName(), "C-4H")
self.assertIn("C-4H", well_info_ICON0.allWellNames())

self.check_connections(well_info_ICON0, False)
self.check_connections(well_info_ICON1, True)

well_info_ICON0.addWellFile(
ResdataFile(self.rst_file_ICON0), load_segment_information=False
)

0 comments on commit a2bc01d

Please sign in to comment.