NitrogenGas Class


NitrogenGas Class

Now that we have defined the Species , N2 , and N classes we are ready to create a specific real gas mixture class. The class we will write will encapsulate a nitrogen gas mixture containing two species ”atomic and diatomic nitrogen. The class will be called NitrogenGas and will be a subclass of the RealGas class.

Similar to all the other specific subclasses we have looked at so far, the main function of the NitrogenGas class will be to send data for a nitrogen gas to the RealGas constructor. All of the other functionality the NitrogenGas class needs will be inherited from the RealGas class. The mole fraction and collision integral coefficient data is loaded into arrays. The NitrogenGas constructor sends this data and a specified pressure and temperature to the RealGas constructor. The source code for the NitrogenGas class is shown here.

 package TechJava.Gas; public class NitrogenGas extends RealGas {   //  Load data for a nitrogen gas with species   //  [N2,N] into arrays.   private static Species spc[] = {new N2(), new N()};   //  mole fractions   private static double moleFr[] = {1.0, 1.0e-10};   //  Collision integral coefficients   private static double A11[][] = {       {-6.0614558E-03,-1.0796249E-02},       {-1.0796249E-02,-8.4619226E-03} };   private static double B11[][] = {       {1.2689102E-01,2.2656509E-01},       {2.2656509E-01,1.8327232E-01} };   private static double C11[][] = {       {-1.0616948E+00,-1.7910602E+00},       {-1.7910602E+00,-1.5439009E+00} };   private static double E11[][] = {       {2.5768925E+02,1.2877295E+03},       {1.2877295E+03,6.6477619E+02} };   private static double A22[][] = {       {-7.6303990E-03,-8.3493693E-03},       {-8.3493693E-03,-7.0254351E-03} };   private static double B22[][] = {       {1.6878089E-01,1.7808911E-01},       {1.7808911E-01,1.5491560E-01} };   private static double C22[][] = {       {-1.4004234E+00,-1.4466155E+00},       {-1.4466155E+00,-1.3587248E+00} };   private static double E22[][] = {       {6.8206512E+02,6.1510870E+02},       {6.1510870E+02,5.0280608E+02} };   //  The NitrogenGas constructor calls the RealGas   //  constructor passing it data for a nitrogen   //  gas mixture.   public NitrogenGas(double temperature,                         double pressure) {     super("Nitrogen Gas", 2, 1, temperature,            pressure, spc, moleFr, A11, B11,            C11, E11, A22, B22, C22, E22);   } } 

To make sure everything works properly, let's write another driver program that will create a NitrogenGas object and access the data associated with the object. The driver program is named RealGasDriver and its source code is displayed next .

 import TechJava.Gas.*; public class RealGasDriver {   public static void main(String args[]) {     NitrogenGas gas =            new NitrogenGas(5000.0, 100000.0);     System.out.println("gas mixture name = " +                         gas.getName());     System.out.println("number of species = " +                         gas.getNumSpecies());     System.out.println("number of elements = " +                         gas.getNumElements());     for(int i=0; i<gas.getNumSpecies(); ++i) {       System.out.println("mole fraction[" + i +                    "] = " + gas.getMoleFraction(i));     }     for(int i=0; i<gas.getNumSpecies(); ++i) {       System.out.println("molar mass[" + i + "] = " +                    gas.getSpecies(i).getMolarMass());     }     System.out.println("pressure = " +              gas.getPressure() + " N/m^2");     System.out.println("temperature = " +              gas.getTemperature() + " K");     System.out.println("density = " +              gas.getDensity() + " kg/m^3");     System.out.println("molar mass = " +              gas.getMolarMass() + " kg/mole");     System.out.println("viscosity = "+              gas.getViscosity() + " kg/m-s");     System.out.println("enthalpy = " +              gas.getEnthalpy() + " J/mole");     System.out.println("entropy = " +              gas.getEntropy() + " J/mole-K");  } } 

Output ”

 gas mixture name = Nitrogen Gas number of species = 2 number of elements = 1 mole fraction[0] = 1.0 mole fraction[1] = 1.0E-10 molar mass[0] = 0.0280134 molar mass[1] = 0.0140067 pressure = 100000.0 N/m^2 temperature = 5000.0 K density = 0.06738517826616842 kg/m^3 molar mass = 0.028013400001400672 kg/mole viscosity = 1.191101312472402E-4 kg/m-s enthalpy = 167762.46361168486 J/mole entropy = 286.03757189521207 J/mole-K 

In addition to the NitrogenGas class, a class representing a five species air mixture named FiveSpeciesAir can be downloaded from the FTP site associated with this book. You should also download the NO , O2 , and O class source files. Try to modify the RealGasDriver.java program to create a FiveSpeciesAir object and see what happens.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net