-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathlib_pvshade.h
184 lines (144 loc) · 6.66 KB
/
lib_pvshade.h
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
/*
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.
*/
#ifndef __pvshade_h
#define __pvshade_h
#include <string>
#include <unordered_map>
#include <cmath>
#include "lib_util.h"
// Porting of sam_shading_type241.f90 to new orientation
// SUPPORTING STRUCTURES
// static self-shading inputs- these do not change with timestep. dynamic inputs are inputs to the ss_exec function
struct ssinputs
{
int nstrx, nmodx, nmody, nrows;
double length, width;
int mod_orient, str_orient;
double row_space;
int ndiode;
double Vmp;
int mask_angle_calc_method;
double FF0; // Fill Factor at STC = Pmp0 / Voc0 / Isc0;
//constructor for ssarrdat structure- set all values to zero
ssinputs() : nstrx(0), nmodx(0), nmody(0), nrows(0), length(0), width(0), mod_orient(0), str_orient(0), row_space(0), ndiode(0), Vmp(0), mask_angle_calc_method(0), FF0(0) {}
};
struct ssoutputs // self-shading outputs
{
double m_dc_derate;
double m_reduced_diffuse;
double m_reduced_reflected;
double m_diffuse_derate;
double m_reflected_derate;
double m_shade_frac_fixed;
};
// look up table for calculating the diffuse reduction due to gcr and tilt of the panels for self-shading
// added to removing duplicate computations for speed up (https://github.com/NREL/ssc/issues/384)
class sssky_diffuse_table
{
std::unordered_map<int, double> derates_table; // stores pairs of surface tilts and derates
size_t derates_table_digits = 0;
size_t derates_table_digits_multiplier = std::pow(10, derates_table_digits);
double gcr; // 0.01 - 0.99
double compute(double surface_tilt);
public:
sssky_diffuse_table(): gcr(0) {}
// initialize with the ground coverage ratio (fixed per PV simulation) and the starting tilt
void init(double surface_tilt, double groundCoverageRatio) { gcr = groundCoverageRatio; compute(surface_tilt); }
// return the sky diffuse derate for the panel at given surface_tilt
double lookup(double surface_tilt);
};
// SUPPORTING FUNCTIONS
bool selfshade_simple(
/* system parameters */
int ncells, // number of cells in panel
double area, // panel area in m2
int orientation, // 0 = landscape, 1 = portrait
int panels_up, // number of panels along the edge of a row
double FF_stc, // fill factor @ STC = Pmp0 / Voc0 / Isc0;
/* current conditions */
double solzen, // solar zenith angle (deg)
double solazi, // solar azimuth angle (deg)
double beam_horiz, // beam irradiance on the horizontal surface (W/m2)
double diff_poa, // total diffuse irradiance on the tilted surface (W/m2)
double albedo, // ground reflectance [0..1]
/* calculated outputs */
double *dc_derate,
double *skydiff_derate,
double *gnddiff_derate );
void diffuse_reduce(
// inputs (angles in degrees)
double solzen,
double stilt,
double Gb_nor,
double Gdh,
double poa_sky,
double poa_gnd,
double gcr,
// double phi0, // mask angle
double alb,
double nrows,
sssky_diffuse_table &skydiffderates,
// outputs
double &reduced_skydiff,
double &Fskydiff, // derate factor on sky diffuse
double &reduced_gnddiff,
double &Fgnddiff); // derate factor on ground diffuse
double selfshade_dc_derate( double X,
double S,
double FF0, //fill factor
double dbh_ratio,
double m_d, //number of diodes
double Vmp); //module Vmp
void selfshade_xs_horstr( bool landscape, // modules oriented in landscape/portrait on assembly
double W, // module width (short side)
double L, // module length (long side)
int r, // number of rows
int m, // number of modules along row edge (short side of assembly)
int n, // number of modules along (long side of assembly)
int ndiode, // number of bypass diodes
double Fshad, // Fraction of assembly shaded up from long edge
// outputs
double &X, double &S);
// SELF-SHADING CALCULATION FUNCTION
// performs shading calculation and returns outputs
bool ss_exec(
const ssinputs &inputs,
double tilt, // module tilt (constant for fixed tilt, varies for one-axis)
double azimuth, // module azimuth (constant for fixed tilt, varies for one-axis)
double solzen, // solar zenith (deg)
double solazi, // solar azimuth (deg)
double Gb_nor, // beam normal irradiance (W/m2)
double Gdh, // diffuse horizontal irradiance (W/m2)
double Gb_poa, // POA beam irradiance (W/m2)
double poa_sky, // POA diffuse sky irradiance (W/m2)
double poa_gnd, // POA diffuse gnd irradiance (W/m2)
double albedo, // used to calculate reduced relected irradiance
bool trackmode, // 0 for fixed tilt, 1 for one-axis tracking
bool linear, // 0 for non-linear shading (C. Deline's full algorithm), 1 to stop at linear shading
double shade_frac_1x, // geometric calculation of the fraction of one-axis row that is shaded (0-1), not used if fixed tilt
sssky_diffuse_table &skydiffs, // lookup table for sky diffuse derates
ssoutputs &outputs);
#endif