Skip to content

Commit 32f6bcf

Browse files
committed
Adds --daily, --monthly, and --timestep switches to run_simulation.rb script.
1 parent 438e5f6 commit 32f6bcf

2 files changed

Lines changed: 63 additions & 20 deletions

File tree

workflow/run_simulation.rb

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
basedir = File.expand_path(File.dirname(__FILE__))
1212

13-
def run_workflow(basedir, rundir, hpxml, debug, hourly_outputs)
13+
def run_workflow(basedir, rundir, hpxml, debug, timeseries_output_freq, timeseries_outputs)
1414
measures_dir = File.join(basedir, '..')
1515

1616
measures = {}
@@ -26,23 +26,23 @@ def run_workflow(basedir, rundir, hpxml, debug, hourly_outputs)
2626
# Add reporting measure to workflow
2727
measure_subdir = 'SimulationOutputReport'
2828
args = {}
29-
args['timeseries_frequency'] = 'hourly'
30-
args['include_timeseries_fuel_consumptions'] = hourly_outputs.include? 'fuels'
31-
args['include_timeseries_end_use_consumptions'] = hourly_outputs.include? 'enduses'
32-
args['include_timeseries_hot_water_uses'] = hourly_outputs.include? 'hotwater'
33-
args['include_timeseries_total_loads'] = hourly_outputs.include? 'loads'
34-
args['include_timeseries_component_loads'] = hourly_outputs.include? 'componentloads'
35-
args['include_timeseries_zone_temperatures'] = hourly_outputs.include? 'temperatures'
36-
args['include_timeseries_airflows'] = hourly_outputs.include? 'airflows'
37-
args['include_timeseries_weather'] = hourly_outputs.include? 'weather'
29+
args['timeseries_frequency'] = timeseries_output_freq
30+
args['include_timeseries_fuel_consumptions'] = timeseries_outputs.include? 'fuels'
31+
args['include_timeseries_end_use_consumptions'] = timeseries_outputs.include? 'enduses'
32+
args['include_timeseries_hot_water_uses'] = timeseries_outputs.include? 'hotwater'
33+
args['include_timeseries_total_loads'] = timeseries_outputs.include? 'loads'
34+
args['include_timeseries_component_loads'] = timeseries_outputs.include? 'componentloads'
35+
args['include_timeseries_zone_temperatures'] = timeseries_outputs.include? 'temperatures'
36+
args['include_timeseries_airflows'] = timeseries_outputs.include? 'airflows'
37+
args['include_timeseries_weather'] = timeseries_outputs.include? 'weather'
3838
update_args_hash(measures, measure_subdir, args)
3939

4040
results = run_hpxml_workflow(rundir, hpxml, measures, measures_dir, debug: debug)
4141

4242
return results[:success]
4343
end
4444

45-
hourly_types = ['ALL', 'fuels', 'enduses', 'hotwater', 'loads', 'componentloads', 'temperatures', 'airflows', 'weather']
45+
timeseries_types = ['ALL', 'fuels', 'enduses', 'hotwater', 'loads', 'componentloads', 'temperatures', 'airflows', 'weather']
4646

4747
options = {}
4848
OptionParser.new do |opts|
@@ -57,10 +57,25 @@ def run_workflow(basedir, rundir, hpxml, debug, hourly_outputs)
5757
end
5858

5959
options[:hourly_outputs] = []
60-
opts.on('--hourly TYPE', hourly_types, "Request hourly output type (#{hourly_types[0..4].join(', ')},", "#{hourly_types[5..-1].join(', ')}); can be called multiple times") do |t|
60+
opts.on('--hourly TYPE', timeseries_types, "Request hourly output type (#{timeseries_types[0..4].join(', ')},", "#{timeseries_types[5..-1].join(', ')}); can be called multiple times") do |t|
6161
options[:hourly_outputs] << t
6262
end
6363

64+
options[:daily_outputs] = []
65+
opts.on('--daily TYPE', timeseries_types, "Request daily output type (#{timeseries_types[0..4].join(', ')},", "#{timeseries_types[5..-1].join(', ')}); can be called multiple times") do |t|
66+
options[:daily_outputs] << t
67+
end
68+
69+
options[:monthly_outputs] = []
70+
opts.on('--monthly TYPE', timeseries_types, "Request monthly output type (#{timeseries_types[0..4].join(', ')},", "#{timeseries_types[5..-1].join(', ')}); can be called multiple times") do |t|
71+
options[:monthly_outputs] << t
72+
end
73+
74+
options[:timestep_outputs] = []
75+
opts.on('--timestep TYPE', timeseries_types, "Request timestep output type (#{timeseries_types[0..4].join(', ')},", "#{timeseries_types[5..-1].join(', ')}); can be called multiple times") do |t|
76+
options[:timestep_outputs] << t
77+
end
78+
6479
options[:version] = false
6580
opts.on('-v', '--version', 'Reports the version') do |t|
6681
options[:version] = true
@@ -82,14 +97,42 @@ def run_workflow(basedir, rundir, hpxml, debug, hourly_outputs)
8297
exit!
8398
end
8499

85-
if options[:hourly_outputs].include? 'ALL'
86-
options[:hourly_outputs] = hourly_types[1..-1]
87-
end
88-
89100
if not options[:hpxml]
90101
fail "HPXML argument is required. Call #{File.basename(__FILE__)} -h for usage."
91102
end
92103

104+
timeseries_output_freq = 'none'
105+
timeseries_outputs = []
106+
n_freq = 0
107+
if not options[:hourly_outputs].empty?
108+
n_freq += 1
109+
timeseries_output_freq = 'hourly'
110+
timeseries_outputs = options[:hourly_outputs]
111+
end
112+
if not options[:daily_outputs].empty?
113+
n_freq += 1
114+
timeseries_output_freq = 'daily'
115+
timeseries_outputs = options[:daily_outputs]
116+
end
117+
if not options[:monthly_outputs].empty?
118+
n_freq += 1
119+
timeseries_output_freq = 'monthly'
120+
timeseries_outputs = options[:monthly_outputs]
121+
end
122+
if not options[:timestep_outputs].empty?
123+
n_freq += 1
124+
timeseries_output_freq = 'timestep'
125+
timeseries_outputs = options[:timestep_outputs]
126+
end
127+
128+
if n_freq > 1
129+
fail 'Multiple timeseries frequencies (hourly, daily, monthly, timestep) are not supported.'
130+
end
131+
132+
if timeseries_outputs.include? 'ALL'
133+
timeseries_outputs = timeseries_types[1..-1]
134+
end
135+
93136
unless (Pathname.new options[:hpxml]).absolute?
94137
options[:hpxml] = File.expand_path(options[:hpxml])
95138
end
@@ -111,7 +154,7 @@ def run_workflow(basedir, rundir, hpxml, debug, hourly_outputs)
111154

112155
# Run design
113156
puts "HPXML: #{options[:hpxml]}"
114-
success = run_workflow(basedir, rundir, options[:hpxml], options[:debug], options[:hourly_outputs])
157+
success = run_workflow(basedir, rundir, options[:hpxml], options[:debug], timeseries_output_freq, timeseries_outputs)
115158

116159
if success
117160
puts "Completed in #{(Time.now - start_time).round(1)} seconds."

workflow/tests/hpxml_translator_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def before_setup
2727
def test_simulations
2828
sample_files_dir = File.absolute_path(File.join(@this_dir, '..', 'sample_files'))
2929
autosize_dir = File.absolute_path(File.join(@this_dir, '..', 'sample_files', 'hvac_autosizing'))
30-
30+
3131
results_out = File.join(@results_dir, 'results.csv')
3232
File.delete(results_out) if File.exist? results_out
3333
sizing_out = File.join(@results_dir, 'results_hvac_sizing.csv')
@@ -57,7 +57,7 @@ def test_simulations
5757

5858
def test_ashrae_140
5959
ashrae140_dir = File.absolute_path(File.join(@this_dir, 'ASHRAE_Standard_140'))
60-
60+
6161
ashrae140_out = File.join(@results_dir, 'results_ashrae_140.csv')
6262
File.delete(ashrae140_out) if File.exist? ashrae140_out
6363

@@ -74,7 +74,7 @@ def test_ashrae_140
7474
all_results[xml], all_sizing_results[xml] = _run_xml(xml)
7575
end
7676

77-
_write_ashrae_140_results(all_results, ashrae140_dir)
77+
_write_ashrae_140_results(all_results, ashrae140_dir, ashrae140_out)
7878
end
7979

8080
def test_run_simulation_rb

0 commit comments

Comments
 (0)