Relief valve class

Relief valves are the last subclass of the Valve parent class, as demonstrated in the following code:

# valve.py (part 10)
1 class Relief(Valve): 2 """Pressure relieving valve. 3 4 Assumes full open when open set point reached and fully closed when close set point reached. Does not affect flow rate or system pressure; those parameters must be adjusted elsewhere. 5 """ 6 def __init__(self, name="", sys_flow_in=0.0, sys_flow_out=0.0, drop=0.0, position=0, flow_coeff=0.0, press_in=0.0, open_press=0, close_press=0): 7 """Inherits base initialization and adds valve open/close pressure values.""" 8 super(Relief, self).__init__(name, sys_flow_in, sys_flow_out, drop, position, flow_coeff, press_in) 9 self.setpoint_open = open_press 10 self.setpoint_close = close_press

Pressure valves have pressure setpoints, above which the valve will open and below which the valve will close. There's actually a small pressure range between initial lifting and being fully open, as well as when closing. For our purposes, we don't need to account for that and simply model the valve to be fully open/closed when the setpoints are reached.

The Relief subclass defines these setpoints during initialization. This method is unique, compared to the other classes: it includes a super() call. This call ensures that the parent class, Valve, is called for all standard parameters, while allowing Relief to add the new parameters setpoint_open and setpoint_close. Hence, we don't have to redefine all of the initial parameters just to add the two new ones.

The methods used for the relief valve, shown in the following two code blocks, are similar to what we've seen before, so we won't elaborate on them:

# valve.py (part 11)
1 def read_position(self): 2 """Identify the status of the valve.""" 3 if self.position == 0: 4 return "{name} is closed.".format(name=self.name) 5 elif self.position == 100: 6 return "{name} is open.".format(name=self.name) 7 else: # bad condition 8 return "Warning! {name} is partially open.".format(name=self.name) 9​ 10 def set_open_pressure(self, open_set): 11 """Set the pressure setpoint where the valve opens.""" 12 self.setpoint_open = open_set 13​ 14 def read_open_pressure(self): 15 """Read the high pressure setpoint.""" 16 return self.setpoint_open

The following code snippet is part 12 of valve.py:

# valve.py (part 12)
1 def read_close_pressure(self): 2 """Read the low pressure setpoint.""" 3 return self.setpoint_close 4 5 def set_close_press(self, close_set): 6 """Set the pressure setpoint where the valve closes.""" 7 self.setpoint_close = close_set 8 9 def valve_operation(self, press_in): 10 """Open the valve if pressure is too high; close the valve when pressure lowers.""" 11 if press_in >= self.setpoint_open: 12 self.open() 13 elif press_in <= self.setpoint_close: 14 self.close()

The following code shows the simple tests for the valve program, much like we've done before with the utility functions and tank program. They are broken up into three parts, with each one dedicated to testing a specific child class type:

# valve.py (part 13)
1 if __name__ == "__main__": 2 # Functional test_valves 3 # name="", sys_flow_in=0.0, position=0, flow_coeff=0.0, drop=0.0, open_press=0, close_press=0 4 gate1 = Gate("Pump inlet") 5 print("{} created".format(gate1.name)) 6 print(gate1.read_position()) 7 gate1.turn_handle(100) 8 print(gate1.read_position()) 9 gate1.close() 10 print(gate1.read_position()) 11 gate1.open() 12 print(gate1.read_position())

The following code snippet is part 14 of valve.py:

#  valve.py (part 14)
globe1 = Globe(" Throttle valve", flow_coeff=21, press_in=10, sys_flow_in=15) print("{} created".format(globe1.name)) print(globe1.read_position()) globe1.open() print(globe1.read_position()) globe1.close() print(globe1.read_position()) globe1.turn_handle(40) print(globe1.read_position())

The following code snippet is part 15 of valve.py:

#   valve.py (part 15) 
relief1 = Relief(" Pressure relief", open_press=25, close_press=20) print("{} created".format(relief1.name)) print(relief1.read_position()) print("The open setpoint is {} psi.".format(relief1.read_open_pressure())) print("The close setpoint is {} psi.".format(relief1.read_close_pressure())) relief1.set_open_pressure(75) relief1.set_close_press(73) print("The open setpoint is {} psi.".format(relief1.read_open_pressure())) print("The close setpoint is {} psi.".format(relief1.read_close_pressure())) relief1.valve_operation(75) print(relief1.read_position()) relief1.valve_operation(73) print(relief1.read_position())

The output of running valve.py on its own is shown in the following screenshot:

Valve file output
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.72.6