Skip to content

Commit 8cc9014

Browse files
committed
Feature: support user defined precision of elf
1 parent 1cd4fc8 commit 8cc9014

File tree

11 files changed

+31
-21
lines changed

11 files changed

+31
-21
lines changed

source/module_elecstate/elecstate_pw.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ElecStatePW<T, Device>::~ElecStatePW()
3434
if (base_device::get_device_type<Device>(this->ctx) == base_device::GpuDevice)
3535
{
3636
delmem_var_op()(this->ctx, this->rho_data);
37-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf)
37+
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
3838
{
3939
delmem_var_op()(this->ctx, this->kin_r_data);
4040
}
@@ -53,7 +53,7 @@ void ElecStatePW<T, Device>::init_rho_data()
5353
for (int ii = 0; ii < this->charge->nspin; ii++) {
5454
this->rho[ii] = this->rho_data + ii * this->charge->nrxx;
5555
}
56-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf)
56+
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
5757
{
5858
this->kin_r = new Real*[this->charge->nspin];
5959
resmem_var_op()(this->ctx, this->kin_r_data, this->charge->nspin * this->charge->nrxx);
@@ -64,7 +64,7 @@ void ElecStatePW<T, Device>::init_rho_data()
6464
}
6565
else {
6666
this->rho = reinterpret_cast<Real **>(this->charge->rho);
67-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf)
67+
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
6868
{
6969
this->kin_r = reinterpret_cast<Real **>(this->charge->kin_r);
7070
}

source/module_elecstate/module_charge/charge.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void Charge::destroy()
8080
delete[] _space_rhog_save;
8181
delete[] _space_kin_r;
8282
delete[] _space_kin_r_save;
83-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
83+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
8484
{
8585
delete[] kin_r;
8686
delete[] kin_r_save;
@@ -121,7 +121,7 @@ void Charge::allocate(const int& nspin_in)
121121
_space_rho_save = new double[nspin * nrxx];
122122
_space_rhog = new std::complex<double>[nspin * ngmc];
123123
_space_rhog_save = new std::complex<double>[nspin * ngmc];
124-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
124+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
125125
{
126126
_space_kin_r = new double[nspin * nrxx];
127127
_space_kin_r_save = new double[nspin * nrxx];
@@ -130,7 +130,7 @@ void Charge::allocate(const int& nspin_in)
130130
rhog = new std::complex<double>*[nspin];
131131
rho_save = new double*[nspin];
132132
rhog_save = new std::complex<double>*[nspin];
133-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
133+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
134134
{
135135
kin_r = new double*[nspin];
136136
kin_r_save = new double*[nspin];
@@ -151,7 +151,7 @@ void Charge::allocate(const int& nspin_in)
151151
ModuleBase::GlobalFunc::ZEROS(rhog[is], ngmc);
152152
ModuleBase::GlobalFunc::ZEROS(rho_save[is], nrxx);
153153
ModuleBase::GlobalFunc::ZEROS(rhog_save[is], ngmc);
154-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
154+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
155155
{
156156
kin_r[is] = _space_kin_r + is * nrxx;
157157
ModuleBase::GlobalFunc::ZEROS(kin_r[is], nrxx);
@@ -171,7 +171,7 @@ void Charge::allocate(const int& nspin_in)
171171
ModuleBase::Memory::record("Chg::rho_save", sizeof(double) * nspin * nrxx);
172172
ModuleBase::Memory::record("Chg::rhog", sizeof(double) * nspin * ngmc);
173173
ModuleBase::Memory::record("Chg::rhog_save", sizeof(double) * nspin * ngmc);
174-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
174+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
175175
{
176176
ModuleBase::Memory::record("Chg::kin_r", sizeof(double) * nspin * ngmc);
177177
ModuleBase::Memory::record("Chg::kin_r_save", sizeof(double) * nspin * ngmc);

source/module_elecstate/module_charge/charge_mpi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void Charge::rho_mpi()
132132
for (int is = 0; is < PARAM.inp.nspin; ++is)
133133
{
134134
reduce_diff_pools(this->rho[is]);
135-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf)
135+
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
136136
{
137137
reduce_diff_pools(this->kin_r[is]);
138138
}

source/module_esolver/esolver_fp.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void ESolver_FP::after_scf(const int istep)
256256
}
257257

258258
// 5) write ELF
259-
if (PARAM.inp.out_elf)
259+
if (PARAM.inp.out_elf[0] > 0)
260260
{
261261
this->pelec->charge->cal_elf = true;
262262
Symmetry_rho srho;
@@ -277,7 +277,8 @@ void ESolver_FP::after_scf(const int istep)
277277
this->pelec->charge->rho,
278278
this->pelec->charge->kin_r,
279279
this->pw_rhod,
280-
&(GlobalC::ucell));
280+
&(GlobalC::ucell),
281+
PARAM.inp.out_elf[1]);
281282
}
282283
}
283284

source/module_esolver/esolver_ks_lcao.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
10971097
{
10981098
ModuleBase::TITLE("ESolver_KS_LCAO", "after_scf");
10991099
// 1) calculate the kinetic energy density tau, sunliang 2024-09-18
1100-
if (PARAM.inp.out_elf)
1100+
if (PARAM.inp.out_elf[0] > 0)
11011101
{
11021102
this->pelec->cal_tau(*(this->psi));
11031103
}

source/module_esolver/esolver_ks_pw.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ template <typename T, typename Device>
539539
void ESolver_KS_PW<T, Device>::after_scf(const int istep)
540540
{
541541
// 1) calculate the kinetic energy density tau, sunliang 2024-09-18
542-
if (PARAM.inp.out_elf)
542+
if (PARAM.inp.out_elf[0] > 0)
543543
{
544544
this->pelec->cal_tau(*(this->psi));
545545
}

source/module_esolver/esolver_of.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ bool ESolver_OF::check_exit()
511511
void ESolver_OF::after_opt(const int istep, UnitCell& ucell)
512512
{
513513
// 1) calculate the kinetic energy density
514-
if (PARAM.inp.out_elf)
514+
if (PARAM.inp.out_elf[0] > 0)
515515
{
516516
this->kinetic_energy_density(this->pelec->charge->rho, this->pphi_, this->pelec->charge->kin_r);
517517
}

source/module_io/read_input_item_output.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,22 @@ void ReadInput::item_output()
494494
}
495495
{
496496
Input_Item item("out_elf");
497-
item.annotation = "output electron localization function (ELF)";
498-
read_sync_bool(input.out_elf);
497+
item.annotation = "> 0 output electron localization function (ELF) for selected electron steps"
498+
", second parameter controls the precision, default is 3.";
499+
item.read_value = [](const Input_Item& item, Parameter& para) {
500+
size_t count = item.get_size();
501+
std::vector<int> out_elf(count); // create a placeholder vector
502+
std::transform(item.str_values.begin(), item.str_values.end(), out_elf.begin(), [](std::string s) { return std::stoi(s); });
503+
// assign non-negative values to para.input.out_elf
504+
std::copy(out_elf.begin(), out_elf.end(), para.input.out_elf.begin());
505+
};
499506
item.check_value = [](const Input_Item& item, const Parameter& para) {
500-
if (para.input.out_elf && para.input.esolver_type != "ksdft" && para.input.esolver_type != "ofdft")
507+
if (para.input.out_elf[0] > 0 && para.input.esolver_type != "ksdft" && para.input.esolver_type != "ofdft")
501508
{
502509
ModuleBase::WARNING_QUIT("ReadInput", "ELF is only aviailable for ksdft and ofdft");
503510
}
504511
};
512+
sync_intvec(input.out_elf, 2, 0);
505513
this->add_item(item);
506514
}
507515
}

source/module_io/write_elf.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ void write_elf(
1414
const double* const* rho,
1515
const double* const* tau,
1616
ModulePW::PW_Basis* rho_basis,
17-
const UnitCell* ucell_)
17+
const UnitCell* ucell_,
18+
const int& precision)
1819
{
1920
std::vector<std::vector<double>> elf(nspin, std::vector<double>(rho_basis->nrxx, 0.));
2021
// 1) calculate the kinetic energy density of vW KEDF
@@ -78,7 +79,6 @@ void write_elf(
7879
}
7980

8081
// 4) output the ELF = 1 / (1 + F^2) to cube file
81-
int precision = 9;
8282
double ef_tmp = 0.0;
8383
int out_fermi = 0;
8484

source/module_io/write_elf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ void write_elf(
1818
const double* const* rho,
1919
const double* const* tau,
2020
ModulePW::PW_Basis* rho_basis,
21-
const UnitCell* ucell_);
21+
const UnitCell* ucell_,
22+
const int& precision);
2223
}
2324

2425
#endif

source/module_parameter/input_parameter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ struct Input_para
356356
int nbands_istate = 5; ///< number of bands around fermi level for get_pchg calculation.
357357
std::vector<int> bands_to_print = {}; ///< specify the bands to be calculated in the get_pchg
358358
bool if_separate_k = false; ///< whether to write partial charge for all k-points to individual files or merge them
359-
bool out_elf = false; ///< output the electron localization function (ELF)
359+
std::vector<int> out_elf = {0, 3}; ///< output the electron localization function (ELF). 0: no; 1: yes
360360

361361
// ============== #Parameters (12.Postprocess) ===========================
362362
double dos_emin_ev = -15.0;

0 commit comments

Comments
 (0)