feat(utbygging): build out solution T in modules and add S48-S54

utbyggingsplan_trinnvis follows chapter 17.1: the grid balance of the
first stage, the payment condition for a module's power plants, S49,
and in T-K the two stocks of chips and the queue for replacements.
tidslinje gives MW IT in operation per type of power (S50). S48-S54
are pure functions in ligninger.py, and Inndata carries the new
quantities, the scenarios for the loss of demand and the paths of
u_alt. lag_plan returns a Trinnvisplan for T-F and T-K; regn_program
refuses T until it is taken through the cash flow.

Tested on made-up numbers only (59 new tests, hand-computed build-outs).
Nothing is computed for the hypothesis.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-12 23:55:57 +01:00
commit bca6496c0a
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
12 changed files with 1271 additions and 31 deletions

View file

@ -156,6 +156,34 @@ def test_karbonprisen_er_lineaer_mellom_aarene_i_tabellen(
assert inn.karbonpris_i(2025) == 1588.0
def test_stoerrelsene_for_tillegget_til_retningen_foelger_parameterfila(
forste_trekning: inndata.Inndata,
) -> None:
"""Chapter 17.8: units and tables only; nothing is computed with them."""
inn = forste_trekning
assert (inn["P_m"], inn["eps_d"], inn["w_N_forbruk"], inn["w_D_sjo"]) == (100.0, 1.0, 0.0, 98.0)
assert 3.0 <= inn["tau_1"] <= 7.0
assert 18.0 <= inn["n_1"] <= 268.0
assert 0.07 <= inn["w_D_uttak"] <= 0.10
assert 119.0 <= inn["w_N_uttak"] <= 168.0
# the table of 17.3
assert inn.bortfall[inndata.BORTFALL_KILDE] == (0.119, 0.21)
assert inn.bortfall[inndata.BORTFALL_EGNE_LAV] == pytest.approx((0.188, 0.376))
assert inn.bortfall[inndata.BORTFALL_EGNE_HOY] == pytest.approx((0.32, 0.64))
assert inn.bortfall_i(inndata.BORTFALL_KILDE, 2040) == 0.21
# the table of 17.4, g CO2 per kWh converted to tonnes per MWh
assert set(inn.u_alt) == {"hoved", "lav", "hoy_nedre", "hoy_ovre", "null"}
assert inn.u_alt_i("hoved", 2024) == pytest.approx(0.43)
assert inn.u_alt_i("hoved", 2045) == pytest.approx((0.2012 + 0.1312) / 2)
assert inn.u_alt_i("hoved", 2100) == pytest.approx(0.1312)
assert inn.u_alt_i("lav", 2100) == pytest.approx(0.09)
assert (inn.u_alt_i("hoy_nedre", 2050), inn.u_alt_i("hoy_ovre", 2050)) == pytest.approx(
(0.41, 0.626)
)
assert inn.u_alt_i("null", 2050) == 0.0
assert inn.kjoletaarn == {"forbruk": (2.2, 2.5, 3.2), "uttak": (3.0, 4.2, 9.8)}
def test_heltall_avviser_tall_som_ikke_er_hele(forste_trekning: inndata.Inndata) -> None:
with pytest.raises(ValueError, match="should be a whole number"):
forste_trekning.heltall("rho_N")