34template <
typename T,
typename Device>
42 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik)
44 this->phi_cal(this->k_pack, ik);
46 this->judge_singularity(ik);
53 this->sum2_factor = 0.0;
57 this->sum3[iw_l][iw_r] =
T(0.0);
61 for (
int iq_tmp = this->iq_vecik; iq_tmp < this->iq_vecik + this->q_pack->kv_ptr->get_nks() /
PARAM.
inp.
nspin; ++iq_tmp)
66 ? (iq_tmp % (this->q_pack->kv_ptr->get_nks() /
PARAM.
inp.
nspin))
68 this->qkg2_exp(ik, iq);
71 this->b_cal(ik, iq, ib);
73 if (iq == this->iq_vecik) {
74 this->sum3_cal(iq, ib);
81 this->exx_energy_cal();
86template <
typename T,
typename Device>
111 int gzero_judge = -1;
175template <
typename T,
typename Device>
179 {
delete this->k_pack->hvec_array; this->k_pack->hvec_array =
nullptr; }
180 delete this->k_pack; this->k_pack =
nullptr;
184 this->q_pack =
nullptr;
188 delete this->q_pack->kv_ptr; this->q_pack->kv_ptr =
nullptr;
191 delete this->q_pack; this->q_pack =
nullptr;
195template <
typename T,
typename Device>
201 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
203 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib) / 2;
206 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
208 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib);
213template <
typename T,
typename Device>
217 std::vector<T> porter (this->wfc_basis->nrxx);
221 this->wfc_basis->recip2real(&(kq_pack->
psi_local->operator()(ikq, iw, 0)), porter.data(), ikq);
223 for (
int ix = 0; ix < this->rho_basis->nx; ++ix)
226 for (
int iy = 0; iy < this->rho_basis->ny; ++iy)
228 const Treal phase_xy = phase_x + kq_pack->
kv_ptr->
kvec_d[ikq].y * iy / this->rho_basis->ny;
229 for (
int iz = this->rho_basis->startz_current; iz < this->rho_basis->startz_current + this->rho_basis->nplane; ++iz)
231 const Treal phase_xyz = phase_xy + kq_pack->
kv_ptr->
kvec_d[ikq].z * iz / this->rho_basis->nz;
232 const T exp_tmp = std::exp(phase_xyz * this->two_pi_i);
233 this->phi[iw][ir] = porter[ir] * exp_tmp;
242template <
typename T,
typename Device>
249 std::vector<T> porter (this->wfc_basis->nrxx);
250 for (
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
254 this->wfc_basis->recip2real(&(this->q_pack->kspw_psi_ptr->operator()(iq, ib, 0)), porter.data(), iq);
257 for (
int ix = 0; ix < this->rho_basis->nx; ++ix)
259 const Treal phase_x = this->q_pack->kv_ptr->kvec_d[iq].x * ix / this->rho_basis->nx;
260 for (
int iy = 0; iy < this->rho_basis->ny; ++iy)
262 const Treal phase_xy = phase_x + this->q_pack->kv_ptr->kvec_d[iq].y * iy / this->rho_basis->ny;
263 for (
int iz = this->rho_basis->startz_current; iz < this->rho_basis->startz_current + this->rho_basis->nplane; ++iz)
265 const Treal phase_xyz = phase_xy + this->q_pack->kv_ptr->kvec_d[iq].z * iz / this->rho_basis->nz;
266 const T exp_tmp = std::exp(phase_xyz * this->two_pi_i);
267 this->
psi[iq][ib][ir] = porter[ir] * exp_tmp;
277 for (
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
279 this->phi_cal(this->q_pack, iq);
285 for (
int ir = 0; ir < this->rho_basis->nrxx; ++ir)
287 this->
psi[iq][ib][ir] += (*this->q_pack->hvec_array)(iq, ib, iw) * this->phi[iw][ir];
299template <
typename T,
typename Device>
309 Treal min_q_minus_k(std::numeric_limits<Treal>::max());
310 for(
int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
312 const Treal q_minus_k((this->q_pack->kv_ptr->kvec_c[iq] - this->k_pack->kv_ptr->kvec_c[ik]).norm2());
313 if(q_minus_k < min_q_minus_k)
315 min_q_minus_k = q_minus_k;
323template <
typename T,
typename Device>
327 for(
int ig=0; ig<this->rho_basis->npw; ++ig)
329 const Treal qkg2 = ((this->q_pack->kv_ptr->kvec_c[iq] - this->k_pack->kv_ptr->kvec_c[ik] + this->rho_basis->gcar[ig]) * (
ModuleBase::TWO_PI / this->ucell_ptr->lat0)).norm2();
332 if (std::abs(qkg2) < 1e-10)
333 { this->recip_qkg2[ig] = 0.0; }
335 { this->recip_qkg2[ig] = 1.0 / qkg2; }
336 this->sum2_factor += this->recip_qkg2[ig] * std::exp(-info.lambda * qkg2);
337 this->recip_qkg2[ig] = sqrt(this->recip_qkg2[ig]);
341 if (std::abs(qkg2) < 1e-10)
342 { this->recip_qkg2[ig] = 1.0 / (2 * info.hse_omega); }
344 { this->recip_qkg2[ig] = sqrt((1 - std::exp(-qkg2 / (4 * info.hse_omega * info.hse_omega))) / qkg2); }
348 throw( std::string(__FILE__) +
" line " + std::to_string(__LINE__) );
354template <
typename T,
typename Device>
359 std::vector<T > mul_tmp(this->rho_basis->nrxx);
360 for(
size_t ir=0,ix=0; ix<this->rho_basis->nx; ++ix)
362 const Treal phase_x = q_minus_k.
x * ix / this->rho_basis->nx;
363 for(
size_t iy=0; iy<this->rho_basis->ny; ++iy)
365 const Treal phase_xy = phase_x + q_minus_k.
y * iy / this->rho_basis->ny;
366 for(
size_t iz=this->rho_basis->startz_current; iz<this->rho_basis->startz_current+this->rho_basis->nplane; ++iz)
368 const Treal phase_xyz = phase_xy + q_minus_k.
z * iz / this->rho_basis->nz;
369 mul_tmp[ir] = std::exp(-phase_xyz * this->two_pi_i);
370 mul_tmp[ir] *= this->
psi[iq][ib][ir];
376 std::vector<T> porter (this->rho_basis->nrxx);
379 auto& phi_w = this->phi[iw];
380 for(
size_t ir=0; ir<this->rho_basis->nrxx; ++ir)
382 porter[ir] =
conj(phi_w[ir]) * mul_tmp[ir] ;
385 T*
const b_w = &this->b[iw * this->rho_basis->npw];
386 this->rho_basis->real2recip( porter.data(), b_w);
389 this->b0[iw] = b_w[this->rho_basis->ig_gge0];
392 for (
size_t ig = 0; ig < this->rho_basis->npw; ++ig)
393 { b_w[ig] *= this->recip_qkg2[ig]; }
398template <
typename T,
typename Device>
405 this->sum3[iw_l][iw_r] += this->b0[iw_l] *
conj(this->b0[iw_r]) * (
Treal)this->q_pack->wf_wg(iq, ib);
410template <
typename T,
typename Device>
415 LapackConnector::herk(
418 (
Treal)this->q_pack->wf_wg(iq, ib), this->b.data(), this->rho_basis->npw,
427template <
typename T,
typename Device>
431 Treal sum2_factor_g = 0.0;
433 const Treal spin_fac = 2.0;
436 { MPI_Reduce(&this->sum2_factor, &sum2_factor_g, 1, MPI_DOUBLE, MPI_SUM, gzero_rank_in_pool,
POOL_WORLD); }
439 for (
size_t iw_r = 0; iw_r < iw_l; ++iw_r) {
447 this->exx_matrix[ik][iw_l][iw_r] = -fourpi_div_omega * this->sum1[iw_l *
PARAM.
globalv.
nlocal + iw_r] * spin_fac;
452 this->exx_matrix[ik][iw_l][iw_r] += spin_fac * (fourpi_div_omega * this->sum3[iw_l][iw_r] * sum2_factor_g);
453 this->exx_matrix[ik][iw_l][iw_r] += spin_fac * (-1 / (
Treal)sqrt(info.lambda *
ModuleBase::PI) * (
Treal)(this->q_pack->kv_ptr->get_nks() /
PARAM.
inp.
nspin) * this->sum3[iw_l][iw_r]);
461template <
typename T,
typename Device>
467 Treal exx_energy_tmp = 0.0;
469 for(
int ik=0; ik<this->k_pack->kv_ptr->get_nks(); ++ik) {
473 exx_energy_tmp += (this->exx_matrix[ik][iw_l][iw_r] *
conj((*this->k_pack->hvec_array)(ik, ib, iw_l)) * (*this->k_pack->hvec_array)(ik, ib, iw_r)).real() * this->k_pack->wf_wg(ik, ib);
476 MPI_Allreduce( &exx_energy_tmp, &this->exx_energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
479 this->exx_energy /= 2;
483template <
typename T,
typename Device>
493 const std::string exx_q_pack =
"exx_q_pack/";
496 int ret = mkdir(dir_path.c_str(), 0755);
497 assert(ret == 0 || errno == EEXIST);
501 if (stat(kpoint_dest.c_str(), &st) != 0)
504 std::ofstream dst(kpoint_dest, std::ios::binary);
509 std::stringstream ss_wf_wg;
511 std::ofstream ofs_wf_wg(ss_wf_wg.str().c_str());
512 for(
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
516 ofs_wf_wg<<this->q_pack->wf_wg(iq,ib)<<
"\t";
518 ofs_wf_wg<<std::endl;
522 std::stringstream ss_hvec;
524 std::ofstream ofs_hvec(ss_hvec.str().c_str());
525 for(
int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
531 ofs_hvec << (*this->q_pack->hvec_array)(iq, ib, iw).real() <<
" " << (*this->q_pack->hvec_array)(iq, ib, iw).imag() <<
" ";
int gzero_rank_in_pool
Definition exx_lip.h:73
std::vector< T > b
Definition exx_lip.h:95
std::vector< std::vector< T > > phi
Definition exx_lip.h:91
const UnitCell * ucell_ptr
Definition exx_lip.h:123
struct Exx_Lip::k_package * q_pack
struct Exx_Lip::k_package * k_pack
void sum_all(const int ik)
Definition exx_lip.hpp:428
const Exx_Info::Exx_Info_Lip & info
Definition exx_lip.h:36
void b_sum(const int iq, const int ib)
Definition exx_lip.hpp:411
void cal_exx()
Definition exx_lip.hpp:35
const ModulePW::PW_Basis_K * wfc_basis
Definition exx_lip.h:121
void write_q_pack() const
Definition exx_lip.hpp:484
void exx_energy_cal()
Definition exx_lip.hpp:462
~Exx_Lip()
Definition exx_lip.hpp:176
std::vector< Treal > recip_qkg2
Definition exx_lip.h:93
void qkg2_exp(const int ik, const int iq)
Definition exx_lip.hpp:324
typename GetTypeReal< T >::type Treal
Definition exx_lip.h:31
std::vector< std::vector< std::vector< T > > > exx_matrix
Definition exx_lip.h:100
void phi_cal(k_package *kq_pack, const int ikq)
Definition exx_lip.hpp:214
std::vector< T > sum1
Definition exx_lip.h:97
void wf_wg_cal()
Definition exx_lip.hpp:196
Exx_Lip(const Exx_Info::Exx_Info_Lip &info_in)
std::vector< std::vector< T > > sum3
Definition exx_lip.h:98
void judge_singularity(const int ik)
Definition exx_lip.hpp:300
std::vector< T > b0
Definition exx_lip.h:96
void sum3_cal(const int iq, const int ib)
Definition exx_lip.hpp:399
void b_cal(const int ik, int iq, const int ib)
Definition exx_lip.hpp:355
void psi_cal()
Definition exx_lip.hpp:243
const ModulePW::PW_Basis * rho_basis
Definition exx_lip.h:120
int get_nks() const
Definition klist.h:68
std::vector< ModuleBase::Vector3< double > > kvec_d
Cartesian coordinates of k points.
Definition klist.h:16
std::vector< int > ngk
wk, weight of k points
Definition klist.h:20
3 elements vector
Definition vector3.h:22
T x
Definition vector3.h:24
T y
Definition vector3.h:25
T z
Definition vector3.h:26
void create(const int nrow, const int ncol, const bool flag_zero=true)
Definition matrix.cpp:122
static void tick(const std::string &class_name_in, const std::string &name_in)
Use twice at a time: the first time, set start_flag to false; the second time, calculate the time dur...
Definition timer.cpp:62
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:57
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:56
int nrxx
Definition pw_basis.h:120
int npw
Definition pw_basis.h:115
double * gg_uniq
Definition pw_basis.h:160
const Input_para & inp
Definition parameter.h:26
const System_para & globalv
Definition parameter.h:30
Definition structure_factor.h:11
Definition elecstate.h:15
#define T
Definition exp.cpp:237
This is a wrapper of some LAPACK routines. Row-Major version.
int MY_POOL
global index of pool (count in pool)
Definition global_variable.cpp:22
int RANK_IN_POOL
global index of pool (count in process), my_rank in each pool
Definition global_variable.cpp:26
void ZEROS(std::complex< T > *u, const TI n)
Definition global_function.h:109
const double TWO_PI
Definition constants.h:21
const double PI
Definition constants.h:19
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
double conj(double a)
Definition operator_lr_hxc.cpp:14
MPI_Comm POOL_WORLD
Definition parallel_comm.cpp:6
Parameter PARAM
Definition parameter.cpp:3
const Conv_Coulomb_Pot_K::Ccp_Type & ccp_type
Definition exx_info.h:42
const elecstate::ElecState * pelec
Definition exx_lip.h:86
psi::Psi< T, Device > * kspw_psi_ptr
PW wavefunction.
Definition exx_lip.h:80
K_Vectors * kv_ptr
Definition exx_lip.h:78
psi::Psi< T, Device > * psi_local
NAOs in PW.
Definition exx_lip.h:81
psi::Psi< T, Device > * hvec_array
LCAO wavefunction, the eigenvectors from lapack diagonalization.
Definition exx_lip.h:85
ModuleBase::matrix wf_wg
Definition exx_lip.h:82
int nlocal
total number of local basis.
Definition system_parameter.h:23
std::string global_out_dir
global output directory
Definition system_parameter.h:42