Skip to content

Commit 34160e6

Browse files
authored
Merge branch 'develop' into ucell20
2 parents ba6a70f + 028e91d commit 34160e6

File tree

39 files changed

+1626
-1695
lines changed

39 files changed

+1626
-1695
lines changed

source/module_basis/module_ao/ORB_read.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void LCAO_Orbitals::init(
8282
this->orbital_file.push_back(orbital_dir + orbital_file[it]);
8383
}
8484
}
85-
85+
this->descriptor_file = descriptor_file;
8686
#ifdef __MPI
8787
bcast_files(ntype, my_rank);
8888
#endif
@@ -263,7 +263,6 @@ void LCAO_Orbitals::Read_Orbitals(std::ofstream& ofs_in,
263263

264264
delete[] this->Alpha;
265265
this->Alpha = new Numerical_Orbital[1]; // not related to atom type -- remain to be discussed
266-
267266
this->Read_Descriptor(ofs_in, force_flag, my_rank);
268267
}
269268

source/module_basis/module_nao/two_center_bundle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void TwoCenterBundle::tabulate()
107107
{
108108
overlap_orb_alpha = std::unique_ptr<TwoCenterIntegrator>(new TwoCenterIntegrator);
109109
overlap_orb_alpha->tabulate(*orb_, *alpha_, 'S', nr, cutoff);
110-
ModuleBase::Memory::record("TwoCenterTable: Descriptor", overlap_orb_beta->table_memory());
110+
ModuleBase::Memory::record("TwoCenterTable: Descriptor", overlap_orb_alpha->table_memory());
111111
}
112112

113113
if (orb_onsite_)

source/module_cell/unitcell.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ void UnitCell::cal_nwfc(std::ofstream& log) {
592592
//========================
593593
this->lmax = 0;
594594
this->nmax = 0;
595+
this->nmax_total = 0;
595596
for (int it = 0; it < ntype; it++) {
596597
lmax = std::max(lmax, atoms[it].nwl);
597598
for (int l = 0; l < atoms[it].nwl + 1; l++) {

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
3737
this->pgrid = &pgrid;
3838

3939
bool read_error = false;
40+
bool read_kin_error = false;
4041
if (PARAM.inp.init_chg == "file" || PARAM.inp.init_chg == "auto")
4142
{
4243
GlobalV::ofs_running << " try to read charge from file" << std::endl;
@@ -101,72 +102,100 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
101102
}
102103
}
103104

104-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
105+
if (read_error)
105106
{
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++)
107+
const std::string warn_msg
108+
= " WARNING: \"init_chg\" is enabled but ABACUS failed to read charge density from file.\n"
109+
" Please check if there is SPINX_CHG.cube (X=1,...) or {suffix}-CHARGE-DENSITY.restart in the "
110+
"directory.\n";
111+
std::cout << std::endl << warn_msg;
112+
if (PARAM.inp.init_chg == "file")
111113
{
112-
kin_g.push_back(kin_g_space.data() + is * this->ngmc);
114+
ModuleBase::WARNING_QUIT("Charge::init_rho",
115+
"Failed to read in charge density from file.\nIf you want to use atomic "
116+
"charge initialization, \nplease set init_chg to atomic in INPUT.");
113117
}
118+
}
114119

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()))
120+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
121+
{
122+
// If the charge density is not read in, then the kinetic energy density is not read in either
123+
if (!read_error)
118124
{
119-
GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str() << std::endl;
120-
for (int is = 0; is < PARAM.inp.nspin; ++is)
125+
GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl;
126+
// try to read charge from binary file first, which is the same as QE
127+
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->ngmc, {0.0, 0.0});
128+
std::vector<std::complex<double>*> kin_g;
129+
for (int is = 0; is < PARAM.inp.nspin; is++)
121130
{
122-
rhopw->recip2real(kin_g[is], this->kin_r[is]);
131+
kin_g.push_back(kin_g_space.data() + is * this->ngmc);
123132
}
124-
}
125-
else
126-
{
127-
for (int is = 0; is < PARAM.inp.nspin; is++)
133+
134+
std::stringstream binary;
135+
binary << PARAM.globalv.global_readin_dir << PARAM.inp.suffix + "-TAU-DENSITY.restart";
136+
if (ModuleIO::read_rhog(binary.str(), rhopw, kin_g.data()))
128137
{
129-
std::stringstream ssc;
130-
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube";
131-
// mohan update 2012-02-10, sunliang update 2023-03-09
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))
138+
GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str() << std::endl;
139+
for (int is = 0; is < PARAM.inp.nspin; ++is)
139140
{
140-
GlobalV::ofs_running << " Read in the kinetic energy density: " << ssc.str() << std::endl;
141+
rhopw->recip2real(kin_g[is], this->kin_r[is]);
141142
}
142143
}
144+
else
145+
{
146+
for (int is = 0; is < PARAM.inp.nspin; is++)
147+
{
148+
std::stringstream ssc;
149+
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube";
150+
// mohan update 2012-02-10, sunliang update 2023-03-09
151+
if (ModuleIO::read_vdata_palgrid(
152+
pgrid,
153+
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
154+
GlobalV::ofs_running,
155+
ssc.str(),
156+
this->kin_r[is],
157+
ucell.nat))
158+
{
159+
GlobalV::ofs_running << " Read in the kinetic energy density: " << ssc.str() << std::endl;
160+
}
161+
else
162+
{
163+
read_kin_error = true;
164+
std::cout << " WARNING: \"init_chg\" is enabled but ABACUS failed to read kinetic energy "
165+
"density from file.\n"
166+
" Please check if there is SPINX_TAU.cube (X=1,...) or "
167+
"{suffix}-TAU-DENSITY.restart in the directory.\n"
168+
<< std::endl;
169+
break;
170+
}
171+
}
172+
}
173+
}
174+
else
175+
{
176+
read_kin_error = true;
143177
}
144178
}
145179
}
146-
if (read_error)
180+
181+
if (PARAM.inp.init_chg == "atomic" || read_error) // mohan add 2007-10-17
147182
{
148-
const std::string warn_msg = " WARNING: \"init_chg\" is enabled but ABACUS failed to read charge density from file.\n"
149-
" Please check if there is SPINX_CHG.cube (X=1,...) or {suffix}-CHARGE-DENSITY.restart in the directory.\n";
150-
std::cout << std::endl << warn_msg;
151-
if (PARAM.inp.init_chg == "auto")
183+
if (read_error)
152184
{
153-
std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl << std::endl;
154-
}
155-
else if (PARAM.inp.init_chg == "file")
156-
{
157-
ModuleBase::WARNING_QUIT("Charge::init_rho", "Failed to read in charge density from file.\nIf you want to use atomic charge initialization, \nplease set init_chg to atomic in INPUT.");
185+
std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl;
158186
}
187+
this->atomic_rho(PARAM.inp.nspin, ucell.omega, rho, strucFac, ucell);
159188
}
160189

161-
if (PARAM.inp.init_chg == "atomic" ||
162-
(PARAM.inp.init_chg == "auto" && read_error)) // mohan add 2007-10-17
190+
// wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi
191+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
163192
{
164-
this->atomic_rho(PARAM.inp.nspin, ucell.omega, rho, strucFac, ucell);
165-
166-
// liuyu 2023-06-29 : move here from atomic_rho(), which will be called several times in charge extrapolation
167-
// wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi
168-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
193+
if (PARAM.inp.init_chg == "atomic" || read_kin_error)
169194
{
195+
if (read_kin_error)
196+
{
197+
std::cout << " Charge::init_rho: init kinetic energy density from rho." << std::endl;
198+
}
170199
const double pi = 3.141592653589790;
171200
const double fact = (3.0 / 5.0) * pow(3.0 * pi * pi, 2.0 / 3.0);
172201
for (int is = 0; is < PARAM.inp.nspin; ++is)

source/module_esolver/esolver_gets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
147147
}
148148

149149
void ESolver_GetS::after_all_runners(UnitCell& ucell) {};
150-
double ESolver_GetS::cal_energy() {};
150+
double ESolver_GetS::cal_energy() { return 0.0; };
151151
void ESolver_GetS::cal_force(UnitCell& ucell, ModuleBase::matrix& force) {};
152152
void ESolver_GetS::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress) {};
153153

source/module_esolver/esolver_ks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ESolver_KS : public ESolver_FP
4343
virtual void iter_init(UnitCell& ucell, const int istep, const int iter);
4444

4545
//! Something to do after hamilt2density function in each iter loop.
46-
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter);
46+
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter) override;
4747

4848
// calculate electron density from a specific Hamiltonian with ethr
4949
virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr);

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
5555
auto* paraV = this->hR->get_paraV(); // get parallel orbitals from HR
5656
// TODO: if paraV is nullptr, AtomPair can not use paraV for constructor, I will repair it in the future.
5757

58-
// this->H_V_delta = new HContainer<TR>(paraV);
58+
this->H_V_delta = new HContainer<TR>(paraV);
5959
if (std::is_same<TK, double>::value)
6060
{
61-
this->H_V_delta = new HContainer<TR>(paraV);
61+
//this->H_V_delta = new HContainer<TR>(paraV);
6262
this->H_V_delta->fix_gamma();
6363
}
6464

@@ -123,10 +123,10 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
123123
R_index2.y - R_index1.y,
124124
R_index2.z - R_index1.z,
125125
paraV);
126-
if (std::is_same<TK, double>::value)
127-
{
128-
this->H_V_delta->insert_pair(tmp);
129-
}
126+
// if (std::is_same<TK, double>::value)
127+
// {
128+
this->H_V_delta->insert_pair(tmp);
129+
// }
130130
}
131131
}
132132
if (pre_cal_nlm)
@@ -135,15 +135,14 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
135135
}
136136
}
137137
// allocate the memory of BaseMatrix in HR, and set the new values to zero
138-
if (std::is_same<TK, double>::value)
139-
{
140-
// only gamma-only has full size of Hamiltonian of DeePKS now,
141-
// multi-k keep same size of nonlocal operator, H_V_delta will be allocated by hR
142-
this->H_V_delta->allocate(nullptr, true);
143-
// expand hR with H_V_delta, only gamma-only case now
144-
this->hR->add(*this->H_V_delta);
145-
this->hR->allocate(nullptr, false);
146-
}
138+
// if (std::is_same<TK, double>::value)
139+
// {
140+
this->H_V_delta->allocate(nullptr, true);
141+
// expand hR with H_V_delta
142+
// update : for computational rigor, gamma-only and multi-k cases both have full size of Hamiltonian of DeePKS now
143+
this->hR->add(*this->H_V_delta);
144+
this->hR->allocate(nullptr, false);
145+
// }
147146

148147
ModuleBase::timer::tick("DeePKS", "initialize_HR");
149148
}
@@ -165,11 +164,11 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
165164
GlobalC::ld.cal_descriptor(this->ucell->nat);
166165
GlobalC::ld.cal_gedm(this->ucell->nat);
167166

168-
// recalculate the H_V_delta
169-
if (this->H_V_delta == nullptr)
170-
{
171-
this->H_V_delta = new hamilt::HContainer<TR>(*this->hR);
172-
}
167+
// // recalculate the H_V_delta
168+
// if (this->H_V_delta == nullptr)
169+
// {
170+
// this->H_V_delta = new hamilt::HContainer<std::complex<double>>(*this->hR);
171+
// }
173172
this->H_V_delta->set_zero();
174173
this->calculate_HR();
175174

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DeePKS<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
6161
// LCAO_Deepks* ld = nullptr;
6262

6363
const UnitCell* ucell = nullptr;
64+
Grid_Driver* gridD = nullptr;
6465

6566
const Grid_Driver* gd = nullptr;
6667

source/module_hamilt_lcao/module_deepks/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ if(ENABLE_DEEPKS)
3030
endif()
3131

3232
# I will rewrite the test later, the current test rely on too many modules
33-
# if(BUILD_TESTING)
34-
# add_subdirectory(test)
35-
# endif()
33+
if(BUILD_TESTING)
34+
add_subdirectory(test)
35+
endif()
3636
endif()
3737

source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void LCAO_Deepks::cal_projected_DM(const elecstate::DensityMatrix<TK, double>* d
379379

380380
void LCAO_Deepks::check_projected_dm()
381381
{
382-
const std::string file_projdm = PARAM.globalv.global_out_dir + "deepks_projdm.dat";
382+
const std::string file_projdm = PARAM.globalv.global_out_dir + "pdm.dat";
383383
std::ofstream ofs(file_projdm.c_str());
384384

385385
ofs << std::setprecision(10);

0 commit comments

Comments
 (0)