GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 73.8% 149 / 0 / 202
Functions: 70.2% 40 / 0 / 57
Branches: 59.8% 110 / 0 / 184

src/model/CurveLinear.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 "CurveLinear.hpp"
7 #include "CurveLinear_Impl.hpp"
8
9 #include <utilities/idd/IddFactory.hxx>
10
11 #include <utilities/idd/OS_Curve_Linear_FieldEnums.hxx>
12 #include <utilities/idd/IddEnums.hxx>
13
14 #include "../utilities/core/Assert.hpp"
15
16 #include <cmath>
17
18 using namespace std;
19
20 namespace openstudio {
21 namespace model {
22
23 namespace detail {
24
25 157 CurveLinear_Impl::CurveLinear_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : Curve_Impl(idfObject, model, keepHandle) {
26
4/6
✓ Branch 1 taken 157 times.
✓ Branch 4 taken 157 times.
✓ Branch 7 taken 157 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 157 times.
✗ Branch 13 not taken.
157 OS_ASSERT(idfObject.iddObject().type() == CurveLinear::iddObjectType());
27 157 }
28
29 17 CurveLinear_Impl::CurveLinear_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
30 17 : Curve_Impl(other, model, keepHandle) {
31
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() == CurveLinear::iddObjectType());
32 17 }
33
34 71 CurveLinear_Impl::CurveLinear_Impl(const CurveLinear_Impl& other, Model_Impl* model, bool keepHandle) : Curve_Impl(other, model, keepHandle) {}
35
36 ✗ const std::vector<std::string>& CurveLinear_Impl::outputVariableNames() const {
37 ✗ static const std::vector<std::string> result{"Performance Curve Output Value", "Performance Curve Input Variable 1 Value"};
38 ✗ return result;
39 ✗ }
40
41 ✗ IddObjectType CurveLinear_Impl::iddObjectType() const {
42 ✗ return CurveLinear::iddObjectType();
43 }
44
45 ✗ int CurveLinear_Impl::numVariables() const {
46 ✗ return 1;
47 }
48
49 8 double CurveLinear_Impl::evaluate(const std::vector<double>& independentVariables) const {
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 OS_ASSERT(independentVariables.size() == 1u);
51
52 8 double x = independentVariables[0];
53
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
8 if (x < minimumValueofx()) {
54
5/5
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
2 LOG(Warn, "Supplied x is below the minimumValueofx, resetting it.");
55 2 x = minimumValueofx();
56 }
57
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
8 if (x > maximumValueofx()) {
58
5/5
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
2 LOG(Warn, "Supplied x is above the maximumValueofx, resetting it.");
59 2 x = maximumValueofx();
60 }
61
62 8 double result = coefficient1Constant();
63 8 result += coefficient2x() * x;
64
65
3/3
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 6 times.
16 if (boost::optional<double> _minVal = minimumCurveOutput()) {
66
1/1
✓ Branch 1 taken 2 times.
2 double minVal = _minVal.get();
67
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (result < minVal) {
68
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
1 LOG(Warn, "Calculated curve output is below minimumCurveOutput, resetting it.");
69 1 result = minVal;
70 }
71 }
72
73
3/3
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 6 times.
16 if (boost::optional<double> _maxVal = maximumCurveOutput()) {
74
1/1
✓ Branch 1 taken 2 times.
2 double maxVal = _maxVal.get();
75
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (result > maxVal) {
76
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
1 LOG(Warn, "Calculated curve output is above maximumCurveOutput, resetting it.");
77 1 result = maxVal;
78 }
79 }
80
81 8 return result;
82 }
83
84 55 double CurveLinear_Impl::coefficient1Constant() const {
85
1/1
✓ Branch 1 taken 55 times.
55 boost::optional<double> value = getDouble(OS_Curve_LinearFields::Coefficient1Constant, true);
86
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 4 not taken.
55 OS_ASSERT(value);
87
1/1
✓ Branch 1 taken 55 times.
110 return value.get();
88 }
89
90 55 double CurveLinear_Impl::coefficient2x() const {
91
1/1
✓ Branch 1 taken 55 times.
55 boost::optional<double> value = getDouble(OS_Curve_LinearFields::Coefficient2x, true);
92
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 4 not taken.
55 OS_ASSERT(value);
93
1/1
✓ Branch 1 taken 55 times.
110 return value.get();
94 }
95
96 56 double CurveLinear_Impl::minimumValueofx() const {
97
1/1
✓ Branch 1 taken 56 times.
56 boost::optional<double> value = getDouble(OS_Curve_LinearFields::MinimumValueofx, true);
98
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 4 not taken.
56 OS_ASSERT(value);
99
1/1
✓ Branch 1 taken 56 times.
112 return value.get();
100 }
101
102 56 double CurveLinear_Impl::maximumValueofx() const {
103
1/1
✓ Branch 1 taken 56 times.
56 boost::optional<double> value = getDouble(OS_Curve_LinearFields::MaximumValueofx, true);
104
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 4 not taken.
56 OS_ASSERT(value);
105
1/1
✓ Branch 1 taken 56 times.
112 return value.get();
106 }
107
108 55 boost::optional<double> CurveLinear_Impl::minimumCurveOutput() const {
109 55 return getDouble(OS_Curve_LinearFields::MinimumCurveOutput, true);
110 }
111
112 55 boost::optional<double> CurveLinear_Impl::maximumCurveOutput() const {
113 55 return getDouble(OS_Curve_LinearFields::MaximumCurveOutput, true);
114 }
115
116 13 std::string CurveLinear_Impl::inputUnitTypeforX() const {
117
1/1
✓ Branch 1 taken 13 times.
13 boost::optional<std::string> value = getString(OS_Curve_LinearFields::InputUnitTypeforX, true);
118
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 4 not taken.
13 OS_ASSERT(value);
119
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
26 return value.get();
120 13 }
121
122 44 bool CurveLinear_Impl::isInputUnitTypeforXDefaulted() const {
123 44 return isEmpty(OS_Curve_LinearFields::InputUnitTypeforX);
124 }
125
126 13 std::string CurveLinear_Impl::outputUnitType() const {
127
1/1
✓ Branch 1 taken 13 times.
13 boost::optional<std::string> value = getString(OS_Curve_LinearFields::OutputUnitType, true);
128
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 4 not taken.
13 OS_ASSERT(value);
129
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
26 return value.get();
130 13 }
131
132 44 bool CurveLinear_Impl::isOutputUnitTypeDefaulted() const {
133 44 return isEmpty(OS_Curve_LinearFields::OutputUnitType);
134 }
135
136 70 bool CurveLinear_Impl::setCoefficient1Constant(double coefficient1Constant) {
137 70 bool result = setDouble(OS_Curve_LinearFields::Coefficient1Constant, coefficient1Constant);
138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 OS_ASSERT(result);
139 70 return result;
140 }
141
142 70 bool CurveLinear_Impl::setCoefficient2x(double coefficient2x) {
143 70 bool result = setDouble(OS_Curve_LinearFields::Coefficient2x, coefficient2x);
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 OS_ASSERT(result);
145 70 return result;
146 }
147
148 68 bool CurveLinear_Impl::setMinimumValueofx(double minimumValueofx) {
149 68 bool result = setDouble(OS_Curve_LinearFields::MinimumValueofx, minimumValueofx);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 OS_ASSERT(result);
151 68 return result;
152 }
153
154 68 bool CurveLinear_Impl::setMaximumValueofx(double maximumValueofx) {
155 68 bool result = setDouble(OS_Curve_LinearFields::MaximumValueofx, maximumValueofx);
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 OS_ASSERT(result);
157 68 return result;
158 }
159
160 36 bool CurveLinear_Impl::setMinimumCurveOutput(boost::optional<double> minimumCurveOutput) {
161 36 bool result = false;
162
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (minimumCurveOutput) {
163 36 result = setDouble(OS_Curve_LinearFields::MinimumCurveOutput, minimumCurveOutput.get());
164 } else {
165 ✗ result = setString(OS_Curve_LinearFields::MinimumCurveOutput, "");
166 }
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 OS_ASSERT(result);
168 36 return result;
169 }
170
171 ✗ void CurveLinear_Impl::resetMinimumCurveOutput() {
172 ✗ bool result = setString(OS_Curve_LinearFields::MinimumCurveOutput, "");
173 ✗ OS_ASSERT(result);
174 ✗ }
175
176 36 bool CurveLinear_Impl::setMaximumCurveOutput(boost::optional<double> maximumCurveOutput) {
177 36 bool result = false;
178
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (maximumCurveOutput) {
179 36 result = setDouble(OS_Curve_LinearFields::MaximumCurveOutput, maximumCurveOutput.get());
180 } else {
181 ✗ result = setString(OS_Curve_LinearFields::MaximumCurveOutput, "");
182 }
183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 OS_ASSERT(result);
184 36 return result;
185 }
186
187 ✗ void CurveLinear_Impl::resetMaximumCurveOutput() {
188 ✗ bool result = setString(OS_Curve_LinearFields::MaximumCurveOutput, "");
189 ✗ OS_ASSERT(result);
190 ✗ }
191
192 ✗ bool CurveLinear_Impl::setInputUnitTypeforX(const std::string& inputUnitTypeforX) {
193 ✗ bool result = setString(OS_Curve_LinearFields::InputUnitTypeforX, inputUnitTypeforX);
194 ✗ return result;
195 }
196
197 ✗ void CurveLinear_Impl::resetInputUnitTypeforX() {
198 ✗ bool result = setString(OS_Curve_LinearFields::InputUnitTypeforX, "");
199 ✗ OS_ASSERT(result);
200 ✗ }
201
202 ✗ bool CurveLinear_Impl::setOutputUnitType(const std::string& outputUnitType) {
203 ✗ bool result = setString(OS_Curve_LinearFields::OutputUnitType, outputUnitType);
204 ✗ return result;
205 }
206
207 ✗ void CurveLinear_Impl::resetOutputUnitType() {
208 ✗ bool result = setString(OS_Curve_LinearFields::OutputUnitType, "");
209 ✗ OS_ASSERT(result);
210 ✗ }
211
212 } // namespace detail
213
214 140 CurveLinear::CurveLinear(const Model& model) : Curve(CurveLinear::iddObjectType(), model) {
215
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 140 times.
✗ Branch 5 not taken.
140 OS_ASSERT(getImpl<detail::CurveLinear_Impl>());
216
1/1
✓ Branch 1 taken 140 times.
140 setDouble(OS_Curve_LinearFields::Coefficient1Constant, 0.0);
217
1/1
✓ Branch 1 taken 140 times.
140 setDouble(OS_Curve_LinearFields::Coefficient2x, 1.0);
218
1/1
✓ Branch 1 taken 140 times.
140 setDouble(OS_Curve_LinearFields::MinimumValueofx, 0.0);
219
1/1
✓ Branch 1 taken 140 times.
140 setDouble(OS_Curve_LinearFields::MaximumValueofx, 1.0);
220 140 }
221
222 33 CurveLinear CurveLinear::defaultHeatPumpCoilPLFCorrelationCurve(const Model& model, double maximumCyclingRatePerHour,
223 double heatPumpTimeConstantSeconds) {
224 33 const double A = 4 * (heatPumpTimeConstantSeconds / 3600.0) * maximumCyclingRatePerHour;
225 33 const double Cd = A * (1 - std::exp(-1 / A));
226
227 33 CurveLinear c(model);
228
2/2
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
66 c.setName("PLFCorrelationCurve");
229
230
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::Coefficient1Constant, (1 - Cd));
231
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::Coefficient2x, Cd);
232
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::MinimumValueofx, 0.0);
233
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::MaximumValueofx, 1.0);
234
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::MinimumCurveOutput, 0.0);
235
1/1
✓ Branch 1 taken 33 times.
33 c.setDouble(OS_Curve_LinearFields::MaximumCurveOutput, 1.0);
236
2/2
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
66 c.setString(OS_Curve_LinearFields::InputUnitTypeforX, "Dimensionless");
237
2/2
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
66 c.setString(OS_Curve_LinearFields::OutputUnitType, "Dimensionless");
238 33 return c;
239 ✗ }
240
241 8050 IddObjectType CurveLinear::iddObjectType() {
242
1/1
✓ Branch 1 taken 8050 times.
8050 IddObjectType result(IddObjectType::OS_Curve_Linear);
243 8050 return result;
244 }
245
246 ✗ std::vector<std::string> CurveLinear::validInputUnitTypeforXValues() {
247 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Curve_LinearFields::InputUnitTypeforX);
248 }
249
250 ✗ std::vector<std::string> CurveLinear::validOutputUnitTypeValues() {
251 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Curve_LinearFields::OutputUnitType);
252 }
253
254 47 double CurveLinear::coefficient1Constant() const {
255
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::CurveLinear_Impl>()->coefficient1Constant();
256 }
257
258 47 double CurveLinear::coefficient2x() const {
259
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::CurveLinear_Impl>()->coefficient2x();
260 }
261
262 46 double CurveLinear::minimumValueofx() const {
263
1/1
✓ Branch 3 taken 46 times.
46 return getImpl<detail::CurveLinear_Impl>()->minimumValueofx();
264 }
265
266 46 double CurveLinear::maximumValueofx() const {
267
1/1
✓ Branch 3 taken 46 times.
46 return getImpl<detail::CurveLinear_Impl>()->maximumValueofx();
268 }
269
270 47 boost::optional<double> CurveLinear::minimumCurveOutput() const {
271
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::CurveLinear_Impl>()->minimumCurveOutput();
272 }
273
274 47 boost::optional<double> CurveLinear::maximumCurveOutput() const {
275
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::CurveLinear_Impl>()->maximumCurveOutput();
276 }
277
278 13 std::string CurveLinear::inputUnitTypeforX() const {
279
1/1
✓ Branch 3 taken 13 times.
13 return getImpl<detail::CurveLinear_Impl>()->inputUnitTypeforX();
280 }
281
282 44 bool CurveLinear::isInputUnitTypeforXDefaulted() const {
283
1/1
✓ Branch 3 taken 44 times.
44 return getImpl<detail::CurveLinear_Impl>()->isInputUnitTypeforXDefaulted();
284 }
285
286 13 std::string CurveLinear::outputUnitType() const {
287
1/1
✓ Branch 3 taken 13 times.
13 return getImpl<detail::CurveLinear_Impl>()->outputUnitType();
288 }
289
290 44 bool CurveLinear::isOutputUnitTypeDefaulted() const {
291
1/1
✓ Branch 3 taken 44 times.
44 return getImpl<detail::CurveLinear_Impl>()->isOutputUnitTypeDefaulted();
292 }
293
294 70 bool CurveLinear::setCoefficient1Constant(double coefficient1Constant) {
295
1/1
✓ Branch 3 taken 70 times.
70 return getImpl<detail::CurveLinear_Impl>()->setCoefficient1Constant(coefficient1Constant);
296 }
297
298 70 bool CurveLinear::setCoefficient2x(double coefficient2x) {
299
1/1
✓ Branch 3 taken 70 times.
70 return getImpl<detail::CurveLinear_Impl>()->setCoefficient2x(coefficient2x);
300 }
301
302 68 bool CurveLinear::setMinimumValueofx(double minimumValueofx) {
303
1/1
✓ Branch 3 taken 68 times.
68 return getImpl<detail::CurveLinear_Impl>()->setMinimumValueofx(minimumValueofx);
304 }
305
306 68 bool CurveLinear::setMaximumValueofx(double maximumValueofx) {
307
1/1
✓ Branch 3 taken 68 times.
68 return getImpl<detail::CurveLinear_Impl>()->setMaximumValueofx(maximumValueofx);
308 }
309
310 36 bool CurveLinear::setMinimumCurveOutput(double minimumCurveOutput) {
311
2/2
✓ Branch 3 taken 36 times.
✓ Branch 6 taken 36 times.
36 return getImpl<detail::CurveLinear_Impl>()->setMinimumCurveOutput(minimumCurveOutput);
312 }
313
314 ✗ void CurveLinear::resetMinimumCurveOutput() {
315 ✗ getImpl<detail::CurveLinear_Impl>()->resetMinimumCurveOutput();
316 ✗ }
317
318 36 bool CurveLinear::setMaximumCurveOutput(double maximumCurveOutput) {
319
2/2
✓ Branch 3 taken 36 times.
✓ Branch 6 taken 36 times.
36 return getImpl<detail::CurveLinear_Impl>()->setMaximumCurveOutput(maximumCurveOutput);
320 }
321
322 ✗ void CurveLinear::resetMaximumCurveOutput() {
323 ✗ getImpl<detail::CurveLinear_Impl>()->resetMaximumCurveOutput();
324 ✗ }
325
326 ✗ bool CurveLinear::setInputUnitTypeforX(const std::string& inputUnitTypeforX) {
327 ✗ return getImpl<detail::CurveLinear_Impl>()->setInputUnitTypeforX(inputUnitTypeforX);
328 }
329
330 ✗ void CurveLinear::resetInputUnitTypeforX() {
331 ✗ getImpl<detail::CurveLinear_Impl>()->resetInputUnitTypeforX();
332 ✗ }
333
334 ✗ bool CurveLinear::setOutputUnitType(const std::string& outputUnitType) {
335 ✗ return getImpl<detail::CurveLinear_Impl>()->setOutputUnitType(outputUnitType);
336 }
337
338 ✗ void CurveLinear::resetOutputUnitType() {
339 ✗ getImpl<detail::CurveLinear_Impl>()->resetOutputUnitType();
340 ✗ }
341
342 /// @cond
343
1/1
✓ Branch 3 taken 70 times.
70 CurveLinear::CurveLinear(std::shared_ptr<detail::CurveLinear_Impl> impl) : Curve(std::move(impl)) {}
344 /// @endcond
345
346 } // namespace model
347 } // namespace openstudio
348