GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 83.3% 169 / 0 / 203
Functions: 83.3% 50 / 0 / 60
Branches: 62.1% 113 / 0 / 182

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