GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 69.4% 111 / 0 / 160
Functions: 70.7% 29 / 0 / 41
Branches: 63.0% 114 / 0 / 181

src/model/ControllerMechanicalVentilation.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 "ControllerMechanicalVentilation.hpp"
7 #include "ControllerMechanicalVentilation_Impl.hpp"
8 #include "AirLoopHVACOutdoorAirSystem.hpp"
9 #include "AirLoopHVACOutdoorAirSystem_Impl.hpp"
10 #include "AirLoopHVAC.hpp"
11 #include "AirLoopHVAC_Impl.hpp"
12 #include "ControllerOutdoorAir.hpp"
13 #include "ControllerOutdoorAir_Impl.hpp"
14 #include "Schedule.hpp"
15 #include "Schedule_Impl.hpp"
16 #include "SizingSystem.hpp"
17 #include "SizingSystem_Impl.hpp"
18 #include "ThermalZone.hpp"
19 #include "Space.hpp"
20 #include "Model.hpp"
21 #include "Model_Impl.hpp"
22 #include "ScheduleTypeLimits.hpp"
23 #include "ScheduleTypeRegistry.hpp"
24 #include <utilities/idd/IddFactory.hxx>
25
26 #include <utilities/idd/OS_Controller_MechanicalVentilation_FieldEnums.hxx>
27 #include <utilities/idd/IddEnums.hxx>
28 #include "../utilities/core/Assert.hpp"
29
30 #include <algorithm>
31
32 namespace openstudio {
33 namespace model {
34
35 namespace detail {
36
37 294 ControllerMechanicalVentilation_Impl::ControllerMechanicalVentilation_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
38 294 : ModelObject_Impl(idfObject, model, keepHandle) {
39
4/6
✓ Branch 1 taken 294 times.
✓ Branch 4 taken 294 times.
✓ Branch 7 taken 294 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 294 times.
✗ Branch 13 not taken.
294 OS_ASSERT(idfObject.iddObject().type() == ControllerMechanicalVentilation::iddObjectType());
40 294 }
41
42 43 ControllerMechanicalVentilation_Impl::ControllerMechanicalVentilation_Impl(const openstudio::detail::WorkspaceObject_Impl& other,
43 43 Model_Impl* model, bool keepHandle)
44 43 : ModelObject_Impl(other, model, keepHandle) {
45
4/6
✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 43 times.
✗ Branch 13 not taken.
43 OS_ASSERT(other.iddObject().type() == ControllerMechanicalVentilation::iddObjectType());
46 43 }
47
48 141 ControllerMechanicalVentilation_Impl::ControllerMechanicalVentilation_Impl(const ControllerMechanicalVentilation_Impl& other, Model_Impl* model,
49 141 bool keepHandle)
50 141 : ModelObject_Impl(other, model, keepHandle) {}
51
52 1 const std::vector<std::string>& ControllerMechanicalVentilation_Impl::outputVariableNames() const {
53
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;
54 // Not appropriate: no specific output
55 1 return result;
56 }
57
58 1 IddObjectType ControllerMechanicalVentilation_Impl::iddObjectType() const {
59 1 return ControllerMechanicalVentilation::iddObjectType();
60 }
61
62 ✗ std::vector<ScheduleTypeKey> ControllerMechanicalVentilation_Impl::getScheduleTypeKeys(const Schedule& schedule) const {
63 // TODO: Check schedule display names.
64 ✗ std::vector<ScheduleTypeKey> result;
65 ✗ UnsignedVector fieldIndices = getSourceIndices(schedule.handle());
66 ✗ UnsignedVector::const_iterator b(fieldIndices.begin());
67 ✗ UnsignedVector::const_iterator e(fieldIndices.end());
68 ✗ if (std::find(b, e, OS_Controller_MechanicalVentilationFields::AvailabilitySchedule) != e) {
69 ✗ result.push_back(ScheduleTypeKey("ControllerMechanicalVentilation", "Availability Schedule"));
70 }
71 ✗ return result;
72 ✗ }
73
74 18 Schedule ControllerMechanicalVentilation_Impl::availabilitySchedule() const {
75
1/1
✓ Branch 1 taken 18 times.
18 boost::optional<Schedule> value = optionalAvailabilitySchedule();
76
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if (!value) {
77 ✗ LOG_AND_THROW(briefDescription() << " does not have an Availability Schedule attached.");
78 }
79
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
36 return value.get();
80 18 }
81
82 71 bool ControllerMechanicalVentilation_Impl::demandControlledVentilation() const {
83
1/1
✓ Branch 1 taken 71 times.
71 boost::optional<std::string> value = getString(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation, true);
84
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 4 not taken.
71 OS_ASSERT(value);
85
3/3
✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
✓ Branch 7 taken 71 times.
142 return openstudio::istringEqual(value.get(), "Yes");
86 71 }
87
88 ✗ bool ControllerMechanicalVentilation_Impl::isDemandControlledVentilationDefaulted() const {
89 ✗ return isEmpty(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation);
90 }
91
92 28 std::string ControllerMechanicalVentilation_Impl::systemOutdoorAirMethod() const {
93 28 boost::optional<std::string> result;
94
1/1
✓ Branch 1 taken 28 times.
28 const auto value = getString(OS_Controller_MechanicalVentilationFields::SystemOutdoorAirMethod, true);
95
6/7
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 28 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 16 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 16 times.
28 if (value && !value->empty()) {
96
1/1
✓ Branch 1 taken 12 times.
12 result = value;
97 } else {
98 16 boost::optional<ControllerOutdoorAir> controllerOA_;
99
100 // TODO: this should be returning an optional really...
101 try {
102
2/2
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
16 controllerOA_ = controllerOutdoorAir();
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 } catch (openstudio::Exception&) {
104 1 }
105
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 time.
16 if (controllerOA_) {
106 // if there is no value set then look for a related SizingSystem object
107 // and use the SizingSystem::SystemOutdoorAirMethod field as the default value
108
2/2
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
15 const auto oaSystem = controllerOA_->airLoopHVACOutdoorAirSystem();
109
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 time.
15 if (oaSystem) {
110
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
14 const auto airLoop = oaSystem->airLoopHVAC();
111
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 time.
14 if (airLoop) {
112
3/3
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
13 const auto sizingSystemOAMethod = airLoop->sizingSystem().systemOutdoorAirMethod();
113
1/1
✓ Branch 1 taken 13 times.
13 const auto possible_vals = systemOutdoorAirMethodValues();
114
1/1
✓ Branch 3 taken 13 times.
13 if (std::find_if(possible_vals.cbegin(), possible_vals.cend(),
115 22 [&sizingSystemOAMethod](const std::string& val) { return openstudio::istringEqual(val, sizingSystemOAMethod); })
116
2/2
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 1 time.
26 != possible_vals.cend()) {
117
1/1
✓ Branch 1 taken 12 times.
12 result = sizingSystemOAMethod;
118 }
119 13 }
120 14 }
121 15 }
122 16 }
123
124
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 24 times.
28 if (!result) {
125
1/1
✓ Branch 1 taken 4 times.
4 result = "Standard62.1VentilationRateProcedure";
126 }
127
128
2/2
✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
56 return result.get();
129 28 }
130
131 6 bool ControllerMechanicalVentilation_Impl::isSystemOutdoorAirMethodDefaulted() const {
132 6 return isEmpty(OS_Controller_MechanicalVentilationFields::SystemOutdoorAirMethod);
133 }
134
135 250 bool ControllerMechanicalVentilation_Impl::setAvailabilitySchedule(Schedule& schedule) {
136
3/3
✓ Branch 1 taken 250 times.
✓ Branch 4 taken 250 times.
✓ Branch 7 taken 250 times.
1000 bool result = setSchedule(OS_Controller_MechanicalVentilationFields::AvailabilitySchedule, "ControllerMechanicalVentilation",
137 "Availability Schedule", schedule);
138 250 return result;
139 }
140
141 ✗ bool ControllerMechanicalVentilation_Impl::setDemandControlledVentilation(bool demandControlledVentilation) {
142 ✗ return setBooleanFieldValue(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation, demandControlledVentilation);
143 //if (demandControlledVentilation) {
144 // setBooleanFieldValue(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation, true);
145 //} else {
146 // setBooleanFieldValue(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation, false);
147 //}
148 }
149
150 ✗ void ControllerMechanicalVentilation_Impl::resetDemandControlledVentilation() {
151 ✗ bool result = setString(OS_Controller_MechanicalVentilationFields::DemandControlledVentilation, "");
152 ✗ OS_ASSERT(result);
153 ✗ }
154
155 2 bool ControllerMechanicalVentilation_Impl::setSystemOutdoorAirMethod(const std::string& systemOutdoorAirMethod) {
156 2 bool result = setString(OS_Controller_MechanicalVentilationFields::SystemOutdoorAirMethod, systemOutdoorAirMethod);
157 2 return result;
158 }
159
160 ✗ void ControllerMechanicalVentilation_Impl::resetSystemOutdoorAirMethod() {
161 ✗ bool result = setString(OS_Controller_MechanicalVentilationFields::SystemOutdoorAirMethod, "");
162 ✗ OS_ASSERT(result);
163 ✗ }
164
165 18 boost::optional<Schedule> ControllerMechanicalVentilation_Impl::optionalAvailabilitySchedule() const {
166
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
18 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_Controller_MechanicalVentilationFields::AvailabilitySchedule);
167 }
168
169 13 std::vector<std::string> ControllerMechanicalVentilation_Impl::systemOutdoorAirMethodValues() const {
170 13 return ControllerMechanicalVentilation::systemOutdoorAirMethodValues();
171 }
172
173 ✗ boost::optional<ModelObject> ControllerMechanicalVentilation_Impl::availabilityScheduleAsModelObject() const {
174 ✗ OptionalModelObject result = availabilitySchedule();
175 ✗ return result;
176 }
177
178 ✗ bool ControllerMechanicalVentilation_Impl::setAvailabilityScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) {
179 ✗ if (modelObject) {
180 ✗ OptionalSchedule intermediate = modelObject->optionalCast<Schedule>();
181 ✗ if (intermediate) {
182 ✗ Schedule schedule(*intermediate);
183 ✗ return setAvailabilitySchedule(schedule);
184 ✗ }
185 ✗ }
186 ✗ return false;
187 }
188
189 103 ControllerOutdoorAir ControllerMechanicalVentilation_Impl::controllerOutdoorAir() const {
190
191
2/2
✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
103 std::vector<ControllerOutdoorAir> controllers = model().getConcreteModelObjects<ControllerOutdoorAir>();
192
193
2/2
✓ Branch 5 taken 106 times.
✓ Branch 6 taken 1 time.
107 for (const auto& controller : controllers) {
194
6/6
✓ Branch 1 taken 106 times.
✓ Branch 4 taken 106 times.
✓ Branch 7 taken 106 times.
✓ Branch 10 taken 106 times.
✓ Branch 13 taken 102 times.
✓ Branch 14 taken 4 times.
106 if (controller.controllerMechanicalVentilation().handle() == handle()) {
195
1/1
✓ Branch 1 taken 102 times.
204 return controller;
196 }
197 }
198
199
17/17
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
✓ Branch 44 taken 1 time.
✓ Branch 47 taken 1 time.
✓ Branch 52 taken 1 time.
✓ Branch 55 taken 1 time.
1 LOG_AND_THROW(briefDescription() << " does not have a ControllerOutdoorAir assigned");
200 103 }
201
202 61 bool ControllerMechanicalVentilation_Impl::hasZonesWithDesignSpecificationOutdoorAir() const {
203
1/1
✓ Branch 1 taken 61 times.
61 auto oa_controller = controllerOutdoorAir();
204
2/3
✓ Branch 1 taken 61 times.
✓ Branch 3 taken 61 times.
✗ Branch 4 not taken.
122 if (auto oa_sys_ = oa_controller.airLoopHVACOutdoorAirSystem()) {
205
3/4
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
✓ Branch 6 taken 61 times.
✗ Branch 7 not taken.
122 if (auto a_ = oa_sys_->airLoopHVAC()) {
206
2/2
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
61 auto zones = a_->thermalZones();
207
2/2
✓ Branch 1 taken 55 times.
✓ Branch 8 taken 61 times.
116 return std::any_of(zones.cbegin(), zones.cend(), [](const auto& z) { return !z.spacesWithDesignSpecificationOutdoorAir().empty(); });
208 122 }
209 61 }
210 ✗ return false;
211 61 }
212
213 } // namespace detail
214
215 250 ControllerMechanicalVentilation::ControllerMechanicalVentilation(const Model& model)
216 250 : ModelObject(ControllerMechanicalVentilation::iddObjectType(), model) {
217
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 250 times.
✗ Branch 5 not taken.
250 OS_ASSERT(getImpl<detail::ControllerMechanicalVentilation_Impl>());
218
219
1/1
✓ Branch 1 taken 250 times.
250 Schedule schedule = model.alwaysOnDiscreteSchedule();
220
1/1
✓ Branch 1 taken 250 times.
250 setAvailabilitySchedule(schedule);
221 250 }
222
223 8329 IddObjectType ControllerMechanicalVentilation::iddObjectType() {
224
1/1
✓ Branch 1 taken 8329 times.
8329 return {IddObjectType::OS_Controller_MechanicalVentilation};
225 }
226
227 13 std::vector<std::string> ControllerMechanicalVentilation::systemOutdoorAirMethodValues() {
228
5/5
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
✓ Branch 10 taken 13 times.
✓ Branch 13 taken 13 times.
13 return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Controller_MechanicalVentilationFields::SystemOutdoorAirMethod);
229 }
230
231 18 Schedule ControllerMechanicalVentilation::availabilitySchedule() const {
232
1/1
✓ Branch 3 taken 18 times.
18 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->availabilitySchedule();
233 }
234
235 71 bool ControllerMechanicalVentilation::demandControlledVentilation() const {
236
1/1
✓ Branch 3 taken 71 times.
71 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->demandControlledVentilation();
237 }
238
239 ✗ bool ControllerMechanicalVentilation::isDemandControlledVentilationDefaulted() const {
240 ✗ return getImpl<detail::ControllerMechanicalVentilation_Impl>()->isDemandControlledVentilationDefaulted();
241 }
242
243 28 std::string ControllerMechanicalVentilation::systemOutdoorAirMethod() const {
244
1/1
✓ Branch 3 taken 28 times.
28 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->systemOutdoorAirMethod();
245 }
246
247 6 bool ControllerMechanicalVentilation::isSystemOutdoorAirMethodDefaulted() const {
248
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->isSystemOutdoorAirMethodDefaulted();
249 }
250
251 250 bool ControllerMechanicalVentilation::setAvailabilitySchedule(Schedule& schedule) {
252
1/1
✓ Branch 3 taken 250 times.
250 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->setAvailabilitySchedule(schedule);
253 }
254
255 ✗ bool ControllerMechanicalVentilation::setDemandControlledVentilation(bool demandControlledVentilation) {
256 ✗ return getImpl<detail::ControllerMechanicalVentilation_Impl>()->setDemandControlledVentilation(demandControlledVentilation);
257 }
258
259 ✗ void ControllerMechanicalVentilation::setDemandControlledVentilationNoFail(bool demandControlledVentilation) {
260 ✗ bool result = getImpl<detail::ControllerMechanicalVentilation_Impl>()->setDemandControlledVentilation(demandControlledVentilation);
261 ✗ OS_ASSERT(result);
262 ✗ }
263
264 ✗ void ControllerMechanicalVentilation::resetDemandControlledVentilation() {
265 ✗ getImpl<detail::ControllerMechanicalVentilation_Impl>()->resetDemandControlledVentilation();
266 ✗ }
267
268 2 bool ControllerMechanicalVentilation::setSystemOutdoorAirMethod(const std::string& systemOutdoorAirMethod) {
269
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->setSystemOutdoorAirMethod(systemOutdoorAirMethod);
270 }
271
272 ✗ void ControllerMechanicalVentilation::resetSystemOutdoorAirMethod() {
273 ✗ getImpl<detail::ControllerMechanicalVentilation_Impl>()->resetSystemOutdoorAirMethod();
274 ✗ }
275
276 26 ControllerOutdoorAir ControllerMechanicalVentilation::controllerOutdoorAir() const {
277
1/1
✓ Branch 3 taken 26 times.
26 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->controllerOutdoorAir();
278 }
279
280 61 bool ControllerMechanicalVentilation::hasZonesWithDesignSpecificationOutdoorAir() const {
281
1/1
✓ Branch 3 taken 61 times.
61 return getImpl<detail::ControllerMechanicalVentilation_Impl>()->hasZonesWithDesignSpecificationOutdoorAir();
282 }
283
284 /// @cond
285 306 ControllerMechanicalVentilation::ControllerMechanicalVentilation(std::shared_ptr<detail::ControllerMechanicalVentilation_Impl> impl)
286
1/1
✓ Branch 3 taken 306 times.
306 : ModelObject(std::move(impl)) {}
287 /// @endcond
288
289 } // namespace model
290 } // namespace openstudio
291