From d8c85eaf168e067bfb49ab13c0f2dfb5c0080f9f Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Fri, 15 May 2020 15:49:17 +0200 Subject: [PATCH] Fix #3926 - handle multiple AirLoopHVACs and assign the DSOA to all ControllerMechanicalVentilation objects --- .../ForwardTranslateSizingZone.cpp | 91 +++++++------------ 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/src/energyplus/ForwardTranslator/ForwardTranslateSizingZone.cpp b/src/energyplus/ForwardTranslator/ForwardTranslateSizingZone.cpp index ecda47d9c1a..74a9b595e07 100644 --- a/src/energyplus/ForwardTranslator/ForwardTranslateSizingZone.cpp +++ b/src/energyplus/ForwardTranslator/ForwardTranslateSizingZone.cpp @@ -64,26 +64,20 @@ boost::optional ForwardTranslator::translateSizingZone( SizingZone & boost::optional s; boost::optional value; - IdfObject idfObject(IddObjectType::Sizing_Zone); - - m_idfObjects.push_back(idfObject); - // ZoneorZoneListName - model::ThermalZone thermalZone = modelObject.thermalZone(); - boost::optional _thermalZone = translateAndMapModelObject(thermalZone); - - boost::optional name; - - if( _thermalZone ) - { - name = _thermalZone->name(); + if (!_thermalZone) { + // This shouldn't even happen, but in any case, there's no point translating a Sizing:Zone for no Zone... + return boost::none; } - if( name ) + IdfObject idfObject(IddObjectType::Sizing_Zone); + m_idfObjects.push_back(idfObject); + + std::string name = _thermalZone->nameString(); { - idfObject.setString(Sizing_ZoneFields::ZoneorZoneListName,name.get()); + idfObject.setString(Sizing_ZoneFields::ZoneorZoneListName, name); } // ZoneCoolingDesignSupplyAirTemperatureInputMethod @@ -261,11 +255,8 @@ boost::optional ForwardTranslator::translateSizingZone( SizingZone & { IdfObject dSZAD(IddObjectType::DesignSpecification_ZoneAirDistribution); - if( name ) - { - dSZADName = name.get() + " Design Spec Zone Air Dist"; - dSZAD.setName(dSZADName); - } + dSZADName = name + " Design Spec Zone Air Dist"; + dSZAD.setName(dSZADName); // register the DSZAD m_idfObjects.push_back(dSZAD); @@ -298,50 +289,34 @@ boost::optional ForwardTranslator::translateSizingZone( SizingZone & // Add ThermalZone and associated design objects to ControllerMechanicalVentilation. // This would be done in forwardTranslateControllerMechanicalVentilation except doing it here maintains proper order of the idf file. - boost::optional controllerMechanicalVentilation; - boost::optional _controllerMechanicalVentilation; - - if( boost::optional airLoopHVAC = thermalZone.airLoopHVAC() ) - { - if( boost::optional oaSystem = airLoopHVAC->airLoopHVACOutdoorAirSystem() ) - { + // Now that Multiple AirLoopHVACs serving the same zone are possible, need to loop on all + for (const auto& airLoopHVAC : thermalZone.airLoopHVACs()) { + if (boost::optional oaSystem = airLoopHVAC.airLoopHVACOutdoorAirSystem()) { model::ControllerOutdoorAir controllerOutdoorAir = oaSystem->getControllerOutdoorAir(); + model::ControllerMechanicalVentilation controllerMechanicalVentilation = controllerOutdoorAir.controllerMechanicalVentilation(); + if (boost::optional _controllerMechanicalVentilation = translateAndMapModelObject(controllerMechanicalVentilation)) { + IdfExtensibleGroup eg = _controllerMechanicalVentilation->pushExtensibleGroup(); + + // Thermal Zone Name + eg.setString(Controller_MechanicalVentilationExtensibleFields::ZoneorZoneListName, name); + + // DesignSpecificationOutdoorAir + std::vector spaces = thermalZone.spaces(); + + if (spaces.size() > 0) { + if (boost::optional designOASpec = spaces.front().designSpecificationOutdoorAir()) { + if (boost::optional _designOASpec = translateAndMapModelObject(designOASpec.get()) ) { + eg.setString(Controller_MechanicalVentilationExtensibleFields::DesignSpecificationOutdoorAirObjectName,_designOASpec->name().get()); + } + } + } - controllerMechanicalVentilation = controllerOutdoorAir.controllerMechanicalVentilation(); - } - } - - if( controllerMechanicalVentilation ) - { - _controllerMechanicalVentilation = translateAndMapModelObject(controllerMechanicalVentilation.get()); - } - - if( _controllerMechanicalVentilation && _thermalZone ) - { - IdfExtensibleGroup eg = _controllerMechanicalVentilation->pushExtensibleGroup(); - - // Thermal Zone Name - eg.setString(Controller_MechanicalVentilationExtensibleFields::ZoneorZoneListName,_thermalZone->name().get()); - - // DesignSpecificationOutdoorAir - std::vector spaces = thermalZone.spaces(); - - if( spaces.size() > 0 ) - { - if( boost::optional designOASpec = spaces.front().designSpecificationOutdoorAir() ) - { - if( boost::optional _designOASpec = translateAndMapModelObject(designOASpec.get()) ) - { - eg.setString(Controller_MechanicalVentilationExtensibleFields::DesignSpecificationOutdoorAirObjectName,_designOASpec->name().get()); + // DesignSpecificationZoneAirDistributionObjectName + if (isDSZADTranslated) { + eg.setString(Controller_MechanicalVentilationExtensibleFields::DesignSpecificationZoneAirDistributionObjectName, dSZADName); } } } - - // DesignSpecificationZoneAirDistributionObjectName - if( _thermalZone && isDSZADTranslated ) - { - eg.setString(Controller_MechanicalVentilationExtensibleFields::DesignSpecificationZoneAirDistributionObjectName, dSZADName); - } } if( modelObject.accountforDedicatedOutdoorAirSystem() ) {