//this is a file in the VAc dynamic model software package //this is the main file for the absorber //parent-routine: VAmodel.c //subroutines involve: enthalpy_7.c gamma_wilson_7.c //Copyright: Rong Chen and Kedar Dave, June 2002 //VERSION 1.0 //if a user wants to build a DLL for the absorber only, follow the instruction below: //1. Add this line to the head of this file: #include "mex.h" //2. Enable mexFunction(), which is the second routine included in this file (currently disabled) //3. Use the following line to generate a DLL file: absorber.dll // mex absorber.c enthalpy_7.c gamma_wilson_7.c //4. The name of the generated function is "absorber()". This function should be called in MATLAB. //The absorber is modeled by a eight-trayed column with a base tank //The most tricky part is to use a rate-based method to calculate the mass and heat transfered on each tray //A VLE is assumed between the liquid phase and an interface vapor phase //Mass and heat are transferred between the vapor phase and the interface vapor phase using constant transfer coefficients //The base tank is a basic liquid buffer tank, modeled by using mass and energy balances #include #include //#include "mex.h" void Absorber(double *dstatedt, double *dstatedt_other, double *Level, double *TV, double *TL, double *F_AbsGasOut, double *y_AbsGasOut, double *T_AbsGasOut, double *x_AbsLiquidOut, double *T_AbsLiquidOut, double states[], double Pin, double F_AbsLiquidOut, double F_AbsGasIn, double y_AbsGasIn[], double T_AbsGasIn, double F_AbsLiquidIn, double x_AbsLiquidIn[], double T_AbsLiquidIn, double F_Circulation, double Q_Circulation, double Q_Scrub, int NT, int NF, double Working_Level_Volume, double M0[], double L0[], double hydtau, double Nmt[], double Qmt[], double T_Circulation[], double T_Scrub[], double VIJ[][7], double aij[][7], double MW[], double SpG[], double HVAP[], double HCAPLa[], double HCAPLb[], double HCAPVa[], double HCAPVb[], double A[], double B[], double C[], double R, double Dw, double T_ref) { //-------------------------------------------------------------------------- //physical properties: VIJ, aij, MW, SpG, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb, A, B, C, R, Dw, T_ref //-------------------------------------------------------------------------- /*output: dstatedt: state derivatives dstatedt_other: temperature state derivatives Level: absorber level TV: absorber vapor outlet temperature TL: absorber liquid outlet temperature Q_Circulation_out: circulation cooler duty (duplicated when no perfect control is selected) Q_Scrub_out: scrub cooler duty (duplicated when no perfect control is selected) F_AbsGasOut: absorber vapor outlet flowrate y_AbsGasOut: absorber vapor outlet composition T_AbsGasOut: absorber vapor outlet temperature F_AbsLiquidOut_out: absorber liquid outlet flowrate x_AbsLiquidOut: absorber liquid outlet composition T_AbsLiquidOut: absorber liquid outlet temperature --------------------------------------------------------------------------*/ /*input: states: states F_AbsLiquidOut: absorber bottom liquid outlet flowrate F_AbsGasIn: abosrber gas inlet flowrate y_AbsGasIn: abosrber gas inlet composition T_AbsGasIn: abosrber gas inlet temperature F_AbsLiquidIn: abosrber liquid inlet flowrate (the scrub stream) x_AbsLiquidIn: abosrber liquid inlet composition T_AbsLiquidIn: abosrber liquid inlet temperature F_Circulation: abosrber circulation stream flowrate Q_Circulation: abosrber circulation cooler duty Q_Scrub: abosrber liquid inlet cooler duty T_circulation: absorber circulation stream temperature T_Scrub: absorber scrub stream (liquid inlet stream) temperature ------------------------------------------------------------------------*/ /*Equipment Specification Pin: absorber pressure NT: tray number NF: circulation stream feed tray Working_Level_Volume: absorber bottom volume M0[]: tray holdup constant L0[]: liquid flowrate constant hydtau: hydraulic constant Nmt: absorber mass transfer coefficients Qmt: absorber heat transfer coefficients ------------------------------------------------------------------------*/ //local variables //states double x[8][7], M[8]; double x_base[1][7], Volume_base, T_base[1]; double x_Circulation[1][7]; //same as x_base //intermediate variables double y[8][7]; double ps[8][7]; //partial pressure double g[8][7]; //gamma double y_interface[8][7]; double z[8][7]; //mass transfer flow composition double minimum[8][7]; //real mass transfer flow without direction double N[8][7]; //real mass transfer flow with direction double P[8], FL[8], FV[8], Q[8]; double HL[8], HV[8], H_N[8]; double HV_AbsGasIn[1], HL_AbsLiquidIn[1], HL_Scrub[1], HL_base[1], HL_Circulation[1]; double liquid_concentration, liquid_density; //Feed double Y_AbsGasIn[1][7], X_AbsLiquidIn[1][7]; //derivatives double dMdt[8], dxdt[8][7], dTdt[8], dxbasedt[7], dMbasedt, dLbasedt, dTbasedt; //others int i, j, k; double sum1=0., sum2=0., Mol_fract=0., dummy[1] = {0.}; double temp_X[1][7], temp_Y[1][7], temp_T[1], temp_HL[1], temp_HV[1]; double AAA, BBB, CCC, TTT, gg[7], sign[7], sumN[8]; //------------------------------------------------------------------------------- //Initialization for (i=0;i 0.5*F_AbsGasIn*y_AbsGasIn[j]) minimum[i][j]=0.5*F_AbsGasIn*y_AbsGasIn[j]; else minimum[i][j]= fabs(Nmt[i]*(y_AbsGasIn[j]-y_interface[i][j])); N[i][j]=sign[j]*minimum[i][j]; sumN[i]+=N[i][j]; }; FV[i]=F_AbsGasIn-sumN[i]; for (j=0;j<7;j++) { y[i][j]=(F_AbsGasIn*y_AbsGasIn[j]-N[i][j])/FV[i]; z[i][j]=N[i][j]/sumN[i]; }; Q[i]=Qmt[i]*(T_AbsGasIn-TL[i])*9/5; temp_T[0]=TL[i]; for (j=0;j<7;j++) temp_Y[0][j]=z[i][j]; enthalpy_7(dummy, temp_HV, temp_Y, temp_Y, temp_T, MW, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb); H_N[i] = temp_HV[0]; /*use energy balance to calculate TV*/ sum1=0.; AAA=0.; BBB=0.; for (k=0;k<7;k++) { sum1+=HVAP[k]*y[i][k]; BBB+=HCAPVa[k]*MW[k]*y[i][k]; AAA+=0.5*HCAPVb[k]*MW[k]*y[i][k]; }; CCC=-(F_AbsGasIn*HV_AbsGasIn[0]-sumN[i]*H_N[i]-Q[i])/FV[i]+sum1; if ((BBB*BBB-4*AAA*CCC)<0) printf("error on vapor temp"); TV[i]=((-BBB+sqrt(BBB*BBB-4*AAA*CCC))/(2*AAA)); temp_T[0]=TV[i]; for (j=0;j<7;j++) temp_Y[0][j]=y[i][j]; enthalpy_7(dummy, temp_HV, temp_Y, temp_Y, temp_T, MW, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb); HV[i] = temp_HV[0]; }/*end of i==0*/ else { //other trays sumN[i]=0.; for (j=0;j<7;j++) { if (y[i-1][j]==y_interface[i][j]) sign[j] = 0.; else sign[j]=(y[i-1][j]-y_interface[i][j])/fabs(y[i-1][j] - y_interface[i][j]); if(fabs(Nmt[i]*(y[i-1][j]-y_interface[i][j])) > 0.5*FV[i-1]*y[i-1][j]) minimum[i][j]=0.5*FV[i-1]*y[i-1][j]; else minimum[i][j]= fabs(Nmt[i]*(y[i-1][j] - y_interface[i][j])); N[i][j]=sign[j]*minimum[i][j]; sumN[i]+=N[i][j]; }; FV[i]=FV[i-1]-sumN[i]; for (j=0;j<7;j++) { y[i][j]=(FV[i-1]*y[i-1][j]-N[i][j])/FV[i]; z[i][j]=N[i][j]/sumN[i]; }; Q[i]=Qmt[i]*(TV[i-1]-TL[i])*9/5; temp_T[0]=TL[i]; for (j=0;j<7;j++) temp_Y[0][j]=z[i][j]; enthalpy_7(dummy, temp_HV, temp_Y, temp_Y, temp_T, MW, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb); H_N[i] = temp_HV[0]; /*use energy balance to calculate TV*/ sum1=0.; AAA=0.; BBB=0.; for (k=0;k<7;k++) { sum1+=HVAP[k]*y[i][k]; BBB+=HCAPVa[k]*MW[k]*y[i][k]; AAA+=0.5*HCAPVb[k]*MW[k]*y[i][k]; }; CCC=-(FV[i-1]*HV[i-1]-sumN[i]*H_N[i]-Q[i])/FV[i]+sum1; if ((BBB*BBB-4*AAA*CCC)<0) printf("error on vapor temp"); TV[i]=((-BBB+sqrt(BBB*BBB-4*AAA*CCC))/(2*AAA)); temp_T[0]=TV[i]; for (j=0;j<7;j++) temp_Y[0][j]=y[i][j]; enthalpy_7(dummy, temp_HV, temp_Y, temp_Y, temp_T, MW, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb); HV[i] = temp_HV[0]; }/*end of i!=0*/ }/*end of for loop*/ /*------------------------------------------------------------------------*/ //calculate derivatives //base sum1=0.; sum2=0.; for (j=0;j<7;j++) { sum1+=x[0][j]*MW[j]; sum2+=x_base[0][j]*MW[j]; }; dMbasedt=FL[0]-F_AbsLiquidOut-F_Circulation; dLbasedt=dMbasedt/liquid_concentration/Working_Level_Volume; /*volume percentage*/ for (j=0;j<7;j++) { dxbasedt[j]=(FL[0]*x[0][j]-(F_AbsLiquidOut+F_Circulation)*x_base[0][j]-x_base[0][j]*dMbasedt)/liquid_concentration/Volume_base; temp_X[0][j]=x[0][j]; }; temp_T[0]=TL[0]; enthalpy_7(temp_HL, dummy, temp_X, temp_X, temp_T, MW, HVAP, HCAPLa, HCAPLb, HCAPVa,HCAPVb); HL[0] = temp_HL[0]; sum1=0.; for (j=0;j<7;j++) sum1+=x_base[0][j]*MW[j]*(HCAPLa[j]+HCAPLb[j]*T_base[0]); dTbasedt=(FL[0]*(HL[0]-HL_base[0])-(F_AbsLiquidOut+ F_Circulation)*(HL_base[0]-HL_base[0]))/(liquid_concentration*Volume_base)/sum1; //trays for (i=0;i