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

Contents of /trunk/models/sensitivity_test.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1163 - (show annotations) (download) (as text)
Wed Jan 17 06:33:30 2007 UTC (15 years, 5 months ago) by johnpye
File MIME type: text/x-ascend
File size: 1997 byte(s)
Refactored sensitivity module a little further, added self_test.
1 (* ASCEND modelling environment
2 Copyright (C) 1996 Carnegie Mellon University
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *)
20 REQUIRE "system.a4l";
21 IMPORT "sensitivity/sensitivity";
22 (*
23 This module is used to calculate the sensitity matrix dX/dU where
24 X is a vector OF vapor compositions and U is a vector OF liquid
25 compositions. This sensitivity matrix is THEN used to calculate
26 J, the Jacobian, as described IN Fidkowski et al. (1995).
27
28 by Ben Allan, 1996
29 Self-testing added by John Pye, 2007
30 *)
31
32 MODEL sensitivity_test;
33 nc IS_A integer_constant;
34 X[1..nc] IS_A solver_var;
35 U[1..nc] IS_A solver_var;
36 dx_du[1..nc][1..nc] IS_A solver_var;
37
38 (* system for investigation *)
39 k,x,y,u IS_A solver_var;
40 k*x - y = 7;
41 y = u^2;
42 (* hence, dx/du = 2*u/k *)
43
44 nc:==1;
45 u,U[1] ARE_THE_SAME;
46 x,X[1] ARE_THE_SAME;
47
48 METHODS
49 METHOD values;
50 FOR j IN [1..nc] DO
51 U[j] := j;
52 END FOR;
53 END values;
54
55 METHOD specify;
56 FIX u, k;
57 END specify;
58
59 METHOD on_load;
60 RUN reset;
61 RUN values;
62 END on_load;
63
64 METHOD analyse;
65 EXTERNAL do_sensitivity(SELF,U[1..nc],X[1..nc],dx_du[1..nc][1..nc]);
66 END analyse;
67
68 METHOD self_test;
69 FOR i IN [1..nc] DO (* X[i] *)
70 FOR j IN [1..nc] DO (* U[j] *)
71 ASSERT abs(dx_du[i][j] - 2*U[j]/k) < 0.00001 * 2 * U[j]/k;
72 END FOR;
73 END FOR;
74 END self_test;
75 END sensitivity_test;

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