Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:NREL/alfalfa into bump_version_060
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Jul 18, 2023
2 parents 0945d4f + 54fd6a2 commit dd40af8
Show file tree
Hide file tree
Showing 13 changed files with 807 additions and 568 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: CI

on:
push:
branches:
- "*"
release:
types: [released]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
require 'openstudio_mixin'
require 'output'
require 'point'

# Module which contains all OpenStudio code
module OpenStudio
# Module which contains Alfalfa specific functionality
module Alfalfa
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
require_relative 'utils'
module OpenStudio
module Alfalfa
##
# Base mixin for managing alfalfa points
#
module AlfalfaMixin
##
# Base mixin for managing alfalfa points
#

include OpenStudio::Alfalfa::Utils
# Create reports of input and outputs for alfalfa
# Must be executed at the end of the measure to expose points in alfalfa
def report_inputs_outputs
# Create reports of input and outputs for alfalfa
# Must be executed at the end of the measure to expose points in alfalfa
@inputs.each do |input|
next if input.echo.nil?
next if @outputs.include? input.echo

@outputs.append(input.echo)
end

inputs_dict = {}
outputs_dict = {}
Expand All @@ -30,21 +35,21 @@ def report_inputs_outputs
end
end

# Register an input for inclusion in alfalfa
#
# @param [IdfObject, ModelObject, Input] input to register
# May be:
# - ExternalInterface:Actuator
# - ExternalInterface:Variable
# - ExternalInterface:Schedule
# - OS:ExternalInterface:Variable
# - OS:ExternalInterface:Schedule
# - OS:ExternalInterface:Actuator
# or:
# - OpenStudio::Alfalfa::Input
#
# @return [Input]
def register_input(input)
# Register an input for inclusion in alfalfa
#
# @param [IdfObject, ModelObject, Input] input to register
# May be:
# - ExternalInterface:Actuator
# - ExternalInterface:Variable
# - ExternalInterface:Schedule
# - OS:ExternalInterface:Variable
# - OS:ExternalInterface:Schedule
# - OS:ExternalInterface:Actuator
# or:
# - OpenStudio::Alfalfa::Input
#
# @return [Input]
if input.is_a? OpenStudio::Alfalfa::Input
@inputs.append(input)
else
Expand All @@ -54,12 +59,12 @@ def register_input(input)
input
end

# Find an input by it's associated object name
#
# @param [String] name Name of input to find
#
# @return [Input]
def get_input_by_name(name)
# Find an input by it's associated object name
#
# @param [String] name Name of input to find
#
# @return [Input]
@inputs.each do |input|
next unless input.object.name.get == name

Expand All @@ -68,19 +73,19 @@ def get_input_by_name(name)
nil
end

# Register an output for inclusion in alfalfa
#
# @param output [IdfObject, ModelObject, Output] output to register
# May be:
# - Output:Variable
# - EnergyManagementSystem:OutputVariable
# - OS:Output:Variable
# - OS:EnergyManagementSystem:OutputVariable
# or:
# - OpenStudio::Alfalfa::Output
#
# @return [Output]
def register_output(output)
# Register an output for inclusion in alfalfa
#
# @param [IdfObject, ModelObject, Output] input to register
# May be:
# - Output:Variable
# - EnergyManagementSystem:OutputVariable
# - OS:Output:Variable
# - OS:EnergyManagementSystem:OutputVariable
# or:
# - OpenStudio::Alfalfa::Output
#
# @return [Output]
if output.is_a? OpenStudio::Alfalfa::Output
@outputs.append(output)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
require_relative 'utils'
module OpenStudio
module Alfalfa
##
# EnergyPlusMixin
#
# Mixin to include when developing an EnergyPlus Measure
module EnergyPlusMixin
##
# EnergyPlusMixin
#
# Mixin to include when developing an EnergyPlus Measure
include OpenStudio::Alfalfa::AlfalfaMixin
include OpenStudio::Alfalfa::Utils

# Get first node from NodeList
#
# @param [String] node NodeList id
def get_node_from_nodelist(node)
# Get first node from NodeList
#
# @param [String] node NodeList id
node_list_object = @workspace.getObjectByTypeAndName('NodeList'.to_IddObjectType, node)
if node_list_object.is_initialized
return node_list_object.get.getField(1).get
else
return node
end
return node_list_object.get.getField(1).get if node_list_object.is_initialized

node
end

# Create Output Variable
#
# @param [String] key Key of Output Variable
# @param [String] var Variable of Output Variable
#
# @return [Output]
def create_output_variable(key, var)
# Create Output Variable
#
# @param[String] key Key of Output Variable
# @param[String] var Variable of Output Variable
#
# @return [Output]
output_variable_string = "
Output:Variable,
#{key},
Expand All @@ -38,14 +36,14 @@ def create_output_variable(key, var)
OpenStudio::Alfalfa::Output.new(@workspace.addObject(output_variable_object).get)
end

# Create EMS Output Variable
#
# @param [String] name Name of EMS Output Variable to create
# @param [String] variable EMS name of variable to connect to Output Variable
# @param [String] unit Unit of output
#
# @return [Output]
def create_ems_output_variable(name, variable, unit = 'C')
# Create EMS Output Variable
#
# @param[String] name Name of EMS Output Variable to create
# @param[String] variable EMS name of variable to connect to Output Variable
# @param[String] unit Unit of output
#
# @return [Output]
output_variable_string = "
EnergyManagementSystem:OutputVariable,
#{name},
Expand All @@ -58,13 +56,13 @@ def create_ems_output_variable(name, variable, unit = 'C')
OpenStudio::Alfalfa::Output.new(@workspace.addObject(output_variable_object).get)
end

# Create External Interface Variable
#
# @param [String] name Name of external variable to create
# @param [Number] initial_value Initial value of external variable
#
# @return [Input]
def create_external_variable(name, initial_value = 0)
# Create External Interface Variable
#
# @param [String] name Name of external variable to create
# @param [Number] initial_value Initial value of external variable
#
# @return [Input]
new_external_variable_string = "
ExternalInterface:Variable,
#{create_ems_str(name)}, !- Name,
Expand All @@ -76,13 +74,17 @@ def create_external_variable(name, initial_value = 0)
input
end

def create_enabled_input(name, variable_name)
# Create enabled input to actuate an EMS variable
#
# @param [String] name Name of input to create
# @param [String] variable_name EMS name of variable to control
#
# @return [Input]
# Create enabled input to actuate an EMS variable.
# This method creates an external variable with the specified name
# and an EMS program to copy the value to the specified variable if enabled
# or the default value otherwise
#
# @param [String] name Name of input to create
# @param [String] variable_name EMS name of variable to control
# @param [String] default Value to have when not enabled. Default to null for actuator control
#
# @return [Input]
def create_enabled_input(name, variable_name, default = 'Null')
program_name = create_ems_str("#{name}_program")
alfalfa_input = create_external_variable(name)
enable_name = create_ems_str("#{name}_Enable")
Expand All @@ -93,7 +95,7 @@ def create_enabled_input(name, variable_name)
IF #{enable_name},
SET #{variable_name} = #{name},
ELSE,
SET #{variable_name} = Null,
SET #{variable_name} = #{default},
ENDIF;
"
new_program_object = OpenStudio::IdfObject.load(new_program_string).get
Expand All @@ -103,16 +105,16 @@ def create_enabled_input(name, variable_name)
alfalfa_input
end

def create_actuator(name, component, component_type, control_type, external=false)
# Create actuator
#
# @param [String] name Name of actuator to create
# @param [String] component Name of component to actuate
# @param [String] component_type Type of component
# @param [String] control_type Type of control
# @param [Boolean] external When true an external interface variable with {name} will be created and returned
#
# @return [IdfObject, (Input, Output)]
# Create actuator
#
# @param name [String] Name of actuator to create
# @param component [String] Name of component to actuate
# @param component_type [String] Type of component
# @param control_type[String] Type of control
# @param external [Boolean] When true an external interface variable with {name} will be created and returned
#
# @return [IdfObject, Input]
def create_actuator(name, component, component_type, control_type, external = false)
if external
actuator_name = create_ems_str("#{name}_actuator")
actuator_object = create_actuator(actuator_name, component, component_type, control_type)
Expand All @@ -121,7 +123,7 @@ def create_actuator(name, component, component_type, control_type, external=fals
echo_name = create_ems_str("#{actuator_name}_echo")
output = create_ems_output_variable(echo_name, actuator_name)
input.echo = output
return input, output
input
else
new_actuator_string = "
EnergyManagementSystem:Actuator,
Expand All @@ -138,7 +140,7 @@ def create_actuator(name, component, component_type, control_type, external=fals
def create_calling_point
new_calling_manager_string = "
EnergyManagementSystem:ProgramCallingManager,
#{create_ems_str(name())}_calling_point, !- Name
#{create_ems_str(name)}_calling_point, !- Name
EndOfZoneTimestepBeforeZoneReporting; !- EnergyPlus Model Calling Point
"
new_calling_manager_object = OpenStudio::IdfObject.load(new_calling_manager_string).get
Expand Down
17 changes: 11 additions & 6 deletions alfalfa_worker/jobs/openstudio/lib/alfalfa-lib-gem/lib/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
require_relative 'point'
module OpenStudio
module Alfalfa
##
# Input
#
# Class which represents an Input point to Alfalfa
class Input < Point
##
# Input
#
# Class which represents an Input point to Alfalfa
include OpenStudio::Alfalfa::Utils
attr_reader :input_object

Expand Down Expand Up @@ -42,9 +42,12 @@ def actuator=(actuator_object)
actuator_type = get_idd_type(actuator_object)

actuator_types = ['ExternalInterface:Actuator'.to_IddObjectType,
'OS:EnergyManagementSystem:Actuator'.to_IddObjectType,
'EnergyManagementSystem:Actuator'.to_IddObjectType]

raise "#{actuator_type.valueDescription} is not a valid actuator type" unless actuator_types.include? actuator_type
unless actuator_types.include? actuator_type
raise "#{actuator_type.valueDescription} is not a valid actuator type"
end

@hash['actuated_component'] = actuator_object.getString(1).get
@hash['actuated_component_type'] = actuator_object.getString(2).get
Expand All @@ -58,7 +61,9 @@ def enable_variable=(enable_variable)
enable_variable_types = ['ExternalInterface:Variable'.to_IddObjectType,
'OS:ExternalInterface:Variable'.to_IddObjectType]

raise "#{enable_variable_type.valueDescription} is an invalid enable variable type" unless enable_variable_types.include? enable_variable_type
unless enable_variable_types.include? enable_variable_type
raise "#{enable_variable_type.valueDescription} is an invalid enable variable type"
end

@hash['enable_variable'] = enable_variable.name.get
end
Expand Down
Loading

0 comments on commit dd40af8

Please sign in to comment.