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-2018 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/pragma.h"
38 #include "psi4/libmints/vector3.h"
39 
40 namespace psi {
41 
42 class BasisSet;
43 
96  protected:
98  int debug_;
99 
101  std::shared_ptr<BasisSet> primary_;
102 
104  int nbf_;
106  int nshell_;
107 
109  double sieve_;
111  double max_;
115  double sieve2_;
118 
120  std::vector<double> function_pair_values_;
122  std::vector<double> shell_pair_values_;
123 
125  std::vector<std::pair<int, int> > function_pairs_;
127  std::vector<std::pair<int, int> > shell_pairs_;
129  std::vector<long int> function_pairs_reverse_;
131  std::vector<long int> shell_pairs_reverse_;
133  std::vector<std::vector<int> > shell_to_shell_;
135  std::vector<std::vector<int> > function_to_function_;
136 
138  // adding stuff for QQR sieves
139 
140  bool do_qqr_;
141 
142  // erfc^{-1}(threshold), used in QQR sieving
143  double erfc_thresh_;
144 
145  // need an array of extents from the definition
146 
147  // key: how do I efficiently check integrals? without conditional on which
148  // screening I do
149  //
150  // 1) just a different function called outside - shell_significant_qqr()
151 
152  // integrals() - fills array of extents
153 
154  // r_{\mu \nu} in QQR paper (eqn. B2)
155  std::vector<Vector3> contracted_centers_;
156 
157  // ext'_{\mu \nu} (Eqn. B4)
158  // Extents of contracted charge distributions
159  std::vector<double> extents_;
160 
162 
164  void common_init();
166  void integrals();
167 
168  public:
170  ERISieve(std::shared_ptr<BasisSet> primary, double sieve = 0.0);
172  virtual ~ERISieve();
173 
175  void set_sieve(double sieve);
177  double sieve() const { return sieve_; }
179  double max() const { return max_; }
180 
181  // => Significance Checks <= //
182 
184  inline double shell_ceiling2(int M, int N, int R, int S) {
185  return shell_pair_values_[N * (size_t)nshell_ + M] * shell_pair_values_[R * (size_t)nshell_ + S];
186  }
187 
189  inline double function_ceiling2(int m, int n, int r, int s) {
190  return function_pair_values_[m * (size_t)nbf_ + n] * function_pair_values_[r * (size_t)nbf_ + s];
191  }
192 
194 
195  // inline bool shell_significant(int M, int N, int R, int S) {
196  bool shell_significant(int M, int N, int R, int S) {
197  bool schwarz_bound =
198  shell_pair_values_[N * (size_t)nshell_ + M] * shell_pair_values_[R * (size_t)nshell_ + S] >= sieve2_;
199  if (do_qqr_ && schwarz_bound) {
200  bool res = shell_significant_qqr(M, N, R, S);
201  // std::cout << "QQR prune: " << res << "\n";
202  return res;
203  } else {
204  return schwarz_bound;
205  }
206  }
207 
208  // Implements the QQR sieve
209  bool shell_significant_qqr(int M, int N, int R, int S);
210 
212  inline bool function_significant(int m, int n, int r, int s) {
213  return function_pair_values_[m * (size_t)nbf_ + n] * function_pair_values_[r * (size_t)nbf_ + s] >= sieve2_;
214  }
215 
217  inline bool shell_pair_significant(int M, int N) {
218  return shell_pair_values_[M * (size_t)nshell_ + N] * max_ >= sieve2_;
219  }
220 
222  inline bool function_pair_significant(int m, int n) {
223  return function_pair_values_[m * (size_t)nbf_ + n] * max_ >= sieve2_;
224  }
225  // => Indexing [these change after a call to sieve()] <= //
226 
228  const std::vector<std::pair<int, int> >& function_pairs() const { return function_pairs_; }
230  const std::vector<std::pair<int, int> >& shell_pairs() const { return shell_pairs_; }
232  const std::vector<long int> function_pairs_reverse() const { return function_pairs_reverse_; }
234  const std::vector<long int> shell_pairs_reverse() const { return shell_pairs_reverse_; }
236  const std::vector<std::vector<int> >& function_to_function() const { return function_to_function_; }
238  const std::vector<std::vector<int> >& shell_to_shell() const { return shell_to_shell_; }
239 
240  // void shell_pair_values(std::vector<std::vector<std::pair<double, int> > >& values) const;
241 
242  // just return the value of the bound for pair m and n
243  double shell_pair_value(int m, int n) const;
244  // return the vector of
245  std::vector<double> shell_pair_values() { return shell_pair_values_; }
246  // return the vector of function pairs
247  std::vector<double> function_pair_values() { return function_pair_values_; }
248 
250  void set_debug(int debug) { debug_ = debug; }
251 };
252 
253 } // namespace psi
254 #endif
const std::vector< std::pair< int, int > > & shell_pairs() const
Significant unique bra- shell pairs, in reduced triangular indexing.
Definition: sieve.h:230
double max_
Maximum |(mn|ls)|.
Definition: sieve.h:111
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:222
int nshell_
Number of shells.
Definition: sieve.h:106
void set_debug(int debug)
Set debug flag (defaults to 0)
Definition: sieve.h:250
std::vector< double > function_pair_values()
Definition: sieve.h:247
std::vector< std::vector< int > > function_to_function_
Significant shell pairs, indexes by shell.
Definition: sieve.h:135
void PSI_API integrals(psi::OneBodyAOInt &integral, ambit::Tensor *target)
Definition: integrals.cc:48
double max() const
Global maximum |(mn|rs)|.
Definition: sieve.h:179
std::vector< std::vector< int > > shell_to_shell_
Significant function pairs, indexes by function.
Definition: sieve.h:133
std::shared_ptr< BasisSet > primary_
Basis set reference.
Definition: sieve.h:101
double sieve_
Cutoff values.
Definition: sieve.h:109
const std::vector< std::pair< int, int > > & function_pairs() const
Significant unique bra- function pairs, in reduced triangular indexing.
Definition: sieve.h:228
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:234
const std::vector< std::vector< int > > & function_to_function() const
Significant function pairs, indexes by function.
Definition: sieve.h:236
double sieve_over_max_
sieve_ / max_
Definition: sieve.h:113
std::vector< double > extents_
Definition: sieve.h:159
int debug_
Debug flag (defaults to 0)
Definition: sieve.h:98
std::vector< std::pair< int, int > > function_pairs_
Significant unique bra- function pairs, in reduced triangular indexing.
Definition: sieve.h:125
double function_ceiling2(int m, int n, int r, int s)
Square of ceiling of integral (mn|rs)
Definition: sieve.h:189
std::vector< double > shell_pair_values_
max |(MN|MN)| values (nshell * nshell)
Definition: sieve.h:122
bool do_qqr_
Definition: sieve.h:140
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:131
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:196
long int size_t
Definition: sortintegrals.cc:41
double sieve2_
sieve_ * sieve_
Definition: sieve.h:115
const std::vector< std::vector< int > > & shell_to_shell() const
Significant shell pairs, indexes by shell.
Definition: sieve.h:238
int nbf_
Number of basis functions.
Definition: sieve.h:104
double erfc_thresh_
Definition: sieve.h:143
std::vector< double > function_pair_values_
|(mn|mn)| values (nbf * nbf)
Definition: sieve.h:120
Definition: sieve.h:95
#define PSI_API
Definition: pragma.h:155
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:217
std::vector< double > shell_pair_values()
Definition: sieve.h:245
double sieve() const
Get sieve cutoff value.
Definition: sieve.h:177
double shell_ceiling2(int M, int N, int R, int S)
Square of ceiling of shell quartet (MN|RS)
Definition: sieve.h:184
double sieve2_over_max_
sieve_ * sieve_ / max_
Definition: sieve.h:117
std::vector< std::pair< int, int > > shell_pairs_
Significant unique bra- shell pairs, in reduced triangular indexing.
Definition: sieve.h:127
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:129
std::vector< Vector3 > contracted_centers_
Definition: sieve.h:155
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:232
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:212