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

Revision history [back]

click to hide/show revision 1
initial version

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

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