First time here? Check out the Help page!
1 | initial version |
@David, I'm getting closer (at least, I hope so :) ) but I still have some problems with my E+ measure :
Could you help me? :)
Here is my code :
Thank you very much for your help
# see the URL below for information on how to write OpenStudio measures
# http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
# start the measure
class ChangeTheRoomType < OpenStudio::Ruleset::WorkspaceUserScript
# human readable name
def name
return "ChangeTheRoomType"
end
# human readable description
def description
return "Take stratification into account"
end
# human readable description of modeling approach
def modeler_description
return "By changing the room type to constant gradient (vertical)"
end
def arguments(workspace)
args = OpenStudio::Ruleset::OSArgumentVector.new
#----------------------THERMAL ZONE INTO ARGUMENTS------------------------------------------
#populate choice argument for thermal zones in the model
zone_handles = OpenStudio::StringVector.new
zone_display_names = OpenStudio::StringVector.new
#putting zone names into hash
zone_hash = {}
workspace.getObjectsByType("Zone".to_IddObjectType) do |zone|
zone_hash[zone.name.to_s] = zone
end
#looping through sorted hash of zones
zone_hash.sort.map do |zone_name, zone|
zone_handles << zone.handle.to_s
zone_display_names << zone_name
end
#make an argument for zones
zone = OpenStudio::Ruleset::OSArgument::makeChoiceArgument("zone", zone_handles, zone_display_names, true)
zone.setDisplayName("Choose Thermal Zones to add zone ventilation to.")
args << zone
#----------------------------NAME ARGUMENT------------------------------------------
nameRoomAirModel = OpenStudio::Ruleset::OSArgument::makeStringArgument('nameRoomAirModel', true)
nameRoomAirModel.setDisplayName('Name the pattern')
args << nameRoomAirModel
#-------------------------------TEMPERATURE INPUT INTO ARGUMENTS -------------------------------
thermOffset = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('thermOffset',true)
thermOffset.setDisplayName('thermostat Offset')
thermOffset.setDefaultValue(0.0)
args << thermOffset
returnAirOffset = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('returnAirOffset',true)
returnAirOffset.setDisplayName('return Air Offset')
returnAirOffset.setDefaultValue(0.0)
args<<returnAirOffset
exhaustAirOffset = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('exhaustAirOffset',true)
exhaustAirOffset.setDisplayName('exhaust Air Offset')
exhaustAirOffset.setDefaultValue(0.0)
args << exhaustAirOffset
return args
end
#When the measure is run
def run(workspace,runner,user_arguments)
super(workspace, runner, user_arguments)
# errors management
if not runner.validateUserArguments(argumentents(workspace),user_arguments)
return false
end
#assign to variables
nameRoomAirModel=runner.getStringArgumentValue('nameRoomAirModel',user_arguments)
zone=runner.getOptionalWorkspaceObjectChoiceValue('zone',user_arguments, workspace)
thermOffset=runner.getDoubleArgumentValue('thermOffset', user_arguments)
returnAirOffset=runner.getDoubleArgumentValue('returnAirOffset',user_arguments)
exhaustAirOffset=runner.getDoubleArgumentValue('exhaustAirOffset',user_arguments)
#Array to hold new IDF Objects = RoomAirModelType here
string_RoomAirModelType=[]
#this instruction doesnt use the arguments, it s a test
string_RoomAirModelType << "
RoomAir:TemperaturePattern:UserDefined,
#{nameRoomAirModel} , ! Name
#{zone} , ! Zone Name (thermal zone) = user choice
AllwaysOn, ! Availability Schedule Name = integer used need to be the same as the RoomAir:TemperaturePattern:ConstantGradient (here is 1)
Roomair Pattern 1; ! Pattern Control Schedule Name"
#Instruction in EP
string_RoomAirModelGradient=[]
#this instruction doesnt use the arguments, it s a test
string_RoomAirModelGradient << "
RoomAir:TemperaturePattern:ConstantGradient,
StratProduction, !- Name
1, !- Control Integer for Pattern Control Schedule Name
#{thermOffset}, !- Thermostat Offset {deltaC}
#{returnAirOffset} , !- Return Air Offset {deltaC}
#{exhaustAirOffset} , !- Exhaust Air Offset {deltaC}
0.5; !- Temperature Gradient {K/m}"
#add all of the strings to workspace to create IDF objects
idfObject = OpenStudio::IdfObject::load(string_RoomAirModelType)
object = idfObject.get
wsObject1 = workspace.addObject(object)
new_object = wsObject.get
runner.registerInfo("An object named '#{new_object.getString(0)}' was added.")
idfObject = OpenStudio::IdfObject::load(string_RoomAirModelGradient)
object = idfObject.get
wsObject = workspace.addObject(object)
new_object = wsObject.get
runner.registerInfo("An object named '#{new_object.getString(0)}' was added.")
return true
end
end
# register the measure to be used by the application
ChangeTheRoomType.new.registerWithApplication