66namespace hamilt
77{
88
9- class OperatorPW : public Operator
9+ class OperatorPW : public Operator <std:: complex < double >>
1010{
1111 public:
1212 virtual ~OperatorPW (){};
1313
1414 // in PW code, different operators donate hPsi independently
1515 // run this->act function for the first operator and run all act() for other nodes in chain table
16- virtual hpsi_info hPsi (const hpsi_info& input)const
16+ virtual hpsi_info hPsi (hpsi_info& input)const
1717 {
1818 ModuleBase::timer::tick (" OperatorPW" , " hPsi" );
19- std::tuple<const std::complex <double >*, int > psi_info = std::get<0 >(input)->to_range (std::get<1 >(input));
19+ auto psi_input = std::get<0 >(input);
20+ std::tuple<const std::complex <double >*, int > psi_info = psi_input->to_range (std::get<1 >(input));
2021 int n_npwx = std::get<1 >(psi_info);
2122
2223 std::complex <double > *tmhpsi = this ->get_hpsi (input);
@@ -27,20 +28,25 @@ class OperatorPW : public Operator
2728 ModuleBase::WARNING_QUIT (" OperatorPW" , " please choose correct range of psi for hPsi()!" );
2829 }
2930
30- this ->act (std::get< 0 >(input) , n_npwx, tmpsi_in, tmhpsi);
31+ this ->act (psi_input , n_npwx, tmpsi_in, tmhpsi);
3132 OperatorPW* node ((OperatorPW*)this ->next_op );
3233 while (node != nullptr )
3334 {
34- node->act (std::get< 0 >(input) , n_npwx, tmpsi_in, tmhpsi);
35+ node->act (psi_input , n_npwx, tmpsi_in, tmhpsi);
3536 node = (OperatorPW*)(node->next_op );
3637 }
3738
38- // during recursive call of hPsi, delete the input psi
39- if (this ->recursive ) delete std::get<0 >(input);
40-
4139 ModuleBase::timer::tick (" OperatorPW" , " hPsi" );
4240
43- return hpsi_info (this ->hpsi , psi::Range (1 , 0 , 0 , n_npwx/std::get<0 >(input)->npol ));
41+ // if in_place, copy temporary hpsi to target hpsi_pointer, then delete hpsi and new a wrapper for return
42+ std::complex <double >* hpsi_pointer = std::get<2 >(input);
43+ if (this ->in_place )
44+ {
45+ ModuleBase::GlobalFunc::COPYARRAY (this ->hpsi ->get_pointer (), hpsi_pointer, this ->hpsi ->size ());
46+ delete this ->hpsi ;
47+ this ->hpsi = new psi::Psi<std::complex <double >>(hpsi_pointer, *psi_input, 1 , n_npwx/psi_input->npol );
48+ }
49+ return hpsi_info (this ->hpsi , psi::Range (1 , 0 , 0 , n_npwx/psi_input->npol ), hpsi_pointer);
4450 }
4551
4652 // main function which should be modified in Operator for PW base
0 commit comments