Skip to content

Commit

Permalink
Revert measures hash not supporting lists of arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Sep 23, 2024
1 parent 50dc076 commit b45a5f5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
6 changes: 3 additions & 3 deletions HPXMLtoOpenStudio/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>hpxm_lto_openstudio</name>
<uid>b1543b30-9465-45ff-ba04-1d1f85e763bc</uid>
<version_id>bb8b4288-764a-4aca-b5d6-3868995bfc2e</version_id>
<version_modified>2024-09-23T15:30:48Z</version_modified>
<version_id>16ffde52-4759-4a36-ba81-24c76b6b00d8</version_id>
<version_modified>2024-09-23T15:54:34Z</version_modified>
<xml_checksum>D8922A73</xml_checksum>
<class_name>HPXMLtoOpenStudio</class_name>
<display_name>HPXML to OpenStudio Translator</display_name>
Expand Down Expand Up @@ -429,7 +429,7 @@
<filename>meta_measure.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>0B3512F7</checksum>
<checksum>59BD5891</checksum>
</file>
<file>
<filename>minitest_helper.rb</filename>
Expand Down
40 changes: 21 additions & 19 deletions HPXMLtoOpenStudio/resources/meta_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Again, report any log messages to file.
#
# @param rundir [String] The run directory containing all simulation output files
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => Hash of measure arguments
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => List of measure argument hashes
# @param measures_dir [String] Parent directory path of all OpenStudio-HPXML measures
# @param debug [Boolean] If true, reports info statements from the runner results
# @param run_measures_only [Boolean] True applies only OpenStudio Model measures, skipping forward transation and the simulation
Expand Down Expand Up @@ -173,7 +173,7 @@ def run_hpxml_workflow(rundir, measures, measures_dir, debug: false,
# Optionally, save an OpenStudio Workflow based on the provided Hash.
#
# @param measures_dir [String] Parent directory path of all OpenStudio-HPXML measures
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => Hash of measure arguments
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => List of measure argument hashes
# @param runner [OpenStudio::Measure::OSRunner] Object typically used to display warnings
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param show_measure_calls [Boolean] Whether to print the measure name and arguments
Expand Down Expand Up @@ -209,16 +209,17 @@ def apply_measures(measures_dir, measures, runner, model, show_measure_calls = t
full_measure_path = File.join(measures_dir, measure_subdir, 'measure.rb')
check_file_exists(full_measure_path, runner)
measure = get_measure_instance(full_measure_path)
args = measures[measure_subdir]
next unless measure_type == measure.class.superclass.name.to_s
measures[measure_subdir].each do |args|
next unless measure_type == measure.class.superclass.name.to_s

argument_map = get_argument_map(model, measure, args, measure_subdir, runner)
if show_measure_calls
print_measure_call(args, measure_subdir, runner)
end
argument_map = get_argument_map(model, measure, args, measure_subdir, runner)
if show_measure_calls
print_measure_call(args, measure_subdir, runner)
end

if not run_measure(model, measure, argument_map, runner)
return false
if not run_measure(model, measure, argument_map, runner)
return false
end
end
end

Expand All @@ -228,7 +229,7 @@ def apply_measures(measures_dir, measures, runner, model, show_measure_calls = t
# Apply OpenStudio measures and arguments (i.e., "energyPlusOutputRequests" method) corresponding to a provided Hash.
#
# @param measures_dir [String] Parent directory path of all OpenStudio-HPXML measures
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => Hash of measure arguments
# @param measures [Hash] Map of OpenStudio-HPXML measure directory name => List of measure argument hashes
# @param runner [OpenStudio::Measure::OSRunner] Object typically used to display warnings
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param workspace [OpenStudio::Workspace] EnergyPlus Workspace object
Expand All @@ -240,14 +241,15 @@ def apply_energyplus_output_requests(measures_dir, measures, runner, model, work
full_measure_path = File.join(measures_dir, measure_subdir, 'measure.rb')
check_file_exists(full_measure_path, runner)
measure = get_measure_instance(full_measure_path)
args = measures[measure_subdir]
next unless measure.class.superclass.name.to_s == 'OpenStudio::Measure::ReportingMeasure'

argument_map = get_argument_map(model, measure, args, measure_subdir, runner)
runner.setLastOpenStudioModel(model)
idf_objects = measure.energyPlusOutputRequests(runner, argument_map)
idf_objects.each do |idf_object|
workspace.addObject(idf_object)
measures[measure_subdir].each do |args|
next unless measure.class.superclass.name.to_s == 'OpenStudio::Measure::ReportingMeasure'

argument_map = get_argument_map(model, measure, args, measure_subdir, runner)
runner.setLastOpenStudioModel(model)
idf_objects = measure.energyPlusOutputRequests(runner, argument_map)
idf_objects.each do |idf_object|
workspace.addObject(idf_object)
end
end
end

Expand Down
15 changes: 8 additions & 7 deletions tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_hpxmls
json_input.delete('parent_hpxml')

measures = {}
measures['BuildResidentialHPXML'] = json_input
measures['BuildResidentialHPXML'] = [json_input]

measures_dir = File.dirname(__FILE__)
model = OpenStudio::Model::Model.new
Expand All @@ -61,13 +61,14 @@ def create_hpxmls
end

for i in 1..num_apply_measures
measures['BuildResidentialHPXML']['existing_hpxml_path'] = hpxml_path if i > 1
build_residential_hpxml = measures['BuildResidentialHPXML'][0]
build_residential_hpxml['existing_hpxml_path'] = hpxml_path if i > 1
if hpxml_path.include?('base-bldgtype-mf-whole-building.xml')
suffix = "_#{i}" if i > 1
measures['BuildResidentialHPXML']['schedules_filepaths'] = "../../HPXMLtoOpenStudio/resources/schedule_files/occupancy-stochastic#{suffix}.csv"
measures['BuildResidentialHPXML']['geometry_foundation_type'] = (i <= 2 ? 'UnconditionedBasement' : 'AboveApartment')
measures['BuildResidentialHPXML']['geometry_attic_type'] = (i >= 5 ? 'VentedAttic' : 'BelowApartment')
measures['BuildResidentialHPXML']['geometry_unit_height_above_grade'] = { 1 => 0.0, 2 => 0.0, 3 => 10.0, 4 => 10.0, 5 => 20.0, 6 => 20.0 }[i]
build_residential_hpxml['schedules_filepaths'] = "../../HPXMLtoOpenStudio/resources/schedule_files/occupancy-stochastic#{suffix}.csv"
build_residential_hpxml['geometry_foundation_type'] = (i <= 2 ? 'UnconditionedBasement' : 'AboveApartment')
build_residential_hpxml['geometry_attic_type'] = (i >= 5 ? 'VentedAttic' : 'BelowApartment')
build_residential_hpxml['geometry_unit_height_above_grade'] = { 1 => 0.0, 2 => 0.0, 3 => 10.0, 4 => 10.0, 5 => 20.0, 6 => 20.0 }[i]
end

# Re-generate stochastic schedule CSV?
Expand All @@ -77,7 +78,7 @@ def create_hpxmls
'output_csv_path' => csv_path,
'hpxml_output_path' => hpxml_path,
'building_id' => "MyBuilding#{suffix}" }
measures['BuildResidentialScheduleFile'] = sch_args
measures['BuildResidentialScheduleFile'] = [sch_args]
schedules_regenerated << csv_path
end

Expand Down
9 changes: 5 additions & 4 deletions workflow/run_simulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_workflow(basedir, rundir, hpxml, debug, skip_validation, add_comp_loads,
args['output_csv_path'] = File.join(rundir, 'stochastic.csv')
args['debug'] = debug
args['building_id'] = building_id
measures[measure_subdir] = args
measures[measure_subdir] = [args]
end

# Add HPXML translator measure to workflow
Expand All @@ -45,7 +45,7 @@ def run_workflow(basedir, rundir, hpxml, debug, skip_validation, add_comp_loads,
args['skip_validation'] = skip_validation
args['building_id'] = building_id
args['debug'] = debug
measures[measure_subdir] = args
measures[measure_subdir] = [args]

if not skip_simulation
n_timeseries_freqs = [hourly_outputs, daily_outputs, monthly_outputs, timestep_outputs].map { |o| !o.empty? }.count(true)
Expand Down Expand Up @@ -91,14 +91,15 @@ def run_workflow(basedir, rundir, hpxml, debug, skip_validation, add_comp_loads,
# Need to use different timeseries filenames
args['timeseries_output_file_name'] = "results_timeseries_#{timeseries_output_freq}.#{output_format}"
end
measures[measure_subdir] = args
measures[measure_subdir] = [] if not measures.has_key?(measure_subdir)
measures[measure_subdir] << args
end

# Add utility bills measure to workflow
measure_subdir = 'ReportUtilityBills'
args = {}
args['output_format'] = (output_format == 'csv_dview' ? 'csv' : output_format)
measures[measure_subdir] = args
measures[measure_subdir] = [args]
end

results = run_hpxml_workflow(rundir, measures, measures_dir, debug: debug, ep_input_format: ep_input_format, run_measures_only: skip_simulation)
Expand Down

0 comments on commit b45a5f5

Please sign in to comment.