GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 69.3% 149 / 0 / 215
Functions: 67.2% 43 / 0 / 64
Branches: 53.1% 102 / 0 / 192

src/model/CurveCubic.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 "CurveCubic.hpp"
7 #include "CurveCubic_Impl.hpp"
8
9 #include <utilities/idd/IddFactory.hxx>
10
11 #include <utilities/idd/OS_Curve_Cubic_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 797 CurveCubic_Impl::CurveCubic_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : Curve_Impl(idfObject, model, keepHandle) {
26
4/6
✓ Branch 1 taken 797 times.
✓ Branch 4 taken 797 times.
✓ Branch 7 taken 797 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 797 times.
✗ Branch 13 not taken.
797 OS_ASSERT(idfObject.iddObject().type() == CurveCubic::iddObjectType());
27 797 }
28
29 103 CurveCubic_Impl::CurveCubic_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
30 103 : Curve_Impl(other, model, keepHandle) {
31
4/6
✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
✓ Branch 7 taken 103 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 103 times.
✗ Branch 13 not taken.
103 OS_ASSERT(other.iddObject().type() == CurveCubic::iddObjectType());
32 103 }
33
34 574 CurveCubic_Impl::CurveCubic_Impl(const CurveCubic_Impl& other, Model_Impl* model, bool keepHandle) : Curve_Impl(other, model, keepHandle) {}
35
36 ✗ const std::vector<std::string>& CurveCubic_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 CurveCubic_Impl::iddObjectType() const {
42 ✗ return CurveCubic::iddObjectType();
43 }
44
45 ✗ int CurveCubic_Impl::numVariables() const {
46 ✗ return 1;
47 }
48
49 8 double CurveCubic_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 8 result += coefficient3xPOW2() * std::pow(x, 2);
65 8 result += coefficient4xPOW3() * std::pow(x, 3);
66
67
3/3
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 6 times.
16 if (boost::optional<double> _minVal = minimumCurveOutput()) {
68
1/1
✓ Branch 1 taken 2 times.
2 double minVal = _minVal.get();
69
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (result < minVal) {
70
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.");
71 1 result = minVal;
72 }
73 }
74
75
3/3
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 6 times.
16 if (boost::optional<double> _maxVal = maximumCurveOutput()) {
76
1/1
✓ Branch 1 taken 2 times.
2 double maxVal = _maxVal.get();
77
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (result > maxVal) {
78
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.");
79 1 result = maxVal;
80 }
81 }
82
83 8 return result;
84 }
85
86 370 double CurveCubic_Impl::coefficient1Constant() const {
87
1/1
✓ Branch 1 taken 370 times.
370 boost::optional<double> value = getDouble(OS_Curve_CubicFields::Coefficient1Constant, true);
88
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 370 times.
✗ Branch 4 not taken.
370 OS_ASSERT(value);
89
1/1
✓ Branch 1 taken 370 times.
740 return value.get();
90 }
91
92 358 double CurveCubic_Impl::coefficient2x() const {
93
1/1
✓ Branch 1 taken 358 times.
358 boost::optional<double> value = getDouble(OS_Curve_CubicFields::Coefficient2x, true);
94
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 358 times.
✗ Branch 4 not taken.
358 OS_ASSERT(value);
95
1/1
✓ Branch 1 taken 358 times.
716 return value.get();
96 }
97
98 358 double CurveCubic_Impl::coefficient3xPOW2() const {
99
1/1
✓ Branch 1 taken 358 times.
358 boost::optional<double> value = getDouble(OS_Curve_CubicFields::Coefficient3x_POW_2, true);
100
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 358 times.
✗ Branch 4 not taken.
358 OS_ASSERT(value);
101
1/1
✓ Branch 1 taken 358 times.
716 return value.get();
102 }
103
104 360 double CurveCubic_Impl::coefficient4xPOW3() const {
105
1/1
✓ Branch 1 taken 360 times.
360 boost::optional<double> value = getDouble(OS_Curve_CubicFields::Coefficient4x_POW_3, true);
106
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 360 times.
✗ Branch 4 not taken.
360 OS_ASSERT(value);
107
1/1
✓ Branch 1 taken 360 times.
720 return value.get();
108 }
109
110 354 double CurveCubic_Impl::minimumValueofx() const {
111
1/1
✓ Branch 1 taken 354 times.
354 boost::optional<double> value = getDouble(OS_Curve_CubicFields::MinimumValueofx, true);
112
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 354 times.
✗ Branch 4 not taken.
354 OS_ASSERT(value);
113
1/1
✓ Branch 1 taken 354 times.
708 return value.get();
114 }
115
116 354 double CurveCubic_Impl::maximumValueofx() const {
117
1/1
✓ Branch 1 taken 354 times.
354 boost::optional<double> value = getDouble(OS_Curve_CubicFields::MaximumValueofx, true);
118
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 354 times.
✗ Branch 4 not taken.
354 OS_ASSERT(value);
119
1/1
✓ Branch 1 taken 354 times.
708 return value.get();
120 }
121
122 350 boost::optional<double> CurveCubic_Impl::minimumCurveOutput() const {
123 350 return getDouble(OS_Curve_CubicFields::MinimumCurveOutput, true);
124 }
125
126 350 boost::optional<double> CurveCubic_Impl::maximumCurveOutput() const {
127 350 return getDouble(OS_Curve_CubicFields::MaximumCurveOutput, true);
128 }
129
130 ✗ std::string CurveCubic_Impl::inputUnitTypeforX() const {
131 ✗ boost::optional<std::string> value = getString(OS_Curve_CubicFields::InputUnitTypeforX, true);
132 ✗ OS_ASSERT(value);
133 ✗ return value.get();
134 ✗ }
135
136 339 bool CurveCubic_Impl::isInputUnitTypeforXDefaulted() const {
137 339 return isEmpty(OS_Curve_CubicFields::InputUnitTypeforX);
138 }
139
140 ✗ std::string CurveCubic_Impl::outputUnitType() const {
141 ✗ boost::optional<std::string> value = getString(OS_Curve_CubicFields::OutputUnitType, true);
142 ✗ OS_ASSERT(value);
143 ✗ return value.get();
144 ✗ }
145
146 339 bool CurveCubic_Impl::isOutputUnitTypeDefaulted() const {
147 339 return isEmpty(OS_Curve_CubicFields::OutputUnitType);
148 }
149
150 626 bool CurveCubic_Impl::setCoefficient1Constant(double coefficient1Constant) {
151 626 bool result = setDouble(OS_Curve_CubicFields::Coefficient1Constant, coefficient1Constant);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 626 times.
626 OS_ASSERT(result);
153 626 return result;
154 }
155
156 626 bool CurveCubic_Impl::setCoefficient2x(double coefficient2x) {
157 626 bool result = setDouble(OS_Curve_CubicFields::Coefficient2x, coefficient2x);
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 626 times.
626 OS_ASSERT(result);
159 626 return result;
160 }
161
162 626 bool CurveCubic_Impl::setCoefficient3xPOW2(double coefficient3xPOW2) {
163 626 bool result = setDouble(OS_Curve_CubicFields::Coefficient3x_POW_2, coefficient3xPOW2);
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 626 times.
626 OS_ASSERT(result);
165 626 return result;
166 }
167
168 620 bool CurveCubic_Impl::setCoefficient4xPOW3(double coefficient4xPOW3) {
169 620 bool result = setDouble(OS_Curve_CubicFields::Coefficient4x_POW_3, coefficient4xPOW3);
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 620 times.
620 OS_ASSERT(result);
171 620 return result;
172 }
173
174 534 bool CurveCubic_Impl::setMinimumValueofx(double minimumValueofx) {
175 534 bool result = setDouble(OS_Curve_CubicFields::MinimumValueofx, minimumValueofx);
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 534 times.
534 OS_ASSERT(result);
177 534 return result;
178 }
179
180 496 bool CurveCubic_Impl::setMaximumValueofx(double maximumValueofx) {
181 496 bool result = setDouble(OS_Curve_CubicFields::MaximumValueofx, maximumValueofx);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 496 times.
496 OS_ASSERT(result);
183 496 return result;
184 }
185
186 5 bool CurveCubic_Impl::setMinimumCurveOutput(boost::optional<double> minimumCurveOutput) {
187 5 bool result = false;
188
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (minimumCurveOutput) {
189 5 result = setDouble(OS_Curve_CubicFields::MinimumCurveOutput, minimumCurveOutput.get());
190 } else {
191 ✗ result = setString(OS_Curve_CubicFields::MinimumCurveOutput, "");
192 }
193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 OS_ASSERT(result);
194 5 return result;
195 }
196
197 ✗ void CurveCubic_Impl::resetMinimumCurveOutput() {
198 ✗ bool result = setString(OS_Curve_CubicFields::MinimumCurveOutput, "");
199 ✗ OS_ASSERT(result);
200 ✗ }
201
202 5 bool CurveCubic_Impl::setMaximumCurveOutput(boost::optional<double> maximumCurveOutput) {
203 5 bool result = false;
204
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (maximumCurveOutput) {
205 5 result = setDouble(OS_Curve_CubicFields::MaximumCurveOutput, maximumCurveOutput.get());
206 } else {
207 ✗ result = setString(OS_Curve_CubicFields::MaximumCurveOutput, "");
208 }
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 OS_ASSERT(result);
210 5 return result;
211 }
212
213 ✗ void CurveCubic_Impl::resetMaximumCurveOutput() {
214 ✗ bool result = setString(OS_Curve_CubicFields::MaximumCurveOutput, "");
215 ✗ OS_ASSERT(result);
216 ✗ }
217
218 ✗ bool CurveCubic_Impl::setInputUnitTypeforX(const std::string& inputUnitTypeforX) {
219 ✗ bool result = setString(OS_Curve_CubicFields::InputUnitTypeforX, inputUnitTypeforX);
220 ✗ return result;
221 }
222
223 ✗ void CurveCubic_Impl::resetInputUnitTypeforX() {
224 ✗ bool result = setString(OS_Curve_CubicFields::InputUnitTypeforX, "");
225 ✗ OS_ASSERT(result);
226 ✗ }
227
228 ✗ bool CurveCubic_Impl::setOutputUnitType(const std::string& outputUnitType) {
229 ✗ bool result = setString(OS_Curve_CubicFields::OutputUnitType, outputUnitType);
230 ✗ return result;
231 }
232
233 ✗ void CurveCubic_Impl::resetOutputUnitType() {
234 ✗ bool result = setString(OS_Curve_CubicFields::OutputUnitType, "");
235 ✗ OS_ASSERT(result);
236 ✗ }
237
238 } // namespace detail
239
240 694 CurveCubic::CurveCubic(const Model& model) : Curve(CurveCubic::iddObjectType(), model) {
241
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 694 times.
✗ Branch 5 not taken.
694 OS_ASSERT(getImpl<detail::CurveCubic_Impl>());
242
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::Coefficient1Constant, 0.0);
243
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::Coefficient2x, 0.0);
244
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::Coefficient3x_POW_2, 0.0);
245
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::Coefficient4x_POW_3, 1.0);
246
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::MinimumValueofx, 0.0);
247
1/1
✓ Branch 1 taken 694 times.
694 setDouble(OS_Curve_CubicFields::MaximumValueofx, 1.0);
248 694 }
249
250 9377 IddObjectType CurveCubic::iddObjectType() {
251
1/1
✓ Branch 1 taken 9377 times.
9377 IddObjectType result(IddObjectType::OS_Curve_Cubic);
252 9377 return result;
253 }
254
255 ✗ std::vector<std::string> CurveCubic::validInputUnitTypeforXValues() {
256 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Curve_CubicFields::InputUnitTypeforX);
257 }
258
259 ✗ std::vector<std::string> CurveCubic::validOutputUnitTypeValues() {
260 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Curve_CubicFields::OutputUnitType);
261 }
262
263 362 double CurveCubic::coefficient1Constant() const {
264
1/1
✓ Branch 3 taken 362 times.
362 return getImpl<detail::CurveCubic_Impl>()->coefficient1Constant();
265 }
266
267 350 double CurveCubic::coefficient2x() const {
268
1/1
✓ Branch 3 taken 350 times.
350 return getImpl<detail::CurveCubic_Impl>()->coefficient2x();
269 }
270
271 350 double CurveCubic::coefficient3xPOW2() const {
272
1/1
✓ Branch 3 taken 350 times.
350 return getImpl<detail::CurveCubic_Impl>()->coefficient3xPOW2();
273 }
274
275 352 double CurveCubic::coefficient4xPOW3() const {
276
1/1
✓ Branch 3 taken 352 times.
352 return getImpl<detail::CurveCubic_Impl>()->coefficient4xPOW3();
277 }
278
279 344 double CurveCubic::minimumValueofx() const {
280
1/1
✓ Branch 3 taken 344 times.
344 return getImpl<detail::CurveCubic_Impl>()->minimumValueofx();
281 }
282
283 344 double CurveCubic::maximumValueofx() const {
284
1/1
✓ Branch 3 taken 344 times.
344 return getImpl<detail::CurveCubic_Impl>()->maximumValueofx();
285 }
286
287 342 boost::optional<double> CurveCubic::minimumCurveOutput() const {
288
1/1
✓ Branch 3 taken 342 times.
342 return getImpl<detail::CurveCubic_Impl>()->minimumCurveOutput();
289 }
290
291 342 boost::optional<double> CurveCubic::maximumCurveOutput() const {
292
1/1
✓ Branch 3 taken 342 times.
342 return getImpl<detail::CurveCubic_Impl>()->maximumCurveOutput();
293 }
294
295 ✗ std::string CurveCubic::inputUnitTypeforX() const {
296 ✗ return getImpl<detail::CurveCubic_Impl>()->inputUnitTypeforX();
297 }
298
299 339 bool CurveCubic::isInputUnitTypeforXDefaulted() const {
300
1/1
✓ Branch 3 taken 339 times.
339 return getImpl<detail::CurveCubic_Impl>()->isInputUnitTypeforXDefaulted();
301 }
302
303 ✗ std::string CurveCubic::outputUnitType() const {
304 ✗ return getImpl<detail::CurveCubic_Impl>()->outputUnitType();
305 }
306
307 339 bool CurveCubic::isOutputUnitTypeDefaulted() const {
308
1/1
✓ Branch 3 taken 339 times.
339 return getImpl<detail::CurveCubic_Impl>()->isOutputUnitTypeDefaulted();
309 }
310
311 626 bool CurveCubic::setCoefficient1Constant(double coefficient1Constant) {
312
1/1
✓ Branch 3 taken 626 times.
626 return getImpl<detail::CurveCubic_Impl>()->setCoefficient1Constant(coefficient1Constant);
313 }
314
315 626 bool CurveCubic::setCoefficient2x(double coefficient2x) {
316
1/1
✓ Branch 3 taken 626 times.
626 return getImpl<detail::CurveCubic_Impl>()->setCoefficient2x(coefficient2x);
317 }
318
319 626 bool CurveCubic::setCoefficient3xPOW2(double coefficient3xPOW2) {
320
1/1
✓ Branch 3 taken 626 times.
626 return getImpl<detail::CurveCubic_Impl>()->setCoefficient3xPOW2(coefficient3xPOW2);
321 }
322
323 620 bool CurveCubic::setCoefficient4xPOW3(double coefficient4xPOW3) {
324
1/1
✓ Branch 3 taken 620 times.
620 return getImpl<detail::CurveCubic_Impl>()->setCoefficient4xPOW3(coefficient4xPOW3);
325 }
326
327 534 bool CurveCubic::setMinimumValueofx(double minimumValueofx) {
328
1/1
✓ Branch 3 taken 534 times.
534 return getImpl<detail::CurveCubic_Impl>()->setMinimumValueofx(minimumValueofx);
329 }
330
331 496 bool CurveCubic::setMaximumValueofx(double maximumValueofx) {
332
1/1
✓ Branch 3 taken 496 times.
496 return getImpl<detail::CurveCubic_Impl>()->setMaximumValueofx(maximumValueofx);
333 }
334
335 5 bool CurveCubic::setMinimumCurveOutput(double minimumCurveOutput) {
336
2/2
✓ Branch 3 taken 5 times.
✓ Branch 6 taken 5 times.
5 return getImpl<detail::CurveCubic_Impl>()->setMinimumCurveOutput(minimumCurveOutput);
337 }
338
339 ✗ void CurveCubic::resetMinimumCurveOutput() {
340 ✗ getImpl<detail::CurveCubic_Impl>()->resetMinimumCurveOutput();
341 ✗ }
342
343 5 bool CurveCubic::setMaximumCurveOutput(double maximumCurveOutput) {
344
2/2
✓ Branch 3 taken 5 times.
✓ Branch 6 taken 5 times.
5 return getImpl<detail::CurveCubic_Impl>()->setMaximumCurveOutput(maximumCurveOutput);
345 }
346
347 ✗ void CurveCubic::resetMaximumCurveOutput() {
348 ✗ getImpl<detail::CurveCubic_Impl>()->resetMaximumCurveOutput();
349 ✗ }
350
351 ✗ bool CurveCubic::setInputUnitTypeforX(const std::string& inputUnitTypeforX) {
352 ✗ return getImpl<detail::CurveCubic_Impl>()->setInputUnitTypeforX(inputUnitTypeforX);
353 }
354
355 ✗ void CurveCubic::resetInputUnitTypeforX() {
356 ✗ getImpl<detail::CurveCubic_Impl>()->resetInputUnitTypeforX();
357 ✗ }
358
359 ✗ bool CurveCubic::setOutputUnitType(const std::string& outputUnitType) {
360 ✗ return getImpl<detail::CurveCubic_Impl>()->setOutputUnitType(outputUnitType);
361 }
362
363 ✗ void CurveCubic::resetOutputUnitType() {
364 ✗ getImpl<detail::CurveCubic_Impl>()->resetOutputUnitType();
365 ✗ }
366
367 /// @cond
368
1/1
✓ Branch 3 taken 522 times.
522 CurveCubic::CurveCubic(std::shared_ptr<detail::CurveCubic_Impl> impl) : Curve(std::move(impl)) {}
369 /// @endcond
370
371 } // namespace model
372 } // namespace openstudio
373