All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inte_cauchy_cern.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file inte_cauchy_cern.h
24  \brief File defining \ref o2scl::inte_cauchy_cern
25 */
26 #ifndef O2SCL_CERN_CAUCHY_H
27 #define O2SCL_CERN_CAUCHY_H
28 
29 #include <o2scl/inte.h>
30 #include <o2scl/inte_gauss_cern.h>
31 
32 #ifndef DOXYGEN_NO_O2NS
33 namespace o2scl {
34 #endif
35 
36  /** \brief Cauchy principal value integration (CERNLIB)
37 
38  The location of the singularity must be specified before-hand in
39  inte_cauchy_cern::s, and the singularity must not be at one of the
40  endpoints. Note that when integrating a function of the form \f$
41  \frac{f(x)}{(x-s)} \f$, the denominator \f$ (x-s) \f$ must be
42  specified in the argument \c func to integ(). This is different
43  from how the \ref inte_qawc_gsl operates.
44 
45  The method from \ref Longman58 is used for the decomposition of
46  the integral, and the resulting integrals are computed using
47  a user-specified base integration object.
48 
49  The uncertainty in the integral is not calculated, and is always
50  given as zero. The default base integration object is of type
51  \ref inte_gauss_cern. This is the CERNLIB default, but can be
52  modified by calling set_inte(). If the singularity is outside
53  the region of integration, then the result from the base
54  integration object is returned without calling the error
55  handler.
56 
57  Possible errors for integ() and integ_err():
58  - exc_einval - Singularity is on an endpoint
59  - exc_efailed - Couldn't reach requested accuracy
60  (occurs only if inte::err_nonconv is true)
61 
62  This function is based on the CERNLIB routines RCAUCH and
63  DCAUCH which are documented at
64  http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d104/top.html
65  */
66  template<class func_t> class inte_cauchy_cern :
67  public inte<func_t> {
68 
69  public:
70 
72  x[0]=0.96028985649753623;
73  x[1]=0.79666647741362674;
74  x[2]=0.52553240991632899;
75  x[3]=0.18343464249564980;
76  x[4]=0.98940093499164993;
77  x[5]=0.94457502307323258;
78  x[6]=0.86563120238783175;
79  x[7]=0.75540440835500303;
80  x[8]=0.61787624440264375;
81  x[9]=0.45801677765722739;
82  x[10]=0.28160355077925891;
83  x[11]=0.95012509837637440e-1;
84 
85  w[0]=0.10122853629037626;
86  w[1]=0.22238103445337447;
87  w[2]=0.31370664587788729;
88  w[3]=0.36268378337836198;
89  w[4]=0.27152459411754095e-1;
90  w[5]=0.62253523938647893e-1;
91  w[6]=0.95158511682492785e-1;
92  w[7]=0.12462897125553387;
93  w[8]=0.14959598881657673;
94  w[9]=0.16915651939500254;
95  w[10]=0.18260341504492359;
96  w[11]=0.18945061045506850;
97 
98  it=&def_inte;
99  }
100 
101  /// The singularity (must be set before calling integ() or integ_err())
102  double s;
103 
104  /** \brief Set the base integration object to use (default is \ref
105  inte_cauchy_cern::def_inte of type \ref inte_gauss_cern)
106  */
108  it=&i;
109  return 0;
110  }
111 
112  /** \brief Integrate function \c func from \c a to \c b
113  giving result \c res and error \c err
114 
115  \todo Fix converge error issue here.
116  */
117  virtual int integ_err(func_t &func, double a, double b,
118  double &res, double &err) {
119  if (s==a || s==b) {
120  O2SCL_ERR("Singularity on boundary in inte_cauchy_cern::integ().",
121  exc_einval);
122  }
123  res=integ(func,a,b);
124  err=0.0;
125  //if (this->err_nonconv) return this->last_conv;
126  return success;
127  }
128 
129  /** \brief Integrate function \c func from \c a to \c b
130  */
131  virtual double integ(func_t &func, double a, double b) {
132  double y1, y2, y3, y4;
133  size_t itx=0;
134 
135  if (s==a || s==b) {
136  O2SCL_ERR("Singularity on boundary in inte_cauchy_cern::integ().",
137  exc_einval);
138  return 0.0;
139  } else if ((s<a && s<b) || (s>a && s>b)) {
140  return it->integ(func,a,b );
141  }
142  double h, b0;
143  if (2.0*s<a+b) {
144  h=it->integ(func,2.0*s-a,b );
145  b0=s-a;
146  } else {
147  h=it->integ(func,a,2.0*s-b );
148  b0=b-s;
149  }
150  double c=0.005/b0;
151  double bb=0.0;
152  bool loop1=true;
153  while(loop1==true) {
154  itx++;
155  double s8, s16;
156  double aa=bb;
157  bb=b0;
158  bool loop2=true;
159  while(loop2==true) {
160  double c1=(bb+aa)/2.0;
161  double c2=(bb-aa)/2.0;
162  double c3=s+c1;
163  double c4=s-c1;
164  s8=0.0;
165  s16=0.0;
166  for(int i=0;i<4;i++) {
167  double u=c2*x[i];
168  y1=func(c3+u);
169  y2=func(c4-u);
170  y3=func(c3-u);
171  y4=func(c4+u);
172  s8+=w[i]*((y1+y2)+(y3+y4));
173  }
174  s8*=c2;
175  for(int i=4;i<12;i++) {
176  double u=c2*x[i];
177  y1=func(c3+u);
178  y2=func(c4-u);
179  y3=func(c3-u);
180  y4=func(c4+u);
181  s16+=w[i]*((y1+y2)+(y3+y4));
182  }
183  s16*=c2;
184 
185  if (fabs(s16-s8)<=this->tol_rel*(1.0+fabs(s16))) {
186  loop2=false;
187  } else {
188  bb=c1;
189  if ((1.0+fabs(c*c2))==1.0) {
190  loop2=false;
191  } else {
192  this->last_iter=itx;
193  O2SCL_CONV2("Couldn't reach required accuracy in cern_",
194  "cauchy::integ()",exc_efailed,this->err_nonconv);
195  return 0.0;
196  }
197  }
198  }
199  h+=s16;
200  if (bb==b0) loop1=false;
201  }
202  this->last_iter=itx;
203  return h;
204  }
205 
206  /// Default integration object
208 
209  protected:
210 
211 #ifndef DOXYGEN_INTERNAL
212 
213  /** \name Integration constants
214  */
215  //@{
216  double x[12], w[12];
217  //@}
218 
219  /// The base integration object
221 
222 #endif
223 
224  };
225 
226 #ifndef DOXYGEN_NO_O2NS
227 }
228 #endif
229 
230 #endif
int set_inte(inte< func_t > &i)
Set the base integration object to use (default is inte_cauchy_cern::def_inte of type inte_gauss_cern...
virtual int integ_err(func_t &func, double a, double b, double &res, double &err)
Integrate function func from a to b giving result res and error err.
invalid argument supplied by user
Definition: err_hnd.h:59
inte< func_t > * it
The base integration object.
size_t last_iter
The most recent number of iterations taken.
Definition: inte.h:63
bool err_nonconv
If true, call the error handler if the routine does not converge or reach the desired tolerance (defa...
Definition: inte.h:81
generic failure
Definition: err_hnd.h:61
double s
The singularity (must be set before calling integ() or integ_err())
Base integration class [abstract base].
Definition: inte.h:44
inte_gauss_cern< func_t > def_inte
Default integration object.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
#define O2SCL_CONV2(d, d2, n, b)
Set a "convergence" error, two-string version.
Definition: err_hnd.h:286
virtual double integ(func_t &func, double a, double b)
Integrate function func from a to b.
double tol_rel
The maximum relative uncertainty in the value of the integral (default )
Definition: inte.h:68
Cauchy principal value integration (CERNLIB)
Gaussian quadrature (CERNLIB)
Success.
Definition: err_hnd.h:47

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..