Skip to content

Commit cb65d6d

Browse files
committed
modify class RDMFT
1 parent 82faafa commit cb65d6d

File tree

3 files changed

+70
-89
lines changed

3 files changed

+70
-89
lines changed

abaInstall_HZWpara.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
rm -rf build
22

3-
cmake -B build -DCMAKE_INSTALL_PREFIX=/public1/home/t6s000394/jghan/software/abacus-develop/rdmft-abacus/ -DCMAKE_CXX_COMPILER=icpx -DELPA_DIR=/public1/home/t6s000394/jghan/software/elpa-2021.11/ -DCEREAL_INCLUDE_DIR=/public1/home/t6s000394/jghan/software/cereal/cereal-1.3.2/include
4-
#cmake -B build -DCMAKE_INSTALL_PREFIX=/public1/home/t6s000394/jghan/software/abacus-develop/rdmft-abacus/ -DCMAKE_CXX_COMPILER=icpx -DMPI_CXX_COMPILER=mpiicpc -DELPA_DIR=/public1/home/t6s000394/jghan/software/elpa-2021.11/ -DLibxc_DIR=/public1/home/t6s000394/jghan/software/libxc/ -DLIBRI_DIR=/public1/home/t6s000394/jghan/software/LibRI -DLIBCOMM_DIR=/public1/home/t6s000394/jghan/software/LibComm -DCEREAL_INCLUDE_DIR=/public1/home/t6s000394/jghan/software/cereal/cereal-1.3.2/include
3+
#cmake -B build -DCMAKE_INSTALL_PREFIX=/public1/home/t6s000394/jghan/software/abacus-develop/rdmft-abacus/ -DCMAKE_CXX_COMPILER=icpx -DELPA_DIR=/public1/home/t6s000394/jghan/software/elpa-2021.11/ -DCEREAL_INCLUDE_DIR=/public1/home/t6s000394/jghan/software/cereal/cereal-1.3.2/include
4+
cmake -B build -DCMAKE_INSTALL_PREFIX=/public1/home/t6s000394/jghan/software/abacus-develop/rdmft-abacus/ -DCMAKE_CXX_COMPILER=icpx -DMPI_CXX_COMPILER=mpiicpc -DELPA_DIR=/public1/home/t6s000394/jghan/software/elpa-2021.11/ -DLibxc_DIR=/public1/home/t6s000394/jghan/software/libxc/ -DLIBRI_DIR=/public1/home/t6s000394/jghan/software/LibRI -DLIBCOMM_DIR=/public1/home/t6s000394/jghan/software/LibComm -DCEREAL_INCLUDE_DIR=/public1/home/t6s000394/jghan/software/cereal/cereal-1.3.2/include
55

66
#cmake --build build -j 52 2>job.err
7-
cmake --build build -j 92
7+
cmake --build build -j 8
88

99
cmake --install build

source/module_rdmft/rdmft.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ RDMFT<TK, TR>::~RDMFT()
6161
{
6262
delete HR_TV;
6363
delete HR_hartree;
64-
// delete HR_XC;
6564
delete HR_exx_XC;
66-
// delete HR_local;
6765
delete HR_dft_XC;
66+
// delete HR_local;
67+
delete hsk_TV;
68+
delete hsk_hartree;
69+
delete hsk_dft_XC;
70+
delete hsk_exx_XC;
6871
#ifdef __EXX
6972
delete Vxc_fromRI_d;
7073
delete Vxc_fromRI_c;
@@ -73,10 +76,8 @@ RDMFT<TK, TR>::~RDMFT()
7376
delete V_nonlocal;
7477
delete V_local;
7578
delete V_hartree;
76-
// delete V_XC;
7779
delete V_exx_XC;
7880
delete V_dft_XC;
79-
delete V_hartree_XC;
8081
}
8182

8283
template <typename TK, typename TR>
@@ -101,7 +102,7 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
101102
nk_total *= nspin;
102103
only_exx_type = ( XC_func_rdmft == "hf" || XC_func_rdmft == "muller" || XC_func_rdmft == "power" );
103104

104-
// // create desc[] and something about MPI to Eij(nbands*nbands)
105+
// create desc[] and something about MPI to Eij(nbands*nbands)
105106
#ifdef __MPI
106107
para_Eij.set(nbands_total, nbands_total, ParaV->nb, ParaV->blacs_ctxt); // maybe in default, PARAM.inp.nb2d = 0, can't be used
107108
#endif
@@ -146,7 +147,6 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
146147
//
147148
HR_TV = new hamilt::HContainer<TR>(*ucell, ParaV);
148149
HR_hartree = new hamilt::HContainer<TR>(*ucell, ParaV);
149-
// HR_XC = new hamilt::HContainer<TR>(*ucell, ParaV);
150150
HR_exx_XC = new hamilt::HContainer<TR>(*ucell, ParaV);
151151
HR_dft_XC = new hamilt::HContainer<TR>(*ucell, ParaV);
152152
// HR_local = new hamilt::HContainer<TR>(*ucell, ParaV);
@@ -162,7 +162,6 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
162162

163163
HR_TV->set_zero(); // HR->set_zero() might be delete here, test on Gamma_only in the furure
164164
HR_hartree->set_zero();
165-
// HR_XC->set_zero();
166165
HR_exx_XC->set_zero();
167166
HR_dft_XC->set_zero();
168167
// HR_local->set_zero();
@@ -197,7 +196,6 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
197196
{
198197
HR_TV->fix_gamma();
199198
HR_hartree->fix_gamma();
200-
// HR_XC->fix_gamma();
201199
HR_exx_XC->fix_gamma();
202200
HR_dft_XC->fix_gamma();
203201
}

source/module_rdmft/rdmft.h

Lines changed: 61 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,15 @@ namespace rdmft
7878
template <typename TK, typename TR>
7979
class RDMFT
8080
{
81+
8182
public:
8283
RDMFT();
8384
~RDMFT();
8485

85-
86-
/****** these parameters are passed in from outside, don't need delete ******/
87-
Parallel_Orbitals* ParaV = nullptr;
86+
const Parallel_Orbitals* ParaV = nullptr;
8887
Parallel_2D para_Eij;
89-
// Parallel_Orbitals para_Eij;
90-
91-
// GK and GG are used for multi-k grid integration and gamma only algorithms respectively
92-
Gint_k* GK = nullptr;
93-
Gint_Gamma* GG = nullptr;
94-
Charge* charge = nullptr;
9588
elecstate::ElecState* pelec = nullptr; // just to gain Ewald and this->pelec->pot
96-
97-
// update after ion step
98-
UnitCell* ucell = nullptr;
99-
K_Vectors* kv = nullptr;
100-
// LCAO_Matrix* LM = nullptr;
101-
ModulePW::PW_Basis* rho_basis = nullptr;
102-
ModuleBase::matrix* vloc = nullptr;
103-
ModuleBase::ComplexMatrix* sf = nullptr;
104-
LCAO_Orbitals* orb = nullptr;
105-
TwoCenterBundle* two_center_bundle = nullptr;
106-
// Local_Orbital_Charge* loc = nullptr; // would be delete in the future
107-
/****** these parameters are passed in from outside, don't need delete ******/
89+
const K_Vectors* kv = nullptr; // update after ion step
10890

10991
int nk_total = 0;
11092
int nbands_total;
@@ -124,11 +106,56 @@ class RDMFT
124106

125107
// E_RDMFT[4] stores ETV, Ehartree, Exc, Etotal respectively
126108
double E_RDMFT[4] = {0.0};
109+
double Etotal = 0.0;
127110
// std::vector<double> E_RDMFT(4);
128111

112+
//! initialization of rdmft calculation
113+
void init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& ParaV_in, UnitCell& ucell_in,
114+
K_Vectors& kv_in, elecstate::ElecState& pelec_in, LCAO_Orbitals& orb_in, TwoCenterBundle& two_center_bundle_in, std::string XC_func_rdmft_in, double alpha_power_in);
115+
116+
//! update in ion-step and get V_TV
117+
void update_ion(UnitCell& ucell_in, ModulePW::PW_Basis& rho_basis_in,
118+
ModuleBase::matrix& vloc_in, ModuleBase::ComplexMatrix& sf_in);
119+
120+
//! update in elec-step
121+
// Or we can use rdmft_solver.wfc/occ_number directly when optimizing, so that the update_elec() function does not require parameters.
122+
void update_elec(const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in = nullptr);
123+
124+
//! update occ_number for optimization algorithms that depend on Hamilton
125+
void update_occNumber(const ModuleBase::matrix& occ_number_in);
126+
127+
//! update occ_number for optimization algorithms that depend on Hamilton
128+
void update_wg(const ModuleBase::matrix& wg_in);
129+
130+
//! do all calculation after update occNum&wfc, get Etotal and the gradient of energy with respect to the occNum&wfc
131+
double run(ModuleBase::matrix& E_gradient_occNum, psi::Psi<TK>& E_gradient_wfc);
132+
133+
134+
protected:
135+
136+
//! get the special density matrix DM_XC(nk*nbasis_local*nbasis_local)
137+
void get_DM_XC(std::vector< std::vector<TK> >& DM_XC);
138+
139+
void cal_V_TV();
140+
141+
void cal_V_hartree();
142+
143+
//! construct V_XC based on different XC_functional( i.e. RDMFT class member XC_func_rdmft)
144+
void cal_V_XC();
145+
146+
double cal_E_gradient();
147+
148+
void cal_Energy(const int cal_type = 1);
149+
150+
//! get the total Hamilton in k-space
151+
void cal_Hk_Hpsi();
152+
153+
void update_charge();
154+
155+
private:
156+
129157
hamilt::HContainer<TR>* HR_TV = nullptr;
130158
hamilt::HContainer<TR>* HR_hartree = nullptr;
131-
// hamilt::HContainer<TR>* HR_XC = nullptr;
132159
hamilt::HContainer<TR>* HR_dft_XC = nullptr;
133160
hamilt::HContainer<TR>* HR_exx_XC = nullptr;
134161
// hamilt::HContainer<TR>* HR_local = nullptr;
@@ -156,7 +183,6 @@ class RDMFT
156183
psi::Psi<TK> H_wfc_exx_XC;
157184
psi::Psi<TK> H_wfc_dft_XC;
158185

159-
// just for temperate. in the future when realize psiDotPsi() without pzgemm_/pdgemm_,we don't need it
160186
std::vector<TK> Eij_TV;
161187
std::vector<TK> Eij_hartree;
162188
std::vector<TK> Eij_XC;
@@ -166,11 +192,8 @@ class RDMFT
166192
hamilt::OperatorLCAO<TK, TR>* V_nonlocal = nullptr;
167193
hamilt::OperatorLCAO<TK, TR>* V_local = nullptr;
168194
hamilt::OperatorLCAO<TK, TR>* V_hartree = nullptr;
169-
// hamilt::OperatorLCAO<TK, TR>* V_XC = nullptr;
170195
hamilt::OperatorLCAO<TK, TR>* V_exx_XC = nullptr;
171196
hamilt::OperatorLCAO<TK, TR>* V_dft_XC = nullptr;
172-
hamilt::OperatorLCAO<TK, TR>* V_hartree_XC = nullptr;
173-
// bool get_V_local_temp = true;
174197

175198
#ifdef __EXX
176199
Exx_LRI<double>* Vxc_fromRI_d = nullptr;
@@ -179,72 +202,32 @@ class RDMFT
179202
bool exx_spacegroup_symmetry = false;
180203
#endif
181204

182-
double Etotal = 0.0;
183205
double etxc = 0.0;
184206
double vtxc = 0.0;
185207
bool only_exx_type = false;
186208
const int cal_E_type = 1; // cal_type = 2 just support XC-functional without exx
187209

188-
//! initialization of rdmft calculation
189-
void init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& ParaV_in, UnitCell& ucell_in,
190-
K_Vectors& kv_in, elecstate::ElecState& pelec_in, LCAO_Orbitals& orb_in, TwoCenterBundle& two_center_bundle_in, std::string XC_func_rdmft_in, double alpha_power_in);
191-
192-
//! update in ion-step and get V_TV
193-
void update_ion(UnitCell& ucell_in, ModulePW::PW_Basis& rho_basis_in,
194-
ModuleBase::matrix& vloc_in, ModuleBase::ComplexMatrix& sf_in);
195-
196-
//! update in elec-step
197-
// Or we can use rdmft_solver.wfc/occ_number directly when optimizing, so that the update_elec() function does not require parameters.
198-
void update_elec(const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in = nullptr);
199-
200-
//! update occ_number for optimization algorithms that depend on Hamilton
201-
void update_occNumber(const ModuleBase::matrix& occ_number_in);
202-
203-
//! update occ_number for optimization algorithms that depend on Hamilton
204-
void update_wg(const ModuleBase::matrix& wg_in);
205-
206-
//! do all calculation after update occNum&wfc, get Etotal and the gradient of energy with respect to the occNum&wfc
207-
double run(ModuleBase::matrix& E_gradient_occNum, psi::Psi<TK>& E_gradient_wfc);
208-
209-
210-
211-
protected:
212-
213-
//! get the special density matrix DM_XC(nk*nbasis_local*nbasis_local)
214-
void get_DM_XC(std::vector< std::vector<TK> >& DM_XC);
215-
216-
void cal_V_TV();
217210

218-
void cal_V_hartree();
219-
220-
//! construct V_XC based on different XC_functional( i.e. RDMFT class member XC_func_rdmft)
221-
void cal_V_XC();
222-
223-
double cal_E_gradient();
224-
225-
void cal_Energy(const int cal_type = 1);
226-
227-
228-
229-
private:
230-
231-
//! get the total Hamilton in k-space
232-
void cal_Hk_Hpsi();
233-
234-
void update_charge();
211+
/****** these parameters are passed in from outside, don't need delete ******/
212+
// GK and GG are used for multi-k grid integration and gamma only algorithms respectively
213+
Gint_k* GK = nullptr;
214+
Gint_Gamma* GG = nullptr;
215+
Charge* charge = nullptr;
235216

217+
// update after ion step
218+
const UnitCell* ucell = nullptr;
219+
const ModulePW::PW_Basis* rho_basis = nullptr;
220+
const ModuleBase::matrix* vloc = nullptr;
221+
const ModuleBase::ComplexMatrix* sf = nullptr;
222+
const LCAO_Orbitals* orb = nullptr;
223+
const TwoCenterBundle* two_center_bundle = nullptr;
236224

237225

238226
};
239227

240228

241229

242-
243-
244-
245230
}
246231

247232

248-
249-
250233
#endif

0 commit comments

Comments
 (0)