ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
exx_lip.hpp
Go to the documentation of this file.
1//==========================================================
2// AUTHOR : Peize Lin
3
4// DATE : 2015-03-10
5//==========================================================
6
7#ifndef EXX_LIP_HPP
8#define EXX_LIP_HPP
9
10#include "exx_lip.h"
11#include "source_base/vector3.h"
13#include "source_base/vector3.h"
15#include "source_cell/klist.h"
23#include "source_psi/psi_init.h"
26#include "source_base/timer.h"
27
28#include <limits>
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <unistd.h>
32#include <cerrno>
33
34template <typename T, typename Device>
36{
37 ModuleBase::TITLE("Exx_Lip", "cal_exx");
38 ModuleBase::timer::tick("Exx_Lip", "cal_exx");
39
40 this->wf_wg_cal();
41 this->psi_cal();
42 for (int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik)
43 {
44 this->phi_cal(this->k_pack, ik);
45
46 this->judge_singularity(ik);
47 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) {
48 for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) {
49 this->sum1[iw_l * PARAM.globalv.nlocal + iw_r] = T(0.0);
50 } }
51 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type)
52 {
53 this->sum2_factor = 0.0;
54 if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) {
55 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) {
56 for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) {
57 this->sum3[iw_l][iw_r] = T(0.0);
58 } } }
59 }
60
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) // !!! k_point
62 // parallel incompleted.need to loop iq in other pool
63 {
64 const int iq =
65 (ik < (this->k_pack->kv_ptr->get_nks() / PARAM.inp.nspin))
66 ? (iq_tmp % (this->q_pack->kv_ptr->get_nks() / PARAM.inp.nspin))
67 : (iq_tmp % (this->q_pack->kv_ptr->get_nks() / PARAM.inp.nspin) + (this->q_pack->kv_ptr->get_nks() / PARAM.inp.nspin));
68 this->qkg2_exp(ik, iq);
69 for (int ib = 0; ib < PARAM.inp.nbands; ++ib)
70 {
71 this->b_cal(ik, iq, ib);
72 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type) {
73 if (iq == this->iq_vecik) {
74 this->sum3_cal(iq, ib);
75 } }
76 this->b_sum(iq, ib);
77 }
78 }
79 this->sum_all(ik);
80 }
81 this->exx_energy_cal();
82
83 ModuleBase::timer::tick("Exx_Lip", "cal_exx");
84}
85
86template <typename T, typename Device>
88 const ModuleSymmetry::Symmetry& symm,
89 K_Vectors* kv_ptr_in,
90 psi::Psi<T, Device>* psi_local_in,
91 psi::Psi<T, Device>* kspw_psi_ptr_in,
92 const ModulePW::PW_Basis_K* wfc_basis_in,
93 const ModulePW::PW_Basis* rho_basis_in,
94 const Structure_Factor& sf,
95 const UnitCell* ucell_ptr_in,
96 const elecstate::ElecState* pelec_in)
97 : info(info_in)
98{
99 ModuleBase::TITLE("Exx_Lip", "init");
100 ModuleBase::timer::tick("Exx_Lip", "init");
101
102 this->k_pack = new k_package;
103 this->k_pack->kv_ptr = kv_ptr_in;
104 this->k_pack->psi_local = psi_local_in;
105 this->k_pack->pelec = pelec_in;
106 this->k_pack->kspw_psi_ptr = kspw_psi_ptr_in;
107 this->wfc_basis = wfc_basis_in;
108 this->rho_basis = rho_basis_in;
109 this->ucell_ptr = ucell_ptr_in;
110
111 int gzero_judge = -1;
112 if (this->rho_basis->gg_uniq[0] < 1e-8)
113 { gzero_judge = GlobalV::RANK_IN_POOL; }
114 #ifdef __MPI
115 MPI_Allreduce(&gzero_judge, &gzero_rank_in_pool, 1, MPI_INT, MPI_MAX, POOL_WORLD);
116 #endif
118
119 this->k_pack->hvec_array = new psi::Psi<T, Device>(this->k_pack->kv_ptr->get_nks(), PARAM.inp.nbands, PARAM.globalv.nlocal, kv_ptr_in->ngk, true);
120 // this->k_pack->hvec_array = new ModuleBase::ComplexMatrix[this->k_pack->kv_ptr->get_nks()];
121 // for( int ik=0; ik<this->k_pack->kv_ptr->get_nks(); ++ik)
122 // {
123 // this->k_pack->hvec_array[ik].create(PARAM.globalv.nlocal,PARAM.inp.nbands);
124 // }
125
126 // if (PARAM.inp.init_chg=="atomic")
127 {
128 this->q_pack = this->k_pack;
129 }
130 // else if(PARAM.inp.init_chg=="file")
131 // {
132 // read_q_pack(symm, this->wfc_basis, sf);
133 // }
134
135 this->phi.resize(PARAM.globalv.nlocal);
136 for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw)
137 { this->phi[iw].resize(this->rho_basis->nrxx); }
138
139 this->psi.resize(this->q_pack->kv_ptr->get_nks());
140 for (int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
141 {
142 this->psi[iq].resize(PARAM.inp.nbands);
143 for (int ib = 0; ib < PARAM.inp.nbands; ++ib)
144 { this->psi[iq][ib].resize(this->rho_basis->nrxx); }
145 }
146
147 this->recip_qkg2.resize(this->rho_basis->npw);
148
149 this->b.resize(PARAM.globalv.nlocal * this->rho_basis->npw);
150
151 this->sum1.resize(PARAM.globalv.nlocal * PARAM.globalv.nlocal);
152
154 {
156 {
157 this->b0.resize(PARAM.globalv.nlocal);
158 this->sum3.resize(PARAM.globalv.nlocal);
159 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l)
160 { this->sum3[iw_l].resize(PARAM.globalv.nlocal); }
161 }
162 }
163
164 this->exx_matrix.resize(this->k_pack->kv_ptr->get_nks());
165 for (int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik)
166 {
167 this->exx_matrix[ik].resize(PARAM.globalv.nlocal);
168 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l)
169 { this->exx_matrix[ik][iw_l].resize(PARAM.globalv.nlocal); }
170 }
171
172 ModuleBase::timer::tick("Exx_Lip", "init");
173}
174
175template <typename T, typename Device>
177{
178 if (this->k_pack)
179 { delete this->k_pack->hvec_array; this->k_pack->hvec_array = nullptr; }
180 delete this->k_pack; this->k_pack = nullptr;
181
182 if (PARAM.inp.init_chg == "atomic")
183 {
184 this->q_pack = nullptr;
185 }
186 else if (PARAM.inp.init_chg == "file")
187 {
188 delete this->q_pack->kv_ptr; this->q_pack->kv_ptr = nullptr;
189 // delete this->q_pack->wf_ptr; this->q_pack->wf_ptr = nullptr;
190 // delete[] this->q_pack->hvec_array; this->q_pack->hvec_array=nullptr;
191 delete this->q_pack; this->q_pack = nullptr;
192 }
193}
194
195template <typename T, typename Device>
197{
198 ModuleBase::TITLE("Exx_Lip", "wf_wg_cal");
199 ModuleBase::timer::tick("Exx_Lip", "wf_wg_cal");
200 if (PARAM.inp.nspin == 1) {
201 for (int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
202 for (int ib = 0; ib < PARAM.inp.nbands; ++ib) {
203 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib) / 2;
204 } } }
205 else if (PARAM.inp.nspin == 2) {
206 for (int ik = 0; ik < this->k_pack->kv_ptr->get_nks(); ++ik) {
207 for (int ib = 0; ib < PARAM.inp.nbands; ++ib) {
208 this->k_pack->wf_wg(ik, ib) = this->k_pack->pelec->wg(ik, ib);
209 } } }
210 ModuleBase::timer::tick("Exx_Lip", "wf_wg_cal");
211}
212
213template <typename T, typename Device>
214void Exx_Lip<T, Device>::phi_cal(k_package* kq_pack, const int ikq)
215{
216 ModuleBase::timer::tick("Exx_Lip", "phi_cal");
217 std::vector<T> porter (this->wfc_basis->nrxx);
218 for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw)
219 {
220 // this->wfc_basis->recip2real(&kq_pack->wf_ptr->wanf2[ikq](iw,0), porter.data(), ikq);
221 this->wfc_basis->recip2real(&(kq_pack->psi_local->operator()(ikq, iw, 0)), porter.data(), ikq);
222 int ir = 0;
223 for (int ix = 0; ix < this->rho_basis->nx; ++ix)
224 {
225 const Treal phase_x = kq_pack->kv_ptr->kvec_d[ikq].x * ix / this->rho_basis->nx;
226 for (int iy = 0; iy < this->rho_basis->ny; ++iy)
227 {
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)
230 {
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;
234 ++ir;
235 }
236 }
237 }
238 }
239 ModuleBase::timer::tick("Exx_Lip", "phi_cal");
240}
241
242template <typename T, typename Device>
244{
245 ModuleBase::TITLE("Exx_Lip", "psi_cal");
246 ModuleBase::timer::tick("Exx_Lip", "psi_cal");
247 if (PARAM.inp.init_chg == "atomic")
248 {
249 std::vector<T> porter (this->wfc_basis->nrxx);
250 for (int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
251 {
252 for (int ib = 0; ib < PARAM.inp.nbands; ++ib)
253 {
254 this->wfc_basis->recip2real(&(this->q_pack->kspw_psi_ptr->operator()(iq, ib, 0)), porter.data(), iq);
255
256 int ir = 0;
257 for (int ix = 0; ix < this->rho_basis->nx; ++ix)
258 {
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)
261 {
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)
264 {
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;
268 ++ir;
269 }
270 }
271 }
272 }
273 }
274 }
275 else if (PARAM.inp.init_chg == "file")
276 {
277 for (int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
278 {
279 this->phi_cal(this->q_pack, iq);
280 for (int ib = 0; ib < PARAM.inp.nbands; ++ib)
281 {
282 ModuleBase::GlobalFunc::ZEROS(this->psi[iq][ib].data(), this->rho_basis->nrxx);
283 for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw)
284 {
285 for (int ir = 0; ir < this->rho_basis->nrxx; ++ir)
286 {
287 this->psi[iq][ib][ir] += (*this->q_pack->hvec_array)(iq, ib, iw) * this->phi[iw][ir];
288 }
289 }
290 }
291 }
292 }
294 // !!! k_point parallel incompleted. need to loop iq in other pool
296 ModuleBase::timer::tick("Exx_Lip", "psi_cal");
297}
298
299template <typename T, typename Device>
301{
302 ModuleBase::timer::tick("Exx_Lip", "judge_singularity");
303 if (PARAM.inp.init_chg=="atomic")
304 {
305 this->iq_vecik = ik;
306 }
307 else if(PARAM.inp.init_chg=="file")
308 {
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)
311 {
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)
314 {
315 min_q_minus_k = q_minus_k;
316 this->iq_vecik = iq;
317 }
318 }
319 }
320 ModuleBase::timer::tick("Exx_Lip", "judge_singularity");
321}
322
323template <typename T, typename Device>
324void Exx_Lip<T, Device>::qkg2_exp(const int ik, const int iq)
325{
326 ModuleBase::timer::tick("Exx_Lip", "qkg2_exp");
327 for( int ig=0; ig<this->rho_basis->npw; ++ig)
328 {
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();
330 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type)
331 {
332 if (std::abs(qkg2) < 1e-10)
333 { this->recip_qkg2[ig] = 0.0; } // 0 to ignore bb/qkg2 when qkg2==0
334 else
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]);
338 }
339 else if (Conv_Coulomb_Pot_K::Ccp_Type::Erfc == info.ccp_type)
340 {
341 if (std::abs(qkg2) < 1e-10)
342 { this->recip_qkg2[ig] = 1.0 / (2 * info.hse_omega); }
343 else
344 { this->recip_qkg2[ig] = sqrt((1 - std::exp(-qkg2 / (4 * info.hse_omega * info.hse_omega))) / qkg2); }
345 }
346 else
347 {
348 throw( std::string(__FILE__) + " line " + std::to_string(__LINE__) );
349 }
350 }
351 ModuleBase::timer::tick("Exx_Lip", "qkg2_exp");
352}
353
354template <typename T, typename Device>
355void Exx_Lip<T, Device>::b_cal(const int ik, const int iq, const int ib)
356{
357 ModuleBase::timer::tick("Exx_Lip", "b_cal");
358 const ModuleBase::Vector3<double> q_minus_k = this->q_pack->kv_ptr->kvec_d[iq] - this->k_pack->kv_ptr->kvec_d[ik];
359 std::vector<T > mul_tmp(this->rho_basis->nrxx);
360 for( size_t ir=0,ix=0; ix<this->rho_basis->nx; ++ix)
361 {
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)
364 {
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)
367 {
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];
371 ++ir;
372 }
373 }
374 }
375
376 std::vector<T> porter (this->rho_basis->nrxx);
377 for(size_t iw=0; iw< PARAM.globalv.nlocal; ++iw)
378 {
379 auto& phi_w = this->phi[iw];
380 for( size_t ir=0; ir<this->rho_basis->nrxx; ++ir)
381 {
382 porter[ir] = conj(phi_w[ir]) * mul_tmp[ir] ;
383 // porter[ir] = phi_w[ir] * psi_q_b[ir] *exp_tmp[ir] ;
384 }
385 T* const b_w = &this->b[iw * this->rho_basis->npw];
386 this->rho_basis->real2recip( porter.data(), b_w);
387 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type) {
388 if ((iq == this->iq_vecik) && (gzero_rank_in_pool == GlobalV::RANK_IN_POOL)) {
389 this->b0[iw] = b_w[this->rho_basis->ig_gge0];
390 } }
391
392 for (size_t ig = 0; ig < this->rho_basis->npw; ++ig)
393 { b_w[ig] *= this->recip_qkg2[ig]; }
394 }
395 ModuleBase::timer::tick("Exx_Lip", "b_cal");
396}
397
398template <typename T, typename Device>
399void Exx_Lip<T, Device>::sum3_cal(const int iq, const int ib)
400{
401 ModuleBase::timer::tick("Exx_Lip", "sum3_cal");
402 if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) {
403 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) {
404 for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) {
405 this->sum3[iw_l][iw_r] += this->b0[iw_l] * conj(this->b0[iw_r]) * (Treal)this->q_pack->wf_wg(iq, ib);
406 } } }
407 ModuleBase::timer::tick("Exx_Lip", "sum3_cal");
408}
409
410template <typename T, typename Device>
411void Exx_Lip<T, Device>::b_sum(const int iq, const int ib) // Peize Lin change 2019-04-14
412{
413 ModuleBase::timer::tick("Exx_Lip", "b_sum");
414 // this->sum1[iw_l,iw_r] += \sum_{ig} this->b[iw_l,ig] * conj(this->b[iw_r,ig]) * this->q_pack->wf_wg(iq,ib)
415 LapackConnector::herk(
416 'U','N',
417 PARAM.globalv.nlocal, this->rho_basis->npw,
418 (Treal)this->q_pack->wf_wg(iq, ib), this->b.data(), this->rho_basis->npw,
419 1.0, this->sum1.data(), PARAM.globalv.nlocal);
420 // cblas_zherk( CblasRowMajor, CblasUpper, CblasNoTrans,
421 // PARAM.globalv.nlocal, this->rho_basis->npw,
422 // this->q_pack->wf_wg(iq,ib), static_cast<void*>(this->b), this->rho_basis->npw,
423 // 1.0, static_cast<void*>(this->sum1), PARAM.globalv.nlocal);
424 ModuleBase::timer::tick("Exx_Lip", "b_sum");
425}
426
427template <typename T, typename Device>
429{
430 ModuleBase::timer::tick("Exx_Lip", "sum_all");
431 Treal sum2_factor_g = 0.0;
432 const Treal fourpi_div_omega = 4 * (Treal)(ModuleBase::PI / this->ucell_ptr->omega);
433 const Treal spin_fac = 2.0;
434 #ifdef __MPI
435 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type)
436 { MPI_Reduce(&this->sum2_factor, &sum2_factor_g, 1, MPI_DOUBLE, MPI_SUM, gzero_rank_in_pool, POOL_WORLD); }
437 #endif
438 for (size_t iw_l = 1; iw_l < PARAM.globalv.nlocal; ++iw_l) {
439 for (size_t iw_r = 0; iw_r < iw_l; ++iw_r) {
440 this->sum1[iw_l * PARAM.globalv.nlocal + iw_r] = conj(this->sum1[iw_r * PARAM.globalv.nlocal + iw_l]); // Peize Lin add conj 2019-04-14
441 } }
442
443 for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l)
444 {
445 for( int iw_r=0; iw_r<PARAM.globalv.nlocal; ++iw_r)
446 {
447 this->exx_matrix[ik][iw_l][iw_r] = -fourpi_div_omega * this->sum1[iw_l * PARAM.globalv.nlocal + iw_r] * spin_fac;
448 if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type)
449 {
450 if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL)
451 {
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]);
454 }
455 }
456 }
457 }
458 ModuleBase::timer::tick("Exx_Lip", "sum_all");
459}
460
461template <typename T, typename Device>
463{
464 ModuleBase::TITLE("Exx_Lip","exx_energy_cal");
465 ModuleBase::timer::tick("Exx_Lip", "exx_energy_cal");
466
467 Treal exx_energy_tmp = 0.0;
468
469 for( int ik=0; ik<this->k_pack->kv_ptr->get_nks(); ++ik) {
470 for( int iw_l=0; iw_l<PARAM.globalv.nlocal; ++iw_l) {
471 for( int iw_r=0; iw_r<PARAM.globalv.nlocal; ++iw_r) {
472 for( int ib=0; ib<PARAM.inp.nbands; ++ib) {
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);
474 } } } }
475 #ifdef __MPI
476 MPI_Allreduce( &exx_energy_tmp, &this->exx_energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); // !!! k_point parallel incompleted. different pools have different kv.set_nks(>) deadlock
477 #endif
478 this->exx_energy *= (PARAM.inp.nspin==1) ? 2 : 1;
479 this->exx_energy /= 2; // ETOT = E_band - 1/2 E_exx
480 ModuleBase::timer::tick("Exx_Lip", "exx_energy_cal");
481}
482
483template <typename T, typename Device>
485{
486 ModuleBase::timer::tick("Exx_Lip", "write_q_pack");
487
488 if (PARAM.inp.out_chg[0] == 0)
489 { return; }
490
492 {
493 const std::string exx_q_pack = "exx_q_pack/";
494 const std::string dir_path = PARAM.globalv.global_out_dir + exx_q_pack;
495
496 int ret = mkdir(dir_path.c_str(), 0755);
497 assert(ret == 0 || errno == EEXIST);
498
499 const std::string kpoint_dest = dir_path + PARAM.inp.kpoint_file;
500 struct stat st;
501 if (stat(kpoint_dest.c_str(), &st) != 0)
502 {
503 std::ifstream src(PARAM.inp.kpoint_file, std::ios::binary);
504 std::ofstream dst(kpoint_dest, std::ios::binary);
505 dst << src.rdbuf();
506 assert(dst.good());
507 }
508
509 std::stringstream ss_wf_wg;
510 ss_wf_wg << PARAM.globalv.global_out_dir << exx_q_pack << "wf_wg_" << GlobalV::MY_POOL;
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)
513 {
514 for( int ib=0; ib<PARAM.inp.nbands; ++ib)
515 {
516 ofs_wf_wg<<this->q_pack->wf_wg(iq,ib)<<"\t";
517 }
518 ofs_wf_wg<<std::endl;
519 }
520 ofs_wf_wg.close();
521
522 std::stringstream ss_hvec;
523 ss_hvec << PARAM.globalv.global_out_dir << exx_q_pack << "hvec_" << GlobalV::MY_POOL;
524 std::ofstream ofs_hvec(ss_hvec.str().c_str());
525 for( int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
526 {
527 for( int iw=0; iw<PARAM.globalv.nlocal; ++iw)
528 {
529 for( int ib=0; ib<PARAM.inp.nbands; ++ib)
530 {
531 ofs_hvec << (*this->q_pack->hvec_array)(iq, ib, iw).real() << " " << (*this->q_pack->hvec_array)(iq, ib, iw).imag() << " ";
532 }
533 ofs_hvec<<std::endl;
534 }
535 }
536 ofs_hvec.close();
537 }
538 ModuleBase::timer::tick("Exx_Lip", "write_q_pack");
539}
540
541/*
542void Exx_Lip::read_q_pack(const ModuleSymmetry::Symmetry& symm,
543 const ModulePW::PW_Basis_K* this->wfc_basis,
544 const Structure_Factor& sf)
545{
546 const std::string exx_q_pack = "exx_q_pack/";
547 this->q_pack = new k_package();
548 this->q_pack->kv_ptr = new K_Vectors();
549 const std::string exx_kpoint_card = PARAM.globalv.global_out_dir + exx_q_pack + PARAM.inp.kpoint_file;
550 this->q_pack->kv_ptr->set( symm, exx_kpoint_card, PARAM.inp.nspin, this->ucell_ptr->G, this->ucell_ptr->latvec, GlobalV::ofs_running );
551 this->q_pack->wf_ptr = new wavefunc();
552 this->q_pack->wf_ptr->allocate(this->q_pack->kv_ptr->get_nkstot(),
553 this->q_pack->kv_ptr->get_nks(),
554 this->q_pack->kv_ptr->ngk.data(),
555 this->wfc_basis->npwk_max); // mohan update 2021-02-25
556 // this->q_pack->wf_ptr->init(this->q_pack->kv_ptr->get_nks(),this->q_pack->kv_ptr,this->ucell_ptr,old_pwptr,&ppcell,&GlobalC::ORB,&hm,&Pkpoints);
557 this->q_pack->wf_ptr->table_local.create(ucell.ntype, ucell.nmax_total, PARAM.globalv.nqx);
558 // this->q_pack->wf_ptr->table_local.create(this->q_pack->wf_ptr->this->ucell_ptr->ntype, this->q_pack->wf_ptr->this->ucell_ptr->nmax_total, PARAM.globalv.nqx);
559 #ifdef __LCAO
560 Wavefunc_in_pw::make_table_q(GlobalC::ORB.orbital_file, this->q_pack->wf_ptr->table_local);
561 // Wavefunc_in_pw::make_table_q(this->q_pack->wf_ptr->ORB_ptr->orbital_file, this->q_pack->wf_ptr->table_local, this->q_pack->wf_ptr);
562 for(int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
563 {
564 Wavefunc_in_pw::produce_local_basis_in_pw(iq,
565 this->wfc_basis,
566 sf,
567 this->q_pack->wf_ptr->wanf2[iq],
568 this->q_pack->wf_ptr->table_local);
569 // Wavefunc_in_pw::produce_local_basis_in_pw(iq, this->q_pack->wf_ptr->wanf2[iq], this->q_pack->wf_ptr->table_local,
570 // this->q_pack->wf_ptr);
571 }
572 #endif
573 this->q_pack->wf_wg.create(this->q_pack->kv_ptr->get_nks(),PARAM.inp.nbands);
574 if(!GlobalV::RANK_IN_POOL)
575 {
576 std::stringstream ss_wf_wg;
577 ss_wf_wg << PARAM.globalv.global_out_dir << exx_q_pack << "wf_wg_" << GlobalV::MY_POOL;
578 std::ifstream ifs_wf_wg(ss_wf_wg.str().c_str());
579 for( int iq = 0; iq < this->q_pack->kv_ptr->get_nks(); ++iq)
580 {
581 for( int ib=0; ib<PARAM.inp.nbands; ++ib)
582 {
583 ifs_wf_wg>>this->q_pack->wf_wg(iq,ib);
584 }
585 }
586 ifs_wf_wg.close();
587 }
588 #ifdef __MPI
589 MPI_Bcast( this->q_pack->wf_wg.c, this->q_pack->kv_ptr->get_nks()*PARAM.inp.nbands, MPI_DOUBLE, 0, POOL_WORLD);
590 #endif
591 this->q_pack->hvec_array = new ModuleBase::ComplexMatrix [this->q_pack->kv_ptr->get_nks()];
592 for( int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
593 {
594 this->q_pack->hvec_array[iq].create(PARAM.globalv.nlocal,PARAM.inp.nbands);
595 }
596 if(!GlobalV::RANK_IN_POOL)
597 {
598 std::stringstream ss_hvec;
599 ss_hvec << PARAM.globalv.global_out_dir << exx_q_pack << "hvec_" << GlobalV::MY_POOL;
600 std::ifstream ifs_hvec(ss_hvec.str().c_str());
601 for( int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
602 {
603 for( int iw=0; iw<PARAM.globalv.nlocal; ++iw)
604 {
605 for( int ib=0; ib<PARAM.inp.nbands; ++ib)
606 {
607 double a,this->b;
608 ifs_hvec>>a>>this->b;
609 this->q_pack->hvec_array[iq](iw,ib) = {a,this->b};
610 }
611 }
612 }
613 ifs_hvec.close();
614 }
615 #ifdef __MPI
616 for( int iq=0; iq<this->q_pack->kv_ptr->get_nks(); ++iq)
617 {
618 MPI_Bcast( this->q_pack->hvec_array[iq].c, PARAM.globalv.nlocal*PARAM.inp.nbands, MPI_DOUBLE_COMPLEX, 0, POOL_WORLD);
619 }
620 #endif
621 return;
622}
623*/
624
625#endif
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
Definition klist.h:13
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
Definition symmetry.h:16
const Input_para & inp
Definition parameter.h:26
const System_para & globalv
Definition parameter.h:30
Definition structure_factor.h:11
Definition unitcell.h:17
Definition elecstate.h:15
Definition psi.h:37
#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
Definition exx_lip.h:23
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
Definition exx_info.h:41
const Conv_Coulomb_Pot_K::Ccp_Type & ccp_type
Definition exx_info.h:42
Definition exx_lip.h:77
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
std::string init_chg
"file","atomic"
Definition input_parameter.h:50
std::vector< int > out_chg
output charge density. 0: no; 1: yes
Definition input_parameter.h:371
int nspin
LDA ; LSDA ; non-linear spin.
Definition input_parameter.h:85
int nbands
number of bands
Definition input_parameter.h:76
std::string kpoint_file
file contains k-points – xiaohui modify 2015-02-01
Definition input_parameter.h:58
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