MPQC  3.0.0-alpha
sigma2.hpp
1 #ifndef MPQC_CI_SIGMA2_HPP
2 #define MPQC_CI_SIGMA2_HPP
3 
4 #include "mpqc/ci/string.hpp"
5 #include "mpqc/ci/ci.hpp"
6 
7 #include "mpqc/utility/timer.hpp"
8 #include "mpqc/range.hpp"
9 #include "mpqc/math/matrix.hpp"
10 
11 namespace mpqc {
12 namespace ci {
13 
14  template<class CI, class Spin>
15  void sigma12(const CI &ci,
16  const String &I, const Subspace<Spin> &S,
17  const mpqc::Vector &h, const mpqc::Matrix &V,
18  mpqc::Vector &F)
19  {
20  size_t count = I.count();
21  const auto &list = ci.template strings<Spin>();
22  int idx = list[I];
23 
24  std::vector<int> O, E;
25  for (size_t l = 0; l < I.size(); ++l) {
26  if (I[l])
27  O.push_back(l); // occ. orbs
28  if (!I[l]) {
29  E.push_back(l); // exc. orbs
30  }
31  }
32 
33  //asm("#andrey");
34  for (auto k = O.begin(); k < O.end(); ++k) {
35 
36  E.push_back(*k); // k->k
37 
38  for (auto l = E.begin(); l < E.end(); ++l) {
39  String J = I.swap(*k,*l);
40 
41  // out-of-subspace
42  if (abs(ci.excitation(J) - S.rank()) > 1) continue;
43 
44  double sgn_kl = sgn(I,*k,*l);
45  int kl = index(*k,*l);
46  int jdx = (ci.test(J) ? list[J] : -1);
47 
48  std::swap(*k,*l); // k->l
49 
50  bool singles = false;
51  if (S.test(jdx)) {
52  singles = true;
53  F(jdx-*S.begin()) += sgn_kl*h(kl);
54  // l->k, i->i
55  BOOST_FOREACH (int i, O) {
56  F(jdx-*S.begin()) += 0.5*sgn_kl*V(index(i,i),kl);
57  }
58  }
59 
60  // l->k, i->j
61  for (auto j = E.begin(); j < E.end()-1; ++j) {
62  //if (!ci.test(J) && *j > *l) continue;
63  for (auto i = O.begin(); i < O.end(); ++i) {
64  String K = J.swap(*i,*j);
65  if (ci.excitation(K) != S.rank()) continue;
66  int kdx = list[K];
67  if (S.test(kdx))
68  F(kdx-*S.begin()) += 0.5*sgn_kl*sgn(J,*i,*j)*V(index(*i,*j),kl);
69  }
70  }
71 
72  // restore original vectors
73  std::swap(*k,*l);
74 
75  }
76 
77  E.pop_back();
78 
79  } // k
80  }
81 
82  template<class CI, class Spin>
83  void sigma12(const CI &ci, Subspace<Spin> I, Subspace<Spin> J,
84  const mpqc::Vector &H, const mpqc::Matrix &V,
85  const mpqc::Matrix &C,
86  mpqc::Matrix &S)
87  {
88  mpqc::Vector F = mpqc::Vector::Zero(J.size());
89  for (int i = 0; i < (int)I.size(); ++i) {
90  sigma12(ci, ci.template strings<Spin>()[i+*I.begin()], J, H, V, F);
91  for (size_t j = 0; j < J.size(); ++j) {
92  double f = F(j);
93  F(j) = 0;
94  if (fabs(f) < 1e-14) continue;
95  S.col(i) += f*C.col(j);
96  }
97  }
98  }
99 
100 }
101 }
102 
103 #endif /* MPQC_CI_SIGMA2_HPP */
104 
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::matrix
Matrix class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:21
mpqc::vector
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.