GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 15.8% 25 / 0 / 158
Functions: 11.6% 5 / 0 / 43
Branches: 13.1% 29 / 0 / 221

src/model/AirflowNetworkDuctViewFactors.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 "AirflowNetworkDuctViewFactors.hpp"
7 #include "AirflowNetworkDuctViewFactors_Impl.hpp"
8
9 #include "ModelExtensibleGroup.hpp"
10 #include "PlanarSurface.hpp"
11 #include "PlanarSurface_Impl.hpp"
12
13 #include "AirflowNetworkLinkage.hpp"
14 #include "AirflowNetworkLinkage_Impl.hpp"
15
16 #include "Model.hpp"
17
18 #include <utilities/idd/IddEnums.hxx>
19 #include <utilities/idd/OS_AirflowNetworkDuctViewFactors_FieldEnums.hxx>
20
21 #include "../utilities/units/Unit.hpp"
22
23 #include "../utilities/core/Assert.hpp"
24
25 namespace openstudio {
26 namespace model {
27
28 ✗ ViewFactorData::ViewFactorData(const PlanarSurface& s, double viewFactor) : m_planarSurface(s), m_viewFactor(viewFactor) {}
29
30 ✗ PlanarSurface ViewFactorData::planarSurface() const {
31 ✗ return m_planarSurface;
32 }
33
34 ✗ double ViewFactorData::viewFactor() const {
35 ✗ return m_viewFactor;
36 }
37
38 ✗ std::ostream& operator<<(std::ostream& out, const openstudio::model::ViewFactorData& vf) {
39 ✗ out << "(" << vf.planarSurface().nameString() << ", " << vf.viewFactor() << ")";
40 ✗ return out;
41 }
42
43 namespace detail {
44
45 1 AirflowNetworkDuctViewFactors_Impl::AirflowNetworkDuctViewFactors_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
46 1 : ModelObject_Impl(idfObject, model, keepHandle) {
47
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
1 OS_ASSERT(idfObject.iddObject().type() == AirflowNetworkDuctViewFactors::iddObjectType());
48 1 }
49
50 ✗ AirflowNetworkDuctViewFactors_Impl::AirflowNetworkDuctViewFactors_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
51 ✗ bool keepHandle)
52 ✗ : ModelObject_Impl(other, model, keepHandle) {
53 ✗ OS_ASSERT(other.iddObject().type() == AirflowNetworkDuctViewFactors::iddObjectType());
54 ✗ }
55
56 ✗ AirflowNetworkDuctViewFactors_Impl::AirflowNetworkDuctViewFactors_Impl(const AirflowNetworkDuctViewFactors_Impl& other, Model_Impl* model,
57 ✗ bool keepHandle)
58 ✗ : ModelObject_Impl(other, model, keepHandle) {}
59
60 ✗ const std::vector<std::string>& AirflowNetworkDuctViewFactors_Impl::outputVariableNames() const {
61 ✗ static const std::vector<std::string> result;
62 ✗ return result;
63 }
64
65 ✗ IddObjectType AirflowNetworkDuctViewFactors_Impl::iddObjectType() const {
66 ✗ return AirflowNetworkDuctViewFactors::iddObjectType();
67 }
68
69 ✗ AirflowNetworkLinkage AirflowNetworkDuctViewFactors_Impl::linkage() const {
70 ✗ boost::optional<AirflowNetworkLinkage> value = optionalLinkage();
71 ✗ if (!value) {
72 ✗ LOG_AND_THROW(briefDescription() << " does not have an Linkage attached.");
73 }
74 ✗ return value.get();
75 ✗ }
76
77 ✗ double AirflowNetworkDuctViewFactors_Impl::ductSurfaceExposureFraction() const {
78 ✗ boost::optional<double> value = getDouble(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceExposureFraction, true);
79 ✗ OS_ASSERT(value);
80 ✗ return value.get();
81 }
82
83 ✗ bool AirflowNetworkDuctViewFactors_Impl::isDuctSurfaceExposureFractionDefaulted() const {
84 ✗ return isEmpty(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceExposureFraction);
85 }
86
87 ✗ double AirflowNetworkDuctViewFactors_Impl::ductSurfaceEmittance() const {
88 ✗ boost::optional<double> value = getDouble(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceEmittance, true);
89 ✗ OS_ASSERT(value);
90 ✗ return value.get();
91 }
92
93 ✗ bool AirflowNetworkDuctViewFactors_Impl::isDuctSurfaceEmittanceDefaulted() const {
94 ✗ return isEmpty(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceEmittance);
95 }
96
97 ✗ bool AirflowNetworkDuctViewFactors_Impl::setLinkage(const AirflowNetworkLinkage& linkage) {
98 ✗ bool result = setPointer(OS_AirflowNetworkDuctViewFactorsFields::LinkageName, linkage.handle());
99 ✗ return result;
100 }
101
102 ✗ bool AirflowNetworkDuctViewFactors_Impl::setDuctSurfaceExposureFraction(double ductSurfaceExposureFraction) {
103 ✗ bool result = setDouble(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceExposureFraction, ductSurfaceExposureFraction);
104 ✗ return result;
105 }
106
107 ✗ void AirflowNetworkDuctViewFactors_Impl::resetDuctSurfaceExposureFraction() {
108 ✗ bool result = setString(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceExposureFraction, "");
109 ✗ OS_ASSERT(result);
110 ✗ }
111
112 ✗ bool AirflowNetworkDuctViewFactors_Impl::setDuctSurfaceEmittance(double ductSurfaceEmittance) {
113 ✗ bool result = setDouble(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceEmittance, ductSurfaceEmittance);
114 ✗ return result;
115 }
116
117 ✗ void AirflowNetworkDuctViewFactors_Impl::resetDuctSurfaceEmittance() {
118 ✗ bool result = setString(OS_AirflowNetworkDuctViewFactorsFields::DuctSurfaceEmittance, "");
119 ✗ OS_ASSERT(result);
120 ✗ }
121
122 ✗ boost::optional<AirflowNetworkLinkage> AirflowNetworkDuctViewFactors_Impl::optionalLinkage() const {
123 ✗ return getObject<ModelObject>().getModelObjectTarget<AirflowNetworkLinkage>(OS_AirflowNetworkDuctViewFactorsFields::LinkageName);
124 }
125
126 ✗ boost::optional<double> AirflowNetworkDuctViewFactors_Impl::getViewFactor(const PlanarSurface& surf) const {
127 ✗ for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) {
128 ✗ OptionalString name = group.getString(0);
129 ✗ if (name) {
130 ✗ if (name.get() == surf.name()) {
131 ✗ OptionalDouble value = group.getDouble(1);
132 ✗ if (value) {
133 ✗ return value;
134 } else {
135 ✗ LOG(Warn, "Could not read surface view factor " << group.groupIndex() << " in " << briefDescription() << ".");
136 ✗ return boost::none;
137 }
138 }
139 } else {
140 ✗ LOG(Warn, "Could not read surface name " << group.groupIndex() << " in " << briefDescription() << ".");
141 }
142 ✗ }
143 ✗ return boost::none;
144 }
145
146 ✗ std::vector<ViewFactorData> AirflowNetworkDuctViewFactors_Impl::viewFactors() const {
147 ✗ std::vector<ViewFactorData> result;
148 ✗ for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) {
149 ✗ OptionalString name = group.getString(0);
150 ✗ if (name) {
151 ✗ OptionalDouble value = group.getDouble(1);
152 ✗ if (value) {
153 ✗ boost::optional<PlanarSurface> optsurface = group.getModelObjectTarget<PlanarSurface>(0);
154 ✗ if (optsurface) {
155 ✗ result.push_back(ViewFactorData{optsurface.get(), value.get()});
156 } else {
157 ✗ LOG(Warn, "Failed to find surface named " << name.get() << " in " << briefDescription() << ".");
158 }
159 ✗ } else {
160 ✗ LOG(Warn, "Could not read surface view factor " << group.groupIndex() << " in " << briefDescription() << ".");
161 }
162 } else {
163 ✗ LOG(Warn, "Could not read surface name " << group.groupIndex() << " in " << briefDescription() << ".");
164 }
165 ✗ }
166 ✗ return result;
167 ✗ }
168
169 //std::unordered_map<PlanarSurface, double> AirflowNetworkDuctViewFactors_Impl::viewFactorMap() const
170 //{
171 // std::unordered_map<PlanarSurface, double> result;
172 // for (auto &f : viewFactors()) {
173 // result[f.first] = f.second;
174 // }
175 // return result;
176 //}
177
178 2 bool AirflowNetworkDuctViewFactors_Impl::setViewFactor(const PlanarSurface& surf, double F) {
179 //std::vector<unsigned> ids = castVector<WorkspaceExtensibleGroup>(extensibleGroups()) getSourceFieldIndices(surf.handle());
180
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 std::vector<unsigned> ids = getSourceIndices(surf.handle());
181
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
2 if (ids.empty()) {
182
5/5
✓ 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.
1 LOG(Info, "Did not find the surface!");
183 // Didn't find the surface
184
3/5
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
4 std::vector<std::string> values = {toString(surf.handle()), toString(F)};
185
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 auto group = pushExtensibleGroup(values, false).cast<ModelExtensibleGroup>();
186
2/4
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
1 OS_ASSERT(!group.empty());
187 1 } else {
188
5/5
✓ 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.
1 LOG(Info, "Found the surface!");
189 // Found the surface
190 }
191 2 return false;
192 3 }
193
194 ✗ bool AirflowNetworkDuctViewFactors_Impl::removeViewFactor(const PlanarSurface& surf) {
195 ✗ std::vector<unsigned> ids = getSourceIndices(surf.handle());
196 ✗ if (ids.empty()) {
197 ✗ LOG(Info, "Did not find the surface!");
198 // Didn't find the surface
199 ✗ return false;
200 }
201 ✗ LOG(Info, "Found the surface!");
202 // Found the surface, maybe need to check if there is more than one?
203 ✗ return !eraseExtensibleGroup(ids[0]).empty();
204 ✗ }
205
206 ✗ void AirflowNetworkDuctViewFactors_Impl::resetViewFactors() {
207 ✗ auto results = clearExtensibleGroups(false);
208 ✗ OS_ASSERT(!results.empty());
209 ✗ }
210
211 } // namespace detail
212
213 1 AirflowNetworkDuctViewFactors::AirflowNetworkDuctViewFactors(const Model& model)
214 1 : ModelObject(AirflowNetworkDuctViewFactors::iddObjectType(), model) {
215
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 5 not taken.
1 OS_ASSERT(getImpl<detail::AirflowNetworkDuctViewFactors_Impl>());
216
217 // TODO: Appropriately handle the following required object-list fields.
218 // OS_AirflowNetworkDuctViewFactorsFields::LinkageName
219 1 bool ok = true;
220 // ok = setLinkage();
221
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(ok);
222 1 }
223
224 8489 IddObjectType AirflowNetworkDuctViewFactors::iddObjectType() {
225
1/1
✓ Branch 1 taken 8489 times.
8489 return {IddObjectType::OS_AirflowNetworkDuctViewFactors};
226 }
227
228 ✗ AirflowNetworkLinkage AirflowNetworkDuctViewFactors::linkage() const {
229 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->linkage();
230 }
231
232 ✗ double AirflowNetworkDuctViewFactors::ductSurfaceExposureFraction() const {
233 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->ductSurfaceExposureFraction();
234 }
235
236 ✗ bool AirflowNetworkDuctViewFactors::isDuctSurfaceExposureFractionDefaulted() const {
237 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->isDuctSurfaceExposureFractionDefaulted();
238 }
239
240 ✗ double AirflowNetworkDuctViewFactors::ductSurfaceEmittance() const {
241 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->ductSurfaceEmittance();
242 }
243
244 ✗ bool AirflowNetworkDuctViewFactors::isDuctSurfaceEmittanceDefaulted() const {
245 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->isDuctSurfaceEmittanceDefaulted();
246 }
247
248 ✗ bool AirflowNetworkDuctViewFactors::setLinkage(const AirflowNetworkLinkage& linkage) {
249 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->setLinkage(linkage);
250 }
251
252 ✗ bool AirflowNetworkDuctViewFactors::setDuctSurfaceExposureFraction(double ductSurfaceExposureFraction) {
253 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->setDuctSurfaceExposureFraction(ductSurfaceExposureFraction);
254 }
255
256 ✗ void AirflowNetworkDuctViewFactors::resetDuctSurfaceExposureFraction() {
257 ✗ getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->resetDuctSurfaceExposureFraction();
258 ✗ }
259
260 ✗ bool AirflowNetworkDuctViewFactors::setDuctSurfaceEmittance(double ductSurfaceEmittance) {
261 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->setDuctSurfaceEmittance(ductSurfaceEmittance);
262 }
263
264 ✗ void AirflowNetworkDuctViewFactors::resetDuctSurfaceEmittance() {
265 ✗ getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->resetDuctSurfaceEmittance();
266 ✗ }
267
268 ✗ boost::optional<double> AirflowNetworkDuctViewFactors::getViewFactor(const PlanarSurface& surf) const {
269 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->getViewFactor(surf);
270 }
271
272 ✗ std::vector<ViewFactorData> AirflowNetworkDuctViewFactors::viewFactors() const {
273 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->viewFactors();
274 }
275
276 //std::unordered_map<PlanarSurface, double> AirflowNetworkDuctViewFactors::viewFactorMap() const
277 //{
278 // return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->viewFactorMap();
279 //}
280
281 2 bool AirflowNetworkDuctViewFactors::setViewFactor(const PlanarSurface& surf, double F) {
282
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->setViewFactor(surf, F);
283 }
284
285 ✗ bool AirflowNetworkDuctViewFactors::removeViewFactor(const PlanarSurface& surf) {
286 ✗ return getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->removeViewFactor(surf);
287 }
288
289 ✗ void AirflowNetworkDuctViewFactors::resetViewFactors() {
290 ✗ getImpl<detail::AirflowNetworkDuctViewFactors_Impl>()->resetViewFactors();
291 ✗ }
292
293 /// @cond
294 ✗ AirflowNetworkDuctViewFactors::AirflowNetworkDuctViewFactors(std::shared_ptr<detail::AirflowNetworkDuctViewFactors_Impl> impl)
295 ✗ : ModelObject(impl) {}
296 /// @endcond
297
298 } // namespace model
299 } // namespace openstudio
300