Skip to content

Commit 5fccb05

Browse files
committed
update hamiltonian and operator
1 parent 37c253e commit 5fccb05

File tree

8 files changed

+162
-155
lines changed

8 files changed

+162
-155
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ HamiltLCAO<TK, TR>::HamiltLCAO(const UnitCell& ucell,
5353
{
5454
this->classname = "HamiltLCAO";
5555

56-
// Real space Hamiltonian is inited with template TR
57-
// this->hR = new HContainer<TR>(paraV);
56+
// initialize the overlap matrix
5857
this->sR = new HContainer<TR>(paraV);
59-
// this->hsk = new HS_Matrix_K<TK>(paraV);
6058

6159
this->getOperator() = new OverlapNew<OperatorLCAO<TK, TR>>(this->hsk,
6260
kv.kvec_d,
@@ -350,7 +348,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
350348
}
351349
Operator<TK>* td_ekinetic = new TDEkinetic<OperatorLCAO<TK, TR>>(this->hsk,
352350
this->hR,
353-
kv,
351+
&kv,
354352
&ucell,
355353
orb.cutoffs(),
356354
&grid_d,
@@ -419,6 +417,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
419417
this->getOperator()->add(exx);
420418
}
421419
#endif
420+
422421
// if NSPIN==2, HR should be separated into two parts, save HR into this->hRS2
423422
int memory_fold = 1;
424423
if (PARAM.inp.nspin == 2)
@@ -499,7 +498,7 @@ Operator<TK>*& HamiltLCAO<TK, TR>::getOperator()
499498
template <typename TK, typename TR>
500499
void HamiltLCAO<TK, TR>::updateSk(
501500
const int ik,
502-
std::vector<ModuleBase::Vector3<double>>& kvec_d,
501+
const ModuleBase::Vector3<double>& kvec_d,
503502
const int hk_type)
504503
{
505504
ModuleBase::TITLE("HamiltLCAO", "updateSk");
@@ -510,12 +509,12 @@ void HamiltLCAO<TK, TR>::updateSk(
510509
if (hk_type == 1) // collumn-major matrix for SK
511510
{
512511
const int nrow = this->hsk->get_pv()->get_row_size();
513-
hamilt::folding_HR(*this->sR, this->getSk(), kvec_d[ik], nrow, 1);
512+
hamilt::folding_HR(*this->sR, this->getSk(), kvec_d, nrow, 1);
514513
}
515514
else if (hk_type == 0) // row-major matrix for SK
516515
{
517516
const int ncol = this->hsk->get_pv()->get_col_size();
518-
hamilt::folding_HR(*this->sR, this->getSk(), kvec_d[ik], ncol, 0);
517+
hamilt::folding_HR(*this->sR, this->getSk(), kvec_d, ncol, 0);
519518
}
520519
else
521520
{

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,39 +140,40 @@ class HamiltLCAO : public Hamilt<TK>
140140
* @return void
141141
*/
142142
void updateSk(const int ik,
143-
std::vector<ModuleBase::Vector3<double>>& kvec_d,
143+
const ModuleBase::Vector3<double>& kvec_d,
144144
const int hk_type = 0);
145145

146146
// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
147147
// not used in PW base
148-
// void matrix(MatrixBlock<std::complex<double>> &hk_in, MatrixBlock<std::complex<double>> &sk_in) override;
149148
void matrix(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in) override;
150149

151150
private:
152151

153-
// Real space Hamiltonian
152+
//! Real space Hamiltonian H(R), where R is the Bravis lattice vector
154153
HContainer<TR>* hR = nullptr;
154+
155+
//! Real space overlap matrix S(R), where R is the Bravis lattice vector
155156
HContainer<TR>* sR = nullptr;
156157

157158
#ifdef __DEEPKS
158159
HContainer<TR>* V_delta_R = nullptr;
159160
#endif
160161

162+
//! Hamiltonian and overlap matrices for a specific k point
161163
HS_Matrix_K<TK>* hsk = nullptr;
162164

163165
// special case for NSPIN=2 , data of HR should be separated into two parts
164166
// save them in this->hRS2;
165167
std::vector<TR> hRS2;
168+
166169
int refresh_times = 1;
167170

168-
/// current_spin for NSPIN=2, 0: hamiltonian for spin up, 1: hamiltonian for spin down
171+
//! current_spin for NSPIN=2 case
172+
//! 0: Hamiltonian for spin up,
173+
//! 1: Hamiltonian for spin down
169174
int current_spin = 0;
170175

171176
const int istep = 0;
172-
173-
// sk and hk will be refactored to HamiltLCAO later
174-
// std::vector<TK> sk;
175-
// std::vector<TK> hk;
176177
};
177178

178179
} // namespace hamilt

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,11 @@ void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::contributeHk(int ik
388388
const Parallel_Orbitals* paraV = this->hR_tmp->get_atom_pair(0).get_paraV();
389389
// save HR data for output
390390
int spin_tot = PARAM.inp.nspin;
391+
391392
if (spin_tot == 4)
392-
;
393+
{
394+
395+
}
393396
else if (!output_hR_done && TD_Velocity::out_mat_R)
394397
{
395398
for (int spin_now = 0; spin_now < spin_tot; spin_now++)
@@ -402,6 +405,7 @@ void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::contributeHk(int ik
402405
}
403406
output_hR_done = true;
404407
}
408+
405409
// folding inside HR to HK
406410
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
407411
{

source/module_hamilt_lcao/module_dftu/dftu.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//==========================================================
2-
// Author: Xin Qu
3-
// DATE : 2019-12-10
4-
//==========================================================
51
#ifndef DFTU_H
62
#define DFTU_H
73

@@ -187,15 +183,15 @@ class DFTU
187183
const int dim1,
188184
const int dim2,
189185
std::complex<double>* mat_k,
190-
const std::vector<ModuleBase::Vector3<double>>& kvec_d);
186+
const ModuleBase::Vector3<double>& kvec_d);
191187

192188
/**
193189
* @brief new function of folding_S_matrix
194190
* only for Hamiltonian now, for force and stress will be developed later
195191
* use HContainer as input and output in mat_k
196192
*/
197193
void folding_matrix_k_new(const int ik,
198-
std::vector<ModuleBase::Vector3<double>>& kvec_d,
194+
const ModuleBase::Vector3<double>& kvec_d,
199195
hamilt::Hamilt<std::complex<double>>* p_ham);
200196

201197
//=============================================================
@@ -220,7 +216,7 @@ class DFTU
220216
const int ik,
221217
const std::complex<double>* rho_VU,
222218
ModuleBase::matrix& force_dftu,
223-
const std::vector<ModuleBase::Vector3<double>>& kvec_d);
219+
const ModuleBase::Vector3<double>& kvec_d);
224220

225221
void cal_stress_k(const UnitCell& ucell,
226222
const Grid_Driver& gd,
@@ -229,7 +225,7 @@ class DFTU
229225
const int ik,
230226
const std::complex<double>* rho_VU,
231227
ModuleBase::matrix& stress_dftu,
232-
const std::vector<ModuleBase::Vector3<double>>& kvec_d);
228+
const ModuleBase::Vector3<double>& kvec_d);
233229

234230
void cal_force_gamma(const UnitCell& ucell,
235231
const double* rho_VU,

source/module_hamilt_lcao/module_dftu/dftu_folding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void DFTU::folding_matrix_k(const UnitCell& ucell,
133133
const int dim1,
134134
const int dim2,
135135
std::complex<double>* mat_k,
136-
const std::vector<ModuleBase::Vector3<double>>& kvec_d)
136+
const ModuleBase::Vector3<double>& kvec_d)
137137
{
138138
ModuleBase::TITLE("DFTU", "folding_matrix_k");
139139
ModuleBase::timer::tick("DFTU", "folding_matrix_k");
@@ -224,7 +224,7 @@ void DFTU::folding_matrix_k(const UnitCell& ucell,
224224
// dR is the index of box in Crystal coordinates
225225
//------------------------------------------------
226226
ModuleBase::Vector3<double> dR(gd.getBox(ad).x, gd.getBox(ad).y, gd.getBox(ad).z);
227-
const double arg = (kvec_d[ik] * dR) * ModuleBase::TWO_PI;
227+
const double arg = (kvec_d * dR) * ModuleBase::TWO_PI;
228228
const std::complex<double> kphase = std::complex<double>(cos(arg), sin(arg));
229229

230230
//--------------------------------------------------
@@ -279,7 +279,7 @@ void DFTU::folding_matrix_k(const UnitCell& ucell,
279279
}
280280

281281
void DFTU::folding_matrix_k_new(const int ik,
282-
std::vector<ModuleBase::Vector3<double>>& kvec_d,
282+
const ModuleBase::Vector3<double>& kvec_d,
283283
hamilt::Hamilt<std::complex<double>>* p_ham)
284284
{
285285
ModuleBase::TITLE("DFTU", "folding_matrix_k_new");
@@ -307,7 +307,7 @@ void DFTU::folding_matrix_k_new(const int ik,
307307
else
308308
{
309309
dynamic_cast<hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>*>(p_ham)
310-
->updateSk(ik, hk_type);
310+
->updateSk(ik, kvec_d, hk_type);
311311
}
312312
}
313313
}

source/module_hamilt_lcao/module_dftu/dftu_force.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ void DFTU::force_stress(const UnitCell& ucell,
209209

210210
if (PARAM.inp.cal_force)
211211
{
212-
cal_force_k(ucell, gd, fsr, pv, ik, &rho_VU[0], force_dftu, kv.kvec_d);
212+
cal_force_k(ucell, gd, fsr, pv, ik, &rho_VU[0], force_dftu, kv.kvec_d[ik]);
213213
}
214214
if (PARAM.inp.cal_stress)
215215
{
216-
cal_stress_k(ucell, gd, fsr, pv, ik, &rho_VU[0], stress_dftu, kv.kvec_d);
216+
cal_stress_k(ucell, gd, fsr, pv, ik, &rho_VU[0], stress_dftu, kv.kvec_d[ik]);
217217
}
218218
} // ik
219219
}
@@ -256,7 +256,7 @@ void DFTU::cal_force_k(const UnitCell& ucell,
256256
const int ik,
257257
const std::complex<double>* rho_VU,
258258
ModuleBase::matrix& force_dftu,
259-
const std::vector<ModuleBase::Vector3<double>>& kvec_d)
259+
const ModuleBase::Vector3<double>& kvec_d)
260260
{
261261
ModuleBase::TITLE("DFTU", "cal_force_k");
262262
ModuleBase::timer::tick("DFTU", "cal_force_k");
@@ -386,7 +386,7 @@ void DFTU::cal_stress_k(const UnitCell& ucell,
386386
const int ik,
387387
const std::complex<double>* rho_VU,
388388
ModuleBase::matrix& stress_dftu,
389-
const std::vector<ModuleBase::Vector3<double>>& kvec_d)
389+
const ModuleBase::Vector3<double>& kvec_d)
390390
{
391391
ModuleBase::TITLE("DFTU", "cal_stress_k");
392392
ModuleBase::timer::tick("DFTU", "cal_stress_k");
@@ -662,4 +662,4 @@ void DFTU::cal_stress_gamma(const UnitCell& ucell,
662662
return;
663663
}
664664
} // namespace ModuleDFTU
665-
#endif
665+
#endif

source/module_hamilt_lcao/module_dftu/dftu_occup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void DFTU::cal_occup_m_k(const int iter,
175175
for (int ik = 0; ik < kv.get_nks(); ik++)
176176
{
177177
// srho(mu,nu) = \sum_{iw} S(mu,iw)*dm_k(iw,nu)
178-
this->folding_matrix_k_new(ik, kv.kvec_d, p_ham);
178+
this->folding_matrix_k_new(ik, kv.kvec_d[ik], p_ham);
179179

180180
std::complex<double>* s_k_pointer = nullptr;
181181

0 commit comments

Comments
 (0)