/[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 1810 - (show annotations) (download) (as text)
Tue Jul 29 07:45:48 2008 UTC (12 years, 1 month ago) by jpye
File MIME type: text/x-csrc
File size: 2950 byte(s)
Added new code for calculating properties according to modified BWR correlation, also some initial
work on Helmholtz free energy correlation.
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 #include <compiler/extfunc.h>
37
38 ExtBBoxInitFunc addone_prepare;
39 ExtBBoxFunc addone_calc;
40
41 /**
42 This is the function called from "IMPORT extfntest"
43
44 It sets up the functions in this external function library
45 */
46
47 #ifndef ASC_EXPORT
48 # error "Where is ASC_EXPORT?"
49 #endif
50
51 extern
52 ASC_EXPORT int extfntest_register(){
53 const char *addone_help = "This is a test of the dynamic user packages functionality";
54 int result = 0;
55
56 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
57
58 (void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
59
60 result += CreateUserFunctionBlackBox("add_one"
61 , addone_prepare
62 , addone_calc /* value */
63 , (ExtBBoxFunc*)NULL /* deriv */
64 , (ExtBBoxFunc*)NULL /* deriv2 */
65 , (ExtBBoxFinalFunc*)NULL /* final */
66 , 1,1 /* inputs, outputs */
67 , addone_help
68 , 0.0
69 ); /* returns 0 on success */
70
71 if(result){
72 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
73 }
74 return result;
75 }
76
77 int addone_prepare(struct BBoxInterp *slv_interp,
78 struct Instance *data,
79 struct gl_list_t *arglist
80 ){
81 const char *mystring = "MY STRING IS HERE";
82
83 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
84 slv_interp->user_data = (void *)mystring;
85
86 return 0;
87 }
88
89 /* return 0 on success */
90 int addone_calc(struct BBoxInterp *slv_interp,
91 int ninputs, int noutputs,
92 double *inputs, double *outputs,
93 double *jacobian
94 ){
95 if(noutputs != 1)return -1;
96 if(ninputs != 1)return -2;
97 if(inputs==NULL)return -3;
98 if(outputs==NULL)return -4;
99 if(slv_interp==NULL)return -5;
100
101 outputs[0] = inputs[0] + 1;
102
103 return 0;
104 }

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