Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/EMS_ZoneList_Fix' into 2…
Browse files Browse the repository at this point in the history
….4.0Release
  • Loading branch information
macumber committed Jan 3, 2018
2 parents 978a4d7 + fe936ca commit f58a3e1
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ if( BUILD_DVIEW )

ExternalProject_Add(DView
DEPENDS lk curl
GIT_REPOSITORY https://github.com/kbenne/wex.git
GIT_REPOSITORY https://github.com/NREL/wex.git
GIT_TAG develop
CMAKE_CACHE_ARGS
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "../../model/SpaceLoadInstance_Impl.hpp"
#include "../../model/Space.hpp"
#include "../../model/Space_Impl.hpp"
#include "../../model/SpaceType.hpp"
#include "../../model/SpaceType_Impl.hpp"
#include "../../model/ThermalZone.hpp"
#include "../../model/ThermalZone_Impl.hpp"

Expand Down Expand Up @@ -92,26 +94,56 @@ boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemAct

// check if actuatedComponent is a SpaceLoad
if (auto load = m.optionalCast<model::SpaceLoadInstance>()) {
// if SpaceLoad check if thermalzone names exist

// if SpaceLoad, check if thermalzone names exist
auto space = load->space();
if (space) {
auto tz = space->thermalZone();
if (tz) {
std::string tz_name = tz.get().nameString() + " " + m.nameString();
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, tz_name);
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, modelObject.actuatedComponentType());
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, modelObject.actuatedComponentControlType());
m_idfObjects.push_back(idfObject);
return idfObject;
} else {
LOG(Error, "Actuator '" << modelObject.nameString() << "' references a SpaceLoad '"
<< load.get().name().get() << "' which is not associated with a ThermalZone, it will not be translated.");
return boost::none;
auto spaceType = load->spaceType();
if (spaceType) {

// should not also have a space assigned
OS_ASSERT(!space);

// the load references a space type, this means it will reference a zonelist in EnergyPlus
// in EnergyPlus, each load in a zonelist is duplicated into each zone with a new name based on the zone
boost::optional<IdfObject> result;
for (const auto& space : spaceType->spaces()){
auto tz = space.thermalZone();
if (tz) {
std::string tz_name = tz.get().nameString() + " " + m.nameString();
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, tz_name);
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, modelObject.actuatedComponentType());
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, modelObject.actuatedComponentControlType());
if (!result){
result = idfObject;
}
} else {
LOG(Error, "Actuator '" << modelObject.nameString() << "' references a SpaceLoad '"
<< load.get().name().get() << "' which is not associated with a ThermalZone, it will not be translated.");
}
}
//Give WArning that spaceType has multiple spaces
if (spaceType->spaces().size() > 1) {
LOG(Warn, "Actuator '" << modelObject.nameString() << "' references a SpaceLoad '" << load.get().name().get() << "' attached to SpaceType '" << spaceType.get().nameString() << "', with multiple spaces. Check your EMS programs to make sure your actuators are correct.");
}
// return the first idf object
if (result) {
m_idfObjects.push_back(result.get());
}
return result;

} else if (space) {

// if load is assigned to a single space instead of a space type then the name will not be changed in EnergyPlus
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, m.nameString());
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, modelObject.actuatedComponentType());
idfObject.setString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, modelObject.actuatedComponentControlType());
m_idfObjects.push_back(idfObject);

return idfObject;
} else {
LOG(Error, "Actuator '" << modelObject.nameString() << "' references a SpaceLoad '"
<< load.get().name().get() << "' which is not associated with a Space, it will not be translated.");
return boost::none;
LOG(Error, "Actuator '" << modelObject.nameString() << "' references a SpaceLoad '"
<< load.get().name().get() << "' which is not associated with a ThermalZone, it will not be translated.");
return boost::none;
}

// Classic case, we just write it
Expand Down
162 changes: 160 additions & 2 deletions openstudiocore/src/energyplus/Test/EMS_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorWeatherActuator2_EMS) {
model.save(toPath("./EMS_weatheractuator2.osm"), true);
workspace.save(toPath("./EMS_weatheractuator2.idf"), true);
}
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_EMS) {
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_Space_EMS) {
Model model;

Building building = model.getUniqueModelObject<Building>();
Expand All @@ -531,6 +531,7 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_EMS) {
GasEquipmentDefinition gasEquipDef(model);
GasEquipment gasEquip(gasEquipDef);
gasEquip.setName("Gas Equip");
//add to space and not spacetype
space.setGasEquipmentPower(10, gasEquip);

// add actuator
Expand All @@ -551,6 +552,56 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_EMS) {
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::Name, false));
EXPECT_EQ("Gas_Equip_Actuator", object.getString(EnergyManagementSystem_ActuatorFields::Name, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false));
//Should not have TZ in the name since the load is attached to a single space
EXPECT_EQ("Gas Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
//EXPECT_EQ("Thermal Zone Gas Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false));
EXPECT_EQ(ComponentType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false));
EXPECT_EQ(ControlType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false).get());

model.save(toPath("./EMS_example.osm"), true);
workspace.save(toPath("./EMS_example.idf"), true);
}
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_SpaceType_EMS) {
Model model;

Building building = model.getUniqueModelObject<Building>();

ThermalZone zone1(model);
zone1.setName("Thermal Zone");

Space space(model);
SpaceType spaceType(model);
space.setThermalZone(zone1);
space.setSpaceType(spaceType);

GasEquipmentDefinition gasEquipDef(model);
GasEquipment gasEquip(gasEquipDef);
gasEquip.setName("Gas Equip");
gasEquipDef.setDesignLevel(10);
//add to spacetype and not space
gasEquip.setSpaceType(spaceType);

// add actuator
std::string ControlType = "Gas Power Level";
std::string ComponentType = "GasEquipment";
EnergyManagementSystemActuator fanActuator(gasEquip, ComponentType, ControlType);
std::string actName = "Gas Equip Actuator";
fanActuator.setName(actName);

ForwardTranslator forwardTranslator;
Workspace workspace = forwardTranslator.translateModel(model);
EXPECT_EQ(0u, forwardTranslator.errors().size());
EXPECT_EQ(1u, workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator).size());

WorkspaceObject object = workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator)[0];


ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::Name, false));
EXPECT_EQ("Gas_Equip_Actuator", object.getString(EnergyManagementSystem_ActuatorFields::Name, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false));
//Should have TZ in the name since the load is attached to a spacetype with only 1 space
EXPECT_EQ("Thermal Zone Gas Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false));
EXPECT_EQ(ComponentType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false).get());
Expand All @@ -560,7 +611,7 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_EMS) {
model.save(toPath("./EMS_example.osm"), true);
workspace.save(toPath("./EMS_example.idf"), true);
}
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad2_EMS) {
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_Space2_EMS) {
Model model;

Building building = model.getUniqueModelObject<Building>();
Expand All @@ -576,6 +627,7 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad2_EMS) {
ElectricEquipmentDefinition elecEquipDef(model);
ElectricEquipment elecEquip(elecEquipDef);
elecEquip.setName("Electric Equip");
//add to space and not spacetype
space.setElectricEquipmentPower(10, elecEquip);

// add actuator
Expand All @@ -596,6 +648,55 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad2_EMS) {
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::Name, false));
EXPECT_EQ("Electric_Equip_Actuator", object.getString(EnergyManagementSystem_ActuatorFields::Name, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false));
//Should not have TZ in the name since the load is attached to a single space
EXPECT_EQ("Electric Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false));
EXPECT_EQ(ComponentType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false));
EXPECT_EQ(ControlType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false).get());

model.save(toPath("./EMS_example.osm"), true);
workspace.save(toPath("./EMS_example.idf"), true);
}
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_SpaceType2_EMS) {
Model model;

Building building = model.getUniqueModelObject<Building>();

ThermalZone zone1(model);
zone1.setName("Thermal Zone");

Space space(model);
SpaceType spaceType(model);
space.setThermalZone(zone1);
space.setSpaceType(spaceType);

ElectricEquipmentDefinition elecEquipDef(model);
ElectricEquipment elecEquip(elecEquipDef);
elecEquip.setName("Electric Equip");
elecEquipDef.setDesignLevel(10);
//add to spacetype and not space
elecEquip.setSpaceType(spaceType);

// add actuator
std::string ControlType = "Electric Level";
std::string ComponentType = "ElectricEquipment";
EnergyManagementSystemActuator fanActuator(elecEquip, ComponentType, ControlType);
std::string actName = "Electric Equip Actuator";
fanActuator.setName(actName);

ForwardTranslator forwardTranslator;
Workspace workspace = forwardTranslator.translateModel(model);
EXPECT_EQ(0u, forwardTranslator.errors().size());
EXPECT_EQ(1u, workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator).size());

WorkspaceObject object = workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator)[0];


ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::Name, false));
EXPECT_EQ("Electric_Equip_Actuator", object.getString(EnergyManagementSystem_ActuatorFields::Name, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false));
//Should have TZ in the name since the load is attached to a spacetype with only 1 space
EXPECT_EQ("Thermal Zone Electric Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false));
EXPECT_EQ(ComponentType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false).get());
Expand Down Expand Up @@ -640,6 +741,63 @@ TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad3_EMS) {
model.save(toPath("./EMS_example.osm"), true);
workspace.save(toPath("./EMS_example.idf"), true);
}
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad_SpaceTypes_EMS) {
Model model;

Building building = model.getUniqueModelObject<Building>();

ThermalZone zone1(model);
zone1.setName("Thermal Zone 1");
ThermalZone zone2(model);
zone2.setName("Thermal Zone 2");

SpaceType spaceType(model);

Space space1(model);
space1.setThermalZone(zone1);
space1.setSpaceType(spaceType);

Space space2(model);
space2.setThermalZone(zone2);
space2.setSpaceType(spaceType);

ElectricEquipmentDefinition elecEquipDef(model);
ElectricEquipment elecEquip(elecEquipDef);
elecEquip.setName("Electric Equip");
elecEquipDef.setDesignLevel(10);
//set SpaceLoad object to the SpaceType
elecEquip.setSpaceType(spaceType);

// add actuator
std::string ControlType = "Electric Level";
std::string ComponentType = "ElectricEquipment";
EnergyManagementSystemActuator fanActuator(elecEquip, ComponentType, ControlType);
std::string actName = "Electric Equip Actuator";
fanActuator.setName(actName);

ForwardTranslator forwardTranslator;
Workspace workspace = forwardTranslator.translateModel(model);
EXPECT_EQ(0u, forwardTranslator.errors().size());
//expect a warning since there are 2 spaces with the same spaceType
EXPECT_EQ(1u, forwardTranslator.warnings().size());
//expect 1 actuator since there are 2 spaces with the same spaceType but only 1 will get translated right now
EXPECT_EQ(1u, workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator).size());

WorkspaceObject object = workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Actuator)[0];

ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::Name, false));
EXPECT_EQ("Electric_Equip_Actuator", object.getString(EnergyManagementSystem_ActuatorFields::Name, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false));
// cannot guarantee the order of which TZ gets translated first
//EXPECT_EQ("Thermal Zone 2 Electric Equip", object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false));
EXPECT_EQ(ComponentType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType, false).get());
ASSERT_TRUE(object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false));
EXPECT_EQ(ControlType, object.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType, false).get());

model.save(toPath("./EMS_multi_spaces_spacetypes.osm"), true);
workspace.save(toPath("./EMS_multi_spaces_spacetypes.idf"), true);
}
/*
TEST_F(EnergyPlusFixture, ForwardTranslatorActuatorSpaceLoad4_EMS) {
Model model;
Expand Down

1 comment on commit f58a3e1

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.4.0Release (macumber) - x86_64-MacOS-10.10-clang: Build Failed

Build Badge Test Badge

Please sign in to comment.