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_wo_fromtable_multiindex(): """Test that we accept multiindex dataframes, (but a warning will be issued)""" # Test an example dataframe that easily gets sent in from ecl2df.satfunc: df1 = pd.DataFrame( columns=["KEYWORD", "SATNUM", "SW", "KRW", "KROW", "PC"], data=[ ["SWOF", 1, 0, 0, 1, 2], ["SWOF", 1, 0.5, 0.5, 0.5, 1], ["SWOF", 1, 1, 1, 0, 0], ], ).set_index(["KEYWORD", "SATNUM"]) # Check that we have a MultiIndex: assert len(df1.index.names) == 2 wateroil = WaterOil(h=0.1) wateroil.add_fromtable(df1, swcolname="SW", krwcolname="KRW", krowcolname="KROW", pccolname="PC") assert "krw" in wateroil.table.columns assert "krow" in wateroil.table.columns assert "pc" in wateroil.table.columns check_table(wateroil.table)
def test_interpolate_go( swl, sgcr, dsgcr, dswlhigh, sorg, dsorg, ng_l, ng_h, nog_l, nog_h, krgend_l, krgend_h, kroend_l, kroend_h, ): """Test many possible combinations of interpolation between two Corey gasoil curves, looking for numerical corner cases""" go_low = GasOil(swl=swl, sgcr=sgcr, sorg=sorg) go_high = GasOil(swl=swl + dswlhigh, sgcr=sgcr + dsgcr, sorg=max(sorg - dsorg, 0)) go_low.add_corey_gas(ng=ng_l, krgend=krgend_l) go_high.add_corey_gas(ng=ng_h, krgend=krgend_h) go_low.add_corey_oil(nog=nog_l, kroend=kroend_l) go_high.add_corey_oil(nog=nog_h, kroend=kroend_h) ips = [] ip_dist = 0.05 for t in np.arange(0, 1 + ip_dist, ip_dist): go_ip = utils.interpolate_go(go_low, go_high, t) check_table(go_ip.table) ips.append(go_ip) assert 0 < go_ip.crosspoint() < 1 # Distances between low and interpolants: dists = [(go_low.table - interp.table)[["krg", "krog"]].sum().sum() for interp in ips] print("Interpolation, mean: {}, min: {}, max: {}, std: {} ip-par-dist: {}". format(np.mean(dists), min(dists), max(dists), np.std(np.diff(dists[1:])), ip_dist)) assert np.isclose(dists[0], 0) # Reproducing go_low # All curves that are close in parameter t, should be close in sum().sum(). # That means that diff of the distances should be similar, # that is the std.dev of the distances is low: ip_dist_std = np.std(np.diff( dists[1:])) # This number depends on 'h' and 't' range, and # by how different the low and high is. # (avoiding the first which reproduces go_low if ip_dist_std > 1.0: # number found from trial and error. print("ip_dist_std: {}".format(ip_dist_std)) print(dists) from matplotlib import pyplot as plt _, mpl_ax = plt.subplots() go_low.plotkrgkrog(mpl_ax=mpl_ax, color="red") go_high.plotkrgkrog(mpl_ax=mpl_ax, color="blue") for interp in ips: interp.plotkrgkrog(mpl_ax=mpl_ax, color="green") plt.show() assert False
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_interpolation_deprecated(param_wo, param_go): """Testing deprecated functionality. Remove this test function when SCALrecommendation class is updated""" rec = SCALrecommendation(LOW_SAMPLE_LET, BASE_SAMPLE_LET, HIGH_SAMPLE_LET, "foo", h=0.1) rec.add_simple_J() # Add default pc curve try: interpolant = rec.interpolate(param_wo, param_go, h=0.1) except AssertionError: return check_table(interpolant.wateroil.table) check_table(interpolant.gasoil.table) assert len(interpolant.gasoil.SGOF()) > 100 assert len(interpolant.gasoil.SGFN()) > 100 assert len(interpolant.wateroil.SWFN()) > 100 assert len(interpolant.SOF3()) > 100 assert len(interpolant.wateroil.SWOF()) > 100 assert interpolant.threephaseconsistency()
def test_wo_fromtable_simple(): """Test loading a simple curve from a table""" df1 = pd.DataFrame(columns=["SW", "KRW", "KROW", "PC"], data=[[0, 0, 1, 2], [1, 1, 0, 0]]) wateroil = WaterOil(h=0.1) # With wrong names: with pytest.raises(ValueError): # Here we also get a deprecation warning wateroil.add_oilwater_fromtable(df1) # Set names: wateroil.add_fromtable(df1, swcolname="SW") # This didn't do anything, because we did not provide any relperm names assert "krw" not in wateroil.table.columns assert "krow" not in wateroil.table.columns assert "pc" not in wateroil.table.columns # Try again: wateroil.add_fromtable(df1, swcolname="SW", krwcolname="KRW", krowcolname="KROW", pccolname="PC") assert "krw" in wateroil.table.columns assert "krow" in wateroil.table.columns assert "pc" in wateroil.table.columns check_table(wateroil.table)
def test_make_scalrecommendation(): """Test that we can make scal recommendation objects from three WaterOilGas objects""" low = PyscalFactory.create_water_oil_gas(LOW_SAMPLE_LET) base = PyscalFactory.create_water_oil_gas(BASE_SAMPLE_LET) high = PyscalFactory.create_water_oil_gas(HIGH_SAMPLE_LET) rec = SCALrecommendation(low, base, high) interpolant = rec.interpolate(-0.5, h=0.2) check_table(interpolant.wateroil.table) check_table(interpolant.gasoil.table) # Check preservation of tags. swof = interpolant.SWOF() assert "SCAL recommendation interpolation to -0.5" in swof assert "SCAL recommendation interpolation to -0.5" in interpolant.SGOF() assert "SCAL recommendation interpolation to -0.5" in interpolant.SWFN() assert "SCAL recommendation interpolation to -0.5" in interpolant.SOF3() assert "SCAL recommendation interpolation to -0.5" in interpolant.SGFN() assert swof.count("SATNUM X") == 1 assert interpolant.SOF3().count("SATNUM X") == 1 # Check different comment when different interpolation parameter: interpolant = rec.interpolate(-0.777, 0.888, h=0.2) assert "SCAL recommendation interpolation to -0.777" in interpolant.SWOF() assert "SCAL recommendation interpolation to 0.888" in interpolant.SGOF()
def test_normalized_j(): """Test the normalized J-function correlation for capillary pressure""" wateroil = WaterOil(swirr=0.1, h=0.1) with pytest.raises(ValueError): wateroil.add_normalized_J(a=0.5, b=-0.2, poro=0.2, perm=10, sigma_costau=30) wateroil = WaterOil(swirr=0, swl=0.1, h=0.1) wateroil.add_normalized_J(a=0.5, b=-0.2, poro=0.2, perm=10, sigma_costau=30) check_table(wateroil.table) # Sample numerical tests taken from a prior implementation # NB: Prior implementation created Pc in atm, we create in bar bar_to_atm = 1.0 / 1.01325 wateroil.add_normalized_J(a=0.22, b=-0.5, perm=100, poro=0.2, sigma_costau=30) float_df_checker(wateroil.table, "sw", 0.1, "pc", 2.039969 * bar_to_atm) float_df_checker(wateroil.table, "sw", 0.6, "pc", 0.056666 * bar_to_atm) float_df_checker(wateroil.table, "sw", 1.0, "pc", 0.02040 * bar_to_atm)
def test_scalrecommendation(): """Testing making SCAL rec from dict of dict""" factory = PyscalFactory() scal_input = { "low": {"nw": 2, "now": 4, "ng": 1, "nog": 2}, "BASE": {"nw": 3, "NOW": 3, "ng": 1, "nog": 2}, "high": {"nw": 4, "now": 2, "ng": 1, "nog": 3}, } scal = factory.create_scal_recommendation(scal_input) # (not supported yet to make WaterOil only..) scal.interpolate(-0.5).SWOF() incomplete1 = scal_input.copy() del incomplete1["BASE"] with pytest.raises(ValueError): factory.create_scal_recommendation(incomplete1) go_only = scal_input.copy() del go_only["low"]["now"] del go_only["low"]["nw"] gasoil = factory.create_scal_recommendation(go_only) assert gasoil.low.wateroil is None assert gasoil.base.wateroil is not None assert gasoil.high.wateroil is not None interp = scal.interpolate(-0.5) sat_table_str_ok(interp.SWOF()) sat_table_str_ok(interp.SGOF()) sat_table_str_ok(interp.SLGOF()) sat_table_str_ok(interp.SOF3()) check_table(interp.wateroil.table) check_table(interp.gasoil.table)
def test_factory_wateroilgas(): """Test creating discrete cases of WaterOilGas from factory""" logging.getLogger().setLevel("INFO") factory = PyscalFactory() wog = factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5)) swof = wog.SWOF() sgof = wog.SGOF() sat_table_str_ok(swof) # sgof code works for swof also currently sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Corey krw" in swof assert "Corey krow" in swof check_table(wog.gasoil.table) check_table(wog.wateroil.table) # Some users will mess up lower vs upper case: wog = factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5)) swof = wog.SWOF() sgof = wog.SGOF() sat_table_str_ok(swof) # sgof code works for swof also currently sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Corey krw" in swof assert "Corey krow" in swof # Mangling data with pytest.raises(ValueError): factory.create_water_oil_gas(dict(nw=2, now=3, ng=1))
def test_wateroil_krendmax(swl, swcr, sorw, kroend, kromax, krwend, krwmax, h, fast): """Test endpoints for wateroil using hypothesis testing""" try: wateroil = WaterOil(swl=swl, swcr=swcr, sorw=sorw, h=h, fast=fast) except AssertionError: return kroend = min(kroend, kromax) krwend = min(krwend, krwmax) wateroil.add_corey_oil(kroend=kroend, kromax=kromax) wateroil.add_corey_water(krwend=krwend, krwmax=krwmax) check_table(wateroil.table) assert wateroil.selfcheck() assert 0 < wateroil.crosspoint() < 1 check_endpoints(wateroil, krwend, krwmax, kroend, kromax) #################################### # Do it over again, but with LET: wateroil.add_LET_oil(t=1.1, kroend=kroend, kromax=kromax) wateroil.add_LET_water(t=1.1, krwend=krwend, krwmax=krwmax) assert wateroil.selfcheck() check_table(wateroil.table) # Check endpoints for oil curve: check_endpoints(wateroil, krwend, krwmax, kroend, kromax) check_linear_sections(wateroil) assert 0 < wateroil.crosspoint() < 1
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_linearsegments(): """Made for testing the linear segments during the resolution of issue #163""" wateroil = WaterOil(h=0.01, swl=0.1, swcr=0.3, sorw=0.3) wateroil.add_corey_oil(now=10, kroend=0.5) wateroil.add_corey_water(nw=10, krwend=0.5) check_table(wateroil.table) check_linear_sections(wateroil)
def test_linearsegments(): """Made for testing the linear segments during the resolution of issue #163""" gasoil = GasOil(h=0.01, swl=0.1, sgcr=0.3, sorg=0.3) gasoil.add_corey_oil(nog=10, kroend=0.5) gasoil.add_corey_gas(ng=10, krgend=0.5) check_table(gasoil.table) check_linear_sections(gasoil)
def test_interpolate_wo_pc(swl, dswcr, dswlhigh, sorw, a_l, a_h, b_l, b_h): """ Generate two random WaterOil curves, interpolate pc between them and check that the difference between each interpolant is small, this essentially checks that we can go continously between the two functions. """ wo_low = WaterOil(swl=swl, swcr=swl + dswcr, sorw=sorw) wo_high = WaterOil(swl=swl + dswlhigh, swcr=swl + dswlhigh + dswcr, sorw=max(sorw - 0.01, 0)) wo_low.add_corey_water() wo_high.add_corey_water() wo_low.add_corey_oil() wo_high.add_corey_oil() wo_low.add_simple_J(a=a_l, b=b_l) wo_high.add_simple_J(a=a_h, b=b_h) ips = [] ip_dist = 0.05 for t in np.arange(0, 1 + ip_dist, ip_dist): wo_ip = utils.interpolate_wo(wo_low, wo_high, t) check_table(wo_ip.table) ips.append(wo_ip) assert 0 < wo_ip.crosspoint() < 1 # Distances between low and interpolants: dists = [(wo_low.table - interp.table)[["pc"]].sum().sum() for interp in ips] assert np.isclose(dists[0], 0) # Distance between high and the last interpolant assert (wo_high.table - ips[-1].table)[["pc"]].sum().sum() < 0.01 # Distances between low and interpolants: dists = [(wo_low.table - interp.table)[["pc"]].sum().sum() for interp in ips] print("Interpolation, mean: {}, min: {}, max: {}, std: {} ip-par-dist: {}". format(np.mean(dists), min(dists), max(dists), np.std(np.diff(dists[1:])), ip_dist)) assert np.isclose(dists[0], 0) # Reproducing wo_low # All curves that are close in parameter t, should be close in sum().sum(). # That means that diff of the distances should be similar, # that is the std.dev of the distances is low: ip_dist_std = np.std(np.diff( dists[1:])) # This number depends on 'h' and 't' range # (avoiding the first which reproduces go_low if ip_dist_std > 1.0: # Found by trial and error print("ip_dist_std: {}".format(ip_dist_std)) print(dists) from matplotlib import pyplot as plt _, mpl_ax = plt.subplots() wo_low.plotpc(mpl_ax=mpl_ax, color="red", logyscale=True) wo_high.plotpc(mpl_ax=mpl_ax, color="blue", logyscale=True) for interp in ips: interp.plotpc(mpl_ax=mpl_ax, color="green", logyscale=True) plt.show() assert False
def test_wo_fromtable_h(h): """Test making curves from tabular data with random stepsize h""" df1 = pd.DataFrame( columns=["Sw", "krw", "krow", "pcow"], data=[[0.15, 0, 1, 3], [0.89, 1, 0, 0.1], [1, 1, 0, 0]], ) wateroil = WaterOil(h=h, swl=0.15, sorw=1 - 0.89) wateroil.add_fromtable(df1) check_table(wateroil.table)
def test_go_fromtable_simple(): """Test reading of a simple gasoil table""" df1 = pd.DataFrame(columns=["SG", "KRG", "KROG", "PC"], data=[[0, 0, 1, 2], [1, 1, 0, 0]]) gasoil = GasOil(h=0.1) gasoil.add_fromtable(df1, sgcolname="SG", krgcolname="KRG", krogcolname="KROG", pccolname="PC") check_table(gasoil.table)
def test_simple_j_random(a, b, poro_ref, perm_ref, drho, g): """Test different J-function parameters. Parameter ranges tested through hypothesis are limited, as not every number is realistic. Way outside the tested intervals, you can get AssertionErrors or the capillary pressure may not be monotonically decreasing within machine precision. """ wateroil = WaterOil(swl=0.01) wateroil.add_simple_J( a=a, b=b, poro_ref=poro_ref, perm_ref=perm_ref, drho=drho, g=g ) check_table(wateroil.table)
def test_factory_wateroilgas_wo(): """Test making only wateroil through the wateroilgas factory""" factory = PyscalFactory() wog = factory.create_water_oil_gas( dict(nw=2, now=3, krowend=0.5, sorw=0.04, swcr=0.1)) swof = wog.SWOF() assert "Corey krw" in swof assert "krw" in wog.wateroil.table assert sat_table_str_ok(swof) check_table(wog.wateroil.table) assert wog.gasoil is None wog.SGOF()
def test_fromtable_types(): """Test loading from a table with incorrect types""" # This frame is valid, but the type was wrong. This # can happen if data is via CSV files, and some other rows # ruin the numerical interpretation of a column. df1 = pd.DataFrame( columns=["SW", "KRW", "KROW", "PC"], data=[["0", "0", "1", "2"], ["1", "1", "0", "0"]], ) wateroil = WaterOil(h=0.1) wateroil.add_fromtable(df1, swcolname="SW", krwcolname="KRW", krowcolname="KROW", pccolname="PC") assert "krw" in wateroil.table.columns assert "krow" in wateroil.table.columns assert "pc" in wateroil.table.columns check_table(wateroil.table) gasoil = GasOil(h=0.1) gasoil.add_fromtable(df1, sgcolname="SW", krgcolname="KRW", krogcolname="KROW", pccolname="PC") assert "krg" in gasoil.table.columns assert "krog" in gasoil.table.columns assert "pc" in gasoil.table.columns check_table(gasoil.table) # But this should not make sense. df2 = pd.DataFrame( columns=["SW", "KRW", "KROW", "PC"], data=[["0", dict(foo="bar"), "1", "2"], ["1", "1", "0", "0"]], ) wateroil = WaterOil(h=0.1) with pytest.raises((ValueError, TypeError)): wateroil.add_fromtable(df2, swcolname="SW", krwcolname="KRW", krowcolname="KROW", pccolname="PC") gasoil = GasOil(h=0.1) with pytest.raises((ValueError, TypeError)): gasoil.add_fromtable(df2, sgcolname="SW", krgcolname="KRW", krogcolname="KROW", pccolname="PC")
def test_go_fromtable_simple(): """Test reading of a simple gasoil table""" df1 = pd.DataFrame(columns=["SG", "KRG", "KROG", "PC"], data=[[0, 0, 1, 0], [1, 1, 0, 2]]) gasoil = GasOil(h=0.1) gasoil.add_fromtable(df1, sgcolname="SG", krgcolname="KRG", krogcolname="KROG", pccolname="PC") assert sum(gasoil.table["krg"]) > 0 assert sum(gasoil.table["krog"]) > 0 assert np.isclose(sum(gasoil.table["pc"]), 11) # Linearly increasing PCOG check_table(gasoil.table)
def test_wateroil_dual(param1, param2): """Test combination of 2 floats as parameters""" try: wateroil = WaterOil(swl=param1, sorw=param2) check_table(wateroil.table) # Will fail when swl > 1 - sorw except AssertionError: pass try: wateroil = WaterOil(swl=param1, swirr=param2) check_table(wateroil.table) except AssertionError: pass try: wateroil = WaterOil(swcr=param1, sorw=param2) check_table(wateroil.table) except AssertionError: pass try: wateroil = WaterOil(swirr=param1, sorw=param2) check_table(wateroil.table) except AssertionError: pass
def test_wateroil_let1(l, e, t, krwend, krwmax): """Test random LET parameters""" wateroil = WaterOil() try: wateroil.add_LET_oil(l, e, t, krwend, krwmax) 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) swofstr = wateroil.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_gasoil_let1(l, e, t, krgend, krgmax): """Test the LET formulation, take 1""" gasoil = GasOil() try: gasoil.add_LET_oil(l, e, t, krgend) gasoil.add_LET_gas(l, e, t, krgend, krgmax) except AssertionError: # This happens for negative values f.ex. return assert "krog" in gasoil.table assert "krg" in gasoil.table assert isinstance(gasoil.krgcomment, str) check_table(gasoil.table) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 assert sat_table_str_ok(sgofstr)
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_roundoff(): """Test robustness to monotonicity issues arising from representation errors https://docs.python.org/3/tutorial/floatingpoint.html#representation-error The dataframe injected in this function has occured in the wild, and caused fatal errors in Eclipse100. The error lies in pd.dataframe.to_csv(float_format=".7f") which does truncation of floating points instead of rounding (intentional). Since we have a strict dependency on monotonicity properties for Eclipse to work, the data must be rounded before being sent to to_csv(). This is being done in the .SGOF() and SWOF() as it is a representation issue, not a numerical issues in the objects themselves. """ gasoil = GasOil() # Inject a custom dataframe that has occured in the wild, # and given monotonicity issues in GasOil.SGOF(). gasoil.table = pd.DataFrame( columns=["sg", "krg", "krog", "pc"], data=[ [0.02, 0, 0.19524045000000001, 0], [0.040000000000000001, 0, 0.19524044999999998, 0], [0.059999999999999998, 0, 0.19524045000000004, 0], [0.080000000000000002, 0, 0.19524045000000001, 0], [0.10000000000000001, 0, 0.19524045000000001, 0], [0.16, 0, 0.19524045000000001, 0], [0.17999999999999999, 0, 0.19524045000000001, 0], [0.19999999999999998, 0, 0.19524044999999998, 0], [0.22, 0, 0.19524045000000001, 0], [1, 1, 0, 0], ], ) gasoil.table["sgn"] = gasoil.table["sg"] gasoil.table["son"] = 1 - gasoil.table["sg"] # If this value (as string) occurs, then we are victim of floating point truncation # in float_format=".7f": assert "0.1952404" not in gasoil.SGOF() assert "0.1952405" in gasoil.SGOF() check_table(gasoil.table) # This function allows this monotonicity hiccup.
def test_wo_fromtable_problems(): """Test wateroil from tables with problematic data""" # Implicit swl and sorw in the input, how do we handle that? df1 = pd.DataFrame( columns=["Sw", "krw", "krow", "pcow"], data=[[0.15, 0, 1, 3], [0.89, 1, 0, 0.1], [1, 1, 0, 0]], ) # With default object: wateroil = WaterOil(h=0.1) with pytest.raises(ValueError): wateroil.add_fromtable(df1) # This results in krw and krow overshooting 0 and 1 # Fix left endpoint: wateroil = WaterOil(h=0.1, swl=df1["Sw"].min()) wateroil.add_fromtable(df1) # The table is now valid, but we did not preserve the 0.89 point check_table(wateroil.table) # If we also tell the WaterOil object about sorw, we are guaranteed # to have it expclitly included: wateroil = WaterOil(h=0.1, swl=df1["Sw"].min(), sorw=1 - 0.89) wateroil.add_fromtable(df1) check_table(wateroil.table) # For low enough h, this will however NOT matter. df2 = pd.DataFrame(columns=["Sw", "KRW", "KROW", "PCOW"], data=[[0, -0.01, 1, 0], [1, 1, 0, 0]]) wateroil = WaterOil(h=0.1) with pytest.raises(ValueError): # Should say krw is negative wateroil.add_fromtable(df2, krwcolname="KRW") df3 = pd.DataFrame( columns=["Sw", "KRW", "KROW", "PCOW"], data=[[0, 0, 1, 0], [1, 1.000000001, 0, 0]], ) wateroil = WaterOil(h=0.1) with pytest.raises(ValueError): # Should say krw is above 1.0 wateroil.add_fromtable(df3, krwcolname="KRW")
def test_factory_gasoil(): """Test that we can create curves from dictionaries of parameters""" logging.getLogger().setLevel("INFO") factory = PyscalFactory() with pytest.raises(TypeError): # (this must be a dictionary) factory.create_gas_oil(swirr=0.01) # noqa gasoil = factory.create_gas_oil( dict(swirr=0.01, swl=0.1, sgcr=0.05, tag="Good sand", ng=1, nog=2) ) assert isinstance(gasoil, GasOil) assert gasoil.sgcr == 0.05 assert gasoil.swl == 0.1 assert gasoil.swirr == 0.01 assert gasoil.tag == "Good sand" sgof = gasoil.SGOF() sat_table_str_ok(sgof) check_table(gasoil.table) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Zero capillary pressure" in sgof gasoil = factory.create_gas_oil( dict(ng=1.2, nog=2, krgend=0.8, krgmax=0.9, krogend=0.6) ) sgof = gasoil.SGOF() sat_table_str_ok(sgof) assert "kroend=0.6" in sgof assert "krgend=0.8" in sgof check_table(gasoil.table) gasoil = factory.create_gas_oil(dict(ng=1.3, Log=2, Eog=2, Tog=2)) sgof = gasoil.SGOF() check_table(gasoil.table) sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "LET krog" in sgof gasoil = factory.create_gas_oil(dict(Lg=1, Eg=1, Tg=1, Log=2, Eog=2, Tog=2)) sgof = gasoil.SGOF() sat_table_str_ok(sgof) check_table(gasoil.table) assert "LET krg" in sgof assert "LET krog" in sgof
def test_gasoil_corey1(ng, nog): """Test the Corey formulation for gasoil""" gasoil = GasOil() try: gasoil.add_corey_oil(nog=nog) gasoil.add_corey_gas(ng=ng) except AssertionError: # This happens for "invalid" input return assert "krog" in gasoil.table assert "krg" in gasoil.table assert isinstance(gasoil.krgcomment, str) check_table(gasoil.table) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 assert sat_table_str_ok(sgofstr) gasoil.resetsorg() check_table(gasoil.table) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 assert sat_table_str_ok(sgofstr)