1 // 2 // BAGEL - Parallel electron correlation program. 3 // Filename: box.h 4 // Copyright (C) 2016 Toru Shiozaki 5 // 6 // Author: Hai-Anh Le <anh@u.northwestern.edu> 7 // Maintainer: Shiozaki group 8 // 9 // This file is part of the BAGEL package. 10 // 11 // The BAGEL package is free software; you can redistribute it and/or modify 12 // it under the terms of the GNU Library General Public License as published by 13 // the Free Software Foundation; either version 3, or (at your option) 14 // any later version. 15 // 16 // The BAGEL package 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 Library General Public License for more details. 20 // 21 // You should have received a copy of the GNU Library General Public License 22 // along with the BAGEL package; see COPYING. If not, write to 23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 24 // 25 26 27 #ifndef __SRC_SCF_FMM_BOX_H 28 #define __SRC_SCF_FMM_BOX_H 29 30 #include <src/molecule/shellpair.h> 31 32 namespace bagel { 33 34 class Box { 35 friend class FMM; 36 protected: 37 int rank_; 38 double boxsize_; 39 std::array<double, 3> centre_; 40 int boxid_; 41 std::array<int, 3> tvec_; 42 int lmax_, lmax_k_, ws_; 43 std::weak_ptr<const Box> parent_; 44 std::vector<std::weak_ptr<const Box>> child_; 45 std::vector<std::weak_ptr<const Box>> inter_; 46 std::vector<std::weak_ptr<const Box>> neigh_; 47 std::vector<std::weak_ptr<const Box>> nonneigh_; //for debugging 48 std::vector<std::shared_ptr<const ShellPair>> sp_; 49 std::map<std::shared_ptr<const Shell>, std::tuple<int/*local_offset*/,int/*all_offset*/,int/*num*/>> shell0_; 50 int nchild_, ninter_, nneigh_; 51 52 double extent_, schwarz_thresh_; 53 int nmult_; 54 int nsp_; 55 int nshell0_; 56 size_t nsize_, msize_, olm_ndim_, olm_mdim_, olm_size_block_; 57 58 std::shared_ptr<ZMatrix> olm_ji_; 59 std::shared_ptr<ZMatrix> mlm_ji_; 60 61 void init(); 62 void insert_sp(const std::vector<std::shared_ptr<const ShellPair>>&); 63 void insert_child(std::weak_ptr<const Box>); 64 void insert_parent(std::weak_ptr<const Box> parent); 65 bool is_neigh(std::weak_ptr<const Box> b, const double ws) const; 66 void get_neigh(const std::vector<std::weak_ptr<Box>>& box, const double ws); 67 void get_inter(const std::vector<std::weak_ptr<Box>>& box, const double ws); 68 void sort_sp(); 69 70 std::shared_ptr<ZVectorB> olm_; 71 std::shared_ptr<ZVectorB> mlm_; 72 73 void compute_M2M(std::shared_ptr<const Matrix> density); 74 void compute_M2M_X(std::shared_ptr<const Matrix> ocoeff_sj, std::shared_ptr<const Matrix> ocoeff_ui); 75 void compute_M2L(); 76 void compute_M2L_X(); 77 void compute_L2L(); 78 void compute_L2L_X(); 79 std::shared_ptr<const ZMatrix> shift_multipolesX(const int lmax, std::shared_ptr<const ZMatrix> oa, std::array<double, 3> rab) const; 80 std::shared_ptr<const ZMatrix> shift_localLX(const int lmax, std::shared_ptr<const ZMatrix> mr, std::array<double, 3> rb) const; 81 std::shared_ptr<const ZMatrix> shift_localMX(const int lmax, std::shared_ptr<const ZMatrix> olm, std::array<double, 3> r12) const; 82 83 std::shared_ptr<const Matrix> compute_exact_ff(std::shared_ptr<const Matrix> density) const; //debug 84 std::shared_ptr<const Matrix> compute_Fock_nf(std::shared_ptr<const Matrix> density, std::shared_ptr<const VectorB> max_den) const; 85 std::shared_ptr<const Matrix> compute_Fock_ff(std::shared_ptr<const Matrix> density) const; 86 std::shared_ptr<const Matrix> compute_Fock_ff_K(std::shared_ptr<const Matrix> ocoeff_ti) const; 87 // allow constructing FMM_J and FMM_K separately with different parameters 88 std::shared_ptr<const Matrix> compute_Fock_nf_J(std::shared_ptr<const Matrix> density, std::shared_ptr<const VectorB> max_den) const; 89 std::shared_ptr<const Matrix> compute_Fock_nf_K(std::shared_ptr<const Matrix> density, std::shared_ptr<const VectorB> max_den) const; 90 91 public: Box()92 Box() { } 93 Box(int n, double size, const std::array<double, 3>& c, const int id, const std::array<int, 3>& v, const int lmax = 10, 94 const int lmax_k = 10, const std::vector<std::shared_ptr<const ShellPair>>& sp = std::vector<std::shared_ptr<const ShellPair>>(), 95 const double schwarz = 0.0) rank_(n)96 : rank_(n), boxsize_(size), centre_(c), boxid_(id), tvec_(v), lmax_(lmax), lmax_k_(lmax_k), sp_(sp), schwarz_thresh_(schwarz) { } 97 ~Box()98 ~Box() { } 99 centre()100 const std::array<double, 3>& centre() const { return centre_; } centre(const int i)101 double centre(const int i) const { return centre_[i]; } boxsize()102 double boxsize() const { return boxsize_; } 103 rank()104 int rank() const { return rank_; } boxid()105 int boxid() const { return boxid_; } tvec()106 const std::array<int, 3>& tvec() const { return tvec_; } extent()107 double extent() const { return extent_; } parent()108 std::shared_ptr<const Box> parent() const { return parent_.lock(); } 109 sp()110 const std::vector<std::shared_ptr<const ShellPair>>& sp() const { return sp_; } child()111 const std::vector<std::weak_ptr<const Box>>& child() const { return child_; } 112 olm()113 std::shared_ptr<ZVectorB> olm() const { return olm_; } mlm()114 std::shared_ptr<ZVectorB> mlm() const { return mlm_; } 115 olm_ji()116 std::shared_ptr<const ZMatrix> olm_ji() const { return olm_ji_; } mlm_ji()117 std::shared_ptr<const ZMatrix> mlm_ji() const { return mlm_ji_; } 118 119 void print_box() const; 120 }; 121 122 } 123 #endif 124