Skip to content

Commit fcd682b

Browse files
committed
debug now ,some energy is little different from abacus
1 parent 4c44b46 commit fcd682b

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

source/module_esolver/esolver_ks.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,16 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
629629
// if ( (!GlobalC::exx_info.info_global.cal_exx && iter == 1) || one_step_exx )
630630
if ( !GlobalC::exx_info.info_global.cal_exx || (GlobalC::exx_info.info_global.cal_exx && one_step_exx) )
631631
{
632+
std::cout << "\n\n\n******\nrdmft-test-0.0\n******\n\n\n" << std::endl;
633+
632634
ModuleBase::matrix occ_number_ks(this->pelec->wg);
633635
for(int ik=0; ik < occ_number_ks.nr; ++ik)
634636
{
635637
for(int inb=0; inb < occ_number_ks.nc; ++inb) occ_number_ks(ik, inb) /= this->kv.wk[ik];
636638
}
639+
640+
std::cout << "\n\n\n******\nrdmft-test-0.1\n******\n\n\n" << std::endl;
641+
637642
this->update_elec_rdmft(occ_number_ks, *(this->psi));
638643

639644
std::cout << "\n\n\n******\nget the initial values of wfc and occ_numbers successfully\n******\n\n\n" << std::endl;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,24 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
13391339

13401340
// ModuleBase::timer::tick("RDMFT", "E & Egradient");
13411341

1342+
// rdmft, added by jghan, 2024-10-17
1343+
if ( PARAM.inp.ab_initio_type == "rdmft" )
1344+
{
1345+
ModuleBase::matrix occ_number_ks(this->pelec->wg);
1346+
for(int ik=0; ik < occ_number_ks.nr; ++ik)
1347+
{
1348+
for(int inb=0; inb < occ_number_ks.nc; ++inb) occ_number_ks(ik, inb) /= this->kv.wk[ik];
1349+
}
1350+
this->update_elec_rdmft(occ_number_ks, *(this->psi));
1351+
1352+
//initialize the gradients of Etotal on wg and wfc, and set all elements to 0.
1353+
ModuleBase::matrix E_gradient_occNum(this->pelec->wg.nr, this->pelec->wg.nc, true);
1354+
psi::Psi<TK> E_gradient_wfc(this->psi->get_nk(), this->psi->get_nbands(), this->psi->get_nbasis());
1355+
E_gradient_wfc.zero_out();
1356+
1357+
double Etotal_RDMFT = this->Run_rdmft(E_gradient_occNum, E_gradient_wfc);
1358+
}
1359+
13421360
// /******** test RDMFT *********/
13431361

13441362

source/module_rdmft/rdmft.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
9898
// else nk_total = kv->nks;
9999

100100
nk_total = ModuleSymmetry::Symmetry::symm_flag == -1 ? kv->nkstot_full: kv->nks;
101-
nbands_total = PARAM.inp.nbands;
101+
// nbands_total = PARAM.inp.nbands;
102+
nbands_total = GlobalV::NBANDS;
102103
nspin = PARAM.inp.nspin;
103104
only_exx_type = ( XC_func_rdmft == "hf" || XC_func_rdmft == "muller" || XC_func_rdmft == "power" );
104105

105106
// XC_func_rdmft = "power"; // just for test
106107
// alpha_power = 0.525;
107108
std::cout << "\n\n\n******\nXC-functional in rdmft: " << XC_func_rdmft << "\n******\n\n\n" << std::endl;
109+
std::cout << "\n******\nGlobalC::exx_info.info_global.cal_exx: " << GlobalC::exx_info.info_global.cal_exx << "\n******\n" << std::endl;
110+
std::cout << "\n******\nPARAM.inp.ab_initio_type: " << PARAM.inp.ab_initio_type << "\n******\n" << std::endl;
111+
std::cout << "\n******\nGlobalV::NBANDS: " << GlobalV::NBANDS << "\n******\n" << std::endl;
112+
std::cout << "\n******\nPARAM.inp.nbands: " << PARAM.inp.nbands << "\n******\n" << std::endl;
108113
// XC_func_rdmft = "hf";
109114
// std::cout << "\n\n\n******\nXC-functional in rdmft: " << XC_func_rdmft << "\n******\n\n\n" << std::endl;
110115
// std::cout << "\n\n\n******\nXC-functional in GlobalC::atom: " << GlobalC::ucell.atoms[0].ncpp.xc_func << "\n******\n\n\n" << std::endl;
@@ -253,17 +258,28 @@ void RDMFT<TK, TR>::update_ion(UnitCell& ucell_in, ModulePW::PW_Basis& rho_basis
253258
template <typename TK, typename TR>
254259
void RDMFT<TK, TR>::update_elec(const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in)
255260
{
261+
std::cout << "\n\n\n******\nrdmft-test-1.0\n******\n\n\n" << std::endl;
256262
// update occ_number, wg, wk_fun_occNum
257263
occ_number = (occ_number_in);
258264
wg = (occ_number);
265+
std::cout << "\n\n\n******\nrdmft-test-1.1\n******\n\n\n" << std::endl;
266+
267+
std::cout << "\n***\nnk_total: " << nk_total << "\n***\n" << std::endl;
268+
std::cout << "\n***\nnbands_total: " << nbands_total << "\n***\n" << std::endl;
269+
270+
std::cout << "\n***\nwg.nr: " << wg.nr<< "\n***\n" << std::endl;
271+
std::cout << "\n***\nwg.nc: " << wg.nc << "\n***\n" << std::endl;
272+
259273
for(int ik=0; ik < wg.nr; ++ik)
260274
{
261275
for(int inb=0; inb < wg.nc; ++inb)
262276
{
263277
wg(ik, inb) *= kv->wk[ik];
278+
std::cout << "\n\n\n******\nrdmft-test-1.2\n******\n\n\n" << std::endl;
264279
wk_fun_occNum(ik, inb) = kv->wk[ik] * occNum_func(occ_number(ik, inb), 2, XC_func_rdmft, alpha_power);
265280
}
266281
}
282+
std::cout << "\n\n\n******\nrdmft-test-1.3\n******\n\n\n" << std::endl;
267283

268284
// update wfc
269285
TK* pwfc_in = &wfc_in(0, 0, 0);

0 commit comments

Comments
 (0)