/[ascend]/trunk/base/generic/compiler/rel_blackbox.h
ViewVC logotype

Annotation of /trunk/base/generic/compiler/rel_blackbox.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1031 - (hide annotations) (download) (as text)
Wed Jan 3 15:33:23 2007 UTC (17 years, 9 months ago) by johnpye
File MIME type: text/x-chdr
File size: 5903 byte(s)
Merging Ben's changes from trunk, changeset 1105 to changeset 1234.
This breaks Python test suite TestExtFn, so will need investigation.
1 johnpye 909 /*
2     ASCEND Language Interpreter
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 of the License, or
8     (at your option) 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18     This file is part of the SLV solver.
19     *//** @file
20    
21     @NOTE blackbox equations support the form
22    
23     output[i] = f(input[j] for all j) foreach i
24    
25 johnpye 908 which we calculate by calling yhat = f(x),
26 johnpye 909 and then residual is (y - yhat).
27 johnpye 908 */
28    
29 johnpye 909 #ifndef ASC_REL_BLACKBOX_H
30     #define ASC_REL_BLACKBOX_H
31    
32 johnpye 908 extern int BlackBoxCalcResidual(struct Instance *i, double *res, struct relation *r);
33    
34     /** Compute standard form residual and gradient.
35     See relation_util.h gradient functions
36     for additional notes on the gradient output array and varlist.
37     @param i the relation instance in question.
38     @param residual the residual computed (output).
39     @param gradient the gradient computed (output), an array as long as r->varlist
40     and with elements corresponding to the elements of varlist.
41     @param r the relation data from i.
42     */
43     extern int BlackBoxCalcResidGrad(struct Instance *i, double *residual, double *gradient, struct relation *r);
44    
45     /** Compute standard form gradient.
46     See relation_util.h gradient functions
47     for additional notes on the gradient output array and varlist.
48     @param i the relation instance in question.
49     @param gradient the gradient computed (output), an array as long as r->varlist
50     and with elements corresponding to the elements of varlist.
51     @param r the relation data from i.
52     */
53     extern int BlackBoxCalcGradient(struct Instance *i, double *gradient, struct relation *r);
54    
55     /**
56     Return the output variable instance from r, assuming r is from a blackbox.
57     */
58 johnpye 1031 extern struct Instance *BlackBoxGetOutputVar(CONST struct relation *r);
59 johnpye 908
60     /** All the relations evaluated in a single call to y=f(x) have this data in common. */
61     struct BlackBoxCache { /* was extrelcache, sort of. */
62 johnpye 1031 struct gl_list_t *argListNames; /**< list of list of names. */
63     struct Name *dataName; /**< name of the DATA instance. */
64     struct ExternalFunc *efunc; /**< external function table. */
65 johnpye 908 struct BBoxInterp interp; /**< userdata lives in here only */
66     int32 inputsLen; /**< number of actual, not formal, inputs */
67     int32 outputsLen; /**< number of actual, not formal, outputs. */
68     int32 jacobianLen;
69     int32 hessianLen;
70     double *inputs; /**< aka x; previous input for func eval. */
71     double *outputs; /**< aka yhat. previous output for func eval. */
72     double *inputsJac; /**< aka x; previous input for gradient eval. */
73     double *jacobian; /**< sensitivity dyhat/dx ; row major format; previous gradient output. */
74     double *hessian; /**< undetermined format */
75     int residCount; /**< number of calls made for y output. */
76     int gradCount; /**< number of calls made for gradient. */
77 johnpye 1031 int refCount; /**< when to destroy */
78     int count; /**< serial number */
79 johnpye 908 };
80    
81 johnpye 1031 /** Fetch the input array len size.
82     @param bbc the source.
83     */
84     extern int32 BlackBoxCacheInputsLen(struct BlackBoxCache *bbc);
85    
86 johnpye 908 /** All the elements of an array of blackbox relations resulting
87     from a single external statement have the BlackBoxCache in common, but
88     the varlist and lhs are unique to the specific relation.
89     If someone really needs a nodestamp, for some reason,
90     the 'common' pointer is unique to the set.
91     */
92     struct BlackBoxData {
93     struct BlackBoxCache *common;
94 johnpye 1031 int count;
95 johnpye 908 };
96    
97 johnpye 1031 /** make a blackboxdata unique to a single relation.
98     @param common the data common to all the relations in the array of blackbox output relations.
99     @param lhsindex the index of this relation's residual in the blackbox output vector.
100     @param lhsVarNumber the index of the output variable (y) in the relation's varlist.
101     */
102     extern struct BlackBoxData *CreateBlackBoxData(struct BlackBoxCache *common);
103 johnpye 908
104 johnpye 1031 /* do anoncopy of bbox data for relation sharing. */
105     extern void CopyBlackBoxDataByReference(struct relation *src, struct relation *dest, void *bboxtable_p);
106    
107 johnpye 908 /* called when destroying the relation containing b. */
108     extern void DestroyBlackBoxData(struct relation * rel, struct BlackBoxData *b);
109    
110     /**
111     Returns an initialized common data for a blackbox relation array
112     with an initial refcount 1.
113     Call DeleteRefBlackBoxCache when done with the object, and
114     make a call to AddRef any time the pointer is stored in a
115     persistent structure.
116     @param inputsLen number of actual, not formal, inputs.
117     @param outputsLen number of actual, not formal, outputs.
118 johnpye 1031 @param argListNames list of lists of names of real atom instances in/output.
119     @param dataName name of the data instance.
120 johnpye 908 */
121 johnpye 1031 extern struct BlackBoxCache *CreateBlackBoxCache( int32 inputsLen, int32 outputsLen, struct gl_list_t *argListNames, struct Name *dataName, struct ExternalFunc *efunc);
122 johnpye 908
123     /** make a persistent reference to b. */
124     extern void AddRefBlackBoxCache(struct BlackBoxCache *b);
125    
126 johnpye 1031 /** dispatch the init function on a bbox after updating the input instance list
127     from the names list.
128     @param context the parent model containing the relations the cache is
129     referenced by.
130     @param b a cache in need of the init call.
131     */
132     extern void InitBBox(struct Instance *context, struct BlackBoxCache *b);
133    
134 johnpye 908 /** remove a persistent reference to *b.
135     sets *b to null before returning.
136     deallocates **b if refcount has dropped to 0.
137     */
138     extern void DeleteRefBlackBoxCache(struct relation *rel, struct BlackBoxCache **b);
139    
140    
141     #endif /* ASC_REL_BLACKBOX_H */

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