feat(nivaaisert): take solution T and the loss of demand through the levelised cost, ownership and scale
The power cost per module (S11): a renewable module with its own portfolio and grid connection, as a facility in C; the nuclear modules of T-K on the programme's units, as the facilities in B, with only the nuclear modules that use power in the denominator. Tariff, building, IT hardware and residual value per module with P_m. The units' cash flow is shared among the nuclear modules operated that year, never on the renewable modules. The factor of S51 stands per vintage in S19, S27 and S42 and in the disconnection arm a business pays; S31 gets it through the revenue and F_a of the cash flow. Without a loss, and for A, B, B', C and R, every figure of chapters 7 to 9 is unchanged to the last digit (282 made-up paths, 151 525 lines of figures compared byte for byte). The technologies of a facility are now kept in the plants' own order. As a set of names their order differed from run to run, and with it the last digit of every sum over them in C. The refusal of T and of a loss of demand (krev_uten_tillegget) is removed. Run on made-up numbers only; no result for the hypothesis has been computed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
e0db6ab4b7
commit
b58e79ee82
6 changed files with 650 additions and 82 deletions
|
|
@ -16,7 +16,7 @@ from typing import TYPE_CHECKING
|
|||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tokenfabrikker import dommer, eierskap, miljo, nivaaisert, skala
|
||||
from tokenfabrikker import dommer, miljo
|
||||
from tokenfabrikker import kontantstrom as ks
|
||||
from tokenfabrikker import ligninger as lg
|
||||
from tokenfabrikker import utbygging as ub
|
||||
|
|
@ -353,19 +353,12 @@ def test_bortfallet_staar_i_utkoblingsarmen(oppdiktet: LagInndata) -> None:
|
|||
assert med.F_a[j] == pytest.approx(0.8 * uten.F_a[j])
|
||||
|
||||
|
||||
def test_kapitlene_etter_kontantstrommen_avviser_det_de_ikke_kan_ennaa(
|
||||
oppdiktet: LagInndata,
|
||||
) -> None:
|
||||
inn = oppdiktet(tau_nett=6.0)
|
||||
t = _regn(inn, Losning.T_F)
|
||||
med = _regn(inn, Losning.C, bortfall=ks.fast_bortfall(0.2))
|
||||
for res, melding in ((t, "solution T is not taken"), (med, "loss of demand")):
|
||||
with pytest.raises(NotImplementedError, match=melding):
|
||||
nivaaisert.kraftkostnad(inn, res)
|
||||
with pytest.raises(NotImplementedError, match=melding):
|
||||
eierskap.bedriftsstrom(inn, res)
|
||||
with pytest.raises(NotImplementedError, match=melding):
|
||||
skala.skala(inn, res)
|
||||
def test_teknologiene_staar_i_kraftverkenes_rekkefolge(oppdiktet: LagInndata) -> None:
|
||||
"""Not in the order of a set of names: that differs from run to run and moves the last digit."""
|
||||
inn = oppdiktet()
|
||||
res = _regn(inn, Losning.C)
|
||||
assert [list(a.salg) for a in res.anlegg] == [[v.teknologi for v in res.verk[0]]]
|
||||
assert len(res.anlegg[0].salg) == 3
|
||||
|
||||
|
||||
# ------------------------------------------------- S32, S53 and S54 over a programme
|
||||
|
|
|
|||
516
tests/test_trinnvis_nivaaisert.py
Normal file
516
tests/test_trinnvis_nivaaisert.py
Normal file
|
|
@ -0,0 +1,516 @@
|
|||
"""Solution T and the loss of demand through the levelised cost, ownership and scale.
|
||||
|
||||
Made-up round numbers only; nothing here says anything about the hypothesis. The path used
|
||||
most is the one of ``test_trinnvis_kontantstrom.py``: T-K with two facilities' worth of
|
||||
modules, new grid in 2033 and 0.5 TWh of new renewable power a year. Three renewable modules
|
||||
start in 2030, 2031 and 2033, ten nuclear modules in 2035 and seven in 2036. Two units of
|
||||
1 000 MW run from 2035 to 2054, and a third from 2055 for the seven modules still operated.
|
||||
A module uses 8760 * 0.75 * 1.2 * 100 = 788 400 MWh a year. The first two modules have
|
||||
hydropower only: 788 400 / 0.8 = 985 500 MWh in a normal year.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import math
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tokenfabrikker import eierskap as ei
|
||||
from tokenfabrikker import kontantstrom as ks
|
||||
from tokenfabrikker import ligninger as lg
|
||||
from tokenfabrikker import nivaaisert as nv
|
||||
from tokenfabrikker import skala
|
||||
from tokenfabrikker.kontantstrom import Knapphet
|
||||
from tokenfabrikker.utbygging import 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: 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."""
|
||||
|
||||
ALLE = tuple(Losning)
|
||||
"""The five solutions of chapters 0 to 16 and the two versions of solution T."""
|
||||
|
||||
|
||||
def _crf(rho: float, levetid: float) -> float:
|
||||
return float(rho / (1.0 - (1.0 + rho) ** -levetid))
|
||||
|
||||
|
||||
def _sff(rho: float, levetid: float) -> float:
|
||||
return float(rho / ((1.0 + rho) ** levetid - 1.0))
|
||||
|
||||
|
||||
def _byggetid(rho: float, tau: float) -> float:
|
||||
"""S3: the factor for interest during construction."""
|
||||
return float(((1.0 + rho) ** tau - 1.0) / (tau * math.log1p(rho)))
|
||||
|
||||
|
||||
def _lcoe_enhet() -> float:
|
||||
"""S5 for a made-up unit of 1 000 MW on the grid, with the accident cost, kr/MWh."""
|
||||
aarlig = (
|
||||
100e6 * 1000.0 * _byggetid(0.06, 4.0) * _crf(0.06, 20)
|
||||
+ 1e6 * 1000.0
|
||||
+ 5e6 * 1000.0 * _sff(0.06, 20)
|
||||
)
|
||||
ulykke = 1e-5 * (1e12 - 8e9) / E_ENHET
|
||||
return aarlig / E_ENHET + 50.0 + 70.0 + 30.0 + ulykke
|
||||
|
||||
|
||||
LCOE_VANN = 20e6 * _crf(0.06, 40) / 3000.0 + 70.0
|
||||
"""Made-up hydropower: interest during construction is in the investment figure already."""
|
||||
|
||||
LCOE_VIND = 14e6 * _byggetid(0.06, 2.0) * _crf(0.06, 30) / 3000.0 + 120.0
|
||||
|
||||
NETT_FORNYBAR = 5e6 * 0.5 * 1.2 * 100.0 * _crf(0.06, 40)
|
||||
"""H_a for a renewable module: half of the draw of 120 MW displaces private users."""
|
||||
|
||||
NETT_KJERNEKRAFT = 5e6 * (0.5 * 1.2 * 100.0 + 0.75 * 1.2 * 100.0 / 0.8) * _crf(0.06, 40)
|
||||
"""H_a for a nuclear module: also the reactor capacity it needs, 112.5 MW."""
|
||||
|
||||
TARIFF = 0.3e6 * 1.2 * 100.0
|
||||
"""The grid tariff of one module, on its largest draw of 120 MW, kr per year."""
|
||||
|
||||
|
||||
def _regn(
|
||||
inn: Inndata,
|
||||
losning: Losning,
|
||||
*,
|
||||
N_anlegg: int = 1,
|
||||
knapphet: Knapphet = Knapphet.NORMALISERING,
|
||||
bortfall: Callable[[int], float] | None = None,
|
||||
) -> ks.Programresultat:
|
||||
dim = ks.dimensjoner(inn, losning)
|
||||
plan = ks.lag_plan(inn, losning, dim, N_anlegg=N_anlegg)
|
||||
return ks.regn_program(inn, losning, plan, knapphet, dim=dim, bortfall=bortfall)
|
||||
|
||||
|
||||
def _tk(oppdiktet: LagInndata, *, t_nett: float = 0.3e6) -> tuple[Inndata, ks.Programresultat]:
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6, L_N=20.0, t_nett=t_nett)
|
||||
return inn, _regn(inn, Losning.T_K, N_anlegg=2)
|
||||
|
||||
|
||||
def _tall(x: object) -> list[float | None]:
|
||||
"""Every number in a result, in order, so two results can be compared to the last digit."""
|
||||
if x is None or isinstance(x, (bool, int, float)):
|
||||
return [None if x is None else float(x)]
|
||||
if isinstance(x, np.ndarray):
|
||||
return [float(v) for v in x.ravel()]
|
||||
if isinstance(x, (tuple, list)):
|
||||
return [v for del_ in x for v in _tall(del_)]
|
||||
if dataclasses.is_dataclass(x) and not isinstance(x, type):
|
||||
return [
|
||||
v
|
||||
for felt in dataclasses.fields(x)
|
||||
if felt.name != "eierform"
|
||||
for v in _tall(getattr(x, felt.name))
|
||||
]
|
||||
msg = f"cannot compare {type(x)}"
|
||||
raise TypeError(msg)
|
||||
|
||||
|
||||
def _alt(inn: Inndata, res: ks.Programresultat) -> list[float | None]:
|
||||
"""Every figure of chapters 7 to 9 for one path."""
|
||||
ut = _tall(nv.kraftkostnad(inn, res)) + _tall(nv.kraftkostnad(inn, res, bedrift=True))
|
||||
ut += _tall(skala.skala(inn, res))
|
||||
for tilleggsregel in (False, True):
|
||||
strom = ei.bedriftsstrom(inn, res, tilleggsregel=tilleggsregel)
|
||||
ut += _tall(strom)
|
||||
for form in inn.eierformer.values():
|
||||
ut += _tall(ei.eierresultat(inn, strom, form))
|
||||
ut.append(ei.naaverdi_etter_skatt(inn, strom, form))
|
||||
ut.append(ei.lcoc_med_kapitalkostnad(inn, res, ei.krav_for_skatt(inn, form)))
|
||||
return ut
|
||||
|
||||
|
||||
def _like(a: list[float | None], b: list[float | None]) -> bool:
|
||||
"""The same numbers to the last digit (NaN where the other has NaN)."""
|
||||
return len(a) == len(b) and all(
|
||||
x == y or (x is not None and y is not None and math.isnan(x) and math.isnan(y))
|
||||
for x, y in zip(a, b, strict=True)
|
||||
)
|
||||
|
||||
|
||||
# ------------------------------------------------------- the power cost per module (S11)
|
||||
|
||||
|
||||
def test_banen_er_den_haandregnede(oppdiktet: LagInndata) -> None:
|
||||
inn, res = _tk(oppdiktet)
|
||||
assert [a.start for a in res.plan.anlegg] == [2030, 2031, 2033] + [2035] * 10 + [2036] * 7
|
||||
assert [(f.gruppe.start, f.gruppe.numre) for f in res.felles] == [(2035, (1, 2)), (2055, (3,))]
|
||||
assert res.varsigma == {"kjernekraft": 1.0, "vann": 1.0, "vind": 1.0}
|
||||
assert {v.teknologi: v.energi for v in res.verk[0]} == pytest.approx({"vann": 985_500.0})
|
||||
assert {v.teknologi: v.energi for v in res.verk[2]} == pytest.approx(
|
||||
{"vann": 29_000.0, "vind": 765_200.0}
|
||||
)
|
||||
assert res.verk[3] == ()
|
||||
assert res.plan.antall_med_last(2040) == 20
|
||||
assert float(res.F_a[2040 - 2027]) == 0.0
|
||||
assert inn["P_m"] == 100.0
|
||||
|
||||
|
||||
def test_fornybarmodulen_har_sin_egen_portefolje_og_sitt_eget_nett(oppdiktet: LagInndata) -> None:
|
||||
"""S11 per renewable module, as a facility in C, with P_m in the grid connection.
|
||||
|
||||
Module 1 has 985 500 MWh of hydropower for the 788 400 it uses; module 3 has 29 000 MWh
|
||||
of hydropower and 765 200 of wind.
|
||||
"""
|
||||
inn, res = _tk(oppdiktet)
|
||||
j = 2040 - 2027
|
||||
pris = res.kraftaar[j].pris
|
||||
kost = nv.kraftkostnad(inn, res)
|
||||
modul_1 = 1.05 * pris + (LCOE_VANN - 1.2 * pris) * 1.25 + NETT_FORNYBAR / E_MODUL
|
||||
assert kost.c_a[0, j] == pytest.approx(modul_1)
|
||||
assert kost.c_a[1, j] == pytest.approx(modul_1)
|
||||
netto = 29_000.0 * (LCOE_VANN - 1.2 * pris) + 765_200.0 * (LCOE_VIND - 0.9 * pris)
|
||||
assert kost.c_a[2, j] == pytest.approx(1.05 * pris + (netto + NETT_FORNYBAR) / E_MODUL)
|
||||
|
||||
|
||||
def test_kjernekraftmodulene_deler_programmets_enheter(oppdiktet: LagInndata) -> None:
|
||||
"""S11 for the nuclear modules together, as the facilities in B (clarifications 2 and 42).
|
||||
|
||||
In 2040 two units produce for seventeen nuclear modules; the three renewable modules are
|
||||
not in the denominator. In 2055 one new unit produces for the seven modules still
|
||||
operated, and capacity is missing: its cost is shared among the seven.
|
||||
"""
|
||||
inn, res = _tk(oppdiktet)
|
||||
kost = nv.kraftkostnad(inn, res)
|
||||
j = 2040 - 2027
|
||||
pris = res.kraftaar[j].pris
|
||||
netto = (_lcoe_enhet() - pris) * 2.0 * E_ENHET / (17.0 * E_MODUL)
|
||||
assert kost.c_a[3:, j] == pytest.approx(1.05 * pris + netto + NETT_KJERNEKRAFT / E_MODUL)
|
||||
|
||||
j = 2055 - 2027
|
||||
assert res.plan.antall_med_last(2055) == 7
|
||||
assert float(res.F_a[j]) > 0.0
|
||||
pris = res.kraftaar[j].pris
|
||||
netto = (_lcoe_enhet() - pris) * E_ENHET / (7.0 * E_MODUL)
|
||||
faste = (NETT_KJERNEKRAFT + float(res.F_a[j]) / 7.0) / E_MODUL
|
||||
assert kost.c_a[13:, j] == pytest.approx(1.05 * pris + netto + faste)
|
||||
assert np.all(np.isnan(kost.c_a[:13, j]))
|
||||
|
||||
|
||||
def test_en_bedrift_betaler_tariff_per_modul(oppdiktet: LagInndata) -> None:
|
||||
"""Chapter 7 for modules: the tariff on PUE P_m, the electricity tax, no grid investment."""
|
||||
inn, res = _tk(oppdiktet)
|
||||
j = 2040 - 2027
|
||||
pris = res.kraftaar[j].pris
|
||||
kost = nv.kraftkostnad(inn, res, bedrift=True)
|
||||
assert kost.c_a[0, j] == pytest.approx(
|
||||
pris + 70.0 + (LCOE_VANN - 1.2 * pris) * 1.25 + TARIFF / E_MODUL
|
||||
)
|
||||
netto = (_lcoe_enhet() - pris) * 2.0 * E_ENHET / (17.0 * E_MODUL)
|
||||
assert kost.c_a[3:, j] == pytest.approx(pris + 70.0 + netto + TARIFF / E_MODUL)
|
||||
|
||||
|
||||
def test_modulenes_aarganger_og_s42(oppdiktet: LagInndata) -> None:
|
||||
"""Every vintage of every module has one term in S42, per MW IT (clarification 44)."""
|
||||
inn, res = _tk(oppdiktet)
|
||||
kost = nv.kraftkostnad(inn, res, bedrift=True)
|
||||
assert len(kost.aarganger) == sum(len(a.aarganger) for a in res.plan.anlegg)
|
||||
assert {a.anlegg for a in kost.aarganger} == set(range(20))
|
||||
ventet = math.fsum(1.08 ** -(a.t_v - 2027) * (a.inntekt - a.LCOC) for a in kost.aarganger)
|
||||
assert kost.S42 == pytest.approx(ventet)
|
||||
forste = next(a for a in kost.aarganger if a.anlegg == 0 and a.t_v == 2030)
|
||||
vekter = [1.08 ** -(t - 2030) for t in forste.aar]
|
||||
c_a = math.fsum(
|
||||
w * float(kost.c_a[0, t - 2027]) for w, t in zip(vekter, forste.aar, strict=True)
|
||||
)
|
||||
assert forste.c_a == pytest.approx(c_a / math.fsum(vekter))
|
||||
|
||||
|
||||
def test_tk_uten_kjernekraft_er_tf_i_alle_tall(oppdiktet: LagInndata) -> None:
|
||||
"""With one facility's worth of modules S49 is not met: seven modules need 630 of 800 MW."""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6)
|
||||
tk = _regn(inn, Losning.T_K)
|
||||
assert tk.felles == ()
|
||||
assert _like(_alt(inn, tk), _alt(inn, _regn(inn, Losning.T_F)))
|
||||
|
||||
|
||||
# ------------------------------------------------------------ the loss of demand (S51)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", ALLE)
|
||||
def test_uten_bortfall_er_faktoren_noyaktig_en(oppdiktet: LagInndata, losning: Losning) -> None:
|
||||
"""A loss of zero gives every figure of chapters 7 to 9 to the last digit."""
|
||||
inn = oppdiktet(tau_nett=6.0, u_eksport=None)
|
||||
uten = _regn(inn, losning, N_anlegg=2)
|
||||
med = _regn(inn, losning, N_anlegg=2, bortfall=ks.fast_bortfall(0.0))
|
||||
assert _like(_alt(inn, uten), _alt(inn, med))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", ALLE)
|
||||
def test_faktoren_staar_i_inntekten_per_aargang_og_i_s19(
|
||||
oppdiktet: LagInndata, losning: Losning
|
||||
) -> None:
|
||||
"""The revenue is mu mu_d(t_v) Gamma y(t_v) per vintage, and S19 is still an identity."""
|
||||
inn = oppdiktet(tau_nett=6.0, eps_d=2.0, u_eksport=None)
|
||||
bortfall = ks.bortfall_i_scenario(inn, "hoyt")
|
||||
res = _regn(inn, losning, N_anlegg=2, knapphet=Knapphet.VARER, bortfall=bortfall)
|
||||
kost = nv.kraftkostnad(inn, res)
|
||||
assert {res.mu_d(a.t_v) for a in kost.aarganger} != {1.0}
|
||||
for a in kost.aarganger:
|
||||
mu_d = max(0.0, 1.0 - 2.0 * bortfall(a.t_v))
|
||||
assert a.inntekt == pytest.approx(mu_d * res.dim.Gamma * res.y(a.t_v))
|
||||
assert a.margin is not None
|
||||
assert a.margin.sum == pytest.approx(a.overskudd, rel=1e-9, abs=1e-3)
|
||||
|
||||
|
||||
def test_bortfallet_i_s42_uten_effektkostnad(oppdiktet: LagInndata) -> None:
|
||||
"""A: no capacity cost, so the cost is the same and only the revenue falls.
|
||||
|
||||
S42 falls by d times the weighted sum of mu Gamma y over the vintages.
|
||||
"""
|
||||
inn = oppdiktet()
|
||||
uten = nv.kraftkostnad(inn, _regn(inn, Losning.A), bedrift=True)
|
||||
res = _regn(inn, Losning.A, bortfall=ks.fast_bortfall(0.2))
|
||||
med = nv.kraftkostnad(inn, res, bedrift=True)
|
||||
assert res.dim.Gamma < 1.0
|
||||
assert uten.S42 is not None
|
||||
assert med.S42 is not None
|
||||
assert [a.LCOC for a in med.aarganger] == [a.LCOC for a in uten.aarganger]
|
||||
tapt = math.fsum(1.08 ** -(a.t_v - 2027) * a.inntekt for a in uten.aarganger)
|
||||
assert med.S42 == pytest.approx(uten.S42 - 0.2 * tapt)
|
||||
|
||||
|
||||
def test_bortfallet_i_utkoblingsarmen_en_bedrift_betaler(oppdiktet: LagInndata) -> None:
|
||||
"""R builds no power, so the business pays for disconnection: lost revenue, which falls.
|
||||
|
||||
The same loss for every vintage is the same as a lower price (chapter 17.3): the arm
|
||||
falls by the same share, and the power cost by that share of the arm per MWh.
|
||||
"""
|
||||
inn = oppdiktet()
|
||||
uten = _regn(inn, Losning.R)
|
||||
med = _regn(inn, Losning.R, bortfall=ks.fast_bortfall(0.2))
|
||||
F_uten, F_med = nv.effektkostnad_bedrift(inn, uten), nv.effektkostnad_bedrift(inn, med)
|
||||
j = 2032 - 2027
|
||||
assert F_uten[j] > 0.0
|
||||
assert F_med == pytest.approx(0.8 * F_uten)
|
||||
E_D = 8760.0 * 0.75 * 1.2 * 1000.0
|
||||
c_uten = nv.kraftkostnad(inn, uten, bedrift=True).c_a[0, j]
|
||||
c_med = nv.kraftkostnad(inn, med, bedrift=True).c_a[0, j]
|
||||
assert c_med == pytest.approx(c_uten - 0.2 * float(F_uten[j]) / E_D)
|
||||
|
||||
|
||||
def test_bortfallet_i_bedriftens_kontantstrom(oppdiktet: LagInndata) -> None:
|
||||
"""The revenue and the disconnection arm fall; every other cost and investment stands."""
|
||||
inn, uten = _tk(oppdiktet)
|
||||
med = _regn(inn, Losning.T_K, N_anlegg=2, bortfall=ks.fast_bortfall(0.25))
|
||||
a, b = ei.bedriftsstrom(inn, uten), ei.bedriftsstrom(inn, med)
|
||||
assert b.inntekt == pytest.approx(0.75 * a.inntekt)
|
||||
utkobling = nv.effektkostnad_bedrift(inn, uten)
|
||||
assert float(np.max(utkobling)) > 0.0
|
||||
assert b.drift == pytest.approx(a.drift - 0.25 * utkobling)
|
||||
assert np.array_equal(a.investering, b.investering)
|
||||
assert np.array_equal(a.elavgift, b.elavgift)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- scale: S31 and M6
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.T_F, Losning.T_K])
|
||||
@pytest.mark.parametrize("d", [0.0, 0.3])
|
||||
def test_bidraget_er_inntekt_minus_nivaaisert_kostnad_per_modul(
|
||||
oppdiktet: LagInndata, losning: Losning, d: float
|
||||
) -> None:
|
||||
"""Two ways to the same number, as in ``test_skala.py``, with P_m per module.
|
||||
|
||||
In every year all the operated modules use power, S31 before the other effects is P_m
|
||||
times (mu mu_d Gamma y - LCOC_a) summed over the modules. A technology the additionality
|
||||
rule binds for counts the same in both (hydropower in T-F here).
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6, L_N=20.0)
|
||||
res = _regn(inn, losning, N_anlegg=2, knapphet=Knapphet.VARER, bortfall=ks.fast_bortfall(d))
|
||||
kost = nv.kraftkostnad(inn, res)
|
||||
ut = skala.overskudd_utover_avkastning(inn, res)
|
||||
per_aargang = {(a.anlegg, a.t_v): a for a in kost.aarganger}
|
||||
sjekket = 0
|
||||
for j, t in enumerate(res.aar):
|
||||
moduler = [k for k in range(20) if res.plan.i_drift(k, t)]
|
||||
if not moduler or not all(res.plan.har_last(k, t) for k in moduler):
|
||||
continue
|
||||
sum_margin = 0.0
|
||||
for k in moduler:
|
||||
t_v = res.plan.aargang(k, t)
|
||||
assert t_v is not None
|
||||
LCOC = lg.s15_lcoc(
|
||||
c_bygg=inn["c_bygg"],
|
||||
d_bygg=inn["d_bygg"],
|
||||
c_H=lg.s13_it_kostnad(c_H0=inn["c_H0"], gamma_H=inn["gamma_H"], t_v=t_v),
|
||||
rho_D=inn["rho_D"],
|
||||
L_B=inn["L_B"],
|
||||
L_H=inn["L_H"],
|
||||
o_D=inn["o_D"],
|
||||
d_o_D=inn["d_o_D"],
|
||||
lam=inn["lambda"],
|
||||
PUE=inn["PUE"],
|
||||
c_a=float(kost.c_a[k, j]),
|
||||
)
|
||||
inntekt = per_aargang[k, t_v].inntekt
|
||||
assert inntekt == pytest.approx((1.0 - d) * res.y(t_v))
|
||||
sum_margin += 100.0 * (inntekt - LCOC)
|
||||
assert ut[j] == pytest.approx(sum_margin, rel=1e-9, abs=1.0)
|
||||
sjekket += 1
|
||||
assert sjekket >= 10
|
||||
|
||||
|
||||
def test_stabil_drift_er_forste_aar_alle_modulene_er_startet(oppdiktet: LagInndata) -> None:
|
||||
"""Chapter 17.1: the last modules start in 2036 and the first goes out after 2049."""
|
||||
inn, res = _tk(oppdiktet)
|
||||
s = skala.skala(inn, res)
|
||||
assert s.stabilt_aar == 2036
|
||||
assert s.M6 == pytest.approx(float(s.B_6[2036 - 2027]) / inn["SNKS_snitt"])
|
||||
assert s.M6_snitt == pytest.approx(float(np.mean(s.B_6[9:14])) / inn["SNKS_snitt"])
|
||||
|
||||
|
||||
def test_moduler_som_gaar_ut_for_de_siste_starter_gir_ingen_M6(oppdiktet: LagInndata) -> None:
|
||||
"""Chapter 17.9, point 2: T-F is held back by the power, and module 1 goes out in 2049."""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6, L_N=20.0)
|
||||
res = _regn(inn, Losning.T_F, N_anlegg=2)
|
||||
assert res.plan.gjennomforbar
|
||||
assert res.plan.anlegg[-1].start == 2060
|
||||
s = skala.skala(inn, res)
|
||||
assert s.stabilt_aar is None
|
||||
assert s.M6 is None
|
||||
assert s.M6_snitt is None
|
||||
assert 2030 <= s.toppaar <= 2060
|
||||
heleid = inn.eierformer["heleid_selskap"]
|
||||
KS_stat = ei.eierresultat(inn, ei.bedriftsstrom(inn, res, tilleggsregel=True), heleid).KS_stat
|
||||
assert skala.statens_kontantstrom_mot_petroleum(inn, res, KS_stat) is None
|
||||
|
||||
|
||||
# ------------------------------------------------- business cash flow and ownership forms
|
||||
|
||||
|
||||
def test_tariffen_betales_per_modul_som_drives(oppdiktet: LagInndata) -> None:
|
||||
"""The only difference a tariff of zero makes is t_nett PUE P_m per module operated."""
|
||||
inn, res = _tk(oppdiktet)
|
||||
uten_tariff, uten = _tk(oppdiktet, t_nett=0.0)
|
||||
forskjell = ei.bedriftsstrom(inn, res).drift - ei.bedriftsstrom(uten_tariff, uten).drift
|
||||
i_drift = np.array([res.plan.antall_i_drift(t) for t in res.aar], dtype=np.float64)
|
||||
assert float(np.max(i_drift)) == 20.0
|
||||
assert forskjell == pytest.approx(TARIFF * i_drift)
|
||||
per_modul = np.array(ei.netto_per_anlegg(inn, res)) - np.array(
|
||||
ei.netto_per_anlegg(uten_tariff, uten)
|
||||
)
|
||||
drives = np.array(
|
||||
[[1.0 if res.plan.i_drift(k, t) else 0.0 for t in res.aar] for k in range(20)]
|
||||
)
|
||||
assert per_modul == pytest.approx(-TARIFF * drives)
|
||||
|
||||
|
||||
def test_enhetenes_kontantstrom_deles_paa_kjernekraftmodulene(oppdiktet: LagInndata) -> None:
|
||||
"""Clarifications 62 and 76: shared among the nuclear modules operated that year.
|
||||
|
||||
The two first units are paid for in 2031 to 2034, 50 billion kr a year. No nuclear
|
||||
module is operated then, so the amount is not shared, and not on the renewable modules:
|
||||
module 1 has its own revenue, costs, hydropower and the next vintage (20 billion kr,
|
||||
paid in 2034) and nothing else. From 2035 the modules' parts add up to the programme's
|
||||
cash flow.
|
||||
"""
|
||||
inn, res = _tk(oppdiktet)
|
||||
for tilleggsregel in (False, True):
|
||||
strom = ei.bedriftsstrom(inn, res, tilleggsregel=tilleggsregel)
|
||||
per_modul = np.array(ei.netto_per_anlegg(inn, res, tilleggsregel=tilleggsregel))
|
||||
programmet = strom.inntekt - strom.drift - strom.investering
|
||||
ikke_delt = programmet - per_modul.sum(axis=0)
|
||||
assert ikke_delt[4:8] == pytest.approx(-2.0 * 100e6 * 1000.0 / 4.0)
|
||||
assert ikke_delt[8:29] == pytest.approx(0.0, abs=1.0)
|
||||
j = 2034 - 2027
|
||||
pris = res.kraftaar[j].pris
|
||||
faktor = res.varsigma["vann"] if tilleggsregel else 1.0
|
||||
modul_1 = (
|
||||
100.0 * res.y(2030)
|
||||
- 2.5e6 * 100.0
|
||||
- (pris + 70.0) * E_MODUL
|
||||
- TARIFF
|
||||
+ (faktor * 1.2 * pris - 70.0) * 985_500.0
|
||||
- 200e6 * 100.0
|
||||
)
|
||||
assert per_modul[0, j] == pytest.approx(modul_1)
|
||||
|
||||
|
||||
def test_restverdien_per_modul_og_avviklingen_av_den_siste_enheten(
|
||||
oppdiktet: LagInndata,
|
||||
) -> None:
|
||||
"""Every module has gone out by 2055; the unit from 2055 has 14 operating years left."""
|
||||
inn, res = _tk(oppdiktet)
|
||||
strom = ei.bedriftsstrom(inn, res)
|
||||
assert strom.restverdi_anlegg == (0.0,) * 20
|
||||
assert strom.restverdi_felles == pytest.approx(-5e6 * 1000.0 / 1.06**14)
|
||||
assert strom.restverdi[-1] == pytest.approx(strom.restverdi_felles)
|
||||
assert strom.kapital[-1] == pytest.approx(0.0, abs=1.0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", [Losning.T_F, Losning.T_K])
|
||||
def test_eierformene_regnes_for_t_som_for_de_andre(oppdiktet: LagInndata, losning: Losning) -> None:
|
||||
"""Chapter 17.1: direct ownership gives the state the whole cash flow and the levies."""
|
||||
inn = oppdiktet(tau_nett=6.0, g_fornybar=0.5e6, L_N=20.0)
|
||||
res = _regn(inn, losning, N_anlegg=2)
|
||||
strom = ei.bedriftsstrom(inn, res, tilleggsregel=True)
|
||||
direkte = ei.eierresultat(inn, strom, inn.eierformer["direkte"])
|
||||
assert direkte.FKE == pytest.approx(strom.NK)
|
||||
assert direkte.KS_stat == pytest.approx(strom.NK + strom.elavgift)
|
||||
for form in inn.eierformer.values():
|
||||
r = ei.eierresultat(inn, strom, form)
|
||||
assert np.all(np.isfinite(r.KS_stat))
|
||||
assert r.gjeld[-1] == pytest.approx(0.0, abs=1.0)
|
||||
hoy = ei.lcoc_med_kapitalkostnad(inn, res, 0.10)
|
||||
lav = ei.lcoc_med_kapitalkostnad(inn, res, 0.04)
|
||||
assert lav < hoy
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _LaverePris(ks.Regnekraftpris):
|
||||
"""The price of S18 times a fixed factor, for the comparison with a loss of demand."""
|
||||
|
||||
faktor: float = 1.0
|
||||
|
||||
def __call__(self, t_v: int) -> float:
|
||||
return self.faktor * super().__call__(t_v)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("losning", ALLE)
|
||||
def test_likt_bortfall_er_det_samme_som_lavere_pris(
|
||||
oppdiktet: LagInndata, losning: Losning, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Chapter 17.3: mu_d stands everywhere the price does, so d for all vintages is a price cut.
|
||||
|
||||
That is what makes the threshold of S52 the price threshold expressed as a loss. Compared
|
||||
here: the net present value, S42, S31 and the business cash flow with its ownership forms.
|
||||
"""
|
||||
inn = oppdiktet(tau_nett=6.0, eps_d=0.5, u_eksport=None)
|
||||
med_bortfall = _regn(inn, losning, N_anlegg=2, bortfall=ks.fast_bortfall(0.4))
|
||||
vanlig = ks.regnekraftpris
|
||||
|
||||
def lavere(inn: Inndata, knapphet: Knapphet, t_1: int) -> ks.Regnekraftpris:
|
||||
y = vanlig(inn, knapphet, t_1)
|
||||
return _LaverePris(inn=y.inn, paaslag_g=y.paaslag_g, siste=y.siste, faktor=0.8)
|
||||
|
||||
monkeypatch.setattr(ks, "regnekraftpris", lavere)
|
||||
med_pris = _regn(inn, losning, N_anlegg=2)
|
||||
assert med_pris.y(2035) == pytest.approx(0.8 * med_bortfall.y(2035))
|
||||
assert med_bortfall.NNV == pytest.approx(med_pris.NNV, rel=1e-9)
|
||||
a = nv.kraftkostnad(inn, med_bortfall, bedrift=True)
|
||||
b = nv.kraftkostnad(inn, med_pris, bedrift=True)
|
||||
assert a.S42 == pytest.approx(b.S42, rel=1e-9)
|
||||
assert skala.skala(inn, med_bortfall).B_6 == pytest.approx(
|
||||
skala.skala(inn, med_pris).B_6, rel=1e-9, abs=1.0
|
||||
)
|
||||
for tilleggsregel in (False, True):
|
||||
sa = ei.bedriftsstrom(inn, med_bortfall, tilleggsregel=tilleggsregel)
|
||||
sb = ei.bedriftsstrom(inn, med_pris, tilleggsregel=tilleggsregel)
|
||||
assert sa.NK == pytest.approx(sb.NK, rel=1e-9, abs=1.0)
|
||||
for form in inn.eierformer.values():
|
||||
assert ei.eierresultat(inn, sa, form).NV_stat == pytest.approx(
|
||||
ei.eierresultat(inn, sb, form).NV_stat, rel=1e-9, abs=1.0
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue