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

Convert site electricity sensor from Joules to watts #464

Merged
merged 1 commit into from
Jun 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_idd_type(object)
# @return [String]
def create_ems_str(id)
id = id.gsub(/[\s-]/, '_')
id = id.gsub(/[^\w]/, '_')
Copy link
Member Author

@TShapinsky TShapinsky Feb 6, 2024

Choose a reason for hiding this comment

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

Without this the function is not idempotent. It will prepend _ forever

id = "_#{id}" if (id =~ /[0-9].*/) == 0
id
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# start the measure
class AlfalfaSiteSensors < OpenStudio::Measure::EnergyPlusMeasure


FuelMeter = Struct.new(:fuel, :adjustment_factor)

include OpenStudio::Alfalfa::EnergyPlusMixin
# human readable name
def name
Expand All @@ -26,9 +29,13 @@ def arguments(workspace)
return args
end

def create_output_meter(name)
def create_output_meter(name, adjustment_factor=1)
sensor_name = "#{create_ems_str(name)}_sensor"
output_name = "#{create_ems_str(name)}_output"
adjusted_name = "#{create_ems_str(name)}_sensor_adjusted"
program_calling_manager_name = "#{create_ems_str(name)}_calling_point"
program_name = "#{create_ems_str(name)}_program"

new_meter_string = "
Output:Meter,
#{name};
Expand All @@ -45,7 +52,32 @@ def create_output_meter(name)
new_sensor_object = OpenStudio::IdfObject.load(new_sensor_string).get
@workspace.addObject(new_sensor_object)

create_ems_output_variable(output_name, sensor_name)
new_global_variable_string= "
EnergyManagementSystem:GlobalVariable,
#{adjusted_name}; !- Name
"

new_global_variable_object = OpenStudio::IdfObject.load(new_global_variable_string).get
@workspace.addObject(new_global_variable_object)

new_program_string = "
EnergyManagementSystem:Program,
#{program_name}, !- Name
SET #{adjusted_name} = #{sensor_name}*#{adjustment_factor};
"
new_program_object = OpenStudio::IdfObject.load(new_program_string).get
@workspace.addObject(new_program_object)

new_calling_manager_string = "
EnergyManagementSystem:ProgramCallingManager,
#{program_calling_manager_name}, !- Name
EndOfZoneTimestepAfterZoneReporting, !- EnergyPlus Model Calling Point
#{program_name};
"
new_calling_manager_object = OpenStudio::IdfObject.load(new_calling_manager_string).get
@workspace.addObject(new_calling_manager_object)

create_ems_output_variable(output_name, adjusted_name)
end

# define what happens when the measure is run
Expand All @@ -58,11 +90,11 @@ def run(workspace, runner, user_arguments)
end

fuels = [
'Electricity'
FuelMeter.new('Electricity', 1.0/60)
]

fuels.each do |fuel|
register_output(create_output_meter("#{fuel}:Facility")).display_name = "Whole Building #{fuel}"
register_output(create_output_meter("#{fuel.fuel}:Facility", fuel.adjustment_factor)).display_name = "Whole Building #{fuel.fuel}"
end

report_inputs_outputs
Expand Down
Loading