src/energyplus/ReverseTranslator/ReverseTranslateZone.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/ThermalZone.hpp" | ||
| 8 | #include "../../model/ThermalZone_Impl.hpp" | ||
| 9 | #include "../../model/Space.hpp" | ||
| 10 | #include "../../model/Space_Impl.hpp" | ||
| 11 | #include "../../model/ThermostatSetpointDualSetpoint.hpp" | ||
| 12 | #include "../../model/ThermostatSetpointDualSetpoint_Impl.hpp" | ||
| 13 | #include <utilities/idd/Zone_FieldEnums.hxx> | ||
| 14 | #include <utilities/idd/ZoneControl_Thermostat_FieldEnums.hxx> | ||
| 15 | #include <utilities/idd/ZoneList_FieldEnums.hxx> | ||
| 16 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 17 | #include <utilities/idd/ZoneHVAC_EquipmentConnections_FieldEnums.hxx> | ||
| 18 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 19 | #include <utilities/idd/IddEnums.hxx> | ||
| 20 | |||
| 21 | using namespace openstudio::model; | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | |||
| 25 | namespace energyplus { | ||
| 26 | |||
| 27 | 100 | OptionalModelObject ReverseTranslator::translateZone(const WorkspaceObject& workspaceObject) { | |
| 28 |
4/5✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✓ Branch 7 taken 100 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 100 times.
|
100 | if (workspaceObject.iddObject().type() != IddObjectType::Zone) { |
| 29 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: Zone"); | |
| 30 | ✗ | return boost::none; | |
| 31 | } | ||
| 32 | |||
| 33 | // this function creates a space and a thermal zone, it returns the space. If you want the | ||
| 34 | // thermal zone you can reliably dereference the result of space.thermalZone(). | ||
| 35 | |||
| 36 |
1/1✓ Branch 1 taken 100 times.
|
100 | openstudio::model::ThermalZone thermalZone(m_model); |
| 37 | |||
| 38 |
1/1✓ Branch 1 taken 100 times.
|
100 | openstudio::model::Space space(m_model); |
| 39 |
1/1✓ Branch 1 taken 100 times.
|
100 | space.setThermalZone(thermalZone); |
| 40 | |||
| 41 | 100 | boost::optional<std::string> _idfZoneName; | |
| 42 | |||
| 43 |
1/1✓ Branch 1 taken 100 times.
|
100 | OptionalString s = workspaceObject.name(); |
| 44 |
1/2✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
|
100 | if (s) { |
| 45 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
|
100 | thermalZone.setName(*s); |
| 46 |
3/3✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✓ Branch 7 taken 100 times.
|
100 | space.setName(*s + " Space"); |
| 47 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
|
100 | _idfZoneName = *s; |
| 48 | } | ||
| 49 | |||
| 50 |
1/1✓ Branch 1 taken 100 times.
|
100 | OptionalDouble d = workspaceObject.getDouble(ZoneFields::DirectionofRelativeNorth); |
| 51 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 41 times.
|
100 | if (d) { |
| 52 |
2/2✓ Branch 1 taken 59 times.
✓ Branch 4 taken 59 times.
|
59 | space.setDirectionofRelativeNorth(*d); |
| 53 | } | ||
| 54 | |||
| 55 |
1/1✓ Branch 1 taken 100 times.
|
100 | d = workspaceObject.getDouble(ZoneFields::XOrigin); |
| 56 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 40 times.
|
100 | if (d) { |
| 57 |
2/2✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
|
60 | space.setXOrigin(*d); |
| 58 | } | ||
| 59 | |||
| 60 |
1/1✓ Branch 1 taken 100 times.
|
100 | d = workspaceObject.getDouble(ZoneFields::YOrigin); |
| 61 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 40 times.
|
100 | if (d) { |
| 62 |
2/2✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
|
60 | space.setYOrigin(*d); |
| 63 | } | ||
| 64 | |||
| 65 |
1/1✓ Branch 1 taken 100 times.
|
100 | d = workspaceObject.getDouble(ZoneFields::ZOrigin); |
| 66 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 40 times.
|
100 | if (d) { |
| 67 |
2/2✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
|
60 | space.setZOrigin(*d); |
| 68 | } | ||
| 69 | |||
| 70 |
1/1✓ Branch 1 taken 100 times.
|
100 | OptionalInt i = workspaceObject.getInt(ZoneFields::Type); |
| 71 | 100 | if (i) { | |
| 72 | // no-op | ||
| 73 | } | ||
| 74 | |||
| 75 |
1/1✓ Branch 1 taken 100 times.
|
100 | i = workspaceObject.getInt(ZoneFields::Multiplier); |
| 76 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 52 times.
|
100 | if (i) { |
| 77 |
2/2✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
|
48 | thermalZone.setMultiplier(*i); |
| 78 | } | ||
| 79 | |||
| 80 |
1/1✓ Branch 1 taken 100 times.
|
100 | d = workspaceObject.getDouble(ZoneFields::CeilingHeight); |
| 81 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 88 times.
|
100 | if (d) { |
| 82 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | thermalZone.setCeilingHeight(*d); |
| 83 | } | ||
| 84 | |||
| 85 |
1/1✓ Branch 1 taken 100 times.
|
100 | d = workspaceObject.getDouble(ZoneFields::Volume); |
| 86 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 88 times.
|
100 | if (d) { |
| 87 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | thermalZone.setVolume(*d); |
| 88 | } | ||
| 89 | |||
| 90 |
1/1✓ Branch 1 taken 100 times.
|
100 | s = workspaceObject.getString(ZoneFields::ZoneInsideConvectionAlgorithm); |
| 91 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 50 times.
|
100 | if (s) { |
| 92 |
2/2✓ Branch 1 taken 50 times.
✓ Branch 4 taken 50 times.
|
50 | thermalZone.setZoneInsideConvectionAlgorithm(*s); |
| 93 | } | ||
| 94 | |||
| 95 |
1/1✓ Branch 1 taken 100 times.
|
100 | s = workspaceObject.getString(ZoneFields::ZoneOutsideConvectionAlgorithm); |
| 96 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 50 times.
|
100 | if (s) { |
| 97 |
2/2✓ Branch 1 taken 50 times.
✓ Branch 4 taken 50 times.
|
50 | thermalZone.setZoneOutsideConvectionAlgorithm(*s); |
| 98 | } | ||
| 99 | |||
| 100 |
1/1✓ Branch 1 taken 100 times.
|
100 | s = workspaceObject.getString(ZoneFields::PartofTotalFloorArea); |
| 101 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 60 times.
|
100 | if (s) { |
| 102 |
5/5✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 40 times.
✓ Branch 10 taken 34 times.
✓ Branch 11 taken 6 times.
|
120 | if (istringEqual("Yes", *s)) { |
| 103 |
1/1✓ Branch 1 taken 34 times.
|
34 | space.setPartofTotalFloorArea(true); |
| 104 | } else { | ||
| 105 |
1/1✓ Branch 1 taken 6 times.
|
6 | space.setPartofTotalFloorArea(false); |
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | // Thermostat | ||
| 110 | |||
| 111 | // If the zone in the idf file does not have a name, there is no use in even trying to find a thermostat | ||
| 112 |
1/2✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
|
100 | if (_idfZoneName) { |
| 113 |
1/1✓ Branch 1 taken 100 times.
|
100 | Workspace workspace = workspaceObject.workspace(); |
| 114 | |||
| 115 | // Loop on all ZoneControl:Thermostat objects, trying to find the one | ||
| 116 | 100 | std::vector<WorkspaceObject> _zoneControlThermostats; | |
| 117 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
|
100 | _zoneControlThermostats = workspace.getObjectsByType(IddObjectType::ZoneControl_Thermostat); |
| 118 |
2/2✓ Branch 5 taken 299 times.
✓ Branch 6 taken 51 times.
|
350 | for (const auto& _zoneControlThermostat : _zoneControlThermostats) { |
| 119 |
2/3✓ Branch 1 taken 299 times.
✓ Branch 3 taken 299 times.
✗ Branch 4 not taken.
|
598 | if (boost::optional<std::string> zoneName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::ZoneorZoneListName)) { |
| 120 | 299 | bool zoneControlThermostatfound = false; | |
| 121 | |||
| 122 | // If it references our zone, then good to go! | ||
| 123 |
5/5✓ Branch 1 taken 299 times.
✓ Branch 4 taken 299 times.
✓ Branch 7 taken 299 times.
✓ Branch 9 taken 49 times.
✓ Branch 10 taken 250 times.
|
299 | if (openstudio::istringEqual(zoneName.get(), _idfZoneName.get())) { |
| 124 | 49 | zoneControlThermostatfound = true; | |
| 125 | } | ||
| 126 | // Otherwise, it might be in a ZoneList | ||
| 127 |
4/5✓ Branch 1 taken 250 times.
✓ Branch 4 taken 250 times.
✓ Branch 7 taken 250 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 250 times.
|
500 | else if (boost::optional<WorkspaceObject> _zoneList = workspace.getObjectByTypeAndName(IddObjectType::ZoneList, zoneName.get())) { |
| 128 | // Loop on all entries (=Zone Names) in that ZoneList | ||
| 129 | ✗ | std::vector<IdfExtensibleGroup> zoneListGroup = _zoneList->extensibleGroups(); | |
| 130 | ✗ | for (const auto& zoneListElem : zoneListGroup) { | |
| 131 | ✗ | boost::optional<std::string> zoneListZoneName = zoneListElem.getString(ZoneListExtensibleFields::ZoneName); | |
| 132 | ✗ | if (zoneListZoneName) { | |
| 133 | ✗ | if (openstudio::istringEqual(zoneListZoneName.get(), _idfZoneName.get())) { | |
| 134 | // If that's the one, no need to keep processing other Zone Names | ||
| 135 | ✗ | zoneControlThermostatfound = true; | |
| 136 | ✗ | break; | |
| 137 | } | ||
| 138 | } | ||
| 139 | ✗ | } | |
| 140 | 250 | } | |
| 141 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 250 times.
|
299 | if (zoneControlThermostatfound) { |
| 142 | |||
| 143 | // We only support ThermostatSetpoint:DualSetpoint | ||
| 144 | |||
| 145 | // TODO: JM 2019-09-04 switch back to an extensible object once/if https://github.com/NREL/EnergyPlus/issues/7484 is addressed and the | ||
| 146 | // 'Temperature Difference Between Cutout And Setpoint' field is moved before the extensible fields | ||
| 147 | // For now, we revert to a non extensible object, so we can still write that field | ||
| 148 | |||
| 149 | /* | ||
| 150 | * std::vector<IdfExtensibleGroup> extensibleGroups = _zoneControlThermostat.extensibleGroups(); | ||
| 151 | * for( const auto & extensibleGroup : extensibleGroups ) | ||
| 152 | * { | ||
| 153 | * boost::optional<std::string> thermostatType = extensibleGroup.getString(ZoneControl_ThermostatExtensibleFields::ControlObjectType); | ||
| 154 | * boost::optional<std::string> thermostatName = extensibleGroup.getString(ZoneControl_ThermostatExtensibleFields::ControlName); | ||
| 155 | * | ||
| 156 | * if( thermostatName && thermostatType ) | ||
| 157 | * { | ||
| 158 | * boost::optional<WorkspaceObject> _thermostat | ||
| 159 | * = workspace.getObjectByTypeAndName(IddObjectType(thermostatType.get()),thermostatName.get()); | ||
| 160 | * | ||
| 161 | * if( _thermostat ) | ||
| 162 | * { | ||
| 163 | * boost::optional<ModelObject> thermostat = translateAndMapWorkspaceObject(_thermostat.get()); | ||
| 164 | * if( thermostat ) | ||
| 165 | * { | ||
| 166 | * if( boost::optional<ThermostatSetpointDualSetpoint> thermostatSetpointDualSetpoint | ||
| 167 | * = thermostat->optionalCast<ThermostatSetpointDualSetpoint>() ) | ||
| 168 | * { | ||
| 169 | * thermalZone.setThermostatSetpointDualSetpoint(thermostatSetpointDualSetpoint.get()); | ||
| 170 | * } | ||
| 171 | * } | ||
| 172 | * } | ||
| 173 | * } | ||
| 174 | * } | ||
| 175 | */ | ||
| 176 | |||
| 177 | 196 | auto checkIfDualSetpointAndTranslate = [&](boost::optional<std::string>& _thermostatType, boost::optional<std::string>& _thermostatName) { | |
| 178 |
5/6✓ Branch 0 taken 49 times.
✓ Branch 1 taken 147 times.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49 times.
✓ Branch 5 taken 147 times.
|
245 | if (_thermostatName && _thermostatType) { |
| 179 | boost::optional<WorkspaceObject> _i_thermostat = | ||
| 180 |
4/4✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
✓ Branch 7 taken 49 times.
✓ Branch 10 taken 49 times.
|
49 | workspace.getObjectByTypeAndName(IddObjectType(_thermostatType.get()), _thermostatName.get()); |
| 181 |
1/2✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
|
49 | if (_i_thermostat) { |
| 182 |
2/2✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
|
49 | boost::optional<ModelObject> _m_thermostat = translateAndMapWorkspaceObject(_i_thermostat.get()); |
| 183 |
1/2✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
|
49 | if (_m_thermostat) { |
| 184 | 49 | if (boost::optional<ThermostatSetpointDualSetpoint> _thermostatSetpointDualSetpoint = | |
| 185 |
3/4✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
✓ Branch 6 taken 49 times.
✗ Branch 7 not taken.
|
98 | _m_thermostat->optionalCast<ThermostatSetpointDualSetpoint>()) { |
| 186 |
2/2✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
|
49 | thermalZone.setThermostatSetpointDualSetpoint(_thermostatSetpointDualSetpoint.get()); |
| 187 | |||
| 188 | // Reverse Translate 'Temperature Difference Between Cutout And Setpoint' from ZoneControl:Thermostat | ||
| 189 | // by placing it on the ThermostatSetpoint:DualSetpoint object | ||
| 190 | 49 | if (boost::optional<double> _cutOutTemp = | |
| 191 |
3/3✓ Branch 1 taken 49 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 41 times.
|
98 | _zoneControlThermostat.getDouble(ZoneControl_ThermostatFields::TemperatureDifferenceBetweenCutoutAndSetpoint)) { |
| 192 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
8 | _thermostatSetpointDualSetpoint->setTemperatureDifferenceBetweenCutoutAndSetpoint(_cutOutTemp.get()); |
| 193 | } | ||
| 194 | 49 | } | |
| 195 | } | ||
| 196 | 49 | } | |
| 197 | 49 | } | |
| 198 | 196 | }; | |
| 199 | // Group 1 | ||
| 200 | { | ||
| 201 | boost::optional<std::string> thermostatType = | ||
| 202 |
1/1✓ Branch 1 taken 49 times.
|
49 | _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1ObjectType, false, true); |
| 203 |
1/1✓ Branch 1 taken 49 times.
|
49 | boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1Name, false, true); |
| 204 |
1/1✓ Branch 1 taken 49 times.
|
49 | checkIfDualSetpointAndTranslate(thermostatType, thermostatName); |
| 205 | 49 | } | |
| 206 | |||
| 207 | // Group 2 | ||
| 208 | { | ||
| 209 | boost::optional<std::string> thermostatType = | ||
| 210 |
1/1✓ Branch 1 taken 49 times.
|
49 | _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2ObjectType, false, true); |
| 211 |
1/1✓ Branch 1 taken 49 times.
|
49 | boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2Name, false, true); |
| 212 |
1/1✓ Branch 1 taken 49 times.
|
49 | checkIfDualSetpointAndTranslate(thermostatType, thermostatName); |
| 213 | 49 | } | |
| 214 | |||
| 215 | // Group 3 | ||
| 216 | { | ||
| 217 | boost::optional<std::string> thermostatType = | ||
| 218 |
1/1✓ Branch 1 taken 49 times.
|
49 | _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3ObjectType, false, true); |
| 219 |
1/1✓ Branch 1 taken 49 times.
|
49 | boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3Name, false, true); |
| 220 |
1/1✓ Branch 1 taken 49 times.
|
49 | checkIfDualSetpointAndTranslate(thermostatType, thermostatName); |
| 221 | 49 | } | |
| 222 | |||
| 223 | // Group 4 | ||
| 224 | { | ||
| 225 | boost::optional<std::string> thermostatType = | ||
| 226 |
1/1✓ Branch 1 taken 49 times.
|
49 | _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4ObjectType, false, true); |
| 227 |
1/1✓ Branch 1 taken 49 times.
|
49 | boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4Name, false, true); |
| 228 |
1/1✓ Branch 1 taken 49 times.
|
49 | checkIfDualSetpointAndTranslate(thermostatType, thermostatName); |
| 229 | 49 | } | |
| 230 | |||
| 231 | 49 | break; | |
| 232 | } // End if zoneControlThermostatFound | ||
| 233 | 299 | } // End if ZoneorZoneListName exists on ZoneControl:Thermostat object | |
| 234 | } // End Loop on each ZoneControlThermostats | ||
| 235 | 100 | } // End if _idfZoneName | |
| 236 | |||
| 237 | // Zone Equipment | ||
| 238 | /* | ||
| 239 | if( _idfZoneName ) | ||
| 240 | { | ||
| 241 | std::vector<WorkspaceObject> zoneHVACEquipmentConnections; | ||
| 242 | zoneHVACEquipmentConnections = workspaceObject.workspace().getObjectsByType(IddObjectType::ZoneHVAC_EquipmentConnections); | ||
| 243 | |||
| 244 | for( std::vector<WorkspaceObject>::iterator it = zoneHVACEquipmentConnections.begin(); | ||
| 245 | it != zoneHVACEquipmentConnections.end(); | ||
| 246 | it++ ) | ||
| 247 | { | ||
| 248 | s = it->getString(ZoneHVAC_EquipmentConnectionsFields::ZoneName); | ||
| 249 | |||
| 250 | if( s && istringEqual(s.get(),_idfZoneName.get()) ) | ||
| 251 | { | ||
| 252 | boost::optional<WorkspaceObject> _zoneEquipmentList = it->getTarget(ZoneHVAC_EquipmentConnectionsFields::ZoneConditioningEquipmentListName); | ||
| 253 | |||
| 254 | if( _zoneEquipmentList ) | ||
| 255 | { | ||
| 256 | translateAndMapWorkspaceObject(_zoneEquipmentList.get()); | ||
| 257 | } | ||
| 258 | |||
| 259 | break; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | } | ||
| 263 | */ | ||
| 264 | |||
| 265 |
1/1✓ Branch 1 taken 100 times.
|
100 | return space; |
| 266 | 100 | } | |
| 267 | |||
| 268 | } // namespace energyplus | ||
| 269 | |||
| 270 | } // namespace openstudio | ||
| 271 |