Positive displacement pump class

Positive displacement pumps are any pumps that have a set amount of fluid capacity per revolution, which includes rotary, reciprocating, and linear types. Examples include screw pumps, gear pumps, piston pumps, and diaphragm pumps.

The following code listings define the generic characteristics for any positive displacement pump; because it is a general class, any true simulation would require more specific engineering formulas:

# pump.py (part 13)
1 class PositiveDisplacement(Pump): 2 """Defines a positive-displacement pump.""" 3 4 def __init__(self, name="", flow_rate_out=0.0, pump_head_in=0.0, press_out=0.0, pump_speed=0, displacement=0.0): 5 super(PositiveDisplacement, self).__init__(name, flow_rate_out, pump_head_in, press_out, pump_speed) 6 self.displacement = displacement 7 8 def get_speed_str(self): 9 """Get the current speed of the pump, in rpm.""" 10 if self.speed == 0: 11 return "The pump is stopped." 12 else: 13 return "The pump is running at {speed} rpm.".format(speed=self.speed)

For this pump, we have to account for the fluid displacement that occurs per cycle of the pump, so we define a new __init__ method in line 4 and create the new variable displacement in line 6.

Lines 8-13 is a string return method for speed, similar to the centrifugal pump class:

# pump.py (part 14)
1 def get_flow_str(self): 2 """Get the current flow rate of the pump.""" 3 return "The pump outlet flow rate is {flow} gpm.".format(flow=self.flow) 4 5 def get_press_str(self): 6 """Get the current output pressure for the pump.""" 7 return "The pump pressure is {press:.2f} psi.".format(press=self.outlet_pressure) 8 9 def get_power_str(self): 10 """Get the current power draw for the pump.""" 11 return "The power usage for the pump is {pow:.2f} kW.".format(pow=self.power)

The methods listed here are the same types of methods as the centrifugal pump and require no additional explanation.

#  pump.py (part 15)   
1 def adjust_speed(self, new_speed): 2 """Modify the speed of the pump, assuming constant outlet pressure. 3 4 Affects the outlet flow rate and power requirements for the pump. 5 """ 6 self.speed = new_speed 7 press_in = utility_formulas.head_to_press(self.head_in) 8 9 self.flow = self.speed * self.displacement 10 self.power = self.pump_power(self.flow, self.diff_press_psi(press_in, self.outlet_pressure)) 11 # TODO: Account for different flow rates based on outlet pressure

The speed of a positive displacement pump changes the amount of fluid pumped per cycle, as a set amount is moved each time. Therefore, a new speed method is created in the preceding code listing.

Line 11 is a TODO reminder that we will have to return later and figure out how to calculate changes in flow rate based on system pressure. Positive displacement pumps function differently than centrifugal pumps when it comes to outlet pressure. While centrifugal pumps can operate even if the outlet valve is completely shut, positive displacement pumps will continue to displace the same amount of fluid with each revolution, regardless of any obstructions. If it continues long enough, the piping or connections will break due to overpressure.

In other words, with a given speed, a positive displacement pump will attempt to maintain a constant flow rate. The actual flow rate will change based on the backpressure seen on the outlet of the pump, which is shown in the manufacturer's documentation. Currently, this pump program does not account for these real-world changes, but should be included in the future to provide a better simulation.

The basic functionality tests for the pump program are shown next, in two different code listings:

# pump.py (part 16)
1 if __name__ == "__main__": 2 # Functional test_valves 3 # name="", flow_rate=0.0, pump_head_in=0.0, press_out=0.0, pump_speed=0, hp=0.0, displacement=0.0 4 pump1 = CentrifPump("Pumpy", 75, 12, 25, 125) 5 print("{} created.".format(pump1.name)) 6 print(pump1.get_speed_str()) 7 print(pump1.get_flow_str()) 8 print(pump1.get_power_str()) 9 print(pump1.get_press_str()) 10 pump1.adjust_speed(50) 11 print(pump1.get_speed_str()) 12 print(pump1.get_flow_str()) 13 print(pump1.get_power_str()) 14 print(pump1.get_press_str()) 15 pump1.adjust_speed(0) 16 print(pump1.get_speed_str()) 17 print(pump1.get_flow_str()) 18 print(pump1.get_power_str()) 19 print(pump1.get_press_str()) # pump.py (part 17) 1 pump2 = PositiveDisplacement("Grumpy", 100, 0, 200, 300, 0.15) 2 print("\n{} created.".format(pump2.name)) 3 print(pump2.get_speed_str()) 4 print(pump2.get_flow_str()) 5 print(pump2.get_power_str()) 6 pump2.adjust_speed(50) 7 print(pump2.get_speed_str()) 8 print(pump2.get_flow_str()) 9 print(pump2.get_power_str()) 10 pump2.adjust_speed(0) 11 print(pump2.get_speed_str()) 12 print(pump2.get_flow_str()) 13 print(pump2.get_power_str())

The output of these tests are shown in following screenshot:

Pump test output