forked from FZJ-IEK3-VSA/FINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.py
2242 lines (2002 loc) · 94.8 KB
/
storage.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
from fine.component import Component, ComponentModel
from fine import utils
import pyomo.environ as pyomo
import warnings
import pandas as pd
import numpy as np
class Storage(Component):
"""
A Storage component can store a commodity and thus transfers it between time steps.
"""
def __init__(
self,
esM,
name,
commodity,
chargeRate=1,
dischargeRate=1,
chargeEfficiency=1,
dischargeEfficiency=1,
selfDischarge=0,
cyclicLifetime=None,
stateOfChargeMin=0,
stateOfChargeMax=1,
hasCapacityVariable=True,
capacityVariableDomain="continuous",
capacityPerPlantUnit=1,
hasIsBuiltBinaryVariable=False,
bigM=None,
doPreciseTsaModeling=False,
chargeOpRateMax=None,
chargeOpRateFix=None,
chargeTsaWeight=1,
dischargeOpRateMax=None,
dischargeOpRateFix=None,
dischargeTsaWeight=1,
isPeriodicalStorage=False,
locationalEligibility=None,
capacityMin=None,
capacityMax=None,
partLoadMin=None,
sharedPotentialID=None,
linkedQuantityID=None,
capacityFix=None,
commissioningMin=None,
commissioningMax=None,
commissioningFix=None,
isBuiltFix=None,
investPerCapacity=0,
investIfBuilt=0,
opexPerChargeOperation=0,
opexPerDischargeOperation=0,
opexPerCapacity=0,
opexIfBuilt=0,
interestRate=0.08,
economicLifetime=10,
technicalLifetime=None,
floorTechnicalLifetime=True,
socOffsetDown=-1,
socOffsetUp=-1,
stockCommissioning=None,
):
"""
Constructor for creating an Storage class instance.
The Storage component specific input arguments are described below. The general component
input arguments are described in the Component class.
**Required arguments:**
:param commodity: to the component related commodity.
:type commodity: string
**Default arguments:**
:param chargeRate: ratio of the maximum storage inflow (in commodityUnit/hour) to the
storage capacity (in commodityUnit).
Example:
* A hydrogen salt cavern which can store 133 GWh_H2_LHV can be charged 0.45 GWh_H2_LHV during
one hour. The chargeRate thus equals 0.45/133 1/h.
|br| * the default value is 1
:type chargeRate: 0 <= float <=1
:param dischargeRate: ratio of the maximum storage outflow (in commodityUnit/hour) to
the storage capacity (in commodityUnit).
Example:
* A hydrogen salt cavern which can store 133 GWh_H2_LHV can be discharged 0.45 GWh_H2_LHV during
one hour. The dischargeRate thus equals 0.45/133.
|br| * the default value is 1
:type dischargeRate: 0 <= float <=1
:param chargeEfficiency: defines the efficiency with which the storage can be charged (equals
the percentage of the injected commodity that is transformed into stored commodity).
Enter 0.98 for 98% etc.
|br| * the default value is 1
:type chargeEfficiency: 0 <= float <=1
:param dischargeEfficiency: defines the efficiency with which the storage can be discharged
(equals the percentage of the withdrawn commodity that is transformed into stored commodity).
Enter 0.98 for 98% etc.
|br| * the default value is 1
:type dischargeEfficiency: 0 <= float <=1
:param selfDischarge: percentage of self-discharge from the storage during one hour
|br| * the default value is 0
:type selfDischarge: 0 <= float <=1
:param cyclicLifetime: if specified, the total number of full cycle equivalents that are supported
by the technology.
|br| * the default value is None
:type cyclicLifetime: None or positive float
:param stateOfChargeMin: threshold (percentage) that the state of charge can not drop under
|br| * the default value is 0
:type stateOfChargeMin: 0 <= float <=1
:param stateOfChargeMax: threshold (percentage) that the state of charge can not exceed
|br| * the default value is 1
:type stateOfChargeMax: 0 <= float <=1
:param doPreciseTsaModeling: determines whether the state of charge is limited precisely (True) or
with a simplified method (False). The error is small if the selfDischarge is small.
|br| * the default value is False
:type doPreciseTsaModeling: boolean
:param chargeOpRateMax: if specified, indicates a maximum charging rate for each location and each time
step, if required also for each investment period, by a positive float. If hasCapacityVariable is set to True, the values are given relative
to the installed capacities (i.e. a value of 1 indicates a utilization of 100% of the
capacity). If hasCapacityVariable is set to False, the values are given as absolute values in form
of the commodityUnit, referring to the charged commodity (before multiplying the charging efficiency)
during one time step.
|br| * the default value is None
:type chargeOpRateMax:
* None
* Pandas DataFrame with positive (>= 0) entries. The row indices have
to match the in the energy system model specified time steps. The column indices have to match the
in the energy system model specified locations.
* a dictionary with investment periods as keys and one of the two options above as values.
:param chargeOpRateFix: if specified, indicates a fixed charging rate for each location and each time
step, if required also for each investment period, by a positive float. If hasCapacityVariable is set to True, the values are given relative
to the installed capacities (i.e. a value of 1 indicates a utilization of 100% of the
capacity). If hasCapacityVariable is set to False, the values are given as absolute values in form
of the commodityUnit, referring to the charged commodity (before multiplying the charging efficiency)
during one time step.
|br| * the default value is None
:type chargeOpRateFix:
* None
* Pandas DataFrame with positive (>= 0) entries. The row indices have
to match the in the energy system model specified time steps. The column indices have to match the
in the energy system model specified locations.
* a dictionary with investment periods as keys and one of the two options above as values.
:param chargeTsaWeight: weight with which the chargeOpRate (max/fix) time series of the
component should be considered when applying time series aggregation.
|br| * the default value is 1
:type chargeTsaWeight: positive (>= 0) float
:param dischargeOpRateMax: if specified, indicates a maximum discharging rate for each location and each
time step, if required also for each investment period, by a positive float. If hasCapacityVariable is set to True, the values are given relative
to the installed capacities (i.e. a value of 1 indicates a utilization of 100% of the
capacity). If hasCapacityVariable is set to False, the values are given as absolute values in form
of the commodityUnit, referring to the discharged commodity (after multiplying the discharging
efficiency) during one time step.
|br| * the default value is None
:type dischargeOpRateMax:
* None
* Pandas DataFrame with positive (>= 0) entries. The row indices have
to match the in the energy system model specified time steps. The column indices have to match the
in the energy system model specified locations.
* a dictionary with investment periods as keys and one of the two options above as values.
:param dischargeOpRateFix: if specified, indicates a fixed discharging rate for each location and each
time step, if required also for each investment period, by a positive float. If hasCapacityVariable is set to True, the values are given relative
to the installed capacities (i.e. a value of 1 indicates a utilization of 100% of the
capacity). If hasCapacityVariable is set to False, the values are given as absolute values in form
of the commodityUnit, referring to the charged commodity (after multiplying the discharging
efficiency) during one time step.
|br| * the default value is None
:type dischargeOpRateFix:
* None
* Pandas DataFrame with positive (>= 0) entries. The row indices have
to match the in the energy system model specified time steps. The column indices have to match the
in the energy system model specified locations.
* a dictionary with investment periods as keys and one of the two options above as values.
:param dischargeTsaWeight: weight with which the dischargeOpRate (max/fix) time series of the
component should be considered when applying time series aggregation.
|br| * the default value is 1
:type dischargeTsaWeight: positive (>= 0) float
:param isPeriodicalStorage: indicates if the state of charge of the storage has to be at the same value
after the end of each period. This is especially relevant when using daily periods where short term
storage can be restrained to daily cycles. Benefits the run time of the model.
|br| * the default value is False
:type isPeriodicalStorage: boolean
:param opexPerChargeOperation: describes the cost for one unit of the charge operation.
The cost which is directly proportional to the charge operation of the
component is obtained by multiplying the opexPerChargeOperation parameter with the annual sum of the
operational time series of the components. The opexPerChargeOperation can either be given as a float
or a Pandas Series with location specific values or a dictionary per investment period with one of the two previous options.
The cost unit in which the parameter is given has to match the one specified in the energy
system model (e.g. Euro, Dollar, 1e6 Euro).
|br| * the default value is 0
:type opexPerChargeOperation: positive (>=0) float or Pandas Series with positive (>=0) values or dict of
positive (>=0) float or Pandas Series with positive (>=0) values per investment period.
The indices of the series have to equal the in the energy system model specified locations.
:param opexPerDischargeOperation: describes the cost for one unit of the discharge operation.
The cost which is directly proportional to the discharge operation
of the component is obtained by multiplying the opexPerDischargeOperation parameter with the annual sum
of the operational time series of the components. The opexPerDischargeOperation can either be given as
a float or a Pandas Series with location specific values or a dictionary per investment period with one of the two previous options.
The cost unit in which the parameter is given has to match the one specified in the energy
system model (e.g. Euro, Dollar, 1e6 Euro).
|br| * the default value is 0
:type opexPerDischargeOperation:
* positive (>=0) float
* Pandas Series with positive (>=0) values. The indices of the series have to equal the in the energy system model specified locations.
* a dictionary with investment periods as keys and one of the two options above as values.
:param socOffsetDown: determines whether the state of charge at the end of a period p has
to be equal to the one at the beginning of a period p+1 (socOffsetDown=-1) or if
it can be smaller at the beginning of p+1 (socOffsetDown>=0). In the latter case,
the product of the parameter socOffsetDown and the actual soc offset is used as a penalty
factor in the objective function.
|br| * the default value is -1
:type socOffsetDown: float
:param socOffsetUp: determines whether the state of charge at the end of a period p has
to be equal to the one at the beginning of a period p+1 (socOffsetUp=-1) or if
it can be larger at the beginning of p+1 (socOffsetUp>=0). In the latter case,
the product of the parameter socOffsetUp and the actual soc offset is used as a penalty
factor in the objective function.
|br| * the default value is -1
:type socOffsetUp: float
"""
Component.__init__(
self,
esM,
name,
dimension="1dim",
hasCapacityVariable=hasCapacityVariable,
capacityVariableDomain=capacityVariableDomain,
capacityPerPlantUnit=capacityPerPlantUnit,
hasIsBuiltBinaryVariable=hasIsBuiltBinaryVariable,
bigM=bigM,
locationalEligibility=locationalEligibility,
capacityMin=capacityMin,
capacityMax=capacityMax,
partLoadMin=partLoadMin,
sharedPotentialID=sharedPotentialID,
linkedQuantityID=linkedQuantityID,
capacityFix=capacityFix,
commissioningMin=commissioningMin,
commissioningMax=commissioningMax,
commissioningFix=commissioningFix,
isBuiltFix=isBuiltFix,
investPerCapacity=investPerCapacity,
investIfBuilt=investIfBuilt,
opexPerCapacity=opexPerCapacity,
opexIfBuilt=opexIfBuilt,
interestRate=interestRate,
economicLifetime=economicLifetime,
technicalLifetime=technicalLifetime,
stockCommissioning=stockCommissioning,
floorTechnicalLifetime=floorTechnicalLifetime,
)
# Set general storage component data: chargeRate, dischargeRate, chargeEfficiency, dischargeEfficiency,
# selfDischarge, cyclicLifetime, stateOfChargeMin, stateOfChargeMax, isPeriodicalStorage, doPreciseTsaModeling,
# relaxedPeriodConnection
utils.checkCommodities(esM, {commodity})
self.commodity, self.commodityUnit = (
commodity,
esM.commodityUnitsDict[commodity],
)
# TODO unit and type checks
self.chargeRate, self.dischargeRate = chargeRate, dischargeRate
self.chargeEfficiency = chargeEfficiency
self.dischargeEfficiency = dischargeEfficiency
self.selfDischarge = selfDischarge
self.cyclicLifetime = cyclicLifetime
self.stateOfChargeMin = stateOfChargeMin
self.stateOfChargeMax = stateOfChargeMax
self.isPeriodicalStorage = isPeriodicalStorage
self.doPreciseTsaModeling = doPreciseTsaModeling
self.socOffsetUp = socOffsetUp
self.socOffsetDown = socOffsetDown
self.modelingClass = StorageModel
# opexPerChargeOperation
self.opexPerChargeOperation = opexPerChargeOperation
self.processedOpexPerChargeOperation = (
utils.checkAndSetInvestmentPeriodCostParameter(
esM,
name,
opexPerChargeOperation,
"1dim",
locationalEligibility,
esM.investmentPeriods,
)
)
# opexPerDischargeOperation
self.opexPerDischargeOperation = opexPerDischargeOperation
self.processedOpexPerDischargeOperation = (
utils.checkAndSetInvestmentPeriodCostParameter(
esM,
name,
opexPerDischargeOperation,
"1dim",
locationalEligibility,
esM.investmentPeriods,
)
)
# chargeOpRateFix and chargeOpRateMax
self.chargeOpRateMax = chargeOpRateMax
self.chargeOpRateFix = chargeOpRateFix
# chargeOpRateMax
self.fullChargeOpRateMax = utils.checkAndSetInvestmentPeriodTimeSeries(
esM, name, chargeOpRateMax, locationalEligibility
)
self.aggregatedChargeOpRateMax = dict.fromkeys(esM.investmentPeriods)
# chargeOpRateFix
self.fullChargeOpRateFix = utils.checkAndSetInvestmentPeriodTimeSeries(
esM, name, chargeOpRateFix, locationalEligibility
)
self.aggregatedChargeOpRateFix = dict.fromkeys(esM.investmentPeriods)
# dischargeOpRateMax
self.dischargeOpRateMax = dischargeOpRateMax
self.fullDischargeOpRateMax = utils.checkAndSetInvestmentPeriodTimeSeries(
esM, name, dischargeOpRateMax, locationalEligibility
)
self.aggregatedDischargeOpRateMax = {}
# dischargeOpRateFix
self.dischargeOpRateFix = dischargeOpRateFix
self.fullDischargeOpRateFix = utils.checkAndSetInvestmentPeriodTimeSeries(
esM, name, dischargeOpRateFix, locationalEligibility
)
self.aggregatedDischargeOpRateFix = dict.fromkeys(esM.investmentPeriods)
# check for chargeOpRateMax and chargeOpRateFix
for ip in esM.investmentPeriods:
if (
self.fullChargeOpRateMax[ip] is not None
and self.fullChargeOpRateFix[ip] is not None
):
self.fullChargeOpRateMax[ip] = None
if esM.verbose < 2:
warnings.warn(
"If chargeOpRateFix is specified, the chargeOpRateMax parameter is not required.\n"
+ "The chargeOpRateMax time series was set to None."
)
# partLoadMin
self.processedPartLoadMin = utils.checkAndSetPartLoadMin(
esM,
name,
partLoadMin,
self.fullChargeOpRateMax,
self.fullChargeOpRateFix,
self.bigM,
self.hasCapacityVariable,
)
utils.isPositiveNumber(dischargeTsaWeight)
self.dischargeTsaWeight = dischargeTsaWeight
utils.isPositiveNumber(chargeTsaWeight)
self.chargeTsaWeight = chargeTsaWeight
timeSeriesData = {}
for ip in esM.investmentPeriods:
tsNb = sum(
[
0 if data is None else 1
for data in [
self.fullChargeOpRateMax[ip],
self.fullChargeOpRateFix[ip],
self.fullDischargeOpRateMax[ip],
self.fullDischargeOpRateFix[ip],
]
]
)
if tsNb > 0:
timeSeriesData[ip] = sum(
[
data
for data in [
self.fullChargeOpRateMax[ip],
self.fullChargeOpRateFix[ip],
self.fullDischargeOpRateMax[ip],
self.fullDischargeOpRateFix[ip],
]
if data is not None
]
)
else:
timeSeriesData[ip] = None
self.processedLocationalEligibility = utils.setLocationalEligibility(
esM,
self.locationalEligibility,
self.processedCapacityMax,
self.processedCapacityFix,
self.isBuiltFix,
self.hasCapacityVariable,
timeSeriesData,
)
def setTimeSeriesData(self, hasTSA):
"""
Function for setting the maximum operation rate and fixed operation rate for charging and discharging
depending on whether a time series analysis is requested or not.
:param hasTSA: states whether a time series aggregation is requested (True) or not (False).
:type hasTSA: boolean
"""
self.processedChargeOpRateMax = (
self.aggregatedChargeOpRateMax if hasTSA else self.fullChargeOpRateMax
)
self.processedChargeOpRateFix = (
self.aggregatedChargeOpRateFix if hasTSA else self.fullChargeOpRateFix
)
self.processedDischargeOpRateMax = (
self.aggregatedDischargeOpRateMax if hasTSA else self.fullDischargeOpRateMax
)
self.processedDischargeOpRateFix = (
self.aggregatedDischargeOpRateFix if hasTSA else self.fullDischargeOpRateFix
)
def getDataForTimeSeriesAggregation(self, ip):
"""Function for getting the required data if a time series aggregation is requested.
:param ip: investment period of transformation path analysis.
:type ip: int
"""
weightDict, data = {}, []
tsa_input = [
(
self.fullChargeOpRateFix,
self.fullChargeOpRateMax,
"chargeRate_",
self.chargeTsaWeight,
),
(
self.fullDischargeOpRateFix,
self.fullDischargeOpRateMax,
"dischargeRate_",
self.dischargeTsaWeight,
),
]
for rateFix, rateMax, rateName, rateWeight in tsa_input:
if rateFix:
weightDict, data = self.prepareTSAInput(
rateFix, rateName, rateWeight, weightDict, data, ip
)
if rateMax:
weightDict, data = self.prepareTSAInput(
rateMax, rateName, rateWeight, weightDict, data, ip
)
return (pd.concat(data, axis=1), weightDict) if data else (None, {})
def setAggregatedTimeSeriesData(self, data, ip):
"""
Function for determining the aggregated maximum rate and the aggregated fixed operation rate for charging
and discharging.
:param data: Pandas DataFrame with the clustered time series data of the source component
:type data: Pandas DataFrame
:param ip: investment period of transformation path analysis.
:type ip: int
"""
self.aggregatedChargeOpRateFix[ip] = self.getTSAOutput(
self.fullChargeOpRateFix, "chargeRate_", data, ip
)
self.aggregatedChargeOpRateMax[ip] = self.getTSAOutput(
self.fullChargeOpRateMax, "chargeRate_", data, ip
)
self.aggregatedDischargeOpRateFix[ip] = self.getTSAOutput(
self.fullDischargeOpRateFix, "dischargeRate_", data, ip
)
self.aggregatedDischargeOpRateMax[ip] = self.getTSAOutput(
self.fullDischargeOpRateMax, "dischargeRate_", data, ip
)
class StorageModel(ComponentModel):
"""
A StorageModel class instance will be instantly created if a Storage class instance is initialized.
It is used for the declaration of the sets, variables and constraints which are valid for the Storage class
instance. These declarations are necessary for the modeling and optimization of the energy system model.
The StorageModel class inherits from the ComponentModel class.
"""
def __init__(self):
""" " Constructor for creating a StorageModel class instance"""
super().__init__()
self.abbrvName = "stor"
self.dimension = "1dim"
self._chargeOperationVariablesOptimum = {}
self._dischargeOperationVariablesOptimum = {}
self._stateOfChargeOperationVariablesOptimum = {}
####################################################################################################################
# Declare sparse index sets #
####################################################################################################################
def declareSets(self, esM, pyM):
"""
Declare sets: design variable sets, operation variable set, operation mode sets.
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
"""
compDict = self.componentsDict
# Declare design variable sets
self.declareDesignVarSet(pyM, esM)
self.declareCommissioningVarSet(pyM, esM)
self.declareContinuousDesignVarSet(pyM)
self.declareDiscreteDesignVarSet(pyM)
self.declareDesignDecisionVarSet(pyM)
# Declare design pathway sets
self.declarePathwaySets(pyM, esM)
self.declareLocationComponentSet(pyM)
# Declare operation variable set
self.declareOpVarSet(esM, pyM)
if pyM.hasTSA:
varSet = getattr(pyM, "operationVarSet_" + self.abbrvName)
def initVarSimpleTSASet(pyM):
return (
(loc, compName, ip)
for loc, compName, ip in varSet
if not compDict[compName].doPreciseTsaModeling
)
setattr(
pyM,
"varSetSimple_" + self.abbrvName,
pyomo.Set(dimen=3, initialize=initVarSimpleTSASet),
)
def initVarPreciseTSASet(pyM):
return (
(loc, compName, ip)
for loc, compName, ip in varSet
if compDict[compName].doPreciseTsaModeling
)
setattr(
pyM,
"varSetPrecise_" + self.abbrvName,
pyomo.Set(dimen=3, initialize=initVarPreciseTSASet),
)
def initOffsetUpSet(pyM):
return (
(loc, compName, ip)
for loc, compName, ip in getattr(
pyM, "operationVarSet_" + self.abbrvName
)
if compDict[compName].socOffsetUp >= 0
)
setattr(
pyM,
"varSetOffsetUp_" + self.abbrvName,
pyomo.Set(dimen=3, initialize=initOffsetUpSet),
)
def initOffsetDownSet(pyM):
return (
(loc, compName, ip)
for loc, compName, ip in getattr(
pyM, "operationVarSet_" + self.abbrvName
)
if compDict[compName].socOffsetDown >= 0
)
setattr(
pyM,
"varSetOffsetDown_" + self.abbrvName,
pyomo.Set(dimen=3, initialize=initOffsetDownSet),
)
# Declare sets for case differentiation of operating modes
# * Charge operation
self.declareOperationModeSets(
pyM,
"chargeOpConstrSet",
"processedChargeOpRateMax",
"processedChargeOpRateFix",
)
# * Discharge operation
self.declareOperationModeSets(
pyM,
"dischargeOpConstrSet",
"processedDischargeOpRateMax",
"processedDischargeOpRateFix",
)
####################################################################################################################
# Declare variables #
####################################################################################################################
def declareVariables(self, esM, pyM, relaxIsBuiltBinary, relevanceThreshold):
"""
Declare design and operation variables.
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param relaxIsBuiltBinary: states if the optimization problem should be solved as a relaxed LP to get the lower
bound of the problem.
|br| * the default value is False
:type declaresOptimizationProblem: boolean
:param relevanceThreshold: Force operation parameters to be 0 if values are below the relevance threshold.
|br| * the default value is None
:type relevanceThreshold: float (>=0) or None
"""
# Capacity variables [commodityUnit*hour]
self.declareCapacityVars(pyM)
# (Continuous) numbers of installed components [-]
self.declareRealNumbersVars(pyM)
# (Discrete/integer) numbers of installed components [-]
self.declareIntNumbersVars(pyM)
# Binary variables [-] indicating if a component is considered at a location or not
self.declareBinaryDesignDecisionVars(pyM, relaxIsBuiltBinary)
# Energy amount injected into a storage (before injection efficiency losses) between two time steps
self.declareOperationVars(
pyM,
esM,
"chargeOp",
"processedChargeOpRateFix",
"processedChargeOpRateMax",
relevanceThreshold=relevanceThreshold,
)
# Energy amount delivered from a storage (after delivery efficiency losses) between two time steps
self.declareOperationVars(
pyM,
esM,
"dischargeOp",
"processedDischargeOpRateFix",
"processedDischargeOpRateMax",
relevanceThreshold=relevanceThreshold,
)
# Operation of component as binary [1/0]
self.declareOperationBinaryVars(pyM, "chargeOp_bin")
self.declareOperationBinaryVars(pyM, "dischargeOp_bin")
# Capacity development variables [physicalUnit]
self.declareCommissioningVars(pyM, esM)
self.declareDecommissioningVars(pyM, esM)
# Inventory of storage components [commodityUnit*hour]
if not pyM.hasTSA:
# Energy amount stored at the beginning of a time step during the (one) period (the i-th state of charge
# refers to the state of charge at the beginning of the i-th time step, the last index is the state of
# charge after the last time step)
setattr(
pyM,
"stateOfCharge_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "operationVarSet_" + self.abbrvName),
pyM.interTimeStepsSet,
domain=pyomo.NonNegativeReals,
),
)
# Variables to allow a relaxation of the inter period storage connection
setattr(
pyM,
"stateOfChargeOffsetUp_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "varSetOffsetUp_" + self.abbrvName),
esM.periods,
domain=pyomo.NonNegativeReals,
),
)
setattr(
pyM,
"stateOfChargeOffsetDown_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "varSetOffsetDown_" + self.abbrvName),
esM.periods,
domain=pyomo.NonNegativeReals,
),
)
else:
def SOCBounds(pyM, loc, compName, ip, p, t):
# Replaces the intraSOCstart constraint:
# Declare the constraint that the (virtual) state of charge at the beginning of a typical period is zero.
if t == 0:
return (0, 0)
else:
return (None, None)
# (Virtual) energy amount stored during a period (the i-th state of charge refers to the state of charge at
# the beginning of the i-th time step, the last index is the state of charge after the last time step)
setattr(
pyM,
"stateOfCharge_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "operationVarSet_" + self.abbrvName),
pyM.interTimeStepsSet,
domain=pyomo.Reals,
bounds=SOCBounds,
),
)
# (Virtual) minimum amount of energy stored within a period
setattr(
pyM,
"stateOfChargeMin_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "operationVarSet_" + self.abbrvName),
esM.typicalPeriods,
domain=pyomo.Reals,
),
)
# (Virtual) maximum amount of energy stored within a period
setattr(
pyM,
"stateOfChargeMax_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "operationVarSet_" + self.abbrvName),
esM.typicalPeriods,
domain=pyomo.Reals,
),
)
# (Real) energy amount stored at the beginning of a period between periods(the i-th state of charge refers
# to the state of charge at the beginning of the i-th period, the last index is the state of charge after
# the last period)
setattr(
pyM,
"stateOfChargeInterPeriods_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "operationVarSet_" + self.abbrvName),
pyM.investPeriodInterPeriodSet,
domain=pyomo.NonNegativeReals,
),
)
# Variables to allow a relaxation of the inter period storage connection
setattr(
pyM,
"stateOfChargeOffsetUp_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "varSetOffsetUp_" + self.abbrvName),
esM.interPeriodTimeSteps,
domain=pyomo.NonNegativeReals,
),
)
setattr(
pyM,
"stateOfChargeOffsetDown_" + self.abbrvName,
pyomo.Var(
getattr(pyM, "varSetOffsetDown_" + self.abbrvName),
esM.interPeriodTimeSteps,
domain=pyomo.NonNegativeReals,
),
)
####################################################################################################################
# Declare component constraints #
####################################################################################################################
def connectSOCs(self, pyM, esM):
"""
Declare the constraint for connecting the state of charge with the charge and discharge operation:
the change in the state of charge between two points in time has to match the values of charging and
discharging (considering the efficiencies of these processes) within the time step in between minus
the self-discharge of the storage.
.. math::
:nowrap:
\\begin{eqnarray*}
SoC^{comp}_{loc,ip,p,t+1} - \\left( SoC^{comp}_{loc,ip,p,t} \\left( 1 - \\eta^{self-discharge} \\right)^{\\frac{\\tau^{hours}}{h}} + op^{comp,charge}_{loc,ip,p,t} \\eta^{charge} - op^{comp,discharge}_{loc,ip,p,t} / \\eta^{discharge} \\right) = 0
\\end{eqnarray*}
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
SOC = getattr(pyM, "stateOfCharge_" + abbrvName)
chargeOp, dischargeOp = (
getattr(pyM, "chargeOp_" + abbrvName),
getattr(pyM, "dischargeOp_" + abbrvName),
)
opVarSet = getattr(pyM, "operationVarSet_" + abbrvName)
def connectSOCs(pyM, loc, compName, ip, p, t):
if not pyM.hasSegmentation:
return (
SOC[loc, compName, ip, p, t + 1]
- SOC[loc, compName, ip, p, t]
* (1 - compDict[compName].selfDischarge) ** esM.hoursPerTimeStep
== chargeOp[loc, compName, ip, p, t]
* compDict[compName].chargeEfficiency
- dischargeOp[loc, compName, ip, p, t]
/ compDict[compName].dischargeEfficiency
)
else:
return (
SOC[loc, compName, ip, p, t + 1]
- SOC[loc, compName, ip, p, t]
* (1 - compDict[compName].selfDischarge)
** esM.hoursPerSegment[ip].to_dict()[p, t]
== chargeOp[loc, compName, ip, p, t]
* compDict[compName].chargeEfficiency
- dischargeOp[loc, compName, ip, p, t]
/ compDict[compName].dischargeEfficiency
)
setattr(
pyM,
"ConstrConnectSOC_" + abbrvName,
pyomo.Constraint(opVarSet, pyM.intraYearTimeSet, rule=connectSOCs),
)
def cyclicState(self, pyM, esM):
"""
Declare the constraint for connecting the states of charge: the state of charge at the beginning of a period
has to be the same as the state of charge in the end of that period.
with full temporal resolution
.. math::
SoC^{comp}_{loc,ip,0,0} = SoC^{comp}_{loc,ip,0,t^{total}}
with time series aggregation:
.. math::
SoC^{inter}_{loc,ip,0} = SoC^{inter}_{loc,ip,p^{total}}
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
abbrvName = self.abbrvName
opVarSet = getattr(pyM, "operationVarSet_" + abbrvName)
SOC = getattr(pyM, "stateOfCharge_" + abbrvName)
offsetUp = getattr(pyM, "stateOfChargeOffsetUp_" + abbrvName)
offsetDown = getattr(pyM, "stateOfChargeOffsetDown_" + abbrvName)
if not pyM.hasTSA:
def cyclicState(pyM, loc, compName, ip, p):
offsetUp_ = (
offsetUp[loc, compName, 0] if (loc, compName, 0) in offsetUp else 0
)
offsetDown_ = (
offsetDown[loc, compName, 0]
if (loc, compName, 0) in offsetDown
else 0
)
return SOC[loc, compName, ip, 0, 0] == SOC[
loc, compName, ip, 0, esM.timeStepsPerPeriod[-1] + 1
] + (offsetUp_ - offsetDown_)
else:
SOCInter = getattr(pyM, "stateOfChargeInterPeriods_" + abbrvName)
# tests for testing the storage class with ip and TSAM
def cyclicState(pyM, loc, compName, ip, p):
# tLast = esM.interPeriodTimeSteps[-1]
tLast = esM.numberOfInterPeriodTimeSteps
offsetUp_ = (
offsetUp[loc, compName, tLast]
if (loc, compName, tLast) in offsetUp
else 0
)
offsetDown_ = (
offsetDown[loc, compName, tLast]
if (loc, compName, tLast) in offsetDown
else 0
)
return SOCInter[loc, compName, ip, 0] == SOCInter[
loc, compName, ip, tLast
] + (offsetUp_ - offsetDown_)
setattr(
pyM,
"ConstrCyclicState_" + abbrvName,
pyomo.Constraint(
opVarSet, pyM.investPeriodInterPeriodSet, rule=cyclicState
),
)
def cyclicLifetime(self, pyM, esM):
"""
Declare the constraint for limiting the number of full cycle equivalents to stay below cyclic lifetime.
.. math::
:nowrap:
\\begin{eqnarray*}
& & op^{comp,charge}_{loc,annual} \\leq \\left( \\text{SoC}^{max} - \\text{SoC}^{min} \\right) \\cdot cap^{comp}_{loc,ip} \\cdot \\frac{t^{ \\text{comp,cyclic lifetime}}}{\\tau^{ \\text{comp,economic lifetime}}_{loc}} \\\\
\\text{with} \\\\
& & op^{comp,charge}_{loc,annual} = \\sum_{(ip,p,t) \\in \\mathcal{P} \\times \\mathcal{T}} op^{comp,charge}_{loc,ip,p,t} \\cdot freq(p) / \\tau^{years}
\\end{eqnarray*}
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
chargeOp, capVar = (
getattr(pyM, "chargeOp_" + abbrvName),
getattr(pyM, "cap_" + abbrvName),
)
capVarSet = getattr(pyM, "designDimensionVarSet_" + abbrvName)
def cyclicLifetime(pyM, loc, compName, ip):
return (
sum(
chargeOp[loc, compName, ip, p, t] * esM.periodOccurrences[ip][p]
for ip, p, t in pyM.timeSet
)
/ esM.numberOfYears
<= capVar[loc, compName, ip]
* (
compDict[compName].stateOfChargeMax
- compDict[compName].stateOfChargeMin
)
* compDict[compName].cyclicLifetime
/ compDict[compName].economicLifetime[loc]
if compDict[compName].cyclicLifetime is not None
else pyomo.Constraint.Skip
)
setattr(
pyM,
"ConstrCyclicLifetime_" + abbrvName,
pyomo.Constraint(capVarSet, rule=cyclicLifetime),
)
def connectInterPeriodSOC(self, pyM, esM):
"""
Declare the constraint that the state of charge at the end of each period has to be equivalent to the state of
charge of the period before it (minus its self discharge) plus the change in the state of charge which
happened during the typical period which was assigned to that period.
.. math::
:nowrap:
\\begin{eqnarray*}
SoC^{inter}_{loc,ip,p+1} - SoC^{inter}_{loc,ip,p} \\cdot \\left( 1 - \\eta^{self-discharge} \\right)^{\\frac{t^{\\text{per period}} \cdot \\tau^{hours}}{h}}
\\ SoC^{comp}_{loc,ip,map(p),t^{\\text{per period}}} = 0
\\end{eqnarray*}
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVarSet = getattr(pyM, "operationVarSet_" + abbrvName)
SOC = getattr(pyM, "stateOfCharge_" + abbrvName)
SOCInter = getattr(pyM, "stateOfChargeInterPeriods_" + abbrvName)
offsetUp = getattr(pyM, "stateOfChargeOffsetUp_" + abbrvName)
offsetDown = getattr(pyM, "stateOfChargeOffsetDown_" + abbrvName)
def connectInterSOC(pyM, loc, compName, ip, pInter):