GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.9% 37 / 0 / 39
Functions: 100.0% 1 / 0 / 1
Branches: 82.4% 61 / 0 / 74

src/energyplus/ForwardTranslator/ForwardTranslateTableLookup.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/TableLookup.hpp"
9 #include "../../model/TableLookup_Impl.hpp"
10 #include "../../model/TableIndependentVariable.hpp"
11
12 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
13 #include "../../utilities/idf/Workspace.hpp"
14 #include "../../utilities/idf/WorkspaceObjectOrder.hpp"
15 #include "../../utilities/core/Logger.hpp"
16
17 #include <utilities/idd/Table_Lookup_FieldEnums.hxx>
18 #include <utilities/idd/Table_IndependentVariableList_FieldEnums.hxx>
19 #include <utilities/idd/Table_IndependentVariable_FieldEnums.hxx>
20 #include <utilities/idd/IddEnums.hxx>
21
22 #include <algorithm> // For sort, unique
23 #include <iterator> // For distance
24
25 using namespace openstudio::model;
26
27 namespace openstudio {
28
29 namespace energyplus {
30
31 10 boost::optional<IdfObject> ForwardTranslator::translateTableLookup(TableLookup& modelObject) {
32
33
1/1
✓ Branch 1 taken 10 times.
10 std::vector<TableIndependentVariable> independentVariables = modelObject.independentVariables();
34
35 // If the TableLookup doesn't have at least one TableIndependentVariable, then it shouldn't be translated
36
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (independentVariables.empty()) {
37 ✗ LOG(Warn, "TableLookup " << modelObject.name().get() << " has no TableIndependentVariables, it will not be translated");
38 ✗ return boost::none;
39 }
40
41 10 size_t independentVariableGridSize = 1;
42
1/1
✓ Branch 1 taken 10 times.
10 std::vector<double> outputValues = modelObject.outputValues();
43 10 size_t outValueSize = outputValues.size();
44
2/2
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 10 times.
23 for (const auto& independentVariable : independentVariables) {
45
1/1
✓ Branch 1 taken 13 times.
13 auto v = independentVariable.values();
46
1/1
✓ Branch 3 taken 13 times.
13 std::sort(v.begin(), v.end());
47
1/1
✓ Branch 3 taken 13 times.
13 size_t uniqueCount = std::distance(v.begin(), std::unique(v.begin(), v.end()));
48 13 independentVariableGridSize *= uniqueCount;
49 13 }
50
51
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 9 times.
10 if (independentVariableGridSize != outValueSize) {
52
12/12
✓ 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.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 29 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
1 LOG(Warn, "Not translating " << modelObject.briefDescription() << ", it has a mismatch between number of outputValues (=" << outValueSize
53 << ") and the grid size of the TableIndependentVariable(s) (=" << independentVariableGridSize << ").");
54 1 return boost::none;
55 }
56
57 // Table:Lookup
58
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::Table_Lookup, modelObject);
59
60 // Normalization Method: String
61
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 idfObject.setString(Table_LookupFields::NormalizationMethod, modelObject.normalizationMethod());
62
63 // Normalization Divisor: Double
64
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 idfObject.setDouble(Table_LookupFields::NormalizationDivisor, modelObject.normalizationDivisor());
65
66 // Minimum Output: boost::optional<double>
67
3/3
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 5 times.
18 if (boost::optional<double> minimumOutput_ = modelObject.minimumOutput()) {
68
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 idfObject.setDouble(Table_LookupFields::MinimumOutput, minimumOutput_.get());
69 }
70
71 // Maximum Output: boost::optional<double>
72
3/3
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 5 times.
18 if (boost::optional<double> maximumOutput_ = modelObject.maximumOutput()) {
73
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 idfObject.setDouble(Table_LookupFields::MaximumOutput, maximumOutput_.get());
74 }
75
76 // Output Unit Type: String
77
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 idfObject.setString(Table_LookupFields::OutputUnitType, modelObject.outputUnitType());
78
79 // OutputValue
80
2/2
✓ Branch 5 taken 62 times.
✓ Branch 6 taken 9 times.
71 for (const double& outputValue : outputValues) {
81
1/1
✓ Branch 1 taken 62 times.
62 IdfExtensibleGroup eg = idfObject.pushExtensibleGroup();
82
1/1
✓ Branch 1 taken 62 times.
62 eg.setDouble(Table_LookupExtensibleFields::OutputValue, outputValue);
83 62 }
84
85 // Table:IndependentVariableList
86
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 IdfObject tableIndependentVariableList(IddObjectType::Table_IndependentVariableList);
87
3/3
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
9 tableIndependentVariableList.setName(modelObject.nameString() + " Independent Variable List");
88
1/1
✓ Branch 1 taken 9 times.
9 m_idfObjects.push_back(tableIndependentVariableList);
89
90 // IndependentVariableListName
91
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 idfObject.setString(Table_LookupFields::IndependentVariableListName, tableIndependentVariableList.nameString());
92
93 // Table:IndependentVariable
94
2/2
✓ Branch 5 taken 11 times.
✓ Branch 6 taken 9 times.
20 for (auto& independentVariable : independentVariables) {
95
2/3
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
22 if (auto tableIndependentVariable_ = translateAndMapModelObject(independentVariable)) {
96
4/6
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 8 taken 11 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
33 IdfExtensibleGroup independentVariableGroup = tableIndependentVariableList.pushExtensibleGroup({tableIndependentVariable_->nameString()});
97 22 }
98 }
99
100
1/1
✓ Branch 1 taken 9 times.
9 return idfObject;
101 21 }
102
103 } // namespace energyplus
104
105 } // namespace openstudio
106