GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 44.4% 67 / 0 / 151
Functions: 30.8% 4 / 0 / 13
Branches: 37.0% 118 / 0 / 319

src/airflow/SurfaceNetworkBuilder.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 "SurfaceNetworkBuilder.hpp"
7
8 #include "../model/Model.hpp"
9 #include "../model/Space.hpp"
10 #include "../model/Space_Impl.hpp"
11 #include "../model/ThermalZone.hpp"
12 #include "../model/ThermalZone_Impl.hpp"
13 #include "../model/Surface.hpp"
14 #include "../model/Surface_Impl.hpp"
15 #include "../model/SubSurface.hpp"
16 #include "../model/SubSurface_Impl.hpp"
17
18 #include "../utilities/plot/ProgressBar.hpp"
19
20 #include <thread>
21
22 namespace openstudio {
23 namespace airflow {
24
25 6 SurfaceNetworkBuilder::SurfaceNetworkBuilder(ProgressBar* progressBar) : m_progressBar(progressBar) {
26
1/1
✓ Branch 1 taken 6 times.
6 m_logSink.setLogLevel(Info);
27
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_logSink.setChannelRegex(boost::regex("openstudio\\.model\\.SurfaceNetworkBuilder"));
28
1/1
✓ Branch 2 taken 6 times.
6 m_logSink.setThreadId(std::this_thread::get_id());
29 6 m_progressBar = nullptr;
30 6 }
31
32 143 void SurfaceNetworkBuilder::progress() {
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
143 if (m_progressBar) {
34 ✗ m_progressBar->setValue(m_progressBar->value() + 1);
35 }
36 143 }
37
38 17 void SurfaceNetworkBuilder::initProgress(int max, std::string label) {
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (m_progressBar) {
40 ✗ m_progressBar->setWindowTitle(label);
41 ✗ m_progressBar->setMinimum(0);
42 ✗ m_progressBar->setMaximum(max);
43 ✗ m_progressBar->setValue(0);
44 }
45 17 }
46
47 ✗ bool SurfaceNetworkBuilder::linkExteriorSurface(model::ThermalZone zone, model::Space /*space*/, model::Surface surface) {
48 ✗ LOG(Info, "Surface '" << surface.name().get() << "' connects zone '" << zone.name().get() << "' to the ambient");
49 ✗ return true;
50 }
51
52 ✗ bool SurfaceNetworkBuilder::linkInteriorSurface(model::ThermalZone zone, model::Space /*space*/, model::Surface surface,
53 model::Surface adjacentSurface, model::Space /*adjacentSpace*/, model::ThermalZone adjacentZone) {
54 ✗ LOG(Info, "Surfaces '" << surface.name().get() << "' and '" << adjacentSurface.name().get() << "' connect zone '" << zone.name().get()
55 << "' to zone '" << adjacentZone.name().get() << "'");
56 ✗ return true;
57 }
58
59 ✗ bool SurfaceNetworkBuilder::linkExteriorSubSurface(model::ThermalZone zone, model::Space /*space*/, model::Surface /*surface*/,
60 model::SubSurface subSurface) {
61 ✗ LOG(Info, "Subsurface '" << subSurface.name().get() << "' connects zone '" << zone.name().get() << "' to the ambient");
62 ✗ return true;
63 }
64
65 ✗ bool SurfaceNetworkBuilder::linkInteriorSubSurface(model::ThermalZone zone, model::Space /*space*/, model::Surface /*surface*/,
66 model::SubSurface subSurface, model::SubSurface adjacentSubSurface,
67 model::Surface /*adjacentSurface*/, model::Space /*adjacentSpace*/,
68 model::ThermalZone adjacentZone) {
69 ✗ LOG(Info, "Subsurfaces '" << subSurface.name().get() << "' and '" << adjacentSubSurface.name().get() << "' connect zone '" << zone.name().get()
70 << "' to zone '" << adjacentZone.name().get() << "'");
71 ✗ return true;
72 }
73
74 5 bool SurfaceNetworkBuilder::build(model::Model& model) {
75 5 bool first = true;
76 5 bool nowarnings = true;
77 5 std::vector<openstudio::Handle> used;
78
79
1/1
✓ Branch 2 taken 5 times.
5 m_logSink.setThreadId(std::this_thread::get_id());
80
1/1
✓ Branch 1 taken 5 times.
5 m_logSink.resetStringStream();
81
82
1/1
✓ Branch 1 taken 5 times.
5 std::vector<model::Surface> surfaces = model.getConcreteModelObjects<model::Surface>();
83
84
2/2
✓ Branch 1 taken 5 times.
✓ Branch 5 taken 5 times.
5 initProgress(surfaces.size(), "Processing surfaces for network creation");
85
86
2/2
✓ Branch 5 taken 128 times.
✓ Branch 6 taken 5 times.
133 for (const model::Surface& surface : surfaces) {
87
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 5 times.
128 if (!first) {
88
1/1
✓ Branch 1 taken 123 times.
123 progress();
89 }
90 128 first = false;
91
1/1
✓ Branch 1 taken 128 times.
128 std::string bc = surface.outsideBoundaryCondition();
92
3/3
✓ Branch 1 taken 128 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 68 times.
128 if (bc == "Outdoors") {
93 // Get the associated thermal zone
94
1/1
✓ Branch 1 taken 60 times.
60 boost::optional<openstudio::model::Space> space = surface.space();
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
60 if (!space) {
96 ✗ LOG(Warn, "Unattached surface '" << openstudio::toString(surface.handle()) << "'");
97 ✗ nowarnings = false;
98 ✗ continue;
99 ✗ }
100
2/2
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
60 boost::optional<openstudio::model::ThermalZone> thermalZone = space->thermalZone();
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
60 if (!thermalZone) {
102 ✗ LOG(Warn, "Unzoned space '" << openstudio::toString(space->handle()) << "'");
103 ✗ nowarnings = false;
104 ✗ continue;
105 ✗ }
106 // If we made it to here, then the exterior surface is good.
107
6/6
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 7 taken 60 times.
✓ Branch 10 taken 60 times.
✓ Branch 13 taken 60 times.
✓ Branch 16 taken 60 times.
60 linkExteriorSurface(thermalZone.get(), space.get(), surface);
108
3/3
✓ Branch 1 taken 60 times.
✓ Branch 7 taken 58 times.
✓ Branch 8 taken 60 times.
118 for (const model::SubSurface& subSurface : surface.subSurfaces()) {
109
7/7
✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
✓ Branch 10 taken 58 times.
✓ Branch 13 taken 58 times.
✓ Branch 16 taken 58 times.
✓ Branch 19 taken 58 times.
58 linkExteriorSubSurface(thermalZone.get(), space.get(), surface, subSurface);
110 60 }
111
11/13
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 68 times.
✓ Branch 13 taken 68 times.
✓ Branch 16 taken 44 times.
✓ Branch 17 taken 24 times.
✓ Branch 19 taken 44 times.
✓ Branch 21 taken 24 times.
✓ Branch 22 taken 20 times.
✓ Branch 23 taken 24 times.
✓ Branch 24 taken 44 times.
128 } else if ((std::find(used.begin(), used.end(), surface.handle()) == used.end()) && (bc == "Surface")) {
112 // Get the associated thermal zone
113
1/1
✓ Branch 1 taken 24 times.
24 boost::optional<openstudio::model::Space> space = surface.space();
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!space) {
115 ✗ LOG(Warn, "Unattached surface '" << openstudio::toString(surface.handle()) << "'");
116 ✗ nowarnings = false;
117 ✗ continue;
118 ✗ }
119
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 boost::optional<openstudio::model::ThermalZone> thermalZone = space->thermalZone();
120
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!thermalZone) {
121 ✗ LOG(Warn, "Unzoned space '" << openstudio::toString(space->handle()) << "'");
122 ✗ nowarnings = false;
123 ✗ continue;
124 ✗ }
125
1/1
✓ Branch 1 taken 24 times.
24 boost::optional<openstudio::model::Surface> adjacentSurface = surface.adjacentSurface();
126
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!adjacentSurface) {
127 ✗ LOG(Error, "Unable to find adjacent surface for surface '" << openstudio::toString(surface.handle()) << "'");
128 ✗ nowarnings = false;
129 ✗ continue;
130 ✗ }
131
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 boost::optional<openstudio::model::Space> adjacentSpace = adjacentSurface->space();
132
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!adjacentSpace) {
133 ✗ LOG(Error, "Unattached adjacent surface '" << openstudio::toString(adjacentSurface->handle()) << "'");
134 ✗ nowarnings = false;
135 ✗ continue;
136 ✗ }
137
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 boost::optional<openstudio::model::ThermalZone> adjacentZone = adjacentSpace->thermalZone();
138
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!thermalZone) {
139 ✗ LOG(Warn, "Unzoned adjacent space '" << openstudio::toString(adjacentSpace->handle()) << "'");
140 ✗ nowarnings = false;
141 ✗ continue;
142 ✗ }
143 // We could punt the checking of subsurfaces until later, but it is best to get this out of the way now
144
3/3
✓ Branch 1 taken 24 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 24 times.
30 for (const model::SubSurface& subSurface : surface.subSurfaces()) {
145
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<model::SubSurface> adjacentSubSurface = subSurface.adjacentSubSurface();
146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!adjacentSubSurface) {
147 ✗ LOG(Warn, "Unable to find adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "'");
148 ✗ nowarnings = false;
149 ✗ continue;
150 ✗ }
151
4/5
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
6 if (adjacentSubSurface->surface() != adjacentSurface) {
152 ✗ LOG(Warn,
153 "Adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "' is not attached to the expected surface");
154 ✗ nowarnings = false;
155 ✗ continue;
156 ✗ }
157 30 }
158 // Ok, now we a surface, a space, a zone, an adjacent surface, an adjacent space, and an adjacent zone. Finally.
159
3/3
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 24 times.
24 used.push_back(adjacentSurface->handle());
160
3/3
✓ Branch 1 taken 24 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 20 times.
24 if (thermalZone == adjacentZone) {
161 4 continue;
162 }
163 // Now have a surface that is fully connected and separates two zones so it can be linked
164
12/12
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 10 taken 20 times.
✓ Branch 13 taken 20 times.
✓ Branch 16 taken 20 times.
✓ Branch 19 taken 20 times.
✓ Branch 22 taken 20 times.
✓ Branch 25 taken 20 times.
✓ Branch 28 taken 20 times.
✓ Branch 31 taken 20 times.
✓ Branch 34 taken 20 times.
20 linkInteriorSurface(thermalZone.get(), space.get(), surface, adjacentSurface.get(), adjacentSpace.get(), adjacentZone.get());
165 // Link subsurfaces
166
3/3
✓ Branch 1 taken 20 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 20 times.
26 for (const model::SubSurface& subSurface : surface.subSurfaces()) {
167 // Now we need to check the connections as we did with the surface
168
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<model::SubSurface> adjacentSubSurface = subSurface.adjacentSubSurface();
169
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!adjacentSubSurface) {
170 ✗ LOG(Warn, "Unable to find adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "'");
171 ✗ nowarnings = false;
172 ✗ continue;
173 ✗ }
174
4/5
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
6 if (adjacentSubSurface->surface() != adjacentSurface) {
175 ✗ LOG(Warn,
176 "Adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "' is not attached to the expected surface");
177 ✗ nowarnings = false;
178 ✗ continue;
179 ✗ }
180 // If we made it here, then the subsurface is fully connected and can be linked
181
11/11
✓ 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 19 taken 6 times.
✓ Branch 22 taken 6 times.
✓ Branch 25 taken 6 times.
✓ Branch 28 taken 6 times.
✓ Branch 31 taken 6 times.
6 linkInteriorSubSurface(thermalZone.get(), space.get(), surface, subSurface, adjacentSubSurface.get(), adjacentSurface.get(),
182
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
6 adjacentSpace.get(), adjacentZone.get());
183 26 }
184 40 }
185 128 }
186
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 if (!surfaces.empty()) {
187
1/1
✓ Branch 1 taken 5 times.
5 progress();
188 }
189 5 return nowarnings;
190 5 }
191
192 ✗ std::vector<LogMessage> SurfaceNetworkBuilder::warnings() const {
193 ✗ std::vector<LogMessage> result;
194
195 ✗ for (const LogMessage& logMessage : m_logSink.logMessages()) {
196 ✗ if (logMessage.logLevel() == Warn) {
197 ✗ result.push_back(logMessage);
198 }
199 ✗ }
200
201 ✗ return result;
202 ✗ }
203
204 ✗ std::vector<LogMessage> SurfaceNetworkBuilder::errors() const {
205 ✗ std::vector<LogMessage> result;
206
207 ✗ for (const LogMessage& logMessage : m_logSink.logMessages()) {
208 ✗ if (logMessage.logLevel() > Warn) {
209 ✗ result.push_back(logMessage);
210 }
211 ✗ }
212
213 ✗ return result;
214 ✗ }
215
216 ✗ std::vector<LogMessage> SurfaceNetworkBuilder::logMessages() const {
217 ✗ return m_logSink.logMessages();
218 }
219
220 ✗ ProgressBar* SurfaceNetworkBuilder::progressBar() const {
221 ✗ return m_progressBar;
222 }
223
224 ✗ void SurfaceNetworkBuilder::setProgressBar(ProgressBar* progressBar) {
225 ✗ m_progressBar = progressBar;
226 ✗ }
227
228 } // namespace airflow
229 } // namespace openstudio
230