ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
hamilt_zeq_l.h
Go to the documentation of this file.
1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_HAMILT_ZEQ_L_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_HAMILT_ZEQ_L_H
4#include "hamilt_zequlr.h"
10#ifdef __EXX
12#endif
13namespace LR
14{
15 template<typename T>
16 class Z_vector_L : public HamiltLR<T>
17 {
19#ifdef __EXX
20 using ATYPE_EXX = typename OperatorLREXX<T>::MO_TO_AO_TYPE;
21#endif
22 public:
23 Z_vector_L(const std::string& xc_kernel,
24 const int& nspin,
25 const int& naos,
26 const std::vector<int>& nocc,
27 const std::vector<int>& nvirt,
28 const UnitCell& ucell,
29 const std::vector<double>& orb_cutoff,
30 const Grid_Driver& gd,
31 const psi::Psi<T>& psi_ks,
32 const ModuleBase::matrix& eig_ks,
33#ifdef __EXX
34 std::weak_ptr<Exx_LRI<T>> exx_lri,
35 const double& exx_alpha,
36#endif
37 std::weak_ptr<PotLRBase> pot_hxc_gs,
38 const K_Vectors& kv,
39 const std::vector<Parallel_Blkcyclic>& pX,
40 const Parallel_Blkcyclic& pc,
41 const Parallel_Orbitals& pmat,
42 const std::string& spin_type,
43 const std::string& in_dir,
44 const std::string& out_dir,
45 const std::string& dft_functional)
46 : HamiltLR<T>(nspin, nocc, nvirt, pX, kv, pmat)
47 {
48 ModuleBase::TITLE("Z_vector_L", "Z_vector_L");
49 LR_Util::initialize_DMR(*this->DM_trans, pmat, ucell, gd, orb_cutoff);
50 // Hessian (A+B) with GS XC kernel
51 // 1. diag term in A
52 this->ops = new OperatorLRDiag<T>(eig_ks.c, pX[0], kv.get_nks() / nspin, nocc[0], nvirt[0], false);
53 // 2. $H_{ia}[D^Z]$, equals to $2K_{ab}[D^Z]$ when $D^Z$ is symmetrized.
54 // Factor 4 (not 2): the singlet kernel is $K^S_\text{Hxc}=2$`pot_hxc_gs` (not doubled),
55 // while `pot` is the already-doubled singlet potential, so $H^S=2K^S$ here needs 4.
56 // The EXX line below is already $2\alpha$ and is consistent.
57 hamilt::Operator<T>* op_hz = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
58 *this->DM_trans, pot_hxc_gs, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
59 { 0 }, 4.0, ATYPE::CC_vo, hamilt::calculation_type::lr_dmtrans_hxc);
60 this->ops->add(op_hz);
61#ifdef __EXX
62 if (gs_is_hybrid(dft_functional))
63 {
64 // Z_vector_L only exists on the force-calculation path, so cal_force is always true here.
65 hamilt::Operator<T>* op_hz_exx = new OperatorLREXX<T>(nspin, naos, nocc[0], nvirt[0], ucell, psi_ks,
66 *this->DM_trans, exx_lri, kv, pX[0], pc, pmat,
67 /*cal_force=*/true,
68 2.0 * exx_alpha, //alpha; H=2K when D is symmetrized
69 ATYPE_EXX::CC_vo, {}, hamilt::calculation_type::lr_dmtrans_exx);
70 this->ops->add(op_hz_exx);
71 }
72#endif
73 this->cal_dm_trans = [this, &psi_ks, &pc, naos, &nocc, &nvirt, &pmat](const int& is, const T* X)->void
74 {
75 const psi::Psi<T> psi_ks_is = LR_Util::get_psi_spin(psi_ks, is, this->nk);
76#ifdef __MPI
77 std::vector<ct::Tensor> dm_trans_2d = cal_dm_trans_pblas(X, this->pX[is], psi_ks_is, pc, naos, nocc[is], nvirt[is], pmat.para_2d());
78 for (container::Tensor& t: dm_trans_2d)
79 LR_Util::matsym(t.data<T>(), naos, pmat.para_2d());
80#else
81 std::vector<ct::Tensor> dm_trans_2d = cal_dm_trans_blas(X, psi_ks_is, nocc[is], nvirt[is]);
82 for (auto& t: dm_trans_2d)
83 LR_Util::matsym(t.data<T>(), naos);
84#endif
85 // LR_Util::print_tensor<T>(dm_trans_2d[0], "dm_trans_2d[0]", &pmat);
86 // tensor to vector, then set DMK
87 for (int ik = 0; ik < this->nk; ++ik)
88 {
89 this->DM_trans->set_dmk_ptr(ik, dm_trans_2d[ik].data<T>());
90 }
91 };
92 }
93 };
94
106 template<typename T>
107 class Z_vector_UL : public ZeqULR<T>
108 {
110#ifdef __EXX
111 using ATYPE_EXX = typename OperatorLREXX<T>::MO_TO_AO_TYPE;
112#endif
113 public:
114 Z_vector_UL(const std::string& xc_kernel,
115 const int& nspin,
116 const int& naos,
117 const std::vector<int>& nocc,
118 const std::vector<int>& nvirt,
119 const UnitCell& ucell,
120 const std::vector<double>& orb_cutoff,
121 const Grid_Driver& gd,
122 const psi::Psi<T>& psi_ks,
123 const ModuleBase::matrix& eig_ks,
124#ifdef __EXX
125 std::weak_ptr<Exx_LRI<T>> exx_lri,
126 const double& exx_alpha,
127#endif
128 std::weak_ptr<PotLRBase> pot_hxc_gs,
129 const K_Vectors& kv,
130 const std::vector<Parallel_Blkcyclic>& pX,
131 const Parallel_Blkcyclic& pc,
132 const Parallel_Orbitals& pmat,
133 const std::string& dft_functional,
134 const int nk,
135 const int local_dimension,
136 const int global_dimension)
137 : ZeqULR<T>(nocc, nvirt, pX, nk, local_dimension, global_dimension),
138 naos_(naos), pc_(pc), pmat_(pmat), psi_ks_(psi_ks)
139 {
140 ModuleBase::TITLE("Z_vector_UL", "Z_vector_UL");
142 LR_Util::initialize_DMR(*this->DM_trans, pmat, ucell, gd, orb_cutoff);
143
144 // 1. the orbital-energy difference, diagonal blocks only
145 this->ops[0] = new OperatorLRDiag<T>(eig_ks.c, pX[0], this->nk, nocc[0], nvirt[0], /*add_on=*/true);
146 this->ops[3] = new OperatorLRDiag<T>(eig_ks.c + this->nk * (nocc[0] + nvirt[0]),
147 pX[1], this->nk, nocc[1], nvirt[1], /*add_on=*/true);
148
149 // 2. $H_{ai\sigma}[D^Z]=2\sum_{\sigma'}K_{ai\sigma}[D^Z_{\sigma'}]$
150 auto newHxc = [this, &nspin, &naos, &nocc, &nvirt, &psi_ks, &pot_hxc_gs, &ucell, &orb_cutoff, &gd, &kv, &pX, &pc, &pmat](const int sl, const int sr)
151 {
152 return new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
153 *this->DM_trans, pot_hxc_gs, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
154 { sl, sr }, T(2.0), ATYPE::CC_vo, hamilt::calculation_type::lr_dmtrans_hxc);
155 };
156 this->ops[0]->add(newHxc(0, 0));
157 this->ops[1] = newHxc(0, 1);
158 this->ops[2] = newHxc(1, 0);
159 this->ops[3]->add(newHxc(1, 1));
160
161#ifdef __EXX
162 // exchange is spin-diagonal ($\delta_{\sigma\sigma'}$), so only blocks 0 and 3.
163 // Factor 2*alpha is unchanged from the closed-shell version: the EXX part of the
164 // kernel carries no singlet/triplet combination, only $H=2K$.
165 if (gs_is_hybrid(dft_functional))
166 {
167 for (int is : {0, 1})
168 {
169 this->psi_ks_spin_.push_back(LR_Util::get_psi_spin(psi_ks, is, this->nk));
170 }
171 for (int is : {0, 1})
172 {
173 this->ops[(is << 1) + is]->add(new OperatorLREXX<T>(nspin, naos, nocc[is], nvirt[is],
174 ucell, this->psi_ks_spin_[is], *this->DM_trans, exx_lri, kv, pX[is], pc, pmat,
175 /*cal_force=*/true, 2.0 * exx_alpha, ATYPE_EXX::CC_vo, {}, hamilt::calculation_type::lr_dmtrans_exx));
176 }
177 }
178#endif
179 }
180
181 protected:
182 void set_dm(const int is, const T* const X,
183 const std::vector<ct::Tensor>* density_add) override
184 {
185 assert(density_add == nullptr); // The linear Hessian reads only its input Z.
186 const psi::Psi<T> psi_ks_is = LR_Util::get_psi_spin(this->psi_ks_, is, this->nk);
187#ifdef __MPI
188 this->dm_buf_ = cal_dm_trans_pblas(X, this->pX[is], psi_ks_is, this->pc_,
189 this->naos_, this->nocc[is], this->nvirt[is], this->pmat_.para_2d());
190 for (auto& t: this->dm_buf_)
191 {
192 LR_Util::matsym(t.template data<T>(), this->naos_, this->pmat_.para_2d());
193 }
194#else
195 this->dm_buf_ = cal_dm_trans_blas(X, psi_ks_is, this->nocc[is], this->nvirt[is]);
196 for (auto& t: this->dm_buf_)
197 {
198 LR_Util::matsym(t.template data<T>(), this->naos_);
199 }
200#endif
201 for (int ik = 0;ik < this->nk;++ik)
202 {
203 this->DM_trans->set_dmk_ptr(ik, this->dm_buf_[ik].template data<T>());
204 }
205 }
206
207 private:
208 const int naos_ = 1;
212 std::vector<psi::Psi<T>> psi_ks_spin_;
213 std::unique_ptr<module_dm::DensityMatrix<T, T>> DM_trans;
215 std::vector<ct::Tensor> dm_buf_;
216 };
217}
218
219#endif // ABACUS_SOURCE_LCAO_MODULE_LR_HAMILT_ZEQ_L_H
Definition exx_lri.h:50
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
Class for k-points management.
Definition klist.h:20
int get_nks() const
Definition klist.h:71
const int nk
Definition hamilt_casida.h:200
const std::vector< Parallel_Blkcyclic > & pX
Definition hamilt_casida.h:201
std::function< void(const int &, const T *const)> cal_dm_trans
Definition hamilt_casida.h:229
const int nspin
Definition hamilt_casida.h:199
HamiltLR(const std::string &xc_kernel, const int &nspin, const int &naos, const std::vector< int > &nocc, const std::vector< int > &nvirt, const UnitCell &ucell_in, const std::vector< double > &orb_cutoff, const Grid_Driver &gd_in, const psi::Psi< T > &psi_ks_in, const ModuleBase::matrix &eig_ks, std::weak_ptr< PotLRBase > pot_in, const K_Vectors &kv_in, const std::vector< Parallel_Blkcyclic > &pX_in, const Parallel_Blkcyclic &pc_in, const Parallel_Orbitals &pmat_in, const std::string &spin_type, const std::string &in_dir, const std::string &out_dir, const std::string &ri_hartree_benchmark="none", const std::vector< int > &aims_nbasis={})
Definition hamilt_casida.h:23
const std::vector< int > & nocc
Definition hamilt_casida.h:197
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_trans
Definition hamilt_casida.h:224
hamilt::Operator< T, base_device::DEVICE_CPU > * ops
first node operator, add operations from each operators
Definition hamilt_casida.h:227
const std::vector< int > & nvirt
Definition hamilt_casida.h:198
Diag part of A operator: [AX]_iak = (e_ak - e_ik) X_iak.
Definition operator_lr_diag.h:13
Definition exx_lri.h:35
Hxc part of A operator for LR-TDDFT.
Definition operator_lr_hxc.h:17
MO_TO_AO_TYPE
type of molecular orbital to atomic orbital transformation: CC_vo: MO = C_v^* AO C_o; CC_oo: MO = C_o...
Definition operator_lr_hxc.h:24
typename OperatorLRHxc< T >::MO_TO_AO_TYPE ATYPE
Definition hamilt_zeq_l.h:18
Z_vector_L(const std::string &xc_kernel, const int &nspin, const int &naos, const std::vector< int > &nocc, const std::vector< int > &nvirt, const UnitCell &ucell, const std::vector< double > &orb_cutoff, const Grid_Driver &gd, const psi::Psi< T > &psi_ks, const ModuleBase::matrix &eig_ks, std::weak_ptr< PotLRBase > pot_hxc_gs, const K_Vectors &kv, const std::vector< Parallel_Blkcyclic > &pX, const Parallel_Blkcyclic &pc, const Parallel_Orbitals &pmat, const std::string &spin_type, const std::string &in_dir, const std::string &out_dir, const std::string &dft_functional)
Definition hamilt_zeq_l.h:23
const psi::Psi< T > & psi_ks_
Definition hamilt_zeq_l.h:211
std::vector< ct::Tensor > dm_buf_
the tensors DM_trans points into; kept alive for the whole act chain
Definition hamilt_zeq_l.h:215
typename OperatorLRHxc< T >::MO_TO_AO_TYPE ATYPE
Definition hamilt_zeq_l.h:109
Z_vector_UL(const std::string &xc_kernel, const int &nspin, const int &naos, const std::vector< int > &nocc, const std::vector< int > &nvirt, const UnitCell &ucell, const std::vector< double > &orb_cutoff, const Grid_Driver &gd, const psi::Psi< T > &psi_ks, const ModuleBase::matrix &eig_ks, std::weak_ptr< PotLRBase > pot_hxc_gs, const K_Vectors &kv, const std::vector< Parallel_Blkcyclic > &pX, const Parallel_Blkcyclic &pc, const Parallel_Orbitals &pmat, const std::string &dft_functional, const int nk, const int local_dimension, const int global_dimension)
Definition hamilt_zeq_l.h:114
std::vector< psi::Psi< T > > psi_ks_spin_
Definition hamilt_zeq_l.h:212
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_trans
Definition hamilt_zeq_l.h:213
const Parallel_Blkcyclic & pc_
Definition hamilt_zeq_l.h:209
void set_dm(const int is, const T *const X, const std::vector< ct::Tensor > *density_add) override
rebuild the density matrices the operators read, from the is block of X
Definition hamilt_zeq_l.h:182
const Parallel_Orbitals & pmat_
Definition hamilt_zeq_l.h:210
const int naos_
Definition hamilt_zeq_l.h:208
std::vector< hamilt::Operator< T > * > ops
Definition hamilt_zequlr.h:193
const std::vector< int > & nvirt
Definition hamilt_zequlr.h:179
ZeqULR(const std::vector< int > &nocc_in, const std::vector< int > &nvirt_in, const std::vector< Parallel_Blkcyclic > &pX_in, const int nk_in, const int local_dimension, const int global_dimension)
Definition hamilt_zequlr.h:35
const std::vector< int > & nocc
Definition hamilt_zequlr.h:178
const int nk
Definition hamilt_zequlr.h:181
const std::vector< Parallel_Blkcyclic > & pX
Definition hamilt_zequlr.h:180
Definition matrix.h:15
double * c
Definition matrix.h:21
std::vector< ModuleBase::Vector3< double > > kvec_d
Direct coordinates of the points.
Definition reciprocal_grid.h:57
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Definition parallel_orbitals.h:16
Parallel_Blkcyclic & para_2d()
Definition parallel_orbitals.h:24
Provide the basic information about unitcell.
Definition unitcell.h:16
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
Definition operator.h:42
Definition psi.h:37
#define T
Definition exp.cpp:237
psi::Psi< T > get_psi_spin(const psi::Psi< T > &psi_in, const int &is, const int &nk)
get the Psi wrapper of the selected spin from the Psi object
Definition lr_util.hpp:235
std::unique_ptr< T > make_unique(Args &&... args)
Definition lr_util.hpp:33
void matsym(const T *in, const int n, T *out)
Definition lr_util.hpp:79
void initialize_DMR(module_dm::DensityMatrix< T, TR > &dm, const Parallel_Orbitals &pmat, const UnitCell &ucell, const Grid_Driver &gd, const std::vector< double > &orb_cutoff)
Definition lr_util_hcontainer.h:179
Definition esolver_lr_lcao_tddft.h:28
std::vector< container::Tensor > cal_dm_trans_blas(const T *const X_istate, const psi::Psi< T > &c, const int &nocc, const int &nvirt, const T factor=(T) 1.0, const LR_Util::MO_TYPE type=LR_Util::MO_TYPE::VO)
calculate the 2d-block transition density matrix in AO basis using ?gemm
std::vector< container::Tensor > cal_dm_trans_pblas(const T *const X_istate, const Parallel_Blkcyclic &px, const psi::Psi< T > &c, const Parallel_Blkcyclic &pc, const int naos, const int nocc, const int nvirt, const Parallel_Blkcyclic &pmat, const T factor=(T) 1.0, const LR_Util::MO_TYPE type=LR_Util::MO_TYPE::VO)
calculate the 2d-block transition density matrix in AO basis using p?gemm
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
@ lr_dmtrans_exx
Definition operator.h:32
@ lr_dmtrans_hxc
Definition operator.h:29