Realgas Class


Realgas Class

The PerfectGas class defines the state and behavior of a perfect gas. A real gas is more complicated. For instance, it cannot be treated as a homogenous gas mixture, but instead must be considered as a collection of individual gas species. The gas species interact with each other and the chemical composition of the gas can change. The specific heat of the gas mixture and of each individual species in the gas mixture is no longer constant but instead is a function of temperature. The transport properties of the gas, including the mixture viscosity , depend on the interaction of the individual gas species.

We will define the RealGas class to represent a generic real gas mixture. We will build upon the capabilities of the PerfectGas class, so the RealGas class will be written as a subclass of PerfectGas . The RealGas class will have to define some new fields to represent the more complicated state of a real gas. For one thing it needs an array of Species objects for data relating to the species that make up the gas mixture. Other fields will represent the number of species in the gas mixture, the number of elements, the species mole fractions, and arrays containing coefficient data used to compute the transport properties of the gas. A mole fraction is the number of molecules of a given species divided by the total number of molecules in the gas mixture. The sum of the species mole fractions will, by definition, be 1. Because RealGas is a subclass of PerfectGas which itself is a subclass of AbstractGas , the R constant declared in the AbstractctGas class can be accessed inside the RealGas class using the constant's simple name , R .

The RealGas class declares one constructor. The first thing the RealGas constructor does is to call a PerfectGas constructor to initialize the temperature , molarMass , and pressure instance variables . The RealGas members include arrays containing coefficient data. These arrays would be somewhat tedious to load manually, but in the next section we will define a RealGas subclass that will automatically load this data.

The next section of the RealGas class declares get() methods for returning the value of some of its variables. The RealGas class inherits the getTemperature() , getDensity() , and getPressure() methods from the PerfectGas class and these methods are used to return the temperature, density, and pressure of the gas. The computeMolarMass() method is written to compute the molar mass of a real gas mixture by summing the product of the species mole fractions and the species molecular weights (Eq. (18.5)).

Equation 18.5

graphics/18equ05.gif


One big difference between perfect and real gases is the way the thermodynamic functions of enthalpy and entropy are computed. Perfect gases have a constant specific heat and the equations to compute enthalpy and entropy are relatively simple. With a real gas, specific heat is a function of temperature. To calculate species enthalpy or entropy requires integrating the specific heat with respect to temperature over the desired temperature range. Methods to compute the species enthalpy and entropy will be defined in the Species class. The mixture enthalpy and entropy can be expressed as a summation of the species mole fractions multiplied by the species enthalpy or entropy (Eq. (18.6) and Eq. (18.7)).

Equation 18.6

graphics/18equ06.gif


Equation 18.7

graphics/18equ07.gif


You may have noted that we haven't discussed how to implement the getViscosity() method for a real gas. That question will be deferred to the next chapter where we discuss solving systems of equations. The RealGas class source code is shown next.

 package TechJava.Gas; public class RealGas extends PerfectGas {   //  The RealGas class defines some additional data   //  members. The A11, B11, etc. contain   //  coefficients used to calculate viscosity and   //  thermal conductivity.   private int numSpecies, numElements;   private Species spc[];   private double moleFr[];   private double A11[][], B11[][], C11[][], E11[][];   private double A22[][], B22[][], C22[][], E22[][];   //  The RealGas class defines one constructor   public RealGas(String name, int numSpecies,     int numElements, double temperature,     double pressure, Species spc[],     double moleFr[], double A11[][], double B11[][],     double C11[][], double E11[][], double A22[][],     double B22[][], double C22[][], double E22[][]) {     //  A PerfectGas constructor is called to initialize     //  the name, temperature, and pressure values.     super(name, temperature, pressure);     //  Initialize the rest of the RealGas variables.     this.numSpecies = numSpecies;     this.numElements = numElements;     this.spc = spc;     this.moleFr = moleFr;     this.A11 = A11;     this.B11 = B11;     this.C11 = C11;     this.E11 = E11;     this.A22 = A22;     this.B22 = B22;     this.C22 = C22;     this.E22 = E22;     //  Compute the molar mass based on mole fractions.     setMolarMass(computeMolarMass());   }   //  These methods return the number of species and   //  elements in the gas mixture, the mole fraction   //  of a specified species, or a Species object.   public int getNumSpecies() {     return numSpecies;   }   public int getNumElements() {     return numElements;   }   public double getMoleFraction(int i) {     return moleFr[i];   }   public Species getSpecies(int i) {     return spc[i];   }   //  This method can be used to change the species   //  mole fractions   public void setMoleFraction(int i, double value) {     moleFr[i] = value;   }   //  Compute molar mass from mole fractions   public double computeMolarMass() {     double molarMass = 0.0;     for(int i=0; i<numSpecies; ++i) {       molarMass += moleFr[i]*spc[i].getMolarMass();     }     return molarMass;   }   //  The mixture enthalpy is the sum of the species   //  mole fractions times the species enthalpy.   public double getEnthalpy() {     double enthalpy = 0.0;     for(int i=0; i<numSpecies; ++i) {       enthalpy += moleFr[i]*                   spc[i].getEnthalpy(getTemperature());     }     return enthalpy;   }   //  The mixture entropy is the sum of the species   //  mole fractions times the species entropy.   public double getEntropy() {     double entropy = 0.0;     for(int i=0; i<numSpecies; ++i) {       entropy += moleFr[i]*           spc[i].getEntropy(             getTemperature(), getPressure(), moleFr[i]);     }     return entropy;   } } 


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