# Contents of /trunk/paso/src/Functions.c

Revision 2548 - (show annotations)
Mon Jul 20 06:20:06 2009 UTC (10 years, 2 months ago) by jfenwick
File MIME type: text/plain
File size: 2154 byte(s)
```Updating copyright notices
```
 1 2 /******************************************************* 3 * 4 * Copyright (c) 2003-2009 by University of Queensland 5 * Earth Systems Science Computational Center (ESSCC) 6 * http://www.uq.edu.au/esscc 7 * 8 * Primary Business: Queensland, Australia 9 * Licensed under the Open Software License version 3.0 10 * http://www.opensource.org/licenses/osl-3.0.php 11 * 12 *******************************************************/ 13 14 15 #include "Common.h" 16 #include "Functions.h" 17 #include "PasoUtil.h" 18 #include "Solver.h" 19 /* 20 * numerical calculation of the directional derivative J0w if F at x0 in the direction w. f0 is the value of F at x0. 21 * setoff is workspace 22 */ 23 24 err_t Paso_FunctionDerivative(double* J0w, const double* w, Paso_Function* F, const double *f0, const double *x0, double* setoff, const bool_t w_is_normalized, Paso_Performance* pp) 25 { 26 err_t err=0; 27 dim_t n=F->n; 28 double norm_w,epsnew,norm_x0; 29 epsnew=10.*sqrt(EPSILON); 30 if (! w_is_normalized) { 31 norm_w=Paso_l2(n,w,F->mpi_info); 32 } else { 33 norm_w=1.; 34 } 35 36 if (norm_w>0) { 37 epsnew = epsnew/norm_w; 38 norm_x0=Paso_l2(n,x0,F->mpi_info); 39 if (norm_x0>0) epsnew*=norm_x0; 40 Paso_LinearCombination(n,setoff,1.,x0,epsnew,w); 41 err=Paso_FunctionCall(F,J0w,setoff,pp); 42 if (err==NO_ERROR) { 43 Paso_Update(n,1./epsnew,J0w,-1./epsnew,f0); /* J0w = (J0w - f0)/epsnew; */ 44 } 45 } else { 46 Paso_zeroes(n,J0w); 47 } 48 return err; 49 } 50 51 /* 52 * sets value=F(arg) 53 * 54 */ 55 err_t Paso_FunctionCall(Paso_Function * F,double* value, const double* arg, Paso_Performance *pp) 56 { 57 if (F!=NULL) { 58 switch(F->kind) { 59 case LINEAR_SYSTEM: 60 return Paso_Function_LinearSystem_call(F, value, arg,pp); 61 default: 62 return SYSTEM_ERROR; 63 } 64 } 65 /* Added by PGH, assume a null pointe is an error */ 66 return SYSTEM_ERROR; 67 } 68 /* 69 * clear Paso_Function 70 */ 71 void Paso_Function_free(Paso_Function * F) { 72 if (F!=NULL) { 73 74 switch(F->kind) { 75 case LINEAR_SYSTEM: 76 Paso_Function_LinearSystem_free(F); 77 break; 78 default: 79 MEMFREE(F); 80 } 81 } 82 }