GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 37.7% 86 / 0 / 228
Functions: 50.8% 30 / 0 / 59
Branches: 28.4% 61 / 0 / 215

src/model/GasEquipment.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 "GasEquipment.hpp"
7 #include "GasEquipment_Impl.hpp"
8
9 #include "GasEquipmentDefinition.hpp"
10 #include "GasEquipmentDefinition_Impl.hpp"
11 #include "Schedule.hpp"
12 #include "Schedule_Impl.hpp"
13 #include "Space.hpp"
14 #include "Space_Impl.hpp"
15 #include "SpaceType.hpp"
16 #include "SpaceType_Impl.hpp"
17 #include "DefaultScheduleSet.hpp"
18 #include "DefaultScheduleSet_Impl.hpp"
19 #include "LifeCycleCost.hpp"
20 #include "Model.hpp"
21
22 #include <utilities/idd/OS_GasEquipment_FieldEnums.hxx>
23 #include <utilities/idd/IddEnums.hxx>
24
25 #include "../utilities/core/Assert.hpp"
26
27 namespace openstudio {
28 namespace model {
29
30 namespace detail {
31
32 29 GasEquipment_Impl::GasEquipment_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
33 29 : SpaceLoadInstance_Impl(idfObject, model, keepHandle) {
34
4/6
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
✓ Branch 7 taken 29 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 29 times.
✗ Branch 13 not taken.
29 OS_ASSERT(idfObject.iddObject().type() == GasEquipment::iddObjectType());
35 29 }
36
37 17 GasEquipment_Impl::GasEquipment_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
38 17 : SpaceLoadInstance_Impl(other, model, keepHandle) {
39
4/6
✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 17 times.
✗ Branch 13 not taken.
17 OS_ASSERT(other.iddObject().type() == GasEquipment::iddObjectType());
40 17 }
41
42 8 GasEquipment_Impl::GasEquipment_Impl(const GasEquipment_Impl& other, Model_Impl* model, bool keepHandle)
43 8 : SpaceLoadInstance_Impl(other, model, keepHandle) {}
44
45 ✗ const std::vector<std::string>& GasEquipment_Impl::outputVariableNames() const {
46 static const std::vector<std::string> result{
47 "Gas Equipment NaturalGas Rate",
48 "Gas Equipment NaturalGas Energy",
49 "Gas Equipment Radiant Heating Energy",
50 "Gas Equipment Convective Heating Energy",
51 "Gas Equipment Latent Gain Energy",
52 "Gas Equipment Lost Heat Energy",
53 "Gas Equipment Total Heating Energy",
54 "Gas Equipment Radiant Heating Rate",
55 "Gas Equipment Convective Heating Rate",
56 "Gas Equipment Latent Gain Rate",
57 "Gas Equipment Lost Heat Rate",
58 "Gas Equipment Total Heating Rate"
59
60 // Reported in ThermalZone
61 //"Zone Gas Equipment NaturalGas Rate",
62 //"Zone Gas Equipment NaturalGas Energy",
63 //"Zone Gas Equipment Radiant Heating Energy",
64 //"Zone Gas Equipment Radiant Heating Rate",
65 //"Zone Gas Equipment Convective Heating Energy",
66 //"Zone Gas Equipment Convective Heating Rate",
67 //"Zone Gas Equipment Latent Gain Energy",
68 //"Zone Gas Equipment Latent Gain Rate",
69 //"Zone Gas Equipment Lost Heat Energy",
70 //"Zone Gas Equipment Lost Heat Rate",
71 //"Zone Gas Equipment Total Heating Energy",
72 //"Zone Gas Equipment Total Heating Rate"
73 ✗ };
74 ✗ return result;
75 ✗ }
76
77 6 IddObjectType GasEquipment_Impl::iddObjectType() const {
78 6 return GasEquipment::iddObjectType();
79 }
80
81 ✗ std::vector<ScheduleTypeKey> GasEquipment_Impl::getScheduleTypeKeys(const Schedule& schedule) const {
82 ✗ std::vector<ScheduleTypeKey> result;
83 ✗ UnsignedVector fieldIndices = getSourceIndices(schedule.handle());
84 ✗ UnsignedVector::const_iterator b(fieldIndices.begin());
85 ✗ UnsignedVector::const_iterator e(fieldIndices.end());
86 ✗ if (std::find(b, e, OS_GasEquipmentFields::ScheduleName) != e) {
87 ✗ result.push_back(ScheduleTypeKey("GasEquipment", "Gas Equipment"));
88 }
89 ✗ return result;
90 ✗ }
91
92 ✗ bool GasEquipment_Impl::hardSize() {
93 ✗ boost::optional<Space> space = this->space();
94 ✗ if (!space) {
95 ✗ return false;
96 }
97
98 ✗ this->makeUnique();
99
100 ✗ GasEquipmentDefinition gasEquipmentDefinition = this->gasEquipmentDefinition();
101 ✗ for (LifeCycleCost& cost : gasEquipmentDefinition.lifeCycleCosts()) {
102 ✗ cost.convertToCostPerEach();
103 ✗ }
104
105 ✗ boost::optional<double> designLevel = gasEquipmentDefinition.designLevel();
106 ✗ if (designLevel) {
107 ✗ return true;
108 }
109
110 ✗ boost::optional<double> wattsperSpaceFloorArea = gasEquipmentDefinition.wattsperSpaceFloorArea();
111 ✗ if (wattsperSpaceFloorArea) {
112 ✗ return gasEquipmentDefinition.setDesignLevel(*wattsperSpaceFloorArea * space->floorArea());
113 }
114
115 ✗ boost::optional<double> wattsperPerson = gasEquipmentDefinition.wattsperPerson();
116 ✗ if (wattsperPerson) {
117 ✗ return gasEquipmentDefinition.setDesignLevel(*wattsperPerson * space->numberOfPeople());
118 }
119
120 ✗ return false;
121 ✗ }
122
123 ✗ bool GasEquipment_Impl::hardApplySchedules() {
124 ✗ bool result = false;
125 ✗ boost::optional<Schedule> schedule = this->schedule();
126 ✗ if (schedule) {
127 ✗ result = this->setSchedule(*schedule);
128 }
129 ✗ return result;
130 ✗ }
131
132 57 double GasEquipment_Impl::multiplier() const {
133
1/1
✓ Branch 1 taken 57 times.
57 boost::optional<double> value = getDouble(OS_GasEquipmentFields::Multiplier, true);
134
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 4 not taken.
57 OS_ASSERT(value);
135
1/1
✓ Branch 1 taken 57 times.
114 return value.get();
136 }
137
138 ✗ bool GasEquipment_Impl::isMultiplierDefaulted() const {
139 ✗ return isEmpty(OS_GasEquipmentFields::Multiplier);
140 }
141
142 ✗ bool GasEquipment_Impl::isAbsolute() const {
143 ✗ GasEquipmentDefinition definition = gasEquipmentDefinition();
144 ✗ if (definition.designLevel()) {
145 ✗ return true;
146 }
147 ✗ return false;
148 ✗ }
149
150 7 std::string GasEquipment_Impl::endUseSubcategory() const {
151
1/1
✓ Branch 1 taken 7 times.
7 boost::optional<std::string> value = getString(OS_GasEquipmentFields::EndUseSubcategory, true);
152
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 4 not taken.
7 OS_ASSERT(value);
153
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
14 return value.get();
154 7 }
155
156 7 bool GasEquipment_Impl::isEndUseSubcategoryDefaulted() const {
157 7 return isEmpty(OS_GasEquipmentFields::EndUseSubcategory);
158 }
159
160 4 bool GasEquipment_Impl::setMultiplier(double multiplier) {
161 4 bool result = setDouble(OS_GasEquipmentFields::Multiplier, multiplier);
162 4 return result;
163 }
164
165 ✗ void GasEquipment_Impl::resetMultiplier() {
166 ✗ bool result = setString(OS_GasEquipmentFields::Multiplier, "");
167 ✗ OS_ASSERT(result);
168 ✗ }
169
170 13 bool GasEquipment_Impl::setEndUseSubcategory(const std::string& endUseSubcategory) {
171 13 bool result = setString(OS_GasEquipmentFields::EndUseSubcategory, endUseSubcategory);
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 OS_ASSERT(result);
173 13 return result;
174 }
175
176 ✗ void GasEquipment_Impl::resetEndUseSubcategory() {
177 ✗ bool result = setString(OS_GasEquipmentFields::EndUseSubcategory, "");
178 ✗ OS_ASSERT(result);
179 ✗ }
180
181 64 int GasEquipment_Impl::spaceIndex() const {
182 64 return OS_GasEquipmentFields::SpaceorSpaceTypeName;
183 }
184
185 66 int GasEquipment_Impl::definitionIndex() const {
186 66 return OS_GasEquipmentFields::GasEquipmentDefinitionName;
187 }
188
189 7 boost::optional<Schedule> GasEquipment_Impl::schedule() const {
190
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 boost::optional<Schedule> result = getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_GasEquipmentFields::ScheduleName);
191
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1 time.
7 if (!result) {
192 // search upwards
193
1/1
✓ Branch 1 taken 6 times.
6 OptionalSpace space = this->space();
194
1/1
✓ Branch 1 taken 6 times.
6 OptionalSpaceType spaceType = this->spaceType();
195
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (space) {
196
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 result = space->getDefaultSchedule(DefaultScheduleType::GasEquipmentSchedule);
197
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 } else if (spaceType) {
198
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 result = spaceType->getDefaultSchedule(DefaultScheduleType::GasEquipmentSchedule);
199 }
200 6 }
201 7 return result;
202 ✗ }
203
204 ✗ bool GasEquipment_Impl::isScheduleDefaulted() const {
205 ✗ return isEmpty(OS_GasEquipmentFields::ScheduleName);
206 }
207
208 1 bool GasEquipment_Impl::setSchedule(Schedule& schedule) {
209
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
4 bool result = ModelObject_Impl::setSchedule(OS_GasEquipmentFields::ScheduleName, "GasEquipment", "Gas Equipment", schedule);
210 1 return result;
211 }
212
213 ✗ void GasEquipment_Impl::resetSchedule() {
214 ✗ bool result = setString(OS_GasEquipmentFields::ScheduleName, "");
215 ✗ OS_ASSERT(result);
216 ✗ }
217
218 53 GasEquipmentDefinition GasEquipment_Impl::gasEquipmentDefinition() const {
219
2/2
✓ Branch 1 taken 53 times.
✓ Branch 4 taken 53 times.
53 return this->definition().cast<GasEquipmentDefinition>();
220 }
221
222 ✗ bool GasEquipment_Impl::setGasEquipmentDefinition(const GasEquipmentDefinition& definition) {
223 ✗ return this->setPointer(this->definitionIndex(), definition.handle());
224 }
225
226 ✗ bool GasEquipment_Impl::setDefinition(const SpaceLoadDefinition& definition) {
227 ✗ bool result = false;
228 ✗ boost::optional<GasEquipmentDefinition> gasEquipmentDefinition = definition.optionalCast<GasEquipmentDefinition>();
229 ✗ if (gasEquipmentDefinition) {
230 ✗ result = setGasEquipmentDefinition(*gasEquipmentDefinition);
231 }
232 ✗ return result;
233 ✗ }
234
235 ✗ boost::optional<double> GasEquipment_Impl::designLevel() const {
236 ✗ OptionalDouble result = gasEquipmentDefinition().designLevel();
237 ✗ if (result) {
238 ✗ return result.get() * multiplier();
239 }
240 ✗ return result;
241 }
242
243 ✗ boost::optional<double> GasEquipment_Impl::powerPerFloorArea() const {
244 ✗ OptionalDouble result = gasEquipmentDefinition().wattsperSpaceFloorArea();
245 ✗ if (result) {
246 ✗ return result.get() * multiplier();
247 }
248 ✗ return result;
249 }
250
251 ✗ boost::optional<double> GasEquipment_Impl::powerPerPerson() const {
252 ✗ OptionalDouble result = gasEquipmentDefinition().wattsperPerson();
253 ✗ if (result) {
254 ✗ return result.get() * multiplier();
255 }
256 ✗ return result;
257 }
258
259 35 double GasEquipment_Impl::getDesignLevel(double floorArea, double numPeople) const {
260
3/3
✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
35 return gasEquipmentDefinition().getDesignLevel(floorArea, numPeople) * multiplier();
261 }
262
263 5 double GasEquipment_Impl::getPowerPerFloorArea(double floorArea, double numPeople) const {
264
3/3
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
5 return gasEquipmentDefinition().getPowerPerFloorArea(floorArea, numPeople) * multiplier();
265 }
266
267 5 double GasEquipment_Impl::getPowerPerPerson(double floorArea, double numPeople) const {
268
3/3
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
5 return gasEquipmentDefinition().getPowerPerPerson(floorArea, numPeople) * multiplier();
269 }
270
271 ✗ boost::optional<ModelObject> GasEquipment_Impl::gasEquipmentDefinitionAsModelObject() const {
272 ✗ OptionalModelObject result = gasEquipmentDefinition();
273 ✗ return result;
274 }
275
276 ✗ boost::optional<ModelObject> GasEquipment_Impl::scheduleAsModelObject() const {
277 ✗ OptionalModelObject result;
278 ✗ OptionalSchedule intermediate = schedule();
279 ✗ if (intermediate) {
280 ✗ result = *intermediate;
281 }
282 ✗ return result;
283 ✗ }
284
285 ✗ bool GasEquipment_Impl::setGasEquipmentDefinitionAsModelObject(const boost::optional<ModelObject>& modelObject) {
286 ✗ if (modelObject) {
287 ✗ OptionalGasEquipmentDefinition intermediate = modelObject->optionalCast<GasEquipmentDefinition>();
288 ✗ if (intermediate) {
289 ✗ return setGasEquipmentDefinition(*intermediate);
290 }
291 ✗ }
292 ✗ return false;
293 }
294
295 ✗ bool GasEquipment_Impl::setScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) {
296 ✗ if (modelObject) {
297 ✗ OptionalSchedule intermediate = modelObject->optionalCast<Schedule>();
298 ✗ if (intermediate) {
299 ✗ Schedule schedule(*intermediate);
300 ✗ return setSchedule(schedule);
301 ✗ } else {
302 ✗ return false;
303 }
304 ✗ } else {
305 ✗ resetSchedule();
306 }
307 ✗ return true;
308 }
309
310 ✗ std::vector<EMSActuatorNames> GasEquipment_Impl::emsActuatorNames() const {
311 ✗ std::vector<EMSActuatorNames> actuators{{"GasEquipment", "NaturalGas Rate"}};
312 ✗ return actuators;
313 ✗ }
314
315 ✗ std::vector<std::string> GasEquipment_Impl::emsInternalVariableNames() const {
316 ✗ std::vector<std::string> types{"Gas Process Power Design Level"};
317 ✗ return types;
318 ✗ }
319
320 } // namespace detail
321
322 12 GasEquipment::GasEquipment(const GasEquipmentDefinition& gasEquipmentDefinition)
323 12 : SpaceLoadInstance(GasEquipment::iddObjectType(), gasEquipmentDefinition) {
324
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 5 not taken.
12 OS_ASSERT(getImpl<detail::GasEquipment_Impl>());
325
326 /*
327 *Schedule sch = this->model().alwaysOnDiscreteSchedule();
328 *bool test = this->setSchedule(sch);
329 *OS_ASSERT(test);
330 *test = this->setMultiplier(1.0);
331 *OS_ASSERT(test);
332 */
333
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 bool test = this->setEndUseSubcategory("General");
334
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
12 OS_ASSERT(test);
335 12 }
336
337 10755 IddObjectType GasEquipment::iddObjectType() {
338
1/1
✓ Branch 1 taken 10755 times.
10755 IddObjectType result(IddObjectType::OS_GasEquipment);
339 10755 return result;
340 }
341
342 7 std::string GasEquipment::endUseSubcategory() const {
343
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GasEquipment_Impl>()->endUseSubcategory();
344 }
345
346 7 bool GasEquipment::isEndUseSubcategoryDefaulted() const {
347
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GasEquipment_Impl>()->isEndUseSubcategoryDefaulted();
348 }
349
350 4 bool GasEquipment::setMultiplier(double multiplier) {
351
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::GasEquipment_Impl>()->setMultiplier(multiplier);
352 }
353
354 ✗ void GasEquipment::resetMultiplier() {
355 ✗ getImpl<detail::GasEquipment_Impl>()->resetMultiplier();
356 ✗ }
357
358 13 bool GasEquipment::setEndUseSubcategory(const std::string& endUseSubcategory) {
359
1/1
✓ Branch 3 taken 13 times.
13 return getImpl<detail::GasEquipment_Impl>()->setEndUseSubcategory(endUseSubcategory);
360 }
361
362 ✗ void GasEquipment::resetEndUseSubcategory() {
363 ✗ getImpl<detail::GasEquipment_Impl>()->resetEndUseSubcategory();
364 ✗ }
365
366 7 boost::optional<Schedule> GasEquipment::schedule() const {
367
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GasEquipment_Impl>()->schedule();
368 }
369
370 ✗ bool GasEquipment::isScheduleDefaulted() const {
371 ✗ return getImpl<detail::GasEquipment_Impl>()->isScheduleDefaulted();
372 }
373
374 1 bool GasEquipment::setSchedule(Schedule& schedule) {
375
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::GasEquipment_Impl>()->setSchedule(schedule);
376 }
377
378 ✗ void GasEquipment::resetSchedule() {
379 ✗ getImpl<detail::GasEquipment_Impl>()->resetSchedule();
380 ✗ }
381
382 8 GasEquipmentDefinition GasEquipment::gasEquipmentDefinition() const {
383
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::GasEquipment_Impl>()->gasEquipmentDefinition();
384 }
385
386 ✗ bool GasEquipment::setGasEquipmentDefinition(const GasEquipmentDefinition& gasEquipmentDefinition) {
387 ✗ return getImpl<detail::GasEquipment_Impl>()->setGasEquipmentDefinition(gasEquipmentDefinition);
388 }
389
390 ✗ boost::optional<double> GasEquipment::designLevel() const {
391 ✗ return getImpl<detail::GasEquipment_Impl>()->designLevel();
392 }
393
394 ✗ boost::optional<double> GasEquipment::powerPerFloorArea() const {
395 ✗ return getImpl<detail::GasEquipment_Impl>()->powerPerFloorArea();
396 }
397
398 ✗ boost::optional<double> GasEquipment::powerPerPerson() const {
399 ✗ return getImpl<detail::GasEquipment_Impl>()->powerPerPerson();
400 }
401
402 35 double GasEquipment::getDesignLevel(double floorArea, double numPeople) const {
403
1/1
✓ Branch 3 taken 35 times.
35 return getImpl<detail::GasEquipment_Impl>()->getDesignLevel(floorArea, numPeople);
404 }
405
406 5 double GasEquipment::getPowerPerFloorArea(double floorArea, double numPeople) const {
407
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::GasEquipment_Impl>()->getPowerPerFloorArea(floorArea, numPeople);
408 }
409
410 5 double GasEquipment::getPowerPerPerson(double floorArea, double numPeople) const {
411
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::GasEquipment_Impl>()->getPowerPerPerson(floorArea, numPeople);
412 }
413
414 /// @cond
415
1/1
✓ Branch 3 taken 68 times.
68 GasEquipment::GasEquipment(std::shared_ptr<detail::GasEquipment_Impl> impl) : SpaceLoadInstance(std::move(impl)) {}
416 /// @endcond
417
418 } // namespace model
419 } // namespace openstudio
420