/[ascend]/trunk/models/johnpye/extfn/extfntest.c
ViewVC logotype

Contents of /trunk/models/johnpye/extfn/extfntest.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1039 - (show annotations) (download) (as text)
Thu Jan 4 23:21:20 2007 UTC (12 years, 11 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3253 byte(s)
Fixed up some #includes in compiler .[ch] files.
Switched instantiate.c to using 'asc_assert' instead of 'assert'.
Added some missing GPL headers in C++ code.
Silenced some slv3.c debug output.
Switch void-return to int-return in slv9_presolve etc (slv9.c)
Attemping to fix solvernotes.py for the commandline environment (browser==None)
Removed redundant solve(SELF) in thermalequilibrium2.a4c.
Some error reporting from addone_calc (extfntest.c).
Expanded test size in extrelfor.a4c.
Big rearrangement of bboxtest.c for top-down style.
Fixed TestFreesteam.testintegrator, added end-value checks.

1 /* ASCEND modelling environment
2 Copyright (C) 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, or (at your option)
7 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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 This is intended to be a simplest-possible external function and was
20 used by John Pye to test his updates/fixes to the Black Box implementation.
21 Since Ben refactored the the black box stuff separately, this has stopped
22 working (and now causes a runtime crash. The aim now is to work out why
23 the crash occurs and ensure that it can't!
24
25 Note that this external function does *not* provide its own jacobian; it is
26 counting on the default numerical diff function provided by ASCEND.
27 *//*
28 by John Pye, Jan 2006
29 */
30
31 #include <stdio.h>
32
33 #include <utilities/ascConfig.h>
34 #include <utilities/error.h>
35
36 /*
37 #include <compiler/fractions.h>
38 #include <compiler/compiler.h>
39 #include <compiler/dimen.h>
40 #include <compiler/child.h>
41 #include <general/list.h>
42 #include <compiler/module.h>
43 #include <compiler/childinfo.h>
44 #include <compiler/slist.h>
45 #include <compiler/type_desc.h>
46 #include <compiler/packages.h>*/
47 #include <compiler/extfunc.h>
48
49 ExtBBoxInitFunc addone_prepare;
50 ExtBBoxFunc addone_calc;
51
52 /**
53 This is the function called from "IMPORT extfntest"
54
55 It sets up the functions in this external function library
56 */
57
58 #ifndef ASC_EXPORT
59 # error "Where is ASC_EXPORT?"
60 #endif
61
62 extern
63 ASC_EXPORT(int) extfntest_register(){
64 const char *addone_help = "This is a test of the dynamic user packages functionality";
65 int result = 0;
66
67 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
68
69 (void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
70
71 result += CreateUserFunctionBlackBox("add_one"
72 , addone_prepare
73 , addone_calc /* value */
74 , (ExtBBoxFunc*)NULL /* deriv */
75 , (ExtBBoxFunc*)NULL /* deriv2 */
76 , (ExtBBoxFinalFunc*)NULL /* final */
77 , 1,1 /* inputs, outputs */
78 , addone_help
79 , 0.0
80 ); /* returns 0 on success */
81
82 if(result){
83 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
84 }
85 return result;
86 }
87
88 int addone_prepare(struct BBoxInterp *slv_interp,
89 struct Instance *data,
90 struct gl_list_t *arglist
91 ){
92 const char *mystring = "MY STRING IS HERE";
93
94 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
95 slv_interp->user_data = (void *)mystring;
96
97 return 0;
98 }
99
100 /* return 0 on success */
101 int addone_calc(struct BBoxInterp *slv_interp,
102 int ninputs, int noutputs,
103 double *inputs, double *outputs,
104 double *jacobian
105 ){
106 if(noutputs != 1)return -1;
107 if(ninputs != 1)return -2;
108 if(inputs==NULL)return -3;
109 if(outputs==NULL)return -4;
110 if(slv_interp==NULL)return -5;
111
112 outputs[0] = inputs[0] + 1;
113
114 return 0;
115 }

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