-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
115 lines (101 loc) · 4.24 KB
/
test.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
"""
This will serve as a place to run unit tests,
as this is becoming more necessary,
Basic components of the code can be tested here
The idea is that this should be very quick to run,
and can be included the main run files, and run
prior to every simulation
"""
import poisson2D
import diffusion2D
import src.base.geom as g
import src.solar as solar
import src.casegeom as cg
import src.shading as shading
import numpy as np
import time as clocktime
import src.icsolar as icsolar
def runGeometryTest():
latitude = 40.707583
longitude = -74.010828
timezone = -5
solar.setTimezone(timezone)
solar.setLocation(latitude,longitude)
geometry = cg.readFile('data/geometry/whole-building.txt',"whole-building")
geom = geometry[13]
nS = -shading.getSolarVectorAtTime(11.5*3600)
assert abs(geometry.getUnshadedFraction(geom,nS) - 0.5097854) < 1e-6, \
"failed sunlit fraction test"
geometrySet2 = g.GeometrySet('tilt')
geometrySet2.append(geom)
oldg = g.Geometry([np.copy(c) for c in geom])
geom.rotate(np.array([1,1,1]),geom[0],0)
for i in range(4):
assert np.abs(np.linalg.norm(oldg[i]-geom[i])) < 1e-6, \
"failed rotation test"
geom.rotate(geom[2]-geom[1],geom[1],-90./180.*np.pi)
geometrySet2.append(oldg)
assert np.abs(np.linalg.norm(oldg[1]-geom[1])) < 1e-6, \
"failed rotation test"
assert np.abs(np.linalg.norm(oldg[2]-geom[2])) < 1e-6, \
"failed rotation test"
assert np.abs(np.dot(oldg[1]-oldg[0],geom[1]-geom[0])) < 1e-6, \
"failed rotation test"
# newGeometry = cg.readNewFile('data/geometry/whole-building-new.txt',"whole-building-new")
# numWall = 0
# numWindow = 0
# for geom in newGeometry:
# if (geom.facadeType == 'window'):
# numWindow = numWindow + 1
# if (geom.facadeType == 'wall'):
# numWall = numWall + 1
# assert len(newGeometry) == 8, "failed reading new geometry file"
# assert numWall == 4, "failed reading new geometry file"
# assert numWindow == 4, "failed reading new geometry file"
def runSolverTests():
rate = poisson2D.test()
assert (rate[0] > 2.3 and rate[1] > 2.3), \
"testing failed poisson2D: solver error"
rate = diffusion2D.test()
assert (rate[0] > 2.3 and rate[1] > 2.3), \
"testing failed diffusion2D: solver error"
def runSolarTest():
latitude = 40.707583
longitude = -74.010828
timezone = -5
solar.setTimezone(timezone)
solar.setLocation(latitude,longitude)
#(localTime, globalTime) = solar.secondsToDatetime(12*3600)
earlyAngles = solar.getSunPosition(10*3600)
noonAngles = solar.getSunPosition(12*3600)
lateAngles = solar.getSunPosition(14*3600)
summerAngle = solar.getSunPosition(171*24*3600+12*3600)
winterAngle = solar.getSunPosition(1*24*3600+12*3600)
assert (earlyAngles['azimuth'] < noonAngles['azimuth'] < lateAngles['azimuth']), \
"Unexpected: testing azimuth angles - found azimuth angles to be reverse/incorrect"
assert (earlyAngles['altitude'] < noonAngles['altitude'] > lateAngles['altitude']), \
"Unexpected: testing altitude - the sun is not highest at noon"
assert (winterAngle['declination'] < summerAngle['declination']), \
"Unexpected: testing delication - sun is not higher in summer than winter"
geometry = cg.readFile('data/geometry/whole-building.txt',"whole-building")
geom = geometry[13]
# JS: I do not like this test because as we change geometry it will break but it's here.
# assert abs(solar.getAOI(noonAngles,geom) - solar.getAOICheck(noonAngles,0.0,(60*np.pi/180.))) < 1e-6, \
# "Unexpected - Angle of incidence on roof has changed"
(pitchSummer, yawSummer) = solar.getArrayAngle(summerAngle,geom)
(pitchWinter, yawWinter) = solar.getArrayAngle(winterAngle,geom)
assert (pitchWinter < pitchSummer), \
"Unexpected: testing pitch - the winter pitch is higher than summer"
assert(solar.getGlazingTransmitted(earlyAngles,geom,1) < \
solar.getGlazingTransmitted(noonAngles,geom,1) > \
solar.getGlazingTransmitted(lateAngles,geom,1)), \
"Unexpected: testing glazing transmittance - was not greatest at noon for the roof"
def runTests():
start = clocktime.time()
print "running tests ...",
runGeometryTest()
runSolverTests()
runSolarTest()
print "all passed in", '%.2f' % (clocktime.time()-start),"seconds"
if __name__ == '__main__':
runTests()