Example of Using the Excel Unit Op, страница 3

               compLbmol_Hr(X) = outletCompRatesLbmol_Hr(1, X)

Next X

The mixer in this example is adiabatic, so energy must be conserved.The next section of code add  the enthalpies of the two inlet stream and stores the value into the outlet stream enthalpy.

outletEnthBtu_Hr(1) = inletEnthBtu_Hr(1) + inletEnthBtu_Hr(2)

The next statement is an “If…Then…Else” statement that sets the pressure for the outlet stream.

If inletPresPsia(1) <= inletPresPsia(2) Then outletPresPsia(1) = inletPresPsia(1) Else outletPresPsia(1) = inletPresPsia(2)

In the second part of the example, the pressure will be input by the user via the customized dialog box. For the first part of the example, the outlet pressure is fixed as the lower pressure of the two inlet streams.  The statement checks to see if the first inlet stream has a lower or equal pressure to that of the second inlet pressure.  If it does, the outlet pressure is set to the pressure of the first inlet stream.  If it does not, the outlet pressure is set to the pressure of the second inlet stream. 

The next section of code (after variable declarations previously described) stores the new pressure, enthalpy, and temperature into new variables.

presPsia = outletPresPsia(1)

enthbtu_hr = outletEnthBtu_Hr(1)

The temperature is arbitrarily set as the average of the inlet temperatures.  This is done so the variable tempR is not zero when it is used to define the stream.

tempR = (inletTempR(1) + inletTempR(2)) / 2

Next the stream to be flashed is defined with the pressure, enthalpy, and temperature from above (presPSIA, enthbtu_hr, tempR).

check = flash.DefineFeedStream(tempR, presPsia, enthbtu_hr, compLbmol_Hr)

The next lines of code have CHEMCAD perform the flash calculation with the defined stream, and then get the properties of the vapor stream for the flash calculation. 

check = flash.CalculateHPFlash(enthbtu_hr, presPsia)

The flash is done with an HP flash since the enthalpy and pressure of the outlet stream is known. The calculateHPflash method takes the defined overall composition and flashes the stream to the specified enthalpy and pressure. The flash method uses the VLE model selected for the flowsheet in CHEMCAD. Note that temperature, vapor fraction, and phase composition are the unknown variables which CHEMCAD must find.

Once the stream is flashed, the temperature and vapor fraction of the flashed stream need to be returned and stored for the outlet stream.  The vapor fraction is stored  directly to the outlet stream array.

outletMoleVapFrac(1) = flash.GetMoleVaporFraction

The temperature for the vapor portion of the flashed stream is obtained to return the value of the overall temperature. Note that this method will set the specified variables equal to  values for the vapor phase of the defined and flashed stream. We do not wish to overwrite our variables, so new dummy variables are used.

check = flash.GetVaporStream(flashTempR, flashpresPsia, flashenthbtu_hr, flowrate, flashcompLbmol_Hr)

 If there is no vapor in the stream, the vapor stream temperature (and other variables) will be zero.  The next line of code takesthe liquid temperature if there is no vapor.  Again we use the dummy variables.

If flashTempR = 0 Then

check = flash.GetLiquidStream(flashTempR, flashpresPsia, flashenthbtu_hr, flowrate, flashcompLbmol_Hr)

End If

The value for flashTempR is now the temperature calculated by the HPflash method. The outltet temperature is set to this value.

outletTempR(1) = flashTempR

Now all properties for the outlet stream are known. Oultet enthalpy and flowrates were obtained by observing conservation of mass and energy. Outlet pressure was obtained as the lower inlet pressure. After calculating the flash for the outlet stream based on P, H, and composition, the vapor fraction was obtained. The temperature (vapor and / or liquid) has been obtained from the results of the flash calculation.  The outlet arrays have been set to the calculated values.