GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 33.0% 67 / 0 / 203
Functions: 46.3% 19 / 0 / 41
Branches: 18.2% 53 / 0 / 291

src/model/InternalMassDefinition.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 "InternalMassDefinition.hpp"
7 #include "InternalMassDefinition_Impl.hpp"
8
9 #include "ConstructionBase.hpp"
10 #include "ConstructionBase_Impl.hpp"
11
12 #include <utilities/idd/IddFactory.hxx>
13
14 #include <utilities/idd/OS_InternalMass_Definition_FieldEnums.hxx>
15 #include <utilities/idd/IddEnums.hxx>
16
17 #include "../utilities/math/FloatCompare.hpp"
18 #include "../utilities/core/Assert.hpp"
19
20 namespace openstudio {
21 namespace model {
22
23 namespace detail {
24
25 99 InternalMassDefinition_Impl::InternalMassDefinition_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
26 99 : SpaceLoadDefinition_Impl(idfObject, model, keepHandle) {
27
4/6
✓ Branch 1 taken 99 times.
✓ Branch 4 taken 99 times.
✓ Branch 7 taken 99 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 99 times.
✗ Branch 13 not taken.
99 OS_ASSERT(idfObject.iddObject().type() == InternalMassDefinition::iddObjectType());
28 99 }
29
30 58 InternalMassDefinition_Impl::InternalMassDefinition_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
31 58 bool keepHandle)
32 58 : SpaceLoadDefinition_Impl(other, model, keepHandle) {
33
4/6
✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58 times.
✗ Branch 13 not taken.
58 OS_ASSERT(other.iddObject().type() == InternalMassDefinition::iddObjectType());
34 58 }
35
36 12 InternalMassDefinition_Impl::InternalMassDefinition_Impl(const InternalMassDefinition_Impl& other, Model_Impl* model, bool keepHandle)
37 12 : SpaceLoadDefinition_Impl(other, model, keepHandle) {}
38
39 ✗ const std::vector<std::string>& InternalMassDefinition_Impl::outputVariableNames() const {
40 ✗ static const std::vector<std::string> result;
41 ✗ return result;
42 }
43
44 ✗ IddObjectType InternalMassDefinition_Impl::iddObjectType() const {
45 ✗ return InternalMassDefinition::iddObjectType();
46 }
47
48 36 std::string InternalMassDefinition_Impl::designLevelCalculationMethod() const {
49
1/1
✓ Branch 1 taken 36 times.
36 boost::optional<std::string> value = getString(OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod, true);
50
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 4 not taken.
36 OS_ASSERT(value);
51
2/2
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
72 return value.get();
52 36 }
53
54 12 boost::optional<double> InternalMassDefinition_Impl::surfaceArea() const {
55 12 boost::optional<double> result;
56
4/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 11 taken 12 times.
✗ Branch 12 not taken.
36 if (istringEqual("SurfaceArea", this->designLevelCalculationMethod())) {
57
1/1
✓ Branch 1 taken 12 times.
12 result = getDouble(OS_InternalMass_DefinitionFields::SurfaceArea, true);
58 //OS_ASSERT(result);
59 }
60 12 return result;
61 }
62
63 12 boost::optional<double> InternalMassDefinition_Impl::surfaceAreaperSpaceFloorArea() const {
64 12 boost::optional<double> result;
65
4/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
36 if (istringEqual("SurfaceArea/Area", this->designLevelCalculationMethod())) {
66 ✗ result = getDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, true);
67 //OS_ASSERT(result);
68 }
69 12 return result;
70 }
71
72 12 boost::optional<double> InternalMassDefinition_Impl::surfaceAreaperPerson() const {
73 12 boost::optional<double> result;
74
4/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
36 if (istringEqual("SurfaceArea/Person", this->designLevelCalculationMethod())) {
75 ✗ result = getDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, true);
76 //OS_ASSERT(result);
77 }
78 12 return result;
79 }
80
81 72 bool InternalMassDefinition_Impl::setSurfaceArea(boost::optional<double> surfaceArea) {
82 72 bool result = true;
83
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if (surfaceArea) {
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
72 if (*surfaceArea < 0) {
85 ✗ result = false;
86 } else {
87
2/2
✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
144 result = setString(OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod, "SurfaceArea");
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 OS_ASSERT(result);
89 72 result = setDouble(OS_InternalMass_DefinitionFields::SurfaceArea, surfaceArea.get());
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 OS_ASSERT(result);
91
2/2
✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
144 result = setString(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, "");
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 OS_ASSERT(result);
93
2/2
✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
144 result = setString(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, "");
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 OS_ASSERT(result);
95 }
96 } else {
97 ✗ if (istringEqual("SurfaceArea", this->designLevelCalculationMethod())) {
98 ✗ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceArea, 0.0);
99 }
100 }
101 72 return result;
102 }
103
104 ✗ bool InternalMassDefinition_Impl::setSurfaceAreaperSpaceFloorArea(boost::optional<double> surfaceAreaperSpaceFloorArea) {
105 ✗ bool result = true;
106 ✗ if (surfaceAreaperSpaceFloorArea) {
107 ✗ if (*surfaceAreaperSpaceFloorArea < 0) {
108 ✗ result = false;
109 } else {
110 ✗ result = setString(OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod, "SurfaceArea/Area");
111 ✗ OS_ASSERT(result);
112 ✗ result = setString(OS_InternalMass_DefinitionFields::SurfaceArea, "");
113 ✗ OS_ASSERT(result);
114 ✗ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, surfaceAreaperSpaceFloorArea.get());
115 ✗ OS_ASSERT(result);
116 ✗ result = setString(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, "");
117 ✗ OS_ASSERT(result);
118 }
119 } else {
120 ✗ if (istringEqual("SurfaceArea/Area", this->designLevelCalculationMethod())) {
121 ✗ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, 0.0);
122 }
123 }
124 ✗ return result;
125 }
126
127 ✗ bool InternalMassDefinition_Impl::setSurfaceAreaperPerson(boost::optional<double> surfaceAreaperPerson) {
128 ✗ bool result = true;
129 ✗ if (surfaceAreaperPerson) {
130 ✗ if (*surfaceAreaperPerson < 0) {
131 ✗ result = false;
132 } else {
133 ✗ result = setString(OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod, "SurfaceArea/Person");
134 ✗ OS_ASSERT(result);
135 ✗ result = setString(OS_InternalMass_DefinitionFields::SurfaceArea, "");
136 ✗ OS_ASSERT(result);
137 ✗ result = setString(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, "");
138 ✗ OS_ASSERT(result);
139 ✗ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, surfaceAreaperPerson.get());
140 ✗ OS_ASSERT(result);
141 }
142 } else {
143 ✗ if (istringEqual("SurfaceArea/Person", this->designLevelCalculationMethod())) {
144 ✗ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, 0.0);
145 }
146 }
147 ✗ return result;
148 }
149
150 12 boost::optional<ConstructionBase> InternalMassDefinition_Impl::construction() const {
151
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 return getObject<ModelObject>().getModelObjectTarget<ConstructionBase>(OS_InternalMass_DefinitionFields::ConstructionName);
152 }
153
154 ✗ bool InternalMassDefinition_Impl::isConstructionDefaulted() const {
155 ✗ return isEmpty(OS_InternalMass_DefinitionFields::ConstructionName);
156 }
157
158 28 bool InternalMassDefinition_Impl::setConstruction(const ConstructionBase& construction) {
159
2/2
✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
28 return setPointer(OS_InternalMass_DefinitionFields::ConstructionName, construction.handle());
160 }
161
162 ✗ void InternalMassDefinition_Impl::resetConstruction() {
163 ✗ setString(OS_InternalMass_DefinitionFields::ConstructionName, "");
164 ✗ }
165
166 ✗ double InternalMassDefinition_Impl::getSurfaceArea(double floorArea, double numPeople) const {
167 ✗ std::string method = designLevelCalculationMethod();
168
169 ✗ if (method == "SurfaceArea") {
170 ✗ return surfaceArea().get();
171 ✗ } else if (method == "SurfaceArea/Area") {
172 ✗ return surfaceAreaperSpaceFloorArea().get() * floorArea;
173 ✗ } else if (method == "SurfaceArea/Person") {
174 ✗ return surfaceAreaperPerson().get() * numPeople;
175 }
176
177 ✗ OS_ASSERT(false);
178 ✗ return 0.0;
179 ✗ }
180
181 ✗ double InternalMassDefinition_Impl::getSurfaceAreaPerFloorArea(double floorArea, double numPeople) const {
182 ✗ std::string method = designLevelCalculationMethod();
183
184 ✗ if (method == "SurfaceArea") {
185 ✗ if (equal(floorArea, 0.0)) {
186 ✗ LOG_AND_THROW("Calculation would require division by zero.");
187 }
188 ✗ return surfaceArea().get() / floorArea;
189 ✗ } else if (method == "SurfaceArea/Area") {
190 ✗ return surfaceAreaperSpaceFloorArea().get();
191 ✗ } else if (method == "SurfaceArea/Person") {
192 ✗ if (equal(floorArea, 0.0)) {
193 ✗ LOG_AND_THROW("Calculation would require division by zero.");
194 }
195 ✗ return surfaceAreaperPerson().get() * numPeople / floorArea;
196 }
197
198 ✗ OS_ASSERT(false);
199 ✗ return 0.0;
200 ✗ }
201
202 ✗ double InternalMassDefinition_Impl::getSurfaceAreaPerPerson(double floorArea, double numPeople) const {
203 ✗ std::string method = designLevelCalculationMethod();
204
205 ✗ if (method == "SurfaceArea") {
206 ✗ if (equal(numPeople, 0.0)) {
207 ✗ LOG_AND_THROW("Calculation would require division by zero.");
208 }
209 ✗ return surfaceArea().get() / numPeople;
210 ✗ } else if (method == "SurfaceArea/Area") {
211 ✗ if (equal(numPeople, 0.0)) {
212 ✗ LOG_AND_THROW("Calculation would require division by zero.");
213 }
214 ✗ return surfaceAreaperSpaceFloorArea().get() * floorArea / numPeople;
215 ✗ } else if (method == "SurfaceArea/Person") {
216 ✗ return surfaceAreaperPerson().get();
217 }
218
219 ✗ OS_ASSERT(false);
220 ✗ return 0.0;
221 ✗ }
222
223 ✗ bool InternalMassDefinition_Impl::setDesignLevelCalculationMethod(const std::string& method, double floorArea, double numPeople) {
224 ✗ std::string wmethod(method);
225 ✗ boost::to_lower(wmethod);
226
227 ✗ if (wmethod == "surfacearea") {
228 ✗ return setSurfaceArea(getSurfaceArea(floorArea, numPeople));
229 ✗ } else if (wmethod == "surfacearea/area") {
230 ✗ return setSurfaceAreaperSpaceFloorArea(getSurfaceAreaPerFloorArea(floorArea, numPeople));
231 ✗ } else if (wmethod == "surfacearea/person") {
232 ✗ return setSurfaceAreaperPerson(getSurfaceAreaPerPerson(floorArea, numPeople));
233 }
234
235 ✗ return false;
236 ✗ }
237
238 ✗ boost::optional<ModelObject> InternalMassDefinition_Impl::constructionAsModelObject() const {
239 ✗ OptionalModelObject result;
240 ✗ OptionalConstructionBase intermediate = construction();
241 ✗ if (intermediate) {
242 ✗ result = *intermediate;
243 }
244 ✗ return result;
245 ✗ }
246
247 ✗ bool InternalMassDefinition_Impl::setConstructionAsModelObject(const boost::optional<ModelObject>& modelObject) {
248 ✗ if (modelObject) {
249 ✗ OptionalConstructionBase intermediate = modelObject->optionalCast<ConstructionBase>();
250 ✗ if (intermediate) {
251 ✗ return setConstruction(*intermediate);
252 } else {
253 ✗ return false;
254 }
255 ✗ } else {
256 ✗ resetConstruction();
257 }
258 ✗ return true;
259 }
260
261 } // namespace detail
262
263 41 InternalMassDefinition::InternalMassDefinition(const Model& model) : SpaceLoadDefinition(InternalMassDefinition::iddObjectType(), model) {
264
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
✗ Branch 5 not taken.
41 OS_ASSERT(getImpl<detail::InternalMassDefinition_Impl>());
265
1/1
✓ Branch 1 taken 41 times.
41 bool test = this->setSurfaceArea(0.0);
266
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
✗ Branch 3 not taken.
41 OS_ASSERT(test);
267 41 }
268
269 7926 IddObjectType InternalMassDefinition::iddObjectType() {
270
1/1
✓ Branch 1 taken 7926 times.
7926 IddObjectType result(IddObjectType::OS_InternalMass_Definition);
271 7926 return result;
272 }
273
274 ✗ std::vector<std::string> InternalMassDefinition::validDesignLevelCalculationMethodValues() {
275 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod);
276 }
277
278 ✗ std::string InternalMassDefinition::designLevelCalculationMethod() const {
279 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->designLevelCalculationMethod();
280 }
281
282 12 boost::optional<double> InternalMassDefinition::surfaceArea() const {
283
1/1
✓ Branch 3 taken 12 times.
12 return getImpl<detail::InternalMassDefinition_Impl>()->surfaceArea();
284 }
285
286 12 boost::optional<double> InternalMassDefinition::surfaceAreaperSpaceFloorArea() const {
287
1/1
✓ Branch 3 taken 12 times.
12 return getImpl<detail::InternalMassDefinition_Impl>()->surfaceAreaperSpaceFloorArea();
288 }
289
290 12 boost::optional<double> InternalMassDefinition::surfaceAreaperPerson() const {
291
1/1
✓ Branch 3 taken 12 times.
12 return getImpl<detail::InternalMassDefinition_Impl>()->surfaceAreaperPerson();
292 }
293
294 72 bool InternalMassDefinition::setSurfaceArea(double surfaceArea) {
295
2/2
✓ Branch 3 taken 72 times.
✓ Branch 6 taken 72 times.
72 return getImpl<detail::InternalMassDefinition_Impl>()->setSurfaceArea(surfaceArea);
296 }
297
298 ✗ bool InternalMassDefinition::setSurfaceAreaperSpaceFloorArea(double surfaceAreaperSpaceFloorArea) {
299 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->setSurfaceAreaperSpaceFloorArea(surfaceAreaperSpaceFloorArea);
300 }
301
302 ✗ bool InternalMassDefinition::setSurfaceAreaperPerson(double surfaceAreaperPerson) {
303 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->setSurfaceAreaperPerson(surfaceAreaperPerson);
304 }
305
306 12 boost::optional<ConstructionBase> InternalMassDefinition::construction() const {
307
1/1
✓ Branch 3 taken 12 times.
12 return getImpl<detail::InternalMassDefinition_Impl>()->construction();
308 }
309
310 ✗ bool InternalMassDefinition::isConstructionDefaulted() const {
311 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->isConstructionDefaulted();
312 }
313
314 28 bool InternalMassDefinition::setConstruction(const ConstructionBase& construction) {
315
1/1
✓ Branch 3 taken 28 times.
28 return getImpl<detail::InternalMassDefinition_Impl>()->setConstruction(construction);
316 }
317
318 ✗ void InternalMassDefinition::resetConstruction() {
319 ✗ getImpl<detail::InternalMassDefinition_Impl>()->resetConstruction();
320 ✗ }
321
322 ✗ double InternalMassDefinition::getSurfaceArea(double floorArea, double numPeople) const {
323 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->getSurfaceArea(floorArea, numPeople);
324 }
325
326 ✗ double InternalMassDefinition::getSurfaceAreaPerFloorArea(double floorArea, double numPeople) const {
327 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->getSurfaceAreaPerFloorArea(floorArea, numPeople);
328 }
329
330 ✗ double InternalMassDefinition::getSurfaceAreaPerPerson(double floorArea, double numPeople) const {
331 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->getSurfaceAreaPerPerson(floorArea, numPeople);
332 }
333
334 ✗ bool InternalMassDefinition::setDesignLevelCalculationMethod(const std::string& method, double floorArea, double numPeople) {
335 ✗ return getImpl<detail::InternalMassDefinition_Impl>()->setDesignLevelCalculationMethod(method, floorArea, numPeople);
336 }
337
338 /// @cond
339
1/1
✓ Branch 3 taken 12 times.
12 InternalMassDefinition::InternalMassDefinition(std::shared_ptr<detail::InternalMassDefinition_Impl> impl) : SpaceLoadDefinition(std::move(impl)) {}
340 /// @endcond
341
342 } // namespace model
343 } // namespace openstudio
344