Component coding

Since we have already coded the foundation parts of the valves, pumps, and tanks, writing the instances of the specific components for our diagram is comparatively easy, as shown in the code listings that we will explain in this section.

We have split the components.py file into the following separate parts, with a discussion of each code listing following its respective part. Part 1 is the same introduction that we've seen before. If you look at the date for this listing compared to the previous ones, you'll see that it took about two months to complete the work on the foundation code. Of course, this work was done by one person, who also had other work projects to handle during the same time frame, but it's also a good example of how much time it takes to make full-blown programming projects, especially if it's a personal project:

components.py (part 1)

1  #!/usr/bin/env python3
2 """
3 FuelFarm.py
4​
5 Purpose: Simulate an aviation fuel storage and transfer system.
6​
7 Author: Cody Jackson
8​
9 Date: 6/12/18
10 #################################
11 Version 0.2
12 Added path extension for utility formulas
13 Version 0.1
14 Initial build
15 """

We've seen the code in part 2 before as well. We have the normal imports, plus the extension to the system path to ensure that we can actually call the parts of the project that we need without errors. We also specify the unique density and specific gravity values of JP-8 fuel:

components.py (part 2)

1  import sys
2 sys.path.extend(["/home/cody/PycharmProjects/VirtualPLC"])
3 from Utilities import utility_formulas
4​
5 from PipingSystems.pump import pump
6 from PipingSystems.valve import valve
7 from PipingSystems.storage_tank import tank
8​
9 # Constants
10 DENSITY = 1.629869
11 SPEC_GRAVITY = 0.840

In part 3, we define the specifications for the storage tank instances. The comments also show some of the assumptions that are used to provide the parameters:

components.py (part 3)

1  # Storage tanks
2 # Assumes 36 ft tall tank w/ 1 million gallon capacity = 27778 gallons per foot
3 # Assumes 16 inch diam transfer piping
4 tank1 = tank.Tank("Tank 1", level=36.0, fluid_density=DENSITY, spec_gravity=SPEC_GRAVITY, outlet_diam=16, outlet_slope=0.25)
5 tank1.static_tank_press = tank1.level
6 tank1.gravity_flow(tank1.pipe_diam, tank1.pipe_slope, tank1.pipe_coeff)
7​
8 tank2 = tank.Tank("Tank 2", level=36.0, fluid_density=DENSITY, spec_gravity=SPEC_GRAVITY, outlet_diam=16, outlet_slope=0.25)
9 tank2.static_tank_press = tank2.level
10 tank2.gravity_flow(tank2.pipe_diam, tank2.pifunctionalitype_slope, tank2.pipe_coeff)

In part 4, we again provide some comments for the basis of the parameters, then start creating instances of the inlet valves to the pumps. Valve flow coefficients are normally found in manufacturers' data manuals, but we can use the diameter of the valve to roughly calculate the coefficient:

components.py (part 4)

1  # Pump inlet manifold
2 # 16 inch to 4 inch connections
3 gate1 = valve.Gate("Gate valve 1", sys_flow_in=tank1.flow_out, press_in=tank1.static_tank_press)
4 gate1.calc_coeff(16)
5​
6 gate2 = valve.Gate("Gate valve 2", sys_flow_in=tank2.flow_out, press_in=tank2.static_tank_press)
7 gate2.calc_coeff(16)
8​
9 gate3 = valve.Gate("Gate valve 3")
10 gate3.calc_coeff(16)
11​
12 gate4 = valve.Gate("Gate valve 4")
13 gate4.calc_coeff(16)

In part 5, we continue defining the inlet valve instances (note that in part 4, only valves 1-4 are 16 inches in diameter, while the valves in part 5 are 4 inches), then create the fuel pump instances. Note that, as screw-type pumps, we have provided a set RPM value, which determines the volume of fluid displaced per revolution. These values would normally be determined by looking at pump curves provided by the manufacturer:

components.py (part 5)

1  gate5 = valve.Gate("Gate valve 5")
2 gate5.calc_coeff(4)
3​
4 gate6 = valve.Gate("Gate valve 6", sys_flow_in=gate3.flow_out + gate4.flow_out,
5 press_in=gate3.press_out + gate4.press_out)
6 gate6.calc_coeff(4)
7​
8 gate7 = valve.Gate("Gate valve 7")
9 gate7.calc_coeff(4)
10​
11 # Fuel pumps @ 1480 rpm
12 pump1 = pump.PositiveDisplacement("Pump 1", flow_rate_out=0.0, pump_head_in=utility_formulas.press_to_head(gate5.press_out), displacement=0.24)
13​
14 pump2 = pump.PositiveDisplacement("Pump 2", flow_rate_out=0.0, pump_head_in=utility_formulas.press_to_head(gate6.press_out), displacement=0.24)

Part 6 shows the creation of the instances of the remaining fuel pump, the relief valves, and the pressure-regulating throttle valves:

components.py (part 6)

1  pump3 = pump.PositiveDisplacement("Pump 3", flow_rate_out=0.0, pump_head_in=utility_formulas.press_to_head(gate7.press_out), displacement=0.24)
2​
3 # Pump outlet manifold
4 relief1 = valve.Relief("Relief 1", sys_flow_in=pump1.flow, flow_coeff=0.81)
5 relief2 = valve.Relief("Relief 2", sys_flow_in=pump2.flow, flow_coeff=0.81)
6 relief3 = valve.Relief("Relief 3", sys_flow_in=pump3.flow, flow_coeff=0.81)
7​
8  throttle1 = valve.Globe("Flow Control 1", sys_flow_in=pump1.flow, press_in=pump1.outlet_pressure, flow_coeff=165)
9 throttle2 = valve.Globe("Flow Control 2", sys_flow_in=pump1.flow, press_in=pump1.outlet_pressure, flow_coeff=165)
10 throttle3 = valve.Globe("Flow Control 3", sys_flow_in=pump1.flow, press_in=pump1.outlet_pressure, flow_coeff=165)

We finish the file with part 7 by creating instances for the fluid-distribution valves that send the fuel back to the tanks or to the flight line.

Also, rather than creating some self-tests at the end of the program, we use the pass statement to allow Python to continue. Functionally, there is no difference between using pass and not even having the if __name__ == "__main__" code block; having it there makes it easier if we want to add self-test code or other code that should be run if components.py is run by itself:

components.py (part 7)

1  gate8 = valve.Gate("Gate valve 8", sys_flow_in=throttle3.flow_out, press_in=throttle3.press_out)
2 gate8.calc_coeff(4)
3​
4 gate9 = valve.Gate("Gate valve 9", sys_flow_in=throttle1.flow_out, press_in=throttle1.press_out)
5 gate9.calc_coeff(4)
6​
7 gate10 = valve.Gate("Gate valve 10", sys_flow_in=throttle3.flow_out, press_in=throttle3.press_out)
8 gate10.calc_coeff(4)
9​
10 if __name__ == "__main__":
11 pass
..................Content has been hidden....................

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