/[ascend]/trunk/base/generic/packages/sensitivity.h
ViewVC logotype

Contents of /trunk/base/generic/packages/sensitivity.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1162 - (show annotations) (download) (as text)
Wed Jan 17 04:34:59 2007 UTC (15 years, 5 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4882 byte(s)
Fixed sensitivity module. It now runs as mostly external code, with just a few relics required by LSODE still in packages/sensitivity.c.
1 /* ASCEND modelling environment
2 Copyright (C) 1990-2006 Carnegie-Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 This file is part of the SLV solver.
18 *//** @file
19 Sensitivity add-on for ASCEND
20 by Tom Epperly, Kirk Abbot
21
22 @note This is a static package in ASCEND. It can not be built as a dynamic package
23 because it doesn't contain the self-registration stuff.
24
25 This file attempts to implement the extraction of dy_dx from
26 a system of equations. If one considers a black-box where x are
27 the input variables, u are input parameters, y are the output
28 variables, f(x,y,u) is the system of equations that will be solved
29 for given x and u, then one can extract the sensitivity information
30 of y wrt x.
31
32 One crude but simple way of doing this is to finite-difference the
33 given black box, i.e, perturb x, n\subx times by delta x, resolve
34 the system of equations at the new value of x, and compute
35 dy/dx = (f(x\sub1) - f(x\sub2))/(x\sub1 - x\sub2).
36 This is known to be very expensive.
37
38 The solution that will be adopted here is to formulate the Jacobian J of
39 the system, (or the system is already solved, to grab the jacobian at
40 the solution. Develop the sensitivity matrix df/dx by exact numnerical
41 differentiation; this will be a n x n\subx matrix. Compute the LU factors
42 for J, and to solve column by column to : LU dz/dx = df/dx. Here
43 z, represents all the internal variables to the system and the strictly
44 output variables y. In other words J = df/dz.
45
46 Given the solution of the above problem we then simply extract the rows
47 of dz/dx, that pertain to the y variables that we are interested in;
48 this will give us dy/dx.
49
50 @todo Do we really need 2 files called [Ss]ensitivity.[ch]? Other one is in tcltk.
51
52 @todo Make this self-registering so that it can be compiled as a dlopenable library.
53 */
54
55 #ifndef ASC_SENSITIVITY_H
56 #define ASC_SENSITIVITY_H
57
58 #include <utilities/ascConfig.h>
59 #include <compiler/instance_enum.h>
60 #include <compiler/compiler.h>
61 #include <general/list.h>
62 #include <compiler/extfunc.h>
63
64 #include <solver/mtx.h>
65 #include <solver/mtx_basic.h>
66 #include <solver/mtx_perms.h>
67 #include <solver/mtx_query.h>
68 #include <solver/linsol.h>
69 #include <solver/linsolqr.h>
70 #include <solver/slv_types.h>
71 #include <solver/var.h>
72 #include <solver/rel.h>
73 #include <solver/discrete.h>
74 #include <solver/conditional.h>
75 #include <solver/logrel.h>
76 #include <solver/bnd.h>
77 #include <solver/calc.h>
78 #include <solver/relman.h>
79 #include <solver/slv_common.h>
80 #include <solver/slv_stdcalls.h>
81 #include <solver/system.h>
82 #include <solver/slv_client.h>
83
84 /*--------------------------------------------------
85 The following functions are provided only for use by LSODE. We want to
86 phase this out and replace with a new solver like IDA.
87 */
88 ASC_DLLSPEC int Compute_J(slv_system_t sys);
89 ASC_DLLSPEC int NumberFreeVars(slv_system_t sys);
90 int NumberIncludedRels(slv_system_t sys);
91 int LUFactorJacobian(slv_system_t sys);
92 ASC_DLLSPEC int Compute_dy_dx_smart(slv_system_t sys, real64 *rhs, real64 **dy_dx,
93 int *inputs, int ninputs, int *outputs, int noutputs
94 );
95
96 /*--------------------------------------------------
97 The following are provided to the external module 'sensitivity'. We want
98 to move all of these out into the external shared object, but can't until
99 the LSODE dependency goes away.
100 */
101
102 ASC_DLLSPEC int DoSolve(struct Instance *inst);
103 ASC_DLLSPEC int DoDataAnalysis(struct var_variable **inputs,
104 struct var_variable **outputs,
105 int ninputs, int noutputs,
106 real64 **dy_dx);
107 ASC_DLLSPEC int finite_difference(struct gl_list_t *arglist);
108 ASC_DLLSPEC struct Instance *FetchElement(struct gl_list_t *arglist,
109 unsigned long whichbranch,
110 unsigned long whichelement);
111 ASC_DLLSPEC int NumberRels(slv_system_t sys);
112 ASC_DLLSPEC int LUFactorJacobian1(slv_system_t sys,int rank);
113 ASC_DLLSPEC struct Instance *FetchElement(struct gl_list_t *arglist,
114 unsigned long whichbranch,
115 unsigned long whichelement);
116
117 /* I *think* that we can probably replace these with 'densemtx.h' functions. */
118
119 ASC_DLLSPEC real64 **make_matrix(int nrows, int ncols);
120 ASC_DLLSPEC void free_matrix(real64 **matrix, int nrows);
121
122 #endif /* ASC_SENSITIVITY_H */
123

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