Skip to content

Commit d061719

Browse files
authored
Restore deepks unit test in gamma-only case and make H_V_delta have full size of Hamiltonian in multi-k case (#5785)
* renew deepks unit test * renew deepks unit test * reduce deepks-unitest's dependence on other modules * fix the bug of "Couldn't find orbital files for descriptor" * fix bugs of read orbitals and init orb&ParaO * fix the bug of DMR ; change the names of files being compared * fix: calculate H_V_delta * fix : cal_H_V_delta for check_e_deltabands * fix : Add pointer for GridD in deepks operator. use Test_Deepks::GridD in deepks unit test instead of GlobalC::GridD * fix : modify deepks operator to support insert_pair in initilize_HR in multi-k * fix : undefined reference of test_hsolver_sdft when using mpiicpx and icpx * update intergrate test result. Note modification in deepks operator for complete atom_pairs will cause time increase in multi-k cases. * remove some useless code * remove nnr in deepks unittest * fix: cutoff for overlap_orb_alpha_ in deepks test * fix : psialpha ref of gamma only case , just change the order of neighour atoms * fix uninitilized nmax_total in unitcell; simplize cal_descriptor * restore deepks unit test in gamma-only case * modify STRU of SiO2 in deepks test to reduce the number of neighbor atoms, thus reducing much time * fix a bug when merge * fix : setup nonlocal for ucell * rename phialpha_ref.dat for multi-k * modify STRU of H2O_multik in deepks test to reduce the number of neighbor atoms, thus reducing much time * fix : add module paw dependence in deepks unittest * fix : rename descriptor file * fix : modify result.ref for SiO2. The privious modification don't change totaldes wrongly. * update CMakeLists.txt
1 parent 7d14803 commit d061719

File tree

33 files changed

+1535
-1639
lines changed

33 files changed

+1535
-1639
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
@@ -651,6 +651,7 @@ void UnitCell::cal_nwfc(std::ofstream& log) {
651651
//========================
652652
this->lmax = 0;
653653
this->nmax = 0;
654+
this->nmax_total = 0;
654655
for (int it = 0; it < ntype; it++) {
655656
lmax = std::max(lmax, atoms[it].nwl);
656657
for (int l = 0; l < atoms[it].nwl + 1; l++) {

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);

source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
add_executable(
22
test_deepks
3-
main_deepks.cpp klist_1.cpp LCAO_deepks_test_prep.cpp LCAO_deepks_test.cpp nnr.cpp
3+
main_deepks.cpp klist_1.cpp LCAO_deepks_test_prep.cpp LCAO_deepks_test.cpp
4+
../../../module_cell/unitcell.cpp
5+
../../../module_cell/update_cell.cpp
6+
../../../module_cell/bcast_cell.cpp
7+
../../../module_cell/atom_spec.cpp
8+
../../../module_cell/atom_pseudo.cpp
9+
../../../module_cell/read_atoms.cpp
10+
../../../module_cell/setup_nonlocal.cpp
11+
../../../module_cell/pseudo.cpp
12+
../../../module_cell/read_pp.cpp
13+
../../../module_cell/read_pp_complete.cpp
14+
../../../module_cell/read_pp_upf100.cpp
15+
../../../module_cell/read_pp_upf201.cpp
16+
../../../module_cell/read_pp_vwr.cpp
17+
../../../module_cell/read_pp_blps.cpp
18+
../../../module_hamilt_pw/hamilt_pwdft/soc.cpp
19+
../../../module_io/output.cpp
20+
../../../module_elecstate/read_pseudo.cpp
21+
../../../module_elecstate/cal_nelec_nband.cpp
22+
../../../module_elecstate/module_dm/density_matrix.cpp
23+
../../../module_elecstate/module_dm/density_matrix_io.cpp
24+
../../../module_hamilt_lcao/module_hcontainer/base_matrix.cpp
25+
../../../module_hamilt_lcao/module_hcontainer/hcontainer.cpp
26+
../../../module_hamilt_lcao/module_hcontainer/atom_pair.cpp
27+
../../../module_hamilt_lcao/module_hcontainer/func_transfer.cpp
28+
../../../module_hamilt_lcao/module_hcontainer/func_folding.cpp
29+
../../../module_hamilt_lcao/module_hcontainer/transfer.cpp
30+
../../../module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp
31+
../../../module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp
32+
../../../module_hamilt_general/operator.cpp
433
)
534

6-
if(ENABLE_COVERAGE)
7-
add_coverage(test_deepks)
8-
endif()
9-
10-
get_target_property(ABACUS_LINK_LIBRARIES ${ABACUS_BIN_NAME} LINK_LIBRARIES)
1135
target_link_libraries(
1236
test_deepks
13-
base cell symmetry md surchem xc_
14-
neighbor orb io_basic io_advanced relax gint driver esolver hsolver psi elecstate
15-
hamilt_general hamilt_pwdft hamilt_lcao tddft hamilt_ofdft hamilt_stodft planewave
16-
pthread vdw dftu deltaspin hcontainer
17-
deepks device numerical_atomic_orbitals container psi_initializer psi_overall_init
18-
${ABACUS_LINK_LIBRARIES}
37+
base device parameter deepks psi planewave neighbor container
38+
orb gint numerical_atomic_orbitals paw
39+
${math_libs}
1940
)
2041

21-
if(ENABLE_PAW)
22-
target_link_libraries(
23-
test_deepks
24-
paw
25-
)
26-
endif()
27-
28-
if(USE_ELPA)
29-
target_link_libraries(
30-
test_deepks
31-
genelpa
32-
)
33-
endif()
34-
if(USE_CUDA)
35-
target_link_libraries(diag_cusolver)
42+
if(ENABLE_COVERAGE)
43+
add_coverage(test_deepks)
3644
endif()
3745

38-
if (ENABLE_LIBRI)
39-
target_link_libraries(test_deepks
40-
ri)
41-
endif()
4246

4347
install(
4448
TARGETS test_deepks

0 commit comments

Comments
 (0)