1 /*
2  *                This source code is part of
3  *
4  *                     E  R  K  A  L  E
5  *                             -
6  *                       DFT from Hel
7  *
8  * Written by Susi Lehtola, 2010-2011
9  * Copyright (c) 2010-2011, Susi Lehtola
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  */
16 
17 #include "global.h"
18 #include "basis.h"
19 
20 #ifndef ERKALE_ERITABLE
21 #define ERKALE_ERITABLE
22 
23 // Debug usage of ERIs?
24 //#define CHECKFILL
25 
26 #include <armadillo>
27 #include <cfloat>
28 #include <vector>
29 // Forward declaration
30 class BasisSet;
31 
32 /**
33  * \class ERItable
34  *
35  * \brief Table of electron repulsion integrals
36  *
37  * This class is used to store electron repulsion integrals in memory
38  * and to form the Coulomb and exchange matrices. There is no special
39  * indexing, so also zeros are stored.
40  *
41  * \author Susi Lehtola
42  * \date 2011/05/12 18:35
43  */
44 class ERItable {
45  protected:
46   /// Integral pairs sorted by value
47   std::vector<eripair_t> shpairs;
48   /// Screening matrices
49   arma::mat Q, M;
50   /// Number of basis functions
51   size_t Nbf;
52 
53   /// Table of integrals
54   std::vector<double> ints;
55   /// Offset lookup
56   std::vector<size_t> shoff;
57 
58   /// Range separation parameter
59   double omega;
60   /// Fraction of long-range (i.e. exact) exchange
61   double alpha;
62   /// Fraction of short-range exchange
63   double beta;
64 
65   /// Calculate offset in integrals table
66   size_t offset(size_t ip, size_t jp) const;
67 
68  public:
69   /// Constructor
70   ERItable();
71   /// Destructor
72   ~ERItable();
73 
74   /// Set range separation
75   void set_range_separation(double omega, double alpha, double beta);
76   /// Get range separation
77   void get_range_separation(double & omega, double & alpha, double & beta) const;
78 
79   /// Fill table, return amount of significant shell pairs
80   size_t fill(const BasisSet * basis, double thr);
81 
82   /// Compute number of integrals
83   size_t N_ints(const BasisSet * basis, double thr);
84 
85   /// Print ERI table
86   void print() const;
87 
88   /// Get size of ERI table
89   size_t get_N() const;
90 
91   /// Form Coulomb matrix
92   arma::mat calcJ(const arma::mat & P) const;
93   /// Form exchange matrix
94   arma::mat calcK(const arma::mat & P) const;
95   /// Form exchange matrix
96   arma::cx_mat calcK(const arma::cx_mat & P) const;
97 };
98 
99 #endif
100