GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 72.9% 121 / 0 / 166
Functions: 77.8% 35 / 0 / 45
Branches: 44.5% 89 / 0 / 200

src/model/LoadProfilePlant.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 "LoadProfilePlant.hpp"
7 #include "LoadProfilePlant_Impl.hpp"
8
9 #include "Schedule.hpp"
10 #include "Schedule_Impl.hpp"
11 #include "ScheduleRuleset.hpp"
12 #include "ScheduleDay.hpp"
13 #include "Model.hpp"
14 #include "Model_Impl.hpp"
15 #include "Node.hpp"
16 #include "Node_Impl.hpp"
17 #include "PlantLoop.hpp"
18 #include "PlantLoop_Impl.hpp"
19 #include "ScheduleTypeLimits.hpp"
20 #include "ScheduleTypeRegistry.hpp"
21
22 #include "../utilities/core/Assert.hpp"
23 #include "../utilities/data/DataEnums.hpp"
24 #include "../utilities/time/Time.hpp"
25
26 #include <utilities/idd/IddEnums.hxx>
27 #include <utilities/idd/OS_LoadProfile_Plant_FieldEnums.hxx>
28
29 namespace openstudio {
30 namespace model {
31
32 namespace detail {
33
34 2 LoadProfilePlant_Impl::LoadProfilePlant_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
35 2 : StraightComponent_Impl(idfObject, model, keepHandle) {
36
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(idfObject.iddObject().type() == LoadProfilePlant::iddObjectType());
37 2 }
38
39 1 LoadProfilePlant_Impl::LoadProfilePlant_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
40 1 : StraightComponent_Impl(other, model, keepHandle) {
41
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
1 OS_ASSERT(other.iddObject().type() == LoadProfilePlant::iddObjectType());
42 1 }
43
44 1 LoadProfilePlant_Impl::LoadProfilePlant_Impl(const LoadProfilePlant_Impl& other, Model_Impl* model, bool keepHandle)
45 1 : StraightComponent_Impl(other, model, keepHandle) {}
46
47 ✗ const std::vector<std::string>& LoadProfilePlant_Impl::outputVariableNames() const {
48 static const std::vector<std::string> result{"Plant Load Profile Mass Flow Rate", "Plant Load Profile Heat Transfer Rate",
49 "Plant Load Profile Heat Transfer Energy", "Plant Load Profile Heating Energy",
50 ✗ "Plant Load Profile Cooling Energy"};
51 ✗ return result;
52 ✗ }
53
54 ✗ IddObjectType LoadProfilePlant_Impl::iddObjectType() const {
55 ✗ return LoadProfilePlant::iddObjectType();
56 }
57
58 ✗ std::vector<ScheduleTypeKey> LoadProfilePlant_Impl::getScheduleTypeKeys(const Schedule& schedule) const {
59 // TODO: Check schedule display names.
60 ✗ std::vector<ScheduleTypeKey> result;
61 ✗ UnsignedVector fieldIndices = getSourceIndices(schedule.handle());
62 ✗ UnsignedVector::const_iterator b(fieldIndices.begin());
63 ✗ UnsignedVector::const_iterator e(fieldIndices.end());
64 ✗ if (std::find(b, e, OS_LoadProfile_PlantFields::LoadScheduleName) != e) {
65 ✗ result.push_back(ScheduleTypeKey("LoadProfilePlant", "Load"));
66 }
67 ✗ if (std::find(b, e, OS_LoadProfile_PlantFields::FlowRateFractionScheduleName) != e) {
68 ✗ result.push_back(ScheduleTypeKey("LoadProfilePlant", "Flow Rate Fraction"));
69 }
70 ✗ return result;
71 ✗ }
72
73 3 unsigned LoadProfilePlant_Impl::inletPort() const {
74 3 return OS_LoadProfile_PlantFields::InletNodeName;
75 }
76
77 5 unsigned LoadProfilePlant_Impl::outletPort() const {
78 5 return OS_LoadProfile_PlantFields::OutletNodeName;
79 }
80
81 1 Schedule LoadProfilePlant_Impl::loadSchedule() const {
82
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<Schedule> value = optionalLoadSchedule();
83
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!value) {
84 ✗ LOG_AND_THROW(briefDescription() << " does not have an Load Schedule attached.");
85 }
86
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 return value.get();
87 1 }
88
89 1 double LoadProfilePlant_Impl::peakFlowRate() const {
90
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<double> value = getDouble(OS_LoadProfile_PlantFields::PeakFlowRate, true);
91
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(value);
92
1/1
✓ Branch 1 taken 1 time.
2 return value.get();
93 }
94
95 1 Schedule LoadProfilePlant_Impl::flowRateFractionSchedule() const {
96
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<Schedule> value = optionalFlowRateFractionSchedule();
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!value) {
98 ✗ LOG_AND_THROW(briefDescription() << " does not have an Flow Rate Fraction Schedule attached.");
99 }
100
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 return value.get();
101 1 }
102
103 1 std::string LoadProfilePlant_Impl::plantLoopFluidType() const {
104
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<std::string> value = getString(OS_LoadProfile_PlantFields::PlantLoopFluidType, true);
105
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(value);
106
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 return value.get();
107 1 }
108
109 1 double LoadProfilePlant_Impl::degreeofSubCooling() const {
110
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<double> value = getDouble(OS_LoadProfile_PlantFields::DegreeofSubCooling, true);
111
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(value);
112
1/1
✓ Branch 1 taken 1 time.
2 return value.get();
113 }
114
115 1 double LoadProfilePlant_Impl::degreeofLoopSubCooling() const {
116
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<double> value = getDouble(OS_LoadProfile_PlantFields::DegreeofLoopSubCooling, true);
117
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(value);
118
1/1
✓ Branch 1 taken 1 time.
2 return value.get();
119 }
120
121 2 bool LoadProfilePlant_Impl::setLoadSchedule(Schedule& schedule) {
122
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
8 bool result = setSchedule(OS_LoadProfile_PlantFields::LoadScheduleName, "LoadProfilePlant", "Load", schedule);
123 2 return result;
124 }
125
126 2 bool LoadProfilePlant_Impl::setPeakFlowRate(double peakFlowRate) {
127 2 bool result = setDouble(OS_LoadProfile_PlantFields::PeakFlowRate, peakFlowRate);
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 OS_ASSERT(result);
129 2 return result;
130 }
131
132 2 bool LoadProfilePlant_Impl::setFlowRateFractionSchedule(Schedule& schedule) {
133
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
8 bool result = setSchedule(OS_LoadProfile_PlantFields::FlowRateFractionScheduleName, "LoadProfilePlant", "Flow Rate Fraction", schedule);
134 2 return result;
135 }
136
137 1 boost::optional<Schedule> LoadProfilePlant_Impl::optionalLoadSchedule() const {
138
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_LoadProfile_PlantFields::LoadScheduleName);
139 }
140
141 1 boost::optional<Schedule> LoadProfilePlant_Impl::optionalFlowRateFractionSchedule() const {
142
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_LoadProfile_PlantFields::FlowRateFractionScheduleName);
143 }
144
145 2 bool LoadProfilePlant_Impl::setPlantLoopFluidType(const std::string& plantLoopFluidType) {
146 2 bool result = setString(OS_LoadProfile_PlantFields::PlantLoopFluidType, plantLoopFluidType);
147 2 return result;
148 }
149
150 2 bool LoadProfilePlant_Impl::setDegreeofSubCooling(double degreeofSubCooling) {
151 2 bool result = setDouble(OS_LoadProfile_PlantFields::DegreeofSubCooling, degreeofSubCooling);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 OS_ASSERT(result);
153 2 return result;
154 }
155
156 2 bool LoadProfilePlant_Impl::setDegreeofLoopSubCooling(double degreeofLoopSubCooling) {
157 2 bool result = setDouble(OS_LoadProfile_PlantFields::DegreeofLoopSubCooling, degreeofLoopSubCooling);
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 OS_ASSERT(result);
159 2 return result;
160 }
161
162 1 bool LoadProfilePlant_Impl::addToNode(Node& node) {
163
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
2 if (auto plant = node.plantLoop()) {
164
4/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
2 if (plant->demandComponent(node.handle())) {
165
1/1
✓ Branch 1 taken 1 time.
1 return StraightComponent_Impl::addToNode(node);
166 }
167 1 }
168 ✗ return false;
169 }
170
171 ✗ std::vector<EMSActuatorNames> LoadProfilePlant_Impl::emsActuatorNames() const {
172 ✗ std::vector<EMSActuatorNames> actuators{{"Plant Load Profile", "Mass Flow Rate"}, {"Plant Load Profile", "Power"}};
173 ✗ return actuators;
174 ✗ }
175
176 ✗ std::vector<std::string> LoadProfilePlant_Impl::emsInternalVariableNames() const {
177 ✗ std::vector<std::string> types;
178 ✗ return types;
179 }
180
181 ✗ ComponentType LoadProfilePlant_Impl::componentType() const {
182 ✗ return ComponentType::None;
183 }
184
185 ✗ std::vector<FuelType> LoadProfilePlant_Impl::coolingFuelTypes() const {
186 ✗ return {};
187 }
188
189 ✗ std::vector<FuelType> LoadProfilePlant_Impl::heatingFuelTypes() const {
190 ✗ return {};
191 }
192
193 ✗ std::vector<AppGFuelType> LoadProfilePlant_Impl::appGHeatingFuelTypes() const {
194 ✗ return {};
195 }
196
197 } // namespace detail
198
199 1 LoadProfilePlant::LoadProfilePlant(const Model& model) : StraightComponent(LoadProfilePlant::iddObjectType(), model) {
200
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 5 not taken.
1 OS_ASSERT(getImpl<detail::LoadProfilePlant_Impl>());
201
202
1/1
✓ Branch 1 taken 1 time.
1 auto alwaysOn = model.alwaysOnDiscreteSchedule();
203
204
1/1
✓ Branch 1 taken 1 time.
1 auto scheduleRuleset = ScheduleRuleset(model);
205
1/1
✓ Branch 1 taken 1 time.
1 auto scheduleDay = scheduleRuleset.defaultDaySchedule();
206
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 scheduleDay.addValue(Time(0, 4), 8000);
207
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 scheduleDay.addValue(Time(0, 8), 6000);
208
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 scheduleDay.addValue(Time(0, 9), 0);
209
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 scheduleDay.addValue(Time(0, 12), 6000);
210
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 scheduleDay.addValue(Time(0, 24), 10000);
211
212 1 bool ok = true;
213
1/1
✓ Branch 1 taken 1 time.
1 ok = setLoadSchedule(scheduleRuleset);
214
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
215
1/1
✓ Branch 1 taken 1 time.
1 setPeakFlowRate(0.002);
216
1/1
✓ Branch 1 taken 1 time.
1 ok = setFlowRateFractionSchedule(alwaysOn);
217
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
218
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 ok = setPlantLoopFluidType("Water");
219
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
220
1/1
✓ Branch 1 taken 1 time.
1 ok = setDegreeofSubCooling(5.0);
221
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
222
1/1
✓ Branch 1 taken 1 time.
1 ok = setDegreeofLoopSubCooling(20.0);
223
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
224 1 }
225
226 ✗ LoadProfilePlant::LoadProfilePlant(const Model& model, Schedule& loadSchedule, Schedule& flowRateFractionSchedule)
227 ✗ : StraightComponent(LoadProfilePlant::iddObjectType(), model) {
228 ✗ OS_ASSERT(getImpl<detail::LoadProfilePlant_Impl>());
229
230 ✗ setLoadSchedule(loadSchedule);
231 ✗ setPeakFlowRate(0.0);
232 ✗ setFlowRateFractionSchedule(flowRateFractionSchedule);
233 ✗ setPlantLoopFluidType("Water");
234 ✗ setDegreeofSubCooling(5.0);
235 ✗ setDegreeofLoopSubCooling(20.0);
236 ✗ }
237
238 7602 IddObjectType LoadProfilePlant::iddObjectType() {
239
1/1
✓ Branch 1 taken 7602 times.
7602 return {IddObjectType::OS_LoadProfile_Plant};
240 }
241
242 1 Schedule LoadProfilePlant::loadSchedule() const {
243
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->loadSchedule();
244 }
245
246 1 double LoadProfilePlant::peakFlowRate() const {
247
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->peakFlowRate();
248 }
249
250 1 Schedule LoadProfilePlant::flowRateFractionSchedule() const {
251
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->flowRateFractionSchedule();
252 }
253
254 1 std::string LoadProfilePlant::plantLoopFluidType() const {
255
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->plantLoopFluidType();
256 }
257
258 1 double LoadProfilePlant::degreeofSubCooling() const {
259
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->degreeofSubCooling();
260 }
261
262 1 double LoadProfilePlant::degreeofLoopSubCooling() const {
263
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::LoadProfilePlant_Impl>()->degreeofLoopSubCooling();
264 }
265
266 2 bool LoadProfilePlant::setLoadSchedule(Schedule& schedule) {
267
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setLoadSchedule(schedule);
268 }
269
270 2 bool LoadProfilePlant::setPeakFlowRate(double peakFlowRate) {
271
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setPeakFlowRate(peakFlowRate);
272 }
273
274 2 bool LoadProfilePlant::setFlowRateFractionSchedule(Schedule& schedule) {
275
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setFlowRateFractionSchedule(schedule);
276 }
277
278 2 bool LoadProfilePlant::setPlantLoopFluidType(const std::string& plantLoopFluidType) {
279
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setPlantLoopFluidType(plantLoopFluidType);
280 }
281
282 2 bool LoadProfilePlant::setDegreeofSubCooling(double degreeofSubCooling) {
283
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setDegreeofSubCooling(degreeofSubCooling);
284 }
285
286 2 bool LoadProfilePlant::setDegreeofLoopSubCooling(double degreeofLoopSubCooling) {
287
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::LoadProfilePlant_Impl>()->setDegreeofLoopSubCooling(degreeofLoopSubCooling);
288 }
289
290 /// @cond
291
1/1
✓ Branch 3 taken 1 time.
1 LoadProfilePlant::LoadProfilePlant(std::shared_ptr<detail::LoadProfilePlant_Impl> impl) : StraightComponent(std::move(impl)) {}
292 /// @endcond
293
294 } // namespace model
295 } // namespace openstudio
296