//this is a file in the VAc dynamic model software package //this is the main file for the azeotropic distillation column with a decanter and an HAc buffer tank //parent-routine: VAmodel.c //subroutines involve: bubpt_column.c enthalpy_3.c enthalpy_7.c Ludcmp.c mixer.c gamma_wilson_3.c //Copyright: Rong Chen and Kedar Dave, June 2002 //VERSION 1.0 //if a user wants to build a DLL for the column simulation 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: column.dll // mex column.c bubpt_column.c enthalpy_3.c enthalpy_7.c Ludcmp.c mixer.c gamma_wilson_3.c //4. The name of the generated function is "column()". This function should be called in MATLAB. //The azeotropic distillation column is a lumped model assuming VLE and the vapor phase dynamics are ignored //In the column, the tray temperature profile and the vapor flowrate profile are calculated from the state variables //The decanter is modeled using static partition coefficient for the two liquid phases while in the column there is only one liquid phase //The tank is a basic liquid buffer tank, modeled by using mass and energy balances #include #include //#include "mex.h" void Column(double *dstatedt, double *dstatedt_other, double *T_Column, double *x_Organic, double *T_Organic, double *x_Aqueous, double *T_Aqueous, double *beta_out, double states[], double P[], double FL, double xF[], double TFL, double LR, double QR, double LO, double LA, double LB, double T_guess[], double F_HAc, double x_HAc[], double T_HAc, double F_Scrub, double F_VapLiquidIn, int NT, int NF, double PD, double PB, double T_decanter[], double K[], double hydtau, double M0[], double LZERO[], double Bottom_Working_Level_Volume, double Organic_Working_Level_Volume, double Aqueous_Working_Level_Volume, double HAcTank_Working_Level_Volume, 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, double Q_Condenser) { //-------------------------------------------------------------------------- //physical properties: VIJ, aij, MW, SpG, HVAP, HCAPLa, HCAPLb, HCAPVa, HCAPVb, A, B, C, R, Dw, T_ref //-------------------------------------------------------------------------- /*output: dstatedt: state derivatives T_Column: column temperature profile T_decanter: decanter temperature LO_out: organic product flowrate x_Organic: organic product composition T_Organic: organic product temperature LA_out: aqueous product flowrate x_Aqueous: aqueous product composition T_Aqueous: aqueous product temperature LB_out: bottom product flowrate F_HAc_out: HAc fresh feed flowrate beta_out: decanter partition ratio Q_Condenser_out: condenser heat duty (duplicated when no perfect control is selected) --------------------------------------------------------------------------*/ /*input: states: states P: column pressure profile FL: feed flowrate xF: feed composition TFL: feed temperature LR: reflux QR: reboiler duty LO: organic product flowrate LA: aqueous product flowrate LB: bottom flowrate T_guess: initial guess of the column temperature profile F_HAc: HAc feed flowrate x_HAc[]: HAc feed composition T_HAc: HAc feed temperature F_ToScrub: scrub flowrate F_VapLiquidIn: Vaporizer Liquid Inlet flowrate Q_Condenser: condenser heat duty ------------------------------------------------------------------------*/ /*Equipment Specification NT: tray number NF: feed tray number PD: top tray pressure PB: reboiler pressure K[]: decanter partition coefficients hydtau: hydraulic constant M0[]: tray holdup constant LZERO[]: liquid flowrate constant Bottom_Working_Level_Volume: Organic_Working_Level_Volume: Aqueous_Working_Level_Volume: HAcTank_Working_Level_Volume: ------------------------------------------------------------------------*/ //local variables //states double x[20][3], M[20]; double x_bottom[1][3], Volume_bottom, x_organic[1][3], Volume_organic, x_aqueous[1][3], Volume_aqueous; double x_HAcTank[1][7]= {{0., 0., 0., 0., 0., 0., 0.},}, Volume_HAcTank, T_HAcTank[1]; //intermediate variables double L[20], HL[20], y[20][3], V[20], HV[20], T[20], liquid_concentration, liquid_density; double TB[1], HLB[1], yB[1][3], VB, HVB[1], bottom_concentration, bottom_density; double HLO[1], organic_concentration, organic_density; double HLA[1], aqueous_concentration, aqueous_density; double HL_HAcTank[1], HL_CondenserOut[1], HV_CondenserIn[1]; double F_organic, F_aqueous, organic_x[3], aqueous_x[3]; double F_HAcTankIn[1], x_HAcTankIn[1][7]={{0., 0., 0., 0., 0., 0., 0.},}, T_HAcTankIn[1], HL_HAcTankIn[1]; //Feed double x_F[1][3], HLF[1]; double HL_HAc[1]; //derivatives double dMdt[20], dMxdt[20][3], dxdt[20][3]; double dMdt_bottom, L_dot_bottom, dxdt_bottom[3]; double dMdt_organic, L_dot_organic, dxdt_organic[3]; double dMdt_aqueous, L_dot_aqueous, dxdt_aqueous[3]; double dTdt_HAcTank, dLdt_HAcTank, dxdt_HAcTank[7], dMdt_HAcTank; //others int i, j, n; double sum1, sum2, sum3, dummy[1], AAA, BBB, CCC; double temp_P, temp_HL[1], temp_HV[1], temp_T[1], temp_x[1][3], temp_y[1][3]; double X[7]={0., 0., 0., 0., 0., 0., 0.}, Y[7]={0., 0., 0., 0., 0., 0., 0.}, X_bottom[1][7]= {{0., 0., 0., 0., 0., 0., 0.},}, X_HAc[1][7]={0., 0., 0., 0., 0., 0., 0.}; double aaa[36]= {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,}; double bbb[6] = {0., 0., 0., 0., 0., 0.}; double error=1.0; double beta=1.0; int indx[6] = {0, 0, 0, 0, 0, 0}; //Initialization //In the column and the decanter, three component variables are used in the calculation, while in the HAc tank, seven component variables are used //Tray number is counted from bottom (1) to top (20) for (i=0;i1e-10) { error=0.; for (i=0;i<3;i++) error+=(K[i]-1)*y[NT-1][i]/(1+beta*(K[i]-1)); beta+=0.1*error; }; aaa[0]=1.; aaa[3]=-K[0]; aaa[7]=1.; aaa[10]=-K[1]; aaa[14]=1.; aaa[17]=-K[2]; aaa[18]=beta*V[NT-1]; aaa[21]=(1-beta)*V[NT-1]; aaa[25]= beta*V[NT-1]; aaa[28]= (1-beta)*V[NT-1]; aaa[32]= beta*V[NT-1]; aaa[35]= (1-beta)*V[NT-1]; bbb[3]=V[NT-1]*y[NT-1][0]; bbb[4]=V[NT-1]*y[NT-1][1]; bbb[5]=V[NT-1]*y[NT-1][2]; Ludcmp(6, aaa, indx); Lubksb(6, aaa, indx, bbb); F_organic=beta*V[NT-1]; F_aqueous=V[NT-1]-F_organic; for (i=0;i<3;i++) { organic_x[i]=bbb[i]; aqueous_x[i]=bbb[i+3]; }; *beta_out=beta; //Time derivatives from material balances for total holdup and component holdup /*Inside Column*/ for (i=1;i<(NT-1);i++) { dMdt[i] = L[i+1]- L[i]+ V[i-1]- V[i]; dMxdt[i][0]= L[i+1]*x[i+1][0] - L[i]*x[i][0] + V[i-1]*y[i-1][0] - V[i]*y[i][0]; dMxdt[i][2]= L[i+1]*x[i+1][2] - L[i]*x[i][2] + V[i-1]*y[i-1][2] - V[i]*y[i][2]; }; /* Correction for feed at the feed stage */ dMdt[NF-1] = dMdt[NF-1] + FL; dMxdt[NF-1][0]= dMxdt[NF-1][0] + FL*x_F[0][0]; dMxdt[NF-1][2]= dMxdt[NF-1][2] + FL*x_F[0][2]; /* Bottom*/ dMdt[0] = L[1]- L[0]+ VB - V[0]; dMxdt[0][0]= L[1]*x[1][0] - V[0]*y[0][0] + VB*yB[0][0] - L[0]*x[0][0]; dMxdt[0][2]= L[1]*x[1][2] - V[0]*y[0][2] + VB*yB[0][2] - L[0]*x[0][2]; /*Top*/ dMdt[NT-1] = V[NT-2] - L[NT-1] + LR - V[NT-1]; dMxdt[NT-1][0]= V[NT-2]*y[NT-2][0] + LR*x_organic[0][0] - L[NT-1]*x[NT-1][0] - V[NT-1]*y[NT-1][0]; dMxdt[NT-1][2]= V[NT-2]*y[NT-2][2] + LR*x_organic[0][2] - L[NT-1]*x[NT-1][2] - V[NT-1]*y[NT-1][2]; /* Compute the derivative for the mole fractions from d(Mx) = x dM + M dx */ for (i=0;i