Exemplo n.º 1
0
def GibbsCalculation(XSolution):

    #    print
    #    print
    #    print ' = = = = = = BEGIN OF THE GIBBS CALCULATIONS = = = =  = = = = = = '
    #    print
    #    print

    ThT.ReadSet_Global_Variables()  # reading the external file
    """ Populating the MFRAC array that will be used throughout the calculation. In this thermodynamic module,
           MFRAC contains the mole fraction of all components in the vapour (0:Nc-1) and liquid (Nc:Nc*Np)
           phases. This function has XSolution[0:Nc] as an input and it contains the Nc-1 mole fractions
           of copmponents at the liquid phase and molar fraction of liquid phase.                             """

    MFrac = [0. for i in range(ThT.NComp * ThT.NPhase)
             ]  # create an a array with 0 values for the MFrac

    Lphase = XSolution[ThT.NComp - 1]
    Vphase = 1. - Lphase
    Sum1 = 0.
    inc = 0

    for icomp in xrange(ThT.NComp, ThT.NComp *
                        ThT.NPhase):  # Determining MFrac @ Liquid Phase
        if icomp < ThT.NComp * ThT.NPhase - 1:
            MFrac[icomp] = XSolution[inc]
            Sum1 = Sum1 + MFrac[icomp]
            inc += 1

    MFrac[ThT.NComp * ThT.NPhase -
          1] = 1. - Sum1  # Determining MFrac @ Liquid Phase (last component)

    Sum2 = 0.
    for icomp in range(ThT.NComp - 1):  # Determining MFrac @ Vapour phase
        MFrac[icomp] = (ThT.Z_Feed[icomp] -
                        Lphase * MFrac[ThT.NComp + icomp]) / Vphase
        Sum2 = Sum2 + MFrac[icomp]

    MFrac[ThT.NComp -
          1] = 1. - Sum2  # Determining MFrac @ Vapour Phase (last component

    # For debugging
    # pdb.set_trace()

    ChemPot = Call_Calc_ChemPot(
        MFrac)  # ChemPot has dimension (NPhase * NComp)

    #MolarGibbs = -Call_Calc_Gibbs( MFrac, ChemPot )
    MolarGibbs = Call_Calc_Gibbs(MFrac, ChemPot)

    return MolarGibbs, ThT.Z_Feed
import calculate_fi_test as fi
import calculate_terms_test as terms
import calculate_chemical_potential_test as chemp
import pylab as pl
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import time

print
print
print ' = = = = = = = = = = = = = = = = = = = = = = = = = BEGIN OF THE GIBBS CALCULATIONS = = = = = = = = = = = = = = = = = = = = = = = = '
print
print

ThT.ReadSet_Global_Variables()  # reading the external file

MFrac = [0. for i in range(ThT.NComp * ThT.NPhase)
         ]  # create an a array with 0 values for the MFrac

c1 = np.linspace(0.74535, 0.9999, 100)  # + - 25%
#c1 = np.linspace(0.7478, 0.9999, 10)
#c1 = np.linspace(0.7487, 0.9999, 10)
#c1 = np.linspace(0.7499, 0.9999, 10)

c2 = []
#c2 = np.linspace(0.5891, 0.9818, 5 )
for x in c1:
    c2.append(1.0 - x)

c2 = np.array(c2)
import sys
import thermotools_test as ThT
import EOS_PR_test as PR
import time
#import matplotlib.pyplot as plt

print
print
print ' = = = = = = = = = = = = = = = = = = = = = = = = = BEGIN OF THE GIBBS CALCULATIONS = = = = = = = = = = = = = = = = = = = = = = = = '
print
print

# = = = = = = = = = = = = = = = = = = = = = = = = = Reading Input data from external file = = = = = = = = = = = = = = = = = = = = = = = = =
Rconst = 8.314  # Gas constant [J/(gmol.K)]

ThT.ReadSet_Global_Variables()

MFrac = [0. for i in range(ThT.NComp * ThT.NPhase)]
print '  the initial molar fraction before reading from the input.dat is', MFrac

# declare a vector with MFrac values - molar fraction
MFrac[0] = 0.40
MFrac[1] = 0.20
# Vapour phase
MFrac[2] = 0.10
MFrac[3] = 0.10
# Liquid phase

print
print '  ---------------------------------------------------------------------------------------------------------------------'
# we have already declare the type and number of species from the input.dat
Exemplo n.º 4
0
        term2 = (1 / terms.BM(frac)) * q * (z - 1)
        term3 = (0.5 / np.sqrt(2)) * (
            (1 / terms.AM(frac)) * d * ThT.Rconst * ThT.T_System[0]) - (
                (1 / terms.BM(frac)) * q)
        term4 = np.log((z / terms.B(frac) + 1 - np.sqrt(2)) /
                       (z / terms.B(frac) + 1 + np.sqrt(2)))
        print ' term1 = ', term1, z, frac[i]
        print ' term2 = ', term2
        print ' term3 = ', term3
        print ' term4 = ', term4
        lnfi[i] = term1 + term2 + term3 * term4
        print '    fi = ', lnfi[i], ' for the MFrac = ', frac[i]

    return lnfi


'''
ThT.ReadSet_Global_Variables()

MFrac = [ 0. for i in range( ThT.NComp ) ]
print '  the initial molar fraction before reading from the input.dat is ', MFrac
# declare a vector with MFrac values - molar fraction
MFrac[ 0 ] = 0.40; MFrac[ 1 ] = 0.20; # Vapour phase
#MFrac[ 2 ] = 0.10; MFrac[ 3 ] = 0.10; # Liquid phase

iphase = 0

phi = CALC_FI( iphase, MFrac )
print 'ln_phi = ', phi 
'''