def test_deprecated_kroend(): """Testing that the deprecated scalrecommendation can take both kroend and krogend/krowend""" low_krowend = dict(LOW_SAMPLE_LET) low_krowend["krowend"] = low_krowend["kroend"] del low_krowend["kroend"] base_krowend = dict(BASE_SAMPLE_LET) base_krowend["krowend"] = base_krowend["kroend"] del base_krowend["kroend"] high_krowend = dict(HIGH_SAMPLE_LET) high_krowend["krowend"] = high_krowend["kroend"] del high_krowend["kroend"] rec = SCALrecommendation(low_krowend, base_krowend, high_krowend, "foo", h=0.1) rec.add_simple_J() # Add default pc curve interpolant = rec.interpolate(0.1, 0, h=0.1) check_table(interpolant.wateroil.table) print(interpolant.SWOF())
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_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 assert rec.type == WaterOilGas 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 if not interpolant.threephaseconsistency(): print(interpolant.wateroil.SWOF()) print(interpolant.gasoil.SGOF()) assert interpolant.threephaseconsistency()
def interpolatetest(): rec = SCALrecommendation(lowsample(), basesample(), highsample(), "foo", h=0.05) rec.add_simple_J() # Add default pc curve # print rec.low.wateroil.table interpolant = rec.interpolate(0.3, parameter2=-0.9, h=0.05) print(interpolant.wateroil.SWOF()) print(interpolant.gasoil.SGOF()) print("Consistency check: ", end=" ") print(interpolant.threephaseconsistency())
def create_scal_recommendation(params, tag="", h=None): """ Set up a SCAL recommendation curve set from input as a dictionary of dictionary. The keys in in the dictionary *must* be "low", "base" and "high". The value for "low" must be a new dictionary with saturation endpoints and LET/Corey parameters, as you would feed it to the create_water_oil_gas() factory function, and then similarly for base and high. For oil-water only, you may omit the parameters for gas-oil. """ if not isinstance(params, dict): raise ValueError("Input must be a dictionary (of dictionaries)") # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} if "low" not in params: raise ValueError('"low" case not supplied') if "base" not in params: raise ValueError('"base" case not supplied') if "high" not in params: raise ValueError('"high" case not supplied') if not all([isinstance(x, dict) for x in params.values()]): raise ValueError( "All values in parameter dict must be dictionaries") check_deprecated(params["low"]) check_deprecated(params["base"]) check_deprecated(params["high"]) errored = False if h is not None: params["low"]["h"] = h params["base"]["h"] = h params["high"]["h"] = h wog_low = PyscalFactory.create_water_oil_gas(params["low"]) if not wog_low.selfcheck(): logger.error("Incomplete parameter set for low case") errored = True wog_base = PyscalFactory.create_water_oil_gas(params["base"]) if not wog_base.selfcheck(): logger.error("Incomplete parameter set for base case") errored = True wog_high = PyscalFactory.create_water_oil_gas(params["high"]) if not wog_high.selfcheck(): logger.error("Incomplete parameter set for high case") errored = True if errored: raise ValueError("Incomplete SCAL recommendation") scal = SCALrecommendation(wog_low, wog_base, wog_high, tag) return scal
def test_interpolation(param_wo, param_go): 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_wo(interpolant.wateroil.table) check_table_go(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_make_scalrecommendation_go(): """Test that we can make scal recommendation objects from three WaterOilGas objects, but only with GasOil objects""" go_param_names = [ "swirr", "sorg", "krgend", "krgmax", "swl", "sgcr", "Lg", "Eg", "Tg", "Log", "Eog", "Tog", "kroend", ] low_let_go = slicedict(LOW_SAMPLE_LET, go_param_names) low = PyscalFactory.create_water_oil_gas(low_let_go) base_let_go = slicedict(BASE_SAMPLE_LET, go_param_names) base = PyscalFactory.create_water_oil_gas(base_let_go) high_let_go = slicedict(HIGH_SAMPLE_LET, go_param_names) assert "Lw" not in high_let_go high = PyscalFactory.create_water_oil_gas(high_let_go) rec = SCALrecommendation(low, base, high) assert rec.type == WaterOilGas interpolant = rec.interpolate(-0.5) check_table(interpolant.gasoil.table) assert interpolant.wateroil is None sat_table_str_ok(interpolant.SGOF()) sat_table_str_ok(interpolant.SGFN()) # This should return empty string assert not interpolant.SWOF()
def test_make_scalrecommendation_wo(): """Test that we can make scal recommendation objects from three WaterOilGas objects, but only with WaterOil objects""" wo_param_names = [ "swirr", "sorw", "krwend", "krwmax", "swl", "swcr", "Lw", "Ew", "Tw", "Lo", "Eo", "To", "krowend", ] low_let_wo = slicedict(LOW_SAMPLE_LET, wo_param_names) low = PyscalFactory.create_water_oil_gas(low_let_wo) base_let_wo = slicedict(BASE_SAMPLE_LET, wo_param_names) base = PyscalFactory.create_water_oil_gas(base_let_wo) high_let_wo = slicedict(HIGH_SAMPLE_LET, wo_param_names) assert "Lg" not in high_let_wo high = PyscalFactory.create_water_oil_gas(high_let_wo) rec = SCALrecommendation(low, base, high) interpolant = rec.interpolate(-0.5) check_table(interpolant.wateroil.table) assert interpolant.gasoil is None assert sat_table_str_ok(interpolant.SWOF()) assert sat_table_str_ok(interpolant.SWFN()) # This should return empty string assert not interpolant.SGOF()
def test_fast(): """Test the fast option""" low_fast = PyscalFactory.create_water_oil_gas(LOW_SAMPLE_LET, fast=True) base_fast = PyscalFactory.create_water_oil_gas(BASE_SAMPLE_LET, fast=True) high_fast = PyscalFactory.create_water_oil_gas(HIGH_SAMPLE_LET, fast=True) rec = SCALrecommendation(low_fast, base_fast, high_fast) interp = rec.interpolate(-0.5) assert rec.fast assert interp.fast # test that one or more inputs not being set to fast does not trigger fast mode 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_fast, base_fast, high) interp = rec.interpolate(-0.5) assert not rec.fast assert not interp.fast rec = SCALrecommendation(low, base_fast, high) interp = rec.interpolate(-0.5) assert not rec.fast assert not interp.fast rec = SCALrecommendation(low, base, high) interp = rec.interpolate(-0.5) assert not rec.fast assert not interp.fast
def interpolateplottest(): """Demonstration of interpolation pointwise between LET curves""" import matplotlib.pyplot as plt import matplotlib matplotlib.style.use("ggplot") rec = SCALrecommendation(lowsample(), basesample(), highsample(), "foo", h=0.001) _, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) # Choosing logarithmic spaced interpolation parameters # is not the same as interpolating in log(kr)-space # check the effect by setting # for t in -2 + np.logspace(1e-5,1e-1,15): # and # for t in -1 + np.logspace(1e-5,1e-1,15) # in the loops below. Curves get clustered to the bottom # in both linear and log(kr) spaces, but there # still might be some other distribution for the interpolants # that yields something that spans nicely both the linear and the # logarithmic kr space (?) for t in np.arange(-1, 0, 0.2): interp = rec.interpolate(t, h=0.001) interp.wateroil.plotkrwkrow(ax1, "r") interp.wateroil.plotkrwkrow(ax2, "r") for t in np.arange(0, 1, 0.2): interp = rec.interpolate(t, h=0.001) interp.wateroil.plotkrwkrow(ax1, "g") interp.wateroil.plotkrwkrow(ax2, "g") rec.low.wateroil.plotkrwkrow(ax1, linewidth=2, linestyle=":") rec.base.wateroil.plotkrwkrow(ax1, linewidth=2) rec.high.wateroil.plotkrwkrow(ax1, linewidth=2, linestyle="--") rec.low.wateroil.plotkrwkrow(ax2, linewidth=2, linestyle=":") rec.base.wateroil.plotkrwkrow(ax2, linewidth=2) rec.high.wateroil.plotkrwkrow(ax2, linewidth=2, linestyle="--") ax2.set_yscale("log") ax2.set_ylim([1e-10, 1]) ax1.set_title("Water-oil, low, base, high and interpolants") ax2.set_title("Water-oil, low, base, high and interpolants") for t in np.arange(-1, 0, 0.2): interp = rec.interpolate(t, h=0.001) interp.gasoil.plotkrgkrog(ax3, "r") interp.gasoil.plotkrgkrog(ax4, "r") for t in np.arange(0, 1, 0.2): interp = rec.interpolate(t, h=0.001) interp.gasoil.plotkrgkrog(ax3, "g") interp.gasoil.plotkrgkrog(ax4, "g") rec.low.gasoil.plotkrgkrog(ax3, linewidth=2, linestyle=":") rec.base.gasoil.plotkrgkrog(ax3, linewidth=2) rec.high.gasoil.plotkrgkrog(ax3, linewidth=2, linestyle="--") rec.low.gasoil.plotkrgkrog(ax4, linewidth=2, linestyle=":") rec.base.gasoil.plotkrgkrog(ax4, linewidth=2) rec.high.gasoil.plotkrgkrog(ax4, linewidth=2, linestyle="--") ax3.set_title("Gas-oil, low, base, high and interpolants") ax4.set_title("Gas-oil, low, base, high and interpolants") ax4.set_yscale("log") ax4.set_ylim([1e-05, 1]) plt.subplots_adjust(hspace=0.3) plt.show()
def test_boundary_cases(): rec = SCALrecommendation(low_sample_let, base_sample_let, high_sample_let, "foo", h=0.1) # Object reference equivalence is a little bit strict, # because it would be perfectly fine if interpolate() # retured copied objects. But we don't have an equivalence operator # implemented. assert rec.interpolate(0).wateroil == rec.base.wateroil assert rec.interpolate(-1).wateroil == rec.low.wateroil assert rec.interpolate(1).wateroil == rec.high.wateroil assert rec.interpolate(0).gasoil == rec.base.gasoil assert rec.interpolate(-1).gasoil == rec.low.gasoil assert rec.interpolate(1).gasoil == rec.high.gasoil assert rec.interpolate(0, 1).wateroil == rec.base.wateroil assert rec.interpolate(-1, 1).wateroil == rec.low.wateroil assert rec.interpolate(1, 1).wateroil == rec.high.wateroil assert rec.interpolate(0, 1).gasoil == rec.high.gasoil assert rec.interpolate(-1, 1).gasoil == rec.high.gasoil assert rec.interpolate(1, 1).gasoil == rec.high.gasoil assert rec.interpolate(0, 0).gasoil == rec.base.gasoil assert rec.interpolate(-1, 0).gasoil == rec.base.gasoil assert rec.interpolate(1, 0).gasoil == rec.base.gasoil assert rec.interpolate(0, -1).gasoil == rec.low.gasoil assert rec.interpolate(-1, -1).gasoil == rec.low.gasoil assert rec.interpolate(1, -1).gasoil == rec.low.gasoil