~jdpipe/ascend/trunk-old

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
REQUIRE "atoms.a4l";
(* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
PROVIDE "kinetics.a4l";

(*
 *  kinetics.a4l
 *  by Duncan Coffey
 *  Part of the ASCEND Library
 *  $Date: 1998/06/17 19:10:29 $
 *  $Revision: 1.3 $
 *  $Author: mthomas $
 *  $Source: /afs/cs.cmu.edu/project/ascend/Repository/models/kinetics.a4l,v $
 *
 *  This file is part of the ASCEND Modeling Library.
 *
 *  Copyright (C) 1998 Duncan Coffey
 *
 *  The ASCEND Modeling Library is free software; you can redistribute
 *  it and/or modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  The ASCEND Modeling Library is distributed in hope that it
 *  will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *)


(* ************************************************************************ *)
(* ********************           Kinetics             ******************** *)
(* ************************************************************************ *)
MODEL base_kinetics(
    components		       	IS_A set OF symbol_constant;
    nr			       	IS_A set OF symbol_constant;
    Kr[nr]	      		IS_A constant;
    active_energy[nr]		IS_A constant;
    reac_T			WILL_BE temperature;
    species[nr]		       	IS_A set OF symbol_constant;
    nu[components][nr]		WILL_BE integer_constant;
    conc[components]		WILL_BE molar_density;
)WHERE(

)REFINES cmumodel;
NOTES
'purpose' SELF {
This MODEL computes the production rates per volume of the reactant
speices given.  There are three possible models to use.

base_kinetics - No rate law is constructed and is expected to be given
by the user. Production rates are then calculated from the given rate laws.

nr - names of reactions
Kr[nr] - rate constants
species[nr] - set of components involved in each reaction
nu[components][nr] - stoichiometry for each components and reaction
conc[components] - Concentrations used in rate laws.

element_kinetics - Here the rate laws are constructed from the
stoichiometry (nu) given.

specify_kinetics - Here the rate laws are constructed from the orders (order) given.

}
'developer-Duncan' SELF {From the element_kinetics and
specify_kinetics most rate laws can be constructed. However in many cases
there may need to be intermediate steps and it might just be easier to
use base_kinetics.
}
END NOTES;

    rate[nr]		       	IS_A conc_rate;
    reactions[components]     	IS_A set OF symbol_constant;
    production[components]     	IS_A conc_rate;
    Ftot_scale			IS_A scaling_constant;
    R				IS_A molar_gas_constant;

    (* Define the production rate for a component *)
    FOR i IN components CREATE
	production[i] / Ftot_scale = SUM[nu[i][j]*rate[j] | j IN reactions[i]] / Ftot_scale;
    END FOR;

    (* define rxns where each component is present *)
    FOR i IN components CREATE
	reactions[i] :== [j IN nr | i IN species[j]];
    END FOR;

    METHODS

    METHOD default_self;
	rate[nr].lower_bound :=-1e100 {mole/m^3/s};
	production[components].lower_bound :=-1e100 {mole/m^3/s};
	Ftot_scale :=1000;
    END default_self;

    METHOD default_all;
	RUN reac.default_self;
    END default_all;

    METHOD check_self;
    END check_self;

    METHOD check_all;
	RUN check_self;
    END check_all;

    METHOD bound_self;
    END bound_self;

    METHOD bound_all;
	RUN bound_self;
    END bound_all;

    METHOD scale_self;
    END scale_self;

    METHOD scale_all;
	RUN scale_self;
    END scale_all;

    METHOD seqmod;
	FIX conc[components];
	FIX reac_T;
    END seqmod;

    METHOD specify;
	RUN seqmod;
    END specify;
END base_kinetics;


MODEL element_kinetics(
    components		       	IS_A set OF symbol_constant;
    nr			       	IS_A set OF symbol_constant;
    Kr[nr]	      		IS_A constant;
    active_energy[nr]		IS_A constant;
    reac_T			WILL_BE temperature;
    species[nr]		       	IS_A set OF symbol_constant;
    nu[components][nr]		WILL_BE integer_constant;
    conc[components]		WILL_BE molar_density;
)WHERE(

)REFINES base_kinetics;

    (* define the rate equations for each component *)
    FOR j IN nr CREATE
	rate[j] / Ftot_scale = (Kr[j]*exp(-active_energy[j]/R/reac_T)*PROD[
	PROD[ conc[i] | m IN [1..-(nu[i][j])]] | i IN species[j]]) / Ftot_scale;
    END FOR;



    METHODS

    METHOD default_self;
	rate[nr].lower_bound :=-1e100 {mole/m^3/s};
	production[components].lower_bound :=-1e100 {mole/m^3/s};
	Ftot_scale :=1000;
    END default_self;

    METHOD default_all;
	RUN reac.default_self;
    END default_all;

    METHOD check_self;
    END check_self;

    METHOD check_all;
	RUN check_self;
    END check_all;

    METHOD bound_self;
    END bound_self;

    METHOD bound_all;
	RUN bound_self;
    END bound_all;

    METHOD scale_self;
    END scale_self;

    METHOD scale_all;
	RUN scale_self;
    END scale_all;

    METHOD seqmod;
	FIX conc[components];
	FIX reac_T;
    END seqmod;

    METHOD specify;
	RUN seqmod;
    END specify;

END element_kinetics;


MODEL specify_kinetics(
    components		       	IS_A set OF symbol_constant;
    nr			       	IS_A set OF symbol_constant;
    Kr[nr]	      		IS_A constant;
    active_energy[nr]		IS_A constant;
    reac_T			WILL_BE temperature;
    species[nr]		       	IS_A set OF symbol_constant;
    nu[components][nr]		WILL_BE integer_constant;
    conc[components]		WILL_BE molar_density;
    order[components][nr]      	WILL_BE constant;
)WHERE(

)REFINES base_kinetics;


    (* define the rate equations for each component *)
    FOR j IN nr CREATE
	rate[j] / Ftot_scale = (Kr[j]*exp(-active_energy[j]/R/reac_T)*
	   PROD[conc[i]^order[i][j] | i IN species[j]]) / Ftot_scale;
    END FOR;

    METHODS

    METHOD default_self;
	rate[nr].lower_bound 			:=-1e100 {mole/m^3/s};
	production[components].lower_bound	:=-1e100 {mole/m^3/s};
	Ftot_scale				:=1000;
    END default_self;

    METHOD seqmod;
	FIX conc[components];
	FIX reac_T;
    END seqmod;

    METHOD specify;
	RUN seqmod;
    END specify;

END specify_kinetics;

MODEL test_elm_kinetics;
    components		       	IS_A set OF symbol_constant;
    nr			       	IS_A set OF symbol_constant;
    Kr[nr]	      		IS_A constant;
    active_energy[nr]		IS_A constant;
    reac_T			IS_A temperature;
    species[nr]		       	IS_A set OF symbol_constant;
    nu[components][nr]		IS_A integer_constant;
    conc[components]		IS_A molar_density;


    components	:==['methane','ethane','n_butane'];
    nr		:==['reaction_1','reaction_2'];
    species['reaction_1']	:==['methane','ethane'];
    species['reaction_2']	:==['methane','ethane'];
    Kr['reaction_1']		:==2 {m^3/mol/s};
    Kr['reaction_2']		:==3 {1/s};
    active_energy['reaction_1']	:==70000 {J};
    active_energy['reaction_2']	:==70000 {J};

    nu['methane']['reaction_1']	:==-2;
    nu['ethane']['reaction_1']	:==1;
    nu['methane']['reaction_2']	:==2;
    nu['ethane']['reaction_2']	:==-1;
    (* define nu=0 FOR components not IN reactions*)
    FOR i IN nr CREATE
	FOR j IN components - [species[i]] CREATE
	    nu[j][i]	:==0;
	END FOR;
    END FOR;



    reac IS_A element_kinetics(components, nr, Kr, active_energy,
                               reac_T, species, nu, conc);

    METHODS

    METHOD default_self;
	RUN reac.default_self;
    END default_self;

    METHOD default_all;
	RUN reac.default_self;
    END default_all;

    METHOD check_self;
    END check_self;

    METHOD check_all;
	RUN check_self;
    END check_all;

    METHOD bound_self;
    END bound_self;

    METHOD bound_all;
	RUN bound_self;
    END bound_all;

    METHOD scale_self;
    END scale_self;

    METHOD scale_all;
	RUN scale_self;
    END scale_all;
END test_elm_kinetics;

MODEL test_ord_kinetics;
    components		       	IS_A set OF symbol_constant;
    nr			       	IS_A set OF symbol_constant;
    Kr[nr]	      		IS_A constant;
    active_energy[nr]		IS_A constant;
    reac_T			IS_A temperature;
    species[nr]		       	IS_A set OF symbol_constant;
    nu[components][nr]		IS_A integer_constant;
    order[components][nr]      	IS_A constant;
    conc[components]		IS_A molar_density;


    components	:==['methane','ethane','n_butane'];
    nr		:==['reaction_1','reaction_2'];
    species['reaction_1']	:==['methane','ethane'];
    species['reaction_2']	:==['methane','ethane'];
    Kr['reaction_1']		:==2 {m^3/mol/s};
    Kr['reaction_2']		:==3 {1/s};
    active_energy['reaction_1']	:==70000 {J};
    active_energy['reaction_2']	:==70000 {J};

    nu['methane']['reaction_1']	:==-2;
    nu['ethane']['reaction_1']	:==1;
    nu['methane']['reaction_2']	:==2;
    nu['ethane']['reaction_2']	:==-1;
    (* define nu=0 FOR components not IN reactions*)
    FOR i IN nr CREATE
	FOR j IN components - [species[i]] CREATE
	    nu[j][i]	:==0;
	END FOR;
    END FOR;

    order['methane']['reaction_1']	:==2;
    order['ethane']['reaction_1']	:==0;
    order['methane']['reaction_2']	:==3;
    order['ethane']['reaction_2']	:==1;
    FOR i IN nr CREATE
	FOR j IN components - [species[i]] CREATE
	    order[j][i]	:==0;
	END FOR;
    END FOR;

    reac IS_A specify_kinetics(components, nr, Kr, active_energy,
                               reac_T, species, nu, conc, order);

    METHODS
    METHOD default_self;
	RUN reac.default_self;
    END default_self;

    METHOD default_all;
	RUN reac.default_self;
    END default_all;

    METHOD check_self;
    END check_self;

    METHOD check_all;
	RUN check_self;
    END check_all;

    METHOD bound_self;
    END bound_self;

    METHOD bound_all;
	RUN bound_self;
    END bound_all;

    METHOD scale_self;
    END scale_self;

    METHOD scale_all;
	RUN scale_self;
    END scale_all;
END test_ord_kinetics;