Class: BTAPWorkflow

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/btap/costing/btap_workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(measures_folder: File.join(__dir__, '../../measures')) ⇒ BTAPWorkflow



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 6

def initialize(measures_folder: File.join(__dir__, '../../measures'))
  @model = nil
  @run_dir = nil
  @sql_path = nil
  @idf_name = 'in.idf'
  @osm_name = 'in.osm'
  @osw_name = 'out.osw'
  @epw_path = 'in.epw'
  @workflow = OpenStudio::WorkflowJSON.new
  @workflow.addMeasurePath(measures_folder)
  @run_cli_verbose = true
  @os_measures = []
  @ep_measures = []
  @report_measures = []
end

Instance Attribute Details

#workflowObject

Returns the value of attribute workflow.



4
5
6
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 4

def workflow
  @workflow
end

Instance Method Details

#add_btap_create_necb_prototype_building_measure(building_type:, epw_file:, template:, primary_heating_fuel:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 59

def add_btap_create_necb_prototype_building_measure(building_type:, epw_file:, template:, primary_heating_fuel:)
  os_measure_type = OpenStudio::MeasureType.new("ModelMeasure")
  create_prototype_measure = OpenStudio::MeasureStep.new("btap_create_necb_prototype_building")
  create_prototype_measure.setName("btap_create_necb_prototype_building")
  create_prototype_measure.setArgument('building_type', building_type)
  create_prototype_measure.setArgument('epw_file', epw_file)
  create_prototype_measure.setArgument('template', template)
  create_prototype_measure.setArgument('primary_heating_fuel', primary_heating_fuel)
  @os_measures << create_prototype_measure
end

#add_btap_results_measureObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 71

def add_btap_results_measure
  reporting_measure_type = OpenStudio::MeasureType.new("ReportingMeasure")
  btap_results = OpenStudio::MeasureStep.new("btap_results")
  btap_results.setName("btap_results")
  btap_results.setArgument('generate_hourly_report', 'false')
  btap_results.setArgument('output_diet', false)
  btap_results.setArgument('envelope_costing', true)
  btap_results.setArgument('lighting_costing', true)
  btap_results.setArgument('boilers_costing', true)
  btap_results.setArgument('chillers_costing', true)
  btap_results.setArgument('cooling_towers_costing', true)
  btap_results.setArgument('shw_costing', true)
  btap_results.setArgument('ventilation_costing', true)
  btap_results.setArgument('zone_system_costing', true)
  @report_measures << btap_results
end

#add_ep_measure(measure) ⇒ Object



33
34
35
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 33

def add_ep_measure(measure)
  @ep_measures << measure
end

#add_measures_to_workflowObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 42

def add_measures_to_workflow
  unless @os_measures.empty?
    measure_type = OpenStudio::MeasureType.new("ModelMeasure")
    @workflow.setMeasureSteps(measure_type, @os_measures)
  end
  unless @ep_measures.empty?
    measure_type = OpenStudio::MeasureType.new("EnergyPlusMeasure")
    @workflow.setMeasureSteps(measure_type, @ep_measures)
  end
  unless @report_measures.empty?
    measure_type = OpenStudio::MeasureType.new("ReportingMeasure")
    @workflow.setMeasureSteps(measure_type, @report_measures)
  end
  @workflow
  return self
end

#add_os_measure(measure) ⇒ Object



29
30
31
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 29

def add_os_measure(measure)
  @os_measures << measure
end

#add_reporting_measure(measure) ⇒ Object



37
38
39
40
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 37

def add_reporting_measure(measure)
  @report_measures << measure
  return self
end

#run_command(command:) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 89

def run_command(command:)
  stdout_str, stderr_str, status = Open3.capture3({}, command)
  if status.success?
    puts "Command completed successfully"
    puts "stdout: #{stdout_str}"
    puts "stderr: #{stderr_str}"
    return true
  else
    puts "Error running command: '#{command}'"
    puts "stdout: #{stdout_str}"
    puts "stderr: #{stderr_str}"
    return false
  end
end

#run_workflow(postprocess_only: nil, osw_path:) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 104

def run_workflow(postprocess_only: nil, osw_path:)
  #command to run workflow
  os_ruby_cli = "bundle exec ruby #{File.join(File.dirname(OpenStudio.getOpenStudioCLI.to_s), '..', 'Ruby', 'openstudio_cli.rb')}"
  extra_args = ' --postprocess_only ' if postprocess_only == true
  cmd = "#{os_ruby_cli} run #{extra_args} --debug --workflow \"#{osw_path}\""
  puts "running cli command: #{cmd}"
  OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "running cli command: #{cmd}")
  self.run_command(command: cmd)
  OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished cli run.')
  #Ensure items are written to disk.
  sleep 3
  return true
end

#set_run_dir(run_dir: "#{Dir.pwd}/Run") ⇒ Object



22
23
24
25
26
27
# File 'lib/openstudio-standards/btap/costing/btap_workflow.rb', line 22

def set_run_dir(run_dir: "#{Dir.pwd}/Run")
  puts "set run folder to #{run_dir}"
  @run_dir = run_dir
  @sql_path = OpenStudio::Path.new("#{@run_dir}/run/eplusout.sql")
  return self
end