#include <integrate.h>
A C++ interface for numerical integration in one dimension with the GSL CQUAD integration functions.
Example:
const auto result =
integrate(0.1, 0.9, [](
double x) {
return x * x; });
Definition at line 106 of file integrate.h.
|
| Integrator (size_t workspace_size=1000) |
| Construct an integration functor with the given workspace_size . More...
|
|
template<typename F > |
Result | operator() (double a, double b, F &&fun) |
| The function call operator implements the integration functionality. More...
|
|
smash::Integrator::Integrator |
( |
size_t |
workspace_size = 1000 | ) |
|
|
inlineexplicit |
Construct an integration functor with the given workspace_size
.
- Note
- Since the workspace is allocated in the constructor and deallocated on destruction, you should not recreate Integrator objects unless required. Thus, if you want to calculate multiple integrals with the same
workspace_size
, keep the Integrator object around.
- Parameters
-
workspace_size | The internal workspace is allocated such that it can hold the given number of double precision intervals, their integration results, and error estimates. It also determines the maximum number of subintervals the integration algorithm will use. |
Definition at line 122 of file integrate.h.
123 :
workspace_(gsl_integration_cquad_workspace_alloc(workspace_size)) {}
std::unique_ptr< gsl_integration_cquad_workspace, GslWorkspaceDeleter > workspace_
Holds the workspace pointer.
template<typename F >
Result smash::Integrator::operator() |
( |
double |
a, |
|
|
double |
b, |
|
|
F && |
fun |
|
) |
| |
|
inline |
The function call operator implements the integration functionality.
- Parameters
-
[in] | a | The lower limit of the integral. |
[in] | b | The upper limit of the integral. |
- Template Parameters
-
F | Type of the integrand function. |
- Parameters
-
[in] | fun | The callable to integrate over. This callable may be a function pointer, lambda, or a functor object. In any case, the callable must return a double and take a single double argument. If you want to pass additional data to the callable you can e.g. use lambda captures. |
- Returns
- Pair of integral value and absolute error estimate.
Definition at line 139 of file integrate.h.
141 const gsl_function gslfun{
144 [](
double x,
void *type_erased) ->
double {
145 auto &&f = *
static_cast<F *
>(type_erased);
150 DisableFloatTraps guard;
151 const int error_code = gsl_integration_cquad(
153 &result.first, &result.second,
156 std::stringstream err;
157 err <<
"GSL 1D deterministic integration: " << gsl_strerror(error_code);
158 throw std::runtime_error(err.str());
std::unique_ptr< gsl_integration_cquad_workspace, GslWorkspaceDeleter > workspace_
Holds the workspace pointer.
const double accuracy_relative_
Parameter to the GSL integration function: desired relative error limit.
const double accuracy_absolute_
Parameter to the GSL integration function: desired absolute error limit.
std::unique_ptr<gsl_integration_cquad_workspace, GslWorkspaceDeleter> smash::Integrator::workspace_ |
|
private |
Holds the workspace pointer.
Definition at line 168 of file integrate.h.
const double smash::Integrator::accuracy_absolute_ = 1.0e-9 |
|
private |
Parameter to the GSL integration function: desired absolute error limit.
Definition at line 171 of file integrate.h.
const double smash::Integrator::accuracy_relative_ = 5.0e-4 |
|
private |
Parameter to the GSL integration function: desired relative error limit.
Definition at line 174 of file integrate.h.
The documentation for this class was generated from the following file: