@@ -110,6 +110,11 @@ void DFTU::cal_occ_pw(const int iter, const void* psi_in, const ModuleBase::matr
110110 const int nbands = psi_p->get_nbands ();
111111 for (int ik = 0 ; ik < psi_p->get_nk (); ik++)
112112 {
113+ int is = 0 ;
114+ if (GlobalV::NSPIN == 2 && ik >= psi_p->get_nk ()/2 )
115+ {
116+ is = 1 ;
117+ }
113118 psi_p->fix_k (ik);
114119 onsite_p->tabulate_atomic (ik);
115120
@@ -133,29 +138,49 @@ void DFTU::cal_occ_pw(const int iter, const void* psi_in, const ModuleBase::matr
133138 const int m_begin = target_l * target_l;
134139 const int tlp1 = 2 * target_l + 1 ;
135140 const int tlp1_2 = tlp1 * tlp1;
136- for ( int ib = 0 ;ib<nbands;ib++ )
141+ if (GlobalV:: NSPIN == 4 )
137142 {
138- const double weight = wg_in (ik, ib);
139- int ind_m1m2 = 0 ;
140- for (int m1 = 0 ; m1 < tlp1; m1++)
143+ for (int ib = 0 ;ib<nbands;ib++)
141144 {
142- const int index_m1 = ib*2 *nkb + begin_ih + m_begin + m1;
143- for (int m2 = 0 ; m2 < tlp1; m2++)
145+ const double weight = wg_in (ik, ib);
146+ int ind_m1m2 = 0 ;
147+ for (int m1 = 0 ; m1 < tlp1; m1++)
144148 {
145- const int index_m2 = ib*2 *nkb + begin_ih + m_begin + m2;
146- std::complex <double > occ[4 ];
147- occ[0 ] = weight * conj (becp[index_m1]) * becp[index_m2];
148- occ[1 ] = weight * conj (becp[index_m1]) * becp[index_m2 + nkb];
149- occ[2 ] = weight * conj (becp[index_m1 + nkb]) * becp[index_m2];
150- occ[3 ] = weight * conj (becp[index_m1 + nkb]) * becp[index_m2 + nkb];
151- this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2] += (occ[0 ] + occ[3 ]).real ();
152- this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + tlp1_2] += (occ[1 ] + occ[2 ]).real ();
153- this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + 2 * tlp1_2] += (occ[1 ] - occ[2 ]).imag ();
154- this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + 3 * tlp1_2] += (occ[0 ] - occ[3 ]).real ();
155- ind_m1m2++;
149+ const int index_m1 = ib*2 *nkb + begin_ih + m_begin + m1;
150+ for (int m2 = 0 ; m2 < tlp1; m2++)
151+ {
152+ const int index_m2 = ib*2 *nkb + begin_ih + m_begin + m2;
153+ std::complex <double > occ[4 ];
154+ occ[0 ] = weight * conj (becp[index_m1]) * becp[index_m2];
155+ occ[1 ] = weight * conj (becp[index_m1]) * becp[index_m2 + nkb];
156+ occ[2 ] = weight * conj (becp[index_m1 + nkb]) * becp[index_m2];
157+ occ[3 ] = weight * conj (becp[index_m1 + nkb]) * becp[index_m2 + nkb];
158+ this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2] += (occ[0 ] + occ[3 ]).real ();
159+ this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + tlp1_2] += (occ[1 ] + occ[2 ]).real ();
160+ this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + 2 * tlp1_2] += (occ[1 ] - occ[2 ]).imag ();
161+ this ->locale [iat][target_l][0 ][0 ].c [ind_m1m2 + 3 * tlp1_2] += (occ[0 ] - occ[3 ]).real ();
162+ ind_m1m2++;
163+ }
156164 }
157- }
158- }// ib
165+ }// ib
166+ }
167+ else {
168+ for (int ib = 0 ;ib<nbands;ib++)
169+ {
170+ const double weight = wg_in (ik, ib);
171+ int ind_m1m2 = 0 ;
172+ for (int m1 = 0 ; m1 < tlp1; m1++)
173+ {
174+ const int index_m1 = ib*nkb + begin_ih + m_begin + m1;
175+ for (int m2 = 0 ; m2 < tlp1; m2++)
176+ {
177+ const int index_m2 = ib*nkb + begin_ih + m_begin + m2;
178+ this ->locale [iat][target_l][0 ][is].c [ind_m1m2] += weight * (conj (becp[index_m1]) * becp[index_m2]).real ();
179+ ind_m1m2++;
180+ }
181+ } // m1
182+ } // ib
183+ }// if NSPIN
159184 begin_ih += nh;
160185 }// iat
161186 }// ik
0 commit comments