ReFRACtor
fp_gsl_integrate.cc
Go to the documentation of this file.
1 #include "fp_gsl_integrate.h"
2 #include "fp_exception.h"
3 #include <boost/foreach.hpp>
4 using namespace FullPhysics;
5 
6 //-----------------------------------------------------------------------
11 //-----------------------------------------------------------------------
12 
13 GslIntegrate::GslIntegrate(int Max_intervals)
14  : max_ninterval(1000)
15 {
16  w = gsl_integration_workspace_alloc(Max_intervals);
17 }
18 
20 {
21  gsl_integration_workspace_free(w);
22 }
23 
24 
25 //-----------------------------------------------------------------------
33 //-----------------------------------------------------------------------
34 
36 (const boost::function<double (double)>& F, double xmin, double xmax,
37  double eps_abs, double eps_rel, int key) const
38 {
39  double res, error_est;
40  integrate_err_est(F, xmin, xmax,res, error_est, eps_abs, eps_rel, key);
41  return res;
42 }
43 
44 //-----------------------------------------------------------------------
52 //-----------------------------------------------------------------------
53 
55 (const boost::function<double (double)>& F, double xmin, double xmax,
56  const std::vector<double>& breakpoints,
57  double eps_abs, double eps_rel, int key) const
58 {
59  double res, error_est;
60  integrate_err_est(F, xmin, xmax, breakpoints, res, error_est,
61  eps_abs, eps_rel, key);
62  return res;
63 }
64 
65 //-----------------------------------------------------------------------
67 //-----------------------------------------------------------------------
68 
69 double gsl_integrate_integrand_wrapper(double x, void* params)
70 {
71  const boost::function<double (double)>* f =
72  (const boost::function<double (double)>*) params;
73  return (*f)(x);
74 }
75 
76 //-----------------------------------------------------------------------
86 //-----------------------------------------------------------------------
87 
89 (const boost::function<double (double)>& F,
90  double xmin, double xmax, double &Res, double& Error_est,
91  double eps_abs, double eps_rel,
92  int key) const
93 {
94  gsl_function gf;
95  gf.function = &gsl_integrate_integrand_wrapper;
96  gf.params = (void *) &F;
97  int status = gsl_integration_qags(&gf, xmin, xmax, eps_abs, eps_rel,
98  max_ninterval, w, &Res, &Error_est);
99  gsl_check(status);
100 }
101 
102 //-----------------------------------------------------------------------
110 //-----------------------------------------------------------------------
111 
113 (const boost::function<double (double)>& F,
114  double xmin, double xmax, const std::vector<double>& breakpoints,
115  double &Res, double& Error_est,
116  double eps_abs, double eps_rel,
117  int key) const
118 {
119  gsl_function gf;
120  gf.function = &gsl_integrate_integrand_wrapper;
121  gf.params = (void *) &F;
122  std::vector<double> bp;
123  bp.push_back(xmin);
124  BOOST_FOREACH(double x, breakpoints)
125  if(x > xmin && x < xmax)
126  bp.push_back(x);
127  bp.push_back(xmax);
128  std::sort(bp.begin(), bp.end());
129  int status = gsl_integration_qagp(&gf, &bp[0], bp.size(),
130  eps_abs, eps_rel,
131  max_ninterval, w, &Res, &Error_est);
132  gsl_check(status);
133 }
GslIntegrate(int Max_intervals=1000)
This sets up the workspace need by GSL for integration.
double gsl_integrate_integrand_wrapper(double x, void *params)
Wrapper used by integrate.
void integrate_err_est(const boost::function< double(double)> &F, double xmin, double xmax, double &Res, double &Error_est, double eps_abs=0.0, double eps_rel=1e-8, int key=GSL_INTEG_GAUSS15) const
Calculate the definite integral of F from xmin to xmax.
#define gsl_check(status)
GSL check.
Definition: fp_exception.h:228
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
double integrate(const boost::function< double(double)> &F, double xmin, double xmax, double eps_abs=0.0, double eps_rel=1e-8, int key=GSL_INTEG_GAUSS15) const
Version of integrate that only returns the results, without the error estimate.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11