GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 68.0% 140 / 0 / 206
Functions: 65.0% 39 / 0 / 60
Branches: 54.2% 103 / 0 / 190

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