10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/openstudio-standards/standards/necb/common/btap_datapoint.rb', line 10
def initialize(input_folder: nil,
output_folder: nil,
weather_folder: nil,
input_folder_cache: File.join(__dir__, 'input_cache'))
@failed = false
if input_folder.nil?
input_folder = File.join(__dir__, 'input')
end
if output_folder.nil?
output_folder = File.join(__dir__, 'output')
end
if weather_folder.nil?
weather_folder = File.join(__dir__, 'weather')
end
puts("INPUT FOLDER:#{input_folder}")
puts("OUTPUT FOLDER:#{output_folder}")
@dp_input_folder = File.join(input_folder)
@dp_temp_folder = File.join(__dir__, 'temp_folder')
FileUtils.rm_rf(@dp_temp_folder)
FileUtils.mkdir_p(@dp_temp_folder)
FileUtils.rm_rf(input_folder_cache)
FileUtils.mkdir_p(input_folder_cache)
if @dp_input_folder.start_with?('s3:')
m = @dp_input_folder.match(%r{s3://(.*?)/(.*)})
puts(m)
puts(m[1])
puts(m[2])
@s3_bucket = m[1]
@s3_input_folder_object = m[2]
m = output_folder.match(%r{s3://(.*?)/(.*)})
puts(m)
puts(m[1])
puts(m[2])
@s3_output_folder_object = m[2]
puts("s3_bucket:#{@s3_bucket}")
puts("s3_input_folder_object:#{@s3_input_folder_object}")
puts("s3_output_folder_object:#{@s3_output_folder_object}")
s3_copy(source_folder: @dp_input_folder, target_folder: input_folder_cache)
else
raise("input folder dne:#{@dp_input_folder}") unless Dir.exist?(@dp_input_folder)
puts @dp_input_folder
puts input_folder_cache
FileUtils.cp_r(File.join(@dp_input_folder, '.'), input_folder_cache)
end
run_options_path = File.join(input_folder_cache, 'run_options.yml')
raise("Could not read input from #{run_options_path}") unless File.file?(run_options_path)
@options = YAML.load_file(run_options_path)
@dp_output_folder = File.join(output_folder, @options[:datapoint_id])
@options[:btap_costing_git_revision] = Git::Revision.commit_short
@options[:os_git_revision] = OpenstudioStandards.git_revision
@npv_start_year = @options[:npv_start_year]
@npv_end_year = @options[:npv_end_year]
@npv_discount_rate = @options[:npv_discount_rate]
File.open(File.join(@dp_temp_folder, 'run_options.yml'), 'w') { |file| file.write(@options.to_yaml) }
begin
@options[:template] = 'NECB2011' if @options[:algorithm_type] == 'osm_batch'
@standard = Standard.build(@options[:template])
model = @standard.load_building_type_from_library(building_type: @options[:building_type])
if false == model
osm_model_path = File.absolute_path(File.join(input_folder_cache, @options[:building_type] + '.osm'))
raise("File #{osm_model_path} not found") unless File.exist?(osm_model_path)
model = BTAP::FileIO.load_osm(osm_model_path)
end
if @options[:algorithm_type] == 'osm_batch'
@standard.set_output_variables(model: model, output_variables: @options[:output_variables])
@standard.set_output_meters(model: model, output_meters: @options[:output_meters])
climate_zone = 'NECB HDD Method'
model.getYearDescription.setDayofWeekforStartDay('Sunday')
epw_file = @options[:epw_file]
epw_dir = nil
local_epw_file_path = File.join(input_folder_cache,@options[:epw_file])
epw_dir = input_folder_cache if File.exist? local_epw_file_path
weather_file_path = OpenstudioStandards::Weather.get_standards_weather_file_path(epw_file)
OpenstudioStandards::Weather.model_set_building_location(model, weather_file_path: weather_file_path)
else
@standard.model_apply_standard(model: model,
epw_file: @options[:epw_file],
custom_weather_folder: weather_folder,
sizing_run_dir: File.join(@dp_temp_folder, 'sizing_folder'),
primary_heating_fuel: @options[:primary_heating_fuel],
necb_reference_hp: @options[:necb_reference_hp],
necb_reference_hp_supp_fuel: @options[:necb_reference_hp_supp_fuel],
dcv_type: @options[:dcv_type], lights_type: @options[:lights_type], lights_scale: @options[:lights_scale],
daylighting_type: @options[:daylighting_type], ecm_system_name: @options[:ecm_system_name],
ecm_system_zones_map_option: @options[:ecm_system_zones_map_option], erv_package: @options[:erv_package],
boiler_eff: @options[:boiler_eff],
unitary_cop: @options[:adv_dx_units],
furnace_eff: @options[:furnace_eff],
shw_eff: @options[:shw_eff],
ext_wall_cond: @options[:ext_wall_cond],
ext_floor_cond: @options[:ext_floor_cond],
ext_roof_cond: @options[:ext_roof_cond],
ground_wall_cond: @options[:ground_wall_cond],
ground_floor_cond: @options[:ground_floor_cond],
ground_roof_cond: @options[:ground_roof_cond],
door_construction_cond: @options[:door_construction_cond],
fixed_window_cond: @options[:fixed_window_cond],
glass_door_cond: @options[:glass_door_cond],
overhead_door_cond: @options[:overhead_door_cond],
skylight_cond: @options[:skylight_cond],
glass_door_solar_trans: @options[:glass_door_solar_trans],
fixed_wind_solar_trans: @options[:fixed_wind_solar_trans],
skylight_solar_trans: @options[:skylight_solar_trans],
fdwr_set: @options[:fdwr_set],
srr_set: @options[:srr_set],
rotation_degrees: @options[:rotation_degrees],
scale_x: @options[:scale_x],
scale_y: @options[:scale_y],
scale_z: @options[:scale_z],
pv_ground_type: @options[:pv_ground_type],
pv_ground_total_area_pv_panels_m2: @options[:pv_ground_total_area_pv_panels_m2],
pv_ground_tilt_angle: @options[:pv_ground_tilt_angle],
pv_ground_azimuth_angle: @options[:pv_ground_azimuth_angle],
pv_ground_module_description: @options[:pv_ground_module_description],
nv_type: @options[:nv_type],
nv_opening_fraction: @options[:nv_opening_fraction],
nv_temp_out_min: @options[:nv_temp_out_min],
nv_delta_temp_in_out: @options[:nv_delta_temp_in_out],
occupancy_loads_scale: @options[:occupancy_loads_scale],
electrical_loads_scale: @options[:electrical_loads_scale],
oa_scale: @options[:oa_scale],
infiltration_scale: @options[:infiltration_scale],
chiller_type: @options[:chiller_type],
output_variables: @options[:output_variables],
output_meters: @options[:output_meters],
airloop_economizer_type: @options[:airloop_economizer_type],
shw_scale: @options[:shw_scale],
baseline_system_zones_map_option: @options[:baseline_system_zones_map_option],
tbd_option: @options[:tbd_option],
necb_hdd: @options[:necb_hdd],
boiler_fuel: @options[:boiler_fuel],
boiler_cap_ratio: @options[:boiler_cap_ratio]
)
end
puts "saving model to #{File.join(@dp_temp_folder, 'output.osm')}"
BTAP::FileIO.save_osm(model, File.join(@dp_temp_folder, 'output.osm'))
if @options[:run_annual_simulation]
@run_dir = File.join(@dp_temp_folder, 'run_dir')
puts "running simulation in #{@run_dir}"
@standard.model_run_simulation_and_log_errors(model, @run_dir)
raise('no sql file found,simulation probably could not start due to error...see error logs.') if model.sqlFile.empty?
@qaqc = @standard.init_qaqc(model)
command = "SELECT Value
FROM TabularDataWithStrings
WHERE ReportName='LEEDsummary'
AND ReportForString='Entire Facility'
AND TableName='Sec1.1A-General Information'
AND RowName = 'Principal Heating Source'
AND ColumnName='Data'"
value = model.sqlFile.get.execAndReturnFirstString(command)
@qaqc[:building][:principal_heating_source] = 'unknown'
unless value.empty?
@qaqc[:building][:principal_heating_source] = value.get
end
if @qaqc[:building][:principal_heating_source] == 'Additional Fuel'
model.getPlantLoops.sort.each do |iplantloop|
boilers = iplantloop.components.select { |icomponent| icomponent.to_BoilerHotWater.is_initialized }
@qaqc[:building][:principal_heating_source] = 'FuelOilNo2' unless boilers.select { |boiler| boiler.to_BoilerHotWater.get.fuelType.to_s == 'FuelOilNo2' }.empty?
end
end
@qaqc[:aws_datapoint_id] = @options[:datapoint_id]
@qaqc[:aws_analysis_id] = @options[:analysis_id]
sql_path = OpenStudio::Path.new(File.join(@run_dir, 'run/eplusout.sql'))
raise(OpenStudio::Error, 'openstudio.model.Model', "Results for the sizing run couldn't be found here: #{sql_path}.") unless OpenStudio.exists(sql_path)
sql = OpenStudio::SqlFile.new(sql_path)
unless sql.connectionOpen
raise(OpenStudio::Error, 'openstudio.model.Model', "The run failed. Look at the eplusout.err file in #{File.dirname(sql_path.to_s)} to see the cause.")
return false
end
model.setSqlFile(sql)
@cost_result = nil
if defined?(BTAPCosting)
costing = BTAPCosting.new
costing.load_database
@cost_result, @btap_items = costing.cost_audit_all(model: model, prototype_creator: @standard, template_type: @options[:template])
@qaqc[:costing_information] = @cost_result
File.open(File.join(@dp_temp_folder, 'cost_results.json'), 'w') { |f| f.write(JSON.pretty_generate(@cost_result, allow_nan: true)) }
puts "Wrote File cost_results.json in #{Dir.pwd} "
end
@qaqc[:options] = @options @btap_data = BTAPData.new(model: model,
runner: nil,
cost_result: @cost_result,
qaqc: @qaqc,
npv_start_year: @npv_start_year,
npv_end_year: @npv_end_year,
npv_discount_rate: @npv_discount_rate).btap_data
File.open(File.join(@dp_temp_folder, 'btap_data.json'), 'w') { |f| f.write(JSON.pretty_generate(@btap_data.sort.to_h, allow_nan: true)) }
puts "Wrote File btap_data.json in #{Dir.pwd} "
File.open(File.join(@dp_temp_folder, 'qaqc.json'), 'w') { |f| f.write(JSON.pretty_generate(@qaqc, allow_nan: true)) }
puts "Wrote File qaqc.json in #{Dir.pwd} "
self.output_hourly_data(model,@dp_temp_folder, @options[:datapoint_id])
end
rescue StandardError => bang
puts "Error occured: #{bang}"
@bang = bang
File.open(File.join(@dp_temp_folder, 'error.txt'), 'w') { |f| f.write(@bang.message + "\n" + @bang.backtrace.join("\n")) }
@failed = true
ensure if @dp_output_folder.start_with?('s3://')
@dp_output_folder = File.join(@s3_output_folder_object, @options[:datapoint_id])
s3_copy_folder_to_s3(bucket_name: @s3_bucket,
source_folder: @dp_temp_folder,
target_folder: @dp_output_folder)
else
@dp_output_folder = File.join(output_folder, @options[:datapoint_id])
FileUtils.rm_rf(@dp_output_folder)
FileUtils.mkdir_p(@dp_output_folder)
FileUtils.cp_r(File.join(@dp_temp_folder, '.'), @dp_output_folder) puts "Copied output to your designated output folder in the #{@options[:datapoint_id]} subfolder."
end
FileUtils.rm_rf(input_folder_cache)
FileUtils.rm_rf(@dp_temp_folder)
if @failed == true
raise(@bang)
end
end
end
|