src/energyplus/ReverseTranslator/ReverseTranslateAirLoopHVACOutdoorAirSystem.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/AirLoopHVACOutdoorAirSystem.hpp" | ||
| 8 | #include "../../model/AirLoopHVACOutdoorAirSystem_Impl.hpp" | ||
| 9 | #include "../../model/ControllerOutdoorAir.hpp" | ||
| 10 | #include "../../model/ControllerOutdoorAir_Impl.hpp" | ||
| 11 | #include "../../model/Node.hpp" | ||
| 12 | #include "../../model/Node_Impl.hpp" | ||
| 13 | #include <utilities/idd/AirLoopHVAC_OutdoorAirSystem_FieldEnums.hxx> | ||
| 14 | #include <utilities/idd/OutdoorAir_Mixer_FieldEnums.hxx> | ||
| 15 | #include <utilities/idd/EvaporativeCooler_Direct_ResearchSpecial_FieldEnums.hxx> | ||
| 16 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 17 | #include <utilities/idd/IddEnums.hxx> | ||
| 18 | |||
| 19 | using namespace openstudio::model; | ||
| 20 | |||
| 21 | namespace openstudio { | ||
| 22 | |||
| 23 | namespace energyplus { | ||
| 24 | |||
| 25 | ✗ | OptionalModelObject ReverseTranslator::translateAirLoopHVACOutdoorAirSystem(const WorkspaceObject& workspaceObject) { | |
| 26 | ✗ | if (workspaceObject.iddObject().type() != IddObjectType::AirLoopHVAC_OutdoorAirSystem) { | |
| 27 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: AirLoopHVAC_OutdoorAirSystem"); | |
| 28 | ✗ | return boost::none; | |
| 29 | } | ||
| 30 | |||
| 31 | ✗ | Workspace _workspace = workspaceObject.workspace(); | |
| 32 | |||
| 33 | ✗ | boost::optional<WorkspaceObject> _controllerList; | |
| 34 | ✗ | boost::optional<WorkspaceObject> _controllerOutdoorAir; | |
| 35 | ✗ | boost::optional<std::string> controllerName; | |
| 36 | ✗ | boost::optional<std::string> controllerType; | |
| 37 | ✗ | boost::optional<ControllerOutdoorAir> oaController; | |
| 38 | |||
| 39 | ✗ | _controllerList = workspaceObject.getTarget(AirLoopHVAC_OutdoorAirSystemFields::ControllerListName); | |
| 40 | |||
| 41 | ✗ | if (_controllerList) { | |
| 42 | ✗ | for (int i = 1; _controllerList->getString(i); i = i + 2) { | |
| 43 | ✗ | controllerType = _controllerList->getString(i); | |
| 44 | ✗ | controllerName = _controllerList->getString(i + 1); | |
| 45 | ✗ | if (controllerType) { | |
| 46 | ✗ | if (istringEqual(controllerType.get(), "Controller:OutdoorAir")) { | |
| 47 | ✗ | break; | |
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | ✗ | if (controllerName && controllerType) { | |
| 54 | ✗ | boost::optional<WorkspaceObject> wo = _workspace.getObjectByTypeAndName(IddObjectType(controllerType.get()), controllerName.get()); | |
| 55 | ✗ | if (wo) { | |
| 56 | ✗ | boost::optional<ModelObject> mo = translateAndMapWorkspaceObject(wo.get()); | |
| 57 | ✗ | if (mo) { | |
| 58 | ✗ | oaController = mo->optionalCast<ControllerOutdoorAir>(); | |
| 59 | } | ||
| 60 | ✗ | } | |
| 61 | ✗ | } | |
| 62 | |||
| 63 | ✗ | if (oaController) { | |
| 64 | ✗ | AirLoopHVACOutdoorAirSystem mo(m_model, oaController.get()); | |
| 65 | |||
| 66 | ✗ | boost::optional<std::string> name = workspaceObject.getString(AirLoopHVAC_OutdoorAirSystemFields::Name); | |
| 67 | ✗ | if (name) { | |
| 68 | ✗ | mo.setName(name.get()); | |
| 69 | } | ||
| 70 | |||
| 71 | ✗ | Node outboardOANode = mo.outboardOANode().get(); | |
| 72 | |||
| 73 | ✗ | boost::optional<WorkspaceObject> _oaEquipmentList; | |
| 74 | ✗ | boost::optional<WorkspaceObject> _outdoorAirMixer; | |
| 75 | ✗ | std::vector<WorkspaceObject> equipmentVector; | |
| 76 | ✗ | _oaEquipmentList = workspaceObject.getTarget(AirLoopHVAC_OutdoorAirSystemFields::OutdoorAirEquipmentListName); | |
| 77 | |||
| 78 | ✗ | if (_oaEquipmentList) { | |
| 79 | ✗ | for (int i = 1; _oaEquipmentList->getString(i); i = i + 2) { | |
| 80 | ✗ | boost::optional<std::string> equipmentName; | |
| 81 | ✗ | boost::optional<std::string> equipmentType; | |
| 82 | |||
| 83 | ✗ | equipmentType = _oaEquipmentList->getString(i); | |
| 84 | ✗ | equipmentName = _oaEquipmentList->getString(i + 1); | |
| 85 | |||
| 86 | ✗ | if (equipmentName && equipmentType) { | |
| 87 | ✗ | boost::optional<WorkspaceObject> wo = _workspace.getObjectByTypeAndName(IddObjectType(equipmentType.get()), equipmentName.get()); | |
| 88 | ✗ | if (wo) { | |
| 89 | ✗ | equipmentVector.push_back(wo.get()); | |
| 90 | |||
| 91 | ✗ | if (wo->iddObject().type() == IddObjectType::OutdoorAir_Mixer) { | |
| 92 | ✗ | _outdoorAirMixer = wo; | |
| 93 | } | ||
| 94 | } | ||
| 95 | ✗ | } | |
| 96 | ✗ | } | |
| 97 | ✗ | if (_outdoorAirMixer) { | |
| 98 | ✗ | boost::optional<std::string> mixerOAInletNodeName = _outdoorAirMixer->getString(OutdoorAir_MixerFields::OutdoorAirStreamNodeName); | |
| 99 | ✗ | boost::optional<std::string> mixerOAReliefNodeName = _outdoorAirMixer->getString(OutdoorAir_MixerFields::ReliefAirStreamNodeName); | |
| 100 | ✗ | if (mixerOAInletNodeName) { | |
| 101 | ✗ | mo.outdoorAirModelObject()->cast<Node>().setName(mixerOAInletNodeName.get()); | |
| 102 | } | ||
| 103 | ✗ | if (mixerOAReliefNodeName) { | |
| 104 | ✗ | mo.reliefAirModelObject()->cast<Node>().setName(mixerOAReliefNodeName.get()); | |
| 105 | } | ||
| 106 | |||
| 107 | ✗ | boost::optional<std::string> oaStreamInletNodeName; | |
| 108 | ✗ | boost::optional<std::string> oaStreamOutletNodeName; | |
| 109 | |||
| 110 | ✗ | oaStreamInletNodeName = _outdoorAirMixer->getString(OutdoorAir_MixerFields::OutdoorAirStreamNodeName); | |
| 111 | |||
| 112 | ✗ | while (oaStreamInletNodeName) { | |
| 113 | ✗ | boost::optional<ModelObject> oaComponentModelObject; | |
| 114 | ✗ | boost::optional<std::string> newOAStreamInletNodeName; | |
| 115 | |||
| 116 | ✗ | for (const auto& equipmentElem : equipmentVector) { | |
| 117 | ✗ | switch (equipmentElem.iddObject().type().value()) { | |
| 118 | ✗ | case openstudio::IddObjectType::EvaporativeCooler_Direct_ResearchSpecial: { | |
| 119 | ✗ | oaStreamOutletNodeName = equipmentElem.getString(EvaporativeCooler_Direct_ResearchSpecialFields::AirOutletNodeName); | |
| 120 | ✗ | if (oaStreamOutletNodeName) { | |
| 121 | ✗ | if (istringEqual(oaStreamOutletNodeName.get(), oaStreamInletNodeName.get())) { | |
| 122 | ✗ | newOAStreamInletNodeName = equipmentElem.getString(EvaporativeCooler_Direct_ResearchSpecialFields::AirInletNodeName); | |
| 123 | |||
| 124 | ✗ | oaComponentModelObject = translateAndMapWorkspaceObject(equipmentElem); | |
| 125 | } | ||
| 126 | } | ||
| 127 | ✗ | break; | |
| 128 | } | ||
| 129 | ✗ | default: { | |
| 130 | ✗ | break; | |
| 131 | } | ||
| 132 | } | ||
| 133 | ✗ | if (newOAStreamInletNodeName) { | |
| 134 | ✗ | break; | |
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | ✗ | oaStreamInletNodeName = newOAStreamInletNodeName; | |
| 139 | |||
| 140 | ✗ | if (oaComponentModelObject) { | |
| 141 | ✗ | bool success = false; | |
| 142 | |||
| 143 | ✗ | if (boost::optional<HVACComponent> hvacComponent = oaComponentModelObject->optionalCast<HVACComponent>()) { | |
| 144 | ✗ | success = hvacComponent->addToNode(outboardOANode); | |
| 145 | |||
| 146 | ✗ | if (success) { | |
| 147 | ✗ | if (boost::optional<StraightComponent> straightComponent = hvacComponent->optionalCast<StraightComponent>()) { | |
| 148 | ✗ | if (oaStreamInletNodeName) { | |
| 149 | ✗ | straightComponent->inletModelObject()->cast<Node>().setName(oaStreamInletNodeName.get()); | |
| 150 | } | ||
| 151 | ✗ | if (oaStreamOutletNodeName) { | |
| 152 | ✗ | straightComponent->outletModelObject()->cast<Node>().setName(oaStreamOutletNodeName.get()); | |
| 153 | } | ||
| 154 | ✗ | } | |
| 155 | } | ||
| 156 | ✗ | } | |
| 157 | |||
| 158 | ✗ | if (!success) { | |
| 159 | ✗ | oaComponentModelObject->remove(); | |
| 160 | } | ||
| 161 | } | ||
| 162 | ✗ | } | |
| 163 | ✗ | } | |
| 164 | } | ||
| 165 | |||
| 166 | ✗ | return mo; | |
| 167 | ✗ | } else { | |
| 168 | ✗ | return boost::none; | |
| 169 | } | ||
| 170 | ✗ | } | |
| 171 | |||
| 172 | } // namespace energyplus | ||
| 173 | |||
| 174 | } // namespace openstudio | ||
| 175 |