Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
BoysFunction Class Reference

Calculates the Boys function efficiently for any argument and level. More...

#include <boysfunction.h>

Collaboration diagram for BoysFunction:
Collaboration graph
[legend]

Public Member Functions

 BoysFunction ()
 
 BoysFunction (double arg, int levelMax=0, BoysFunctionIntermediate *intermediate=0)
 
void set (double arg, int levelMax=0, BoysFunctionIntermediate *intermediate=0)
 
double result (int level=0) const
 

Static Public Member Functions

static double calculateAsymptopticForm (double arg, int level)
 
static double calculateTaylorExpansion (double arg, int level)
 
static double calculateZeroLevel (double arg)
 
static double doubleFactorial (double n)
 
static double factorial (double n)
 

Protected Attributes

vec m_results
 
BoysFunctionIntermediatem_intermediate
 

Detailed Description

Calculates the Boys function efficiently for any argument and level.

The argument and the highest level is specified upon construction, while the other levels are fetched on demand.

Definition at line 10 of file boysfunction.h.

Constructor & Destructor Documentation

BoysFunction::BoysFunction ( )

Definition at line 15 of file boysfunction.cpp.

16 {
17 
18 }
BoysFunction::BoysFunction ( double  arg,
int  levelMax = 0,
BoysFunctionIntermediate intermediate = 0 
)

Definition at line 20 of file boysfunction.cpp.

21 {
22  set(arg, levelMax, intermediate);
23 }

Member Function Documentation

double BoysFunction::calculateAsymptopticForm ( double  arg,
int  level 
)
static

Definition at line 56 of file boysfunction.cpp.

56  {
57  double n = level;
58  double dfac = doubleFactorial(2 * n - 1);
59  double result = dfac / pow(2, n + 1) * sqrt(M_PI / pow(arg, 2*n + 1));
60  return result;
61 }
double BoysFunction::calculateTaylorExpansion ( double  arg,
int  level 
)
static

Definition at line 86 of file boysfunction.cpp.

86  {
87  double n = level;
88  double result = 0;
89  for(int k = 0; k < 100; k++) {
90  result += pow(-arg, k) / (factorial(k) * (2 * n + 2 * k + 1));
91  }
92  return result;
93 }
double BoysFunction::calculateZeroLevel ( double  arg)
static

Definition at line 95 of file boysfunction.cpp.

95  {
96  if (arg < 1.0E-6){
97  return 1.0;
98  } else {
99  arg = sqrt(arg);
100  double f = 1.0/arg * erf(arg) *sqrt(M_PI)/2.0;
101  return f;
102  }
103 }
double BoysFunction::doubleFactorial ( double  n)
static

Definition at line 63 of file boysfunction.cpp.

63  {
64  if(n == -1) {
65  return 1;
66  }
67  double result = 1;
68  for(double i = n; i >= 1; i -= 2) {
69  result *= i;
70  }
71  return result;
72 }
double BoysFunction::factorial ( double  n)
static

Definition at line 74 of file boysfunction.cpp.

74  {
75  if(n == 0) {
76  return 1;
77  }
78  double result = 1;
79  double startPoint = 2;
80  for(double i = startPoint; i <= n; i++) {
81  result *= i;
82  }
83  return result;
84 }
double BoysFunction::result ( int  level = 0) const

Definition at line 105 of file boysfunction.cpp.

106 {
107  return m_results(level);
108 }
void BoysFunction::set ( double  arg,
int  levelMax = 0,
BoysFunctionIntermediate intermediate = 0 
)

Definition at line 25 of file boysfunction.cpp.

26 {
27  double limitMin = 0;
28  double limitMax = 50;
29  if(intermediate == 0) {
31  } else {
32  m_intermediate = intermediate;
33  }
34  double x = arg;
35  m_results = zeros(levelMax + 1);
36  double expmx = exp(-x);
37  if(arg < limitMin || arg > limitMax) {
38  if(arg < limitMin) {
39  m_results(levelMax) = calculateTaylorExpansion(arg, levelMax);
40  } else if(arg > limitMax) {
41  m_results(levelMax) = calculateAsymptopticForm(arg, levelMax);
42  }
43  // Iterate down
44  for(int n = levelMax; n > 0; n--) {
45  double Fn = m_results(n);
46  m_results(n - 1) = (2*x*Fn + expmx) / (2*n - 1);
47  }
48  } else {
49  // Get results from intermediate area
50  for(int n = 0; n < levelMax + 1; n++) {
51  m_results(n) = m_intermediate->result(arg, n);
52  }
53  }
54 }

Member Data Documentation

BoysFunctionIntermediate* BoysFunction::m_intermediate
protected

Definition at line 28 of file boysfunction.h.

vec BoysFunction::m_results
protected

Definition at line 27 of file boysfunction.h.


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