GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 79.5% 70 / 0 / 88
Functions: 100.0% 1 / 0 / 1
Branches: 65.9% 91 / 0 / 138

src/energyplus/ForwardTranslator/ForwardTranslateTableMultiVariableLookup.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 "../ForwardTranslator.hpp"
7 #include "../../model/Model.hpp"
8 #include "../../model/TableMultiVariableLookup.hpp"
9 #include "../../model/TableMultiVariableLookup_Impl.hpp"
10 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
11 #include "../../utilities/idf/Workspace.hpp"
12 #include "../../utilities/idf/WorkspaceObjectOrder.hpp"
13 #include "../../utilities/core/Logger.hpp"
14 #include <utilities/idd/Table_Lookup_FieldEnums.hxx>
15 #include <utilities/idd/Table_IndependentVariableList_FieldEnums.hxx>
16 #include <utilities/idd/Table_IndependentVariable_FieldEnums.hxx>
17 #include <utilities/idd/IddEnums.hxx>
18
19 #include "../../utilities/core/DeprecatedHelpers.hpp"
20
21 using namespace openstudio::model;
22
23 namespace openstudio {
24
25 namespace energyplus {
26
27 #if defined(_MSC_VER)
28 # pragma warning(push)
29 # pragma warning(disable : 4996)
30 #elif (defined(__GNUC__))
31 # pragma GCC diagnostic push
32 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
33 #endif
34
35 3 boost::optional<IdfObject> ForwardTranslator::translateTableMultiVariableLookup(TableMultiVariableLookup& modelObject) {
36
5/5
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
12 DEPRECATED_AT_MSG(3, 5, 0, "The entire TableMultiVariableLookup will be removed.");
37 3 OptionalString s;
38 3 OptionalDouble d;
39 3 OptionalModelObject temp;
40 3 OptionalInt n;
41
42 // create these objects here but do not add to file yet in case of failure
43 3 std::vector<IdfObject> tableIndependentVariables;
44
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 IdfObject tableIndependentVariableList(IddObjectType::Table_IndependentVariableList);
45
1/1
✓ Branch 1 taken 3 times.
3 s = modelObject.name();
46
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (s) {
47
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 tableIndependentVariableList.setName(*s + "_IndependentVariableList");
48 }
49
50
1/1
✓ Branch 1 taken 3 times.
3 std::string interpolationMethod = modelObject.interpolationMethod();
51
52
1/1
✓ Branch 1 taken 3 times.
3 int numberofIndependentVariables = modelObject.numberofIndependentVariables();
53 3 unsigned expectedNumberOfValues = 1;
54
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 for (int i = 0; i < numberofIndependentVariables; ++i) {
55
1/1
✓ Branch 1 taken 5 times.
5 auto xValues = modelObject.xValues(i);
56 5 auto sizeX = xValues.size();
57
58 // expect a full grid of values
59 5 expectedNumberOfValues *= sizeX;
60
61 // create an independent variable for this x
62
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 IdfObject tableIndependentVariable(IddObjectType::Table_IndependentVariable);
63
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (s) {
64
4/4
✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
✓ Branch 11 taken 5 times.
5 tableIndependentVariable.setName(*s + "_IndependentVariable_" + std::to_string(i));
65 }
66
3/3
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
5 tableIndependentVariableList.pushExtensibleGroup(std::vector<std::string>(1, tableIndependentVariable.nameString()));
67
68 // there is not a straightforward mapping of the old interpolation methods to new ones, e.g. there is no "None" option for extrapolation
69
3/4
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
10 if (istringEqual(interpolationMethod, "LagrangeInterpolationLinearExtrapolation")) {
70
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
10 tableIndependentVariable.setString(Table_IndependentVariableFields::InterpolationMethod, "Cubic");
71
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
10 tableIndependentVariable.setString(Table_IndependentVariableFields::ExtrapolationMethod, "Linear");
72 ✗ } else if (istringEqual(interpolationMethod, "LinearInterpolationOfTable")) {
73 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::InterpolationMethod, "Linear");
74 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::ExtrapolationMethod, "Constant");
75 ✗ } else if (istringEqual(interpolationMethod, "EvaluateCurveToLimits")) {
76 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::InterpolationMethod, "Cubic");
77 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::ExtrapolationMethod, "Constant");
78 }
79
80 // these values should be unique and sorted in ascending order
81
1/1
✓ Branch 2 taken 5 times.
5 tableIndependentVariable.setDouble(Table_IndependentVariableFields::MinimumValue, xValues[0]);
82
1/1
✓ Branch 2 taken 5 times.
5 tableIndependentVariable.setDouble(Table_IndependentVariableFields::MaximumValue, xValues[sizeX - 1]);
83
84
3/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 switch (i) {
85 3 case 0:
86
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 tableIndependentVariable.setString(Table_IndependentVariableFields::UnitType, modelObject.inputUnitTypeforX1());
87 3 break;
88 1 case 1:
89
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 tableIndependentVariable.setString(Table_IndependentVariableFields::UnitType, modelObject.inputUnitTypeforX2());
90 1 break;
91 1 case 2:
92
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 tableIndependentVariable.setString(Table_IndependentVariableFields::UnitType, modelObject.inputUnitTypeforX3());
93 1 break;
94 ✗ case 3:
95 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::UnitType, modelObject.inputUnitTypeforX4());
96 ✗ break;
97 ✗ case 4:
98 ✗ tableIndependentVariable.setString(Table_IndependentVariableFields::UnitType, modelObject.inputUnitTypeforX5());
99 ✗ break;
100 ✗ default:
101 ✗ break;
102 }
103
104 // add the values
105
2/2
✓ Branch 5 taken 19 times.
✓ Branch 6 taken 5 times.
24 for (const auto& xValue : xValues) {
106
1/1
✓ Branch 1 taken 19 times.
19 auto eg = tableIndependentVariable.pushExtensibleGroup();
107
1/1
✓ Branch 1 taken 19 times.
19 eg.setDouble(Table_IndependentVariableExtensibleFields::Value, xValue);
108 19 }
109
110
1/1
✓ Branch 1 taken 5 times.
5 tableIndependentVariables.push_back(tableIndependentVariable);
111 5 }
112
113 // check that we have the correct number of points
114
1/1
✓ Branch 1 taken 3 times.
3 auto points = modelObject.points();
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (expectedNumberOfValues != points.size()) {
116 ✗ LOG(Error, "Expected " << expectedNumberOfValues << " points but found " << points.size() << " in object " << modelObject.briefDescription()
117 << ". Object not translated");
118 ✗ return boost::none;
119 }
120
121 // important to sort points in order expected by EnergyPlus
122
1/1
✓ Branch 3 taken 3 times.
3 std::sort(points.begin(), points.end());
123
124 // Create a new IddObjectType::Table_Lookup, this is the main object returned
125
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 IdfObject tableLookup(IddObjectType::Table_Lookup);
126
1/1
✓ Branch 1 taken 3 times.
3 m_idfObjects.push_back(tableLookup);
127
1/1
✓ Branch 1 taken 3 times.
3 m_idfObjects.push_back(tableIndependentVariableList);
128
2/2
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 3 times.
8 for (const auto& tableIndependentVariable : tableIndependentVariables) {
129
1/1
✓ Branch 1 taken 5 times.
5 m_idfObjects.push_back(tableIndependentVariable);
130 }
131
132 // Name
133
1/1
✓ Branch 1 taken 3 times.
3 s = modelObject.name();
134
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (s) {
135
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 tableLookup.setName(*s);
136 }
137
138 // Independent Variable List Name
139
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 tableLookup.setString(Table_LookupFields::IndependentVariableListName, tableIndependentVariableList.nameString());
140
141 // NormalizationReference
142
3/3
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 2 times.
6 if ((d = modelObject.normalizationReference())) {
143
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 tableLookup.setString(Table_LookupFields::NormalizationMethod, "DivisorOnly");
144
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 tableLookup.setDouble(Table_LookupFields::NormalizationDivisor, d.get());
145 } else {
146
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 tableLookup.setString(Table_LookupFields::NormalizationMethod, "None");
147
1/1
✓ Branch 1 taken 2 times.
2 tableLookup.setDouble(Table_LookupFields::NormalizationDivisor, 1.0);
148 }
149
150 // MinimumTableOutput
151
2/3
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
6 if ((d = modelObject.minimumTableOutput())) {
152 ✗ tableLookup.setDouble(Table_LookupFields::MinimumOutput, d.get());
153 }
154
155 // MaximumTableOutput
156
2/3
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
6 if ((d = modelObject.maximumTableOutput())) {
157 ✗ tableLookup.setDouble(Table_LookupFields::MaximumOutput, d.get());
158 }
159
160 // OutputUnitType
161
3/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
6 if ((s = modelObject.outputUnitType())) {
162
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 tableLookup.setString(Table_LookupFields::OutputUnitType, s.get());
163 }
164
165 // ExternalFileName
166 // Not supported
167
168 // add the sorted values
169
2/2
✓ Branch 5 taken 34 times.
✓ Branch 6 taken 3 times.
37 for (const auto& point : points) {
170
1/1
✓ Branch 1 taken 34 times.
34 auto eg = tableLookup.pushExtensibleGroup();
171
2/2
✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
34 eg.setDouble(Table_LookupExtensibleFields::OutputValue, point.y());
172 34 }
173
174
1/1
✓ Branch 1 taken 3 times.
3 return tableLookup;
175 3 }
176
177 #if defined(_MSC_VER)
178 # pragma warning(pop)
179 #elif (defined(__GNUC__))
180 # pragma GCC diagnostic pop
181 #endif
182
183 } // namespace energyplus
184
185 } // namespace openstudio
186