Skip to content

Commit e23a0e9

Browse files
committed
add test in esolver_ks_lcao.cpp, function after_scf(): update exx to test the exx_energy get by rdmft is exactly equal to exx_energy by abacus
1 parent e0ba750 commit e23a0e9

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,73 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
12481248
// rdmft, added by jghan, 2024-10-17
12491249
if ( PARAM.inp.ab_initio_type == "rdmft" )
12501250
{
1251+
#ifdef __EXX
1252+
if( GlobalC::exx_info.info_global.cal_exx )
1253+
{
1254+
UnitCell* ucell = this->rdmft_solver.ucell;
1255+
bool exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1);
1256+
1257+
// get the current DM
1258+
elecstate::DensityMatrix<TK, double> DM_test(&this->pv, PARAM.inp.nspin, this->kv.kvec_d, this->rdmft_solver.nk_total);
1259+
elecstate::cal_dm_psi(&this->pv, this->pelec->wg, *(this->psi), DM_test);
1260+
DM_test.init_DMR(&GlobalC::GridD, &GlobalC::ucell);
1261+
DM_test.cal_DMR();
1262+
1263+
std::vector< std::vector<TK> > DM_XC_test = DM_test.get_DMK_vector();
1264+
ModuleSymmetry::Symmetry_rotation symrot_exx;
1265+
if( exx_spacegroup_symmetry )
1266+
{
1267+
const std::array<int, 3> period = RI_Util::get_Born_vonKarmen_period(this->kv);
1268+
symrot_exx.find_irreducible_sector(ucell->symm, ucell->atoms, ucell->st,
1269+
RI_Util::get_Born_von_Karmen_cells(period), period, ucell->lat);
1270+
symrot_exx.cal_Ms(this->kv, *ucell, this->pv);
1271+
1272+
// get DM_XC of all k points
1273+
DM_XC_test = symrot_exx.restore_dm(*this->rdmft_solver.kv, DM_XC_test, this->pv); // class vector could be auto resize()
1274+
}
1275+
1276+
std::vector< const std::vector<TK>* > DM_pointer(DM_XC_test.size());
1277+
for(int ik=0; ik<DM_XC_test.size(); ++ik) DM_pointer[ik] = &(DM_XC_test[ik]);
1278+
1279+
// convert format and update exx
1280+
if (GlobalC::exx_info.info_ri.real_number)
1281+
{
1282+
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<double>>>>
1283+
Ds_d = std::is_same<TK, double>::value //gamma_only_local
1284+
? RI_2D_Comm::split_m2D_ktoR<double>(this->kv, DM_pointer, this->pv, PARAM.inp.nspin)
1285+
: RI_2D_Comm::split_m2D_ktoR<double>(this->kv, DM_pointer, this->pv, PARAM.inp.nspin, exx_spacegroup_symmetry);
1286+
1287+
if (exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
1288+
{
1289+
this->exx_lri_double->cal_exx_elec(Ds_d, this->pv, &symrot_exx);
1290+
}
1291+
else
1292+
{
1293+
this->exx_lri_double->cal_exx_elec(Ds_d, this->pv);
1294+
}
1295+
1296+
this->pelec->f_en.exx = this->exx_lri_double->Eexx;
1297+
}
1298+
else
1299+
{
1300+
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<std::complex<double>>>>>
1301+
Ds_c = std::is_same<TK, double>::value //gamma_only_local
1302+
? RI_2D_Comm::split_m2D_ktoR<std::complex<double>>(this->kv, DM_pointer, this->pv, PARAM.inp.nspin)
1303+
: RI_2D_Comm::split_m2D_ktoR<std::complex<double>>(this->kv, DM_pointer, this->pv, PARAM.inp.nspin, exx_spacegroup_symmetry);
1304+
1305+
if (exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
1306+
{
1307+
this->exx_lri_complex->cal_exx_elec(Ds_c, this->pv, &symrot_exx);
1308+
}
1309+
else
1310+
{
1311+
this->exx_lri_complex->cal_exx_elec(Ds_c, this->pv);
1312+
}
1313+
1314+
this->pelec->f_en.exx = this->exx_lri_complex->Eexx;
1315+
}
1316+
}
1317+
#endif
12511318
ModuleBase::matrix occ_number_ks(this->pelec->wg);
12521319
for(int ik=0; ik < occ_number_ks.nr; ++ik)
12531320
{

0 commit comments

Comments
 (0)