/[ascend]/trunk/base/generic/solver/bnd.c
ViewVC logotype

Annotation of /trunk/base/generic/solver/bnd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (hide annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 3 months ago) by johnpye
File MIME type: text/x-csrc
File size: 7014 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 aw0a 1 /*
2     * Boundary Module
3     * Created: 04/97
4     * Version: $Revision: 1.8 $
5     * Version control file: $RCSfile: bnd.c,v $
6     * Date last modified: $Date: 1997/07/18 12:13:54 $
7     * Last modified by: $Author: mthomas $
8     *
9     * This file is part of the SLV solver.
10     *
11     * The SLV solver is free software; you can redistribute
12     * it and/or modify it under the terms of the GNU General Public License as
13     * published by the Free Software Foundation; either version 2 of the
14     * License, or (at your option) any later version.
15     *
16     * The SLV solver is distributed in hope that it will be
17     * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19     * General Public License for more details.
20     *
21     * You should have received a copy of the GNU General Public License
22     * along with the program; if not, write to the Free Software Foundation,
23     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
24     * COPYING. COPYING is found in ../compiler.
25     *
26     */
27    
28     #include <math.h>
29 johnpye 399 #include <utilities/ascConfig.h>
30     #include <utilities/ascPanic.h>
31     #include <utilities/ascMalloc.h>
32     #include <general/list.h>
33     #include <general/dstring.h>
34     #include <compiler/compiler.h>
35     #include <compiler/fractions.h>
36     #include <compiler/instance_enum.h>
37     #include <compiler/extfunc.h>
38     #include <compiler/extcall.h>
39     #include <compiler/functype.h>
40     #include <compiler/safe.h>
41     #include <compiler/dimen.h>
42 johnpye 669 #include <compiler/expr_types.h>
43 johnpye 399 #include <compiler/find.h>
44     #include <compiler/atomvalue.h>
45     #include <compiler/instquery.h>
46     #include <compiler/mathinst.h>
47     #include <compiler/parentchild.h>
48     #include <compiler/instance_io.h>
49 aw0a 1 #define _SLV_SERVER_C_SEEN_
50 johnpye 399 #include <utilities/mem.h>
51     #include "mtx.h"
52     #include "slv_types.h"
53     #include "var.h"
54     #include "rel.h"
55     #include "discrete.h"
56     #include "conditional.h"
57     #include "logrel.h"
58     #include "bnd.h"
59     #include "slv_server.h"
60 aw0a 1
61     #define IPTR(i) ((struct Instance *)(i))
62     #ifndef DEFTOLERANCE
63     #define DEFTOLERANCE 1e-08
64     #endif /* DEFTOLERANCE */
65    
66    
67     struct bnd_boundary *bnd_create(struct bnd_boundary *newbnd)
68     {
69    
70     if (newbnd==NULL) {
71     newbnd = (struct bnd_boundary *)ascmalloc( sizeof(struct bnd_boundary) );
72     assert(newbnd!=NULL);
73     memset((char *)&(newbnd->cond),0,sizeof(union bnd_union));
74     newbnd->kind = e_bnd_undefined;
75     newbnd->logrels = NULL;
76     newbnd->tolerance = DEFTOLERANCE;
77     newbnd->mindex = -1;
78     newbnd->sindex = -1;
79     newbnd->model = -1;
80     newbnd->flags = BND_IN_LOGREL;
81     } else {
82     memset((char *)&(newbnd->cond),0,sizeof(union bnd_union));
83     newbnd->kind = e_bnd_undefined;
84     newbnd->logrels = NULL;
85     newbnd->tolerance = DEFTOLERANCE;
86     newbnd->mindex = -1;
87     newbnd->sindex = -1;
88     newbnd->model = -1;
89     newbnd->flags = BND_IN_LOGREL;
90     }
91     return(newbnd);
92     }
93    
94    
95 johnpye 224 void bnd_destroy(struct bnd_boundary *bnd)
96 aw0a 1 {
97     if (bnd==NULL) return;
98     if (bnd->logrels != NULL) {
99     gl_destroy(bnd->logrels);
100     bnd->logrels = NULL;
101     }
102     }
103    
104    
105     enum bnd_enum bnd_kind(struct bnd_boundary *bnd)
106     {
107 jds 114 asc_assert(bnd!=NULL);
108 aw0a 1 return bnd->kind;
109     }
110    
111    
112     void bnd_set_kind(struct bnd_boundary *bnd, enum bnd_enum kind)
113     {
114 jds 114 asc_assert(bnd!=NULL);
115 aw0a 1 bnd->kind = kind;
116     }
117    
118    
119     void bnd_set_logrels(struct bnd_boundary *bnd,
120     struct gl_list_t *logrels)
121     {
122 jds 114 asc_assert(bnd!=NULL);
123 aw0a 1 bnd->logrels = logrels;
124     }
125    
126    
127     struct gl_list_t *bnd_logrels(struct bnd_boundary *bnd)
128     {
129 jds 114 asc_assert(bnd!=NULL);
130 aw0a 1 return bnd->logrels;
131     }
132    
133    
134     void bnd_set_tolerance(struct bnd_boundary *bnd,real64 tolerance)
135     {
136 jds 114 asc_assert(bnd!=NULL);
137 aw0a 1 bnd->tolerance = tolerance;
138     }
139    
140    
141     real64 bnd_tolerance(struct bnd_boundary *bnd)
142     {
143 jds 114 asc_assert(bnd!=NULL);
144 aw0a 1 return bnd->tolerance;
145     }
146    
147    
148     char *bnd_make_name(slv_system_t sys,struct bnd_boundary *bnd)
149     {
150     enum bnd_enum kind;
151     struct rel_relation *rel;
152     struct logrel_relation *lrel;
153    
154 jds 114 if ((NULL == sys) || (NULL == bnd)) {
155     return NULL;
156     }
157 aw0a 1 kind = bnd_kind(bnd);
158     if (kind == e_bnd_rel) {
159     rel = bnd_rel(bnd_real_cond(bnd));
160     return WriteInstanceNameString(IPTR(rel_instance(rel)),
161     IPTR(slv_instance(sys)));
162     } else {
163     lrel = bnd_logrel(bnd_log_cond(bnd));
164     return WriteInstanceNameString(IPTR(logrel_instance(lrel)),
165     IPTR(slv_instance(sys)));
166     }
167     }
168    
169    
170     int32 bnd_mindex( struct bnd_boundary *bnd)
171     {
172 jds 114 asc_assert(bnd!=NULL);
173 aw0a 1 return( bnd->mindex );
174     }
175    
176    
177     void bnd_set_mindex( struct bnd_boundary *bnd, int32 index)
178     {
179 jds 114 asc_assert(bnd!=NULL);
180 aw0a 1 bnd->mindex = index;
181     }
182    
183    
184     int32 bnd_sindex( const struct bnd_boundary *bnd)
185     {
186 jds 114 asc_assert(bnd!=NULL);
187 aw0a 1 return( bnd->sindex );
188     }
189    
190    
191     void bnd_set_sindex( struct bnd_boundary *bnd, int32 index)
192     {
193 jds 114 asc_assert(bnd!=NULL);
194 aw0a 1 bnd->sindex = index;
195     }
196    
197    
198     int32 bnd_model(const struct bnd_boundary *bnd)
199     {
200 jds 114 asc_assert(bnd!=NULL);
201 aw0a 1 return((const int32) bnd->model );
202     }
203    
204    
205     void bnd_set_model( struct bnd_boundary *bnd, int32 index)
206     {
207 jds 114 asc_assert(bnd!=NULL);
208 aw0a 1 bnd->model = index;
209     }
210    
211    
212     struct var_variable **bnd_real_incidence(struct bnd_boundary *bnd)
213     {
214     enum bnd_enum kind;
215     struct var_variable **incidence;
216     struct rel_relation *rel;
217 jds 114 kind = bnd_kind(bnd); /* check for bnd==NULL done in bnd_kind() */
218 aw0a 1 if (kind == e_bnd_rel) {
219     rel = bnd_rel(bnd_real_cond(bnd));
220     incidence = rel_incidence_list_to_modify(rel);
221     return incidence;
222     } else {
223     FPRINTF(stderr,"bnd_real_incidence called with incorrect boundary\n");
224     return NULL;
225     }
226     }
227    
228    
229     int32 bnd_n_real_incidences(struct bnd_boundary *bnd)
230     {
231     enum bnd_enum kind;
232     int32 n_incidences;
233     struct rel_relation *rel;
234 jds 114 kind = bnd_kind(bnd); /* check for bnd==NULL done in bnd_kind() */
235 aw0a 1 if (kind == e_bnd_rel) {
236     rel = bnd_rel(bnd_real_cond(bnd));
237     n_incidences = rel_n_incidences(rel);
238     return n_incidences;
239     } else {
240     FPRINTF(stderr,"bnd_n_real_incidences called with incorrect boundary\n");
241     return 0;
242     }
243     }
244    
245    
246     int32 bnd_apply_filter( const struct bnd_boundary *bnd, bnd_filter_t *filter)
247     {
248     if (bnd==NULL || filter==NULL) {
249     FPRINTF(stderr,"bnd_apply_filter miscalled with NULL\n");
250     return FALSE;
251     }
252     return ( (filter->matchbits & bnd->flags) ==
253     (filter->matchbits & filter->matchvalue) );
254     }
255    
256    
257     uint32 bnd_flags( struct bnd_boundary *bnd)
258     {
259 jds 114 asc_assert(bnd!=NULL);
260     return bnd->flags;
261 aw0a 1 }
262    
263    
264     void bnd_set_flags(struct bnd_boundary *bnd, unsigned int flags)
265     {
266 jds 114 asc_assert(bnd!=NULL);
267 aw0a 1 bnd->flags = flags;
268     }
269    
270    
271     uint32 bnd_flagbit(struct bnd_boundary *bnd, uint32 one)
272     {
273 jds 114 asc_assert(bnd!=NULL);
274 aw0a 1 return (bnd->flags & one);
275 jds 216 }
276 aw0a 1
277    
278     void bnd_set_flagbit(struct bnd_boundary *bnd, uint32 field,uint32 one)
279     {
280 jds 114 asc_assert(bnd!=NULL);
281 aw0a 1 if (one) {
282     bnd->flags |= field;
283     } else {
284     bnd->flags &= ~field;
285     }
286     }
287    
288    
289     int32 bnd_status_cur( struct bnd_boundary *bnd)
290     {
291 jds 114 asc_assert(bnd!=NULL);
292     if (bnd_cur_status(bnd)) {
293     return 1;
294     } else {
295 aw0a 1 return 0;
296     }
297     }
298    
299    
300     int32 bnd_status_pre( struct bnd_boundary *bnd)
301     {
302 jds 114 asc_assert(bnd!=NULL);
303     if (bnd_pre_status(bnd)) {
304     return 1;
305     } else {
306 aw0a 1 return 0;
307     }
308     }

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