MPQC  3.0.0-alpha
collapse.hpp
1 #ifndef MPQC_CI_COLLAPSE_HPP
2 #define MPQC_CI_COLLAPSE_HPP
3 
4 #include "mpqc/ci/string.hpp"
5 
6 #include "mpqc/math.hpp"
7 #include "mpqc/array.hpp"
8 #include "mpqc/python.hpp"
9 #include "mpqc/file.hpp"
10 #include "mpqc/task.hpp"
11 
12 // #define MPQC_PROFILE_ENABLE
13 // #include "mpqc/profile.hpp"
14 
15 namespace mpqc {
16 namespace ci {
17 
19 
20  void collapse() {
21  // collapse
22  if (ci.collapse && (M > ci.collapse)) {
23  printf("collapse %lu to %lu\n", M, ci.collapse);
24  int k = 0;
25  Vector c = a.col(k);
26 
27  {
28  Matrix v(alpha.size(), beta.size());
29  Matrix C(alpha.size(), beta.size());
30  Matrix S(alpha.size(), beta.size());
31 
32  C.fill(0);
33  // shift b(i+1) to b(i)
34  for (int i = 0; i < M; ++i) {
35  ds.b(alpha,beta,i) >> v;
36  //ds.b(alpha,beta,j) << v;
37  C += c(i)*v;
38  printf("C* = %e*C(%i)\n", c(i), i);
39  //printf("C(%i) = C(%i)\n", j, i);
40  }
41  // printf("C(%lu) = C*\n", ci.collapse);
42  // ds.b(alpha,beta,ci.collapse) << d;
43 
44  S.fill(0);
45  // shift Hb(i+1) to Hb(i)
46  for (int i = 0; i < M; ++i) {
47  ds.Hb(alpha,beta,i) >> v;
48  //ds.Hb(alpha,beta,j) << v;
49  S += c(i)*v;
50  printf("S* = %e*S(%i)\n", c(i), i);
51  //printf("S(%i) = S(%i)\n", j, i);
52  }
53  // printf("S(%lu) = S*\n", ci.collapse);
54  // ds.Hb(alpha,beta,ci.collapse) << d;
55 
56 
57  for (int j = 1; j < ci.collapse; ++j) {
58  C.fill(0);
59  auto last = iters[it-j];
60  for (int i = 0; i < last.M; ++i) {
61  double a = last.a(i,k);
62  ds.b(alpha,beta,i) >> v;
63  C += a*v;
64  printf("C* = %e*C(%i)\n", a, i);
65  }
66  Matrix b(alpha.size(), beta.size());
67  ds.b(alpha,beta,i) >> b;
68  orthonormalize(alpha, beta, b, C);
69  std::cout << C << std::endl;
70  }
71 
72 
73  }
74 
75  M = ci.collapse;
76 
77  throw;
78 
79  // orthonormalize
80  for (int i = 0; i < M; ++i) {
81  MPQC_PROFILE_LINE;
82  Array<double> &b = C;
83  b.read(ds.b[i]);
84  double q = orthonormalize(alpha, beta, b, D);
85  }
86 
87 
88  for (auto rb : range(beta).block(128)) {
89  MPQC_PROFILE_LINE;
90  Matrix c(alpha.size(), rb.size());
91  const Matrix &s = D(alpha, rb);
92  for (int j = 0; j < M; ++j) {
93  int i = it;
94  ds.b(alpha,rb,j) >> c;
95  double q = 0;
96 #pragma omp parallel for schedule(dynamic,1) reduction(+:q)
97  for (int b = 0; b < rb.size(); ++b) {
98  q += dot(c.col(b), s.col(b));
99  }
100  G(i,j) += q;
101  G(j,i) = G(i,j);
102  }
103  }
104  // solve G eigenvalue
105  Vector lambda = symmetric(G).eigenvalues();
106  Matrix a = symmetric(G).eigenvectors();
107  iters[it].lambda = lambda;
108  //std::cout << "G:\n" << G << std::endl;
109 
110  }
111  }
112 
113 } // namespace ci
114 } // namespace mpqc
115 
116 #endif /* MPQC_CI_COLLAPSE_HPP */
mpqc::orthonormalize
void orthonormalize(matrix< T > &d, const matrix< T > &b)
orthormalize matrix d wrt to normalized matrix b d = normalize(d - (<d|b>*b))
Definition: matrix.hpp:224
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::Matrix
matrix< double > Matrix
Convience double matrix type.
Definition: matrix.hpp:170
mpqc::dot
T dot(const matrix< T > &a, const matrix< T > &b)
element-wise dot product of two matrices
Definition: matrix.hpp:186
mpqc::Vector
vector< double > Vector
Convience double vector type.
Definition: matrix.hpp:172
mpqc::symmetric
Eigen::SelfAdjointEigenSolver< Matrix::EigenType > symmetric(const matrix< T > &a)
Computes (Eigen::SelfAdjointEigenSolver) eigensystem of a matrix.
Definition: matrix.hpp:199

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