31template <
typename T,
typename Device>
39 for (
int ik = 0; ik < this->
k_pack->kv_ptr->get_nks(); ++ik)
44 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l) {
45 for (
int iw_r = 0; iw_r <
PARAM.globalv.nlocal; ++iw_r) {
46 this->
sum1[iw_l *
PARAM.globalv.nlocal + iw_r] =
T(0.0);
52 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l) {
53 for (
int iw_r = 0; iw_r <
PARAM.globalv.nlocal; ++iw_r) {
54 this->
sum3[iw_l][iw_r] =
T(0.0);
62 (ik < (this->
k_pack->kv_ptr->get_nks() /
PARAM.inp.nspin))
63 ? (iq_tmp % (this->
q_pack->kv_ptr->get_nks() /
PARAM.inp.nspin))
64 : (iq_tmp % (this->
q_pack->kv_ptr->get_nks() /
PARAM.inp.nspin) + (this->q_pack->kv_ptr->get_nks() /
PARAM.inp.nspin));
66 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib)
68 this->
b_cal(ik, iq, ib);
83template <
typename T,
typename Device>
98 this->
k_pack->kv_ptr = kv_ptr_in;
99 this->
k_pack->psi_local = psi_local_in;
100 this->
k_pack->pelec = pelec_in;
101 this->
k_pack->kspw_psi_ptr = kspw_psi_ptr_in;
106 int gzero_judge = -1;
125 this->
phi.resize(
PARAM.globalv.nlocal);
126 for (
int iw = 0; iw <
PARAM.globalv.nlocal; ++iw)
129 this->
psi.resize(this->
q_pack->kv_ptr->get_nks());
130 for (
int iq = 0; iq < this->
q_pack->kv_ptr->get_nks(); ++iq)
132 this->
psi[iq].resize(
PARAM.inp.nbands);
133 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib)
139 this->
b.resize(
PARAM.globalv.nlocal * this->rho_basis->npw);
147 this->
b0.resize(
PARAM.globalv.nlocal);
149 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l)
150 { this->
sum3[iw_l].resize(
PARAM.globalv.nlocal); }
155 for (
int ik = 0; ik < this->
k_pack->kv_ptr->get_nks(); ++ik)
158 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l)
165template <
typename T,
typename Device>
169 {
delete this->
k_pack->hvec_array; this->
k_pack->hvec_array =
nullptr; }
172 if (
PARAM.inp.init_chg ==
"atomic")
176 else if (
PARAM.inp.init_chg ==
"file")
178 delete this->
q_pack->kv_ptr; this->
q_pack->kv_ptr =
nullptr;
185template <
typename T,
typename Device>
190 if (
PARAM.inp.nspin == 1) {
191 for (
int ik = 0; ik < this->
k_pack->kv_ptr->get_nks(); ++ik) {
192 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib) {
193 this->
k_pack->wf_wg(ik, ib) = this->
k_pack->pelec->wg(ik, ib) / 2;
195 else if (
PARAM.inp.nspin == 2) {
196 for (
int ik = 0; ik < this->
k_pack->kv_ptr->get_nks(); ++ik) {
197 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib) {
198 this->
k_pack->wf_wg(ik, ib) = this->
k_pack->pelec->wg(ik, ib);
203template <
typename T,
typename Device>
207 std::vector<T> porter (this->
wfc_basis->nrxx);
208 for (
int iw = 0; iw <
PARAM.globalv.nlocal; ++iw)
211 this->
wfc_basis->recip2real(&(kq_pack->
psi_local->operator()(ikq, iw, 0)), porter.data(), ikq);
213 for (
int ix = 0; ix < this->
rho_basis->nx; ++ix)
216 for (
int iy = 0; iy < this->
rho_basis->ny; ++iy)
219 for (
int iz = this->
rho_basis->startz_current; iz < this->
rho_basis->startz_current + this->rho_basis->nplane; ++iz)
222 const T exp_tmp = std::exp(phase_xyz * this->
two_pi_i);
223 this->
phi[iw][ir] = porter[ir] * exp_tmp;
232template <
typename T,
typename Device>
237 if (
PARAM.inp.init_chg ==
"atomic")
239 std::vector<T> porter (this->
wfc_basis->nrxx);
240 for (
int iq = 0; iq < this->
q_pack->kv_ptr->get_nks(); ++iq)
242 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib)
244 this->
wfc_basis->recip2real(&(this->
q_pack->kspw_psi_ptr->operator()(iq, ib, 0)), porter.data(), iq);
247 for (
int ix = 0; ix < this->
rho_basis->nx; ++ix)
250 for (
int iy = 0; iy < this->
rho_basis->ny; ++iy)
253 for (
int iz = this->
rho_basis->startz_current; iz < this->
rho_basis->startz_current + this->rho_basis->nplane; ++iz)
255 const Treal phase_xyz = phase_xy + this->
q_pack->kv_ptr->kvec_d[iq].z * iz / this->
rho_basis->nz;
256 const T exp_tmp = std::exp(phase_xyz * this->
two_pi_i);
257 this->
psi[iq][ib][ir] = porter[ir] * exp_tmp;
265 else if (
PARAM.inp.init_chg ==
"file")
267 for (
int iq = 0; iq < this->
q_pack->kv_ptr->get_nks(); ++iq)
270 for (
int ib = 0; ib <
PARAM.inp.nbands; ++ib)
273 for (
int iw = 0; iw <
PARAM.globalv.nlocal; ++iw)
275 for (
int ir = 0; ir < this->
rho_basis->nrxx; ++ir)
277 this->
psi[iq][ib][ir] += (*this->
q_pack->hvec_array)(iq, ib, iw) * this->
phi[iw][ir];
289template <
typename T,
typename Device>
293 if (
PARAM.inp.init_chg==
"atomic")
297 else if(
PARAM.inp.init_chg==
"file")
299 Treal min_q_minus_k(std::numeric_limits<Treal>::max());
300 for(
int iq=0; iq<this->
q_pack->kv_ptr->get_nks(); ++iq)
302 const Treal q_minus_k((this->
q_pack->kv_ptr->kvec_c[iq] - this->k_pack->kv_ptr->kvec_c[ik]).norm2());
303 if(q_minus_k < min_q_minus_k)
305 min_q_minus_k = q_minus_k;
313template <
typename T,
typename Device>
317 for(
int ig=0; ig<this->
rho_basis->npw; ++ig)
322 if (std::abs(qkg2) < 1e-10)
331 if (std::abs(qkg2) < 1e-10)
334 { this->
recip_qkg2[ig] = std::sqrt((1 - std::exp(-qkg2 / (4 *
info.hse_omega *
info.hse_omega))) / qkg2); }
338 throw( std::string(__FILE__) +
" line " + std::to_string(__LINE__) );
344template <
typename T,
typename Device>
349 std::vector<T > mul_tmp(this->
rho_basis->nrxx);
350 for( std::size_t ir=0,ix=0; ix<this->
rho_basis->nx; ++ix)
353 for( std::size_t iy=0; iy<this->
rho_basis->ny; ++iy)
355 const Treal phase_xy = phase_x + q_minus_k.
y * iy / this->
rho_basis->ny;
356 for( std::size_t iz=this->
rho_basis->startz_current; iz<this->
rho_basis->startz_current+this->rho_basis->nplane; ++iz)
358 const Treal phase_xyz = phase_xy + q_minus_k.
z * iz / this->
rho_basis->nz;
359 mul_tmp[ir] = std::exp(-phase_xyz * this->
two_pi_i);
360 mul_tmp[ir] *= this->
psi[iq][ib][ir];
366 std::vector<T> porter (this->
rho_basis->nrxx);
367 for(std::size_t iw=0; iw<
PARAM.globalv.nlocal; ++iw)
369 auto& phi_w = this->
phi[iw];
370 for( std::size_t ir=0; ir<this->
rho_basis->nrxx; ++ir)
372 porter[ir] = std::conj(phi_w[ir]) * mul_tmp[ir] ;
375 T*
const b_w = &this->
b[iw * this->
rho_basis->npw];
376 this->
rho_basis->real2recip( porter.data(), b_w);
382 for (std::size_t ig = 0; ig < this->
rho_basis->npw; ++ig)
388template <
typename T,
typename Device>
393 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l) {
394 for (
int iw_r = 0; iw_r <
PARAM.globalv.nlocal; ++iw_r) {
395 this->
sum3[iw_l][iw_r] += this->
b0[iw_l] * std::conj(this->
b0[iw_r]) * (
Treal)this->
q_pack->wf_wg(iq, ib);
400template <
typename T,
typename Device>
405 LapackConnector::herk(
407 PARAM.globalv.nlocal, this->rho_basis->npw,
408 (
Treal)this->q_pack->wf_wg(iq, ib), this->b.data(), this->rho_basis->npw,
409 1.0, this->sum1.data(),
PARAM.globalv.nlocal);
417template <
typename T,
typename Device>
421 Treal sum2_factor_g = 0.0;
423 const Treal spin_fac = 2.0;
428 for (std::size_t iw_l = 1; iw_l <
PARAM.globalv.nlocal; ++iw_l) {
429 for (std::size_t iw_r = 0; iw_r < iw_l; ++iw_r) {
430 this->
sum1[iw_l *
PARAM.globalv.nlocal + iw_r] = std::conj(this->
sum1[iw_r *
PARAM.globalv.nlocal + iw_l]);
433 for (
int iw_l = 0; iw_l <
PARAM.globalv.nlocal; ++iw_l)
435 for(
int iw_r=0; iw_r<
PARAM.globalv.nlocal; ++iw_r)
437 this->
exx_matrix[ik][iw_l][iw_r] = -fourpi_div_omega * this->
sum1[iw_l *
PARAM.globalv.nlocal + iw_r] * spin_fac;
442 this->
exx_matrix[ik][iw_l][iw_r] += spin_fac * (fourpi_div_omega * this->
sum3[iw_l][iw_r] * sum2_factor_g);
451template <
typename T,
typename Device>
457 Treal exx_energy_tmp = 0.0;
459 for(
int ik=0; ik<this->
k_pack->kv_ptr->get_nks(); ++ik) {
460 for(
int iw_l=0; iw_l<
PARAM.globalv.nlocal; ++iw_l) {
461 for(
int iw_r=0; iw_r<
PARAM.globalv.nlocal; ++iw_r) {
462 for(
int ib=0; ib<
PARAM.inp.nbands; ++ib) {
463 exx_energy_tmp += (this->
exx_matrix[ik][iw_l][iw_r] * std::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);
466 MPI_Allreduce( &exx_energy_tmp, &this->
exx_energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
473template <
typename T,
typename Device>
476 if (
PARAM.inp.out_chg[0] == 0)
485 const std::string exx_q_pack =
"exx_q_pack/";
486 const std::string dir_path =
PARAM.globalv.global_out_dir + exx_q_pack;
488 int ret = mkdir(dir_path.c_str(), 0755);
489 assert(ret == 0 || errno == EEXIST);
491 const std::string kpoint_dest = dir_path +
PARAM.inp.kpoint_file;
493 if (stat(kpoint_dest.c_str(), &st) != 0)
495 std::ifstream src(
PARAM.inp.kpoint_file, std::ios::binary);
496 std::ofstream dst(kpoint_dest, std::ios::binary);
501 std::stringstream ss_wf_wg;
503 std::ofstream ofs_wf_wg(ss_wf_wg.str().c_str());
504 for(
int iq = 0; iq < this->
q_pack->kv_ptr->get_nks(); ++iq)
506 for(
int ib=0; ib<
PARAM.inp.nbands; ++ib)
508 ofs_wf_wg<<this->
q_pack->wf_wg(iq,ib)<<
"\t";
510 ofs_wf_wg<<std::endl;
514 std::stringstream ss_hvec;
516 std::ofstream ofs_hvec(ss_hvec.str().c_str());
517 for(
int iq=0; iq<this->
q_pack->kv_ptr->get_nks(); ++iq)
519 for(
int iw=0; iw<
PARAM.globalv.nlocal; ++iw)
521 for(
int ib=0; ib<
PARAM.inp.nbands; ++ib)
523 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:69
std::vector< T > b
Definition exx_lip.h:91
std::vector< std::vector< T > > phi
Definition exx_lip.h:87
int iq_vecik
Definition exx_lip.h:85
const UnitCell * ucell_ptr
Definition exx_lip.h:116
struct Exx_Lip::k_package * q_pack
struct Exx_Lip::k_package * k_pack
const Exx_Info_Lip & info
Definition exx_lip.h:34
void sum_all(const int ik)
Definition exx_lip.hpp:418
void b_sum(const int iq, const int ib)
Definition exx_lip.hpp:401
void cal_exx()
Definition exx_lip.hpp:32
Treal exx_energy
Definition exx_lip.h:97
const ModulePW::PW_Basis_K * wfc_basis
Definition exx_lip.h:114
Exx_Lip(const Exx_Info_Lip &info_in)
void write_q_pack() const
Definition exx_lip.hpp:474
const T two_pi_i
Definition exx_lip.h:111
void exx_energy_cal()
Definition exx_lip.hpp:452
~Exx_Lip()
Definition exx_lip.hpp:166
std::vector< Treal > recip_qkg2
Definition exx_lip.h:89
void qkg2_exp(const int ik, const int iq)
Definition exx_lip.hpp:314
typename GetTypeReal< T >::type Treal
Definition exx_lip.h:29
std::vector< std::vector< std::vector< T > > > exx_matrix
Definition exx_lip.h:96
void phi_cal(k_package *kq_pack, const int ikq)
Definition exx_lip.hpp:204
std::vector< T > sum1
Definition exx_lip.h:93
void wf_wg_cal()
Definition exx_lip.hpp:186
std::vector< std::vector< T > > sum3
Definition exx_lip.h:94
void judge_singularity(const int ik)
Definition exx_lip.hpp:290
std::vector< T > b0
Definition exx_lip.h:92
void sum3_cal(const int iq, const int ib)
Definition exx_lip.hpp:389
Treal sum2_factor
Definition exx_lip.h:90
void b_cal(const int ik, int iq, const int ib)
Definition exx_lip.hpp:345
void psi_cal()
Definition exx_lip.hpp:233
const ModulePW::PW_Basis * rho_basis
Definition exx_lip.h:113
Class for k-points management.
Definition klist.h:20
3 elements vector
Definition vector3.h:21
T x
Definition vector3.h:23
T y
Definition vector3.h:24
T z
Definition vector3.h:25
static void start(void)
Start total time calculation.
Definition timer.cpp:44
static void end(const std::string &class_name_in, const std::string &name_in)
Definition timer.cpp:109
std::vector< ModuleBase::Vector3< double > > kvec_d
Direct coordinates of the points.
Definition reciprocal_grid.h:57
std::vector< int > ngk
Number of plane waves for each point (filled by the PW basis).
Definition reciprocal_grid.h:63
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:56
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition elecstate.h:20
#define T
Definition exp.cpp:237
This is a wrapper of some LAPACK routines. Row-Major version.
@ Erfc
Definition coulomb_config.h:19
@ Ccp
Definition coulomb_config.h:17
@ Hf
Definition coulomb_config.h:18
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
Definition diag_lcao.h:14
MPI_Comm POOL_WORLD
Definition parallel_comm.cpp:6
Parameter PARAM
Definition parameter.cpp:3
Definition exx_info_lip.h:7
K_Vectors * kv_ptr
Definition exx_lip.h:74
psi::Psi< T, Device > * psi_local
NAOs in PW.
Definition exx_lip.h:77