@@ -16,7 +16,7 @@ const double* ElecState::getRho(int spin) const
1616 return &(this ->charge ->rho [spin][0 ]);
1717}
1818
19- void ElecState::calculate_weights (void )
19+ void ElecState::calculate_weights ()
2020{
2121 ModuleBase::TITLE (" ElecState" , " calculate_weights" );
2222
@@ -30,6 +30,7 @@ void ElecState::calculate_weights(void)
3030 ekb_tmp[i] = &(this ->ekb (i, 0 ));
3131 }
3232 int nbands = this ->ekb .nc ;
33+ int nks = this ->ekb .nr ;
3334
3435 if (GlobalV::KS_SOLVER == " selinv" )
3536 {
@@ -41,46 +42,46 @@ void ElecState::calculate_weights(void)
4142 {
4243 if (GlobalV::TWO_EFERMI)
4344 {
44- Occupy::iweights (GlobalC::kv. nks ,
45- GlobalC::kv. wk ,
45+ Occupy::iweights (nks,
46+ this -> klist -> wk ,
4647 nbands,
4748 GlobalC::ucell.magnet .get_nelup (),
4849 ekb_tmp,
4950 GlobalC::en.ef_up ,
5051 this ->wg ,
5152 0 ,
52- GlobalC::kv. isk );
53- Occupy::iweights (GlobalC::kv. nks ,
54- GlobalC::kv. wk ,
53+ this -> klist -> isk );
54+ Occupy::iweights (nks,
55+ this -> klist -> wk ,
5556 nbands,
5657 GlobalC::ucell.magnet .get_neldw (),
5758 ekb_tmp,
5859 GlobalC::en.ef_dw ,
5960 this ->wg ,
6061 1 ,
61- GlobalC::kv. isk );
62+ this -> klist -> isk );
6263 // ef = ( ef_up + ef_dw ) / 2.0_dp need??? mohan add 2012-04-16
6364 }
6465 else
6566 {
6667 // -1 means don't need to consider spin.
67- Occupy::iweights (GlobalC::kv. nks ,
68- GlobalC::kv. wk ,
68+ Occupy::iweights (nks,
69+ this -> klist -> wk ,
6970 nbands,
70- GlobalC::CHR. nelec ,
71+ this -> charge -> nelec ,
7172 ekb_tmp,
7273 this ->ef ,
7374 this ->wg ,
7475 -1 ,
75- GlobalC::kv. isk );
76+ this -> klist -> isk );
7677 }
7778 }
7879 else if (Occupy::use_tetrahedron_method)
7980 {
8081 ModuleBase::WARNING_QUIT (" calculate_weights" , " not implemented yet,coming soon!" );
8182 // if(my_rank == 0)
8283 // {
83- // tweights(GlobalC::kv.nkstot, nspin, nbands, GlobalC::CHR. nelec, ntetra,tetra, GlobalC::wf.et,
84+ // tweights(GlobalC::kv.nkstot, nspin, nbands, this->charge-> nelec, ntetra,tetra, GlobalC::wf.et,
8485 // this->ef, this->wg);
8586 // }
8687 }
@@ -90,8 +91,8 @@ void ElecState::calculate_weights(void)
9091 {
9192 double demet_up = 0.0 ;
9293 double demet_dw = 0.0 ;
93- Occupy::gweights (GlobalC::kv. nks ,
94- GlobalC::kv. wk ,
94+ Occupy::gweights (nks,
95+ this -> klist -> wk ,
9596 nbands,
9697 GlobalC::ucell.magnet .get_nelup (),
9798 Occupy::gaussian_parameter,
@@ -101,9 +102,9 @@ void ElecState::calculate_weights(void)
101102 demet_up,
102103 this ->wg ,
103104 0 ,
104- GlobalC::kv. isk );
105- Occupy::gweights (GlobalC::kv. nks ,
106- GlobalC::kv. wk ,
105+ this -> klist -> isk );
106+ Occupy::gweights (nks,
107+ this -> klist -> wk ,
107108 nbands,
108109 GlobalC::ucell.magnet .get_neldw (),
109110 Occupy::gaussian_parameter,
@@ -113,35 +114,35 @@ void ElecState::calculate_weights(void)
113114 demet_dw,
114115 this ->wg ,
115116 1 ,
116- GlobalC::kv. isk );
117- GlobalC::en. demet = demet_up + demet_dw;
117+ this -> klist -> isk );
118+ this -> demet = demet_up + demet_dw;
118119 }
119120 else
120121 {
121122 // -1 means is no related to spin.
122- Occupy::gweights (GlobalC::kv. nks ,
123- GlobalC::kv. wk ,
123+ Occupy::gweights (nks,
124+ this -> klist -> wk ,
124125 nbands,
125- GlobalC::CHR. nelec ,
126+ this -> charge -> nelec ,
126127 Occupy::gaussian_parameter,
127128 Occupy::gaussian_type,
128129 ekb_tmp,
129130 this ->ef ,
130- GlobalC::en. demet ,
131+ this -> demet ,
131132 this ->wg ,
132133 -1 ,
133- GlobalC::kv. isk );
134+ this -> klist -> isk );
134135 }
135136
136137 // qianrui fix a bug on 2021-7-21
137- Parallel_Reduce::reduce_double_allpool (GlobalC::en. demet );
138+ Parallel_Reduce::reduce_double_allpool (this -> demet );
138139 }
139140 else if (Occupy::fixed_occupations)
140141 {
141142 // fix occupations need nelup and neldw.
142143 // mohan add 2011-04-03
143144 this ->ef = -1.0e+20 ;
144- for (int ik = 0 ; ik < GlobalC::kv. nks ; ik++)
145+ for (int ik = 0 ; ik < nks; ik++)
145146 {
146147 for (int ibnd = 0 ; ibnd < nbands; ibnd++)
147148 {
@@ -162,7 +163,7 @@ void ElecState::calculate_weights(void)
162163 {
163164 double ebotom = ekb_tmp[0 ][0 ];
164165 double etop = ekb_tmp[0 ][0 ];
165- for (int ik = 0 ; ik < GlobalC::kv. nks ; ik++)
166+ for (int ik = 0 ; ik < nks; ik++)
166167 {
167168 for (int ib = 0 ; ib < nbands; ib++)
168169 {
@@ -188,15 +189,27 @@ void ElecState::calculate_weights(void)
188189 return ;
189190}
190191
191- double ElecState::eBandK ( const int & ik )
192+ void ElecState::calEBand ( )
192193{
193- ModuleBase::TITLE (" ElecStatePW" , " eBandK" );
194- double eband_k = 0.0 ;
195- for (int ibnd = 0 ; ibnd < this ->ekb .nc ; ibnd++)
194+ ModuleBase::TITLE (" ElecStatePW" , " calEBand" );
195+ // calculate ebands using wg and ekb
196+ this ->eband = 0.0 ;
197+ for (int ik = 0 ; ik < this ->ekb .nr ; ++ik)
196198 {
197- eband_k += this ->ekb (ik, ibnd) * this ->wg (ik, ibnd);
199+ for (int ibnd = 0 ; ibnd < this ->ekb .nc ; ibnd++)
200+ {
201+ this ->eband += this ->ekb (ik, ibnd) * this ->wg (ik, ibnd);
202+ }
198203 }
199- return eband_k;
204+ if (GlobalV::KPAR != 1 )
205+ {
206+ // ==================================
207+ // Reduce all the Energy in each cpu
208+ // ==================================
209+ this ->eband /= GlobalV::NPROC_IN_POOL;
210+ Parallel_Reduce::reduce_double_all (this ->eband );
211+ }
212+ return ;
200213}
201214
202215void ElecState::print_band (const int & ik, const int & printe, const int & iter)
0 commit comments