MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
sigma.hpp
1#ifndef MPQC_CI_SIGMA_HPP
2#define MPQC_CI_SIGMA_HPP
3
4#include "mpqc/ci/ci.hpp"
5#include "mpqc/ci/string.hpp"
6#include "mpqc/ci/sigma2.hpp"
7#include "mpqc/ci/sigma3.hpp"
8#include "mpqc/ci/vector.hpp"
9
10#include "mpqc/utility/timer.hpp"
11#include "mpqc/range.hpp"
12#include "mpqc/math/matrix.hpp"
13#include "mpqc/mpi.hpp"
14#include "mpqc/mpi/task.hpp"
15
16#include "mpqc/utility/profile.hpp"
17
18namespace mpqc {
19namespace ci {
20
23
29 template<class Type, class Index>
30 void sigma(const CI<Type, Index> &ci,
31 const mpqc::Vector &h, const Matrix &V,
32 ci::Vector &C, ci::Vector &S) {
33
34 struct { double s1, s2, s3; timer t; } time = { };
35
36 auto &comm = ci.comm;
37
38 size_t no = ci.alpha[0].size();
39 mpqc::Vector H = h;
40 for (int j = 0; j < no; ++j) {
41 for (int i = 0; i <= j; ++i) {
42 double v = 0;
43 for (int k = 0; k < no; ++k) {
44 v += V(index(i,k), index(k,j));
45 }
46 H(index(i,j)) -= 0.5*v;
47 }
48 }
49
50 const std::vector< Subspace<Alpha> > &alpha = ci.subspace.alpha();
51 const std::vector< Subspace<Beta> > &beta = ci.subspace.beta();
52 const auto &blocks = ci::blocks(alpha, beta);
53
54 std::unique_ptr<MPI::Task> task;
55
56 task.reset(new MPI::Task(comm));
57#pragma omp parallel
58 while (true) {
59
60 auto next = task->next(blocks.begin(), blocks.end());
61 if (next == blocks.end()) break;
62
63 auto Ia = alpha.at(next->alpha);
64 auto Ib = beta.at(next->beta);
65 if (!ci.test(Ia,Ib)) continue;
66
67 Matrix s = Matrix::Zero(Ia.size(), Ib.size()); //S(Ia, Ib);
68
69 // sigma1
70 BOOST_FOREACH (auto Jb, beta) {
71 MPQC_PROFILE_LINE;
72 // only single and double excitations are allowed
73 if (!ci.test(Ia,Jb) || ci.diff(Ib,Jb) > 2) continue;
74 Matrix c = C(Ia,Jb);
75 timer t;
76 sigma12(ci, Ib, Jb, H, V, c, s);
77#pragma omp master
78 time.s1 += t;
79 }
80
81 // with ms == 0 symmetry, S is symmetrized in sigma3 step
82 if (ci.config.ms == 0) goto end;
83
84 // sigma2, need to transpose s, c
85 s = Matrix(s.transpose());
86 BOOST_FOREACH (auto Ja, alpha) {
87 MPQC_PROFILE_LINE;
88 if (!ci.test(Ja,Ib) || ci.diff(Ia,Ja) > 2) continue;
89 Matrix c = Matrix(C(Ja,Ib)).transpose();
90 timer t;
91 sigma12(ci, Ia, Ja, H, V, c, s);
92 time.s2 += t;
93 }
94 s = Matrix(s.transpose());
95
96 end:
97 //s = Matrix::Random(Ia.size(), Ib.size());
98 S(Ia,Ib) = s;
99
100 }
101
102 task.reset(new MPI::Task(comm));
103#pragma omp parallel
104 while (true) {
105
106 timer t;
107
108 auto next = task->next(blocks.begin(), blocks.end());
109 if (next == blocks.end()) break;
110
111 if (ci.config.ms == 0 && next->alpha > next->beta) continue;
112
113 auto Ia = alpha.at(next->alpha);
114 auto Ib = beta.at(next->beta);
115 if (!ci.test(Ia,Ib)) continue;
116
117 // excitations from Ib into each Jb subspace
118 std::vector< Excitations<Beta> > BB;
119 BOOST_FOREACH (auto Jb, beta) {
120 MPQC_PROFILE_LINE;
121 BB.push_back(Excitations<Beta>(ci, Ib, Jb));
122 }
123
124 // excitations from Ia into each Ja subspace
125 std::vector< Excitations<Alpha> > AA;
126 BOOST_FOREACH (auto Ja, alpha) {
127 MPQC_PROFILE_LINE;
128 AA.push_back(Excitations<Alpha>(ci, Ia, Ja));
129 }
130
131 Matrix s = S(Ia,Ib);
132
133 // if symmetric CI, symmetrize diagonal block
134 if (ci.config.ms == 0 && next->alpha == next->beta)
135 s += Matrix(s).transpose();
136
137 for (auto bb = BB.begin(); bb != BB.end(); ++bb) {
138 MPQC_PROFILE_LINE;
139 if (!bb->size()) continue; // no beta excitations
140 auto Jb = bb->J();
141 for (auto aa = AA.begin(); aa != AA.end(); ++aa) {
142 if (!aa->size()) continue; // no alpha excitations
143 auto Ja = aa->J();
144 if (!ci.test(Ja,Jb)) continue; // forbidden block
145 Matrix c = C(Ja,Jb);
146 timer t;
147 sigma3(*aa, *bb, V, c, s);
148#pragma omp master
149 time.s3 += t;
150 }
151 }
152
153 //s = Matrix::Random(Ia.size(), Ib.size());
154
155 // if symmetric CI, symmetrize off-diagonal blocks S(Ia,Ib) and S(Ib,Ia)
156 if (ci.config.ms == 0 && next->alpha != next->beta) {
157 MPQC_PROFILE_LINE;
158 Matrix t = S(Ib,Ia);
159 t += s.transpose();
160 s = t.transpose();
161 S(Ib,Ia) = t;
162 }
163
164 {
165 MPQC_PROFILE_LINE;
166 S(Ia,Ib) = s;
167 }
168
169 }
170
171 S.sync();
172
173 sc::ExEnv::out0() << sc::indent << "sigma took " << double(time.t) << std::endl;
174 sc::ExEnv::out0() << sc::indent << " sigma1: " << time.s1 << std::endl;
175 sc::ExEnv::out0() << sc::indent << " sigma2: " << time.s2 << std::endl;
176 sc::ExEnv::out0() << sc::indent << " sigma3: " << time.s3 << std::endl;
177
178
179 }
180
182
183}
184}
185
186#endif /* MPQC_CI_SIGMA_HPP */
187
static std::ostream & out0()
Return an ostream that writes from node 0.
void sigma(const CI< Type, Index > &ci, const mpqc::Vector &h, const Matrix &V, ci::Vector &C, ci::Vector &S)
Computes sigma 1,2,3 contributions.
Definition sigma.hpp:30
matrix< double > Matrix
Convience double matrix type.
Definition matrix.hpp:170
Contains new MPQC code since version 3.
Definition integralenginepool.hpp:37
Distributed task.
Definition task.hpp:22
CI class template.
Definition ci.hpp:75
bool test(const String &a) const
test if string is allowed
Definition ci.hpp:193
const ci::Config config
CI configuration.
Definition ci.hpp:79
SubspaceGrid subspace
CI subspaces grid.
Definition ci.hpp:84
static int diff(const Space< Spin > &a, const Space< Spin > &b)
test if space configuration is allowed
Definition ci.hpp:188
MPI::Comm comm
CI communicator.
Definition ci.hpp:86
ci::String::List< Index > alpha
Alpha string list.
Definition ci.hpp:81
size_t ms
magnetic moment/Ms
Definition ci.hpp:26
Vector of single particle excitations from I to J subspace.
Definition sigma3.hpp:70
const std::vector< Subspace< Alpha > > & alpha() const
Returns all alpha subspaces.
Definition subspace.hpp:144
const std::vector< Subspace< Beta > > & beta() const
Returns all beta subspaces.
Definition subspace.hpp:149
Block CI Vector, with 1-d (vector) and 2-d (matrix) access.
Definition vector.hpp:18
Matrix class derived from Eigen::Matrix with additional MPQC integration.
Definition matrix.hpp:23
Definition timer.hpp:9
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition matrix.hpp:133

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.