Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
hermiteintegral.cpp
Go to the documentation of this file.
1 #include "hermiteintegral.h"
2 
3 #include "math/vector3.h"
4 #include <math/boysfunction.h>
5 
12  m_alpha(0),
13  m_A(Vector3::createZeros()),
14  m_dimensionMax(dimensionMax)
15 {
16  reset(dimensionMax);
17 }
18 
19 void HermiteIntegral::reset(int dimension)
20 {
21  m_dimensionMax = dimension;
22  int tMax = m_dimensionMax;
23  int nMax = m_dimensionMax;
24  m_R.reset();
25  // nMax + 1 because looking up element n = nMax requires a size of nMax + 1 to be available
26  m_R.set_size(nMax + 1);
27  for(int n = 0; n <= nMax; n++) {
28  m_R(n) = zeros(tMax + 1, tMax + 1, tMax + 1);
29  }
30 }
31 
32 void HermiteIntegral::set(double alpha, const Vector3 &A,
33  int t, int u, int v)
34 {
35  m_alpha = alpha;
36  m_A = A;
37  setupR(t, u, v);
38 }
39 
40 void HermiteIntegral::setupR(int tin, int uin, int vin) {
41  const Vector3 &PC = m_A;
42  double p = m_alpha;
43  double boysArg = p * dot(m_A, m_A);
44  int tuvSumMax = tin + uin + vin;
45  int nMax = tin + uin + vin;
46  boysFunction.set(boysArg, nMax);
47  // Calculate R0_tuv
48  double powResult = 1;
49  m_R(0)(0,0,0) = boysFunction.result(0);
50  for(int n = 1; n <= nMax; n++) {
51  powResult *= -2*p;
52  m_R(n)(0,0,0) = powResult * boysFunction.result(n);
53  }
54  // Iterate over all elements with t + u + v = tuvSum (slide 36)
55  for(int tuvSum = 1; tuvSum <= tuvSumMax; tuvSum++) {
56  for(int n = 0; n <= nMax - tuvSum; n++) {
57  for(int t = 0; t <= tin; t++) {
58  for(int u = 0; u <= uin; u++) {
59  for(int v = 0; v <= vin; v++) {
60  if(t + u + v != tuvSum || t + u + v == 0) {
61  continue;
62  }
63  int largestElement = max(t,max(u,v));
64  // Needed indices
65  int t2 = t;
66  int u2 = u;
67  int v2 = v;
68  int t3 = t;
69  int u3 = u;
70  int v3 = v;
71  // Resulting factors
72  int factor2 = t;
73  double factor3 = PC(0);
74  // Choose indices based on method (slide 34)
75  if(largestElement == t) {
76  t2 = t - 2;
77  t3 = t - 1;
78  factor2 = t - 1;
79  factor3 = PC(0);
80  } else if(largestElement == u) {
81  u2 = u - 2;
82  u3 = u - 1;
83  factor2 = u - 1;
84  factor3 = PC(1);
85  } else {
86  v2 = v - 2;
87  v3 = v - 1;
88  factor2 = v - 1;
89  factor3 = PC(2);
90  }
91  double currentValue = 0;
92  if(t2 >= 0 && u2 >= 0 && v2 >= 0) {
93  currentValue += factor2 * m_R(n+1)(t2, u2, v2);
94  }
95  if(t3 >= 0 && u3 >= 0 && v3 >= 0) {
96  currentValue += factor3 * m_R(n+1)(t3, u3, v3);
97  }
98  m_R(n)(t, u, v) = currentValue;
99  }
100  }
101  }
102  }
103  }
104 }