Skip to content

Commit 7ae18a5

Browse files
authored
Feature: enable init_chg=file for metagga (#5792)
* Feature: enable init_chg=file for metagga * Tests: decrease the size of charge file
1 parent 3a2eb06 commit 7ae18a5

File tree

9 files changed

+43
-17
lines changed

9 files changed

+43
-17
lines changed

source/module_elecstate/module_charge/charge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Charge
145145

146146
// mohan add 2021-02-20
147147
int nrxx=0; // number of r vectors in this processor
148-
int nxyz=0; // total nuber of r vectors
148+
int nxyz = 0; // total number of r vectors
149149
int ngmc=0; // number of g vectors in this processor
150150
int nspin=0; // number of spins
151151
ModulePW::PW_Basis* rhopw = nullptr;// When double_grid is used, rhopw = rhodpw (dense grid)

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
3939
bool read_error = false;
4040
if (PARAM.inp.init_chg == "file" || PARAM.inp.init_chg == "auto")
4141
{
42-
GlobalV::ofs_running << " try to read charge from file : " << std::endl;
42+
GlobalV::ofs_running << " try to read charge from file" << std::endl;
4343

4444
// try to read charge from binary file first, which is the same as QE
4545
// liuyu 2023-12-05
@@ -99,22 +99,43 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
9999
break;
100100
}
101101
}
102+
}
103+
104+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
105+
{
106+
GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl;
107+
// try to read charge from binary file first, which is the same as QE
108+
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->ngmc, {0.0, 0.0});
109+
std::vector<std::complex<double>*> kin_g;
110+
for (int is = 0; is < PARAM.inp.nspin; is++)
111+
{
112+
kin_g.push_back(kin_g_space.data() + is * this->ngmc);
113+
}
102114

103-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
115+
std::stringstream binary;
116+
binary << PARAM.globalv.global_readin_dir << PARAM.inp.suffix + "-TAU-DENSITY.restart";
117+
if (ModuleIO::read_rhog(binary.str(), rhopw, kin_g.data()))
118+
{
119+
GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str() << std::endl;
120+
for (int is = 0; is < PARAM.inp.nspin; ++is)
121+
{
122+
rhopw->recip2real(kin_g[is], this->kin_r[is]);
123+
}
124+
}
125+
else
104126
{
105127
for (int is = 0; is < PARAM.inp.nspin; is++)
106128
{
107129
std::stringstream ssc;
108130
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube";
109-
GlobalV::ofs_running << " try to read kinetic energy density from file : " << ssc.str()
110-
<< std::endl;
111131
// mohan update 2012-02-10, sunliang update 2023-03-09
112-
if (ModuleIO::read_vdata_palgrid(pgrid,
113-
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
114-
GlobalV::ofs_running,
115-
ssc.str(),
116-
this->kin_r[is],
117-
ucell.nat))
132+
if (ModuleIO::read_vdata_palgrid(
133+
pgrid,
134+
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
135+
GlobalV::ofs_running,
136+
ssc.str(),
137+
this->kin_r[is],
138+
ucell.nat))
118139
{
119140
GlobalV::ofs_running << " Read in the kinetic energy density: " << ssc.str() << std::endl;
120141
}

tests/integrate/101_PW_15_f_pseudopots/INPUT

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
INPUT_PARAMETERS
22
#Parameters (1.General)
33
suffix autotest
4-
calculation scf
4+
calculation scf
5+
dft_functional scan
56

67
nbands 8
78
symmetry 1
@@ -23,3 +24,5 @@ smearing_sigma 0.002
2324
mixing_type broyden
2425
mixing_beta 0.7
2526

27+
init_chg file
28+
read_file_dir .

tests/integrate/101_PW_15_f_pseudopots/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ This test for:
33
*SG15 pseudopotential containing f electron
44
*mixing_type broyden
55
*mixing_beta 0.7
6+
*dft_functional scan
7+
*init_chg file

tests/integrate/101_PW_15_f_pseudopots/STRU

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ATOMIC_SPECIES
22
Ce 140.115 58_Ce.UPF upf201
33

44
LATTICE_CONSTANT
5-
8.92
5+
6
66

77
LATTICE_VECTORS
88
0.5 0.5 0.0
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test SG15 pseudopotential containing f electron, symmetry=on
1+
test SG15 pseudopotential containing f electron with scan, symmetry=on, init_chg=file
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
etotref -3436.745619582930
2-
etotperatomref -3436.7456195829
1+
etotref -3644.833836110242
2+
etotperatomref -3644.8338361102
33
pointgroupref O_h
44
spacegroupref O_h
55
nksibzref 3
6-
totaltimeref 0.16141
6+
totaltimeref 0.33

0 commit comments

Comments
 (0)