Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
hermiteexpansioncoefficient.cpp
Go to the documentation of this file.
2 
9  m_a(0),
10  m_b(0),
11  m_A(Vector3::createZeros()),
12  m_B(Vector3::createZeros())
13 {
14  reset(dimensionMax);
15 }
16 
17 void HermiteExpansionCoefficient::reset(int dimensionMax)
18 {
19  m_dimensionMax = dimensionMax;
20  int maxL = m_dimensionMax;
21  int maxiA = m_dimensionMax;
22  int maxiB = m_dimensionMax;
23  // Since we are only going to need E_i_j_0 for the integrals, we cap t to i and j to only have the
24  // needed values available for the algorithm.
25  int maxt = 2 * maxL;
26  for(int dim = 0; dim < 3; dim++) {
27  cube& dim_E = m_E[dim];
28  dim_E = zeros(maxiA, maxiB, maxt + 1);
29  }
30 }
31 
32 void HermiteExpansionCoefficient::set(double a, double b, const Vector3 &A, const Vector3 &B,
33  int iA, int iB, int jA, int jB, int kA, int kB)
34 {
35  m_a = a;
36  m_b = b;
37  m_A = A;
38  m_B = B;
39  setupE(iA, iB, jA, jB, kA, kB);
40 }
41 
43  if(t < 0 || t > (iA + iB) || iA < 0 || iB < 0) {
44  return false;
45  } else {
46  return true;
47  }
48 }
49 
50 void HermiteExpansionCoefficient::setupE(int iA, int iB, int jA, int jB, int kA, int kB) {
51  int maxiAs[3];
52  maxiAs[0] = iA + 1;
53  maxiAs[1] = jA + 1;
54  maxiAs[2] = kA + 1;
55 
56  int maxiBs[3];
57  maxiBs[0] = iB + 1;
58  maxiBs[1] = jB + 1;
59  maxiBs[2] = kB + 1;
60 
61  // Since we are only going to need E_i_j_0 for the integrals, we cap t to i and j to only have the
62  // needed values available for the algorithm.
63  int maxts[3];
64  maxts[0] = iA + iB + 1;
65  maxts[1] = jA + jB + 1;
66  maxts[2] = kA + kB + 1;
67 
68  double a = m_a;
69  double b = m_b;
70  double p = a + b;
71  double mu = a * b / (a + b);
72  m_AB = m_A - m_B;
73  m_P = (a * m_A + b * m_B) / p;
74  m_PA = m_P - m_A;
75  m_PB = m_P - m_B;
76  for(int dim = 0; dim < 3; dim++) {
77  cube& E = m_E[dim];
78  double AB = m_AB(dim);
79  double PA = m_PA(dim);
80  double PB = m_PB(dim);
81 
82  int maxiA = maxiAs[dim];
83  int maxiB = maxiBs[dim];
84  int maxt = maxts[dim];
85 
86  // First row is special
87  E(0,0,0) = exp(-mu * AB * AB);
88 
89  // Build the first row, iA = 0
90  for(int iB = 0; iB < maxiB; iB++) {
91  for(int t = 0; t < maxt; t++) {
92  int iA = 0;
93  if(iA == 0 && iB == 0 && t == 0) {
94  continue;
95  }
96  // p = previous, n = next
97  // E(t,i,j) = 1 / (2*p) * E(t-1,i,j-1) + XPA * E(t,i,j-1) + (t + 1)*E(t+1,i,j-1)
98  int iBp = iB - 1;
99  int tp = t - 1;
100  int tn = t + 1;
101  double E_iA_iBp_tp = 0;
102  if(checkIndexCombinationForE(iA, iBp, tp)) {
103  E_iA_iBp_tp = E(iA, iBp, tp);
104  }
105  double E_iA_iBp_t = 0;
106  if(checkIndexCombinationForE(iA, iBp, t)) {
107  E_iA_iBp_t = E(iA, iBp, t);
108  }
109  double E_iA_iBp_tn = 0;
110  if(checkIndexCombinationForE(iA, iBp, tn)) {
111  E_iA_iBp_tn = E(iA, iBp, tn);
112  }
113  E(iA,iB,t) = 1 / (2*p) * E_iA_iBp_tp + PB * E_iA_iBp_t + (t + 1)*E_iA_iBp_tn;
114  }
115  }
116 
117  // Iterate over all rows for iA >= 1
118  for(int iA = 1; iA < maxiA; iA++) {
119  for(int iB = 0; iB < maxiB; iB++) {
120  for(int t = 0; t < maxt; t++) {
121  // p = previous, n = next
122  // E(t,i,j) = 1 / (2*p) * E(t-1,i-1,j) + XPA * E(t,i-1,j) + (t + 1)*E(t+1,i-1,j)
123  int iAp = iA - 1;
124  int tp = t - 1;
125  int tn = t + 1;
126  double E_iAp_iB_tp = 0;
127  if(checkIndexCombinationForE(iAp, iB, tp)) {
128  E_iAp_iB_tp = E(iAp, iB, tp);
129  }
130  double E_iAp_iB_t = 0;
131  if(checkIndexCombinationForE(iAp, iB, t)) {
132  E_iAp_iB_t = E(iAp, iB, t);
133  }
134  double E_iAp_iB_tn = 0;
135  if(checkIndexCombinationForE(iAp, iB, tn)) {
136  E_iAp_iB_tn = E(iAp, iB, tn);
137  }
138  E(iA,iB,t) = 1 / (2*p) * E_iAp_iB_tp + PA * E_iAp_iB_t + (t + 1)*E_iAp_iB_tn;
139  }
140  }
141  }
142  }
143 }