Skip to content

Commit

Permalink
Use GridGenerator in tests
Browse files Browse the repository at this point in the history
Resolving deprecation warning from Grid.createRectangular
  • Loading branch information
berland committed Sep 2, 2024
1 parent 3712d21 commit a2df4c2
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 63 deletions.
22 changes: 11 additions & 11 deletions python/tests/rd_tests/test_fault_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from resdata import ResDataType
from resdata.resfile import ResdataKW
from resdata.grid import Grid, ResdataRegion
from resdata.grid import Grid, ResdataRegion, GridGenerator
from resdata.grid.faults import FaultBlock, FaultBlockLayer, FaultCollection
from resdata.geometry import Polyline, CPolylineCollection
from resdata.util.test import TestAreaContext
Expand All @@ -13,7 +13,7 @@

class FaultBlockTest(ResdataTest):
def setUp(self):
self.grid = Grid.createRectangular((10, 10, 10), (1, 1, 1))
self.grid = GridGenerator.createRectangular((10, 10, 10), (1, 1, 1))
self.kw = ResdataKW("FAULTBLK", self.grid.getGlobalSize(), ResDataType.RD_INT)
self.kw.assign(1)

Expand All @@ -26,7 +26,7 @@ def setUp(self):
self.kw[k * self.grid.getNX() * self.grid.getNY() + 7] = 177

def test_fault_block(self):
grid = Grid.createRectangular((5, 5, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((5, 5, 1), (1, 1, 1))
kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT)
kw.assign(0)
for j in range(1, 4):
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_get_ijk(self):
with cwrap.open("kw.grdecl") as f:
kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT)

grid = Grid.createRectangular((5, 5, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((5, 5, 1), (1, 1, 1))
layer = FaultBlockLayer(grid, 0)
layer.loadKeyword(kw)

Expand Down Expand Up @@ -85,7 +85,7 @@ def test_neighbours(self):
with cwrap.open("kw.grdecl") as f:
kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT)

grid = Grid.createRectangular((5, 5, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((5, 5, 1), (1, 1, 1))
layer = FaultBlockLayer(grid, 0)

layer.loadKeyword(kw)
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_neighbours2(self):
nx = 8
ny = 8
nz = 1
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
layer = FaultBlockLayer(grid, 0)
with TestAreaContext("python/FaultBlocks/neighbours"):
with open("faultblock.grdecl", "w") as fileH:
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_neighbours3(self):
nx = 8
ny = 8
nz = 1
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
layer = FaultBlockLayer(grid, 0)
with TestAreaContext("python/FaultBlocks/neighbours"):
with open("faultblock.grdecl", "w") as fileH:
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_neighbours3(self):
self.assertTrue(b2 in nb)

def test_fault_block_edge(self):
grid = Grid.createRectangular((5, 5, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((5, 5, 1), (1, 1, 1))
kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT)
kw.assign(0)
for j in range(1, 4):
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_fault_block_layer(self):
self.assertEqual([1, 2, 3], list(fault_block.getRegionList()))

def test_add_polyline_barrier1(self):
grid = Grid.createRectangular((4, 1, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((4, 1, 1), (1, 1, 1))
layer = FaultBlockLayer(self.grid, 0)
polyline = Polyline(init_points=[(1.99, 0.001), (2.01, 0.99)])

Expand All @@ -349,7 +349,7 @@ def test_add_polyline_barrier1(self):
self.assertFalse(geo_layer.cellContact(p1, p2))

def test_add_polyline_barrier2(self):
grid = Grid.createRectangular((10, 10, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((10, 10, 1), (1, 1, 1))
layer = FaultBlockLayer(self.grid, 0)
polyline = Polyline(init_points=[(0.1, 0.9), (8.9, 0.9), (8.9, 8.9)])

Expand Down Expand Up @@ -389,7 +389,7 @@ def test_internal_blocks(self):
nx = 8
ny = 8
nz = 1
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
layer = FaultBlockLayer(grid, 0)
with TestAreaContext("python/FaultBlocks/internal_blocks"):
with open("faultblock.grdecl", "w") as fileH:
Expand Down
30 changes: 15 additions & 15 deletions python/tests/rd_tests/test_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from resdata import ResDataType
from resdata.resfile import ResdataKW
from resdata.grid import Grid
from resdata.grid import Grid, GridGenerator
from resdata.grid.faults import (
FaultCollection,
Fault,
Expand All @@ -21,7 +21,7 @@
class FaultTest(ResdataTest):
@classmethod
def setUpClass(cls):
cls.grid = Grid.createRectangular((151, 100, 50), (1, 1, 1))
cls.grid = GridGenerator.createRectangular((151, 100, 50), (1, 1, 1))

def setUp(self):
self.faults1 = self.createTestPath("local/ECLIPSE/FAULTS/fault1.grdecl")
Expand All @@ -31,7 +31,7 @@ def test_PolylineIJ(self):
nx = 10
ny = 10
nz = 10
grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1))
grid = GridGenerator.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1))
f = Fault(grid, "F")
f.addRecord(0, 1, 0, 0, 0, 0, "Y-")
f.addRecord(2, 2, 0, 1, 0, 0, "X-")
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_faultLine_center(self):
nx = 10
ny = 10
nz = 2
grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1))
grid = GridGenerator.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1))
fl = FaultLine(grid, 0)
C1 = (nx + 1) * 5 + 3
C2 = C1 + 2
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_load(self):
faults.load(self.grid, "No/this/does/not/exist")

def test_connect_faults(self):
grid = Grid.createRectangular((100, 100, 10), (1, 1, 1))
grid = GridGenerator.createRectangular((100, 100, 10), (1, 1, 1))

# Fault1 Fault4
# | |
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_intersect_intRays(self):
self.assertEqual(join, [p1, p2])

def test_join_faults(self):
grid = Grid.createRectangular((100, 100, 10), (1, 1, 1))
grid = GridGenerator.createRectangular((100, 100, 10), (1, 1, 1))

# Fault1 Fault4
# | |
Expand Down Expand Up @@ -373,7 +373,7 @@ def test_join_faults(self):
self.assertEqual(extra, [(2, 10), (2, 6), (5, 6)])

def test_contact(self):
grid = Grid.createRectangular((100, 100, 10), (1, 1, 1))
grid = GridGenerator.createRectangular((100, 100, 10), (1, 1, 1))

# Fault1 Fault4
# | |
Expand Down Expand Up @@ -471,7 +471,7 @@ def test_fault_line_order(self):
nx = 120
ny = 60
nz = 43
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
with TestAreaContext("python/faults/line_order"):
with open("faults.grdecl", "w") as f:
f.write(
Expand Down Expand Up @@ -509,7 +509,7 @@ def test_neighbour_cells(self):
nx = 10
ny = 8
nz = 7
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
faults_file = self.createTestPath("local/ECLIPSE/FAULTS/faults_nb.grdecl")
faults = FaultCollection(grid, faults_file)

Expand Down Expand Up @@ -570,7 +570,7 @@ def test_neighbour_cells(self):
self.assertListEqual(nb_cells1, true_nb_cells1)

def test_polyline_intersection(self):
grid = Grid.createRectangular((100, 100, 10), (0.25, 0.25, 1))
grid = GridGenerator.createRectangular((100, 100, 10), (0.25, 0.25, 1))

# Fault1 Fault4
# | |
Expand Down Expand Up @@ -609,7 +609,7 @@ def test_num_linesegment(self):
nx = 10
ny = 10
nz = 1
grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1))
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1))
with TestAreaContext("python/faults/line_order"):
with open("faults.grdecl", "w") as f:
f.write(
Expand All @@ -628,7 +628,7 @@ def test_num_linesegment(self):
self.assertEqual(1, f2.numLines(0))

def test_extend_to_polyline(self):
grid = Grid.createRectangular((3, 3, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((3, 3, 1), (1, 1, 1))

# o o o o
#
Expand All @@ -655,7 +655,7 @@ def test_extend_to_polyline(self):
self.assertIsNone(end_join)

def test_extend_polyline_on(self):
grid = Grid.createRectangular((3, 3, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((3, 3, 1), (1, 1, 1))

# o o o o
#
Expand Down Expand Up @@ -686,7 +686,7 @@ def test_extend_polyline_on(self):
self.assertIsNone(points)

def test_stepped(self):
grid = Grid.createRectangular((6, 1, 4), (1, 1, 1))
grid = GridGenerator.createRectangular((6, 1, 4), (1, 1, 1))
f = Fault(grid, "F")
f.addRecord(4, 4, 0, 0, 0, 1, "X")
f.addRecord(2, 2, 0, 0, 1, 1, "Z")
Expand Down Expand Up @@ -725,7 +725,7 @@ def test_stepped(self):
self.assertFalse(layer3.cellContact((1, 0), (2, 0)))

def test_connectWithPolyline(self):
grid = Grid.createRectangular((4, 4, 1), (1, 1, 1))
grid = GridGenerator.createRectangular((4, 4, 1), (1, 1, 1))

# o o o o o
#
Expand Down
12 changes: 6 additions & 6 deletions python/tests/rd_tests/test_geertsma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from resdata import ResDataType
from resdata.resfile import ResdataKW, openFortIO, FortIO, ResdataFile
from resdata.grid import Grid
from resdata.grid import GridGenerator
from resdata.gravimetry import ResdataSubsidence

from resdata.util.test import TestAreaContext
Expand All @@ -27,7 +27,7 @@ def create_init(grid, case):
class GeertsmaTest(ResdataTest):
@staticmethod
def test_geertsma_kernel():
grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
grid = GridGenerator.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
with TestAreaContext("Subsidence"):
p1 = [1]
create_restart(grid, "TEST", p1)
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_geertsma_kernel():

@staticmethod
def test_geertsma_kernel_2_source_points_2_vintages():
grid = Grid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))
grid = GridGenerator.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))

with TestAreaContext("Subsidence"):
p1 = [1, 10]
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_geertsma_kernel_2_source_points_2_vintages():

@staticmethod
def test_geertsma_kernel_seabed():
grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
grid = GridGenerator.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
with TestAreaContext("Subsidence"):
p1 = [1]
create_restart(grid, "TEST", p1)
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_geertsma_kernel_seabed():

@staticmethod
def test_geertsma_kernel_seabed():
grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
grid = GridGenerator.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
with TestAreaContext("Subsidence"):
p1 = [1]
create_restart(grid, "TEST", p1)
Expand All @@ -164,7 +164,7 @@ def test_geertsma_kernel_seabed():
np.testing.assert_almost_equal(dz, 5.819790154474284e-08)

def test_geertsma_rporv_kernel_2_source_points_2_vintages(self):
grid = Grid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))
grid = GridGenerator.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))

with TestAreaContext("Subsidence"):
p1 = [1, 10]
Expand Down
4 changes: 2 additions & 2 deletions python/tests/rd_tests/test_grav.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from resdata import ResDataType
from resdata.resfile import ResdataKW, ResdataFile, openFortIO, FortIO
from resdata.grid import Grid
from resdata.grid import GridGenerator
from resdata.gravimetry import ResdataGrav
from resdata.util.test import TestAreaContext
from tests import ResdataTest
Expand All @@ -10,7 +10,7 @@

class ResdataGravTest(ResdataTest):
def setUp(self):
self.grid = Grid.createRectangular((10, 10, 10), (1, 1, 1))
self.grid = GridGenerator.createRectangular((10, 10, 10), (1, 1, 1))

def test_create(self):
kws = [
Expand Down
6 changes: 3 additions & 3 deletions python/tests/rd_tests/test_grid_equinor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_rect(self):
a1 = 1.0
a2 = 2.0
a3 = 3.0
grid = Grid.createRectangular((9, 9, 9), (a1, a2, a3))
grid = GridGenerator.createRectangular((9, 9, 9), (a1, a2, a3))
grid.save_EGRID("rect.EGRID")
grid2 = Grid("rect.EGRID")
self.assertTrue(grid)
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_grdecl_load(self):

actnum = IntVector(default_value=1, initial_size=1000)
actnum[0] = 0
g1 = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum)
g1 = GridGenerator.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum)
self.assertEqual(g1.getNumActive(), actnum.elementSum())
g1.save_EGRID("G.EGRID")

Expand Down Expand Up @@ -220,7 +220,7 @@ def test_raise_IO_error(self):
g = Grid("/does/not/exist.EGRID")

def test_boundingBox(self):
grid = Grid.createRectangular((10, 10, 10), (1, 1, 1))
grid = GridGenerator.createRectangular((10, 10, 10), (1, 1, 1))
with self.assertRaises(ValueError):
bbox = grid.getBoundingBox2D(layer=-1)

Expand Down
10 changes: 7 additions & 3 deletions python/tests/rd_tests/test_grid_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

from resdata.resfile import ResdataKW

from resdata.grid import Grid
from resdata.grid import Grid, GridGenerator

from tests import ResdataTest


class GridPandasTest(ResdataTest):
def test_dataframe_actnum(self):
grid = Grid.create_rectangular((2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1])
grid = GridGenerator.create_rectangular(
(2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1]
)
df = grid.export_index(True)
index_matrix = np.array(
[[0, 0, 0, 0], [1, 0, 0, 1], [0, 2, 0, 2], [1, 2, 0, 3]]
Expand Down Expand Up @@ -70,7 +72,9 @@ def test_dataframe_actnum(self):
assert np.array_equal(data, np.array([10.5, 9.25, 2222.0, 2222.0, 2.0, 1.625]))

def test_dataframe_grid_data(self):
grid = Grid.create_rectangular((2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1])
grid = GridGenerator.create_rectangular(
(2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1]
)
index_frame = grid.export_index()
volume_data = grid.export_volume(index_frame)
assert len(volume_data) == 6
Expand Down
4 changes: 2 additions & 2 deletions python/tests/rd_tests/test_kw_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from resdata import ResDataType
from resdata.resfile import ResdataKW, Resdata3DKW
from resdata.grid import Grid
from resdata.grid import GridGenerator
from resdata.util.util import IntVector
from tests import ResdataTest

Expand All @@ -16,7 +16,7 @@ def test_region_filter(self):
actnum = IntVector(initial_size=nx * ny * nz, default_value=1)
actnum[nx * ny - 1] = 0

grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1), actnum=actnum)
grid = GridGenerator.createRectangular((nx, ny, nz), (1, 1, 1), actnum=actnum)
self.assertEqual(grid.getNumActive(), nx * ny * nz - 1)

kw = Resdata3DKW.create("REGIONS", grid, ResDataType.RD_INT, global_active=True)
Expand Down
Loading

0 comments on commit a2df4c2

Please sign in to comment.