def test_simple_j_petro(): """Simple test of the simple J petrophysical function correlation""" wateroil = WaterOil(swl=0.01) wateroil.add_simple_J_petro(a=1, b=-2) check_table(wateroil.table) assert wateroil.pccomment assert "etrophysic" in wateroil.pccomment # Zero gravity: wateroil.add_simple_J_petro(a=1, b=-2, g=0) assert wateroil.table.pc.unique() == 0.0 # Numerical test from sample numbers calculated independently in different tool: wateroil = WaterOil(swl=0.05, h=0.025) wateroil.add_simple_J_petro( a=1.45, b=-0.285, drho=143, g=9.81, perm_ref=15, poro_ref=0.27 ) float_df_checker(wateroil.table, "sw", 0.1, "pc", 22.36746) assert "Simplified" in wateroil.pccomment assert "etrophysic" in wateroil.pccomment wateroil.add_corey_oil() wateroil.add_corey_water() swof = wateroil.SWOF() assert isinstance(swof, str) assert swof assert sat_table_str_ok(swof) assert sat_table_str_ok(wateroil.SWFN())
def test_let_pc_pd(): """Test LET formulation for primary drainage capillary pressure""" wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_pd(Lp=1, Ep=1, Tp=1, Lt=1, Et=1, Tt=1, Pcmax=10, Pct=5) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), 0) # (everything is linear) wateroil.add_LET_pc_pd(Lp=10, Ep=10, Tp=10, Lt=10, Et=10, Tt=10, Pcmax=10, Pct=5) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), 0) # On a plot, you can see a kink at Pc=5. # wateroil.plotpc() wateroil = WaterOil(swirr=0.1, sorw=0.4) wateroil.add_LET_pc_pd(Lp=10, Ep=10, Tp=10, Lt=10, Et=10, Tt=10, Pcmax=5, Pct=2) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 0) # On plot: hard-to-see kink at Pc=2. Linear curve from sw=0.6 to 1 due to sorw. assert ( len(wateroil.table[(wateroil.table["sw"] >= 0.6) & (wateroil.table["sw"] <= 1)]) == 2 ) wateroil.add_corey_water() wateroil.add_corey_oil() assert sat_table_str_ok(wateroil.SWOF())
def test_simple_j(): """Simple test of the simple J function correlation""" wateroil = WaterOil(swl=0.01) wateroil.add_simple_J() # swl set to zero will give infinite pc check_table(wateroil.table) assert wateroil.pccomment # Zero gravity: wateroil.add_simple_J(g=0) assert wateroil.table.pc.unique() == 0.0 # This should give back Sw: # This ensures that density and gravity scaling is correct wateroil.add_simple_J(a=1, b=1, poro_ref=1, perm_ref=1, drho=1000, g=100) assert (wateroil.table["pc"] - wateroil.table["sw"]).sum() < 0.00001 # (check_table() will fail on this, when b > 0) # Some values seen in real life: wateroil.add_simple_J(a=100, b=-1.5, poro_ref=0.12, perm_ref=100, drho=200) check_table(wateroil.table) assert "Simplified" in wateroil.pccomment assert "a=100" in wateroil.pccomment assert "b=-1.5" in wateroil.pccomment wateroil.add_corey_oil() wateroil.add_corey_water() swof = wateroil.SWOF() assert isinstance(swof, str) assert swof assert sat_table_str_ok(swof) assert sat_table_str_ok(wateroil.SWFN())
def test_wateroil_linear(): """Test linear wateroil curves""" wateroil = WaterOil(h=1) wateroil.add_corey_water() wateroil.add_corey_oil() swofstr = wateroil.SWOF(header=False) check_table(wateroil.table) check_linear_sections(wateroil) assert isinstance(swofstr, str) assert swofstr assert len(wateroil.table) == 2 assert np.isclose(wateroil.crosspoint(), 0.5) # What if there is no space for our choice of h? # We should be able to initialize nonetheless # (a warning could be given) wateroil = WaterOil(swl=0.1, h=1) wateroil.add_corey_water() wateroil.add_corey_oil() check_table(wateroil.table) check_linear_sections(wateroil) assert len(wateroil.table) == 2 assert np.isclose(wateroil.table["sw"].min(), 0.1) assert np.isclose(wateroil.table["sw"].max(), 1.0) assert np.isclose(wateroil.crosspoint(), 0.55)
def test_wateroil_tag(tag): """Test that we are unlikely to crash Eclipse by having ugly tag names""" wateroil = WaterOil(h=0.5, tag=tag) wateroil.add_corey_oil() wateroil.add_corey_water() sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN())
def test_selfcheck(columnname, errorvalues): """Test the selfcheck feature of a WaterOil object""" wateroil = WaterOil(h=1) wateroil.add_corey_water() wateroil.add_corey_oil() assert wateroil.selfcheck() # Punch the internal table directly to trigger error: wateroil.table[columnname] = errorvalues assert not wateroil.selfcheck() assert wateroil.SWOF() == "" if not columnname == "KROW": assert wateroil.SWFN() == ""
def test_wateroil_let1(l, e, t, krwend, krwmax): wo = WaterOil() try: wo.add_LET_oil(l, e, t, krwend, krwmax) wo.add_LET_water(l, e, t, krwend, krwmax) except AssertionError: # This happens for negative values f.ex. return assert "krow" in wo.table assert "krw" in wo.table assert isinstance(wo.krwcomment, str) check_table(wo.table) swofstr = wo.SWOF() assert len(swofstr) > 100
def test_let_pc_imb(): """Test the LET formulation for imbibition capillary pressures""" wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_imb( Ls=1, Es=1, Ts=1, Lf=1, Ef=1, Tf=1, Pcmax=10, Pcmin=-10, Pct=3 ) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), -10) wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_imb(Ls=5, Es=5, Ts=5, Lf=5, Ef=5, Tf=5, Pcmax=5, Pcmin=1, Pct=4) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 1) wateroil = WaterOil(swirr=0.1, sorw=0.3) wateroil.add_LET_pc_imb(Ls=5, Es=5, Ts=5, Lf=5, Ef=5, Tf=5, Pcmax=5, Pcmin=1, Pct=4) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 1) wateroil.add_corey_water() wateroil.add_corey_oil() print(wateroil.SWOF()) assert sat_table_str_ok(wateroil.SWOF())
def test_wateroil_corey1(nw, now): wo = WaterOil() try: wo.add_corey_oil(now=now) wo.add_corey_water(nw=nw) except AssertionError: # This happens for "invalid" input return assert "krow" in wo.table assert "krw" in wo.table assert isinstance(wo.krwcomment, str) check_table(wo.table) swofstr = wo.SWOF() assert len(swofstr) > 100
def test_wateroil_corey1(nw, now): """Test random corey parameters""" wateroil = WaterOil() try: wateroil.add_corey_oil(now=now) wateroil.add_corey_water(nw=nw) except AssertionError: # This happens for "invalid" input return assert "krow" in wateroil.table assert "krw" in wateroil.table assert isinstance(wateroil.krwcomment, str) check_table(wateroil.table) swofstr = wateroil.SWOF() assert len(swofstr) > 100
def test_wateroil_let1(l, e, t, krwend, krwmax): """Test random LET parameters""" wateroil = WaterOil() try: wateroil.add_LET_oil(l, e, t, krwend) wateroil.add_LET_water(l, e, t, krwend, krwmax) except AssertionError: # This happens for negative values f.ex. return assert "KROW" in wateroil.table assert "KRW" in wateroil.table assert isinstance(wateroil.krwcomment, str) check_table(wateroil.table) check_linear_sections(wateroil) swofstr = wateroil.SWOF() assert len(swofstr) > 100
def testplot(): """Generate and plot relperm curves Use this as a template function. """ swof = WaterOil(tag="Testcurve", h=0.01, swirr=0.2, swl=0.2, sorw=0.1) swof.add_corey_water(nw=5, krwend=0.7, krwmax=0.9) swof.add_corey_oil(now=2, kroend=0.95) swof.add_LET_water(l=2, e=1, t=1.4, krwend=0.7, krwmax=0.9) swof.add_LET_oil(l=2, e=1, t=1.4, kroend=0.9) # Print the first 7 lines of SWOF: print("\n".join(swof.SWOF().split("\n")[0:8])) _, mpl_ax = plt.subplots() swof.plotkrwkrow(mpl_ax) plt.show()
def main(): """Entry point for interactive tests, will run some tests where the intention is that the user will look at what is displayed, and potentially see if something looks really bad""" print("-- **********************************") print("-- Manual check of output") swof = WaterOil(tag="Good sand, SATNUM 1", h=0.1, swl=0.1) swof.add_corey_water() swof.add_LET_water() swof.add_corey_oil() swof.add_simple_J() print(swof.SWOF()) sgof = GasOil(tag="Good sand, SATNUM 1", h=0.1) sgof.add_corey_gas() sgof.add_corey_oil() print(sgof.SGOF()) print("") print("-- ******************************************") print("-- Manual visual check of interpolation in LET-space") print("-- Check:") print("-- * green curves are between red and blue blue line") print("-- (close plot window to continue)") for _ in range(0, 5): test_interpolate_wo() test_interpolate_go() test_interpolate_gw() print("") print("-- ******************************************") print("-- Manual visual check of interpolation in LET-space") print("-- Check:") print("-- * Red curves are between dotted and solid blue line") print("-- * Green curves are between solid blue and dashed") print("-- (close plot window to continue)") interpolateplottest() print("") print("-- ***********************************************") print("-- Span of LET curves when LET parameters are varied") print("-- within the bounds of the parameters of the red curves") print( "-- Blue dim curves are allowed to go outside the red boundary curves") print("-- (close plot window to continue)") letspan()
def test_norm_j_pc_random(swirr, swl, a_pc, b_pc, poro, perm, sigma_costau): """Test many possibilities of Pc-parameters. Outside of the tested range, there are many combination of parameters that can give infinite capillary pressure""" swl = swirr + swl # No point in getting too many AssertionErrors wateroil = WaterOil(swirr=swirr, swl=swl, h=0.01) try: wateroil.add_normalized_J( a=a_pc, b=b_pc, perm=perm, poro=poro, sigma_costau=sigma_costau ) except (AssertionError, ValueError): # when poro is < 0 f.ex. return check_table(wateroil.table) wateroil.add_corey_water() wateroil.add_corey_oil() assert sat_table_str_ok(wateroil.SWOF())
def test_swof_generation() -> None: """ Testing if the FlowNet code and pyscal generate the same SWOF table - test tolerance set to 4 decimals """ parameter_dict = {} parameter_dict["swirr"] = 0.01 parameter_dict["swl"] = 0.05 parameter_dict["swcr"] = 0.2 parameter_dict["sorw"] = 0.25 parameter_dict["krwend"] = 0.5 parameter_dict["krwmax"] = 0.6 parameter_dict["kroend"] = 0.95 parameter_dict["nw"] = 2.25 parameter_dict["now"] = 2.25 wateroil = WaterOil( swirr=parameter_dict["swirr"], swl=parameter_dict["swl"], swcr=parameter_dict["swcr"], sorw=parameter_dict["sorw"], h=H_CONSTANT, ) wateroil.add_corey_oil(now=parameter_dict["now"], kroend=parameter_dict["kroend"]) wateroil.add_corey_water( nw=parameter_dict["nw"], krwend=parameter_dict["krwend"], krwmax=parameter_dict["krwmax"], ) pyscal_swof_string = wateroil.SWOF( header=False, dataincommentrow=False ).splitlines()[3:-1] numpy_swof_string = swof_from_parameters(parameter_dict).splitlines() for i, line in enumerate(pyscal_swof_string): assert [round(float(elem), 4) for elem in line.split()] == [ round(float(elem), 4) for elem in numpy_swof_string[i].split() ]
def main(): print("-- **********************************") print("-- Manual check of output") swof = WaterOil(tag="Good sand, SATNUM 1", h=0.1, swl=0.1) swof.add_corey_water() swof.add_LET_water() swof.add_corey_oil() swof.add_simple_J() print(swof.SWOF()) sgof = GasOil(tag="Good sand, SATNUM 1", h=0.1) sgof.add_corey_gas() sgof.add_corey_oil() print(sgof.SGOF()) print("") print("-- ***************************************") print("-- Test of one Corey curve set") print("-- Check that all the defined endpoints are correct") print("-- (close plot window to continue)") testplot() print("") print("-- ******************************************") print("-- Manual visual check of interpolation in LET-space") print("-- Check:") print("-- * Red curves are between dotted and solid blue line") print("-- * Green curves are between solid blue and dashed") print("-- (close plot window to continue)") interpolateplottest() print("") print("-- ***********************************************") print("-- Span of LET curves when LET parameters are varied") print("-- within the bounds of the parameters of the red curves") print("-- Blue dim curves are allowed to go outside the red boundary curves") print("-- (close plot window to continue)") letspan()
def test_comments(): """Test that the outputters include endpoints in comments""" wateroil = WaterOil(h=0.3) wateroil.add_corey_water() wateroil.add_corey_oil() swfn = wateroil.SWFN() assert "--" in swfn assert "pyscal: " in swfn # part of version string assert "swirr=0" in swfn assert "swcr=0" in swfn assert "swl=0" in swfn assert "sorw=0" in swfn assert "nw=2" in swfn assert "krwend=1" in swfn assert "Corey" in swfn assert "krw = krow @ sw=0.5" in swfn assert "Zero capillary pressure" in swfn assert "SW" in swfn assert "KRW" in swfn assert "KROW" not in swfn assert "PC" in swfn swof = wateroil.SWOF() assert "--" in swof assert "pyscal: " in swof # part of version string assert "swirr=0" in swof assert "swcr=0" in swof assert "swl=0" in swof assert "sorw=0" in swof assert "nw=2" in swof assert "now=2" in swof assert "krwend=1" in swof assert "Corey" in swof assert "krw = krow @ sw=0.5" in swof assert "Zero capillary pressure" in swof assert "SW" in swof assert "KRW" in swof assert "KROW" in swof assert "PC" in swof
def test_simple_j_petro(): """Simple test of the simple J petrophysical function correlation""" wateroil = WaterOil(swl=0) with pytest.raises(ValueError, match="swl must be larger than zero"): wateroil.add_simple_J_petro(a=1, b=-2) wateroil = WaterOil(swl=0.01) wateroil.add_simple_J_petro(a=1, b=-2) check_table(wateroil.table) assert wateroil.pccomment assert "etrophysic" in wateroil.pccomment # Zero gravity: wateroil.add_simple_J_petro(a=1, b=-2, g=0) assert wateroil.table["PC"].unique() == 0.0 # Numerical test from sample numbers calculated independently in different tool: wateroil = WaterOil(swl=0.05, h=0.025) wateroil.add_simple_J_petro(a=1.45, b=-0.285, drho=143, g=9.81, perm_ref=15, poro_ref=0.27) float_df_checker(wateroil.table, "SW", 0.1, "PC", 22.36746) assert "Simplified" in wateroil.pccomment assert "etrophysic" in wateroil.pccomment wateroil.add_corey_oil() wateroil.add_corey_water() swof = wateroil.SWOF() assert isinstance(swof, str) assert swof sat_table_str_ok(swof) sat_table_str_ok(wateroil.SWFN()) with pytest.raises(ValueError, match="positive b"): wateroil = WaterOil(swl=0.01) wateroil.add_simple_J_petro(a=1, b=2)