MPQC  3.0.0-alpha
dmm_scf.hpp
1 /*
2  * dmm_scf.hpp
3  *
4  * Created on: Aug 14, 2013
5  * Author: drewlewis
6  */
7 
8 #ifndef mpqc_interfaces_tiledarray_tests_dmm_scf_hpp
9 #define mpqc_interfaces_tiledarray_tests_dmm_scf_hpp
10 
11 #include "common.hpp"
12 #include "tiledarray_fock.hpp"
13 #include <TiledArray/algebra/diis.h>
14 #include "curvy_steps.hpp"
15 
16 namespace mpqc {
17 namespace tests {
18 
19  using Array2 = TA::Array<double,2>;
20  using Array3 = TA::Array<double,3>;
21  using Array4 = TA::Array<double,4>;
22 
23  // Function that controls how the desnity will be updated, may change for
24  // Different methods. I should make an attemp to wrap this in class.
25  void
26  Density_Update(Array2 &R, const Array2 &S, const Array2 &F,
27  const std::size_t iter,
28  const std::size_t rot_order = 4){
29  curvy_steps::Density_Update(R, S, F, iter, rot_order);
30  }
31 
32  double DF_DMM(Array2 &D, const Array2 &S, const Array2 &H,
33  Array2 &F, Array2 &G, const Array3 &Eri3,
34  const Array2 &Inv_Eri2, double nuc_repl){
35 
36  // create a DIIS object to extrapolate Fock matrix
37  TA::DIIS<Array2> diis;
38 
39  // How many purification steps to use in Density code
40  int scf_iter = 1;
41  double energy = 0;
42  double error_norminf = 1.0;
43 
44  // Begin SCF iterations
45  while(error_norminf > 4e-6){
46  double iter0 = madness::wall_time(); // Iteration timer
47 
48  //Density Update
49  double mad_conj0 = madness::wall_time();
50  Density_Update(D, S, F, scf_iter);
51  double mad_conjf = madness::wall_time();
52 
53  //Fock Build
54  double Fock0 = madness::wall_time(); // Fock build timer
55  G("i,j") = 2.0 *
56  (Eri3("i,j,X") * Inv_Eri2("X,Y") * (Eri3("n,m,Y") * D("m,n"))) -
57  (Eri3("i,n,X") * Inv_Eri2("X,Y") * (Eri3("j,m,Y") * D("m,n")));
58  F("i,j") = H("i,j") + G("i,j");
59  S.world().gop.fence();
60 
61  // Computing gradient for DIIS error calculation
62  Array2 gradient = 8 * ( S("i,q") * D("q,x") * F("x,j") -
63  F("i,q") * D("q,x") * S("x,j") );
64 
65  //Performing DIIS update of the Fock Matrix
66  error_norminf = TA::expressions::norminf(gradient("i,j"));
67  diis.extrapolate(F, gradient);
68 
69  //Energy for this iteration
70  energy = TA::expressions::dot( 2.0 * H("i,j") + G("i,j"), D("i,j") );
71 
72  S.world().gop.fence(); // End of iteration work
73  double iterf = madness::wall_time(); // End iteration timer
74 
75  ++scf_iter;
76  }
77 
78  return energy + nuc_repl;
79  }
80 
81 
82 
83 } // namespace tests
84 } // namesapce mpqc
85 
86 
87 
88 
89 #endif /* mpqc_interfaces_tiledarray_tests_dmm_scf_hpp */
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37

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