Skip to content

Commit 6d7111a

Browse files
committed
Merge branch 'HSolver' of https://github.com/deepmodeling/abacus-develop into SDFT
2 parents 45e8781 + 7876f92 commit 6d7111a

File tree

145 files changed

+11899
-639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+11899
-639
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ target_link_libraries(${ABACUS_BIN_NAME}
295295
ri
296296
driver
297297
xc
298+
hsolver
299+
elecstate
300+
hamilt
301+
psi
298302
esolver
299303
-lm
300304
)

source/Makefile.Objects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ sto_iter.o\
6161
sto_wf.o\
6262
sto_hchi.o\
6363
sto_che.o\
64+
sto_forces.o\
65+
sto_stress_pw.o
6466

6567
OBJS_TOOLS=complexarray.o\
6668
complexmatrix.o \

source/input.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void Input::Default(void)
383383

384384
cell_factor = 1.2; // LiuXh add 20180619
385385

386-
GlobalV::out_mul = 0; // qi feng add 2019/9/10
386+
out_mul = 0; // qi feng add 2019/9/10
387387

388388
//---------------------------------------------------------- //Peize Lin add 2020-04-04
389389
// restart
@@ -1342,7 +1342,7 @@ bool Input::Read(const std::string &fn)
13421342
}
13431343
else if (strcmp("out_mul", word) == 0)
13441344
{
1345-
read_value(ifs, GlobalV::out_mul);
1345+
read_value(ifs, out_mul);
13461346
} // qifeng add 2019/9/10
13471347
//----------------------------------------------------------
13481348
// exx
@@ -1841,6 +1841,7 @@ void Input::Default_2(void) // jiyy add 2019-08-04
18411841
}
18421842
}
18431843
if(calculation.substr(0,3) != "sto") bndpar = 1;
1844+
if(bndpar > GlobalV::NPROC) bndpar = GlobalV::NPROC;
18441845
}
18451846
#ifdef __MPI
18461847
void Input::Bcast()
@@ -2092,7 +2093,7 @@ void Input::Bcast()
20922093
Parallel_Common::bcast_bool(test_just_neighbor);
20932094
Parallel_Common::bcast_int(GlobalV::ocp);
20942095
Parallel_Common::bcast_string(GlobalV::ocp_set);
2095-
Parallel_Common::bcast_int(GlobalV::out_mul); // qifeng add 2019/9/10
2096+
Parallel_Common::bcast_int(out_mul); // qifeng add 2019/9/10
20962097

20972098
// Peize Lin add 2018-06-20
20982099
Parallel_Common::bcast_string(dft_functional);
@@ -2314,9 +2315,9 @@ void Input::Check(void)
23142315
ModuleBase::WARNING_QUIT("Input::Check", "calculate = istate is only availble for LCAO.");
23152316
}
23162317
}
2317-
else if (calculation == "md") // mohan add 2011-11-04
2318+
else if (calculation == "md" || calculation == "sto-md") // mohan add 2011-11-04
23182319
{
2319-
GlobalV::CALCULATION = "md";
2320+
GlobalV::CALCULATION = calculation;
23202321
symmetry = false;
23212322
cal_force = 1;
23222323
if (mdp.md_nstep == 0)

source/module_deepks/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ get_target_property(ABACUS_LINK_LIBRARIES ${ABACUS_BIN_NAME} LINK_LIBRARIES)
77
target_link_libraries(
88
test_deepks
99
base cell symmetry md surchem xc
10-
neighbor orb io ions lcao parallel mrrr pdiag pw ri driver esolver
10+
neighbor orb io ions lcao parallel mrrr pdiag pw ri driver esolver hsolver psi elecstate hamilt
1111
pthread
1212
deepks
1313
${ABACUS_LINK_LIBRARIES}

source/module_elecstate/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ add_library(
66
elecstate_lcao.cpp
77
dm2d_to_grid.cpp
88
)
9+
10+
IF (BUILD_TESTING)
11+
add_subdirectory(test)
12+
endif()

source/module_elecstate/elecstate.cpp

Lines changed: 46 additions & 33 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
{
@@ -188,15 +189,27 @@ void ElecState::calculate_weights(void)
188189
return;
189190
}
190191

191-
double ElecState::eBandK(const int& ik)
192+
void ElecState::calEBand()
192193
{
193-
ModuleBase::TITLE("ElecStatePW", "eBandK");
194-
double eband_k = 0.0;
195-
for (int ibnd = 0; ibnd < this->ekb.nc; ibnd++)
194+
ModuleBase::TITLE("ElecStatePW", "calEBand");
195+
//calculate ebands using wg and ekb
196+
this->eband = 0.0;
197+
for (int ik = 0; ik < this->ekb.nr; ++ik)
196198
{
197-
eband_k += this->ekb(ik, ibnd) * this->wg(ik, ibnd);
199+
for (int ibnd = 0; ibnd < this->ekb.nc; ibnd++)
200+
{
201+
this->eband += this->ekb(ik, ibnd) * this->wg(ik, ibnd);
202+
}
198203
}
199-
return eband_k;
204+
if(GlobalV::KPAR != 1)
205+
{
206+
//==================================
207+
// Reduce all the Energy in each cpu
208+
//==================================
209+
this->eband /= GlobalV::NPROC_IN_POOL;
210+
Parallel_Reduce::reduce_double_all(this->eband);
211+
}
212+
return;
200213
}
201214

202215
void ElecState::print_band(const int& ik, const int& printe, const int& iter)

source/module_elecstate/elecstate.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33

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

78
namespace elecstate
89
{
910

1011
class ElecState
1112
{
1213
public:
14+
ElecState(){};
1315
virtual void init(Charge *chg_in, // pointer for class Charge
16+
const K_Vectors *klist_in,
1417
int nk_in, // number of k points
1518
int nb_in) // number of bands
1619
{
1720
this->charge = chg_in;
21+
this->klist = klist_in;
1822
this->ekb.create(nk_in, nb_in);
1923
this->wg.create(nk_in, nb_in);
2024
}
@@ -47,26 +51,33 @@ class ElecState
4751
}
4852

4953
// calculate wg from ekb
50-
void calculate_weights(void);
54+
virtual void calculate_weights(void);
5155

52-
Charge *charge;
56+
// pointer to charge density
57+
Charge *charge = nullptr;
58+
// pointer to k points lists
59+
const K_Vectors* klist = nullptr;
5360
// energy for sum of electrons
5461
double eband = 0.0;
5562
// Fermi energy
5663
double ef = 0.0;
64+
// correction energy for metals
65+
double demet = 0.0;
5766

5867
// band energy at each k point, each band.
5968
ModuleBase::matrix ekb;
6069
// occupation weight for each k-point and band
6170
ModuleBase::matrix wg;
6271

72+
std::string classname = "none";
73+
6374
protected:
64-
// calculate ebands for each k point
65-
double eBandK(const int &ik);
75+
// calculate ebands for all k points and all occupied bands
76+
void calEBand();
6677

6778
// print and check for band energy and occupations
6879
void print_band(const int &ik, const int &printe, const int &iter);
6980
};
7081

7182
} // namespace elecstate
72-
#endif
83+
#endif

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void ElecStateLCAO::psiToRho(const psi::Psi<std::complex<double>>& psi)
5959
ModuleBase::TITLE("ElecStateLCAO", "psiToRho");
6060
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
6161

62+
this->calculate_weights();
63+
this->calEBand();
64+
6265
ModuleBase::GlobalFunc::NOTE("Calculate the density matrix.");
6366

6467
// this part for calculating dm_k in 2d-block format, not used for charge now
@@ -109,6 +112,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi<double>& psi)
109112
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
110113

111114
this->calculate_weights();
115+
this->calEBand();
112116

113117
if (GlobalV::KS_SOLVER == "genelpa" || GlobalV::KS_SOLVER == "scalapack_gvx" || GlobalV::KS_SOLVER == "lapack")
114118
{

source/module_elecstate/elecstate_lcao.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ 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;
27+
this->classname = "ElecStateLCAO";
2628
}
2729
// void init(Charge* chg_in):charge(chg_in){} override;
2830

0 commit comments

Comments
 (0)