GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 57.7% 60 / 0 / 104
Functions: 100.0% 1 / 0 / 1
Branches: 52.4% 109 / 0 / 208

src/energyplus/ForwardTranslator/ForwardTranslateShadingSurface.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/ShadingSurface.hpp"
10 #include "../../model/ShadingSurface_Impl.hpp"
11 #include "../../model/ShadingSurfaceGroup.hpp"
12 #include "../../model/ShadingSurfaceGroup_Impl.hpp"
13 #include "../../model/Space.hpp"
14 #include "../../model/Space_Impl.hpp"
15 #include "../../model/Surface.hpp"
16 #include "../../model/Surface_Impl.hpp"
17 #include "../../model/Building.hpp"
18 #include "../../model/Building_Impl.hpp"
19 #include "../../model/Schedule.hpp"
20 #include "../../model/Schedule_Impl.hpp"
21 #include "../../model/Construction.hpp"
22 #include "../../model/Construction_Impl.hpp"
23 #include "../../model/StandardOpaqueMaterial.hpp"
24 #include "../../model/StandardOpaqueMaterial_Impl.hpp"
25 #include "../../model/MasslessOpaqueMaterial.hpp"
26 #include "../../model/MasslessOpaqueMaterial_Impl.hpp"
27
28 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
29 #include "../../utilities/geometry/Transformation.hpp"
30 #include "../../utilities/geometry/Geometry.hpp"
31
32 #include <utilities/idd/Shading_Site_Detailed_FieldEnums.hxx>
33 #include <utilities/idd/Shading_Building_Detailed_FieldEnums.hxx>
34 #include <utilities/idd/Shading_Zone_Detailed_FieldEnums.hxx>
35 #include <utilities/idd/ShadingProperty_Reflectance_FieldEnums.hxx>
36
37 #include "../../utilities/idd/IddEnums.hpp"
38 #include <utilities/idd/IddEnums.hxx>
39 #include <utilities/idd/IddFactory.hxx>
40
41 #include "../../utilities/core/Assert.hpp"
42
43 using namespace openstudio::model;
44
45 using namespace std;
46
47 namespace openstudio {
48
49 namespace energyplus {
50
51 404 boost::optional<IdfObject> ForwardTranslator::translateShadingSurface(model::ShadingSurface& modelObject) {
52 404 boost::optional<IdfObject> idfObject;
53
54
1/1
✓ Branch 1 taken 404 times.
404 boost::optional<Schedule> transmittanceSchedule = modelObject.transmittanceSchedule();
55
1/1
✓ Branch 1 taken 404 times.
404 Transformation transformation;
56 404 Point3dVector points;
57
58
1/1
✓ Branch 1 taken 404 times.
404 boost::optional<ShadingSurfaceGroup> shadingSurfaceGroup = modelObject.shadingSurfaceGroup();
59
1/2
✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
404 if (shadingSurfaceGroup) {
60
61
2/2
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
404 transformation = shadingSurfaceGroup->transformation();
62
2/2
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
404 points = transformation * modelObject.vertices();
63
64
6/6
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
✓ Branch 7 taken 404 times.
✓ Branch 10 taken 404 times.
✓ Branch 14 taken 111 times.
✓ Branch 15 taken 293 times.
1212 if (istringEqual("Space", shadingSurfaceGroup->shadingSurfaceType())) {
65
66
3/3
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
✓ Branch 7 taken 111 times.
111 idfObject = IdfObject(openstudio::IddObjectType::Shading_Zone_Detailed);
67
4/4
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
✓ Branch 7 taken 111 times.
✓ Branch 10 taken 111 times.
111 idfObject->setString(Shading_Zone_DetailedFields::Name, modelObject.name().get());
68
69
2/2
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
111 boost::optional<Space> space = shadingSurfaceGroup->space();
70
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if (space) {
71
72 111 boost::optional<Surface> baseSurface;
73 111 double minDistance = std::numeric_limits<double>::max();
74
75 // at this point zone has one space and internal surfaces have already been combined
76
4/4
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
✓ Branch 11 taken 826 times.
✓ Branch 12 taken 111 times.
937 for (const Surface& surface : space->surfaces()) {
77
5/5
✓ Branch 1 taken 826 times.
✓ Branch 4 taken 826 times.
✓ Branch 7 taken 826 times.
✓ Branch 11 taken 362 times.
✓ Branch 12 taken 464 times.
1652 if (istringEqual(surface.outsideBoundaryCondition(), "Outdoors")) {
78
1/1
✓ Branch 1 taken 362 times.
362 Point3dVector surfaceVertices = surface.vertices();
79
2/2
✓ Branch 5 taken 1418 times.
✓ Branch 6 taken 362 times.
1780 for (const Point3d& point : points) {
80
2/2
✓ Branch 5 taken 5672 times.
✓ Branch 6 taken 1418 times.
7090 for (const Point3d& surfaceVertex : surfaceVertices) {
81
1/1
✓ Branch 1 taken 5672 times.
5672 double distance = getDistance(point, surfaceVertex);
82
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 5284 times.
5672 if (distance < minDistance) {
83
1/1
✓ Branch 1 taken 388 times.
388 baseSurface = surface;
84 388 minDistance = distance;
85 }
86 }
87 }
88 362 }
89 111 }
90
91
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
111 if (!baseSurface) {
92 ✗ LOG(Error, "Cannot find appropriate base surface for shading surface '" << modelObject.name().get()
93 << "', the shading surface will not be translated");
94 ✗ return boost::none;
95 }
96
97
5/5
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
✓ Branch 7 taken 111 times.
✓ Branch 10 taken 111 times.
✓ Branch 13 taken 111 times.
111 idfObject->setString(Shading_Zone_DetailedFields::BaseSurfaceName, baseSurface->name().get());
98 111 }
99
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (transmittanceSchedule) {
101 ✗ idfObject->setString(Shading_Zone_DetailedFields::TransmittanceScheduleName, transmittanceSchedule->name().get());
102 }
103
104
7/8
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 293 times.
✓ Branch 7 taken 293 times.
✓ Branch 10 taken 293 times.
✓ Branch 13 taken 293 times.
✓ Branch 17 taken 38 times.
✓ Branch 18 taken 255 times.
990 } else if (istringEqual("Site", shadingSurfaceGroup->shadingSurfaceType())) {
105
106
3/3
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
38 idfObject = IdfObject(openstudio::IddObjectType::Shading_Site_Detailed);
107
4/4
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
✓ Branch 10 taken 38 times.
38 idfObject->setString(Shading_Site_DetailedFields::Name, modelObject.name().get());
108
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (transmittanceSchedule) {
110 ✗ idfObject->setString(Shading_Site_DetailedFields::TransmittanceScheduleName, transmittanceSchedule->name().get());
111 }
112
113
5/6
✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
✓ Branch 10 taken 255 times.
✓ Branch 14 taken 255 times.
✗ Branch 15 not taken.
765 } else if (istringEqual("Building", shadingSurfaceGroup->shadingSurfaceType())) {
114
3/3
✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
255 boost::optional<Building> building = modelObject.model().getUniqueModelObject<Building>();
115
1/2
✓ Branch 0 taken 255 times.
✗ Branch 1 not taken.
255 if (building) {
116
4/4
✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
✓ Branch 10 taken 255 times.
255 transformation = building->transformation().inverse() * transformation;
117 }
118
119
3/3
✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
255 idfObject = IdfObject(openstudio::IddObjectType::Shading_Building_Detailed);
120
4/4
✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
✓ Branch 10 taken 255 times.
255 idfObject->setString(Shading_Building_DetailedFields::Name, modelObject.name().get());
121
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 255 times.
255 if (transmittanceSchedule) {
123 ✗ idfObject->setString(Shading_Building_DetailedFields::TransmittanceScheduleName, transmittanceSchedule->name().get());
124 }
125 255 } else {
126 ✗ OS_ASSERT(false);
127 }
128
129 } else {
130 ✗ idfObject = IdfObject(openstudio::IddObjectType::Shading_Building_Detailed);
131 ✗ idfObject->setString(Shading_Building_DetailedFields::Name, modelObject.name().get());
132
133 ✗ if (transmittanceSchedule) {
134 ✗ idfObject->setString(Shading_Building_DetailedFields::TransmittanceScheduleName, transmittanceSchedule->name().get());
135 }
136 }
137
138
2/2
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
404 m_idfObjects.push_back(*idfObject);
139
140
2/2
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
404 idfObject->clearExtensibleGroups();
141
142
2/2
✓ Branch 5 taken 1601 times.
✓ Branch 6 taken 404 times.
2005 for (const Point3d& point : points) {
143
2/2
✓ Branch 1 taken 1601 times.
✓ Branch 4 taken 1601 times.
1601 IdfExtensibleGroup group = idfObject->pushExtensibleGroup();
144
2/4
✓ Branch 1 taken 1601 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1601 times.
✗ Branch 6 not taken.
1601 OS_ASSERT(group.numFields() == 3);
145
2/2
✓ Branch 1 taken 1601 times.
✓ Branch 4 taken 1601 times.
1601 group.setDouble(0, point.x());
146
2/2
✓ Branch 1 taken 1601 times.
✓ Branch 4 taken 1601 times.
1601 group.setDouble(1, point.y());
147
2/2
✓ Branch 1 taken 1601 times.
✓ Branch 4 taken 1601 times.
1601 group.setDouble(2, point.z());
148 1601 }
149
150 // get reflectance properties from construction if possible
151 404 bool addShadingPropertyObject = false;
152
153
2/2
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
404 IdfObject shadingPropertyObject = IdfObject(openstudio::IddObjectType::ShadingProperty_Reflectance);
154
3/3
✓ Branch 1 taken 404 times.
✓ Branch 4 taken 404 times.
✓ Branch 7 taken 404 times.
404 shadingPropertyObject.setString(ShadingProperty_ReflectanceFields::ShadingSurfaceName, modelObject.name().get());
155
156
1/1
✓ Branch 1 taken 404 times.
404 boost::optional<model::ConstructionBase> constructionBase = modelObject.construction();
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 404 times.
404 if (constructionBase) {
158 ✗ if (constructionBase->isFenestration()) {
159
160 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::FractionofShadingSurfaceThatIsGlazed, 1.0);
161 ✗ shadingPropertyObject.setString(ShadingProperty_ReflectanceFields::GlazingConstructionName, constructionBase->name().get());
162 ✗ addShadingPropertyObject = true;
163
164 } else {
165
166 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::FractionofShadingSurfaceThatIsGlazed, 0.0);
167
168 ✗ boost::optional<model::Construction> construction = constructionBase->optionalCast<model::Construction>();
169 ✗ if (construction) {
170
171 ✗ std::vector<model::Material> layers = construction->layers();
172
173 // we want the outer layer
174 ✗ if (!layers.empty()) {
175
176 ✗ if (layers[0].optionalCast<model::StandardOpaqueMaterial>()) {
177 ✗ auto outerMaterial = layers[0].cast<model::StandardOpaqueMaterial>();
178
179 ✗ boost::optional<double> solRefl = outerMaterial.solarReflectance();
180 ✗ if (solRefl) {
181 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::DiffuseSolarReflectanceofUnglazedPartofShadingSurface, *solRefl);
182 ✗ addShadingPropertyObject = true;
183 }
184
185 ✗ boost::optional<double> visRefl = outerMaterial.visibleReflectance();
186 ✗ if (visRefl) {
187 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::DiffuseVisibleReflectanceofUnglazedPartofShadingSurface, *visRefl);
188 ✗ addShadingPropertyObject = true;
189 }
190 ✗ }
191
192 ✗ if (layers[0].optionalCast<model::MasslessOpaqueMaterial>()) {
193 ✗ auto outerMaterial = layers[0].cast<model::MasslessOpaqueMaterial>();
194
195 ✗ boost::optional<double> solRefl = outerMaterial.solarReflectance();
196 ✗ if (solRefl) {
197 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::DiffuseSolarReflectanceofUnglazedPartofShadingSurface, *solRefl);
198 ✗ addShadingPropertyObject = true;
199 }
200
201 ✗ boost::optional<double> visRefl = outerMaterial.visibleReflectance();
202 ✗ if (visRefl) {
203 ✗ shadingPropertyObject.setDouble(ShadingProperty_ReflectanceFields::DiffuseVisibleReflectanceofUnglazedPartofShadingSurface, *visRefl);
204 ✗ addShadingPropertyObject = true;
205 }
206 ✗ }
207 }
208 ✗ }
209 ✗ }
210 }
211
212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 404 times.
404 if (addShadingPropertyObject) {
213 ✗ m_idfObjects.push_back(shadingPropertyObject);
214 }
215
216 404 return idfObject;
217 404 }
218
219 } // namespace energyplus
220
221 } // namespace openstudio
222