bifacial-radiance 0.5.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bifacial_radiance/HPCScripts/BasicSimulations/addNewModule.py +15 -0
- bifacial_radiance/HPCScripts/BasicSimulations/dask_on_node.sh +11 -0
- bifacial_radiance/HPCScripts/BasicSimulations/run_sbatch.sbatch +51 -0
- bifacial_radiance/HPCScripts/BasicSimulations/simulate_fixedtilt_gencumsky.py +110 -0
- bifacial_radiance/HPCScripts/BasicSimulations/simulate_fixedtilt_gendaylit.py +102 -0
- bifacial_radiance/HPCScripts/BasicSimulations/simulate_tracking_gendaylit.py +126 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/PuertoRico.py +168 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/PuertoRico_2.py +166 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/PuertoRico_Original.py +195 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/basic_module_sampling.py +154 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_B.py +162 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_Cases.py +122 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_CasesMonth.py +142 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_PRNew.py +91 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_PRNewP2.py +95 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_TreeResults.py +108 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/compile_basic_module_sampling.py +103 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/simulate_JackHourly.py +160 -0
- bifacial_radiance/HPCScripts/Other Examples (unorganized)/simulate_improvedArray_Oct2127.py +623 -0
- bifacial_radiance/TEMP/.gitignore +4 -0
- bifacial_radiance/__init__.py +24 -0
- bifacial_radiance/data/CEC Modules.csv +16860 -0
- bifacial_radiance/data/default.ini +65 -0
- bifacial_radiance/data/falsecolor.exe +0 -0
- bifacial_radiance/data/gencumsky/License.txt +54 -0
- bifacial_radiance/data/gencumsky/Makefile +17 -0
- bifacial_radiance/data/gencumsky/README.txt +9 -0
- bifacial_radiance/data/gencumsky/Solar Irradiation Modelling.doc +0 -0
- bifacial_radiance/data/gencumsky/Sun.cpp +118 -0
- bifacial_radiance/data/gencumsky/Sun.h +45 -0
- bifacial_radiance/data/gencumsky/average_val.awk +3 -0
- bifacial_radiance/data/gencumsky/cPerezSkyModel.cpp +238 -0
- bifacial_radiance/data/gencumsky/cPerezSkyModel.h +57 -0
- bifacial_radiance/data/gencumsky/cSkyVault.cpp +536 -0
- bifacial_radiance/data/gencumsky/cSkyVault.h +86 -0
- bifacial_radiance/data/gencumsky/climateFile.cpp +312 -0
- bifacial_radiance/data/gencumsky/climateFile.h +37 -0
- bifacial_radiance/data/gencumsky/cumulative.cal +177 -0
- bifacial_radiance/data/gencumsky/cumulative.rad +14 -0
- bifacial_radiance/data/gencumsky/cumulativesky_rotated.rad +2 -0
- bifacial_radiance/data/gencumsky/gencumulativesky +0 -0
- bifacial_radiance/data/gencumsky/gencumulativesky.cpp +269 -0
- bifacial_radiance/data/gencumsky/make_gencumskyexe.py +107 -0
- bifacial_radiance/data/gencumsky/paths.h +62 -0
- bifacial_radiance/data/gencumulativesky +0 -0
- bifacial_radiance/data/gencumulativesky.exe +0 -0
- bifacial_radiance/data/ground.rad +83 -0
- bifacial_radiance/data/module.json +103 -0
- bifacial_radiance/gui.py +1696 -0
- bifacial_radiance/images/fig1_fixed_small.gif +0 -0
- bifacial_radiance/images/fig2_tracked_small.gif +0 -0
- bifacial_radiance/load.py +1156 -0
- bifacial_radiance/main.py +5673 -0
- bifacial_radiance/mismatch.py +461 -0
- bifacial_radiance/modelchain.py +299 -0
- bifacial_radiance/module.py +1427 -0
- bifacial_radiance/performance.py +466 -0
- bifacial_radiance/spectral_utils.py +555 -0
- bifacial_radiance-0.5.1.dist-info/METADATA +129 -0
- bifacial_radiance-0.5.1.dist-info/RECORD +63 -0
- bifacial_radiance-0.5.1.dist-info/WHEEL +6 -0
- bifacial_radiance-0.5.1.dist-info/licenses/LICENSE +30 -0
- bifacial_radiance-0.5.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
#include "./cSkyVault.h"
|
|
2
|
+
#define _USE_MATH_DEFINES
|
|
3
|
+
#include <math.h>
|
|
4
|
+
|
|
5
|
+
//////////////////////////
|
|
6
|
+
// Sky Vault
|
|
7
|
+
//////////////////////////
|
|
8
|
+
|
|
9
|
+
cSkyVault::cSkyVault(double latitude, double longitude):
|
|
10
|
+
m_latitude(latitude), m_longitude(longitude), m_SkyCalculated(false)
|
|
11
|
+
{
|
|
12
|
+
double defaultvalues[7]={12,12,15,15,20,30,60};
|
|
13
|
+
// double defaultvalues[14]={6,6,6,6,7.5,7.5,7.5,7.5,10,10,15,15,30,30};
|
|
14
|
+
double Az, Alt, DeltaAz, DeltaAlt;
|
|
15
|
+
|
|
16
|
+
int i,j,pointer;
|
|
17
|
+
pointer=0;
|
|
18
|
+
double SkyAziIncrement[7];
|
|
19
|
+
for (i=0; i<7; i++)
|
|
20
|
+
{
|
|
21
|
+
for (j=0; j<1;j++)
|
|
22
|
+
{
|
|
23
|
+
SkyAziIncrement[pointer]=defaultvalues[i];
|
|
24
|
+
pointer++;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
int CurrentPatch;
|
|
29
|
+
|
|
30
|
+
// initialise array pointer to 0
|
|
31
|
+
m_ptRadiance=0;
|
|
32
|
+
|
|
33
|
+
// create sky patches
|
|
34
|
+
m_NumPatches=145;
|
|
35
|
+
|
|
36
|
+
m_ptPatchAlt=new double[m_NumPatches];
|
|
37
|
+
m_ptPatchAz=new double[m_NumPatches];
|
|
38
|
+
m_ptPatchDeltaAlt=new double[m_NumPatches];
|
|
39
|
+
m_ptPatchDeltaAz=new double[m_NumPatches];
|
|
40
|
+
m_ptPatchLuminance=new double[m_NumPatches];
|
|
41
|
+
m_ptPatchSolidAngle=new double[m_NumPatches];
|
|
42
|
+
|
|
43
|
+
m_ptRadiance=new float[8760][145];
|
|
44
|
+
|
|
45
|
+
CurrentPatch=0;
|
|
46
|
+
|
|
47
|
+
DeltaAlt=12;
|
|
48
|
+
pointer=0;
|
|
49
|
+
|
|
50
|
+
for (Alt=DeltaAlt/2; Alt<=84; Alt+=DeltaAlt)
|
|
51
|
+
{
|
|
52
|
+
DeltaAz=SkyAziIncrement[pointer];
|
|
53
|
+
for (Az=0; Az <= 360-DeltaAz; Az+=DeltaAz)
|
|
54
|
+
{
|
|
55
|
+
// set each patch's position and size
|
|
56
|
+
m_ptPatchAlt[CurrentPatch]=Alt*M_PI/180;
|
|
57
|
+
m_ptPatchAz[CurrentPatch]=Az*M_PI/180;
|
|
58
|
+
m_ptPatchDeltaAlt[CurrentPatch]=DeltaAlt*M_PI/180;
|
|
59
|
+
m_ptPatchDeltaAz[CurrentPatch]=DeltaAz*M_PI/180;
|
|
60
|
+
m_ptPatchSolidAngle[CurrentPatch]=2*M_PI*(sin(m_ptPatchAlt[CurrentPatch]+m_ptPatchDeltaAlt[CurrentPatch]/2)-sin(m_ptPatchAlt[CurrentPatch]-m_ptPatchDeltaAlt[CurrentPatch]/2))/(2*M_PI/m_ptPatchDeltaAz[CurrentPatch]);
|
|
61
|
+
CurrentPatch++;
|
|
62
|
+
}
|
|
63
|
+
pointer++;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// zenith patch (last patch is always top patch)
|
|
67
|
+
m_ptPatchAlt[CurrentPatch]=M_PI/2;
|
|
68
|
+
m_ptPatchAz[CurrentPatch]=0;
|
|
69
|
+
m_ptPatchDeltaAlt[CurrentPatch]=6*M_PI/180;
|
|
70
|
+
m_ptPatchDeltaAz[CurrentPatch]=2*M_PI;
|
|
71
|
+
m_ptPatchSolidAngle[CurrentPatch]=2*M_PI*(sin(m_ptPatchAlt[CurrentPatch])-sin(m_ptPatchAlt[CurrentPatch]-m_ptPatchDeltaAlt[CurrentPatch]))/(2*M_PI/m_ptPatchDeltaAz[CurrentPatch]);
|
|
72
|
+
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
cSkyVault::~cSkyVault(void)
|
|
77
|
+
{
|
|
78
|
+
delete[] m_ptPatchAlt;
|
|
79
|
+
delete[] m_ptPatchAz;
|
|
80
|
+
delete[] m_ptPatchDeltaAlt;
|
|
81
|
+
delete[] m_ptPatchDeltaAz;
|
|
82
|
+
delete[] m_ptPatchLuminance;
|
|
83
|
+
delete[] m_ptPatchSolidAngle;
|
|
84
|
+
delete[] m_ptRadiance;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void cSkyVault::GetPatchDetails(double (*ptPatchDat)[5])
|
|
88
|
+
{
|
|
89
|
+
int i;
|
|
90
|
+
|
|
91
|
+
for (i=0; i<m_NumPatches; i++)
|
|
92
|
+
{
|
|
93
|
+
ptPatchDat[i][0] = m_ptPatchAlt[i];
|
|
94
|
+
ptPatchDat[i][1] = m_ptPatchAz[i];
|
|
95
|
+
ptPatchDat[i][2] = m_ptPatchDeltaAlt[i];
|
|
96
|
+
ptPatchDat[i][3] = m_ptPatchDeltaAz[i];
|
|
97
|
+
ptPatchDat[i][4] = m_ptPatchSolidAngle[i];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
bool cSkyVault::LoadClimateFile(char *filename, cClimateFile::eClimateFileFormat ClimateFileFormat,double StartTime, double EndTime, int StartDay, int EndDay, int StartMonth, int EndMonth)
|
|
104
|
+
{
|
|
105
|
+
return m_ClimateFile.ReadClimateFile(filename,0, ClimateFileFormat, StartTime, EndTime, StartDay, EndDay, StartMonth, EndMonth);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
bool cSkyVault::SetLatitude(double latitude)
|
|
109
|
+
{
|
|
110
|
+
if (latitude <= M_PI/2 && latitude >= -M_PI/2)
|
|
111
|
+
{
|
|
112
|
+
m_latitude=latitude;
|
|
113
|
+
m_Sun.SetLatitude(m_latitude);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
bool cSkyVault::SetLongitude(double longitude)
|
|
121
|
+
{
|
|
122
|
+
if (longitude <= M_PI && longitude >= -M_PI)
|
|
123
|
+
{
|
|
124
|
+
m_longitude=longitude;
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
bool cSkyVault::SetMeridian(double meridian)
|
|
132
|
+
{
|
|
133
|
+
|
|
134
|
+
m_meridian=meridian;
|
|
135
|
+
m_Sun.SetMeridian(m_meridian);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void cSkyVault::CalculateSky(cSkyVault::eSunType Suns, bool DoDiffuse, bool DoIlluminance, double hourshift)
|
|
140
|
+
{
|
|
141
|
+
// calculates sky patch radiance distribution for whole year (0:30 1st Jan -> 23:30 31st Dec)
|
|
142
|
+
int i, j,SunPatch;
|
|
143
|
+
|
|
144
|
+
double hour;
|
|
145
|
+
int day, index;
|
|
146
|
+
|
|
147
|
+
double CosMinSunDist, CosSunDist;
|
|
148
|
+
double SunAlt, SunAz;
|
|
149
|
+
|
|
150
|
+
double *ptLv, EIllum;
|
|
151
|
+
double PatchAltitude, PatchAzimuth, Idh, Ibh, Ibn;
|
|
152
|
+
|
|
153
|
+
double sunset, sunrise, hourangle;
|
|
154
|
+
int AltIndex, AzIndex;
|
|
155
|
+
|
|
156
|
+
const double BINSIZE=5;
|
|
157
|
+
|
|
158
|
+
double x,y,z,SolarRadiance;
|
|
159
|
+
double halfsolarangle=0.02665; //degrees
|
|
160
|
+
// double halfsolarangle=0.2665; //degrees
|
|
161
|
+
// double halfsolarangle=1.2665; //degrees
|
|
162
|
+
double temp=0;
|
|
163
|
+
|
|
164
|
+
// 5 degree bins of sun position
|
|
165
|
+
double SunRadiance[18][72];
|
|
166
|
+
// various arrays to keep track of the actual positions of the suns that were binned into a particular sun
|
|
167
|
+
double AltxIbh[18][72];
|
|
168
|
+
double AzxIbh[18][72];
|
|
169
|
+
double NxIbh[18][72];
|
|
170
|
+
int SunUpHourCount=0;
|
|
171
|
+
double NormFac;
|
|
172
|
+
|
|
173
|
+
for (i=0; i<18; i++)
|
|
174
|
+
{
|
|
175
|
+
for (j=0; j<72; j++)
|
|
176
|
+
{
|
|
177
|
+
SunRadiance[i][j]=0;
|
|
178
|
+
AltxIbh[i][j]=0;
|
|
179
|
+
AzxIbh[i][j]=0;
|
|
180
|
+
NxIbh[i][j]=0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const char *SunFileName="SunFile.rad";
|
|
184
|
+
FILE *SunFile;
|
|
185
|
+
if (Suns==MANY_SUNS)
|
|
186
|
+
{
|
|
187
|
+
// open file for sun data (checking that you can...)
|
|
188
|
+
if ((SunFile=fopen(SunFileName,"w"))==NULL)
|
|
189
|
+
{
|
|
190
|
+
fprintf(stderr,"Error opening: %s\n",SunFileName);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
for (day=1; day<=365; day++)
|
|
197
|
+
{
|
|
198
|
+
|
|
199
|
+
// setup sun position
|
|
200
|
+
m_Sun.SetDay(day);
|
|
201
|
+
|
|
202
|
+
sunrise=m_Sun.GetSunrise();
|
|
203
|
+
sunset=2*M_PI - sunrise;
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
for (hour=.5; hour<24; hour++)
|
|
208
|
+
{
|
|
209
|
+
EIllum=0;
|
|
210
|
+
CosMinSunDist=-999;
|
|
211
|
+
|
|
212
|
+
index=(day-1)*24+(int)hour;
|
|
213
|
+
ptLv=new double[m_NumPatches];
|
|
214
|
+
|
|
215
|
+
// !!!!!!!!!!!!!!!!!!!!!!
|
|
216
|
+
hourangle=(hour+hourshift+m_Sun.TimeDiff(m_longitude,m_meridian))*M_PI/12;
|
|
217
|
+
// TODO: UNCOMMENT THESE LINES
|
|
218
|
+
// if this is the first/last sun-up hour of the day, use the average position for while it is up
|
|
219
|
+
if (fabs(hourangle-sunrise)<M_PI/24)
|
|
220
|
+
hourangle=(hourangle+M_PI/24+sunrise)/2;
|
|
221
|
+
else if (fabs(hourangle-sunset)<M_PI/24)
|
|
222
|
+
hourangle=(hourangle-M_PI/24+sunset)/2;
|
|
223
|
+
|
|
224
|
+
m_Sun.SetHourAngle(hourangle);
|
|
225
|
+
m_Sun.GetPosition(SunAlt,SunAz);
|
|
226
|
+
|
|
227
|
+
// get diffuse horizontal irradiation from climate file
|
|
228
|
+
Idh=m_ClimateFile.GetDiffuseRad(hour,day);
|
|
229
|
+
Ibh=m_ClimateFile.GetDirectRad(hour,day);
|
|
230
|
+
|
|
231
|
+
//Tito
|
|
232
|
+
//fprintf(stderr,"Report: %d %.1f dir %.0f dif %.0f, long %.0f mer %.0f",day,hour,Ibh,Idh,m_longitude*180/M_PI,m_meridian*180/M_PI);
|
|
233
|
+
//fprintf(stderr, "sun position %.2f %.2f hour ang %.2f time Diff %f\n",SunAlt*180/M_PI,SunAz*180/M_PI,12/M_PI*hourangle,12/M_PI*m_Sun.TimeDiff(m_longitude,m_meridian));
|
|
234
|
+
|
|
235
|
+
if (Idh < 0) Idh=0;
|
|
236
|
+
if (Ibh < 0) Ibh=0;
|
|
237
|
+
|
|
238
|
+
// setup sky model
|
|
239
|
+
if (!m_SkyModel.SetSkyConditions(Idh,Ibh,&m_Sun))
|
|
240
|
+
goto NextHour;
|
|
241
|
+
|
|
242
|
+
CosSunDist=-1;
|
|
243
|
+
for (i=0; i<m_NumPatches; i++)
|
|
244
|
+
{
|
|
245
|
+
// first calculate relative luminance and scaling factor
|
|
246
|
+
PatchAltitude=m_ptPatchAlt[i];
|
|
247
|
+
PatchAzimuth=m_ptPatchAz[i];
|
|
248
|
+
|
|
249
|
+
ptLv[i]=m_SkyModel.GetRelativeLuminance(PatchAltitude,PatchAzimuth);
|
|
250
|
+
EIllum+= ptLv[i]*m_ptPatchSolidAngle[i]*sin(PatchAltitude);
|
|
251
|
+
|
|
252
|
+
// work out distance of sun from this patch
|
|
253
|
+
CosSunDist = cos(SunAlt)*cos(fabs(SunAz-PatchAzimuth))*cos(PatchAltitude) + sin(SunAlt)*sin(PatchAltitude);
|
|
254
|
+
|
|
255
|
+
if (CosSunDist > CosMinSunDist)
|
|
256
|
+
{
|
|
257
|
+
CosMinSunDist=CosSunDist;
|
|
258
|
+
SunPatch=i;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
if (SunAlt> 0)
|
|
263
|
+
Ibn=Ibh/sin(SunAlt);
|
|
264
|
+
else
|
|
265
|
+
Ibn=0;
|
|
266
|
+
|
|
267
|
+
if (Ibn> 1367)
|
|
268
|
+
{
|
|
269
|
+
// Very large value for direct radiation - probably low solar altitude
|
|
270
|
+
Idh=Idh+Ibh;
|
|
271
|
+
Ibn=0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (DoIlluminance)
|
|
275
|
+
NormFac=Idh*m_SkyModel.GetDiffuseLumEffy(SunAlt,0.0);
|
|
276
|
+
else
|
|
277
|
+
NormFac=Idh;
|
|
278
|
+
|
|
279
|
+
if (EIllum>0)
|
|
280
|
+
SunUpHourCount++;
|
|
281
|
+
|
|
282
|
+
for (i=0; i<m_NumPatches; i++)
|
|
283
|
+
{
|
|
284
|
+
if ((EIllum > 0) && DoDiffuse)
|
|
285
|
+
{
|
|
286
|
+
m_ptRadiance[index][i]=ptLv[i]*NormFac/EIllum;
|
|
287
|
+
}
|
|
288
|
+
else
|
|
289
|
+
m_ptRadiance[index][i]=0;
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (DoIlluminance)
|
|
294
|
+
NormFac=Ibn*m_SkyModel.GetBeamLumEffy(SunAlt,0.0);
|
|
295
|
+
else
|
|
296
|
+
NormFac=Ibn;
|
|
297
|
+
|
|
298
|
+
// now do sun
|
|
299
|
+
if (Suns==CUMULATIVE_SUN)
|
|
300
|
+
{
|
|
301
|
+
// add on direct radiation to patch with sun in
|
|
302
|
+
if (SunAlt > 0 && Ibn >0)
|
|
303
|
+
m_ptRadiance[index][SunPatch]+= NormFac/(m_ptPatchSolidAngle[SunPatch]);
|
|
304
|
+
}
|
|
305
|
+
else if (Suns==MANY_SUNS && Ibn>0 && m_SkyModel.GetSkyClearness() > 1 )
|
|
306
|
+
{
|
|
307
|
+
// Work out solar radiance
|
|
308
|
+
SolarRadiance=NormFac/(2.0*M_PI*(1-cos(halfsolarangle*M_PI/180)));
|
|
309
|
+
|
|
310
|
+
AltIndex=(int)(SunAlt/(BINSIZE*M_PI/180));
|
|
311
|
+
AzIndex=(int)(SunAz/(BINSIZE*M_PI/180));
|
|
312
|
+
|
|
313
|
+
if (DoIlluminance)
|
|
314
|
+
NormFac=Ibh*m_SkyModel.GetBeamLumEffy(SunAlt,0.0);
|
|
315
|
+
else
|
|
316
|
+
NormFac=Ibh;
|
|
317
|
+
|
|
318
|
+
AltxIbh[AltIndex][AzIndex]+=SunAlt*NormFac;
|
|
319
|
+
AzxIbh[AltIndex][AzIndex]+=SunAz*NormFac;
|
|
320
|
+
NxIbh[AltIndex][AzIndex]+=NormFac;
|
|
321
|
+
}
|
|
322
|
+
delete ptLv;
|
|
323
|
+
NextHour:
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
fprintf(stderr,"There were %d sun up hours in this climate file\n",SunUpHourCount);
|
|
328
|
+
|
|
329
|
+
// work out cumulative sky
|
|
330
|
+
m_CumSky = new double[m_NumPatches];
|
|
331
|
+
|
|
332
|
+
// if we are doing the annual irradiance output the total, for illuminance output the mean
|
|
333
|
+
if (!DoIlluminance)
|
|
334
|
+
SunUpHourCount=1;
|
|
335
|
+
|
|
336
|
+
for (i=0; i<m_NumPatches; i++)
|
|
337
|
+
{
|
|
338
|
+
m_CumSky[i]=0;
|
|
339
|
+
for (j=0; j<8760; j++)
|
|
340
|
+
{
|
|
341
|
+
m_CumSky[i]+=m_ptRadiance[j][i]/SunUpHourCount;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// output the suns
|
|
345
|
+
if (Suns==MANY_SUNS)
|
|
346
|
+
{
|
|
347
|
+
//////////////////////
|
|
348
|
+
temp =0;
|
|
349
|
+
for (day=1; day<=365; day++)
|
|
350
|
+
// for (day=91; day<=273; day++)
|
|
351
|
+
{
|
|
352
|
+
sunrise=m_Sun.GetSunrise();
|
|
353
|
+
sunset=2*M_PI - sunrise;
|
|
354
|
+
|
|
355
|
+
//Tito for (hour=0; hour<24; hour+=0.25)
|
|
356
|
+
for (hour=0.5; hour<24; hour++)
|
|
357
|
+
|
|
358
|
+
// for (hour=12.5; hour<=16.5; hour++)
|
|
359
|
+
{
|
|
360
|
+
CosMinSunDist=-999;
|
|
361
|
+
|
|
362
|
+
// setup sun position
|
|
363
|
+
m_Sun.SetDay(day);
|
|
364
|
+
hourangle=(hour+m_Sun.TimeDiff(m_longitude,m_meridian))*M_PI/12;
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
m_Sun.SetHourAngle(hourangle);
|
|
369
|
+
m_Sun.GetPosition(SunAlt,SunAz);
|
|
370
|
+
|
|
371
|
+
// we impose a minimum on the solar altitude to avoid extremely bright low altitude suns
|
|
372
|
+
if (SunAlt<3*M_PI/180 && SunAlt>0) // 6 degrees is minimum alt for circumsolar region in perez mod.
|
|
373
|
+
{
|
|
374
|
+
SunAlt=3*M_PI/180;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Tito: commented statement out
|
|
378
|
+
//if (SunAlt < 49*M_PI/180)
|
|
379
|
+
// continue;
|
|
380
|
+
|
|
381
|
+
// get diffuse horizontal irradiation from climate file
|
|
382
|
+
Idh=m_ClimateFile.GetDiffuseRad(hour,day);
|
|
383
|
+
Ibh=m_ClimateFile.GetDirectRad(hour,day);
|
|
384
|
+
|
|
385
|
+
if (Idh < 0) Idh=0;
|
|
386
|
+
if (Ibh < 0) Ibh=0;
|
|
387
|
+
|
|
388
|
+
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
389
|
+
//Ibh=0.25;
|
|
390
|
+
|
|
391
|
+
if (SunAlt> 0)
|
|
392
|
+
Ibn=Ibh/sin(SunAlt);
|
|
393
|
+
else
|
|
394
|
+
Ibn=0;
|
|
395
|
+
|
|
396
|
+
if (Ibn> 1367)
|
|
397
|
+
{
|
|
398
|
+
// Very large value for direct radiation - probably low solar altitude
|
|
399
|
+
Ibn=0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
CosSunDist=-1;
|
|
403
|
+
for (i=0; i<m_NumPatches; i++)
|
|
404
|
+
{
|
|
405
|
+
// first calculate relative luminance and scaling factor
|
|
406
|
+
PatchAltitude=m_ptPatchAlt[i];
|
|
407
|
+
PatchAzimuth=m_ptPatchAz[i];
|
|
408
|
+
|
|
409
|
+
// work out distance of sun from this patch
|
|
410
|
+
CosSunDist = cos(SunAlt)*cos(fabs(SunAz-PatchAzimuth))*cos(PatchAltitude) + sin(SunAlt)*sin(PatchAltitude);
|
|
411
|
+
|
|
412
|
+
if (CosSunDist > CosMinSunDist)
|
|
413
|
+
{
|
|
414
|
+
CosMinSunDist=CosSunDist;
|
|
415
|
+
SunPatch=i;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
}
|
|
419
|
+
if (SunAlt >=0)
|
|
420
|
+
{
|
|
421
|
+
SolarRadiance=Ibn/(2.0*M_PI*(1-cos(halfsolarangle*M_PI/180))) ; // !!!!!!!!!!!!!!!!+m_CumSky[SunPatch];
|
|
422
|
+
|
|
423
|
+
temp+=SolarRadiance*(2.0*M_PI*(1-cos(halfsolarangle*M_PI/180)));
|
|
424
|
+
|
|
425
|
+
// work out sun direction in x,y,z form
|
|
426
|
+
x=sin(SunAz)*cos(SunAlt);
|
|
427
|
+
y=cos(SunAz)*cos(SunAlt);
|
|
428
|
+
z=sin(SunAlt);
|
|
429
|
+
|
|
430
|
+
fprintf(SunFile,"\nvoid light solar\n");
|
|
431
|
+
fprintf(SunFile,"0\n0\n");
|
|
432
|
+
fprintf(SunFile,"3 %.3e %.3e %.3e",SolarRadiance,SolarRadiance,SolarRadiance);
|
|
433
|
+
|
|
434
|
+
fprintf(SunFile,"\nsolar source sun\n");
|
|
435
|
+
fprintf(SunFile,"0\n0\n");
|
|
436
|
+
fprintf(SunFile,"4 %f %f %f %f\n",x,y,z,2*halfsolarangle);
|
|
437
|
+
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
/////////////
|
|
446
|
+
// double BinnedSunAlt, BinnedSunAz;
|
|
447
|
+
|
|
448
|
+
// for (BinnedSunAlt=BINSIZE/2.0; BinnedSunAlt<90; BinnedSunAlt+=BINSIZE)
|
|
449
|
+
// {
|
|
450
|
+
// for (BinnedSunAz=BINSIZE/2.0; BinnedSunAz<360; BinnedSunAz+=BINSIZE)
|
|
451
|
+
// {
|
|
452
|
+
// AltIndex=(int)(BinnedSunAlt/BINSIZE);
|
|
453
|
+
// AzIndex=(int)(BinnedSunAz/BINSIZE);
|
|
454
|
+
|
|
455
|
+
// if (NxIbh[AltIndex][AzIndex]>0)
|
|
456
|
+
// {
|
|
457
|
+
// SunAlt=AltxIbh[AltIndex][AzIndex]/NxIbh[AltIndex][AzIndex];
|
|
458
|
+
// SunAz=AzxIbh[AltIndex][AzIndex]/NxIbh[AltIndex][AzIndex];
|
|
459
|
+
|
|
460
|
+
// if (fabs(SunAlt*180/M_PI-BinnedSunAlt)>2.5)
|
|
461
|
+
// fprintf(stderr,"Altitude wrong %f %f %f %f\n",SunAlt*180/M_PI, BinnedSunAlt,AltxIbh[AltIndex][AzIndex],NxIbh[AltIndex][AzIndex]);
|
|
462
|
+
// if (fabs(SunAz*180/M_PI-BinnedSunAz)>2.5)
|
|
463
|
+
// fprintf(stderr,"Az wrong %f %f\n",SunAz*180/M_PI, BinnedSunAz);
|
|
464
|
+
|
|
465
|
+
// // find sky patch closest to the sun so we can add on its radiance
|
|
466
|
+
// for (i=0; i<m_NumPatches; i++)
|
|
467
|
+
// {
|
|
468
|
+
// PatchAltitude=m_ptPatchAlt[i];
|
|
469
|
+
// PatchAzimuth=m_ptPatchAz[i];
|
|
470
|
+
|
|
471
|
+
// // work out distance of sun from this patch
|
|
472
|
+
// CosSunDist = cos(SunAlt)*cos(fabs(SunAz-PatchAzimuth))*cos(PatchAltitude) + sin(SunAlt)*sin(PatchAltitude);
|
|
473
|
+
|
|
474
|
+
// if (CosSunDist > CosMinSunDist)
|
|
475
|
+
// {
|
|
476
|
+
// CosMinSunDist=CosSunDist;
|
|
477
|
+
// SunPatch=i;
|
|
478
|
+
// }
|
|
479
|
+
//
|
|
480
|
+
// }
|
|
481
|
+
//
|
|
482
|
+
// SunRadiance[AltIndex][AzIndex]=NxIbh[AltIndex][AzIndex]/(SunUpHourCount*2.0*M_PI*(1-cos(halfsolarangle*M_PI/180))*sin(SunAlt)) + m_CumSky[SunPatch];
|
|
483
|
+
|
|
484
|
+
// // work out sun direction in x,y,z form
|
|
485
|
+
// x=sin(SunAz)*cos(SunAlt);
|
|
486
|
+
// y=cos(SunAz)*cos(SunAlt);
|
|
487
|
+
// z=sin(SunAlt);
|
|
488
|
+
|
|
489
|
+
// fprintf(SunFile,"\nvoid light solar%d%d\n",AltIndex,AzIndex);
|
|
490
|
+
// fprintf(SunFile,"0\n0\n");
|
|
491
|
+
// fprintf(SunFile,"3 %.3e %.3e %.3e",SunRadiance[AltIndex][AzIndex],SunRadiance[AltIndex][AzIndex],SunRadiance[AltIndex][AzIndex]);
|
|
492
|
+
|
|
493
|
+
// fprintf(SunFile,"\nsolar%d%d source sun%d%d\n",AltIndex,AzIndex,AltIndex,AzIndex);
|
|
494
|
+
// fprintf(SunFile,"0\n0\n");
|
|
495
|
+
// fprintf(SunFile,"4 %f %f %f %f\n",x,y,z,2*halfsolarangle);
|
|
496
|
+
// }
|
|
497
|
+
// }
|
|
498
|
+
// }
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//temp=0;
|
|
502
|
+
//for (SunAlt=0; SunAlt<90; SunAlt+=BINSIZE)
|
|
503
|
+
//{
|
|
504
|
+
// for (SunAz=0; SunAz<360; SunAz+=BINSIZE)
|
|
505
|
+
// {
|
|
506
|
+
// AltIndex=(int)(SunAlt/BINSIZE);
|
|
507
|
+
// AzIndex=(int)(SunAz/BINSIZE);
|
|
508
|
+
// if (NxIbh[AltIndex][AzIndex]>0)
|
|
509
|
+
// temp+=SunRadiance[AltIndex][AzIndex]*(2.0*M_PI*(1-cos(halfsolarangle*M_PI/180)))*sin(AltxIbh[AltIndex][AzIndex]/NxIbh[AltIndex][AzIndex]);
|
|
510
|
+
// }
|
|
511
|
+
//}
|
|
512
|
+
//////////////
|
|
513
|
+
|
|
514
|
+
fprintf(stderr,"Total Ibh/Lbh: %f\n",temp);
|
|
515
|
+
m_SkyCalculated=true;
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
double* cSkyVault::GetCumulativeSky()
|
|
520
|
+
{
|
|
521
|
+
int i;
|
|
522
|
+
int j;
|
|
523
|
+
|
|
524
|
+
// double *CumSky = new double[m_NumPatches];
|
|
525
|
+
|
|
526
|
+
/* for (i=0; i<m_NumPatches; i++)
|
|
527
|
+
{
|
|
528
|
+
CumSky[i]=0;
|
|
529
|
+
for (j=0; j<8760; j++)
|
|
530
|
+
{
|
|
531
|
+
CumSky[i]+=m_ptRadiance[j][i];
|
|
532
|
+
}
|
|
533
|
+
}*/
|
|
534
|
+
return m_CumSky;
|
|
535
|
+
}
|
|
536
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#include "cPerezSkyModel.h"
|
|
2
|
+
#include "climateFile.h"
|
|
3
|
+
|
|
4
|
+
/////////////////////////////////////////////
|
|
5
|
+
// Check to see if cSkyVault has already been declared
|
|
6
|
+
#if (!defined(CSKYVAULT_H))
|
|
7
|
+
#define CSKYVAULT_H
|
|
8
|
+
|
|
9
|
+
class cSkyVault
|
|
10
|
+
{
|
|
11
|
+
public:
|
|
12
|
+
enum eSunType { NO_SUN, CUMULATIVE_SUN, MANY_SUNS };
|
|
13
|
+
|
|
14
|
+
cSkyVault(double latitude=51.7, double longitude=0);
|
|
15
|
+
~cSkyVault(void);
|
|
16
|
+
|
|
17
|
+
inline int GetNumberOfPatches() { return m_NumPatches; }
|
|
18
|
+
|
|
19
|
+
// updates PREDEFINED array pointed to by PatchDat with locations of sky patches and their sizes
|
|
20
|
+
// length m_NumPatches, 1st element altitude, 2nd azimuth (in rads), 2nd = deltaAlt, 3rd= deltaAz
|
|
21
|
+
void GetPatchDetails(double (*ptPatchDat)[5]);
|
|
22
|
+
|
|
23
|
+
// Calculate the sky radiance distribution for the whole year
|
|
24
|
+
void CalculateSky(eSunType Suns=NO_SUN, bool DoDiffuse=true, bool DoIlluminance=false, double hourshift=0);
|
|
25
|
+
|
|
26
|
+
bool LoadClimateFile(char *filename, cClimateFile::eClimateFileFormat ClimateFileFormat,double StartTime, double EndTime, int StartDay, int EndDay, int StartMonth, int EndMonth);
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
bool SetLatitude(double latitude);
|
|
31
|
+
bool SetLongitude(double longitude);
|
|
32
|
+
bool SetMeridian(double meridian);
|
|
33
|
+
|
|
34
|
+
// Temporary function to return the cumulative sky
|
|
35
|
+
double* GetCumulativeSky();
|
|
36
|
+
|
|
37
|
+
// start time and date; end time and date
|
|
38
|
+
double StartTime;
|
|
39
|
+
double EndTime;
|
|
40
|
+
int StartDay;
|
|
41
|
+
int EndDay;
|
|
42
|
+
int StartMonth;
|
|
43
|
+
int EndMonth;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
// number of patches in sky
|
|
48
|
+
int m_NumPatches;
|
|
49
|
+
|
|
50
|
+
// data for each sky patch
|
|
51
|
+
double *m_ptPatchAlt;
|
|
52
|
+
double *m_ptPatchAz;
|
|
53
|
+
double *m_ptPatchDeltaAlt;
|
|
54
|
+
double *m_ptPatchDeltaAz;
|
|
55
|
+
double *m_ptPatchLuminance;
|
|
56
|
+
double *m_ptPatchSolidAngle;
|
|
57
|
+
|
|
58
|
+
// Sky radiances (last element is mean annual radiance)
|
|
59
|
+
// define as float to improve run time (with minimal loss of accuracy)
|
|
60
|
+
float (*m_ptRadiance)[145];
|
|
61
|
+
|
|
62
|
+
// The sky luminance model to be used
|
|
63
|
+
cPerezSkyModel m_SkyModel;
|
|
64
|
+
|
|
65
|
+
// Climate file containing irradiation data
|
|
66
|
+
cClimateFile m_ClimateFile;
|
|
67
|
+
|
|
68
|
+
// Sun object (to handle solar geometry
|
|
69
|
+
cSun m_Sun;
|
|
70
|
+
|
|
71
|
+
// Remember whether or not we've already processed the sky
|
|
72
|
+
bool m_SkyCalculated;
|
|
73
|
+
|
|
74
|
+
// Cumulative sky
|
|
75
|
+
double *m_CumSky;
|
|
76
|
+
|
|
77
|
+
// radians
|
|
78
|
+
double m_latitude;
|
|
79
|
+
double m_longitude;
|
|
80
|
+
double m_meridian;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
#endif
|
|
86
|
+
//////////////////////////////////////////
|