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
|
|
@ -55,8 +55,8 @@ M6_MINST: Final = 0.25
|
|||
M6_UNDER: Final = 0.05
|
||||
"""M6: at least 25 % of the petroleum cash flow holds; under 5 % does not."""
|
||||
|
||||
DOMSLOSNINGER: Final = (Losning.A, Losning.B, Losning.C)
|
||||
"""The solutions the verdict for part I is about (pre-registration, clarification 3)."""
|
||||
DOMSLOSNINGER: Final = (Losning.A, Losning.B, Losning.C, Losning.T_F, Losning.T_K)
|
||||
"""The solutions the ladder, part I and M7 are about (pre-registration, clarifications 3 and 13)."""
|
||||
|
||||
MAAL_DEL_I: Final = ("M1", "M2", "M3", "M4", "M5", "M6")
|
||||
MAAL_SOM_FELLER: Final = ("M1", "M2", "M3", "M4", "M5")
|
||||
|
|
@ -229,21 +229,28 @@ def dom_m6(m6: Utfall) -> Dom:
|
|||
return dom_av_andeler(holder, under)
|
||||
|
||||
|
||||
def a_er_best(nnv_A: Utfall, nnv_B: Utfall, nnv_C: Utfall) -> list[bool]:
|
||||
"""M7 per draw: NNV_A > max(NNV_B, NNV_C), among the solutions that can be built.
|
||||
def a_er_best(nnv: Mapping[Losning, Utfall]) -> list[bool]:
|
||||
"""M7 per draw: A can be built and has a strictly higher net present value than the others.
|
||||
|
||||
A draw in which A cannot be built is not one where A is best.
|
||||
``nnv[losning]`` holds the net present value per draw, None where the path
|
||||
cannot be built. The others are B, C, T-F and T-K (chapter 17.1), each
|
||||
only in the draws where it can be built. A draw in which A cannot be built
|
||||
is not one where A is best. The reference run R and B' are not part of M7.
|
||||
"""
|
||||
best = []
|
||||
for a, b, c in zip(nnv_A, nnv_B, nnv_C, strict=True):
|
||||
andre = [x for x in (b, c) if x is not None]
|
||||
best.append(a is not None and all(a > x for x in andre))
|
||||
return best
|
||||
ukjent = [a for a in nnv if a not in DOMSLOSNINGER]
|
||||
if Losning.A not in nnv or ukjent:
|
||||
msg = f"M7 compares A with B, C, T-F and T-K; got {sorted(nnv)}"
|
||||
raise ValueError(msg)
|
||||
andre = [nnv[a] for a in DOMSLOSNINGER if a is not Losning.A and a in nnv]
|
||||
return [
|
||||
a is not None and all(a > x for x in rad if x is not None)
|
||||
for a, *rad in zip(nnv[Losning.A], *andre, strict=True)
|
||||
]
|
||||
|
||||
|
||||
def dom_m7(nnv_A: Utfall, nnv_B: Utfall, nnv_C: Utfall) -> Dom:
|
||||
def dom_m7(nnv: Mapping[Losning, Utfall]) -> Dom:
|
||||
"""M7: A has the highest net present value in at least half of the draws; under 20 % not."""
|
||||
return dom_av_andel_som_naar(lg.s37_andel(a_er_best(nnv_A, nnv_B, nnv_C)), holder_fra=ANDEL_M7)
|
||||
return dom_av_andel_som_naar(lg.s37_andel(a_er_best(nnv)), holder_fra=ANDEL_M7)
|
||||
|
||||
|
||||
# ------------------------------------------------- the step of the ladder
|
||||
|
|
@ -278,10 +285,12 @@ def trinn_for_dommene(m6: Mapping[int, Mapping[Losning, Utfall]]) -> Trinnvalg:
|
|||
|
||||
``m6[trinn][losning]`` holds M6 per draw in «normalisering» (None where the
|
||||
path cannot be built or has no year of stable operation). The 25 % step is
|
||||
the lowest step where at least 80 % of the draws reach 25 % for one of A, B
|
||||
and C; the 5 % step likewise. Without either, the verdicts are read on the
|
||||
highest step that can be built: the highest where one of A, B and C has a
|
||||
value in at least 80 % of the draws (chapter 16, clarification 57).
|
||||
the lowest step where at least 80 % of the draws reach 25 % for one of A,
|
||||
B, C, T-F and T-K; the 5 % step likewise. Without either, the verdicts are
|
||||
read on the highest step that can be built: the highest where one of the
|
||||
five has a value in at least 80 % of the draws (chapter 16, clarification
|
||||
57; chapter 17.1). A step is a number of facilities; in solution T it is
|
||||
ten times as many modules, the same MW IT.
|
||||
"""
|
||||
for minst, grunnlag in ((M6_MINST, Grunnlag.TRINN_25), (M6_UNDER, Grunnlag.TRINN_5)):
|
||||
trinn = _laveste_trinn(m6, minst)
|
||||
|
|
@ -311,8 +320,9 @@ def del_I(
|
|||
"""The verdict for part I (the programme), as far as it follows from the targets.
|
||||
|
||||
``dommer[losning]`` holds the verdicts for M1 to M6 on the step in ``valg``,
|
||||
``median_m1`` the median net present value. «Holder»: one of A, B and C has
|
||||
M1 to M6 all holding, on the 25 % step, with more than one facility.
|
||||
``median_m1`` the median net present value. «Holder»: one of A, B, C, T-F
|
||||
and T-K has M1 to M6 all holding, on the 25 % step, with more than one
|
||||
facility (step 1 is ten modules in T and counts as a single facility).
|
||||
«Holder ikke»: each of them has at least one of M1 to M5 not holding, or a
|
||||
negative median in M1. Otherwise it holds under conditions, and only when
|
||||
the conditions can be named within the range of the sources
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ nothing is computed with them here.
|
|||
from __future__ import annotations
|
||||
|
||||
import statistics
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import dataclass, field, replace
|
||||
from typing import TYPE_CHECKING, Final, cast
|
||||
|
||||
from tokenfabrikker import ligninger as lg
|
||||
|
|
@ -141,6 +141,18 @@ class Inndata:
|
|||
"""The scalar quantity with this id, in the units of the equations."""
|
||||
return self.v[navn]
|
||||
|
||||
def med(self, endringer: Mapping[str, float]) -> Inndata:
|
||||
"""The same set with the named scalar quantities replaced, for a sensitivity.
|
||||
|
||||
Modules of 50 and 200 MW (chapter 17.8) are ``inn.med({"P_m": 50.0})``.
|
||||
A name the set does not have is an error.
|
||||
"""
|
||||
ukjent = sorted(set(endringer) - set(self.v))
|
||||
if ukjent:
|
||||
msg = f"unknown quantities: {ukjent}"
|
||||
raise KeyError(msg)
|
||||
return replace(self, v={**self.v, **endringer})
|
||||
|
||||
def heltall(self, navn: str) -> int:
|
||||
"""A quantity that is a whole number (calendar years, L_H, n_0)."""
|
||||
verdi = self.v[navn]
|
||||
|
|
|
|||
|
|
@ -324,6 +324,8 @@ class Programresultat:
|
|||
NNV: net present value for Norway (S26).
|
||||
P_enhet: MW IT per facility: P_IT, and P_m per module in solution T.
|
||||
mu_d: the factor of S51 per vintage (exactly one on the main path).
|
||||
full_fortrengning: True in the sensitivity "full displacement in the first stage"
|
||||
(chapter 17.8): delta_V is one for the modules of the first stage.
|
||||
"""
|
||||
|
||||
losning: Losning
|
||||
|
|
@ -354,11 +356,16 @@ class Programresultat:
|
|||
NNV: float
|
||||
P_enhet: float
|
||||
mu_d: Etterspoersel
|
||||
full_fortrengning: bool = False
|
||||
|
||||
def paa_felles_kjernekraft(self, k: int) -> bool:
|
||||
"""True when facility or module ``k`` (0 is the first) runs on the programme's units."""
|
||||
return paa_felles_kjernekraft(self.losning, self.plan, k)
|
||||
|
||||
def delta_V(self, inn: Inndata, k: int) -> float:
|
||||
"""delta_V for facility or module ``k``: the share of its draw that displaces others."""
|
||||
return fortrengningsandel(inn, self.plan, k, full_i_forste_trinn=self.full_fortrengning)
|
||||
|
||||
def reaktoreffekt(self, k: int) -> float:
|
||||
"""P_G^N for facility or module ``k``, MW; zero for a renewable module in T."""
|
||||
return reaktoreffekt(self.dim, self.plan, k)
|
||||
|
|
@ -499,7 +506,9 @@ def _tidligste_aar(inn: Inndata, losning: Losning) -> int:
|
|||
return lg.forste_driftsaar(tidspunkt=tidspunkt)
|
||||
|
||||
|
||||
def _kraftrom(inn: Inndata, losning: Losning, dim: Dimensjonering) -> Callable[[int], float]:
|
||||
def _kraftrom(
|
||||
inn: Inndata, losning: Losning, dim: Dimensjonering, *, ny_kraft_fra: int | None = None
|
||||
) -> Callable[[int], float]:
|
||||
T_0 = inn.heltall("T0")
|
||||
if losning.kjernekraft and not losning.trinnvis:
|
||||
return ub.kraftrom_reaktor(n_reaktor=inn["n_reaktor"], P_G_N=dim.P_G_N, T_0=T_0)
|
||||
|
|
@ -511,6 +520,7 @@ def _kraftrom(inn: Inndata, losning: Losning, dim: Dimensjonering) -> Callable[[
|
|||
E_vind_rest=inn["E_vind_rest"],
|
||||
E_D=dim.E_D,
|
||||
T_0=T_0,
|
||||
forste_aar=ny_kraft_fra,
|
||||
)
|
||||
return ub.kraftrom_ubegrenset
|
||||
|
||||
|
|
@ -525,6 +535,7 @@ def lag_plan(
|
|||
brikker_fra_T0: bool = False,
|
||||
uten_forste_trinn: bool = False,
|
||||
uten_s49: bool = False,
|
||||
ny_kraft_fra: int | None = None,
|
||||
) -> Plan:
|
||||
"""The build-out of a path with ``N_anlegg`` facilities (S22, S33; chapter 17.1 for T).
|
||||
|
||||
|
|
@ -540,6 +551,11 @@ def lag_plan(
|
|||
start in the year new grid can be in place at the earliest ("C built in
|
||||
modules"), and ``uten_s49=True`` builds nuclear power in T-K whenever at
|
||||
least one module remains when nuclear power can come.
|
||||
|
||||
``ny_kraft_fra`` is a third sensitivity of chapter 17.8, for C and T: the
|
||||
first year new renewable power beyond the zero alternative can be in
|
||||
operation (2031 in the list). The pace is then counted from that year
|
||||
instead of from T_0 + 1.
|
||||
"""
|
||||
phi_X = inn["phi_X"] if eksportregel else 0.0
|
||||
stopp = ub.eksportstopp(u=inn.u_eksport, phi_X=phi_X, D_X=inn["D_X"])
|
||||
|
|
@ -555,7 +571,11 @@ def lag_plan(
|
|||
stopp=stopp,
|
||||
uten_forste_trinn=uten_forste_trinn,
|
||||
uten_s49=uten_s49,
|
||||
ny_kraft_fra=ny_kraft_fra,
|
||||
)
|
||||
if ny_kraft_fra is not None and losning is not Losning.C:
|
||||
msg = "only C and T build new renewable power, so only they can have it delayed"
|
||||
raise ValueError(msg)
|
||||
if uten_forste_trinn or uten_s49:
|
||||
msg = "the switches for the first stage and for S49 only apply to solution T"
|
||||
raise ValueError(msg)
|
||||
|
|
@ -572,7 +592,7 @@ def lag_plan(
|
|||
brikker_per_aar=lg.s22_grense_brikker(
|
||||
s_brikker=inn["s_brikker"], G_server=inn["G_server"], utskifting=0.0
|
||||
),
|
||||
kraftrom=_kraftrom(inn, losning, dim),
|
||||
kraftrom=_kraftrom(inn, losning, dim, ny_kraft_fra=ny_kraft_fra),
|
||||
stopp=stopp,
|
||||
)
|
||||
|
||||
|
|
@ -613,6 +633,7 @@ def _lag_plan_trinnvis(
|
|||
stopp: Sequence[bool],
|
||||
uten_forste_trinn: bool,
|
||||
uten_s49: bool,
|
||||
ny_kraft_fra: int | None,
|
||||
) -> ub.Trinnvisplan:
|
||||
"""Chapter 17.1: the build-out of a path in T-F or T-K, in modules."""
|
||||
T_0 = inn.heltall("T0")
|
||||
|
|
@ -655,7 +676,7 @@ def _lag_plan_trinnvis(
|
|||
brikker_per_aar=lg.s22_grense_brikker(
|
||||
s_brikker=inn["s_brikker"], G_server=inn["G_server"], utskifting=0.0
|
||||
),
|
||||
kraftrom=_kraftrom(inn, losning, dim),
|
||||
kraftrom=_kraftrom(inn, losning, dim, ny_kraft_fra=ny_kraft_fra),
|
||||
forste_aar_kraft=forste_aar_kraft(inn, dim),
|
||||
stopp=stopp,
|
||||
kjernekraft=fase,
|
||||
|
|
@ -773,6 +794,21 @@ def paa_felles_kjernekraft(losning: Losning, plan: Plan, k: int) -> bool:
|
|||
return losning is Losning.B
|
||||
|
||||
|
||||
def fortrengningsandel(inn: Inndata, plan: Plan, k: int, *, full_i_forste_trinn: bool) -> float:
|
||||
"""delta_V for facility or module ``k`` (0 is the first).
|
||||
|
||||
The drawn value for every facility and module on the main path. In the
|
||||
sensitivity "full displacement in the first stage" (chapter 17.8) it is
|
||||
one for the modules of solution T that started within the grid that
|
||||
exists, through all their operating years (clarification 80): they pay for
|
||||
no new grid, take nothing new from the power system, and the whole of
|
||||
their draw displaces someone else.
|
||||
"""
|
||||
if full_i_forste_trinn and isinstance(plan, ub.Trinnvisplan) and plan.i_forste_trinn(k):
|
||||
return 1.0
|
||||
return inn["delta_V"]
|
||||
|
||||
|
||||
def enheter_i_B(
|
||||
inn: Inndata, dim: Dimensjonering, plan: Plan, *, losning: Losning = Losning.B
|
||||
) -> tuple[Enhetsgruppe, ...]:
|
||||
|
|
@ -969,6 +1005,7 @@ class _Program:
|
|||
mu_d: Etterspoersel
|
||||
T_0: int
|
||||
T_s: int
|
||||
full_fortrengning: bool = False
|
||||
|
||||
@property
|
||||
def antall_aar(self) -> int:
|
||||
|
|
@ -987,6 +1024,28 @@ class _Program:
|
|||
"""P_G^N for facility ``k``, MW (clarification 14); zero for a renewable module in T."""
|
||||
return reaktoreffekt(self.dim, self.plan, k)
|
||||
|
||||
def delta_V(self, k: int) -> float:
|
||||
"""delta_V for facility ``k``; one for a first-stage module with full displacement."""
|
||||
return fortrengningsandel(
|
||||
self.inn, self.plan, k, full_i_forste_trinn=self.full_fortrengning
|
||||
)
|
||||
|
||||
def med_last(self, t: int) -> tuple[int, int]:
|
||||
"""The facilities with a vintage in operation in year ``t``, in two groups.
|
||||
|
||||
First those with the drawn delta_V, then those that displace others
|
||||
with their whole draw (none on the main path). The second group takes
|
||||
nothing new from the power system: (1 - delta_V) is exactly zero.
|
||||
"""
|
||||
if not self.full_fortrengning:
|
||||
return self.plan.antall_med_last(t), 0
|
||||
fullt = sum(
|
||||
1
|
||||
for k in range(len(self.plan.anlegg))
|
||||
if self.plan.har_last(k, t) and self.delta_V(k) == 1.0
|
||||
)
|
||||
return self.plan.antall_med_last(t) - fullt, fullt
|
||||
|
||||
def forste_kjernekraftaar(self) -> int | None:
|
||||
"""The year S41 counts to, or None when the programme builds no nuclear power.
|
||||
|
||||
|
|
@ -1097,7 +1156,8 @@ def _kraftsystem_per_aar(p: _Program) -> tuple[Kraftaar, ...]:
|
|||
rader = []
|
||||
for t in range(p.T_0, p.T_s + 1):
|
||||
paa_nett = [v for v in p.verk_i_drift(t) if v.selges]
|
||||
antall = p.plan.antall_med_last(t) if p.losning.paa_nett else 0
|
||||
# modules that displace others with their whole draw take nothing new (chapter 17.8)
|
||||
antall = p.med_last(t)[0] if p.losning.paa_nett else 0
|
||||
rader.append(
|
||||
kraftsystem.kraftaar(
|
||||
p.inn,
|
||||
|
|
@ -1289,7 +1349,7 @@ def _nett_buffer_og_forsyning(
|
|||
)
|
||||
|
||||
if p.losning.paa_nett:
|
||||
uttak = (1.0 - inn["delta_V"]) * inn["PUE"] * p.P_enhet
|
||||
uttak = (1.0 - p.delta_V(k)) * inn["PUE"] * p.P_enhet
|
||||
betal(I_nett, NETT, inn["I_nett"] * (uttak + p.reaktoreffekt(k)), L_nett)
|
||||
return I_nett, buffer, I_g
|
||||
P_buf = lg.s36_buffer(delta_L=inn["delta_L"], PUE=inn["PUE"], P_IT=inn["P_IT"])
|
||||
|
|
@ -1408,7 +1468,8 @@ def _ovrige_virkninger(
|
|||
j = t - p.T_0
|
||||
if p.losning.paa_nett:
|
||||
Delta_W[j] = kraftaar[j].velferd(S_0=inn["S0"])
|
||||
V[j] = inn["delta_V"] * p.plan.antall_med_last(t) * p.dim.E_D * inn["t_el"]
|
||||
vanlig, fullt = p.med_last(t)
|
||||
V[j] = (inn["delta_V"] * vanlig + fullt) * p.dim.E_D * inn["t_el"]
|
||||
for a in anlegg:
|
||||
for t in a.bygg_i_drift:
|
||||
utslipp[t - p.T_0] += inn.karbonpris_i(t) * inn["s_B_NO"] * inn["u_B"] * p.P_enhet
|
||||
|
|
@ -1495,6 +1556,7 @@ def regn_program(
|
|||
dim: Dimensjonering | None = None,
|
||||
tilleggsregel: bool = True,
|
||||
bortfall: Callable[[int], float] | None = None,
|
||||
full_fortrengning_i_forste_trinn: bool = False,
|
||||
) -> Programresultat:
|
||||
"""S26 for one path: the yearly cash flows and the net present value for Norway.
|
||||
|
||||
|
|
@ -1508,6 +1570,11 @@ def regn_program(
|
|||
away for the vintage that enters operation in t_v (``bortfall_i_scenario``
|
||||
or ``fast_bortfall``). Left out, nothing falls away. The build-out and the
|
||||
costs are the same with and without it.
|
||||
|
||||
``full_fortrengning_i_forste_trinn=True`` is a sensitivity of chapter 17.8
|
||||
for solution T: delta_V is one for the modules that started within the
|
||||
grid that exists, in S23, S24, the grid investment and V, through all
|
||||
their operating years (clarification 80).
|
||||
"""
|
||||
if losning.trinnvis != isinstance(plan, ub.Trinnvisplan):
|
||||
msg = "solution T, and only solution T, takes a plan built in modules"
|
||||
|
|
@ -1515,6 +1582,9 @@ def regn_program(
|
|||
if not plan.gjennomforbar:
|
||||
msg = "the path cannot be built within the final year, so it has no net present value"
|
||||
raise ValueError(msg)
|
||||
if full_fortrengning_i_forste_trinn and not losning.trinnvis:
|
||||
msg = "only solution T has a first stage, so only it has the sensitivity for it"
|
||||
raise ValueError(msg)
|
||||
dim = dimensjoner(inn, losning) if dim is None else dim
|
||||
p = _Program(
|
||||
inn=inn,
|
||||
|
|
@ -1527,6 +1597,7 @@ def regn_program(
|
|||
mu_d=Etterspoersel(eps_d=inn["eps_d"], d=bortfall),
|
||||
T_0=plan.T_0,
|
||||
T_s=plan.T_s,
|
||||
full_fortrengning=full_fortrengning_i_forste_trinn,
|
||||
)
|
||||
kraftaar = _kraftsystem_per_aar(p)
|
||||
pris = np.array([rad.pris for rad in kraftaar], dtype=np.float64)
|
||||
|
|
@ -1585,4 +1656,5 @@ def regn_program(
|
|||
),
|
||||
P_enhet=p.P_enhet,
|
||||
mu_d=p.mu_d,
|
||||
full_fortrengning=p.full_fortrengning,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import numpy as np
|
|||
from tokenfabrikker import kontantstrom as ks
|
||||
from tokenfabrikker import ligninger as lg
|
||||
from tokenfabrikker.dommer import Dom
|
||||
from tokenfabrikker.utbygging import Losning
|
||||
from tokenfabrikker.utbygging import Kraft, Losning, krafttype
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
|
@ -105,6 +105,27 @@ def kjernekraftproduksjon(res: Programresultat) -> Tabell:
|
|||
return E_N
|
||||
|
||||
|
||||
def kjernekraft_til_egen_bruk(res: Programresultat) -> Tabell:
|
||||
"""The part of E_N the data centres themselves use, MWh per year (index t - T_0).
|
||||
|
||||
Shown next to S54 (clarification 88): E_D for each facility or module on
|
||||
nuclear power with a vintage in operation, and never more than the units
|
||||
produce that year. In A it is all of E_N. On the grid the rest of E_N is
|
||||
sold to others.
|
||||
"""
|
||||
plan = res.plan
|
||||
kjernekraft = {Kraft.EGET_KJERNEKRAFTVERK, Kraft.KJERNEKRAFT_PAA_NETTET}
|
||||
paa_kjernekraft = [
|
||||
krafttype(res.losning, plan, k) in kjernekraft for k in range(len(plan.anlegg))
|
||||
]
|
||||
E_N = kjernekraftproduksjon(res)
|
||||
egen = np.zeros(len(res.aar), dtype=np.float64)
|
||||
for j, t in enumerate(res.aar):
|
||||
antall = sum(1 for k, paa in enumerate(paa_kjernekraft) if paa and plan.har_last(k, t))
|
||||
egen[j] = min(float(E_N[j]), antall * res.dim.E_D)
|
||||
return egen
|
||||
|
||||
|
||||
def brukt_brensel(inn: Inndata, res: Programresultat) -> Tabell:
|
||||
"""Chapter 10: spent fuel per year, eta_N E_N, tonnes of uranium (reported, not judged)."""
|
||||
return inn["eta_N"] * kjernekraftproduksjon(res)
|
||||
|
|
@ -151,13 +172,18 @@ def it_energi(inn: Inndata, res: Programresultat) -> Tabell:
|
|||
return np.array([res.plan.antall_med_last(t) * per_enhet for t in res.aar], dtype=np.float64)
|
||||
|
||||
|
||||
def vannmengde(inn: Inndata, res: Programresultat, *, w_D: float, w_N: float) -> Tabell:
|
||||
def vannmengde(
|
||||
inn: Inndata, res: Programresultat, *, w_D: float, w_N: float, bare_egen_bruk: bool = False
|
||||
) -> Tabell:
|
||||
"""S54 with the factors given: w_D E_IT + w_N E_N per year, cubic metres.
|
||||
|
||||
For the figures shown next to the main ones (cooling towers, a data centre
|
||||
cooled with sea water) the caller passes those factors.
|
||||
``bare_egen_bruk=True`` counts only the part of E_N the data centres
|
||||
themselves use (clarification 88), also shown next to the main figure.
|
||||
"""
|
||||
E_IT, E_N = it_energi(inn, res), kjernekraftproduksjon(res)
|
||||
E_IT = it_energi(inn, res)
|
||||
E_N = kjernekraft_til_egen_bruk(res) if bare_egen_bruk else kjernekraftproduksjon(res)
|
||||
return np.array(
|
||||
[
|
||||
lg.s54_kjolevann(w_D=w_D, w_N=w_N, E_IT=e_it, E_N=e_n)
|
||||
|
|
@ -173,12 +199,16 @@ class Kjolevann:
|
|||
|
||||
Attributes:
|
||||
uttak: withdrawal: the data centres' water and the sea water through the nuclear units.
|
||||
uttak_egen_bruk: the same with the sea water only for the part of the nuclear
|
||||
production the data centres themselves use (clarification 88); shown next to
|
||||
``uttak``, which also holds the water for power sold to others.
|
||||
forbruk_kjernekraft: fresh water consumed by the nuclear units.
|
||||
forbruk_hoyst: consumption when the data centres consume all they withdraw. No Nordic
|
||||
source gives their consumption, so it is reported as at most this.
|
||||
"""
|
||||
|
||||
uttak: Tabell
|
||||
uttak_egen_bruk: Tabell
|
||||
forbruk_kjernekraft: Tabell
|
||||
forbruk_hoyst: Tabell
|
||||
|
||||
|
|
@ -187,6 +217,9 @@ def kjolevann(inn: Inndata, res: Programresultat) -> Kjolevann:
|
|||
"""S54 with the main figures: sea water in once-through cooling for nuclear power."""
|
||||
return Kjolevann(
|
||||
uttak=vannmengde(inn, res, w_D=inn["w_D_uttak"], w_N=inn["w_N_uttak"]),
|
||||
uttak_egen_bruk=vannmengde(
|
||||
inn, res, w_D=inn["w_D_uttak"], w_N=inn["w_N_uttak"], bare_egen_bruk=True
|
||||
),
|
||||
forbruk_kjernekraft=vannmengde(inn, res, w_D=0.0, w_N=inn["w_N_forbruk"]),
|
||||
forbruk_hoyst=vannmengde(inn, res, w_D=inn["w_D_uttak"], w_N=inn["w_N_forbruk"]),
|
||||
)
|
||||
|
|
@ -242,8 +275,10 @@ def m5_utslipp(losning: Losning, kilder: Sequence[Kildeverdier]) -> Dom:
|
|||
«Holder» when nuclear power is not above the lower of onshore wind and
|
||||
hydropower in any source. «Holder ikke» (clearly broken) when its central
|
||||
value in at least one source is above the highest value that source gives
|
||||
for onshore wind. Everything in between holds under conditions. C and R
|
||||
meet (i) by definition.
|
||||
for onshore wind. Everything in between holds under conditions. C, R and
|
||||
T-F meet (i) by definition. T-K is judged as nuclear power on every step
|
||||
of the ladder, also where S49 is seldom met: M5 is decided without draws
|
||||
and cannot follow the single draw (chapter 17.1).
|
||||
"""
|
||||
if not losning.kjernekraft:
|
||||
return Dom.HOLDER
|
||||
|
|
@ -263,7 +298,8 @@ def m5_areal(losning: Losning, *, kjernekraft: float, vind_direkte: float, vind_
|
|||
«Holder» when nuclear power does not use more than the direct area of
|
||||
onshore wind, the lower of the two figures for wind. «Holder ikke» (clearly
|
||||
broken) when it uses more than the whole planning area of wind, the
|
||||
higher. In between it holds under conditions. C and R hold by definition.
|
||||
higher. In between it holds under conditions. C, R and T-F hold by
|
||||
definition; T-K is judged as nuclear power (chapter 17.1).
|
||||
"""
|
||||
if not losning.kjernekraft or kjernekraft <= vind_direkte:
|
||||
return Dom.HOLDER
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ def _kraftkostnad_per_aar(
|
|||
H_a = [
|
||||
lg.s11_nettkostnad(
|
||||
I_nett=inn["I_nett"],
|
||||
delta_V=inn["delta_V"],
|
||||
delta_V=res.delta_V(inn, k),
|
||||
PUE=inn["PUE"],
|
||||
P_IT=res.P_enhet,
|
||||
P_G_N=res.reaktoreffekt(k),
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ def _faste_aarskostnader(inn: Inndata, res: Programresultat, r: Renter, k: int)
|
|||
if res.losning.paa_nett:
|
||||
return lg.s11_nettkostnad(
|
||||
I_nett=inn["I_nett"],
|
||||
delta_V=inn["delta_V"],
|
||||
delta_V=res.delta_V(inn, k),
|
||||
PUE=inn["PUE"],
|
||||
P_IT=res.P_enhet,
|
||||
P_G_N=res.reaktoreffekt(k),
|
||||
|
|
|
|||
|
|
@ -269,16 +269,24 @@ def kraftrom_fornybar(
|
|||
E_vind_rest: float,
|
||||
E_D: float,
|
||||
T_0: int,
|
||||
forste_aar: int | None = None,
|
||||
) -> Callable[[int], float]:
|
||||
"""S22, second term accumulated from T_0 (C): facilities the renewable power has room for.
|
||||
|
||||
The pace ``g_fornybar`` (MWh of normal-year production per year) is filled
|
||||
in the fixed order of S39, and what counts is the production in a dry year.
|
||||
|
||||
``forste_aar`` is the first year new renewable power can be in operation,
|
||||
T_0 + 1 when it is left out (clarification 24). A later year is the
|
||||
sensitivity of chapter 17.8: nothing can be built by the years before it,
|
||||
and the pace is counted from it, so that one year's worth can be in
|
||||
operation in that year. A year before T_0 + 1 changes nothing.
|
||||
"""
|
||||
fra = T_0 if forste_aar is None else max(T_0, forste_aar - 1)
|
||||
|
||||
def rom(t: int) -> float:
|
||||
torr = lg.s39_torraarsenergi_av_takt(
|
||||
E_normal=g_fornybar * (t - T_0),
|
||||
E_normal=g_fornybar * max(0, t - fra),
|
||||
w_tort_vann=w_tort_vann,
|
||||
E_vann_rest=E_vann_rest,
|
||||
E_vind_rest=E_vind_rest,
|
||||
|
|
|
|||
|
|
@ -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