def test_gasoil_krendmax(swl, sgcr, sorg, kroend, kromax, krgend, krgmax, h): try: go = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, tag="") except AssertionError: return kroend = min(kroend, kromax) krgend = min(krgend, krgmax) go.add_corey_oil(kroend=kroend, kromax=kromax) go.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(go.table) assert go.selfcheck() check_endpoints(go, krgend, krgmax, kroend, kromax) # Redo with krgendanchor not defaulted go = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, krgendanchor="", tag="") go.add_corey_oil(kroend=kroend, kromax=kromax) go.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(go.table) assert go.selfcheck() check_endpoints(go, krgend, krgmax, kroend, kromax) # Redo with LET: go = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, tag="") go.add_LET_oil(kroend=kroend, kromax=kromax) go.add_LET_gas(krgend=krgend, krgmax=krgmax) check_table(go.table) assert go.selfcheck() check_endpoints(go, krgend, krgmax, kroend, kromax)
def test_gasoil_krgendanchor(): """Test behaviour of the krgendanchor""" gasoil = GasOil(krgendanchor="sorg", sorg=0.2, h=0.1) assert gasoil.sorg gasoil.add_corey_gas(ng=1) gasoil.add_corey_oil(nog=1) # kg should be 1.0 at 1 - sorg due to krgendanchor == "sorg": assert ( gasoil.table[np.isclose(gasoil.table["sg"], 1 - gasoil.sorg)]["krg"].values[0] == 1.0 ) assert gasoil.table[np.isclose(gasoil.table["sg"], 1.0)]["krg"].values[0] == 1.0 gasoil = GasOil(krgendanchor="", sorg=0.2, h=0.1) assert gasoil.sorg gasoil.add_corey_gas(ng=1) gasoil.add_corey_oil(nog=1) # kg should be < 1 at 1 - sorg due to krgendanchor being "" assert ( gasoil.table[np.isclose(gasoil.table["sg"], 1 - gasoil.sorg)]["krg"].values[0] < 1.0 ) assert gasoil.table[np.isclose(gasoil.table["sg"], 1.0)]["krg"].values[0] == 1.0 assert gasoil.selfcheck() assert gasoil.crosspoint() > 0 # Test once more for LET curves: gasoil = GasOil(krgendanchor="sorg", sorg=0.2, h=0.1) assert gasoil.sorg gasoil.add_LET_gas(1, 1, 1.1) gasoil.add_LET_oil(1, 1, 1.1) check_linear_sections(gasoil) assert 0 < gasoil.crosspoint() < 1 # kg should be 1.0 at 1 - sorg due to krgendanchor == "sorg": assert ( gasoil.table[np.isclose(gasoil.table["sg"], 1 - gasoil.sorg)]["krg"].values[0] == 1.0 ) assert gasoil.table[np.isclose(gasoil.table["sg"], 1.0)]["krg"].values[0] == 1.0 gasoil = GasOil(krgendanchor="", sorg=0.2, h=0.1) assert gasoil.sorg gasoil.add_LET_gas(1, 1, 1.1) gasoil.add_LET_oil(1, 1, 1.1) check_linear_sections(gasoil) assert gasoil.selfcheck() # kg should be < 1 at 1 - sorg due to krgendanchor being "" assert ( gasoil.table[np.isclose(gasoil.table["sg"], 1 - gasoil.sorg)]["krg"].values[0] < 1.0 ) assert gasoil.table[np.isclose(gasoil.table["sg"], 1.0)]["krg"].values[0] == 1.0
def test_gasoil_krendmax(swl, sgcr, sorg, sgrononzero, kroend, kromax, krgend, krgmax, h, fast): """Test that relperm curves are valid in all numerical corner cases.""" if sgrononzero: sgro = sgcr else: sgro = 0 try: gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, sgro=sgro, h=h, tag="", fast=fast) except AssertionError: return krgend = min(krgend, krgmax) kroend = min(kroend, kromax) gasoil.add_corey_oil(kroend=kroend, kromax=kromax) gasoil.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1 # Redo with krgendanchor not defaulted gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, krgendanchor="", tag="") gasoil.add_corey_oil(kroend=kroend) gasoil.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1 # Redo with LET: gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, tag="") gasoil.add_LET_oil(t=1.1, kroend=kroend, kromax=kromax) gasoil.add_LET_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1
def test_gasoil_let1(l, e, t, krgend, krgmax): go = GasOil() try: go.add_LET_oil(l, e, t, krgend) go.add_LET_gas(l, e, t, krgend, krgmax) except AssertionError: # This happens for negative values f.ex. return assert "krog" in go.table assert "krg" in go.table assert isinstance(go.krgcomment, str) check_table(go.table) sgofstr = go.SGOF() assert len(sgofstr) > 100
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_kroend(): """Manual testing of kromax and kroend behaviour""" gasoil = GasOil(swirr=0.01, sgcr=0.01, h=0.01, swl=0.1, sorg=0.05) gasoil.add_LET_gas() gasoil.add_LET_oil(2, 2, 2.1) assert gasoil.table["krog"].max() == 1 gasoil.add_LET_oil(2, 2, 2.1, kroend=0.5) check_linear_sections(gasoil) assert gasoil.table["krog"].max() == 0.5 assert 0 < gasoil.crosspoint() < 1 gasoil.add_corey_oil(2) assert gasoil.table["krog"].max() == 1 gasoil.add_corey_oil(nog=2, kroend=0.5) assert gasoil.table["krog"].max() == 0.5
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_kromaxend(): """Manual testing of kromax and kroend behaviour""" gasoil = GasOil(swirr=0.01, sgcr=0.01, h=0.01, swl=0.1, sorg=0.05) gasoil.add_LET_gas() gasoil.add_LET_oil(2, 2, 2) assert gasoil.table["krog"].max() == 1 gasoil.add_LET_oil(2, 2, 2, 0.5, 0.9) assert gasoil.table["krog"].max() == 0.5 # Second krog-value should be kroend, values in between will be linearly # interpolated in Eclipse assert gasoil.table.sort_values("krog")[-2:-1]["krog"].values[0] == 0.5 gasoil.add_corey_oil(2) assert gasoil.table["krog"].max() == 1 gasoil.add_corey_oil(2, 0.5, 0.9) assert gasoil.table["krog"].max() == 0.5 assert gasoil.table.sort_values("krog")[-2:-1]["krog"].values[0] == 0.5
def test_gasoil_krendmax(swl, sgcr, sorg, kroend, kromax, krgend, krgmax, h, fast): """Test that krendmax gets correct in all numerical corner cases. The normalized sg-range is allowed to collapse to nothing in this test. (causes AssertionError) """ try: gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, tag="", fast=fast) except AssertionError: return kroend = min(kroend, kromax) krgend = min(krgend, krgmax) gasoil.add_corey_oil(kroend=kroend, kromax=kromax) gasoil.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1 # Redo with krgendanchor not defaulted gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, krgendanchor="", tag="") gasoil.add_corey_oil(kroend=kroend, kromax=kromax) gasoil.add_corey_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1 # Redo with LET: gasoil = GasOil(swl=swl, sgcr=sgcr, sorg=sorg, h=h, tag="") gasoil.add_LET_oil(t=1.1, kroend=kroend, kromax=kromax) gasoil.add_LET_gas(krgend=krgend, krgmax=krgmax) check_table(gasoil.table) check_linear_sections(gasoil) assert gasoil.selfcheck() check_endpoints(gasoil, krgend, krgmax, kroend, kromax) assert 0 < gasoil.crosspoint() < 1
def test_kromaxend(): """Manual testing of kromax and kroend behaviour""" gasoil = GasOil(swirr=0.01, sgcr=0.01, h=0.01, swl=0.1, sorg=0.05) gasoil.add_LET_gas() gasoil.add_LET_oil(2, 2, 2.1) assert gasoil.table["krog"].max() == 1 gasoil.add_LET_oil(2, 2, 2.1, kroend=0.5, kromax=0.9) check_linear_sections(gasoil) assert gasoil.table["krog"].max() == 0.9 # Second krog-value should be kroend, values in between will be linearly # interpolated in Eclipse assert gasoil.table.sort_values("krog")[-2:-1]["krog"].values[0] == 0.5 assert 0 < gasoil.crosspoint() < 1 gasoil.add_corey_oil(2) assert gasoil.table["krog"].max() == 1 gasoil.add_corey_oil(nog=2, kroend=0.5, kromax=0.9) assert gasoil.table["krog"].max() == 0.9 assert gasoil.table.sort_values("krog")[-2:-1]["krog"].values[0] == 0.5
def create_gas_oil(params=None): """Create a GasOil object from a dictionary of parameters. Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary. Don't rely on behaviour of you supply both Corey and LET at the same time. NB: the add_LET_* methods have the names 'l', 'e' and 't' in their signatures, which is not precise enough in this context, so we require e.g. 'Lg' and 'Log' (which both will be translated to 'l'). Also note that in this factory context, kroend is an ambiguous parameter, krogend must be used. Recognized parameters: swirr, sgcr, sorg, swl, krgendanchor, h, tag, ng, krgend, krgmax, nog, krogend, lg, eg, tg, log, eog, tog """ if not params: params = dict() if not isinstance(params, dict): raise TypeError("Parameter to create_gas_oil must be a dictionary") check_deprecated(params) # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} # Allowing sending in NaN values, delete those keys. params = filter_nan_from_dict(params) usedparams = set() # No requirements to the base objects, defaults are ok. gasoil = GasOil(**slicedict(params, GO_INIT)) usedparams = usedparams.union(set(slicedict(params, GO_INIT).keys())) logger.info("Initialized GasOil object from parameters %s", str(list(usedparams))) # Gas curve params_corey_gas = slicedict(params, GO_COREY_GAS + GO_GAS_ENDPOINTS) params_let_gas = slicedict(params, GO_LET_GAS + GO_GAS_ENDPOINTS) if set(GO_COREY_GAS).issubset(set(params_corey_gas)): gasoil.add_corey_gas(**params_corey_gas) usedparams = usedparams.union(set(params_corey_gas.keys())) logger.info( "Added Corey gas to GasOil object from parameters %s", str(params_corey_gas.keys()), ) elif set(GO_LET_GAS).issubset(set(params_let_gas)): params_let_gas["l"] = params_let_gas.pop("lg") params_let_gas["e"] = params_let_gas.pop("eg") params_let_gas["t"] = params_let_gas.pop("tg") gasoil.add_LET_gas(**params_let_gas) usedparams = usedparams.union(set(params_let_gas.keys())) logger.info( "Added LET gas to GasOil object from parameters %s", str(params_let_gas.keys()), ) else: logger.warning( "Missing or ambiguous parameters for gas curve in GasOil object" ) # Oil curve: params_corey_oil = slicedict(params, GO_COREY_OIL + GO_OIL_ENDPOINTS) params_let_oil = slicedict(params, GO_LET_OIL + GO_OIL_ENDPOINTS) if set(GO_COREY_OIL).issubset(set(params_corey_oil)): if "krogend" in params_corey_oil: params_corey_oil["kroend"] = params_corey_oil.pop("krogend") gasoil.add_corey_oil(**params_corey_oil) logger.info( "Added Corey gas to GasOil object from parameters %s", str(params_corey_oil.keys()), ) elif set(GO_LET_OIL).issubset(set(params_let_oil)): params_let_oil["l"] = params_let_oil.pop("log") params_let_oil["e"] = params_let_oil.pop("eog") params_let_oil["t"] = params_let_oil.pop("tog") if "krogend" in params_corey_oil: params_let_oil["kroend"] = params_let_oil.pop("krogend") gasoil.add_LET_oil(**params_let_oil) logger.info( "Added LET gas to GasOil object from parameters %s", str(params_let_oil.keys()), ) else: logger.warning( "Missing or ambiguous parameters for oil curve in GasOil object" ) if not gasoil.selfcheck(): raise ValueError( ("Incomplete GasOil object, some parameters missing to factory" )) return gasoil