53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/openstudio/workflow/jobs/run_initialization.rb', line 53
def perform
@logger.info "Calling #{__method__} in the #{self.class} class"
@logger.debug 'Registering that the workflow has started with the adapter'
@output_adapter.communicate_started
@registry.register(:workflow) { @input_adapter.workflow }
raise 'Specified workflow was nil' unless @registry[:workflow]
@logger.debug 'Retrieved the workflow from the adapter'
@registry.register(:osw_dir) { @input_adapter.osw_dir }
@logger.debug "osw_dir is #{@registry[:osw_dir]}"
@registry.register(:datapoint) { @input_adapter.datapoint }
@logger.debug 'Found associated OSD file' if @registry[:datapoint]
@registry.register(:analysis) { @input_adapter.analysis }
@logger.debug 'Found associated OSA file' if @registry[:analysis]
if @registry[:openstudio_2]
workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(@registry[:workflow]))
workflow_json.setOswDir(@registry[:osw_dir])
else
workflow_json = WorkflowJSON_Shim.new(@registry[:workflow], @registry[:osw_dir])
end
@registry.register(:workflow_json) { workflow_json }
@registry.register(:root_dir) { workflow_json.absoluteRootDir }
@logger.debug "The root_dir for the datapoint is #{@registry[:root_dir]}"
generated_files_dir = "#{@registry[:root_dir]}/generated_files"
if File.exist?(generated_files_dir)
@logger.debug "Removing existing generated files directory: #{generated_files_dir}"
FileUtils.rm_rf(generated_files_dir)
end
@logger.debug "Creating generated files directory: #{generated_files_dir}"
FileUtils.mkdir_p(generated_files_dir)
file_paths = @registry[:workflow_json].filePaths
@registry[:workflow_json].resetFilePaths
@registry[:workflow_json].addFilePath(generated_files_dir)
file_paths.each do |file_path|
@registry[:workflow_json].addFilePath(file_path)
end
reports_dir = "#{@registry[:root_dir]}/reports"
if File.exist?(reports_dir)
@logger.debug "Removing existing reports directory: #{reports_dir}"
FileUtils.rm_rf(reports_dir)
end
@registry.register(:runner) { WorkflowRunner.new(@registry[:logger], @registry[:workflow_json], @registry[:openstudio_2]) }
@registry[:runner].setDatapoint(@registry[:datapoint])
@registry[:runner].setAnalysis(@registry[:analysis])
@logger.debug 'Initialized runner'
if @options[:verify_osw]
@logger.info 'Attempting to validate the measure workflow'
validate_measures(@registry, @logger)
@logger.info 'Validated the measure workflow'
end
@logger.debug 'Finding and loading the seed file'
model_path = workflow_json.seedFile
if !model_path.empty?
model_full_path = workflow_json.findFile(model_path.get)
if model_full_path.empty?
raise "Seed model #{model_path.get} specified in OSW cannot be found"
end
model_full_path = model_full_path.get
if File.extname(model_full_path.to_s) == '.idf'
@registry.register(:model_idf) { load_idf(model_full_path, @logger) }
@registry.register(:model) { nil }
else
@registry.register(:model) { load_osm(model_full_path, @logger) }
end
else
@registry.register(:model) { OpenStudio::Model::Model.new }
begin
OpenStudio::Model.initializeModelObjects(@registry[:model])
rescue NameError
@registry[:model].getBuilding
@registry[:model].getFacility
@registry[:model].getSimulationControl
@registry[:model].getSizingParameters
@registry[:model].getTimestep
@registry[:model].getShadowCalculation
@registry[:model].getHeatBalanceAlgorithm
@registry[:model].getRunPeriod
@registry[:model].getLifeCycleCostParameters
end
end
if @registry[:openstudio_2]
@registry[:model]&.setWorkflowJSON(workflow_json.clone)
end
@logger.debug 'Getting the initial weather file'
weather_path = workflow_json.weatherFile
if weather_path.empty?
@logger.debug 'No weather file specified in OSW, looking in model'
if @registry[:model]
model = @registry[:model]
unless model.weatherFile.empty?
weather_path = model.weatherFile.get.path
end
end
end
unless weather_path.empty?
weather_path = weather_path.get
@logger.debug 'Searching for weather file #{weather_path}'
weather_full_path = workflow_json.findFile(weather_path)
if weather_full_path.empty?
weather_full_path = workflow_json.findFile(File.basename(weather_path.to_s))
end
if weather_full_path.empty?
raise "Weather file '#{weather_path}' specified but cannot be found"
end
weather_full_path = weather_full_path.get
@registry.register(:wf) { weather_full_path.to_s }
end
@logger.warn 'No valid weather file defined in either the osm or osw.' unless @registry[:wf]
workflow_json.start
nil
end
|