def test_time_arrays() -> None: t = dca.get_time() assert is_monotonic_increasing(t) int_t = dca.get_time_monthly_vol() thm = dca.THM(1000, 0.5, 2.0, 1.0, 30.0)
def check_transient_model_rate_cum(model: dca.THM) -> bool: # these are computationally expensive, so check separately t = dca.get_time() with warnings.catch_warnings(record=True) as w: t_N = model.transient_cum(t) assert is_float_array_like(t_N, t) # assert is_monotonic_nondecreasing(t_N) assert np.all(np.isfinite(t_N)) t_q = model.transient_rate(t) assert is_float_array_like(t_q, t) # assert is_monotonic_nonincreasing(t_q) assert np.all(np.isfinite(t_q)) return True
def test_nulls() -> None: t = dca.get_time() primary = dca.NullPrimaryPhase() assert np.allclose(primary.rate(t), 0.0) assert np.allclose(primary.cum(t), 0.0) assert np.allclose(primary.D(t), 0.0) assert np.allclose(primary.beta(t), 0.0) assert np.allclose(primary.b(t), 0.0) assert np.allclose(primary._Dfn2(t), 0.0) secondary = dca.NullAssociatedPhase() assert np.allclose(secondary.gor(t), 0.0) assert np.allclose(secondary.cgr(t), 0.0) assert np.allclose(secondary.wor(t), 0.0) assert np.allclose(secondary.rate(t), 0.0) assert np.allclose(secondary.cum(t), 0.0) assert np.allclose(secondary.D(t), 0.0) assert np.allclose(secondary.beta(t), 0.0) assert np.allclose(secondary.b(t), 0.0) assert np.allclose(secondary._Dfn2(t), 0.0)
def check_transient_model(model: dca.THM) -> bool: t = dca.get_time() with warnings.catch_warnings(record=True) as w: t_D = model.transient_D(t) assert is_float_array_like(t_D, t) # assert is_monotonic_nonincreasing(t_D) assert np.all(np.isfinite(t_D)) t_beta = model.transient_beta(t) assert is_float_array_like(t_beta, t) # assert is_monotonic_nonincreasing(t_beta) assert np.all(np.isfinite(t_beta)) t_b = model.transient_b(t) assert is_float_array_like(t_b, t) # assert is_monotonic_nonincreasing(t_b) assert np.all(np.isfinite(t_b)) return True
def check_model(model: dca.DeclineCurve, qi: float) -> bool: t = dca.get_time() with warnings.catch_warnings(record=True) as w: if isinstance(model, dca.Duong): t0 = 1e-3 assert np.isclose(model.rate(np.array(1.0)), qi, atol=1e-10) assert np.isclose(model.cum(np.array(1.0)), qi / model.a, atol=1e-10) else: t0 = 0.0 assert np.isclose(model.rate(np.array(0.0)), qi, atol=1e-10) assert np.isclose(model.cum(np.array(0.0)), 0.0, atol=1e-10) rate = model.rate(t) assert is_float_array_like(rate, t) # assert is_monotonic_nonincreasing(rate) assert np.all(np.isfinite(rate)) cum = model.cum(t) assert is_float_array_like(cum, t) # if not isinstance(model, dca.PLE): # exclude PLE as it is numerically integrated # assert is_monotonic_nondecreasing(cum) assert np.all(np.isfinite(cum)) mvolume = model.monthly_vol(t) mavg_rate = np.gradient(mvolume, t) # assert is_float_array_like(mvolume, t) # assert is_monotonic_nonincreasing(mavg_rate) assert np.all(np.isfinite(mvolume)) assert np.all(np.isfinite(mavg_rate)) ivolume = model.interval_vol(t) iavg_rate = np.gradient(ivolume, t) # assert is_float_array_like(ivolume, t) # assert is_monotonic_nonincreasing(iavg_rate) assert np.all(np.isfinite(ivolume)) assert np.all(np.isfinite(iavg_rate)) evolume = model.monthly_vol_equiv(t) mavg_rate = np.gradient(evolume, t) # assert is_float_array_like(evolume, t) # assert is_monotonic_nonincreasing(mavg_rate) assert np.all(np.isfinite(evolume)) assert np.all(np.isfinite(mavg_rate)) D = model.D(t) assert is_float_array_like(D, t) # assert is_monotonic_nonincreasing(D) assert np.all(np.isfinite(D)) D2 = model._Dfn2(t) assert is_float_array_like(D2, t) # assert is_monotonic_nonincreasing(D2) assert np.all(np.isfinite(D2)) beta = model.beta(t) assert is_float_array_like(beta, t) # TODO: what are the invariants for beta? D_inferred = beta / t # assert is_monotonic_nonincreasing(D_inferred) assert np.all(np.isfinite(beta)) b = model.b(t) assert is_float_array_like(b, t) assert np.all(np.isfinite(b)) return True
def check_yield_model(model: Union[dca.SecondaryPhase, dca.WaterPhase], phase: str, qi: float) -> bool: t = dca.get_time() with warnings.catch_warnings(record=True) as w: t0 = 0.0 assert np.isclose(model.cum(np.array(0.0)), 0.0, atol=1e-10) if phase == 'secondary' and isinstance(model, dca.SecondaryPhase): gor = model.gor(t) assert is_float_array_like(gor, t) assert np.all(np.isfinite(gor)) cgr = model.cgr(t) assert is_float_array_like(cgr, t) assert np.all(np.isfinite(cgr)) with pytest.raises(ValueError) as e: wor = model.wor(t) # type: ignore assert is_float_array_like(wor, t) assert np.all(np.isfinite(wor)) elif phase == 'water' and isinstance(model, dca.WaterPhase): with pytest.raises(ValueError) as e: gor = model.gor(t) # type: ignore assert is_float_array_like(gor, t) assert np.all(np.isfinite(gor)) cgr = model.cgr(t) # type: ignore assert is_float_array_like(cgr, t) assert np.all(np.isfinite(cgr)) wor = model.wor(t) assert is_float_array_like(wor, t) assert np.all(np.isfinite(wor)) rate = model.rate(t) assert is_float_array_like(rate, t) # assert is_monotonic_nonincreasing(rate) assert np.all(np.isfinite(rate)) cum = model.cum(t) assert is_float_array_like(cum, t) # if not isinstance(model, dca.PLE): # exclude PLE as it is numerically integrated # assert is_monotonic_nondecreasing(cum) assert np.all(np.isfinite(cum)) mvolume = model.monthly_vol(t) mavg_rate = np.gradient(mvolume, t) # assert is_float_array_like(mvolume, t) # assert is_monotonic_nonincreasing(mavg_rate) assert np.all(np.isfinite(mvolume)) assert np.all(np.isfinite(mavg_rate)) ivolume = model.interval_vol(t, t0=t0) iavg_rate = np.gradient(ivolume, t) # assert is_float_array_like(ivolume, t) # assert is_monotonic_nonincreasing(iavg_rate) assert np.all(np.isfinite(ivolume)) assert np.all(np.isfinite(iavg_rate)) evolume = model.monthly_vol_equiv(t) mavg_rate = np.gradient(evolume, t) # assert is_float_array_like(evolume, t) # assert is_monotonic_nonincreasing(mavg_rate) assert np.all(np.isfinite(evolume)) assert np.all(np.isfinite(mavg_rate)) D = model.D(t) assert is_float_array_like(D, t) # assert is_monotonic_nonincreasing(D) # assert np.all(np.isfinite(D)) D2 = model._Dfn2(t) assert is_float_array_like(D2, t) # assert is_monotonic_nonincreasing(D2) # assert np.all(np.isfinite(D2)) beta = model.beta(t) assert is_float_array_like(beta, t) # TODO: what are the invariants for beta? # D_inferred = beta / t # assert is_monotonic_nonincreasing(D_inferred) # assert np.all(np.isfinite(beta)) b = model.b(t) assert is_float_array_like(b, t) assert np.all(np.isfinite(b)) # der = model._derfn(np.array([0.0])) # NN = model._NNfn(np.array([0.0])) return True
from petbox import dca # ftime = dca.get_time() # thm = dca.THM(qi=750, Di=.8, bi=2, bf=.5, telf=28) q_trans = thm.transient_rate(ftime) N_trans = thm.transient_cum(ftime) D_trans = thm.transient_D(ftime) b_trans = thm.transient_b(ftime) beta_trans = thm.transient_beta(ftime) # q_thm = thm.rate(ftime) N_thm = thm.cum(ftime) D_thm = thm.D(ftime) b_thm = thm.b(ftime) beta_thm = thm.beta(ftime) # mh = dca.MH(qi=725, Di=0.85, bi=0.6, Dterm=0.2) q_mh = mh.rate(ftime) N_mh = mh.cum(ftime) N_mh = mh.monthly_vol(ftime) N_mh = mh.interval_vol(ftime) D_mh = mh.D(ftime) b_mh = mh.b(ftime) beta_mh = mh.beta(ftime) #