-
Notifications
You must be signed in to change notification settings - Fork 84
/
cmod_pvwattsv8.cpp
1458 lines (1234 loc) · 90.6 KB
/
cmod_pvwattsv8.cpp
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
/*
BSD 3-Clause License
Copyright (c) Alliance for Sustainable Energy, LLC. See also https://github.com/NREL/ssc/blob/develop/LICENSE
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memory>
#include "core.h"
#include "common.h"
#include "lib_weatherfile.h"
#include "lib_irradproc.h"
#include "lib_pvshade.h"
#include "lib_pvmodel.h"
#include "lib_snowmodel.h"
#include "lib_sandia.h"
#include "lib_pv_incidence_modifier.h"
#include "lib_cec6par.h"
class lossdiagram
{
unordered_map< std::string, double > m_map;
struct loss_item {
loss_item(const std::string& _n, bool _b) : name(_n), baseline(_b) { }
std::string name;
bool baseline;
};
std::string m_error;
std::vector<loss_item> m_items;
public:
lossdiagram()
{
}
std::string errormsg() { return m_error; }
void add(const std::string& name, bool baseline)
{
m_items.push_back(loss_item(name, baseline));
m_map[name] = 0.0;
}
bool assign(compute_module* cm, const std::string& prefix)
{
m_error.clear();
// calculate percentages
double last_baseline = 0.0;
for (size_t i = 0; i < m_items.size(); i++)
{
if (m_map.find(m_items[i].name) == m_map.end())
{
m_error = "could not locate loss accumulation value '" + m_items[i].name + "'";
}
if (m_items[i].baseline)
last_baseline = m_map[m_items[i].name];
else
{
double value = m_map[m_items[i].name];
double percent = value / last_baseline * 100.0;
cm->assign(prefix + m_items[i].name + "_percent", (ssc_number_t)percent);
}
}
for (auto it = m_map.begin(); it != m_map.end(); ++it)
cm->assign(prefix + it->first, var_data((ssc_number_t)it->second));
return m_error.size() == 0;
}
double& operator() (const std::string& name)
{
auto it = m_map.find(name);
if (it != m_map.end())
{
return it->second;
}
else
{
m_map[name] = 0.0;
return m_map.find(name)->second;
}
}
};
static var_info _cm_vtab_pvwattsv8[] = {
/* VARTYPE DATATYPE NAME LABEL UNITS META GROUP REQUIRED_IF CONSTRAINTS UI_HINTS*/
{ SSC_INPUT, SSC_STRING, "solar_resource_file", "Weather file path", "", "", "Solar Resource", "", "", "" },
{ SSC_INPUT, SSC_TABLE, "solar_resource_data", "Weather data", "", "dn,df,tdry,wspd,lat,lon,tz,elev", "Solar Resource", "", "", "" },
{ SSC_INPUT, SSC_ARRAY, "albedo", "Albedo", "0..1", "albedo input array of 1 constant value or 12 monthly values","Solar Resource", "", "", "" },
{ SSC_INPUT, SSC_NUMBER, "albedo_default", "Albedo default", "0..1", "default when albedo invalid","Solar Resource", "?=0.2", "", "" },
{ SSC_INPUT, SSC_NUMBER, "albedo_default_snow", "Albedo default for snow", "0..1", "default when albedo invalid and snow model enabled","Solar Resource", "?=0.6", "", "" },
{ SSC_INPUT, SSC_NUMBER, "use_wf_albedo", "Use albedo from weather file", "0/1", "0=albedo input, 1=albedo from weather file (use albedo default if invalid)","Solar Resource","?=1", "BOOLEAN", "" },
{ SSC_INOUT, SSC_NUMBER, "system_use_lifetime_output", "Run lifetime simulation", "0/1", "", "Lifetime", "?=0", "", "" },
{ SSC_INPUT, SSC_NUMBER, "analysis_period", "Analysis period", "years", "", "Lifetime", "system_use_lifetime_output=1", "", "" },
{ SSC_INPUT, SSC_ARRAY, "dc_degradation", "Annual DC degradation for lifetime simulations","%/year", "", "Lifetime", "system_use_lifetime_output=1", "", "" },
{ SSC_INPUT, SSC_NUMBER, "system_capacity", "System size (DC nameplate)", "kW", "", "System Design", "*", "", "" },
{ SSC_INPUT, SSC_NUMBER, "module_type", "Module type", "0/1/2", "standard,premium,thin film", "System Design", "?=0", "MIN=0,MAX=2,INTEGER", "" },
{ SSC_INPUT, SSC_NUMBER, "dc_ac_ratio", "DC to AC ratio", "ratio", "", "System Design", "?=1.1", "POSITIVE", "" },
{ SSC_INPUT, SSC_NUMBER, "bifaciality", "Module bifaciality factor", "0 or ~0.65","", "System Design", "?=0", "", "" },
{ SSC_INPUT, SSC_NUMBER, "array_type", "Array type", "0/1/2/3/4", "fixed open rack,fixed roof mount,1-axis tracking,1-axis backtracking,2-axis tracking","System Design", "*", "MIN=0,MAX=4,INTEGER", "" },
{ SSC_INPUT, SSC_NUMBER, "tilt", "Tilt angle", "degrees", "H=0,V=90", "System Design", "array_type<4", "MIN=0,MAX=90", "" },
{ SSC_INPUT, SSC_NUMBER, "azimuth", "Azimuth angle", "degrees", "E=90,S=180,W=270", "System Design", "array_type<4", "MIN=0,MAX=360", "" },
{ SSC_INPUT, SSC_NUMBER, "gcr", "Ground coverage ratio", "0..1", "", "System Design", "?=0.3", "MIN=0.01,MAX=0.99", "" },
{ SSC_INPUT, SSC_NUMBER, "rotlim", "Tracker rotation angle limit", "degrees", "", "System Design", "?=45.0", "", "" },
{ SSC_INPUT, SSC_ARRAY, "soiling", "Soiling loss", "%", "", "System Design", "?", "", "" },
{ SSC_INPUT, SSC_NUMBER, "losses", "DC system losses", "%", "total system losses", "System Design", "*", "MIN=-5,MAX=99", "" },
{ SSC_INPUT, SSC_NUMBER, "enable_wind_stow", "Enable tracker stow at high wind speeds", "0/1", "", "System Design", "?=0", "BOOLEAN", "" },
{ SSC_INPUT, SSC_NUMBER, "stow_wspd", "Tracker stow wind speed threshold", "m/s", "", "System Design", "?=10", "", "" },
{ SSC_INPUT, SSC_NUMBER, "gust_factor", "Wind gust estimation factor", "", "", "System Design", "?", "", "" },
{ SSC_INPUT, SSC_NUMBER, "wind_stow_angle", "Tracker angle for wind stow", "degrees", "", "System Design", "?=30.0", "", "" },
{ SSC_INPUT, SSC_NUMBER, "en_snowloss", "Enable snow loss model", "0/1", "", "System Design", "?=0", "BOOLEAN", "" },
{ SSC_INPUT, SSC_NUMBER, "inv_eff", "Inverter efficiency at rated power", "%", "", "System Design", "?=96", "MIN=90,MAX=99.5", "" },
{ SSC_INPUT, SSC_NUMBER, "xfmr_nll", "GSU transformer no load loss (iron core)", "%(ac)", "", "System Design", "?=0.0", "", "" },
{ SSC_INPUT, SSC_NUMBER, "xfmr_ll", "GSU transformer load loss (resistive)", "%(ac)", "", "System Design", "?=0.0", "", "" },
// { SSC_INPUT, SSC_TABLE, "shading", "Shading loss table", "", "", "System Design", "?", "", "" },
{SSC_INPUT, SSC_NUMBER, "shading_en_string_option", "Enable shading string option", "0/1", "0=false,1=true", "Shading", "?=0", "BOOLEAN", "" },
{SSC_INPUT, SSC_NUMBER, "shading_string_option", "Shading string option", "", "0=shadingdb,1=average,2=maximum,3=minimum", "Shading", "?=-1", "INTEGER,MIN=-1,MAX=4","" },
{SSC_INPUT, SSC_NUMBER, "shading_en_timestep", "Enable timestep beam shading losses", "0/1", "0=false,1=true", "Shading", "?=0", "BOOLEAN", "" },
{SSC_INPUT, SSC_MATRIX, "shading_timestep", "Timestep beam shading losses", "%", "", "Shading", "?", "", "" },
{SSC_INPUT, SSC_NUMBER, "shading_en_mxh", "Enable month x Hour beam shading losses", "0/1", "0=false,1=true", "Shading", "?=0", "BOOLEAN", "" },
{SSC_INPUT, SSC_MATRIX, "shading_mxh", "Month x Hour beam shading losses", "%", "", "Shading", "?", "", "" },
{SSC_INPUT, SSC_NUMBER, "shading_en_azal", "Enable azimuth x altitude beam shading losses", "0/1", "0=false,1=true", "Shading", "?=0", "BOOLEAN", "" },
{SSC_INPUT, SSC_MATRIX, "shading_azal", "Azimuth x altitude beam shading losses", "%", "", "Shading", "?", "", "" },
{SSC_INPUT, SSC_NUMBER, "shading_en_diff", "Enable diffuse shading loss", "0/1", "0=false,1=true", "Shading", "?=0", "BOOLEAN", "" },
{SSC_INPUT, SSC_NUMBER, "shading_diff", "Diffuse shading loss", "%", "", "Shading", "?", "", "" },
{ SSC_INPUT, SSC_NUMBER, "batt_simple_enable", "Enable Battery", "0/1", "", "System Design", "?=0", "BOOLEAN", "" },
/* outputs */
{ SSC_OUTPUT, SSC_ARRAY, "gh", "Weather file global horizontal irradiance", "W/m2", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "dn", "Weather file beam irradiance", "W/m2", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "df", "Weather file diffuse irradiance", "W/m2", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "tamb", "Weather file ambient temperature", "C", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "wspd", "Weather file wind speed", "m/s", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "snow", "Weather file snow depth", "cm", "", "Time Series", "", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "alb", "Albedo", "", "", "Time Series", "", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "soiling_f", "Soiling factor", "", "", "Time Series", "", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "sunup", "Sun up over horizon", "0/1", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "shad_beam_factor", "External shading factor for beam radiation", "", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ss_beam_factor", "Calculated self-shading factor for beam radiation", "", "1=no shading", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ss_sky_diffuse_factor", "Calculated self-shading factor for sky diffuse radiation", "", "1=no shading", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ss_gnd_diffuse_factor", "Calculated self-shading factor for ground-reflected diffuse radiation", "", "1=no shading", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "aoi", "Angle of incidence", "degrees", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "poa", "Plane of array irradiance", "W/m2", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "tpoa", "Transmitted plane of array irradiance", "W/m2", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "tcell", "Module temperature", "C", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "dcsnowderate", "DC power loss due to snow", "%", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "snow_cover", "Fraction of row covered by snow", "0..1", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "dc", "DC inverter input power", "W", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ac", "AC inverter output power", "W", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ac_pre_adjust", "AC inverter output power before system availability", "W", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "inv_eff_output", "Inverter efficiency", "%", "", "Time Series", "*", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "poa_monthly", "Plane of array irradiance", "kWh/m2", "", "Monthly", "", "LENGTH=12", "" },
{ SSC_OUTPUT, SSC_ARRAY, "solrad_monthly", "Daily average solar irradiance", "kWh/m2/day","", "Monthly", "", "LENGTH=12", "" },
{ SSC_OUTPUT, SSC_ARRAY, "dc_monthly", "Monthly DC energy", "kWh", "", "Monthly", "", "LENGTH=12", "" },
{ SSC_OUTPUT, SSC_ARRAY, "ac_monthly", "Monthly AC energy", "kWh", "", "Monthly", "", "LENGTH=12", "" },
{ SSC_OUTPUT, SSC_ARRAY, "monthly_energy", "Monthly AC energy in Year 1", "kWh", "", "Monthly", "", "LENGTH=12", "" },
{ SSC_OUTPUT, SSC_MATRIX, "annual_energy_distribution_time","Annual energy production as function of time", "", "", "Heatmaps", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "solrad_annual", "Daily average solar irradiance", "kWh/m2/day","", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "ac_annual", "Annual AC output", "kWh", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "ac_annual_pre_adjust", "Annual AC output before system availability", "kWh", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "annual_energy", "Annual AC energy in Year 1", "kWh", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "capacity_factor", "Capacity factor based on nameplate DC capacity", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "capacity_factor_ac", "Capacity factor based on total AC capacity", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "kwh_per_kw", "Energy yield", "kWh/kW", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_STRING, "location", "Location ID", "", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_STRING, "city", "City", "", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_STRING, "state", "State", "", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "lat", "Latitude", "degrees", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "lon", "Longitude", "degrees", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "tz", "Time zone", "UTC offset", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "elev", "Site elevation", "m", "", "Location", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "inverter_efficiency", "Inverter efficiency at rated power", "%", "", "PVWatts", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "ts_shift_hours", "Time offset for interpreting time series outputs", "hours","", "Miscellaneous", "*", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "percent_complete", "Estimated percent of total completed simulation", "%", "", "Miscellaneous", "", "", "" },
var_info_invalid };
class cm_pvwattsv8 : public compute_module
{
protected:
enum module_type { STANDARD, PREMIUM, THINFILM };
enum module_orientation { PORTRAIT, LANDSCAPE };
enum array_type { FIXED_RACK, FIXED_ROOF, ONE_AXIS, ONE_AXIS_BACKTRACKING, TWO_AXIS, AZIMUTH_AXIS }; //azimuth axis not enabled in inputs?
static const constexpr double bifacialTransmissionFactor = 0.013;
struct {
module_type type; //standard, premium, thinfilm
double stc_watts; //rated power at STC in Watts
double stc_eff; //rated efficiency at STC (unitless)
double ff; //fill factor (unitless)
double aspect_ratio; //module length / width (unitless)
double width; //module width in meters
double length; //module length in meters
double area; //module area in square meters
double vmp; //maximum power voltage in volts
int ndiode; //number of diodes in module (unitless)
double gamma; //temperature coefficient of maximum power- units are 1 / degree Celsius
bool ar_glass; //whether or not module has anti-reflective glass
double bifaciality; //bifaciality factor for bifacial modules (unitless)
} module;
struct {
array_type type;
double dc_nameplate; //nameplate rated capacity of the DC side of the system units of this variable are W, while input is in kW
double dc_ac_ratio; //ratio of DC nameplate capacity to AC nameplate capacity (unitless)
double ac_nameplate; //nameplate rated capacity of the AC side of the system (W)
double xfmr_rating; //rating of the transformer, hardcoded to be equal to ac_nameplate (W)
double inv_eff_percent; //inverter efficiency at rated power (percent)
double dc_loss_percent; //DC system losses (percent)
double tilt, azimuth; //tilt and azimuth of the system (degrees)
double rotlim; //tracker rotation limit (degrees)
double xfmr_nll_f; //transformer no-load-loss (percent of AC power)
double xfmr_ll_f; //transformer load loss (percent of AC power)
double nmodules; //number of modules (unitless)
double nmodperstr; //number of modules per string (unitless)
int nmodx, nmody, nrows;//number of modules along the bottom of a row, number of modules along the upward direction of a row, number of rows (unitless)
double row_spacing; //row spacing, calculated from other inputs (meters)
double gcr; //ground coverage ratio (unitless)
} pv;
struct sdmml { //single diode model mermoud lejeune (alternative to pvwatts model)
double Area;
double Vmp;
double Imp;
double Voc;
double Isc;
double n_0;
double mu_n;
double N_series;
double alpha_isc;
double E_g;
double R_shexp;
double R_sh0;
double R_shref;
double R_s;
double D2MuTau;
};
sdmml sdm;
lossdiagram ld;
public:
cm_pvwattsv8()
{
add_var_info(vtab_technology_outputs);
add_var_info(_cm_vtab_pvwattsv8);
add_var_info(vtab_adjustment_factors);
add_var_info(vtab_technology_outputs);
add_var_info(vtab_hybrid_tech_om_outputs);
ld.add("poa_nominal", true);
ld.add("poa_loss_tracker_stow", false);
ld.add("poa_loss_ext_beam_shade", false);
ld.add("poa_loss_ext_diff_shade", false);
ld.add("poa_loss_self_beam_shade", false);
ld.add("poa_loss_self_diff_shade", false);
ld.add("poa_loss_soiling", false);
ld.add("poa_loss_bifacial", false);
ld.add("dc_nominal", true);
ld.add("dc_loss_cover", false);
ld.add("dc_loss_spectral", false);
ld.add("dc_loss_thermal", false);
ld.add("dc_loss_nonlinear", false);
ld.add("dc_loss_snow", false);
ld.add("dc_loss_other", false);
ld.add("ac_nominal", true);
ld.add("ac_loss_efficiency", false);
ld.add("ac_loss_inverter_clipping", false);
ld.add("ac_loss_adjustments", false);
ld.add("ac_loss_plant_clipping", false);
ld.add("ac_loss_transformer", false);
ld.add("ac_delivered", true);
}
virtual ~cm_pvwattsv8()
{
// nothing to do
}
double sdmml_power(sdmml& m, double S, double T_cell) //mermoud lejeune single diode model structure, S=irradiance, T_cell is cell temperature
{
static const double S_ref = 1000;
static const double T_ref = 25;
static const double k = 1.38064852e-23; // Boltzmann constant [J/K]
static const double q = 1.60217662e-19; // Elemenatry charge [C]
static const double T_0 = 273.15; // 0 degrees Celsius in Kelvin [K]
if (S > 1)
{
double R_sh_STC = m.R_shref + (m.R_sh0 - m.R_shref) * exp(-m.R_shexp * (S_ref / S_ref));
double nVT = m.N_series * m.n_0 * k * (T_ref + T_0) / q;
double I_0ref = (m.Isc + (m.Isc * m.R_s - m.Voc) / R_sh_STC) / ((exp(m.Voc / nVT) - 1) - (exp((m.Isc * m.R_s) / nVT) - 1));
double I_Lref = I_0ref * (exp(m.Voc / nVT) - 1) + m.Voc / R_sh_STC;
double Vbi = 0.9 * m.N_series;
double n = m.n_0 + m.mu_n * (T_cell - T_ref);
double a = m.N_series * k * (T_cell + T_0) * n / q;
double I_L = (S / S_ref) * (I_Lref + m.alpha_isc * (T_cell - T_ref));
double I_0 = I_0ref * pow(((T_cell + T_0) / (T_ref + T_0)), 3) * exp((q * m.E_g) / (n * k) * (1 / (T_ref + T_0) - 1 / (T_cell + T_0)));
double R_sh = m.R_shref + (m.R_sh0 - m.R_shref) * exp(-m.R_shexp * (S / S_ref));
double V_oc = openvoltage_5par_rec(m.Voc, a, I_L, I_0, R_sh, m.D2MuTau, Vbi);
double V, I;
return maxpower_5par_rec(V_oc, a, I_L, I_0, m.R_s, R_sh, m.D2MuTau, Vbi, &V, &I);
}
else
return 0.0;
}
void exec()
{
std::unique_ptr<weather_data_provider> wdprov;
if (is_assigned("solar_resource_file"))
{
const char* file = as_string("solar_resource_file");
wdprov = std::unique_ptr<weather_data_provider>(new weatherfile(file));
weatherfile* wfile = dynamic_cast<weatherfile*>(wdprov.get());
if (!wfile->ok()) throw exec_error("pvwattsv8", wfile->message());
if (wfile->has_message()) log(wfile->message(), SSC_WARNING);
}
else if (is_assigned("solar_resource_data"))
{
wdprov = std::unique_ptr<weather_data_provider>(new weatherdata(lookup("solar_resource_data")));
if (!wdprov->ok()) {
throw exec_error("pvwattsv8", wdprov->message());
}
if (wdprov->has_message()) log(wdprov->message(), SSC_WARNING);
}
else
throw exec_error("pvwattsv8", "No weather data supplied.");
pv.dc_nameplate = as_double("system_capacity") * 1000; //units of this variable are W, while input is in kW
pv.dc_ac_ratio = as_double("dc_ac_ratio");
pv.ac_nameplate = pv.dc_nameplate / pv.dc_ac_ratio;
pv.xfmr_rating = pv.ac_nameplate;
pv.inv_eff_percent = as_double("inv_eff");
size_t soiling_len = 0;
ssc_number_t* soiling = nullptr;
if (is_assigned("soiling"))
{
soiling = as_array("soiling", &soiling_len);
}
size_t albedo_len = 0;
ssc_number_t* albedo = 0;
if (is_assigned("albedo"))
{
albedo = as_array("albedo", &albedo_len);
}
bool use_wf_albedo = as_boolean("use_wf_albedo");
pv.dc_loss_percent = as_double("losses");
pv.tilt = pv.azimuth = std::numeric_limits<double>::quiet_NaN();
pv.rotlim = 45.0;
if (is_assigned("tilt")) pv.tilt = as_double("tilt");
if (is_assigned("azimuth")) pv.azimuth = as_double("azimuth");
if (is_assigned("rotlim")) pv.rotlim = as_double("rotlim");
pv.xfmr_ll_f = as_double("xfmr_ll") * 0.01; //transformer inputs always present, but default to 0
pv.xfmr_nll_f = as_double("xfmr_nll") * 0.01;
bool enable_wind_stow = as_boolean("enable_wind_stow");
if (enable_wind_stow && !wdprov->annualSimulation())
log("Using the wind stow model with weather data that is not continuous over one year may result in over-estimation of stow losses.", SSC_WARNING);
double wstow = std::numeric_limits<double>::quiet_NaN();
if (is_assigned("stow_wspd")) wstow = as_double("stow_wspd"); // wind stow speed, m/s.
double wind_stow_angle_deg = std::numeric_limits<double>::quiet_NaN(); // default is to assume stowing at 30 degrees (set in var_table) for better dynamic torsional stability, despite higher static loading on piles
if (is_assigned("wind_stow_angle")) wind_stow_angle_deg = as_double("wind_stow_angle");
// gust factor defined later because it depends on timestep
//hidden input variable (not in var_table): whether or not to use the mermoud lejeune single diode model as defined above (0 = don't use model, 1 = use model)
int en_mlm = is_assigned("en_mlm") ? as_integer("en_mlm") : 0;
cec6par_module_t mod; // structure for the CEC single diode model calculations
noct_celltemp_t modTempCalc; // structure for the module temperature calculations
modTempCalc.standoff_tnoct_adj = 0; // do not use the adjustment for cell temperature, but rather set noct as commented below
modTempCalc.ffv_wind = 0.51; // assume that all mounting configurations are < 22 ft. This may not be perfect for roof-mounted systems, but the differences are likely minimal.
module.type = (module_type)as_integer("module_type");
switch (module.type)
{
case STANDARD:
module.gamma = -0.0037;
module.ar_glass = true;
module.ff = 0.778; //fill factors required for self-shading calculations
module.stc_eff = 0.19;
// for full CEC single diode model, Canadian Solar CS1H-320MS, parameters calculated by SAM version 2020.2.29 r3
mod.Area = 1.6864;
mod.Vmp = 35.8;
mod.Imp = 9.01;
mod.Voc = 43.3;
mod.Isc = 9.51;
mod.alpha_isc = 0.004755;
mod.beta_voc = -0.12557;
mod.a = 1.65916;
mod.Il = 9.51393;
mod.Io = 4.37813e-11;
mod.Rs = 0.269953;
mod.Rsh = 654.059;
mod.Adj = 5.79586;
// for optional SDM module model:
// selected module from PVsyst PAN database: TSM-330DD14A(II)
// note that this is a DIFFERENT module than the factors listed above
sdm.Area = 1.940;
sdm.Vmp = 37.8;
sdm.Imp = 8.73;
sdm.Voc = 46.2;
sdm.Isc = 9.27;
sdm.n_0 = 0.92;
sdm.mu_n = 0;
sdm.N_series = 72;
sdm.alpha_isc = 0.0046;
sdm.E_g = 1.12;
sdm.R_shexp = 20;
sdm.R_sh0 = 2000;
sdm.R_shref = 550;
sdm.R_s = 0.382;
sdm.D2MuTau = 0.0;
break;
case PREMIUM:
module.gamma = -0.0035;
module.ar_glass = true;
module.ff = 0.780;
module.stc_eff = 0.21; //efficiency assumption updated per Sunpower
// for full CEC single diode model, Sunpower SPR-E20-327
mod.Area = 1.6297;
mod.Vmp = 54.7;
mod.Imp = 5.98;
mod.Voc = 64.9;
mod.Isc = 6.46;
mod.alpha_isc = 0.0026;
mod.beta_voc = -0.1766;
mod.a = 2.45326;
mod.Il = 6.4704;
mod.Io = 2.01784e-11;
mod.Rs = 0.421231;
mod.Rsh = 261.723;
mod.Adj = 9.56482;
// for optional SDM module model:
// selected module from PVsyst PAN database: SPR-X20-327-COM
// note that this is a DIFFERENT module than the factors listed above
sdm.Area = 1.630;
sdm.Vmp = 59.5;
sdm.Imp = 5.49;
sdm.Voc = 70.0;
sdm.Isc = 5.84;
sdm.n_0 = 1.17;
sdm.mu_n = 0;
sdm.N_series = 96;
sdm.alpha_isc = 0.0025;
sdm.E_g = 1.12;
sdm.R_shexp = 5.5;
sdm.R_sh0 = 14000;
sdm.R_shref = 3444;
sdm.R_s = 0.4;
sdm.D2MuTau = 0.0;
break;
case THINFILM:
module.gamma = -0.0032;
module.ar_glass = true;
module.ff = 0.777;
module.stc_eff = 0.18;
// for full CEC single diode model, First Solar FS-6435A
mod.Area = 2.4751;
mod.Vmp = 183.6;
mod.Imp = 2.37;
mod.Voc = 219.6;
mod.Isc = 2.55;
mod.alpha_isc = 0.00102;
mod.beta_voc = -0.61488;
mod.a = 7.97293;
mod.Il = 2.55475;
mod.Io = 2.69243e-12;
mod.Rs = 4.60991;
mod.Rsh = 2476.95;
mod.Adj = -2.49865;
// for optional SDM module model:
// selected module from PVsyst PAN database: FS-4112-3
// note that this is a DIFFERENT module than the factors listed above
sdm.Area = 0.72;
sdm.Vmp = 68.5;
sdm.Imp = 1.64;
sdm.Voc = 87.0;
sdm.Isc = 1.83;
sdm.n_0 = 1.5;
sdm.mu_n = 0.002;
sdm.N_series = 108;
sdm.alpha_isc = 0.0007;
sdm.E_g = 1.12;
sdm.R_shexp = 6;
sdm.R_sh0 = 12000;
sdm.R_shref = 3500;
sdm.R_s = 4.36;
sdm.D2MuTau = 0.95;
break;
}
// common module parameters
module.aspect_ratio = 1.7; // typical geometry, length / width
module.stc_watts = 300; // assume a typical mid-size module nameplate (e.g. 300 Watts)
module.area = module.stc_watts / module.stc_eff / 1000.0; // module area in m2
module.width = sqrt((module.area / module.aspect_ratio));
module.length = module.width * module.aspect_ratio;
module.vmp = 60.0;
module.ndiode = 3;
module.bifaciality = 0.0;
if (is_assigned("bifaciality"))
module.bifaciality = as_double("bifaciality");
static double AMdesoto[5] = { 0.918093, 0.086257, -0.024459, 0.002816, -0.000126 }; // !Air mass modifier coefficients as indicated in DeSoto paper
double module_m2 = pv.dc_nameplate / module.stc_eff / 1000;
pv.type = (array_type)as_integer("array_type");
switch (pv.type)
{
case FIXED_ROOF:
modTempCalc.Tnoct = 49; // rather than using the standoff_tnoct_adj factor from the noct_celltemp_t structure, we just make an assumption here for increased Tnoct due to roof-mounting
break;
default: // all other types
modTempCalc.Tnoct = 45;
break;
}
// warning if tilt is > 0 for a tracking system becaues this is a very uncommon configuration but an easy mistake to make
if ((pv.type == ONE_AXIS || pv.type == ONE_AXIS_BACKTRACKING) && pv.tilt > 0)
log(util::format("The tilt angle is %f degrees with one-axis tracking. Large one-axis tracking arrays typically have a tilt angle of zero.", pv.tilt), SSC_WARNING);
if (!(pv.type == FIXED_RACK || pv.type == FIXED_ROOF) && module.bifaciality > 0.0)
log("The bifacial model is designed for fixed arrays and may not produce reliable results for tracking arrays.", SSC_WARNING);
if (pv.type == FIXED_ROOF && module.bifaciality > 0.0)
log("The Fixed Roof Mount array type is not appropriate for bifacial modules because it assumes there is no space between the back of the array and the roof surface.", SSC_WARNING);
pv.gcr = as_double("gcr");
if (pv.gcr < 0.01 || pv.gcr >= 1.0)
throw exec_error("pvwattsv8", "invalid gcr");
bool en_self_shading = (pv.type == FIXED_RACK || pv.type == ONE_AXIS || pv.type == ONE_AXIS_BACKTRACKING);
// Electrical Layout
// modules per string: 7 modules of about 60 Vmp each
// gives a nominal DC voltage of about 420 V DC which seems reasonable
pv.nmodperstr = 7;
pv.nmodules = ceil(pv.dc_nameplate / module.stc_watts); // estimate of # of modules in system
// but make sure there's at least one module, in the case where dc_nameplate < stc_watts
if (pv.nmodules < 1) pv.nmodules = 1;
// Physical Layout
// reasonable estimates of system geometry, used for self-shading calculations ONLY.
// assume one module high for trackers, 2 modules high for fixed or two-axis
if (pv.type == ONE_AXIS || pv.type == ONE_AXIS_BACKTRACKING)
pv.nmody = 1; // e.g. Nextracker or ArrayTechnologies single portrait
else
pv.nmody = 2; // typical fixed 2 up portrait
if (pv.type == FIXED_ROOF)
pv.nrows = 1; // fixed roof systems are all in one "row", so we'll assign that here for clarity even though these numbers only affect self-shading and that's disabled for rooftop systems
else
pv.nrows = (int)ceil(sqrt(pv.nmodules/pv.nmody)); // assume a ''square'' system layout- same number of modules across a row (nmodx) as number of rows (nrows), so need to divide by nmody to ensure that's true
pv.nmodx = ceil(pv.nmodules / ( pv.nrows * pv.nmody)); // would rather that the estimated physical layout be larger than the actual number of modules for estimating self-shading impacts
if (pv.nmodx < 1) pv.nmodx = 1; // shading calculation fails for pv.nmodx < 1
pv.row_spacing = module.length * pv.nmody / pv.gcr;
// see note farther down in code about self-shading for small systems
// assume at least some reasonable number of rows.
// otherwise self shading model may not really apply very well.
// in fact, should have some minimum system size
/*if (pv.nrows < 10)
log(util::format("system size is too small to accurately estimate regular row-row self shading impacts. (estimates: #modules=%d, #rows=%d). disabling self-shading calculations.",
(int)pv.nmodules, (int)pv.nrows), SSC_WARNING);*/
pvsnowmodel snowmodel;
bool en_snowloss = as_boolean("en_snowloss");
if (en_snowloss)
{
// check for snow model with non-annual simulations: because snow model coefficients need to know the timestep, and we don't know timestep if non-annual
if (!wdprov->annualSimulation())
log("Using the snow model with weather data that is not continuous over one year may result in over-estimation of snow losses.", SSC_WARNING);
// if tracking mode is 1-axis tracking,
// don't need to limit tilt angles
if (snowmodel.setup(pv.nmody,
(float)pv.tilt, 1.97,
pv.type == FIXED_RACK || pv.type == FIXED_ROOF)) {
if (!snowmodel.good) {
log(snowmodel.msg, SSC_ERROR);
}
}
}
// read all the shading input data and calculate the hourly factors for use subsequently
// timeseries beam shading factors cannot be used with non-annual data
if (is_assigned("shading_en_timestep") && as_boolean("shading_en_timestep") && !wdprov->annualSimulation())
// if (is_assigned("shading:timestep") && !wdprov->annualSimulation())
throw exec_error("pvwattsv8", "Timeseries beam shading inputs cannot be used for a simulation period that is not continuous over one or more years.");
shading_factor_calculator shad;
if (!shad.setup(this, ""))
throw exec_error("pvwattsv8", shad.get_error());
// self-shading initialization
sssky_diffuse_table ssSkyDiffuseTable;
if (en_self_shading)
ssSkyDiffuseTable.init(pv.tilt, pv.gcr);
weather_header hdr;
wdprov->header(&hdr);
// assumes instantaneous values, unless hourly file with no minute column specified- same code as lib_pv_io_manager.cpp. can we make this one set of code somehow?
double ts_shift_hours = 0.0;
bool instantaneous = true;
if (wdprov->has_data_column(weather_data_provider::MINUTE))
{
// if we have an file with a minute column, then
// the starting time offset equals the time
// of the first record (for correct plotting)
// this holds true even for hourly data with a minute column
weather_record rec;
if (wdprov->read(&rec))
ts_shift_hours = rec.minute / 60.0;
wdprov->rewind();
}
else if (wdprov->nrecords() == 8760)
{
// hourly file with no minute data column. assume
// integrated/averaged values and use mid point convention for interpreting results
instantaneous = false;
ts_shift_hours = 0.5;
}
else
throw exec_error("pvwattsv8", "Minute column required in weather data for subhourly data or data that is not continuous over one year.");
assign("ts_shift_hours", var_data((ssc_number_t)ts_shift_hours));
weather_record wf;
size_t nyears = 1;
std::vector<double> degradationFactor;
if (as_boolean("system_use_lifetime_output")) {
if (!wdprov->annualSimulation())
throw exec_error("pvwattsv8", "Simulation cannot be run over analysis period for weather data that is not continuous over one year. Set system_use_lifetime_output to 0 to resolve this issue.");
nyears = as_unsigned_long("analysis_period");
std::vector<double> dc_degradation = as_vector_double("dc_degradation");
if (dc_degradation.size() == 1) {
degradationFactor.push_back(1.0); // assume zero degradation in year 1
for (size_t y = 1; y < nyears; y++) {
degradationFactor.push_back(1.0 - (dc_degradation[0] * y) / 100.0);
}
}
else {
if (dc_degradation.size() != nyears)
throw exec_error("pvwattsv8", "Length of degradation array must be equal to analysis period.");
for (size_t y = 0; y < nyears; y++) {
degradationFactor.push_back(1.0 - dc_degradation[y] / 100.0);
}
}
}
else {
degradationFactor.push_back(1.0);
}
size_t nrec = wdprov->nrecords();
size_t nlifetime = nrec * nyears;
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec, nyears))
throw exec_error("pvwattsv8", "Failed to set up adjustment factors: " + haf.error());
size_t step_per_hour = 1; //default to 1 step per hour for non-annual simulations
if (wdprov->annualSimulation())
step_per_hour = nrec / 8760; //overwrite with real value for annual simulations
if (wdprov->annualSimulation() && (step_per_hour < 1 || step_per_hour > 60 || step_per_hour * 8760 != nrec))
throw exec_error("pvwattsv8", util::format("Invalid number of data records (%d): must be an integer multiple of 8760.", (int)nrec));
double ts_hour = 1.0 / step_per_hour; //timestep in fraction of hours (decimal)
double wm2_to_wh = module_m2 * ts_hour; //conversion from watts per meter squared to watt hours- need to convert with ts_hour for subhourly data
double gustf = std::numeric_limits<double>::quiet_NaN(); // gust factor
if (is_assigned("gust_factor")) gustf = as_double("gust_factor");
double gf = gustf;
if (!std::isfinite(gf)) //if gust factor isn't defined by user, determine it for them
{
// determine the sustained 1 minute gust wind speed
// based on the current time step
// this translation is for the 'in-land' category in
// table 1.1 of the World Metereological Organization report
// 'Guidelines for converting between various wind averaging periods
// in tropical cyclone conditions', October 2008
double ts_sec = ts_hour * 3600.0;
if (ts_sec >= 600)
gf = 1.28;
else if (ts_sec >= 180)
gf = 1.21;
else if (ts_sec >= 120)
gf = 1.15;
else if (ts_sec >= 60)
gf = 1.13;
else
gf = 1.0;
}
/* allocate output arrays */
ssc_number_t* p_gh = allocate("gh", nrec);
ssc_number_t* p_dn = allocate("dn", nrec);
ssc_number_t* p_df = allocate("df", nrec);
ssc_number_t* p_tamb = allocate("tamb", nrec);
ssc_number_t* p_wspd = allocate("wspd", nrec);
ssc_number_t* p_snow = allocate("snow", nrec);
ssc_number_t* p_sunup = allocate("sunup", nrec);
ssc_number_t* p_aoi = allocate("aoi", nrec);
ssc_number_t* p_shad_beam = allocate("shad_beam_factor", nrec); // just for reporting output
ssc_number_t* p_ss_beam = allocate("ss_beam_factor", nrec);
ssc_number_t* p_ss_sky_diffuse = allocate("ss_sky_diffuse_factor", nrec);
ssc_number_t* p_ss_gnd_diffuse = allocate("ss_gnd_diffuse_factor", nrec);
ssc_number_t* p_stow = allocate("tracker_stowing", nrec); // just for reporting output
ssc_number_t* p_tmod = allocate("tcell", nrec);
ssc_number_t* p_alb = allocate("alb", nrec);
ssc_number_t* p_soiling_f = allocate("soiling_f", nrec);
ssc_number_t* p_dcshadederate = allocate("dcshadederate", nrec);
ssc_number_t* p_dcsnowderate = allocate("dcsnowderate", nrec);
ssc_number_t* p_snowcover = allocate("snow_cover", nrec);
ssc_number_t* p_poa = allocate("poa", nrec);
ssc_number_t* p_tpoa = allocate("tpoa", nrec);
ssc_number_t* p_dc = allocate("dc", nrec);
ssc_number_t* p_ac = allocate("ac", nrec);
ssc_number_t* p_ac_pre_adjust = allocate("ac_pre_adjust", nrec);
ssc_number_t* p_inv_eff = allocate("inv_eff_output", nrec);
ssc_number_t* p_gen = allocate("gen", nlifetime);
double annual_kwh = 0;
size_t idx_life = 0;
float percent = 0;
int n_alb_errs = 0;
double elev, pres, t_amb;
irrad irr;
if (nyears > 1)
irr.setup_solarpos_outputs_for_lifetime(nrec);
for (size_t y = 0; y < nyears; y++)
{
for (size_t idx = 0; idx < nrec; idx++)
{
if (!wdprov->read(&wf))
throw exec_error("pvwattsv8", util::format("could not read data line %d of %d in weather file", (int)(idx + 1), (int)nrec));
size_t hour_of_year = util::hour_of_year(wf.month, wf.day, wf.hour);
#define NSTATUS_UPDATES 50 // set this to the number of times a progress update should be issued for the simulation
if (nrec > 50) //avoid divide by zero problems in the following if statement- probably don't need a lot of updates otherwise
{
if (idx % (nrec / NSTATUS_UPDATES) == 0)
{
percent = 100.0f * ((float)idx_life + 1) / ((float)nlifetime); //3 is the number of technologies we're assuming for this output (pvwatts + fuel cell + battery)
// check percentage
if (percent > 100.0f) percent = 99.0f;
if (!update("", percent, (float)hour_of_year))
throw exec_error("pvwattsv8", "Simulation stopped at hour " + util::to_string(hour_of_year + 1.0));
}
}
bool tracker_stowing = false;
p_gh[idx] = (ssc_number_t)wf.gh;
p_dn[idx] = (ssc_number_t)wf.dn;
p_df[idx] = (ssc_number_t)wf.df;
p_tamb[idx] = (ssc_number_t)wf.tdry;
p_wspd[idx] = (ssc_number_t)wf.wspd;
p_snow[idx] = (ssc_number_t)wf.snow; // if there is no snow data in the weather file, this will be NaN- consistent with pvsamv1
p_tmod[idx] = (ssc_number_t)wf.tdry;
// use wf albedo if use_wf_albedo is true and wf albedo is valid
// use user albedo if use_wf_albedo is false and user albedo is valid
// otherwise use default albedo (snow or no snow)
double alb = 0;
if (use_wf_albedo)
{
if ((std::isfinite(wf.alb) && (wf.alb > 0 && wf.alb < 1)))
alb = wf.alb;
else
n_alb_errs++;
}
else
{
if (albedo_len == 1)
alb = albedo[0];
else if (albedo_len == 12)
alb = albedo[wf.month - 1];
else if (albedo_len == nrec)
alb = albedo[idx];
else if (is_assigned("albedo") && (idx == 0)) // display warning once
log(util::format("Albedo input array is not the correct length (1, 12, or %d entries). "
"Using default albedo value of %f (snow) or %f (no snow). "
"[year:%d month:%d day:%d hour:%d minute:%lg]. ",
nrec, as_double("albedo_default_snow"), as_double("albedo_default"),
wf.year, wf.month, wf.day, wf.hour, wf.minute), SSC_NOTICE);
}
if (alb <= 0 || alb >= 1)
{
if (std::isfinite(wf.snow) && wf.snow > 0.5 && wf.snow < 999 && en_snowloss)
alb = as_double("albedo_default_snow");
else
alb = as_double("albedo_default");
if (!use_wf_albedo && n_alb_errs < 5) // display warning up to 5 times
{
log(util::format("Albedo input value is not valid for time step %d. Using default albedo value of %f (snow) or %f (no snow). This warning only appears for the first five instances of this error.", idx, as_double("albedo_default_snow"), as_double("albedo_default")), SSC_NOTICE);
n_alb_errs++;
}
}
// report albedo value as output
p_alb[idx] = (ssc_number_t)alb;
irr.set_time(wf.year, wf.month, wf.day, wf.hour, wf.minute,
instantaneous ? IRRADPROC_NO_INTERPOLATE_SUNRISE_SUNSET : ts_hour);
irr.set_location(hdr.lat, hdr.lon, hdr.tz);
irr.set_optional(hdr.elev, wf.pres, wf.tdry);
irr.set_sky_model(irrad::PEREZ, alb);
irr.set_beam_diffuse(wf.dn, wf.df);
int track_mode = 0;
switch (pv.type)
{
case FIXED_RACK:
case FIXED_ROOF:
track_mode = 0;
break;
case ONE_AXIS:
case ONE_AXIS_BACKTRACKING:
track_mode = 1;
break;
case TWO_AXIS:
track_mode = 2;
break;
case AZIMUTH_AXIS:
track_mode = 3;
break;
}
irr.set_surface(track_mode, pv.tilt, pv.azimuth, pv.rotlim,
pv.type == ONE_AXIS_BACKTRACKING, // backtracking mode
pv.gcr, 0.0, 0.0, false, 0.0);
int code = irr.calc();
//create variables to store outputs
double solazi, solzen, solalt, aoi, stilt, sazi, rot, btd;
int sunup;
double ibeam = 0.0, iskydiff = 0.0, ignddiff = 0.0, irear = 0.0;
double poa = 0.0, tpoa = 0.0, tmod = 0.0, dc = 0.0, ac = 0.0;
irr.get_sun(&solazi, &solzen, &solalt, nullptr, nullptr, nullptr, &sunup, nullptr, nullptr, nullptr); //nullptr used when you don't need to retrieve the output
irr.get_angles(&aoi, &stilt, &sazi, &rot, &btd);
irr.get_poa(&ibeam, &iskydiff, &ignddiff, nullptr, nullptr, nullptr); //nullptr used when you don't need to retrieve the output
irr.get_optional(&elev, &pres, &t_amb);
if (module.bifaciality > 0)
{
irr.calc_rear_side(bifacialTransmissionFactor, 1, module.length * pv.nmody);
irear = irr.get_poa_rear() * module.bifaciality; //total rear irradiance is returned, so must multiply module bifaciality
}
if (-1 == code)
{
log(util::format("Beam irradiance exceeded extraterrestrial value at record [year:%d month:%d day:%d hour:%d minute:%lg].",
wf.year, wf.month, wf.day, wf.hour, wf.minute));
}
else if (0 != code)
throw exec_error("pvwattsv8",
util::format("Failed to process irradiation on surface (message: %s) [year:%d month:%d day:%d hour:%d minute:%lg].",
irr.getErrorMessage().c_str(), wf.year, wf.month, wf.day, wf.hour, wf.minute));
p_sunup[idx] = (ssc_number_t)sunup;
p_aoi[idx] = (ssc_number_t)aoi;
double shad_beam = 1.0;
if (shad.fbeam(hour_of_year, wf.minute, solalt, solazi))
shad_beam = shad.beam_shade_factor();
p_shad_beam[idx] = (ssc_number_t)shad_beam;
p_ss_beam[idx] = (ssc_number_t)1.0;
p_ss_sky_diffuse[idx] = (ssc_number_t)1.0;
p_ss_gnd_diffuse[idx] = (ssc_number_t)1.0;
if (sunup > 0)
{
// save the total available POA for the loss diagram
if (y == 0 && wdprov->annualSimulation()) ld("poa_nominal") += (ibeam + iskydiff + ignddiff) * wm2_to_wh;
if (y == 0 && wdprov->annualSimulation()) ld("poa_loss_bifacial") += (-irear) * wm2_to_wh;
// check for wind stowing on trackers
if ((pv.type == ONE_AXIS
|| pv.type == ONE_AXIS_BACKTRACKING
|| pv.type == TWO_AXIS)
&& std::isfinite(wf.wspd) && wf.wspd > 0
&& std::isfinite(wstow)
&& enable_wind_stow)
{
double gust = gf * wf.wspd;
if (gust > wstow)
{
// save poa before going into stow position
double poa_no_stow = ibeam + iskydiff + ignddiff;
if (pv.type == TWO_AXIS)
{
// two axis tracker stows at the horizontal position
// easiest way to do this in two dimensions is to set it as a flat fixed tilt system
// because the force to stow flag only fixes one rotation angle, not both
irr.set_surface(irrad::FIXED_TILT, // tracking 0=fixed
0, 180, // tilt, azimuth
0, 0, 0.4, 0.0, 0.0, false, 0.0); // rotlim, bt, gcr, force to stow, stow angle
}