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 testgascurves(): """test of gas-oil curves""" sgof = GasOil(tag="Testcurve", h=0.02, swirr=0.18, swl=0.31, sorg=0.09, sgcr=0.04) sgof.add_corey_gas(ng=1.5, krgend=0.7) sgof.add_corey_oil(nog=2, kroend=0.4) sgof.add_LET_gas(l=2, e=1, t=1.4, krgend=0.9) sgof.add_LET_oil(l=2, e=3, t=1.4, kroend=0.7) print(sgof.table) _, mpl_ax = plt.subplots() sgof.plotkrgkrog(mpl_ax) # mpl_ax.set_yscale('log') print(sgof.SGOF()) plt.show()
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, ): # pylint: disable=too-many-arguments,too-many-locals """Test many possible combinations of interpolation between two Corey gasoil curves, looking for numerical corner cases""" h = 0.01 go_low = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h) go_high = GasOil( swl=swl + dswlhigh, sgcr=sgcr + dsgcr, sorg=max(sorg - dsorg, 0), h=h ) 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 = interpolate_go(go_low, go_high, t) check_table(go_ip.table) ips.append(go_ip) assert 0 < go_ip.crosspoint() < 1 # sgcr is non-trivial, if exponents are high, an effective sgcr might # be larger than the value used to initialize the curve. Try to be # permissive enough here. This can even cause the interpolant to be # outside the low-high envelope, but it is the way it is supposed to # be when sgcr is interpolated separately. sgcr_low = min( go_low.sgcr, go_low.estimate_sgcr(), go_high.sgcr, go_high.estimate_sgcr() ) sgcr_high = max( go_low.sgcr, go_low.estimate_sgcr(), go_high.sgcr, go_high.estimate_sgcr() ) sgcr_ip = go_ip.estimate_sgcr() sgcr_lower_bound_ok = sgcr_low - h - epsilon < sgcr_ip sgcr_upper_bound_ok = sgcr_ip < sgcr_high + h + epsilon assert sgcr_lower_bound_ok assert sgcr_upper_bound_ok # 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) _, 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_interpolate_go(): """Interactive tests for gasoil""" swl_l = random.uniform(0, 0.1) sgcr_l = random.uniform(0, 0.1) swl_h = random.uniform(0, 0.1) sgcr_h = random.uniform(0, 0.1) sorg_l = random.uniform(0, 0.2) sorg_h = random.uniform(0, 0.2) if bool(random.getrandbits(1)): # Interpolation is not possible if only # one of the curves has nonzero sgro sgro_l = sgcr_l sgro_h = sgcr_h else: sgro_l = 0 sgro_h = 0 krgend_l = random.uniform(0.5, 1) krgend_h = random.uniform(0.5, 1) kromax_l = random.uniform(0.5, 1) kromax_h = random.uniform(0.5, 1) kroend_l = min(random.uniform(0.5, 1), kromax_l) kroend_h = min(random.uniform(0.5, 1), kromax_h) if random.uniform(0, 1) > 0.5: krgendanchor_l = "sorg" else: krgendanchor_l = "" if random.uniform(0, 1) > 0.5: krgendanchor_h = "sorg" else: krgendanchor_h = "" go_low = GasOil( swl=swl_l, sgcr=sgcr_l, sorg=sorg_l, sgro=sgro_l, krgendanchor=krgendanchor_l, h=0.001, ) go_high = GasOil( swl=swl_h, sgcr=sgcr_h, sorg=sorg_h, sgro=sgro_h, krgendanchor=krgendanchor_h, h=0.001, ) go_low.add_corey_gas(ng=random.uniform(1, 3), krgend=krgend_l) go_high.add_corey_gas(ng=random.uniform(1, 3), krgend=krgend_h) go_low.add_corey_oil(nog=random.uniform(1, 3), kroend=kroend_l, kromax=kromax_l) go_high.add_corey_oil(nog=random.uniform(1, 3), kroend=kroend_h, kromax=kromax_h) print(" ** Low curve GasOil (red):\n" + go_low.sgcomment + go_low.krgcomment + go_low.krogcomment) print(" ** High curve GasOil (blue):\n" + go_high.sgcomment + go_high.krgcomment + go_high.krogcomment) _, mpl_ax = pyplot.subplots() go_low.plotkrgkrog(mpl_ax, color="red") go_high.plotkrgkrog(mpl_ax, color="blue") for tparam in np.arange(0, 1, 0.1): go_ip = utils.interpolation.interpolate_go(go_low, go_high, tparam) go_ip.plotkrgkrog(mpl_ax, color="green") mpl_ax.set_title("GasOil, random Corey, linear y-scale") _pyplot_show_with_user_message() _, mpl_ax = pyplot.subplots() go_low.plotkrgkrog(mpl_ax, color="red") go_high.plotkrgkrog(mpl_ax, color="blue") # Plot again with log yscale: for tparam in np.arange(0, 1, 0.1): go_ip = utils.interpolation.interpolate_go(go_low, go_high, tparam) go_ip.plotkrgkrog(mpl_ax, color="green", logyscale=True) mpl_ax.set_title("GasOil, random Corey, log y-scale") _pyplot_show_with_user_message()
def test_interpolate_go(): """Interactive tests for gasoil""" swl_l = random.uniform(0, 0.1) sgcr_l = random.uniform(0, 0.1) swl_h = random.uniform(0, 0.1) sgcr_h = random.uniform(0, 0.1) sorg_l = random.uniform(0, 0.2) sorg_h = random.uniform(0, 0.2) if random.uniform(0, 1) > 0.5: krgendanchor_l = "sorg" else: krgendanchor_l = "" if random.uniform(0, 1) > 0.5: krgendanchor_h = "sorg" else: krgendanchor_h = "" go_low = GasOil(swl=swl_l, sgcr=sgcr_l, sorg=sorg_l, krgendanchor=krgendanchor_l, h=0.001) go_high = GasOil(swl=swl_h, sgcr=sgcr_h, sorg=sorg_h, krgendanchor=krgendanchor_h, h=0.001) go_low.add_corey_gas(ng=random.uniform(1, 3), krgend=random.uniform(0.5, 1)) go_high.add_corey_gas(ng=random.uniform(1, 3), krgend=random.uniform(0.5, 1)) go_low.add_corey_oil(nog=random.uniform(1, 3), kroend=random.uniform(0.5, 1)) go_high.add_corey_oil(nog=random.uniform(1, 3), kroend=random.uniform(0.5, 1)) print(" ** Low curve GasOil (red):\n" + go_low.sgcomment + go_low.krgcomment + go_low.krogcomment) print(" ** High curve GasOil (blue):\n" + go_high.sgcomment + go_high.krgcomment + go_high.krogcomment) _, mpl_ax = plt.subplots() go_low.plotkrgkrog(mpl_ax, color="red") go_high.plotkrgkrog(mpl_ax, color="blue") for tparam in np.arange(0, 1, 0.1): go_ip = utils.interpolation.interpolate_go(go_low, go_high, tparam) go_ip.plotkrgkrog(mpl_ax, color="green") mpl_ax.set_title("GasOil, random Corey, linear y-scale") plt.show() _, mpl_ax = plt.subplots() go_low.plotkrgkrog(mpl_ax, color="red") go_high.plotkrgkrog(mpl_ax, color="blue") # Plot again with log yscale: for tparam in np.arange(0, 1, 0.1): go_ip = utils.interpolation.interpolate_go(go_low, go_high, tparam) go_ip.plotkrgkrog(mpl_ax, color="green", logyscale=True) mpl_ax.set_title("GasOil, random Corey, log y-scale") plt.show() # Capillary pressure - This is barely supported for gasoil # so the plotpc() function is missing. Include calculations # here so we ensure we don't crash on the all zeros. # _, mpl_ax = plt.subplots() # go_low.plotpc(mpl_ax, color="red", logyscale=True) # go_high.plotpc(mpl_ax, color="blue", logyscale=True) for tparam in np.arange(0, 1, 0.1): go_ip = utils.interpolation.interpolate_go(go_low, go_high, tparam, h=0.001)
def test_plotting(): """Test that plotting code pass through (nothing displayed)""" gasoil = GasOil(swl=0.1, h=0.1) gasoil.add_corey_gas() gasoil.add_corey_oil() gasoil.plotkrgkrog(mpl_ax=matplotlib.pyplot.subplots()[1])