23 |
@file |
@file |
24 |
SLV common utilities & structures for ASCEND solvers. |
SLV common utilities & structures for ASCEND solvers. |
25 |
|
|
26 |
Routines in this header a applicable to both the system API (as accessed |
Routines in this header are applicable to both the system API (as accessed |
27 |
from ASCEND compiler and GUI/CLI) as well as the solver backend (slv3.c, |
from ASCEND compiler and GUI/CLI) as well as the solver backend (slv3.c, |
28 |
and other solvers, etc) |
and other solvers, etc) |
29 |
|
|
66 |
#include <solver/logrel.h> |
#include <solver/logrel.h> |
67 |
#include <solver/mtx.h> |
#include <solver/mtx.h> |
68 |
#include <general/list.h> |
#include <general/list.h> |
69 |
|
*/ |
70 |
|
|
71 |
|
/** @page solver-parameters Solver Parameters in ASCEND |
72 |
|
|
73 |
Details on solver parameter definition: |
@NOTE This stuff REALLY seems painful to use! Is there not a way that |
74 |
|
we could make it a bit easier? @ENDNOTE |
75 |
|
|
76 |
When used together the parameter-related structures, functions, and |
When used together the parameter-related structures, functions, and |
77 |
macros allow us to define all of a solver's parameters in one file |
macros allow us to define all of a solver's parameters in one file |
275 |
}; |
}; |
276 |
|
|
277 |
/*------------------------------------------------------------------------------ |
/*------------------------------------------------------------------------------ |
278 |
|
SOME STRUCTURES FOR SANER INITIALISATION OF PARAMETERS (says I -- JP) |
279 |
|
*/ |
280 |
|
|
281 |
|
typedef struct{ |
282 |
|
const char *codename; |
283 |
|
const char *guiname; |
284 |
|
const int guipagenum; |
285 |
|
const char *description; |
286 |
|
} SlvParameterInitMeta; |
287 |
|
|
288 |
|
typedef struct{ |
289 |
|
const SlvParameterInitMeta meta; |
290 |
|
const int val; |
291 |
|
const int low; |
292 |
|
const int high; |
293 |
|
} SlvParameterInitInt; |
294 |
|
|
295 |
|
typedef struct{ |
296 |
|
const SlvParameterInitMeta meta; |
297 |
|
const int val; |
298 |
|
} SlvParameterInitBool; |
299 |
|
|
300 |
|
typedef struct{ |
301 |
|
const SlvParameterInitMeta meta; |
302 |
|
const double val; |
303 |
|
const double low; |
304 |
|
const double high; |
305 |
|
} SlvParameterInitReal; |
306 |
|
|
307 |
|
typedef struct{ |
308 |
|
const SlvParameterInitMeta meta; |
309 |
|
const char *val; |
310 |
|
const char *options[]; /* Important: NULL terminated */ |
311 |
|
} SlvParameterInitChar; |
312 |
|
|
313 |
|
struct slv_parameters_structure; |
314 |
|
|
315 |
|
int slv_param_int (struct slv_parameters_structure *p, const int index, const SlvParameterInitInt); |
316 |
|
int slv_param_bool(struct slv_parameters_structure *p, const int index, const SlvParameterInitBool); |
317 |
|
int slv_param_real(struct slv_parameters_structure *p, const int index, const SlvParameterInitReal); |
318 |
|
int slv_param_char(struct slv_parameters_structure *p, const int index, const SlvParameterInitChar); |
319 |
|
|
320 |
|
/* macros to access values from your solver code |
321 |
|
|
322 |
|
Usage example: |
323 |
|
if(SLV_PARAM_BOOL(p,IDA_PARAM_AUTODIFF)){ |
324 |
|
// do something |
325 |
|
} |
326 |
|
SLV_PARAM_BOOL(p,IDA_PARAM_AUTODIFF) = FALSE; |
327 |
|
*/ |
328 |
|
|
329 |
|
/* the first three are read/write */ |
330 |
|
#define SLV_PARAM_INT(PARAMS,INDEX) (PARAMS)->parms[INDEX].info.i.value |
331 |
|
#define SLV_PARAM_BOOL(PARAMS,INDEX) (PARAMS)->parms[INDEX].info.b.value |
332 |
|
#define SLV_PARAM_REAL(PARAMS,INDEX) (PARAMS)->parms[INDEX].info.r.value |
333 |
|
|
334 |
|
#define SLV_PARAM_CHAR(PARAMS,INDEX) (PARAMS)->parms[INDEX].info.c.value |
335 |
|
/**< |
336 |
|
@NOTE, don't use this macro to set the value of your string, as it will |
337 |
|
result in memory leaks |
338 |
|
*/ |
339 |
|
|
340 |
|
/*------------------------------------------------------------------------------ |
341 |
ACCESSOR MACROS for parm_arg unions |
ACCESSOR MACROS for parm_arg unions |
342 |
|
|
343 |
* Macros for parm_arg unions. |
* Macros for parm_arg unions. |
605 |
ASC_DLLSPEC(void ) slv_destroy_parms(slv_parameters_t *p); |
ASC_DLLSPEC(void ) slv_destroy_parms(slv_parameters_t *p); |
606 |
/**< |
/**< |
607 |
Deallocates any allocated memory held by a parameter structure. |
Deallocates any allocated memory held by a parameter structure. |
608 |
|
|
609 |
|
* All the 'meta' strings are freed, as they are allocated using ascstrdup. |
610 |
|
* String values and option arrays are |
611 |
|
|
612 |
Only the held memory is freed, not p itself. Further, if |
Only the held memory is freed, not p itself. Further, if |
613 |
(p->dynamic_parms != 0), the strings in p->parms are freed |
(p->dynamic_parms != 0), the strings in p->parms are freed |
614 |
but not p->parms itself. Does nothing if p is NULL. |
but not p->parms itself. Does nothing if p is NULL. |
615 |
|
|
616 |
|
@NOTE the above description does not appear to be correct! check the code! |
617 |
|
|
618 |
@param p The parameter structure to destroy. |
@param p The parameter structure to destroy. |
619 |
*/ |
*/ |
620 |
|
|