GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.0% 225 / 0 / 250
Functions: 94.2% 49 / 0 / 52
Branches: 75.4% 358 / 0 / 475

src/model/ZonePropertyUserViewFactorsBySurfaceName.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 <vector>
7 #include <string>
8 #include "ZonePropertyUserViewFactorsBySurfaceName.hpp"
9 #include "ZonePropertyUserViewFactorsBySurfaceName_Impl.hpp"
10 #include "ThermalZone.hpp"
11 #include "ThermalZone_Impl.hpp"
12 #include "Surface.hpp"
13 #include "Surface_Impl.hpp"
14 #include "SubSurface.hpp"
15 #include "SubSurface_Impl.hpp"
16 #include "InternalMass.hpp"
17 #include "InternalMass_Impl.hpp"
18 #include "Space.hpp"
19 #include "Space_Impl.hpp"
20
21 #include "Model.hpp"
22 #include "Model_Impl.hpp"
23
24 #include "ModelExtensibleGroup.hpp"
25
26 #include <utilities/idd/IddEnums.hxx>
27 #include <utilities/idd/OS_ZoneProperty_UserViewFactors_BySurfaceName_FieldEnums.hxx>
28
29 #include "../utilities/core/Assert.hpp"
30 #include <algorithm>
31
32 namespace openstudio {
33 namespace model {
34
35 /*****************************************************************************************************************************************************
36 * V I E W F A C T O R W R A P P E R *
37 *****************************************************************************************************************************************************/
38 55 ViewFactor::ViewFactor(const ModelObject& fromSurface, const ModelObject& toSurface, double viewFactor)
39
1/1
✓ Branch 2 taken 55 times.
55 : m_from_surface(fromSurface), m_to_surface(toSurface), m_view_factor(viewFactor) {
40 // Matches the maximum value in IDD
41
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 54 times.
55 if (m_view_factor > 1) {
42
17/17
✓ 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 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
1 LOG_AND_THROW("Unable to create view factor, factor of " << m_view_factor << " more than 1");
43 }
44
45 // Note JM 2019-09-13: E+ will issue a Warning if you don't have numSurfaces^2 viewFactors in HeatBalanceIntRadExchange::GetInputViewFactorsbyName
46 // and set them to zero (which is probably what you want). In order to avoid this warning, I'll allow toSurface == fromSurface
47
5/5
✓ Branch 1 taken 54 times.
✓ Branch 4 taken 54 times.
✓ Branch 7 taken 54 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 50 times.
54 if (fromSurface.handle() == toSurface.handle()) {
48 // LOG_AND_THROW("Cannot create a viewFactor when fromSurface and toSurface are the same: " << fromSurface.briefDescription());
49
50 // Issue a warning if viewFactor isn't zero though, it's unusual for a surface to view itself
51
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (viewFactor != 0.0) {
52
9/9
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 20 taken 4 times.
✓ Branch 23 taken 4 times.
✓ Branch 26 taken 4 times.
4 LOG(Warn, "You are creating a viewFactor with a value of "
53 << viewFactor << " while fromSurface and toSurface are the same: " << fromSurface.briefDescription());
54 }
55 }
56
57 // Check the IDD types to ensure they are ok
58
1/1
✓ Branch 1 taken 54 times.
54 const IddObjectType fromIddType = fromSurface.iddObjectType();
59
4/4
✓ Branch 1 taken 54 times.
✓ Branch 5 taken 29 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 17 times.
83 if ((fromIddType != IddObjectType::OS_Surface) && (fromIddType != IddObjectType::OS_SubSurface)
60
7/7
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 25 times.
✓ Branch 3 taken 12 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 11 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 53 times.
83 && (fromIddType != IddObjectType::OS_InternalMass)) {
61
17/17
✓ 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 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
1 LOG_AND_THROW("fromSurface can be only of type Surface, SubSurface or InternalMass, not " << fromIddType.value());
62 }
63
64
1/1
✓ Branch 1 taken 53 times.
53 const IddObjectType toIddType = toSurface.iddObjectType();
65
11/11
✓ Branch 1 taken 53 times.
✓ Branch 4 taken 25 times.
✓ Branch 5 taken 28 times.
✓ Branch 7 taken 25 times.
✓ Branch 10 taken 15 times.
✓ Branch 11 taken 10 times.
✓ Branch 13 taken 15 times.
✓ Branch 16 taken 1 time.
✓ Branch 17 taken 14 times.
✓ Branch 18 taken 1 time.
✓ Branch 19 taken 52 times.
53 if ((toIddType != IddObjectType::OS_Surface) && (toIddType != IddObjectType::OS_SubSurface) && (toIddType != IddObjectType::OS_InternalMass)) {
66
17/17
✓ 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 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
1 LOG_AND_THROW("toSurface can be only of type Surface, SubSurface or InternalMass, not " << toIddType.value());
67 }
68 58 }
69
70 71 ModelObject ViewFactor::fromSurface() const {
71 71 return m_from_surface;
72 }
73
74 62 ModelObject ViewFactor::toSurface() const {
75 62 return m_to_surface;
76 }
77
78 33 double ViewFactor::viewFactor() const {
79 33 return m_view_factor;
80 }
81
82 4 std::ostream& operator<<(std::ostream& out, const openstudio::model::ViewFactor& viewFactor) {
83
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
12 out << "(from " << viewFactor.fromSurface().iddObject().name() << "='" << viewFactor.fromSurface().nameString() << "', " << "to "
84
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
12 << viewFactor.toSurface().iddObject().name() << "='" << viewFactor.toSurface().nameString() << "', "
85
17/17
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 17 taken 4 times.
✓ Branch 20 taken 4 times.
✓ Branch 23 taken 4 times.
✓ Branch 26 taken 4 times.
✓ Branch 29 taken 4 times.
✓ Branch 32 taken 4 times.
✓ Branch 35 taken 4 times.
✓ Branch 38 taken 4 times.
✓ Branch 41 taken 4 times.
✓ Branch 44 taken 4 times.
✓ Branch 47 taken 4 times.
✓ Branch 50 taken 4 times.
20 << "view factor=" << viewFactor.viewFactor() << ")";
86 4 return out;
87 }
88
89 /*****************************************************************************************************************************************************
90 * Z O N E P R O P E R T Y U S E R V I E W F A C T O R S B Y S U R F A C E N A M E *
91 *****************************************************************************************************************************************************/
92
93 namespace detail {
94
95 9 ZonePropertyUserViewFactorsBySurfaceName_Impl::ZonePropertyUserViewFactorsBySurfaceName_Impl(const IdfObject& idfObject, Model_Impl* model,
96 9 bool keepHandle)
97 9 : ModelObject_Impl(idfObject, model, keepHandle) {
98
4/6
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 13 not taken.
9 OS_ASSERT(idfObject.iddObject().type() == ZonePropertyUserViewFactorsBySurfaceName::iddObjectType());
99 9 }
100
101 ✗ ZonePropertyUserViewFactorsBySurfaceName_Impl::ZonePropertyUserViewFactorsBySurfaceName_Impl(
102 ✗ const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
103 ✗ : ModelObject_Impl(other, model, keepHandle) {
104 ✗ OS_ASSERT(other.iddObject().type() == ZonePropertyUserViewFactorsBySurfaceName::iddObjectType());
105 ✗ }
106
107 1 ZonePropertyUserViewFactorsBySurfaceName_Impl::ZonePropertyUserViewFactorsBySurfaceName_Impl(
108 1 const ZonePropertyUserViewFactorsBySurfaceName_Impl& other, Model_Impl* model, bool keepHandle)
109 1 : ModelObject_Impl(other, model, keepHandle) {}
110
111 ✗ const std::vector<std::string>& ZonePropertyUserViewFactorsBySurfaceName_Impl::outputVariableNames() const {
112 ✗ static const std::vector<std::string> result;
113 ✗ return result;
114 }
115
116 ✗ IddObjectType ZonePropertyUserViewFactorsBySurfaceName_Impl::iddObjectType() const {
117 ✗ return ZonePropertyUserViewFactorsBySurfaceName::iddObjectType();
118 }
119
120 1 ModelObject ZonePropertyUserViewFactorsBySurfaceName_Impl::clone(Model /*model*/) const {
121
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 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
1 LOG_AND_THROW("Cloning isn't allowed for ZonePropertyUserViewFactorsBySurfaceName in order to guarantee that every "
122 "ZonePropertyUserViewFactorsBySurfaceName has a thermal zone, and "
123 "that a thermal zone must have only one ZonePropertyUserViewFactorsBySurfaceName.");
124 }
125
126 45 ThermalZone ZonePropertyUserViewFactorsBySurfaceName_Impl::thermalZone() const {
127 boost::optional<ThermalZone> thermalZone =
128
2/2
✓ Branch 1 taken 45 times.
✓ Branch 4 taken 45 times.
45 getObject<ModelObject>().getModelObjectTarget<ThermalZone>(OS_ZoneProperty_UserViewFactors_BySurfaceNameFields::ThermalZoneName);
129
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 4 not taken.
45 OS_ASSERT(thermalZone);
130
2/2
✓ Branch 1 taken 45 times.
✓ Branch 4 taken 45 times.
90 return thermalZone.get();
131 45 }
132
133 76 unsigned int ZonePropertyUserViewFactorsBySurfaceName_Impl::numberofViewFactors() const {
134 76 return numExtensibleGroups();
135 }
136
137 22 boost::optional<unsigned> ZonePropertyUserViewFactorsBySurfaceName_Impl::viewFactorIndex(const ViewFactor& t_viewFactor) const {
138 22 boost::optional<unsigned> result;
139
140 // Find with custom predicate, checking handle equality between the toSurface and the fromSurface pairs
141 // We do it with extensibleGroups() (rather than viewFactors()) and getString to avoid overhead
142 // of manipulating actual model objects (getTarget, then create a ViewFactor wrapper, get handle convert to string...) and speed up the routine
143
2/2
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
22 auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups());
144
3/3
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
22 auto from = toString(t_viewFactor.fromSurface().handle());
145
3/3
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
22 auto to = toString(t_viewFactor.toSurface().handle());
146
1/1
✓ Branch 3 taken 22 times.
22 auto it = std::find_if(egs.begin(), egs.end(), [&](const WorkspaceExtensibleGroup& eg) {
147
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
128 return ((eg.getField(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::FromSurfaceName).get() == from)
148
11/14
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 45 times.
✓ Branch 9 taken 19 times.
✓ Branch 12 taken 19 times.
✓ Branch 15 taken 3 times.
✓ Branch 16 taken 16 times.
✓ Branch 17 taken 19 times.
✓ Branch 18 taken 45 times.
✓ Branch 20 taken 64 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
192 && (eg.getField(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ToSurfaceName).get() == to));
149 });
150
151 // If found, we compute the index by using std::distance between the start of vector and the iterator returned by std::find_if
152
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 19 times.
22 if (it != egs.end()) {
153
1/1
✓ Branch 2 taken 3 times.
6 result = std::distance(egs.begin(), it);
154 }
155
156 22 return result;
157 22 }
158
159 21 boost::optional<ViewFactor> ZonePropertyUserViewFactorsBySurfaceName_Impl::getViewFactor(unsigned groupIndex) const {
160
161 21 boost::optional<ViewFactor> result;
162
163
3/3
✓ Branch 1 taken 21 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 20 times.
21 if (groupIndex >= numberofViewFactors()) {
164
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 ViewFactor with index " << groupIndex << ", but " << briefDescription() << " has just " << numberofViewFactors()
165 << " ViewFactors.");
166 1 return result;
167 }
168
169
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>();
170
171 boost::optional<ModelObject> _toSurface =
172
1/1
✓ Branch 1 taken 20 times.
20 group.getModelObjectTarget<ModelObject>(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::FromSurfaceName);
173 boost::optional<ModelObject> _fromSurface =
174
1/1
✓ Branch 1 taken 20 times.
20 group.getModelObjectTarget<ModelObject>(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ToSurfaceName);
175
1/1
✓ Branch 1 taken 20 times.
20 boost::optional<double> value = group.getDouble(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ViewFactor);
176
177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (!_toSurface) {
178 ✗ LOG(Error, "Could not retrieve FromSurfaceName for extensible group " << group.groupIndex() << ".");
179 }
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (!_fromSurface) {
181 ✗ LOG(Error, "Could not retrieve ToSurfaceName for extensible group " << group.groupIndex() << ".");
182 }
183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (!value) {
184 ✗ LOG(Error, "Could not retrieve ViewFactor for extensible group " << group.groupIndex() << ".");
185 }
186
187
5/5
✓ 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.
20 result = ViewFactor(_toSurface.get(), _fromSurface.get(), value.get());
188
189 20 return result;
190 20 }
191
192 29 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const ViewFactor& viewFactor) {
193 29 bool result = false;
194
195 // This the only place we need to cast, in order to check if the actual to/from stuff is part of our zone
196 // This lambda checks that the InternalMass/Surface/SubSurface is part of the ThermalZone referenced by this object
197 49 auto checkIfInThermalZone = [this](const ModelObject& modelObject) {
198 49 bool result = false;
199 49 boost::optional<Space> _space;
200
201
3/3
✓ Branch 1 taken 49 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 25 times.
98 if (boost::optional<Surface> _fromSurfaceAsSurface = modelObject.optionalCast<Surface>()) {
202
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 _space = _fromSurfaceAsSurface->space();
203
3/3
✓ Branch 1 taken 25 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 12 times.
50 } else if (boost::optional<SubSurface> _fromSurfaceAsSubSurface = modelObject.optionalCast<SubSurface>()) {
204
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 _space = _fromSurfaceAsSubSurface->space();
205
2/3
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
24 } else if (boost::optional<InternalMass> _fromSurfaceAsInternalMass = modelObject.optionalCast<InternalMass>()) {
206
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 _space = _fromSurfaceAsInternalMass->space();
207 } else {
208 // This can't happen, ViewFactor shouldn't accept anything else
209 ✗ OS_ASSERT(false);
210 86 }
211
212
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 if (_space) {
213
4/4
✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 9 times.
98 if (boost::optional<ThermalZone> _zone = _space->thermalZone()) {
214
6/7
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 40 times.
✓ Branch 10 taken 40 times.
✓ Branch 13 taken 40 times.
✓ Branch 16 taken 40 times.
✗ Branch 17 not taken.
40 if (_zone->handle() == this->thermalZone().handle()) {
215 40 result = true;
216 }
217 49 }
218 }
219 49 return result;
220 49 };
221
222
1/1
✓ Branch 1 taken 29 times.
29 ModelObject fromSurface = viewFactor.fromSurface();
223
3/3
✓ Branch 1 taken 29 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 20 times.
29 if (!checkIfInThermalZone(fromSurface)) {
224
11/11
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
✓ Branch 16 taken 9 times.
✓ Branch 19 taken 9 times.
✓ Branch 22 taken 9 times.
✓ Branch 27 taken 9 times.
✓ Branch 30 taken 9 times.
✓ Branch 33 taken 9 times.
9 LOG(Error, "Cannot add ViewFactor to " << briefDescription() << " because fromSurface=" << fromSurface.briefDescription()
225 << "'is not part of the ThermalZone.");
226 9 return false;
227 }
228
229
1/1
✓ Branch 1 taken 20 times.
20 ModelObject toSurface = viewFactor.toSurface();
230
2/3
✓ Branch 1 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
20 if (!checkIfInThermalZone(toSurface)) {
231 ✗ LOG(Error, "Cannot add ViewFactor to " << briefDescription() << " because toSurface=" << toSurface.briefDescription()
232 << "'is not part of the ThermalZone.");
233 ✗ return false;
234 }
235
236 // Check if viewFactor already exists
237
1/1
✓ Branch 1 taken 20 times.
20 boost::optional<unsigned> _existingIndex = viewFactorIndex(viewFactor);
238
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (_existingIndex) {
239
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 boost::optional<ViewFactor> _viewFactor = getViewFactor(_existingIndex.get());
240
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(_viewFactor);
241
13/13
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 32 taken 2 times.
✓ Branch 35 taken 2 times.
✓ Branch 38 taken 2 times.
2 LOG(Warn, "For " << briefDescription() << ", ViewFactor already exists, will be modified in place from " << _viewFactor.get() << " to "
242 << viewFactor << ".");
243 2 }
244
245 // If existing, get it, otherwise Push an extensible group. ModelExtensibleGroup cannot be default-constructed, so use a ternary operator
246 // Given that we will potentially push many extensible groups
247 // (number of viewFactors to add in a Zone = x^2 where x is number of surfaces + subsurfaces + internalMass)
248 // we will suffer from going through the internal checks in WorkspaceObject, especially in setPointer,
249 // and performance will be roughly O(n^2) when adding viewFactors.
250 // So to improve the performance we pushExtensible group without validity check, and call setPointer without validity check (`isValid`)
251 20 std::vector<std::string> temp;
252
2/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
4 ModelExtensibleGroup eg = (_existingIndex ? getExtensibleGroup(_existingIndex.get()).cast<ModelExtensibleGroup>()
253
9/11
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 11 taken 18 times.
✓ Branch 12 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 18 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
22 : pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>());
254
255
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 bool from = eg.setPointer(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::FromSurfaceName, fromSurface.handle(), false);
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!from) {
257 ✗ LOG(Error, "Unable to add View Factor which has an incompatible fromSurface object to " << briefDescription());
258 ✗ OS_ASSERT(false);
259 }
260
261
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 bool to = eg.setPointer(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ToSurfaceName, toSurface.handle(), false);
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!to) {
263 ✗ LOG(Error, "Unable to add View Factor which has an incompatible toSurface object to " << briefDescription());
264 ✗ OS_ASSERT(false);
265 }
266
267
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 bool value = eg.setDouble(OS_ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ViewFactor, viewFactor.viewFactor());
268
3/6
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 if (from && to && value) {
269 20 result = true;
270 } else {
271 // Something went wrong
272 // So erase the new extensible group
273 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
274 ✗ result = false;
275 }
276 20 return result;
277 29 }
278
279 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const Surface& fromSurface, const Surface& toSurface, double value) {
280
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromSurface, toSurface, value);
281
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
282 2 }
283
284 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const Surface& fromSurface, const SubSurface& toSubSurface, double value) {
285
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromSurface, toSubSurface, value);
286
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
287 2 }
288
289 3 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const Surface& fromSurface, const InternalMass& toInternalMass, double value) {
290
1/1
✓ Branch 1 taken 3 times.
3 ViewFactor viewFactor(fromSurface, toInternalMass, value);
291
1/1
✓ Branch 1 taken 3 times.
6 return addViewFactor(viewFactor);
292 3 }
293
294 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const SubSurface& fromSubSurface, const SubSurface& toSubSurface,
295 double value) {
296
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromSubSurface, toSubSurface, value);
297
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
298 2 }
299
300 3 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const SubSurface& fromSubSurface, const Surface& toSurface, double value) {
301
1/1
✓ Branch 1 taken 3 times.
3 ViewFactor viewFactor(fromSubSurface, toSurface, value);
302
1/1
✓ Branch 1 taken 3 times.
6 return addViewFactor(viewFactor);
303 3 }
304
305 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const SubSurface& fromSubSurface, const InternalMass& toInternalMass,
306 double value) {
307
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromSubSurface, toInternalMass, value);
308
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
309 2 }
310
311 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const InternalMass& fromInternalMass, const InternalMass& toSubSurface,
312 double value) {
313
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromInternalMass, toSubSurface, value);
314
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
315 2 }
316
317 3 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const InternalMass& fromInternalMass, const Surface& toSurface, double value) {
318
1/1
✓ Branch 1 taken 3 times.
3 ViewFactor viewFactor(fromInternalMass, toSurface, value);
319
1/1
✓ Branch 1 taken 3 times.
6 return addViewFactor(viewFactor);
320 3 }
321
322 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactor(const InternalMass& fromInternalMass, const SubSurface& toSubSurface,
323 double value) {
324
1/1
✓ Branch 1 taken 2 times.
2 ViewFactor viewFactor(fromInternalMass, toSubSurface, value);
325
1/1
✓ Branch 1 taken 2 times.
4 return addViewFactor(viewFactor);
326 2 }
327
328 2 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::removeViewFactor(unsigned groupIndex) {
329 2 bool result = false;
330
331 2 unsigned int num = numberofViewFactors();
332
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (groupIndex < num) {
333
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
334 1 result = true;
335 }
336 2 return result;
337 }
338
339 2 void ZonePropertyUserViewFactorsBySurfaceName_Impl::removeAllViewFactors() {
340
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getObject<ModelObject>().clearExtensibleGroups();
341 2 }
342
343 6 std::vector<ViewFactor> ZonePropertyUserViewFactorsBySurfaceName_Impl::viewFactors() const {
344 6 std::vector<ViewFactor> result;
345
346
3/3
✓ Branch 1 taken 21 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 6 times.
21 for (unsigned i = 0; i < numberofViewFactors(); ++i) {
347
348
1/1
✓ Branch 1 taken 15 times.
15 boost::optional<ViewFactor> _viewFactor = getViewFactor(i);
349
350 // getViewFactor is responsible for handling error and issuing Error log messages.
351 // Here we add it to the result array if it worked, and if it didn't, we keep going
352 // We just issue a message about index so user can delete it easily
353
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (_viewFactor) {
354
2/2
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
15 result.push_back(_viewFactor.get());
355 } else {
356 ✗ LOG(Error, briefDescription() << " has an invalid ViewFactor group at index " << i);
357 }
358 15 }
359
360 6 return result;
361 ✗ }
362
363 1 bool ZonePropertyUserViewFactorsBySurfaceName_Impl::addViewFactors(const std::vector<ViewFactor>& viewFactors) {
364 1 bool result = true;
365
366
2/2
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
3 for (const ViewFactor& viewFactor : viewFactors) {
367
1/1
✓ Branch 1 taken 2 times.
2 bool thisResult = addViewFactor(viewFactor);
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!thisResult) {
369 ✗ LOG(Error, "Could not add viewFactor " << viewFactor << " to " << briefDescription() << ". Continuing with others.");
370 // OS_ASSERT(false);
371 // result = false;
372 }
373 }
374
375 1 return result;
376 }
377
378 } // namespace detail
379
380 9 ZonePropertyUserViewFactorsBySurfaceName::ZonePropertyUserViewFactorsBySurfaceName(const ThermalZone& thermalZone)
381
3/3
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
9 : ModelObject(ZonePropertyUserViewFactorsBySurfaceName::iddObjectType(), thermalZone.model()) {
382 std::vector<ZonePropertyUserViewFactorsBySurfaceName> zoneProps =
383
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 thermalZone.getModelObjectSources<ZonePropertyUserViewFactorsBySurfaceName>(ZonePropertyUserViewFactorsBySurfaceName::iddObjectType());
384
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 8 times.
9 if (!zoneProps.empty()) {
385
1/1
✓ Branch 1 taken 1 time.
1 remove();
386
17/17
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
✓ Branch 44 taken 1 time.
✓ Branch 47 taken 1 time.
✓ Branch 52 taken 1 time.
✓ Branch 55 taken 1 time.
1 LOG_AND_THROW(thermalZone.briefDescription() << " already has a ZonePropertyUserViewFactorsBySurfaceName, cannot create a new one. Use "
387 "ThermalZone::getZonePropertyUserViewFactorsBySurfaceName() instead.");
388 }
389
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 5 not taken.
8 OS_ASSERT(getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>());
390
391
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 bool ok = setPointer(OS_ZoneProperty_UserViewFactors_BySurfaceNameFields::ThermalZoneName, thermalZone.handle());
392
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
8 OS_ASSERT(ok);
393 10 }
394
395 7766 IddObjectType ZonePropertyUserViewFactorsBySurfaceName::iddObjectType() {
396
1/1
✓ Branch 1 taken 7766 times.
7766 return {IddObjectType::OS_ZoneProperty_UserViewFactors_BySurfaceName};
397 }
398
399 5 ThermalZone ZonePropertyUserViewFactorsBySurfaceName::thermalZone() const {
400
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->thermalZone();
401 }
402
403 31 unsigned int ZonePropertyUserViewFactorsBySurfaceName::numberofViewFactors() const {
404
1/1
✓ Branch 3 taken 31 times.
31 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->numberofViewFactors();
405 }
406
407 6 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const ViewFactor& viewFactor) {
408
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(viewFactor);
409 }
410
411 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const Surface& fromSurface, const Surface& toSurface, double viewFactor) {
412
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSurface, toSurface, viewFactor);
413 }
414
415 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const Surface& fromSurface, const SubSurface& toSubSurface, double viewFactor) {
416
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSurface, toSubSurface, viewFactor);
417 }
418
419 3 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const Surface& fromSurface, const InternalMass& toInternalMass, double viewFactor) {
420
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSurface, toInternalMass, viewFactor);
421 }
422
423 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const SubSurface& fromSubSurface, const SubSurface& toSubSurface, double viewFactor) {
424
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSubSurface, toSubSurface, viewFactor);
425 }
426
427 3 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const SubSurface& fromSubSurface, const Surface& toSurface, double viewFactor) {
428
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSubSurface, toSurface, viewFactor);
429 }
430
431 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const SubSurface& fromSubSurface, const InternalMass& toInternalMass,
432 double viewFactor) {
433
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromSubSurface, toInternalMass, viewFactor);
434 }
435
436 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const InternalMass& fromInternalMass, const InternalMass& toInternalMass,
437 double viewFactor) {
438
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromInternalMass, toInternalMass, viewFactor);
439 }
440
441 3 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const InternalMass& fromInternalMass, const Surface& toSurface, double viewFactor) {
442
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromInternalMass, toSurface, viewFactor);
443 }
444
445 2 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactor(const InternalMass& fromInternalMass, const SubSurface& toSubSurface,
446 double viewFactor) {
447
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactor(fromInternalMass, toSubSurface, viewFactor);
448 }
449
450 2 boost::optional<unsigned> ZonePropertyUserViewFactorsBySurfaceName::viewFactorIndex(const ViewFactor& viewFactor) const {
451
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->viewFactorIndex(viewFactor);
452 }
453
454 4 boost::optional<ViewFactor> ZonePropertyUserViewFactorsBySurfaceName::getViewFactor(unsigned groupIndex) const {
455
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->getViewFactor(groupIndex);
456 }
457
458 2 void ZonePropertyUserViewFactorsBySurfaceName::removeViewFactor(int groupIndex) {
459
1/1
✓ Branch 3 taken 2 times.
2 getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->removeViewFactor(groupIndex);
460 2 }
461
462 2 void ZonePropertyUserViewFactorsBySurfaceName::removeAllViewFactors() {
463
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->removeAllViewFactors();
464 }
465
466 6 std::vector<ViewFactor> ZonePropertyUserViewFactorsBySurfaceName::viewFactors() const {
467
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->viewFactors();
468 }
469
470 1 bool ZonePropertyUserViewFactorsBySurfaceName::addViewFactors(const std::vector<ViewFactor>& viewFactors) {
471
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl>()->addViewFactors(viewFactors);
472 }
473
474 /// @cond
475 5 ZonePropertyUserViewFactorsBySurfaceName::ZonePropertyUserViewFactorsBySurfaceName(
476 5 std::shared_ptr<detail::ZonePropertyUserViewFactorsBySurfaceName_Impl> impl)
477
1/1
✓ Branch 3 taken 5 times.
5 : ModelObject(std::move(impl)) {}
478 /// @endcond
479
480 } // namespace model
481 } // namespace openstudio
482