def create_water_oil_gas(params=None): """Create a WaterOilGas object from a dictionary of parameters Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary. """ if not params: params = dict() if not isinstance(params, dict): raise TypeError( "Parameter to create_water_oil_gas must be a dictionary") # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} wateroil = PyscalFactory.create_water_oil(params) gasoil = PyscalFactory.create_gas_oil(params) wog_init_params = slicedict(params, WOG_INIT) wateroilgas = WaterOilGas(**wog_init_params) # The wateroilgas __init__ has already created WaterOil and GasOil objects # but we overwrite the references with newly created ones, this factory function # must then guarantee that they are compatible. wateroilgas.wateroil = wateroil wateroilgas.gasoil = gasoil if not wateroilgas.selfcheck(): raise ValueError(("Incomplete WaterOilGas object, " "some parameters missing to factory")) return wateroilgas
def test_not_threephase_consistency(): wog = WaterOilGas() # To trigger this, we need to hack the WaterOilGas object # by overriding the effect of its __init__ wog.wateroil = WaterOil(swl=0.4) wog.gasoil = GasOil(swl=0.2) wog.wateroil.add_corey_water(nw=2) wog.wateroil.add_corey_oil(now=2, kroend=0.9) wog.gasoil.add_corey_gas(ng=2) wog.gasoil.add_corey_oil(nog=2, kroend=1) assert not wog.threephaseconsistency()
def create_water_oil_gas(params=None): """Create a WaterOilGas object from a dictionary of parameters Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary. Check create_water_oil() and create_gas_oil() for lists of supported parameters (case insensitive) """ if not params: params = dict() if not isinstance(params, dict): raise TypeError( "Parameter to create_water_oil_gas 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()} if sufficient_water_oil_params(params): wateroil = PyscalFactory.create_water_oil(params) else: logger.info( "No wateroil parameters. Assuming only gas-oil in wateroilgas") wateroil = None if sufficient_gas_oil_params(params): gasoil = PyscalFactory.create_gas_oil(params) else: logger.info("No gasoil parameters, assuming two-phase oilwatergas") gasoil = None wog_init_params = slicedict(params, WOG_INIT) wateroilgas = WaterOilGas(**wog_init_params) # The wateroilgas __init__ has already created WaterOil and GasOil objects # but we overwrite the references with newly created ones, this factory function # must then guarantee that they are compatible. wateroilgas.wateroil = wateroil # This might be None wateroilgas.gasoil = gasoil # This might be None if not wateroilgas.selfcheck(): raise ValueError(( "Incomplete WaterOilGas object, some parameters missing to factory" )) return wateroilgas
def interpolate(self, parameter, parameter2=None, h=0.02): """Interpolate between low, base and high parameter = -1 reproduces low curve parameter = 0 reproduces base curve parameter = 1 reproduces high curve Interpolation is performed pointwise in the "relperm" direction for each saturation point. During interpolation, endpoints are hard to handle, and only swirr is attempted preserved. Interpolation is linear in relperm-direction, and will thus not be linear in log-relperm-direction This method returns an WaterOilGasTable object which can be realized into printed tables. No attempt is made to parametrize the interpolant in L,E,T parameter space. If a second parameter is supplied ("parameter2") this is used for the gas-oil interpolation. This enables the gas-oil interpolant to be fully uncorrelated to the water-oil interpolant. CHECK how this affects endpoints and Eclipse consistency!! """ if parameter2 is not None: gasparameter = parameter2 else: gasparameter = parameter # Initialize wateroil and gasoil curves to be filled with # interpolated curves: interpolant = WaterOilGas() if abs(parameter) > 1.0: logging.error("Interpolation parameter must be in [-1,1]") interpolant.wateroil = None raise AssertionError elif np.isclose(parameter, 0.0): interpolant.wateroil = self.base.wateroil elif np.isclose(parameter, -1.0): interpolant.wateroil = self.low.wateroil elif np.isclose(parameter, 1.0): interpolant.wateroil = self.high.wateroil elif parameter < 0.0: curve1 = copy.deepcopy(self.base.wateroil) curve2 = copy.deepcopy(self.low.wateroil) param_transf = -parameter # 0 gives base, 1 gives low. swl = (curve1.table["sw"][0] * (1 - param_transf) + curve2.table["sw"][0] * param_transf) interpolant.wateroil = WaterOil( swirr=swl, swl=swl, sorw=0.0, h=h, tag=self.tag + " interpolant at %g" % parameter, ) interpolator( interpolant.wateroil, curve1, curve2, param_transf, "sw", "krw", "krow", "pc", ) elif parameter > 0.0: curve1 = copy.deepcopy(self.base.wateroil) curve2 = copy.deepcopy(self.high.wateroil) param_transf = parameter # 0 gives base, 1 gives high swl = (curve1.table["sw"][0] * (1 - param_transf) + curve2.table["sw"][0] * param_transf) interpolant.wateroil = WaterOil( swirr=swl, swl=swl, sorw=0.0, h=h, tag=self.tag + " interpolant at %g" % parameter, ) interpolator( interpolant.wateroil, curve1, curve2, param_transf, "sw", "krw", "krow", "pc", ) # Gas-oil interpolation # We need swl from the interpolated WaterOil object. swl = interpolant.wateroil.swl if abs(gasparameter) > 1.0: logging.error("Interpolation parameter must be in [-1,1]") interpolant.gasoil = None raise AssertionError elif np.isclose(gasparameter, 0.0): interpolant.gasoil = self.base.gasoil elif np.isclose(gasparameter, -1.0): interpolant.gasoil = self.low.gasoil elif np.isclose(gasparameter, 1.0): interpolant.gasoil = self.high.gasoil elif gasparameter < 0.0: curve1 = copy.deepcopy(self.base.gasoil) curve2 = copy.deepcopy(self.low.gasoil) gas_param_transf = -1 * gasparameter # 0 gives base, 1 gives low. # We have to use the extreme, not interpolated sgcr. sgcr = min(curve1.sgcr, curve2.sgcr) interpolant.gasoil = GasOil( sgcr=sgcr, swl=swl, sorg=0.0, h=h, tag=self.tag + " interpolant at %g" % gasparameter, ) interpolator( interpolant.gasoil, curve1, curve2, gas_param_transf, "sg", "krg", "krog", "pc", ) interpolant.gasoil.resetsorg() elif gasparameter > 0.0: curve1 = copy.deepcopy(self.base.gasoil) curve2 = copy.deepcopy(self.high.gasoil) gas_param_transf = gasparameter # 0 gives base, 1 gives high # We have to use the extreme, not interpolated sgcr. sgcr = min(curve1.sgcr, curve2.sgcr) interpolant.gasoil = GasOil( sgcr=sgcr, swl=swl, sorg=0.0, h=h, tag=self.tag + " interpolant at %g" % gasparameter, ) interpolator( interpolant.gasoil, curve1, curve2, gas_param_transf, "sg", "krg", "krog", "pc", ) interpolant.gasoil.resetsorg() return interpolant
def interpolate(self, parameter, parameter2=None, h=0.02): """Interpolate between low, base and high parameter = -1 reproduces low curve parameter = 0 reproduces base curve parameter = 1 reproduces high curve Endpoints are located for input curves, and interpolated individually. Interpolation for the nonlinear part is done on a normalized interval between the endpoints Interpolation is linear in relperm-direction, and will thus not be linear in log-relperm-direction This method returns an WaterOilGas object which can be realized into printed tables. No attempt is made to parametrize the interpolant in L,E,T parameter space, or Corey-space. If a second parameter is supplied ("parameter2") this is used for the gas-oil interpolation. This enables the gas-oil interpolant to be fully uncorrelated to the water-oil interpolant. CHECK how this affects endpoints and Eclipse consistency!! """ if parameter2 is not None: gasparameter = parameter2 else: gasparameter = parameter # Either wateroil or gasoil can be None in the low, base, high # If they are None, it is a two-phase problem and we # should support this. do_wateroil = (self.base.wateroil is not None and self.low.wateroil is not None and self.high.wateroil is not None) do_gasoil = (self.base.gasoil is not None and self.low.gasoil is not None and self.high.gasoil is not None) if not do_wateroil and not do_gasoil: raise ValueError( "Neither wateroil or gasoil is complete in SCAL recommendation" ) if parameter2 is not None and not do_gasoil: logger.warning("parameter2 is meaningless for water-oil only") # Initialize wateroil and gasoil curves to be filled with # interpolated curves: tags = set() if do_wateroil: tags = tags.union( set([ self.base.wateroil.tag, self.low.wateroil.tag, self.high.wateroil.tag, ])) if do_gasoil: tags = tags.union( set([ self.base.gasoil.tag, self.low.gasoil.tag, self.high.gasoil.tag ])) tagstring = "\n".join(tags) interpolant = WaterOilGas(h=h, tag=tagstring) if do_wateroil: tag = ( "SCAL recommendation interpolation to {}\n".format(parameter) + tagstring) if abs(parameter) > 1.0: logger.error("Interpolation parameter must be in [-1,1]") assert abs(parameter) <= 1.0 elif np.isclose(parameter, 0.0): interpolant.wateroil = self.base.wateroil interpolant.wateroil.tag = tag elif np.isclose(parameter, -1.0): interpolant.wateroil = self.low.wateroil interpolant.wateroil.tag = tag elif np.isclose(parameter, 1.0): interpolant.wateroil = self.high.wateroil interpolant.wateroil.tag = tag elif parameter < 0.0: interpolant.wateroil = utils.interpolate_wo(self.base.wateroil, self.low.wateroil, -parameter, h=h, tag=tag) elif parameter > 0.0: interpolant.wateroil = utils.interpolate_wo(self.base.wateroil, self.high.wateroil, parameter, h=h, tag=tag) else: interpolant.wateroil = None if do_gasoil: tag = ("SCAL recommendation interpolation to {}\n".format( gasparameter) + tagstring) if abs(gasparameter) > 1.0: logger.error("Interpolation parameter must be in [-1,1]") assert abs(gasparameter) <= 1.0 elif np.isclose(gasparameter, 0.0): interpolant.gasoil = self.base.gasoil interpolant.gasoil.tag = tag elif np.isclose(gasparameter, -1.0): interpolant.gasoil = self.low.gasoil interpolant.gasoil.tag = tag elif np.isclose(gasparameter, 1.0): interpolant.gasoil = self.high.gasoil interpolant.gasoil.tag = tag elif gasparameter < 0.0: interpolant.gasoil = utils.interpolate_go(self.base.gasoil, self.low.gasoil, -1 * gasparameter, h=h, tag=tag) elif gasparameter > 0.0: interpolant.gasoil = utils.interpolate_go(self.base.gasoil, self.high.gasoil, gasparameter, h=h, tag=tag) else: interpolant.gasoil = None return interpolant