-
Notifications
You must be signed in to change notification settings - Fork 2
/
component_templates.py
1434 lines (1235 loc) · 57.8 KB
/
component_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import logging
from dataclasses import dataclass
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import pandas as pd
from gurobipy import GRB, Model, quicksum
from draf import Collectors, Dimensions, Params, Results, Scenario, Vars
from draf import helper as hp
# from draf.model_builder import autocollectors
from draf.abstract_component import Component
from draf.conventions import Descs
from draf.helper import conv, get_annuity_factor, set_component_order_by_order_restrictions
from draf.paths import DATA_DIR
from draf.prep import DataBase as db
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.WARN)
@dataclass
class Main(Component):
"""Objective functions and general collectors. This must be the last model_func to be executed."""
def param_func(self, sc: Scenario):
sc.collector("P_EL_source_T", doc="Power sources", unit="kW_el")
sc.collector("P_EL_sink_T", doc="Power sinks", unit="kW_el")
sc.collector("dQ_cooling_source_TN", doc="Cooling energy flow sources", unit="kW_th")
sc.collector("dQ_cooling_sink_TN", doc="Cooling energy flow sinks", unit="kW_th")
sc.collector("dQ_heating_source_TH", doc="Heating energy flow sources", unit="kW_th")
sc.collector("dQ_heating_sink_TH", doc="Heating energy flow sinks", unit="kW_th")
sc.collector("dH_hydrogen_source_T", doc="Hydrogen energy flow sources", unit="kW")
sc.collector("dH_hydrogen_sink_T", doc="Hydrogen energy flow sinks", unit="kW")
sc.collector("C_TOT_", doc="Total costs", unit="k€/a")
sc.collector("C_TOT_op_", doc="Total operating costs", unit="k€/a")
sc.collector("CE_TOT_", doc="Total carbon emissions", unit="kgCO2eq/a")
sc.collector("X_TOT_penalty_", doc="Penalty term for objective function", unit="Any")
if sc.consider_invest:
sc.collector("C_TOT_RMI_", doc="Total annual maintenance cost", unit="k€/a")
sc.collector("C_TOT_inv_", doc="Total investment costs", unit="k€")
sc.collector("C_TOT_invAnn_", doc="Total annualized investment costs", unit="k€")
sc.var("C_TOT_", doc="Total costs", unit="k€/a", lb=-GRB.INFINITY)
sc.var("C_TOT_op_", doc="Total operating costs", unit="k€/a", lb=-GRB.INFINITY)
sc.var("CE_TOT_", doc="Total emissions", unit="kgCO2eq/a", lb=-GRB.INFINITY)
if sc.consider_invest:
sc.param("k__r_", data=0.06, doc="Calculatory interest rate")
sc.var("C_TOT_inv_", doc="Total investment costs", unit="k€")
sc.var("C_TOT_invAnn_", doc="Total annualized investment costs", unit="k€")
sc.var("C_TOT_RMI_", doc="Total annual maintenance cost", unit="k€")
sc.param("k_PTO_alpha_", data=0, doc="Pareto weighting factor")
sc.param("k_PTO_C_", data=1, doc="Normalization factor")
sc.param("k_PTO_CE_", data=1 / 1e4, doc="Normalization factor")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
m.setObjective(
(
(1 - p.k_PTO_alpha_) * v.C_TOT_ * p.k_PTO_C_
+ p.k_PTO_alpha_ * v.CE_TOT_ * p.k_PTO_CE_
+ quicksum(c.X_TOT_penalty_.values())
),
GRB.MINIMIZE,
)
m.addConstr(v.C_TOT_op_ == quicksum(c.C_TOT_op_.values()), "operating_cost_balance")
c.C_TOT_["op"] = v.C_TOT_op_
if sc.consider_invest:
m.addConstr(v.C_TOT_inv_ == quicksum(c.C_TOT_inv_.values()), "investment_cost")
m.addConstr(v.C_TOT_RMI_ == quicksum(c.C_TOT_RMI_.values()), "repair_cost")
m.addConstr(
v.C_TOT_invAnn_ == quicksum(c.C_TOT_invAnn_.values()), "annualized_investment_cost"
)
c.C_TOT_op_["RMI"] = v.C_TOT_RMI_
c.C_TOT_["inv"] = v.C_TOT_invAnn_
## AUTOCOLLECTORS (currently unused) ---------------------------------------------------
# m.addConstr( (v.C_TOT_inv_ == autocollectors.C_inv_(p, v, r=p.k__r_) * conv("€", "k€", 1e-3)) )
# m.addConstr( (v.C_TOT_invAnn_ == autocollectors.C_inv_Annual_(p, v, r=p.k__r_) * conv("€", "k€", 1e-3)) )
# m.addConstr( (v.C_TOT_RMI_ == autocollectors.C_TOT_RMI_(p, v) * conv("€", "k€", 1e-3)), "DEF_C_TOT_RMI_", )
## -------------------------------------------------------------------------------------
m.addConstr(v.C_TOT_ == quicksum(c.C_TOT_.values()), "total_cost_balance")
m.addConstr(
v.CE_TOT_ == p.k__PartYearComp_ * quicksum(c.CE_TOT_.values()),
"carbon_emission_balance",
)
m.addConstrs(
(
quicksum(x(t) for x in c.P_EL_source_T.values())
== quicksum(x(t) for x in c.P_EL_sink_T.values())
for t in d.T
),
"electricity_balance",
)
if c.dH_hydrogen_source_T:
m.addConstrs(
(
quicksum(x(t) for x in c.dH_hydrogen_source_T.values())
== quicksum(x(t) for x in c.dH_hydrogen_sink_T.values())
for t in d.T
),
"hydrogen_balance",
)
if hasattr(d, "N"):
m.addConstrs(
(
quicksum(x(t, n) for x in c.dQ_cooling_source_TN.values())
== quicksum(x(t, n) for x in c.dQ_cooling_sink_TN.values())
for t in d.T
for n in d.N
),
"cool_balance",
)
if hasattr(d, "H"):
m.addConstrs(
(
quicksum(x(t, h) for x in c.dQ_heating_source_TH.values())
== quicksum(x(t, h) for x in c.dQ_heating_sink_TH.values())
for t in d.T
for h in d.H
),
"heat_balance",
)
@dataclass
class cDem(Component):
"""Cooling demand"""
def dim_func(self, sc: Scenario):
sc.dim("N", data=["7/12", "30/35"], doc="Cooling temperature levels (inlet / outlet) in °C")
def param_func(self, sc: Scenario):
sc.param(name="dQ_cDem_TN", fill=0, doc="Cooling demand", unit="kW_th")
sc.params.dQ_cDem_TN.loc[:, sc.dims.N[0]] = sc.prep.dQ_cDem_T(annual_energy=1e4).values
sc.param(
"T_cDem_in_N",
data=[int(i.split("/")[0]) for i in sc.dims.N],
doc="Cooling inlet temperature",
unit="°C",
)
sc.param(
"T_cDem_out_N",
data=[int(i.split("/")[1]) for i in sc.dims.N],
doc="Cooling outlet temperature",
unit="°C",
)
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
c.dQ_cooling_source_TN["cDem"] = lambda t, n: p.dQ_cDem_TN[t, n]
@dataclass
class hDem(Component):
"""Heating demand"""
def dim_func(self, sc: Scenario):
sc.dim(
"H", data=["90/60", "70/40"], doc="Heating temperature levels (inlet / outlet) in °C"
)
def param_func(self, sc: Scenario):
sc.param(name="dQ_hDem_TH", fill=0, doc="Heating demand", unit="kW_th")
sc.params.dQ_hDem_TH.loc[:, sc.dims.H[0]] = sc.prep.dQ_hDem_T(annual_energy=1e6).values
sc.param(
"T_hDem_in_H",
data=[int(i.split("/")[0]) for i in sc.dims.H],
doc="Heating inlet temperature",
unit="°C",
)
sc.param(
"T_hDem_out_H",
data=[int(i.split("/")[1]) for i in sc.dims.H],
doc="Heating outlet temperature",
unit="°C",
)
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
c.dQ_heating_sink_TH["hDem"] = lambda t, h: p.dQ_hDem_TH[t, h]
@dataclass
class eDem(Component):
"""Electricity demand"""
p_el: Optional[pd.Series] = None
profile: str = "G3"
annual_energy: float = 5e6
def param_func(self, sc: Scenario):
if self.p_el is None:
sc.prep.P_eDem_T(profile=self.profile, annual_energy=self.annual_energy)
else:
sc.param("P_eDem_T", data=self.p_el, doc="Electricity demand", unit="kW_el")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
c.P_EL_sink_T["eDem"] = lambda t: p.P_eDem_T[t]
@dataclass
class EG(Component):
"""Electricity grid"""
c_buyPeak: float = 50.0
prepared_tariffs: Tuple = ("FLAT", "TOU", "RTP")
selected_tariff: str = "RTP"
consider_intensiveGridUse: bool = False
feedin_reduces_emissions: bool = False
maxsell: float = 20e3
maxbuy: float = 20e3
def param_func(self, sc: Scenario):
sc.collector("P_EG_sell_T", doc="Sold electricity power", unit="kW_el")
sc.param("c_EG_buyPeak_", data=self.c_buyPeak, doc="Peak price", unit="€/kW_el/a")
if "RTP" in self.prepared_tariffs:
sc.prep.c_EG_RTP_T()
if "TOU" in self.prepared_tariffs:
sc.prep.c_EG_RTP_T()
sc.prep.c_EG_TOU_T()
if "FLAT" in self.prepared_tariffs:
sc.prep.c_EG_RTP_T()
sc.prep.c_EG_FLAT_T()
sc.param(
"c_EG_T",
data=getattr(sc.params, f"c_EG_{self.selected_tariff}_T"),
doc="Chosen electricity tariff",
unit="€/kWh_el",
)
sc.prep.c_EG_addon_()
sc.prep.ce_EG_T()
sc.param("t_EG_minFLH_", data=0, doc="Minimal full load hours", unit="h")
sc.var("P_EG_buy_T", doc="Purchased electrical power", unit="kW_el")
sc.var("P_EG_sell_T", doc="Selling electrical power", unit="kW_el", ub=self.maxsell)
sc.var("P_EG_buyPeak_", doc="Peak electrical power", unit="kW_el", ub=self.maxbuy)
if self.consider_intensiveGridUse:
# FIXME: Currently not working
sc.dim(
"G",
data=["7000-7500", "7500-8000", ">8000"],
doc="Full load hour sections for indensive grid use",
)
sc.var("Y_EG_FLH_G", doc="If full load hour section applies", vtype=GRB.BINARY)
sc.param("t_EG_minFLH_G", data=[7000, 7500, 8000], unit="h")
sc.param(
"k_EG_FLH_G",
data=[0.8, 0.85, 0.9],
doc="Peak price reduction factor if full load hour section applies",
src="@Tieman_2020",
)
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
m.addConstrs(
(v.P_EG_sell_T[t] == sum(x(t) for x in c.P_EG_sell_T.values()) for t in d.T), "EG_sell"
)
m.addConstrs((v.P_EG_buy_T[t] <= v.P_EG_buyPeak_ for t in d.T), "EG_peak_price")
if p.t_EG_minFLH_ > 0:
m.addConstr(
v.P_EG_buy_T.sum() * p.k__dT_ * p.k__PartYearComp_
>= p.t_EG_minFLH_ * v.P_EG_buyPeak_,
"EG_minimum_full_load_hours",
)
if self.consider_intensiveGridUse:
m.addConstrs(
(
v.P_EG_buy_T.sum() * p.k__dT_ * p.k__PartYearComp_
>= p.t_EG_minFLH_G[g] * v.Y_EG_FLH_G[g] * v.P_EG_buyPeak_
for g in d.G
),
"EG_intensive_grid_use",
)
m.addConstr(v.Y_EG_FLH_G.sum() <= 1, "DEF_FLH_2")
c.P_EL_source_T["EG"] = lambda t: v.P_EG_buy_T[t]
c.P_EL_sink_T["EG"] = lambda t: v.P_EG_sell_T[t]
igu_factor = (1 - v.Y_EG_FLH_G.prod(p.k_EG_FLH_G)) if self.consider_intensiveGridUse else 1
c.C_TOT_op_["EG_peak"] = (
v.P_EG_buyPeak_ * igu_factor * p.c_EG_buyPeak_ * conv("€", "k€", 1e-3)
)
c.C_TOT_op_["EG"] = (
p.k__dT_
* p.k__PartYearComp_
* quicksum(
v.P_EG_buy_T[t] * (p.c_EG_T[t] + p.c_EG_addon_) - v.P_EG_sell_T[t] * p.c_EG_T[t]
for t in d.T
)
* conv("€", "k€", 1e-3)
)
if self.feedin_reduces_emissions:
c.CE_TOT_["EG"] = (
p.k__dT_
* p.k__PartYearComp_
* quicksum(p.ce_EG_T[t] * (v.P_EG_buy_T[t] - v.P_EG_sell_T[t]) for t in d.T)
)
else:
c.CE_TOT_["EG"] = (
p.k__dT_
* p.k__PartYearComp_
* quicksum(p.ce_EG_T[t] * (v.P_EG_buy_T[t]) for t in d.T)
)
def postprocess_func(self, r: Results):
r.make_pos_ent("P_EG_buy_T")
@dataclass
class Fuel(Component):
"""Fuels"""
c_ceTax: float = 55
def dim_func(self, sc: Scenario):
sc.dim("F", ["ng", "bio"], doc="Types of fuel")
def param_func(self, sc: Scenario):
sc.collector("F_fuel_F", doc="Fuel power", unit="kWh")
sc.param(from_db=db.c_Fuel_F)
sc.param("c_Fuel_ceTax_", data=self.c_ceTax, doc="Carbon tax on fuel", unit="€/tCO2eq")
sc.param(from_db=db.ce_Fuel_F)
sc.var("C_Fuel_ceTax_", doc="Total carbon tax on fuel", unit="k€/a")
sc.var("CE_Fuel_", doc="Total carbon emissions for fuel", unit="kgCO2eq/a")
sc.var("C_Fuel_", doc="Total cost for fuel", unit="k€/a")
sc.var("F_fuel_F", doc="Total fuel consumption", unit="kW")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
m.addConstrs(
(v.F_fuel_F[f] == quicksum(x(f) for x in c.F_fuel_F.values()) for f in d.F),
"fuel_balance",
)
m.addConstr(v.CE_Fuel_ == p.k__dT_ * v.F_fuel_F.prod(p.ce_Fuel_F))
m.addConstr(v.C_Fuel_ == p.k__dT_ * v.F_fuel_F.prod(p.c_Fuel_F) * conv("€", "k€", 1e-3))
m.addConstr(
v.C_Fuel_ceTax_
== p.c_Fuel_ceTax_ * conv("/t", "(/kg", 1e-3) * v.CE_Fuel_ * conv("€", "k€", 1e-3)
)
c.CE_TOT_["Fuel"] = v.CE_Fuel_
c.C_TOT_op_["Fuel"] = p.k__PartYearComp_ * v.C_Fuel_
c.C_TOT_op_["FuelCeTax"] = p.k__PartYearComp_ * v.C_Fuel_ceTax_
@dataclass
class BES(Component):
"""Battery Energy Storage"""
E_CAPx: float = 0
allow_new: bool = True
def param_func(self, sc: Scenario):
sc.param("E_BES_CAPx_", data=self.E_CAPx, doc="Existing capacity", unit="kWh_el")
sc.param("k_BES_ini_", data=0, doc="Initial and final energy filling share")
sc.param(
"eta_BES_ch_",
data=db.eta_BES_cycle_.data**0.5,
doc="Charging efficiency",
src="@Carroquino_2021",
)
sc.param(
"eta_BES_dis_",
data=db.eta_BES_cycle_.data**0.5,
doc="Discharging efficiency",
src="@Carroquino_2021",
)
sc.param(from_db=db.eta_BES_self_)
sc.param(from_db=db.k_BES_inPerCap_)
sc.param(from_db=db.k_BES_outPerCap_)
sc.var("E_BES_T", doc="Electricity stored", unit="kWh_el")
sc.var("P_BES_in_T", doc="Charging power", unit="kW_el")
sc.var("P_BES_out_T", doc="Discharging power", unit="kW_el")
if sc.consider_invest:
sc.param(from_db=db.k_BES_RMI_)
sc.param(from_db=db.N_BES_)
sc.param("z_BES_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.funcs.c_BES_inv_(estimated_size=100, which="mean"))
sc.var("E_BES_CAPn_", doc="New capacity", unit="kWh_el")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
"""Note: In this model does not prevent simultaneous charging and discharging,
which can appear negativ electricity prices. To avoid this behaviour expensive binary
variables can be introduced, e.g., like in
AmirMansouri.2021: https://doi.org/10.1016/j.seta.2021.101376
"""
cap = p.E_BES_CAPx_ + v.E_BES_CAPn_ if sc.consider_invest else p.E_BES_CAPx_
m.addConstrs(
(v.P_BES_in_T[t] <= p.k_BES_inPerCap_ * cap for t in d.T), "BES_limit_charging_power"
)
m.addConstrs(
(v.P_BES_out_T[t] <= p.k_BES_outPerCap_ * cap for t in d.T),
"BES_limit_discharging_power",
)
m.addConstrs((v.E_BES_T[t] <= cap for t in d.T), "BES_limit_cap")
m.addConstr((v.E_BES_T[d.T[-1]] == p.k_BES_ini_ * cap), "BES_last_timestep")
m.addConstrs(
(
v.E_BES_T[t]
== (p.k_BES_ini_ * cap if t == d.T[0] else v.E_BES_T[t - 1])
* (1 - p.eta_BES_self_ * p.k__dT_)
+ (v.P_BES_in_T[t] * p.eta_BES_ch_ - v.P_BES_out_T[t] / p.eta_BES_dis_) * p.k__dT_
for t in d.T
),
"BES_electricity_balance",
)
c.P_EL_source_T["BES"] = lambda t: v.P_BES_out_T[t]
c.P_EL_sink_T["BES"] = lambda t: v.P_BES_in_T[t]
if sc.consider_invest:
m.addConstr((v.E_BES_CAPn_ <= p.z_BES_ * 1e6), "BES_limit_new_capa")
C_inv_ = v.E_BES_CAPn_ * p.c_BES_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["BES"] = C_inv_
c.C_TOT_invAnn_["BES"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_BES_)
c.C_TOT_RMI_["BES"] = C_inv_ * p.k_BES_RMI_
@dataclass
class PV(Component):
"""Photovoltaic System"""
P_CAPx: float = 0
A_avail_: float = 100
allow_new: bool = True
def param_func(self, sc: Scenario):
sc.param("P_PV_CAPx_", data=self.P_CAPx, doc="Existing capacity", unit="kW_peak")
sc.prep.P_PV_profile_T(use_coords=True)
sc.var("P_PV_FI_T", doc="Feed-in", unit="kW_el")
sc.var("P_PV_OC_T", doc="Own consumption", unit="kW_el")
sc.param(
"A_PV_PerPeak_",
data=6.5,
doc="Area efficiency of new PV",
unit="m²/kW_peak",
src="https://www.dachvermieten.net/wieviel-qm-dachflaeche-fuer-1-kw-kilowatt",
)
sc.param("A_PV_avail_", data=self.A_avail_, doc="Area available for new PV", unit="m²")
if sc.consider_invest:
sc.param("z_PV_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.funcs.c_PV_inv_())
sc.param(from_db=db.k_PV_RMI_)
sc.param(from_db=db.N_PV_)
sc.var("P_PV_CAPn_", doc="New capacity", unit="kW_peak")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
cap = p.P_PV_CAPx_ + v.P_PV_CAPn_ if sc.consider_invest else p.P_PV_CAPx_
m.addConstrs(
(cap * p.P_PV_profile_T[t] == v.P_PV_FI_T[t] + v.P_PV_OC_T[t] for t in d.T),
"PV_balance",
)
c.P_EL_source_T["PV"] = lambda t: v.P_PV_FI_T[t] + v.P_PV_OC_T[t]
c.P_EG_sell_T["PV"] = lambda t: v.P_PV_FI_T[t]
if sc.consider_invest:
m.addConstr(v.P_PV_CAPn_ <= p.z_PV_ * p.A_PV_avail_ / p.A_PV_PerPeak_, "PV_limit_capn")
C_inv_ = v.P_PV_CAPn_ * p.c_PV_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["PV"] = C_inv_
c.C_TOT_invAnn_["PV"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_PV_)
c.C_TOT_RMI_["PV"] = C_inv_ * p.k_PV_RMI_
@dataclass
class WT(Component):
"""Wind turbine"""
P_CAPx: float = 0
allow_new: bool = True
pay_network_tariffs: bool = True
def param_func(self, sc: Scenario):
sc.param("P_WT_CAPx_", data=self.P_CAPx, doc="Existing capacity", unit="kW_peak")
sc.param(
"P_WT_profile_T",
data=hp.read(DATA_DIR / "wind/2019_wind_kelmarsh2.csv"),
doc="Wind profile",
unit="kW_el",
)
sc.param(
"y_WT_pnt_",
data=int(self.pay_network_tariffs),
doc="If `c_EG_addon_` is paid on own wind energy consumption (e.g. for off-site PPA)",
)
sc.var("P_WT_FI_T", doc="Feed-in", unit="kW_el")
sc.var("P_WT_OC_T", doc="Own consumption", unit="kW_el")
if sc.consider_invest:
sc.param("P_WT_max_", data=1e5, doc="Maximum installed capacity", unit="kW_peak")
sc.param("z_WT_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(
"c_WT_inv_",
data=1682,
doc="CAPEX",
unit="€/kW_peak",
src="https://windeurope.org/newsroom/press-releases/europe-invested-41-bn-euros-in-new-wind-farms-in-2021",
) # or 1118.77 €/kWp invest and 27 years operation life for onshore wind https://github.com/PyPSA/technology-data/blob/4eaddec90f429246445f08476b724393dde753c8/outputs/costs_2020.csv
sc.param(
"k_WT_RMI_",
data=0.01,
doc=Descs.RMI.en,
unit="",
src="https://www.npro.energy/main/en/help/economic-parameters",
)
sc.param(
"N_WT_",
data=20,
doc="Operation life",
unit="a",
src="https://www.twi-global.com/technical-knowledge/faqs/how-long-do-wind-turbines-last",
)
sc.var("P_WT_CAPn_", doc="New capacity", unit="kW_peak")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
cap = p.P_WT_CAPx_ + v.P_WT_CAPn_ if sc.consider_invest else p.P_WT_CAPx_
m.addConstrs(
(cap * p.P_WT_profile_T[t] == v.P_WT_FI_T[t] + v.P_WT_OC_T[t] for t in d.T),
"WT_balance",
)
c.P_EL_source_T["WT"] = lambda t: v.P_WT_FI_T[t] + v.P_WT_OC_T[t]
c.P_EG_sell_T["WT"] = lambda t: v.P_WT_FI_T[t]
if p.y_WT_pnt_:
c.C_TOT_op_["WT"] = (
p.k__dT_
* p.k__PartYearComp_
* v.P_WT_OC_T.sum()
* p.c_EG_addon_
* conv("€", "k€", 1e-3)
)
if sc.consider_invest:
m.addConstr(v.P_WT_CAPn_ <= p.z_WT_ * p.P_WT_max_, "WT_limit_capn")
C_inv_ = v.P_WT_CAPn_ * p.c_WT_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["WT"] = C_inv_
c.C_TOT_invAnn_["WT"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_WT_)
c.C_TOT_RMI_["WT"] = C_inv_ * p.k_WT_RMI_
@dataclass
class HP(Component):
"""Electric heat pump"""
dQ_CAPx: float = 0
allow_new: bool = True
time_dependent_amb: bool = True
n: int = 1
heating_levels: Optional[List] = None
cooling_levels: Optional[List] = None
ambient_as_sink: bool = True
ambient_as_source: bool = True
def dim_func(self, sc: Scenario):
def get_E():
e = ["E_amb"] if self.ambient_as_source else []
e += sc.dims.N if self.cooling_levels is None else self.cooling_levels
return e
def get_C():
c = ["C_amb"] if self.ambient_as_sink else []
c += sc.dims.H if self.heating_levels is None else self.heating_levels
return c
sc.dim("E", data=get_E(), doc="Evaporation temperature levels")
sc.dim("C", data=get_C(), doc="Condensing temperature levels")
def param_func(self, sc: Scenario):
p = sc.params
sc.collector("dQ_amb_source_", doc="Thermal energy flow to ambient", unit="kW_th")
sc.collector("dQ_amb_sink_", doc="Thermal energy flow from ambient", unit="kW_th")
if self.time_dependent_amb:
sc.prep.T__amb_T()
sc.param("T__amb_", data=25, doc="Approximator for ambient air", unit="°C")
sc.param(
"T_HP_Cond_C", data=p.T_hDem_in_H + 5, doc="Condensation side temperature", unit="°C"
)
sc.param(
"T_HP_Eva_E", data=p.T_cDem_in_N - 5, doc="Evaporation side temperature", unit="°C"
)
sc.param("n_HP_", data=self.n, doc="Maximum number of parallel operation modes")
sc.param(
"eta_HP_",
data=0.5,
doc="Ratio of reaching the ideal COP (exergy efficiency)",
src="@Arat_2017",
# Cox_2022 used 0.45: https://doi.org/10.1016/j.apenergy.2021.118499
# but roughly 0.5 in recent real operation of high temperature HP: https://www.waermepumpe.de/fileadmin/user_upload/waermepumpe/01_Verband/Webinare/Vortrag_Wilk_AIT_02062020.pdf
)
sc.param("dQ_HP_CAPx_", data=self.dQ_CAPx, doc="Existing heating capacity", unit="kW_th")
sc.param(
"dQ_HP_max_", data=1e5, doc="Big-M number (upper bound for CAPn + CAPx)", unit="kW_th"
)
sc.var("P_HP_TEC", doc="Consuming power", unit="kW_el")
sc.var("dQ_HP_Cond_TEC", doc="Heat flow released on condensation side", unit="kW_th")
sc.var("dQ_HP_Eva_TEC", doc="Heat flow absorbed on evaporation side", unit="kW_th")
sc.var("Y_HP_TEC", doc="If source and sink are connected at time-step", vtype=GRB.BINARY)
if sc.consider_invest:
sc.param("z_HP_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.k_HP_RMI_)
sc.param(from_db=db.N_HP_)
sc.param(from_db=db.funcs.c_HP_inv_())
sc.var("dQ_HP_CAPn_", doc="New heating capacity", unit="kW_th")
def get_cop_via_hplib(
self, t_eva: pd.Series, t_cond: pd.Series, type: str = "air", regulated: bool = True
):
"""UNUSED: Get the heating COP from the hplib package https://github.com/RE-Lab-Projects/hplib
TODO: integrate this function in model_func
Args:
t_eva: Evaporation temperature time series
t_cond: Condenstaion temperature time series
type: on of 'air', 'brine'
regulated: If the heat pump is regulated (Otherwise On-Off)
"""
import hplib as hpl
group_id = 1 if type == "air" else 2
if not regulated:
group_id += 3
pars = hpl.get_parameters(model="Generic", group_id=group_id, t_in=-7, t_out=52, p_th=1e4)
results = hpl.simulate(
t_in_primary=t_eva, t_in_secondary=t_cond, t_amb=t_eva, parameters=pars
)
return results["COP"]
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
def get_cop(t, e, c):
T_amb = p.T__amb_T[t] if self.time_dependent_amb else p.T__amb_
T_cond = T_amb + 5 if c == "C_amb" else p.T_HP_Cond_C[c]
T_eva = T_amb - 5 if e == "E_amb" else p.T_HP_Eva_E[e]
return 100 if T_cond <= T_eva else p.eta_HP_ * (T_cond + 273) / (T_cond - T_eva)
m.addConstrs(
(
v.dQ_HP_Cond_TEC[t, e, c] == v.P_HP_TEC[t, e, c] * get_cop(t, e, c)
for t in d.T
for e in d.E
for c in d.C
),
"HP_balance_1",
)
m.addConstrs(
(
v.dQ_HP_Cond_TEC[t, e, c] == v.dQ_HP_Eva_TEC[t, e, c] + v.P_HP_TEC[t, e, c]
for t in d.T
for e in d.E
for c in d.C
),
"HP_balance_2",
)
m.addConstrs(
(
v.dQ_HP_Cond_TEC[t, e, c] <= v.Y_HP_TEC[t, e, c] * p.dQ_HP_max_
for t in d.T
for e in d.E
for c in d.C
),
"HP_bigM",
)
if ("E_amb" in d.E) and ("C_amb" in d.C):
# Avoid E_amb --> C_amb HP operation occur due to negative electricity prices
m.addConstr((v.Y_HP_TEC.sum("*", "E_amb", "C_amb") == 0), "HP_no_Eamb_to_C_amb")
cap = p.dQ_HP_CAPx_ + v.dQ_HP_CAPn_ if sc.consider_invest else p.dQ_HP_CAPx_
m.addConstrs((v.dQ_HP_Cond_TEC.sum(t, "*", "*") <= cap for t in d.T), "HP_limit_cap")
m.addConstrs((v.Y_HP_TEC.sum(t, "*", "*") <= p.n_HP_ for t in d.T), "HP_operating_mode")
c.P_EL_sink_T["HP"] = lambda t: v.P_HP_TEC.sum(t, "*", "*")
c.dQ_cooling_sink_TN["HP"] = lambda t, n: v.dQ_HP_Eva_TEC.sum(t, n, "*")
c.dQ_heating_source_TH["HP"] = lambda t, h: v.dQ_HP_Cond_TEC.sum(t, "*", h)
c.dQ_amb_sink_["HP"] = v.dQ_HP_Eva_TEC.sum("*", "E_amb", "*") * p.k__dT_
c.dQ_amb_source_["HP"] = v.dQ_HP_Cond_TEC.sum("*", "*", "C_amb") * p.k__dT_
if sc.consider_invest:
m.addConstr((v.dQ_HP_CAPn_ <= p.z_HP_ * 1e6), "HP_limit_capn")
C_inv_ = v.dQ_HP_CAPn_ * p.c_HP_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["HP"] = C_inv_
c.C_TOT_invAnn_["HP"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_HP_)
c.C_TOT_RMI_["HP"] = C_inv_ * p.k_HP_RMI_
@dataclass
class P2H(Component):
"""Power to heat"""
dQ_CAPx: float = 0
allow_new: bool = True
H_level_target: str = "90/60"
def param_func(self, sc: Scenario):
sc.param("dQ_P2H_CAPx_", data=self.dQ_CAPx, doc="Existing capacity", unit="kW_th")
sc.param(from_db=db.eta_P2H_)
sc.var("P_P2H_T", doc="Consuming power", unit="kW_el")
sc.var("dQ_P2H_T", doc="Producing heat flow", unit="kW_th")
if sc.consider_invest:
sc.param(from_db=db.N_P2H_)
sc.param("z_P2H_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.c_P2H_inv_)
sc.param("k_P2H_RMI_", data=0, doc=Descs.RMI.en)
sc.var("dQ_P2H_CAPn_", doc="New capacity", unit="kW_th")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
cap = p.dQ_P2H_CAPx_ + v.dQ_P2H_CAPn_ if sc.consider_invest else p.dQ_P2H_CAPx_
m.addConstrs((v.dQ_P2H_T[t] == p.eta_P2H_ * v.P_P2H_T[t] for t in d.T), "P2H_balance")
m.addConstrs((v.dQ_P2H_T[t] <= cap for t in d.T), "P2H_limit_heat_flow")
c.dQ_heating_source_TH["P2H"] = (
lambda t, h: v.dQ_P2H_T[t] if h == self.H_level_target else 0
)
c.P_EL_sink_T["P2H"] = lambda t: v.P_P2H_T[t]
if sc.consider_invest:
m.addConstr((v.dQ_P2H_CAPn_ <= p.z_P2H_ * 1e6), "P2H_limit_new_capa")
C_inv_ = v.dQ_P2H_CAPn_ * p.c_P2H_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["P2H"] = C_inv_
c.C_TOT_invAnn_["P2H"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_P2H_)
c.C_TOT_RMI_["P2H"] = C_inv_ * p.k_P2H_RMI_
@dataclass
class DAC(Component):
"""Direct air capture: More precisely carbon offsetting through direct air carbon capture
and storage. Reduces total carbon emissions for a price per unit of carbon emissions.
"""
allow_new: bool = True
def param_func(self, sc: Scenario):
sc.param("z_DAC_", data=int(self.allow_new), doc="If DAC is allowed")
sc.param(
"c_DAC_",
data=222,
doc="Cost of direct air capture and storage",
unit="€/tCO2eq",
src="https://doi.org/10.1016/j.jclepro.2019.03.086",
)
sc.var("CE_DAC_", doc="Carbon emissions captured and stored by DAC", unit="kgCO2eq/a")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
c.C_TOT_op_["DAC"] = v.CE_DAC_ * p.c_DAC_ * conv("€", "k€", 1e-3) * conv("/t", "/kg", 1e-3)
c.CE_TOT_["DAC"] = -v.CE_DAC_
@dataclass
class CHP(Component):
"""Combined heat and power"""
P_CAPx: float = 0
allow_new: bool = True
H_level_target: str = "90/60"
minPL: Optional[float] = 0.5
def param_func(self, sc: Scenario):
sc.param("P_CHP_CAPx_", data=self.P_CAPx, doc="Existing capacity", unit="kW_el")
sc.param(
"P_CHP_max_", data=1e5, doc="Big-M number (upper bound for CAPn + CAPx)", unit="kW_el"
)
sc.param(from_db=db.funcs.eta_CHP_el_(fuel="ng"))
sc.param(from_db=db.funcs.eta_CHP_th_(fuel="ng"))
sc.var("dQ_CHP_T", doc="Producing heat flow", unit="kW_th")
sc.var("F_CHP_TF", doc="Consumed fuel flow", unit="kW")
sc.var("P_CHP_FI_T", doc="Feed-in", unit="kW_el")
sc.var("P_CHP_OC_T", doc="Own consumption", unit="kW_el")
sc.var("P_CHP_T", doc="Producing power", unit="kW_el")
if self.minPL is not None:
sc.param("k_CHP_minPL_", data=0.5, doc="Minimal allowed part load")
sc.var("Y_CHP_T", doc="If in operation", vtype=GRB.BINARY)
if sc.consider_invest:
sc.param("z_CHP_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.funcs.c_CHP_inv_(estimated_size=400, fuel_type="ng"))
sc.param(from_db=db.k_CHP_RMI_)
sc.param(from_db=db.N_CHP_)
sc.var("P_CHP_CAPn_", doc="New capacity", unit="kW_el")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
m.addConstrs(
(v.P_CHP_T[t] == p.eta_CHP_el_ * quicksum(v.F_CHP_TF[t, f] for f in d.F) for t in d.T),
"CHP_elec_balance",
)
m.addConstrs(
(v.dQ_CHP_T[t] == p.eta_CHP_th_ * quicksum(v.F_CHP_TF[t, f] for f in d.F) for t in d.T),
"CHP_heat_balance",
)
cap = p.P_CHP_CAPx_ + v.P_CHP_CAPn_ if sc.consider_invest else p.P_CHP_CAPx_
m.addConstrs((v.P_CHP_T[t] <= cap for t in d.T), "CHP_limit_elecPower")
m.addConstrs(
(v.P_CHP_T[t] == v.P_CHP_FI_T[t] + v.P_CHP_OC_T[t] for t in d.T),
"CHP_feedIn_vs_ownConsumption",
)
if self.minPL:
m.addConstrs(
(v.P_CHP_T[t] <= v.Y_CHP_T[t] * p.P_CHP_max_ for t in d.T),
"CHP_minimal_part_load_1",
)
m.addConstrs(
(
v.P_CHP_T[t] >= p.k_CHP_minPL_ * cap - p.P_CHP_max_ * (1 - v.Y_CHP_T[t])
for t in d.T
),
"CHP_minimal_part_load_2",
)
c.P_EL_source_T["CHP"] = lambda t: v.P_CHP_FI_T[t] + v.P_CHP_OC_T[t]
c.dQ_heating_source_TH["CHP"] = (
lambda t, h: v.dQ_CHP_T[t] if h == self.H_level_target else 0
)
c.P_EG_sell_T["CHP"] = lambda t: v.P_CHP_FI_T[t]
c.F_fuel_F["CHP"] = lambda f: v.F_CHP_TF.sum("*", f) * p.k__dT_
if sc.consider_invest:
m.addConstr((v.P_CHP_CAPn_ <= p.z_CHP_ * 1e6), "CHP_limit_new_capa")
C_inv_ = v.P_CHP_CAPn_ * p.c_CHP_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["CHP"] = C_inv_
c.C_TOT_invAnn_["CHP"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_CHP_)
c.C_TOT_RMI_["CHP"] = C_inv_ * p.k_CHP_RMI_
@dataclass
class HOB(Component):
"""Heat-only boiler"""
dQ_CAPx: float = 0
allow_new: bool = True
H_level_target: str = "90/60"
def param_func(self, sc: Scenario):
sc.param("dQ_HOB_CAPx_", data=self.dQ_CAPx, doc="Existing capacity", unit="kW_th")
sc.param("eta_HOB_", from_db=db.eta_HOB_)
sc.var("dQ_HOB_T", doc="Ouput heat flow", unit="kW_th")
sc.var("F_HOB_TF", doc="Input fuel flow", unit="kW")
if sc.consider_invest:
sc.param(from_db=db.funcs.c_HOB_inv_())
sc.param(from_db=db.k_HOB_RMI_)
sc.param(from_db=db.N_HOB_)
sc.param("z_HOB_", data=int(self.allow_new), doc="If new capacity is allowed")
sc.var("dQ_HOB_CAPn_", doc="New capacity", unit="kW_th")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
cap = p.dQ_HOB_CAPx_ + v.dQ_HOB_CAPn_ if sc.consider_invest else p.dQ_HOB_CAPx_
m.addConstrs((v.dQ_HOB_T[t] == v.F_HOB_TF.sum(t, "*") * p.eta_HOB_ for t in d.T), "HOB_bal")
m.addConstrs((v.dQ_HOB_T[t] <= cap for t in d.T), "HOB_limit_heat_flow")
c.dQ_heating_source_TH["HOB"] = (
lambda t, h: v.dQ_HOB_T[t] if h == self.H_level_target else 0
)
c.F_fuel_F["HOB"] = lambda f: v.F_HOB_TF.sum("*", f) * p.k__dT_
if sc.consider_invest:
m.addConstr((v.dQ_HOB_CAPn_ <= p.z_HOB_ * 1e6), "HOB_limit_new_capa")
C_inv_ = v.dQ_HOB_CAPn_ * p.c_HOB_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["HOB"] = C_inv_
c.C_TOT_invAnn_["HOB"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_HOB_)
c.C_TOT_RMI_["HOB"] = C_inv_ * p.k_HOB_RMI_
@dataclass
class TES(Component):
"""Thermal energy storage"""
allow_new: bool = True
def dim_func(self, sc: Scenario):
d = sc.dims
L = []
if hasattr(d, "N"):
L += d.N
if hasattr(d, "H"):
L += d.H
sc.dim("L", data=L, doc="Thermal demand temperature levels (inlet / outlet) in °C")
def param_func(self, sc: Scenario):
sc.param("Q_TES_CAPx_L", fill=0, doc="Existing capacity", unit="kWh_th")
sc.param("eta_TES_self_", data=0.005, doc="Self-discharge")
sc.param("k_TES_inPerCap_", data=0.5, doc="Ratio loading power / capacity")
sc.param("k_TES_outPerCap_", data=0.5, doc="Ratio loading power / capacity")
sc.param("k_TES_ini_L", fill=0.5, doc="Initial and final energy level share")
sc.var("dQ_TES_in_TL", doc="Storage input heat flow", unit="kW_th", lb=-GRB.INFINITY)
sc.var("Q_TES_TL", doc="Stored heat", unit="kWh_th")
if sc.consider_invest:
sc.param("z_TES_L", fill=int(self.allow_new), doc="If new capacity is allowed")
sc.param(from_db=db.funcs.c_TES_inv_(estimated_size=100, temp_spread=40))
sc.param(from_db=db.k_TES_RMI_)
sc.param(from_db=db.N_TES_)
sc.var("Q_TES_CAPn_L", doc="New capacity", unit="kWh_th", ub=1e7)
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
cap = lambda l: p.Q_TES_CAPx_L[l] + (
v.Q_TES_CAPn_L[l] if sc.consider_invest else p.Q_TES_CAPx_L[l]
)
m.addConstrs(
(
v.Q_TES_TL[t, l]
== ((p.k_TES_ini_L[l] * cap(l)) if t == d.T[0] else v.Q_TES_TL[t - 1, l])
* (1 - p.eta_TES_self_ * p.k__dT_)
+ p.k__dT_ * v.dQ_TES_in_TL[t, l]
for t in d.T
for l in d.L
),
"TES_balance",
)
m.addConstrs((v.Q_TES_TL[t, l] <= cap(l) for t in d.T for l in d.L), "TES_limit_cap")
m.addConstrs(
(v.dQ_TES_in_TL[t, l] <= p.k_TES_inPerCap_ * cap(l) for t in d.T for l in d.L),
"TES_limit_in",
)
m.addConstrs(
(v.dQ_TES_in_TL[t, l] >= -p.k_TES_outPerCap_ * cap(l) for t in d.T for l in d.L),
"TES_limit_out",
)
m.addConstrs(
(v.Q_TES_TL[d.T[-1], l] == p.k_TES_ini_L[l] * cap(l) for l in d.L), "TES_last_timestep"
)
# only sink here, since dQ_TES_in_TL is also defined for negative
# values to reduce number of variables:
c.dQ_cooling_sink_TN["TES"] = lambda t, n: v.dQ_TES_in_TL[t, n]
c.dQ_heating_sink_TH["TES"] = lambda t, h: v.dQ_TES_in_TL[t, h]
if sc.consider_invest:
m.addConstrs((v.Q_TES_CAPn_L[l] <= p.z_TES_L[l] * 1e5 for l in d.L), "TES_limit_capn")
C_inv_ = v.Q_TES_CAPn_L.sum() * p.c_TES_inv_ * conv("€", "k€", 1e-3)
c.C_TOT_inv_["TES"] = C_inv_
c.C_TOT_invAnn_["TES"] = C_inv_ * get_annuity_factor(r=p.k__r_, N=p.N_TES_)
c.C_TOT_RMI_["TES"] = C_inv_ * p.k_TES_RMI_
def postprocess_func(self, r: Results):
r.make_pos_ent("dQ_TES_in_TL", "dQ_TES_out_TL", "Storage output heat flow")
@dataclass
class HD(Component):
"""Heat downgrading"""
from_level: str = "90/60"
to_level: str = "70/40"
def param_func(self, sc: Scenario):
sc.var("dQ_HD_T", doc="Heat down-grading", unit="kW_th")
def model_func(self, sc: Scenario, m: Model, d: Dimensions, p: Params, v: Vars, c: Collectors):
c.dQ_heating_sink_TH["HD"] = lambda t, h: v.dQ_HD_T[t] if h == self.from_level else 0
c.dQ_heating_source_TH["HD"] = lambda t, h: v.dQ_HD_T[t] if h == self.to_level else 0
@dataclass
class BEV(Component):
"""Battery electric Vehicle"""
allow_V2X: bool = False
allow_smart: bool = False
def dim_func(self, sc: Scenario):
sc.dim("B", data=[1, 2], doc="BEV batteries")
def param_func(self, sc: Scenario):
p = sc.params
sc.param("E_BEV_CAPx_B", fill=1000, doc="Capacity of all batteries", unit="kWh_el")
sc.param(
"eta_BEV_self_",
data=0.0,
doc="Self discharge. Must be 0.0 for the uncontrolled charging in REF",
)
sc.param(
"eta_BEV_ch_",
data=db.eta_BES_cycle_.data**0.5,
doc="Charging efficiency",
src="@Carroquino_2021",
)
sc.param(
"eta_BEV_dis_",
data=db.eta_BES_cycle_.data**0.5,
doc="Discharging efficiency",
src="@Carroquino_2021",
)
sc.param("P_BEV_drive_TB", fill=0, doc="Power use", unit="kW_el")
sc.param("y_BEV_avail_TB", fill=1, doc="If BEV is available for charging at time step")
sc.param(
"k_BEV_inPerCap_B",
fill=0.7,
doc="Maximum charging power per capacity",