PerfectGas Class


PerfectGas Class

The PerfectGas class is a nonabstract subclass of AbstractGas . It represents a perfect gas, one that does not chemically react and that has a constant specific heat. Every gas mixture will have an associated pressure, temperature, and molar mass. The PerfectGas class declares fields that represent these quantities . Other fields include the gas mixture name , the constant specific heat, and the reference entropy at a temperature of 100 K.

The PerfectGas class declares constructors to initialize its fields. The first constructor is used to create a PerfectGas object. The second constructor will be used by subclasses of PerfectGas that represent real gases. We will discuss the RealGas class in a subsequent section. The second constructor does not initialize the molarMass , cp , and Sref fields, so they are given default values. The cp and Sref fields are not used by the RealGas class, and the RealGas constructor initializes the molarMass field. After the constructors, the PerfectGas class declares methods to get or set the values of its fields.

One of the design considerations for the PerfectGas class is whether to include the density, viscosity , enthalpy, and entropy as fields. Since these quantities are all functions of pressure and temperature, including them as fields would result in an overspecified system. Rather than including them as fields, get() methods are provided to compute and return the value of these quantities. The getDensity() method computes the density according to Eq. (18.1). The getEnthalpy() and getEntropy() methods calculate the enthalpy and entropy according to the perfect gas relations in Eq. (18.2) and Eq. (18.3).

Equation 18.2

graphics/18equ02.gif


Equation 18.3

graphics/18equ03.gif


The specific heat, c p , in Eq. (18.2) and Eq. (18.3) is normalized by the Universal Gas Constant and has a value of 3.5 for diatomic gases. The T and p parameters in Eq. (18.3) are the reference temperature and pressure for the calculation. We will use values of 100 K and 1.0e+5 Pa for these quantities. The S ref parameter is the entropy at the reference temperature of 100 K.

The getViscosity() method returns the viscosity coefficient of the gas mixture using a relation known as Sutherland's law, shown in Eq. (18.4).

Equation 18.4

graphics/18equ04.gif


The source code for the PerfectGas class is shown next . Keep in mind the principles of state and behavior. The PerfectGas class has a number of variables to represent state and methods to get or set the value of these variables .

 package TechJava.Gas; public class PerfectGas extends AbstractGas {   //  The PerfectGas class declares fields for the gas   //  mixture name, temperature, molar mass, and   //  pressure. The cp variable is the specific heat at   //  constant pressure and Sref is the reference   //  entropy at 100 K   private String name;   private double temperature, molarMass, pressure;   private double cp, Sref;   //  The PerfectGas class defines two constructors   public PerfectGas(String name, double temperature,                     double molarMass, double pressure,                     double cp, double Sref) {     this.name = name;     this.temperature = temperature;     this.molarMass = molarMass;     this.pressure = pressure;     this.cp = cp;     this.Sref = Sref;   }   //  The second constructor is used by the RealGas   //  class. Default values are assigned to the   //  molarMass, cp, and Sref fields   public PerfectGas(String name, double temperature,                      double pressure) {     this.name = name;     this.temperature = temperature;     this.pressure = pressure;   }   //  These methods set the values of pressure,   //  molar mass, or temperature.   public void setPressure(double p) {     pressure = p;   }   public void setMolarMass(double m) {     molarMass = m;   }   public void setTemperature(double t) {     temperature = t;   }   //  These methods return the gas mixture name   //  and the current value of the pressure,   //  temperature, and molarMass variables.   public String getName() {     return name;   }   public double getPressure() {     return pressure;   }   public double getMolarMass() {     return molarMass;   }   public double getTemperature() {     return temperature;   }   //  Compute and return density in units of kg/m^3   public double getDensity() {     return pressure*molarMass/(R*temperature);   }   //  Viscosity is computed using Sutherland's law.   //  The units are kg/m-s   public double getViscosity() {     return 1.458e-06*        Math.pow(temperature,1.5)/(temperature+110.4);   }   //  Compute enthalpy in units of J/mole   public double getEnthalpy() {     return cp*R*temperature;   }   //  Compute entropy in units of J/mole-K   public double getEntropy() {     return Sref +            cp*R*Math.log(temperature/100.0) -            R*Math.log(pressure/100000.0);   } } 


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