Skip to content

Commit 4356f9f

Browse files
mohanchenmaki49
andauthored
LCAO refactor step 4 (#3921)
* update timer, add std * update the format of esolver_fp.cpp * add description in esolver_fp.h * update a few esolver files * update esolver description for LCAO * update some formats of esolver codes * update esolver_ks_pw.cpp formats * update formats of esolver_ks_pw.cpp and esolver_ks_pw.h * update esolver_ks_lcao_tddft.cpp formats * update format of esolver_sdft_pw.cpp * update the format of esolver_sdft_pw_tool.cpp * keep formating esolver_ks_pw.cpp * formating esolver_of_interface.cpp * change GlobalC::ucell to ucell in esolver_ks.cpp * remove some GlobalC::ucell in esolver_sdft_pw.cpp * refactor the code before getting rid of RA in esolver_lcao * refactor before getting rid of LOWF * refactor before getting rid of LCAO_hamilt.h and LCAO_matrix.h * refactor wavefunc_in_pw * refactor density matrix * refactor the format cal_dm_psi.cpp * format forces.cpp * refactor esolver_of_tool.cpp * change member function beforescf in Esolver to before_scf * change afterscf to after_scf * change updatepot to update_pot * change eachiterinit to iter_init, change eachiterfinish to iter_finish * refactor esolvers, change member function names of most esolvers * reformat esolver.h * update tests for esolvers * add TITLE in esolver_ks_lcao * update esolver_ks_lcao * update esolver_lcao * update timer::tick in esolver_lcao * try to delete LCAO_Matrix in LCAO_Hamilt, and try to delete Parallel_Orbitals in Force_k * fix the compiling issue with LCAO_hamilt.hpp * try to divide the FORCE_k.cpp into several small files * divide FORCE_k into foverlap_k.cpp ftvnl_dphi_k.cpp fvl_dphi_k.cpp fvnl_dbeta_k.cpp four files * get rid of UHM in FORCE_k.cpp * cannot compile, but I have modified some files in order to get rid of Gint_k and Gint_Gamma in UHM * keep updating, cannot run * update write_Vxc, cannot run yet * keep updating gint_gamma and gint_k * update LCAO_matrix.cpp * divide force files, and update Makefile.Objects * update LCAO_hamilt.cpp * delete genH pointer in UHM * divide LCAO_hamilt.cpp into small codes, grid_init.cpp is the first one * update grid_init in esolver_ks_lcao * add a new namespace named sparse_format, most of the functions that originally belong to LCAO_hamilt should be moved to sparse_format * cannot find the mismatch of DFTU * fix the DFTU error * update * enable the test_memory function again by setting calcalculation parameter in INPUT file * update memory record functions * add sparse_format_u * keep refactoring LCAO_hamilt * rename sparse format files, which are originally defined in LCAO_hamilt.h * add spar_u.h and spar_u.cpp * update sparse matrix * add spar_exx * update LCAO_hamilt.cpp * tear down LCAO_hamilt.h and .cpp, DONE. * keep updating spar * fix the bugs after deleting LCAO_hamilt * continue * fix some errors when compiling * fix compiling errors in DOS * fix errors without uhm * remove directly use of LM in spar_hsr.cpp * update spa_ files * keep cleaning the mass left by UHM * finnaly, all files can be compiled without uhm * previous commit has problems, now it has been fixed. * fix makefile bugs * fix exx compiling errors * fix exx problems * update exx * fix exx * in some sense, the exx code is a disaster * let's fix exx again * fix undefination * fix a bug in LCAO Refactor Step 4, I accidently forgot to add & for Grid_Driver& _grid in output_mat_sparse.h --------- Co-authored-by: maki49 <[email protected]>
1 parent 3d1ad16 commit 4356f9f

Some content is hidden

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

45 files changed

+1564
-1137
lines changed

source/Makefile.Objects

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,12 @@ OBJS_LCAO=DM_gamma.o\
501501
fvl_dphi_k.o\
502502
fvnl_dbeta_k.o\
503503
LCAO_gen_fixedH.o\
504-
LCAO_hamilt.o\
505504
grid_init.o\
506-
sparse_format.o\
505+
spar_dh.o\
506+
spar_exx.o\
507+
spar_hsr.o\
508+
spar_st.o\
509+
spar_u.o\
507510
LCAO_matrix.o\
508511
LCAO_nnr.o\
509512
center2_orb-orb11.o\

source/module_elecstate/elecstate_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ElecStateLCAO : public ElecState
2121
Local_Orbital_Charge* loc_in ,
2222
Gint_Gamma* gint_gamma_in, //mohan add 2024-04-01
2323
Gint_k* gint_k_in, //mohan add 2024-04-01
24-
LCAO_Hamilt* uhm_in ,
2524
Local_Orbital_wfc* lowf_in ,
2625
ModulePW::PW_Basis* rhopw_in ,
2726
ModulePW::PW_Basis_Big* bigpw_in )
@@ -77,7 +76,6 @@ class ElecStateLCAO : public ElecState
7776
Local_Orbital_Charge* loc = nullptr;
7877
Gint_Gamma* gint_gamma = nullptr; // mohan add 2024-04-01
7978
Gint_k* gint_k = nullptr; // mohan add 2024-04-01
80-
//LCAO_Hamilt* uhm = nullptr; // mohan modify 2024-04-01
8179
Local_Orbital_wfc* lowf = nullptr;
8280
DensityMatrix<TK,double>* DM = nullptr;
8381

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ void ESolver_KS_LCAO<TK, TR>::init(Input& inp, UnitCell& ucell)
117117
&(this->LOC),
118118
&(this->GG), // mohan add 2024-04-01
119119
&(this->GK), // mohan add 2024-04-01
120-
&(this->uhm),
121120
&(this->LOWF),
122121
this->pw_rho,
123122
this->pw_big);
@@ -131,7 +130,7 @@ void ESolver_KS_LCAO<TK, TR>::init(Input& inp, UnitCell& ucell)
131130
//------------------init Basis_lcao----------------------
132131

133132
//! pass Hamilt-pointer to Operator
134-
this->gen_h.LM = this->uhm.LM = &this->LM;
133+
this->gen_h.LM = &this->LM;
135134

136135
//! pass basis-pointer to EState and Psi
137136
this->LOC.ParaV = this->LOWF.ParaV = this->LM.ParaV = &(this->orb_con.ParaV);
@@ -259,7 +258,6 @@ void ESolver_KS_LCAO<TK, TR>::init_after_vc(Input& inp, UnitCell& ucell)
259258
&(this->LOC),
260259
&(this->GG), // mohan add 2024-04-01
261260
&(this->GK), // mohan add 2024-04-01
262-
&(this->uhm),
263261
&(this->LOWF),
264262
this->pw_rho,
265263
this->pw_big);
@@ -426,7 +424,7 @@ void ESolver_KS_LCAO<TK, TR>::post_process(void)
426424
{
427425
ModuleIO::write_proj_band_lcao(
428426
this->psi,
429-
this->uhm,
427+
this->LM,
430428
this->pelec,
431429
this->kv,
432430
GlobalC::ucell,
@@ -437,7 +435,8 @@ void ESolver_KS_LCAO<TK, TR>::post_process(void)
437435
{
438436
ModuleIO::out_dos_nao(
439437
this->psi,
440-
this->uhm,
438+
this->LM,
439+
this->orb_con.ParaV,
441440
this->pelec->ekb,
442441
this->pelec->wg,
443442
INPUT.dos_edelta_ev,
@@ -1204,10 +1203,10 @@ ModuleIO::Output_Mat_Sparse<TK> ESolver_KS_LCAO<TK, TR>::create_Output_Mat_Spars
12041203
istep,
12051204
this->pelec->pot->get_effective_v(),
12061205
*this->LOWF.ParaV,
1207-
this->uhm,
1208-
this->gen_h, // mohan add 2024-04-02
1206+
this->gen_h, // mohan add 2024-04-06
12091207
this->GK, // mohan add 2024-04-01
12101208
this->LM,
1209+
GlobalC::GridD, // mohan add 2024-04-06
12111210
this->kv,
12121211
this->p_hamilt);
12131212
}

source/module_esolver/esolver_ks_lcao.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h"
66
#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h"
77
#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h"
8-
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h"
98
// for grid integration
109
#include "module_hamilt_lcao/module_gint/gint_gamma.h"
1110
#include "module_hamilt_lcao/module_gint/gint_k.h"
@@ -76,9 +75,6 @@ namespace ModuleESolver
7675
// we will get rid of this class soon, don't use it, mohan 2024-03-28
7776
Local_Orbital_Charge LOC;
7877

79-
// we will get rid of this class soon, don't use it, mohan 2024-03-28
80-
LCAO_Hamilt uhm;
81-
8278
LCAO_gen_fixedH gen_h; // mohan add 2024-04-02
8379

8480
// used for k-dependent grid integration.
@@ -106,6 +102,7 @@ namespace ModuleESolver
106102
//--------------common for all calculation, not only scf-------------
107103
// set matrix and grid integral
108104
void set_matrix_grid(Record_adj& ra);
105+
109106
void beforesolver(const int istep);
110107
//----------------------------------------------------------------------
111108

@@ -127,11 +124,15 @@ namespace ModuleESolver
127124
std::shared_ptr<Exx_LRI<double>> exx_lri_double = nullptr;
128125
std::shared_ptr<Exx_LRI<std::complex<double>>> exx_lri_complex = nullptr;
129126
#endif
127+
130128
private:
129+
131130
// tmp interfaces before sub-modules are refactored
132131
void dftu_cal_occup_m(const int& iter, const std::vector<std::vector<TK>>& dm) const;
132+
133133
#ifdef __DEEPKS
134134
void dpks_cal_e_delta_band(const std::vector<std::vector<TK>>& dm) const;
135+
135136
void dpks_cal_projected_DM(const elecstate::DensityMatrix<TK, double>* dm) const;
136137
#endif
137138

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ void ESolver_KS_LCAO<std::complex<double>, double>::get_S(void)
494494
dynamic_cast<hamilt::OperatorLCAO<std::complex<double>, double>*>(this->p_hamilt->ops)->contributeHR();
495495
}
496496

497-
ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr");
497+
ModuleIO::output_SR(orb_con.ParaV, this->LM, GlobalC::GridD, this->p_hamilt, "SR.csr");
498+
499+
return;
498500
}
499501

500502

@@ -525,7 +527,10 @@ void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::get_S(void)
525527
dynamic_cast<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>*>(this->p_hamilt->ops)
526528
->contributeHR();
527529
}
528-
ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr");
530+
531+
ModuleIO::output_SR(orb_con.ParaV, this->LM, GlobalC::GridD, this->p_hamilt, "SR.csr");
532+
533+
return;
529534
}
530535

531536

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void ESolver_KS_LCAO_TDDFT::init(Input& inp, UnitCell& ucell)
100100
//------------------init Hamilt_lcao----------------------
101101

102102
// pass Hamilt-pointer to Operator
103-
this->gen_h.LM = this->uhm.LM = &this->LM;
103+
this->gen_h.LM = &this->LM;
104104
// pass basis-pointer to EState and Psi
105105
this->LOC.ParaV = this->LOWF.ParaV = this->LM.ParaV;
106106

source/module_esolver/esolver_ks_lcao_tddft.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "esolver_ks_lcao.h"
55
#include "module_basis/module_ao/ORB_control.h"
66
#include "module_psi/psi.h"
7-
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h"
87
#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h"
98
#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h"
109
#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h"

source/module_esolver/esolver_ks_lcao_tmpfunc.cpp

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,111 @@
44
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
55
#include "module_hamilt_pw/hamilt_pwdft/global.h"
66
#endif
7+
78
namespace ModuleESolver
89
{
10+
11+
using namespace std;
12+
13+
//! dftu occupation matrix for gamma only using dm(double)
914
template <>
10-
void ESolver_KS_LCAO<double, double>::dftu_cal_occup_m(const int& iter, const std::vector<std::vector<double>>& dm)const
15+
void ESolver_KS_LCAO<double, double>::dftu_cal_occup_m(
16+
const int& iter,
17+
const vector<vector<double>>& dm)const
1118
{
12-
GlobalC::dftu.cal_occup_m_gamma(iter, dm, this->p_chgmix->get_mixing_beta());
19+
GlobalC::dftu.cal_occup_m_gamma(
20+
iter,
21+
dm,
22+
this->p_chgmix->get_mixing_beta());
1323
}
1424

25+
//! dftu occupation matrix for multiple k-points using dm(complex)
1526
template <>
16-
void ESolver_KS_LCAO<std::complex<double>, double>::dftu_cal_occup_m(const int& iter, const std::vector<std::vector<std::complex<double>>>& dm)const
27+
void ESolver_KS_LCAO<complex<double>, double>::dftu_cal_occup_m(
28+
const int& iter,
29+
const vector<vector<complex<double>>>& dm)const
1730
{
18-
GlobalC::dftu.cal_occup_m_k(iter, dm, this->kv, this->p_chgmix->get_mixing_beta(), this->p_hamilt);
31+
GlobalC::dftu.cal_occup_m_k(
32+
iter,
33+
dm,
34+
this->kv,
35+
this->p_chgmix->get_mixing_beta(),
36+
this->p_hamilt);
1937
}
38+
39+
//! dftu occupation matrix
2040
template <>
21-
void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::dftu_cal_occup_m(const int& iter, const std::vector<std::vector<std::complex<double>>>& dm)const
41+
void ESolver_KS_LCAO<complex<double>, complex<double>>::dftu_cal_occup_m(
42+
const int& iter,
43+
const vector<vector<complex<double>>>& dm)const
2244
{
23-
GlobalC::dftu.cal_occup_m_k(iter, dm, this->kv, this->p_chgmix->get_mixing_beta(), this->p_hamilt);
45+
GlobalC::dftu.cal_occup_m_k(
46+
iter,
47+
dm,
48+
this->kv,
49+
this->p_chgmix->get_mixing_beta(),
50+
this->p_hamilt);
2451
}
52+
2553
#ifdef __DEEPKS
2654
template<>
27-
void ESolver_KS_LCAO<double, double>::dpks_cal_e_delta_band(const std::vector<std::vector<double>>& dm)const
55+
void ESolver_KS_LCAO<double, double>::dpks_cal_e_delta_band(
56+
const vector<vector<double>>& dm)const
2857
{
2958
GlobalC::ld.cal_e_delta_band(dm);
3059
}
60+
61+
3162
template<>
32-
void ESolver_KS_LCAO<std::complex<double>, double>::dpks_cal_e_delta_band(const std::vector<std::vector<std::complex<double>>>& dm)const
63+
void ESolver_KS_LCAO<complex<double>, double>::dpks_cal_e_delta_band(
64+
const vector<vector<complex<double>>>& dm)const
3365
{
3466
GlobalC::ld.cal_e_delta_band_k(dm, this->kv.nks);
3567
}
68+
69+
3670
template<>
37-
void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::dpks_cal_e_delta_band(const std::vector<std::vector<std::complex<double>>>& dm)const
71+
void ESolver_KS_LCAO<complex<double>, complex<double>>::dpks_cal_e_delta_band(
72+
const vector<vector<complex<double>>>& dm)const
3873
{
3974
GlobalC::ld.cal_e_delta_band_k(dm, this->kv.nks);
4075
}
76+
77+
4178
template<>
42-
void ESolver_KS_LCAO<double, double>::dpks_cal_projected_DM(const elecstate::DensityMatrix<double, double>* dm)const
79+
void ESolver_KS_LCAO<double, double>::dpks_cal_projected_DM(
80+
const elecstate::DensityMatrix<double, double>* dm)const
4381
{
44-
GlobalC::ld.cal_projected_DM(dm, //this->LOC.dm_gamma,
82+
GlobalC::ld.cal_projected_DM(dm,
4583
GlobalC::ucell,
4684
GlobalC::ORB,
4785
GlobalC::GridD);
4886
}
87+
88+
4989
template<>
50-
void ESolver_KS_LCAO<std::complex<double>, double>::dpks_cal_projected_DM(const elecstate::DensityMatrix<std::complex<double>, double>* dm)const
90+
void ESolver_KS_LCAO<complex<double>, double>::dpks_cal_projected_DM(
91+
const elecstate::DensityMatrix<complex<double>, double>* dm)const
5192
{
52-
GlobalC::ld.cal_projected_DM_k(dm, //this->LOC.dm_k,
93+
GlobalC::ld.cal_projected_DM_k(dm,
5394
GlobalC::ucell,
5495
GlobalC::ORB,
5596
GlobalC::GridD,
5697
this->kv.nks,
5798
this->kv.kvec_d);
5899
}
100+
101+
59102
template<>
60-
void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::dpks_cal_projected_DM(const elecstate::DensityMatrix<std::complex<double>, double>* dm)const
103+
void ESolver_KS_LCAO<complex<double>, complex<double>>::dpks_cal_projected_DM(
104+
const elecstate::DensityMatrix<complex<double>, double>* dm)const
61105
{
62-
GlobalC::ld.cal_projected_DM_k(dm, //this->LOC.dm_k,
106+
GlobalC::ld.cal_projected_DM_k(dm,
63107
GlobalC::ucell,
64108
GlobalC::ORB,
65109
GlobalC::GridD,
66110
this->kv.nks,
67111
this->kv.kvec_d);
68112
}
69113
#endif
70-
}
114+
}

source/module_hamilt_general/hamilt.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ class Hamilt
2121
virtual void updateHk(const int ik){return;}
2222

2323
/// refresh status of Hamiltonian, for example, refresh H(R) and S(R) in LCAO case
24-
virtual void refresh(){return;}
24+
virtual void refresh(void){return;}
2525

2626
/// core function: for solving eigenvalues of Hamiltonian with iterative method
27-
virtual void hPsi(const T* psi_in, T* hpsi, const size_t size) const{return;}
27+
virtual void hPsi(
28+
const T* psi_in,
29+
T* hpsi,
30+
const size_t size) const
31+
{
32+
return;
33+
}
34+
2835
virtual void sPsi(const T* psi_in, // psi
2936
T* spsi, // spsi
3037
const int nrow, // dimension of spsi: nbands * nrow
@@ -35,21 +42,28 @@ class Hamilt
3542
syncmem_op()(this->ctx, this->ctx, spsi, psi_in, static_cast<size_t>(nbands * nrow));
3643
}
3744

38-
/// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
39-
virtual void matrix(MatrixBlock<std::complex<double>> &hk_in, MatrixBlock<std::complex<double>> &sk_in){return;}
40-
virtual void matrix(MatrixBlock<double> &hk_in, MatrixBlock<double> &sk_in){return;}
45+
/// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
46+
virtual void matrix(
47+
MatrixBlock<std::complex<double>> &hk_in,
48+
MatrixBlock<std::complex<double>> &sk_in){return;}
49+
50+
virtual void matrix(
51+
MatrixBlock<double> &hk_in,
52+
MatrixBlock<double> &sk_in){return;}
4153

4254
std::string classname = "none";
4355

4456
int non_first_scf=0;
4557

4658
/// first node operator, add operations from each operators
4759
Operator<T, Device>* ops = nullptr;
60+
4861
protected:
62+
4963
Device* ctx = {};
5064
using syncmem_op = psi::memory::synchronize_memory_op<T, Device, Device>;
5165
};
5266

5367
} // namespace hamilt
5468

55-
#endif
69+
#endif

source/module_hamilt_lcao/hamilt_lcaodft/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ if(ENABLE_LCAO)
2626
fvl_dphi_k.cpp
2727
fvnl_dbeta_k.cpp
2828
LCAO_gen_fixedH.cpp
29-
LCAO_hamilt.cpp
3029
grid_init.cpp
31-
sparse_format.cpp
30+
spar_dh.cpp
31+
spar_exx.cpp
32+
spar_hsr.cpp
33+
spar_st.cpp
34+
spar_u.cpp
3235
LCAO_matrix.cpp
3336
LCAO_nnr.cpp
3437
record_adj.cpp

0 commit comments

Comments
 (0)