def test_roffbin_import_v2(): """Test roff binary import ROFF using new API""" grd1 = Grid() grd1.from_file(REEKFIL4, _roffapiv=1) cell1 = np.array(grd1.get_xyz_cell_corners(ijk=(12, 13, 4))) grd2 = Grid() grd2.from_file(REEKFIL4, _roffapiv=2) cell2 = np.array(grd2.get_xyz_cell_corners(ijk=(12, 13, 4))) assert np.allclose(cell1, cell2) grd3 = Grid() grd3.from_file(DUALFIL1, _roffapiv=2) grd4 = Grid() grd4.from_file(DUALFIL2, _roffapiv=2) grd5 = Grid() grd5.from_file(DUALFIL1, _roffapiv=1) cell3 = np.array(grd3.get_xyz_cell_corners(ijk=(2, 1, 0), zerobased=True)) cell4 = np.array(grd4.get_xyz_cell_corners(ijk=(2, 1, 0), zerobased=True)) cell5 = np.array(grd5.get_xyz_cell_corners(ijk=(2, 1, 0), zerobased=True)) assert np.allclose(cell3, cell5) assert np.allclose(cell3, cell4)
def test_reverse_row_axis_dual(tmpdir): """Reverse axis for distorted but small grid""" grd = Grid(DUAL) assert grd.ijk_handedness == "left" grd.to_file(join(tmpdir, "dual_left.grdecl"), fformat="grdecl") cellcorners1 = grd.get_xyz_cell_corners((5, 1, 1)) grd.reverse_row_axis() assert grd.ijk_handedness == "right" grd.to_file(join(tmpdir, "dual_right.grdecl"), fformat="grdecl") cellcorners2 = grd.get_xyz_cell_corners((5, 3, 1)) assert cellcorners1[7] == cellcorners2[1]
def test_get_cell_corners(): """Get X Y Z for one cell as tuple""" grid = Grid(TESTFILE8A) clist = grid.get_xyz_cell_corners(ijk=(4, 4, 1)) logger.debug(clist) tsetup.assert_almostequal(clist[0], 457168.358886, 0.1)
def test_roffbin_import_v2_banal(): """Test roff binary import ROFF using new API, banal case""" t0 = xtg.timer() grd1 = Grid() grd1._xtgformat = 1 grd1.from_file(BANAL6) print("V1: ", xtg.timer(t0)) t0 = xtg.timer() grd2 = Grid() grd2._xtgformat = 2 grd2.from_file(BANAL6) print("V2: ", xtg.timer(t0)) t0 = xtg.timer() grd3 = Grid() grd3._xtgformat = 2 grd3.from_file(BANAL6) grd3._convert_xtgformat2to1() print("V3: ", xtg.timer(t0)) t0 = xtg.timer() grd4 = Grid() grd4._xtgformat = 1 grd4.from_file(BANAL6) grd4._convert_xtgformat1to2() print("V4: ", xtg.timer(t0)) for irange in range(grd1.ncol): for jrange in range(grd1.nrow): for krange in range(grd1.nlay): cell = (irange + 1, jrange + 1, krange + 1) xx1 = grd1.get_xyz_cell_corners(cell, activeonly=False) xx2 = grd2.get_xyz_cell_corners(cell, activeonly=False) xx3 = grd3.get_xyz_cell_corners(cell, activeonly=False) xx4 = grd4.get_xyz_cell_corners(cell, activeonly=False) assert np.allclose(np.array(xx1), np.array(xx2)) is True assert np.allclose(np.array(xx1), np.array(xx3)) is True assert np.allclose(np.array(xx1), np.array(xx4)) is True
def test_grid_layer_slice(): """Test grid slice coordinates.""" grd = Grid() grd.from_file(REEKFILE) sarr1, _ibarr = grd.get_layer_slice(1) sarrn, _ibarr = grd.get_layer_slice(grd.nlay, top=False) cell1 = grd.get_xyz_cell_corners(ijk=(1, 1, 1)) celln = grd.get_xyz_cell_corners(ijk=(1, 1, grd.nlay)) celll = grd.get_xyz_cell_corners(ijk=(grd.ncol, grd.nrow, grd.nlay)) assert sarr1[0, 0, 0] == cell1[0] assert sarr1[0, 0, 1] == cell1[1] assert sarrn[0, 0, 0] == celln[12] assert sarrn[0, 0, 1] == celln[13] assert sarrn[-1, 0, 0] == celll[12] assert sarrn[-1, 0, 1] == celll[13]
def test_roffbin_export_v2_banal6(): """Test roff binary export v2 for banal no. 6 case""" # export grd1 = Grid() grd1._xtgformat = 2 grd1.from_file(BANAL6) logger.info("EXPORT") grd1.to_file(join(TMPDIR, "b6_export.roffasc"), fformat="roff_asc") grd1.to_file(join(TMPDIR, "b6_export.roffbin"), fformat="roff_bin") grd2 = Grid(join(TMPDIR, "b6_export.roffbin")) cell1 = grd1.get_xyz_cell_corners((2, 2, 2)) cell2 = grd2.get_xyz_cell_corners((2, 2, 2)) assert cell1 == cell2 reek = Grid() reek._xtgformat = 2 reek.from_file(REEKFIL4) reek.to_file("TMP/reek_xtgformat2", fformat="roff_ascii")
def test_roffbin_bigbox(tmpdir): """Test roff binary for bigbox, to monitor performance""" bigbox = os.path.join(tmpdir, "bigbox.roff") if not os.path.exists(bigbox): logger.info("Create tmp big roff grid file...") grd0 = Grid() grd0.create_box(dimension=(500, 500, 100)) grd0.to_file(bigbox) grd1 = Grid() t0 = xtg.timer() grd1._xtgformat = 1 grd1.from_file(bigbox) t_old = xtg.timer(t0) logger.info("Reading bigbox xtgeformat=1 took %s seconds", t_old) cell1 = grd1.get_xyz_cell_corners((13, 14, 15)) grd2 = Grid() t0 = xtg.timer() t1 = xtg.timer() grd2._xtgformat = 2 grd2.from_file(bigbox) t_new = xtg.timer(t0) logger.info("Reading bigbox xtgformat=2 took %s seconds", t_new) cell2a = grd2.get_xyz_cell_corners((13, 14, 15)) t0 = xtg.timer() grd2._convert_xtgformat2to1() cell2b = grd2.get_xyz_cell_corners((13, 14, 15)) logger.info("Conversion to xtgformat1 took %s seconds", xtg.timer(t0)) t_newtot = xtg.timer(t1) logger.info("Total run time xtgformat=2 + conv took %s seconds", t_newtot) logger.info("Speed gain new vs old: %s", t_old / t_new) logger.info("Speed gain new incl conv vs old: %s", t_old / t_newtot) assert cell1 == cell2a assert cell1 == cell2b
def test_roffbin_banal6(): """Test roff binary for banal no. 6 case.""" grd1 = Grid() grd1.from_file(BANAL6) grd2 = Grid() grd2._xtgformat = 2 grd2.from_file(BANAL6) assert grd1.get_xyz_cell_corners() == grd2.get_xyz_cell_corners() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3)) grd2._convert_xtgformat2to1() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3)) grd2._convert_xtgformat1to2() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3))