Chapters 7 to 11 of the specification, on the made-up set only: - nivaaisert: the power cost per facility, year and vintage on levelised form (S9, S11 with clarifications 2, 11, 13 and 15), S15, S19, S27, S42 - eierskap: the business cash flow with every asset booked, tax, S28, S29 and S30 for the four ownership forms, the criteria over the draws - skala: S31 year by year, the first year with stable operation, M6 - miljo: S32 year by year, the rules of M5 (i) and (ii) - dommer: S37, the verdict per target, the step of the ladder, the overall verdicts; tested on invented outcomes - kontantstrom: each asset is recorded as it is paid, and the price of compute exposes the competitor's cost and the markup This is an intermediate step. The readings are not settled: an independent reader is coding the same from the specification alone, a first comparison agrees on the levelised cost, S19, S42, the cash flows, M3 and M4 and differs on depreciation at the final year, tax, debt and two definitions. Chapter 16 gets the clarifications before any result is computed. Nothing is computed for the hypothesis; the parameter file is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
150 lines
6.7 KiB
Python
150 lines
6.7 KiB
Python
"""Environment (chapter 10): S32 year by year and the rules of M5.
|
|
|
|
Made-up round numbers only; the source values in the tests of M5 are invented. Nothing
|
|
here says anything about the hypothesis.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
|
|
from tokenfabrikker import kontantstrom as ks
|
|
from tokenfabrikker import ligninger as lg
|
|
from tokenfabrikker import miljo
|
|
from tokenfabrikker.dommer import Dom
|
|
from tokenfabrikker.kontantstrom import Knapphet
|
|
from tokenfabrikker.miljo import Kildeverdier
|
|
from tokenfabrikker.utbygging import Losning
|
|
|
|
if TYPE_CHECKING:
|
|
from conftest import LagInndata
|
|
from tokenfabrikker.inndata import Inndata
|
|
|
|
E_D = 8760.0 * 0.75 * 1.2 * 1000.0
|
|
"""Yearly energy to one made-up data centre: 7 884 000 MWh."""
|
|
|
|
PORTEFOLJE = {"vann": 2e6, "vind": 3e6, "havvind": E_D - 1.6e6 - 3e6}
|
|
"""The made-up portfolio of one facility in C: normal-year production per technology, MWh."""
|
|
|
|
U_FORNYBAR = (0.004 * 2e6 + 0.011 * 3e6 + 0.012 * PORTEFOLJE["havvind"]) / sum(PORTEFOLJE.values())
|
|
"""Its emissions per MWh, weighted by production."""
|
|
|
|
|
|
def _regn(inn: Inndata, losning: Losning, *, N_anlegg: int = 1) -> 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.NORMALISERING, dim=dim)
|
|
|
|
|
|
def test_s32_er_summen_av_kraft_maskinvare_og_bygg() -> None:
|
|
U = lg.s32_utslipp(kraft=500.0, u_H=1000.0, u_B=2000.0, P_IT=10.0, nye_aarganger=2, nye_bygg=1)
|
|
assert U == pytest.approx(500.0 + 20_000.0 + 20_000.0)
|
|
|
|
|
|
@pytest.mark.parametrize("losning", [Losning.C, Losning.R])
|
|
def test_utslipp_aar_for_aar_med_fornybar_kraft(oppdiktet: LagInndata, losning: Losning) -> None:
|
|
"""One facility from 2030: building and first vintage in 2030, a vintage every five years.
|
|
|
|
The building lasts 15 years and is renewed in 2045. R uses the same figure for power
|
|
as C: the portfolio the facility has in C.
|
|
"""
|
|
inn = oppdiktet()
|
|
res = _regn(inn, losning)
|
|
U = miljo.utslipp_livslop(inn, res)
|
|
kraft = U_FORNYBAR * E_D
|
|
assert miljo.kraftutslipp_per_mwh(inn, res, 0) == pytest.approx(U_FORNYBAR)
|
|
assert not U[:3].any()
|
|
assert U[2030 - 2027] == pytest.approx(kraft + 1000.0 * 1000.0 + 2000.0 * 1000.0)
|
|
assert U[2031 - 2027] == pytest.approx(kraft)
|
|
assert U[2035 - 2027] == pytest.approx(kraft + 1000.0 * 1000.0)
|
|
assert U[2045 - 2027] == pytest.approx(kraft + 1000.0 * 1000.0 + 2000.0 * 1000.0)
|
|
assert not U[2050 - 2027 :].any()
|
|
|
|
|
|
@pytest.mark.parametrize("losning", [Losning.A, Losning.B, Losning.B_MERKET])
|
|
def test_kjernekraftens_utslipp_regnes_paa_det_datasenteret_bruker(
|
|
oppdiktet: LagInndata, losning: Losning
|
|
) -> None:
|
|
inn = oppdiktet()
|
|
res = _regn(inn, losning)
|
|
U = miljo.utslipp_livslop(inn, res)
|
|
assert U[2036 - 2027] == pytest.approx(0.012 * E_D)
|
|
|
|
|
|
def test_anlegg_uten_brikker_bruker_ikke_kraft(oppdiktet: LagInndata) -> None:
|
|
u = tuple(0.0 if aar == 2035 else 0.5 for aar in range(2028, 2061))
|
|
inn = oppdiktet(u_eksport=u, phi_X=0.1, D_X=3.0)
|
|
U = miljo.utslipp_livslop(inn, _regn(inn, Losning.R))
|
|
assert U[2036 - 2027] == 0.0
|
|
assert U[2038 - 2027] > 1000.0 * 1000.0
|
|
|
|
|
|
@pytest.mark.parametrize("losning", [Losning.C, Losning.R])
|
|
def test_hvert_anlegg_bruker_sin_egen_portefolje(oppdiktet: LagInndata, losning: Losning) -> None:
|
|
"""The first facility takes the hydropower and the wind; the second gets offshore wind only.
|
|
|
|
In R, facility k uses the figure of the portfolio facility k has in C.
|
|
"""
|
|
inn = oppdiktet()
|
|
res = _regn(inn, losning, N_anlegg=2)
|
|
assert miljo.kraftutslipp_per_mwh(inn, res, 0) == pytest.approx(U_FORNYBAR)
|
|
assert miljo.kraftutslipp_per_mwh(inn, res, 1) == pytest.approx(0.012)
|
|
U = miljo.utslipp_livslop(inn, res)
|
|
# 2034: both facilities are in operation in both solutions, and no vintage is new
|
|
assert U[2034 - 2027] == pytest.approx((U_FORNYBAR + 0.012) * E_D)
|
|
|
|
|
|
def test_brukt_brensel_og_areal(oppdiktet: LagInndata) -> None:
|
|
inn = oppdiktet()
|
|
res = _regn(inn, Losning.B_MERKET)
|
|
tonn = miljo.brukt_brensel(inn, res)
|
|
assert tonn[2036 - 2027] == pytest.approx(3e-6 * res.verk[0][0].energi)
|
|
assert not miljo.brukt_brensel(inn, _regn(inn, Losning.R)).any()
|
|
# A: only what the data centre uses is produced
|
|
assert miljo.brukt_brensel(inn, _regn(inn, Losning.A))[2036 - 2027] == pytest.approx(3e-6 * E_D)
|
|
# 0.1 km2 per TWh for nuclear power, 1.5 for wind, and 0.001 km2 per MW IT for the plot
|
|
assert miljo.areal(inn, teknologi="kjernekraft", energi=E_D, P_IT=1000.0) == pytest.approx(
|
|
0.7884 + 1.0
|
|
)
|
|
assert miljo.areal(inn, teknologi="vind_direkte", energi=E_D, P_IT=1000.0) == pytest.approx(
|
|
11.826 + 1.0
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------------ M5
|
|
|
|
|
|
def test_m5_utslipp_kilde_for_kilde() -> None:
|
|
"""Invented source values. Nuclear must not be above the lower of wind and hydro in any."""
|
|
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.A, [under, under]) is Dom.HOLDER
|
|
assert miljo.m5_utslipp(Losning.B, [under, mellom]) is Dom.BETINGELSER
|
|
assert miljo.m5_utslipp(Losning.A, [under, mellom, over]) is Dom.HOLDER_IKKE
|
|
lik = Kildeverdier("W", kjernekraft=6.0, vind=11.0, vann=6.0, vind_hoyeste=50.0)
|
|
assert miljo.m5_utslipp(Losning.A, [lik]) is Dom.HOLDER
|
|
# C and R meet (i) by definition
|
|
assert miljo.m5_utslipp(Losning.C, [over]) is Dom.HOLDER
|
|
assert miljo.m5_utslipp(Losning.R, []) is Dom.HOLDER
|
|
with pytest.raises(ValueError, match="at least one source"):
|
|
miljo.m5_utslipp(Losning.A, [])
|
|
|
|
|
|
def test_m5_areal_mot_vind_paa_land() -> None:
|
|
felles = {"vind_direkte": 1.5, "vind_plan": 35.0}
|
|
assert miljo.m5_areal(Losning.A, kjernekraft=0.1, **felles) is Dom.HOLDER
|
|
assert miljo.m5_areal(Losning.A, kjernekraft=1.5, **felles) is Dom.HOLDER
|
|
assert miljo.m5_areal(Losning.B, kjernekraft=10.0, **felles) is Dom.BETINGELSER
|
|
assert miljo.m5_areal(Losning.A, kjernekraft=40.0, **felles) is Dom.HOLDER_IKKE
|
|
assert miljo.m5_areal(Losning.C, kjernekraft=40.0, **felles) is Dom.HOLDER
|
|
|
|
|
|
def test_m5_samlet() -> None:
|
|
assert miljo.m5(Dom.HOLDER, Dom.HOLDER) is Dom.HOLDER
|
|
assert miljo.m5(Dom.BETINGELSER, Dom.HOLDER) is Dom.BETINGELSER
|
|
assert miljo.m5(Dom.BETINGELSER, Dom.BETINGELSER) is Dom.BETINGELSER
|
|
assert miljo.m5(Dom.HOLDER, Dom.HOLDER_IKKE) is Dom.HOLDER_IKKE
|
|
assert miljo.m5(Dom.HOLDER, Dom.HOLDER, kostnadsfort=False) is Dom.HOLDER_IKKE
|