1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_HAMILT_ZEQ_R_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_HAMILT_ZEQ_R_H
27 const std::vector<int>&
nocc,
28 const std::vector<int>&
nvirt,
30 const std::vector<double>& orb_cutoff,
36 const double& exx_alpha,
38 std::weak_ptr<PotHxcLR> pot,
39 std::weak_ptr<PotHxcLR> pot_hxc_gs,
41 const std::vector<Parallel_Blkcyclic>&
pX,
44 const std::string& in_dir,
45 const std::string& out_dir,
46 const std::string& dft_functional,
47 const std::string& spin_type =
"singlet")
60 *this->
DM_trans, pot, ucell, orb_cutoff, gd, kv,
pX, pc, pmat,
63 if (exx_kernel_list().count(xc_kernel))
70 this->
ops->add(op_hz_exx);
78 *this->
DM_diff, pot_hxc_gs, ucell, orb_cutoff, gd, kv,
pX, pc, pmat,
80 this->
ops->add(op_ht);
82 if (gs_is_hybrid(dft_functional))
85 *this->
DM_diff, exx_lri, kv,
pX[0], pc, pmat,
89 this->
ops->add(op_ht_exx);
100 const std::shared_ptr<LR::PotHxcLR> lr_potential = pot.lock();
101 const LR::KernelXC& kernel = lr_potential->xc_kernel_components();
103 const bool triplet = spin_type ==
"triplet";
104 const int kernel_nspin = kernel.
nspin();
105 this->
pot_grad = std::make_shared<PotGradXCLR>(kernel, rho_basis, ucell,
106 lr_potential->nrxx, kernel_nspin, triplet);
110 assert(op_gxc !=
nullptr);
111 this->
ops->add(op_gxc);
138 for (
auto& t : dm_trans_2d)
141 for (
int u = 0; u < naos; ++u)
143 for (
int v = u + 1; v < naos; ++v)
145 std::swap(d[u * naos + v], d[v * naos + u]);
150 for (
int ik = 0; ik < this->
nk; ++ik)
152 this->
DM_trans->set_dmk_ptr(ik, dm_trans_2d[ik].data<T>());
156 this->
cal_dm_diff = [
this, &psi_ks, &pc, naos, &
nocc, &
nvirt, &pmat](
const int& is,
const T*
const X,
const std::vector<ct::Tensor>* density_add)->
void
165 for (
auto& t: dm_diff_2d)
168 for (
int ik = 0; ik < this->
nk; ++ik)
170 if (density_add !=
nullptr)
172 dm_diff_2d[ik] = dm_diff_2d[ik] + density_add->at(ik);
174 this->
DM_diff->set_dmk_ptr(ik, dm_diff_2d[ik].data<T>());
182 virtual void hPsi(
const T*
const psi,
T*
const hpsi,
const int ld_psi,
const int nband)
const override
184 const std::vector<std::vector<ct::Tensor>> no_density;
185 this->
hPsi(psi, hpsi, ld_psi, nband, no_density);
188 void hPsi(
const T*
psi,
T* hpsi,
const int ld_psi,
const int nband,
189 const std::vector<std::vector<ct::Tensor>>& window_density)
const
191 assert(window_density.empty() || window_density.size() == nband);
192 assert(ld_psi == this->
nk * this->
pX[0].size());
193 for (
int ib = 0;ib < nband;++ib)
195 const int offset = ib * ld_psi;
197 const auto* density_add = window_density.empty() ? nullptr : &window_density[ib];
200 while (node !=
nullptr)
202 node->
act(1, ld_psi, 1,
psi + offset, hpsi + offset);
209 std::unique_ptr<module_dm::DensityMatrix<T, T>>
DM_diff;
210 std::function<void(
const int&,
const T*,
const std::vector<ct::Tensor>*)>
cal_dm_diff;
238 const std::vector<int>&
nocc,
239 const std::vector<int>&
nvirt,
241 const std::vector<double>& orb_cutoff,
247 const double& exx_alpha,
249 std::weak_ptr<PotHxcLR> pot,
250 std::weak_ptr<PotHxcLR> pot_hxc_gs,
252 const std::vector<Parallel_Blkcyclic>&
pX,
255 const std::string& ks_solver,
256 const std::string& dft_functional,
258 const int local_dimension,
259 const int global_dimension)
271 auto newCXC = [
this, &nspin, &naos, &
nocc, &
nvirt, &psi_ks, &pot, &ucell, &orb_cutoff, &gd, &kv, &
pX, &pc, &pmat](
const int sl,
const int sr)
274 *this->
DM_trans, pot, ucell, orb_cutoff, gd, kv,
pX, pc, pmat,
277 this->
ops[0] = newCXC(0, 0);
278 this->
ops[1] = newCXC(0, 1);
279 this->
ops[2] = newCXC(1, 0);
280 this->
ops[3] = newCXC(1, 1);
283 auto newHT = [
this, &nspin, &naos, &
nocc, &
nvirt, &psi_ks, &pot_hxc_gs, &ucell, &orb_cutoff, &gd, &kv, &
pX, &pc, &pmat](
const int sl,
const int sr)
286 *this->
DM_diff, pot_hxc_gs, ucell, orb_cutoff, gd, kv,
pX, pc, pmat,
289 this->
ops[0]->add(newHT(0, 0));
290 this->
ops[1]->add(newHT(0, 1));
291 this->
ops[2]->add(newHT(1, 0));
292 this->
ops[3]->add(newHT(1, 1));
301 pot.lock()->get_rho_basis(), ucell, orb_cutoff, gd, kv, pmat, pc, psi_ks,
310 if (exx_kernel_list().count(xc_kernel))
312 for (
int is : {0, 1})
319 if (gs_is_hybrid(dft_functional))
321 for (
int is : {0, 1})
336 this->
gxc_->act(X, out);
344 const std::vector<ct::Tensor>* density_add)
override
358 LR_Util::matsym(t.template data<T>(), this->naos_, this->pmat_.para_2d());
362 for (
auto& t : this->dmx_buf_)
364 T* d = t.template data<T>();
365 for (
int u = 0;u < this->
naos_;++u)
367 for (
int v = u + 1; v < this->naos_; ++v)
369 std::swap(d[u * this->naos_ + v], d[v * this->naos_ + u]);
374 for (
auto& t: this->dmd_buf_)
379 for (
int ik = 0;ik < this->
nk;++ik)
381 this->
DM_trans->set_dmk_ptr(ik, this->dmx_buf_[ik].
template data<T>());
382 if (density_add !=
nullptr)
384 const int block = is * this->nk + ik;
385 this->dmd_buf_[ik] = this->dmd_buf_[ik] + density_add->at(block);
387 this->
DM_diff->set_dmk_ptr(ik, this->dmd_buf_[ik].
template data<T>());
397 std::unique_ptr<module_dm::DensityMatrix<T, T>>
DM_trans;
398 std::unique_ptr<module_dm::DensityMatrix<T, T>>
DM_diff;
401 std::unique_ptr<OperatorGxcULR<T>>
gxc_;
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
Class for k-points management.
Definition klist.h:20
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
Calculate the exchange-correlation (XC) kernel ($f_{xc}=\delta^2E_xc/\delta\rho^2$) and store its com...
Definition xc_kernel.h:84
int nspin() const
Metadata belongs to this coefficient set, independent of later global XC changes.
Definition xc_kernel.h:109
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
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_diff
Definition hamilt_zeq_r.h:209
Z_vector_R(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< PotHxcLR > pot, std::weak_ptr< PotHxcLR > pot_hxc_gs, const K_Vectors &kv, const std::vector< Parallel_Blkcyclic > &pX, const Parallel_Blkcyclic &pc, const Parallel_Orbitals &pmat, const std::string &in_dir, const std::string &out_dir, const std::string &dft_functional, const std::string &spin_type="singlet")
Definition hamilt_zeq_r.h:24
typename OperatorLRHxc< T >::MO_TO_AO_TYPE ATYPE
Definition hamilt_zeq_r.h:19
std::function< void(const int &, const T *, const std::vector< ct::Tensor > *)> cal_dm_diff
Definition hamilt_zeq_r.h:210
std::shared_ptr< PotLRBase > pot_grad
Definition hamilt_zeq_r.h:211
void hPsi(const T *psi, T *hpsi, const int ld_psi, const int nband, const std::vector< std::vector< ct::Tensor > > &window_density) const
Definition hamilt_zeq_r.h:188
virtual void hPsi(const T *const psi, T *const hpsi, const int ld_psi, const int nband) const override
Definition hamilt_zeq_r.h:182
std::unique_ptr< OperatorGxcULR< T > > gxc_
Definition hamilt_zeq_r.h:401
Z_vector_UR(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< PotHxcLR > pot, std::weak_ptr< PotHxcLR > pot_hxc_gs, const K_Vectors &kv, const std::vector< Parallel_Blkcyclic > &pX, const Parallel_Blkcyclic &pc, const Parallel_Orbitals &pmat, const std::string &ks_solver, const std::string &dft_functional, const int nk, const int local_dimension, const int global_dimension)
Definition hamilt_zeq_r.h:235
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_trans
Definition hamilt_zeq_r.h:397
void set_dm(const int is, const T *const X, const std::vector< ct::Tensor > *density_add) override
Definition hamilt_zeq_r.h:343
const psi::Psi< T > & psi_ks_
Definition hamilt_zeq_r.h:395
const Parallel_Orbitals & pmat_
Definition hamilt_zeq_r.h:394
std::vector< ct::Tensor > dmd_buf_
Definition hamilt_zeq_r.h:400
void band_extra(const T *const X, T *const out) const override
optional per-band contribution that does not fit the 2x2 block structure. NOTE matrix() deliberately ...
Definition hamilt_zeq_r.h:332
typename OperatorLRHxc< T >::MO_TO_AO_TYPE ATYPE
Definition hamilt_zeq_r.h:230
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_diff
Definition hamilt_zeq_r.h:398
const Parallel_Blkcyclic & pc_
Definition hamilt_zeq_r.h:393
const int naos_
Definition hamilt_zeq_r.h:392
std::vector< ct::Tensor > dmx_buf_
Definition hamilt_zeq_r.h:399
std::vector< psi::Psi< T > > psi_ks_spin_
Definition hamilt_zeq_r.h:396
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
std::vector< ModuleBase::Vector3< double > > kvec_d
Direct coordinates of the points.
Definition reciprocal_grid.h:57
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
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
Operator * next_op
interface type 3: return a Psi-type HPsi
Definition operator.h:112
virtual void act(const int nbands, const int nbasis, const int npol, const T *tmpsi_in, T *tmhpsi, const int ngk_ik=0, const bool is_first_node=false) const
Definition operator.h:95
#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
@ VO
Definition mo_type.h:9
bool has_local_xc(const std::string &name)
check if the xc functional has local xc kernel
Definition lr_util.h:80
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
void mattrans(const T *in, const int n, const Parallel_Blkcyclic &pmat, T *out)
Definition esolver_lr_lcao_tddft.h:28
std::vector< container::Tensor > cal_dm_diff_pblas(const T *const X_istate, const Parallel_Blkcyclic &px, const psi::Psi< T, base_device::DEVICE_CPU > &c, const Parallel_Blkcyclic &pc, const int &naos, const int &nocc, const int &nvirt, const Parallel_Blkcyclic &pmat, const bool renorm_k=true, const int nspin=1)
calculate the 2d-block difference density matrix in AO basis using p?gemm
Definition dm_diff_par.cpp:235
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
std::vector< container::Tensor > cal_dm_diff_blas(const T *const X_istate, const psi::Psi< T, base_device::DEVICE_CPU > &c, const int &naos, const int &nocc, const int &nvirt, const bool renorm_k=true, const int nspin=1)
calculate the 2d-block transition density matrix in AO basis using ?gemm
Definition dm_diff_ser.cpp:184
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_dmdiff_hxc
Definition operator.h:31
@ lr_dmtrans_hxc
Definition operator.h:29
@ lr_dmdiff_exx
Definition operator.h:33
@ lr_dmtrans_gxc
Definition operator.h:30
Definition diag_lcao.h:14