/[ascend]/trunk/models/johnpye/planck/asc_planck.c
ViewVC logotype

Contents of /trunk/models/johnpye/planck/asc_planck.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2809 - (show annotations) (download) (as text)
Fri Aug 15 04:57:39 2014 UTC (5 years, 3 months ago) by jpye
File MIME type: text/x-csrc
File size: 3154 byte(s)
Adding Planck integral external function.
1 /* ASCEND modelling environment
2 Copyright (C) 2008 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, see <http://www.gnu.org/licenses/>.
16 *//** @file
17 Wrapper for plnkin.c to allow access to the calculation from ASCEND.
18 */
19
20 /* include the external function API from libascend... */
21 #include <ascend/compiler/extfunc.h>
22
23 /* include error reporting API as well, so we can send messages to user */
24 #include <ascend/utilities/error.h>
25
26 /* the code that we're wrapping... */
27 #include "plnkin.h"
28
29 static ExtBBoxInitFunc planck_prepare;
30 static ExtBBoxFunc planck_calc;
31
32 static const char *planck_help = "\
33 Calculate the normalised Planck integral. Inputs are wavelength and \
34 absolute tempearture. Result is the fraction of the black body radiation energy \
35 at temperature T that is present in the wavelength range 0--lambda. See \
36 http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19680008986.pdf \
37 for details.";
38
39 /*------------------------------------------------------------------------------
40 REGISTRATION FUNCTION
41 */
42
43 /**
44 This is the function called from 'IMPORT "johnpye/planck/planck";'
45
46 It sets up the functions contained in this external library
47 */
48 extern
49 ASC_EXPORT int planck_register(){
50 int result = 0;
51
52 #define CALCFN(NAME,INPUTS,OUTPUTS) \
53 result += CreateUserFunctionBlackBox(#NAME \
54 , NAME##_prepare \
55 , NAME##_calc /* value */ \
56 , (ExtBBoxFunc*)NULL /* derivatives not provided yet*/ \
57 , (ExtBBoxFunc*)NULL /* hessian not provided yet */ \
58 , (ExtBBoxFinalFunc*)NULL /* finalisation not implemented */ \
59 , INPUTS,OUTPUTS /* inputs, outputs */ \
60 , NAME##_help /* help text */ \
61 , 0.0 \
62 ) /* returns 0 on success */
63
64 CALCFN(planck,2,1);
65
66 #undef CALCFN
67
68 if(result){
69 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
70 }
71 return result;
72 }
73
74 /**
75 This function is called when the black-box relation is being instantiated.
76 */
77 static int planck_prepare(struct BBoxInterp *bbox,
78 struct Instance *data,
79 struct gl_list_t *arglist
80 ){
81 bbox->user_data = NULL;
82 return 0;
83 }
84
85 #define CALCPREPARE(NIN,NOUT) \
86 /* a few checks about the input requirements */ \
87 if(ninputs != NIN)return -1; \
88 if(noutputs != NOUT)return -2; \
89 if(inputs==NULL)return -3; \
90 if(outputs==NULL)return -4; \
91 if(bbox==NULL)return -5;
92
93 /**
94 Evaluation function for 'planck'
95 @return 0 on success
96 */
97 static int planck_calc(struct BBoxInterp *bbox,
98 int ninputs, int noutputs,
99 double *inputs, double *outputs,
100 double *jacobian
101 ){
102 CALCPREPARE(2,1);
103
104 double lam, T;
105
106 lam = inputs[0];
107 T = inputs[1];
108
109 double res = plnkin(lam,T);
110
111 outputs[0] = res;
112 return 0;
113 }
114

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