GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 63.1% 41 / 0 / 65
Functions: 100.0% 1 / 0 / 1
Branches: 46.5% 46 / 0 / 99

src/energyplus/ForwardTranslator/ForwardTranslateInternalMass.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 "../ForwardTranslator.hpp"
7
8 #include "../../model/Model.hpp"
9 #include "../../model/InternalMass.hpp"
10 #include "../../model/InternalMass_Impl.hpp"
11 #include "../../model/InternalMassDefinition.hpp"
12 #include "../../model/InternalMassDefinition_Impl.hpp"
13 #include "../../model/Space.hpp"
14 #include "../../model/Space_Impl.hpp"
15 #include "../../model/SpaceType.hpp"
16 #include "../../model/SpaceType_Impl.hpp"
17 #include "../../model/ThermalZone.hpp"
18 #include "../../model/ThermalZone_Impl.hpp"
19 #include "../../model/ConstructionBase.hpp"
20 #include "../../model/ConstructionBase_Impl.hpp"
21 #include "../../model/SurfacePropertyConvectionCoefficients.hpp"
22
23 #include <utilities/idd/InternalMass_FieldEnums.hxx>
24 #include "../../utilities/idd/IddEnums.hpp"
25 #include <utilities/idd/IddEnums.hxx>
26
27 using namespace openstudio::model;
28
29 using namespace std;
30
31 namespace openstudio {
32
33 namespace energyplus {
34
35 12 boost::optional<IdfObject> ForwardTranslator::translateInternalMass(model::InternalMass& modelObject) {
36
37 // TODO: handle (m_forwardTranslatorOptions.excludeSpaceTranslation() = false)
38 // Note: E+kept a ‘Zone or ZoneList name’ field and added a ‘Space or SpaceList’ field.
39 // It should have been a single ‘Zone or ZoneList or Space or SpaceList Name’ like it's done on many other objects
40 // If former is specified as a **ZONELIST** name, later is omitted.
41 // Currently you do need to write BOTH the Zone Name (as its a required field) and Space Name when you want to bind it to a Space
42
43 // EnergyPlus does not support internal mass objects referencing zone lists (TODO: <-- this is outdated)
44
45
1/1
✓ Branch 1 taken 12 times.
12 InternalMassDefinition definition = modelObject.internalMassDefinition();
46
47
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<ConstructionBase> construction = definition.construction();
48
49 12 bool prefixSpaceName = false;
50 12 std::vector<Space> spaces;
51
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<Space> space = modelObject.space();
52
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<SpaceType> spaceType = modelObject.spaceType();
53
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (space) {
54
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 spaces.push_back(*space);
55 ✗ } else if (spaceType) {
56 ✗ prefixSpaceName = true;
57 ✗ spaces = spaceType->spaces();
58 }
59
60 // Call the translation of the SurfacePropertyConvectionCoefficients, which has two advantages:
61 // * will not translate them if they are orphaned (=not referencing a surface or subsurface), and,
62 // * makes the order of these objects in the IDF deterministic
63
3/3
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 10 times.
24 if (boost::optional<SurfacePropertyConvectionCoefficients> _sCoefs = modelObject.surfacePropertyConvectionCoefficients()) {
64
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 translateAndMapModelObject(_sCoefs.get());
65 12 }
66
67 12 boost::optional<IdfObject> result;
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (spaces.empty()) {
69
70 // translate detached internal mass object
71 ✗ IdfObject idfObject(openstudio::IddObjectType::InternalMass);
72
73 ✗ m_idfObjects.push_back(idfObject);
74
75 ✗ if (construction) {
76 ✗ idfObject.setString(InternalMassFields::ConstructionName, construction->nameString());
77 }
78
79 ✗ double surfaceArea = 0;
80
81 ✗ OptionalDouble d = definition.surfaceArea();
82 ✗ if (d) {
83 ✗ surfaceArea += *d;
84 }
85
86 ✗ d = definition.surfaceAreaperSpaceFloorArea();
87 ✗ if (d) {
88 ✗ LOG(Error, "Cannot compute space area because InternalMass object does not reference a Space or SpaceType");
89 }
90
91 ✗ d = definition.surfaceAreaperPerson();
92 ✗ if (d) {
93 ✗ LOG(Error, "Cannot compute number of people because InternalMass object does not reference a Space or SpaceType");
94 }
95
96 ✗ double multiplier = modelObject.multiplier();
97
98 ✗ idfObject.setDouble(InternalMassFields::SurfaceArea, multiplier * surfaceArea);
99
100 ✗ result = idfObject;
101 ✗ } else {
102
103 // create InternalMass object for each zone
104
2/2
✓ Branch 5 taken 12 times.
✓ Branch 6 taken 12 times.
24 for (const Space& space : spaces) {
105
106
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 IdfObject idfObject(openstudio::IddObjectType::InternalMass);
107
108
1/1
✓ Branch 1 taken 12 times.
12 m_idfObjects.push_back(idfObject);
109
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (prefixSpaceName) {
111 ✗ idfObject.setString(InternalMassFields::Name, space.nameString() + " " + modelObject.nameString());
112 } else {
113
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 idfObject.setString(InternalMassFields::Name, modelObject.nameString());
114 }
115
116 // Even if we want to bind to a Space Name, we need to write the Zone Name as it's a required field
117 // cf https://github.com/NREL/EnergyPlus/issues/9141
118 // As of E+ v24.2, Zone Name is ignored when Space Name is specified
119
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<ThermalZone> thermalZone = space.thermalZone();
120
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (thermalZone) {
121
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 idfObject.setString(InternalMassFields::ZoneorZoneListName, thermalZone->nameString());
122 }
123
2/3
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
12 if (!m_forwardTranslatorOptions.excludeSpaceTranslation()) {
124
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 idfObject.setString(InternalMassFields::SpaceorSpaceListName, space.nameString());
125 }
126
127
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
12 if (construction) {
128
3/3
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
7 idfObject.setString(InternalMassFields::ConstructionName, construction->nameString());
129 }
130
131 12 double surfaceArea = 0;
132
133
1/1
✓ Branch 1 taken 12 times.
12 OptionalDouble d = definition.surfaceArea();
134
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (d) {
135
1/1
✓ Branch 1 taken 12 times.
12 surfaceArea += *d;
136 }
137
138
1/1
✓ Branch 1 taken 12 times.
12 d = definition.surfaceAreaperSpaceFloorArea();
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (d) {
140 ✗ surfaceArea += (*d) * space.floorArea();
141 }
142
143
1/1
✓ Branch 1 taken 12 times.
12 d = definition.surfaceAreaperPerson();
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (d) {
145 ✗ surfaceArea += (*d) * space.numberOfPeople();
146 }
147
148
1/1
✓ Branch 1 taken 12 times.
12 double multiplier = modelObject.multiplier();
149
150
1/1
✓ Branch 1 taken 12 times.
12 idfObject.setDouble(InternalMassFields::SurfaceArea, multiplier * surfaceArea);
151
152
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 if (!result) {
153
1/1
✓ Branch 1 taken 12 times.
12 result = idfObject;
154 }
155 12 }
156 }
157
158 24 return result;
159 12 }
160
161 } // namespace energyplus
162
163 } // namespace openstudio
164