Skip to content

Commit 70510ad

Browse files
committed
Fix: 1. non-collinear spin error, 2. davidson method error
1 parent 845b8b0 commit 70510ad

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

source/module_hamilt/hamilt_pw.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ HamiltPW::HamiltPW()
2626
{
2727
Operator* ekinetic = new Ekinetic<OperatorPW>(
2828
tpiba2,
29-
gk2
29+
gk2,
30+
GlobalC::wfcpw->npwk_max
3031
);
3132
if(this->ops == nullptr)
3233
{

source/module_hamilt/ks_pw/ekinetic_pw.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ template class Ekinetic<OperatorPW>;
1111
template<>
1212
Ekinetic<OperatorPW>::Ekinetic(
1313
double tpiba2_in,
14-
const double* gk2_in
14+
const double* gk2_in,
15+
const int gk2_dim_in
1516
)
1617
{
1718
this->cal_type = 10;
1819
this->tpiba2 = tpiba2_in;
1920
this->gk2 = gk2_in;
21+
this->gk2_dim = gk2_dim_in;
2022
if( this->tpiba2 < 1e-10 || this->gk2 == nullptr
2123
)
2224
{
@@ -38,7 +40,7 @@ void Ekinetic<OperatorPW>::act
3840
this->max_npw = psi_in->get_nbasis() / psi_in->npol;
3941

4042

41-
const double *gk2_ik = &(this->gk2[this->ik * this->max_npw]);
43+
const double *gk2_ik = &(this->gk2[this->ik * this->gk2_dim]);
4244

4345
for (int ib = 0; ib < n_npwx; ++ib)
4446
{

source/module_hamilt/ks_pw/ekinetic_pw.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class Ekinetic : public T
1212
public:
1313
Ekinetic(
1414
double tpiba2_in,
15-
const double* gk2_in
15+
const double* gk2_in,
16+
const int gk2_dim_in
1617
);
1718

1819
virtual void act
@@ -33,6 +34,8 @@ class Ekinetic : public T
3334

3435
const double* gk2 = nullptr;
3536

37+
int gk2_dim = 0;
38+
3639
};
3740

3841
} // namespace hamilt

source/module_hamilt/ks_pw/meta_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void Meta<OperatorPW>::act
4949

5050
const int npw = psi_in->get_ngk(this->ik);
5151
const int current_spin = this->isk[this->ik];
52-
this->max_npw = psi_in->get_nbasis();
52+
this->max_npw = psi_in->get_nbasis() / psi_in->npol;
5353
//npol == 2 case has not been considered
5454
this->npol = psi_in->npol;
5555

source/module_hamilt/ks_pw/nonlocal_pw.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void Nonlocal<OperatorPW>::act
7575
&nkb,
7676
&ModuleBase::ONE,
7777
this->ppcell->vkb.c,
78-
&this->max_npw,
78+
&this->ppcell->vkb.nc,
7979
tmpsi_in,
8080
&inc,
8181
&ModuleBase::ZERO,
@@ -92,7 +92,7 @@ void Nonlocal<OperatorPW>::act
9292
&this->npw,
9393
&ModuleBase::ONE,
9494
this->ppcell->vkb.c,
95-
&this->max_npw,
95+
&this->ppcell->vkb.nc,
9696
tmpsi_in,
9797
&this->max_npw,
9898
&ModuleBase::ZERO,
@@ -171,7 +171,7 @@ void Nonlocal<OperatorPW>::add_nonlocal_pp(std::complex<double> *hpsi_in, const
171171
{
172172
for (int ib = 0; ib < m; ib+=2)
173173
{
174-
psind = (sum + ip2) * 2 * m + ib;
174+
psind = (sum + ip2) * m + ib;
175175
becpind = ib * nkb + sum + ip;
176176
becp1 = becp[becpind];
177177
becp2 = becp[becpind + nkb];
@@ -201,7 +201,7 @@ void Nonlocal<OperatorPW>::add_nonlocal_pp(std::complex<double> *hpsi_in, const
201201
&(this->ppcell->nkb),
202202
&ModuleBase::ONE,
203203
this->ppcell->vkb.c,
204-
&this->max_npw,
204+
&this->ppcell->vkb.nc,
205205
ps,
206206
&inc,
207207
&ModuleBase::ONE,
@@ -218,7 +218,7 @@ void Nonlocal<OperatorPW>::add_nonlocal_pp(std::complex<double> *hpsi_in, const
218218
&(this->ppcell->nkb),
219219
&ModuleBase::ONE,
220220
this->ppcell->vkb.c,
221-
&this->max_npw,
221+
&this->ppcell->vkb.nc,
222222
ps,
223223
&npm,
224224
&ModuleBase::ONE,

source/module_hamilt/ks_pw/veff_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void Veff<OperatorPW>::act
4242
this->npol = psi_in->npol;
4343

4444
std::complex<double> *porter = new std::complex<double>[wfcpw->nmaxgr];
45-
for (int ib = 0; ib < n_npwx; ++ib)
45+
for (int ib = 0; ib < n_npwx; ib += this->npol)
4646
{
4747
if (this->npol == 1)
4848
{

source/module_hsolver/diago_david.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void DiagoDavid::cal_grad(hamilt::Hamilt* phm_in,
228228
}
229229
}
230230

231-
ppsi = &basis(m, 0);
231+
ppsi = &basis(nbase + m, 0);
232232
spsi = &sp(nbase + m, 0);
233233
for (int ig = 0; ig < npw; ig++)
234234
{

source/module_psi/psi.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ class Psi
5353
{
5454
public:
5555
//Constructor 1: basic
56-
Psi(void){};
56+
Psi(void){
57+
this->npol = GlobalV::NPOL;
58+
};
5759
//Constructor 2: specify ngk only, should call resize() later
58-
Psi(const int* ngk_in){this->ngk = ngk_in;}
60+
Psi(const int* ngk_in)
61+
{
62+
this->ngk = ngk_in;
63+
this->npol = GlobalV::NPOL;
64+
}
5965
//Constructor 3: specify nk, nbands, nbasis, ngk, and do not need to call resize() later
6066
Psi(int nk_in, int nbd_in, int nbs_in, const int* ngk_in=nullptr)
6167
{
@@ -76,16 +82,20 @@ class Psi
7682
this->resize(nk_in, nband_in, psi_in.get_nbasis());
7783
this->ngk = psi_in.ngk;
7884
this->npol = psi_in.npol;
79-
// copy from Psi from psi_in(current_k, 0, 0),
80-
// if size of k is 1, current_k in new Psi is psi_in.current_k
81-
const T* tmp = psi_in.get_pointer();
82-
if(nk_in==1) for(size_t index=0; index<this->size();++index)
85+
86+
if(nband_in <= psi_in.get_nbands())
8387
{
84-
psi[index] = tmp[index];
85-
//current_k for this Psi only keep the spin index same as the copied Psi
86-
this->current_k = psi_in.get_current_k();
87-
}
88-
else for(size_t index=0; index<this->size();++index) psi[index] = tmp[index];
88+
// copy from Psi from psi_in(current_k, 0, 0),
89+
// if size of k is 1, current_k in new Psi is psi_in.current_k
90+
const T* tmp = psi_in.get_pointer();
91+
if(nk_in==1) for(size_t index=0; index<this->size();++index)
92+
{
93+
psi[index] = tmp[index];
94+
//current_k for this Psi only keep the spin index same as the copied Psi
95+
this->current_k = psi_in.get_current_k();
96+
}
97+
else for(size_t index=0; index<this->size();++index) psi[index] = tmp[index];
98+
}
8999
}
90100
// initialize the wavefunction coefficient
91101
// only resize and construct function now is used
@@ -235,12 +245,12 @@ class Psi
235245
else
236246
{
237247
const T* p = &this->psi[(range.index_1 * this->nbands + range.range_1) * this->nbasis];
238-
int m = range.range_2 - range.range_1 + 1;
248+
int m = (range.range_2 - range.range_1 + 1)* this->npol;
239249
return std::tuple<const T*, int>(p, m);
240250
}
241251
}
242252

243-
bool npol = 1;
253+
int npol = 1;
244254

245255
private:
246256
std::vector<T> psi;

0 commit comments

Comments
 (0)