Skip to content

Commit 975c2cc

Browse files
committed
fix bug
1 parent 119872f commit 975c2cc

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ template <typename TK, typename TR>
4747
HamiltLCAO<TK, TR>::HamiltLCAO(const UnitCell& ucell,
4848
const Grid_Driver& grid_d,
4949
const Parallel_Orbitals* paraV,
50-
const K_Vectors& kv,
50+
const K_Vectors& kv_in,
5151
const TwoCenterIntegrator& intor_overlap_orb,
5252
const std::vector<double>& orb_cutoff)
5353
{
5454
this->classname = "HamiltLCAO";
5555

56+
this->kv = &kv_in;
57+
5658
// initialize the overlap matrix
5759
this->sR = new HContainer<TR>(paraV);
5860

5961
this->getOperator() = new OverlapNew<OperatorLCAO<TK, TR>>(this->hsk,
60-
kv.kvec_d,
62+
this->kv->kvec_d,
6163
this->hR,
6264
this->sR,
6365
&ucell,
@@ -73,7 +75,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
7375
const Grid_Driver& grid_d,
7476
const Parallel_Orbitals* paraV,
7577
elecstate::Potential* pot_in,
76-
const K_Vectors& kv,
78+
const K_Vectors& kv_in,
7779
const TwoCenterBundle& two_center_bundle,
7880
const LCAO_Orbitals& orb,
7981
elecstate::DensityMatrix<TK, double>* DM_in
@@ -92,6 +94,8 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
9294
{
9395
this->classname = "HamiltLCAO";
9496

97+
this->kv = &kv_in;
98+
9599
// Real space Hamiltonian is inited with template TR
96100
this->hR = new HContainer<TR>(paraV);
97101
this->sR = new HContainer<TR>(paraV);
@@ -139,7 +143,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
139143
// overlap term (<psi|psi>) is indispensable
140144
// in Gamma_only case, target SK is this->hsk->get_sk(), the target SR is this->sR
141145
this->getOperator() = new OverlapNew<OperatorLCAO<TK, TR>>(this->hsk,
142-
kv.kvec_d,
146+
this->kv->kvec_d,
143147
this->hR,
144148
this->sR,
145149
&ucell,
@@ -151,7 +155,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
151155
if (PARAM.inp.t_in_h)
152156
{
153157
Operator<TK>* ekinetic = new EkineticNew<OperatorLCAO<TK, TR>>(this->hsk,
154-
kv.kvec_d,
158+
this->kv->kvec_d,
155159
this->hR,
156160
&ucell,
157161
orb.cutoffs(),
@@ -165,7 +169,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
165169
if (PARAM.inp.vnl_in_h)
166170
{
167171
Operator<TK>* nonlocal = new NonlocalNew<OperatorLCAO<TK, TR>>(this->hsk,
168-
kv.kvec_d,
172+
this->kv->kvec_d,
169173
this->hR,
170174
&ucell,
171175
orb.cutoffs(),
@@ -186,7 +190,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
186190
// effective potential term
187191
Operator<TK>* veff = new Veff<OperatorLCAO<TK, TR>>(GG_in,
188192
this->hsk,
189-
kv.kvec_d,
193+
this->kv->kvec_d,
190194
pot_in,
191195
this->hR, // no explicit call yet
192196
&ucell,
@@ -201,13 +205,13 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
201205
if (PARAM.inp.deepks_scf)
202206
{
203207
Operator<TK>* deepks = new DeePKS<OperatorLCAO<TK, TR>>(this->hsk,
204-
kv.kvec_d,
208+
this->kv->kvec_d,
205209
this->hR, // no explicit call yet
206210
&ucell,
207211
&grid_d,
208212
two_center_bundle.overlap_orb_alpha.get(),
209213
&orb,
210-
kv.get_nks(),
214+
this->kv->get_nks(),
211215
DM_in,
212216
ld_in);
213217
this->getOperator()->add(deepks);
@@ -222,14 +226,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
222226
if (PARAM.inp.dft_plus_u == 2)
223227
{
224228
dftu = new OperatorDFTU<OperatorLCAO<TK, TR>>(this->hsk,
225-
kv.kvec_d,
229+
this->kv->kvec_d,
226230
this->hR, // no explicit call yet
227-
kv.isk);
231+
this->kv->isk);
228232
}
229233
else
230234
{
231235
dftu = new DFTU<OperatorLCAO<TK, TR>>(this->hsk,
232-
kv.kvec_d,
236+
this->kv->kvec_d,
233237
this->hR,
234238
ucell,
235239
&grid_d,
@@ -256,7 +260,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
256260
// Veff term
257261
this->getOperator() = new Veff<OperatorLCAO<TK, TR>>(GK_in,
258262
this->hsk,
259-
kv.kvec_d,
263+
this->kv->kvec_d,
260264
pot_in,
261265
this->hR,
262266
&ucell,
@@ -269,7 +273,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
269273
// initial operator for multi-k case
270274
// overlap term is indispensable
271275
Operator<TK>* overlap = new OverlapNew<OperatorLCAO<TK, TR>>(this->hsk,
272-
kv.kvec_d,
276+
this->kv->kvec_d,
273277
this->hR,
274278
this->sR,
275279
&ucell,
@@ -290,7 +294,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
290294
if (PARAM.inp.t_in_h)
291295
{
292296
Operator<TK>* ekinetic = new EkineticNew<OperatorLCAO<TK, TR>>(this->hsk,
293-
kv.kvec_d,
297+
this->kv->kvec_d,
294298
this->hR,
295299
&ucell,
296300
orb.cutoffs(),
@@ -304,7 +308,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
304308
if (PARAM.inp.vnl_in_h)
305309
{
306310
Operator<TK>* nonlocal = new NonlocalNew<OperatorLCAO<TK, TR>>(this->hsk,
307-
kv.kvec_d,
311+
this->kv->kvec_d,
308312
this->hR,
309313
&ucell,
310314
orb.cutoffs(),
@@ -326,13 +330,13 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
326330
if (PARAM.inp.deepks_scf)
327331
{
328332
Operator<TK>* deepks = new DeePKS<OperatorLCAO<TK, TR>>(this->hsk,
329-
kv.kvec_d,
333+
this->kv->kvec_d,
330334
hR,
331335
&ucell,
332336
&grid_d,
333337
two_center_bundle.overlap_orb_alpha.get(),
334338
&orb,
335-
kv.get_nks(),
339+
this->kv->get_nks(),
336340
DM_in,
337341
ld_in);
338342
this->getOperator()->add(deepks);
@@ -348,15 +352,15 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
348352
}
349353
Operator<TK>* td_ekinetic = new TDEkinetic<OperatorLCAO<TK, TR>>(this->hsk,
350354
this->hR,
351-
&kv,
355+
this->kv,
352356
&ucell,
353357
orb.cutoffs(),
354358
&grid_d,
355359
two_center_bundle.overlap_orb.get());
356360
this->getOperator()->add(td_ekinetic);
357361

358362
Operator<TK>* td_nonlocal
359-
= new TDNonlocal<OperatorLCAO<TK, TR>>(this->hsk, kv.kvec_d, this->hR, &ucell, orb, &grid_d);
363+
= new TDNonlocal<OperatorLCAO<TK, TR>>(this->hsk, this->kv->kvec_d, this->hR, &ucell, orb, &grid_d);
360364
this->getOperator()->add(td_nonlocal);
361365
}
362366
if (PARAM.inp.dft_plus_u)
@@ -365,14 +369,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
365369
if (PARAM.inp.dft_plus_u == 2)
366370
{
367371
dftu = new OperatorDFTU<OperatorLCAO<TK, TR>>(this->hsk,
368-
kv.kvec_d,
372+
this->kv->kvec_d,
369373
this->hR, // no explicit call yet
370-
kv.isk);
374+
this->kv->isk);
371375
}
372376
else
373377
{
374378
dftu = new DFTU<OperatorLCAO<TK, TR>>(this->hsk,
375-
kv.kvec_d,
379+
this->kv->kvec_d,
376380
this->hR,
377381
ucell,
378382
&grid_d,
@@ -385,7 +389,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
385389
if (PARAM.inp.sc_mag_switch)
386390
{
387391
Operator<TK>* sc_lambda = new DeltaSpin<OperatorLCAO<TK, TR>>(this->hsk,
388-
kv.kvec_d,
392+
this->kv->kvec_d,
389393
this->hR,
390394
ucell,
391395
&grid_d,
@@ -406,7 +410,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
406410
Operator<TK>* exx = new OperatorEXX<OperatorLCAO<TK, TR>>(this->hsk,
407411
this->hR,
408412
ucell,
409-
kv,
413+
*kv,
410414
Hexxd,
411415
Hexxc,
412416
Add_Hexx_Type::R,
@@ -443,28 +447,26 @@ void HamiltLCAO<TK, TR>::matrix(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in)
443447
}
444448

445449
template <typename TK, typename TR>
446-
void HamiltLCAO<TK, TR>::updateHk(const int ik, const int isk)
450+
void HamiltLCAO<TK, TR>::updateHk(const int ik)
447451
{
448452
ModuleBase::TITLE("HamiltLCAO", "updateHk");
449453
ModuleBase::timer::tick("HamiltLCAO", "updateHk");
450454

451-
// isk is kv.isk[ik], mohan note 2025-03-31
452-
453455
// update global spin index
454456
if (PARAM.inp.nspin == 2)
455457
{
456458
// if Veff is added and current_spin is changed, refresh HR
457-
if (PARAM.inp.vl_in_h && isk != this->current_spin)
459+
if (PARAM.inp.vl_in_h && this->kv->isk[ik] != this->current_spin)
458460
{
459461
// change data pointer of HR
460-
this->hR->allocate(this->hRS2.data() + this->hRS2.size() / 2 * isk, 0);
462+
this->hR->allocate(this->hRS2.data() + this->hRS2.size() / 2 * this->kv->isk[ik], 0);
461463
if (this->refresh_times > 0)
462464
{
463465
this->refresh_times--;
464466
dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(this->ops)->set_hr_done(false);
465467
}
466468
}
467-
this->current_spin = isk;
469+
this->current_spin = this->kv->isk[ik];
468470
}
469471
this->getOperator()->init(ik);
470472
ModuleBase::timer::tick("HamiltLCAO", "updateHk");

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class HamiltLCAO : public Hamilt<TK>
4747
const Grid_Driver& grid_d,
4848
const Parallel_Orbitals* paraV,
4949
elecstate::Potential* pot_in,
50-
const K_Vectors& kv,
50+
const K_Vectors& kv_in,
5151
const TwoCenterBundle& two_center_bundle,
5252
const LCAO_Orbitals& orb,
5353
elecstate::DensityMatrix<TK, double>* DM_in
@@ -70,7 +70,7 @@ class HamiltLCAO : public Hamilt<TK>
7070
HamiltLCAO(const UnitCell& ucell,
7171
const Grid_Driver& grid_d,
7272
const Parallel_Orbitals* paraV,
73-
const K_Vectors& kv,
73+
const K_Vectors& kv_in,
7474
const TwoCenterIntegrator& intor_overlap_orb,
7575
const std::vector<double>& orb_cutoff);
7676

@@ -129,7 +129,7 @@ class HamiltLCAO : public Hamilt<TK>
129129
void refresh() override;
130130

131131
// for target K point, update consequence of hPsi() and matrix()
132-
void updateHk(const int ik, const int isk);
132+
virtual void updateHk(const int ik) override;
133133

134134
/**
135135
* @brief special for LCAO, update SK only
@@ -149,6 +149,8 @@ class HamiltLCAO : public Hamilt<TK>
149149

150150
private:
151151

152+
const K_Vectors* kv = nullptr;
153+
152154
//! Real space Hamiltonian H(R), where R is the Bravis lattice vector
153155
HContainer<TR>* hR = nullptr;
154156

0 commit comments

Comments
 (0)