Skip to content

Commit

Permalink
Find epw path from model weather file, update E+ version
Browse files Browse the repository at this point in the history
  • Loading branch information
eringold committed Jul 21, 2015
1 parent 07be0f6 commit 2cbafa7
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions HardSizeHVACEquipment/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@

# start the measure
class HardSizeHVACEquipment < OpenStudio::Ruleset::ModelUserScript

# define the name that a user will see, this method may be deprecated as
# the display name in PAT comes from the name field in measure.xml
def name
return "HardSizeHVACEquipment"
end

# define the arguments that the user will input
def arguments(model)
args = OpenStudio::Ruleset::OSArgumentVector.new

return args
end #end the arguments method

# define what happens when the measure is run
def run(model, runner, user_arguments)
super(model, runner, user_arguments)
# use the built-in error checking

# use the built-in error checking
if not runner.validateUserArguments(arguments(model), user_arguments)
return false
end

# make a copy of the model and set up for sizing run
sizing_model = model

# report the sizing factors being used
siz_params = model.getSimulationControl.sizingParameters
if siz_params.is_initialized
Expand All @@ -46,34 +46,56 @@ def run(model, runner, user_arguments)
end
runner.registerInfo("The heating sizing factor for the model is #{siz_params.heatingSizingFactor}. 90.1 Appendix G requires 1.25.")
runner.registerInfo("The cooling sizing factor for the model is #{siz_params.coolingSizingFactor}. 90.1 Appendix G requires 1.15.")

# set the simulation to only run the sizing
sim_control = sizing_model.getSimulationControl
sim_control.setRunSimulationforSizingPeriods(true)
sim_control.setRunSimulationforWeatherFileRunPeriods(false)

# save the model to energyplus idf
idf_directory = Dir.pwd
idf_name = "sizing.idf"
runner.registerInfo("Saving sizing idf to #{idf_directory} as '#{idf_name}'")
forward_translator = OpenStudio::EnergyPlus::ForwardTranslator.new()
workspace = forward_translator.translateModel(sizing_model)
idf_path = OpenStudio::Path.new("#{idf_directory}/#{idf_name}")
idf_path = OpenStudio::Path.new("#{idf_directory}/#{idf_name}")
workspace.save(idf_path,true)

# set up to run the sizing simulation
require 'openstudio/energyplus/find_energyplus'
epw_path = OpenStudio::Path.new("#{Dir.pwd}/in.epw")
if not File.file?("#{epw_path}")
epw_path = OpenStudio::Path.new("#{Dir.pwd}/../in.epw")
epw_path = nil
if model.weatherFile.is_initialized
epw_path = model.weatherFile.get.path
if epw_path.is_initialized
if File.exist?(epw_path.get.to_s)
epw_path = epw_path.get
else
# If this is an always-run Measure, need to check a different path
alt_weath_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../resources"))
alt_epw_path = File.expand_path(File.join(alt_weath_path, epw_path.get.to_s))
if File.exist?(alt_epw_path)
epw_path = OpenStudio::Path.new(alt_epw_path)
else
OpenStudio::logFree(OpenStudio::Error, "openstudio.model.Model", "Model has been assigned a weather file, but the file is not in the specified location of '#{epw_path.get}'.")
return false
end
end
else
OpenStudio::logFree(OpenStudio::Error, "openstudio.model.Model", "Model has a weather file assigned, but the weather file path has been deleted.")
return false
end
else
OpenStudio::logFree(OpenStudio::Error, 'openstudio.model.Model', 'Model has not been assigned a weather file.')
return false
end

# find energyplus
ep_hash = OpenStudio::EnergyPlus::find_energyplus(8,0)
# find_energyplus is deprecated, won't use the OS-packaged install
ep_hash = OpenStudio::EnergyPlus::find_energyplus(8,3)
ep_path = OpenStudio::Path.new(ep_hash[:energyplus_exe].to_s)
idd_path = OpenStudio::Path.new(ep_hash[:energyplus_idd].to_s)
weather_path = OpenStudio::Path.new(ep_hash[:energyplus_weatherdata].to_s)

# make a run manager
run_manager_db_path = OpenStudio::Path.new("#{idf_directory}/sizing_run.db")
run_manager = OpenStudio::Runmanager::RunManager.new(run_manager_db_path, true)
Expand All @@ -86,14 +108,14 @@ def run(model, runner, user_arguments)
# get the run manager configuration options
config_options = run_manager.getConfigOptions()
output_path = OpenStudio::Path.new("#{idf_directory}/")

# make a job for the file we want to run
job = OpenStudio::Runmanager::JobFactory::createEnergyPlusJob(ep_tool,
idd_path,
idf_path,
epw_path,
output_path)

# put the job in the run queue
run_manager.enqueue(job, true)

Expand All @@ -103,18 +125,18 @@ def run(model, runner, user_arguments)
OpenStudio::Application::instance().processEvents()
end
runner.registerInfo("Finished sizing run.")

# load the sql file, exiting and erroring if a problem is found
sql_path = OpenStudio::Path.new("#{idf_directory}/Energyplus/eplusout.sql")
if OpenStudio::exists(sql_path)
sql = OpenStudio::SqlFile.new(sql_path)
# attach the sql file from the run to the sizing model
attach_sql = model.setSqlFile(sql)
else
else
runner.registerError("#{sql_path} couldn't be found")
return false
end

# load the helper libraries
@resource_path = "#{File.dirname(__FILE__)}/resources"
require "#{@resource_path}/Model.rb"
Expand All @@ -138,24 +160,25 @@ def run(model, runner, user_arguments)
require "#{@resource_path}/ChillerElectricEIR.rb"
require "#{@resource_path}/CoolingTowerSingleSpeed.rb"
require "#{@resource_path}/ControllerWaterCoil.rb"

require "#{@resource_path}/ZoneHVACLowTempRadiantVarFlow.rb"

# hard size the HVAC equipment
apply_sizes_success = model.applySizingValues
if apply_sizes_success
runner.registerInfo("Successfully applied component sizing values.")
else
runner.registerInfo("Failed to apply component sizing values.")
end

# set the simulation back to running the weather file
sim_control.setRunSimulationforSizingPeriods(false)
sim_control.setRunSimulationforWeatherFileRunPeriods(true)

return true

end #end the run method

end #end the measure

#this allows the measure to be use by the application
HardSizeHVACEquipment.new.registerWithApplication
HardSizeHVACEquipment.new.registerWithApplication

0 comments on commit 2cbafa7

Please sign in to comment.