77
88LCAO_Matrix::LCAO_Matrix ()
99{
10- // for gamma_only
11- Sloc = new double [1 ];
12- Hloc_fixed = new double [1 ];
13- Hloc = new double [1 ];
14- Sdiag = new double [1 ];
15-
16- // for many k points
17- Sloc2 = new std::complex <double >[1 ];
18- Hloc_fixed2 = new std::complex <double >[1 ];
19- Hloc2 = new std::complex <double >[1 ];
20- Sdiag2 = new std::complex <double >[1 ];
2110}
2211
2312LCAO_Matrix::~LCAO_Matrix ()
2413{
25- // delete matrix for gamma_only.
26- delete[] Sloc;
27- delete[] Hloc_fixed;
28- delete[] Hloc;
29- delete[] Sdiag;
30-
31- // delete matrix for many k points
32- delete[] Sloc2;
33- delete[] Hloc_fixed2;
34- delete[] Hloc2;
35- delete[] Sdiag2;
3614}
3715
3816
@@ -97,20 +75,16 @@ void LCAO_Matrix::allocate_HS_gamma(const long &nloc)
9775 // because we initilize in the constructor function
9876 // with dimension '1', so here we reconstruct these
9977 // matrices
100- delete[] Sloc;
101- delete[] Hloc_fixed;
102- delete[] Hloc;
103- delete[] Sdiag;
10478
105- this ->Sloc = new double [ nloc] ;
106- this ->Hloc_fixed = new double [ nloc] ;
107- this ->Hloc = new double [ nloc] ;
108- this ->Sdiag = new double [ nloc] ;
79+ this ->Sloc . resize ( nloc) ;
80+ this ->Hloc_fixed . resize ( nloc) ;
81+ this ->Hloc . resize ( nloc) ;
82+ this ->Sdiag . resize ( nloc) ;
10983
110- ModuleBase::GlobalFunc::ZEROS (Sloc,nloc);
111- ModuleBase::GlobalFunc::ZEROS (Hloc_fixed,nloc);
112- ModuleBase::GlobalFunc::ZEROS (Hloc,nloc);
113- ModuleBase::GlobalFunc::ZEROS (Sdiag,nloc); // mohan add 2021-01-30
84+ ModuleBase::GlobalFunc::ZEROS (Sloc. data () ,nloc);
85+ ModuleBase::GlobalFunc::ZEROS (Hloc_fixed. data () ,nloc);
86+ ModuleBase::GlobalFunc::ZEROS (Hloc. data () ,nloc);
87+ ModuleBase::GlobalFunc::ZEROS (Sdiag. data () ,nloc); // mohan add 2021-01-30
11488
11589 return ;
11690}
@@ -126,52 +100,35 @@ void LCAO_Matrix::allocate_HS_k(const long &nloc)
126100 // because we initilize in the constructor function
127101 // with dimension '1', so here we reconstruct these
128102 // matrices
129- delete[] Sloc2;
130- delete[] Hloc_fixed2;
131- delete[] Hloc2;
132- delete[] Sdiag2;
133-
134- this ->Sloc2 = new std::complex <double >[nloc];
135- this ->Hloc_fixed2 = new std::complex <double >[nloc];
136- this ->Hloc2 = new std::complex <double >[nloc];
137- this ->Sdiag2 = new std::complex <double >[nloc];
138-
139- ModuleBase::GlobalFunc::ZEROS (Sloc2,nloc);
140- ModuleBase::GlobalFunc::ZEROS (Hloc_fixed2,nloc);
141- ModuleBase::GlobalFunc::ZEROS (Hloc2,nloc);
103+ this ->Sloc2 .resize (nloc);
104+ this ->Hloc_fixed2 .resize (nloc);
105+ this ->Hloc2 .resize (nloc);
106+ this ->Sdiag2 .resize (nloc);
107+
108+ ModuleBase::GlobalFunc::ZEROS (Sloc2.data (),nloc);
109+ ModuleBase::GlobalFunc::ZEROS (Hloc_fixed2.data (),nloc);
110+ ModuleBase::GlobalFunc::ZEROS (Hloc2.data (),nloc);
142111
143112 return ;
144113}
145114
146115void LCAO_Matrix::allocate_HS_R (const int &nnR)
147116{
148117 if (GlobalV::NSPIN!=4 )
149- {
150- delete[] HlocR;
151- delete[] SlocR;
152- delete[] Hloc_fixedR;
153-
154- this ->HlocR = new double [nnR];
155- this ->SlocR = new double [nnR];
156- this ->Hloc_fixedR = new double [nnR];
118+ {
119+ this ->SlocR .resize (nnR);
120+ this ->Hloc_fixedR .resize (nnR);
157121
158- ModuleBase::GlobalFunc::ZEROS (HlocR, nnR);
159- ModuleBase::GlobalFunc::ZEROS (SlocR, nnR);
160- ModuleBase::GlobalFunc::ZEROS (Hloc_fixedR, nnR);
122+ ModuleBase::GlobalFunc::ZEROS (SlocR.data (), nnR);
123+ ModuleBase::GlobalFunc::ZEROS (Hloc_fixedR.data (), nnR);
161124 }
162125 else
163126 {
164- delete[] HlocR_soc;
165- delete[] SlocR_soc;
166- delete[] Hloc_fixedR_soc;
167-
168- this ->HlocR_soc = new std::complex <double >[nnR];
169- this ->SlocR_soc = new std::complex <double >[nnR];
170- this ->Hloc_fixedR_soc = new std::complex <double >[nnR];
127+ this ->SlocR_soc .resize (nnR);
128+ this ->Hloc_fixedR_soc .resize (nnR);
171129
172- ModuleBase::GlobalFunc::ZEROS (HlocR_soc, nnR);
173- ModuleBase::GlobalFunc::ZEROS (SlocR_soc, nnR);
174- ModuleBase::GlobalFunc::ZEROS (Hloc_fixedR_soc, nnR);
130+ ModuleBase::GlobalFunc::ZEROS (SlocR_soc.data (), nnR);
131+ ModuleBase::GlobalFunc::ZEROS (Hloc_fixedR_soc.data (), nnR);
175132
176133 }
177134
@@ -389,33 +346,31 @@ void LCAO_Matrix::set_stress
389346
390347void LCAO_Matrix::zeros_HSgamma (const char &mtype)
391348{
392- if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (Sloc,GlobalC::ParaO. nloc );
393- else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (Hloc_fixed,GlobalC::ParaO. nloc );
394- else if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (Hloc,GlobalC::ParaO. nloc );
349+ if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (this -> Sloc . data (), this -> Sloc . size () );
350+ else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (this -> Hloc_fixed . data (), this -> Hloc_fixed . size () );
351+ else if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (this -> Hloc . data (), this -> Hloc . size () );
395352 return ;
396353}
397354
398355void LCAO_Matrix::zeros_HSk (const char &mtype)
399356{
400- if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (Sloc2,GlobalC::ParaO. nloc );
401- else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (Hloc_fixed2,GlobalC::ParaO. nloc );
402- else if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (Hloc2,GlobalC::ParaO. nloc );
357+ if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (this -> Sloc2 . data (), this -> Sloc2 . size () );
358+ else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (this -> Hloc_fixed2 . data (), this -> Hloc_fixed2 . size () );
359+ else if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (this -> Hloc2 . data (), this -> Hloc2 . size () );
403360 return ;
404361}
405362
406- void LCAO_Matrix::zeros_HSR (const char &mtype, const int &nnr )
363+ void LCAO_Matrix::zeros_HSR (const char &mtype)
407364{
408365 if (GlobalV::NSPIN!=4 )
409366 {
410- if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (SlocR, nnr);
411- else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (Hloc_fixedR, nnr);
412- else if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (HlocR, nnr);
367+ if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (this ->SlocR .data (), this ->SlocR .size ());
368+ else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (this ->Hloc_fixedR .data (), this ->Hloc_fixedR .size ());
413369 }
414370 else
415371 {
416- if (mtype==' H' ) ModuleBase::GlobalFunc::ZEROS (this ->HlocR_soc , nnr);
417- else if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (this ->SlocR_soc , nnr);
418- else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (this ->Hloc_fixedR_soc , nnr);
372+ if (mtype==' S' ) ModuleBase::GlobalFunc::ZEROS (this ->SlocR_soc .data (), this ->SlocR_soc .size ());
373+ else if (mtype==' T' ) ModuleBase::GlobalFunc::ZEROS (this ->Hloc_fixedR_soc .data (), this ->Hloc_fixedR_soc .size ());
419374 }
420375 return ;
421376}
0 commit comments