(* 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) *) (* Doing a simple PT Flash Calculations ... Specify P, T, Antoine Coefficients, Total Feed, Feed Composition ... Calculate Liquid, Vapor ... In this problem, we assume ideal gas, ideal liquid ... obviously it will be more interesting to include activity coefficient models, fugacity calculations from equation of state ... *) (* 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 vaporpressure; components IS_A set OF symbol_constant; components :== ['acetone','acetonitrile','nitromethane']; TA IS_A factor; PA IS_A factor; F IS_A positive_factor; V IS_A positive_factor; L IS_A positive_factor; kv[components] IS_A factor; Aterm[components], Bterm[components], Cterm[components] IS_A factor; z[components], x[components], y[components] IS_A fraction; FOR i IN components CREATE eq1[i]: z[i]*F = y[i]*V + x[i]*L; END FOR; FOR i IN components CREATE eq2[i]: y[i] = kv[i]*x[i]; END FOR; FOR i IN components CREATE eq3[i]:kv[i] = exp(Aterm[i] - Bterm[i]/(TA + Cterm[i]))/PA; END FOR; eq4: F = L + V; eq5: SUM[y[i] | i IN components] - SUM[x[i] | i IN components] = 0.0; METHODS METHOD clear; x[components].fixed := FALSE; y[components].fixed := FALSE; z[components].fixed := FALSE; Aterm[components].fixed := FALSE; Bterm[components].fixed := FALSE; Cterm[components].fixed := FALSE; TA.fixed := FALSE; PA.fixed := FALSE; kv[components].fixed := FALSE; F.fixed := FALSE; L.fixed := FALSE; V.fixed := FALSE; END clear; METHOD seqmod; Aterm[components].fixed := TRUE; Bterm[components].fixed := TRUE; Cterm[components].fixed := TRUE; TA.fixed := TRUE; PA.fixed := TRUE; z[components].fixed := TRUE; x[components].fixed := FALSE; y[components].fixed := FALSE; kv[components].fixed := FALSE; F.fixed := TRUE; L.fixed := FALSE; V.fixed := FALSE; END seqmod; METHOD specify; RUN seqmod; END specify; METHOD reset; RUN clear; RUN specify; END reset; END vaporpressure; MODEL antoine_constants; vpressure IS_A vaporpressure; METHODS METHOD values; vpressure.Aterm['acetone'] := 14.5463; vpressure.Aterm['acetonitrile'] := 14.2724; vpressure.Aterm['nitromethane'] := 14.2043; vpressure.Bterm['acetone'] := 2940.46; vpressure.Bterm['acetonitrile'] := 2945.47; vpressure.Bterm['nitromethane'] := 2972.64; vpressure.Cterm['acetone'] := 237.22; vpressure.Cterm['acetonitrile'] := 224.00; vpressure.Cterm['nitromethane'] := 209.00; vpressure.TA := 80.0; vpressure.PA := 110.0; vpressure.z['acetone'] := 0.45; vpressure.z['acetonitrile'] := 0.35; vpressure.z['nitromethane'] := 0.20; vpressure.F := 100.0; END values; METHOD clear; RUN vpressure.clear; END clear; METHOD seqmod; RUN vpressure.seqmod; END seqmod; METHOD specify; RUN vpressure.specify; END specify; METHOD reset; RUN vpressure.specify; END reset; END antoine_constants; MODEL do_the_test; fs IS_A antoine_constants; METHODS METHOD clear; RUN fs.clear; END clear; METHOD seqmod; RUN fs.seqmod; END seqmod; METHOD specify; RUN fs.specify; END specify; METHOD reset; RUN fs.reset; END reset; METHOD values; RUN fs.values; END values; END do_the_test;