Psi4
jk_grad.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 program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef JK_GRAD_H
29 #define JK_GRAD_H
30 
31 #include "psi4/libmints/typedefs.h"
32 #include <map>
33 
34 namespace psi {
35 
36 class ERISieve;
37 
38 namespace scfgrad {
39 
40 class JKGrad {
41 
42 protected:
44  int print_;
46  int debug_;
48  int bench_;
50  unsigned long int memory_;
54  double cutoff_;
56  int deriv_;
57 
58  std::shared_ptr<BasisSet> primary_;
59 
61  std::shared_ptr<ERISieve> sieve_;
62 
65 
69 
70  bool do_J_;
71  bool do_K_;
72  bool do_wK_;
73 
74  double omega_;
75 
76  std::map<std::string, SharedMatrix> gradients_;
77  std::map<std::string, SharedMatrix> hessians_;
78 
79  void common_init();
80 
81 public:
82  JKGrad(int deriv, std::shared_ptr<BasisSet> primary);
83  virtual ~JKGrad();
84 
91  static std::shared_ptr<JKGrad> build_JKGrad(int deriv, std::shared_ptr<BasisSet> primary,
92  std::shared_ptr<BasisSet> auxiliary);
93 
94  void set_Ca(SharedMatrix Ca) { Ca_ = Ca; }
95  void set_Cb(SharedMatrix Cb) { Cb_ = Cb; }
96  void set_Da(SharedMatrix Da) { Da_ = Da; }
97  void set_Db(SharedMatrix Db) { Db_ = Db; }
98  void set_Dt(SharedMatrix Dt) { Dt_ = Dt; }
99 
107  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
113  void set_memory(unsigned long int memory) { memory_ = memory; }
123  void set_omp_num_threads(int omp_nthread) { omp_num_threads_ = omp_nthread; }
125  void set_print(int print) { print_ = print; }
127  void set_debug(int debug) { debug_ = debug; }
129  void set_bench(int bench) { bench_ = bench; }
135  void set_do_J(bool do_J) { do_J_ = do_J; }
141  void set_do_K(bool do_K) { do_K_ = do_K; }
147  void set_do_wK(bool do_wK) { do_wK_ = do_wK; }
152  void set_omega(double omega) { omega_ = omega; }
153 
154  std::map<std::string, SharedMatrix>& gradients() { return gradients_; }
155  std::map<std::string, SharedMatrix>& hessians() { return hessians_; }
156 
157  virtual void compute_gradient() = 0;
158  virtual void compute_hessian() = 0;
159 
160  virtual void print_header() const = 0;
161 };
162 
163 class DFJKGrad : public JKGrad {
164 
165 protected:
166  std::shared_ptr<BasisSet> auxiliary_;
167 
168  std::shared_ptr<PSIO> psio_;
169 
173  double condition_;
174 
175  void common_init();
176 
177  void build_Amn_terms();
178  void build_Amn_lr_terms();
179  void build_AB_inv_terms();
180  void build_UV_terms();
181  void build_AB_x_terms();
182  void build_Amn_x_terms();
183  void build_Amn_x_lr_terms();
184 
186  unsigned int unit_a_;
188  unsigned int unit_b_;
190  unsigned int unit_c_;
191 
192 public:
193  DFJKGrad(int deriv, std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
194  virtual ~DFJKGrad();
195 
196  void compute_gradient();
197  void compute_hessian();
198 
199  void print_header() const;
200 
208  void set_condition(double condition) { condition_ = condition; }
213  void set_unit_a(unsigned int unit) { unit_a_ = unit; }
218  void set_unit_b(unsigned int unit) { unit_b_ = unit; }
223  void set_unit_c(unsigned int unit) { unit_c_ = unit; }
224 
230 };
231 
232 class DirectJKGrad : public JKGrad {
233 
234 protected:
235  // Number of threads to use
237 
238  void common_init();
239 
240  std::map<std::string, std::shared_ptr<Matrix> > compute1(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
241  std::map<std::string, std::shared_ptr<Matrix> > compute2(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
242 public:
243  DirectJKGrad(int deriv, std::shared_ptr<BasisSet> primary);
244  virtual ~DirectJKGrad();
245 
246  void compute_gradient();
247  void compute_hessian();
248 
249  void print_header() const;
250 
255  void set_ints_num_threads(int val) { ints_num_threads_ = val; }
256 
257 
258 };
259 
260 }} // Namespaces
261 #endif
void set_Cb(SharedMatrix Cb)
Definition: jk_grad.h:95
std::map< std::string, std::shared_ptr< Matrix > > compute2(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2661
void build_Amn_x_terms()
Definition: jk_grad.cc:1018
void set_memory(unsigned long int memory)
Definition: jk_grad.h:113
void set_omp_num_threads(int omp_nthread)
Definition: jk_grad.h:123
virtual ~DFJKGrad()
Definition: jk_grad.cc:125
void compute_gradient()
Definition: jk_grad.cc:2364
virtual ~JKGrad()
Definition: jk_grad.cc:54
int print_
Print flag, defaults to 1.
Definition: jk_grad.h:44
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: jk_grad.h:54
void print_header() const
Definition: jk_grad.cc:2348
Definition: jk_grad.h:232
virtual void print_header() const =0
std::map< std::string, SharedMatrix > & hessians()
Definition: jk_grad.h:155
void set_unit_a(unsigned int unit)
Definition: jk_grad.h:213
std::shared_ptr< BasisSet > primary_
Definition: jk_grad.h:58
void set_unit_b(unsigned int unit)
Definition: jk_grad.h:218
void set_omega(double omega)
Definition: jk_grad.h:152
void set_ints_num_threads(int val)
Definition: jk_grad.h:255
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: jk_grad.h:61
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: jk_grad.h:129
virtual void compute_gradient()=0
int deriv_
Maximum derivative level.
Definition: jk_grad.h:56
JKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:49
bool do_wK_
Definition: jk_grad.h:72
std::map< std::string, SharedMatrix > hessians_
Definition: jk_grad.h:77
int bench_
Bench flag, defaults to 0.
Definition: jk_grad.h:48
void compute_gradient()
Definition: jk_grad.cc:161
unsigned int unit_a_
File number for Alpha (Q|mn) tensor.
Definition: jk_grad.h:186
void set_cutoff(double cutoff)
Definition: jk_grad.h:107
SharedMatrix Dt_
Definition: jk_grad.h:68
std::map< std::string, std::shared_ptr< Matrix > > compute1(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2412
DFJKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:120
void build_Amn_x_lr_terms()
Definition: jk_grad.cc:1368
std::map< std::string, SharedMatrix > & gradients()
Definition: jk_grad.h:154
void set_unit_c(unsigned int unit)
Definition: jk_grad.h:223
void set_print(int print)
Print flag (defaults to 1)
Definition: jk_grad.h:125
SharedMatrix Da_
Definition: jk_grad.h:66
int omp_num_threads_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: jk_grad.h:52
virtual ~DirectJKGrad()
Definition: jk_grad.cc:2338
Definition: jk_grad.h:163
void build_AB_x_terms()
Definition: jk_grad.cc:834
void compute_hessian()
Definition: jk_grad.cc:1592
void set_df_ints_num_threads(int val)
Definition: jk_grad.h:229
void set_do_J(bool do_J)
Definition: jk_grad.h:135
void set_Db(SharedMatrix Db)
Definition: jk_grad.h:97
SharedMatrix Ca_
Definition: jk_grad.h:63
SharedMatrix scfgrad(SharedWavefunction, Options &)
Definition: scfgrad/wrapper.cc:37
void build_Amn_lr_terms()
Definition: jk_grad.cc:411
void build_Amn_terms()
Definition: jk_grad.cc:226
void set_do_wK(bool do_wK)
Definition: jk_grad.h:147
void set_Da(SharedMatrix Da)
Definition: jk_grad.h:96
void set_do_K(bool do_K)
Definition: jk_grad.h:141
void build_UV_terms()
Definition: jk_grad.cc:726
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk_grad.h:171
void set_Ca(SharedMatrix Ca)
Definition: jk_grad.h:94
void set_condition(double condition)
Definition: jk_grad.h:208
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:50
SharedMatrix Db_
Definition: jk_grad.h:67
static std::shared_ptr< JKGrad > build_JKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:57
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk_grad.h:173
int ints_num_threads_
Definition: jk_grad.h:236
void build_AB_inv_terms()
Definition: jk_grad.cc:575
void common_init()
Definition: jk_grad.cc:128
bool do_K_
Definition: jk_grad.h:71
unsigned long int memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: jk_grad.h:50
unsigned int unit_c_
File number for J tensors.
Definition: jk_grad.h:190
unsigned int unit_b_
File number for Beta (Q|mn) tensor.
Definition: jk_grad.h:188
std::map< std::string, SharedMatrix > gradients_
Definition: jk_grad.h:76
double omega_
Definition: jk_grad.h:74
void common_init()
Definition: jk_grad.cc:101
SharedMatrix Cb_
Definition: jk_grad.h:64
std::shared_ptr< BasisSet > auxiliary_
Definition: jk_grad.h:166
virtual void compute_hessian()=0
void compute_hessian()
Definition: jk_grad.cc:2613
void print_header() const
Definition: jk_grad.cc:140
void common_init()
Definition: jk_grad.cc:2341
bool do_J_
Definition: jk_grad.h:70
DirectJKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:2333
void set_Dt(SharedMatrix Dt)
Definition: jk_grad.h:98
std::shared_ptr< PSIO > psio_
Definition: jk_grad.h:168
Definition: jk_grad.h:40
int debug_
Debug flag, defaults to 0.
Definition: jk_grad.h:46
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: jk_grad.h:127