NcmIntegral

NcmIntegral — Numerical integration helpers.

Stability Level

Stable, unless otherwise indicated

Functions

Types and Values

Includes

#include <numcosmo/math/ncm_integrate.h>

Description

This module provides functions to perform numerical integration. It uses GSL library to perform the integration.

Functions

ncm_integral_get_workspace ()

gsl_integration_workspace **
ncm_integral_get_workspace (void);

This function provides a workspace to be used by numerical integration functions of GSL. It keeps a internal pool of workspaces and allocate a new one if the function is called and the pool is empty. It is designed to be used in a multi-thread environment. The workspace must be unlocked in order to return to the pool. This must be done using the ncm_memory_pool_return.

[skip]

Returns

a pointer to gsl_integration_workspace structure.


_NcmIntegrand2dimFunc ()

gdouble
(*_NcmIntegrand2dimFunc) (gdouble x,
                          gdouble y,
                          gpointer userdata);

NcmIntegralPeakfinder ()

void
(*NcmIntegralPeakfinder) (const gint *ndim,
                          const gdouble b[],
                          gint *n,
                          gdouble x[],
                          void *userdata);

_NcmIntegrand3dimFunc ()

gdouble
(*_NcmIntegrand3dimFunc) (gdouble x,
                          gdouble y,
                          gdouble z,
                          gpointer userdata);

ncm_integral_locked_a_b ()

gint
ncm_integral_locked_a_b (gsl_function *F,
                         gdouble a,
                         gdouble b,
                         gdouble abstol,
                         gdouble reltol,
                         gdouble *result,
                         gdouble *error);

This function uses a workspace from the pool and gsl_integration_qag function to perform the numerical integration in the [a, b] interval.

[skip]

Parameters

F

a gsl_function wich is the integrand.

 

a

lower integration limit.

 

b

upper integration limit.

 

abstol

absolute tolerance.

 

reltol

relative tolerance.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

the error code returned by gsl_integration_qag.


ncm_integral_locked_a_inf ()

gint
ncm_integral_locked_a_inf (gsl_function *F,
                           gdouble a,
                           gdouble abstol,
                           gdouble reltol,
                           gdouble *result,
                           gdouble *error);

This function uses a workspace from the pool and gsl_integration_qagiu function to perform the numerical integration in the $[a, \infty]$ interval.

[skip]

Parameters

F

a gsl_function which is the integrand.

 

a

lower integration limit.

 

abstol

absolute tolerance.

 

reltol

relative tolerance.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

the error code returned by gsl_integration_qagiu.


ncm_integral_cached_0_x ()

gint
ncm_integral_cached_0_x (NcmFunctionCache *cache,
                         gsl_function *F,
                         gdouble x,
                         gdouble *result,
                         gdouble *error);

This function searches for the nearest x_near value previously chosen as the upper integration limit and perform the integration at [x_near, x] interval. This result is summed to that obtained at [0, x_near] and then it is saved in the cache.

[skip]

Parameters

cache

a pointer to NcmFunctionCache.

 

F

a gsl_function wich is the integrand.

 

x

upper integration limit.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

the error code returned by gsl_integration_qag.


ncm_integral_cached_x_inf ()

gint
ncm_integral_cached_x_inf (NcmFunctionCache *cache,
                           gsl_function *F,
                           gdouble x,
                           gdouble *result,
                           gdouble *error);

This function searchs for the nearest x_near value previously chosed as the lower integration limit and perform the integration at $[x, x_{near}]$ interval. This result is summed to that obtained at $[x_{near}, \infty]$ and then it is saved in the cache.

[skip]

Parameters

cache

a pointer to NcmFunctionCache.

 

F

a gsl_function wich is the integrand.

 

x

lower integration limit.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

the error code returned by gsl_integration_qagiu.


ncm_integrate_2dim ()

gboolean
ncm_integrate_2dim (NcmIntegrand2dim *integ,
                    gdouble xi,
                    gdouble yi,
                    gdouble xf,
                    gdouble yf,
                    gdouble epsrel,
                    gdouble epsabs,
                    gdouble *result,
                    gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] using the Cuhre algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand2dim.

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

epsrel

relative error

 

epsabs

absolute error

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_2dim_divonne ()

gboolean
ncm_integrate_2dim_divonne (NcmIntegrand2dim *integ,
                            gdouble xi,
                            gdouble yi,
                            gdouble xf,
                            gdouble yf,
                            gdouble epsrel,
                            gdouble epsabs,
                            const gint ngiven,
                            const gint ldxgiven,
                            gdouble xgiven[],
                            gdouble *result,
                            gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] using the Divonne algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand2dim

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

epsrel

relative error

 

epsabs

absolute error

 

ngiven

number of peaks

 

ldxgiven

the leading dimension of xgiven, i.e. the offset between one point and the next in memory (ref. libcuba documentation)

 

xgiven

list of points where the integrand might have peaks (ref. libcuba documentation)

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_2dim_divonne_peakfinder ()

gboolean
ncm_integrate_2dim_divonne_peakfinder (NcmIntegrand2dim *integ,
                                       gdouble xi,
                                       gdouble yi,
                                       gdouble xf,
                                       gdouble yf,
                                       gdouble epsrel,
                                       gdouble epsabs,
                                       const gint ngiven,
                                       const gint ldxgiven,
                                       gdouble xgiven[],
                                       const gint nextra,
                                       NcmIntegralPeakfinder peakfinder,
                                       gdouble *result,
                                       gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] using the Divonne algorithm from the Cuba library. It uses a peakfinder to find the peaks of the integrand and improve the integration of concentrated functions.

Parameters

integ

a pointer to NcmIntegrand2dim

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

epsrel

relative error

 

epsabs

absolute error

 

ngiven

number of peaks

 

ldxgiven

the leading dimension of xgiven, i.e. the offset between one point and the next in memory (ref. libcuba documentation)

 

xgiven

list of points where the integrand might have peaks (ref. libcuba documentation)

 

nextra

the maximum number of extra points the peakfinder will return.

 

peakfinder

a NcmIntegralPeakfinder.

[scope call]

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_2dim_vegas ()

gboolean
ncm_integrate_2dim_vegas (NcmIntegrand2dim *integ,
                          gdouble xi,
                          gdouble yi,
                          gdouble xf,
                          gdouble yf,
                          gdouble epsrel,
                          gdouble epsabs,
                          const gint nstart,
                          gdouble *result,
                          gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] using the Vegas algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand2dim

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

epsrel

relative error

 

epsabs

absolute error

 

nstart

number of samples to start the first round of integration with.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_3dim ()

gboolean
ncm_integrate_3dim (NcmIntegrand3dim *integ,
                    gdouble xi,
                    gdouble yi,
                    gdouble zi,
                    gdouble xf,
                    gdouble yf,
                    gdouble zf,
                    gdouble epsrel,
                    gdouble epsabs,
                    gdouble *result,
                    gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] and [zi, zf] using the Cuhre algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand3dim.

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

zi

gbouble which is the lower integration limit of variable z.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

zf

gbouble which is the upper integration limit of variable z.

 

epsrel

relative error

 

epsabs

absolute error

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_3dim_divonne ()

gboolean
ncm_integrate_3dim_divonne (NcmIntegrand3dim *integ,
                            gdouble xi,
                            gdouble yi,
                            gdouble zi,
                            gdouble xf,
                            gdouble yf,
                            gdouble zf,
                            gdouble epsrel,
                            gdouble epsabs,
                            const gint ngiven,
                            const gint ldxgiven,
                            gdouble xgiven[],
                            gdouble *result,
                            gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] and [zi, zf] using the Divonne algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand3dim

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

zi

gbouble which is the lower integration limit of variable z.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

zf

gbouble which is the upper integration limit of variable z.

 

epsrel

relative error

 

epsabs

absolute error

 

ngiven

number of peaks

 

ldxgiven

the leading dimension of xgiven, i.e. the offset between one point and the next in memory (ref. libcuba documentation)

 

xgiven

list of points where the integrand might have peaks (ref. libcuba documentation)

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integrate_3dim_vegas ()

gboolean
ncm_integrate_3dim_vegas (NcmIntegrand3dim *integ,
                          gdouble xi,
                          gdouble yi,
                          gdouble zi,
                          gdouble xf,
                          gdouble yf,
                          gdouble zf,
                          gdouble epsrel,
                          gdouble epsabs,
                          const gint nstart,
                          gdouble *result,
                          gdouble *error);

This function computes the integral of the function integ->f over the interval [xi, xf] and [yi, yf] and [zi, zf] using the Vegas algorithm from the Cuba library.

Parameters

integ

a pointer to NcmIntegrand3dim

 

xi

gbouble which is the lower integration limit of variable x.

 

yi

gbouble which is the lower integration limit of variable y.

 

zi

gbouble which is the lower integration limit of variable z.

 

xf

gbouble which is the upper integration limit of variable x.

 

yf

gbouble which is the upper integration limit of variable y.

 

zf

gbouble which is the upper integration limit of variable z.

 

epsrel

relative error

 

epsabs

absolute error

 

nstart

number of samples to start the first round of integration with.

 

result

a pointer to a gdouble in which the function stores the result.

 

error

a pointer to a gdouble in which the function stores the estimated error.

 

Returns

whether the integration was successful.


ncm_integral_fixed_new ()

NcmIntegralFixed *
ncm_integral_fixed_new (gulong n_nodes,
                        gulong rule_n,
                        gdouble xl,
                        gdouble xu);

This function prepares the NcmIntegralFixed with a grid with n_nodes - 1 intervals beteween xl and xu. In each interval it uses a fixed order (rule_n) Gauss-Legendre integration rule to determine the interval inner points. This results in a grid with (n_nodes - 1) * rule_n points.

[skip]

Parameters

n_nodes

number of nodes in the full interval.

 

rule_n

order of the Gauss-Legendre integration rule to be applied in each interval.

 

xl

the interval lower limit.

 

xu

the interval upper limit.

 

Returns

a pointer to the newly created NcmIntegralFixed structure.


ncm_integral_fixed_free ()

void
ncm_integral_fixed_free (NcmIntegralFixed *intf);

This function frees the memory associated to NcmIntegralFixed.

Parameters

intf

a pointer to NcmIntegralFixed.

 

ncm_integral_fixed_calc_nodes ()

void
ncm_integral_fixed_calc_nodes (NcmIntegralFixed *intf,
                               gsl_function *F);

This function calculates the nodes of the NcmIntegralFixed. It uses the Gauss-Legendre integration rule to determine the interval inner points.

[skip]

Parameters

intf

a pointer to NcmIntegralFixed.

 

F

a pointer to a gsl_function.

 

ncm_integral_fixed_nodes_eval ()

gdouble
ncm_integral_fixed_nodes_eval (NcmIntegralFixed *intf);

This function evaluates the integral of the function integ->f over the interval [xi, xf] using the nodes calculated by ncm_integral_fixed_calc_nodes.

Parameters

intf

a pointer to NcmIntegralFixed.

 

Returns

the integral of the function integ->f over the interval [xi, xf].


ncm_integral_fixed_integ_mult ()

gdouble
ncm_integral_fixed_integ_mult (NcmIntegralFixed *intf,
                               gsl_function *F);

This function evaluates the integral of the function integ->f over the interval [xi, xf] using the nodes calculated by ncm_integral_fixed_calc_nodes. It uses the Gauss-Legendre integration rule to determine the interval inner points. This function multiplies the integrand by the function F .

[skip]

Parameters

intf

a pointer to NcmIntegralFixed.

 

F

a pointer to gsl_function.

 

Returns

the integral of the function integ->f times F over the interval [xi, xf].


ncm_integral_fixed_integ_posdef_mult ()

gdouble
ncm_integral_fixed_integ_posdef_mult (NcmIntegralFixed *intf,
                                      gsl_function *F,
                                      gdouble max,
                                      gdouble reltol);

This function computes the integral of the function integ->f over the interval starting at max and going to the left using the nodes calculated by ncm_integral_fixed_calc_nodes. It uses the Gauss-Legendre integration rule to determine the interval inner points. This function multiplies the integrand by the function F . It stops when the relative error is less than reltol .

[skip]

Parameters

intf

a pointer to NcmIntegralFixed

 

F

a pointer to gsl_function

 

max

maximum value of the integration interval

 

reltol

relative tolerance

 

Returns

the integral of the function integ->f times F over the interval [max, xf].

Types and Values

struct NcmIntegrand2dim

struct NcmIntegrand2dim {
};

FIXME


struct NcmIntegrand3dim

struct NcmIntegrand3dim {
};

FIXME


struct NcmIntegralFixed

struct NcmIntegralFixed {
};

FIXME


NCM_INTEGRAL_PARTITION

#define NCM_INTEGRAL_PARTITION 100000

NCM_INTEGRAL_ALG

#define NCM_INTEGRAL_ALG 6

NCM_INTEGRAL_ERROR

#define NCM_INTEGRAL_ERROR 1e-13

NCM_INTEGRAL_ABS_ERROR

#define NCM_INTEGRAL_ABS_ERROR 0.0