-
Notifications
You must be signed in to change notification settings - Fork 11
/
components.py
3441 lines (2734 loc) · 113 KB
/
components.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
import numpy as np
import pandas as pd
from mswh.comm.label_map import SwhLabels
from mswh.tools.unit_converters import UnitConv
log = logging.getLogger(__name__)
class Converter(object):
"""Contains energy converter models, such as
solar collectors, electric resistance heaters, gas burners,
photovoltaic panels, and heat pumps. Depending on the intended
usage, the models can be used to determine either a time period
of component operation (for example an entire year), or a single
timestep of component performance.
Parameters:
params: pd df
Component performance parameters per project
Default: None (default model parameters will get used)
weather: pd df
Weather data timeseries with columns: amb. temp,
solar irradiation. Number of rows equals the number of timesteps.
Default: None (constant values will be set - use for
a single timestep calculation, or if passing arguments
directly to static methods)
sizes: pd df
Component sizes per project.
Default: 1. (see individual components for specifics)
log_level: None or python logger logging level,
Default: logging.DEBUG
This applies for a subset of the class functionality, mostly
used to deprecate logger messages for certain calculations.
For Example: log_level = logging.ERROR will only throw error
messages and ignore INFO, DEBUG and WARNING.
Note:
If more than one of the same component is a part of the
system, a separate instance of the converter should
be created for each instance of the component.
Each component is also implemented as a static method that
can be used outside of this framework.
Examples:
See :func:`mswh.system.tests.test_components <mswh.system.tests.test_components>` module and
:func:`scripts/Project Level MSWH System Tool.ipynb <scripts/Project Level MSWH System Tool.ipynb>`
for examples on how to use the methods as stand alone and
in a system model simulation.
"""
def __init__(
self, params=None, weather=None, sizes=1.0, log_level=logging.DEBUG
):
# log level (e.g. only partial functionality of the class
# is being used and one does not desire to see all infos)
self.log_level = log_level
logging.getLogger().setLevel(log_level)
# extract labels
self.c = SwhLabels().set_hous_labels()
self.s = SwhLabels().set_prod_labels()
self.r = SwhLabels().set_res_labels()
if isinstance(params, pd.DataFrame):
self.use_defaults = False
# extract components and their performance parameters
self.components = []
# extract components provided in params
components = params[self.s["comp"]].unique().tolist()
if self.s["sol_col"] in components:
self.components.append(self.s["sol_col"])
self.params_sol_col = dict()
# this method of collector model selection prefers the
# model under ```try:``` as long as the parameters were
# found in the parameter table
try: # HWB
self.params_sol_col[self.s["interc_hwb"]] = params.loc[
params[self.s["param"]] == self.s["interc_hwb"],
self.s["param_value"],
].values[0]
self.params_sol_col[self.s["slope_hwb"]] = params.loc[
params[self.s["param"]] == self.s["slope_hwb"],
self.s["param_value"],
].values[0]
self.solar_model = "HWB"
except: # CD
self.params_sol_col[self.s["interc_cd"]] = params.loc[
params[self.s["param"]] == self.s["interc_cd"],
self.s["param_value"],
].values[0]
self.params_sol_col[self.s["a1_cd"]] = params.loc[
params[self.s["param"]] == self.s["a1_cd"],
self.s["param_value"],
].values[0]
self.params_sol_col[self.s["a2_cd"]] = params.loc[
params[self.s["param"]] == self.s["a2_cd"],
self.s["param_value"],
].values[0]
self.solar_model = "CD"
if self.s["pv"] in components:
self.components.append(self.s["pv"])
self.params_pv = dict()
# Extract the model parameters
self.params_pv[self.s["eta_pv"]] = params.loc[
params[self.s["param"]] == self.s["eta_pv"],
self.s["param_value"],
].values[0]
self.params_pv[self.s["f_act"]] = params.loc[
params[self.s["param"]] == self.s["f_act"],
self.s["param_value"],
].values[0]
self.params_pv[self.s["irrad_ref"]] = params.loc[
params[self.s["param"]] == self.s["irrad_ref"],
self.s["param_value"],
].values[0]
msg = "Photovoltaic is setup."
log.info(msg)
if self.s["inv"] in components:
self.components.append(self.s["inv"])
self.params_inv = dict()
# extract the total dc-ac conversion efficiency
self.params_inv[self.s["eta_dc_ac"]] = params.loc[
params[self.s["param"]] == self.s["eta_dc_ac"],
self.s["param_value"],
].values[0]
msg = "Inverter is setup."
log.info(msg)
if self.s["hp"] in components:
self.components.append(self.s["hp"])
self.params_hp = dict()
# Extract the model parameters
self.params_hp[self.s["c1_cop"]] = params.loc[
params[self.s["param"]] == self.s["c1_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c2_cop"]] = params.loc[
params[self.s["param"]] == self.s["c2_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c3_cop"]] = params.loc[
params[self.s["param"]] == self.s["c3_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c4_cop"]] = params.loc[
params[self.s["param"]] == self.s["c4_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c5_cop"]] = params.loc[
params[self.s["param"]] == self.s["c5_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c6_cop"]] = params.loc[
params[self.s["param"]] == self.s["c6_cop"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c1_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c1_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c2_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c2_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c3_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c3_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c4_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c4_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c5_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c5_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["c6_heat_cap"]] = params.loc[
params[self.s["param"]] == self.s["c6_heat_cap"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["heat_cap_rated"]] = params.loc[
params[self.s["param"]] == self.s["heat_cap_rated"],
self.s["param_value"],
].values[0]
self.params_hp[self.s["cop_rated"]] = params.loc[
params[self.s["param"]] == self.s["cop_rated"],
self.s["param_value"],
].values[0]
msg = "Heat pump is setup."
log.info(msg)
if self.s["el_res"] in components:
self.components.append(self.s["el_res"])
self.params_el_res = dict()
# Extract electric resistance parameters
self.params_el_res[self.s["eta_el_res"]] = params.loc[
params[self.s["param"]] == self.s["eta_el_res"],
self.s["param_value"],
].values[0]
if self.s["gas_burn"] in components:
self.components.append(self.s["gas_burn"])
self.params_gas_burn = dict()
# Extract gas burner parameters
self.params_gas_burn[self.s["comb_eff"]] = params.loc[
params[self.s["param"]] == self.s["comb_eff"],
self.s["param_value"],
].values[0]
# when adding components, extract parameters similarly
elif not isinstance(params, pd.DataFrame):
self.use_defaults = True
# extract component size/capacity (see setter for details)
self.size = sizes
# extract weather and irradiation data
self.weather = weather
@property
def weather(self):
return self.__weather
@weather.setter
def weather(self, value):
"""Re-extracts weather timeseries if a new weather dataset
is assigned to an instantiated class object
"""
self.__weather = value
if isinstance(value, pd.DataFrame):
self.t_amb = UnitConv(
self.weather[self.c["t_amb_C"]].values
).degC_K(unit_in="degC")
self.inc_rad = self.weather[self.c["irrad_on_tilt"]].values
msg = "Assigned weather data timeseries."
log.info(msg)
elif value is None:
self.t_amb = 293.15 # K
self.inc_rad = 800 # W
msg = (
"No weather data got passed to converters. "
"Setting default scalar values for ambient temperature, "
"{}, and solar irradiation, {}."
)
log.info(msg.format(self.t_amb, self.inc_rad))
@property
def size(self):
return self.__size
@size.setter
def size(self, value):
"""Re-extracts sizes from a dataframe"""
set_sizes = dict()
if (not isinstance(value, pd.DataFrame)) and (value == 1.0):
# assign unit size
set_sizes = value
elif isinstance(value, pd.DataFrame):
if self.s["gas_tank"] in self.components:
set_sizes[self.s["gas_tank"]] = value.loc[
value[self.s["comp"]] == self.s["gas_tank"], self.s["cap"]
].values[0]
if self.s["sol_col"] in self.components:
set_sizes[self.s["sol_col"]] = value.loc[
value[self.s["comp"]] == self.s["sol_col"], self.s["cap"]
].values[0]
if self.s["pv"] in self.components:
set_sizes[self.s["pv"]] = value.loc[
value[self.s["comp"]] == self.s["pv"], self.s["cap"]
].values[0]
if self.s["hp"] in self.components:
set_sizes[self.s["hp"]] = value.loc[
value[self.s["comp"]] == self.s["hp"], self.s["cap"]
].values[0]
if self.s["el_res"] in self.components:
set_sizes[self.s["el_res"]] = value.loc[
value[self.s["comp"]] == self.s["el_res"], self.s["cap"]
].values[0]
if self.s["gas_burn"] in self.components:
try:
set_sizes[self.s["gas_burn"]] = value.loc[
value[self.s["comp"]] == self.s["gas_burn"],
self.s["cap"],
].values[0]
except:
set_sizes[self.s["gas_burn"]] = None
msg = (
"Could not find the size for the "
"gas instantaneous water heater, "
"Setting size to infinite."
)
log.info(msg)
else:
msg = "Provided sizes format is not supported."
log.error(msg)
raise ValueError
self.__size = set_sizes
def heat_pump(self, T_wet_bulb, T_tank):
"""Returns the current heating performance and electricity usage
in the current conditions depending on wet bulb temperature,
average tank water temperature, and the rated heating performance.
Rated conditions are: wet bulb = 14 degC, tank = 48.9 degC
Parameters:
T_wet_bulb: real, array
Inlet air wet bulb temperature [K]
T_tank: real, array
Water temperature in the storage tank [K]
C1: real
Coefficient 1, either for normalized COP or heating
capacity curve [-]
C2: real
Coefficient 2, either for normalized COP or heating
capacity curve [1/degC]
C3: real
Coefficient 3, either for normalized COP or heating
capacity curve [1/degC2]
C4: real
Coefficient 4, either for normalized COP or heating
capacity curve [1/degC]
C5: real
Coefficient 5, either for normalized COP or heating
capacity curve [1/degC2]
C6: real
Coefficient 6, either for normalized COP or heating
capacity curve [1/degC2]
Returns:
performance: dict
* 'cop': current Coefficient Of Performance (COP), [-]
* 'heat_cap': current heating capacity of heat pump, [W]
* 'el_use': current electricity use of heat pump [W]
"""
# Set rated heating capacity
heat_cap_rated = self.params_hp[self.s["heat_cap_rated"]]
# Set rated COP (coefficient of performance)
cop_rated = self.params_hp[self.s["cop_rated"]]
# Calculate actual heating capacity under current conditions
# (T_wet_bulb and T_tank)
heat_cap = heat_cap_rated * self._heat_pump(
T_wet_bulb,
T_tank,
self.params_hp[self.s["c1_heat_cap"]],
self.params_hp[self.s["c2_heat_cap"]],
self.params_hp[self.s["c3_heat_cap"]],
self.params_hp[self.s["c4_heat_cap"]],
self.params_hp[self.s["c5_heat_cap"]],
self.params_hp[self.s["c6_heat_cap"]],
)
# if the temperature difference between the tank and the
# ambient is large (e.g. an outside tank in a cold climate)
# negative heat_cap values may occur based on the
# equation in _heat_pump. Assuming that the device is
# disabled at those times, we impose a lower limit at 0:
if isinstance(heat_cap, np.ndarray):
heat_cap[heat_cap < 0.0] = 0.0
elif isinstance(heat_cap, float):
heat_cap = abs(heat_cap * (heat_cap > 0))
# Calculate actual COP under current conditions
# (T_wet_bulb and T_tank)
cop = cop_rated * self._heat_pump(
T_wet_bulb,
T_tank,
self.params_hp[self.s["c1_cop"]],
self.params_hp[self.s["c2_cop"]],
self.params_hp[self.s["c3_cop"]],
self.params_hp[self.s["c4_cop"]],
self.params_hp[self.s["c5_cop"]],
self.params_hp[self.s["c6_cop"]],
)
# Dictionary containing the results
res = {}
res["cop"] = cop
res["heat_cap"] = heat_cap
res["el_use"] = heat_cap / cop
return res
@staticmethod
def _heat_pump(
T_wet_bulb,
T_tank,
C1=1.229e00,
C2=5.549e-02,
C3=1.139e-04,
C4=-1.128e-02,
C5=-3.570e-06,
C6=-7.234e-04,
):
"""Heat pump model. Source:
B. Sparn, K. Hudon, and D. Christensen, “Laboratory Performance Evaluation of Residential Integrated Heat Pump Water Heaters,” Renew. Energy, p. 77, 2014.
https://www1.eere.energy.gov/buildings/publications/pdfs/building_america/evaluation_hpwh.pdf
Parameters:
T_wet_bulb: real, array
Inlet air wet bulb temperature [K]
T_tank: real, array
Water temperature in the storage tank [K]
C1: real
Coefficient 1, either for normalized COP or heating capacity
curve [-]
C2: real
Coefficient 2, either for normalized COP or heating capacity
curve [1/degC]
C3: real
Coefficient 3, either for normalized COP or heating capacity
curve [1/degC^2]
C4: real
Coefficient 4, either for normalized COP or heating capacity
curve [1/deg^C]
C5: real
Coefficient 5, either for normalized COP or heating capacity
curve [1/degC^2]
C6: real
Coefficient 6, either for normalized COP or heating capacity
curve [1/degC^2]
Returns:
performance: real
Performance factor
"""
# The formula needs temperatures in Celsius
T_wet_bulb_C = UnitConv(T_wet_bulb).degC_K(unit_in="K")
T_tank_C = UnitConv(T_tank).degC_K(unit_in="K")
# Calculate performance factor
performance = (
C1
+ C2 * T_wet_bulb_C
+ C3 * T_wet_bulb_C * T_wet_bulb_C
+ C4 * T_tank_C
+ C5 * T_tank_C * T_tank_C
+ C6 * T_wet_bulb_C * T_tank_C
)
return performance
def electric_resistance(self, Q_dem):
"""Electric resistance heater model. Can be
used both as an instantaneous electric WH and as
an auxiliary heater within the thermal tank.
Parameters:
Q_dem: float or array like, [W]
Heat demand
Returns:
res: dict
* self.r['q_del_bckp'] : float,
array - delivered heat rate, [W]
* self.r['q_el_use'] : float,
array - electricity use, [W]
* self.r['q_unmet'] : float,
array - unmet demand heat rate, [W]
"""
# return the heat rates for:
# delivered heat, electricity use, and unmet demand
Q_del, P_el_use, Q_unmet = self._heater(
Q_dem,
Q_nom=self.size[self.s["el_res"]],
eff=self.params_el_res[self.s["eta_el_res"]],
)
# return the heat rate of heat delivered and gas consumed
res = {
self.r["q_del_bckp"]: Q_del,
self.r["el_use"]: P_el_use,
self.r["q_unmet"]: Q_unmet,
}
return res
def gas_burner(self, Q_dem):
"""Gas burner model. Used both
as an instantaneous gas WH and as a
gas backup for solar thermal.
Parameters:
Q_dem: float or array like, W
Heat demand
Returns:
res: dict
* self.r['q_del_bckp'] : float,
array - delivered heat rate, [W]
* self.r['q_gas_use'] : float, array - gas use heat rate, [W]
* self.r['q_unmet'] : float, array -
unmet demand heat rate, [W]
Any further unit conversion should be performed
using unit_converters.Utility class
"""
# return the heat rates for:
# delivered heat, gas use, and unmet demand
Q_del, Q_en_use, Q_unmet = self._heater(
Q_dem,
eff=self.params_gas_burn[self.s["comb_eff"]],
Q_nom=self.size[self.s["gas_burn"]],
)
# return the heat rate of heat delivered and gas consumed
res = {
self.r["q_del_bckp"]: Q_del,
self.r["gas_use"]: Q_en_use,
self.r["q_unmet"]: Q_unmet,
}
return res
@staticmethod
def _heater(Q_dem, eff=0.85, Q_nom=None):
"""Simplified efficiency based model that can be
used for an in-tank main or auxiliary gas and
electric resistance heater.
Parameters:
Q_dem: float or array like, W
Heat demand
eff: float
Energy conversion efficiency, such as
combustion or electric resistance
Q_nom: float, W
Nominal capacity.
Default: None - infinite capacity
so that the heater can cover any load
Returns:
Q_del: float, array
Delivered heat rate, [W]
Q_gas_use: float, array
Energy (gas, electricity) use heat rate, [W]
Q_unmet: float, array
Unmet demand heat rate, [W]
"""
# start with assuming the heater capacity is infinite
Q_del = Q_dem + 0.0
# limit the delivery if the heater has a limited capacity
if Q_nom is not None:
if not np.isscalar(Q_dem):
Q_del[Q_del > Q_nom] = Q_nom
elif np.isscalar(Q_dem):
Q_del = min(Q_dem, Q_nom)
else:
msg = "Heater demand data type {} seems not supported."
log.error(msg.format(type(Q_dem)))
raise ValueError
# Unmet demand
Q_unmet = Q_dem - Q_del
# Gas consumption (heat rate in W, use unit_converters.Utility class
# for further conversions)
Q_en_use = Q_del / eff
return Q_del, Q_en_use, Q_unmet
def solar_collector(self, t_in, t_amb=None, inc_rad=None):
"""Two commonly used empirical instantaneous collector
efficiency models based on test data from standard
test procedures (SRCC, ISO9806), found in
J. A. Duffie and W. A. Beckman, Solar engineering of thermal processes, 3rd ed. Hoboken, N.J: Wiley, 2006., are:
* Cooper and Dunkle (CD model, eq 6.17.7)
* Hottel-Whillier-Bliss (HWB model, eq 6.16.1, 6.7.6)
Parameters:
t_in: float, array
Collector inlet temperature (timeseries) [K]
t_amb: float, array
Ambient temperature (timeseries) [K]
Default: None (to use data extracted from the weather df)
inc_rad: float, array
Incident radiation (timeseries) [W]
Default: None (to use data extracted from the weather df)
Returns:
res: dict or floats or arrays
{'Q_gain' : Solar gains from the gross collector area, [W]
'eff' : Efficiency of solar to heat conversion, [-]
"""
try:
gross_area = self.size[self.s["sol_col"]]
except:
gross_area = 1.0
msg = "Could not extract collector size. " "Setting it to {}."
log.info(msg.format(gross_area))
# if t_in is output of the tank model, solar collector
# model needs to be simulated step by step. In that
# case the timestep ambient temperature and incident solar
# radiation should be passed directly to this method
if t_amb is None:
msg = (
"Using ambient temperature array to get solar "
"collector gains. This will result in an array calculation."
)
log.info(msg)
t_amb = self.t_amb
if inc_rad is None:
msg = (
"Using irradiation array to get solar collector"
" gains. This will result in an array calculation."
)
log.info(msg)
inc_rad = self.inc_rad
if self.use_defaults:
msg = (
"Solar collector parameters have not been passed to the"
" component model. Using HWB model with default parameters."
)
log.info(msg)
self.sol_col_gain, self.sol_col_eff = self._hwb_solar_collector(
gross_area, inc_rad, t_amb, t_in
)
# based on the keywords in self.params call one or the other method
elif self.solar_model == "HWB":
self.sol_col_gain, self.sol_col_eff = self._hwb_solar_collector(
gross_area,
inc_rad,
t_amb,
t_in,
intercept=self.params_sol_col[self.s["interc_hwb"]],
slope=self.params_sol_col[self.s["slope_hwb"]],
)
elif self.solar_model == "CD":
self.sol_col_gain, self.sol_col_eff = self._cd_solar_collector(
gross_area,
inc_rad,
t_amb,
t_in,
intercept=self.params_sol_col[self.s["interc_cd"]],
a_1=self.params_sol_col[self.s["a1_cd"]],
a_2=self.params_sol_col[self.s["a2_cd"]],
)
if not isinstance(t_in, float):
msg = "\nCalculated solar collector gain time series.\n"
log.info(msg)
res = {"Q_gain": self.sol_col_gain, "eff": self.sol_col_eff}
return res
@staticmethod
def _hwb_solar_collector(
gross_area, inc_rad, t_amb, t_in, intercept=0.753, slope=-4.025
):
"""HWB based model as applied in test procedures
used in SRCC Standard 100-2006-09 (ASHRAE 93)
Default parameters: Heliodyne, Inc, GOBI 410 001 Plus
Parameters:
gross_area: float
Gross collector area [m2]
inc_rad: float or array like
Global solar radiation on 1 m2 of the
collector tilted surface [W/m2]
t_amb: float or array like
Ambient temperature (timeseries) [K or degC]
t_in: float or array like
Collector inlet temperature (timeseries)
[use same unit as t_amb]
intercept: float
Rating parameter
slope: float
Rating parameter
Returns:
solar_gain: float, array
Solar gains from the gross collector area [W]
conversion_efficiency: float, array
Conversion efficiency [-]
"""
# msg = 'Allow div 0.'
# log.debug(msg)
# avoid division by zero by creating a copy
# of the irradiation data with infinity
# instead of zero (see efficiency formula)
if not np.isscalar(inc_rad):
inc_rad_mod = inc_rad
inc_rad_mod[inc_rad == 0] = -np.inf
elif np.isscalar(inc_rad):
if inc_rad == 0.0:
inc_rad_mod = -np.inf
else:
inc_rad_mod = inc_rad
else:
msg = "Solar irradiation data type {} seems not supported."
log.error(msg.format(type(inc_rad)))
raise ValueError
# instantaneous collector efficiency, [-]
eta = intercept * (inc_rad != 0.0) + slope * (
(t_in - t_amb) / inc_rad_mod
)
# instantaneous solar gain, [W]
calc_gain = inc_rad * gross_area * eta
# set negative gains that the model may yield at
# cold weather to zero
if isinstance(calc_gain, np.ndarray):
calc_gain[calc_gain < 0.0] = 0.0
gain = calc_gain
elif isinstance(calc_gain, float):
gain = calc_gain * (calc_gain > 0)
return gain, eta
@staticmethod
def _cd_solar_collector(
gross_area,
inc_rad,
t_amb,
t_in,
intercept=0.75,
a_1=-3.688,
a_2=-0.0055,
):
"""CD based model as applied in test procedures
used in SRCC Standard 100-2006-09 (ISO 12975 with dT = Tin - Tamb)
Default parameters: `Heliodyne, Inc, GOBI 410 001 Plus <https://secure.solar-rating.org/Certification/Ratings/RatingsReport.aspx?device=6931&units=METRICS>`_
Parameters:
gross_area: float
Gross collector area [m2]
inc_rad: float, array
Global solar radiation on 1 m2 of the
collector tilted surface [W/m2]
t_amb: float, array
Ambient temperature (timeseries) [K or degC]
t_in: float, array
Collector inlet temperature (timeseries)
[use same unit as t_amb]
intercept: float
Rating parameter
a_1: float
Rating parameter
a_2: float
Rating parameter
"""
# avoid division by zero by creating a copy
# of the irradiation data with infinity
# instead of zero (see efficiency formula)
if not np.isscalar(inc_rad):
inc_rad_mod = inc_rad
inc_rad_mod[inc_rad == 0] = -np.inf
elif np.isscalar(inc_rad):
if inc_rad == 0.0:
inc_rad_mod = -np.inf
else:
inc_rad_mod = inc_rad
else:
msg = "Solar irradiation data type {} seems not supported."
log.error(msg.format(type(inc_rad)))
raise ValueError
# instantaneous collector efficiency, [-]
eta = (
intercept * (inc_rad != 0.0)
+ a_1 * ((t_in - t_amb) / inc_rad_mod)
+ a_2 * ((t_in - t_amb) / inc_rad_mod ** 2)
)
# instantaneous solar gain, [W]
calc_gain = inc_rad * gross_area * np.nan_to_num(eta)
# set negative gains that the model may yield at
# cold weather to zero
if isinstance(calc_gain, np.ndarray):
calc_gain[calc_gain < 0.0] = 0.0
gain = calc_gain
elif isinstance(calc_gain, float):
gain = calc_gain * (calc_gain > 0)
return gain, eta
def photovoltaic(self, use_p_peak=True, inc_rad=None):
"""Photovoltaic model
Parameters:
use_p_peak: boolean
Boolean flag determining if peak power is used for sizing
the pv panel (instead of area and efficiency)
Returns:
self.pv_power: dict of floats
Generated power [W]
* 'ac' : AC
* 'dc' : DC
"""
try:
panel_size = self.size[self.s["pv"]]
except:
# default to 1000. kW_peak or it's equivalent in m2 for
# default efficiency
panel_size = 1000.0 if use_p_peak else 6.25
log.info(
"Could not get panel size. Setting it to {}".format(panel_size)
)
# Set panel size according to use_p_peak value
if use_p_peak:
p_peak = panel_size
panel_area = None
# Uncomment this line, since it creates too much output
# for system level simulation
# log.info('Using peak power as a PV size parameter.')
else:
p_peak = None
panel_area = panel_size
# Uncomment this line, since it creates too much output
# for system level simulation
# log.info('Using area as a PV size parameter.')
if inc_rad is None:
msg = (
"Using irradiation array to get photovoltaic"
" gains. This will result in an array calculation."
)
log.info(msg)
inc_rad = self.inc_rad
# if no input parameters have been passed to the class
if self.use_defaults:
msg = (
"Photovoltaic parameters have not been passed to the"
" component model. Using default parameters."
)
log.info(msg)
self.pv_power = self._simple_photovoltaic(
irrad=inc_rad, panel_area=panel_area, p_peak=p_peak
)
# pass parameters from the param input dataframe
else:
self.pv_power = self._simple_photovoltaic(
irrad=inc_rad,
panel_area=panel_area,
f_act=self.params_pv[self.s["f_act"]],
eta_pv=self.params_pv[self.s["eta_pv"]],
eta_dc_ac=self.params_inv[self.s["eta_dc_ac"]],
irrad_ref=self.params_pv[self.s["irrad_ref"]],
p_peak=p_peak,
)
return self.pv_power
@staticmethod
def _simple_photovoltaic(
irrad,
p_peak=None,
panel_area=None,
f_act=1.0,
eta_pv=0.16,
eta_dc_ac=0.85,
irrad_ref=1000.0,
):
"""Simple photovoltaic model based on
http://simulationresearch.lbl.gov/modelica/releases/latest/help/Buildings_Electrical_AC_OnePhase_Sources.html#Buildings.Electrical.AC.OnePhase.Sources.PVSimple
Parameters:
irrad: float
Total solar irradiation (direct and diffuse) [W/m2]
panel_area: float or None
Panel area (area of active cells) [m2].
Set to None if using the peak power as a PV sizing variable.
p_peak: float or None
Peak power of the photovoltaic panel
(also: nominal power, nameplate size) [W]
Set to None if using the panel area as a PV sizing variable.
irrad_ref: float
Reference irradiation of the photovoltaic panel
(default: 1000 W/m2) [W/m2]