Psi4
corr_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 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 Corr_GRAD_H
30 #define Corr_GRAD_H
31 
32 #include "psi4/libmints/typedefs.h"
33 #include <map>
34 
35 namespace psi {
36 
37 class ERISieve;
38 class BasisSet;
39 class PSIO;
40 
41 namespace dfmp2 {
42 
43 class CorrGrad {
44 
45 protected:
47  int print_;
49  int debug_;
51  int bench_;
53  size_t memory_;
55  int nthreads_;
57  double cutoff_;
58 
59  std::shared_ptr<BasisSet> primary_;
60 
75 
82 
83  std::map<std::string, SharedMatrix> gradients_;
84 
85  void common_init();
86 
87 public:
88  CorrGrad(std::shared_ptr<BasisSet> primary);
89  virtual ~CorrGrad();
90 
97  static std::shared_ptr<CorrGrad> build_CorrGrad(std::shared_ptr<BasisSet> primary,
98  std::shared_ptr<BasisSet> auxiliary);
99 
100  void set_Ca(SharedMatrix Ca) { Ca_ = Ca; }
101  void set_Cb(SharedMatrix Cb) { Cb_ = Cb; }
102  void set_La(SharedMatrix La) { La_ = La; }
103  void set_Lb(SharedMatrix Lb) { Lb_ = Lb; }
104  void set_Ra(SharedMatrix Ra) { Ra_ = Ra; }
105  void set_Rb(SharedMatrix Rb) { Rb_ = Rb; }
106  void set_Da(SharedMatrix Da) { Da_ = Da; }
107  void set_Db(SharedMatrix Db) { Db_ = Db; }
108  void set_Dt(SharedMatrix Dt) { Dt_ = Dt; }
109  void set_Pa(SharedMatrix Pa) { Pa_ = Pa; }
110  void set_Pb(SharedMatrix Pb) { Pb_ = Pb; }
111  void set_Pt(SharedMatrix Pt) { Pt_ = Pt; }
112 
120  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
126  void set_memory(size_t memory) { memory_ = memory; }
136  void set_omp_num_threads(int omp_nthread) { nthreads_ = omp_nthread; }
138  void set_print(int print) { print_ = print; }
140  void set_debug(int debug) { debug_ = debug; }
142  void set_bench(int bench) { bench_ = bench; }
143 
144  std::map<std::string, SharedMatrix>& gradients() { return gradients_; }
145 
146  virtual void compute_gradient() = 0;
147 
148  virtual void print_header() const = 0;
149 };
150 
151 class DFCorrGrad : public CorrGrad {
152 
153 protected:
154  std::shared_ptr<BasisSet> auxiliary_;
155 
156  std::shared_ptr<PSIO> psio_;
157 
161  double condition_;
162 
164  std::shared_ptr<ERISieve> sieve_;
165 
166  void common_init();
167 
168  void build_Amn_terms();
169  void build_AB_inv_terms();
170  void build_UV_terms();
171  void build_AB_x_terms();
172  void build_Amn_x_terms();
173 
174  void fitting_helper(SharedMatrix J, size_t file, const std::string& label, size_t naux, size_t nij, size_t memory);
175  void UV_helper(SharedMatrix V, double c, size_t file, const std::string& label, size_t naux, size_t nij, size_t memory);
176 
178  size_t unit_a_;
180  size_t unit_b_;
182  size_t unit_c_;
183 
184 public:
185  DFCorrGrad(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
186  virtual ~DFCorrGrad();
187 
188  void compute_gradient();
189 
190  void print_header() const;
191 
199  void set_condition(double condition) { condition_ = condition; }
204  void set_unit_a(size_t unit) { unit_a_ = unit; }
209  void set_unit_b(size_t unit) { unit_b_ = unit; }
214  void set_unit_c(size_t unit) { unit_c_ = unit; }
215 
221 };
222 
223 }} // Namespaces
224 #endif
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: corr_grad.h:57
void build_AB_inv_terms()
Definition: corr_grad.cc:445
void print_header() const
Definition: corr_grad.cc:126
SharedMatrix Pt_
Definition: corr_grad.h:81
int nthreads_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: corr_grad.h:55
void common_init()
Definition: corr_grad.cc:114
SharedMatrix La_
Definition: corr_grad.h:71
void build_UV_terms()
Definition: corr_grad.cc:539
int print_
Print flag, defaults to 1.
Definition: corr_grad.h:47
SharedMatrix Pa_
Definition: corr_grad.h:79
void set_print(int print)
Print flag (defaults to 1)
Definition: corr_grad.h:138
void set_Rb(SharedMatrix Rb)
Definition: corr_grad.h:105
void build_Amn_terms()
Definition: corr_grad.cc:187
void fitting_helper(SharedMatrix J, size_t file, const std::string &label, size_t naux, size_t nij, size_t memory)
Definition: corr_grad.cc:502
std::map< std::string, SharedMatrix > & gradients()
Definition: corr_grad.h:144
virtual ~DFCorrGrad()
Definition: corr_grad.cc:111
SharedMatrix Lb_
Definition: corr_grad.h:72
SharedMatrix Cb_
Definition: corr_grad.h:70
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: corr_grad.h:159
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: corr_grad.h:142
virtual ~CorrGrad()
Definition: corr_grad.cc:62
void set_unit_c(size_t unit)
Definition: corr_grad.h:214
int bench_
Bench flag, defaults to 0.
Definition: corr_grad.h:51
Definition: corr_grad.h:43
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: corr_grad.h:140
void build_Amn_x_terms()
Definition: corr_grad.cc:750
void set_Dt(SharedMatrix Dt)
Definition: corr_grad.h:108
SharedMatrix Ra_
Definition: corr_grad.h:73
SharedMatrix Dt_
Definition: corr_grad.h:78
SharedMatrix Ca_
Definition: corr_grad.h:69
std::map< std::string, SharedMatrix > gradients_
Definition: corr_grad.h:83
void set_df_ints_num_threads(int val)
Definition: corr_grad.h:220
size_t memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: corr_grad.h:53
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: corr_grad.h:164
void set_cutoff(double cutoff)
Definition: corr_grad.h:120
std::shared_ptr< BasisSet > primary_
Definition: corr_grad.h:59
void set_Cb(SharedMatrix Cb)
Definition: corr_grad.h:101
SharedMatrix Rb_
Definition: corr_grad.h:74
void build_AB_x_terms()
Definition: corr_grad.cc:611
size_t unit_a_
File number for Alpha (Q|mn) tensor.
Definition: corr_grad.h:178
void set_Ca(SharedMatrix Ca)
Definition: corr_grad.h:100
Definition: corr_grad.h:151
void set_Pb(SharedMatrix Pb)
Definition: corr_grad.h:110
DFCorrGrad(std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: corr_grad.cc:106
virtual void print_header() const =0
void set_Pa(SharedMatrix Pa)
Definition: corr_grad.h:109
SharedMatrix Da_
Definition: corr_grad.h:76
std::shared_ptr< PSIO > psio_
Definition: corr_grad.h:156
int debug_
Debug flag, defaults to 0.
Definition: corr_grad.h:49
std::shared_ptr< BasisSet > auxiliary_
Definition: corr_grad.h:154
void set_Db(SharedMatrix Db)
Definition: corr_grad.h:107
void set_Lb(SharedMatrix Lb)
Definition: corr_grad.h:103
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
virtual void compute_gradient()=0
void common_init()
Definition: corr_grad.cc:92
void set_Ra(SharedMatrix Ra)
Definition: corr_grad.h:104
SharedMatrix Db_
Definition: corr_grad.h:77
size_t unit_b_
File number for Beta (Q|mn) tensor.
Definition: corr_grad.h:180
void set_La(SharedMatrix La)
Definition: corr_grad.h:102
void compute_gradient()
Definition: corr_grad.cc:141
void set_condition(double condition)
Definition: corr_grad.h:199
void set_unit_a(size_t unit)
Definition: corr_grad.h:204
size_t unit_c_
File number for J tensors.
Definition: corr_grad.h:182
SharedWavefunction dfmp2(SharedWavefunction, Options &)
Definition: dfmp2/wrapper.cc:53
static std::shared_ptr< CorrGrad > build_CorrGrad(std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: corr_grad.cc:65
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: corr_grad.h:161
void set_Da(SharedMatrix Da)
Definition: corr_grad.h:106
void UV_helper(SharedMatrix V, double c, size_t file, const std::string &label, size_t naux, size_t nij, size_t memory)
Definition: corr_grad.cc:580
void set_Pt(SharedMatrix Pt)
Definition: corr_grad.h:111
SharedMatrix Pb_
Definition: corr_grad.h:80
CorrGrad(std::shared_ptr< BasisSet > primary)
Definition: corr_grad.cc:57
void set_memory(size_t memory)
Definition: corr_grad.h:126
void set_omp_num_threads(int omp_nthread)
Definition: corr_grad.h:136
void set_unit_b(size_t unit)
Definition: corr_grad.h:209