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-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 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  protected:
46  int print_;
48  int debug_;
50  int bench_;
52  size_t memory_;
54  int nthreads_;
56  double cutoff_;
57 
58  std::shared_ptr<BasisSet> primary_;
59 
74 
81 
82  std::map<std::string, SharedMatrix> gradients_;
83 
84  void common_init();
85 
86  public:
87  CorrGrad(std::shared_ptr<BasisSet> primary);
88  virtual ~CorrGrad();
89 
96  static std::shared_ptr<CorrGrad> build_CorrGrad(std::shared_ptr<BasisSet> primary,
97  std::shared_ptr<BasisSet> auxiliary);
98 
99  void set_Ca(SharedMatrix Ca) { Ca_ = Ca; }
100  void set_Cb(SharedMatrix Cb) { Cb_ = Cb; }
101  void set_La(SharedMatrix La) { La_ = La; }
102  void set_Lb(SharedMatrix Lb) { Lb_ = Lb; }
103  void set_Ra(SharedMatrix Ra) { Ra_ = Ra; }
104  void set_Rb(SharedMatrix Rb) { Rb_ = Rb; }
105  void set_Da(SharedMatrix Da) { Da_ = Da; }
106  void set_Db(SharedMatrix Db) { Db_ = Db; }
107  void set_Dt(SharedMatrix Dt) { Dt_ = Dt; }
108  void set_Pa(SharedMatrix Pa) { Pa_ = Pa; }
109  void set_Pb(SharedMatrix Pb) { Pb_ = Pb; }
110  void set_Pt(SharedMatrix Pt) { Pt_ = Pt; }
111 
119  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
125  void set_memory(size_t memory) { memory_ = memory; }
135  void set_omp_num_threads(int omp_nthread) { nthreads_ = omp_nthread; }
137  void set_print(int print) { print_ = print; }
139  void set_debug(int debug) { debug_ = debug; }
141  void set_bench(int bench) { bench_ = bench; }
142 
143  std::map<std::string, SharedMatrix>& gradients() { return gradients_; }
144 
145  virtual void compute_gradient() = 0;
146 
147  virtual void print_header() const = 0;
148 };
149 
150 class DFCorrGrad : public CorrGrad {
151  protected:
152  std::shared_ptr<BasisSet> auxiliary_;
153 
154  std::shared_ptr<PSIO> psio_;
155 
159  double condition_;
160 
162  std::shared_ptr<ERISieve> sieve_;
163 
164  void common_init();
165 
166  void build_Amn_terms();
167  void build_AB_inv_terms();
168  void build_UV_terms();
169  void build_AB_x_terms();
170  void build_Amn_x_terms();
171 
172  void fitting_helper(SharedMatrix J, size_t file, const std::string& label, size_t naux, size_t nij, size_t memory);
173  void UV_helper(SharedMatrix V, double c, size_t file, const std::string& label, size_t naux, size_t nij,
174  size_t memory);
175 
177  size_t unit_a_;
179  size_t unit_b_;
181  size_t unit_c_;
182 
183  public:
184  DFCorrGrad(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
185  virtual ~DFCorrGrad();
186 
187  void compute_gradient();
188 
189  void print_header() const;
190 
198  void set_condition(double condition) { condition_ = condition; }
203  void set_unit_a(size_t unit) { unit_a_ = unit; }
208  void set_unit_b(size_t unit) { unit_b_ = unit; }
213  void set_unit_c(size_t unit) { unit_c_ = unit; }
214 
220 };
221 
222 } // namespace dfmp2
223 } // namespace psi
224 #endif
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: corr_grad.h:56
void build_AB_inv_terms()
Definition: corr_grad.cc:415
void print_header() const
Definition: corr_grad.cc:110
SharedMatrix Pt_
Definition: corr_grad.h:80
int nthreads_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: corr_grad.h:54
void common_init()
Definition: corr_grad.cc:99
SharedMatrix La_
Definition: corr_grad.h:70
void build_UV_terms()
Definition: corr_grad.cc:508
int print_
Print flag, defaults to 1.
Definition: corr_grad.h:46
SharedMatrix Pa_
Definition: corr_grad.h:78
void set_print(int print)
Print flag (defaults to 1)
Definition: corr_grad.h:137
void set_Rb(SharedMatrix Rb)
Definition: corr_grad.h:104
void build_Amn_terms()
Definition: corr_grad.cc:168
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:471
std::map< std::string, SharedMatrix > & gradients()
Definition: corr_grad.h:143
virtual ~DFCorrGrad()
Definition: corr_grad.cc:98
SharedMatrix Lb_
Definition: corr_grad.h:71
SharedMatrix Cb_
Definition: corr_grad.h:69
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: corr_grad.h:157
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: corr_grad.h:141
virtual ~CorrGrad()
Definition: corr_grad.cc:58
void set_unit_c(size_t unit)
Definition: corr_grad.h:213
int bench_
Bench flag, defaults to 0.
Definition: corr_grad.h:50
Definition: corr_grad.h:43
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: corr_grad.h:139
void build_Amn_x_terms()
Definition: corr_grad.cc:716
void set_Dt(SharedMatrix Dt)
Definition: corr_grad.h:107
SharedMatrix Ra_
Definition: corr_grad.h:72
SharedMatrix Dt_
Definition: corr_grad.h:77
SharedMatrix Ca_
Definition: corr_grad.h:68
std::map< std::string, SharedMatrix > gradients_
Definition: corr_grad.h:82
void set_df_ints_num_threads(int val)
Definition: corr_grad.h:219
size_t memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: corr_grad.h:52
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: corr_grad.h:162
void set_cutoff(double cutoff)
Definition: corr_grad.h:119
std::shared_ptr< BasisSet > primary_
Definition: corr_grad.h:58
void set_Cb(SharedMatrix Cb)
Definition: corr_grad.h:100
SharedMatrix Rb_
Definition: corr_grad.h:73
void build_AB_x_terms()
Definition: corr_grad.cc:579
size_t unit_a_
File number for Alpha (Q|mn) tensor.
Definition: corr_grad.h:177
void set_Ca(SharedMatrix Ca)
Definition: corr_grad.h:99
Definition: corr_grad.h:150
void set_Pb(SharedMatrix Pb)
Definition: corr_grad.h:109
DFCorrGrad(std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: corr_grad.cc:94
virtual void print_header() const =0
void set_Pa(SharedMatrix Pa)
Definition: corr_grad.h:108
SharedMatrix Da_
Definition: corr_grad.h:75
std::shared_ptr< PSIO > psio_
Definition: corr_grad.h:154
int debug_
Debug flag, defaults to 0.
Definition: corr_grad.h:48
std::shared_ptr< BasisSet > auxiliary_
Definition: corr_grad.h:152
void set_Db(SharedMatrix Db)
Definition: corr_grad.h:106
void set_Lb(SharedMatrix Lb)
Definition: corr_grad.h:102
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
virtual void compute_gradient()=0
void common_init()
Definition: corr_grad.cc:81
void set_Ra(SharedMatrix Ra)
Definition: corr_grad.h:103
SharedMatrix Db_
Definition: corr_grad.h:76
size_t unit_b_
File number for Beta (Q|mn) tensor.
Definition: corr_grad.h:179
void set_La(SharedMatrix La)
Definition: corr_grad.h:101
void compute_gradient()
Definition: corr_grad.cc:124
void set_condition(double condition)
Definition: corr_grad.h:198
void set_unit_a(size_t unit)
Definition: corr_grad.h:203
size_t unit_c_
File number for J tensors.
Definition: corr_grad.h:181
SharedWavefunction dfmp2(SharedWavefunction, Options &)
Definition: dfmp2/wrapper.cc:52
static std::shared_ptr< CorrGrad > build_CorrGrad(std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: corr_grad.cc:59
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: corr_grad.h:159
void set_Da(SharedMatrix Da)
Definition: corr_grad.h:105
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:548
void set_Pt(SharedMatrix Pt)
Definition: corr_grad.h:110
SharedMatrix Pb_
Definition: corr_grad.h:79
CorrGrad(std::shared_ptr< BasisSet > primary)
Definition: corr_grad.cc:57
void set_memory(size_t memory)
Definition: corr_grad.h:125
void set_omp_num_threads(int omp_nthread)
Definition: corr_grad.h:135
void set_unit_b(size_t unit)
Definition: corr_grad.h:208