Skip to content

Commit

Permalink
Fix add_survey_RPORV looping forever on all zero input
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Jan 6, 2025
1 parent 01753df commit fefb063
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 45 deletions.
8 changes: 4 additions & 4 deletions lib/resdata/rd_grav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ static void rd_grav_survey_assert_RPORV(const rd_grav_survey_type *survey,
int active_size = grid_cache.size();
const rd_kw_type *init_porv_kw =
rd_file_iget_named_kw(init_file, PORV_KW, 0);
int check_points = 100;
int check_points = std::min(100, active_size);
int check_nr = 0;
const std::vector<int> &global_index = grid_cache.global_index();

Expand All @@ -388,8 +388,8 @@ static void rd_grav_survey_assert_RPORV(const rd_grav_survey_type *survey,
double log_pormod = log10(rporv / init_porv);

if (fabs(log_pormod) > 1) {
/* Detected as error if the effective pore volume multiplier
is greater than 10 or less than 0.10. */
// Detected as error if the effective pore volume multiplier
// is greater than 10 or less than 0.10.
fprintf(stderr, "----------------------------------------------"
"-------------------\n");
fprintf(stderr, "INIT PORV : %g \n", init_porv);
Expand All @@ -406,8 +406,8 @@ static void rd_grav_survey_assert_RPORV(const rd_grav_survey_type *survey,
"-------------------\n");
exit(1);
}
check_nr++;
}
check_nr++;
}
}

Expand Down
111 changes: 70 additions & 41 deletions python/tests/rd_tests/test_grav.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,46 @@
from resdata.gravimetry import ResdataGrav
from resdata.util.test import TestAreaContext
from tests import ResdataTest
from resdata.rd_util import Phase


def write_kws(filename, kws):
with openFortIO(filename + ".UNRST", mode=FortIO.WRITE_MODE) as f:
seq_hdr = ResdataKW("SEQNUM", 1, ResDataType.RD_INT)
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)

header = ResdataKW("INTEHEAD", 95, ResDataType.RD_INT)
header[14] = 1 # sets phase to oil
header[94] = 100 # E100
with openFortIO(filename + ".INIT", mode=FortIO.WRITE_MODE) as f:
header.fwrite(f)
for kw in kws:
kw.fwrite(f)


class ResdataGravTest(ResdataTest):
Expand Down Expand Up @@ -42,49 +81,13 @@ def test_create(self):
kws += int_kws

with TestAreaContext("grav_init"):
with openFortIO("TEST.UNRST", mode=FortIO.WRITE_MODE) as f:
seq_hdr = ResdataKW("SEQNUM", 1, ResDataType.RD_INT)
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)

write_kws("TEST", kws)
# The init file created here only contains a PORO field. More
# properties must be added to this before it can be used for
# any useful 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:
header.fwrite(f)
for kw in kws:
kw.fwrite(f)
self.init = ResdataFile("TEST.INIT")
init = ResdataFile("TEST.INIT")

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

restart_file = ResdataFile("TEST.UNRST")
restart_view = restart_file.restartView(sim_time=datetime.date(2000, 1, 1))
Expand All @@ -100,6 +103,32 @@ def test_create(self):
grav.eval("rporv", "pormod", (0, 0, 0), phase_mask=1)

# Test that missing std_density raises
grav = ResdataGrav(self.grid, self.init)
grav = ResdataGrav(self.grid, init)
with self.assertRaises(ValueError):
grav.add_survey_FIP("fip", restart_view)

def test_create_minimal(self):
kws = [
ResdataKW(kw, self.grid.getGlobalSize(), ResDataType.RD_FLOAT)
for kw in [
"PORO",
"PORV",
"SWAT",
"OIL_DEN",
"RPORV",
]
]

with TestAreaContext("grav_init"):
write_kws("TEST", kws)
init = ResdataFile("TEST.INIT")

grav = ResdataGrav(self.grid, 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)

0 comments on commit fefb063

Please sign in to comment.