GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 77.1% 131 / 0 / 170
Functions: 73.2% 30 / 0 / 41
Branches: 55.4% 148 / 0 / 267

src/model/ThermochromicGlazing.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 "ThermochromicGlazing.hpp"
7 #include "ThermochromicGlazing_Impl.hpp"
8 #include "StandardGlazing.hpp"
9 #include "StandardGlazing_Impl.hpp"
10 #include "ModelExtensibleGroup.hpp"
11
12 #include "../utilities/core/Assert.hpp"
13 #include "../utilities/math/FloatCompare.hpp"
14
15 #include <utilities/idd/OS_WindowMaterial_GlazingGroup_Thermochromic_FieldEnums.hxx>
16 #include <utilities/idd/IddEnums.hxx>
17
18 namespace openstudio {
19 namespace model {
20
21 // Helper class for the extensible groups
22 85 ThermochromicGroup::ThermochromicGroup(const StandardGlazing& standardGlazing, double opticalDataTemperature)
23 85 : m_standardGlazing(standardGlazing), m_opticalDataTemperature(opticalDataTemperature) {}
24
25 128 StandardGlazing ThermochromicGroup::standardGlazing() const {
26 128 return m_standardGlazing;
27 }
28
29 112 double ThermochromicGroup::opticalDataTemperature() const {
30 112 return m_opticalDataTemperature;
31 }
32
33 33 bool ThermochromicGroup::operator==(const ThermochromicGroup& other) const {
34
10/17
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 7 taken 33 times.
✓ Branch 9 taken 30 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 30 times.
✓ Branch 16 taken 30 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 30 times.
✓ Branch 21 taken 33 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 33 times.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
33 return (standardGlazing() == other.standardGlazing()) || openstudio::equal(opticalDataTemperature(), other.opticalDataTemperature());
35 }
36
37 ✗ bool ThermochromicGroup::operator!=(const ThermochromicGroup& other) const {
38 ✗ return (!operator==(other));
39 }
40
41 ✗ bool ThermochromicGroup::operator<(const ThermochromicGroup& other) const {
42 ✗ return opticalDataTemperature() < other.opticalDataTemperature();
43 }
44
45 ✗ bool ThermochromicGroup::operator>(const ThermochromicGroup& other) const {
46 ✗ return opticalDataTemperature() > other.opticalDataTemperature();
47 }
48
49 ✗ bool ThermochromicGroup::operator<=(const ThermochromicGroup& other) const {
50 ✗ return opticalDataTemperature() <= other.opticalDataTemperature();
51 }
52
53 ✗ bool ThermochromicGroup::operator>=(const ThermochromicGroup& other) const {
54 ✗ return opticalDataTemperature() >= other.opticalDataTemperature();
55 }
56
57 2 std::ostream& operator<<(std::ostream& out, const openstudio::model::ThermochromicGroup& thermochromicGroup) {
58
1/1
✓ Branch 1 taken 2 times.
4 out << "(StandardGlazing = '" << thermochromicGroup.standardGlazing().nameString()
59
6/6
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 17 taken 2 times.
4 << "', Optional Data Temperature = " << thermochromicGroup.opticalDataTemperature() << ")";
60 2 return out;
61 }
62
63 namespace detail {
64
65 6 ThermochromicGlazing_Impl::ThermochromicGlazing_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
66 6 : Glazing_Impl(idfObject, model, keepHandle) {
67
4/6
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 13 not taken.
6 OS_ASSERT(idfObject.iddObject().type() == ThermochromicGlazing::iddObjectType());
68 6 }
69
70 ✗ ThermochromicGlazing_Impl::ThermochromicGlazing_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
71 ✗ : Glazing_Impl(other, model, keepHandle) {
72 ✗ OS_ASSERT(other.iddObject().type() == ThermochromicGlazing::iddObjectType());
73 ✗ }
74
75 4 ThermochromicGlazing_Impl::ThermochromicGlazing_Impl(const ThermochromicGlazing_Impl& other, Model_Impl* model, bool keepHandle)
76 4 : Glazing_Impl(other, model, keepHandle) {}
77
78 ✗ IddObjectType ThermochromicGlazing_Impl::iddObjectType() const {
79 ✗ return ThermochromicGlazing::iddObjectType();
80 }
81
82 ✗ const std::vector<std::string>& ThermochromicGlazing_Impl::outputVariableNames() const {
83 // TODO: Technically, this is not on this object, but on the Glazed Surface that uses the Construction that references this ThermochromicGlazing
84 // Add it to SubSurface?
85 static const std::vector<std::string> result{"Surface Window Thermochromic Layer Temperature",
86 ✗ "Surface Window Thermochromic Layer Property Specification Temperature"};
87 ✗ return result;
88 ✗ }
89
90 188 unsigned int ThermochromicGlazing_Impl::numberofThermochromicGroups() const {
91 188 return numExtensibleGroups();
92 }
93
94 30 std::vector<ThermochromicGroup> ThermochromicGlazing_Impl::thermochromicGroups() const {
95 30 std::vector<ThermochromicGroup> result;
96
97
3/3
✓ Branch 1 taken 97 times.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 30 times.
97 for (unsigned i = 0; i < numberofThermochromicGroups(); ++i) {
98
99
1/1
✓ Branch 1 taken 67 times.
67 boost::optional<ThermochromicGroup> group_ = getThermochromicGroup(i);
100
101 // getThermochromicGroup is responsible for handling error and issuing Error log messages.
102 // Here we add it to the result array if it worked, and if it didn't, we keep going
103 // We just issue a message about index so user can delete it easily
104
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 if (group_) {
105
2/2
✓ Branch 1 taken 67 times.
✓ Branch 5 taken 67 times.
67 result.push_back(std::move(*group_));
106 } else {
107 ✗ LOG(Error, briefDescription() << " has an invalid ThermochromicGroup group at index " << i);
108 }
109 67 }
110
111 30 return result;
112 ✗ }
113
114 19 boost::optional<unsigned> ThermochromicGlazing_Impl::thermochromicGroupIndex(const ThermochromicGroup& thermochromicGroup) const {
115
1/1
✓ Branch 1 taken 19 times.
19 const std::vector<ThermochromicGroup> groups = thermochromicGroups();
116
1/1
✓ Branch 3 taken 19 times.
19 auto it = std::find(groups.cbegin(), groups.cend(), thermochromicGroup);
117
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 16 times.
19 if (it != groups.end()) {
118
1/1
✓ Branch 2 taken 3 times.
6 return static_cast<unsigned>(std::distance(groups.cbegin(), it));
119 }
120 16 return boost::none;
121 19 }
122
123 71 boost::optional<ThermochromicGroup> ThermochromicGlazing_Impl::getThermochromicGroup(unsigned groupIndex) const {
124
3/3
✓ Branch 1 taken 71 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 70 times.
71 if (groupIndex >= numberofThermochromicGroups()) {
125
13/13
✓ 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 28 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
✓ Branch 38 taken 1 time.
1 LOG(Error, "Asked to get ThermochromicGroup with index " << groupIndex << ", but " << briefDescription() << " has just "
126 << numberofThermochromicGroups() << " ThermochromicGroups.");
127 1 return boost::none;
128 }
129
2/2
✓ Branch 1 taken 70 times.
✓ Branch 4 taken 70 times.
70 auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>();
130
131 boost::optional<StandardGlazing> standardGlazing_ =
132
1/1
✓ Branch 1 taken 70 times.
70 group.getModelObjectTarget<StandardGlazing>(OS_WindowMaterial_GlazingGroup_ThermochromicExtensibleFields::WindowMaterialGlazingName);
133
134 boost::optional<double> opticalDataTemperature_ =
135
1/1
✓ Branch 1 taken 70 times.
70 group.getDouble(OS_WindowMaterial_GlazingGroup_ThermochromicExtensibleFields::OpticalDataTemperature);
136
137
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
70 if (!standardGlazing_) {
138 ✗ LOG(Error, "Could not retrieve StandardGlazing (WindowMaterialGlazingName) for extensible group " << group.groupIndex() << ".");
139 ✗ return boost::none;
140 }
141
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
70 if (!opticalDataTemperature_) {
142 ✗ LOG(Error, "Could not retrieve OpticalDataTemperature for extensible group " << group.groupIndex() << ".");
143 ✗ return boost::none;
144 }
145
146
4/4
✓ Branch 1 taken 70 times.
✓ Branch 4 taken 70 times.
✓ Branch 7 taken 70 times.
✓ Branch 10 taken 70 times.
70 return {ThermochromicGroup(*standardGlazing_, *opticalDataTemperature_)};
147 70 }
148
149 16 bool ThermochromicGlazing_Impl::addThermochromicGroup(const ThermochromicGroup& thermochromicGroup) {
150
151 // Check if ThermochromicGroup already exists
152
1/1
✓ Branch 1 taken 16 times.
16 boost::optional<unsigned> existingIndex_ = thermochromicGroupIndex(thermochromicGroup);
153
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 15 times.
16 if (existingIndex_) {
154
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 boost::optional<ThermochromicGroup> group_ = getThermochromicGroup(*existingIndex_);
155
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(group_);
156
13/13
✓ 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 28 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
✓ Branch 38 taken 1 time.
1 LOG(Warn, "For " << briefDescription() << ", ThermochromicGroup already exists, will be modified in place from " << group_.get() << " to "
157 << thermochromicGroup << ".");
158 1 }
159
160 // If existing, get it, otherwise Push an extensible group. ModelExtensibleGroup cannot be default-constructed, so use a ternary operator
161 // Given that we will potentially push many extensible groups
162 // we will suffer from going through the internal checks in WorkspaceObject, especially in setPointer,
163 // and performance will be roughly O(n^2) when adding groups.
164 // So to improve the performance we pushExtensible group without validity check, and call setPointer without validity check (`isValid`)
165 16 std::vector<std::string> temp;
166
2/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 ModelExtensibleGroup eg = (existingIndex_ ? getExtensibleGroup(existingIndex_.get()).cast<ModelExtensibleGroup>()
167
9/11
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 15 times.
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 15 times.
✓ Branch 9 taken 15 times.
✓ Branch 11 taken 15 times.
✓ Branch 12 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 15 taken 15 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
17 : pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>());
168
169
1/1
✓ Branch 1 taken 16 times.
16 bool result = eg.setPointer(OS_WindowMaterial_GlazingGroup_ThermochromicExtensibleFields::WindowMaterialGlazingName,
170
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
32 thermochromicGroup.standardGlazing().handle());
171
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 result |= eg.setDouble(OS_WindowMaterial_GlazingGroup_ThermochromicExtensibleFields::OpticalDataTemperature,
172 thermochromicGroup.opticalDataTemperature());
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (!result) {
174 // Something went wrong
175 // So erase the new extensible group
176 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
177 ✗ result = false;
178 }
179 16 return result;
180 16 }
181
182 8 bool ThermochromicGlazing_Impl::addThermochromicGroup(const StandardGlazing& standardGlazing, double opticalDataTemperature) {
183
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 return addThermochromicGroup(ThermochromicGroup{standardGlazing, opticalDataTemperature});
184 }
185
186 1 bool ThermochromicGlazing_Impl::addThermochromicGroups(const std::vector<ThermochromicGroup>& thermochromicGroups) {
187 1 bool result = true;
188
189
2/2
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
3 for (const auto& thermochromicGroup : thermochromicGroups) {
190
1/1
✓ Branch 1 taken 2 times.
2 bool thisResult = addThermochromicGroup(thermochromicGroup);
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!thisResult) {
192 ✗ LOG(Error, "Could not add ThermochromicGroup " << thermochromicGroup << " to " << briefDescription() << ". Continuing with others.");
193 // OS_ASSERT(false);
194 ✗ result = false;
195 }
196 }
197
198 1 return result;
199 }
200
201 3 bool ThermochromicGlazing_Impl::removeThermochromicGroup(unsigned groupIndex) {
202 3 bool result = false;
203
204 3 unsigned int num = numberofThermochromicGroups();
205
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
3 if (groupIndex < num) {
206
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
207 1 result = true;
208 }
209 3 return result;
210 }
211
212 1 void ThermochromicGlazing_Impl::removeAllThermochromicGroups() {
213
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().clearExtensibleGroups();
214 1 }
215
216 ✗ boost::optional<double> ThermochromicGlazing_Impl::getVisibleTransmittance() const {
217 ✗ LOG_AND_THROW("Visible transmittance not yet supported for ThermochromicGlazings.");
218 }
219
220 ✗ boost::optional<double> ThermochromicGlazing_Impl::interiorVisibleAbsorptance() const {
221 ✗ LOG_AND_THROW("Interior Visible Absorptance not yet supported for ThermochromicGlazings.");
222 }
223
224 ✗ boost::optional<double> ThermochromicGlazing_Impl::exteriorVisibleAbsorptance() const {
225 ✗ LOG_AND_THROW("Exterior Visible Absorptance not yet supported for ThermochromicGlazings.");
226 }
227
228 2 double ThermochromicGlazing_Impl::thickness() const {
229 2 double result = 0.0; // running average
230 2 unsigned n = 0;
231 2 bool warned = false;
232
3/3
✓ Branch 1 taken 2 times.
✓ Branch 7 taken 10 times.
✓ Branch 8 taken 2 times.
12 for (const auto& group : thermochromicGroups()) {
233
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
10 double glazingThickness = group.standardGlazing().thickness();
234
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (n == 0) {
235 2 result = glazingThickness;
236 } else {
237 // keep running average
238
6/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 7 times.
8 if (!warned && !equal(glazingThickness, result)) {
239
8/8
✓ 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 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
1 LOG(Warn, "Thermochromic group '" << nameString() << "' contains glazings of different thicknesses.");
240 1 warned = true;
241 }
242 8 result = (result * static_cast<double>(n) + glazingThickness) / static_cast<double>(n + 1);
243 }
244 10 ++n;
245 2 }
246 2 return result;
247 }
248
249 1 bool ThermochromicGlazing_Impl::setThickness(double value) {
250
1/1
✓ Branch 1 taken 1 time.
1 auto groups = thermochromicGroups();
251 1 std::vector<double> rollbackValues;
252
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
6 for (unsigned i = 0, n = groups.size(); i < n; ++i) {
253
1/1
✓ Branch 2 taken 5 times.
5 auto standardGlazing = groups[i].standardGlazing();
254
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 rollbackValues.push_back(standardGlazing.thickness());
255
1/1
✓ Branch 1 taken 5 times.
5 bool ok = standardGlazing.setThickness(value);
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!ok) {
257 // rollback previous values
258 ✗ for (int j = i - 1; j >= 0; --j) {
259 ✗ standardGlazing.setThickness(rollbackValues[j]);
260 }
261 ✗ return false;
262 }
263 5 }
264 1 return true;
265 1 }
266
267 } // namespace detail
268
269 6 ThermochromicGlazing::ThermochromicGlazing(const Model& model) : Glazing(ThermochromicGlazing::iddObjectType(), model) {
270
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 5 not taken.
6 OS_ASSERT(getImpl<detail::ThermochromicGlazing_Impl>());
271 6 }
272
273 7612 IddObjectType ThermochromicGlazing::iddObjectType() {
274
1/1
✓ Branch 1 taken 7612 times.
7612 return {IddObjectType::OS_WindowMaterial_GlazingGroup_Thermochromic};
275 }
276
277 8 std::vector<ThermochromicGroup> ThermochromicGlazing::thermochromicGroups() const {
278
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::ThermochromicGlazing_Impl>()->thermochromicGroups();
279 }
280
281 16 unsigned int ThermochromicGlazing::numberofThermochromicGroups() const {
282
1/1
✓ Branch 3 taken 16 times.
16 return getImpl<detail::ThermochromicGlazing_Impl>()->numberofThermochromicGroups();
283 }
284
285 3 boost::optional<unsigned> ThermochromicGlazing::thermochromicGroupIndex(const ThermochromicGroup& thermochromicGroup) const {
286
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ThermochromicGlazing_Impl>()->thermochromicGroupIndex(thermochromicGroup);
287 }
288
289 3 boost::optional<ThermochromicGroup> ThermochromicGlazing::getThermochromicGroup(unsigned groupIndex) const {
290
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ThermochromicGlazing_Impl>()->getThermochromicGroup(groupIndex);
291 }
292
293 6 bool ThermochromicGlazing::addThermochromicGroup(const ThermochromicGroup& thermochromicGroup) {
294
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::ThermochromicGlazing_Impl>()->addThermochromicGroup(thermochromicGroup);
295 }
296
297 8 bool ThermochromicGlazing::addThermochromicGroup(const StandardGlazing& standardGlazing, double opticalDataTemperature) {
298
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::ThermochromicGlazing_Impl>()->addThermochromicGroup(standardGlazing, opticalDataTemperature);
299 }
300
301 1 bool ThermochromicGlazing::addThermochromicGroups(const std::vector<ThermochromicGroup>& thermochromicGroups) {
302
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ThermochromicGlazing_Impl>()->addThermochromicGroups(thermochromicGroups);
303 }
304
305 3 bool ThermochromicGlazing::removeThermochromicGroup(unsigned groupIndex) {
306
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ThermochromicGlazing_Impl>()->removeThermochromicGroup(groupIndex);
307 }
308
309 1 void ThermochromicGlazing::removeAllThermochromicGroups() {
310
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::ThermochromicGlazing_Impl>()->removeAllThermochromicGroups();
311 1 }
312
313 /// @cond
314
1/1
✓ Branch 3 taken 6 times.
6 ThermochromicGlazing::ThermochromicGlazing(std::shared_ptr<detail::ThermochromicGlazing_Impl> impl) : Glazing(std::move(impl)) {}
315 /// @endcond
316
317 } // namespace model
318 } // namespace openstudio
319