GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 85.4% 88 / 0 / 103
Functions: 100.0% 1 / 0 / 1
Branches: 66.7% 202 / 0 / 303

src/energyplus/ForwardTranslator/ForwardTranslateSurface.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
8 #include "../../model/Model.hpp"
9 #include "../../model/Surface.hpp"
10 #include "../../model/Surface_Impl.hpp"
11 #include "../../model/SubSurface.hpp"
12 #include "../../model/SubSurface_Impl.hpp"
13 #include "../../model/Space.hpp"
14 #include "../../model/Space_Impl.hpp"
15 #include "../../model/ThermalZone.hpp"
16 #include "../../model/ThermalZone_Impl.hpp"
17 #include "../../model/ConstructionBase.hpp"
18 #include "../../model/ConstructionBase_Impl.hpp"
19 #include "../../model/SurfaceControlMovableInsulation.hpp"
20 #include "../../model/SurfaceControlMovableInsulation_Impl.hpp"
21 #include "../../model/SurfacePropertyOtherSideCoefficients.hpp"
22 #include "../../model/SurfacePropertyOtherSideConditionsModel.hpp"
23 #include "../../model/SurfacePropertyConvectionCoefficients.hpp"
24 #include "../../model/SurfacePropertyLocalEnvironment.hpp"
25 #include "../../model/PlanarSurface.hpp"
26 #include "../../model/FoundationKiva.hpp"
27 #include "../../model/FoundationKiva_Impl.hpp"
28 #include "../../model/SurfacePropertyExposedFoundationPerimeter.hpp"
29 #include "../../model/SurfacePropertyExposedFoundationPerimeter_Impl.hpp"
30
31 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
32
33 #include <utilities/idd/BuildingSurface_Detailed_FieldEnums.hxx>
34
35 #include "../../utilities/idd/IddEnums.hpp"
36 #include <utilities/idd/IddEnums.hxx>
37 #include <utilities/idd/IddFactory.hxx>
38
39 #include "../../utilities/core/Assert.hpp"
40
41 using namespace openstudio::model;
42
43 using namespace std;
44
45 namespace openstudio {
46
47 namespace energyplus {
48
49 3288 boost::optional<IdfObject> ForwardTranslator::translateSurface(model::Surface& modelObject) {
50
2/2
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
3288 IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::BuildingSurface_Detailed, modelObject);
51
52
1/1
✓ Branch 1 taken 3288 times.
3288 std::string surfaceType = modelObject.surfaceType();
53
4/4
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
✓ Branch 7 taken 600 times.
✓ Branch 8 taken 2688 times.
6576 if (istringEqual("RoofCeiling", surfaceType)) {
54
3/3
✓ Branch 1 taken 600 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 114 times.
600 if (modelObject.isPartOfEnvelope()) {
55
1/1
✓ Branch 1 taken 486 times.
486 surfaceType = "Roof";
56 } else {
57
1/1
✓ Branch 1 taken 114 times.
114 surfaceType = "Ceiling";
58 }
59 }
60
1/1
✓ Branch 1 taken 3288 times.
3288 idfObject.setString(BuildingSurface_DetailedFields::SurfaceType, surfaceType);
61
62 // Write the construction:
63 // - When it is hard-assigned
64 // - When the construction assignment sets are excluded
65
8/8
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 1794 times.
✓ Branch 4 taken 1494 times.
✓ Branch 6 taken 1794 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1792 times.
✓ Branch 10 taken 1496 times.
✓ Branch 11 taken 1792 times.
3288 if (!modelObject.isConstructionDefaulted() || m_forwardTranslatorOptions.excludeConstructionAssignmentSets()) {
66
3/3
✓ Branch 1 taken 1496 times.
✓ Branch 3 taken 1495 times.
✓ Branch 4 taken 1 time.
2992 if (boost::optional<ConstructionBase> construction = modelObject.construction()) {
67
3/3
✓ Branch 1 taken 1495 times.
✓ Branch 4 taken 1495 times.
✓ Branch 7 taken 1495 times.
1495 idfObject.setString(BuildingSurface_DetailedFields::ConstructionName, construction->nameString());
68 1496 }
69
1/1
✓ Branch 1 taken 1792 times.
1792 } else if (const std::string obc = modelObject.outsideBoundaryCondition();
70
19/33
✓ Branch 1 taken 1792 times.
✓ Branch 4 taken 1791 times.
✓ Branch 7 taken 1791 times.
✓ Branch 9 taken 1790 times.
✓ Branch 10 taken 1 time.
✓ Branch 12 taken 1790 times.
✓ Branch 15 taken 1790 times.
✓ Branch 17 taken 1789 times.
✓ Branch 18 taken 1 time.
✓ Branch 20 taken 1790 times.
✓ Branch 21 taken 2 times.
✓ Branch 22 taken 1791 times.
✓ Branch 23 taken 1 time.
✓ Branch 25 taken 1791 times.
✓ Branch 26 taken 1 time.
✓ Branch 27 taken 1792 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1792 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 6 times.
✓ Branch 33 taken 1786 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
12538 (istringEqual("GroundFCfactorMethod", obc) || istringEqual("Foundation", obc) || istringEqual("OtherSideCoefficients", obc)
71
13/17
✓ Branch 1 taken 1792 times.
✓ Branch 3 taken 1791 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 1789 times.
✓ Branch 9 taken 1789 times.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 1786 times.
✓ Branch 13 taken 1789 times.
✓ Branch 14 taken 3 times.
✓ Branch 16 taken 1789 times.
✓ Branch 17 taken 3 times.
✓ Branch 18 taken 1790 times.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
7164 || istringEqual("OtherSideConditionsModel", obc))) {
72 // OpenStudio doesn't resolve a default construction for these Outside Boundary Conditions (so there's no need to call construction()),
73 // but EnergyPlus does look them up in the ConstructionAssignmentSet (Ground Contact for GroundFCfactorMethod/Foundation, Exterior for
74 // OtherSideCoefficients, Interior for OtherSideConditionsModel)
75
9/9
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 20 taken 6 times.
✓ Branch 23 taken 6 times.
✓ Branch 26 taken 6 times.
6 LOG(Warn, modelObject.briefDescription()
76 << " with Outside Boundary Condition '" << obc
77 << "' has no construction in OpenStudio, EnergyPlus may resolve it, and incorrectly, from the ConstructionAssignmentSet");
78 1792 }
79
80
1/1
✓ Branch 1 taken 3288 times.
3288 boost::optional<Space> space = modelObject.space();
81
1/2
✓ Branch 0 taken 3288 times.
✗ Branch 1 not taken.
3288 if (space) {
82
2/2
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
3288 boost::optional<ThermalZone> thermalZone = space->thermalZone();
83
1/2
✓ Branch 0 taken 3288 times.
✗ Branch 1 not taken.
3288 if (thermalZone) {
84
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
✓ Branch 7 taken 3288 times.
3288 idfObject.setString(BuildingSurface_DetailedFields::ZoneName, thermalZone->nameString());
85 }
86 // TODO: do we want that?
87
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 2876 times.
✓ Branch 4 taken 412 times.
3288 if (!m_forwardTranslatorOptions.excludeSpaceTranslation()) {
88
3/3
✓ Branch 1 taken 2876 times.
✓ Branch 4 taken 2876 times.
✓ Branch 7 taken 2876 times.
2876 idfObject.setString(BuildingSurface_DetailedFields::SpaceName, space->nameString());
89 }
90 3288 }
91
92
1/1
✓ Branch 1 taken 3288 times.
3288 boost::optional<Surface> adjacentSurface = modelObject.adjacentSurface();
93
1/1
✓ Branch 1 taken 3288 times.
3288 boost::optional<FoundationKiva> adjacentFoundation = modelObject.adjacentFoundation();
94
1/1
✓ Branch 1 taken 3288 times.
3288 boost::optional<SurfacePropertyOtherSideCoefficients> surfacePropertyOtherSideCoefficients = modelObject.surfacePropertyOtherSideCoefficients();
95 boost::optional<SurfacePropertyOtherSideConditionsModel> surfacePropertyOtherSideConditionsModel =
96
1/1
✓ Branch 1 taken 3288 times.
3288 modelObject.surfacePropertyOtherSideConditionsModel();
97
1/1
✓ Branch 1 taken 3288 times.
3288 std::string outsideBoundaryCondition = modelObject.outsideBoundaryCondition();
98
4/4
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
✓ Branch 7 taken 1043 times.
✓ Branch 8 taken 2245 times.
6576 if (istringEqual("Surface", outsideBoundaryCondition)) {
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1043 times.
1043 if (!adjacentSurface) {
100 ✗ LOG(Warn, "Surface '" << modelObject.nameString()
101 << "' has blank Outside Boundary Condition Object. "
102 "Changing Outside Boundary Condition from 'Surface' to 'Adiabatic'");
103
104 ✗ outsideBoundaryCondition = "Adiabatic";
105 }
106
4/4
✓ Branch 1 taken 2245 times.
✓ Branch 4 taken 2245 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 2244 times.
4490 } else if (istringEqual("OtherSideCoefficients", outsideBoundaryCondition)) {
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!surfacePropertyOtherSideCoefficients) {
108 ✗ LOG(Warn, "Surface '" << modelObject.nameString()
109 << "' has blank Outside Boundary Condition Object. "
110 "Changing Outside Boundary Condition from 'Surface' to 'Adiabatic'");
111
112 ✗ outsideBoundaryCondition = "OtherSideCoefficients";
113 }
114
4/4
✓ Branch 1 taken 2244 times.
✓ Branch 4 taken 2244 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 2241 times.
4488 } else if (istringEqual("OtherSideConditionsModel", outsideBoundaryCondition)) {
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (!surfacePropertyOtherSideConditionsModel) {
116 ✗ LOG(Warn, "Surface '" << modelObject.nameString()
117 << "' has blank Outside Boundary Condition Object. "
118 "Changing Outside Boundary Condition from 'OtherSideConditionsModel' to 'Adiabatic'");
119
120 ✗ outsideBoundaryCondition = "Adiabatic";
121 }
122 }
123
124
3/4
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3288 times.
6576 if (istringEqual("Adiabatic", outsideBoundaryCondition)) {
125 ✗ std::vector<SubSurface> subSurfaces = modelObject.subSurfaces();
126 ✗ if (!subSurfaces.empty()) {
127 ✗ LOG(Warn, "Surface '" << modelObject.nameString() << "' is adiabatic, removing all sub surfaces");
128 ✗ for (auto& subSurface : subSurfaces) {
129 ✗ subSurface.remove();
130 }
131 }
132 ✗ }
133
134
1/1
✓ Branch 1 taken 3288 times.
3288 idfObject.setString(BuildingSurface_DetailedFields::OutsideBoundaryCondition, outsideBoundaryCondition);
135
136
2/2
✓ Branch 0 taken 1043 times.
✓ Branch 1 taken 2245 times.
3288 if (adjacentSurface) {
137 // do not translate and map here, wait for adjacent surface to be translated on its own
138
3/3
✓ Branch 1 taken 1043 times.
✓ Branch 4 taken 1043 times.
✓ Branch 7 taken 1043 times.
1043 idfObject.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, adjacentSurface->nameString());
139 }
140
141
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3287 times.
3288 if (adjacentFoundation) {
142 // do not translate and map here, wait for adjacent foundation to be translated on its own
143
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 idfObject.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, adjacentFoundation->nameString());
144 }
145
146
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3287 times.
3288 if (surfacePropertyOtherSideCoefficients) {
147
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 boost::optional<IdfObject> osc = translateAndMapModelObject(*surfacePropertyOtherSideCoefficients);
148
6/12
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
3 if (osc && osc->name()) {
149
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 idfObject.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, osc->nameString());
150 } else {
151 ✗ LOG(Error, "Surface '" << modelObject.nameString() << "', could not translate OutsideBoundaryConditionObject");
152 }
153 1 }
154
155
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3285 times.
3288 if (surfacePropertyOtherSideConditionsModel) {
156
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 boost::optional<IdfObject> oscm = translateAndMapModelObject(*surfacePropertyOtherSideConditionsModel);
157
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
9 if (oscm && oscm->name()) {
158
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 idfObject.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, oscm->nameString());
159 } else {
160 ✗ LOG(Error, "Surface '" << modelObject.nameString() << "', could not translate OutsideBoundaryConditionObject");
161 }
162 3 }
163
164
2/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 3288 times.
✗ Branch 4 not taken.
3288 if (!modelObject.isSunExposureDefaulted()) {
165
2/2
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
3288 idfObject.setString(BuildingSurface_DetailedFields::SunExposure, modelObject.sunExposure());
166 }
167
168
2/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 3288 times.
✗ Branch 4 not taken.
3288 if (!modelObject.isWindExposureDefaulted()) {
169
2/2
✓ Branch 1 taken 3288 times.
✓ Branch 4 taken 3288 times.
3288 idfObject.setString(BuildingSurface_DetailedFields::WindExposure, modelObject.windExposure());
170 }
171
172
1/1
✓ Branch 1 taken 3288 times.
3288 boost::optional<double> viewFactortoGround = modelObject.viewFactortoGround();
173
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3283 times.
3288 if (viewFactortoGround) {
174
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 idfObject.setDouble(BuildingSurface_DetailedFields::ViewFactortoGround, *viewFactortoGround);
175 }
176
177
1/1
✓ Branch 1 taken 3288 times.
3288 idfObject.clearExtensibleGroups();
178
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 8 taken 13868 times.
✓ Branch 9 taken 3288 times.
17156 for (const Point3d& point : modelObject.vertices()) {
179
1/1
✓ Branch 1 taken 13868 times.
13868 IdfExtensibleGroup group = idfObject.pushExtensibleGroup();
180
2/4
✓ Branch 1 taken 13868 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13868 times.
✗ Branch 6 not taken.
13868 OS_ASSERT(group.numFields() == 3);
181
2/2
✓ Branch 1 taken 13868 times.
✓ Branch 4 taken 13868 times.
13868 group.setDouble(0, point.x());
182
2/2
✓ Branch 1 taken 13868 times.
✓ Branch 4 taken 13868 times.
13868 group.setDouble(1, point.y());
183
2/2
✓ Branch 1 taken 13868 times.
✓ Branch 4 taken 13868 times.
13868 group.setDouble(2, point.z());
184 17156 }
185
186 // translate subsurfaces
187
1/1
✓ Branch 1 taken 3288 times.
3288 SubSurfaceVector subSurfaces = modelObject.subSurfaces();
188
1/1
✓ Branch 3 taken 3288 times.
3288 std::sort(subSurfaces.begin(), subSurfaces.end(), WorkspaceObjectNameLess());
189
2/2
✓ Branch 4 taken 411 times.
✓ Branch 5 taken 3288 times.
3699 for (SubSurface& subSurface : subSurfaces) {
190
1/1
✓ Branch 1 taken 411 times.
411 translateAndMapModelObject(subSurface);
191 }
192
193 // Call the translation of these objects, which has two advantages:
194 // * will not translate them if they are orphaned (=not referencing a surface), and,
195 // * makes the order of these objects in the IDF deterministic
196
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3287 times.
6576 if (boost::optional<SurfaceControlMovableInsulation> _sIns = modelObject.surfaceControlMovableInsulation()) {
197
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 translateAndMapModelObject(_sIns.get());
198 3288 }
199
200
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3287 times.
6576 if (boost::optional<SurfacePropertyConvectionCoefficients> _sCoefs = modelObject.surfacePropertyConvectionCoefficients()) {
201
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 translateAndMapModelObject(_sCoefs.get());
202 3288 }
203
204
3/3
✓ Branch 1 taken 3288 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 3284 times.
6576 if (boost::optional<SurfacePropertyLocalEnvironment> localEnv_ = modelObject.surfacePropertyLocalEnvironment()) {
205
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 translateAndMapModelObject(localEnv_.get());
206 3288 }
207
208
2/3
✓ Branch 1 taken 3288 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3288 times.
6576 if (boost::optional<SurfacePropertyExposedFoundationPerimeter> _sProps = modelObject.surfacePropertyExposedFoundationPerimeter()) {
209 ✗ translateAndMapModelObject(_sProps.get());
210 } else {
211 // create a defaulted SurfacePropertyExposedFoundationPerimeter object if it doesn't exist
212
6/7
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3287 times.
✓ Branch 3 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 3287 times.
3288 if ((adjacentFoundation) && (surfaceType == "Floor")) {
213 boost::optional<SurfacePropertyExposedFoundationPerimeter> optprop =
214
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 modelObject.createSurfacePropertyExposedFoundationPerimeter("ExposedPerimeterFraction", 1);
215
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 translateAndMapModelObject(optprop.get());
216 1 }
217 3288 }
218
219
1/1
✓ Branch 1 taken 3288 times.
6576 return idfObject;
220 3288 }
221
222 } // namespace energyplus
223
224 } // namespace openstudio
225