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

Contents of /trunk/models/sensitivity_test.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1167 - (show annotations) (download) (as text)
Wed Jan 17 09:32:29 2007 UTC (12 years, 10 months ago) by johnpye
File MIME type: text/x-ascend
File size: 2436 byte(s)
Added (failing) test case for do_sensitivity_all.
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 A very simple test model for the external sensitivity analysis
24 module.
25
26 by Ben Allan, 1996
27 Self-testing added by John Pye, 2007
28
29 --- old comments (don't seem to be accurate) ---
30
31 This module is used to calculate the sensitity matrix dX/dU where
32 X is a vector OF vapor compositions and U is a vector OF liquid
33 compositions. This sensitivity matrix is THEN used to calculate
34 J, the Jacobian, as described IN Fidkowski et al. (1995).
35 *)
36
37 MODEL sensitivity_test;
38 nc IS_A integer_constant;
39 X[1..nc] IS_A solver_var;
40 U[1..nc] IS_A solver_var;
41 dx_du[1..nc][1..nc] IS_A solver_var;
42
43 (* system for investigation *)
44 k,x,y,u IS_A solver_var;
45 k*x - y = 7;
46 y = u^2;
47 (* hence, dx/du = 2*u/k *)
48
49 nc:==1;
50 u,U[1] ARE_THE_SAME;
51 x,X[1] ARE_THE_SAME;
52
53 METHODS
54 METHOD values;
55 FOR j IN [1..nc] DO
56 U[j] := j;
57 END FOR;
58 END values;
59
60 METHOD specify;
61 FIX u, k;
62 END specify;
63
64 METHOD on_load;
65 RUN reset;
66 RUN values;
67 END on_load;
68
69 METHOD analyse;
70 EXTERNAL do_sensitivity(SELF,U[1..nc],X[1..nc],dx_du[1..nc][1..nc]);
71 END analyse;
72
73 METHOD self_test;
74 FOR i IN [1..nc] DO (* X[i] *)
75 FOR j IN [1..nc] DO (* U[j] *)
76 ASSERT abs(dx_du[i][j] - 2*U[j]/k) < 0.00001 * 2 * U[j]/k;
77 END FOR;
78 END FOR;
79 END self_test;
80 END sensitivity_test;
81
82 MODEL sensitivity_test_all REFINES sensitivity_test;
83 U_new[1..nc] IS_A real;
84 stepsize IS_A real_constant;
85 stepsize :== 0.0001;
86 METHODS
87 METHOD analyse;
88 EXTERNAL do_sensitivity_all(SELF,U[1..nc],U_new[1..nc],stepsize);
89 END analyse;
90
91 METHOD self_test;
92 ASSERT 1==0;
93 END self_test;
94 END sensitivity_test_all;

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