Skip to content

Commit

Permalink
Merge pull request #3112 from NREL/ems-enhancements
Browse files Browse the repository at this point in the history
resolve EMS Sensor issue 3102
  • Loading branch information
kbenne authored Apr 29, 2018
2 parents c1c4504 + 7e23793 commit 4f268e2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemSen
boost::optional<std::string> s;

IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_Sensor);
m_idfObjects.push_back(idfObject);
//Name
s = modelObject.name();
if (s) {
Expand Down Expand Up @@ -91,24 +90,33 @@ boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemSen
newline.replace(pos, 38, mObject.get().nameString());
}
}
else {
//did not find an object with the UID so do not FT
LOG(Error, "Key Name for Sensor '" << modelObject.nameString() << "' is UID but does not exist, it will not be translated.");
return boost::none;
}
}
idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterIndexKeyName, newline);
}
d = modelObject.outputVariable();
if (d.is_initialized()) {
idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, d.get().variableName());
m_idfObjects.push_back(idfObject);
return idfObject;
}
m = modelObject.outputMeter();
if (m.is_initialized()){
idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, m.get().name());
m_idfObjects.push_back(idfObject);
return idfObject;
}
s = modelObject.outputVariableOrMeterName();
if (s.is_initialized()) {
idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, s.get());
m_idfObjects.push_back(idfObject);
return idfObject;
}
m_idfObjects.push_back(idfObject);
return idfObject;
}

Expand Down
51 changes: 51 additions & 0 deletions openstudiocore/src/energyplus/Test/EMS_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
#include "../../model/OtherEquipment_Impl.hpp"
#include "../../model/OtherEquipmentDefinition.hpp"
#include "../../model/OtherEquipmentDefinition_Impl.hpp"
#include "../../model/PlantLoop.hpp"
#include "../../model/Node.hpp"
#include "../../model/Node_Impl.hpp"
#include "../../model/AvailabilityManagerHighTemperatureTurnOff.hpp"
#include "../../model/AvailabilityManagerHighTemperatureTurnOff_Impl.hpp"

#include "../../model/Version.hpp"
#include "../../model/Version_Impl.hpp"
Expand Down Expand Up @@ -1595,3 +1600,49 @@ TEST_F(EnergyPlusFixture, ReverseTranslatorTrendVariable2_EMS) {
model.save(toPath("./EMS_TrendVariable2T.osm"), true);

}

TEST_F(EnergyPlusFixture, ForwardTranslatorSensorDelete_EMS) {

Model model;
PlantLoop plantLoop(model);
AvailabilityManagerHighTemperatureTurnOff avm(model);
avm.setSensorNode(model.outdoorAirNode());
plantLoop.addAvailabilityManager(avm);
std::vector<std::string> avm_names = avm.outputVariableNames();

// add sensor 1
EnergyManagementSystemSensor sensor(model, avm_names[0]);
sensor.setKeyName(toString(avm.handle()));

// Sensor attached to AVM
std::string key = toString(avm.handle());
EXPECT_EQ(key, sensor.keyName());
// 1 sensor in the model
EXPECT_EQ(static_cast<unsigned>(1), model.getModelObjects<EnergyManagementSystemSensor>().size());
// 1 avm in the model
EXPECT_EQ(static_cast<unsigned>(1), model.getModelObjects<AvailabilityManagerHighTemperatureTurnOff>().size());

ForwardTranslator forwardTranslator;
Workspace workspace = forwardTranslator.translateModel(model);

//there should be 1 sensor
ASSERT_EQ(1u, workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Sensor).size());
WorkspaceObject object = workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_Sensor)[0];

//model.save(toPath("./EMS_SensorBeforeDelete.osm"), true);
//workspace.save(toPath("./EMS_SensorBeforeDelete.idf"), true);

avm.remove();
// 0 avm in the model
EXPECT_EQ(static_cast<unsigned>(0), model.getModelObjects<AvailabilityManagerHighTemperatureTurnOff>().size());
//sensor still has keyName as avm UUID string (will not FT though eventually)
EXPECT_EQ(key, sensor.keyName());

Workspace workspaceDelete = forwardTranslator.translateModel(model);

ASSERT_EQ(0u, workspaceDelete.getObjectsByType(IddObjectType::EnergyManagementSystem_Sensor).size());

//model.save(toPath("./EMS_SensorDelete.osm"), true);
//workspaceDelete.save(toPath("./EMS_SensorDelete.idf"), true);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
#include "ModelFixture.hpp"
#include "../Building.hpp"
#include "../Building_Impl.hpp"
#include "../PlantLoop.hpp"
#include "../Node.hpp"
#include "../Node_Impl.hpp"
#include "../AvailabilityManagerHighTemperatureTurnOff.hpp"
#include "../AvailabilityManagerHighTemperatureTurnOff_Impl.hpp"
#include "../ThermalZone.hpp"
#include "../EnergyManagementSystemSensor.hpp"
#include "../EnergyManagementSystemSensor_Impl.hpp"
Expand Down Expand Up @@ -177,4 +182,32 @@ TEST_F(ModelFixture, EMSSensorOutVar) {

}

TEST_F(ModelFixture, EMSSensorDelete) {
Model model;
PlantLoop plantLoop(model);
AvailabilityManagerHighTemperatureTurnOff avm(model);
avm.setSensorNode(model.outdoorAirNode());
plantLoop.addAvailabilityManager(avm);
std::vector<std::string> avm_names = avm.outputVariableNames();

// add sensor 1
EnergyManagementSystemSensor sensor(model, avm_names[0]);
sensor.setKeyName(toString(avm.handle()));

// Sensor attached to AVM
std::string key = toString(avm.handle());
EXPECT_EQ(key, sensor.keyName());
// 1 sensor in the model
EXPECT_EQ(static_cast<unsigned>(1), model.getModelObjects<EnergyManagementSystemSensor>().size());
// 1 avm in the model
EXPECT_EQ(static_cast<unsigned>(1), model.getModelObjects<AvailabilityManagerHighTemperatureTurnOff>().size());
model.save(toPath("./EMS_sensor_delete_test.osm"), true);

avm.remove();
// 0 avm in the model
EXPECT_EQ(static_cast<unsigned>(0), model.getModelObjects<AvailabilityManagerHighTemperatureTurnOff>().size());
//sensor still has keyName as avm UUID string (will not FT though eventually)
EXPECT_EQ(key, sensor.keyName());
}


0 comments on commit 4f268e2

Please sign in to comment.