Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

@adhilton, this EMS code isn't too different from yours. The model this was used on has PlantComponent:TemperatureSource object on the demand side, and then cooling and heating water to air heat pumps on the demand side.

image description

Here is the full run section of the measure that add's EMS code wasn't modeling infinite capacity. You could modify this to use the ES code from your answer.

# use the built-in error checking 
if !runner.validateUserArguments(arguments(workspace), user_arguments)
  return false
end

# reporting initial condition of model
runner.registerInitialCondition("The building started with #{workspace.objects.size} Energy Management  objects.")

# Get the last openstudio model
model = runner.lastOpenStudioModel
if model.empty?
  runner.registerError("Could not load last OpenStudio model, cannot apply measure.")
  return false
end
model = model.get

plant_component_temperature_source = model.getPlantComponentTemperatureSources.first
inlet_port = plant_component_temperature_source.inletModelObject.get # todo - confirm this exists
schedule = plant_component_temperature_source.sourceTemperatureSchedule.get # todo - confirm this exists

string_objects = []

string_objects << "
Output:Variable,
  #{inlet_port.name},                   !- Key Value
  System Node Temperature,              !- Variable Name
  Hourly;                               !- Reporting Frequency
"

string_objects << "
EnergyManagementSystem:Sensor,
  Ground_HX_Inlet_Temp,                   !- Name
  #{inlet_port.name},                     !- Output:Variable or Output:Meter Index Key Name
  System Node Temperature;                !- Output:Variable or Output:Meter Name
"

string_objects << "
EnergyManagementSystem:Actuator,
  Ground_HX_Schedule_Actuator,            !- Name
  #{schedule.name},                       !- Actuated Component Unique Name
  Schedule:Constant,                      !- Actuated Component Type
  Schedule Value;                         !- Actuated Component Control Type
"

string_objects << "
EnergyManagementSystem:Program,
  Ground_HX,                              !- Name
  SET Tin = Ground_HX_Inlet_Temp,         !- Program Line 1
  IF Tin < 15.556,                        !- Program Line 2
  SET Tout = Tin + 5.556,                 !- Program Line 3
  ELSE,                                   !- Program Line 4
  SET Tout = Tin - 5.556,                 !- Program Line 5
  ENDIF,                                  !- Program Line 6
  SET Ground_HX_Schedule_Actuator = Tout; !- Program Line 7
"

string_objects << "
EnergyManagementSystem:ProgramCallingManager,
  Ground HX,                              !- Name
  InsideHVACSystemIterationLoop,          !- EnergyPlus Model Calling Point
  Ground_HX;                              !- Program Name 1
"

# add all of the strings to workspace
string_objects.each do |string_object|
  idfObject = OpenStudio::IdfObject::load(string_object)
  object = idfObject.get
  wsObject = workspace.addObject(object)
end

# report final condition of model
runner.registerFinalCondition("The finished started with #{workspace.objects.size} Energy Management objects.")

return true

@adhilton, this EMS code isn't too different from yours. The model this was used on has PlantComponent:TemperatureSource object on the demand supply side, and then cooling and heating water to air heat pumps on the demand side.

image description

Here is the full run section of the measure that add's EMS code wasn't modeling infinite capacity. You could modify this to use the ES code from your answer.

# use the built-in error checking 
if !runner.validateUserArguments(arguments(workspace), user_arguments)
  return false
end

# reporting initial condition of model
runner.registerInitialCondition("The building started with #{workspace.objects.size} Energy Management  objects.")

# Get the last openstudio model
model = runner.lastOpenStudioModel
if model.empty?
  runner.registerError("Could not load last OpenStudio model, cannot apply measure.")
  return false
end
model = model.get

plant_component_temperature_source = model.getPlantComponentTemperatureSources.first
inlet_port = plant_component_temperature_source.inletModelObject.get # todo - confirm this exists
schedule = plant_component_temperature_source.sourceTemperatureSchedule.get # todo - confirm this exists

string_objects = []

string_objects << "
Output:Variable,
  #{inlet_port.name},                   !- Key Value
  System Node Temperature,              !- Variable Name
  Hourly;                               !- Reporting Frequency
"

string_objects << "
EnergyManagementSystem:Sensor,
  Ground_HX_Inlet_Temp,                   !- Name
  #{inlet_port.name},                     !- Output:Variable or Output:Meter Index Key Name
  System Node Temperature;                !- Output:Variable or Output:Meter Name
"

string_objects << "
EnergyManagementSystem:Actuator,
  Ground_HX_Schedule_Actuator,            !- Name
  #{schedule.name},                       !- Actuated Component Unique Name
  Schedule:Constant,                      !- Actuated Component Type
  Schedule Value;                         !- Actuated Component Control Type
"

string_objects << "
EnergyManagementSystem:Program,
  Ground_HX,                              !- Name
  SET Tin = Ground_HX_Inlet_Temp,         !- Program Line 1
  IF Tin < 15.556,                        !- Program Line 2
  SET Tout = Tin + 5.556,                 !- Program Line 3
  ELSE,                                   !- Program Line 4
  SET Tout = Tin - 5.556,                 !- Program Line 5
  ENDIF,                                  !- Program Line 6
  SET Ground_HX_Schedule_Actuator = Tout; !- Program Line 7
"

string_objects << "
EnergyManagementSystem:ProgramCallingManager,
  Ground HX,                              !- Name
  InsideHVACSystemIterationLoop,          !- EnergyPlus Model Calling Point
  Ground_HX;                              !- Program Name 1
"

# add all of the strings to workspace
string_objects.each do |string_object|
  idfObject = OpenStudio::IdfObject::load(string_object)
  object = idfObject.get
  wsObject = workspace.addObject(object)
end

# report final condition of model
runner.registerFinalCondition("The finished started with #{workspace.objects.size} Energy Management objects.")

return true

@adhilton, this EMS code isn't too different from yours. The model this was used on has PlantComponent:TemperatureSource object on the supply side, and then cooling and heating water to air heat pumps on the demand side.

image description

Here is the full run section of the measure that add's EMS code adds EMS. Code wasn't modeling infinite capacity. You could modify this to use the ES code from your answer.

# use the built-in error checking 
if !runner.validateUserArguments(arguments(workspace), user_arguments)
  return false
end

# reporting initial condition of model
runner.registerInitialCondition("The building started with #{workspace.objects.size} Energy Management  objects.")

# Get the last openstudio model
model = runner.lastOpenStudioModel
if model.empty?
  runner.registerError("Could not load last OpenStudio model, cannot apply measure.")
  return false
end
model = model.get

plant_component_temperature_source = model.getPlantComponentTemperatureSources.first
inlet_port = plant_component_temperature_source.inletModelObject.get # todo - confirm this exists
schedule = plant_component_temperature_source.sourceTemperatureSchedule.get # todo - confirm this exists

string_objects = []

string_objects << "
Output:Variable,
  #{inlet_port.name},                   !- Key Value
  System Node Temperature,              !- Variable Name
  Hourly;                               !- Reporting Frequency
"

string_objects << "
EnergyManagementSystem:Sensor,
  Ground_HX_Inlet_Temp,                   !- Name
  #{inlet_port.name},                     !- Output:Variable or Output:Meter Index Key Name
  System Node Temperature;                !- Output:Variable or Output:Meter Name
"

string_objects << "
EnergyManagementSystem:Actuator,
  Ground_HX_Schedule_Actuator,            !- Name
  #{schedule.name},                       !- Actuated Component Unique Name
  Schedule:Constant,                      !- Actuated Component Type
  Schedule Value;                         !- Actuated Component Control Type
"

string_objects << "
EnergyManagementSystem:Program,
  Ground_HX,                              !- Name
  SET Tin = Ground_HX_Inlet_Temp,         !- Program Line 1
  IF Tin < 15.556,                        !- Program Line 2
  SET Tout = Tin + 5.556,                 !- Program Line 3
  ELSE,                                   !- Program Line 4
  SET Tout = Tin - 5.556,                 !- Program Line 5
  ENDIF,                                  !- Program Line 6
  SET Ground_HX_Schedule_Actuator = Tout; !- Program Line 7
"

string_objects << "
EnergyManagementSystem:ProgramCallingManager,
  Ground HX,                              !- Name
  InsideHVACSystemIterationLoop,          !- EnergyPlus Model Calling Point
  Ground_HX;                              !- Program Name 1
"

# add all of the strings to workspace
string_objects.each do |string_object|
  idfObject = OpenStudio::IdfObject::load(string_object)
  object = idfObject.get
  wsObject = workspace.addObject(object)
end

# report final condition of model
runner.registerFinalCondition("The finished started with #{workspace.objects.size} Energy Management objects.")

return true