Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
3

Run ExpandObjects Programmatically in Ruby

asked 2016-04-29 09:30:41 -0600

Alex Bennett's avatar

updated 2016-04-29 09:53:20 -0600

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-04-29 09:35:34 -0600

Try changing your workflow to this:

wf = OpenStudio::Runmanager::Workflow.new("modeltoidf->expandobjects->energypluspreprocess->energyplus")
edit flag offensive delete link more

Comments

Thanks! That worked perfectly.

Alex Bennett's avatar Alex Bennett  ( 2016-04-29 10:09:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

Stats

Asked: 2016-04-29 09:30:41 -0600

Seen: 155 times

Last updated: Apr 29 '16