GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.7% 40 / 0 / 60
Functions: 75.0% 3 / 0 / 4
Branches: 57.8% 48 / 0 / 83

src/radiance/AnnualIlluminanceMap.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "AnnualIlluminanceMap.hpp"
7 #include "HeaderInfo.hpp"
8
9 #include <iostream>
10 #include <fstream>
11 #include <vector>
12
13 #include <boost/lexical_cast.hpp>
14 #include <boost/regex.hpp>
15
16 #include <boost/algorithm/string.hpp>
17 #include <boost/tokenizer.hpp>
18
19 using namespace std;
20 using namespace boost;
21 using namespace openstudio;
22
23 namespace openstudio {
24 namespace radiance {
25
26 /// default constructor
27
3/3
✓ Branch 2 taken 13 times.
✓ Branch 5 taken 13 times.
✓ Branch 8 taken 13 times.
13 AnnualIlluminanceMap::AnnualIlluminanceMap() = default;
28
29 /// constructor with path
30
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
1 AnnualIlluminanceMap::AnnualIlluminanceMap(const openstudio::path& path) {
31
1/1
✓ Branch 1 taken 1 time.
1 init(path);
32 1 }
33
34 1 void AnnualIlluminanceMap::init(const openstudio::path& path) {
35 // file must exist
36
2/3
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
1 if (!exists(path)) {
37 ✗ LOG(Fatal, "File does not exist: '" << toString(path) << "'");
38 1 return;
39 }
40
41 // open file
42
1/1
✓ Branch 1 taken 1 time.
1 openstudio::filesystem::ifstream file(path);
43
44 // keep track of line number
45 1 unsigned lineNum = 0;
46
47 // keep track of matrix size
48 1 unsigned M = 0;
49 1 unsigned N = 0;
50
51 // temp string to read file
52 1 string line;
53
54 // lines 1 and 2 are the header lines
55 1 string line1;
56 1 string line2;
57
58 // this will contain matches to regular expressions
59
1/1
✓ Branch 1 taken 1 time.
1 smatch matches;
60
61 // matches a single number followed by either tabs or spaces
62
1/1
✓ Branch 1 taken 1 time.
1 const regex singleNumber("([-+]?[0-9]*\\.?[0-9]+)[\\s\\t]*");
63
64 // conversion from footcandles to lux
65 1 const double footcandlesToLux(10.76);
66
67 // read the rest of the file line by line
68
3/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 while (getline(file, line)) {
69 3 ++lineNum;
70
71
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
3 if (lineNum == 1) {
72
73 // save line 1
74
1/1
✓ Branch 1 taken 1 time.
1 line1 = line;
75
76
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 } else if (lineNum == 2) {
77
78 // save line 2
79
1/1
✓ Branch 1 taken 1 time.
1 line2 = line;
80
81 // create the header info
82
1/1
✓ Branch 1 taken 1 time.
1 HeaderInfo headerInfo(line1, line2);
83
84 // we can now initialize x and y vectors
85
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 m_xVector = headerInfo.xVector();
86
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 m_yVector = headerInfo.yVector();
87
88
1/1
✓ Branch 1 taken 1 time.
1 M = m_xVector.size();
89
1/1
✓ Branch 1 taken 1 time.
1 N = m_yVector.size();
90
91 1 } else {
92
93 // each line contains the month, day, time (in hours),
94 // Solar Azimuth(degrees from south), Solar Altitude(degrees), Global Horizontal Illuminance (fc)
95 // followed by M*N illuminance points
96
97 // break the line up by spaces
98 1 vector<string> lineVector;
99
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 tokenizer<char_separator<char>, std::string::const_iterator, std::string> tk(line, char_separator<char>(" "));
100
6/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 87 times.
✓ Branch 7 taken 88 times.
✓ Branch 10 taken 88 times.
✓ Branch 13 taken 87 times.
✓ Branch 14 taken 1 time.
88 for (tokenizer<char_separator<char>, std::string::const_iterator, std::string>::iterator it(tk.begin()); it != tk.end(); ++it) {
101
2/2
✓ Branch 1 taken 87 times.
✓ Branch 4 taken 87 times.
87 lineVector.push_back(*it);
102 1 }
103
104 // total number minus 6 standard header items
105 1 unsigned numValues = lineVector.size() - 6;
106
107
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (numValues != M * N) {
108
9/9
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
1 LOG(Fatal, "Incorrect number of illuminance values read " << numValues << ", expecting " << M * N << ".");
109 1 return;
110 } else {
111
112 ✗ MonthOfYear thisMonth = monthOfYear(lexical_cast<unsigned>(lineVector[0]));
113 ✗ auto day = lexical_cast<unsigned>(lineVector[1]);
114 ✗ double fracDays = lexical_cast<double>(lineVector[2]) / 24.0;
115
116 // ignore solar angles and global horizontal for now
117
118 // make the date time
119 ✗ DateTime dateTime(Date(thisMonth, day), Time(fracDays));
120
121 // matrix we are going to read in
122 ✗ Matrix illuminanceMap(M, N);
123
124 // read in the values
125 ✗ unsigned index = 6;
126 ✗ for (unsigned j = 0; j < N; ++j) {
127 ✗ for (unsigned i = 0; i < M; ++i) {
128 ✗ illuminanceMap(i, j) = footcandlesToLux * lexical_cast<double>(lineVector[index]);
129 ✗ ++index;
130 }
131 }
132
133 ✗ m_dateTimes.push_back(dateTime);
134 ✗ m_dateTimeIlluminanceMap[dateTime] = illuminanceMap;
135 ✗ }
136 2 }
137 }
138
139 // close file
140 ✗ file.close();
141 6 }
142
143 /// get the illuminance map in lux corresponding to date and time
144 ✗ openstudio::Matrix AnnualIlluminanceMap::illuminanceMap(const openstudio::DateTime& dateTime) const {
145 ✗ auto it = m_dateTimeIlluminanceMap.find(dateTime);
146 ✗ if (it != m_dateTimeIlluminanceMap.end()) {
147 ✗ return it->second;
148 }
149
150 ✗ return m_nullIlluminanceMap;
151 }
152
153 } // namespace radiance
154 } // namespace openstudio
155