55#include " module_hamilt_pw/hamilt_pwdft/global.h"
66#include " module_elecstate/module_charge/symmetry_rho.h"
77#include " module_parameter/parameter.h"
8+ #include " module_elecstate/kernels/elecstate_op.h"
89
910void ModuleIO::read_wfc_to_rho (const ModulePW::PW_Basis_K* pw_wfc,
1011 ModuleSymmetry::Symmetry& symm,
@@ -21,14 +22,14 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc,
2122 const int nbands = GlobalV::NBANDS;
2223 const int nspin = PARAM.inp .nspin ;
2324
24- const int npwk_max = pw_wfc->npwk_max ;
25+ const int ng_npol = pw_wfc->npwk_max * PARAM. globalv . npol ;
2526 const int nrxx = pw_wfc->nrxx ;
2627 for (int is = 0 ; is < nspin; ++is)
2728 {
2829 ModuleBase::GlobalFunc::ZEROS (chg.rho [is], nrxx);
2930 }
3031
31- ModuleBase::ComplexMatrix wfc_tmp (nbands, npwk_max );
32+ ModuleBase::ComplexMatrix wfc_tmp (nbands, ng_npol );
3233 std::vector<std::complex <double >> rho_tmp (nrxx);
3334
3435 // read occupation numbers
@@ -78,21 +79,44 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc,
7879 std::stringstream filename;
7980 filename << PARAM.globalv .global_readin_dir << " WAVEFUNC" << ikstot + 1 << " .dat" ;
8081 ModuleIO::read_wfc_pw (filename.str (), pw_wfc, ik, nkstot, wfc_tmp);
81- for ( int ib = 0 ; ib < nbands; ++ib )
82+ if (PARAM. inp . nspin == 4 )
8283 {
83- const std::complex <double >* wfc_ib = wfc_tmp.c + ib * npwk_max;
84- pw_wfc->recip2real (wfc_ib, rho_tmp.data (), ik);
85-
86- const double w1 = wg_tmp (ikstot, ib) / pw_wfc->omega ;
84+ std::vector<std::complex <double >> rho_tmp2 (nrxx);
85+ for (int ib = 0 ; ib < nbands; ++ib)
86+ {
87+ const std::complex <double >* wfc_ib = wfc_tmp.c + ib * ng_npol;
88+ const std::complex <double >* wfc_ib2 = wfc_tmp.c + ib * ng_npol + ng_npol / 2 ;
89+ pw_wfc->recip2real (wfc_ib, rho_tmp.data (), ik);
90+ pw_wfc->recip2real (wfc_ib2, rho_tmp2.data (), ik);
91+ const double w1 = wg_tmp (ikstot, ib) / pw_wfc->omega ;
8792
88- if (w1 != 0.0 )
93+ if (w1 != 0.0 )
94+ {
95+ base_device::DEVICE_CPU* ctx = nullptr ;
96+ elecstate::elecstate_pw_op<double , base_device::DEVICE_CPU>()(ctx,
97+ PARAM.globalv .domag ,
98+ PARAM.globalv .domag_z ,
99+ nrxx,
100+ w1,
101+ chg.rho ,
102+ rho_tmp.data (),
103+ rho_tmp2.data ());
104+ }
105+ }
106+ }
107+ else
108+ {
109+ for (int ib = 0 ; ib < nbands; ++ib)
89110 {
90- #ifdef _OPENMP
91- #pragma omp parallel for
92- #endif
93- for (int ir = 0 ; ir < nrxx; ir++)
111+ const std::complex <double >* wfc_ib = wfc_tmp.c + ib * ng_npol;
112+ pw_wfc->recip2real (wfc_ib, rho_tmp.data (), ik);
113+
114+ const double w1 = wg_tmp (ikstot, ib) / pw_wfc->omega ;
115+
116+ if (w1 != 0.0 )
94117 {
95- chg.rho [is][ir] += w1 * std::norm (rho_tmp[ir]);
118+ base_device::DEVICE_CPU* ctx = nullptr ;
119+ elecstate::elecstate_pw_op<double , base_device::DEVICE_CPU>()(ctx, is, nrxx, w1, chg.rho , rho_tmp.data ());
96120 }
97121 }
98122 }
0 commit comments