def test_swcrsorw(): """Test estimate_sorw/swcr for some manually set up cases""" # swcr, sorw, h: testtuples = [ (0, 0.3, 0.1), (0.01, 0.2, 0.1), (0.3, 0.1, 0.1), (0.0, 0.0, 0.1), (0.00001, 0.9, 0.1), (0.0001, 0.99, 0.1), ] for testtuple in testtuples: real_swcr = testtuple[0] real_sorw = testtuple[1] h = testtuple[2] wateroil = WaterOil(swcr=real_swcr, sorw=real_sorw, h=h) wateroil.add_corey_oil(now=2, kroend=0.8) wateroil.add_corey_water(nw=2, krwend=0.9) est_sorw = wateroil.estimate_sorw() mis = abs(est_sorw - real_sorw) print("Testing sorw={}, swcr={} on h={}".format(real_sorw, real_swcr, h)) if mis > 0.01: print("Missed, estimated was {}".format(est_sorw)) assert mis < h + epsilon # Can't guarantee better than h. est_swcr = wateroil.estimate_swcr() mis_swcr = abs(est_swcr - real_swcr) if mis_swcr > 0.0: print("Missed swcr, estimate was {}".format(est_swcr)) assert mis_swcr < h + epsilon
def test_normalize_nonlinpart_wo(): """Manual tests for utils.normalize_nonlinpart_wo""" wateroil = WaterOil(swl=0.1, swcr=0.12, sorw=0.05, h=0.05) wateroil.add_corey_water(nw=2.1, krwend=0.9) wateroil.add_corey_oil(now=3, kroend=0.8) krwn, kron = utils.normalize_nonlinpart_wo(wateroil) assert np.isclose(krwn(0), 0) assert np.isclose(krwn(1), 0.9) # kron is normalized on son assert np.isclose(kron(0), 0) assert np.isclose(kron(1), 0.8) # Test with tricky endpoints h = 0.01 wateroil = WaterOil(swl=h, swcr=h, sorw=h, h=h) wateroil.add_corey_water(nw=2.1, krwend=0.9) wateroil.add_corey_oil(now=3, kroend=0.8) krwn, kron = utils.normalize_nonlinpart_wo(wateroil) assert np.isclose(krwn(0), 0.0) assert np.isclose(krwn(1), 0.9) assert np.isclose(kron(0), 0) assert np.isclose(kron(1), 0.8) # Test again with zero endpoints: wateroil = WaterOil(swl=0, swcr=0, sorw=0, h=0.01) wateroil.add_corey_water(nw=2.1, krwend=0.9) wateroil.add_corey_oil(now=3, kroend=0.8) krwn, kron = utils.normalize_nonlinpart_wo(wateroil) assert np.isclose(krwn(0), 0.0) assert np.isclose(krwn(1), 0.9) assert np.isclose(kron(0), 0) assert np.isclose(kron(1), 0.8) # Test when endpoints are messed up: wateroil = WaterOil(swl=0.1, swcr=0.2, sorw=0.1, h=0.1) wateroil.add_corey_water(nw=2.1, krwend=0.6) wateroil.add_corey_oil(now=3, kroend=0.8) wateroil.swl = 0 wateroil.swcr = 0 wateroil.sorw = 0 krwn, kron = utils.normalize_nonlinpart_wo(wateroil) # These go well still, since we are at zero assert np.isclose(krwn(0), 0.0) assert np.isclose(kron(0), 0) # These do not match when endpoints are wrong assert not np.isclose(krwn(1), 0.6) assert not np.isclose(kron(1), 0.8) # So fix endpoints! wateroil.swl = wateroil.table["sw"].min() wateroil.swcr = wateroil.estimate_swcr() wateroil.sorw = wateroil.estimate_sorw() # Try again krwn, kron = utils.normalize_nonlinpart_wo(wateroil) assert np.isclose(krwn(0), 0.0) assert np.isclose(kron(0), 0) assert np.isclose(krwn(1), 0.6) assert np.isclose(kron(1), 0.8)
def test_swcr(): wo = WaterOil(swcr=0.3, swl=0.1, sorw=0.1, h=0.05) wo.add_corey_oil(now=2, kroend=0.8) wo.add_corey_water(nw=2, krwend=0.6) est_sorw = wo.estimate_sorw() est_swcr = wo.estimate_swcr() assert np.isclose(est_sorw, 0.1) assert np.isclose(est_swcr, 0.3)
def test_swcr(): """Test that we can locate swcr with a certain accuracy""" wateroil = WaterOil(swcr=0.3, swl=0.1, sorw=0.1, h=0.05) wateroil.add_corey_oil(now=2, kroend=0.8) wateroil.add_corey_water(nw=2, krwend=0.6) est_sorw = wateroil.estimate_sorw() est_swcr = wateroil.estimate_swcr() assert np.isclose(est_sorw, 0.1) assert np.isclose(est_swcr, 0.3)
def test_interpolations_wo_fromtable(): """Analog test as test_interpolations_go_fromtable(). Pyscal 0.6.1 and earlier fails this test sorw. """ base = pd.DataFrame( columns=["Sw", "krw", "krow"], data=[ [0.0, 0.0, 1.0], [0.1, 0.0, 1.0], [0.2, 0.0, 1.0], # swcr [0.3, 0.1, 0.9], [0.8, 0.8, 0.0], # sorw [0.9, 0.9, 0.0], [1.0, 1.0, 0.0], ], ) opt = pd.DataFrame( columns=["Sw", "krw", "krow"], data=[ [0.0, 0.0, 1.0], [0.1, 0.0, 1.0], [0.3, 0.0, 1.0], [0.4, 0.1, 0.2], # swcr [0.9, 0.9, 0.0], # sorw [0.95, 0.95, 0.0], [1.0, 1.0, 0.0], ], ) wo_base = WaterOil(h=0.01) wo_base.add_fromtable(base) assert np.isclose(wo_base.estimate_swcr(), 0.2) assert np.isclose(wo_base.estimate_sorw(), 0.2) wo_opt = WaterOil(h=0.01) wo_opt.add_fromtable(opt) assert np.isclose(wo_opt.estimate_swcr(), 0.3) assert np.isclose(wo_opt.estimate_sorw(), 0.1) wo_ip = interpolate_wo(wo_base, wo_opt, 0.5, h=0.01) assert np.isclose(wo_ip.estimate_swcr(), 0.25) assert np.isclose(wo_ip.estimate_sorw(), 0.15)
def test_linear_corey(): """Test how the estimate_sorw works when Corey is linear""" # Piecewise linear, this we can detect: wateroil = WaterOil(swl=0, h=0.01, sorw=0.3) wateroil.add_corey_water(nw=1, krwend=0.8) est_sorw = wateroil.estimate_sorw() assert np.isclose(est_sorw, 0.3) # Piecewise linear, this we can detect: wateroil = WaterOil(swl=0, h=0.01, sorw=0.5) wateroil.add_corey_water(nw=1, krwend=1) est_sorw = wateroil.estimate_sorw() assert np.isclose(est_sorw, 0.5) # This one is impossible to deduct sorw from, because # the entire krw curve is linear. wateroil = WaterOil(swl=0, h=0.01, sorw=0.5) wateroil.add_corey_water(nw=1, krwend=0.5) wateroil.add_corey_oil(now=2) est_sorw = wateroil.estimate_sorw() # The code will return sw = swl + h by design: # Unless information is in the krow table, anything better is impossible assert np.isclose(est_sorw, 1 - 0.01)
def test_sorw_hypo(h, sorw, nw): """Test estimate_sorw extensively""" wateroil = WaterOil(sorw=sorw, h=h) wateroil.add_corey_oil(now=2) wateroil.add_corey_water(nw=nw) est_sorw = wateroil.estimate_sorw() est_error = abs(sorw - est_sorw) assert not np.isnan(est_sorw) error_requirement = h + 10000 * epsilon if abs(1 - nw) < 0.1: # When the Corey curve is almost linear, we don't # expect sorw estimation to be robust error_requirement = 3 * h if est_error > error_requirement: print("h = {}, sorw = {}".format(h, sorw)) print("estimated sorw = {}".format(est_sorw)) print(wateroil.table) # We don't bother to tune the code better than this: assert est_error <= error_requirement