GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.2% 699 / 0 / 775
Functions: 86.0% 37 / 0 / 43
Branches: 92.0% 803 / 0 / 873

src/isomodel/SimModel.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 "SimModel.hpp"
7
8 #include <cmath>
9 #include <array>
10
11 #if _DEBUG || (__GNUC__ && !NDEBUG)
12 # define DEBUG_ISO_MODEL_SIMULATION
13 #endif
14
15 using namespace openstudio::isomodel;
16 using namespace openstudio;
17
18 namespace openstudio {
19 namespace isomodel {
20
21 ✗ double ISOResults::totalEnergyUse() const {
22 ✗ double result = 0;
23 ✗ std::vector<EndUseFuelType> fuelTypes = openstudio::EndUses::fuelTypes();
24 ✗ for (const auto& monthlyResult : monthlyResults) {
25 ✗ for (const auto& fuelType : fuelTypes) {
26 ✗ result += monthlyResult.getEndUseByFuelType(fuelType);
27 }
28 }
29
30 ✗ return result;
31 ✗ }
32
33 59 void SimModel::printVector(const char* vecName, const Vector& vec) {
34 #ifdef DEBUG_ISO_MODEL_SIMULATION
35 std::stringstream ss;
36
37 ss << vecName << "(" << vec.size() << ") = [";
38 if (vec.size() > 0) {
39 ss << vec[0];
40 for (unsigned int i = 1; i < vec.size(); i++) {
41 ss << ", " << vec[i];
42 }
43 }
44 ss << "]";
45 LOG(Trace, ss.str());
46 #endif
47 59 }
48
49 1 void SimModel::printMatrix(const char* matName, const Matrix& mat) {
50 #ifdef DEBUG_ISO_MODEL_SIMULATION
51 std::stringstream ss;
52
53 ss << matName << "(" << mat.size1() << ", " << mat.size2() << "): " << "\t";
54 for (unsigned int j = 0; j < mat.size2(); j++) {
55 ss << "," << j;
56 }
57 for (unsigned int i = 0; i < mat.size1(); i++) {
58 ss << "\t" << i;
59 for (unsigned int j = 0; j < mat.size2(); j++) {
60 ss << "," << mat(i, j);
61 }
62 ss << '\n';
63 }
64
65 LOG(Trace, ss.str());
66 #endif
67 1 }
68 /**
69 * Initializes a vector to the specified value
70 */
71 7 void vectorInit(Vector& vec, double val) {
72
2/2
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 7 times.
91 for (unsigned int i = 0; i < vec.size(); i++) {
73 84 vec[i] = val;
74 }
75 7 }
76
77 /**
78 * Initializes a vector to 0
79 */
80 7 void zero(Vector& vec) {
81 7 vectorInit(vec, 0);
82 7 }
83
84 /**
85 * Initializes a vector to 1
86 */
87 ✗ void one(Vector& vec) {
88 ✗ vectorInit(vec, 1);
89 ✗ }
90
91 /// array-scalar product
92 7 Vector mult(const double* v1, const double s1, int size) {
93 7 Vector vp = Vector(size);
94
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 7 times.
91 for (int i = 0; i < size; i++) {
95
1/1
✓ Branch 1 taken 84 times.
84 vp[i] = v1[i] * s1;
96 }
97 7 return vp;
98 ✗ }
99 /// vector-scalar product
100 41 Vector mult(const Vector& v1, const double s1) {
101 41 Vector vp = Vector(v1.size());
102
3/3
✓ Branch 1 taken 527 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 41 times.
527 for (size_t i = 0; i < v1.size(); i++) {
103
2/2
✓ Branch 1 taken 486 times.
✓ Branch 4 taken 486 times.
486 vp[i] = v1[i] * s1;
104 }
105 41 return vp;
106 ✗ }
107 /// vector-array product
108 5 Vector mult(const Vector& v1, const double* v2) {
109 5 Vector vp = Vector(v1.size());
110
3/3
✓ Branch 1 taken 65 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 5 times.
65 for (size_t i = 0; i < v1.size(); i++) {
111
2/2
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
60 vp[i] = v1[i] * v2[i];
112 }
113 5 return vp;
114 ✗ }
115 /// vector-vector product
116 28 Vector mult(const Vector& v1, const Vector& v2) {
117 assert(v1.size() == v2.size());
118 28 Vector vp = Vector(v1.size());
119
3/3
✓ Branch 1 taken 325 times.
✓ Branch 3 taken 297 times.
✓ Branch 4 taken 28 times.
325 for (size_t i = 0; i < v1.size(); i++) {
120
3/3
✓ Branch 1 taken 297 times.
✓ Branch 4 taken 297 times.
✓ Branch 7 taken 297 times.
297 vp[i] = v1[i] * v2[i];
121 }
122 28 return vp;
123 ✗ }
124 ///Vector-scalar division
125 38 Vector div(const Vector& v1, const double s1) {
126 38 Vector vp = Vector(v1.size());
127
3/3
✓ Branch 1 taken 494 times.
✓ Branch 3 taken 456 times.
✓ Branch 4 taken 38 times.
494 for (size_t i = 0; i < v1.size(); i++) {
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456 times.
456 if (s1 == 0) {
129 ✗ vp[i] = std::numeric_limits<double>::max();
130 } else {
131
2/2
✓ Branch 1 taken 456 times.
✓ Branch 4 taken 456 times.
456 vp[i] = v1[i] / s1;
132 }
133 }
134 38 return vp;
135 ✗ }
136 ✗ Vector div(const double s1, const Vector& v1) {
137 ✗ Vector vp = Vector(v1.size());
138 ✗ for (size_t i = 0; i < v1.size(); i++) {
139 ✗ if (v1[i] == 0) {
140 ✗ vp[i] = std::numeric_limits<double>::max();
141 } else {
142 ✗ vp[i] = s1 / v1[i];
143 }
144 }
145 ✗ return vp;
146 ✗ }
147 ///vector-vector division
148 12 Vector div(const Vector& v1, const Vector& v2) {
149 assert(v1.size() == v2.size());
150 12 Vector vp = Vector(v1.size());
151
3/3
✓ Branch 1 taken 156 times.
✓ Branch 3 taken 144 times.
✓ Branch 4 taken 12 times.
156 for (size_t i = 0; i < v1.size(); i++) {
152
2/3
✓ Branch 1 taken 144 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
144 if (v2[i] == 0) {
153 ✗ vp[i] = std::numeric_limits<double>::max();
154 } else {
155
3/3
✓ Branch 1 taken 144 times.
✓ Branch 4 taken 144 times.
✓ Branch 7 taken 144 times.
144 vp[i] = v1[i] / v2[i];
156 }
157 }
158 12 return vp;
159 ✗ }
160 27 Vector sum(const Vector& v1, const Vector& v2) {
161 assert(v1.size() == v2.size());
162
163 27 Vector vs = Vector(v1.size());
164
3/3
✓ Branch 1 taken 348 times.
✓ Branch 3 taken 321 times.
✓ Branch 4 taken 27 times.
348 for (size_t i = 0; i < v1.size(); i++) {
165
3/3
✓ Branch 1 taken 321 times.
✓ Branch 4 taken 321 times.
✓ Branch 7 taken 321 times.
321 vs[i] = v1[i] + v2[i];
166 }
167 27 return vs;
168 ✗ }
169 6 Vector sum(const Vector& v1, const double v2) {
170 6 Vector vs = Vector(v1.size());
171
3/3
✓ Branch 1 taken 78 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 6 times.
78 for (size_t i = 0; i < v1.size(); i++) {
172
2/2
✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
72 vs[i] = v1[i] + v2;
173 }
174 6 return vs;
175 ✗ }
176 9 Vector dif(const Vector& v1, const Vector& v2) {
177 assert(v1.size() == v2.size());
178 9 Vector vd = Vector(v1.size());
179
3/3
✓ Branch 1 taken 117 times.
✓ Branch 3 taken 108 times.
✓ Branch 4 taken 9 times.
117 for (size_t i = 0; i < v1.size(); i++) {
180
3/3
✓ Branch 1 taken 108 times.
✓ Branch 4 taken 108 times.
✓ Branch 7 taken 108 times.
108 vd[i] = v1[i] - v2[i];
181 }
182 9 return vd;
183 ✗ }
184 1 Vector dif(const Vector& v1, const double v2) {
185 1 Vector vd = Vector(v1.size());
186
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v1.size(); i++) {
187
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 vd[i] = v1[i] - v2;
188 }
189 1 return vd;
190 ✗ }
191 1 Vector dif(const double v1, const Vector& v2) {
192 1 Vector vd = Vector(v2.size());
193
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v2.size(); i++) {
194
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 vd[i] = v1 - v2[i];
195 }
196 1 return vd;
197 ✗ }
198 ✗ double maximum(const Vector& v1) {
199 ✗ double max = -std::numeric_limits<double>::max();
200 ✗ for (size_t i = 0; i < v1.size(); i++) {
201 ✗ if (v1[i] > max) {
202 ✗ max = v1[i];
203 }
204 }
205 ✗ return max;
206 }
207 3 Vector maximum(const Vector& v1, const Vector& v2) {
208 assert(v1.size() == v2.size());
209 3 Vector vx = Vector(v1.size());
210
3/3
✓ Branch 1 taken 39 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 3 times.
39 for (size_t i = 0; i < v1.size(); i++) {
211
3/3
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
✓ Branch 8 taken 36 times.
36 vx[i] = std::max(v1[i], v2[i]);
212 }
213 3 return vx;
214 ✗ }
215 3 Vector maximum(const Vector& v1, double val) {
216 3 Vector vx = Vector(v1.size());
217
3/3
✓ Branch 1 taken 39 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 3 times.
39 for (size_t i = 0; i < v1.size(); i++) {
218
2/2
✓ Branch 1 taken 36 times.
✓ Branch 5 taken 36 times.
36 vx[i] = std::max(v1[i], val);
219 }
220 3 return vx;
221 ✗ }
222 ✗ double minimum(const Vector& v1) {
223 ✗ double min = std::numeric_limits<double>::max();
224 ✗ for (size_t i = 0; i < v1.size(); i++) {
225 ✗ if (v1[i] < min) {
226 ✗ min = v1[i];
227 }
228 }
229 ✗ return min;
230 }
231 ✗ Vector minimum(const Vector& v1, double val) {
232 ✗ Vector vn = Vector(v1.size());
233 ✗ for (size_t i = 0; i < v1.size(); i++) {
234 ✗ vn[i] = std::min(v1[i], val);
235 }
236 ✗ return vn;
237 ✗ }
238 2 Vector abs(const Vector& v1) {
239 2 Vector va = Vector(v1.size());
240
3/3
✓ Branch 1 taken 26 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 2 times.
26 for (size_t i = 0; i < v1.size(); i++) {
241
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 va[i] = std::fabs(v1[i]);
242 }
243 2 return va;
244 ✗ }
245 4 Vector pow(const Vector& v1, const double xp) {
246 4 Vector va = Vector(v1.size());
247
3/3
✓ Branch 1 taken 52 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 4 times.
52 for (size_t i = 0; i < v1.size(); i++) {
248
2/2
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
48 va[i] = std::pow(v1[i], xp);
249 }
250 4 return va;
251 ✗ }
252
253 //End Utility Functions
254 constexpr double daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
255 constexpr double hoursInMonth[] = {744, 672, 744, 720, 744, 720, 744, 744, 720, 744, 720, 744};
256 constexpr double megasecondsInMonth[] = {2.6784, 2.4192, 2.6784, 2.592, 2.6784, 2.592, 2.6784, 2.6784, 2.592, 2.6784, 2.592, 2.6784};
257 constexpr double monthFractionOfYear[] = {0.0849315068493151, 0.0767123287671233, 0.0849315068493151, 0.0821917808219178,
258 0.0849315068493151, 0.0821917808219178, 0.0849315068493151, 0.0849315068493151,
259 0.0821917808219178, 0.0849315068493151, 0.0821917808219178, 0.0849315068493151};
260 constexpr double daysInYear = 365;
261 constexpr double hoursInYear = 8760;
262 constexpr double hoursInWeek = 168;
263 constexpr double EECALC_NUM_MONTHS = 12;
264 constexpr double EECALC_NUM_HOURS = 24;
265 constexpr double EECALC_WEEKDAY_START = 7;
266 constexpr double kWh2MJ = 3.6f;
267
268 //Solver functions
269 1 void SimModel::scheduleAndOccupancy(Vector& weekdayOccupiedMegaseconds, Vector& weekdayUnoccupiedMegaseconds, Vector& weekendOccupiedMegaseconds,
270 Vector& weekendUnoccupiedMegaseconds, Vector& clockHourOccupied, Vector& clockHourUnoccupied,
271 double& frac_hrs_wk_day, double& hoursUnoccupiedPerDay, double& hoursOccupiedPerDay, double& frac_hrs_wk_nt,
272 double& frac_hrs_wke_tot) const {
273 1 hoursOccupiedPerDay = pop->hoursEnd() - pop->hoursStart();
274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (hoursOccupiedPerDay < 0) {
275 ✗ hoursOccupiedPerDay += 24;
276 }
277 1 double daysOccupiedPerWeek = pop->daysEnd() - pop->daysStart() + 1;
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (daysOccupiedPerWeek < 0) {
279 ✗ daysOccupiedPerWeek += 7;
280 }
281
282 1 double hoursOccupiedDuringWeek = hoursOccupiedPerDay * daysOccupiedPerWeek;
283 1 frac_hrs_wk_day = hoursOccupiedDuringWeek / hoursInWeek;
284
285 1 hoursUnoccupiedPerDay = 24 - hoursOccupiedPerDay;
286 1 double hoursUnoccupiedDuringWeek = (daysOccupiedPerWeek - 1) * hoursUnoccupiedPerDay;
287 1 frac_hrs_wk_nt = hoursUnoccupiedDuringWeek / hoursInWeek;
288
289 // double occupationDensity = pop->densityOccupied();
290 // double unoccupiedDensity = pop->densityUnoccupied();
291 // double densityRatio = occupationDensity / unoccupiedDensity;
292
293 1 double totalWeekendHours = hoursInWeek - hoursOccupiedDuringWeek - hoursUnoccupiedDuringWeek;
294 1 frac_hrs_wke_tot = totalWeekendHours / hoursInWeek;
295
296 1 double weekendHoursOccupied = (7 - daysOccupiedPerWeek) * hoursOccupiedPerDay;
297 1 double frac_hrs_wke_day = weekendHoursOccupied / hoursInWeek;
298
299 1 double weekendHoursUnoccupied = totalWeekendHours - weekendHoursOccupied;
300 1 double frac_hrs_wke_nt = weekendHoursUnoccupied / hoursInWeek;
301
302
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 time.
13 for (int m = 0; m < EECALC_NUM_MONTHS; m++) {
303 12 weekdayOccupiedMegaseconds[m] = megasecondsInMonth[m] * frac_hrs_wk_day;
304 12 weekdayUnoccupiedMegaseconds[m] = megasecondsInMonth[m] * frac_hrs_wk_nt;
305 12 weekendOccupiedMegaseconds[m] = megasecondsInMonth[m] * frac_hrs_wke_day;
306 12 weekendUnoccupiedMegaseconds[m] = megasecondsInMonth[m] * frac_hrs_wke_nt;
307 }
308
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 time.
25 for (int h = 0; h < EECALC_NUM_HOURS; h++) {
309
4/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 6 times.
24 if (h - EECALC_WEEKDAY_START >= 0 && h - EECALC_WEEKDAY_START < hoursOccupiedPerDay) {
310 11 clockHourOccupied[h] = 1;
311 11 clockHourUnoccupied[h] = 0;
312 } else {
313 13 clockHourOccupied[h] = 0;
314 13 clockHourUnoccupied[h] = 1;
315 }
316 }
317 1 }
318 1 void SimModel::solarRadiationBreakdown(const Vector& weekdayOccupiedMegaseconds, const Vector& weekdayUnoccupiedMegaseconds,
319 const Vector& weekendOccupiedMegaseconds, const Vector& weekendUnoccupiedMegaseconds,
320 const Vector& clockHourOccupied, const Vector& clockHourUnoccupied, Vector& v_hrs_sun_down_mo,
321 Vector& frac_Pgh_wk_nt, Vector& frac_Pgh_wke_day, Vector& frac_Pgh_wke_nt, Vector& v_Tdbt_nt) const {
322
323
1/1
✓ Branch 5 taken 1 time.
1 Matrix m_mhEgh = location->weather()->mhEgh();
324
1/1
✓ Branch 5 taken 1 time.
1 Matrix m_mhdbt = location->weather()->mhdbt();
325
326 // TODO: unreadVariable
327 // Vector v_Tdbt_Day = prod(m_mhdbt, clockHourOccupied);
328 // v_Tdbt_Day /= sum(clockHourOccupied);
329
330
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Tdbt_nt = prod(m_mhdbt, clockHourUnoccupied);
331
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Tdbt_nt /= sum(clockHourUnoccupied);
332
333
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Egh_day = prod(m_mhEgh, clockHourOccupied);
334
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Egh_day /= sum(clockHourOccupied);
335
336
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Egh_nt = prod(m_mhEgh, clockHourUnoccupied);
337
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Egh_nt /= sum(clockHourUnoccupied);
338 /**
339 v_mdbt=W.mdbt; % copy to a new variable so vector nature is clear
340 M_mhdbt=W.mhdbt; % copy to a new variable so matrix nature is clear
341 M_mhEgh=W.mhEgh; % copy to a new variable so matrix nature is clear
342
343 % Note, these are matrix multiplies (matrix*vector) resulting in a vector
344 v_Tdbt_day=(M_mhdbt*v_day_hrs_yesno)./sum(v_day_hrs_yesno); %monthly average dry bulb temp (dbt) during the occupied hours of days
345 v_Tdbt_nt=(M_mhdbt*v_nt_hrs_yesno)./sum(v_nt_hrs_yesno); %monthly avg dbt during the unoccupied hours of days
346
347 v_Egh_day=(M_mhEgh*v_day_hrs_yesno)./sum(v_day_hrs_yesno); %monthly avg global horiz rad power (Egh) during the "day" hours
348 v_Egh_nt=(M_mhEgh*v_nt_hrs_yesno)./sum(v_nt_hrs_yesno); %monthly avg Egh during the "night" hours
349 */
350
351
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Wgh_wk_day = mult(v_Egh_day, weekdayOccupiedMegaseconds);
352
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Wgh_wk_nt = mult(v_Egh_nt, weekdayUnoccupiedMegaseconds);
353
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Wgh_wke_day = mult(v_Egh_day, weekendOccupiedMegaseconds);
354
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Wgh_wke_nt = mult(v_Egh_nt, weekendUnoccupiedMegaseconds);
355
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 Vector v_Wgh_tot = sum(sum(v_Wgh_wk_day, v_Wgh_wk_nt), sum(v_Wgh_wke_day, v_Wgh_wke_nt));
356 /**
357 v_Wgh_wk_day=v_Egh_day.*v_Msec_wk_day; % monthly avg Egh energy (Wgh) during the week days
358 v_Wgh_wk_nt=v_Egh_nt.*v_Msec_wk_nt; %monthly avg Wgh during week nights
359 v_Wgh_wke_day=v_Egh_day.*v_Msec_wke_day; %monthly avg Wgh during weekend days
360 v_Wgh_wke_nt=v_Egh_nt.*v_Msec_wke_nt; %monthly avg Wgh during weekend nights
361 v_Wgh_tot=v_Wgh_wk_day+v_Wgh_wk_nt+v_Wgh_wke_day+v_Wgh_wke_nt; %Egh_avg_total MJ/m2
362 */
363
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 frac_Pgh_wk_nt = div(v_Wgh_wk_nt, v_Wgh_tot);
364
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 frac_Pgh_wke_day = div(v_Wgh_wke_day, v_Wgh_tot);
365
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 frac_Pgh_wke_nt = div(v_Wgh_wke_nt, v_Wgh_tot);
366 /**
367
368 %FRAC_PGH_DAYTIME=v_Wgh_wk_day./v_Wgh_tot; %frac_Egh_occ
369 frac_Pgh_wk_nt=v_Wgh_wk_nt./v_Wgh_tot; %frac_Egh_unocc_weekday_night
370 frac_Pgh_wke_day=v_Wgh_wke_day./v_Wgh_tot; %frac_Egh_unocc_weekend_day
371 frac_Pgh_wke_nt=v_Wgh_wke_nt./v_Wgh_tot; %frac_Egh_unocc_weekend_night
372 */
373
1/1
✓ Branch 1 taken 1 time.
1 Vector v_frac_hrs_sun_down = Vector(12);
374
1/1
✓ Branch 1 taken 1 time.
1 Vector v_frac_hrs_sun_up = Vector(12);
375 // TODO: unreadVariable
376 // Vector v_sun_up_time = Vector(12);
377 // Vector v_sun_down_time = Vector(12);
378
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 time.
13 for (int i = 0; i < 12; i++) {
379
1/1
✓ Branch 1 taken 12 times.
12 v_frac_hrs_sun_up[i] = 0;
380
1/1
✓ Branch 1 taken 12 times.
12 v_frac_hrs_sun_down[i] = 0;
381
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 for (int j = 0; j < 24; j++) {
382
3/3
✓ Branch 1 taken 74 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 62 times.
74 if (m_mhEgh(i, j) != 0) {
383
1/1
✓ Branch 1 taken 12 times.
12 v_frac_hrs_sun_up[i] = j;
384 12 break;
385 }
386 }
387
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 for (int j = 23; j >= 0; j--) {
388
3/3
✓ Branch 1 taken 76 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 64 times.
76 if (m_mhEgh(i, j) != 0) {
389
1/1
✓ Branch 1 taken 12 times.
12 v_frac_hrs_sun_down[i] = j;
390 12 break;
391 }
392 }
393
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 v_frac_hrs_sun_up[i] = (v_frac_hrs_sun_down[i] - v_frac_hrs_sun_up[i] + 1) / 24.0;
394
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_frac_hrs_sun_down[i] = 1.0 - v_frac_hrs_sun_up[i];
395 }
396 /**
397 %% find what time the sun comes up and goes down and the fraction of hours sun is up and down
398
399 %%% CHANGE
400 % the following two lines were in the original spreadsheet and the fraction of hours up was fixed.
401 % Let's do this properly by looking for the hours the sun is up and down each month
402 % RTM 10-NOV-2012
403 %
404 % v_frac_hrs_sun_down=ones(12,1)*(24-(19-7+1))/24;
405 % v_hrs_sun_down_mo=b_frac_hrs_sun_down.*v_hrs_ina_mo;
406
407 v_frac_hrs_sun_down=zeros(12,1);
408 v_frac_hrs_sun_up=zeros(12,1);
409 v_sun_up_time=zeros(12,1);
410 v_sun_down_time=zeros(12,1);
411
412 for I=1:12
413 J=find(W.mhEgh(I,:)~=0); % find the hours where Egh is nonzero and identify as sun being up
414 v_sun_up_time(I)=J(1); % first element is the sunup hour
415 v_sun_down_time(I)=J(end); % last element is sundown hour
416 v_frac_hrs_sun_up(I)=length(J)/24; % fraction of hours in the day the sun is up
417 v_frac_hrs_sun_down(I)=1-v_frac_hrs_sun_up(I); % fraction of hours in the day the sun is down
418 end
419 v_hrs_sun_down_mo=v_frac_hrs_sun_down.*v_hrs_ina_mo;
420 */
421 //Vector v_hrs_sun_down_mo = Vector(v_frac_hrs_sun_down.size());
422
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_frac_hrs_sun_down.size(); i++) {
423
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_hrs_sun_down_mo[i] = v_frac_hrs_sun_down[i] * hoursInMonth[i];
424 }
425 1 }
426
427 1 void SimModel::lightingEnergyUse(const Vector& v_hrs_sun_down_mo, double& Q_illum_occ, double& Q_illum_unocc, double& Q_illum_tot_yr,
428 Vector& v_Q_illum_tot, Vector& v_Q_illum_ext_tot) const {
429 1 double lpd_occ = lights->powerDensityOccupied();
430 1 double lpd_unocc = lights->powerDensityUnoccupied();
431 1 double F_D = lights->dimmingFraction();
432 1 double F_O = building->lightingOccupancySensor();
433 1 double F_C = building->constantIllumination();
434 /*
435 %% compute lighting energy use as per prEN 15193:2006
436
437 lpd_occ=In.LPD_occ;
438 lpd_unocc=In.LPD_unocc;
439
440 % assign fractions for daylighting, occupancy sensors, and const illum
441 % sensors as per prEN 1593:2006.
442 % Lookup tables are on the spreadsheet
443
444 F_D=In.daylighting_sensor; % F_D = daylight sensor dimming fraction
445 F_O=In.lighting_occupancy_sensor; % F_O = occupancy sensor control fraction
446 F_C=In.lighting_constant_illumination; %F_c = constant illuminance control fraction
447 */
448
449 1 double n_day_start = 7;
450 1 double n_day_end = 19;
451 1 double n_weeks = 50;
452 double t_lt_D =
453 1 (std::min(n_day_end, pop->hoursEnd()) - std::max(pop->hoursStart(), n_day_start)) * (pop->daysEnd() + 1 - pop->daysStart() + 1) * n_weeks;
454 1 double t_lt_N = (std::max(n_day_start - pop->hoursStart(), 0.0) + std::max(pop->hoursEnd() - n_day_end, 0.0))
455 1 * (pop->daysEnd() + 1 - pop->daysStart() + 1) * n_weeks;
456 1 Q_illum_occ = structure->floorArea() * lpd_occ * F_C * F_O * (t_lt_D * F_D + t_lt_N) / 1000.0;
457 /*
458 %%% NOTE
459 % the following assumes day starts at hour 7 and ends at hour 19
460 % and 2 weeks per year are considered completely unoccupied for lighting
461 % This should be converted to a monthly quanitity using the monthly
462 % average sunup and sundown times
463
464 n_day_start=7;
465 n_day_end=19;
466 n_weeks=50;
467 t_lt_D=(min(In.occ_hour_end,n_day_end)-max(In.occ_hour_start,n_day_start))*(In.occ_day_end+1-In.occ_day_start+1)*n_weeks; %lighting_operating_hours during the daytime
468 t_lt_N=(max(n_day_start-In.occ_hour_start,0)+max(In.occ_hour_end-n_day_end,0))*(In.occ_day_end+1-In.occ_day_start+1)*n_weeks; %lighting_operating_hours during the nighttime
469
470 % total lighting energy
471 Q_illum_occ=In.cond_flr_area*lpd_occ*F_C*F_O*(t_lt_D*F_D + t_lt_N)/1000; % find the total lighting energy for occupied times in kWh
472
473 %%% CHANGE
474 % as an alternative to a fixed parasitic lighting energy density use an unoccupied
475 % number for illumuniation LPD
476 % RTM 13-NOV-2012
477 %
478 % this is the original code from the spreadsheet that fixed the parasitic
479 % lighting load at 6 kWh/m2/yr as per pren 15193-2006 B12
480 % Q_lt_par_den=1+5; % parasitic lighting energy density is emergency + control lighting kWh/m2/yr
481 % Q_illum_par=Q_lt_par_den*In.cond_flr_area;
482 % Q_illum_tot_yr=Q_illum_occ+Q_illum_par;
483 */
484
485 1 double t_unocc = hoursInYear - t_lt_D - t_lt_N;
486 1 Q_illum_unocc = structure->floorArea() * lpd_unocc * t_unocc / 1000.0;
487 1 Q_illum_tot_yr = Q_illum_occ + Q_illum_unocc;
488
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Q_illum_tot = mult(monthFractionOfYear, Q_illum_tot_yr, 12);
489
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_Q_illum_ext_tot = mult(v_hrs_sun_down_mo, lights->exteriorEnergy() / 1000.0);
490 /*
491 t_unocc=hrs_ina_yr - t_lt_D - t_lt_N; % find the number of unoccupied lighting hours in the year
492 Q_illum_unocc = In.cond_flr_area*lpd_unocc*t_unocc/1000; % find the total annual lighting energy for unoccupied times in kWh
493 Q_illum_tot_yr=Q_illum_occ+Q_illum_unocc; % find the total annual lighting energy in kWh
494
495 % split annual lighting energy into monthly lighting energy via the month fraction of year
496 v_Q_illum_tot=Q_illum_tot_yr.*v_mo_frac_of_yr; %total interior monthly lighting energy in kWh
497
498 % exterior lighting
499 v_Q_illum_ext_tot=v_hrs_sun_down_mo*In.E_lt_ext/1000; %etotal exterior monthly lighting energy in kWh
500
501 */
502 1 }
503 1 void SimModel::envelopCalculations(Vector& v_win_A, Vector& v_wall_emiss, Vector& v_wall_alpha_sc, Vector& v_wall_U, Vector& v_wall_A,
504 double& H_tr) const {
505
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_wall_A = structure->wallArea();
506
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_win_A = structure->windowArea();
507
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_wall_U = structure->wallUniform();
508
1/1
✓ Branch 3 taken 1 time.
1 Vector v_win_U = structure->windowUniform();
509
510
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 Vector v_env_UA = sum(mult(v_wall_A, v_wall_U), mult(v_win_A, v_win_U));
511
1/1
✓ Branch 1 taken 1 time.
1 double H_D = sum(v_env_UA);
512 /*
513 %% compute envelope parameters as per ISO 13790 8.3
514
515 % convert vectored inputs to vectors for clarification
516 v_wall_A=In.wall_area;
517 v_win_A=In.win_area;
518 v_wall_U=In.wall_U;
519 v_win_U=In.win_U;
520
521 v_env_UA=v_wall_A.*v_wall_U + v_win_A.*v_win_U; %compute total envelope U*A
522
523
524 % compute direct transmission heat transfer coefficient to exterior in W/K as per 8.3.1
525 % ignore linear and point thermal bridges for now
526 H_D = sum(v_env_UA);
527 */
528 1 double H_g = 0;
529 1 double H_U = 0;
530 1 double H_A = 0;
531 1 H_tr = H_D + H_g + H_U + H_A;
532 /*
533 % for now, also ignore heat transfer to ground (minmal in big office buildings), unconditioned spaces
534 % and to adjacent buildings
535 H_g = 0; % steady state heat transfer coefficient by transfer to ground - not yet implemented
536 H_U = 0; % heat transfer coefficient for transmission through unconditioned spaces - not yet implemented
537 H_A = 0; % heat transfer coefficient for transmission to adjacent buildings - not yet implemented
538
539 H_tr=H_D+H_g+H_U+H_A; %total transmission heat transfer coefficient as per eqn 17 in 8.3.1
540 */
541
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_wall_emiss = structure->wallThermalEmissivity();
542
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 v_wall_alpha_sc = structure->wallSolarAbsorbtion();
543 /*
544 % copy the following from input structure to vectors for clarity
545 v_wall_emiss=In.wall_thermal_emiss; % wall thermal emissivity
546 v_wall_alpha_sc =In.wall_solar_alpha; %wall solar absorption coefficient
547 */
548 1 }
549 1 void SimModel::windowSolarGain(const Vector& v_win_A, const Vector& v_wall_emiss, const Vector& v_wall_alpha_sc, const Vector& v_wall_U,
550 const Vector& v_wall_A, Vector& v_wall_A_sol, Vector& v_win_hr, Vector& v_wall_R_sc, Vector& v_win_A_sol) const {
551 /*
552 %% Window Solar Gain
553
554 %%% REVISIT THIS SECTION
555 %%% The solar heat gain could be improved
556 %%% better understand SCF and SDF and how they map to F_sh
557 %%% calculate effective sky temp so we can better estimate theta_er and
558 %%% theta_ss, and hr
559
560 % From ISO 13790 11.3.3 Effective solar collecting area of glazed elements,% eqn 44
561 % A_sol = F_sh,gl* g_gl*(1 ? F_f)*A_w,p
562 % A_sol = effective solar collecting area of window in m2
563 % F_sh,gl = shading reduction factor for movable shades as per 11.4.3 % (v_win_SDF *v_win_SDF_frac)
564 % g_gl = total solar energy transmittance of transparent element as per % 11.4.2
565 % F_f = Frame area fraction (ratio of projected frame area to overall glazed element area) as per 11.4.5 (v_wind_ff)
566 % A_w,p = ovaral projected area of glazed element in m2 (v_wind_A)
567
568 %v_win_SHGC=In.win_SHGC; % copy to a new variable with a v_ for clarification
569 %v_win_SCF=In.win_SCF; % copy to a new variable with a v_ for clarification
570
571
572 % The frame factor, v_win_ff is found using ISO 10077-1, in absence a national standard
573 % can be used. Examples range from 0.2 for heating climates to 0.3 for
574 % cooling. Use 0.25 as a compromise
575 */
576 1 int vsize = 9;
577 1 double n_win_ff = 0.25;
578
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_ff = Vector(vsize);
579
580 1 constexpr std::array<double, 3> n_win_SDF_table = {0.5, 0.35, 1.0};
581
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_SDF = Vector(vsize);
582
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_SDF_frac = Vector(vsize);
583
584 /// \todo looking at forward translator, I'm not sure what's supposed to happen here,
585 /// but I know I cannot let it get below 0 or above 2, previous the code was hitting -1
586 1 int n_win_SDF_table_index = std::min(2, std::max(static_cast<int>(structure->windowShadingDevice()) - 1, 0));
587
588 #ifdef DEBUG_ISO_MODEL_SIMULATION
589 LOG(Trace, "WindowShadingDevice index: " << n_win_SDF_table_index);
590 #endif
591
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 time.
10 for (int i = 0; i < vsize; i++) {
592
1/1
✓ Branch 1 taken 9 times.
9 v_win_ff[i] = 1.0 - n_win_ff;
593
1/1
✓ Branch 2 taken 9 times.
9 v_win_SDF[i] = n_win_SDF_table[n_win_SDF_table_index];
594
1/1
✓ Branch 1 taken 9 times.
9 v_win_SDF_frac[i] = 1.0;
595 }
596
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_F_shgl = mult(v_win_SDF, v_win_SDF_frac);
597 /*
598 n_win_ff=0.25;
599 v_win_ff=ones(size(1,9))*n_win_ff; %window frame_factor;
600
601 % assign SDF based on pulldown:
602 n_win_SDF_table=[0.5,0.35,1.0];% assign SDF based on pulldown value of 1, 2 or 3
603 v_win_SDF=n_win_SDF_table(In.win_SDF); %window SDF
604
605 % set the SCF and SDF fractions which includes heat transfer - set at 100% for now
606 %v_win_SCF_frac=ones(size(In.win_SCF)); % SCF fraction to include in HX;
607 v_win_SDF_frac=ones(size(v_win_SDF)); % SDF fraction to include in HX; Fixed at 100% for now
608
609 v_win_F_shgl = v_win_SDF.*v_win_SDF_frac;
610 */
611
1/1
✓ Branch 3 taken 1 time.
1 Vector v_g_gln = structure->windowNormalIncidenceSolarEnergyTransmittance();
612 1 double n_win_F_W = 0.9;
613
1/1
✓ Branch 1 taken 1 time.
1 Vector v_g_gl = mult(v_g_gln, n_win_F_W);
614
615
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 v_win_A_sol = mult(mult(mult(v_win_F_shgl, v_g_gl), v_win_ff), v_win_A);
616
617 #ifdef DEBUG_ISO_MODEL_SIMULATION
618 printVector("v_g_gln", v_g_gln);
619 printVector("v_g_gl", v_g_gl);
620 printVector("v_win_ff", v_win_ff);
621 printVector("v_win_A", v_win_A);
622 printVector("v_win_F_shgl", v_win_F_shgl);
623 printVector("v_win_A_sol", v_win_A_sol);
624 #endif
625
626 /*
627 v_g_gln = In.win_SHGC ; % normal incidence solar energy transmittance which is SHGC in america
628 n_win_F_W = 0.9;% correction factor for non-scattering window as per ISO 13790 11.4.2
629 v_g_gl = v_g_gln*n_win_F_W; % solar energy transmittance of glazing as per 11.4.2
630
631 v_win_A_sol=v_win_F_shgl.*v_g_gl.*(1-v_win_ff).*v_win_A;
632
633 % form factors given in ISO 13790, 11.4.6 as 0.5 for wall, 1.0 for unshaded roof
634
635 */
636
637 // double n_v_env_form_factors[]={0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1};
638 1 double n_R_sc_ext = 0.04;
639
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_wall_R_sc = Vector(vsize);
640
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 time.
10 for (int i = 0; i < vsize; i++) {
641
1/1
✓ Branch 1 taken 9 times.
9 v_wall_R_sc[i] = n_R_sc_ext;
642 }
643
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_win_hr = mult(v_wall_emiss, 5.0);
644
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 v_wall_A_sol = mult(mult(mult(v_wall_alpha_sc, v_wall_R_sc), v_wall_U), v_wall_A);
645 /*
646 n_v_env_form_factors=[0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 1]; %formfactor_to_sky. Walls are all 0.5, roof is 1.0
647 n_R_sc_ext=0.04; % vertical wall external convection surface heat resistance as per ISO 6946
648 v_wall_R_sc=ones(size(1,9))*n_R_sc_ext; %vertical wall external convective surface heat resistances
649
650 % 11.4.6 says use hr=5 as a first approx.
651 v_win_hr=5*v_wall_emiss; %window external radiative heat xfer coeff.
652
653 % effective collecting area of opaque building elements, A_sol EN ISO 13790 11.3.4
654 % A_sol = ?_S,c × R_se × U_c × A_c
655 % A_sol = effective solar collecting area
656 % ?_S,c = dimensionless solar absorption coefficient
657 % R_se = external surface heat resistance determined via ISO 6946 in m2*K/W
658 % U_c = thermal transmittance of opaque part determined via ISO 6946 W/m2K
659 % A_c = projected area of opaque part in m2
660
661 v_wall_A_sol=v_wall_alpha_sc.*v_wall_R_sc.*v_wall_U.*v_wall_A;
662
663 */
664 1 }
665 1 void SimModel::solarHeatGain(const Vector& v_win_A_sol, const Vector& v_wall_R_sc, const Vector& v_wall_U, const Vector& v_wall_A,
666 const Vector& v_win_hr, const Vector& v_wall_A_sol, Vector& v_E_sol) const {
667 /*
668 %% Solar Heat Gain
669 % From EN ISo 13790 11.3.2 eqn 43
670 %
671 % ?sol,k = F_sh,ob,k * A_sol,k * I_sol,k ? F*r,k ?_r,k
672 %
673 % ?_sol,k = solar heat flow gains through building element k
674 % F_sh,ob,k = shading reduction factor for external obstacles calculated via 11.4.4
675 % A_sol,k = effective collecting area of surface calculated via 11.3.3 (glazing ) 11.3.4 (opaque)
676 % I_sol,k = solar irradiance, mean energy of solar irradiation per square meter calculated using Annex F
677 % F_r,k form factor between building and sky determined using 11.4.6
678 % ?_r,k extra heat flow from thermal radiation to sky determined using 11.3.5
679
680
681 %%% REVISIT THIS SECTION
682 %%% The solar heat gain could be improved
683 %%% better understand SCF and SDF and how they map to F_SH
684 %%% calculate effective sky temp so we can better estimate theta_er and
685 %%% theta_ss
686 */
687
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector v_win_SCF_frac(structure->windowShadingCorrectionFactor().size());
688
3/3
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1 time.
10 for (unsigned int i = 0; i < v_win_SCF_frac.size(); i++) {
689
1/1
✓ Branch 1 taken 9 times.
9 v_win_SCF_frac[i] = 1;
690 }
691
1/1
✓ Branch 1 taken 1 time.
1 Matrix m_I_sol(12, 9, 0); //month x direction + 1 (roof?)
692
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 time.
13 for (size_t r = 0; r < m_I_sol.size1(); r++) {
693
2/2
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 12 times.
108 for (size_t c = 0; c < m_I_sol.size2() - 1; c++) {
694
2/2
✓ Branch 5 taken 96 times.
✓ Branch 8 taken 96 times.
96 m_I_sol(r, c) = location->weather()->msolar()(r, c);
695 }
696
2/2
✓ Branch 5 taken 12 times.
✓ Branch 9 taken 12 times.
12 m_I_sol(r, m_I_sol.size2() - 1) = location->weather()->mEgh()[r];
697 }
698
1/1
✓ Branch 1 taken 1 time.
1 printMatrix("m_I_sol", m_I_sol);
699 /*
700 v_win_SCF_frac=ones(size(In.win_SCF)); % SCF fraction to include in HX; Fixed at 100% for now
701
702 v_I_sol=[W.msolar W.mEgh]; % create a new solar irradiance vector with the horizontal included as the last column
703 */
704
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_phi_sol(12);
705
1/1
✓ Branch 1 taken 1 time.
1 Vector temp(9);
706
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_win_phi_sol.size(); i++) {
707
3/3
✓ Branch 1 taken 120 times.
✓ Branch 3 taken 108 times.
✓ Branch 4 taken 12 times.
120 for (size_t j = 0; j < temp.size(); j++) {
708
5/5
✓ Branch 3 taken 108 times.
✓ Branch 6 taken 108 times.
✓ Branch 9 taken 108 times.
✓ Branch 12 taken 108 times.
✓ Branch 15 taken 108 times.
108 temp[j] = structure->windowShadingCorrectionFactor()[j] * v_win_SCF_frac[j] * v_win_A_sol[j] * m_I_sol(i, j);
709 }
710
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_win_phi_sol[i] = sum(temp);
711 }
712 /*
713 % compute the total solar heat gain for the glazing area
714 % note that the stuff in the sum is a 1x9 row vector for each surface since
715 % the .* multiplies element by element not a vector multiply.
716 v_win_phi_sol=zeros(12,1);
717 for I=1:12
718 temp=In.win_SCF.*v_win_SCF_frac.*v_win_A_sol.*v_I_sol(I,:);
719 v_win_phi_sol(I)=sum(temp);
720 end
721
722 % compute opaque area thermal radiation to the sky from EN ISO 13790 11.3.5
723 % ?_r,k = Rse×Uc×Ac×hr×??er (46)
724 % ?_r,k = thermal radiation to sky in W
725 % R_se = external heat resistance as defined above m2K/W
726 % U_c = U value of element as defined above W/m2K
727 % A_c = area of element defined above m2
728 % ??er = is the average difference between the external air temperature and the apparent sky temperature,
729 % determined in accordance with 11.4.6, expressed in degrees centigrade.
730
731 % 11.4.6 says take ?er=9k in sub polar zones, 13 K in tropical or 11 K in intermediate
732 */
733
1/1
✓ Branch 1 taken 1 time.
1 Vector theta_er(9);
734
3/3
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1 time.
10 for (size_t i = 0; i < theta_er.size(); i++) {
735
1/1
✓ Branch 1 taken 9 times.
9 theta_er[i] = 11.0;
736 }
737 1 constexpr std::array<double, 9> n_v_env_form_factors = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1};
738
739
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 Vector v_wall_phi_r = mult(mult(mult(mult(v_wall_R_sc, v_wall_U), v_wall_A), v_win_hr), theta_er);
740
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_phi_sol(12);
741
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_win_phi_sol.size(); i++) {
742
3/3
✓ Branch 1 taken 120 times.
✓ Branch 3 taken 108 times.
✓ Branch 4 taken 12 times.
120 for (size_t j = 0; j < temp.size(); j++) {
743
4/4
✓ Branch 1 taken 108 times.
✓ Branch 4 taken 108 times.
✓ Branch 7 taken 108 times.
✓ Branch 11 taken 108 times.
108 temp[j] = v_wall_A_sol[j] * m_I_sol(i, j) - v_wall_phi_r[j] * n_v_env_form_factors[j];
744 }
745
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_wall_phi_sol[i] = sum(temp);
746 }
747
748
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_wall_phi_r", v_wall_phi_r);
749
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_win_phi_sol", v_win_phi_sol);
750
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_wall_phi_sol", v_wall_phi_sol);
751
1/1
✓ Branch 1 taken 1 time.
1 Vector v_phi_sol = sum(v_win_phi_sol, v_wall_phi_sol);
752
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_phi_sol", v_phi_sol);
753
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_E_sol = mult(v_phi_sol, megasecondsInMonth);
754 /*
755 theta_er=ones(size(1,9))*11; % average difference between air temp and sky temp = 11K as per 11.4.6
756
757 v_wall_phi_r = v_wall_R_sc.*v_wall_U.*v_wall_A.*v_win_hr.*theta_er;
758
759 % compute the total solar heat gain for the opaque area
760 v_wall_phi_sol=zeros(12,1);
761 for I=1:12
762 temp=(v_wall_A_sol.*v_I_sol(I,:)-v_wall_phi_r.*n_v_env_form_factors);
763 v_wall_phi_sol(I)=sum(temp);
764 end
765
766 v_phi_sol=v_win_phi_sol+v_wall_phi_sol; % total envelope solar heat gain in W
767 v_E_sol= v_phi_sol.* v_Msec_ina_mo(I); % total envelope heat gain in MJ
768 */
769 1 }
770 1 void SimModel::heatGainsAndLosses(double frac_hrs_wk_day, double /*Q_illum_occ*/, double Q_illum_unocc, double Q_illum_tot_yr, double& phi_int_avg,
771 double& phi_plug_avg, double& phi_illum_avg, double& phi_int_wke_nt, double& phi_int_wke_day,
772 double& phi_int_wk_nt) const {
773 1 double phi_int_occ = pop->heatGainPerPerson() / pop->densityOccupied();
774 1 double phi_int_unocc = pop->heatGainPerPerson() / pop->densityUnoccupied();
775 1 phi_int_avg = frac_hrs_wk_day * phi_int_occ + (1 - frac_hrs_wk_day) * phi_int_unocc;
776
777 1 double phi_plug_occ = building->electricApplianceHeatGainOccupied()
778 1 + building->gasApplianceHeatGainOccupied(); //%get the heat again in W/m2 from appliances during occupied times
779 1 double phi_plug_unocc = building->electricApplianceHeatGainUnoccupied()
780 1 + building->gasApplianceHeatGainUnoccupied(); //%get the heat again in W/m2 from appliances during unoccupied times
781 1 phi_plug_avg = phi_plug_occ * frac_hrs_wk_day + phi_plug_unocc * (1 - frac_hrs_wk_day); //% get the average heat gain from appliances in W/m2
782
783 // double phi_illum_occ = Q_illum_occ/structure->floorArea()/hoursInYear/frac_hrs_wk_day*1000; //% convert occ illum energy from kWh to W/m2
784 double phi_illum_unocc =
785 1 Q_illum_unocc / structure->floorArea() / hoursInYear / (1 - frac_hrs_wk_day) * 1000; //% convert unocc illum engergy from kWh to W/m2
786 1 phi_illum_avg = Q_illum_tot_yr / structure->floorArea() / hoursInYear * 1000; //% % convert avg E_illum from kWh per year to average W/m2
787
788 /*
789 %% Compute heat gains and losses
790
791 % heat gain from occupants
792 %%% from Table G-9 of ISO 13790
793
794 %
795 phi_int_occ=In.htgain_per_person/In.people_density_occ; % get the heat gain in W/m2 from people during occupied times
796 phi_int_unocc=In.htgain_per_person/In.people_density_unocc; % get the heat gain in W/m2 from people during unoccupied times
797 phi_int_avg=frac_hrs_wk_day*phi_int_occ +(1-frac_hrs_wk_day)*phi_int_unocc; %get the average heat gain from people in W/m2
798
799 phi_plug_occ=In.elec_plug_dens_occ + In.gas_plug_dens_occ; %get the heat again in W/m2 from appliances during occupied times
800 phi_plug_unocc=In.elec_plug_dens_unocc + In.gas_plug_dens_unocc; %get the heat again in W/m2 from appliances during unoccupied times
801 phi_plug_avg=phi_plug_occ*frac_hrs_wk_day + phi_plug_unocc*(1-frac_hrs_wk_day); % get the average heat gain from appliances in W/m2
802
803 phi_illum_occ = Q_illum_occ/In.cond_flr_area/hrs_ina_yr/frac_hrs_wk_day*1000; % convert occ illum energy from kWh to W/m2
804 phi_illum_unocc = Q_illum_unocc/In.cond_flr_area/hrs_ina_yr/(1-frac_hrs_wk_day)*1000; % convert unocc illum engergy from kWh to W/m2
805 phi_illum_avg = Q_illum_tot_yr/In.cond_flr_area/hrs_ina_yr*1000; % % convert avg E_illum from kWh per year to average W/m2
806
807 %%% CHANGED
808 % modified code to read average people density during unoccupied times
809 % rathter than assuming it is 1/9 of occupied times.
810 %
811
812 % original spreadsheet computed the approximate internal heat gain for week nights, weekend days, and weekend nights
813 % assuming they scale as the occ. fractions. These are used for finding temp and not for directly calculating energy
814 % use total so approximations are more acceptable
815 % phi_int_wk_nt=(phi_int_occ+phi_plug_occ+phi_illum_occ)*occ_frac_wk_nt;
816 % phi_int_wke_day=(phi_int_occ+phi_plug_occ+phi_illum_occ)*occ_frac_wke_day;
817 % phi_int_wke_nt=(phi_int_occ+phi_plug_occ+phi_illum_occ)*occ_frac_wke_nt;
818
819 % the following is a more accuate internal heat gain for week nights,
820 % weekend days and weekend nights as it uses the unoccupied values rather
821 % than just scaling occupied versions with the occupancy fraction
822 % RTM 13-Nov-2012
823 */
824 1 phi_int_wk_nt = (phi_int_unocc + phi_plug_unocc + phi_illum_unocc);
825 1 phi_int_wke_day = (phi_int_unocc + phi_plug_unocc + phi_illum_unocc);
826 1 phi_int_wke_nt = (phi_int_unocc + phi_plug_unocc + phi_illum_unocc);
827
828 /*
829 phi_int_wk_nt=(phi_int_unocc+phi_plug_unocc+phi_illum_unocc);
830 phi_int_wke_day=(phi_int_unocc+phi_plug_unocc+phi_illum_unocc);
831 phi_int_wke_nt=(phi_int_unocc+phi_plug_unocc+phi_illum_unocc);
832 */
833 1 }
834 1 void SimModel::internalHeatGain(double phi_int_avg, double phi_plug_avg, double phi_illum_avg, double& phi_I_tot) const {
835 1 double phi_I_occ = phi_int_avg * structure->floorArea(); //%phi_I_occ - total occupant internal heat gain per year
836 1 double phi_I_app = phi_plug_avg * structure->floorArea(); // %phi_I_app - total appliance internal heat gain per year
837 1 double phi_I_lt = phi_illum_avg * structure->floorArea(); //%phi_I_lg - total lighting internal heat gain per year
838 1 phi_I_tot = phi_I_occ + phi_I_app + phi_I_lt;
839
840 /*
841 %% Internal Heat Gain in MJ
842
843 phi_I_occ = phi_int_avg*In.cond_flr_area; %phi_I_occ - total occupant internal heat gain per year
844 phi_I_app = phi_plug_avg*In.cond_flr_area; %phi_I_app - total appliance internal heat gain per year
845 phi_I_lt = phi_illum_avg*In.cond_flr_area; %phi_I_lg - total lighting internal heat gain per year
846 phi_I_tot = phi_I_occ + phi_I_app + phi_I_lt;
847 */
848 1 }
849 1 void SimModel::unoccupiedHeatGain(double phi_int_wk_nt, double phi_int_wke_day, double phi_int_wke_nt, const Vector& weekdayUnoccupiedMegaseconds,
850 const Vector& weekendOccupiedMegaseconds, const Vector& weekendUnoccupiedMegaseconds,
851 const Vector& frac_Pgh_wk_nt, const Vector& frac_Pgh_wke_day, const Vector& frac_Pgh_wke_nt,
852 const Vector& v_E_sol, Vector& v_P_tot_wke_day, Vector& v_P_tot_wk_nt, Vector& v_P_tot_wke_nt) const {
853
1/1
✓ Branch 3 taken 1 time.
1 Vector v_W_int_wk_nt = mult(weekdayUnoccupiedMegaseconds, phi_int_wk_nt * structure->floorArea());
854
1/1
✓ Branch 3 taken 1 time.
1 Vector v_W_int_wke_day = mult(weekendOccupiedMegaseconds, phi_int_wke_day * structure->floorArea());
855
1/1
✓ Branch 3 taken 1 time.
1 Vector v_W_int_wke_nt = mult(weekendUnoccupiedMegaseconds, phi_int_wke_nt * structure->floorArea());
856
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_int_wk_nt", v_W_int_wk_nt);
857
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_int_wke_day", v_W_int_wke_day);
858
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_int_wke_nt", v_W_int_wke_nt);
859
1/1
✓ Branch 1 taken 1 time.
1 Vector v_W_sol_wk_nt = mult(v_E_sol, frac_Pgh_wk_nt);
860
1/1
✓ Branch 1 taken 1 time.
1 Vector v_W_sol_wke_day = mult(v_E_sol, frac_Pgh_wke_day);
861
1/1
✓ Branch 1 taken 1 time.
1 Vector v_W_sol_wke_nt = mult(v_E_sol, frac_Pgh_wke_nt);
862
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_sol_wk_nt", v_W_sol_wk_nt);
863
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_sol_wke_day", v_W_sol_wke_day);
864
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_W_sol_wke_nt", v_W_sol_wke_nt);
865
866
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_P_tot_wk_nt = div(sum(v_W_int_wk_nt, v_W_sol_wk_nt), weekdayUnoccupiedMegaseconds);
867
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_P_tot_wke_day = div(sum(v_W_int_wke_day, v_W_sol_wke_day), weekendOccupiedMegaseconds);
868
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_P_tot_wke_nt = div(sum(v_W_int_wke_nt, v_W_sol_wke_nt), weekendUnoccupiedMegaseconds);
869 /*
870 %% Unoccupied time heat gains in MJ
871 v_W_int_wk_nt=In.cond_flr_area.*phi_int_wk_nt.*v_Msec_wk_nt; %internal heat gain for "week" "night"
872 v_W_int_wke_day=In.cond_flr_area.*phi_int_wke_day.*v_Msec_wke_day; %internal heat gain "weekend" "day"
873 v_W_int_wke_nt=In.cond_flr_area.*phi_int_wke_nt.*v_Msec_wke_nt; %internal heat gain "weekend" "night"
874
875 v_W_sol_wk_nt = v_E_sol.*frac_Pgh_wk_nt; %solar heat gain "week" "night" in MJ
876 v_W_sol_wke_day = v_E_sol.*frac_Pgh_wke_day; % solar heat gain "weekend" "day" in MJ
877 v_W_sol_wke_nt = v_E_sol.*frac_Pgh_wke_nt; % solar heat gain "weekend" "night" in MJ
878
879 v_P_tot_wk_nt = (v_W_int_wk_nt+v_W_sol_wk_nt)./v_Msec_wk_nt; % total heat gain "week" "night" W/m2
880 v_P_tot_wke_day = (v_W_int_wke_day+v_W_sol_wke_day)./v_Msec_wke_day;% total heat gain "weekend" "day W/m2
881 v_P_tot_wke_nt = (v_W_int_wke_nt+v_W_sol_wke_nt)./v_Msec_wke_nt; % total heat gain "weekend" "night" W/m2
882
883
884 */
885 1 }
886 1 void SimModel::interiorTemp(const Vector& v_wall_A, const Vector& /*v_P_tot_wke_day*/, const Vector& v_P_tot_wk_nt,
887 const Vector& /*v_P_tot_wke_nt*/, const Vector& v_Tdbt_nt, double H_tr, double hoursUnoccupiedPerDay,
888 double hoursOccupiedPerDay, double frac_hrs_wk_day, double frac_hrs_wk_nt, double frac_hrs_wke_tot, Vector& v_Th_avg,
889 Vector& v_Tc_avg, double& tau) const {
890 //BEM Type
891 1 double T_adj = 0;
892
1/4
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1 switch (static_cast<int>(building->buildingEnergyManagement())) {
893 1 case 1:
894 1 T_adj = 0.0;
895 1 break;
896 ✗ case 2:
897 ✗ T_adj = 0.5;
898 ✗ break;
899 ✗ case 3:
900 ✗ T_adj = 1.0;
901 ✗ break;
902 }
903 1 double ht_tset_ctrl = heating->temperatureSetPointOccupied() - T_adj;
904 1 double cl_tset_ctrl = cooling->temperatureSetPointOccupied() + T_adj;
905
906 1 double ht_tset_unocc = heating->temperatureSetPointUnoccupied();
907 1 double cl_tset_unocc = cooling->temperatureSetPointUnoccupied();
908
909 #ifdef DEBUG_ISO_MODEL_SIMULATION
910 LOG(Trace, "ht_tset_ctrl " << ht_tset_ctrl);
911 LOG(Trace, "cl_tset_ctrl " << cl_tset_ctrl);
912 LOG(Trace, "ht_tset_unocc" << ht_tset_unocc);
913 LOG(Trace, "cl_tset_unocc" << cl_tset_unocc);
914 #endif
915
916
1/1
✓ Branch 1 taken 1 time.
2 Vector v_ht_tset_ctrl(12);
917
1/1
✓ Branch 1 taken 1 time.
2 Vector v_cl_tset_ctrl(12);
918
919
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_cl_tset_ctrl.size(); i++) {
920
1/1
✓ Branch 1 taken 12 times.
12 v_cl_tset_ctrl[i] = cl_tset_ctrl;
921
1/1
✓ Branch 1 taken 12 times.
12 v_ht_tset_ctrl[i] = ht_tset_ctrl;
922 }
923
924 #ifdef DEBUG_ISO_MODEL_SIMULATION
925 printVector("v_cl_tset_ctrl", v_cl_tset_ctrl);
926 printVector("v_ht_tset_ctrl", v_ht_tset_ctrl);
927 #endif
928
929 /*
930 %% Interior Temp (occ, weekday unocc, weekend day, weekend night)
931
932 % det the temp differential from the interior heating./cooling setpoint
933 % based on the BEM type.
934 % an advanced BEM has the effect of reducing the effective heating temp and
935 % raising the effective cooling temp during times of control (i.e. during
936 % occupancy).
937 %
938 switch In.BEM_type
939 case 1
940 T_adj=0;
941 case 2
942 T_adj=0.5;
943 case 3
944 T_adj=1;
945 end
946
947 ht_tset_ctrl = In.ht_tset_occ - T_adj; %
948 cl_tset_ctrl = In.cl_tset_occ + T_adj;
949
950 % during unoccupied times, we use a setback temp and even if we have a BEM
951 % it has no effect
952 ht_tset_unocc = In.ht_tset_unocc;
953 cl_tset_unocc = In.cl_tset_unocc;
954
955 v_ht_tset_ctrl = ones(12,1).*ht_tset_ctrl; % create a column vector of the interior heating temp set point for each month
956 v_cl_tset_ctrl = ones(12,1).*cl_tset_ctrl;
957 */
958
959 1 double T_ht_ctrl_flag = 1;
960 1 double T_cl_ctrl_flag = 1;
961 1 double Cm_int = structure->interiorHeatCapacity() * structure->floorArea(); //% set the interior heat capacity
962
963
1/1
✓ Branch 3 taken 1 time.
1 double Cm_env = structure->wallHeatCapacity() * sum(v_wall_A);
964 1 double Cm = Cm_int + Cm_env;
965
966 /*
967 % flags to signify if we have heating and controls turned on or off
968 % and cooling and controls turned off. We might turn off if we are
969 % unoccupied for an extended period of time, say a school in summer
970 T_ht_ctrl_flag=1;
971 T_cl_ctrl_flag=1;
972
973 %%% NOTE heat capacity description had an error on input sheet before. It asked for
974 % envelope heat capacity but used floor area for Cm calc so this should ask
975 % for heat capacity of interior construction.
976 % We should really should separate this into envelope and interior terms
977 % and add them together
978 % RTM 13-NOV-2012
979
980
981 % set the heat capacity given the building interior heat capacity per unit
982 % area J/K/m2 from input spreadsheet
983 Cm_int=In.heat_capacity_int*In.cond_flr_area; % set the interior heat capacity
984
985 %%% CHANGE
986 % add in the heat capacity of the wall to the heat capacity of interior
987 % based on floor area. Assume same J/K/m2 for walls as interior for now
988 % do not add in window areas
989 Cm_env=In.heat_capacity_env.*(sum(v_wall_A));
990
991 %Cm_env=0; % use this to match old spreadsheet Cm calc;
992 Cm=Cm_int+Cm_env;
993 */
994 1 double H_ve = 0.0;
995 1 double H_tot = H_tr + H_ve;
996 1 tau = Cm / H_tot / 3600.0;
997 /*
998 % H_ve is overall heat transfer coefficient by ventilation as per ISO 13790 9.3
999 H_ve=0; % not implemented, set to 0 for now (its small so a good approx anyhow)
1000 H_tot=H_tr+H_ve; %total overall heat transfer coefficient as per 12.2.1.3
1001
1002 tau=Cm./H_tot/3600; % time constant of building in *hours* as per eqn 62 in 12.2.1.3 of 13790
1003
1004 % The following code computes the average weekend room temp using exponential rise and
1005 % decays as we switch between day and night temp settings. It assumes that
1006 % the weekend is two days (we'll call them sat and sun)
1007 %
1008 % we do this wierd breakdown breakdown because want to separate day with
1009 % solar loading from night without. We can then use the average temp
1010 % in each time frame rather than the overall monthly average. right now
1011 % wk_nt stuff is the same as wke_nt, but wke_day is much different because
1012 % the solar gain increases the heat gain considerably, even on the weekend
1013 % when occupant, lighting, and plugload gains are small
1014 */
1015
1016
1/1
✓ Branch 1 taken 1 time.
2 Vector v_ti(5);
1017
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_ti[0] = v_ti[2] = v_ti[4] = hoursUnoccupiedPerDay;
1018
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_ti[1] = v_ti[3] = hoursOccupiedPerDay;
1019
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 Matrix M_dT(v_P_tot_wk_nt.size(), 5, 0);
1020
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 Matrix M_Te(v_Tdbt_nt.size(), 5, 0);
1021 /*
1022 %%% NOTE
1023 % The following code is not a direct translation of the excel spreadsheet
1024 % but makes use of both loops and matricies for clarity but computes the same results
1025
1026 % create a vector of lengths of the periods of times between possible temperature resets during
1027 % the weekend
1028 v_ti=[hrs_unocc_per_day, hrs_occ_per_day, hrs_unocc_per_day, hrs_occ_per_day, hrs_unocc_per_day];
1029
1030 % generate an effective delta T matrix from ratio of total interior gains to heat
1031 % transfer coefficient for each time period
1032 % Note this is a matrix where the columns are the vectors v_P_tot_wk_nt/H_tot, and so on
1033 % this is for a week night, weekend day, weekend night, weekend day,weekend night sequence
1034 M_dT=[v_P_tot_wk_nt, v_P_tot_wke_day, v_P_tot_wke_nt, v_P_tot_wke_day, v_P_tot_wke_nt]./H_tot;
1035 M_Te=[v_Tdbt_nt, v_Tdbt_day, v_Tdbt_nt, v_Tdbt_day, v_Tdbt_nt]; % create a matrix of the average dry bulb temps
1036
1037 */
1038
1039 /*re-arrange the Else by just using the copy constructors
1040
1041 else % if the HVAC heating controls are turned off there is no setback so temp is constant
1042 v_Th_wk_day=v_ht_tset_ctrl;
1043 v_Th_wk_nt=v_ht_tset_ctrl;
1044 v_Th_wke_avg=v_ht_tset_ctrl;
1045 end
1046 */
1047
1048
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Th_wke_avg(v_ht_tset_ctrl);
1049
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Th_wk_day(v_ht_tset_ctrl);
1050
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Th_wk_nt(v_ht_tset_ctrl);
1051
1052 /*
1053 % compute the change in temp from setback to another heating temp in unoccupied times
1054 if T_ht_ctrl_flag ==1 % if the HVAC heating controls are turned on.*/
1055
1056
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (T_ht_ctrl_flag == 1) { //if the HVAC heating controls are turned on.
1057
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Ta(12, 4, 0);
1058
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Tstart(v_ht_tset_ctrl);
1059
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
5 for (size_t i = 0; i < M_Ta.size2(); i++) {
1060
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 4 times.
52 for (size_t j = 0; j < M_Ta.size1(); j++) {
1061
8/8
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 13 taken 48 times.
✓ Branch 16 taken 48 times.
✓ Branch 19 taken 48 times.
✓ Branch 22 taken 48 times.
48 v_Tstart(j) = M_Ta(j, i) = (v_Tstart(j) - M_Te(j, i) - M_dT(j, i)) * std::exp(-1 * v_ti(i) / tau) + M_Te(j, i) + M_dT(j, i);
1062 }
1063 }
1064
1065 /*
1066 % find the exponential Temp decay after any changes in heating temp setpoint and put
1067 % in the matrix M_Ta with columns being the different time segments
1068
1069 M_Ta=zeros(12,4);
1070 v_Tstart=v_ht_tset_ctrl;
1071 for I=1:4
1072 M_Ta(:,I)=(v_Tstart - M_Te(:,I) - M_dT(:,I)).*std::exp(-v_ti(I)./tau)+M_Te(:,I)+M_dT(:,I);
1073 v_Tstart=M_Ta(:,I);
1074 end
1075 */
1076
1077
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Taa(12, 5, 0);
1078 #ifdef DEBUG_ISO_MODEL_SIMULATION
1079 printMatrix("M_Taa", M_Taa);
1080 #endif
1081
1082
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 time.
13 for (size_t j = 0; j < M_Taa.size1(); j++) {
1083
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 M_Taa(j, 1) = v_ht_tset_ctrl[j];
1084 }
1085
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
5 for (size_t i = 1; i < M_Taa.size2(); i++) {
1086
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 4 times.
52 for (size_t j = 0; j < M_Taa.size1(); j++) {
1087
2/2
✓ Branch 1 taken 48 times.
✓ Branch 5 taken 48 times.
48 M_Taa(j, i) = std::max(M_Ta(j, i - 1), ht_tset_unocc);
1088 }
1089 }
1090 #ifdef DEBUG_ISO_MODEL_SIMULATION
1091 printMatrix("M_Taa", M_Taa);
1092 #endif
1093
1094 /*
1095 % the temp will only decay to the new lower setpoint, so find which is
1096 % higher the setpoint or the decay and select that as the start point for
1097 % the average integration to follow
1098 M_Taa=zeros(12,5);
1099 M_Taa(:,1)=v_ht_tset_ctrl;
1100 for I=2:5 % loop wke day to wke nt to wke day to wke nt
1101 M_Taa(:,I)=max(M_Ta(:,I-1),ht_tset_unocc);
1102 %v_Tstart=M_Ta(:,I);
1103 end
1104 */
1105
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Tb(12, 5, 0);
1106
1107
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
6 for (size_t i = 0; i < M_Tb.size2(); i++) {
1108
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 5 times.
65 for (size_t j = 0; j < M_Tb.size1(); j++) {
1109
7/7
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 7 taken 60 times.
✓ Branch 10 taken 60 times.
✓ Branch 13 taken 60 times.
✓ Branch 16 taken 60 times.
✓ Branch 19 taken 60 times.
60 double v_T_avg = tau / v_ti(i) * (M_Taa(j, i) - M_Te(j, i) - M_dT(j, i)) * (1 - std::exp(-1 * v_ti(i) / tau)) + M_Te(j, i) + M_dT(j, i);
1110
1/1
✓ Branch 2 taken 60 times.
60 M_Tb(j, i) = std::max(v_T_avg, ht_tset_unocc);
1111 }
1112 }
1113
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_Th_wke_avg.size(); i++) {
1114 12 double thisSum = 0;
1115
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 12 times.
72 for (size_t j = 0; j < M_Tb.size2(); j++) {
1116
1/1
✓ Branch 1 taken 60 times.
60 thisSum += M_Tb(i, j);
1117 }
1118
1/1
✓ Branch 2 taken 12 times.
12 v_Th_wke_avg[i] = thisSum / M_Tb.size2();
1119 }
1120
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 time.
13 for (size_t j = 0; j < M_Tb.size1(); j++) {
1121
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_Th_wk_nt[j] = M_Tb(j, 1);
1122 }
1123 1 }
1124 /*
1125 M_Tb=zeros(12,5);
1126 % for each time period, find the average temp given the start and
1127 % ending temp and assuming exponential decay of temps
1128 %v_t_start=M_Taa(:,1);
1129 for I=1:5 % loop through wk nt to wke day to wke nt to wke day to wke nt
1130 v_T_avg=tau./v_ti(I).*(M_Taa(:,I) - M_Te(:,I) -M_dT(:,I)).*(1-std::exp(-v_ti(I)/tau)) + M_Te(:,I) +M_dT(:,I);
1131 M_Tb(:,I) = max(v_T_avg,ht_tset_unocc);
1132 end
1133
1134 v_Th_wke_avg=zeros(12,1);
1135 for I=1:12 % for each month
1136 v_Th_wke_avg(I)=mean(M_Tb(I,:)); % get the average for each month
1137 end
1138 v_Th_wk_day = v_ht_tset_ctrl;
1139 v_Th_wk_nt=M_Tb(:,1);
1140 */
1141
1142
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Tc_wk_day(v_cl_tset_ctrl);
1143
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Tc_wk_nt(v_cl_tset_ctrl);
1144
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Tc_wke_avg(v_cl_tset_ctrl);
1145
1146 /*else % if cooling controls are turned off, temp will be constant at the control set temp with no setback
1147 v_Tc_wk_day=v_cl_tset_ctrl;
1148 v_Tc_wk_nt=v_cl_tset_ctrl;
1149 v_Tc_wke_avg=v_cl_tset_ctrl;
1150 end*/
1151
1152
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (T_cl_ctrl_flag == 1) {
1153
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Tc(12, 4, 0);
1154
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Tstart(v_cl_tset_ctrl);
1155
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
5 for (size_t i = 0; i < M_Tc.size2(); i++) {
1156
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 4 times.
52 for (size_t j = 0; j < M_Tc.size1(); j++) {
1157
8/8
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 13 taken 48 times.
✓ Branch 16 taken 48 times.
✓ Branch 19 taken 48 times.
✓ Branch 22 taken 48 times.
48 v_Tstart(j) = M_Tc(j, i) = (v_Tstart(j) - M_Te(j, i) - M_dT(j, i)) * std::exp(-1 * v_ti(i) / tau) + M_Te(j, i) + M_dT(j, i);
1158 }
1159 }
1160 /*
1161 if T_cl_ctrl_flag ==1 % if the HVAC cooling controls are on
1162 % find the Temp decay after any changes in cooling temp setpoint
1163 M_Tc=zeros(12,4);
1164 v_Tstart=v_cl_tset_ctrl;
1165 for I=1:4
1166 M_Tc(:,I)=(v_Tstart - M_Te(:,I) - M_dT(:,I)).*std::exp(-v_ti(I)/tau)+M_Te(:,I)+M_dT(:,I);
1167 v_Tstart=M_Tc(:,I);
1168 end
1169 */
1170
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Tcc(12, 5, 0);
1171
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 time.
13 for (size_t j = 0; j < M_Tcc.size1(); j++) {
1172
2/2
✓ Branch 1 taken 12 times.
✓ Branch 5 taken 12 times.
12 M_Tcc(j, 1) = std::min(v_ht_tset_ctrl[j], cl_tset_unocc);
1173 }
1174
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
5 for (size_t i = 1; i < M_Tcc.size2(); i++) {
1175
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 4 times.
52 for (size_t j = 0; j < M_Tcc.size1(); j++) {
1176
2/2
✓ Branch 1 taken 48 times.
✓ Branch 5 taken 48 times.
48 M_Tcc(j, i) = std::max(M_Tc(j, i - 1), cl_tset_unocc);
1177 }
1178 }
1179 /*
1180 % Check to see if the decay temp is lower than the temp setpoint. If so, the space will cool
1181 % to that level. If the cooling setpoint is lower the cooling system will kick in and lower the
1182 % temp to the cold temp setpoint
1183 M_Tcc=zeros(12,5);
1184 M_Tcc(:,1)=min(v_cl_tset_ctrl,cl_tset_unocc);
1185 for I=2:5
1186 M_Tcc(:,I)=min(M_Tc(:,I-1),cl_tset_unocc);
1187 end
1188 */
1189
1190
1/1
✓ Branch 1 taken 1 time.
1 Matrix M_Td(12, 5, 0);
1191
1192
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
6 for (size_t i = 0; i < M_Td.size2(); i++) {
1193
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 5 times.
65 for (size_t j = 0; j < M_Td.size1(); j++) {
1194
7/7
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 7 taken 60 times.
✓ Branch 10 taken 60 times.
✓ Branch 13 taken 60 times.
✓ Branch 16 taken 60 times.
✓ Branch 19 taken 60 times.
60 double v_T_avg = tau / v_ti(i) * (M_Tcc(j, i) - M_Te(j, i) - M_dT(j, i)) * (1 - std::exp(-1 * v_ti(i) / tau)) + M_Te(j, i) + M_dT(j, i);
1195
1/1
✓ Branch 2 taken 60 times.
60 M_Td(j, i) = std::max(v_T_avg, cl_tset_unocc);
1196 }
1197 }
1198
1199
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_Th_wke_avg.size(); i++) {
1200 12 double thisSum = 0;
1201
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 12 times.
72 for (size_t j = 0; j < M_Td.size2(); j++) {
1202
1/1
✓ Branch 1 taken 60 times.
60 thisSum += M_Td(i, j);
1203 }
1204
1/1
✓ Branch 2 taken 12 times.
12 v_Tc_wke_avg[i] = thisSum / M_Td.size2();
1205 }
1206
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 time.
13 for (size_t j = 0; j < M_Td.size1(); j++) {
1207
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_Tc_wk_nt[j] = M_Td(j, 1);
1208 }
1209 /*
1210 % for each time period, find the average temp given the exponential
1211 % decay
1212 %v_t_start=M_Tcc(:,1);
1213 M_Td=zeros(12,5);
1214 for I=1:5
1215 v_T_avg=tau./v_ti(I).*(M_Tcc(:,I) - M_Te(:,I) -M_dT(:,I)).*(1-std::exp(-v_ti(I)/tau)) + M_Te(:,I) +M_dT(:,I);
1216 M_Td(:,I) = min(v_T_avg,cl_tset_unocc);
1217 end
1218
1219 v_Tc_wke_avg=zeros(12,1);
1220 for I=1:12
1221 v_Tc_wke_avg(I)=mean(M_Td(I,:)); % get the average for each month
1222 end
1223 v_Tc_wk_day = v_cl_tset_ctrl;
1224 v_Tc_wk_nt=M_Td(:,1); % T_i_unocc_weekday_night
1225 */
1226 1 }
1227
1228
5/5
✓ 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.
2 Vector v_Th_wk_avg = sum(sum(mult(v_Th_wk_day, frac_hrs_wk_day), mult(v_Th_wk_nt, frac_hrs_wk_nt)), mult(v_Th_wke_avg, frac_hrs_wke_tot));
1229
5/5
✓ 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.
2 Vector v_Tc_wk_avg = sum(sum(mult(v_Tc_wk_day, frac_hrs_wk_day), mult(v_Tc_wk_nt, frac_hrs_wk_nt)), mult(v_Tc_wke_avg, frac_hrs_wke_tot));
1230
1231 //v_Th_avg(v_Th_wk_avg);
1232 //v_Tc_avg(v_Tc_wk_avg);
1233 #ifdef DEBUG_ISO_MODEL_SIMULATION
1234 LOG(Trace, "ht_tset_ctrl " << ht_tset_ctrl);
1235 LOG(Trace, "cl_tset_ctrl " << cl_tset_ctrl);
1236
1237 printVector("v_Th_wk_day", v_Th_wk_day);
1238 printVector("v_Th_wk_nt", v_Th_wk_nt);
1239 printVector("v_Th_wke_nt", v_Th_wke_avg);
1240
1241 printVector("v_Th_wk_avg", v_Th_wk_avg);
1242 printVector("v_Tc_wk_avg", v_Th_wk_avg);
1243 #endif
1244
1245
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_Tc_wk_avg.size(); i++) {
1246
2/2
✓ Branch 1 taken 12 times.
✓ Branch 5 taken 12 times.
12 v_Th_avg[i] = std::min(v_Th_wk_avg[i], ht_tset_ctrl);
1247
2/2
✓ Branch 1 taken 12 times.
✓ Branch 5 taken 12 times.
12 v_Tc_avg[i] = std::min(v_Tc_wk_avg[i], cl_tset_ctrl);
1248 }
1249 /*
1250
1251
1252 %find the average temp for the whole week from the fractions of each period
1253 v_Th_wk_avg = v_Th_wk_day*frac_hrs_wk_day+v_Th_wk_nt*frac_hrs_wk_nt+v_Th_wke_avg*frac_hrs_wke_tot; % T_i_average
1254 v_Tc_wk_avg = v_Tc_wk_day*frac_hrs_wk_day+v_Tc_wk_nt*frac_hrs_wk_nt+v_Tc_wke_avg*frac_hrs_wke_tot; % T_i_average
1255
1256 % the final avg for monthly energy computations is the lesser of the avg
1257 % computed above and the heating set control
1258 v_Th_avg = min(v_Th_wk_avg,ht_tset_ctrl) ;% T_i_heat_average_cal
1259 v_Tc_avg = max(v_Tc_wk_avg,cl_tset_ctrl); % T_i_cool_average_cal
1260
1261 */
1262 1 }
1263 1 void SimModel::ventilationCalc(const Vector& v_Th_avg, const Vector& v_Tc_avg, double frac_hrs_wk_day, Vector& v_Hve_ht, Vector& v_Hve_cl) const {
1264 1 double vent_zone_height = std::max(0.1, structure->buildingHeight());
1265 1 double qv_supp = ventilation->supplyRate() / structure->floorArea() / 3.6;
1266 1 double qv_ext = -(qv_supp - ventilation->supplyDifference() / structure->floorArea() / 3.6);
1267 1 double qv_comb = 0;
1268 1 double qv_diff = qv_supp + qv_ext + qv_comb;
1269 1 double vent_ht_recov = ventilation->heatRecoveryEfficiency();
1270 1 double vent_outdoor_frac = 1 - ventilation->exhaustAirRecirculated();
1271
2/2
✓ Branch 3 taken 1 time.
✓ Branch 8 taken 1 time.
1 double tot_env_A = sum(structure->wallArea()) + sum(structure->windowArea());
1272 /*
1273
1274 %% Ventilation
1275 % required energy for mechanical ventilation based on source EN ISO 13789
1276 % C.3, C.5 and EN 15242:2007 6.7 and EN ISO 13790 Sec 9.2
1277
1278 vent_zone_height=max(0.1, In.stories*In.ftof); % Ventilztion Zone Height (m) with a minimum of 0.1 m
1279
1280 qv_supp=In.vent_supply_rate./In.cond_flr_area./3.6; %vent_supply_rate m3/h/m2 (input is in in L/s)
1281 qv_ext=-(qv_supp-In.vent_supply_diff./In.cond_flr_area./3.6); %vent exhaust rate m3/h/m2, negative indicates out of building
1282
1283 qv_comb = 0 ; % combustion appliance ventilation rate - not implemented yet but will be impt for restaurants
1284 qv_diff=qv_supp + qv_ext + qv_comb; % difference between air intake and air exhaust including combustion exhaust
1285
1286 vent_ht_recov=In.vent_heat_recovery; %vent_heat_recovery_eff
1287 vent_outdoor_frac=1-In.vent_recirc_fraction; % fctrl_vent_recirculation
1288
1289 % infilatration source EN 15242:2007 Sec 6.7 direct method
1290 tot_env_A=sum(In.wall_area)+sum(In.win_area);
1291 */
1292 1 double n_p_exp = 0.65;
1293 /// \todo Note: v_Q75pa, aka infiltrationRate(), is never being calculated or set, so it is, at least in some cases, a
1294 /// random value (now that the matrices are properly initialized to 0). So when it goes to 0, the rest
1295 /// of the model goes to infinity for the HVAC calculations.
1296 /// I'm setting it to non-zero here
1297 1 double v_Q75pa = structure->infiltrationRate();
1298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (v_Q75pa == 0) {
1299 ✗ v_Q75pa = 0.00000000001; // this might be a vestige of the rmeove of the "epsilon" code in the translator
1300 }
1301
1302 1 double floorArea = structure->floorArea();
1303 1 double v_Q4pa = v_Q75pa * tot_env_A / floorArea * (std::pow((4.0 / 75.0), n_p_exp));
1304
1305 #ifdef DEBUG_ISO_MODEL_SIMULATION
1306 LOG(Trace, "v_Q4pa " << v_Q4pa << " v_Q75pa " << v_Q75pa << " tot_env_A " << tot_env_A << " floorArea: " << floorArea << " n_p_exp " << n_p_exp);
1307 #endif
1308
1309 1 double n_zone_frac = 0.7;
1310 1 double h_stack = n_zone_frac * vent_zone_height;
1311 1 double n_stack_exp = 0.667; //% reset the pressure exponent to 0.667 for this part of the calc
1312 1 double n_stack_coeff = 0.0146;
1313
1/1
✓ Branch 5 taken 1 time.
1 Vector dbtDiff = dif(location->weather()->mdbt(), v_Th_avg);
1314
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtDiff", dbtDiff);
1315
1/1
✓ Branch 1 taken 1 time.
1 Vector dbtDiffAbs = isomodel::abs(dbtDiff);
1316
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtDiffAbs", dbtDiffAbs);
1317
1/1
✓ Branch 1 taken 1 time.
1 Vector dbtHStack = mult(dbtDiffAbs, h_stack);
1318
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtHstack", dbtHStack);
1319
1/1
✓ Branch 1 taken 1 time.
1 Vector dbtPowered = pow(dbtHStack, n_stack_exp);
1320
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtPowered", dbtPowered);
1321
1/1
✓ Branch 1 taken 1 time.
1 Vector dbtMultQ4 = mult(dbtPowered, n_stack_coeff * v_Q4pa);
1322
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtMultQ4", dbtMultQ4);
1323
1324
1/1
✓ Branch 1 taken 1 time.
1 Vector v_qv_stack_ht = maximum(dbtMultQ4, 0.001); //%qv_stack_heating m3/h/m2
1325
2/2
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
1 dbtDiff = dif(location->weather()->mdbt(), v_Tc_avg);
1326
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtDiff", dbtDiff);
1327
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 dbtDiffAbs = isomodel::abs(dbtDiff);
1328
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtDiffAbs", dbtDiffAbs);
1329
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 dbtHStack = mult(dbtDiffAbs, h_stack);
1330
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtHstack", dbtHStack);
1331
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 dbtPowered = pow(dbtHStack, n_stack_exp);
1332
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtPowered", dbtPowered);
1333
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 dbtMultQ4 = mult(dbtPowered, n_stack_coeff * v_Q4pa);
1334
1/1
✓ Branch 1 taken 1 time.
1 printVector("dbtMultQ4", dbtMultQ4);
1335
1/1
✓ Branch 1 taken 1 time.
1 Vector v_qv_stack_cl = maximum(dbtMultQ4, 0.001); //%qv_stack_cooling
1336
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_stack_ht", v_qv_stack_ht);
1337
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_stack_cl", v_qv_stack_cl);
1338
1339 /*
1340 % infiltration data from
1341 % Tamura, (1976), Studies on exterior wall air tightness and air infiltration of tall buildings, ASHRAE Transactions, 82(1), 122-134.
1342 % Orm (1998), AIVC TN44: Numerical data for air infiltration and natural ventilation calculations, Air Infiltration and Ventilation Centre.
1343 % Emmerich, (2005), Investigation of the Impact of Commercial Building Envelope Airtightness on HVAC Energy Use.
1344 % create a different table for different building types
1345 %n_highrise_inf_table=[4 6 10 15 20]; % infiltration table for high rise buildings as per Tamura, Orm and Emmerich
1346 n_p_exp=0.65; % assumed flow exponent for infiltration pressure conversion
1347 v_Q75pa=In.infilt_rate; % infiltration rate in m3/h/m2 @ 75 Pa based on wall area
1348 v_Q4pa = v_Q75pa.*tot_env_A./In.cond_flr_area*( (4/75).^n_p_exp); % convert infiltration to Q@4Pa in m3/h /m2 based on floor area
1349
1350 n_zone_frac = 0.7; %fraction that h_stack/zone height. assume 0.7 as per en 15242
1351
1352 h_stack=n_zone_frac.*vent_zone_height; % get the effective stack height for infiltration calcs
1353 % calculate the infiltration from stack effect pressure difference from EN 15242: sec 6.7.1
1354 n_stack_exp=0.667; % reset the pressure exponent to 0.667 for this part of the calc
1355 n_stack_coeff=0.0146;
1356 v_qv_stack_ht=max(n_stack_coeff.*v_Q4pa*(h_stack.*std::abs(W.mdbt-v_Th_avg)).^n_stack_exp,0.001); %qv_stack_heating m3/h/m2
1357 v_qv_stack_cl=max(n_stack_coeff.*v_Q4pa*(h_stack.*std::abs(W.mdbt-v_Tc_avg)).^n_stack_exp,0.001); %qv_stack_cooling
1358 */
1359 1 double n_wind_exp = 0.667;
1360 1 double n_wind_coeff = 0.0769;
1361 1 double n_dCp = 0.75; // % conventional value for cp difference between windward and leeward sides for low rise buildings as per 15242
1362
1363 Vector v_qv_wind_ht =
1364
4/4
✓ Branch 11 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
2 mult(mult(pow(mult(mult(location->weather()->mwind(), location->weather()->mwind()), n_dCp * location->terrain()), n_wind_exp), v_Q4pa),
1365
1/1
✓ Branch 1 taken 1 time.
1 n_wind_coeff); // % qv_wind_heating
1366 Vector v_qv_wind_cl =
1367
4/4
✓ Branch 11 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
2 mult(mult(pow(mult(mult(location->weather()->mwind(), location->weather()->mwind()), n_dCp * location->terrain()), n_wind_exp), v_Q4pa),
1368
1/1
✓ Branch 1 taken 1 time.
1 n_wind_coeff); // % qv_wind_cooling
1369
1370
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_wind_ht", v_qv_wind_ht);
1371
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_wind_cl", v_qv_wind_cl);
1372
1373 1 double n_sw_coeff = 0.14;
1374
1/1
✓ Branch 1 taken 1 time.
1 Vector v_qv_ht_max = maximum(v_qv_stack_ht, v_qv_wind_ht);
1375
1/1
✓ Branch 1 taken 1 time.
1 Vector v_qv_cl_max = maximum(v_qv_stack_cl, v_qv_wind_cl);
1376
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_ht_max", v_qv_ht_max);
1377
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_cl_max", v_qv_cl_max);
1378
1379
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 Vector v_qv_sw_ht = sum(v_qv_ht_max, div(mult(mult(v_qv_stack_ht, v_qv_wind_ht), n_sw_coeff), v_Q4pa)); // %qv_sw_heat m3/h/m2
1380
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 Vector v_qv_sw_cl = sum(v_qv_cl_max, div(mult(mult(v_qv_stack_cl, v_qv_wind_cl), n_sw_coeff), v_Q4pa)); // %qv_sw_cool m3/h/m2
1381
1382
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_sw_ht", v_qv_sw_ht);
1383
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_sw_cl", v_qv_sw_cl);
1384
1385
1/1
✓ Branch 2 taken 1 time.
1 Vector v_qv_inf_ht = sum(v_qv_sw_ht, std::max(0.0, -qv_diff)); // %q_inf_heat m3/h/m2
1386
1/1
✓ Branch 2 taken 1 time.
1 Vector v_qv_inf_cl = sum(v_qv_sw_cl, std::max(0.0, -qv_diff)); // %q_inf_cool m3/h/m2
1387
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_inf_ht", v_qv_inf_ht);
1388
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qv_inf_cl", v_qv_inf_cl);
1389
1390 /*
1391 % calculate infiltration from wind
1392 % note: terrain_class [1 = open, 0.9 = country, 0.8 =urban]
1393 n_wind_exp=0.667;
1394 n_wind_coeff=0.0769;
1395 n_dCp = 0.75; % conventional value for cp difference between windward and leeward sides for low rise buildings as per 15242
1396
1397 v_qv_wind_ht=n_wind_coeff.*v_Q4pa.*(n_dCp.*In.terrain_class.*W.mwind.^2).^n_wind_exp; % qv_wind_heating
1398 v_qv_wind_cl=n_wind_coeff.*v_Q4pa.*(n_dCp.*In.terrain_class.*W.mwind.^2).^n_wind_exp; % qv_wind_cooling
1399
1400 n_sw_coeff=0.14;
1401 v_qv_sw_ht = max(v_qv_stack_ht,v_qv_wind_ht)+n_sw_coeff.*v_qv_stack_ht.*v_qv_wind_ht./v_Q4pa; %qv_sw_heat m3/h/m2
1402 v_qv_sw_cl = max(v_qv_stack_cl,v_qv_wind_cl)+n_sw_coeff.*v_qv_stack_cl.*v_qv_wind_cl./v_Q4pa; %qv_sw_cool m3/h/m2
1403
1404 v_qv_inf_ht = max(0,-qv_diff)+v_qv_sw_ht; %q_inf_heat m3/h/m2
1405 v_qv_inf_cl = max(0,-qv_diff)+v_qv_sw_cl; %q_inf_cool m3/h/m2
1406
1407
1408 % source EN ISO 13789 C.5 There they use Vdot instead of Q
1409 % Vdot = Vdot_f (1??_v) +Vdot_x
1410 % Vdot_f is the design airflow rate due to mechanical ventilation;
1411 % Vdot_x is the additional airflow rate with fans on, due to wind effects;
1412 % ?_v is the global heat recovery efficiency, taking account of the differences between supply and extract
1413 % airflow rates. Heat in air leaving the building through leakage cannot be recovered.
1414
1415 % set vent_rate_flag=0 if ventilation rate is constant, 1 if we assume vent off in unoccopied times or
1416 % 2 if we assume ventilation rate is dropped proportionally to population
1417 %
1418 % set to 1 to mimic the behavior of the original spreadsheet
1419 */
1420 1 int vent_rate_flag = 1;
1421 double vent_op_frac;
1422
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 switch (vent_rate_flag) {
1423 ✗ case 0:
1424 ✗ vent_op_frac = 1;
1425 ✗ break;
1426 1 case 1:
1427 1 vent_op_frac = frac_hrs_wk_day;
1428 1 break;
1429 ✗ default:
1430 ✗ vent_op_frac = frac_hrs_wk_day + (1 - frac_hrs_wk_day) * pop->densityOccupied() / pop->densityUnoccupied();
1431 ✗ break;
1432 }
1433 /*
1434 vent_rate_flag=1;
1435
1436 % set the operation fraction for the ventilation rate
1437 if vent_rate_flag==0
1438 vent_op_frac=1;
1439 elseif vent_rate_flag==1
1440 vent_op_frac=frac_hrs_wk_day;
1441 else
1442 vent_op_frac=frac_hrs_wk_day+(1-frac_hrs_wk_day)*occ_dens/unocc_dens;
1443 end
1444 */
1445
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 double initVal = ventilation->type() == 3 ? 0 : (vent_op_frac * qv_supp * vent_outdoor_frac * (1 - vent_ht_recov));
1446
1/1
✓ Branch 1 taken 1 time.
2 Vector v_qv_mve_ht(12);
1447
1/1
✓ Branch 1 taken 1 time.
2 Vector v_qv_mve_cl(12);
1448
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_qv_mve_ht.size(); i++) {
1449
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 v_qv_mve_cl[i] = v_qv_mve_ht[i] = initVal;
1450 }
1451
1/1
✓ Branch 1 taken 1 time.
2 Vector v_qve_ht = sum(v_qv_inf_ht, v_qv_mve_ht);
1452
1/1
✓ Branch 1 taken 1 time.
1 Vector v_qve_cl = sum(v_qv_inf_cl, v_qv_mve_cl);
1453
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qve_ht", v_qve_ht);
1454
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_qve_cl", v_qve_cl);
1455
1456 1 double n_rhoc_air = 1200;
1457
1458
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_Hve_ht = div(mult(v_qve_ht, n_rhoc_air), 3600.0);
1459
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_Hve_cl = div(mult(v_qve_cl, n_rhoc_air), 3600.0);
1460 /*
1461 if In.vent_type==3
1462 v_qv_mve_ht=zeros(12,1); %qv_me_heating for calc
1463 else
1464 v_qv_mve_ht=ones(12,1)*vent_op_frac*qv_supp*vent_outdoor_frac*(1-vent_ht_recov);
1465 end
1466
1467 %qv_f_cl=ones(12,1)*qv_supp*vent_outdoor_frac; %qv_me_cooling
1468 if In.vent_type==3
1469 v_qv_mve_cl=zeros(12,1); %qv_me_cooling for calc
1470 else
1471 v_qv_mve_cl=ones(12,1)*vent_op_frac*qv_supp*vent_outdoor_frac*(1-vent_ht_recov);
1472 end
1473
1474 v_qve_ht = v_qv_inf_ht+v_qv_mve_ht; %total air flow in m3/s when heating
1475 v_qve_cl = v_qv_inf_cl+v_qv_mve_cl; %total air flow in m3/s when cooling
1476
1477 n_rhoc_air = 1200; % heat capacity of air per unit volume in J/(m3 K)
1478 v_Hve_ht = n_rhoc_air*v_qve_ht/3600; % Hve (W/K/m2) heating
1479 v_Hve_cl = n_rhoc_air*v_qve_cl/3600; % Hve (W/K/m2) cooling
1480
1481
1482 */
1483 1 }
1484 1 void SimModel::heatingAndCooling(const Vector& v_E_sol, const Vector& v_Th_avg, const Vector& v_Hve_ht, const Vector& v_Tc_avg,
1485 const Vector& v_Hve_cl, double tau, double H_tr, double phi_I_tot, double frac_hrs_wk_day, Vector& v_Qfan_tot,
1486 Vector& v_Qneed_ht, Vector& v_Qneed_cl, double& Qneed_ht_yr, double& Qneed_cl_yr) const {
1487
1/1
✓ Branch 1 taken 1 time.
1 Vector temp = mult(megasecondsInMonth, phi_I_tot, 12);
1488
1/1
✓ Branch 1 taken 1 time.
1 Vector v_tot_mo_ht_gain = sum(temp, v_E_sol);
1489
1490 1 double a_H0 = 1;
1491 1 double tau_H0 = 15;
1492 1 double a_H = a_H0 + tau / tau_H0;
1493
1494
3/3
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
1 Vector v_QT_ht = mult(mult(dif(v_Th_avg, location->weather()->mdbt()), megasecondsInMonth), H_tr);
1495
4/4
✓ Branch 5 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
1 Vector v_QV_ht = mult(mult(mult(v_Hve_ht, structure->floorArea()), dif(v_Th_avg, location->weather()->mdbt())), megasecondsInMonth);
1496
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qtot_ht = sum(v_QT_ht, v_QV_ht);
1497 /*
1498 %% Heating and Cooling Needs
1499
1500 %total monthly heat gains (MJ)
1501
1502 v_tot_mo_ht_gain = phi_I_tot*v_Msec_ina_mo + v_E_sol; % total_heat_gain = total internal + total solar in MJ/m2.
1503
1504 % compute the heating need including thermal mass effects
1505 % NOTE: the building heat thermal time constant, tau, was calculated in the section
1506 % on interior temperature
1507 a_H0=1; % a_H_0 = reference dimensionless parameter
1508 tau_H0=15; % tau_H_0 = reference time constant
1509 a_H = a_H0+tau/tau_H0; %a_H_building heating dimensionless constant
1510
1511 v_QT_ht = H_tr.*(v_Th_avg-v_mdbt).*v_Msec_ina_mo; %QT = transmission loss (MJ)
1512 v_QV_ht = v_Hve_ht*In.cond_flr_area.*(v_Th_avg-v_mdbt).*v_Msec_ina_mo; % QV in MJ
1513 v_Qtot_ht = v_QT_ht+v_QV_ht ; %QL_total total heat loss in MJ
1514 */
1515
2/2
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
1 Vector v_gamma_H_ht = div(v_tot_mo_ht_gain, sum(v_Qtot_ht, std::numeric_limits<double>::min()));
1516
1/1
✓ Branch 1 taken 1 time.
1 Vector v_eta_g_H(12);
1517
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_eta_g_H.size(); i++) {
1518
6/6
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 11 times.
✓ Branch 9 taken 11 times.
✓ Branch 12 taken 12 times.
13 v_eta_g_H[i] = v_gamma_H_ht(i) > 0 ? (1 - std::pow(v_gamma_H_ht[i], a_H)) / (1 - std::pow(v_gamma_H_ht[i], (a_H + 1)))
1519
1/1
✓ Branch 1 taken 1 time.
1 : 1 / (v_gamma_H_ht(i) + std::numeric_limits<double>::min());
1520 }
1521
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_Qneed_ht = dif(v_Qtot_ht, mult(v_eta_g_H, v_tot_mo_ht_gain));
1522
1/1
✓ Branch 1 taken 1 time.
1 Qneed_ht_yr = sum(v_Qneed_ht);
1523
1524 /*
1525 % compute the ratio of heat gain to heating loss, gamma_H
1526 v_gamma_H_ht = v_tot_mo_ht_gain./(v_Qtot_ht+eps); %gamma_H = QG/QL - eps added to avoid divide by zero problem
1527
1528 % for each month, check the heat gain ratio and set the heating gain
1529 % utilization factor, eta_g_H accordingly
1530 v_eta_g_H=zeros(12,1);
1531 for I=1:12
1532 if v_gamma_H_ht(I)>0
1533 v_eta_g_H(I) = (1-v_gamma_H_ht(I).^a_H)./(1-v_gamma_H_ht(I).^(a_H+1)); % eta_g_H heating gain utilization factor
1534 else
1535 v_eta_g_H(I) = 1./(v_gamma_H_ht(I)+eps);
1536 end
1537 end
1538 v_Qneed_ht = v_Qtot_ht - v_eta_g_H.*v_tot_mo_ht_gain; %QNH = QL,H - eta_G_H.*Q_G_H
1539
1540 Qneed_ht_yr = sum(v_Qneed_ht);
1541 */
1542
1543
3/3
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
1 Vector v_QT_cl = mult(mult(dif(v_Tc_avg, location->weather()->mdbt()), H_tr), megasecondsInMonth); // % QT for cooling in MJ
1544 Vector v_QV_cl =
1545
4/4
✓ Branch 5 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
1 mult(mult(mult(v_Hve_cl, structure->floorArea()), dif(v_Tc_avg, location->weather()->mdbt())), megasecondsInMonth); // % QT for coolin in MJ
1546
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qtot_cl = sum(v_QT_cl, v_QV_cl); // % QL = QT + QV for cooling = total cooling heat loss in MJ
1547
1548
2/2
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
1 Vector v_gamma_H_cl = div(v_Qtot_cl, sum(v_tot_mo_ht_gain, std::numeric_limits<double>::min())); // %gamma_C = heat loss ratio Qloss/Qgain
1549
1550 //% compute the cooling gain utilization factor eta_g_cl
1551
1/1
✓ Branch 1 taken 1 time.
1 Vector v_eta_g_CL(12);
1552
3/3
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
13 for (size_t i = 0; i < v_eta_g_CL.size(); i++) {
1553 #ifdef DEBUG_ISO_MODEL_SIMULATION
1554 double numer = (1.0 - std::pow(v_gamma_H_cl[i], a_H));
1555 //double denom = (1.0-std::pow(v_gamma_H_cl[i],(a_H+1.0)));
1556 LOG(Trace, numer << " = 1.0 - " << v_gamma_H_cl[i] << "^" << a_H);
1557 LOG(Trace, numer << " = 1.0 - " << v_gamma_H_cl[i] << "^" << (a_H + 1.0));
1558 #endif
1559
1560
5/6
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✓ Branch 9 taken 12 times.
✓ Branch 12 taken 12 times.
12 v_eta_g_CL[i] = v_gamma_H_cl(i) > 0.0 ? (1.0 - std::pow(v_gamma_H_cl[i], a_H)) / (1.0 - std::pow(v_gamma_H_cl[i], (a_H + 1.0))) : 1.0;
1561 }
1562
1563
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_Qneed_cl = dif(v_tot_mo_ht_gain, mult(v_eta_g_CL, v_Qtot_cl)); // % QNC = Q_G_C - eta*Q_L_C = total cooling need
1564
1/1
✓ Branch 1 taken 1 time.
1 Qneed_cl_yr = sum(v_Qneed_cl);
1565 /*
1566 % n_a_C0 = 1; %a_C_0 building cooling reference constant
1567 % n_tau_C0 = 15;%tau_C_0 building cooling reference time constant
1568 % C366 = n_a_C0+tau/n_tau_C0; % a_C = building cooling constant
1569
1570 v_QT_cl = H_tr*(v_Tc_avg - v_mdbt).*v_Msec_ina_mo; % QT for cooling in MJ
1571 v_QV_cl = v_Hve_cl*In.cond_flr_area.*(v_Tc_avg - v_mdbt).*v_Msec_ina_mo; % QT for coolin in MJ
1572 v_Qtot_cl = v_QT_cl+v_QV_cl; % QL = QT + QV for cooling = total cooling heat loss in MJ
1573
1574 v_gamma_H_cl = v_Qtot_cl./(v_tot_mo_ht_gain+eps); %gamma_C = heat loss ratio Qloss/Qgain
1575
1576 % compute the cooling gain utilization factor eta_g_cl
1577 v_eta_g_CL=zeros(12,1);
1578 for I=1:12 % for each month
1579 if v_gamma_H_cl(I)>0
1580 v_eta_g_CL(I) = (1-v_gamma_H_cl(I).^a_H)./(1-v_gamma_H_cl(I).^(a_H+1)); % eta_g_H cooling gain utilization factor
1581 else
1582 v_eta_g_CL(I) = 1;
1583 end
1584 end
1585
1586 v_Qneed_cl = v_tot_mo_ht_gain - v_eta_g_CL.*v_Qtot_cl; % QNC = Q_G_C - eta*Q_L_C = total cooling need
1587 Qneed_cl_yr=sum(v_Qneed_cl);
1588 */
1589 1 double n_dT_supp_ht = 7.0; //% set heating temp diff between supply air and room air
1590 1 double n_dT_supp_cl = 7.0; //%set cooling temp diff between supply air and room air
1591 1 double T_sup_ht = heating->temperatureSetPointOccupied() + n_dT_supp_ht; //%hot air supply temp - assume supply air is 7C hotter than room
1592 1 double T_sup_cl = cooling->temperatureSetPointOccupied() - n_dT_supp_cl; //%cool air supply temp - assume 7C lower than room
1593 1 double n_rhoC_a = 1.22521 * 0.001012;
1594 /*
1595 %% Fan Energy
1596
1597 n_dT_supp_ht=7; % set heating temp diff between supply air and room air
1598 n_dT_supp_cl=7; %set cooling temp diff between supply air and room air
1599 T_sup_ht = In.ht_tset_occ+n_dT_supp_ht; %hot air supply temp - assume supply air is 7C hotter than room
1600 T_sup_cl = In.cl_tset_occ-n_dT_supp_cl; %cool air supply temp - assume 7C lower than room
1601
1602 n_rhoC_a = 1.22521.*0.001012; % rho*Cp for air (MJ/m3/K)
1603 */
1604
1605
4/4
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
1 Vector v_Vair_ht = div(v_Qneed_ht, sum(mult(dif(T_sup_ht, v_Th_avg), n_rhoC_a), std::numeric_limits<double>::min()));
1606
4/4
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
1 Vector v_Vair_cl = div(v_Qneed_cl, sum(mult(dif(v_Tc_avg, T_sup_cl), n_rhoC_a), std::numeric_limits<double>::min()));
1607 1 ventilation->fanPower();
1608 1 ventilation->fanControlFactor();
1609 1 structure->floorArea();
1610
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Vair_ht", v_Vair_ht);
1611
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Vair_cl", v_Vair_cl);
1612
1613
1/1
✓ Branch 1 taken 1 time.
2 Vector v_Vair_tot = maximum(sum(v_Vair_ht, v_Vair_cl),
1614
3/3
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
3 div(mult(megasecondsInMonth, ventilation->supplyRate() * frac_hrs_wk_day, 12), 1000)); //% compute air flow in m3
1615
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Vair_tot", v_Vair_tot);
1616
1/1
✓ Branch 5 taken 1 time.
1 Vector fanPower = mult(v_Vair_tot, ventilation->fanPower() * ventilation->fanControlFactor());
1617
1/1
✓ Branch 1 taken 1 time.
1 printVector("fanPower", fanPower);
1618
1619 #ifdef DEBUG_ISO_MODEL_SIMULATION
1620 LOG(Trace, "ventilation->fanPower() = " << ventilation->fanPower());
1621 LOG(Trace, "ventilation->fanControlFactor() = " << ventilation->fanControlFactor());
1622 LOG(Trace, "structure->floorArea() = " << structure->floorArea());
1623 #endif
1624
1625
3/3
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
1 v_Qfan_tot = div(div(fanPower, structure->floorArea()), 3600); //% compute fan energy in kWh/m2
1626
1627 /*
1628 v_Vair_ht = v_Qneed_ht./(n_rhoC_a.*(T_sup_ht -v_Th_avg)+eps); %compute volume of air moved for heating
1629 v_Vair_cl = v_Qneed_cl./(n_rhoC_a.*(v_Tc_avg - T_sup_cl)+eps); % compute volume of air moved for cooling
1630
1631 v_Vair_tot=max((v_Vair_ht+v_Vair_cl),In.vent_supply_rate.*frac_hrs_wk_day.*v_Msec_ina_mo./1000); % compute air flow in m3
1632 v_Qfan_tot = v_Vair_tot.*In.fan_specific_power.*In.fan_flow_ctrl_factor./In.cond_flr_area./3600; % compute fan energy in kWh/m2
1633 */
1634 1 }
1635 1 void SimModel::hvac(const Vector& v_Qneed_ht, const Vector& v_Qneed_cl, double Qneed_ht_yr, double Qneed_cl_yr, Vector& v_Qelec_ht,
1636 Vector& v_Qgas_ht, Vector& v_Qcl_elec_tot, Vector& v_Qcl_gas_tot) const {
1637 1 double DH_YesNo = 0;
1638 1 double n_eta_DH_network = 0.9;
1639 1 double n_eta_DH_sys = 0.87;
1640 1 double n_frac_DH_free = 0.000;
1641
1642 1 double DC_YesNo = 0;
1643 1 double n_eta_DC_network = 0.9;
1644 1 double n_eta_DC_COP = 5.5;
1645 1 double n_eta_DC_frac_abs = 0;
1646 1 double n_eta_DC_COP_abs = 1;
1647 1 double n_frac_DC_free = 0;
1648 /*
1649 %% District H/C info
1650
1651 DH_YesNo =0; % building connected to DH (0=no, 1=yes. Assume DH is powered by natural gas)
1652 n_eta_DH_network = 0.9; % efficiency of DH network. Typical value 0l75-0l9 EN 15316-4-5
1653 n_eta_DH_sys = 0.87; % efficiency of DH heating system
1654 n_frac_DH_free = 0.000; % fraction of free heat source to DH (0 to 1)
1655
1656 DC_YesNo = 0; % building connected to DC (0=no, 1=yes)
1657 n_eta_DC_network = 0.9; % efficiency of DC network.
1658 n_eta_DC_COP = 5.5; % COP of DC elec Chillers
1659 n_eta_DC_frac_abs = 0; % fraction of DC chillers that are absorption
1660 n_eta_DC_COP_abs = 1; % COP of DC absorption chillers
1661 n_frac_DC_free = 0; % fraction of free heat source to absorption DC chillers (0 to 1)
1662 */
1663 1 double IEER = cooling->cop() * cooling->partialLoadValue();
1664 1 double f_waste = heating->hotcoldWasteFactor();
1665 1 double a_ht_loss = heating->hvacLossFactor();
1666 1 double a_cl_loss = cooling->hvacLossFactor();
1667
1668 /* %% HVAC System
1669 %
1670 % From EN 15243-2007 Annex E.
1671 % HVAC system info table from EN 15243:2007 Table E1. columns are
1672
1673 % SEER = COP *mPLV or maybe more properly , IEER = COP * IPLV
1674 IEER = In.COP*In.PLV ; % compute IEER the effective average COP for the cooling system
1675
1676 % copy over the HVAC loss/waste factors into local variables with names
1677 % that match the equations better
1678 f_waste=In.hotcold_waste_factor;
1679 a_ht_loss=In.heat_loss_factor;
1680 a_cl_loss=In.cool_loss_factor;
1681
1682 */
1683 1 double f_dem_ht = std::max(Qneed_ht_yr / (Qneed_cl_yr + Qneed_ht_yr), 0.1);
1684 1 double f_dem_cl = std::max((1.0 - f_dem_ht), 0.1);
1685 1 double eta_dist_ht = 1.0 / (1.0 + a_ht_loss + f_waste / f_dem_ht); //% overall distribution efficiency for heating
1686 1 double eta_dist_cl = 1.0 / (1.0 + a_cl_loss + f_waste / f_dem_cl); //%overall distrubtion efficiency for cooling
1687
1688
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Qloss_ht_dist = div(mult(v_Qneed_ht, (1 - eta_dist_ht)), eta_dist_ht);
1689
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Qloss_cl_dist = div(mult(v_Qneed_cl, (1 - eta_dist_cl)), eta_dist_cl);
1690
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qloss_ht_dist", v_Qloss_ht_dist);
1691
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qloss_cl_dist", v_Qloss_cl_dist);
1692 /*
1693 f_dem_ht=max(Qneed_ht_yr/(Qneed_cl_yr+Qneed_ht_yr),0.1); %fraction of yearly heating demand with regard to total heating + cooling demand
1694 f_dem_cl=max((1-f_dem_ht),0.1); %fraction of yearly cooling demand
1695 eta_dist_ht =1.0/(1.0+a_ht_loss+f_waste/f_dem_ht); % overall distribution efficiency for heating
1696 eta_dist_cl = 1.0/(1.0+a_cl_loss+f_waste/f_dem_cl); %overall distrubtion efficiency for cooling
1697
1698 v_Qloss_ht_dist=v_Qneed_ht*(1-eta_dist_ht)/eta_dist_ht; %losses from HVAC heat distribution
1699 v_Qloss_cl_dist = v_Qneed_cl*(1-eta_dist_cl)/eta_dist_cl; %losses from HVAC cooling distribution
1700 */
1701
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qht_sys(12);
1702
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qht_DH(12);
1703
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qcl_sys(12);
1704
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qcool_DC(12);
1705
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Qht_sys);
1706
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Qht_DH);
1707
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Qcl_sys);
1708
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Qcool_DC);
1709 // TODO: always true right now
1710 // cppcheck-suppress knownConditionTrueFalse
1711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (DH_YesNo == 1) {
1712 ✗ v_Qht_DH = sum(v_Qneed_ht, v_Qloss_ht_dist);
1713 } else {
1714
3/3
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 v_Qht_sys = div(sum(v_Qloss_ht_dist, v_Qneed_ht), heating->efficiency() + std::numeric_limits<double>::min());
1715 }
1716
1717 // TODO: always true right now
1718 // cppcheck-suppress knownConditionTrueFalse
1719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (DC_YesNo == 1) {
1720 ✗ v_Qcool_DC = sum(v_Qneed_cl, v_Qloss_cl_dist);
1721 } else {
1722
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
1 v_Qcl_sys = div(sum(v_Qloss_cl_dist, v_Qneed_cl), IEER + std::numeric_limits<double>::min());
1723 }
1724
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qht_sys", v_Qht_sys);
1725
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qht_DH", v_Qht_DH);
1726
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcl_sys", v_Qcl_sys);
1727
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcool_DC", v_Qcool_DC);
1728 /*
1729 if DH_YesNo==1
1730 v_Qht_sys = zeros(12,1); % if we have district heating our heating energy needs from our system are zero
1731 v_Qht_DH = v_Qneed_ht+v_Qloss_ht_dist; %Q_heat_nd for DH
1732 else
1733 v_Qht_sys =(v_Qloss_ht_dist+v_Qneed_ht)/(In.heat_sys_eff+eps); % total heating energy need from our system including losses
1734 v_Qht_DH = zeros(12,1);
1735 end
1736
1737 if DC_YesNo==1
1738 v_Qcl_sys = zeros(12,1); % if we have district cooling our cooling energy needs from our system are zero
1739 v_Qcool_DC = v_Qloss_cl_dist+v_Qneed_cl; % if we have DC the cooling needs are the dist losses + the cooling needs themselves
1740 else
1741 v_Qcl_sys =(v_Qloss_cl_dist+v_Qneed_cl)/(IEER+eps); % if no DC compute our total system cooling energy needs including losses
1742 v_Qcool_DC=zeros(12,1); % if no DC, DC cooling needs are zero
1743 end
1744
1745
1746 */
1747
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Qcl_DC_elec = div(mult(v_Qcool_DC, 1 - n_eta_DC_frac_abs), n_eta_DC_COP * n_eta_DC_network);
1748
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Qcl_DC_abs = div(mult(v_Qcool_DC, 1 - n_frac_DC_free), n_eta_DC_COP_abs);
1749
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcl_DC_elec", v_Qcl_DC_elec);
1750
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcl_DC_abs", v_Qcl_DC_abs);
1751
1752 // cppcheck-suppress invalidFunctionArg
1753
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Qht_DH_total = div(mult(v_Qht_DH, 1 - n_frac_DH_free), n_eta_DH_sys * n_eta_DH_network);
1754
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Qcl_elec_tot = sum(v_Qcl_sys, v_Qcl_DC_elec);
1755
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Qcl_gas_tot = v_Qcl_DC_abs;
1756
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qht_DH_total", v_Qht_DH_total);
1757
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcl_elec_tot", v_Qcl_elec_tot);
1758
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qcl_gas_tot", v_Qcl_gas_tot);
1759
1760 //Vector v_Qelec_ht,v_Qgas_ht;
1761
1762
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
1 if (heating->energyType() == 1) {
1763 ✗ v_Qelec_ht = v_Qht_sys;
1764 ✗ v_Qgas_ht = v_Qht_DH_total;
1765 } else {
1766
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Qelec_ht = Vector(12);
1767
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Qelec_ht);
1768
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Qgas_ht = sum(v_Qht_sys, v_Qht_DH_total);
1769 }
1770
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qelec_ht", v_Qelec_ht);
1771
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qgas_ht", v_Qgas_ht);
1772
1773 /*
1774 v_Qcl_DC_elec = v_Qcool_DC * (1-n_eta_DC_frac_abs) / (n_eta_DC_COP*n_eta_DC_network); % Energy used for cooling by district electric chillers
1775 v_Qcl_DC_abs = v_Qcool_DC * (1-n_frac_DC_free) / n_eta_DC_COP_abs; %Energy used for cooling by district absorption chillers
1776
1777 v_Qht_DH_total = v_Qht_DH * (1 - n_frac_DH_free) / (n_eta_DH_sys * n_eta_DH_network);
1778 v_Qcl_elec_tot = v_Qcl_sys + v_Qcl_DC_elec; %total electric cooling energy (MJ)
1779 v_Qcl_gas_tot = v_Qcl_DC_abs; % total gas cooliing energy
1780
1781 if In.heat_energy_type==1 %check if fuel type is electric
1782 v_Qelec_ht=v_Qht_sys; % total electric heating energy (MJ)
1783 v_Qgas_ht=v_Qht_DH_total; % total gas heating energy is DH if fuel type is electric
1784 else
1785 v_Qelec_ht = zeros(12,1); % if we get here, fuel was gas to total electric heating energy is 0
1786 v_Qgas_ht=v_Qht_sys+v_Qht_DH_total; % total gas heating energy is building + any DH
1787 end
1788
1789 */
1790 1 }
1791 1 void SimModel::pump(const Vector& v_Qneed_ht, const Vector& v_Qneed_cl, double Qneed_ht_yr, double Qneed_cl_yr, Vector& v_Q_pump_tot) const {
1792
1793 /*
1794 %% Pump Energy
1795
1796 %%% NOTE original GIT spreadsheet had this hardwired
1797 %Q_pumps_yr = 8; % set pump energy density 8 MJ/m2/yr
1798 %
1799 %
1800 % new GIT model following EPA NR 2007 6.9.7.1 and 6.9.7.2
1801 % European Performance Assessment - Non Residential
1802
1803 */
1804 1 double n_E_pumps = 0.25;
1805
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_pumps = mult(megasecondsInMonth, n_E_pumps, 12);
1806
1/1
✓ Branch 1 taken 1 time.
1 double Q_pumps_yr = sum(v_Q_pumps);
1807
1808
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_frac_ht_mode = div(v_Qneed_ht, sum(v_Qneed_ht, v_Qneed_cl));
1809
1/1
✓ Branch 1 taken 1 time.
1 double frac_ht_total = sum(v_frac_ht_mode);
1810 1 double Q_pumps_ht = Q_pumps_yr * heating->pumpControlReduction() * structure->floorArea();
1811
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Q_pumps_ht = div(mult(v_frac_ht_mode, Q_pumps_ht), frac_ht_total);
1812 /*
1813 n_E_pumps = 0.25; % specific power of systems pumps + control systems in W/m2
1814 v_Q_pumps=n_E_pumps*v_Msec_ina_mo; % energy per month for pumps + control if running continuously in MJ/m2/mo
1815
1816 Q_pumps_yr=sum(v_Q_pumps);% total annual energy for pumps+ctrl if running continuously MJ/m2/yr
1817
1818
1819 v_frac_ht_mode = v_Qneed_ht./(v_Qneed_ht+v_Qneed_cl); %fraction of time system is in in heating mode each month
1820 frac_ht_total=sum(v_frac_ht_mode); % total heating pump energy fraction
1821 Q_pumps_ht=Q_pumps_yr*In.pump_heat_ctrl_factor*In.cond_flr_area; % total heating pump energy;
1822 v_Q_pumps_ht = Q_pumps_ht*v_frac_ht_mode/frac_ht_total; % break down total according to fractional operation and monthly fraction
1823
1824 %v_frac_pump_ht = v_Qneed_ht./(v_Qneed_ht+v_Qneed_cl); %heating pump operation fraction for each month.
1825 %v_Q_pump_mo=Q_pumps_yr*In.pump_heat_ctrl_factor*In.cond_flr_area.*v_frac_ht_mode;
1826
1827 */
1828
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_frac_cl_mode = div(v_Qneed_cl, sum(v_Qneed_ht, v_Qneed_cl));
1829
1/1
✓ Branch 1 taken 1 time.
1 double frac_cl_total = sum(v_frac_cl_mode);
1830 1 double Q_pumps_cl = Q_pumps_yr * cooling->pumpControlReduction() * structure->floorArea();
1831
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Q_pumps_cl = div(mult(v_frac_cl_mode, Q_pumps_cl), frac_cl_total);
1832
1833 /*
1834 v_frac_cl_mode = v_Qneed_cl./(v_Qneed_ht+v_Qneed_cl);% fraction of time system is in cooling mode
1835 frac_cl_total=sum(v_frac_cl_mode); % total cooling pump energy fraction
1836 Q_pumps_cl=Q_pumps_yr*In.pump_cool_ctrl_factor*In.cond_flr_area; % total cooling pump energy fraction
1837 v_Q_pumps_cl = Q_pumps_cl*v_frac_cl_mode/frac_cl_total; % break down total into monthly fractional parts
1838
1839 %v_frac_pump_cl = v_Qneed_cl./(v_Qneed_ht+v_Qneed_cl);% cooling pump operation factor
1840
1841 */
1842
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_frac_tot = div(sum(v_Qneed_ht, v_Qneed_cl), Qneed_ht_yr + Qneed_cl_yr);
1843
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
1 if (Q_pumps_ht == 0 || Q_pumps_cl == 0) {
1844 ✗ v_Q_pump_tot = sum(v_Q_pumps_ht, v_Q_pumps_cl);
1845 } else {
1846 1 const double Q_pumps_tot = Q_pumps_ht + Q_pumps_cl;
1847
1/1
✓ Branch 1 taken 1 time.
1 const double frac_total = sum(v_frac_tot);
1848
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 v_Q_pump_tot = div(mult(v_frac_tot, Q_pumps_tot), frac_total);
1849 }
1850 /*
1851 v_frac_tot = (v_Qneed_ht+v_Qneed_cl)/(Qneed_ht_yr+Qneed_cl_yr); % total pump operational factor
1852 frac_total = sum(v_frac_tot);
1853 Q_pumps_tot = Q_pumps_ht + Q_pumps_cl;
1854
1855 if (Q_pumps_ht==0 || Q_pumps_cl==0)
1856 v_Q_pump_tot = v_Q_pumps_ht+v_Q_pumps_cl;
1857 else
1858 v_Q_pump_tot = Q_pumps_tot*v_frac_tot/frac_total;
1859 end
1860
1861 %Q_pump_tot_yr=sum(v_Q_pump_tot);
1862
1863 */
1864 1 }
1865
1866 1 void SimModel::energyGeneration() const {
1867 /*
1868 %% Energy Generation
1869
1870 %%% NOT INCLUDED YET
1871 */
1872 1 }
1873
1874 1 void SimModel::heatedWater(Vector& v_Q_dhw_elec, Vector& v_Q_dhw_gas) const {
1875 1 double n_dhw_tset = 60; // % water temperature set point (C)
1876 1 double n_dhw_tsupply = 20; //% water initial temp (C)
1877 1 double n_CP_h20 = 4.18; //% specific heat of water in MJ/m3/K
1878
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_dhw_solar(12);
1879
1/1
✓ Branch 1 taken 1 time.
1 zero(v_Q_dhw_solar); //Q from solar energy hot water collectors - not included yet
1880 1 double Q_dhw_yr = heating->hotWaterDemand() * (n_dhw_tset - n_dhw_tsupply) * n_CP_h20;
1881
1882 /*%% DHW and Solar Water Heating
1883 %
1884 % Qdhw= ((Qdem;DWH/?sys;DHW) - Qses;DHW)/?gen;DHW
1885 % Source: NEN 2916 12.2
1886
1887 n_dhw_tset = 60; % water temperature set point (C)
1888 n_dhw_tsupply = 20; % water initial temp (C)
1889 n_CP_h20=4.18; % specific heat of water in MJ/m3/K
1890
1891 %solar hot water heating contribution
1892 %D738 =0; % solar collector surface area
1893 v_Q_dhw_solar =zeros(12,1); % Q from solar energy hot water collectors - not included yet
1894
1895
1896 Q_dhw_yr = In.DHW_demand*(n_dhw_tset-n_dhw_tsupply).*n_CP_h20; % total annual energy required for heating DHW MJ/yr
1897
1898 % n_dhw_dist_eff_table=[1 0.8 0.6]; % all taps < 3m from gen = 1, taps> 3m = 0.8, circulation or unknown =0.6
1899 % %eta_dhw_dist = n_dhw_dist_eff_table(In.DHW_dist_sys_type); % set the distribution efficiency from table
1900 %
1901 % eta_dhw_dist = In.DHW_dist_eff; % DHW distribtuion efficiency
1902 % eta_dhw_sys = In.DHW_sys_eff; % DHW system efficiency
1903
1904
1905 */
1906
1/1
✓ Branch 1 taken 1 time.
1 Vector v_MonthlyDemand = mult(daysInMonth, Q_dhw_yr, 12);
1907
1/1
✓ Branch 1 taken 1 time.
1 Vector v_frac_MonthlyDemand_yr = div(v_MonthlyDemand, daysInYear);
1908
1/1
✓ Branch 3 taken 1 time.
1 Vector v_Qe_demand = div(v_frac_MonthlyDemand_yr, heating->hotWaterDistributionEfficiency());
1909
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_dhw_demand = div(v_Qe_demand, kWh2MJ);
1910
3/3
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
1 Vector v_Q_dhw_need = maximum(div(dif(v_Q_dhw_demand, v_Q_dhw_solar), heating->hotWaterSystemEfficiency()), 0);
1911
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector Z(v_Q_dhw_need.size());
1912
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_MonthlyDemand", v_MonthlyDemand);
1913
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_frac_MonthlyDemand_yr", v_frac_MonthlyDemand_yr);
1914
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Qe_demand", v_Qe_demand);
1915
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_dhw_demand", v_Q_dhw_demand);
1916
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_dhw_need", v_Q_dhw_need);
1917
1/1
✓ Branch 1 taken 1 time.
1 zero(Z);
1918
1/1
✓ Branch 1 taken 1 time.
1 printVector("Z", Z);
1919
1920
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 if (heating->hotWaterEnergyType() == 1) {
1921
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Q_dhw_elec = v_Q_dhw_need;
1922
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 v_Q_dhw_gas = Z;
1923 } else {
1924 ✗ v_Q_dhw_gas = v_Q_dhw_need;
1925 ✗ v_Q_dhw_elec = Z;
1926 }
1927
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_dhw_gas", v_Q_dhw_gas);
1928
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_dhw_elec", v_Q_dhw_elec);
1929
1930 /*
1931 v_Q_dhw_demand = Q_dhw_yr.*v_days_ina_mo./days_ina_year./In.DHW_dist_eff/kWh2MJ; % monthly DHW energy demand including distribution inefficiency
1932 v_Q_dhw_need = max((v_Q_dhw_demand-v_Q_dhw_solar)./In.DHW_sys_eff,0); % total monthly supply need is (demand - solar)/system efficiency
1933
1934 Z=zeros(size(v_Q_dhw_need));
1935 if(In.DHW_energy_type)==1
1936 v_Q_dhw_elec = v_Q_dhw_need;
1937 v_Q_dhw_gas = Z;
1938 else
1939 v_Q_dhw_gas = v_Q_dhw_need;
1940 v_Q_dhw_elec = Z;
1941 end
1942 */
1943 1 }
1944
1945 1 ISOResults SimModel::simulate() const {
1946
1/1
✓ Branch 1 taken 1 time.
1 Vector weekdayOccupiedMegaseconds(12);
1947
1/1
✓ Branch 1 taken 1 time.
1 Vector weekdayUnoccupiedMegaseconds(12);
1948
1/1
✓ Branch 1 taken 1 time.
1 Vector weekendOccupiedMegaseconds(12);
1949
1/1
✓ Branch 1 taken 1 time.
1 Vector weekendUnoccupiedMegaseconds(12);
1950
1/1
✓ Branch 1 taken 1 time.
1 Vector clockHourOccupied(24);
1951
1/1
✓ Branch 1 taken 1 time.
1 Vector clockHourUnoccupied(24);
1952 1 double frac_hrs_wk_day = 0;
1953 1 double hoursUnoccupiedPerDay = 0;
1954 1 double hoursOccupiedPerDay = 0;
1955 1 double frac_hrs_wk_nt = 0;
1956 1 double frac_hrs_wke_tot = 0;
1957
1958 //Solor Radiation Breakdown Results
1959
1/1
✓ Branch 1 taken 1 time.
1 Vector v_hrs_sun_down_mo(12);
1960
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Tdbt_nt;
1961
1/1
✓ Branch 1 taken 1 time.
1 Vector frac_Pgh_wk_nt;
1962
1/1
✓ Branch 1 taken 1 time.
1 Vector frac_Pgh_wke_day;
1963
1/1
✓ Branch 1 taken 1 time.
1 Vector frac_Pgh_wke_nt;
1964 //Envelop Calculations Results
1965
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_A;
1966
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_emiss;
1967
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_alpha_sc;
1968
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_U;
1969
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_A;
1970
1971
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_A_sol;
1972
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_hr;
1973
1/1
✓ Branch 1 taken 1 time.
1 Vector v_wall_R_sc;
1974
1/1
✓ Branch 1 taken 1 time.
1 Vector v_win_A_sol;
1975
1976 double Q_illum_occ;
1977 double Q_illum_unocc;
1978 double Q_illum_tot_yr;
1979
1980 double phi_int_avg;
1981 double phi_plug_avg;
1982 double phi_illum_avg;
1983
1984 double phi_int_wk_nt;
1985 double phi_int_wke_day;
1986 double phi_int_wke_nt;
1987
1/1
✓ Branch 1 taken 1 time.
1 Vector v_E_sol;
1988
1989 double H_tr;
1990
1/1
✓ Branch 1 taken 1 time.
1 Vector v_P_tot_wke_day;
1991
1/1
✓ Branch 1 taken 1 time.
1 Vector v_P_tot_wk_nt;
1992
1/1
✓ Branch 1 taken 1 time.
1 Vector v_P_tot_wke_nt;
1993
1994
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Th_avg(12);
1995
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Tc_avg(12);
1996
1997 double phi_I_tot;
1998 double tau;
1999
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Hve_ht;
2000
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Hve_cl;
2001
2002 double Qneed_ht_yr;
2003 double Qneed_cl_yr;
2004
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qneed_ht;
2005
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qneed_cl;
2006
2007
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qelec_ht;
2008
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qcl_elec_tot;
2009
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_illum_tot;
2010
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_illum_ext_tot;
2011
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qfan_tot;
2012
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_pump_tot;
2013
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_dhw_elec;
2014
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qgas_ht;
2015
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Qcl_gas_tot;
2016
1/1
✓ Branch 1 taken 1 time.
1 Vector v_Q_dhw_gas;
2017
2018 1 frac_hrs_wk_day = hoursUnoccupiedPerDay = hoursOccupiedPerDay = frac_hrs_wk_nt = frac_hrs_wke_tot = 1;
2019
2020 //openstudio::isomodel::loadDefaults(simModel);
2021
2022 #ifdef DEBUG_ISO_MODEL_SIMULATION
2023 LOG(Trace, "scheduleAndOccupancy: ");
2024 #endif
2025
2026
1/1
✓ Branch 1 taken 1 time.
1 scheduleAndOccupancy(weekdayOccupiedMegaseconds, weekdayUnoccupiedMegaseconds, weekendOccupiedMegaseconds, weekendUnoccupiedMegaseconds,
2027 clockHourOccupied, clockHourUnoccupied, frac_hrs_wk_day, hoursUnoccupiedPerDay, hoursOccupiedPerDay, frac_hrs_wk_nt,
2028 frac_hrs_wke_tot);
2029
2030 #ifdef DEBUG_ISO_MODEL_SIMULATION
2031 LOG(Trace, "frac_hrs_wk_day: " << frac_hrs_wk_day);
2032 LOG(Trace, "hoursUnoccupiedPerDay: " << hoursUnoccupiedPerDay);
2033 LOG(Trace, "hoursOccupiedPerDay: " << hoursOccupiedPerDay);
2034 LOG(Trace, "frac_hrs_wk_nt: " << frac_hrs_wk_nt);
2035 LOG(Trace, "frac_hrs_wke_tot: " << frac_hrs_wke_tot);
2036
2037 printVector("weekdayOccupiedMegaseconds", weekdayOccupiedMegaseconds);
2038 printVector("weekdayUnoccupiedMegaseconds", weekdayUnoccupiedMegaseconds);
2039 printVector("weekendOccupiedMegaseconds", weekendOccupiedMegaseconds);
2040 printVector("weekendUnoccupiedMegaseconds", weekendUnoccupiedMegaseconds);
2041 printVector("clockHourOccupied", clockHourOccupied);
2042 printVector("clockHourUnoccupied", clockHourUnoccupied);
2043
2044 LOG(Trace, "solarRadiationBreakdown: ");
2045 #endif
2046
2047
1/1
✓ Branch 1 taken 1 time.
1 solarRadiationBreakdown(weekdayOccupiedMegaseconds, weekdayUnoccupiedMegaseconds, weekendOccupiedMegaseconds, weekendUnoccupiedMegaseconds,
2048 clockHourOccupied, clockHourUnoccupied, v_hrs_sun_down_mo, frac_Pgh_wk_nt, frac_Pgh_wke_day, frac_Pgh_wke_nt, v_Tdbt_nt);
2049
2050 #ifdef DEBUG_ISO_MODEL_SIMULATION
2051 printVector("v_hrs_sun_down_mo", v_hrs_sun_down_mo);
2052 printVector("frac_Pgh_wk_nt", frac_Pgh_wk_nt);
2053 printVector("frac_Pgh_wke_day", frac_Pgh_wke_day);
2054 printVector("frac_Pgh_wke_nt", frac_Pgh_wke_nt);
2055 printVector("v_Tdbt_nt", v_Tdbt_nt);
2056
2057 LOG(Trace, "lightingEnergyUse: ");
2058 #endif
2059
2060
1/1
✓ Branch 1 taken 1 time.
1 lightingEnergyUse(v_hrs_sun_down_mo, Q_illum_occ, Q_illum_unocc, Q_illum_tot_yr, v_Q_illum_tot, v_Q_illum_ext_tot);
2061
2062 #ifdef DEBUG_ISO_MODEL_SIMULATION
2063 LOG(Trace, "Q_illum_occ: " << Q_illum_occ);
2064 LOG(Trace, "Q_illum_unocc: " << Q_illum_unocc);
2065 LOG(Trace, "Q_illum_unocc: " << Q_illum_unocc);
2066 printVector("v_Q_illum_tot", v_Q_illum_tot);
2067 printVector("v_Q_illum_ext_tot", v_Q_illum_ext_tot);
2068
2069 LOG(Trace, "envelopCalculations: "); /*
2070 v_wall_A = structure->wallArea();
2071 v_win_A = structure->windowArea();
2072 v_wall_U = structure->wallUniform();
2073 Vector v_win_U = structure->windowUniform();*/
2074 printVector("structure->wallArea()", structure->wallArea());
2075 printVector("structure->windowArea()", structure->windowArea());
2076 printVector("structure->wallUniform()", structure->wallUniform());
2077 printVector("structure->windowUniform()", structure->windowUniform());
2078 #endif
2079
2080
1/1
✓ Branch 1 taken 1 time.
1 envelopCalculations(v_win_A, v_wall_emiss, v_wall_alpha_sc, v_wall_U, v_wall_A, H_tr);
2081
2082 #ifdef DEBUG_ISO_MODEL_SIMULATION
2083 LOG(Trace, "H_tr: " << H_tr);
2084 printVector("v_win_A", v_win_A);
2085 printVector("v_wall_emiss", v_wall_emiss);
2086 printVector("v_wall_alpha_sc", v_wall_alpha_sc);
2087 printVector("v_wall_U", v_wall_U);
2088 printVector("v_wall_A", v_wall_A);
2089
2090 LOG(Trace, "windowSolarGain: ");
2091 #endif
2092
2093
1/1
✓ Branch 1 taken 1 time.
1 windowSolarGain(v_win_A, v_wall_emiss, v_wall_alpha_sc, v_wall_U, v_wall_A, v_wall_A_sol, v_win_hr, v_wall_R_sc, v_win_A_sol);
2094
2095 #ifdef DEBUG_ISO_MODEL_SIMULATION
2096 printVector("v_wall_A_sol", v_wall_A_sol);
2097 printVector("v_win_hr", v_win_hr);
2098 printVector("v_wall_R_sc", v_wall_R_sc);
2099 printVector("v_win_A_sol", v_win_A_sol);
2100
2101 LOG(Trace, "solarHeatGain: ");
2102 #endif
2103
2104
1/1
✓ Branch 1 taken 1 time.
1 solarHeatGain(v_win_A_sol, v_wall_R_sc, v_wall_U, v_wall_A, v_win_hr, v_wall_A_sol, v_E_sol);
2105
2106 #ifdef DEBUG_ISO_MODEL_SIMULATION
2107 printVector("v_E_sol", v_E_sol);
2108
2109 LOG(Trace, "heatGainsAndLosses: ");
2110 #endif
2111
2112
1/1
✓ Branch 1 taken 1 time.
1 heatGainsAndLosses(frac_hrs_wk_day, Q_illum_occ, Q_illum_unocc, Q_illum_tot_yr, phi_int_avg, phi_plug_avg, phi_illum_avg, phi_int_wke_nt,
2113 phi_int_wke_day, phi_int_wk_nt);
2114
2115 #ifdef DEBUG_ISO_MODEL_SIMULATION
2116 LOG(Trace, "phi_int_avg: " << phi_int_avg);
2117 LOG(Trace, "phi_plug_avg: " << phi_plug_avg);
2118 LOG(Trace, "phi_illum_avg: " << phi_illum_avg);
2119 LOG(Trace, "phi_int_wke_nt: " << phi_int_wke_nt);
2120 LOG(Trace, "phi_int_wke_day: " << phi_int_wke_day);
2121 LOG(Trace, "phi_int_wk_nt: " << phi_int_wk_nt);
2122
2123 LOG(Trace, "internalHeatGain: ");
2124 #endif
2125
2126
1/1
✓ Branch 1 taken 1 time.
1 internalHeatGain(phi_int_avg, phi_plug_avg, phi_illum_avg, phi_I_tot);
2127
2128 #ifdef DEBUG_ISO_MODEL_SIMULATION
2129 LOG(Trace, "phi_I_tot: " << phi_I_tot);
2130
2131 LOG(Trace, "unoccupiedHeatGain: ");
2132 #endif
2133
2134
1/1
✓ Branch 1 taken 1 time.
1 unoccupiedHeatGain(phi_int_wk_nt, phi_int_wke_day, phi_int_wke_nt, weekdayUnoccupiedMegaseconds, weekendOccupiedMegaseconds,
2135 weekendUnoccupiedMegaseconds, frac_Pgh_wk_nt, frac_Pgh_wke_day, frac_Pgh_wke_nt, v_E_sol, v_P_tot_wke_day, v_P_tot_wk_nt,
2136 v_P_tot_wke_nt);
2137 #ifdef DEBUG_ISO_MODEL_SIMULATION
2138 printVector("v_P_tot_wke_day", v_P_tot_wke_day);
2139 printVector("v_P_tot_wk_nt", v_P_tot_wk_nt);
2140 printVector("v_P_tot_wke_nt", v_P_tot_wke_nt);
2141
2142 LOG(Trace, "interiorTemp: ");
2143 #endif
2144
2145
1/1
✓ Branch 1 taken 1 time.
1 interiorTemp(v_wall_A, v_P_tot_wke_day, v_P_tot_wk_nt, v_P_tot_wke_nt, v_Tdbt_nt, H_tr, hoursUnoccupiedPerDay, hoursOccupiedPerDay,
2146 frac_hrs_wk_day, frac_hrs_wk_nt, frac_hrs_wke_tot, v_Th_avg, v_Tc_avg, tau);
2147
2148 #ifdef DEBUG_ISO_MODEL_SIMULATION
2149 LOG(Trace, "tau: " << tau);
2150 printVector("v_Th_avg", v_Th_avg);
2151 printVector("v_Tc_avg", v_Tc_avg);
2152
2153 LOG(Trace, "ventilationCalc: ");
2154 #endif
2155
2156
1/1
✓ Branch 1 taken 1 time.
1 ventilationCalc(v_Th_avg, v_Tc_avg, frac_hrs_wk_day, v_Hve_ht, v_Hve_cl);
2157
2158 #ifdef DEBUG_ISO_MODEL_SIMULATION
2159 printVector("v_Hve_ht", v_Hve_ht);
2160 printVector("v_Hve_cl", v_Hve_cl);
2161
2162 LOG(Trace, "heatingAndCooling: ");
2163 #endif
2164
2165
1/1
✓ Branch 1 taken 1 time.
1 heatingAndCooling(v_E_sol, v_Th_avg, v_Hve_ht, v_Tc_avg, v_Hve_cl, tau, H_tr, phi_I_tot, frac_hrs_wk_day, v_Qfan_tot, v_Qneed_ht, v_Qneed_cl,
2166 Qneed_ht_yr, Qneed_cl_yr);
2167
2168 #ifdef DEBUG_ISO_MODEL_SIMULATION
2169 LOG(Trace, "Qneed_ht_yr: " << Qneed_ht_yr);
2170 LOG(Trace, "Qneed_cl_yr: " << Qneed_cl_yr);
2171 printVector("v_Qfan_tot", v_Qfan_tot);
2172
2173 LOG(Trace, "hvac: ");
2174 #endif
2175
2176
1/1
✓ Branch 1 taken 1 time.
1 hvac(v_Qneed_ht, v_Qneed_cl, Qneed_ht_yr, Qneed_cl_yr, v_Qelec_ht, v_Qgas_ht, v_Qcl_elec_tot, v_Qcl_gas_tot);
2177
2178 #ifdef DEBUG_ISO_MODEL_SIMULATION
2179 printVector("v_Qelec_ht", v_Qelec_ht);
2180 printVector("v_Qgas_ht", v_Qgas_ht);
2181 printVector("v_Qcl_elec_tot", v_Qcl_elec_tot);
2182 printVector("v_Qcl_gas_tot", v_Qcl_gas_tot);
2183
2184 LOG(Trace, "pump: ");
2185 #endif
2186
2187
1/1
✓ Branch 1 taken 1 time.
1 pump(v_Qneed_ht, v_Qneed_cl, Qneed_ht_yr, Qneed_cl_yr, v_Q_pump_tot);
2188
2189 #ifdef DEBUG_ISO_MODEL_SIMULATION
2190 printVector("v_Q_pump_tot", v_Q_pump_tot);
2191
2192 LOG(Trace, "energyGeneration: ");
2193 #endif
2194
2195
1/1
✓ Branch 1 taken 1 time.
1 energyGeneration();
2196
2197 #ifdef DEBUG_ISO_MODEL_SIMULATION
2198 LOG(Trace, "heatedWater: ");
2199 #endif
2200
2201
1/1
✓ Branch 1 taken 1 time.
1 heatedWater(v_Q_dhw_elec, v_Q_dhw_gas);
2202
2203 #ifdef DEBUG_ISO_MODEL_SIMULATION
2204 printVector("v_Q_dhw_elec", v_Q_dhw_elec);
2205 printVector("v_Q_dhw_gas", v_Q_dhw_gas);
2206 #endif
2207
2208 return outputGeneration(v_Qelec_ht, v_Qcl_elec_tot, v_Q_illum_tot, v_Q_illum_ext_tot, v_Qfan_tot, v_Q_pump_tot, v_Q_dhw_elec, v_Qgas_ht,
2209
1/1
✓ Branch 1 taken 1 time.
2 v_Qcl_gas_tot, v_Q_dhw_gas, frac_hrs_wk_day);
2210 1 }
2211
2212 1 ISOResults SimModel::outputGeneration(const Vector& v_Qelec_ht, const Vector& v_Qcl_elec_tot, const Vector& v_Q_illum_tot,
2213 const Vector& v_Q_illum_ext_tot, const Vector& v_Qfan_tot, const Vector& v_Q_pump_tot,
2214 const Vector& v_Q_dhw_elec, const Vector& v_Qgas_ht, const Vector& v_Qcl_gas_tot, const Vector& v_Q_dhw_gas,
2215 double frac_hrs_wk_day) const {
2216
3/7
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
26 EndUses results[12];
2217 1 ISOResults allResults;
2218
2219 double E_plug_elec =
2220 1 building->electricApplianceHeatGainOccupied() * frac_hrs_wk_day + building->electricApplianceHeatGainUnoccupied() * (1.0 - frac_hrs_wk_day);
2221 double E_plug_gas =
2222 1 building->gasApplianceHeatGainOccupied() * frac_hrs_wk_day + building->gasApplianceHeatGainUnoccupied() * (1.0 - frac_hrs_wk_day);
2223
2224
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Q_plug_elec = div(mult(hoursInMonth, E_plug_elec, 12), 1000.0);
2225
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Vector v_Q_plug_gas = div(mult(hoursInMonth, E_plug_gas, 12), 1000.0);
2226
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_plug_elec", v_Q_plug_elec);
2227
1/1
✓ Branch 1 taken 1 time.
1 printVector("v_Q_plug_gas", v_Q_plug_gas);
2228
2229 /*
2230 %% Plugload
2231
2232 E_plug_elec =( In.elec_plug_dens_occ*frac_hrs_wk_day + In.elec_plug_dens_unocc*(1-frac_hrs_wk_day)); % average electric plugloads in W/m2
2233 E_plug_gas = (In.gas_plug_dens_occ*frac_hrs_wk_day + In.gas_plug_dens_unocc*(1-frac_hrs_wk_day)); % averaged gas plugloads in W/m2
2234
2235 v_Q_plug_elec = E_plug_elec*v_hrs_ina_mo/1000; % Electric plugload kWh/m2
2236 v_Q_plug_gas = E_plug_gas*v_hrs_ina_mo/1000; % gas plugload kWh/m2
2237
2238 */
2239
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector Eelec_ht = div(div(v_Qelec_ht, structure->floorArea()), kWh2MJ); //% Total monthly electric usage for heating
2240
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector Eelec_cl = div(div(v_Qcl_elec_tot, structure->floorArea()), kWh2MJ); //% Total monthly electric usage for cooling
2241
1/1
✓ Branch 3 taken 1 time.
1 Vector Eelec_int_lt = div(v_Q_illum_tot, structure->floorArea()); //% Total monthly electric usage density for interior lighting
2242
1/1
✓ Branch 3 taken 1 time.
1 Vector Eelec_ext_lt = div(v_Q_illum_ext_tot, structure->floorArea()); //% Total monthly electric usage for exterior lights
2243
1/1
✓ Branch 1 taken 1 time.
1 Vector Eelec_fan = v_Qfan_tot; //%Total monthly elec usage for fans
2244
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector Eelec_pump = div(div(v_Q_pump_tot, structure->floorArea()), kWh2MJ); //% Total monthly elec usage for pumps
2245
1/1
✓ Branch 1 taken 1 time.
1 Vector Eelec_plug = v_Q_plug_elec; //% Total monthly elec usage for elec plugloads
2246
1/1
✓ Branch 3 taken 1 time.
1 Vector Eelec_dhw = div(v_Q_dhw_elec, structure->floorArea());
2247 /*
2248 %% Generating output table
2249
2250 Eelec_ht = v_Qelec_ht./In.cond_flr_area./kWh2MJ; % Total monthly electric usage for heating
2251 Eelec_cl = v_Qcl_elec_tot./In.cond_flr_area./kWh2MJ; % Total monthly electric usage for cooling
2252 Eelec_int_lt = v_Q_illum_tot./In.cond_flr_area; % Total monthly electric usage density for interior lighting
2253 Eelec_ext_lt = v_Q_illum_ext_tot./In.cond_flr_area; % Total monthly electric usage for exterior lights
2254 Eelec_fan = v_Qfan_tot; %Total monthly elec usage for fans
2255 Eelec_pump = v_Q_pump_tot./In.cond_flr_area./kWh2MJ; % Total monthly elec usage for pumps
2256 Eelec_plug = v_Q_plug_elec; % Total monthly elec usage for elec plugloads
2257 Eelec_dhw = v_Q_dhw_elec/In.cond_flr_area;
2258
2259 */
2260
2261
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector Egas_ht = div(div(v_Qgas_ht, structure->floorArea()), kWh2MJ); //% total monthly gas usage for heating
2262
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 Vector Egas_cl = div(div(v_Qcl_gas_tot, structure->floorArea()), kWh2MJ); //% total monthly gas usage for cooling
2263
1/1
✓ Branch 1 taken 1 time.
1 Vector Egas_plug = v_Q_plug_gas; //% total monthly gas plugloads
2264
1/1
✓ Branch 3 taken 1 time.
1 Vector Egas_dhw = div(v_Q_dhw_gas, structure->floorArea()); //% total monthly dhw gas plugloads
2265
2266
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 time.
13 for (int i = 0; i < 12; i++) {
2267
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_ht[i], EndUseFuelType::Electricity, EndUseCategoryType::Heating);
2268
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_cl[i], EndUseFuelType::Electricity, EndUseCategoryType::Cooling);
2269
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_int_lt[i], EndUseFuelType::Electricity, EndUseCategoryType::InteriorLights);
2270
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_ext_lt[i], EndUseFuelType::Electricity, EndUseCategoryType::ExteriorLights);
2271
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_fan[i], EndUseFuelType::Electricity, EndUseCategoryType::Fans);
2272
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_pump[i], EndUseFuelType::Electricity, EndUseCategoryType::Pumps);
2273
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_plug[i], EndUseFuelType::Electricity, EndUseCategoryType::InteriorEquipment);
2274
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Eelec_dhw[i], EndUseFuelType::Electricity, EndUseCategoryType::WaterSystems);
2275
2276
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Egas_ht[i], EndUseFuelType::Gas, EndUseCategoryType::Heating);
2277
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Egas_cl[i], EndUseFuelType::Gas, EndUseCategoryType::Cooling);
2278
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Egas_plug[i], EndUseFuelType::Gas, EndUseCategoryType::InteriorEquipment);
2279
5/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
24 results[i].addEndUse(Egas_dhw[i], EndUseFuelType::Gas, EndUseCategoryType::WaterSystems);
2280
1/1
✓ Branch 1 taken 12 times.
12 allResults.monthlyResults.push_back(results[i]);
2281 }
2282
2283 2 return allResults;
2284
2285 // Note JM 2019-01-03: commented out any code after the existing, above return statement
2286
2287 /*
2288 %Etotal_elec=Eelec_ht + Eelec_cl+Eelec_int_lt+Eelec_ext_lt+Eelec_fan+Eelec_pump+Eelec_plug;
2289
2290 Egas_ht = v_Qgas_ht./In.cond_flr_area./kWh2MJ; % total monthly gas usage for heating
2291 Egas_cl = v_Qcl_gas_tot./In.cond_flr_area./kWh2MJ; % total monthly gas usage for cooling
2292 Egas_plug = v_Q_plug_gas; % total monthly gas plugloads
2293 Egas_dhw = v_Q_dhw_gas./In.cond_flr_area; % total monthly dhw gas plugloads
2294
2295 Z=zeros(size(Eelec_ht));
2296
2297 */
2298 //Vector Etot_ht = sum(Eelec_ht, Egas_ht);
2299 //Vector Etot_cl = sum(Eelec_cl, Egas_cl);
2300 //Vector Etot_int_lt = Eelec_int_lt; //% Total monthly electric usage density for interior lighting
2301 //Vector Etot_ext_lt = Eelec_ext_lt; //% Total monthly electric usage for exterior lights
2302 //Vector Etot_fan = Eelec_fan; //%Total monthly elec usage for fans
2303 //Vector Etot_pump = Eelec_pump; //% Total monthly elec usage for pumps
2304 //Vector Etot_plug = sum(v_Q_plug_elec, v_Q_plug_gas); //% Total monthly elec usage for elec plugloads
2305 //Vector Etot_dhw = sum(v_Q_dhw_elec, v_Q_plug_elec);
2306
2307 /*
2308 Ebldg.elec=[Eelec_ht,Eelec_cl,Eelec_int_lt,Eelec_ext_lt,Eelec_fan,Eelec_pump,Eelec_plug,Eelec_dhw];
2309 Ebldg.gas=[Egas_ht,Egas_cl,Z,Z,Z,Z,Egas_plug,Egas_dhw];
2310 Ebldg.total=Ebldg.elec+Ebldg.gas;
2311 Ebldg.cols={'Heat','Cool','Int Lt','Ext Lt','Fans','Pump','Plug','DHW'};
2312 Ebldg.rows=['Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'];
2313
2314
2315 */
2316 //double yrSum = 0;
2317 //Vector monthly(Etot_ht.size());
2318 //for(size_t i = 0;i<Etot_ht.size();i++)
2319 //{
2320 //monthly[i] = Etot_ht[i] + Etot_cl[i] + Etot_int_lt[i] + Etot_ext_lt[i] +
2321 //Etot_fan[i] + Etot_pump[i] + Etot_plug[i] + Etot_dhw[i];
2322 //yrSum += monthly[i];
2323 //}
2324
2325 /*
2326 % Find the totals for each month by summing across the columns
2327 Ebldg.mon=sum(Ebldg.total,2); % sum normally works down columns but by putting in the ,2 we sum across rows instead
2328 Ebldg.yr=sum(Ebldg.mon);
2329 */
2330 14 }
2331 } // namespace isomodel
2332 } // namespace openstudio
2333