3

Run ExpandObjects Programmatically in Ruby

I have been trying to run a reporting script through a web interface to output the electricity and gas heating usages. In my model I am setting the HVAC systems to Ideal Air Loads. I discovered though that for EnergyPlus to execute properly, ExpandObjects program has to be run on the model first in order to accept the HVACTemplate objects from the ideal air loads. The code I am working with is shown below. This is the 'setup_test' routine and I am struggling to find any documentation or ways to run the ExpandObjects program in Ruby. Thanks for the help!

 @@co = OpenStudio::Runmanager::ConfigOptions.new(true)
def Reporting_Lib.setup_test(test_name, idf_output_requests,model_name,location)
    @@co.findTools(false, true, false, true)

if !File.exist?(Reporting_Lib.run_dir(test_name))
  FileUtils.mkdir_p(Reporting_Lib.run_dir(test_name))
end

if File.exist?(Reporting_Lib.run_dir(test_name)) == false then return false end

if File.exist?(Reporting_Lib.report_path(test_name))
  FileUtils.rm(Reporting_Lib.report_path(test_name))
end
if File.exist?(Reporting_Lib.model_in_path(model_name)) == false then return false end

if File.exist?(Reporting_Lib.model_out_path(test_name))
  FileUtils.rm(Reporting_Lib.model_out_path(test_name))
end

# convert output requests to OSM for testing, OS App and PAT will add these to the E+ Idf 
workspace = OpenStudio::Workspace.new("Draft".to_StrictnessLevel, "EnergyPlus".to_IddFileType)
workspace.addObjects(idf_output_requests)
rt = OpenStudio::EnergyPlus::ReverseTranslator.new
request_model = rt.translateWorkspace(workspace)

model = OpenStudio::Model::Model.load(Reporting_Lib.model_in_path(model_name)).get
model.addObjects(request_model.objects)
model.save(Reporting_Lib.model_out_path(test_name), true)

puts "Running EnergyPlus"
wf = OpenStudio::Runmanager::Workflow.new("modeltoidf->energypluspreprocess->energyplus")
# puts wf
wf.add(@@co.getTools())
# puts wf.add(@@co.getTools())
job = wf.create(OpenStudio::Path.new(Reporting_Lib.run_dir(test_name)), OpenStudio::Path.new(Reporting_Lib.model_out_path(test_name)), OpenStudio::Path.new(Reporting_Lib.epw_path(location)))

rm = OpenStudio::Runmanager::RunManager.new

rm.enqueue(job, true)
rm.waitForFinished


end
Alex Bennett's avatar
327
Alex Bennett
asked 2016-04-29 09:30:41 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2016-04-29 09:53:20 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

2

Try changing your workflow to this:

wf = OpenStudio::Runmanager::Workflow.new("modeltoidf->expandobjects->energypluspreprocess->energyplus")
macumber's avatar
12k
macumber
answered 2016-04-29 09:35:34 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks! That worked perfectly.

Alex Bennett's avatar Alex Bennett (2016-04-29 10:09:27 -0500) edit
add a comment see more comments