alfalfa-lib 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/alfalfa.rb +13 -0
- data/lib/alfalfa_mixin.rb +99 -0
- data/lib/energy_plus_mixin.rb +167 -0
- data/lib/input.rb +72 -0
- data/lib/openstudio_mixin.rb +117 -0
- data/lib/output.rb +48 -0
- data/lib/point.rb +71 -0
- data/lib/utils.rb +36 -0
- data/lib/version.rb +6 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ed2dabb03d5554d08b9d59d60c6a428a558e003ae35ce9b8e82c3f6bd51f0c9
|
4
|
+
data.tar.gz: bc789596938cecc94e6b16f99ac20a3a65b03153a5dee380907f79823b604d80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7be3f7dadf87b569b097a2ff283bbceed8925abbf786e9ba7829713c7d428938d914034b60cb561d818b3513218e337d3de904d3a4a5d7386b00d55bb611a047
|
7
|
+
data.tar.gz: 625097e38f00189cd1c0bc44b7665cd44e4d8b995b5e34d656f4c3b5c493d4fbb1bd7da928cd2dd45bdc8f908f691da209548bf1acea98965382a23e02d2b277
|
data/lib/alfalfa.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'alfalfa_mixin'
|
2
|
+
require 'energy_plus_mixin'
|
3
|
+
require 'input'
|
4
|
+
require 'openstudio_mixin'
|
5
|
+
require 'output'
|
6
|
+
require 'point'
|
7
|
+
|
8
|
+
# Module which contains all OpenStudio code
|
9
|
+
module OpenStudio
|
10
|
+
# Module which contains Alfalfa specific functionality
|
11
|
+
module Alfalfa
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative 'utils'
|
2
|
+
module OpenStudio
|
3
|
+
module Alfalfa
|
4
|
+
##
|
5
|
+
# Base mixin for managing alfalfa points
|
6
|
+
#
|
7
|
+
module AlfalfaMixin
|
8
|
+
include OpenStudio::Alfalfa::Utils
|
9
|
+
# Create reports of input and outputs for alfalfa
|
10
|
+
# Must be executed at the end of the measure to expose points in alfalfa
|
11
|
+
def report_inputs_outputs
|
12
|
+
@inputs.each do |input|
|
13
|
+
next if input.echo.nil?
|
14
|
+
next if @outputs.include? input.echo
|
15
|
+
|
16
|
+
@outputs.append(input.echo)
|
17
|
+
end
|
18
|
+
|
19
|
+
inputs_dict = {}
|
20
|
+
outputs_dict = {}
|
21
|
+
@inputs.each do |input|
|
22
|
+
hash = input.to_dict
|
23
|
+
inputs_dict[hash['id']] = hash
|
24
|
+
end
|
25
|
+
@outputs.each do |output|
|
26
|
+
hash = output.to_dict
|
27
|
+
outputs_dict[hash['id']] = hash
|
28
|
+
end
|
29
|
+
|
30
|
+
File.open('./report_inputs.json', 'w') do |f|
|
31
|
+
JSON.dump(inputs_dict, f)
|
32
|
+
end
|
33
|
+
File.open('./report_outputs.json', 'w') do |f|
|
34
|
+
JSON.dump(outputs_dict, f)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Register an input for inclusion in alfalfa
|
39
|
+
#
|
40
|
+
# @param [IdfObject, ModelObject, Input] input to register
|
41
|
+
# May be:
|
42
|
+
# - ExternalInterface:Actuator
|
43
|
+
# - ExternalInterface:Variable
|
44
|
+
# - ExternalInterface:Schedule
|
45
|
+
# - OS:ExternalInterface:Variable
|
46
|
+
# - OS:ExternalInterface:Schedule
|
47
|
+
# - OS:ExternalInterface:Actuator
|
48
|
+
# or:
|
49
|
+
# - OpenStudio::Alfalfa::Input
|
50
|
+
#
|
51
|
+
# @return [Input]
|
52
|
+
def register_input(input)
|
53
|
+
if input.is_a? OpenStudio::Alfalfa::Input
|
54
|
+
@inputs.append(input)
|
55
|
+
else
|
56
|
+
input = OpenStudio::Alfalfa::Input.new(input)
|
57
|
+
register_input(input)
|
58
|
+
end
|
59
|
+
input
|
60
|
+
end
|
61
|
+
|
62
|
+
# Find an input by it's associated object name
|
63
|
+
#
|
64
|
+
# @param [String] name Name of input to find
|
65
|
+
#
|
66
|
+
# @return [Input]
|
67
|
+
def get_input_by_name(name)
|
68
|
+
@inputs.each do |input|
|
69
|
+
next unless input.object.name.get == name
|
70
|
+
|
71
|
+
return input
|
72
|
+
end
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
# Register an output for inclusion in alfalfa
|
77
|
+
#
|
78
|
+
# @param output [IdfObject, ModelObject, Output] output to register
|
79
|
+
# May be:
|
80
|
+
# - Output:Variable
|
81
|
+
# - EnergyManagementSystem:OutputVariable
|
82
|
+
# - OS:Output:Variable
|
83
|
+
# - OS:EnergyManagementSystem:OutputVariable
|
84
|
+
# or:
|
85
|
+
# - OpenStudio::Alfalfa::Output
|
86
|
+
#
|
87
|
+
# @return [Output]
|
88
|
+
def register_output(output)
|
89
|
+
if output.is_a? OpenStudio::Alfalfa::Output
|
90
|
+
@outputs.append(output)
|
91
|
+
else
|
92
|
+
output = OpenStudio::Alfalfa::Output.new(output)
|
93
|
+
register_output(output)
|
94
|
+
end
|
95
|
+
output
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require_relative 'alfalfa_mixin'
|
2
|
+
require_relative 'utils'
|
3
|
+
module OpenStudio
|
4
|
+
module Alfalfa
|
5
|
+
##
|
6
|
+
# EnergyPlusMixin
|
7
|
+
#
|
8
|
+
# Mixin to include when developing an EnergyPlus Measure
|
9
|
+
module EnergyPlusMixin
|
10
|
+
include OpenStudio::Alfalfa::AlfalfaMixin
|
11
|
+
include OpenStudio::Alfalfa::Utils
|
12
|
+
|
13
|
+
# Get first node from NodeList
|
14
|
+
#
|
15
|
+
# @param [String] node NodeList id
|
16
|
+
def get_node_from_nodelist(node)
|
17
|
+
node_list_object = @workspace.getObjectByTypeAndName('NodeList'.to_IddObjectType, node)
|
18
|
+
return node_list_object.get.getField(1).get if node_list_object.is_initialized
|
19
|
+
|
20
|
+
node
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create Output Variable
|
24
|
+
#
|
25
|
+
# @param [String] key Key of Output Variable
|
26
|
+
# @param [String] var Variable of Output Variable
|
27
|
+
#
|
28
|
+
# @return [Output]
|
29
|
+
def create_output_variable(key, var)
|
30
|
+
output_variable_string = "
|
31
|
+
Output:Variable,
|
32
|
+
#{key},
|
33
|
+
#{var},
|
34
|
+
Timestep;"
|
35
|
+
output_variable_object = OpenStudio::IdfObject.load(output_variable_string).get
|
36
|
+
OpenStudio::Alfalfa::Output.new(@workspace.addObject(output_variable_object).get)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create EMS Output Variable
|
40
|
+
#
|
41
|
+
# @param [String] name Name of EMS Output Variable to create
|
42
|
+
# @param [String] variable EMS name of variable to connect to Output Variable
|
43
|
+
# @param [String] unit Unit of output
|
44
|
+
#
|
45
|
+
# @return [Output]
|
46
|
+
def create_ems_output_variable(name, variable, unit = 'C')
|
47
|
+
output_variable_string = "
|
48
|
+
EnergyManagementSystem:OutputVariable,
|
49
|
+
#{name},
|
50
|
+
#{variable},
|
51
|
+
Averaged,
|
52
|
+
SystemTimestep,
|
53
|
+
,
|
54
|
+
#{unit};"
|
55
|
+
output_variable_object = OpenStudio::IdfObject.load(output_variable_string).get
|
56
|
+
OpenStudio::Alfalfa::Output.new(@workspace.addObject(output_variable_object).get)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Create External Interface Variable
|
60
|
+
#
|
61
|
+
# @param [String] name Name of external variable to create
|
62
|
+
# @param [Number] initial_value Initial value of external variable
|
63
|
+
#
|
64
|
+
# @return [Input]
|
65
|
+
def create_external_variable(name, initial_value = 0)
|
66
|
+
new_external_variable_string = "
|
67
|
+
ExternalInterface:Variable,
|
68
|
+
#{create_ems_str(name)}, !- Name,
|
69
|
+
#{initial_value}; !- Initial value
|
70
|
+
"
|
71
|
+
new_external_variable_object = OpenStudio::IdfObject.load(new_external_variable_string).get
|
72
|
+
input = OpenStudio::Alfalfa::Input.new(@workspace.addObject(new_external_variable_object).get)
|
73
|
+
input.display_name = name
|
74
|
+
input
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create enabled input to actuate an EMS variable.
|
78
|
+
# This method creates an external variable with the specified name
|
79
|
+
# and an EMS program to copy the value to the specified variable if enabled
|
80
|
+
# or the default value otherwise
|
81
|
+
#
|
82
|
+
# @param [String] name Name of input to create
|
83
|
+
# @param [String] variable_name EMS name of variable to control
|
84
|
+
# @param [String] default Value to have when not enabled. Default to null for actuator control
|
85
|
+
#
|
86
|
+
# @return [Input]
|
87
|
+
def create_enabled_input(name, variable_name, default = 'Null')
|
88
|
+
program_name = create_ems_str("#{name}_program")
|
89
|
+
alfalfa_input = create_external_variable(name)
|
90
|
+
enable_name = create_ems_str("#{name}_Enable")
|
91
|
+
alfalfa_input_enable = create_external_variable(enable_name)
|
92
|
+
new_program_string = "
|
93
|
+
EnergyManagementSystem:Program,
|
94
|
+
#{program_name}, !- Name
|
95
|
+
IF #{enable_name},
|
96
|
+
SET #{variable_name} = #{name},
|
97
|
+
ELSE,
|
98
|
+
SET #{variable_name} = #{default},
|
99
|
+
ENDIF;
|
100
|
+
"
|
101
|
+
new_program_object = OpenStudio::IdfObject.load(new_program_string).get
|
102
|
+
@workspace.addObject(new_program_object)
|
103
|
+
register_program(program_name)
|
104
|
+
alfalfa_input.enable_variable = alfalfa_input_enable
|
105
|
+
alfalfa_input
|
106
|
+
end
|
107
|
+
|
108
|
+
# Create actuator
|
109
|
+
#
|
110
|
+
# @param name [String] Name of actuator to create
|
111
|
+
# @param component [String] Name of component to actuate
|
112
|
+
# @param component_type [String] Type of component
|
113
|
+
# @param control_type[String] Type of control
|
114
|
+
# @param external [Boolean] When true an external interface variable with {name} will be created and returned
|
115
|
+
#
|
116
|
+
# @return [IdfObject, Input]
|
117
|
+
def create_actuator(name, component, component_type, control_type, external = false)
|
118
|
+
if external
|
119
|
+
actuator_name = create_ems_str("#{name}_actuator")
|
120
|
+
actuator_object = create_actuator(actuator_name, component, component_type, control_type)
|
121
|
+
input = create_enabled_input(name, actuator_name)
|
122
|
+
input.actuator = actuator_object
|
123
|
+
echo_name = create_ems_str("#{actuator_name}_echo")
|
124
|
+
output = create_ems_output_variable(echo_name, actuator_name)
|
125
|
+
input.echo = output
|
126
|
+
input
|
127
|
+
else
|
128
|
+
new_actuator_string = "
|
129
|
+
EnergyManagementSystem:Actuator,
|
130
|
+
#{name}, !- Name
|
131
|
+
#{component}, !- Actuated Component Unique Name
|
132
|
+
#{component_type}, !- Actuated Component Type
|
133
|
+
#{control_type}; !- Actuated Component Control Type
|
134
|
+
"
|
135
|
+
new_actuator_object = OpenStudio::IdfObject.load(new_actuator_string).get
|
136
|
+
@workspace.addObject(new_actuator_object).get
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_calling_point
|
141
|
+
new_calling_manager_string = "
|
142
|
+
EnergyManagementSystem:ProgramCallingManager,
|
143
|
+
#{create_ems_str(name)}_calling_point, !- Name
|
144
|
+
EndOfZoneTimestepBeforeZoneReporting; !- EnergyPlus Model Calling Point
|
145
|
+
"
|
146
|
+
new_calling_manager_object = OpenStudio::IdfObject.load(new_calling_manager_string).get
|
147
|
+
@calling_point_manager = @workspace.addObject(new_calling_manager_object).get
|
148
|
+
@program_count = 0
|
149
|
+
end
|
150
|
+
|
151
|
+
def register_program(program_name)
|
152
|
+
create_calling_point if @calling_point_manager.nil?
|
153
|
+
|
154
|
+
@calling_point_manager.setString(2 + @program_count, program_name)
|
155
|
+
@program_count += 1
|
156
|
+
end
|
157
|
+
|
158
|
+
def run(workspace, runner, user_arguments)
|
159
|
+
super(workspace, runner, user_arguments)
|
160
|
+
@workspace = workspace
|
161
|
+
@calling_point_manager = nil
|
162
|
+
@inputs = []
|
163
|
+
@outputs = []
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/lib/input.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require_relative 'utils'
|
3
|
+
require_relative 'point'
|
4
|
+
module OpenStudio
|
5
|
+
module Alfalfa
|
6
|
+
##
|
7
|
+
# Input
|
8
|
+
#
|
9
|
+
# Class which represents an Input point to Alfalfa
|
10
|
+
class Input < Point
|
11
|
+
include OpenStudio::Alfalfa::Utils
|
12
|
+
attr_reader :input_object
|
13
|
+
|
14
|
+
def initialize(input_object)
|
15
|
+
super(input_object)
|
16
|
+
|
17
|
+
input_type = get_idd_type(input_object)
|
18
|
+
name = input_object.name.get
|
19
|
+
|
20
|
+
case input_type
|
21
|
+
when 'ExternalInterface:Actuator'.to_IddObjectType
|
22
|
+
@hash['actuator'] = name
|
23
|
+
self.actuator = input_object
|
24
|
+
when 'ExternalInterface:Variable'.to_IddObjectType
|
25
|
+
@hash['variable'] = name
|
26
|
+
when 'ExternalInterface:Schedule'.to_IddObjectType
|
27
|
+
@hash['schedule'] = name
|
28
|
+
when 'OS:ExternalInterface:Variable'.to_IddObjectType
|
29
|
+
@hash['variable'] = name
|
30
|
+
when 'OS:ExternalInterface:Schedule'.to_IddObjectType
|
31
|
+
@hash['schedule'] = name
|
32
|
+
when 'OS:ExternalInterface:Actuator'.to_IddObjectType
|
33
|
+
@hash['actuator'] = name
|
34
|
+
self.actuator = input_object
|
35
|
+
else
|
36
|
+
raise "#{input_type.valueDescription} is not a valid input type"
|
37
|
+
end
|
38
|
+
self.display_name = name
|
39
|
+
end
|
40
|
+
|
41
|
+
def actuator=(actuator_object)
|
42
|
+
actuator_type = get_idd_type(actuator_object)
|
43
|
+
|
44
|
+
actuator_types = ['ExternalInterface:Actuator'.to_IddObjectType,
|
45
|
+
'OS:EnergyManagementSystem:Actuator'.to_IddObjectType,
|
46
|
+
'EnergyManagementSystem:Actuator'.to_IddObjectType]
|
47
|
+
|
48
|
+
unless actuator_types.include? actuator_type
|
49
|
+
raise "#{actuator_type.valueDescription} is not a valid actuator type"
|
50
|
+
end
|
51
|
+
|
52
|
+
@hash['actuated_component'] = actuator_object.getString(1).get
|
53
|
+
@hash['actuated_component_type'] = actuator_object.getString(2).get
|
54
|
+
@hash['actuated_component_control_type'] = actuator_object.getString(3).get
|
55
|
+
end
|
56
|
+
|
57
|
+
def enable_variable=(enable_variable)
|
58
|
+
enable_variable = enable_variable.object if enable_variable.instance_of? OpenStudio::Alfalfa::Input
|
59
|
+
|
60
|
+
enable_variable_type = get_idd_type(enable_variable)
|
61
|
+
enable_variable_types = ['ExternalInterface:Variable'.to_IddObjectType,
|
62
|
+
'OS:ExternalInterface:Variable'.to_IddObjectType]
|
63
|
+
|
64
|
+
unless enable_variable_types.include? enable_variable_type
|
65
|
+
raise "#{enable_variable_type.valueDescription} is an invalid enable variable type"
|
66
|
+
end
|
67
|
+
|
68
|
+
@hash['enable_variable'] = enable_variable.name.get
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'alfalfa_mixin'
|
2
|
+
module OpenStudio
|
3
|
+
module Alfalfa
|
4
|
+
##
|
5
|
+
# OpenStudioMixin
|
6
|
+
#
|
7
|
+
# Mixin to include when developing an Model Measure
|
8
|
+
module OpenStudioMixin
|
9
|
+
include OpenStudio::Alfalfa::AlfalfaMixin
|
10
|
+
|
11
|
+
# Create Output Variable
|
12
|
+
#
|
13
|
+
# @param [String] key Key of Output Variable
|
14
|
+
# @param [String] var Variable of Output Variable
|
15
|
+
#
|
16
|
+
# @return [Output]
|
17
|
+
def create_output_variable(key, var)
|
18
|
+
output_variable = OpenStudio::Model::OutputVariable.new(create_ems_str("#{key}_#{var}"), @model)
|
19
|
+
output_variable.setKeyValue(key)
|
20
|
+
output_variable.setVariableName(var)
|
21
|
+
|
22
|
+
OpenStudio::Alfalfa::Output.new(output_variable)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Create EMS Output Variable
|
26
|
+
#
|
27
|
+
# @param [String, ModelObject] variable EMS name of variable to connect to Output Variable
|
28
|
+
# @param [String] unit Unit of output
|
29
|
+
#
|
30
|
+
# @return [Output]
|
31
|
+
def create_ems_output_variable(variable, unit = 'C')
|
32
|
+
output_variable = OpenStudio::Model::EnergyManagementSystemOutputVariable.new(@model, variable)
|
33
|
+
output_variable.setUnits(unit)
|
34
|
+
Output.new(output_variable)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create External Interface Variable
|
38
|
+
#
|
39
|
+
# @param [String] name Name of external variable to create
|
40
|
+
# @param [Number] initial_value Initial value of external variable
|
41
|
+
#
|
42
|
+
# @return [Input]
|
43
|
+
def create_external_variable(name, initial_value = 0)
|
44
|
+
external_variable = OpenStudio::Model::ExternalInterfaceVariable.new(@model, create_ems_str(name),
|
45
|
+
initial_value)
|
46
|
+
external_variable.setExportToBCVTB(false)
|
47
|
+
Input.new(external_variable)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create enabled input to actuate an EMS variable.
|
51
|
+
# This method creates an external variable with the specified name
|
52
|
+
# and an EMS program to copy the value to the specified variable if enabled
|
53
|
+
# or the default value otherwise
|
54
|
+
#
|
55
|
+
# @param [String] name Name of input to create
|
56
|
+
# @param [String] variable_name EMS name of variable to control
|
57
|
+
# @param [String] default Value to have when not enabled. Default to null for actuator control
|
58
|
+
#
|
59
|
+
# @return [Input]
|
60
|
+
def create_enabled_input(name, variable_name, default = 'Null')
|
61
|
+
alfalfa_input = create_external_variable(name)
|
62
|
+
enable_name = create_ems_str("#{name}_Enable")
|
63
|
+
alfalfa_input_enable = create_external_variable(enable_name)
|
64
|
+
new_program = OpenStudio::Model::EnergyManagementSystemProgram.new(@model)
|
65
|
+
new_program.setLines(["IF #{enable_name},",
|
66
|
+
"SET #{variable_name} = #{name},",
|
67
|
+
'ELSE,',
|
68
|
+
"SET #{variable_name} = #{default},",
|
69
|
+
'ENDIF'])
|
70
|
+
register_program(new_program)
|
71
|
+
alfalfa_input.enable_variable = alfalfa_input_enable
|
72
|
+
alfalfa_input
|
73
|
+
end
|
74
|
+
|
75
|
+
# Create actuator
|
76
|
+
#
|
77
|
+
# @param name [String] Name of actuator to create
|
78
|
+
# @param component [ModelObject] component to actuate
|
79
|
+
# @param component_type[String] Type of component
|
80
|
+
# @param control_type [String] Type of control
|
81
|
+
# @param external [Boolean] When true an external interface variable with {name} will be created and returned
|
82
|
+
#
|
83
|
+
# @return [ModelObject, Input]
|
84
|
+
def create_actuator(name, component, component_type, control_type, external = false)
|
85
|
+
if external
|
86
|
+
actuator_name = create_ems_str("#{name}_actuator")
|
87
|
+
actuator_object = create_actuator(actuator_name, component, component_type, control_type)
|
88
|
+
input = create_enabled_input(name, actuator_name)
|
89
|
+
input.actuator = actuator_object
|
90
|
+
output = create_ems_output_variable(actuator_object)
|
91
|
+
input.echo = output
|
92
|
+
input
|
93
|
+
else
|
94
|
+
OpenStudio::Model::EnergyManagementSystemActuator.new(component, component_type, control_type)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def create_calling_point
|
99
|
+
@calling_point_manager = OpenStudio::Model::EnergyManagementSystemProgramCallingManager.new(@model)
|
100
|
+
@calling_point_manager.setCallingPoint('EndOfZoneTimestepBeforeZoneReporting')
|
101
|
+
end
|
102
|
+
|
103
|
+
def register_program(program)
|
104
|
+
create_calling_point if @calling_point_manager.nil?
|
105
|
+
@calling_point_manager.addProgram(program)
|
106
|
+
end
|
107
|
+
|
108
|
+
def run(model, runner, user_arguments)
|
109
|
+
super(model, runner, user_arguments)
|
110
|
+
@model = model
|
111
|
+
@calling_point_manager = nil
|
112
|
+
@inputs = []
|
113
|
+
@outputs = []
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/output.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'openstudio'
|
3
|
+
require_relative 'utils'
|
4
|
+
require_relative 'point'
|
5
|
+
module OpenStudio
|
6
|
+
module Alfalfa
|
7
|
+
##
|
8
|
+
# Output
|
9
|
+
#
|
10
|
+
# Class which represents an Output point to Alfalfa
|
11
|
+
class Output < Point
|
12
|
+
include OpenStudio::Alfalfa::Utils
|
13
|
+
def initialize(output_object)
|
14
|
+
super(output_object)
|
15
|
+
output_type = get_idd_type(@object)
|
16
|
+
|
17
|
+
case output_type
|
18
|
+
when 'Output:Variable'.to_IddObjectType
|
19
|
+
@hash['component'] = @object.getString(0).get
|
20
|
+
@hash['variable'] = @object.getString(1).get
|
21
|
+
when 'EnergyManagementSystem:OutputVariable'.to_IddObjectType
|
22
|
+
@hash['component'] = 'EMS'
|
23
|
+
self.display_name = @object.name.get
|
24
|
+
@hash['variable'] = @object.getString(0).get
|
25
|
+
self.units = @object.getString(5).get
|
26
|
+
when 'OS:Output:Variable'.to_IddObjectType
|
27
|
+
@hash['component'] = @object.keyValue
|
28
|
+
@hash['variable'] = @object.variableName
|
29
|
+
self.display_name = @object.name.get
|
30
|
+
when 'OS:EnergyManagementSystem:OutputVariable'.to_IddObjectType
|
31
|
+
@hash['component'] = 'EMS'
|
32
|
+
@hash['variable'] = @object.name.get
|
33
|
+
self.display_name = @object.name.get
|
34
|
+
else
|
35
|
+
raise "#{output_type.valueDescription} is not a valid output type"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def component
|
40
|
+
@hash['component']
|
41
|
+
end
|
42
|
+
|
43
|
+
def variable
|
44
|
+
@hash['variable']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/point.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
module OpenStudio
|
3
|
+
module Alfalfa
|
4
|
+
##
|
5
|
+
# Point
|
6
|
+
# Base type for input and output point in alfalfa
|
7
|
+
class Point
|
8
|
+
attr_reader :echo, :object
|
9
|
+
|
10
|
+
# @param [IdfObject, ModelObject] object
|
11
|
+
def initialize(object)
|
12
|
+
@hash = {}
|
13
|
+
@hash['id'] = SecureRandom.uuid
|
14
|
+
@object = object
|
15
|
+
end
|
16
|
+
|
17
|
+
# Unique identifier of point
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def id
|
21
|
+
@hash['id']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Display name used by Alfalfa
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def display_name
|
28
|
+
@hash['display_name']
|
29
|
+
end
|
30
|
+
|
31
|
+
def display_name=(display_name)
|
32
|
+
@hash['display_name'] = display_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def echo=(output)
|
36
|
+
@echo = output
|
37
|
+
@hash['echo_id'] = output.id
|
38
|
+
end
|
39
|
+
|
40
|
+
def units=(units)
|
41
|
+
@hash['units'] = units
|
42
|
+
end
|
43
|
+
|
44
|
+
# Units for point
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
def units
|
48
|
+
@hash['units']
|
49
|
+
end
|
50
|
+
|
51
|
+
# Add zone that point is related to
|
52
|
+
#
|
53
|
+
# @param zone [String]
|
54
|
+
def add_zone(zone)
|
55
|
+
if @hash.key? 'zone'
|
56
|
+
@hash['zone'].append(zone)
|
57
|
+
else
|
58
|
+
@hash['zone'] = [zone]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get dictionary of point
|
63
|
+
# This is used when compiling reports
|
64
|
+
#
|
65
|
+
# @return [Hash]
|
66
|
+
def to_dict
|
67
|
+
@hash
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'openstudio'
|
2
|
+
module OpenStudio
|
3
|
+
module Alfalfa
|
4
|
+
##
|
5
|
+
# This module provides utility functions
|
6
|
+
# for alfalfa and openstudio
|
7
|
+
module Utils
|
8
|
+
# Get Idd Type
|
9
|
+
# get the Idd type of objects in either an OSW of IDF context
|
10
|
+
#
|
11
|
+
# @param [ModelObject, IdfObject] object Object to get type of
|
12
|
+
#
|
13
|
+
# @return [IddType]
|
14
|
+
def get_idd_type(object)
|
15
|
+
if object.is_a? OpenStudio::Model::ModelObject
|
16
|
+
object.iddObjectType
|
17
|
+
elsif object.is_a? OpenStudio::IdfObject
|
18
|
+
object.iddObject.type
|
19
|
+
else
|
20
|
+
raise "cannot get idd_type of #{object.class}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# return string formatted with no spaces or '-' (can be used as EMS var name)
|
25
|
+
# strings beginning with numbers will be prepended with '_'
|
26
|
+
# @param [String] id String to process into an EMS valid string
|
27
|
+
#
|
28
|
+
# @return [String]
|
29
|
+
def create_ems_str(id)
|
30
|
+
id = id.gsub(/[\s-]/, '_')
|
31
|
+
id = "_#{id}" if (id =~ /[0-9].*/) == 0
|
32
|
+
id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alfalfa-lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Shapinsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Library and measures to create input and output points in Alfalfa
|
14
|
+
email:
|
15
|
+
- tobias.shapinsky@nrel.gov
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/alfalfa.rb
|
21
|
+
- lib/alfalfa_mixin.rb
|
22
|
+
- lib/energy_plus_mixin.rb
|
23
|
+
- lib/input.rb
|
24
|
+
- lib/openstudio_mixin.rb
|
25
|
+
- lib/output.rb
|
26
|
+
- lib/point.rb
|
27
|
+
- lib/utils.rb
|
28
|
+
- lib/version.rb
|
29
|
+
homepage: https://github.com/NREL/alfalfa
|
30
|
+
licenses: []
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.0
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.1.4
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Create input and output points in Aflalfa
|
51
|
+
test_files: []
|