Psi4
jk.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 JK_H
30 #define JK_H
31 
32 #include <vector>
33 #include "psi4/pragma.h"
34 PRAGMA_WARNING_PUSH
35 PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
36 #include <memory>
38 #include "psi4/libmints/typedefs.h"
40 
41 namespace psi {
42 class MinimalInterface;
43 class BasisSet;
44 class Matrix;
45 class ERISieve;
46 class TwoBodyAOInt;
47 class Options;
48 class PSIO;
49 class DFHelper;
50 
51 namespace pk {
52 class PKManager;
53 }
54 
55 // => BASE CLASS <= //
56 
227 class PSI_API JK {
228  protected:
229  // => Utility Variables <= //
230 
232  int print_;
234  int debug_;
236  int bench_;
238  size_t memory_;
242  double cutoff_;
244  std::vector<bool> input_symmetry_cast_map_;
245 
246  // => Tasks <= //
247 
249  bool do_J_;
251  bool do_K_;
253  bool do_wK_;
254 
256  double omega_;
257 
260 
261  // => Architecture-Level State Variables (Spatial Symmetry) <= //
262 
264  std::vector<SharedMatrix> C_left_;
266  std::vector<SharedMatrix> C_right_;
268  std::vector<SharedMatrix> D_;
270  std::vector<SharedMatrix> J_;
272  std::vector<SharedMatrix> K_;
274  std::vector<SharedMatrix> wK_;
275 
276  // => Microarchitecture-Level State Variables (No Spatial Symmetry) <= //
277 
279  std::shared_ptr<BasisSet> primary_;
283  std::vector<SharedMatrix> C_left_ao_;
285  std::vector<SharedMatrix> C_right_ao_;
287  std::vector<SharedMatrix> D_ao_;
289  std::vector<SharedMatrix> J_ao_;
291  std::vector<SharedMatrix> K_ao_;
293  std::vector<SharedMatrix> wK_ao_;
294 
295  // => Per-Iteration Setup/Finalize Routines <= //
296 
298  void compute_D();
300  void USO2AO();
302  void AO2USO();
304  void allocate_JK();
316  void common_init();
317 
318  // => Required Algorithm-Specific Methods <= //
319 
321  virtual void preiterations() = 0;
323  virtual void compute_JK() = 0;
325  virtual void postiterations() = 0;
326 
327  // => Helper Routines <= //
328 
330  size_t memory_overhead() const;
331 
332  public:
333  // => Constructors <= //
334 
348  JK(std::shared_ptr<BasisSet> primary);
349 
351  virtual ~JK();
352 
360  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
361  Options& options);
362  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
363  Options& options, std::string jk_type);
364  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
365  Options& options, bool do_wK, size_t doubles);
366 
368  virtual bool C1() const = 0;
369 
370  // => Knobs <= //
371 
379  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
385  void set_memory(size_t memory) { memory_ = memory; }
395  void set_omp_nthread(int omp_nthread) { omp_nthread_ = omp_nthread; }
397  void set_print(int print) { print_ = print; }
399  void set_debug(int debug) { debug_ = debug; }
401  void set_bench(int bench) { bench_ = bench; }
407  void set_do_J(bool do_J) { do_J_ = do_J; }
413  void set_do_K(bool do_K) { do_K_ = do_K; }
419  void set_do_wK(bool do_wK) { do_wK_ = do_wK; }
424  void set_omega(double omega) { omega_ = omega; }
425 
426  // => Computers <= //
427 
433  void initialize();
441  void compute();
448  void finalize();
449 
456  virtual SharedVector iaia(SharedMatrix Ci, SharedMatrix Ca);
457 
458  // => Accessors <= //
459 
464  std::vector<SharedMatrix>& C_left() { return C_left_; }
470  std::vector<SharedMatrix>& C_right() { return C_right_; }
471 
480  const std::vector<SharedMatrix>& J() const { return J_; }
489  const std::vector<SharedMatrix>& K() const { return K_; }
498  const std::vector<SharedMatrix>& wK() const { return wK_; }
507  const std::vector<SharedMatrix>& D() const { return D_; }
508 
513  virtual void print_header() const = 0;
514 };
515 
516 // => APPLIED CLASSES <= //
517 
524 class DiskJK : public JK {
526  int* so2index_;
529 
532 
534  virtual bool C1() const { return false; }
536  virtual void preiterations();
538  virtual void compute_JK();
540  virtual void postiterations();
541 
543  void common_init();
544 
545  public:
546  // => Constructors < = //
547 
555  DiskJK(std::shared_ptr<BasisSet> primary, Options& options);
557  virtual ~DiskJK();
558 
559  // => Accessors <= //
560 
565  virtual void print_header() const;
566 };
567 
574 class PSI_API PKJK : public JK {
576  std::shared_ptr<PSIO> psio_;
577 
580 
582  int pk_file_;
583 
586 
588  std::shared_ptr<pk::PKManager> PKmanager_;
589 
591  virtual bool C1() const;
593  virtual void preiterations();
595  virtual void compute_JK();
597  virtual void postiterations();
598 
600  void common_init();
601 
603  int nso_;
605  int nirrep_;
608 
609  public:
610  // => Constructors < = //
611 
620  PKJK(std::shared_ptr<BasisSet> primary, Options& options);
622  virtual ~PKJK();
623 
624  // => Accessors <= //
625 
630  virtual void print_header() const;
631 };
632 
644 class DirectJK : public JK {
645  protected:
649  std::shared_ptr<ERISieve> sieve_;
650 
651  // => Required Algorithm-Specific Methods <= //
652 
654  virtual bool C1() const { return true; }
656  virtual void preiterations();
658  virtual void compute_JK();
660  virtual void postiterations();
661 
663  void build_JK(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints, std::vector<std::shared_ptr<Matrix> >& D,
664  std::vector<std::shared_ptr<Matrix> >& J, std::vector<std::shared_ptr<Matrix> >& K);
665 
667  void common_init();
668 
669  public:
670  // => Constructors < = //
671 
679  DirectJK(std::shared_ptr<BasisSet> primary);
681  virtual ~DirectJK();
682 
683  // => Knobs <= //
684 
690 
691  // => Accessors <= //
692 
697  virtual void print_header() const;
698 };
699 
713 class GTFockJK : public JK {
714  private:
716  std::shared_ptr<MinimalInterface> Impl_;
717  int NMats_ = 0;
718 
719  protected:
721  virtual bool C1() const { return true; }
723  virtual void preiterations() {}
725  virtual void compute_JK();
727  virtual void postiterations() {}
729  virtual void print_header() const {}
730 
731  public:
745  GTFockJK(std::shared_ptr<psi::BasisSet> Primary, size_t NMats, bool AreSymm);
750  GTFockJK(std::shared_ptr<psi::BasisSet> Primary);
751 };
752 
759 class PSI_API DiskDFJK : public JK {
760  protected:
761  // => DF-Specific stuff <= //
762 
764  std::shared_ptr<BasisSet> auxiliary_;
766  std::shared_ptr<PSIO> psio_;
768  std::string df_ints_io_;
772  double condition_;
774  size_t unit_;
776  bool is_core_;
782  std::shared_ptr<ERISieve> sieve_;
783 
790 
791  // => Temps (built/destroyed in compute_JK) <= //
792  std::shared_ptr<Vector> J_temp_;
793  std::shared_ptr<Vector> D_temp_;
794  std::shared_ptr<Vector> d_temp_;
795 
798  std::vector<SharedMatrix> C_temp_;
799  std::vector<SharedMatrix> Q_temp_;
800 
801  // => Required Algorithm-Specific Methods <= //
802 
804  virtual bool C1() const { return true; }
806  virtual void preiterations();
808  virtual void compute_JK();
810  virtual void postiterations();
811 
813  void common_init();
814 
815  bool is_core() const;
816  size_t memory_temp() const;
817  int max_rows() const;
818  int max_nocc() const;
819  void initialize_temps();
820  void free_temps();
821  void initialize_w_temps();
822  void free_w_temps();
823 
824  // => J <= //
825  virtual void initialize_JK_core();
826  virtual void initialize_JK_disk();
827  virtual void manage_JK_core();
828  virtual void manage_JK_disk();
829  virtual void block_J(double** Qmnp, int naux);
830  virtual void block_K(double** Qmnp, int naux);
831 
832  // => wK <= //
833  virtual void initialize_wK_core();
834  virtual void initialize_wK_disk();
835  virtual void manage_wK_core();
836  virtual void manage_wK_disk();
837  virtual void block_wK(double** Qlmnp, double** Qrmnp, int naux);
838  virtual void rebuild_wK_disk();
839 
840  public:
841  // => Constructors < = //
842 
851  DiskDFJK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
852 
854  virtual ~DiskDFJK();
855 
862  virtual SharedVector iaia(SharedMatrix Ci, SharedMatrix Ca);
863 
864  // => Knobs <= //
865 
873  void set_condition(double condition) { condition_ = condition; }
878  void set_unit(size_t unit) { unit_ = unit; }
883  void set_df_ints_io(const std::string& val) { df_ints_io_ = val; }
888  void set_df_ints_num_threads(int val) { df_ints_num_threads_ = val; }
889 
890  // => Accessors <= //
891 
896  virtual void print_header() const;
897 };
904 class CDJK : public DiskDFJK {
905  protected:
906  // the number of cholesky vectors
907  long int ncholesky_;
908 
909  // => Required Algorithm-Specific Methods <= //
910 
911  virtual bool is_core() { return true; }
912 
913  // => J <= //
914  virtual void initialize_JK_core();
915  virtual void initialize_JK_disk();
916  virtual void manage_JK_core();
917 
919 
920  // => Accessors <= //
921 
926  virtual void print_header() const;
927 
928  public:
929  // => Constructors < = //
930 
939  CDJK(std::shared_ptr<BasisSet> primary, double cholesky_tolerance);
940 
942  virtual ~CDJK();
943 };
944 
953 class MemDFJK : public JK {
954 
955  protected:
956  // => DF-Specific stuff <= //
957 
959  std::shared_ptr<DFHelper> dfh_;
960 
962  std::shared_ptr<BasisSet> auxiliary_;
966  double condition_ = 1.0E-12;
967 
968  // => Required Algorithm-Specific Methods <= //
969 
970  int max_nocc() const;
972  virtual bool C1() const { return true; }
975  virtual void preiterations();
977  virtual void compute_JK();
979  virtual void postiterations();
980 
982  void common_init();
983 
984 
985  public:
986  // => Constructors < = //
987 
992  MemDFJK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
993 
995  virtual ~MemDFJK();
996 
997 
998  // => Knobs <= //
999 
1007  void set_condition(double condition) { condition_ = condition; }
1008 
1014 
1015 
1016  // => Accessors <= //
1017 
1022  virtual void print_header() const;
1023 };
1024 }
1025 #endif
virtual void initialize_JK_core()
Definition: CDJK.cc:68
std::shared_ptr< BasisSet > auxiliary_
Auxiliary basis set.
Definition: jk.h:962
MemDFJK(std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: MemDFJK.cc:57
int nso_
Total number of SOs.
Definition: jk.h:603
std::shared_ptr< BasisSet > primary_
Primary basis set.
Definition: jk.h:279
int debug_
Debug flag, defaults to 0.
Definition: jk.h:234
void set_print(int print)
Print flag (defaults to 1)
Definition: jk.h:397
void set_df_ints_io(const std::string &val)
Definition: jk.h:883
double cholesky_tolerance_
Definition: jk.h:918
virtual void initialize_JK_disk()
Definition: CDJK.cc:63
size_t unit_
File number for (Q|mn) tensor.
Definition: jk.h:774
Definition: jk.h:524
int * so2index_
Absolute AO index to relative SO index.
Definition: jk.h:526
Derived class extending the JK object to GTFock.
Definition: jk.h:713
std::vector< SharedMatrix > C_left_
Pseudo-occupied C matrices, left side.
Definition: jk.h:264
int pk_file_
The pk file to use for storing the pk batches.
Definition: jk.h:582
void set_omega(double omega)
Definition: jk.h:424
void set_do_wK(bool do_wK)
Definition: jk.h:419
virtual void manage_JK_core()
Definition: CDJK.cc:131
virtual ~DirectJK()
Destructor.
Definition: DirectJK.cc:66
std::string df_ints_io_
Cache action for three-index integrals.
Definition: jk.h:768
virtual void postiterations()
Delete integrals, files, etc.
Definition: DiskJK.cc:597
std::vector< SharedMatrix > C_temp_
Definition: jk.h:798
Dimension nsopi_
Number of so per irrep.
Definition: jk.h:607
void set_omp_nthread(int omp_nthread)
Definition: jk.h:395
CDJK(std::shared_ptr< BasisSet > primary, double cholesky_tolerance)
Definition: CDJK.cc:56
virtual void print_header() const
Definition: MemDFJK.cc:123
virtual bool is_core()
Definition: jk.h:911
SharedMatrix Qmn_
Main (Q|mn) Tensor (or chunk for disk-based)
Definition: jk.h:785
virtual void print_header() const
Definition: DiskJK.cc:65
double omega_
Omega, defaults to 0.0.
Definition: jk.h:256
std::vector< SharedMatrix > C_right_
Pseudo-occupied C matrices, right side.
Definition: jk.h:266
void set_cutoff(double cutoff)
Definition: jk.h:379
int NMats_
Definition: jk.h:717
int max_nocc() const
Definition: MemDFJK.cc:143
virtual bool C1() const
Do we need to backtransform to C1 under the hood?
Definition: jk.h:721
void set_df_ints_num_threads(int val)
Definition: jk.h:888
bool do_wK_
Do wK matrices? Defaults to false.
Definition: jk.h:253
std::shared_ptr< BasisSet > auxiliary_
Auxiliary basis set.
Definition: jk.h:764
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk.h:966
std::shared_ptr< pk::PKManager > PKmanager_
Class handling the PK integrals.
Definition: jk.h:588
virtual void postiterations()
Delete integrals, files, etc.
Definition: MemDFJK.cc:121
std::shared_ptr< MinimalInterface > Impl_
The actual instance that does the implementing.
Definition: jk.h:716
int max_nocc_
Maximum number of nocc in C vectors.
Definition: jk.h:780
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: jk.h:401
virtual void compute_JK()
Compute J/K for current C/D.
std::vector< SharedMatrix > C_right_ao_
Pseudo-occupied C matrices, right side.
Definition: jk.h:285
std::vector< bool > input_symmetry_cast_map_
Whether to all desymmetrization, for cases when it&#39;s already been performed elsewhere.
Definition: jk.h:244
void common_init()
Common initialization.
Definition: MemDFJK.cc:64
Definition: PKmanagers.h:95
std::vector< SharedMatrix > D_
Pseudo-density matrices .
Definition: jk.h:268
void common_init()
Common initialization.
Definition: DiskJK.cc:62
int bench_
Bench flag, defaults to 0.
Definition: jk.h:236
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: jk.h:242
SharedMatrix E_right_
Definition: jk.h:797
std::vector< SharedMatrix > & C_left()
Definition: jk.h:464
std::vector< SharedMatrix > wK_
wK matrices:
Definition: jk.h:274
std::shared_ptr< PSIO > psio_
PSIO object.
Definition: jk.h:766
void set_df_ints_num_threads(int val)
Definition: jk.h:689
int df_ints_num_threads_
Number of threads for DF integrals TODO: DF_INTS_NUM_THREADS.
Definition: jk.h:647
Definition: pointgrp.h:114
bool is_core_
Core or disk?
Definition: jk.h:776
virtual bool C1() const
Do we need to backtransform to C1 under the hood?
Definition: jk.h:534
void set_condition(double condition)
Definition: jk.h:1007
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk.h:964
const std::vector< SharedMatrix > & K() const
Definition: jk.h:489
int print_
Print flag, defaults to 1.
Definition: jk.h:232
Options & options_
Options object.
Definition: jk.h:531
virtual bool C1() const
Do we need to backtransform to C1 under the hood?
Definition: jk.h:654
DiskJK(std::shared_ptr< BasisSet > primary, Options &options)
Definition: DiskJK.cc:54
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: jk.h:399
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: jk.h:782
virtual void preiterations()
Setup integrals, files, etc.
Definition: jk.h:723
void set_condition(double condition)
Definition: jk.h:873
int nthreads_
The number of threads to be used for integral computation.
Definition: jk.h:585
Options & options_
Options object.
Definition: jk.h:579
virtual void preiterations()
Definition: MemDFJK.cc:70
Definition: jk.h:574
virtual void compute_JK()
Compute J/K for current C/D.
Definition: DiskJK.cc:103
Definition: jk.h:644
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk.h:772
SharedMatrix AO2USO_
AO2USO transformation matrix.
Definition: jk.h:281
Definition: jk.h:953
virtual void print_header() const
Definition: DirectJK.cc:76
virtual void preiterations()
Setup integrals, files, etc.
Definition: DirectJK.cc:91
const std::vector< SharedMatrix > & J() const
Definition: jk.h:480
std::vector< SharedMatrix > C_left_ao_
Pseudo-occupied C matrices, left side.
Definition: jk.h:283
std::shared_ptr< DFHelper > dfh_
This class wraps a DFHelper object.
Definition: jk.h:959
SharedMatrix Qrmn_
(Q|w|mn) for wK (or chunk for disk-based)
Definition: jk.h:789
virtual ~MemDFJK()
Destructor.
Definition: MemDFJK.cc:62
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
int max_rows_
Maximum number of rows to handle at a time.
Definition: jk.h:778
virtual ~DiskJK()
Destructor.
Definition: DiskJK.cc:59
bool do_J_
Do J matrices? Defaults to true.
Definition: jk.h:249
Definition: dimension.h:40
void common_init()
Common initialization.
Definition: DirectJK.cc:69
virtual void print_header() const
I don&#39;t fell the need to further clutter the output...
Definition: jk.h:729
void set_do_J(bool do_J)
Definition: jk.h:407
bool do_K_
Do K matrices? Defaults to true.
Definition: jk.h:251
void set_memory(size_t memory)
Definition: jk.h:385
std::vector< SharedMatrix > K_
K matrices: .
Definition: jk.h:272
std::shared_ptr< ERISieve > sieve_
ERI Sieve.
Definition: jk.h:649
Definition: liboptions.h:355
Definition: jk.h:759
SharedMatrix E_left_
Definition: jk.h:796
void set_df_ints_num_threads(int val)
Definition: jk.h:1013
common_init()
void build_JK(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints, std::vector< std::shared_ptr< Matrix > > &D, std::vector< std::shared_ptr< Matrix > > &J, std::vector< std::shared_ptr< Matrix > > &K)
Build the J and K matrices for this integral class.
Definition: DirectJK.cc:147
std::vector< SharedMatrix > wK_ao_
wK matrices: wK_mn = (ml|w|ns) C_li^left C_si^right
Definition: jk.h:293
std::vector< SharedMatrix > J_ao_
J matrices: J_mn = (mn|ls) C_li^left C_si^right.
Definition: jk.h:289
int omp_nthread_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: jk.h:240
virtual ~CDJK()
Destructor.
Definition: CDJK.cc:60
std::vector< SharedMatrix > & C_right()
Definition: jk.h:470
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_unit(size_t unit)
Definition: jk.h:878
#define PSI_API
Definition: pragma.h:128
Definition: jk.h:904
SharedMatrix Qlmn_
(Q|P)^-1 (P|mn) for wK (or chunk for disk-based)
Definition: jk.h:787
GTFockJK(std::shared_ptr< psi::BasisSet > Primary, size_t NMats, bool AreSymm)
Your public interface to GTFock.
std::shared_ptr< Vector > d_temp_
Definition: jk.h:794
virtual void preiterations()
Setup integrals, files, etc.
Definition: DiskJK.cc:79
Definition: jk.h:227
virtual void postiterations()
Delete integrals, files, etc.
Definition: DirectJK.cc:143
Definition: pointgrp.h:113
virtual void compute_JK()
Compute J/K for current C/D.
Definition: MemDFJK.cc:107
std::vector< SharedMatrix > D_ao_
Pseudo-density matrices.
Definition: jk.h:287
DirectJK(std::shared_ptr< BasisSet > primary)
Definition: DirectJK.cc:61
virtual bool C1() const
Do we need to backtransform to C1 under the hood?
Definition: jk.h:972
size_t memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: jk.h:238
std::shared_ptr< PSIO > psio_
The PSIO instance to use for I/O.
Definition: jk.h:576
std::vector< SharedMatrix > K_ao_
K matrices: K_mn = (ml|ns) C_li^left C_si^right.
Definition: jk.h:291
int nirrep_
Number of irreps.
Definition: jk.h:605
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk.h:770
virtual void print_header() const
Definition: CDJK.cc:147
int * so2symblk_
Absolute AO index to irrep.
Definition: jk.h:528
void set_do_K(bool do_K)
Definition: jk.h:413
const std::vector< SharedMatrix > & D() const
Definition: jk.h:507
std::shared_ptr< Vector > D_temp_
Definition: jk.h:793
bool lr_symmetric_
Left-right symmetric? Determined in each call of compute()
Definition: jk.h:259
std::vector< SharedMatrix > Q_temp_
Definition: jk.h:799
virtual bool C1() const
Do we need to backtransform to C1 under the hood?
Definition: jk.h:804
long int ncholesky_
Definition: jk.h:907
std::shared_ptr< Vector > SharedVector
Definition: adc.h:51
virtual void compute_JK()
Compute J/K for current C/D.
Definition: DirectJK.cc:95
std::vector< SharedMatrix > J_
J matrices: .
Definition: jk.h:270
std::shared_ptr< Vector > J_temp_
Definition: jk.h:792
const std::vector< SharedMatrix > & wK() const
Definition: jk.h:498
virtual void postiterations()
Delete integrals, files, etc.
Definition: jk.h:727