@@ -12,21 +12,18 @@ class Operator
1212{
1313 public:
1414 Operator (){};
15- ~Operator ()
15+ virtual ~Operator ()
1616 {
1717 if (this ->hpsi != nullptr ) delete this ->hpsi ;
18- this ->release ();
1918 Operator* last = this ->next_op ;
2019 if (last != nullptr )
2120 {
22- last->release ();
2321 Operator* node_delete = last;
2422 last = last->next_op ;
2523 node_delete->next_op = nullptr ;
2624 delete node_delete;
2725 }
2826 }
29- virtual void release (){return ;}
3027
3128 typedef std::tuple<const psi::Psi<std::complex <double >>*, const psi::Range> hpsi_info;
3229 virtual hpsi_info hPsi (const hpsi_info& input)const {return hpsi_info (nullptr , 0 );}
@@ -63,6 +60,8 @@ class Operator
6360 protected:
6461 int ik = 0 ;
6562
63+ mutable bool recursive = false ;
64+
6665 // calculation type, only different type can be in main chain table
6766 int cal_type = 0 ;
6867 Operator* next_op = nullptr ;
@@ -73,10 +72,21 @@ class Operator
7372 std::complex <double >* get_hpsi (const hpsi_info& info)const
7473 {
7574 const int nbands_range = (std::get<1 >(info).range_2 - std::get<1 >(info).range_1 + 1 );
76- if (this ->hpsi != nullptr )
75+ // recursive call of hPsi, hpsi inputs as new psi,
76+ // create a new hpsi and delete old hpsi later
77+ if (this ->hpsi != std::get<0 >(info) )
78+ {
79+ this ->recursive = false ;
80+ if (this ->hpsi != nullptr )
81+ {
82+ delete this ->hpsi ;
83+ }
84+ }
85+ else
7786 {
78- delete this ->hpsi ;
87+ this ->recursive = true ;
7988 }
89+ // create a new hpsi
8090 this ->hpsi = new psi::Psi<std::complex <double >>(std::get<0 >(info)[0 ], 1 , nbands_range);
8191
8292 std::complex <double >* pointer_hpsi = this ->hpsi ->get_pointer ();
0 commit comments