12 m_initialCoefficientMatrixSetManually(false)
21 void RestrictedHartreeFockSolver::resetFockMatrix() {
23 m_fockMatrix = zeros(n,n);
26 void RestrictedHartreeFockSolver::resetCoefficientMatrix() {
28 m_coefficientMatrix.reset();
29 if(!m_initialCoefficientMatrixSetManually
31 || m_initialCoefficientMatrix.n_cols != f->
nParticlesUp()) {
34 m_coefficientMatrix = m_initialCoefficientMatrix;
37 void RestrictedHartreeFockSolver::setupFockMatrix() {
40 mat &F = m_fockMatrix;
41 const mat &P = m_densityMatrix;
43 for(uint p = 0; p < n; p++) {
44 for(uint q = 0; q < n; q++) {
46 for(uint r = 0; r < n; r++) {
47 for(uint s = 0; s < n; s++) {
48 double Qtilde = coupledMatrixTilde(p, q, r, s);
49 F(p,q) += 0.5 * Qtilde * P(s,r);
58 m_initialCoefficientMatrixSetManually =
true;
59 m_initialCoefficientMatrix = coefficients;
64 resetCoefficientMatrix();
78 const mat &F = m_fockMatrix;
79 mat Fprime = V.t() * F * V;
82 eig_sym(m_fockEnergies, Cprime, Fprime);
85 mat &C = m_coefficientMatrix;
86 C = V*Cprime.submat(0, 0, no - 1, nk - 1);
93 const mat& P = m_densityMatrix;
95 for(uint p = 0; p < no; p++) {
96 for(uint q = 0; q < no; q++) {
97 energy += P(p,q) * h(p,q);
101 for(uint p = 0; p < no; p++) {
102 for(uint q = 0; q < no; q++) {
103 for(uint r = 0; r < no; r++) {
104 for(uint s = 0; s < no; s++) {
105 double Qtilde = coupledMatrixTilde(p, q, r, s);
106 energy += 0.25 * Qtilde * P(p,q) * P(s,r);
118 vec previousFockEnergies = m_fockEnergies;
121 double averageEnergyChange = sum(abs(m_fockEnergies - previousFockEnergies))
122 / m_fockEnergies.n_elem;
138 return m_densityMatrix;
143 return m_coefficientMatrix;
146 double RestrictedHartreeFockSolver::coupledMatrixTilde(
int p,
int q,
int r,
int s)
149 return 2 * Q(p,r)(q,s) - Q(p,r)(s,q);
152 void RestrictedHartreeFockSolver::setupDensityMatrix() {
153 mat &P = m_densityMatrix;
154 mat &C = m_coefficientMatrix;
155 mat tempP = 2 * C * C.t();