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_COMPOSITE_INTE_H
00024 #define O2SCL_COMPOSITE_INTE_H
00025
00026 #include <iostream>
00027 #include <o2scl/multi_inte.h>
00028 #include <o2scl/inte.h>
00029 #include <o2scl/funct.h>
00030
00031 #ifndef DOXYGENP
00032 namespace o2scl {
00033 #endif
00034
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 template<class param_t, class func_t, class vec_t,
00063 class alloc_vec_t, class alloc_t> class composite_inte :
00064 public multi_inte<param_t,func_t,vec_t> {
00065
00066 public:
00067
00068
00069
00070
00071
00072
00073
00074
00075 typedef struct {
00076
00077 const vec_t *ax;
00078
00079 const vec_t *bx;
00080
00081 alloc_vec_t *cx;
00082
00083 func_t *mf;
00084
00085 int ndim;
00086
00087 int idim;
00088
00089 param_t *vp;
00090 } od_parms;
00091
00092 composite_inte() {
00093 ptrs_set=false;
00094 ndim=0;
00095 fmn=new funct_mfptr_noerr<composite_inte<param_t,func_t,
00096 vec_t,alloc_vec_t,alloc_t>,od_parms>
00097 (this,&composite_inte<param_t,func_t,vec_t,
00098 alloc_vec_t,alloc_t>::odfunc);
00099 }
00100
00101 virtual ~composite_inte() {
00102 delete fmn;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int set_ptrs(inte<od_parms,funct<od_parms> > **ip, int n) {
00116 if (n<1) {
00117 set_err_ret("Number of dimensions less than 1 in set_ptrs().",
00118 gsl_einval);
00119 }
00120 iptrs=ip;
00121 ndim=n;
00122 ptrs_set=true;
00123 return 0;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 virtual double minteg(func_t &func, size_t n, const vec_t &a,
00134 const vec_t &b, param_t &pa)
00135 {
00136 if (ptrs_set==false || n>ndim) {
00137 set_err("Too few objects specified with set_ptrs() in minteg().",
00138 gsl_einval);
00139 return 0.0;
00140 }
00141
00142 alloc_vec_t cx;
00143 ao.allocate(cx,n);
00144
00145 od_parms op={&a,&b,&cx,&func,n,0,&pa};
00146
00147 double res=iptrs[0]->integ(*fmn,a[0],b[0],op);
00148
00149 ao.free(cx);
00150
00151 return res;
00152
00153 }
00154
00155
00156 virtual const char *type() { return "composite_inte"; }
00157
00158 protected:
00159
00160 #ifndef DOXYGEN_INTERNAL
00161
00162
00163 alloc_t ao;
00164
00165
00166 double odfunc(double x, od_parms &od) {
00167
00168 double res;
00169
00170 (*od.cx)[od.idim]=x;
00171 if (od.idim==od.ndim-1) {
00172 (*od.mf)(od.ndim,(*od.cx),res,*od.vp);
00173 } else {
00174 od_parms op2={od.ax,od.bx,od.cx,od.mf,od.ndim,od.idim+1,od.vp};
00175 res=iptrs[od.idim]->integ(*fmn,(*od.ax)[od.idim+1],
00176 (*od.bx)[od.idim+1],op2);
00177 }
00178 return res;
00179 }
00180
00181
00182 funct_mfptr_noerr<composite_inte<param_t,func_t,vec_t,
00183 alloc_vec_t,alloc_t>,od_parms> *fmn;
00184
00185
00186 size_t ndim;
00187
00188
00189 inte<od_parms,funct<od_parms> > **iptrs;
00190
00191
00192 bool ptrs_set;
00193
00194 #endif
00195
00196 };
00197
00198 #ifndef DOXYGENP
00199 }
00200 #endif
00201
00202 #endif
00203