feat(dommer): five solutions in M5 and the verdicts, and three sensitivities of chapter 17.8 as switches
The ladder, part I and M7 now cover A, B, C, T-F and T-K: A is best when it can be built and beats each of the four others that can. M5 holds by definition for T-F and judges T-K as nuclear power on every step. Switches for the sensitivities: full displacement in the first stage (delta_V = 1 for the modules started within the grid that exists, in S11, S23, S24, the grid investment and V), new renewable power counted from a later year for C and T, and Inndata.med for modules of 50 and 200 MW. Next to S54 the withdrawal with sea water only for the nuclear production the data centres themselves use. With the switches off every figure for all seven solutions is unchanged to the last digit (267 made-up paths, 516 817 lines, byte for byte). Not yet reconciled against the independent reader's code. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
811fad1296
commit
fe2b2131f3
9 changed files with 754 additions and 42 deletions
|
|
@ -89,17 +89,22 @@ def test_dom_m2_teller_null_som_oppfylt() -> None:
|
|||
|
||||
|
||||
def test_dom_m7_a_mot_b_og_c() -> None:
|
||||
"""A is best in 5 of 10 draws: holds. A draw where A cannot be built is not one of them."""
|
||||
"""A is best in 5 of 10 draws: holds. A draw where A cannot be built is not one of them.
|
||||
|
||||
The two versions of solution T are left out here; ``test_trinnvis_dommer.py`` has all five.
|
||||
"""
|
||||
A = _utfall((10.0, 5), (1.0, 3), (None, 2))
|
||||
B = _utfall((5.0, 5), (2.0, 3), (-9.0, 2))
|
||||
C = _utfall((None, 5), (0.0, 5))
|
||||
assert dommer.a_er_best(A, B, C) == [True] * 5 + [False] * 5
|
||||
assert dommer.dom_m7(A, B, C) is Dom.HOLDER
|
||||
assert dommer.a_er_best({Losning.A: A, Losning.B: B, Losning.C: C}) == [True] * 5 + [False] * 5
|
||||
assert dommer.dom_m7({Losning.A: A, Losning.B: B, Losning.C: C}) is Dom.HOLDER
|
||||
alltid_bedre = _utfall((5.0, 5), (2.0, 5))
|
||||
assert dommer.dom_m7(_utfall((10.0, 4), (1.0, 6)), alltid_bedre, C) is Dom.BETINGELSER
|
||||
assert dommer.dom_m7(_utfall((10.0, 1), (1.0, 9)), alltid_bedre, C) is Dom.HOLDER_IKKE
|
||||
fire = {Losning.A: _utfall((10.0, 4), (1.0, 6)), Losning.B: alltid_bedre, Losning.C: C}
|
||||
assert dommer.dom_m7(fire) is Dom.BETINGELSER
|
||||
en = {Losning.A: _utfall((10.0, 1), (1.0, 9)), Losning.B: alltid_bedre, Losning.C: C}
|
||||
assert dommer.dom_m7(en) is Dom.HOLDER_IKKE
|
||||
# equal is not best
|
||||
assert dommer.a_er_best([1.0], [1.0], [0.0]) == [False]
|
||||
assert dommer.a_er_best({Losning.A: [1.0], Losning.B: [1.0], Losning.C: [0.0]}) == [False]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ M3 and M4
|
||||
|
|
@ -208,7 +213,7 @@ def test_ellers_paa_hoyeste_trinn_som_lar_seg_bygge() -> None:
|
|||
|
||||
|
||||
def test_referansekjoringen_kan_ikke_gi_trinnet() -> None:
|
||||
"""R reaches 90 % on every step here, but only A, B and C decide the step."""
|
||||
"""R reaches 90 % on every step here, but only A, B, C, T-F and T-K decide the step."""
|
||||
stige = _stige(n1=(0.0, 10), n5=(0.0, 10))
|
||||
assert dommer.trinn_for_dommene(stige).grunnlag is Grunnlag.HOYESTE
|
||||
|
||||
|
|
@ -267,7 +272,7 @@ def test_del_I_holder_ikke_naar_hver_losning_er_felt() -> None:
|
|||
assert dommer.del_I(per_losning, median, Trinnvalg(None, Grunnlag.INGEN)) is Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def test_del_I_ser_bare_paa_A_B_og_C() -> None:
|
||||
def test_del_I_ser_ikke_paa_referansekjoringen() -> None:
|
||||
"""The reference run R holds on everything here; it cannot give «holder»."""
|
||||
per_losning = {
|
||||
Losning.A: _dommer(M2=Dom.HOLDER_IKKE),
|
||||
|
|
|
|||
569
tests/test_trinnvis_dommer.py
Normal file
569
tests/test_trinnvis_dommer.py
Normal file
|
|
@ -0,0 +1,569 @@
|
|||
"""Five solutions in M5 and the verdicts, and the sensitivities of chapter 17.8 that are switches.
|
||||
|
||||
Made-up round numbers and invented outcomes per draw only; nothing here says anything about
|
||||
the hypothesis. The path used most is T-F with one facility's worth of modules from the
|
||||
made-up set with new grid in 2033 (hand-computed in ``test_trinnvis.py``): modules start in
|
||||
2030, 2031 and 2032 within the grid that exists, and seven in 2033. A module of 100 MW
|
||||
draws 120 MW and uses 8760 * 0.75 * 1.2 * 100 = 788 400 MWh a year.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tokenfabrikker import dommer, miljo, skala
|
||||
from tokenfabrikker import kontantstrom as ks
|
||||
from tokenfabrikker import nivaaisert as nv
|
||||
from tokenfabrikker import utbygging as ub
|
||||
from tokenfabrikker.dommer import Dom, Grunnlag, Trinnvalg
|
||||
from tokenfabrikker.kontantstrom import Knapphet
|
||||
from tokenfabrikker.miljo import Kildeverdier
|
||||
from tokenfabrikker.utbygging import Kraft, Losning
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
from conftest import LagInndata
|
||||
from tokenfabrikker.inndata import Inndata
|
||||
|
||||
E_MODUL = 8760.0 * 0.75 * 1.2 * 100.0
|
||||
"""Yearly energy to one made-up module of 100 MW: 788 400 MWh."""
|
||||
|
||||
E_ENHET = 8760.0 * 0.8 * 1000.0
|
||||
"""Yearly production of one made-up unit on the grid: 7 008 000 MWh."""
|
||||
|
||||
T_0 = 2027
|
||||
|
||||
Stige = dict[int, dict[Losning, list[float | None]]]
|
||||
"""M6 per draw for each step of the ladder and each solution."""
|
||||
|
||||
|
||||
def _regn(
|
||||
inn: Inndata,
|
||||
losning: Losning,
|
||||
*,
|
||||
N_anlegg: int = 1,
|
||||
full_fortrengning: bool = False,
|
||||
uten_forste_trinn: bool = False,
|
||||
ny_kraft_fra: int | None = None,
|
||||
) -> ks.Programresultat:
|
||||
dim = ks.dimensjoner(inn, losning)
|
||||
brytere = {"uten_forste_trinn": uten_forste_trinn} if losning.trinnvis else {}
|
||||
plan = ks.lag_plan(inn, losning, dim, N_anlegg=N_anlegg, ny_kraft_fra=ny_kraft_fra, **brytere)
|
||||
return ks.regn_program(
|
||||
inn,
|
||||
losning,
|
||||
plan,
|
||||
Knapphet.NORMALISERING,
|
||||
dim=dim,
|
||||
full_fortrengning_i_forste_trinn=full_fortrengning,
|
||||
)
|
||||
|
||||
|
||||
def _start(plan: ub.Plan) -> list[int]:
|
||||
return [modul.start for modul in plan.anlegg]
|
||||
|
||||
|
||||
def _lik(a: ks.Programresultat, b: ks.Programresultat) -> None:
|
||||
"""Every yearly table and every present value of the two results is the same number."""
|
||||
for navn in ("KS_D", "KS_N", "F_a", "Delta_W", "utslipp", "K_prog", "V"):
|
||||
assert np.array_equal(getattr(a, navn), getattr(b, navn)), navn
|
||||
for navn in ("NV_datasenter", "NV_kraft", "NV_ovrige", "RV", "SE", "NNV"):
|
||||
assert getattr(a, navn) == getattr(b, navn), navn
|
||||
assert a.RV_anlegg == b.RV_anlegg
|
||||
assert a.varsigma == b.varsigma
|
||||
|
||||
|
||||
def _utfall(*deler: tuple[float | None, int]) -> list[float | None]:
|
||||
"""Invented outcomes: each value repeated the given number of draws."""
|
||||
return [verdi for verdi, antall in deler for _ in range(antall)]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------ M5
|
||||
|
||||
|
||||
def test_m5_tf_holder_per_definisjon_og_tk_vurderes_som_kjernekraft() -> None:
|
||||
"""Invented source values. T-F is as C and R; T-K gets the verdict B gets (chapter 17.1)."""
|
||||
under = Kildeverdier("X", kjernekraft=5.0, vind=11.0, vann=6.0, vind_hoyeste=50.0)
|
||||
mellom = Kildeverdier("Y", kjernekraft=12.0, vind=11.0, vann=24.0, vind_hoyeste=56.0)
|
||||
over = Kildeverdier("Z", kjernekraft=60.0, vind=11.0, vann=24.0, vind_hoyeste=56.0)
|
||||
assert miljo.m5_utslipp(Losning.T_F, [over]) is Dom.HOLDER
|
||||
assert miljo.m5_utslipp(Losning.T_F, []) is Dom.HOLDER
|
||||
for kilder, dom in (
|
||||
([under], Dom.HOLDER),
|
||||
([under, mellom], Dom.BETINGELSER),
|
||||
([under, mellom, over], Dom.HOLDER_IKKE),
|
||||
):
|
||||
assert miljo.m5_utslipp(Losning.T_K, kilder) is dom
|
||||
assert miljo.m5_utslipp(Losning.B, kilder) is dom
|
||||
areal = {"vind_direkte": 1.5, "vind_plan": 35.0}
|
||||
assert miljo.m5_areal(Losning.T_F, kjernekraft=40.0, **areal) is Dom.HOLDER
|
||||
assert miljo.m5_areal(Losning.T_K, kjernekraft=1.5, **areal) is Dom.HOLDER
|
||||
assert miljo.m5_areal(Losning.T_K, kjernekraft=10.0, **areal) is Dom.BETINGELSER
|
||||
assert miljo.m5_areal(Losning.T_K, kjernekraft=40.0, **areal) is Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def test_m5_for_tk_folger_ikke_trinnet_eller_trekningen() -> None:
|
||||
"""M5 takes the solution and the sources' figures, nothing from a path or a draw."""
|
||||
alle = {a: miljo.m5_utslipp(a, miljo.KILDEVERDIER_M5) for a in Losning}
|
||||
assert alle[Losning.T_K] is alle[Losning.A] is alle[Losning.B] is alle[Losning.B_MERKET]
|
||||
assert alle[Losning.T_F] is alle[Losning.C] is alle[Losning.R] is Dom.HOLDER
|
||||
|
||||
|
||||
# ----------------------------------------------------------- M7 with five solutions
|
||||
|
||||
|
||||
def test_m7_a_maa_slaa_hver_av_de_fire_som_lar_seg_bygge() -> None:
|
||||
"""Six invented draws.
|
||||
|
||||
1: A highest. 2: T-F higher. 3: T-K equal (strictly higher is required). 4: only A can
|
||||
be built. 5: A cannot be built. 6: A highest among those that can be built.
|
||||
"""
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
Losning.A: [10.0, 10.0, 10.0, 10.0, None, 10.0],
|
||||
Losning.B: [5.0, 5.0, 5.0, None, 1.0, 5.0],
|
||||
Losning.C: [5.0, 5.0, 5.0, None, 1.0, None],
|
||||
Losning.T_F: [5.0, 11.0, 5.0, None, 1.0, None],
|
||||
Losning.T_K: [5.0, 5.0, 10.0, None, 1.0, 9.0],
|
||||
}
|
||||
assert dommer.a_er_best(nnv) == [True, False, False, True, False, True]
|
||||
assert dommer.dom_m7(nnv) is Dom.HOLDER # three of six
|
||||
# without the two versions of T, A is also best in draws 2 and 3
|
||||
tre = {a: nnv[a] for a in (Losning.A, Losning.B, Losning.C)}
|
||||
assert dommer.a_er_best(tre) == [True, True, True, True, False, True]
|
||||
# the order the solutions stand in does not matter
|
||||
snudd = {a: nnv[a] for a in reversed(list(nnv))}
|
||||
assert dommer.a_er_best(snudd) == dommer.a_er_best(nnv)
|
||||
|
||||
|
||||
def test_m7_andelene() -> None:
|
||||
"""A is best in 4 of 10 and in 1 of 10 draws against a T-F that is otherwise higher."""
|
||||
andre = {a: _utfall((5.0, 10)) for a in (Losning.B, Losning.C, Losning.T_K)}
|
||||
tf_fire = {Losning.A: _utfall((10.0, 10)), Losning.T_F: _utfall((1.0, 4), (20.0, 6))}
|
||||
tf_en = {Losning.A: _utfall((10.0, 10)), Losning.T_F: _utfall((1.0, 1), (20.0, 9))}
|
||||
assert dommer.dom_m7({**andre, **tf_fire}) is Dom.BETINGELSER
|
||||
assert dommer.dom_m7({**andre, **tf_en}) is Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def test_m7_gjelder_a_mot_b_c_tf_og_tk() -> None:
|
||||
"""Without A there is nothing to judge; R and B' are not part of M7."""
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.B: [1.0], Losning.C: [2.0]})
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.A: [1.0], Losning.R: [2.0]})
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.A: [1.0], Losning.B_MERKET: [2.0]})
|
||||
|
||||
|
||||
# ------------------------------------------------------ the ladder with five solutions
|
||||
|
||||
|
||||
def _stige(losning: Losning, **per_trinn: tuple[float, int]) -> Stige:
|
||||
"""A made-up ladder: ``losning`` has the given M6 in the given number of 10 draws.
|
||||
|
||||
A, B and C can be built in every draw and reach nothing; R reaches 90 % everywhere.
|
||||
"""
|
||||
stige: Stige = {}
|
||||
for navn, (verdi, antall) in per_trinn.items():
|
||||
stige[int(navn.removeprefix("n"))] = {
|
||||
Losning.A: _utfall((0.0, 10)),
|
||||
Losning.B: _utfall((0.0, 10)),
|
||||
Losning.C: _utfall((0.0, 10)),
|
||||
Losning.R: _utfall((0.9, 10)),
|
||||
losning: _utfall((verdi, antall), (None, 10 - antall)),
|
||||
}
|
||||
return stige
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.T_F, Losning.T_K])
|
||||
def test_en_utgave_av_t_kan_gi_trinnet_alene(losning: Losning) -> None:
|
||||
"""25 % in 8 of 10 draws on step 10 for one version of T; 5 % from step 5."""
|
||||
stige = _stige(losning, n1=(0.03, 10), n5=(0.1, 9), n10=(0.3, 8), n20=(0.5, 10))
|
||||
assert dommer.trinn_for_dommene(stige) == Trinnvalg(10, Grunnlag.TRINN_25)
|
||||
stige = _stige(losning, n1=(0.03, 10), n5=(0.1, 8), n10=(0.3, 7))
|
||||
assert dommer.trinn_for_dommene(stige) == Trinnvalg(5, Grunnlag.TRINN_5)
|
||||
|
||||
|
||||
def test_hoyeste_trinn_som_lar_seg_bygge_gjelder_de_fem() -> None:
|
||||
"""No step reaches 5 %. A, B and C cannot be built on step 20; T-K can in 8 of 10 draws."""
|
||||
stige = _stige(Losning.T_K, n10=(0.01, 10), n20=(0.02, 8))
|
||||
for a in (Losning.A, Losning.B, Losning.C):
|
||||
stige[20][a] = _utfall((None, 10))
|
||||
assert dommer.trinn_for_dommene(stige) == Trinnvalg(20, Grunnlag.HOYESTE)
|
||||
stige[20][Losning.T_K] = _utfall((0.02, 7), (None, 3))
|
||||
assert dommer.trinn_for_dommene(stige) == Trinnvalg(10, Grunnlag.HOYESTE)
|
||||
|
||||
|
||||
# ------------------------------------------------------ part I with five solutions
|
||||
|
||||
|
||||
def _dommer(**endringer: Dom) -> dict[str, Dom]:
|
||||
alle = dict.fromkeys(dommer.MAAL_DEL_I, Dom.HOLDER)
|
||||
alle.update(endringer)
|
||||
return alle
|
||||
|
||||
|
||||
_PAA_25 = Trinnvalg(10, Grunnlag.TRINN_25)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.T_F, Losning.T_K])
|
||||
def test_del_I_holder_naar_en_utgave_av_t_holder_paa_alle_maal(losning: Losning) -> None:
|
||||
"""A, B and C are felled; one version of T holds on M1 to M6 on the 25 % step."""
|
||||
per_losning = {
|
||||
Losning.A: _dommer(M1=Dom.HOLDER_IKKE),
|
||||
Losning.B: _dommer(M2=Dom.HOLDER_IKKE),
|
||||
Losning.C: _dommer(M4=Dom.HOLDER_IKKE),
|
||||
losning: _dommer(),
|
||||
}
|
||||
median = dict.fromkeys(per_losning, 5.0)
|
||||
assert dommer.del_I(per_losning, median, _PAA_25) is Dom.HOLDER
|
||||
assert dommer.del_I(per_losning, median, Trinnvalg(10, Grunnlag.TRINN_5)) is Dom.BETINGELSER
|
||||
# step 1 is ten modules in T; as a single facility it cannot give «holder»
|
||||
assert dommer.del_I(per_losning, median, Trinnvalg(1, Grunnlag.TRINN_25)) is Dom.BETINGELSER
|
||||
|
||||
|
||||
def test_del_I_holder_ikke_forst_naar_alle_fem_er_felt() -> None:
|
||||
"""Four are felled and T-K is not: under conditions. T-K with a negative median: not."""
|
||||
per_losning = {
|
||||
Losning.A: _dommer(M1=Dom.HOLDER_IKKE),
|
||||
Losning.B: _dommer(M2=Dom.HOLDER_IKKE),
|
||||
Losning.C: _dommer(M3=Dom.HOLDER_IKKE),
|
||||
Losning.T_F: _dommer(M4=Dom.HOLDER_IKKE),
|
||||
Losning.T_K: _dommer(M1=Dom.BETINGELSER, M5=Dom.BETINGELSER),
|
||||
}
|
||||
median = dict.fromkeys(per_losning, 5.0)
|
||||
assert dommer.del_I(per_losning, median, _PAA_25) is Dom.BETINGELSER
|
||||
assert (
|
||||
dommer.del_I(per_losning, median, _PAA_25, betingelser_kan_navngis=False) is Dom.HOLDER_IKKE
|
||||
)
|
||||
median[Losning.T_K] = -1.0
|
||||
assert dommer.del_I(per_losning, median, _PAA_25) is Dom.HOLDER_IKKE
|
||||
# the order the solutions stand in does not matter
|
||||
median[Losning.T_K] = 5.0
|
||||
snudd = {a: per_losning[a] for a in reversed(list(per_losning))}
|
||||
assert dommer.del_I(snudd, median, _PAA_25) is Dom.BETINGELSER
|
||||
|
||||
|
||||
def test_m5_kan_felle_tk_men_ikke_tf() -> None:
|
||||
"""T-K with M5 not holding is felled as A and B are; T-F meets M5 by definition."""
|
||||
felt = _dommer(M5=Dom.HOLDER_IKKE)
|
||||
per_losning = dict.fromkeys((Losning.A, Losning.B, Losning.T_K), felt)
|
||||
per_losning[Losning.C] = _dommer(M1=Dom.HOLDER_IKKE)
|
||||
median = dict.fromkeys(dommer.DOMSLOSNINGER, 5.0)
|
||||
assert dommer.del_I(per_losning, median, _PAA_25) is Dom.HOLDER_IKKE
|
||||
per_losning[Losning.T_F] = _dommer()
|
||||
assert dommer.del_I(per_losning, median, _PAA_25) is Dom.HOLDER
|
||||
|
||||
|
||||
# --------------------------------- sensitivity: full displacement in the first stage
|
||||
|
||||
|
||||
def test_full_fortrengning_gjelder_modulene_i_forste_trinn(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed for T-F: three modules started within the grid that exists.
|
||||
|
||||
They pay for no grid, also when the connection is renewed after ten years, and the
|
||||
whole of their draw counts in V. The seven others pay 5 mill. kr per MW for half of
|
||||
120 MW, as before.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, L_nett=10)
|
||||
uten = _regn(inn, Losning.T_F)
|
||||
med = _regn(inn, Losning.T_F, full_fortrengning=True)
|
||||
assert _start(med.plan) == _start(uten.plan) == [2030, 2031, 2032] + [2033] * 7
|
||||
assert [med.delta_V(inn, k) for k in range(10)] == [1.0] * 3 + [0.5] * 7
|
||||
assert [uten.delta_V(inn, k) for k in range(10)] == [0.5] * 10
|
||||
for k in range(3):
|
||||
assert not med.anlegg[k].I_nett.any()
|
||||
assert uten.anlegg[k].I_nett[2029 + k - T_0] == pytest.approx(5e6 * 0.5 * 120.0)
|
||||
# renewed after ten years, in the year before the new connection is in operation
|
||||
assert uten.anlegg[k].I_nett[2039 + k - T_0] == pytest.approx(5e6 * 0.5 * 120.0)
|
||||
for k in range(3, 10):
|
||||
assert np.array_equal(med.anlegg[k].I_nett, uten.anlegg[k].I_nett)
|
||||
assert med.anlegg[k].I_nett[2032 - T_0] == pytest.approx(5e6 * 0.5 * 120.0)
|
||||
# V: 70 kr per MWh of electricity tax on what is displaced
|
||||
assert uten.V[2032 - T_0] == pytest.approx(0.5 * 3 * E_MODUL * 70.0)
|
||||
assert med.V[2032 - T_0] == pytest.approx(3 * E_MODUL * 70.0)
|
||||
# also after new grid can be in place: three modules in full, seven by half
|
||||
for t in (2033, 2040):
|
||||
assert uten.V[t - T_0] == pytest.approx(0.5 * 10 * E_MODUL * 70.0)
|
||||
assert med.V[t - T_0] == pytest.approx((3 + 0.5 * 7) * E_MODUL * 70.0)
|
||||
|
||||
|
||||
def test_full_fortrengning_i_kraftsystemet(oppdiktet: LagInndata) -> None:
|
||||
"""S23 and S24: the first-stage modules take nothing new from the power system.
|
||||
|
||||
Without the switch half of their draw does: 0.5 * 3 * 788 400 MWh and 0.5 * 360 MW.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0)
|
||||
uten = _regn(inn, Losning.T_F)
|
||||
med = _regn(inn, Losning.T_F, full_fortrengning=True)
|
||||
for t in (2032, 2033, 2045):
|
||||
u, m = uten.kraftaar[t - T_0], med.kraftaar[t - T_0]
|
||||
assert m.Delta_Q == pytest.approx(u.Delta_Q - 0.5 * 3 * E_MODUL)
|
||||
assert m.Delta_Q_tort == pytest.approx(u.Delta_Q_tort - 0.5 * 3 * E_MODUL)
|
||||
assert m.Delta_R == pytest.approx(u.Delta_R + 0.5 * 360.0)
|
||||
assert m.Delta_R_utfall == pytest.approx(u.Delta_R_utfall + 0.5 * 360.0)
|
||||
# 2030: one module, and the whole of its draw displaces others: only its power is new
|
||||
(vann,) = med.verk[0]
|
||||
assert med.kraftaar[2030 - T_0].Delta_Q == pytest.approx(-vann.energi)
|
||||
# M3 and M4 are read from the same years
|
||||
assert dommer.m3_verste_prisvirkning(inn, med) < dommer.m3_verste_prisvirkning(inn, uten)
|
||||
|
||||
|
||||
def test_full_fortrengning_for_alle_modulene_er_delta_v_lik_en(oppdiktet: LagInndata) -> None:
|
||||
"""Two ways to the same numbers: every module in the first stage, or delta_V = 1.
|
||||
|
||||
New grid in 2039 and 1 000 MW of draw a year: five modules in 2030 and five in 2031
|
||||
(module six is the first with offshore wind, which cannot be paid for before 2028).
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=12.0, n_1=1000.0)
|
||||
alt = inn.med({"delta_V": 1.0})
|
||||
med = _regn(inn, Losning.T_F, full_fortrengning=True)
|
||||
fasit = _regn(alt, Losning.T_F)
|
||||
assert _start(med.plan) == [2030] * 5 + [2031] * 5
|
||||
assert all(med.plan.i_forste_trinn(k) for k in range(10)) # type: ignore[attr-defined]
|
||||
_lik(med, fasit)
|
||||
assert med.NNV != _regn(inn, Losning.T_F).NNV
|
||||
# chapters 7 to 9: the grid cost H_a in the power cost and in scale
|
||||
for bedrift in (False, True):
|
||||
a = nv.kraftkostnad(inn, med, bedrift=bedrift)
|
||||
b = nv.kraftkostnad(alt, fasit, bedrift=bedrift)
|
||||
assert np.array_equal(a.c_a, b.c_a, equal_nan=True)
|
||||
assert a.S42 == b.S42
|
||||
assert np.array_equal(skala.skala(inn, med).B_6, skala.skala(alt, fasit).B_6)
|
||||
|
||||
|
||||
def test_full_fortrengning_uten_moduler_i_forste_trinn_endrer_ingenting(
|
||||
oppdiktet: LagInndata,
|
||||
) -> None:
|
||||
"""Without a first stage no module is touched, and with delta_V = 1 there is nothing to add."""
|
||||
inn = oppdiktet(tau_nett=6.0)
|
||||
_lik(
|
||||
_regn(inn, Losning.T_F, uten_forste_trinn=True, full_fortrengning=True),
|
||||
_regn(inn, Losning.T_F, uten_forste_trinn=True),
|
||||
)
|
||||
alt = inn.med({"delta_V": 1.0})
|
||||
_lik(_regn(alt, Losning.T_F, full_fortrengning=True), _regn(alt, Losning.T_F))
|
||||
|
||||
|
||||
def test_full_fortrengning_i_tk_gjelder_fornybarmodulene_i_forste_trinn(
|
||||
oppdiktet: LagInndata,
|
||||
) -> None:
|
||||
"""T-K with two facilities: modules 2030 and 2031 are in the first stage, 2033 is not.
|
||||
|
||||
The nuclear modules start after new grid can be in place and are never touched.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6)
|
||||
med = _regn(inn, Losning.T_K, N_anlegg=2, full_fortrengning=True)
|
||||
assert [med.delta_V(inn, k) for k in range(20)] == [1.0] * 2 + [0.5] * 18
|
||||
uten = _regn(inn, Losning.T_K, N_anlegg=2)
|
||||
assert med.V[2036 - T_0] == pytest.approx((2 + 0.5 * 18) * E_MODUL * 70.0)
|
||||
assert np.array_equal(med.anlegg[5].I_nett, uten.anlegg[5].I_nett)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.A, Losning.B, Losning.B_MERKET, Losning.C, Losning.R])
|
||||
def test_full_fortrengning_gjelder_bare_t(oppdiktet: LagInndata, losning: Losning) -> None:
|
||||
inn = oppdiktet()
|
||||
with pytest.raises(ValueError, match="only solution T has a first stage"):
|
||||
_regn(inn, losning, full_fortrengning=True)
|
||||
|
||||
|
||||
# ------------------------------------------------ sensitivity: modules of 50 and 200 MW
|
||||
|
||||
|
||||
def test_inndata_med_bytter_ut_navngitte_storrelser(oppdiktet: LagInndata) -> None:
|
||||
inn = oppdiktet()
|
||||
smaa = inn.med({"P_m": 50.0})
|
||||
assert (smaa["P_m"], inn["P_m"], smaa["P_IT"]) == (50.0, 100.0, 1000.0)
|
||||
assert smaa.psi == inn.psi
|
||||
with pytest.raises(KeyError, match="unknown quantities"):
|
||||
inn.med({"P_modul": 50.0})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("P_m", "per_anlegg"), [(50.0, 20), (100.0, 10), (200.0, 5)])
|
||||
def test_et_trinn_har_like_mange_mw_uansett_modulstorrelse(
|
||||
oppdiktet: LagInndata, P_m: float, per_anlegg: int
|
||||
) -> None:
|
||||
inn = oppdiktet(tau_nett=6.0).med({"P_m": P_m})
|
||||
assert ks.antall_moduler(inn, 2) == 2 * per_anlegg
|
||||
dim = ks.dimensjoner(inn, Losning.T_F)
|
||||
assert dim.E_D == pytest.approx(8760.0 * 0.75 * 1.2 * P_m)
|
||||
plan = ks.lag_plan(inn, Losning.T_F, dim, N_anlegg=1)
|
||||
assert plan.gjennomforbar
|
||||
assert len(plan.anlegg) == per_anlegg
|
||||
linje = ub.tidslinje(Losning.T_F, plan, P_IT=inn["P_IT"])
|
||||
assert linje[Kraft.NY_FORNYBAR][2040 - T_0 - 1] == pytest.approx(1000.0)
|
||||
|
||||
|
||||
def test_moduler_paa_200_mw_i_forste_trinn(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed: 150 MW of draw a year, a module draws 240, the balance stops at 390.
|
||||
|
||||
2030: 150, no module. 2031: 300, one module (60 left). 2032: 210, none. From 2033 no
|
||||
limit: the four that remain. Chips and power have room all the way.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0).med({"P_m": 200.0})
|
||||
res = _regn(inn, Losning.T_F)
|
||||
assert _start(res.plan) == [2031] + [2033] * 4
|
||||
assert res.P_enhet == 200.0
|
||||
# the building of module 1: 100 mill. kr per MW plus ten per cent, over 2029 and 2030
|
||||
assert res.anlegg[0].I_bygg[2029 - T_0] == pytest.approx(11e9)
|
||||
assert res.anlegg[0].I_bygg[2030 - T_0] == pytest.approx(11e9)
|
||||
assert res.anlegg[0].I_nett[2030 - T_0] == pytest.approx(5e6 * 0.5 * 240.0)
|
||||
|
||||
|
||||
def test_moduler_paa_50_mw_i_forste_trinn(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed: a module draws 60 MW, and the balance stops at 210.
|
||||
|
||||
2030: 150, two modules (30 left). 2031: 180, three modules. 2032: 150, two modules.
|
||||
2033: the thirteen that remain.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0).med({"P_m": 50.0})
|
||||
res = _regn(inn, Losning.T_F)
|
||||
assert _start(res.plan) == [2030] * 2 + [2031] * 3 + [2032] * 2 + [2033] * 13
|
||||
assert res.P_enhet == 50.0
|
||||
|
||||
|
||||
def test_s49_med_andre_modulstorrelser(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed: one unit gives 800 MW on average, and what is left must draw that (S49).
|
||||
|
||||
0.5 TWh of new renewable power a year, two facilities' worth, nuclear power from 2035.
|
||||
200 MW: a module needs 1.5768 TWh in a dry year. Module 1 starts in 2031 (2 TWh of
|
||||
hydropower gives 1.6); module 2 would need 3.5536 TWh built, and 3.5 are built by 2034.
|
||||
Nine are left, 1 620 MW. 50 MW: a module needs 0.3942 TWh. Power has room for 3, 4, 5,
|
||||
6 and 7 modules in 2030 to 2034 and the grid balance for two in 2030, so seven start
|
||||
before 2035. 33 are left, 1 485 MW.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6)
|
||||
|
||||
def plan(P_m: float) -> ub.Trinnvisplan:
|
||||
sett = inn.med({"P_m": P_m})
|
||||
resultat = ks.lag_plan(sett, Losning.T_K, ks.dimensjoner(sett, Losning.T_K), N_anlegg=2)
|
||||
assert isinstance(resultat, ub.Trinnvisplan)
|
||||
return resultat
|
||||
|
||||
store, smaa = plan(200.0), plan(50.0)
|
||||
assert (store.t_N, store.J_F, store.kjernekraft_bygges, store.N_anlegg) == (2035, 1, True, 10)
|
||||
assert _start(store)[:2] == [2031, 2035]
|
||||
assert (smaa.t_N, smaa.J_F, smaa.kjernekraft_bygges, smaa.N_anlegg) == (2035, 7, True, 40)
|
||||
assert _start(smaa)[:8] == [2030, 2030, 2031, 2031, 2032, 2033, 2034, 2035]
|
||||
# one facility's worth with 200 MW modules: four are left, 720 MW, less than one unit
|
||||
sett = inn.med({"P_m": 200.0})
|
||||
ett = ks.lag_plan(sett, Losning.T_K, ks.dimensjoner(sett, Losning.T_K), N_anlegg=1)
|
||||
assert isinstance(ett, ub.Trinnvisplan)
|
||||
assert (ett.J_F, ett.kjernekraft_bygges) == (1, False)
|
||||
|
||||
|
||||
# --------------------------------- sensitivity: new renewable power first from 2031
|
||||
|
||||
|
||||
def test_takten_regnes_fra_aaret_ny_kraft_tidligst_kan_komme() -> None:
|
||||
"""1 TWh a year; 2 TWh of hydropower gives 0.8 in a dry year, then wind. E_D = 1 TWh.
|
||||
|
||||
From T_0 + 1 = 2028: 0.8 facilities in 2028. From 2031: nothing by 2030, 0.8 in 2031,
|
||||
1.6 in 2032 and 2.6 in 2033.
|
||||
"""
|
||||
|
||||
def rom(forste_aar: int | None) -> Callable[[int], float]:
|
||||
return ub.kraftrom_fornybar(
|
||||
g_fornybar=1e6,
|
||||
w_tort_vann=0.8,
|
||||
E_vann_rest=2e6,
|
||||
E_vind_rest=3e6,
|
||||
E_D=1e6,
|
||||
T_0=2027,
|
||||
forste_aar=forste_aar,
|
||||
)
|
||||
|
||||
hoved, sen = rom(None), rom(2031)
|
||||
assert [hoved(t) for t in (2028, 2029, 2030)] == pytest.approx([0.8, 1.6, 2.6])
|
||||
assert [sen(t) for t in (2028, 2029, 2030)] == [0.0, 0.0, 0.0]
|
||||
assert [sen(t) for t in (2031, 2032, 2033)] == pytest.approx([0.8, 1.6, 2.6])
|
||||
# a year that is not later than T_0 + 1 changes nothing
|
||||
for forste_aar in (2020, 2027, 2028):
|
||||
tidlig = rom(forste_aar)
|
||||
assert [tidlig(t) for t in range(2028, 2040)] == [hoved(t) for t in range(2028, 2040)]
|
||||
|
||||
|
||||
def test_ny_kraft_fra_2031_i_c(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed: 4 TWh a year, and a facility needs 7.884 TWh in a dry year.
|
||||
|
||||
Main path: 12 TWh by 2030 gives 1.6 + 3 + 7 = 11.6 in a dry year, and the facility
|
||||
starts in 2030. From 2031: 4 TWh gives 3.6, 8 TWh gives 7.6, 12 TWh in 2033 gives 11.6.
|
||||
"""
|
||||
inn = oppdiktet()
|
||||
dim = ks.dimensjoner(inn, Losning.C)
|
||||
assert _start(ks.lag_plan(inn, Losning.C, dim, N_anlegg=1)) == [2030]
|
||||
assert _start(ks.lag_plan(inn, Losning.C, dim, N_anlegg=1, ny_kraft_fra=2031)) == [2033]
|
||||
assert _start(ks.lag_plan(inn, Losning.C, dim, N_anlegg=1, ny_kraft_fra=2028)) == [2030]
|
||||
# the facility has the same portfolio; only the start year differs
|
||||
sen = _regn(inn, Losning.C, ny_kraft_fra=2031)
|
||||
assert sen.verk == _regn(inn, Losning.C).verk
|
||||
|
||||
|
||||
def test_ny_kraft_fra_2031_i_tf(oppdiktet: LagInndata) -> None:
|
||||
"""Hand-computed: no module in 2030; the grid balance is 150, then 270 (the cap).
|
||||
|
||||
2031: two modules (240 of 270). 2032: 180, one module. 2033: the seven that remain.
|
||||
On the main path the modules start in 2030, 2031 and 2032.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0)
|
||||
dim = ks.dimensjoner(inn, Losning.T_F)
|
||||
plan = ks.lag_plan(inn, Losning.T_F, dim, N_anlegg=1, ny_kraft_fra=2031)
|
||||
assert _start(plan) == [2031, 2031, 2032] + [2033] * 7
|
||||
assert _start(ks.lag_plan(inn, Losning.T_F, dim, N_anlegg=1)) == [2030, 2031, 2032] + [2033] * 7
|
||||
# with little power the pace binds: 0.5 TWh a year gives one module in 2032 and two in 2034
|
||||
knapp = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6)
|
||||
sen = ks.lag_plan(
|
||||
knapp, Losning.T_F, ks.dimensjoner(knapp, Losning.T_F), N_anlegg=1, ny_kraft_fra=2031
|
||||
)
|
||||
assert _start(sen)[:3] == [2032, 2034, 2036]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.A, Losning.B, Losning.B_MERKET, Losning.R])
|
||||
def test_ny_kraft_fra_gjelder_bare_c_og_t(oppdiktet: LagInndata, losning: Losning) -> None:
|
||||
inn = oppdiktet()
|
||||
with pytest.raises(ValueError, match="only C and T build new renewable power"):
|
||||
ks.lag_plan(inn, losning, ks.dimensjoner(inn, losning), N_anlegg=1, ny_kraft_fra=2031)
|
||||
|
||||
|
||||
# -------------------------------- next to S54: the water for the data centres' own use
|
||||
|
||||
|
||||
def test_vannet_for_datasentrenes_egen_bruk_i_tk(oppdiktet: LagInndata) -> None:
|
||||
"""T-K in 2036: 17 nuclear modules use 13.4028 TWh; two units produce 14.016 TWh.
|
||||
|
||||
S54 counts all of the production. Next to it stands the withdrawal with the sea water
|
||||
only for what the nuclear modules themselves use. The three renewable modules add
|
||||
nothing to it, and in 2031, before nuclear power, the two figures are the same.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6)
|
||||
res = _regn(inn, Losning.T_K, N_anlegg=2)
|
||||
j = 2036 - T_0
|
||||
E_IT = 20 * 8760.0 * 0.75 * 100.0
|
||||
assert miljo.kjernekraftproduksjon(res)[j] == pytest.approx(2 * E_ENHET)
|
||||
assert miljo.kjernekraft_til_egen_bruk(res)[j] == pytest.approx(17 * E_MODUL)
|
||||
vann = miljo.kjolevann(inn, res)
|
||||
assert vann.uttak[j] == pytest.approx(0.1 * E_IT + 150.0 * 2 * E_ENHET)
|
||||
assert vann.uttak_egen_bruk[j] == pytest.approx(0.1 * E_IT + 150.0 * 17 * E_MODUL)
|
||||
assert vann.uttak_egen_bruk[2031 - T_0] == vann.uttak[2031 - T_0]
|
||||
assert np.all(vann.uttak_egen_bruk <= vann.uttak)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", list(Losning))
|
||||
def test_egen_bruk_er_aldri_mer_enn_produksjonen(oppdiktet: LagInndata, losning: Losning) -> None:
|
||||
"""In A the two are the same; without nuclear power both are zero; on the grid less."""
|
||||
inn = oppdiktet(tau_nett=6.0)
|
||||
res = _regn(inn, losning, N_anlegg=2)
|
||||
E_N, egen = miljo.kjernekraftproduksjon(res), miljo.kjernekraft_til_egen_bruk(res)
|
||||
assert np.all(egen <= E_N)
|
||||
if losning is Losning.A:
|
||||
assert np.array_equal(egen, E_N)
|
||||
if losning in {Losning.C, Losning.R, Losning.T_F}:
|
||||
assert not E_N.any()
|
||||
assert not egen.any()
|
||||
if losning in {Losning.B, Losning.B_MERKET}:
|
||||
j = res.plan.anlegg[1].start - T_0
|
||||
assert egen[j] == pytest.approx(2 * 10 * E_MODUL)
|
||||
assert E_N[j] > egen[j]
|
||||
Loading…
Add table
Add a link
Reference in a new issue