/[escript]/trunk/paso/src/Functions.c
ViewVC logotype

Diff of /trunk/paso/src/Functions.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1628 by phornby, Fri Jul 11 13:12:46 2008 UTC revision 1639 by gross, Mon Jul 14 08:55:25 2008 UTC
# Line 13  Line 13 
13    
14  #include "Common.h"  #include "Common.h"
15  #include "Functions.h"  #include "Functions.h"
16  #include "Util.h"  #include "PasoUtil.h"
17  /*  /*
18   * numerical calculation of the directional derivative J0w if F at x0 in the direction w. f0 is the value of F at x0.   * numerical calculation of the directional derivative J0w if F at x0 in the direction w. f0 is the value of F at x0.
19   * setoff is workspace   * setoff is workspace
# Line 22  Line 22 
22  err_t Paso_FunctionDerivative(double* J0w, const double* w, Paso_Function* F, const double *f0, const double *x0, double* setoff)  err_t Paso_FunctionDerivative(double* J0w, const double* w, Paso_Function* F, const double *f0, const double *x0, double* setoff)
23  {  {
24     err_t err=0;     err_t err=0;
25     dim_t n=F->local_n;     dim_t n=F->n;
26     double norm_w,epsnew,norm_x0;     double norm_w,epsnew,norm_x0;
27     epsnew=10.*sqrt(EPSILON);     epsnew=10.*sqrt(EPSILON);
28     norm_w=Paso_l2(n,w,F->mpi_info);     norm_w=Paso_l2(n,w,F->mpi_info);
# Line 35  err_t Paso_FunctionDerivative(double* J0 Line 35  err_t Paso_FunctionDerivative(double* J0
35         if (norm_x0>0) epsnew*=norm_x0;         if (norm_x0>0) epsnew*=norm_x0;
36         Paso_LinearCombination(n,setoff,1.,x0,epsnew,w);         Paso_LinearCombination(n,setoff,1.,x0,epsnew,w);
37         err=Paso_FunctionCall(F,J0w,setoff);         err=Paso_FunctionCall(F,J0w,setoff);
38         if (err==0) {         if (err==NO_ERROR) {
39             Paso_Update(n,1./epsnew,J0w,-1./epsnew,f0); /* J0w = (J0w - f0)/epsnew; */             Paso_Update(n,1./epsnew,J0w,-1./epsnew,f0); /* J0w = (J0w - f0)/epsnew; */
40         }         }
41     }     }
42     return err;     return err;
43  }  }
44    
45    /*
46     * sets value=F(arg)
47     *
48     */
49  err_t Paso_FunctionCall(Paso_Function * F,double* value, const double* arg)  err_t Paso_FunctionCall(Paso_Function * F,double* value, const double* arg)
50  {  {
51     err_t err=0;     if (F!=NULL) {
52          switch(F->kind) {
53     /* Not yet please */            case LINEAR_SYSTEM:
54     err = 1;                 return Paso_Function_LinearSystem_call(F, value, arg);
55              case FCT:
56                   return Paso_Function_FCT_call(F, value, arg);
57              default:
58                   return SYSTEM_ERROR;
59          }
60       }
61    }
62    /*
63     * clear Paso_Function
64     */
65    void Paso_Function_free(Paso_Function * F) {
66       if (F!=NULL) {
67    
68     return err;        switch(F->kind) {
69              case LINEAR_SYSTEM:
70                   Paso_Function_LinearSystem_free(F);
71                   break;
72              case FCT:
73                   Paso_Function_FCT_free(F);
74                   break;
75              default:
76                   MEMFREE(F);
77          }
78       }
79  }  }

Legend:
Removed from v.1628  
changed lines
  Added in v.1639

  ViewVC Help
Powered by ViewVC 1.1.26