Class: OpenStudio::Analysis::Formulation
- Inherits:
-
Object
- Object
- OpenStudio::Analysis::Formulation
- Defined in:
- lib/openstudio/analysis/formulation.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#analysis_type ⇒ Object
Returns the value of attribute analysis_type.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#seed_model(path) ⇒ Object
readonly
Path to the seed model.
-
#weather_file(path) ⇒ Object
readonly
Path to the weather file (or folder).
-
#workflow ⇒ Object
Initialize or return the current workflow object.
Instance Method Summary collapse
-
#add_output(output_hash) ⇒ Object
Add an output of interest to the problem formulation.
-
#initialize(display_name) ⇒ Object
constructor
Create an instance of the OpenStudio::Analysis::Formulation.
-
#save(filename, version = 1) ⇒ Boolean
save the file to JSON.
-
#save_static_data_point(filename, version = 1) ⇒ Boolean
save the data point JSON with the variables set to the static values.
-
#to_hash(version = 1) ⇒ Hash
return a hash.
-
#to_static_data_point_hash(version = 1) ⇒ Hash
return a hash of the data point with the static variables set.
Constructor Details
#initialize(display_name) ⇒ Object
Create an instance of the OpenStudio::Analysis::Formulation
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/openstudio/analysis/formulation.rb', line 20 def initialize(display_name) @display_name = display_name @analysis_type = nil @outputs = [] # Initialize child objects (expect workflow) @weather_file = WeatherFile.new @seed_model = SeedModel.new @algorithm = OpenStudio::Analysis::AlgorithmAttributes.new end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
12 13 14 |
# File 'lib/openstudio/analysis/formulation.rb', line 12 def algorithm @algorithm end |
#analysis_type ⇒ Object
Returns the value of attribute analysis_type.
14 15 16 |
# File 'lib/openstudio/analysis/formulation.rb', line 14 def analysis_type @analysis_type end |
#display_name ⇒ Object
Returns the value of attribute display_name.
10 11 12 |
# File 'lib/openstudio/analysis/formulation.rb', line 10 def display_name @display_name end |
#seed_model(path) ⇒ Object (readonly)
Path to the seed model
46 47 48 |
# File 'lib/openstudio/analysis/formulation.rb', line 46 def seed_model @seed_model end |
#weather_file(path) ⇒ Object (readonly)
Path to the weather file (or folder). If it is a folder, then the measures will look for the weather file by name in that folder.
54 55 56 |
# File 'lib/openstudio/analysis/formulation.rb', line 54 def weather_file @weather_file end |
#workflow ⇒ Object
Initialize or return the current workflow object
34 35 36 |
# File 'lib/openstudio/analysis/formulation.rb', line 34 def workflow @workflow end |
Instance Method Details
#add_output(output_hash) ⇒ Object
Add an output of interest to the problem formulation
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/openstudio/analysis/formulation.rb', line 74 def add_output(output_hash) output_hash = { units: '', objective_function: false, objective_function_index: nil, objective_function_target: nil, objective_function_group: nil, scaling_factor: nil }.merge(output_hash) # if the objective_function index is nil and the variable is an objective function, then increment and # assign and objective function index unless output_hash[:objective_function_index] values = @outputs.map { |o| o[:objective_function_index] } output_hash[:objective_function_index] = values.empty? ? 0 : values.max + 1 end @outputs << output_hash end |
#save(filename, version = 1) ⇒ Boolean
save the file to JSON. Will overwrite the file if it already exists
157 158 159 160 161 |
# File 'lib/openstudio/analysis/formulation.rb', line 157 def save(filename, version = 1) File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_hash(version)) } true end |
#save_static_data_point(filename, version = 1) ⇒ Boolean
save the data point JSON with the variables set to the static values. Will overwrite the file if it already exists
167 168 169 170 171 |
# File 'lib/openstudio/analysis/formulation.rb', line 167 def save_static_data_point(filename, version = 1) File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_static_data_point_hash(version)) } true end |
#to_hash(version = 1) ⇒ Hash
return a hash.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/openstudio/analysis/formulation.rb', line 98 def to_hash(version = 1) # fail 'Must define an analysis type' unless @analysis_type if version == 1 h = { analysis: { display_name: @display_name, name: @display_name.snake_case, output_variables: @outputs, problem: { analysis_type: @analysis_type, algorithm: algorithm.to_hash(version), workflow: workflow.to_hash(version) }, seed: @seed_model[:path], weather_file: @weather_file[:path], file_format_version: version } } # This is a hack right now, but after the initial hash is created go back and add in the objective functions # to the the algorithm as defined in the output_variables list ofs = @outputs.map { |i| i[:name] if i[:objective_function] }.compact if h[:analysis][:problem][:algorithm] h[:analysis][:problem][:algorithm][:objective_functions] = ofs end h else fail "Version #{version} not defined for #{self.class} and #{__method__}" end end |
#to_static_data_point_hash(version = 1) ⇒ Hash
return a hash of the data point with the static variables set
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/openstudio/analysis/formulation.rb', line 134 def to_static_data_point_hash(version = 1) if version == 1 static_hash = {} # TODO: this method should be on the workflow step and bubbled up to this interface @workflow.items.map do |item| item.variables.map { |v| static_hash[v[:uuid]] = v[:static_value] } end h = { data_point: { set_variable_values: static_hash, status: 'na', uuid: SecureRandom.uuid } } h end end |