Changing a constant speed pump to a variable speed pump with an OpenStudio/PAT measure
I'm trying to put together a measure that will switch a selected Constant Speed Pump to a Variable Speed Pump (VFD). I'm still learning how these are written, but I have the skeleton of the script together. The actual pump replacement process has been a struggle. As far as I can see, the PumpConstantSpeed and PumpVariableSpeed classes and their associated functions only manage the values of their respective attributes, but have no way of adding or removing the overall pump objects.
I've tried using .remove() on the current constant speed pump and then creating a new variable speed pump with OpenStudio::Model::PumpVariableSpeed.new(model), but can't seem to find a way to connect the new pump object to the rest of the system (or substitute it in place of the previous one).
I've also tried breaking up the pump object with .split() and manually substituting in the Handle, Input Node, and Output Node of the previous pump, but I again can't seem to find a way to push this information back into the model to complete the replacement. Does the Connection class offer any potential solutions?
The script is available here, with some commented blocks of failed attempts at solutions: http://tmp.idlboise.com/os/cstovfd.txt
It should work with "Apply Measure Now" in OpenStudio on any model that has an OS:Pump:ConstantSpeed object.
Here is the def run() snippet of the variable speed pump set-up:
def run(model, runner, user_arguments)
super(model, runner, user_arguments)
#use the built-in error checking
if not runner.validateUserArguments(arguments(model), user_arguments)
return false
end
#assign the user inputs to variables
pumps = runner.getOptionalWorkspaceObjectChoiceValue("pumps",user_arguments,model)
if pumps.empty?
runner.registerError("PumpConstantSpeed not found...")
return false
end
pump_rtdflow = runner.getDoubleArgumentValue("pump_rtdflow",user_arguments)
pump_rtdpump = runner.getIntegerArgumentValue("pump_rtdpump",user_arguments)
pump_rtdpwr = runner.getIntegerArgumentValue("pump_rtdpwr",user_arguments)
pump_motor = runner.getDoubleArgumentValue("pump_motor",user_arguments)
pump_frac = runner.getDoubleArgumentValue("pump_frac",user_arguments)
pump_coeff1 = runner.getDoubleArgumentValue("pump_coeff1",user_arguments)
pump_coeff2 = runner.getDoubleArgumentValue("pump_coeff2",user_arguments)
pump_coeff3 = runner.getDoubleArgumentValue("pump_coeff3",user_arguments)
pump_coeff4 = runner.getDoubleArgumentValue("pump_coeff4",user_arguments)
pump_ctrl_type_widget = runner.getOptionalWorkspaceObjectChoiceValue("pump_ctrl_type_widget",user_arguments,model)
cost = runner.getDoubleArgumentValue("material_cost",user_arguments)
selected_pump = nil
if pumps.empty?
handle = runner.getStringArgumentValue("pumps",user_arguments)
if handle.empty?
runner.registerError("No pump was chosen.")
return false
else
runner.registerError("The selected pump with handle '#{handle}' was not found in the model. It may have been removed by another measure.")
return false
end
else
selected_pump = pumps.get.to_PumpConstantSpeed.get
runner.registerInfo("Current pump: #{selected_pump}")
new_pump = OpenStudio::Model::PumpVariableSpeed.new(model)
new_pump.setName("VFD Pump")
new_pump.setRatedFlowRate(pump_rtdflow)
new_pump.setRatedPumpHead(pump_rtdpump)
new_pump.setRatedPowerConsumption(pump_rtdpwr)
new_pump.setMotorEfficiency(pump_motor)
new_pump.setFractionofMotorInefficienciestoFluidStream(pump_frac)
new_pump.setCoefficient1ofthePartLoadPerformanceCurve(pump_coeff1)
new_pump.setCoefficient2ofthePartLoadPerformanceCurve(pump_coeff2)
new_pump.setCoefficient3ofthePartLoadPerformanceCurve(pump_coeff3)
new_pump.setCoefficient4ofthePartLoadPerformanceCurve(pump_coeff4)
new_pump.setPumpControlType("#{pump_ctrl_type_widget}")
runner.registerInfo("New pump: #{new_pump}")
end #end of if pumps.empty?
return true
end