# ******************************************************************************* # OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC. # See also https://openstudio.net/license # ******************************************************************************* # start the measure class CoilCoolingWaterPercentChange < OpenStudio::Measure::ModelMeasure # human readable name def name 'Cooling Coils Water PercentChange' end # human readable description def description 'This is a general purpose measure to calibrate Water Cooling Coils with a PercentChange.' end # human readable description of modeling approach def modeler_description 'It will be used for calibration of inlet water temperatures, inlet and outlet air temperatures and design flowrates. User can choose between a SINGLE coil or ALL the Coils.' end def change_name(object, design_water_flow_rate, design_air_flow_rate, design_inlet_water_temperature, design_inlet_air_temperature, design_outlet_air_temperature, design_inlet_air_humidity_ratio) nameString = object.name.get.to_s if design_water_flow_rate != 1.0 nameString += " #{design_water_flow_rate.round(2)} percng waterDFR" end if design_air_flow_rate != 1.0 nameString += " #{design_air_flow_rate.round(2)}percng airDFR" end if design_inlet_water_temperature != 1.0 nameString += " #{design_inlet_water_temperature.round(2)}percng DIWT" end if design_inlet_air_temperature != 1.0 nameString += " #{design_inlet_air_temperature.round(2)}percng DIAT" end if design_outlet_air_temperature != 1.0 nameString += " #{design_outlet_air_temperature.round(2)}percng DOAT" end if design_inlet_air_humidity_ratio != 1.0 nameString += " #{design_inlet_air_humidity_ratio.round(2)}percng DIAHR" end object.setName(nameString) end # define the arguments that the user will input def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new # populate choice argument for constructions that are applied to surfaces in the model loop_handles = OpenStudio::StringVector.new loop_display_names = OpenStudio::StringVector.new # putting air loops and names into hash loop_args = model.getAirLoopHVACs loop_args_hash = {} loop_args.each do |loop_arg| loop_args_hash[loop_arg.name.to_s] = loop_arg end # looping through sorted hash of air loops loop_args_hash.sort.map do |_key, value| show_loop = false components = value.supplyComponents components.each do |component| next if component.to_CoilCoolingWater.empty? show_loop = true loop_handles << component.handle.to_s loop_display_names << component.name.to_s end # if loop as object of correct type then add to hash. # if show_loop == true # loop_handles << value.handle.to_s # loop_display_names << key # end end # add building to string vector with space type building = model.getBuilding loop_handles << building.handle.to_s loop_display_names << '*All Water Cooling Coils*' loop_handles << '0' loop_display_names << '*None*' # make a choice argument for space type coil_arg = OpenStudio::Measure::OSArgument.makeChoiceArgument('coil', loop_handles, loop_display_names) coil_arg.setDisplayName('Apply the Measure to a SINGLE Water Cooling Coil, ALL the Water Cooling Coils or NONE.') coil_arg.setDefaultValue('*All Water Cooling Coils*') # if no space type is chosen this will run on the entire building args << coil_arg # design_water_flow_rate design_water_flow_rate = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_water_flow_rate', true) design_water_flow_rate.setDisplayName('PercentChange for Design Water Flow Rate.') design_water_flow_rate.setDescription('PercentChange for Design Water Flow Rate.') design_water_flow_rate.setDefaultValue(0.0) args << design_water_flow_rate # design_air_flow_rate design_air_flow_rate = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_air_flow_rate', true) design_air_flow_rate.setDisplayName('PercentChange for Design Air Flow Rate.') design_air_flow_rate.setDescription('PercentChange for Design Air Flow Rate.') design_air_flow_rate.setDefaultValue(0.0) args << design_air_flow_rate # design_inlet_water_temperature design_inlet_water_temperature = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_inlet_water_temperature', true) design_inlet_water_temperature.setDisplayName('PercentChange for Inlet Water Temperature.') design_inlet_water_temperature.setDescription('PercentChange for Inlet Water Temperature.') design_inlet_water_temperature.setDefaultValue(0.0) args << design_inlet_water_temperature # design_inlet_air_temperature design_inlet_air_temperature = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_inlet_air_temperature', true) design_inlet_air_temperature.setDisplayName('PercentChange for Inlet Air Temperature.') design_inlet_air_temperature.setDescription('PercentChange for Inlet Air Temperature.') design_inlet_air_temperature.setDefaultValue(0.0) args << design_inlet_air_temperature # design_outlet_air_temperature design_outlet_air_temperature = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_outlet_air_temperature', true) design_outlet_air_temperature.setDisplayName('PercentChange for Outlet Air Temperature.') design_outlet_air_temperature.setDescription('PercentChange for Outlet Air Temperature.') design_outlet_air_temperature.setDefaultValue(0.0) args << design_outlet_air_temperature # design_inlet_air_humidity_ratio design_inlet_air_humidity_ratio = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_inlet_air_humidity_ratio', true) design_inlet_air_humidity_ratio.setDisplayName('PercentChange for Inlet Air Humidity Ratio.') design_inlet_air_humidity_ratio.setDescription('PercentChange for Inlet Air Humidity Ratio.') design_inlet_air_humidity_ratio.setDefaultValue(0.0) args << design_inlet_air_humidity_ratio args end # 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 unless runner.validateUserArguments(arguments(model), user_arguments) return false end # assign the user inputs to variables coil_object = runner.getOptionalWorkspaceObjectChoiceValue('coil', user_arguments, model) coil_handle = runner.getStringArgumentValue('coil', user_arguments) design_air_flow_rate = runner.getDoubleArgumentValue('design_air_flow_rate', user_arguments) design_water_flow_rate = runner.getDoubleArgumentValue('design_water_flow_rate', user_arguments) design_inlet_air_temperature = runner.getDoubleArgumentValue('design_inlet_air_temperature', user_arguments) design_outlet_air_temperature = runner.getDoubleArgumentValue('design_outlet_air_temperature', user_arguments) design_inlet_air_humidity_ratio = runner.getDoubleArgumentValue('design_inlet_air_humidity_ratio', user_arguments) design_inlet_water_temperature = runner.getDoubleArgumentValue('design_inlet_water_temperature', user_arguments) # find objects to change coils = [] building = model.getBuilding building_handle = building.handle.to_s runner.registerInfo("coil_handle: #{coil_handle}") # setup coils if coil_handle == building_handle # Use ALL coils runner.registerInfo('Applying change to ALL Coils') loops = model.getAirLoopHVACs # loop through air loops loops.each do |loop| supply_components = loop.supplyComponents # find coils on loops supply_components.each do |supply_component| unless supply_component.to_CoilCoolingWater.empty? coils << supply_component.to_CoilCoolingWater.get end end end elsif coil_handle == 0.to_s # coils set to NONE so do nothing runner.registerInfo('Applying change to NONE Coils') elsif !coil_handle.empty? # Single coil handle found, check if object is good if !coil_object.get.to_CoilCoolingWater.empty? runner.registerInfo("Applying change to #{coil_object.get.name} coil") coils << coil_object.get.to_CoilCoolingWater.get else runner.registerError("coil with handle #{coil_handle} could not be found.") end else runner.registerError('coil handle is empty.') return false end # report initial condition of model runner.registerInitialCondition("Coils to change: #{coils.size}") runner.registerInfo("Coils to change: #{coils.size}") altered_coils = [] altered_capacity = [] altered_coilefficiency = [] # loop through coils coils.each do |coil| altered_coil = false # design_air_flow_rate if design_air_flow_rate != 1.0 && coil.designAirFlowRate.is_initialized runner.registerInfo("Applying designAirFlowRate #{design_air_flow_rate} PercentChange to #{coil.name.get}.") coil.setDesignAirFlowRate(coil.designAirFlowRate.get + coil.designAirFlowRate.get * design_air_flow_rate * 0.01) altered_capacity << coil.handle.to_s altered_coil = true end # modify design_water_flow_rate if design_water_flow_rate != 1.0 && coil.designWaterFlowRate.is_initialized runner.registerInfo("Applying designWaterFlowRate #{design_water_flow_rate} PercentChange to #{coil.name.get}.") coil.setDesignWaterFlowRate(coil.designWaterFlowRate.get + coil.designWaterFlowRate.get * design_water_flow_rate * 0.01) altered_coilefficiency << coil.handle.to_s altered_coil = true end # design_inlet_air_temperature if design_inlet_air_temperature != 1.0 && coil.designInletAirTemperature.is_initialized runner.registerInfo("Applying designInletAirTemperature #{design_inlet_air_temperature} PercentChange to #{coil.name.get}.") coil.setDesignInletAirTemperature(coil.designInletAirTemperature.get + coil.designInletAirTemperature.get * design_inlet_air_temperature * 0.01) altered_capacity << coil.handle.to_s altered_coil = true end # modify design_inlet_water_temperature if design_inlet_water_temperature != 1.0 && coil.designInletWaterTemperature.is_initialized runner.registerInfo("Applying designInletWaterTemperature #{design_inlet_water_temperature} PercentChange to #{coil.name.get}.") coil.setDesignInletWaterTemperature(coil.designInletWaterTemperature.get + coil.designInletWaterTemperature.get * design_inlet_water_temperature * 0.01) altered_coilefficiency << coil.handle.to_s altered_coil = true end # design_inlet_air_humidity_ratio if design_inlet_air_humidity_ratio != 1.0 && coil.designInletAirHumidityRatio.is_initialized runner.registerInfo("Applying designInletAirHumidityRatio #{design_inlet_air_humidity_ratio} PercentChange to #{coil.name.get}.") coil.setDesignInletAirHumidityRatio(coil.designInletAirHumidityRatio.get + coil.designInletAirHumidityRatio.get * design_inlet_air_humidity_ratio * 0.01) altered_capacity << coil.handle.to_s altered_coil = true end # modify design_outlet_air_temperature if design_outlet_air_temperature != 1.0 && coil.designOutletAirTemperature.is_initialized runner.registerInfo("Applying designOutletAirTemperature #{design_outlet_air_temperature} PercentChange to #{coil.name.get}.") coil.setDesignOutletAirTemperature(coil.designOutletAirTemperature.get + coil.designOutletAirTemperature.get * design_outlet_air_temperature * 0.01) altered_coilefficiency << coil.handle.to_s altered_coil = true end next unless altered_coil altered_coils << coil.handle.to_s change_name(coil, design_water_flow_rate, design_air_flow_rate, design_inlet_water_temperature, design_inlet_air_temperature, design_outlet_air_temperature, design_inlet_air_humidity_ratio) runner.registerInfo("coil name changed to: #{coil.name.get}") end # na if nothing in model to look at if altered_coils.empty? runner.registerAsNotApplicable('No Coils were altered in the model') return true end # report final condition of model runner.registerFinalCondition("#{altered_coils.size} Coils objects were altered.") true end end # register the measure to be used by the application CoilCoolingWaterPercentChange.new.registerWithApplication