Skip to content

Commit

Permalink
Add more tests to check c calls
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Apr 23, 2024
1 parent 000db1e commit c47fe8e
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 17 deletions.
3 changes: 3 additions & 0 deletions python/tests/geometry_tests/test_cpolyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def test_name(self):
p2 = CPolyline(name="Poly2")
self.assertEqual(p2.getName(), "Poly2")

p1 = CPolyline.createFromXYZFile(self.polyline1, name="poly")
self.assertEqual(p1.getName(), "poly")

def test_unzip(self):
pl = CPolyline(init_points=[(0, 3), (1, 4), (2, 5)])
x, y = pl.unzip()
Expand Down
7 changes: 7 additions & 0 deletions python/tests/geometry_tests/test_geo_pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def test_getitem(self):
gp = GeoPointset.fromSurface(srf)
for i in (561, 1105, 1729, 2465, 2821):
self.assertEqual(gp[i], srf[i])

def test_equal(self):
srf_path = self.createTestPath("local/geometry/surface/valid_ascii.irap")
srf = Surface(srf_path)
gp = GeoPointset.fromSurface(srf)
gp2 = GeoPointset.fromSurface(srf)
self.assertEqual(gp, gp2)
7 changes: 7 additions & 0 deletions python/tests/rd_tests/test_fault_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ def test_fault_block_layer(self):
l0 = layer[0]
l1 = layer[1]
self.assertTrue(isinstance(l1, FaultBlock))
assert l1[0].i == 7
assert l1[0].j == 0
l0.getCentroid()
l1.getBlockID()
assert list(l1.get_region_list()) == []

with self.assertRaises(IndexError):
l2 = layer[2]
Expand All @@ -278,6 +281,10 @@ def test_fault_block_layer(self):

l1 = layer.getBlock(1)
self.assertTrue(isinstance(l1, FaultBlock))
l1.add_cell(9, 9)
assert len(l1.get_global_index_list()) == len(l1)
polyline = Polyline(init_points=[(1.0, 0.0), (2.0, 1.0)])
assert l1.contains_polyline(polyline)

with self.assertRaises(KeyError):
l = layer.getBlock(66)
Expand Down
6 changes: 6 additions & 0 deletions python/tests/rd_tests/test_geertsma.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import pytest
from resdata import ResDataType
from resdata.resfile import ResdataKW, openFortIO, FortIO, ResdataFile
from resdata.grid import Grid
Expand Down Expand Up @@ -80,6 +81,7 @@ def test_geertsma_kernel():

subsidence = ResdataSubsidence(grid, init)
subsidence.add_survey_PRESSURE("S1", restart_view1)
subsidence.add_survey_PRESSURE("S2", restart_view1)

youngs_modulus = 5e8
poisson_ratio = 0.3
Expand All @@ -100,6 +102,10 @@ def test_geertsma_kernel():
)
np.testing.assert_almost_equal(dz, 5.8160298201497136e-08)

assert subsidence.eval(
"S1", "S2", receiver, youngs_modulus, poisson_ratio
) == pytest.approx(0.0)

@staticmethod
def test_geertsma_kernel_2_source_points_2_vintages():
grid = Grid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))
Expand Down
89 changes: 83 additions & 6 deletions python/tests/rd_tests/test_grav.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,101 @@
import time
import datetime
from resdata import ResDataType
from resdata.resfile import ResdataKW, ResdataFile, openFortIO, FortIO
from resdata.grid import Grid
from resdata.gravimetry import ResdataGrav
from resdata.util.test import TestAreaContext
from tests import ResdataTest
from resdata.rd_util import Phase


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

def test_create(self):
# The init file created here only contains a PORO field. More
# properties must be added to this before it can be used for
# any usefull gravity calculations.
poro = ResdataKW("PORO", self.grid.getGlobalSize(), ResDataType.RD_FLOAT)

kws = [
ResdataKW(kw, self.grid.getGlobalSize(), ResDataType.RD_FLOAT)
for kw in [
"PORO",
"PORV",
"PRESSURE",
"SWAT",
"OIL_DEN",
"RPORV",
"PORV_MOD",
"FIPOIL",
"RFIPOIL",
]
]
int_kws = [
ResdataKW(kw, self.grid.getGlobalSize(), ResDataType.RD_INT)
for kw in ["FIP_NUM", "PVTNUM"]
]

for kw in kws:
for i in range(self.grid.getGlobalSize()):
kw[i] = 0.5
for kw in int_kws:
for i in range(self.grid.getGlobalSize()):
kw[i] = 0

kws += int_kws

with TestAreaContext("grav_init"):
with openFortIO("TEST.UNRST", mode=FortIO.WRITE_MODE) as f:
seq_hdr = ResdataKW("SEQNUM", 1, ResDataType.RD_FLOAT)
seq_hdr[0] = 10

header = ResdataKW("INTEHEAD", 67, ResDataType.RD_INT)
header[64] = 1
header[65] = 1
header[66] = 2000

seq_hdr.fwrite(f)
header.fwrite(f)
for kw in kws:
kw.fwrite(f)

seq_hdr[0] = 20
header[66] = 2009

seq_hdr.fwrite(f)
header.fwrite(f)
for kw in kws:
kw.fwrite(f)

seq_hdr[0] = 20
header[66] = 2010

seq_hdr.fwrite(f)
header.fwrite(f)
for kw in kws:
kw.fwrite(f)

# The init file created here only contains a PORO field. More
# properties must be added to this before it can be used for
# any usefull gravity calculations.
header = ResdataKW("INTEHEAD", 95, ResDataType.RD_INT)
header[14] = 1 # sets phase to oil
header[94] = 100 # E100
with openFortIO("TEST.INIT", mode=FortIO.WRITE_MODE) as f:
poro.fwrite(f)
header.fwrite(f)
for kw in kws:
kw.fwrite(f)
self.init = ResdataFile("TEST.INIT")

grav = ResdataGrav(self.grid, self.init)

restart_file = ResdataFile("TEST.UNRST")
restart_view = restart_file.restartView(sim_time=datetime.date(2000, 1, 1))

grav.new_std_density(1, 0.5)
grav.add_std_density(1, 0, 0.5)

grav.add_survey_RPORV("rporv", restart_view)
grav.add_survey_PORMOD("pormod", restart_view)
grav.add_survey_FIP("fip", restart_view)
grav.add_survey_RFIP("fip", restart_view)

grav.eval("rporv", "pormod", (0, 0, 0), phase_mask=1)
76 changes: 75 additions & 1 deletion python/tests/rd_tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import six
from numpy import linspace, allclose
import cwrap

from resdata.util.util import IntVector
from resdata.util.util import IntVector, DoubleVector
from resdata import ResDataType, UnitSystem
from resdata.resfile import ResdataKW, ResdataFile
from resdata.grid import Grid
Expand Down Expand Up @@ -223,13 +224,52 @@ def test_posXYEdge(self):
def test_dims(self):
grid = GridGen.createRectangular((10, 20, 30), (1, 1, 1))
self.assertEqual(grid.get_global_index1F(0), None)
self.assertTrue(grid.equal(grid))
self.assertFalse(grid.dual_grid())
self.assertEqual(grid.get_num_active_fracture(), 0)
self.assertEqual(grid.get_active_fracture_index(global_index=0), -1)
self.assertEqual(
grid.get_bounding_box_2d(),
((0.0, 0.0), (10.0, 0.0), (10.0, 20.0), (0.0, 20.0)),
)
self.assertEqual(grid.depth(ijk=(0, 0, 0)), 0.5)
self.assertEqual(grid.top(0, 0), 0.0)
self.assertEqual(grid.top_active(0, 0), 0.0)
self.assertEqual(grid.bottom(0, 0), 30.0)
self.assertEqual(grid.locate_depth(1.0, 0, 0), 1)
self.assertEqual(grid.find_cell(1.1, 0.0, 0.0), (1, 0, 0))
self.assertTrue(grid.cell_regular(ijk=(1, 0, 0)))
self.assertEqual(grid.get_layer_xyz(1, 0), (1.0, 0.0, 0.0))
self.assertEqual(grid.distance(0, 1), (-1.0, 0.0, 0.0))
self.assertEqual(grid.get_num_lgr(), 0)
self.assertFalse(grid.has_lgr("lgr"))
self.assertEqual(grid.coarse_groups(), 0)
self.assertFalse(grid.in_coarse_group(ijk=(0, 0, 0)))

with self.assertRaises(KeyError):
grid.get_lgr("lgr")
with self.assertRaises(KeyError):
grid.get_lgr(0)
with self.assertRaises(IndexError):
grid.get_cell_lgr(ijk=(0, 0, 0))
self.assertEqual(grid.getNX(), 10)
self.assertEqual(grid.getNY(), 20)
self.assertEqual(grid.getNZ(), 30)
self.assertEqual(grid.nx, 10)
self.assertEqual(grid.ny, 20)
self.assertEqual(grid.nz, 30)
self.assertEqual(grid.getGlobalSize(), 30 * 10 * 20)

self.assertEqual(grid.getDims(), (10, 20, 30, 6000))

def test_load_column(self):
column = DoubleVector(2 * 3 * 4)
grid = GridGen.createRectangular((2, 3, 4), (1, 1, 1))
kw = ResdataKW("KW", 2 * 3 * 4, ResDataType.RD_DOUBLE)
kw[0] = 1.0
grid.load_column(kw, 0, 0, column)
assert list(column) == [1.0, 0.0, 0.0, 0.0]

def test_create(self):
with self.assertRaises(ValueError):
grid = GridGen.createRectangular(
Expand Down Expand Up @@ -684,3 +724,37 @@ def test_concvex_cell_containment(self):
middle_point[2] = 30
for p in points[4:8:]:
assertNotPoint(average(20 * [p] + [middle_point]))


def test_save_grdecl(tmpdir):
grid = GridGen.createRectangular((2, 3, 4), (1, 1, 1))
with tmpdir.as_cwd():
with cwrap.open("grid.grdecl", "w") as f:
grid.save_grdecl(f)
assert grid.equal(Grid.load_from_grdecl("grid.grdecl"))
assert grid.equal(Grid.load_from_file("grid.grdecl"))


def test_save_grid(tmpdir):
grid = GridGen.create_rectangular((2, 3, 4), (1, 1, 1))
with tmpdir.as_cwd():
grid.save_GRID("grid.GRID")
assert grid.equal(Grid("grid.GRID"))


def test_write_grdecl(tmpdir):
kw = ResdataKW("KW", 2 * 3 * 4, ResDataType.RD_DOUBLE)
grid = GridGen.create_rectangular((2, 3, 4), (1, 1, 1))

with tmpdir.as_cwd():
with cwrap.open("kw.grdecl", "w") as f:
grid.write_grdecl(kw, f)
with cwrap.open("kw.grdecl", "r") as f:
kw2 = ResdataKW.read_grdecl(f, "KW")

assert list(kw) == list(kw2)


def test_create_volume_keyword():
grid = GridGen.create_rectangular((2, 3, 4), (1, 1, 1))
assert list(grid.create_volume_keyword()) == [1.0] * (2 * 3 * 4)
10 changes: 0 additions & 10 deletions python/tests/rd_tests/test_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,6 @@ def test_iadd_kw_empty(empty_region, poro):
assert poro == poro_copy


def test_iadd_kw_full(full_region, poro):
poro_copy = poro.copy()
poro.add(poro, mask=full_region)
assert poro == poro_copy * 2


def test_iadd_kw_full(full_region, poro):
poro_copy = poro.copy()
poro.add(2.0, mask=full_region)
Expand Down Expand Up @@ -496,10 +490,6 @@ def test_contains_global(full_region):
assert full_region.contains_global(0)


def test_contains_global(full_region):
assert full_region.contains_active(0)


def test_get_set_name(full_region):
full_region.set_name("full")
assert full_region.get_name() == full_region.name
Expand Down

0 comments on commit c47fe8e

Please sign in to comment.