Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4096 - RT error for ZoneControlThermostat #4097

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/energyplus/ReverseTranslator/ReverseTranslateZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,29 +236,29 @@ OptionalModelObject ReverseTranslator::translateZone( const WorkspaceObject & wo
};
// Group 1
{
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1ObjectType);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1Name);
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1ObjectType, false, true);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control1Name, false, true);
checkIfDualSetpointAndTranslate(thermostatType, thermostatName);
}

// Group 2
{
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2ObjectType);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2Name);
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2ObjectType, false, true);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control2Name, false, true);
checkIfDualSetpointAndTranslate(thermostatType, thermostatName);
}

// Group 3
{
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3ObjectType);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3Name);
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3ObjectType, false, true);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control3Name, false, true);
checkIfDualSetpointAndTranslate(thermostatType, thermostatName);
}

// Group 4
{
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4ObjectType);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4Name);
boost::optional<std::string> thermostatType = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4ObjectType, false, true);
boost::optional<std::string> thermostatName = _zoneControlThermostat.getString(ZoneControl_ThermostatFields::Control4Name, false, true);
checkIfDualSetpointAndTranslate(thermostatType, thermostatName);
}

Expand Down
52 changes: 50 additions & 2 deletions src/energyplus/Test/ThermalZone_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
#include <utilities/idd/Daylighting_Controls_FieldEnums.hxx>
#include <utilities/idd/Zone_FieldEnums.hxx>
#include <utilities/idd/ZoneHVAC_EquipmentList_FieldEnums.hxx>
#include <utilities/idd/Schedule_Constant_FieldEnums.hxx>
#include <utilities/idd/ThermostatSetpoint_DualSetpoint_FieldEnums.hxx>
#include <utilities/idd/ZoneControl_Thermostat_FieldEnums.hxx>

#include <utilities/idd/IddEnums.hxx>

#include "../../utilities/idf/IdfExtensibleGroup.hpp"
Expand Down Expand Up @@ -811,6 +815,50 @@ TEST_F(EnergyPlusFixture,ForwardTranslator_LoadDistributionScheme)
WorkspaceObjectVector idfObjs = workspace.getObjectsByType(IddObjectType::ZoneHVAC_EquipmentList);
EXPECT_EQ(1u, idfObjs.size());
WorkspaceObject idf_eqlist(idfObjs[0]);

EXPECT_EQ("UniformLoad", idf_eqlist.getString(ZoneHVAC_EquipmentListFields::LoadDistributionScheme).get());
}
}

TEST_F(EnergyPlusFixture, ReverseTranslator_ZoneControlThermostat) {
ReverseTranslator rt;

Workspace w(StrictnessLevel::None, IddFileType::EnergyPlus);

OptionalWorkspaceObject _i_zone = w.addObject(IdfObject(IddObjectType::Zone));
ASSERT_TRUE(_i_zone);
EXPECT_TRUE(_i_zone->setName("Zone1"));

auto _i_tstat = w.addObject(IdfObject(IddObjectType::ThermostatSetpoint_DualSetpoint));
ASSERT_TRUE(_i_tstat);
EXPECT_TRUE(_i_tstat->setName("Thermostat Setpoint Dual Setpoint"));

auto _i_heating_sch = w.addObject(IdfObject(openstudio::IddObjectType::Schedule_Constant));
ASSERT_TRUE(_i_heating_sch);
EXPECT_TRUE(_i_heating_sch->setName("Heating Schedule"));
EXPECT_TRUE(_i_heating_sch->setDouble(Schedule_ConstantFields::HourlyValue, 19.0));
EXPECT_TRUE(_i_tstat->setPointer(ThermostatSetpoint_DualSetpointFields::HeatingSetpointTemperatureScheduleName, _i_heating_sch->handle()));

auto _i_cooling_sch = w.addObject(IdfObject(openstudio::IddObjectType::Schedule_Constant));
ASSERT_TRUE(_i_cooling_sch);
EXPECT_TRUE(_i_cooling_sch->setName("Cooling Schedule"));
EXPECT_TRUE(_i_cooling_sch->setDouble(Schedule_ConstantFields::HourlyValue, 26.0));
EXPECT_TRUE(_i_tstat->setPointer(ThermostatSetpoint_DualSetpointFields::CoolingSetpointTemperatureScheduleName, _i_cooling_sch->handle()));

auto _i_zc = w.addObject(IdfObject(IddObjectType::ZoneControl_Thermostat));
ASSERT_TRUE(_i_zc);
EXPECT_TRUE(_i_zc->setName("Zone Control Thermostat"));
EXPECT_TRUE(_i_zc->setPointer(ZoneControl_ThermostatFields::ZoneorZoneListName, _i_zone->handle()));

auto _i_control_sch = w.addObject(IdfObject(openstudio::IddObjectType::Schedule_Constant));
ASSERT_TRUE(_i_control_sch);
EXPECT_TRUE(_i_control_sch->setName("Control Type Schedule"));
EXPECT_TRUE(_i_control_sch->setDouble(Schedule_ConstantFields::HourlyValue, 4.0));

// Make sure like in #4096, we end up with blank "Control Object Type / Name" groups
EXPECT_TRUE(_i_zc->setString(ZoneControl_ThermostatFields::Control1ObjectType, _i_tstat->iddObject().name()));
EXPECT_TRUE(_i_zc->setString(ZoneControl_ThermostatFields::Control1Name, _i_tstat->name().get()));
EXPECT_TRUE(_i_zc->setDouble(ZoneControl_ThermostatFields::TemperatureDifferenceBetweenCutoutAndSetpoint, 0.0));

ASSERT_NO_THROW(rt.translateWorkspace(w));
Model m = rt.translateWorkspace(w);
}
6 changes: 3 additions & 3 deletions src/utilities/core/EnumBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ template<typename Enum>
auto itr = m.find(t_value);
if (itr == m.end())
{
throw std::runtime_error("Invalid domain for OpenStudio Enum");
throw std::runtime_error("Invalid domain for OpenStudio Enum " + Enum::enumName());
}
return itr->second;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ template<typename Enum>
{
return itr->second;
}
throw std::runtime_error("Unknown OpenStudio Enum Value '" + t_name + "'");
throw std::runtime_error("Unknown OpenStudio Enum Value '" + t_name + "' for Enum " + Enum::enumName());
}

/** Returns t_value if it is in the domain. Otherwise throws std::runtime_error. */
Expand All @@ -158,7 +158,7 @@ template<typename Enum>
{
return t_value;
} else {
throw std::runtime_error("Unknown OpenStudio Enum Value = " + std::to_string(t_value));
throw std::runtime_error("Unknown OpenStudio Enum Value = " + std::to_string(t_value) + "' for Enum " + Enum::enumName());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utilities/core/test/Enum_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(Enum, EnumThrows)
try {
openstudio::enums::TestEnum("forth");
} catch (std::runtime_error& e) {
std::string expectedErrorMessage("Unknown OpenStudio Enum Value 'FORTH'");
std::string expectedErrorMessage("Unknown OpenStudio Enum Value 'FORTH' for Enum TestEnum");
EXPECT_EQ(expectedErrorMessage, std::string(e.what()));
}

Expand All @@ -69,7 +69,7 @@ TEST(Enum, EnumThrows)
try {
openstudio::enums::TestEnum(3);
} catch (std::runtime_error& e) {
std::string expectedErrorMessage("Unknown OpenStudio Enum Value = 3");
std::string expectedErrorMessage("Unknown OpenStudio Enum Value = 3 for Enum TestEnum");
EXPECT_EQ(expectedErrorMessage, std::string(e.what()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/idf/Test/Workspace_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ TEST_F(IdfFixture, Workspace_getObjects_Type_StringOverload) {

// And check with a bad std::string, that it throws, and that we get an informative message (#1741)
ASSERT_THROW(workspace.getObjectsByType("BadEnum"), std::runtime_error);
std::string expectedErrorMessage("Unknown OpenStudio Enum Value 'BADENUM'");
std::string expectedErrorMessage("Unknown OpenStudio Enum Value 'BADENUM' for Enum IddObjectType");
try {
workspace.getObjectsByType("BadEnum");
} catch (std::runtime_error& e) {
Expand Down