GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 165
Functions: 0.0% 0 / 0 / 1
Branches: 0.0% 0 / 0 / 355

src/energyplus/ReverseTranslator/ReverseTranslateAirLoopHVAC.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 "../ReverseTranslator.hpp"
7 #include "../../model/AirLoopHVAC.hpp"
8 #include "../../model/AirLoopHVAC_Impl.hpp"
9 #include "../../model/HVACComponent.hpp"
10 #include "../../model/HVACComponent_Impl.hpp"
11 #include "../../model/Node.hpp"
12 #include "../../model/Node_Impl.hpp"
13 #include "../../model/PortList.hpp"
14 #include "../../model/PortList_Impl.hpp"
15 #include "../../model/Space.hpp"
16 #include "../../model/Space_Impl.hpp"
17 #include "../../model/ThermalZone.hpp"
18 #include "../../model/ThermalZone_Impl.hpp"
19 #include "../../model/AirLoopHVACOutdoorAirSystem.hpp"
20 #include "../../model/AirLoopHVACOutdoorAirSystem_Impl.hpp"
21 #include "../../model/ScheduleCompact.hpp"
22 #include "../../model/ScheduleCompact_Impl.hpp"
23 #include "../../model/AirTerminalSingleDuctConstantVolumeNoReheat.hpp"
24 #include "../../model/AirTerminalSingleDuctConstantVolumeNoReheat_Impl.hpp"
25 #include <utilities/idd/AirLoopHVAC_FieldEnums.hxx>
26 #include <utilities/idd/AirLoopHVAC_ZoneMixer_FieldEnums.hxx>
27 #include <utilities/idd/ZoneHVAC_AirDistributionUnit_FieldEnums.hxx>
28 #include <utilities/idd/BranchList_FieldEnums.hxx>
29 #include <utilities/idd/Branch_FieldEnums.hxx>
30 #include <utilities/idd/ZoneHVAC_EquipmentConnections_FieldEnums.hxx>
31 #include "../../utilities/idd/IddEnums.hpp"
32 #include <utilities/idd/IddEnums.hxx>
33 #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp"
34
35 using namespace openstudio::model;
36
37 namespace openstudio {
38
39 namespace energyplus {
40
41 ✗ OptionalModelObject ReverseTranslator::translateAirLoopHVAC(const WorkspaceObject& workspaceObject) {
42 ✗ if (workspaceObject.iddObject().type() != IddObjectType::AirLoopHVAC) {
43 ✗ LOG(Error, "WorkspaceObject is not IddObjectType: AirLoopHVAC");
44 ✗ return boost::none;
45 }
46
47 ✗ OptionalModelObject result;
48 ✗ boost::optional<double> val;
49 ✗ boost::optional<std::string> optionalString;
50 ✗ Workspace _workspace = workspaceObject.workspace();
51
52 ✗ openstudio::model::AirLoopHVAC airLoopHVAC(m_model);
53
54 ✗ boost::optional<std::string> supplyInletNodeName = workspaceObject.getString(AirLoopHVACFields::SupplySideInletNodeName);
55 ✗ boost::optional<std::string> supplyOutletNodeName = workspaceObject.getString(AirLoopHVACFields::SupplySideOutletNodeNames);
56 ✗ boost::optional<std::string> demandInletNodeName = workspaceObject.getString(AirLoopHVACFields::DemandSideInletNodeNames);
57 ✗ boost::optional<std::string> demandOutletNodeName = workspaceObject.getString(AirLoopHVACFields::DemandSideOutletNodeName);
58
59 ✗ Node supplyInletNode = airLoopHVAC.supplyInletNode();
60 ✗ Node supplyOutletNode = airLoopHVAC.supplyOutletNode();
61 ✗ Node demandInletNode = airLoopHVAC.demandInletNode();
62 ✗ Node demandOutletNode = airLoopHVAC.demandOutletNode();
63
64 ✗ if (supplyInletNodeName) {
65 ✗ supplyInletNode.setName(supplyInletNodeName.get());
66 }
67 ✗ if (supplyOutletNodeName) {
68 ✗ supplyOutletNode.setName(supplyOutletNodeName.get());
69 }
70 ✗ if (demandInletNodeName) {
71 ✗ demandInletNode.setName(demandInletNodeName.get());
72 }
73 ✗ if (demandOutletNodeName) {
74 ✗ demandOutletNode.setName(demandOutletNodeName.get());
75 }
76
77 ✗ optionalString = workspaceObject.getString(AirLoopHVACFields::Name);
78 ✗ if (optionalString) {
79 ✗ airLoopHVAC.setName(optionalString.get());
80 }
81
82 ✗ optionalString = workspaceObject.getString(AirLoopHVACFields::DesignSupplyAirFlowRate);
83 ✗ if (optionalString && istringEqual(optionalString.get(), "AutoSize")) {
84 ✗ airLoopHVAC.autosizeDesignSupplyAirFlowRate();
85 ✗ } else if ((val = workspaceObject.getDouble(AirLoopHVACFields::DesignSupplyAirFlowRate))) {
86 ✗ airLoopHVAC.setDesignSupplyAirFlowRate(val.get());
87 }
88
89 // Go find the supply branch.
90 // Currently only supporting one supply branch.
91 // Dual ducts are not supported.
92 ✗ OptionalWorkspaceObject _supplyBranchList;
93 ✗ OptionalWorkspaceObject _supplyBranch;
94
95 ✗ _supplyBranchList = workspaceObject.getTarget(AirLoopHVACFields::BranchListName);
96 ✗ if (_supplyBranchList) {
97 ✗ _supplyBranch = _supplyBranchList->getExtensibleGroup(0).cast<WorkspaceExtensibleGroup>().getTarget(BranchListExtensibleFields::BranchName);
98 ✗ if (!_supplyBranch) {
99 ✗ LOG(Error, _supplyBranchList->briefDescription() << ": Missing supply branch");
100 } else {
101 // March through the equipment on the supply branch and convert them.
102 ✗ for (unsigned i = 0; !_supplyBranch->getExtensibleGroup(i).empty(); i++) {
103 ✗ auto eg = _supplyBranch->getExtensibleGroup(i).cast<WorkspaceExtensibleGroup>();
104 ✗ boost::optional<std::string> componentName = eg.getString(BranchExtensibleFields::ComponentName);
105 ✗ boost::optional<std::string> componentType = eg.getString(BranchExtensibleFields::ComponentObjectType);
106 ✗ boost::optional<std::string> componentInletNodeName = eg.getString(BranchExtensibleFields::ComponentInletNodeName);
107 ✗ boost::optional<std::string> componentOutletNodeName = eg.getString(BranchExtensibleFields::ComponentOutletNodeName);
108 ✗ boost::optional<WorkspaceObject> wo;
109 ✗ OptionalNode node;
110 ✗ OptionalModelObject targetModelObject;
111
112 ✗ if (componentName && (!componentName.get().empty()) && componentType && (!componentType.get().empty())) {
113 ✗ IddObjectType iddType(componentType.get());
114 ✗ wo = _workspace.getObjectByTypeAndName(iddType, componentName.get());
115 }
116
117 ✗ if (wo) {
118 ✗ targetModelObject = translateAndMapWorkspaceObject(wo.get());
119 ✗ if (!targetModelObject) {
120 ✗ LOG(Error, "Error importing object: " << wo->briefDescription());
121 ✗ continue;
122 ✗ }
123
124 ✗ if (OptionalHVACComponent hvacComponent = targetModelObject->optionalCast<HVACComponent>()) {
125 ✗ Node node = airLoopHVAC.supplyOutletNode();
126 ✗ if (hvacComponent->addToNode(node)) {
127 ✗ if (boost::optional<StraightComponent> straightComponent = hvacComponent->optionalCast<StraightComponent>()) {
128 ✗ Node outletNode = straightComponent->outletModelObject()->cast<Node>();
129 ✗ Node inletNode = straightComponent->inletModelObject()->cast<Node>();
130 ✗ if (componentOutletNodeName) {
131 ✗ outletNode.setName(componentOutletNodeName.get());
132 }
133 ✗ if (componentInletNodeName) {
134 ✗ inletNode.setName(componentInletNodeName.get());
135 }
136 ✗ } else if (boost::optional<AirLoopHVACOutdoorAirSystem> oaSystem = hvacComponent->optionalCast<AirLoopHVACOutdoorAirSystem>()) {
137 ✗ Node outletNode = oaSystem->mixedAirModelObject()->cast<Node>();
138 ✗ Node inletNode = oaSystem->returnAirModelObject()->cast<Node>();
139 ✗ if (componentOutletNodeName) {
140 ✗ outletNode.setName(componentOutletNodeName.get());
141 }
142 ✗ if (componentInletNodeName) {
143 ✗ inletNode.setName(componentInletNodeName.get());
144 }
145 ✗ }
146 }
147 ✗ }
148 } else {
149 ✗ LOG(Error, _supplyBranch->briefDescription() << ": Missing object listed at ComponentName " << i);
150 }
151 ✗ }
152 }
153 } else {
154 ✗ LOG(Error, workspaceObject.briefDescription() << ": Missing supply branch list, " << "Supply equipment will be incomplete");
155 }
156
157 // March through the zone on the demand side and add branches for them.
158 ✗ if (demandOutletNodeName) {
159 // Find the zone mixer for this air loop
160 ✗ std::vector<WorkspaceObject> _airLoopHVACZoneMixers;
161 ✗ _airLoopHVACZoneMixers = workspaceObject.workspace().getObjectsByType(IddObjectType::AirLoopHVAC_ZoneMixer);
162
163 ✗ boost::optional<WorkspaceObject> _airLoopHVACZoneMixer;
164 ✗ for (const auto& elem : _airLoopHVACZoneMixers) {
165 ✗ boost::optional<std::string> mixerOutletNodeName;
166 ✗ mixerOutletNodeName = elem.getString(AirLoopHVAC_ZoneMixerFields::OutletNodeName);
167
168 ✗ if (mixerOutletNodeName && mixerOutletNodeName.get() == demandOutletNodeName.get()) {
169 ✗ _airLoopHVACZoneMixer = elem;
170 ✗ break;
171 }
172 ✗ }
173 ✗ if (_airLoopHVACZoneMixer) {
174 ✗ for (int i = 2; _airLoopHVACZoneMixer->getString(i); i++) {
175
176 ✗ std::vector<WorkspaceObject> _zoneHVACEquipmentConnections;
177
178 ✗ std::string mixerInletNodeName = _airLoopHVACZoneMixer->getString(i).get();
179
180 ✗ _zoneHVACEquipmentConnections = _workspace.getObjectsByType(IddObjectType::ZoneHVAC_EquipmentConnections);
181
182 ✗ for (const auto& _zoneHVACEquipmentConnection : _zoneHVACEquipmentConnections) {
183
184 OptionalString returnAirNodeName =
185 ✗ _zoneHVACEquipmentConnection.getString(ZoneHVAC_EquipmentConnectionsFields::ZoneReturnAirNodeorNodeListName);
186 OptionalString inletAirNodeName =
187 ✗ _zoneHVACEquipmentConnection.getString(ZoneHVAC_EquipmentConnectionsFields::ZoneAirInletNodeorNodeListName);
188 ✗ OptionalString zoneName = _zoneHVACEquipmentConnection.getString(ZoneHVAC_EquipmentConnectionsFields::ZoneName);
189 OptionalString zoneEquipListName =
190 ✗ _zoneHVACEquipmentConnection.getString(ZoneHVAC_EquipmentConnectionsFields::ZoneConditioningEquipmentListName);
191
192 ✗ OptionalWorkspaceObject _zone;
193 ✗ OptionalWorkspaceObject _zoneEquipmentList;
194 ✗ OptionalWorkspaceObject _zoneEquipment;
195 ✗ OptionalWorkspaceObject _airTerminal;
196
197 ✗ if (returnAirNodeName && returnAirNodeName.get() == mixerInletNodeName && zoneName && zoneEquipListName) {
198 ✗ _zone = _workspace.getObjectByTypeAndName(IddObjectType::Zone, *zoneName);
199
200 ✗ _zoneEquipmentList = _workspace.getObjectByTypeAndName(IddObjectType::ZoneHVAC_EquipmentList, zoneEquipListName.get());
201
202 ✗ if (!_zone) {
203 ✗ LOG(Error, airLoopHVAC.briefDescription() << " is connected to a zone that does not exist.");
204
205 ✗ break;
206 }
207
208 ✗ if (!_zoneEquipmentList) {
209 ✗ LOG(Error, _zone->briefDescription() << " does not have a zone equipment list, but it is attached to a loop.");
210
211 ✗ break;
212 }
213
214 ✗ for (int j = 1; (optionalString = _zoneEquipmentList->getString(j)); j = j + 4) {
215 ✗ boost::optional<std::string> zoneEquipmentName = _zoneEquipmentList->getString(j + 1);
216 // Possible Zone Equipment
217 //
218 // ZoneHVAC:AirDistributionUnit
219 // AirTerminal:SingleDuct:ConstantVolume:NoReheat (previously named AirTerminal:SingleDuct:Uncontrolled before 9.0.0)
220 // ZoneHVAC:EnergyRecoveryVentilator
221 // ZoneHVAC:FourPipeFanCoil
222 // ZoneHVAC:OutdoorAirUnit
223 // ZoneHVAC:PackagedTerminalAirConditioner
224 // ZoneHVAC:PackagedTerminalHeatPump
225 // ZoneHVAC:UnitHeater
226 // ZoneHVAC:UnitVentilator
227 // ZoneHVAC:VentilatedSlab
228 // ZoneHVAC:WaterToAirHeatPump
229 // ZoneHVAC:WindowAirConditioner
230 // ZoneHVAC:Baseboard:RadiantConvective:Electric
231 // ZoneHVAC:Baseboard:RadiantConvective:Water
232 // ZoneHVAC:Baseboard:RadiantConvective:Steam
233 // ZoneHVAC:Baseboard:Convective:Electric
234 // ZoneHVAC:Baseboard:Convective:Water
235 // ZoneHVAC:HighTemperatureRadiant
236 // ZoneHVAC:LowTemperatureRadiant:VariableFlow
237 // ZoneHVAC:LowTemperatureRadiant:ConstantFlow
238 // ZoneHVAC:LowTemperatureRadiant:Electric
239 // ZoneHVAC:Dehumidifier:DX
240 // ZoneHVAC:IdealLoadsAirSystem
241 // Fan:ZoneExhaust
242 // WaterHeater:HeatPump
243 //
244 ✗ if (zoneEquipmentName) {
245 // TODO: this block shouldn't happen. Unlike AirTerminal:SingleDuct:Uncontrolled (deprecated in 9.0.0, removed in 9.2.0)
246 // this object cannot be placed directly on a branch and uses a ZoneHVAC:AirDistributionUnit
247 ✗ if (istringEqual(optionalString.get(), "AirTerminal:SingleDuct:ConstantVolume:NoReheat")) {
248 _airTerminal =
249 ✗ _workspace.getObjectByTypeAndName(IddObjectType::AirTerminal_SingleDuct_ConstantVolume_NoReheat, zoneEquipmentName.get());
250
251 ✗ break;
252 ✗ } else if (istringEqual(optionalString.get(), "ZoneHVAC:AirDistributionUnit")) {
253 boost::optional<WorkspaceObject> _airDistributionUnit =
254 ✗ _workspace.getObjectByTypeAndName(IddObjectType::ZoneHVAC_AirDistributionUnit, zoneEquipmentName.get());
255
256 ✗ if (_airDistributionUnit) {
257 ✗ boost::optional<std::string> airUnitName;
258 ✗ boost::optional<std::string> airUnitType;
259
260 ✗ airUnitType = _airDistributionUnit->getString(ZoneHVAC_AirDistributionUnitFields::AirTerminalObjectType);
261 ✗ airUnitName = _airDistributionUnit->getString(ZoneHVAC_AirDistributionUnitFields::AirTerminalName);
262
263 ✗ if (airUnitName && airUnitType) {
264 ✗ _airTerminal = _workspace.getObjectByTypeAndName(IddObjectType(airUnitType.get()), airUnitName.get());
265 }
266 ✗ }
267
268 ✗ break;
269 ✗ }
270 }
271 ✗ }
272
273 ✗ OptionalModelObject airTerminalModelObject;
274 ✗ OptionalSpace space;
275 ✗ OptionalStraightComponent straightComponent;
276 ✗ OptionalThermalZone thermalZone;
277
278 ✗ if (_airTerminal) {
279 ✗ airTerminalModelObject = translateAndMapWorkspaceObject(_airTerminal.get());
280 }
281
282 ✗ if (_zone) {
283 ✗ if (OptionalModelObject mo = translateAndMapWorkspaceObject(_zone.get())) {
284 ✗ space = mo->optionalCast<Space>();
285 ✗ }
286 }
287
288 ✗ if (space) {
289 ✗ thermalZone = space->thermalZone();
290 }
291
292 ✗ if (airTerminalModelObject) {
293 ✗ straightComponent = airTerminalModelObject->optionalCast<StraightComponent>();
294 }
295
296 ✗ bool success = false;
297
298 ✗ if (straightComponent && thermalZone) {
299 ✗ success = airLoopHVAC.addBranchForZone(thermalZone.get(), straightComponent.get());
300 ✗ } else if (thermalZone) {
301 ✗ Model m;
302
303 ✗ success = airLoopHVAC.addBranchForZone(thermalZone.get(), boost::none);
304 ✗ }
305
306 ✗ if (success) {
307 ✗ if (inletAirNodeName) {
308 ✗ thermalZone->inletPortList().airLoopHVACModelObject()->cast<Node>().setName(inletAirNodeName.get());
309 }
310 ✗ if (returnAirNodeName) {
311 ✗ thermalZone->returnAirModelObject()->cast<Node>().setName(returnAirNodeName.get());
312 }
313 }
314 ✗ }
315 ✗ }
316 ✗ }
317 }
318 ✗ }
319
320 ✗ return airLoopHVAC;
321 ✗ }
322
323 } // namespace energyplus
324
325 } // namespace openstudio
326