@@ -25,6 +25,8 @@ Veff<OperatorPW<T, Device>>::Veff(const int* isk_in,
2525 this ->veff_row = veff_row;
2626 this ->veff_col = veff_col;
2727 this ->wfcpw = wfcpw_in;
28+ resmem_complex_op ()(nspin_4_veff, 4 *veff_col, " Veff<PW>::porter" );
29+ // this->nspin_4_veff=new std::complex<double>[4*veff_row];
2830 resmem_complex_op ()(this ->porter , this ->wfcpw ->nmaxgr , " Veff<PW>::porter" );
2931 resmem_complex_op ()(this ->porter1 , this ->wfcpw ->nmaxgr , " Veff<PW>::porter1" );
3032
@@ -35,6 +37,7 @@ Veff<OperatorPW<T, Device>>::~Veff()
3537{
3638 delmem_complex_op ()(this ->porter );
3739 delmem_complex_op ()(this ->porter1 );
40+ delmem_complex_op ()(this ->nspin_4_veff );
3841}
3942
4043template <typename T, typename Device>
@@ -111,17 +114,26 @@ void Veff<OperatorPW<T, Device>>::act(
111114 }
112115 else if (npol == 2 )
113116 {
114- const Real* current_veff[4 ]={nullptr };
115- for (int is = 0 ; is < 4 ; is++)
117+ const Real* current_veff={nullptr };
118+ const std::complex <Real> imag=std::complex <Real>(0.0 , 1.0 );
119+ for (int ir=0 ; ir < veff_col; ir++)
116120 {
117- current_veff[is] = this ->veff + is * this ->veff_col ;
121+ const int base = 4 *ir;
122+ Real part_1 = this ->veff [ir];
123+ Real part_2 = this ->veff [ir + veff_col];
124+ Real part_3 = this ->veff [ir + 2 *veff_col];
125+ Real part_4 = this ->veff [ir + 3 *veff_col];
126+ nspin_4_veff[base ] = part_1 + part_4;
127+ nspin_4_veff[base + 1 ] = part_2 - imag * part_3;
128+ nspin_4_veff[base + 2 ] = part_1 - part_4;
129+ nspin_4_veff[base + 3 ] = part_2 + imag * part_3;
118130 }
119131 for (int ib = 0 ; ib < nbands; ib += npol)
120132 {
121133 // FFT to real space and do things.
122134 wfcpw->recip_to_real <T, Device>(tmpsi_in, this ->porter , this ->ik );
123135 wfcpw->recip_to_real <T, Device>(tmpsi_in + max_npw, this ->porter1 , this ->ik );
124- veff_op ()(this ->ctx , this ->veff_col , this ->porter , this ->porter1 , current_veff );
136+ veff_op ()(this ->ctx , this ->veff_col , this ->porter , this ->porter1 , nspin_4_veff );
125137 // FFT back to G space.
126138 wfcpw->real_to_recip <T, Device>(this ->porter , tmhpsi, this ->ik , true );
127139 wfcpw->real_to_recip <T, Device>(this ->porter1 , tmhpsi + max_npw, this ->ik , true );
0 commit comments