/[ascend]/trunk/base/generic/compiler/func.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/func.h

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-chdr
File size: 12961 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) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//** @file
20 Function-of-one-variable module.
21
22 @TODO Complete documentation of func.h.
23
24 Revision notes: If CHRIS_FUNC defined, auxillary quantities to func structure.
25
26 @TODO 2/96 baa Probably somebody should properly set these evaluation
27 defined below based on math.h when possible.
28 *//*
29 by Tom Epperly
30 Version: $Revision: 1.16 $
31 Version control file: $RCSfile: func.h,v $
32 Date last modified: $Date: 2001/01/31 22:23:57 $
33 Last modified by: $Author: ballan $
34 */
35
36 #ifndef ASC_FUNC_H
37 #define ASC_FUNC_H
38
39 #include <utilities/ascConfig.h>
40 #include "functype.h"
41 #include "compiler.h"
42 #include "dimen.h"
43
44 /*
45 * the following should be ifdefed to deal with math.h values
46 */
47 #define F_ERF_COEF 1.1283791670955130 /**< = 2 / sqrt(PI) */
48 #define F_LOG10_COEF 0.4342944819032518 /**< = log10(e) = 1/ln(10) */
49 #define F_PI 3.1415926535897932385E0
50 #define F_PI_HALF 1.5707963267948966192E0
51 #define F_LIM_EXP 709.78 /**< approximately ln(maxdouble) */
52 #define F_LIM_CUBE 5.6438030941223618e101 /**< cbrt(maxdouble)*/
53 #define F_LIM_SQR 1.0e154 /**< sqrt(maxdouble) */
54
55 #ifdef __STDC__
56 # if __STDC__
57 /**
58 * stdc==1 --> erf, cbrt not defined in headers. user should link
59 * against a library that does provide them. ASCEND is research
60 * code: we aren't going to waste time reimplementing these basic
61 * functions.
62 */
63 ASC_DLLSPEC(double) cbrt(double);
64
65 # ifdef HAVE_ERF
66 extern double erf(double);
67 # endif /* HAVE_ERF */
68 # endif /* __STDC__ == 1*/
69 /**<
70 * in the case where __STDC__ is defined but == 0, system headers
71 * should provide cbrt, erf.
72 */
73 #endif /* stdc defined */
74
75 extern CONST struct Func *LookupFunc(CONST char *name);
76 /**<
77 * Lookup the function with the given name. If no match is found, it
78 * returns NULL. name is the ASCEND name, not C name.
79 * <pre>
80 * Currently defined:
81 * "exp" e^x
82 * "ln" natural logarithm of x
83 * "log10" logarithm of x base 10
84 * "sin" sine of x
85 * "cos" cosine of x
86 * "tan" tangent of x
87 * "sqr" x*x
88 * "sqrt" the square root of x
89 * "arcsin" the inverse sine of x
90 * "arccos" the inverse cosine of x
91 * "arctan" the inverse tangent of x
92 *
93 * "erf" the error function
94 * "lnm" modified natural log:
95 * x>epsilon? ln(x): x/epsilon +ln(epsilon) -1
96 * "sinh" hyperbolic sine
97 * "cosh" hyperbolic cosine
98 * "tanh" hyperbolic tangent
99 * "arcsinh" inv hyperbolic sine
100 * "arccosh" inv hyperbolic cosine
101 * "arctanh" inv hyperbolic tangent
102 *
103 * "cube" the cube of x
104 * "cbrt" the cube root of x
105 * "abs" absolute value of x
106 *
107 * "hold" returns the current value of x.
108 * </pre>
109 * The last 10 are not fully supported for chris.[ch]
110 * All functions return principal (postive) values if there is a choice.
111 * None of them perform range checking. ln(-1) -> float error.
112 */
113
114 extern CONST struct Func *LookupFuncById(enum Func_enum id);
115 /**<
116 * Lookups a function by its enumerated type rather than by a string as
117 * in the above function.
118 */
119
120 extern double FuncGetLnmEpsilon(void);
121 /**<
122 * Return the current epsilon for the modified log function lnm.
123 */
124 #define FuncGetLnmEpsilon() (g_lnm_epsilon)
125
126 extern void FuncSetLnmEpsilon(double e);
127 /**<
128 * Change the current epsilon for the modified log function lnm.
129 * epsilon > 0.0.
130 */
131 ASC_DLLSPEC(double ) g_lnm_epsilon;
132 #define FuncSetLnmEpsilon(e) \
133 (e>(double)0.0 ? g_lnm_epsilon=e : FPRINTF(ASCERR,"bad lnm eps"))
134
135 /**<
136 * declare cbrt() and erf() since some vendors put
137 * these functions in odd headers
138 */
139 ASC_DLLSPEC(double) cbrt(double);
140 #ifdef HAVE_ERF
141 extern double erf(double);
142 #endif /* HAVE_ERF */
143
144 #ifdef NDEBUG
145 # define ascnint(d) (((int) (d)>=0.0 ? floor((d) + 0.5) : -floor(0.5 - (d))))
146 /**<
147 * Converts a double to the nearest integer (release version).
148 * @param d double, the real number to convert.
149 * @return The nearest integer as an int.
150 */
151 #else
152 # define ascnint(a) ascnintF(a)
153 /**<
154 * Converts a double to the nearest integer (debug version).
155 * @param d double, the real number to convert.
156 * @return The nearest integer as an int.
157 */
158 ASC_DLLSPEC(int) ascnintF(double);
159 /**<
160 * Implementation function for debug version of ascnint().
161 * Do not call this function directly - use ascnint() instead.
162 */
163
164 #endif
165
166 ASC_DLLSPEC(double) dln(double x);
167 ASC_DLLSPEC(double) dln2(double x);
168 ASC_DLLSPEC(double) dlog10(double x);
169 ASC_DLLSPEC(double) dlog102(double x);
170 ASC_DLLSPEC(double) lnm(double x);
171 ASC_DLLSPEC(double) dlnm(double x);
172 ASC_DLLSPEC(double) dlnm2(double x);
173 /**<
174 * Modified natural log function and derivatives.
175 * <pre>
176 *
177 * ( ln(x) if x.ge.epsilon
178 * lnm(x)= (
179 * ( x/epsilon + ln(epsilon) - 1 otherwise
180 *
181 *
182 * ( 1/x if x.ge.epsilon
183 * d( lnm(x) )/dx = (
184 * ( 1/epsilon otherwise
185 *
186 *
187 * ( -1/x^2 if x.ge.epsilon
188 * d^2( lnm(x) )/dx^2 = (
189 * ( 0 otherwise
190 *
191 * epsilon determined by FuncGet/SetLnmEpsilon.
192 * </pre>
193 */
194
195 ASC_DLLSPEC(double) dtanh(double x);
196 ASC_DLLSPEC(double) dtanh2(double x);
197 ASC_DLLSPEC(double) arcsinh(double x);
198 ASC_DLLSPEC(double) arccosh(double x);
199 ASC_DLLSPEC(double) arctanh(double x);
200 ASC_DLLSPEC(double) darcsinh(double x);
201 ASC_DLLSPEC(double) darcsinh2(double x);
202 ASC_DLLSPEC(double) darccosh(double x);
203 ASC_DLLSPEC(double) darccosh2(double x);
204 ASC_DLLSPEC(double) darctanh(double x);
205 ASC_DLLSPEC(double) darctanh2(double x);
206 /**<
207 * Zero, first and second partials of (inverse) hyperbolic functions.
208 */
209
210 ASC_DLLSPEC(double) sqr(double x);
211 ASC_DLLSPEC(double) dsqr(double x);
212 ASC_DLLSPEC(double) dsqr2(double x);
213 ASC_DLLSPEC(double) cube(double x);
214 ASC_DLLSPEC(double) dcube(double x);
215 ASC_DLLSPEC(double) dcube2(double x);
216 /**<
217 * Zero, first and second partials of x for sqr, cube.
218 */
219
220 ASC_DLLSPEC(double) asc_ipow(double a, int n);
221 ASC_DLLSPEC(double) asc_d1ipow(double a, int n);
222 ASC_DLLSPEC(double) asc_d2ipow(double a, int n);
223 /**<
224 * Integer power function, a^n, and its first and second derivatives.
225 * d = asc_ipow(a,n);
226 * d1 = asc_d1ipow(a,n);
227 * d2 = asc_d2ipow(a,n);
228 *
229 * Special cases ipow:
230 * a^0 = 1, 0^n = 0, 0^0=1 -- the last is mathematically undefined,
231 * so this function should not be called with 0.0,0.
232 *
233 * Special cases d1ipow,d2ipow:
234 */
235
236 ASC_DLLSPEC(double) hold(double x);
237 /**<
238 * Returns the value it is passed.
239 * The primary purpose is as an operator so we can write
240 * equations of the form x = hold(x) which act essentially
241 * as a fixed flag when a solver is partitioning.
242 * If x is fixed, the equation is singular.
243 * hold(x) is a constant value, so its derivatives are 0.
244 */
245
246 ASC_DLLSPEC(double) dsqrt(double x);
247 ASC_DLLSPEC(double) dsqrt2(double x);
248 ASC_DLLSPEC(double) dcbrt(double x);
249 ASC_DLLSPEC(double) dcbrt2(double x);
250 ASC_DLLSPEC(double) dfabs(double x);
251 ASC_DLLSPEC(double) dfabs2(double x);
252 ASC_DLLSPEC(double) dhold(double x);
253 #define dhold2 dhold
254 /**<
255 * first and second partials of sqrt cbrt fabs hold
256 * dfabs is undefined at 0. We take the standard kluge: d(abs(x=0))/dx=0
257 * dfabs2(x) = 0. It might be thought of as infinite at x=0, but not here.
258 * dhold, dhold2 = 0 for all x.
259 */
260
261 ASC_DLLSPEC(double) dasin(double x);
262 ASC_DLLSPEC(double) dasin2(double x);
263 ASC_DLLSPEC(double) dcos(double x);
264 ASC_DLLSPEC(double) dcos2(double x);
265 ASC_DLLSPEC(double) dacos(double x);
266 ASC_DLLSPEC(double) dacos2(double x);
267 ASC_DLLSPEC(double) dtan(double x);
268 ASC_DLLSPEC(double) dtan2(double x);
269 ASC_DLLSPEC(double) datan(double x);
270 ASC_DLLSPEC(double) datan2(double x);
271 /**<
272 * First and second partials of the cosine, tangent, arctangent functions
273 */
274
275 #ifdef HAVE_ERF
276 ASC_DLLSPEC(double) derf(double x);
277 ASC_DLLSPEC(double) derf2(double x);
278 #endif /* HAVE_ERF */
279 /**<
280 * First and second derivatives of erf()
281 */
282
283 ASC_DLLSPEC(CONST char *) FuncName(CONST struct Func *f);
284 /**<
285 * Return the ASCEND language name of the function.
286 * Not a symchar.
287 */
288
289 extern CONST char *FuncCName(CONST struct Func *f);
290 /**<
291 * Return the C language name of the function, if any.
292 */
293
294 extern CONST char *FuncDeriv1CName(CONST struct Func *f);
295 /**<
296 * Return the C language name of the function first derivative, if any.
297 */
298
299 extern CONST char *FuncDeriv2CName(CONST struct Func *f);
300 /**<
301 * Return the C language name of the function second derivative, if any.
302 */
303
304 ASC_DLLSPEC(enum Func_enum ) FuncId(CONST struct Func *f);
305 /**<
306 * Return the identification of the function.
307 */
308
309 extern CONST dim_type *FuncDimens(CONST struct Func *f);
310 /**<
311 * Return the dimensionality required for the arg of the function.
312 * sin, cos, tan -> P.
313 * arc(sin,cos,tan),exp,ln,log,lnm,erf ->dimensionless.
314 * sqrt->wilddimension (user must check for even poweredness of arg)
315 * as this may be the case for an infinite # of different dims.
316 * sqr ->wilddimension (sqr, abs, cube anything you like.)
317 */
318
319 extern double FuncEval(CONST struct Func *f, double u);
320 /**<
321 * Return f(u).
322 */
323
324 extern double FuncEvalSafe(CONST struct Func *f,
325 double u,
326 enum safe_err *not_safe);
327 /**<
328 * Return f(u) (safe version).
329 */
330
331 extern double FuncDeriv(CONST struct Func *f, double u);
332 /**<
333 * Return df/du evaluated at u.
334 */
335
336 extern double FuncDerivSafe(CONST struct Func *f,
337 double u,
338 enum safe_err *not_safe);
339 /**<
340 * Return df/du evaluated at u (safe version).
341 */
342
343 extern double FuncDeriv2(CONST struct Func *f, double u);
344 /**<
345 * Return the second derivative (d^2f/du^2) evaluated at u.
346 */
347
348 extern double FuncDeriv2Safe(CONST struct Func *f,
349 double u,
350 enum safe_err *not_safe);
351 /**<
352 * Return the second derivative (d^2f/du^2) evaluated at u (safe version).
353 */
354
355 #ifdef CHRIS_FUNC
356
357 extern struct Interval FuncRange(CONST struct Func *f, struct Interval i);
358 /**<
359 * Return a bound on the range of the function over the given interval.
360 */
361
362 extern void FuncSlope(CONST struct Func *f,
363 unsigned long nvar,
364 struct Interval *center,
365 struct Interval *range,
366 struct Interval *slope);
367 /**<
368 * Perform the interval slope calculation.
369 */
370
371 extern struct Interval FuncIDeriv(CONST struct Func *f, struct Interval i);
372 /**<
373 * ...
374 */
375
376 extern double ArgMin(CONST struct Func *f, double lower, double upper);
377 /**<
378 * Return the arg min of the function over the range.
379 */
380
381 extern double ArgMax(CONST struct Func *f, double lower, double upper);
382 /**<
383 * Return the arg max of the function over the range.
384 */
385
386 extern double ConvexEnv(CONST struct Func *f, double x,
387 double lower, double upper);
388 /**<
389 * Return the value of the convex envelope of the function at the value
390 * x which ranges from lower to upper.
391 */
392
393 extern double ConvexEnvDeriv(CONST struct Func *f, double x,
394 double lower, double upper);
395 /**<
396 * Return the derivative of the convex envelope of the function at the
397 * value x which ranges from lower to upper.
398 */
399
400 extern double ConcaveEnv(CONST struct Func *f, double x,
401 double lower, double upper);
402 /**<
403 * Return the value of the concave envelope of the function at the value
404 * x which ranges from lower to upper.
405 */
406
407 extern double ConcaveEnvDeriv(CONST struct Func *f, double x,
408 double lower, double upper);
409 /**<
410 * Return the derivative of the concave envelope of the function at the
411 * value x which ranges from lower to upper.
412 */
413
414 #endif /* CHRIS_FUNC */
415
416 #endif /* ASC_FUNC_H */

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