30template <
typename T,
typename Device>
38 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik)
40 this->phi_cal(this->k_pack, ik);
42 this->judge_singularity(ik);
49 this->sum2_factor = 0.0;
53 this->sum3[iw_l][iw_r] =
T(0.0);
57 for (
int iq_tmp = this->iq_vecik; iq_tmp < this->iq_vecik + this->q_pack->kv_ptr->get_nks() /
PARAM.
inp.
nspin; ++iq_tmp)
62 ? (iq_tmp % (this->q_pack->kv_ptr->get_nks() /
PARAM.
inp.
nspin))
64 this->qkg2_exp(ik, iq);
67 this->b_cal(ik, iq, ib);
69 if (iq == this->iq_vecik) {
70 this->sum3_cal(iq, ib);
77 this->exx_energy_cal();
82template <
typename T,
typename Device>
107 int gzero_judge = -1;
171template <
typename T,
typename Device>
175 {
delete this->k_pack->hvec_array; this->k_pack->hvec_array =
nullptr; }
176 delete this->k_pack; this->k_pack =
nullptr;
180 this->q_pack =
nullptr;
184 delete this->q_pack->kv_ptr; this->q_pack->kv_ptr =
nullptr;
187 delete this->q_pack; this->q_pack =
nullptr;
191template <
typename T,
typename Device>
197 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
199 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib) / 2;
202 for (
int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
204 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib);
209template <
typename T,
typename Device>
213 std::vector<T> porter (this->wfc_basis->nrxx);
217 this->wfc_basis->recip2real(&(kq_pack->
psi_local->operator()(ikq, iw, 0)), porter.data(), ikq);
219 for (
int ix = 0; ix < this->rho_basis->nx; ++ix)
222 for (
int iy = 0; iy < this->rho_basis->ny; ++iy)
224 const Treal phase_xy = phase_x + kq_pack->
kv_ptr->
kvec_d[ikq].y * iy / this->rho_basis->ny;
225 for (
int iz = this->rho_basis->startz_current; iz < this->rho_basis->startz_current + this->rho_basis->nplane; ++iz)
227 const Treal phase_xyz = phase_xy + kq_pack->
kv_ptr->
kvec_d[ikq].z * iz / this->rho_basis->nz;
228 const T exp_tmp = std::exp(phase_xyz * this->two_pi_i);
229 this->phi[iw][ir] = porter[ir] * exp_tmp;
238template <
typename T,
typename Device>
245 std::vector<T> porter (this->wfc_basis->nrxx);
246 for (
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
250 this->wfc_basis->recip2real(&(this->q_pack->kspw_psi_ptr->operator()(iq, ib, 0)), porter.data(), iq);
253 for (
int ix = 0; ix < this->rho_basis->nx; ++ix)
255 const Treal phase_x = this->q_pack->kv_ptr->kvec_d[iq].x * ix / this->rho_basis->nx;
256 for (
int iy = 0; iy < this->rho_basis->ny; ++iy)
258 const Treal phase_xy = phase_x + this->q_pack->kv_ptr->kvec_d[iq].y * iy / this->rho_basis->ny;
259 for (
int iz = this->rho_basis->startz_current; iz < this->rho_basis->startz_current + this->rho_basis->nplane; ++iz)
261 const Treal phase_xyz = phase_xy + this->q_pack->kv_ptr->kvec_d[iq].z * iz / this->rho_basis->nz;
262 const T exp_tmp = std::exp(phase_xyz * this->two_pi_i);
263 this->
psi[iq][ib][ir] = porter[ir] * exp_tmp;
273 for (
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
275 this->phi_cal(this->q_pack, iq);
281 for (
int ir = 0; ir < this->rho_basis->nrxx; ++ir)
283 this->
psi[iq][ib][ir] += (*this->q_pack->hvec_array)(iq, ib, iw) * this->phi[iw][ir];
295template <
typename T,
typename Device>
305 Treal min_q_minus_k(std::numeric_limits<Treal>::max());
306 for(
int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
308 const Treal q_minus_k((this->q_pack->kv_ptr->kvec_c[iq] - this->k_pack->kv_ptr->kvec_c[ik]).norm2());
309 if(q_minus_k < min_q_minus_k)
311 min_q_minus_k = q_minus_k;
319template <
typename T,
typename Device>
323 for(
int ig=0; ig<this->rho_basis->npw; ++ig)
325 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();
328 if (std::abs(qkg2) < 1e-10)
329 { this->recip_qkg2[ig] = 0.0; }
331 { this->recip_qkg2[ig] = 1.0 / qkg2; }
332 this->sum2_factor += this->recip_qkg2[ig] * std::exp(-info.lambda * qkg2);
333 this->recip_qkg2[ig] = sqrt(this->recip_qkg2[ig]);
337 if (std::abs(qkg2) < 1e-10)
338 { this->recip_qkg2[ig] = 1.0 / (2 * info.hse_omega); }
340 { this->recip_qkg2[ig] = sqrt((1 - std::exp(-qkg2 / (4 * info.hse_omega * info.hse_omega))) / qkg2); }
344 throw( std::string(__FILE__) +
" line " + std::to_string(__LINE__) );
350template <
typename T,
typename Device>
355 std::vector<T > mul_tmp(this->rho_basis->nrxx);
356 for(
size_t ir=0,ix=0; ix<this->rho_basis->nx; ++ix)
358 const Treal phase_x = q_minus_k.
x * ix / this->rho_basis->nx;
359 for(
size_t iy=0; iy<this->rho_basis->ny; ++iy)
361 const Treal phase_xy = phase_x + q_minus_k.
y * iy / this->rho_basis->ny;
362 for(
size_t iz=this->rho_basis->startz_current; iz<this->rho_basis->startz_current+this->rho_basis->nplane; ++iz)
364 const Treal phase_xyz = phase_xy + q_minus_k.
z * iz / this->rho_basis->nz;
365 mul_tmp[ir] = std::exp(-phase_xyz * this->two_pi_i);
366 mul_tmp[ir] *= this->
psi[iq][ib][ir];
372 std::vector<T> porter (this->rho_basis->nrxx);
375 auto& phi_w = this->phi[iw];
376 for(
size_t ir=0; ir<this->rho_basis->nrxx; ++ir)
378 porter[ir] =
conj(phi_w[ir]) * mul_tmp[ir] ;
381 T*
const b_w = &this->b[iw * this->rho_basis->npw];
382 this->rho_basis->real2recip( porter.data(), b_w);
385 this->b0[iw] = b_w[this->rho_basis->ig_gge0];
388 for (
size_t ig = 0; ig < this->rho_basis->npw; ++ig)
389 { b_w[ig] *= this->recip_qkg2[ig]; }
394template <
typename T,
typename Device>
401 this->sum3[iw_l][iw_r] += this->b0[iw_l] *
conj(this->b0[iw_r]) * (
Treal)this->q_pack->wf_wg(iq, ib);
406template <
typename T,
typename Device>
414 (
Treal)this->q_pack->wf_wg(iq, ib), this->b.data(), this->rho_basis->npw,
423template <
typename T,
typename Device>
427 Treal sum2_factor_g = 0.0;
429 const Treal spin_fac = 2.0;
432 { MPI_Reduce(&this->sum2_factor, &sum2_factor_g, 1, MPI_DOUBLE, MPI_SUM, gzero_rank_in_pool,
POOL_WORLD); }
435 for (
size_t iw_r = 0; iw_r < iw_l; ++iw_r) {
443 this->exx_matrix[ik][iw_l][iw_r] = -fourpi_div_omega * this->sum1[iw_l *
PARAM.
globalv.
nlocal + iw_r] * spin_fac;
448 this->exx_matrix[ik][iw_l][iw_r] += spin_fac * (fourpi_div_omega * this->sum3[iw_l][iw_r] * sum2_factor_g);
449 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]);
457template <
typename T,
typename Device>
463 Treal exx_energy_tmp = 0.0;
465 for(
int ik=0; ik<this->k_pack->kv_ptr->get_nks(); ++ik) {
469 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);
472 MPI_Allreduce( &exx_energy_tmp, &this->exx_energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
475 this->exx_energy /= 2;
479template <
typename T,
typename Device>
489 const std::string exx_q_pack =
"exx_q_pack/";
492 assert( system(command_mkdir.c_str()) == 0);
495 assert( system(command_kpoint.c_str()) == 0);
497 std::stringstream ss_wf_wg;
499 std::ofstream ofs_wf_wg(ss_wf_wg.str().c_str());
500 for(
int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
504 ofs_wf_wg<<this->q_pack->wf_wg(iq,ib)<<
"\t";
506 ofs_wf_wg<<std::endl;
510 std::stringstream ss_hvec;
512 std::ofstream ofs_hvec(ss_hvec.str().c_str());
513 for(
int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
519 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:424
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:407
void cal_exx()
Definition exx_lip.hpp:31
const ModulePW::PW_Basis_K * wfc_basis
Definition exx_lip.h:121
void write_q_pack() const
Definition exx_lip.hpp:480
void exx_energy_cal()
Definition exx_lip.hpp:458
~Exx_Lip()
Definition exx_lip.hpp:172
std::vector< Treal > recip_qkg2
Definition exx_lip.h:93
void qkg2_exp(const int ik, const int iq)
Definition exx_lip.hpp:320
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:210
std::vector< T > sum1
Definition exx_lip.h:97
void wf_wg_cal()
Definition exx_lip.hpp:192
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:296
std::vector< T > b0
Definition exx_lip.h:96
void sum3_cal(const int iq, const int ib)
Definition exx_lip.hpp:395
void b_cal(const int ik, int iq, const int ib)
Definition exx_lip.hpp:351
void psi_cal()
Definition exx_lip.hpp:239
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
static void herk(const char uplo, const char trans, const int n, const int k, const double alpha, const std::complex< double > *A, const int lda, const double beta, std::complex< double > *C, const int ldc)
Definition lapack_connector.h:453
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:57
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
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