GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.5% 129 / 0 / 194
Functions: 76.7% 46 / 0 / 60
Branches: 51.5% 101 / 0 / 196

src/model/RunPeriod.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 "RunPeriod.hpp"
7 #include "RunPeriod_Impl.hpp"
8 #include "Model.hpp"
9
10 #include "SimulationControl.hpp"
11 #include "SimulationControl_Impl.hpp"
12 #include "SkyTemperature.hpp"
13 #include "SkyTemperature_Impl.hpp"
14 #include "Model_Impl.hpp"
15
16 #include <utilities/idd/OS_RunPeriod_FieldEnums.hxx>
17 #include <utilities/idd/IddEnums.hxx>
18
19 #include "../utilities/core/Assert.hpp"
20
21 #include <boost/algorithm/string.hpp>
22
23 namespace openstudio {
24 namespace model {
25
26 namespace detail {
27
28 1174 RunPeriod_Impl::RunPeriod_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : ParentObject_Impl(idfObject, model, keepHandle) {
29
4/6
✓ Branch 1 taken 1174 times.
✓ Branch 4 taken 1174 times.
✓ Branch 7 taken 1174 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1174 times.
✗ Branch 13 not taken.
1174 OS_ASSERT(idfObject.iddObject().type() == RunPeriod::iddObjectType());
30 1174 }
31
32 58 RunPeriod_Impl::RunPeriod_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
33 58 : ParentObject_Impl(other, model, keepHandle) {
34
4/6
✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58 times.
✗ Branch 13 not taken.
58 OS_ASSERT(other.iddObject().type() == RunPeriod::iddObjectType());
35 58 }
36
37 127 RunPeriod_Impl::RunPeriod_Impl(const RunPeriod_Impl& other, Model_Impl* model, bool keepHandle) : ParentObject_Impl(other, model, keepHandle) {}
38
39 8 IddObjectType RunPeriod_Impl::iddObjectType() const {
40 8 return RunPeriod::iddObjectType();
41 }
42
43 1741 int RunPeriod_Impl::getBeginMonth() const {
44 //seems safe since this can't be autocalculate
45
2/2
✓ Branch 1 taken 1741 times.
✓ Branch 4 taken 1741 times.
1741 return getInt(OS_RunPeriodFields::BeginMonth, true).get();
46 }
47
48 1741 int RunPeriod_Impl::getBeginDayOfMonth() const {
49
2/2
✓ Branch 1 taken 1741 times.
✓ Branch 4 taken 1741 times.
1741 return getInt(OS_RunPeriodFields::BeginDayofMonth, true).get();
50 }
51
52 1741 int RunPeriod_Impl::getEndMonth() const {
53
2/2
✓ Branch 1 taken 1741 times.
✓ Branch 4 taken 1741 times.
1741 return getInt(OS_RunPeriodFields::EndMonth, true).get();
54 }
55
56 1741 int RunPeriod_Impl::getEndDayOfMonth() const {
57
2/2
✓ Branch 1 taken 1741 times.
✓ Branch 4 taken 1741 times.
1741 return getInt(OS_RunPeriodFields::EndDayofMonth, true).get();
58 }
59
60 ✗ bool RunPeriod_Impl::getUseWeatherFileHolidays() const {
61 ✗ std::string temp = getString(OS_RunPeriodFields::UseWeatherFileHolidaysandSpecialDays, true).get();
62 ✗ boost::to_lower(temp);
63 ✗ if (temp == "no") {
64 ✗ return false;
65 }
66 ✗ return true;
67 ✗ }
68
69 ✗ bool RunPeriod_Impl::getUseWeatherFileDaylightSavings() const {
70 ✗ std::string temp = getString(OS_RunPeriodFields::UseWeatherFileDaylightSavingPeriod, true).get();
71 ✗ boost::to_lower(temp);
72 ✗ if (temp == "no") {
73 ✗ return false;
74 }
75 ✗ return true;
76 ✗ }
77
78 870 bool RunPeriod_Impl::getApplyWeekendHolidayRule() const {
79
3/3
✓ Branch 1 taken 870 times.
✓ Branch 4 taken 870 times.
✓ Branch 7 taken 870 times.
870 std::string temp = getString(OS_RunPeriodFields::ApplyWeekendHolidayRule, true).get();
80
1/1
✓ Branch 2 taken 870 times.
870 boost::to_lower(temp);
81
2/3
✓ Branch 1 taken 870 times.
✓ Branch 3 taken 870 times.
✗ Branch 4 not taken.
870 if (temp == "no") {
82 870 return false;
83 }
84 ✗ return true;
85 870 }
86
87 870 bool RunPeriod_Impl::getUseWeatherFileRainInd() const {
88
3/3
✓ Branch 1 taken 870 times.
✓ Branch 4 taken 870 times.
✓ Branch 7 taken 870 times.
870 std::string temp = getString(OS_RunPeriodFields::UseWeatherFileRainIndicators, true).get();
89
1/1
✓ Branch 2 taken 870 times.
870 boost::to_lower(temp);
90
3/3
✓ Branch 1 taken 870 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 869 times.
870 if (temp == "no") {
91 1 return false;
92 }
93 869 return true;
94 870 }
95
96 870 bool RunPeriod_Impl::getUseWeatherFileSnowInd() const {
97
3/3
✓ Branch 1 taken 870 times.
✓ Branch 4 taken 870 times.
✓ Branch 7 taken 870 times.
870 std::string temp = getString(OS_RunPeriodFields::UseWeatherFileSnowIndicators, true).get();
98
1/1
✓ Branch 2 taken 870 times.
870 boost::to_lower(temp);
99
3/3
✓ Branch 1 taken 870 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 869 times.
870 if (temp == "no") {
100 1 return false;
101 }
102 869 return true;
103 870 }
104
105 870 int RunPeriod_Impl::getNumTimePeriodRepeats() const {
106
2/2
✓ Branch 1 taken 870 times.
✓ Branch 4 taken 870 times.
870 return getInt(OS_RunPeriodFields::NumberofTimesRunperiodtobeRepeated, true).get();
107 }
108
109 1327 bool RunPeriod_Impl::setBeginMonth(int month) {
110 1327 return setInt(OS_RunPeriodFields::BeginMonth, month);
111 ;
112 }
113
114 1327 bool RunPeriod_Impl::setBeginDayOfMonth(int day) {
115 1327 return setInt(OS_RunPeriodFields::BeginDayofMonth, day);
116 ;
117 }
118
119 1327 bool RunPeriod_Impl::setEndMonth(int month) {
120 1327 return setInt(OS_RunPeriodFields::EndMonth, month);
121 ;
122 }
123
124 1327 bool RunPeriod_Impl::setEndDayOfMonth(int day) {
125 1327 return setInt(OS_RunPeriodFields::EndDayofMonth, day);
126 ;
127 }
128
129 208 bool RunPeriod_Impl::setUseWeatherFileHolidays(bool use) {
130
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 205 times.
208 if (use) {
131
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
9 return setString(OS_RunPeriodFields::UseWeatherFileHolidaysandSpecialDays, "Yes");
132 }
133
2/2
✓ Branch 1 taken 205 times.
✓ Branch 4 taken 205 times.
615 return setString(OS_RunPeriodFields::UseWeatherFileHolidaysandSpecialDays, "No");
134 }
135
136 208 bool RunPeriod_Impl::setUseWeatherFileDaylightSavings(bool use) {
137
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 205 times.
208 if (use) {
138
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
9 return setString(OS_RunPeriodFields::UseWeatherFileDaylightSavingPeriod, "Yes");
139 }
140
2/2
✓ Branch 1 taken 205 times.
✓ Branch 4 taken 205 times.
615 return setString(OS_RunPeriodFields::UseWeatherFileDaylightSavingPeriod, "No");
141 }
142
143 208 bool RunPeriod_Impl::setApplyWeekendHolidayRule(bool apply) {
144
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 207 times.
208 if (apply) {
145
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 return setString(OS_RunPeriodFields::ApplyWeekendHolidayRule, "Yes");
146 }
147
2/2
✓ Branch 1 taken 207 times.
✓ Branch 4 taken 207 times.
621 return setString(OS_RunPeriodFields::ApplyWeekendHolidayRule, "No");
148 }
149
150 207 bool RunPeriod_Impl::setUseWeatherFileRainInd(bool rainInd) {
151
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 1 time.
207 if (rainInd) {
152
2/2
✓ Branch 1 taken 206 times.
✓ Branch 4 taken 206 times.
618 return setString(OS_RunPeriodFields::UseWeatherFileRainIndicators, "Yes");
153 }
154
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 return setString(OS_RunPeriodFields::UseWeatherFileRainIndicators, "No");
155 }
156
157 207 bool RunPeriod_Impl::setUseWeatherFileSnowInd(bool snowInd) {
158
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 1 time.
207 if (snowInd) {
159
2/2
✓ Branch 1 taken 206 times.
✓ Branch 4 taken 206 times.
618 return setString(OS_RunPeriodFields::UseWeatherFileSnowIndicators, "Yes");
160 }
161
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 return setString(OS_RunPeriodFields::UseWeatherFileSnowIndicators, "No");
162 }
163
164 199 bool RunPeriod_Impl::setNumTimePeriodRepeats(int numRepeats) {
165 199 return setInt(OS_RunPeriodFields::NumberofTimesRunperiodtobeRepeated, numRepeats);
166 ;
167 }
168
169 ✗ void RunPeriod_Impl::ensureNoLeapDays() {
170 ✗ boost::optional<int> month;
171 ✗ boost::optional<int> day;
172
173 ✗ month = getInt(OS_RunPeriodFields::BeginMonth);
174 ✗ if (month && (month.get() == 2)) {
175 ✗ day = this->getInt(OS_RunPeriodFields::BeginDayofMonth);
176 ✗ if (day && (day.get() == 29)) {
177 ✗ this->setInt(OS_RunPeriodFields::BeginDayofMonth, 28);
178 }
179 }
180
181 ✗ month = getInt(OS_RunPeriodFields::EndMonth);
182 ✗ if (month && (month.get() == 2)) {
183 ✗ day = this->getInt(OS_RunPeriodFields::EndDayofMonth);
184 ✗ if (day && (day.get() == 29)) {
185 ✗ this->setInt(OS_RunPeriodFields::EndDayofMonth, 28);
186 }
187 }
188 ✗ }
189
190 // return the parent object in the hierarchy
191 1 boost::optional<ParentObject> RunPeriod_Impl::parent() const {
192
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 boost::optional<ParentObject> result(model().getUniqueModelObject<SimulationControl>());
193 1 return result;
194 }
195
196 // set the parent, child may have to call methods on the parent
197 ✗ bool RunPeriod_Impl::setParent(ParentObject& newParent) {
198 ✗ if (newParent.optionalCast<SimulationControl>() && (newParent.model() == model())) {
199 ✗ return true;
200 }
201 ✗ return false;
202 }
203
204 // return any children objects in the hierarchy
205 877 std::vector<ModelObject> RunPeriod_Impl::children() const {
206 877 std::vector<ModelObject> result;
207
2/2
✓ Branch 1 taken 877 times.
✓ Branch 4 taken 877 times.
877 SkyTemperatureVector sts = getObject<ModelObject>().getModelObjectSources<SkyTemperature>();
208
1/1
✓ Branch 5 taken 877 times.
877 result.insert(result.end(), sts.begin(), sts.end());
209 1754 return result;
210 877 }
211
212 ✗ std::vector<IddObjectType> RunPeriod_Impl::allowableChildTypes() const {
213 ✗ IddObjectTypeVector result;
214 ✗ result.push_back(SkyTemperature::iddObjectType());
215 ✗ return result;
216 ✗ }
217
218 // Get all output variable names that could be associated with this object.
219 1 const std::vector<std::string>& RunPeriod_Impl::outputVariableNames() const {
220
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static const std::vector<std::string> result;
221 1 return result;
222 }
223
224 ✗ bool RunPeriod_Impl::isAnnual() const {
225 ✗ if (getBeginMonth() != 1u) {
226 ✗ return false;
227 }
228 ✗ if (getBeginDayOfMonth() != 1u) {
229 ✗ return false;
230 }
231 ✗ if (getEndMonth() != 12u) {
232 ✗ return false;
233 }
234 ✗ if (getEndDayOfMonth() != 31u) {
235 ✗ return false;
236 }
237 ✗ return true;
238 }
239
240 ✗ bool RunPeriod_Impl::isPartialYear() const {
241 ✗ return !isAnnual();
242 }
243
244 ✗ bool RunPeriod_Impl::isRepeated() const {
245 ✗ return (getNumTimePeriodRepeats() > 1);
246 }
247
248 } // namespace detail
249
250 /// constructor
251 1115 RunPeriod::RunPeriod(const Model& model) : ParentObject(RunPeriod::iddObjectType(), model) {
252
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1115 times.
✗ Branch 5 not taken.
1115 OS_ASSERT(getImpl<detail::RunPeriod_Impl>());
253
1/1
✓ Branch 1 taken 1115 times.
1115 setBeginMonth(1);
254
1/1
✓ Branch 1 taken 1115 times.
1115 setBeginDayOfMonth(1);
255
1/1
✓ Branch 1 taken 1115 times.
1115 setEndMonth(12);
256
1/1
✓ Branch 1 taken 1115 times.
1115 setEndDayOfMonth(31);
257 1115 }
258
259 // constructor
260
1/1
✓ Branch 3 taken 999 times.
999 RunPeriod::RunPeriod(std::shared_ptr<detail::RunPeriod_Impl> impl) : ParentObject(std::move(impl)) {}
261
262 1741 int RunPeriod::getBeginMonth() const {
263
1/1
✓ Branch 3 taken 1741 times.
1741 return getImpl<detail::RunPeriod_Impl>()->getBeginMonth();
264 }
265
266 1741 int RunPeriod::getBeginDayOfMonth() const {
267
1/1
✓ Branch 3 taken 1741 times.
1741 return getImpl<detail::RunPeriod_Impl>()->getBeginDayOfMonth();
268 }
269
270 1741 int RunPeriod::getEndMonth() const {
271
1/1
✓ Branch 3 taken 1741 times.
1741 return getImpl<detail::RunPeriod_Impl>()->getEndMonth();
272 }
273
274 1741 int RunPeriod::getEndDayOfMonth() const {
275
1/1
✓ Branch 3 taken 1741 times.
1741 return getImpl<detail::RunPeriod_Impl>()->getEndDayOfMonth();
276 }
277
278 ✗ bool RunPeriod::getUseWeatherFileHolidays() const {
279 ✗ return getImpl<detail::RunPeriod_Impl>()->getUseWeatherFileHolidays();
280 }
281
282 ✗ bool RunPeriod::getUseWeatherFileDaylightSavings() const {
283 ✗ return getImpl<detail::RunPeriod_Impl>()->getUseWeatherFileDaylightSavings();
284 }
285
286 870 bool RunPeriod::getApplyWeekendHolidayRule() const {
287
1/1
✓ Branch 3 taken 870 times.
870 return getImpl<detail::RunPeriod_Impl>()->getApplyWeekendHolidayRule();
288 }
289
290 870 bool RunPeriod::getUseWeatherFileRainInd() const {
291
1/1
✓ Branch 3 taken 870 times.
870 return getImpl<detail::RunPeriod_Impl>()->getUseWeatherFileRainInd();
292 }
293
294 870 bool RunPeriod::getUseWeatherFileSnowInd() const {
295
1/1
✓ Branch 3 taken 870 times.
870 return getImpl<detail::RunPeriod_Impl>()->getUseWeatherFileSnowInd();
296 }
297
298 870 int RunPeriod::getNumTimePeriodRepeats() const {
299
1/1
✓ Branch 3 taken 870 times.
870 return getImpl<detail::RunPeriod_Impl>()->getNumTimePeriodRepeats();
300 }
301
302 1327 bool RunPeriod::setBeginMonth(int month) {
303
1/1
✓ Branch 3 taken 1327 times.
1327 return getImpl<detail::RunPeriod_Impl>()->setBeginMonth(month);
304 }
305
306 1327 bool RunPeriod::setBeginDayOfMonth(int day) {
307
1/1
✓ Branch 3 taken 1327 times.
1327 return getImpl<detail::RunPeriod_Impl>()->setBeginDayOfMonth(day);
308 }
309
310 1327 bool RunPeriod::setEndMonth(int month) {
311
1/1
✓ Branch 3 taken 1327 times.
1327 return getImpl<detail::RunPeriod_Impl>()->setEndMonth(month);
312 }
313
314 1327 bool RunPeriod::setEndDayOfMonth(int day) {
315
1/1
✓ Branch 3 taken 1327 times.
1327 return getImpl<detail::RunPeriod_Impl>()->setEndDayOfMonth(day);
316 }
317
318 208 bool RunPeriod::setUseWeatherFileHolidays(bool use) {
319
1/1
✓ Branch 3 taken 208 times.
208 return getImpl<detail::RunPeriod_Impl>()->setUseWeatherFileHolidays(use);
320 }
321
322 208 bool RunPeriod::setUseWeatherFileDaylightSavings(bool use) {
323
1/1
✓ Branch 3 taken 208 times.
208 return getImpl<detail::RunPeriod_Impl>()->setUseWeatherFileDaylightSavings(use);
324 }
325
326 208 bool RunPeriod::setApplyWeekendHolidayRule(bool apply) {
327
1/1
✓ Branch 3 taken 208 times.
208 return getImpl<detail::RunPeriod_Impl>()->setApplyWeekendHolidayRule(apply);
328 }
329
330 207 bool RunPeriod::setUseWeatherFileRainInd(bool rainInd) {
331
1/1
✓ Branch 3 taken 207 times.
207 return getImpl<detail::RunPeriod_Impl>()->setUseWeatherFileRainInd(rainInd);
332 }
333
334 207 bool RunPeriod::setUseWeatherFileSnowInd(bool snowInd) {
335
1/1
✓ Branch 3 taken 207 times.
207 return getImpl<detail::RunPeriod_Impl>()->setUseWeatherFileSnowInd(snowInd);
336 }
337
338 199 bool RunPeriod::setNumTimePeriodRepeats(int numRepeats) {
339
1/1
✓ Branch 3 taken 199 times.
199 return getImpl<detail::RunPeriod_Impl>()->setNumTimePeriodRepeats(numRepeats);
340 }
341
342 ✗ void RunPeriod::ensureNoLeapDays() {
343 ✗ getImpl<detail::RunPeriod_Impl>()->ensureNoLeapDays();
344 ✗ }
345
346 ✗ bool RunPeriod::isAnnual() const {
347 ✗ return getImpl<detail::RunPeriod_Impl>()->isAnnual();
348 }
349
350 ✗ bool RunPeriod::isPartialYear() const {
351 ✗ return getImpl<detail::RunPeriod_Impl>()->isPartialYear();
352 }
353
354 ✗ bool RunPeriod::isRepeated() const {
355 ✗ return getImpl<detail::RunPeriod_Impl>()->isRepeated();
356 }
357
358 12979 IddObjectType RunPeriod::iddObjectType() {
359
1/1
✓ Branch 1 taken 12979 times.
12979 IddObjectType result(IddObjectType::OS_RunPeriod);
360 12979 return result;
361 }
362
363 } // namespace model
364 } // namespace openstudio
365