Skip to content

Commit ffa4433

Browse files
committed
Fix: delete GlobalC used in calculate_weights(), exclude TWO_FERMI, add pointer of K_Vectors in ElecState.h
1 parent be5924f commit ffa4433

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

source/module_elecstate/elecstate.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const double* ElecState::getRho(int spin) const
1616
return &(this->charge->rho[spin][0]);
1717
}
1818

19-
void ElecState::calculate_weights(void)
19+
void ElecState::calculate_weights()
2020
{
2121
ModuleBase::TITLE("ElecState", "calculate_weights");
2222

@@ -30,6 +30,7 @@ void ElecState::calculate_weights(void)
3030
ekb_tmp[i] = &(this->ekb(i, 0));
3131
}
3232
int nbands = this->ekb.nc;
33+
int nks = this->ekb.nr;
3334

3435
if (GlobalV::KS_SOLVER == "selinv")
3536
{
@@ -41,46 +42,46 @@ void ElecState::calculate_weights(void)
4142
{
4243
if (GlobalV::TWO_EFERMI)
4344
{
44-
Occupy::iweights(GlobalC::kv.nks,
45-
GlobalC::kv.wk,
45+
Occupy::iweights(nks,
46+
this->klist->wk,
4647
nbands,
4748
GlobalC::ucell.magnet.get_nelup(),
4849
ekb_tmp,
4950
GlobalC::en.ef_up,
5051
this->wg,
5152
0,
52-
GlobalC::kv.isk);
53-
Occupy::iweights(GlobalC::kv.nks,
54-
GlobalC::kv.wk,
53+
this->klist->isk);
54+
Occupy::iweights(nks,
55+
this->klist->wk,
5556
nbands,
5657
GlobalC::ucell.magnet.get_neldw(),
5758
ekb_tmp,
5859
GlobalC::en.ef_dw,
5960
this->wg,
6061
1,
61-
GlobalC::kv.isk);
62+
this->klist->isk);
6263
// ef = ( ef_up + ef_dw ) / 2.0_dp need??? mohan add 2012-04-16
6364
}
6465
else
6566
{
6667
// -1 means don't need to consider spin.
67-
Occupy::iweights(GlobalC::kv.nks,
68-
GlobalC::kv.wk,
68+
Occupy::iweights(nks,
69+
this->klist->wk,
6970
nbands,
70-
GlobalC::CHR.nelec,
71+
this->charge->nelec,
7172
ekb_tmp,
7273
this->ef,
7374
this->wg,
7475
-1,
75-
GlobalC::kv.isk);
76+
this->klist->isk);
7677
}
7778
}
7879
else if (Occupy::use_tetrahedron_method)
7980
{
8081
ModuleBase::WARNING_QUIT("calculate_weights", "not implemented yet,coming soon!");
8182
// if(my_rank == 0)
8283
// {
83-
// tweights(GlobalC::kv.nkstot, nspin, nbands, GlobalC::CHR.nelec, ntetra,tetra, GlobalC::wf.et,
84+
// tweights(GlobalC::kv.nkstot, nspin, nbands, this->charge->nelec, ntetra,tetra, GlobalC::wf.et,
8485
// this->ef, this->wg);
8586
// }
8687
}
@@ -90,8 +91,8 @@ void ElecState::calculate_weights(void)
9091
{
9192
double demet_up = 0.0;
9293
double demet_dw = 0.0;
93-
Occupy::gweights(GlobalC::kv.nks,
94-
GlobalC::kv.wk,
94+
Occupy::gweights(nks,
95+
this->klist->wk,
9596
nbands,
9697
GlobalC::ucell.magnet.get_nelup(),
9798
Occupy::gaussian_parameter,
@@ -101,9 +102,9 @@ void ElecState::calculate_weights(void)
101102
demet_up,
102103
this->wg,
103104
0,
104-
GlobalC::kv.isk);
105-
Occupy::gweights(GlobalC::kv.nks,
106-
GlobalC::kv.wk,
105+
this->klist->isk);
106+
Occupy::gweights(nks,
107+
this->klist->wk,
107108
nbands,
108109
GlobalC::ucell.magnet.get_neldw(),
109110
Occupy::gaussian_parameter,
@@ -113,35 +114,35 @@ void ElecState::calculate_weights(void)
113114
demet_dw,
114115
this->wg,
115116
1,
116-
GlobalC::kv.isk);
117-
GlobalC::en.demet = demet_up + demet_dw;
117+
this->klist->isk);
118+
this->demet = demet_up + demet_dw;
118119
}
119120
else
120121
{
121122
// -1 means is no related to spin.
122-
Occupy::gweights(GlobalC::kv.nks,
123-
GlobalC::kv.wk,
123+
Occupy::gweights(nks,
124+
this->klist->wk,
124125
nbands,
125-
GlobalC::CHR.nelec,
126+
this->charge->nelec,
126127
Occupy::gaussian_parameter,
127128
Occupy::gaussian_type,
128129
ekb_tmp,
129130
this->ef,
130-
GlobalC::en.demet,
131+
this->demet,
131132
this->wg,
132133
-1,
133-
GlobalC::kv.isk);
134+
this->klist->isk);
134135
}
135136

136137
// qianrui fix a bug on 2021-7-21
137-
Parallel_Reduce::reduce_double_allpool(GlobalC::en.demet);
138+
Parallel_Reduce::reduce_double_allpool(this->demet);
138139
}
139140
else if (Occupy::fixed_occupations)
140141
{
141142
// fix occupations need nelup and neldw.
142143
// mohan add 2011-04-03
143144
this->ef = -1.0e+20;
144-
for (int ik = 0; ik < GlobalC::kv.nks; ik++)
145+
for (int ik = 0; ik < nks; ik++)
145146
{
146147
for (int ibnd = 0; ibnd < nbands; ibnd++)
147148
{
@@ -162,7 +163,7 @@ void ElecState::calculate_weights(void)
162163
{
163164
double ebotom = ekb_tmp[0][0];
164165
double etop = ekb_tmp[0][0];
165-
for (int ik = 0; ik < GlobalC::kv.nks; ik++)
166+
for (int ik = 0; ik < nks; ik++)
166167
{
167168
for (int ib = 0; ib < nbands; ib++)
168169
{

source/module_elecstate/elecstate.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "module_psi/psi.h"
55
#include "src_pw/charge.h"
6+
#include "src_pw/klist.h"
67

78
namespace elecstate
89
{
@@ -11,10 +12,12 @@ class ElecState
1112
{
1213
public:
1314
virtual void init(Charge *chg_in, // pointer for class Charge
15+
const K_Vectors *klist_in,
1416
int nk_in, // number of k points
1517
int nb_in) // number of bands
1618
{
1719
this->charge = chg_in;
20+
this->klist = klist_in;
1821
this->ekb.create(nk_in, nb_in);
1922
this->wg.create(nk_in, nb_in);
2023
}
@@ -49,11 +52,16 @@ class ElecState
4952
// calculate wg from ekb
5053
virtual void calculate_weights(void);
5154

52-
Charge *charge;
55+
// pointer to charge density
56+
Charge *charge = nullptr;
57+
// pointer to k points lists
58+
const K_Vectors* klist = nullptr;
5359
// energy for sum of electrons
5460
double eband = 0.0;
5561
// Fermi energy
5662
double ef = 0.0;
63+
// correction energy for metals
64+
double demet = 0.0;
5765

5866
// band energy at each k point, each band.
5967
ModuleBase::matrix ekb;

source/module_elecstate/elecstate_lcao.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class ElecStateLCAO : public ElecState
1313
{
1414
public:
1515
ElecStateLCAO(Charge* chg_in,
16+
const K_Vectors* klist_in,
1617
int nks_in,
1718
int nbands_in,
1819
Local_Orbital_Charge* loc_in,
1920
LCAO_Hamilt* uhm_in,
2021
Local_Orbital_wfc* lowf_in)
2122
{
22-
init(chg_in, nks_in, nbands_in);
23+
init(chg_in, klist_in, nks_in, nbands_in);
2324
this->loc = loc_in;
2425
this->uhm = uhm_in;
2526
this->lowf = lowf_in;

source/module_elecstate/elecstate_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ElecStatePW : public ElecState
1212
public:
1313
ElecStatePW(const PW_Basis* basis_in, Charge* chg_in, int nbands_in) : basis(basis_in)
1414
{
15-
init(chg_in, basis_in->Klist->nks, nbands_in);
15+
init(chg_in, basis_in->Klist, basis_in->Klist->nks, nbands_in);
1616
}
1717
// void init(Charge* chg_in):charge(chg_in){} override;
1818

0 commit comments

Comments
 (0)