Psi4
sieve.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef SIEVE_H
30 #define SIEVE_H
31 
32 // need this for erfc^{-1} in the QQR sieve
33 //#include <cfloat>
34 #include <vector>
35 #include <memory>
36 //#include <utility>
37 #include "psi4/libmints/vector3.h"
38 
39 namespace psi {
40 
41 class BasisSet;
42 
94 class ERISieve {
95 
96 protected:
97 
99  int debug_;
100 
102  std::shared_ptr<BasisSet> primary_;
103 
105  int nbf_;
107  int nshell_;
108 
110  double sieve_;
112  double max_;
116  double sieve2_;
119 
121  std::vector<double> function_pair_values_;
123  std::vector<double> shell_pair_values_;
124 
126  std::vector<std::pair<int,int> > function_pairs_;
128  std::vector<std::pair<int,int> > shell_pairs_;
130  std::vector<long int> function_pairs_reverse_;
132  std::vector<long int> shell_pairs_reverse_;
134  std::vector<std::vector<int> > shell_to_shell_;
136  std::vector<std::vector<int> > function_to_function_;
137 
139  // adding stuff for QQR sieves
140 
141  bool do_qqr_;
142 
143  // erfc^{-1}(threshold), used in QQR sieving
144  double erfc_thresh_;
145 
146  // need an array of extents from the definition
147 
148  // key: how do I efficiently check integrals? without conditional on which
149  // screening I do
150  //
151  // 1) just a different function called outside - shell_significant_qqr()
152 
153  // integrals() - fills array of extents
154 
155  // r_{\mu \nu} in QQR paper (eqn. B2)
156  std::vector<Vector3> contracted_centers_;
157 
158  // ext'_{\mu \nu} (Eqn. B4)
159  // Extents of contracted charge distributions
160  std::vector<double> extents_;
161 
163 
165  void common_init();
167  void integrals();
168 
169 public:
170 
172  ERISieve(std::shared_ptr<BasisSet> primary, double sieve = 0.0);
174  virtual ~ERISieve();
175 
177  void set_sieve(double sieve);
179  double sieve() const { return sieve_; }
181  double max() const { return max_; }
182 
183  // => Significance Checks <= //
184 
186  inline double shell_ceiling2(int M, int N, int R, int S) {
187  return shell_pair_values_[N * (unsigned long int) nshell_ + M] *
188  shell_pair_values_[R * (unsigned long int) nshell_ + S]; }
189 
191  inline double function_ceiling2(int m, int n, int r, int s) {
192  return function_pair_values_[m * (unsigned long int) nbf_ + n] *
193  function_pair_values_[r * (unsigned long int) nbf_ + s]; }
194 
196 
197  //inline bool shell_significant(int M, int N, int R, int S) {
198  bool shell_significant(int M, int N, int R, int S) {
199 
200  bool schwarz_bound = shell_pair_values_[N * (unsigned long int) nshell_ + M] *
201  shell_pair_values_[R * (unsigned long int) nshell_ + S] >= sieve2_;
202  if (do_qqr_ && schwarz_bound) {
203  bool res = shell_significant_qqr(M, N, R, S);
204  //std::cout << "QQR prune: " << res << "\n";
205  return res;
206  }
207  else {
208  return schwarz_bound;
209  }
210  }
211 
212  // Implements the QQR sieve
213  bool shell_significant_qqr(int M, int N, int R, int S);
214 
216  inline bool function_significant(int m, int n, int r, int s) {
217  return function_pair_values_[m * (unsigned long int) nbf_ + n] *
218  function_pair_values_[r * (unsigned long int) nbf_ + s] >= sieve2_; }
219 
220 
222  inline bool shell_pair_significant(int M, int N) {
223  return shell_pair_values_[M * (unsigned long int) nshell_ + N] *
224  max_ >= sieve2_; }
225 
227  inline bool function_pair_significant(int m, int n) {
228  return function_pair_values_[m * (unsigned long int) nbf_ + n] *
229  max_ >= sieve2_; }
230  // => Indexing [these change after a call to sieve()] <= //
231 
233  const std::vector<std::pair<int,int> >& function_pairs() const { return function_pairs_; }
235  const std::vector<std::pair<int,int> >& shell_pairs() const { return shell_pairs_; }
237  const std::vector<long int> function_pairs_reverse() const { return function_pairs_reverse_; }
239  const std::vector<long int> shell_pairs_reverse() const { return shell_pairs_reverse_; }
241  const std::vector<std::vector<int> >& function_to_function() const { return function_to_function_; }
243  const std::vector<std::vector<int> >& shell_to_shell() const { return shell_to_shell_; }
244 
245  //void shell_pair_values(std::vector<std::vector<std::pair<double, int> > >& values) const;
246 
247  // just return the value of the bound for pair m and n
248  double shell_pair_value(int m, int n) const;
249  // return the vector of
250  std::vector<double> shell_pair_values() { return shell_pair_values_;}
251  // return the vector of function pairs
252  std::vector<double> function_pair_values() {return function_pair_values_;}
253 
255  void set_debug(int debug) { debug_ = debug; }
256 
257 };
258 
259 
260 }
261 #endif
void integrals()
Compute sieve integrals (only done once)
Definition: sieve.cc:206
double max_
Maximum |(mn|ls)|.
Definition: sieve.h:112
bool function_pair_significant(int m, int n)
Is the function pair (mn| ever significant according to sieve (no restriction on mn order) ...
Definition: sieve.h:227
int nshell_
Number of shells.
Definition: sieve.h:107
void set_debug(int debug)
Set debug flag (defaults to 0)
Definition: sieve.h:255
std::vector< double > function_pair_values()
Definition: sieve.h:252
std::vector< std::vector< int > > function_to_function_
Significant shell pairs, indexes by shell.
Definition: sieve.h:136
double max() const
Global maximum |(mn|rs)|.
Definition: sieve.h:181
std::vector< std::vector< int > > shell_to_shell_
Significant function pairs, indexes by function.
Definition: sieve.h:134
std::shared_ptr< BasisSet > primary_
Basis set reference.
Definition: sieve.h:102
double sieve_
Cutoff values.
Definition: sieve.h:110
double shell_pair_value(int m, int n) const
Definition: sieve.cc:346
std::vector< std::pair< int, int > > function_pairs_
Significant unique bra- function pairs, in reduced triangular indexing.
Definition: sieve.h:126
const std::vector< long int > shell_pairs_reverse() const
Unique bra- shell pair indexing, accessed in triangular order, or -1 for non-significant pair...
Definition: sieve.h:239
const std::vector< std::vector< int > > & function_to_function() const
Significant function pairs, indexes by function.
Definition: sieve.h:241
double sieve_over_max_
sieve_ / max_
Definition: sieve.h:114
std::vector< double > extents_
Definition: sieve.h:160
int debug_
Debug flag (defaults to 0)
Definition: sieve.h:99
void common_init()
Set initial indexing.
Definition: sieve.cc:52
double function_ceiling2(int m, int n, int r, int s)
Square of ceiling of integral (mn|rs)
Definition: sieve.h:191
std::vector< double > shell_pair_values_
max |(MN|MN)| values (nshell * nshell)
Definition: sieve.h:123
virtual ~ERISieve()
Destructor, frees memory.
Definition: sieve.cc:48
bool do_qqr_
Definition: sieve.h:141
std::vector< long int > shell_pairs_reverse_
Unique bra- shell pair indexing, accessed in triangular order, or -1 for non-significant pair...
Definition: sieve.h:132
bool shell_significant(int M, int N, int R, int S)
Is the shell quartet (MN|RS) significant according to sieve? (no restriction on MNRS order) ...
Definition: sieve.h:198
double sieve2_
sieve_ * sieve_
Definition: sieve.h:116
std::vector< std::pair< int, int > > shell_pairs_
Significant unique bra- shell pairs, in reduced triangular indexing.
Definition: sieve.h:128
const std::vector< std::pair< int, int > > & function_pairs() const
Significant unique bra- function pairs, in reduced triangular indexing.
Definition: sieve.h:233
const std::vector< std::vector< int > > & shell_to_shell() const
Significant shell pairs, indexes by shell.
Definition: sieve.h:243
int nbf_
Number of basis functions.
Definition: sieve.h:105
double erfc_thresh_
Definition: sieve.h:144
std::vector< double > function_pair_values_
|(mn|mn)| values (nbf * nbf)
Definition: sieve.h:121
Definition: sieve.h:94
bool shell_pair_significant(int M, int N)
Is the shell pair (MN| ever significant according to sieve (no restriction on MN order) ...
Definition: sieve.h:222
std::vector< double > shell_pair_values()
Definition: sieve.h:250
double sieve() const
Get sieve cutoff value.
Definition: sieve.h:179
void set_sieve(double sieve)
Set sieve value and redo indexing.
Definition: sieve.cc:71
double shell_ceiling2(int M, int N, int R, int S)
Square of ceiling of shell quartet (MN|RS)
Definition: sieve.h:186
const std::vector< std::pair< int, int > > & shell_pairs() const
Significant unique bra- shell pairs, in reduced triangular indexing.
Definition: sieve.h:235
ERISieve(std::shared_ptr< BasisSet > primary, double sieve=0.0)
Constructor, basis set and first sieve cutoff.
Definition: sieve.cc:42
bool shell_significant_qqr(int M, int N, int R, int S)
Definition: sieve.cc:319
double sieve2_over_max_
sieve_ * sieve_ / max_
Definition: sieve.h:118
std::vector< long int > function_pairs_reverse_
Unique bra- function pair indexing, accessed in triangular order, or -1 for non-significant pair...
Definition: sieve.h:130
std::vector< Vector3 > contracted_centers_
Definition: sieve.h:156
const std::vector< long int > function_pairs_reverse() const
Unique bra- function pair indexing, accessed in triangular order, or -1 for non-significant pair...
Definition: sieve.h:237
bool function_significant(int m, int n, int r, int s)
Is the integral (mn|rs) significant according to sieve? (no restriction on mnrs order) ...
Definition: sieve.h:216