MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
marley::Integrator Class Reference

Numerical integrator that uses Clenshaw-Curtis quadrature More...

#include <Integrator.hh>

Public Member Functions

 Integrator (size_t num=N_DEFAULT_)
 Create a Clenshaw-Curtis quadrature integrator that uses 2*num sampling points.
 
double num_integrate (const std::function< double(double)> &f, double a, double b) const
 Numerically integrate an arbitrary 1D function.
 

Detailed Description

Numerical integrator that uses Clenshaw-Curtis quadrature

Definition at line 28 of file Integrator.hh.

Constructor & Destructor Documentation

◆ Integrator()

marley::Integrator::Integrator ( size_t num = N_DEFAULT_)

Create a Clenshaw-Curtis quadrature integrator that uses 2*num sampling points.

Parameters
numhalf the number of sampling points to use
Todo
add error check for when num == 0 or too small
Todo
Todo
add error check for when num is ridiculously large

Definition at line 22 of file Integrator.cc.

22 : N_(num), weights_(num + 1, 0.),
23 offsets_(num - 1)
24{
27
28 // Precompute the N_ - 1 offsets for speed
29 double arg = 0.;
30 for (size_t n = 0; n < N_ - 1; ++n) {
31 arg += marley_utils::half_pi / N_;
32 offsets_[n] = std::cos(arg);
33 }
34
35 // Also precompute the N_ + 1 weights
36 for (size_t n = 0; n <= N_; ++n) {
37 for (size_t k = 0; k <= N_; ++k) {
38 double weight_piece = std::cos(n * k * marley_utils::pi / N_)
39 / (1. - std::pow(2*k, 2));
40 if (k != 0 && k != N_) weight_piece *= 2.;
41 weights_[n] += weight_piece;
42 }
43 weights_[n] /= N_;
44 }
45}

Member Function Documentation

◆ num_integrate()

double marley::Integrator::num_integrate ( const std::function< double(double)> & f,
double a,
double b ) const

Numerically integrate an arbitrary 1D function.

Numerically integrate a std::function<double(double)> over the interval [a,b] using Clenshaw-Curtis quadrature at 2N_ sampling points.

Definition at line 47 of file Integrator.cc.

49{
50 double A = (b - a) / 2.;
51 double B = (b + a) / 2.;
52 double C = (f(a) + f(b)) / 2.;
53
54 double integral = weights_[0] * C; // n = 0 term
55 integral += weights_[N_] * f(B); // n = N_ term
56
57 // n = 1 to n = N_ - 1 terms
58 for (size_t n = 1; n < N_; ++n) {
59 double epoint = A * offsets_[n - 1];
60 integral += weights_[n] * (f(B + epoint) + f(B - epoint));
61 }
62
63 return A * integral;
64}

Referenced by marley::DiscreteNuclearReaction::total_xs().


The documentation for this class was generated from the following files: