Version: SMASH-3.1
smash::Result Class Reference

#include <integrate.h>

The result type returned from integrations, containing the value and an error.

Definition at line 54 of file integrate.h.

Inheritance diagram for smash::Result:

Public Member Functions

 operator double () const
 Conversion to double yields the value of the integral. More...
 
double value () const
 Access the first entry in the pair as the value. More...
 
double error () const
 Access the second entry in the pair as the absolute error. More...
 
void check_error (const std::string &integration_name, double relative_tolerance=5e-4, double absolute_tolerance=1e-9) const
 Check whether the error is small and alert if it is not. More...
 

Private Types

using Base = std::pair< double, double >
 The data type to store the value and the error of the integration. More...
 

Member Typedef Documentation

◆ Base

using smash::Result::Base = std::pair<double, double>
private

The data type to store the value and the error of the integration.

Definition at line 56 of file integrate.h.

Member Function Documentation

◆ operator double()

smash::Result::operator double ( ) const
inline

Conversion to double yields the value of the integral.

Definition at line 63 of file integrate.h.

63 { return Base::first; }

◆ value()

double smash::Result::value ( ) const
inline

Access the first entry in the pair as the value.

Definition at line 66 of file integrate.h.

66 { return Base::first; }

◆ error()

double smash::Result::error ( ) const
inline

Access the second entry in the pair as the absolute error.

Definition at line 69 of file integrate.h.

69 { return Base::second; }

◆ check_error()

void smash::Result::check_error ( const std::string &  integration_name,
double  relative_tolerance = 5e-4,
double  absolute_tolerance = 1e-9 
) const
inline

Check whether the error is small and alert if it is not.

Parameters
[in]integration_nameName of the integration used for error message.
[in]relative_toleranceRelative error tolerance.
[in]absolute_toleranceAbsolute error tolerance.

Definition at line 79 of file integrate.h.

81  {
82  const double allowed_error =
83  std::max(absolute_tolerance, value() * relative_tolerance);
84  if (error() > allowed_error) {
85  std::stringstream error_msg;
86  error_msg << integration_name << " resulted in I = " << value() << " ± "
87  << error()
88  << ", but the required precision is either absolute error < "
89  << absolute_tolerance << " or relative error < "
90  << relative_tolerance << std::endl;
91  throw std::runtime_error(error_msg.str());
92  }
93  }
double value() const
Access the first entry in the pair as the value.
Definition: integrate.h:66
double error() const
Access the second entry in the pair as the absolute error.
Definition: integrate.h:69

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