00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_COMP_GEN_INTE_H
00024 #define O2SCL_COMP_GEN_INTE_H
00025
00026 #include <iostream>
00027 #include <o2scl/collection.h>
00028 #include <o2scl/funct.h>
00029 #include <o2scl/inte.h>
00030 #include <o2scl/gen_inte.h>
00031
00032 #ifndef DOXYGENP
00033 namespace o2scl {
00034 #endif
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 template<class param_t, class func_t, class lfunc_t=func_t,
00064 class ufunc_t=func_t, class vec_t=ovector_view,
00065 class alloc_vec_t=ovector, class alloc_t=ovector_alloc>
00066 class comp_gen_inte :
00067 public gen_inte<param_t,func_t,lfunc_t,ufunc_t,vec_t> {
00068
00069 public:
00070
00071 comp_gen_inte() {
00072
00073 ptrs_set=false;
00074
00075 fmn=new funct_mfptr_noerr<comp_gen_inte<param_t,func_t,lfunc_t,
00076 ufunc_t,vec_t,alloc_vec_t,alloc_t>,od_parms>
00077 (this,&comp_gen_inte<param_t,func_t,lfunc_t,ufunc_t,vec_t,
00078 alloc_vec_t,alloc_t>::odfunc);
00079 }
00080
00081 virtual ~comp_gen_inte() {
00082 delete fmn;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 typedef struct {
00092
00093 alloc_vec_t *cx;
00094
00095 lfunc_t *lower;
00096
00097 ufunc_t *upper;
00098
00099 func_t *func;
00100
00101 int ndim;
00102
00103 int idim;
00104
00105 param_t *vp;
00106 } od_parms;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 int set_ptrs(inte<od_parms,funct<od_parms> > **ip, int n) {
00124 if (n<1) {
00125 set_err_ret
00126 ("Number of dimensions less than 1 in set_ptrs().",gsl_einval);
00127 }
00128 ptrs=ip;
00129 ndim=n;
00130 ptrs_set=true;
00131 return 0;
00132 }
00133
00134
00135
00136
00137
00138 virtual double ginteg(func_t &func, size_t n, func_t &lower,
00139 func_t &upper, param_t &pa) {
00140
00141 if (ptrs_set==false || n>ndim || n==0) {
00142 set_err("Pointers not set with proper dimension in ginteg().",
00143 gsl_einval);
00144 return 0.0;
00145 }
00146
00147 alloc_vec_t cx;
00148 ao.allocate(cx,n);
00149
00150 od_parms op={&cx,&lower,&upper,&func,n,0,&pa};
00151
00152 double res=ptrs[0]->integ(*fmn,lower(0,cx,pa),upper(0,cx,pa),op);
00153
00154 ao.free(cx);
00155
00156 return res;
00157 }
00158
00159
00160 virtual const char *type() { return "comp_gen_inte"; }
00161
00162 #ifndef DOXYGEN_INTERNAL
00163
00164 protected:
00165
00166
00167 alloc_t ao;
00168
00169
00170 funct_mfptr_noerr<comp_gen_inte<param_t,func_t,lfunc_t,ufunc_t,
00171 vec_t,alloc_vec_t,alloc_t>,od_parms> *fmn;
00172
00173
00174 double odfunc(double x, od_parms &od) {
00175
00176 double res;
00177
00178 (*od.cx)[od.idim]=x;
00179 if (od.idim==od.ndim-1) {
00180 (*od.func)(od.ndim,(*od.cx),res,*od.vp);
00181 } else {
00182 od_parms od2={od.cx,od.lower,od.upper,od.func,
00183 od.ndim,od.idim+1,od.vp};
00184 (*od.func)(od.idim+1,*od.cx,res,*od.vp);
00185 res*=ptrs[od.idim]->integ
00186 (*fmn,(*od.lower)(od.idim+1,*od.cx,*od.vp),
00187 (*od.upper)(od.idim+1,*od.cx,*od.vp),od2);
00188 }
00189 return res;
00190 }
00191
00192
00193 size_t ndim;
00194
00195
00196 inte<od_parms,funct<od_parms> > **ptrs;
00197
00198
00199 bool ptrs_set;
00200
00201 #endif
00202
00203
00204 };
00205
00206 #ifndef DOXYGENP
00207 }
00208 #endif
00209
00210 #endif
00211