(* This is written in the ASCEND Language ... ASCEND is an environment to pose modeling problems and solve the resulting equations in an object oriented fashion ... ASCEND is copyrighted by Carnegie Mellon University ... the project has been directed by Prof. Art Westerberg in the Chemical Engineering Department ...*) (* ASCEND is free software, released under GNU ... and you can get it from http://www.cs.cmu.edu/~ascend ... The software has been released WITH source code ... it compiles under Solaris, Linux and IRIX (SGI) ... thanks to the excellent job in putting the software together by the folks at CMU! ... and autoconf ... I have no idea of how people compiled things before ./configure ! *) (* This example written by Krishnan Chittur (chitturk@uah.edu) Chemical Engineering Department, University of Alabama in Huntsville, Huntsville, AL 35899 (205) 890 6850 (V), (205) 890 6839 (FAX) *) (* This is the NRTL Model for liquid phase activity coefficients ... contains information pertinent to the 1998 AIChE student design problem *) (* obviously the modeling style here is primitive ... write down the equations all together in one model and solve it .. it can get quite confusing for real problems!*) REQUIRE "atoms.a4l"; MODEL nrtl; components IS_A set OF symbol_constant; components :== ['acetonitrile','toluene','water','pxylene']; x[components] IS_A fraction; G[components][components] IS_A factor; tau[components][components] IS_A factor; gamma[components] IS_A factor; A[components][components] IS_A molar_energy; alpha[components][components] IS_A factor; term1[components] IS_A factor; term2[components] IS_A factor; term3[components] IS_A factor; term4[components] IS_A factor; term5[components] IS_A factor; term6[components] IS_A factor; RG IS_A gas_constant; TA IS_A temperature; FOR i IN components CREATE term1[i] = SUM[tau[k][i]*G[k][i]*x[k] | k IN components]; term2[i] = SUM[G[k][i]*x[k] | k IN components]; FOR j IN components CREATE term3[j] = SUM[G[m][j]*x[m] | m IN components]; term4[j] = SUM[x[n]*tau[n][j]*G[n][j] | n IN components]; term5[j] = SUM[G[k][j]*x[k] | k IN components]; END FOR; term6[i] = SUM[x[j]*G[i][j]*(tau[i][j] - term4[j]/term5[j])/term3[j] | j IN components]; ln(gamma[i]) = term1[i]/term2[i] + term6[i]; END FOR; FOR i IN components CREATE FOR j IN components CREATE tau[j][i] = A[j][i]/(RG*TA); END FOR; END FOR; FOR i IN components CREATE FOR j IN components CREATE G[j][i] = exp(-alpha[j][i]*tau[j][i]); END FOR; END FOR; METHODS METHOD clear; x[components].fixed := FALSE; G[components][components].fixed := FALSE; tau[components][components].fixed := FALSE; A[components][components].fixed := FALSE; alpha[components][components].fixed := FALSE; TA.fixed := FALSE; END clear; METHOD specify; x[components].fixed := TRUE; G[components][components].fixed := FALSE; tau[components][components].fixed := FALSE; A[components][components].fixed := TRUE; alpha[components][components].fixed := TRUE; TA.fixed := TRUE; END specify; METHOD values; x['acetonitrile'] := 0.2; x['toluene'] := 0.3; x['water'] := 0.3; x['pxylene'] := 0.2; A['acetonitrile']['acetonitrile'] := 0 {cal/mole}; A['toluene']['acetonitrile'] := 724.0 {cal/mole}; A['water']['acetonitrile'] := 1217.0 {cal/mole}; A['pxylene']['acetonitrile'] := -210 {cal/mole}; A['acetonitrile']['toluene'] := 790 {cal/mole}; A['toluene']['toluene'] := 0 {cal/mole}; A['water']['toluene'] := 4375.0 {cal/mole}; A['pxylene']['toluene'] := -242 {cal/mole}; A['acetonitrile']['water'] := 1100 {cal/mole}; A['toluene']['water'] := 5680.0 {cal/mole}; A['water']['water'] := 0 {cal/mole}; A['pxylene']['water'] := 2456 {cal/mole}; A['acetonitrile']['pxylene'] := 1413 {cal/mole}; A['toluene']['pxylene'] := 226.0 {cal/mole}; A['water']['pxylene'] := 1387.2 {cal/mole}; A['pxylene']['pxylene'] := 0 {cal/mole}; alpha['acetonitrile']['acetonitrile'] := 0; alpha['toluene']['acetonitrile'] := 0.9353; alpha['water']['acetonitrile'] := 0.5654; alpha['pxylene']['acetonitrile'] := 0.294; alpha['acetonitrile']['toluene'] := 0.9353; alpha['toluene']['toluene'] := 0; alpha['water']['toluene'] := 0.2; alpha['pxylene']['toluene'] := 0.287; alpha['acetonitrile']['water'] := 0.5654; alpha['toluene']['water'] := 0.2; alpha['water']['water'] := 0; alpha['pxylene']['water'] := 0.2; alpha['acetonitrile']['pxylene'] := 0.294; alpha['toluene']['pxylene'] := 0.287; alpha['water']['pxylene'] := 0.2; alpha['pxylene']['pxylene'] := 0; TA := 300.0 {K}; END values; END nrtl;