GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 57.8% 115 / 0 / 199
Functions: 63.0% 34 / 0 / 54
Branches: 46.8% 80 / 0 / 171

src/model/WaterUseConnections.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 "Model.hpp"
7 #include "WaterUseConnections.hpp"
8 #include "WaterUseConnections_Impl.hpp"
9 #include "WaterUseEquipment.hpp"
10 #include "WaterUseEquipment_Impl.hpp"
11 #include "Connection.hpp"
12 #include "Connection_Impl.hpp"
13 #include "Schedule.hpp"
14 #include "Schedule_Impl.hpp"
15 #include "Node.hpp"
16 #include "Node_Impl.hpp"
17 #include "PlantLoop.hpp"
18 #include "PlantLoop_Impl.hpp"
19 #include <utilities/idd/IddFactory.hxx>
20
21 #include "../utilities/core/Assert.hpp"
22 #include "../utilities/data/DataEnums.hpp"
23 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
24
25 #include <utilities/idd/OS_WaterUse_Connections_FieldEnums.hxx>
26 #include <utilities/idd/IddEnums.hxx>
27
28 namespace openstudio {
29
30 namespace model {
31
32 namespace detail {
33
34 40 WaterUseConnections_Impl::WaterUseConnections_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
35 40 : StraightComponent_Impl(idfObject, model, keepHandle) {
36
4/6
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 40 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 40 times.
✗ Branch 13 not taken.
40 OS_ASSERT(idfObject.iddObject().type() == WaterUseConnections::iddObjectType());
37 40 }
38
39 13 WaterUseConnections_Impl::WaterUseConnections_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
40 13 : StraightComponent_Impl(other, model, keepHandle) {
41
4/6
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 13 times.
✗ Branch 13 not taken.
13 OS_ASSERT(other.iddObject().type() == WaterUseConnections::iddObjectType());
42 13 }
43
44 48 WaterUseConnections_Impl::WaterUseConnections_Impl(const WaterUseConnections_Impl& other, Model_Impl* model, bool keepHandle)
45 48 : StraightComponent_Impl(other, model, keepHandle) {}
46
47 ✗ const std::vector<std::string>& WaterUseConnections_Impl::outputVariableNames() const {
48 static const std::vector<std::string> result{"Water Use Connections Hot Water Mass Flow Rate",
49 "Water Use Connections Cold Water Mass Flow Rate",
50 "Water Use Connections Total Mass Flow Rate",
51 "Water Use Connections Drain Water Mass Flow Rate",
52 "Water Use Connections Heat Recovery Mass Flow Rate",
53 "Water Use Connections Hot Water Volume Flow Rate",
54 "Water Use Connections Cold Water Volume Flow Rate",
55 "Water Use Connections Total Volume Flow Rate",
56 "Water Use Connections Hot Water Volume",
57 "Water Use Connections Cold Water Volume",
58 "Water Use Connections Total Volume",
59 "Water Use Connections Hot Water Temperature",
60 "Water Use Connections Cold Water Temperature",
61 "Water Use Connections Drain Water Temperature",
62 "Water Use Connections Return Water Temperature",
63 "Water Use Connections Waste Water Temperature",
64 "Water Use Connections Heat Recovery Water Temperature",
65 "Water Use Connections Heat Recovery Effectiveness",
66 "Water Use Connections Heat Recovery Rate",
67 "Water Use Connections Heat Recovery Energy",
68 ✗ "Water Use Connections Plant Hot Water Energy"};
69 ✗ return result;
70 ✗ }
71
72 ✗ std::vector<ScheduleTypeKey> WaterUseConnections_Impl::getScheduleTypeKeys(const Schedule& schedule) const {
73 ✗ std::vector<ScheduleTypeKey> result;
74 ✗ UnsignedVector fieldIndices = getSourceIndices(schedule.handle());
75 ✗ UnsignedVector::const_iterator b(fieldIndices.begin());
76 ✗ UnsignedVector::const_iterator e(fieldIndices.end());
77 ✗ if (std::find(b, e, OS_WaterUse_ConnectionsFields::HotWaterSupplyTemperatureScheduleName) != e) {
78 ✗ result.push_back(ScheduleTypeKey("WaterUseConnections", "Hot Water Supply Temperature"));
79 }
80 ✗ if (std::find(b, e, OS_WaterUse_ConnectionsFields::ColdWaterSupplyTemperatureScheduleName) != e) {
81 ✗ result.push_back(ScheduleTypeKey("WaterUseConnections", "Cold Water Supply Temperature"));
82 }
83 ✗ return result;
84 ✗ }
85
86 20 IddObjectType WaterUseConnections_Impl::iddObjectType() const {
87 20 return WaterUseConnections::iddObjectType();
88 }
89
90 11 boost::optional<Schedule> WaterUseConnections_Impl::hotWaterSupplyTemperatureSchedule() const {
91
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_WaterUse_ConnectionsFields::HotWaterSupplyTemperatureScheduleName);
92 }
93
94 11 boost::optional<Schedule> WaterUseConnections_Impl::coldWaterSupplyTemperatureSchedule() const {
95
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_WaterUse_ConnectionsFields::ColdWaterSupplyTemperatureScheduleName);
96 }
97
98 ✗ bool WaterUseConnections_Impl::setHotWaterSupplyTemperatureSchedule(Schedule& schedule) {
99 ✗ bool result = setSchedule(OS_WaterUse_ConnectionsFields::HotWaterSupplyTemperatureScheduleName, "WaterUseConnections",
100 "Hot Water Supply Temperature", schedule);
101 ✗ return result;
102 }
103
104 ✗ void WaterUseConnections_Impl::resetHotWaterSupplyTemperatureSchedule() {
105 ✗ bool result = setString(OS_WaterUse_ConnectionsFields::HotWaterSupplyTemperatureScheduleName, "");
106 ✗ OS_ASSERT(result);
107 ✗ }
108
109 ✗ bool WaterUseConnections_Impl::setColdWaterSupplyTemperatureSchedule(Schedule& schedule) {
110 ✗ bool result = setSchedule(OS_WaterUse_ConnectionsFields::ColdWaterSupplyTemperatureScheduleName, "WaterUseConnections",
111 "Cold Water Supply Temperature", schedule);
112 ✗ return result;
113 }
114
115 ✗ void WaterUseConnections_Impl::resetColdWaterSupplyTemperatureSchedule() {
116 ✗ bool result = setString(OS_WaterUse_ConnectionsFields::ColdWaterSupplyTemperatureScheduleName, "");
117 ✗ OS_ASSERT(result);
118 ✗ }
119
120 ✗ boost::optional<ModelObject> WaterUseConnections_Impl::hotWaterSupplyTemperatureScheduleAsModelObject() const {
121 ✗ OptionalModelObject result;
122 ✗ OptionalSchedule intermediate = hotWaterSupplyTemperatureSchedule();
123 ✗ if (intermediate) {
124 ✗ result = *intermediate;
125 }
126 ✗ return result;
127 ✗ }
128
129 ✗ boost::optional<ModelObject> WaterUseConnections_Impl::coldWaterSupplyTemperatureScheduleAsModelObject() const {
130 ✗ OptionalModelObject result;
131 ✗ OptionalSchedule intermediate = coldWaterSupplyTemperatureSchedule();
132 ✗ if (intermediate) {
133 ✗ result = *intermediate;
134 }
135 ✗ return result;
136 ✗ }
137
138 ✗ bool WaterUseConnections_Impl::setHotWaterSupplyTemperatureScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) {
139 ✗ if (modelObject) {
140 ✗ OptionalSchedule intermediate = modelObject->optionalCast<Schedule>();
141 ✗ if (intermediate) {
142 ✗ return setHotWaterSupplyTemperatureSchedule(*intermediate);
143 } else {
144 ✗ return false;
145 }
146 ✗ } else {
147 ✗ resetHotWaterSupplyTemperatureSchedule();
148 }
149 ✗ return true;
150 }
151
152 ✗ bool WaterUseConnections_Impl::setColdWaterSupplyTemperatureScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) {
153 ✗ if (modelObject) {
154 ✗ OptionalSchedule intermediate = modelObject->optionalCast<Schedule>();
155 ✗ if (intermediate) {
156 ✗ return setColdWaterSupplyTemperatureSchedule(*intermediate);
157 } else {
158 ✗ return false;
159 }
160 ✗ } else {
161 ✗ resetColdWaterSupplyTemperatureSchedule();
162 }
163 ✗ return true;
164 }
165
166 48 unsigned WaterUseConnections_Impl::inletPort() const {
167 48 return OS_WaterUse_ConnectionsFields::InletNodeName;
168 }
169
170 2470 unsigned WaterUseConnections_Impl::outletPort() const {
171 2470 return OS_WaterUse_ConnectionsFields::OutletNodeName;
172 }
173
174 15 std::vector<WaterUseEquipment> WaterUseConnections_Impl::waterUseEquipment() const {
175 15 std::vector<WaterUseEquipment> result;
176
177
1/1
✓ Branch 1 taken 15 times.
15 std::vector<IdfExtensibleGroup> groups = extensibleGroups();
178
179
2/2
✓ Branch 5 taken 33 times.
✓ Branch 6 taken 15 times.
48 for (const auto& elem : groups) {
180
1/1
✓ Branch 1 taken 33 times.
33 auto group = elem.cast<WorkspaceExtensibleGroup>();
181
182
1/1
✓ Branch 1 taken 33 times.
33 boost::optional<WorkspaceObject> wo = group.getTarget(OS_WaterUse_ConnectionsExtensibleFields::WaterUseEquipmentName);
183
184
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 if (wo) {
185
2/2
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
33 auto equipment = wo->cast<WaterUseEquipment>();
186
187
1/1
✓ Branch 1 taken 33 times.
33 result.push_back(equipment);
188 33 }
189 33 }
190
191 30 return result;
192 15 }
193
194 29 bool WaterUseConnections_Impl::addWaterUseEquipment(const WaterUseEquipment& waterUseEquipment) {
195 29 bool result = false;
196
197
4/5
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
✓ Branch 7 taken 29 times.
✓ Branch 11 taken 29 times.
✗ Branch 12 not taken.
29 if (waterUseEquipment.model() == model()) {
198
3/3
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
✓ Branch 7 taken 29 times.
29 auto group = getObject<WaterUseConnections>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
199
200
2/2
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
29 group.setPointer(OS_WaterUse_ConnectionsExtensibleFields::WaterUseEquipmentName, waterUseEquipment.handle());
201
202 29 result = true;
203 29 }
204
205 29 return result;
206 }
207
208 1 bool WaterUseConnections_Impl::removeWaterUseEquipment(WaterUseEquipment& _waterUseEquipment) {
209
1/1
✓ Branch 1 taken 1 time.
1 std::vector<WaterUseEquipment> equipment = waterUseEquipment();
210
211 1 int i = 0;
212
213
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 for (const auto& elem : equipment) {
214
5/5
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 1 time.
2 if (elem.handle() == _waterUseEquipment.handle()) {
215
1/1
✓ Branch 1 taken 1 time.
1 eraseExtensibleGroup(i);
216
217 1 return true;
218 }
219
220 1 i++;
221 }
222
223 ✗ return false;
224 1 }
225
226 28 bool WaterUseConnections_Impl::addToNode(Node& node) {
227
3/3
✓ Branch 1 taken 28 times.
✓ Branch 3 taken 26 times.
✓ Branch 4 taken 2 times.
56 if (boost::optional<PlantLoop> plant = node.plantLoop()) {
228
5/5
✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✓ Branch 10 taken 25 times.
✓ Branch 11 taken 1 time.
52 if (plant->demandComponent(node.handle())) {
229
1/1
✓ Branch 1 taken 25 times.
25 return StraightComponent_Impl::addToNode(node);
230 }
231 28 }
232
233 3 return false;
234 }
235
236 14 std::string WaterUseConnections_Impl::drainWaterHeatExchangerType() const {
237
1/1
✓ Branch 1 taken 14 times.
14 boost::optional<std::string> value = getString(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerType, true);
238
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
14 OS_ASSERT(value);
239
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
28 return value.get();
240 14 }
241
242 30 bool WaterUseConnections_Impl::setDrainWaterHeatExchangerType(const std::string& drainWaterHeatExchangerType) {
243 30 bool result = setString(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerType, drainWaterHeatExchangerType);
244 30 return result;
245 }
246
247 14 std::string WaterUseConnections_Impl::drainWaterHeatExchangerDestination() const {
248
1/1
✓ Branch 1 taken 14 times.
14 boost::optional<std::string> value = getString(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerDestination, true);
249
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
14 OS_ASSERT(value);
250
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
28 return value.get();
251 14 }
252
253 30 bool WaterUseConnections_Impl::setDrainWaterHeatExchangerDestination(const std::string& drainWaterHeatExchangerDestination) {
254 30 bool result = setString(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerDestination, drainWaterHeatExchangerDestination);
255 30 return result;
256 }
257
258 15 boost::optional<double> WaterUseConnections_Impl::drainWaterHeatExchangerUFactorTimesArea() const {
259 15 return getDouble(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerUFactorTimesArea, true);
260 }
261
262 3 bool WaterUseConnections_Impl::setDrainWaterHeatExchangerUFactorTimesArea(double drainWaterHeatExchangerUFactorTimesArea) {
263 3 bool result = setDouble(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerUFactorTimesArea, drainWaterHeatExchangerUFactorTimesArea);
264 3 return result;
265 }
266
267 1 void WaterUseConnections_Impl::resetDrainWaterHeatExchangerUFactorTimesArea() {
268
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_WaterUse_ConnectionsFields::DrainWaterHeatExchangerUFactorTimesArea, "");
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
270 1 }
271
272 ✗ ComponentType WaterUseConnections_Impl::componentType() const {
273 ✗ return ComponentType::None;
274 }
275
276 ✗ std::vector<FuelType> WaterUseConnections_Impl::coolingFuelTypes() const {
277 ✗ return {};
278 }
279
280 ✗ std::vector<FuelType> WaterUseConnections_Impl::heatingFuelTypes() const {
281 ✗ return {};
282 }
283
284 ✗ std::vector<AppGFuelType> WaterUseConnections_Impl::appGHeatingFuelTypes() const {
285 ✗ return {};
286 }
287
288 } // namespace detail
289
290 27 WaterUseConnections::WaterUseConnections(const Model& model) : StraightComponent(WaterUseConnections::iddObjectType(), model) {
291
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✗ Branch 5 not taken.
27 OS_ASSERT(getImpl<detail::WaterUseConnections_Impl>());
292
293
2/2
✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
54 setDrainWaterHeatExchangerType("None");
294
2/2
✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
27 setDrainWaterHeatExchangerDestination("Plant");
295 27 }
296
297 7828 IddObjectType WaterUseConnections::iddObjectType() {
298
4/7
✓ Branch 0 taken 3864 times.
✓ Branch 1 taken 3964 times.
✓ Branch 3 taken 3864 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3864 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
7828 static const IddObjectType result(IddObjectType::OS_WaterUse_Connections);
299 7828 return result;
300 }
301
302 11 boost::optional<Schedule> WaterUseConnections::hotWaterSupplyTemperatureSchedule() const {
303
1/1
✓ Branch 3 taken 11 times.
11 return getImpl<detail::WaterUseConnections_Impl>()->hotWaterSupplyTemperatureSchedule();
304 }
305
306 11 boost::optional<Schedule> WaterUseConnections::coldWaterSupplyTemperatureSchedule() const {
307
1/1
✓ Branch 3 taken 11 times.
11 return getImpl<detail::WaterUseConnections_Impl>()->coldWaterSupplyTemperatureSchedule();
308 }
309
310 ✗ bool WaterUseConnections::setHotWaterSupplyTemperatureSchedule(Schedule& hotWaterSupplyTemperatureSchedule) {
311 ✗ return getImpl<detail::WaterUseConnections_Impl>()->setHotWaterSupplyTemperatureSchedule(hotWaterSupplyTemperatureSchedule);
312 }
313
314 ✗ void WaterUseConnections::resetHotWaterSupplyTemperatureSchedule() {
315 ✗ getImpl<detail::WaterUseConnections_Impl>()->resetHotWaterSupplyTemperatureSchedule();
316 ✗ }
317
318 ✗ bool WaterUseConnections::setColdWaterSupplyTemperatureSchedule(Schedule& coldWaterSupplyTemperatureSchedule) {
319 ✗ return getImpl<detail::WaterUseConnections_Impl>()->setColdWaterSupplyTemperatureSchedule(coldWaterSupplyTemperatureSchedule);
320 }
321
322 ✗ void WaterUseConnections::resetColdWaterSupplyTemperatureSchedule() {
323 ✗ getImpl<detail::WaterUseConnections_Impl>()->resetColdWaterSupplyTemperatureSchedule();
324 ✗ }
325
326 ✗ unsigned WaterUseConnections::inletPort() const {
327 ✗ return getImpl<detail::WaterUseConnections_Impl>()->inletPort();
328 }
329
330 ✗ unsigned WaterUseConnections::outletPort() const {
331 ✗ return getImpl<detail::WaterUseConnections_Impl>()->outletPort();
332 }
333
334 14 std::vector<WaterUseEquipment> WaterUseConnections::waterUseEquipment() const {
335
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::WaterUseConnections_Impl>()->waterUseEquipment();
336 }
337
338 29 bool WaterUseConnections::addWaterUseEquipment(const WaterUseEquipment& waterUseEquipment) {
339
1/1
✓ Branch 3 taken 29 times.
29 return getImpl<detail::WaterUseConnections_Impl>()->addWaterUseEquipment(waterUseEquipment);
340 }
341
342 1 bool WaterUseConnections::removeWaterUseEquipment(WaterUseEquipment& waterUseEquipment) {
343
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::WaterUseConnections_Impl>()->removeWaterUseEquipment(waterUseEquipment);
344 }
345
346 14 std::string WaterUseConnections::drainWaterHeatExchangerType() const {
347
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::WaterUseConnections_Impl>()->drainWaterHeatExchangerType();
348 }
349
350 30 bool WaterUseConnections::setDrainWaterHeatExchangerType(const std::string& drainWaterHeatExchangerType) {
351
1/1
✓ Branch 3 taken 30 times.
30 return getImpl<detail::WaterUseConnections_Impl>()->setDrainWaterHeatExchangerType(drainWaterHeatExchangerType);
352 }
353
354 14 std::string WaterUseConnections::drainWaterHeatExchangerDestination() const {
355
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::WaterUseConnections_Impl>()->drainWaterHeatExchangerDestination();
356 }
357
358 30 bool WaterUseConnections::setDrainWaterHeatExchangerDestination(const std::string& drainWaterHeatExchangerDestination) {
359
1/1
✓ Branch 3 taken 30 times.
30 return getImpl<detail::WaterUseConnections_Impl>()->setDrainWaterHeatExchangerDestination(drainWaterHeatExchangerDestination);
360 }
361
362 15 boost::optional<double> WaterUseConnections::drainWaterHeatExchangerUFactorTimesArea() const {
363
1/1
✓ Branch 3 taken 15 times.
15 return getImpl<detail::WaterUseConnections_Impl>()->drainWaterHeatExchangerUFactorTimesArea();
364 }
365
366 3 bool WaterUseConnections::setDrainWaterHeatExchangerUFactorTimesArea(double drainWaterHeatExchangerUFactorTimesArea) {
367
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::WaterUseConnections_Impl>()->setDrainWaterHeatExchangerUFactorTimesArea(drainWaterHeatExchangerUFactorTimesArea);
368 }
369
370 1 void WaterUseConnections::resetDrainWaterHeatExchangerUFactorTimesArea() {
371
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::WaterUseConnections_Impl>()->resetDrainWaterHeatExchangerUFactorTimesArea();
372 1 }
373
374 /// @cond
375
1/1
✓ Branch 3 taken 41 times.
41 WaterUseConnections::WaterUseConnections(std::shared_ptr<detail::WaterUseConnections_Impl> impl) : StraightComponent(std::move(impl)) {}
376 /// @endcond
377
378 } // namespace model
379 } // namespace openstudio
380