From 45d2bd16eacd2a2d7c0f4dc0f02f176069048c5d Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Fri, 15 May 2020 16:23:37 +0200 Subject: [PATCH 1/2] Add test for #2797 --- src/energyplus/CMakeLists.txt | 1 + .../ZoneHVACLowTempRadiantConstFlow_GTest.cpp | 124 ++++++++++++++++++ .../ZoneHVACLowTempRadiantElectric_GTest.cpp | 45 ++++++- .../ZoneHVACLowTempRadiantVarFlow_GTest.cpp | 8 ++ 4 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 src/energyplus/Test/ZoneHVACLowTempRadiantConstFlow_GTest.cpp diff --git a/src/energyplus/CMakeLists.txt b/src/energyplus/CMakeLists.txt index 78632d86d62..34e78ec95a8 100644 --- a/src/energyplus/CMakeLists.txt +++ b/src/energyplus/CMakeLists.txt @@ -640,6 +640,7 @@ set(${target_name}_test_src Test/ThermostatSetpointDualSetpoint_GTest.cpp Test/WindowPropertyFrameAndDivider_GTest.cpp Test/ZoneHVACLowTemperatureRadiantConstFlow_GTest.cpp + Test/ZoneHVACLowTempRadiantConstFlow_GTest.cpp Test/ZoneHVACLowTempRadiantElectric_GTest.cpp Test/ZoneHVACLowTempRadiantVarFlow_GTest.cpp Test/ZoneHVACTerminalUnitVariableRefrigerantFlow_GTest.cpp diff --git a/src/energyplus/Test/ZoneHVACLowTempRadiantConstFlow_GTest.cpp b/src/energyplus/Test/ZoneHVACLowTempRadiantConstFlow_GTest.cpp new file mode 100644 index 00000000000..5c436966f21 --- /dev/null +++ b/src/energyplus/Test/ZoneHVACLowTempRadiantConstFlow_GTest.cpp @@ -0,0 +1,124 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include +#include "EnergyPlusFixture.hpp" + +#include "../ForwardTranslator.hpp" +#include "../ReverseTranslator.hpp" + +#include "../../model/ZoneHVACLowTempRadiantConstFlow.hpp" +#include "../../model/ZoneHVACLowTempRadiantConstFlow_Impl.hpp" +#include "../../model/CoilCoolingLowTempRadiantConstFlow.hpp" +#include "../../model/CoilCoolingLowTempRadiantConstFlow_Impl.hpp" +#include "../../model/CoilHeatingLowTempRadiantConstFlow.hpp" +#include "../../model/CoilHeatingLowTempRadiantConstFlow_Impl.hpp" +#include "../../model/ConstructionWithInternalSource.hpp" +#include "../../model/ScheduleConstant.hpp" +#include "../../model/ThermalZone.hpp" +#include "../../model/Space.hpp" + +#include +#include + +#include "../../utilities/idf/IdfExtensibleGroup.hpp" + +#include + +#include + +using namespace openstudio::energyplus; +using namespace openstudio::model; +using namespace openstudio; + +TEST_F(EnergyPlusFixture, ZoneHVACLowTempRadiantConstFlow_Crash_no_constructions) { + + ForwardTranslator ft; + + Model m; + + // make a space with some surfaces + Point3dVector points; + points.push_back(Point3d(0, 0, 0)); + points.push_back(Point3d(0, 1, 0)); + points.push_back(Point3d(1, 1, 0)); + points.push_back(Point3d(1, 0, 0)); + + boost::optional _space1 = Space::fromFloorPrint(points, 3, m); + ASSERT_TRUE(_space1); + + // make a zone, add the space + ThermalZone z(m); + _space1->setThermalZone(z); + + // make some plant loops + PlantLoop clg_loop(m); + PlantLoop htg_loop(m); + + ASSERT_NO_THROW(ft.translateModel(m)); + + // Make a radiant low temperature system + Schedule alwaysOn = m.alwaysOnDiscreteSchedule(); + + + + ScheduleConstant availabilitySched(m); + ScheduleConstant coolingHighWaterTempSched(m); + ScheduleConstant coolingLowWaterTempSched(m); + ScheduleConstant coolingHighControlTempSched(m); + ScheduleConstant coolingLowControlTempSched(m); + ScheduleConstant heatingHighWaterTempSched(m); + ScheduleConstant heatingLowWaterTempSched(m); + ScheduleConstant heatingHighControlTempSched(m); + ScheduleConstant heatingLowControlTempSched(m); + + availabilitySched.setValue(1.0); + coolingHighWaterTempSched.setValue(15.0); + coolingLowWaterTempSched.setValue(10.0); + coolingHighControlTempSched.setValue(26.0); + coolingLowControlTempSched.setValue(22.0); + heatingHighWaterTempSched.setValue(50.0); + heatingLowWaterTempSched.setValue(30.0); + heatingHighControlTempSched.setValue(21.0); + heatingLowControlTempSched.setValue(15.0); + + CoilCoolingLowTempRadiantConstFlow clg_coil(m,coolingHighWaterTempSched,coolingLowWaterTempSched,coolingHighControlTempSched,coolingLowControlTempSched); + CoilHeatingLowTempRadiantConstFlow htg_coil(m,heatingHighWaterTempSched,heatingLowWaterTempSched,heatingHighControlTempSched,heatingLowControlTempSched); + + ZoneHVACLowTempRadiantConstFlow testRad(m, alwaysOn, htg_coil, clg_coil); + EXPECT_TRUE(testRad.addToThermalZone(z)); + + ASSERT_NO_THROW(ft.translateModel(m)); + + // Test for #2797 - When no surfaces, it shouldn't even be translated or E+ will crash + EXPECT_TRUE(testRad.surfaces().empty()); + Workspace w = ft.translateModel(m); + WorkspaceObjectVector idf_rads(w.getObjectsByType(IddObjectType::ZoneHVAC_LowTemperatureRadiant_ConstantFlow)); + EXPECT_EQ(0u, idf_rads.size()); +} diff --git a/src/energyplus/Test/ZoneHVACLowTempRadiantElectric_GTest.cpp b/src/energyplus/Test/ZoneHVACLowTempRadiantElectric_GTest.cpp index 7eb3a07d22c..3a4b7ac2afe 100644 --- a/src/energyplus/Test/ZoneHVACLowTempRadiantElectric_GTest.cpp +++ b/src/energyplus/Test/ZoneHVACLowTempRadiantElectric_GTest.cpp @@ -52,6 +52,8 @@ #include "../../model/StandardOpaqueMaterial_Impl.hpp" #include "../../model/ThermalZone.hpp" #include "../../model/ThermalZone_Impl.hpp" +#include "../../model/Space.hpp" +#include #include #include "../../utilities/idf/IdfExtensibleGroup.hpp" @@ -122,7 +124,48 @@ TEST_F(EnergyPlusFixture,ZoneHVACLowTempRadiantElectric_Set_Flow_Fractions) } } } - } +TEST_F(EnergyPlusFixture, ZoneHVACLowTempRadiantElectric_Crash_no_constructions) { + + ForwardTranslator ft; + + Model m; + + // make a space with some surfaces + Point3dVector points; + points.push_back(Point3d(0, 0, 0)); + points.push_back(Point3d(0, 1, 0)); + points.push_back(Point3d(1, 1, 0)); + points.push_back(Point3d(1, 0, 0)); + + boost::optional _space1 = Space::fromFloorPrint(points, 3, m); + ASSERT_TRUE(_space1); + + // make a zone, add the space + ThermalZone z(m); + _space1->setThermalZone(z); + + // make some plant loops + PlantLoop clg_loop(m); + PlantLoop htg_loop(m); + ASSERT_NO_THROW(ft.translateModel(m)); + + // Make a radiant low temperature system + Schedule alwaysOn = m.alwaysOnDiscreteSchedule(); + + ScheduleConstant heatingControlTemperatureSchedule(m); + heatingControlTemperatureSchedule.setValue(10.0); + + ZoneHVACLowTemperatureRadiantElectric testRad(m,alwaysOn,heatingControlTemperatureSchedule); + EXPECT_TRUE(testRad.addToThermalZone(z)); + + ASSERT_NO_THROW(ft.translateModel(m)); + + // Test for #2797 - When no surfaces, it shouldn't even be translated or E+ will crash + EXPECT_TRUE(testRad.surfaces().empty()); + Workspace w = ft.translateModel(m); + WorkspaceObjectVector idf_rads(w.getObjectsByType(IddObjectType::ZoneHVAC_LowTemperatureRadiant_Electric)); + EXPECT_EQ(0u, idf_rads.size()); +} diff --git a/src/energyplus/Test/ZoneHVACLowTempRadiantVarFlow_GTest.cpp b/src/energyplus/Test/ZoneHVACLowTempRadiantVarFlow_GTest.cpp index 0e4e9b1c590..0c9d4d34cac 100644 --- a/src/energyplus/Test/ZoneHVACLowTempRadiantVarFlow_GTest.cpp +++ b/src/energyplus/Test/ZoneHVACLowTempRadiantVarFlow_GTest.cpp @@ -59,6 +59,8 @@ #include "../../model/Space.hpp" #include +#include + #include "../../utilities/idf/IdfExtensibleGroup.hpp" #include @@ -184,4 +186,10 @@ TEST_F(EnergyPlusFixture, ZoneHVACLowTempRadiantVarFlow_Crash_no_constructions) EXPECT_TRUE(testRad.addToThermalZone(z)); ASSERT_NO_THROW(ft.translateModel(m)); + + // Test for #2797 - When no surfaces, it shouldn't even be translated or E+ will crash + EXPECT_TRUE(testRad.surfaces().empty()); + Workspace w = ft.translateModel(m); + WorkspaceObjectVector idf_rads(w.getObjectsByType(IddObjectType::ZoneHVAC_LowTemperatureRadiant_VariableFlow)); + EXPECT_EQ(0u, idf_rads.size()); } From 16156e9569fbad72f08338642b38eaf0bc3f2dcb Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Fri, 15 May 2020 16:24:35 +0200 Subject: [PATCH 2/2] Fix #2797 - Do not translate a ZoneHVACLowTempRadiant object if it doesn't have any surfaces with Internal Source --- .../ForwardTranslateZoneHVACLowTempRadiantConstFlow.cpp | 6 ++++++ .../ForwardTranslateZoneHVACLowTempRadiantVarFlow.cpp | 6 ++++++ ...orwardTranslateZoneHVACLowTemperatureRadiantElectric.cpp | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantConstFlow.cpp b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantConstFlow.cpp index d2564c2626b..39682760a5e 100644 --- a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantConstFlow.cpp +++ b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantConstFlow.cpp @@ -78,6 +78,12 @@ boost::optional ForwardTranslator::translateZoneHVACLowTempRadiantCon boost::optional value; boost::optional temp; + // If it doesn't have any surfaces, then don't bother translating it, E+ will crash + if (modelObject.surfaces().empty()) { + LOG(Info, modelObject.briefDescription() << " does not have any target surfaces with ConstructionWithInternalSource, it will not be translated"); + return boost::none; + } + IdfObject idfObject(IddObjectType::ZoneHVAC_LowTemperatureRadiant_ConstantFlow); m_idfObjects.push_back(idfObject); diff --git a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantVarFlow.cpp b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantVarFlow.cpp index 3adcb5178a4..1a4ff76b484 100644 --- a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantVarFlow.cpp +++ b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTempRadiantVarFlow.cpp @@ -79,6 +79,12 @@ boost::optional ForwardTranslator::translateZoneHVACLowTempRadiantVar boost::optional value; boost::optional temp; + // If it doesn't have any surfaces, then don't bother translating it, E+ will crash + if (modelObject.surfaces().empty()) { + LOG(Info, modelObject.briefDescription() << " does not have any target surfaces with ConstructionWithInternalSource, it will not be translated"); + return boost::none; + } + IdfObject idfObject(IddObjectType::ZoneHVAC_LowTemperatureRadiant_VariableFlow); m_idfObjects.push_back(idfObject); diff --git a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTemperatureRadiantElectric.cpp b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTemperatureRadiantElectric.cpp index eed878d46b5..652d9b6a846 100644 --- a/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTemperatureRadiantElectric.cpp +++ b/src/energyplus/ForwardTranslator/ForwardTranslateZoneHVACLowTemperatureRadiantElectric.cpp @@ -79,6 +79,12 @@ boost::optional ForwardTranslator::translateZoneHVACLowTemperatureRad boost::optional value; boost::optional temp; + // If it doesn't have any surfaces, then don't bother translating it, E+ will crash + if (modelObject.surfaces().empty()) { + LOG(Info, modelObject.briefDescription() << " does not have any target surfaces with ConstructionWithInternalSource, it will not be translated"); + return boost::none; + } + IdfObject idfObject(IddObjectType::ZoneHVAC_LowTemperatureRadiant_Electric); m_idfObjects.push_back(idfObject);