/* * PS3Prob2.java * * Created on February 22, 2002, 3:24 PM */ /** * * @author Curtis Eubanks * @version */ import java.util.Vector; import javax.swing.JOptionPane; public class PS3Prob2 { /** Creates new PS3Prob2 */ public PS3Prob2() { } /** * @param args the command line arguments */ public static void main(String args[]) { Fluid[] fluids = new Fluid[4]; fluids[0] = new Fluid("water", 1.0E3, 1.0E-3); fluids[1] = new Fluid("air", 1.2, 1.8E-5); fluids[2] = new Fluid("ethyl alcohol", 0.79E3, 1.2E-3); fluids[3] = new Fluid("methyl alcohol", 0.79E3, 0.62E-3); String fluidInput = JOptionPane.showInputDialog("Enter fluid type (1=water, 2=air, 3=ethyl alcohol, 4=methyl alcohol"); int fluidIndex = Integer.parseInt(fluidInput)-1; Vector pipes = new Vector(5); Pipe ab = new Pipe("AB", 0.5, 50.0, -0.1); pipes.addElement(ab); Pipe bc = new Pipe("BC", 0.4, 15, -0.05); ab.addOutflow(bc); pipes.addElement(bc); Pipe cd = new Pipe("CD", 0.3, 5.0, -0.03); bc.addOutflow(cd); pipes.addElement(cd); Pipe ce = new Pipe("CE", Math.sqrt(7.0)/10.0, 8.0, -0.03); bc.addOutflow(ce); pipes.addElement(ce); Pipe bf = new Pipe("BF", 0.3, 25.0, 0.05); ab.addOutflow(bf); pipes.addElement(bf); String input = JOptionPane.showInputDialog("Initial pressure at A: "); double initialPressure = Double.parseDouble(input); input = JOptionPane.showInputDialog("Initial velocity at A: "); double initialVelocity = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter pipe roughness: "); Pipe.setRoughness(Double.parseDouble(input)); /* start the juices flowing */ /* this will calculate input & output pressures for all pipes in the network */ ab.startFlow(fluids[fluidIndex], initialVelocity, initialPressure); /* compute desired quantities */ for (int i=0; i < pipes.size(); i++) { Pipe pipe = (Pipe)pipes.elementAt(i); pipe.printPipeInfo(fluids[fluidIndex], initialVelocity, initialPressure); } System.exit(0); } } class Fluid { private String name; private double density; private double viscosity; public Fluid(String name, double density, double viscosity) { this.name = name; this.density = density; this.viscosity = viscosity; } public String toString() { return "Fluid: \"" + name +"\", density = " + density + ", viscosity = " + viscosity; } public double getDensity() { return density; } public double getViscosity() { return viscosity; } } class Pipe { private static double roughness = 0.00001; /* in meters */ /* gravitational acceleration on the earth's surface at sea level */ final private static double g = 9.8; /* in meters/sec^2 */ private String name; private double diameter; /* in meters */ private double length; /* in meters */ private double elevationChange; /* in meters */ /* the pressure (if calculated) */ public double inPressure, outPressure; /* list of Pipe objects whose input is our output */ private Vector outflows; public Pipe(String name, double diameter, double length, double elevationChange) { this.name = name; this.diameter = diameter; this.length = length; this.elevationChange = elevationChange; inPressure = 0.0; /* empty pipe */ outPressure = 0.0; /* empty pipe */ outflows = new Vector(); } public void addOutflow(Pipe p) { outflows.addElement(p); } public void startFlow(Fluid fluid, double velocity, double inputPressure) { inPressure = inputPressure; outPressure = pressureChange(inputPressure, fluid, velocity); /* calculate pressure of all outflows */ for (int i=0; i