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
|
|
@ -248,8 +248,11 @@ def bedriftsstrom(
|
|||
``tilleggsregel=True`` multiplies the power plants' sales by the factor of
|
||||
S45; that is the cash flow S30 is computed on, while M2 and S28 use the
|
||||
sales as they are.
|
||||
|
||||
In solution T the tariff is paid per module, on PUE P_m (chapter 17.1). The
|
||||
revenue and the disconnection arm carry the factor of S51 when the path is
|
||||
computed with a loss of demand (chapter 17.3).
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
plan = res.plan
|
||||
null = np.zeros(len(res.aar), dtype=np.float64)
|
||||
med_last = np.array([plan.antall_med_last(t) for t in res.aar], dtype=np.float64)
|
||||
|
|
@ -266,7 +269,7 @@ def bedriftsstrom(
|
|||
faktor = res.varsigma[ks.KJERNEKRAFT] if tilleggsregel else 1.0
|
||||
drift += f.drift + f.ulykke + f.avvikling - faktor * f.salg
|
||||
if res.losning.paa_nett:
|
||||
tariff = i_drift * lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=inn["P_IT"])
|
||||
tariff = i_drift * lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=res.P_enhet)
|
||||
drift += pris * brukt + tariff + nivaaisert.effektkostnad_bedrift(inn, res)
|
||||
else:
|
||||
P_buf = lg.s36_buffer(delta_L=inn["delta_L"], PUE=inn["PUE"], P_IT=inn["P_IT"])
|
||||
|
|
@ -300,15 +303,18 @@ def netto_per_anlegg(
|
|||
them. The disconnection arm of S47 is shared as F_a is: equally among the
|
||||
facilities that use power that year. In B the year's cash flow of the
|
||||
programme's nuclear units is shared equally among the facilities operated
|
||||
that year; in a year without any, it is not shared.
|
||||
that year; in a year without any, it is not shared. In T-K it is shared
|
||||
among the nuclear modules operated that year, and never on the renewable
|
||||
modules (chapter 17.1, clarification 76).
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
plan = res.plan
|
||||
pris = np.array([rad.pris for rad in res.kraftaar], dtype=np.float64)
|
||||
med_last = np.array([max(1, plan.antall_med_last(t)) for t in res.aar], dtype=np.float64)
|
||||
i_drift = np.array([max(1, plan.antall_i_drift(t)) for t in res.aar], dtype=np.float64)
|
||||
paa_felles = np.array(
|
||||
[max(1, res.antall_paa_felles(t, med_last=False)) for t in res.aar], dtype=np.float64
|
||||
)
|
||||
utkobling = nivaaisert.effektkostnad_bedrift(inn, res)
|
||||
tariff = lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=inn["P_IT"])
|
||||
tariff = lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=res.P_enhet)
|
||||
buffer = inn["f_buf"] * lg.s36_buffer(delta_L=inn["delta_L"], PUE=inn["PUE"], P_IT=inn["P_IT"])
|
||||
|
||||
def faktor(teknologi: str) -> float:
|
||||
|
|
@ -330,7 +336,8 @@ def netto_per_anlegg(
|
|||
strom -= pris * brukt + drives * tariff + utkobling * last / med_last
|
||||
else:
|
||||
strom -= drives * buffer
|
||||
netto.append(strom + felles * drives / i_drift)
|
||||
andel = felles * drives / paa_felles if res.paa_felles_kjernekraft(k) else 0.0
|
||||
netto.append(strom + andel)
|
||||
return tuple(netto)
|
||||
|
||||
|
||||
|
|
@ -344,7 +351,6 @@ def restverdi_bedrift(
|
|||
falls after the final year is always deducted, discounted with rho_N
|
||||
(rho_A in A).
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
vindu = min(res.plan.L_H, len(res.aar))
|
||||
rho_avvikling = inn["rho_N"] if res.losning.paa_nett else res.dim.rho_A
|
||||
anlegg = tuple(
|
||||
|
|
@ -402,7 +408,6 @@ def lcoc_med_kapitalkostnad(inn: Inndata, res: Programresultat, r_e: float) -> f
|
|||
criterion of the pre-registration uses the requirement before tax,
|
||||
``krav_for_skatt`` (clarification 66).
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
kost = nivaaisert.kraftkostnad(
|
||||
inn, res, bedrift=True, renter=Renter(rho_D=r_e, rho_N=r_e, rho_A=r_e)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -359,20 +359,24 @@ class Programresultat:
|
|||
"""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 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)
|
||||
|
||||
def krev_uten_tillegget(res: Programresultat) -> None:
|
||||
"""Refuse a result the chapters after the cash flow cannot take yet.
|
||||
def antall_paa_felles(self, t: int, *, med_last: bool) -> int:
|
||||
"""The facilities or modules on the programme's units in year ``t``.
|
||||
|
||||
The levelised cost, the ownership forms and scale are not taken through
|
||||
chapter 17: they neither know modules nor carry the factor of S51 (S19,
|
||||
S27, S31 and S42).
|
||||
"""
|
||||
if res.losning.trinnvis:
|
||||
msg = "solution T is not taken through the levelised cost, ownership and scale yet"
|
||||
raise NotImplementedError(msg)
|
||||
if not res.mu_d.hovedforlop:
|
||||
msg = "the loss of demand (S51) is not in the levelised cost, ownership and scale yet"
|
||||
raise NotImplementedError(msg)
|
||||
``med_last=True`` counts those that use power that year (the denominator
|
||||
of S11, clarifications 2 and 42), ``False`` those that are operated (the
|
||||
sharing of the units' cash flow, clarifications 29 and 62). Every
|
||||
facility in B, the nuclear modules in T-K (chapter 17.1).
|
||||
"""
|
||||
teller = self.plan.har_last if med_last else self.plan.i_drift
|
||||
return sum(
|
||||
1
|
||||
for k in range(len(self.plan.anlegg))
|
||||
if self.paa_felles_kjernekraft(k) and teller(k, t)
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- dimensioning
|
||||
|
|
@ -749,6 +753,16 @@ def _portefolje(inn: Inndata, dim: Dimensjonering, antall: int) -> lg.Fornybarpo
|
|||
)
|
||||
|
||||
|
||||
def reaktoreffekt(dim: Dimensjonering, plan: Plan, k: int) -> float:
|
||||
"""P_G^N for facility or module ``k`` (0 is the first), MW (clarifications 14 and 76).
|
||||
|
||||
What the facility needs of reactor capacity; zero for a renewable module in T.
|
||||
"""
|
||||
if isinstance(plan, ub.Trinnvisplan) and not plan.er_kjernekraftmodul(k):
|
||||
return 0.0
|
||||
return dim.P_G_N
|
||||
|
||||
|
||||
def paa_felles_kjernekraft(losning: Losning, plan: Plan, k: int) -> bool:
|
||||
"""True when facility or module ``k`` (0 is the first) runs on the programme's nuclear units.
|
||||
|
||||
|
|
@ -971,9 +985,7 @@ class _Program:
|
|||
|
||||
def reaktoreffekt(self, k: int) -> float:
|
||||
"""P_G^N for facility ``k``, MW (clarification 14); zero for a renewable module in T."""
|
||||
if isinstance(self.plan, ub.Trinnvisplan) and not self.plan.er_kjernekraftmodul(k):
|
||||
return 0.0
|
||||
return self.dim.P_G_N
|
||||
return reaktoreffekt(self.dim, self.plan, k)
|
||||
|
||||
def forste_kjernekraftaar(self) -> int | None:
|
||||
"""The year S41 counts to, or None when the programme builds no nuclear power.
|
||||
|
|
@ -1292,7 +1304,9 @@ def _nett_buffer_og_forsyning(
|
|||
def _anleggsstrom(p: _Program, k: int, pris: Tabell) -> Anleggsstrom:
|
||||
eiendeler: list[Eiendel] = []
|
||||
inntekt, drift, kraftkjop, I_bygg, I_H = _datasenter(p, k, pris, eiendeler)
|
||||
teknologier = {verk.teknologi for verk in p.verk[k]}
|
||||
# in the plants' own order, not a set: the order of a set of strings differs from run to
|
||||
# run, and with it the last digit of every sum over the technologies
|
||||
teknologier = tuple(dict.fromkeys(verk.teknologi for verk in p.verk[k]))
|
||||
salg, investering, kraftdrift, avvikling = (
|
||||
{i: p.null() for i in teknologier} for _ in range(4)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ class Aargangskost:
|
|||
aar: the years the vintage is in operation.
|
||||
c_a: the power cost weighted by present value over those years, kr/MWh.
|
||||
LCOC: S15 with that power cost, kr per MW IT and year.
|
||||
inntekt: mu Gamma y(t_v), kr per MW IT and year.
|
||||
inntekt: mu mu_d(t_v) Gamma y(t_v), kr per MW IT and year (mu_d is S51, one without
|
||||
a loss of demand).
|
||||
margin: the four parts of S19; None in the business version.
|
||||
"""
|
||||
|
||||
|
|
@ -108,15 +109,17 @@ def renter_i_hovedkjoringen(inn: Inndata, res: Programresultat) -> Renter:
|
|||
|
||||
|
||||
def effektkostnad_bedrift(inn: Inndata, res: Programresultat) -> Tabell:
|
||||
"""Chapter 7: the disconnection arm of S47 per year for the programme, kr. Zero in A."""
|
||||
ks.krev_uten_tillegget(res)
|
||||
"""Chapter 7: the disconnection arm of S47 per year for the programme, kr. Zero in A.
|
||||
|
||||
The price is the average of mu_d y over the vintages in operation (chapter 17.3).
|
||||
"""
|
||||
plan = res.plan
|
||||
F = np.zeros(len(res.aar), dtype=np.float64)
|
||||
if not res.losning.paa_nett:
|
||||
return F
|
||||
for j, t in enumerate(res.aar):
|
||||
aarganger = [plan.aargang(k, t) for k in range(len(plan.anlegg))]
|
||||
priser = [res.y(v) for v in aarganger if v is not None]
|
||||
priser = [res.mu_d(v) * res.y(v) for v in aarganger if v is not None]
|
||||
if priser:
|
||||
F[j] = lg.s47_utkobling(
|
||||
Delta_R_utfall=res.kraftaar[j].Delta_R_utfall,
|
||||
|
|
@ -179,7 +182,6 @@ def lcoe_fornybar(inn: Inndata, teknologi: str, rho_N: float) -> float:
|
|||
|
||||
def kraftkostnad_dedikert(inn: Inndata, res: Programresultat, k: int, rho_A: float) -> float:
|
||||
"""S9 for facility ``k`` (0 is the first) in A, kr per MWh delivered to the data centre."""
|
||||
ks.krev_uten_tillegget(res)
|
||||
dim = res.dim
|
||||
numre = ks.enhetsnumre(dim, k + 1)
|
||||
return lg.s9_kraftkostnad_dedikert(
|
||||
|
|
@ -233,7 +235,11 @@ class _Portefolje:
|
|||
def _egen_portefolje(
|
||||
inn: Inndata, res: Programresultat, k: int, r: Renter, *, bedrift: bool
|
||||
) -> _Portefolje:
|
||||
"""B' and C: the plants that belong to facility ``k``. Empty in R (and in B, see below)."""
|
||||
"""B' and C: the plants that belong to facility ``k``. Empty in R (and in B, see below).
|
||||
|
||||
In solution T a renewable module has its own plants, as a facility in C, and a
|
||||
nuclear module has none, as a facility in B (chapter 17.1).
|
||||
"""
|
||||
verk = res.verk[k]
|
||||
E_G = math.fsum(v.energi for v in verk)
|
||||
ledd = []
|
||||
|
|
@ -260,7 +266,10 @@ def _egen_portefolje(
|
|||
def _felles_portefolje(
|
||||
inn: Inndata, res: Programresultat, t: int, r: Renter, *, bedrift: bool
|
||||
) -> _Portefolje:
|
||||
"""B: the programme's units in operation in year ``t`` (clarifications 2 and 29)."""
|
||||
"""B and the nuclear modules of T-K: the programme's units in operation in year ``t``.
|
||||
|
||||
Clarifications 2 and 29, and chapter 17.1 for T-K.
|
||||
"""
|
||||
i_drift = [f.gruppe for f in res.felles if f.gruppe.start <= t <= f.gruppe.siste_driftsaar]
|
||||
if not i_drift:
|
||||
return _Portefolje(ledd=(), E_G=0.0)
|
||||
|
|
@ -293,36 +302,49 @@ def _dedikert_per_aar(inn: Inndata, res: Programresultat, r: Renter, *, bedrift:
|
|||
def _kraftkostnad_per_aar(
|
||||
inn: Inndata, res: Programresultat, r: Renter, F: Tabell, *, bedrift: bool
|
||||
) -> Tabell:
|
||||
"""c_a per facility and year, kr/MWh; NaN where the facility uses no power."""
|
||||
"""c_a per facility and year, kr/MWh; NaN where the facility uses no power.
|
||||
|
||||
In solution T everything is per module, with P_m in place of P_IT: a
|
||||
renewable module has its own portfolio, as a facility in C, and the nuclear
|
||||
modules of T-K share the programme's units, as the facilities in B
|
||||
(chapter 17.1). The capacity cost is the programme's and is shared equally
|
||||
among all the modules that use power that year (clarification 76).
|
||||
"""
|
||||
if res.losning is Losning.A:
|
||||
return _dedikert_per_aar(inn, res, r, bedrift=bedrift)
|
||||
plan, dim = res.plan, res.dim
|
||||
antall = range(len(plan.anlegg))
|
||||
c_a = np.full((len(plan.anlegg), len(res.aar)), np.nan, dtype=np.float64)
|
||||
H_a = lg.s11_nettkostnad(
|
||||
I_nett=inn["I_nett"],
|
||||
delta_V=inn["delta_V"],
|
||||
PUE=inn["PUE"],
|
||||
P_IT=inn["P_IT"],
|
||||
P_G_N=dim.P_G_N,
|
||||
rho_N=r.rho_N,
|
||||
L_nett=inn["L_nett"],
|
||||
)
|
||||
H_a = [
|
||||
lg.s11_nettkostnad(
|
||||
I_nett=inn["I_nett"],
|
||||
delta_V=inn["delta_V"],
|
||||
PUE=inn["PUE"],
|
||||
P_IT=res.P_enhet,
|
||||
P_G_N=res.reaktoreffekt(k),
|
||||
rho_N=r.rho_N,
|
||||
L_nett=inn["L_nett"],
|
||||
)
|
||||
for k in antall
|
||||
]
|
||||
tariff = (
|
||||
lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=inn["P_IT"]) if bedrift else 0.0
|
||||
lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=res.P_enhet) if bedrift else 0.0
|
||||
)
|
||||
egne = [_egen_portefolje(inn, res, k, r, bedrift=bedrift) for k in range(len(plan.anlegg))]
|
||||
egne = [_egen_portefolje(inn, res, k, r, bedrift=bedrift) for k in antall]
|
||||
for j, t in enumerate(res.aar):
|
||||
med_last = plan.antall_med_last(t)
|
||||
if med_last == 0:
|
||||
continue
|
||||
felles = _felles_portefolje(inn, res, t, r, bedrift=bedrift)
|
||||
for k in range(len(plan.anlegg)):
|
||||
paa_felles = res.antall_paa_felles(t, med_last=True)
|
||||
for k in antall:
|
||||
if not plan.har_last(k, t):
|
||||
continue
|
||||
# the programme's units are shared by energy use: equally among those with load
|
||||
# the programme's units are shared by energy use: equally among those on them
|
||||
# that use power this year
|
||||
portefolje = (
|
||||
_Portefolje(ledd=felles.ledd, E_G=felles.E_G / med_last)
|
||||
if res.losning is Losning.B
|
||||
_Portefolje(ledd=felles.ledd, E_G=felles.E_G / paa_felles)
|
||||
if res.paa_felles_kjernekraft(k)
|
||||
else egne[k]
|
||||
)
|
||||
p_z = res.kraftaar[j].pris
|
||||
|
|
@ -343,7 +365,7 @@ def _kraftkostnad_per_aar(
|
|||
portefolje=portefolje.ledd,
|
||||
E_G=portefolje.E_G,
|
||||
E_D=dim.E_D,
|
||||
H_a=H_a,
|
||||
H_a=H_a[k],
|
||||
F_a=F[j] / med_last,
|
||||
)
|
||||
return c_a
|
||||
|
|
@ -352,11 +374,16 @@ def _kraftkostnad_per_aar(
|
|||
def _aarganger(
|
||||
inn: Inndata, res: Programresultat, r: Renter, c_a: Tabell, *, bedrift: bool
|
||||
) -> tuple[Aargangskost, ...]:
|
||||
"""S15 per vintage with the power cost of clarification 15, and S19 or S27 with it."""
|
||||
"""S15 per vintage with the power cost of clarification 15, and S19 or S27 with it.
|
||||
|
||||
The share of capacity sold is mu mu_d(t_v), with the factor of S51 for the
|
||||
vintage (chapter 17.3); the cost is the same with and without a loss.
|
||||
"""
|
||||
plan = res.plan
|
||||
rader = []
|
||||
for k, anlegg in enumerate(plan.anlegg):
|
||||
for t_v in anlegg.aarganger:
|
||||
mu = inn["mu_rel"] * res.mu_d(t_v)
|
||||
aar = tuple(t for t in range(t_v, plan.T_s + 1) if plan.aargang(k, t) == t_v)
|
||||
vekter = [lg.diskonteringsfaktor(rho=r.rho_D, t=t, T_0=t_v) for t in aar]
|
||||
kraft = math.fsum(
|
||||
|
|
@ -393,7 +420,7 @@ def _aarganger(
|
|||
c_bygg=inn["c_bygg"],
|
||||
rho_D=r.rho_D,
|
||||
L_B=inn["L_B"],
|
||||
mu=inn["mu_rel"],
|
||||
mu=mu,
|
||||
Gamma=res.dim.Gamma,
|
||||
)
|
||||
)
|
||||
|
|
@ -404,7 +431,7 @@ def _aarganger(
|
|||
aar=aar,
|
||||
c_a=kraft,
|
||||
LCOC=LCOC,
|
||||
inntekt=inn["mu_rel"] * res.dim.Gamma * res.y(t_v),
|
||||
inntekt=mu * res.dim.Gamma * res.y(t_v),
|
||||
margin=margin,
|
||||
)
|
||||
)
|
||||
|
|
@ -426,8 +453,11 @@ def kraftkostnad(
|
|||
disconnection arm of S47; S42 is then summed over the vintages.
|
||||
``renter`` replaces the required returns of the main run (used for the
|
||||
cost of capital of an ownership form, chapter 8).
|
||||
|
||||
The path may be solution T, built in modules, and may be computed with a
|
||||
loss of demand: the factor of S51 then stands in S19, S27 and S42 and in
|
||||
the disconnection arm of S47.
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
r = renter_i_hovedkjoringen(inn, res) if renter is None else renter
|
||||
F = effektkostnad_bedrift(inn, res) if bedrift else res.F_a
|
||||
c_a = _kraftkostnad_per_aar(inn, res, r, F, bedrift=bedrift)
|
||||
|
|
@ -437,7 +467,10 @@ def kraftkostnad(
|
|||
S42 = lg.s42_naaverdivektet_margin(
|
||||
marginer=[
|
||||
lg.s27_margin_bedrift(
|
||||
mu=inn["mu_rel"], Gamma=res.dim.Gamma, y=res.y(a.t_v), LCOC_bed=a.LCOC
|
||||
mu=inn["mu_rel"] * res.mu_d(a.t_v),
|
||||
Gamma=res.dim.Gamma,
|
||||
y=res.y(a.t_v),
|
||||
LCOC_bed=a.LCOC,
|
||||
)
|
||||
for a in aarganger
|
||||
],
|
||||
|
|
|
|||
|
|
@ -102,19 +102,20 @@ def _kraftverk_netto(
|
|||
return kostnad + verk.variabel_drift - verk.psi * pris * verk.energi
|
||||
|
||||
|
||||
def _faste_aarskostnader(inn: Inndata, res: Programresultat, r: Renter) -> float:
|
||||
"""What one facility carries each operating year besides plant and data centre, kr.
|
||||
def _faste_aarskostnader(inn: Inndata, res: Programresultat, r: Renter, k: int) -> float:
|
||||
"""What facility ``k`` carries each operating year besides plant and data centre, kr.
|
||||
|
||||
On the grid the grid connection H_a (S11); in A the buffer and the external
|
||||
supply to the plant itself (S36, S9).
|
||||
On the grid the grid connection H_a (S11), for a module in T with P_m and
|
||||
with reactor capacity only for a nuclear module; in A the buffer and the
|
||||
external supply to the plant itself (S36, S9).
|
||||
"""
|
||||
if res.losning.paa_nett:
|
||||
return lg.s11_nettkostnad(
|
||||
I_nett=inn["I_nett"],
|
||||
delta_V=inn["delta_V"],
|
||||
PUE=inn["PUE"],
|
||||
P_IT=inn["P_IT"],
|
||||
P_G_N=res.dim.P_G_N,
|
||||
P_IT=res.P_enhet,
|
||||
P_G_N=res.reaktoreffekt(k),
|
||||
rho_N=r.rho_N,
|
||||
L_nett=inn["L_nett"],
|
||||
)
|
||||
|
|
@ -141,28 +142,30 @@ def overskudd_utover_avkastning(
|
|||
Revenue minus operation, power and the yearly cost of all capital in
|
||||
operation that year: the building, the vintage of IT hardware, the power
|
||||
plants, and grid connection or buffer and external supply. In B the
|
||||
programme's units count in every year they are in operation.
|
||||
programme's units count in every year they are in operation, and so do the
|
||||
units of T-K. In solution T the sum goes over the modules, each with P_m
|
||||
(chapter 17.1). The revenue is the cash flow's, so it carries the factor of
|
||||
S51 when the path is computed with a loss of demand, and so does F_a.
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
r = nivaaisert.renter_i_hovedkjoringen(inn, res) if renter is None else renter
|
||||
plan = res.plan
|
||||
rho_kraft = r.rho_N if res.losning.paa_nett else r.rho_A
|
||||
bygg = (
|
||||
inn["c_bygg"] * (1.0 + inn["d_bygg"]) * inn["P_IT"] * lg.s1_crf(rho=r.rho_D, L=inn["L_B"])
|
||||
inn["c_bygg"] * (1.0 + inn["d_bygg"]) * res.P_enhet * lg.s1_crf(rho=r.rho_D, L=inn["L_B"])
|
||||
)
|
||||
crf_H = lg.s1_crf(rho=r.rho_D, L=inn["L_H"])
|
||||
faste = _faste_aarskostnader(inn, res, r)
|
||||
faste = [_faste_aarskostnader(inn, res, r, k) for k in range(len(res.anlegg))]
|
||||
ut = -res.F_a.copy()
|
||||
for j, t in enumerate(res.aar):
|
||||
pris = res.kraftaar[j].pris
|
||||
for k, a in enumerate(res.anlegg):
|
||||
if not plan.i_drift(k, t):
|
||||
continue
|
||||
ut[j] += a.inntekt[j] - a.drift[j] - a.kraftkjop[j] - bygg - faste
|
||||
ut[j] += a.inntekt[j] - a.drift[j] - a.kraftkjop[j] - bygg - faste[k]
|
||||
aargang = plan.aargang(k, t)
|
||||
if aargang is not None:
|
||||
ut[j] -= (
|
||||
inn["P_IT"]
|
||||
res.P_enhet
|
||||
* crf_H
|
||||
* lg.s13_it_kostnad(c_H0=inn["c_H0"], gamma_H=inn["gamma_H"], t_v=aargang)
|
||||
)
|
||||
|
|
@ -189,7 +192,12 @@ def overskudd_utover_avkastning(
|
|||
|
||||
|
||||
def forste_aar_med_stabil_drift(res: Programresultat) -> int | None:
|
||||
"""Chapter 9: the first year every facility of the path is in operation, or None."""
|
||||
"""Chapter 9: the first year every facility of the path is in operation, or None.
|
||||
|
||||
In solution T: the first year every module of the path has started and none
|
||||
has gone out (chapter 17.1). A path where the first modules go out before
|
||||
the last have started has no such year.
|
||||
"""
|
||||
plan = res.plan
|
||||
for t in res.aar:
|
||||
if plan.antall_i_drift(t) == plan.N_anlegg:
|
||||
|
|
@ -218,7 +226,6 @@ def skala(inn: Inndata, res: Programresultat, *, u_e: float = 0.0) -> Skala:
|
|||
``u_e`` is the share owned outside Norway; it is zero in the verdict, which
|
||||
is computed with one wholly state-owned company.
|
||||
"""
|
||||
ks.krev_uten_tillegget(res)
|
||||
B_6 = lg.s31_nettobidrag(
|
||||
u_e=u_e,
|
||||
overskudd_utover_avkastning=overskudd_utover_avkastning(inn, res),
|
||||
|
|
|
|||
|
|
@ -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