/[ascend]/trunk/models/ratelaws.a4c
ViewVC logotype

Contents of /trunk/models/ratelaws.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (15 years, 5 months ago) by aw0a
File MIME type: text/x-ascend
File size: 5337 byte(s)
Setting up web subdirectory in repository
1 REQUIRE "atoms.a4l";
2 (* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
3 PROVIDE "ratelaws.a4c";
4 (*
5 * This file is part of the ASCEND Modeling Library and is released
6 * under the GNU Public License as described at the end of this file.
7 *
8 * Use of this module requires an empty ascend system.
9 *)
10
11 MODEL rxntest;
12
13 (* this MODEL is generic to all reacting systems that conserve mass *)
14 species IS_A set OF symbol_constant;
15 (* all the species in our system *)
16 species :== ['A','B','C','D'];
17
18 rxns IS_A set OF integer_constant;
19 (* all the chemical reactions we will model *)
20 rxns :== [1..3];
21
22 reactants[rxns] IS_A set OF symbol_constant;
23 (* species participating in each reaction *)
24 reactants[1] :== ['A','B','C'];
25 reactants[2] :== ['A','C'];
26 reactants[3] :== ['A','B','D'];
27
28 reactions[species] IS_A set OF integer_constant;
29 (* reactions each species participates in *)
30 FOR i IN species CREATE
31 reactions[i] :== [j IN rxns SUCH_THAT i IN reactants[j]];
32 END FOR;
33
34 (* sparse stoichiometric matrix. nu could be a variable if needed *)
35 FOR j IN rxns CREATE
36 FOR i IN reactants[j] CREATE
37 nu[i][j] IS_A integer_constant;
38 (* mole i/mole rxn j*)
39 END FOR;
40 END FOR;
41
42
43 production[species] IS_A molar_rate;
44 (* production rates of all species *)
45
46 rate[rxns] IS_A molar_rate;
47 (* mole rxn j/time *)
48
49 (* generic conservation of species equations. *)
50 FOR i IN species CREATE
51 netgen[i]: production[i] =
52 SUM[nu[i][j]*rate[j] SUCH_THAT j IN reactions[i]];
53 END FOR;
54
55 END rxntest;
56
57 MODEL ratetest REFINES rxntest;
58 (* some less generic rate equations that assume
59 * elementary reaction kinetics and forward-only mechanisms
60 * written in mole fraction terms.
61 *)
62
63 x[species] IS_A mole_fraction;
64 k[rxns] IS_A real; (* rate coefficient values the user must specify *)
65 FOR j IN rxns CREATE
66 ratelaw[j]:
67 rate[j] =
68 k[j]*
69 PROD[
70 PROD[ x[i] | m IN [1..-(nu[i][j])]]
71 | i IN reactants[j] ];
72 END FOR;
73 (*
74 * note this equation filters out the rhs stoichiometric coefficents
75 * because [m..n] where (n < m) == empty set, [].
76 *)
77 END ratetest;
78
79
80 (* very specific chemistry *)
81 MODEL kintest REFINES ratetest;
82 (* stoichiometric coefficients *)
83 (* rxn 1 *)
84 nu['A'][1] :== -2;
85 nu['B'][1] :== -1;
86 nu['C'][1] :== 1;
87 (* rxn 2 *)
88 nu['A'][2] :== -1;
89 nu['C'][2] :== 3;
90 (* rxn 3 *)
91 nu['A'][3] :== 1;
92 nu['B'][3] :== -1;
93 nu['D'][3] :== 1;
94 END kintest;
95
96 MODEL rxntest2;
97
98 (* Here is the dense version without the extra-silly sets.
99 * It gives equivalent eqns, but has extra constants defined.
100 * When moving to several dozen species and rxns, this is not
101 * scalable.
102 *)
103 species IS_A set OF symbol_constant;
104 species :== ['A','B','C','D'];
105
106 rxns IS_A set OF integer_constant;
107 rxns :== [1..3];
108
109 reactants[rxns] IS_A set OF symbol_constant;
110 (* species in each rxn *)
111 reactants[1] :== ['A','B','C'];
112 reactants[2] :== ['A','C'];
113 reactants[3] :== ['A','B','D'];
114
115 reactions[species] IS_A set OF integer_constant;
116 (* rxns for each species *)
117 FOR i IN species CREATE
118 reactions[i] :== [j IN rxns | i IN reactants[j]];
119 END FOR;
120
121 nu[species][rxns] IS_A real_constant; (* mole i/mole rxn j*)
122
123 (* rxn 1 *)
124 nu['A'][1] :== -2;
125 nu['B'][1] :== -1;
126 nu['C'][1] :== 1;
127 nu['D'][1] :== 0;
128 (* rxn 2 *)
129 nu['A'][2] :== -1;
130 nu['B'][2] :== 0;
131 nu['C'][2] :== 3;
132 nu['D'][2] :== 0;
133 (* rxn 3 *)
134 nu['A'][3] :== 1;
135 nu['B'][3] :== -1;
136 nu['C'][3] :== 0;
137 nu['D'][3] :== 1;
138 (* this data entry would be much much much easier in the
139 * table data syntax we don't have implemented yet.
140 *)
141
142 production[species] IS_A molar_rate;
143 rate[rxns] IS_A molar_rate; (* mole rxn j/time *)
144
145 FOR i IN species CREATE
146 netgen[i]: production[i] = SUM[nu[i][j]*rate[j] |j IN rxns];
147 END FOR;
148
149 END rxntest2;
150
151
152 (*
153 * ratetest.a4c
154 * by Benjamin Allan
155 * Part of the ASCEND Library
156 * $Date: 1998/06/17 19:23:05 $
157 * $Revision: 1.2 $
158 * $Author: mthomas $
159 * $Source: /afs/cs.cmu.edu/project/ascend/Repository/models/ratelaws.a4c,v $
160 *
161 * This file is part of the ASCEND Modeling Library.
162 *
163 * Copyright (C) 1997 Benjamin Allan
164 *
165 * The ASCEND Modeling Library is free software; you can redistribute
166 * it and/or modify it under the terms of the GNU General Public
167 * License as published by the Free Software Foundation; either
168 * version 2 of the License, or (at your option) any later version.
169 *
170 * The ASCEND Modeling Library is distributed in hope that it will be
171 * useful, but WITHOUT ANY WARRANTY; without even the implied
172 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
173 * See the GNU General Public License for more dnuils.
174 *
175 * You should have received a copy of the GNU General Public License
176 * along with the program; if not, write to the Free Software
177 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
178 * the file named COPYING.
179 *)

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22