Skip to content

Commit 28b8e58

Browse files
committed
prepare for PR
2 parents d2e2640 + ea575ed commit 28b8e58

File tree

10 files changed

+77
-1238
lines changed

10 files changed

+77
-1238
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,3 @@ OBJS_TENSOR=tensor.o\
736736

737737
OBJS_RDMFT=rdmft.o\
738738
rdmft_tools.o\
739-
rdmft_test.o\

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
// test RDMFT
5959
#include "module_rdmft/rdmft.h"
60+
#include "module_elecstate/module_dm/cal_dm_psi.h" //temp ,delete
61+
6062
#include <iostream>
6163

6264
namespace ModuleESolver
@@ -953,15 +955,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
953955
}
954956

955957
// 2.5) determine whether rdmft needs to get the initial value, added by jghan, 2024-10-25
956-
bool one_step_exx = false;
958+
int one_step_exx = false;
957959
bool get_init_value_rdmft = false;
958960
if( iter == 1 ) get_init_value_rdmft = true; // the case without hybrid functionals
959961
#ifdef __EXX
960962
if( GlobalC::exx_info.info_global.cal_exx )
961963
{
962964
if( this->conv_esolver ) one_step_exx = true;
963-
// the case with hybrid functionals
964-
if( one_step_exx && iter==1 ) get_init_value_rdmft = true;
965+
// the case with hybrid functionals, calculate rdmft just after updateExx, cal once in one inner loop
966+
if( one_step_exx ) get_init_value_rdmft = true;
965967
else get_init_value_rdmft = false;
966968
}
967969
#endif
@@ -1132,6 +1134,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
11321134
}
11331135

11341136
this->rdmft_solver.update_elec(occ_number_ks, *(this->psi));
1137+
std::cout << "\n******\n" << "update elec in rdmft successfully" << "\n******\n" << std::endl;
11351138

11361139
//initialize the gradients of Etotal on occupation numbers and wfc, and set all elements to 0.
11371140
ModuleBase::matrix dE_dOccNum(this->pelec->wg.nr, this->pelec->wg.nc, true);
@@ -1248,8 +1251,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
12481251
ModuleBase::matrix occ_number_ks(this->pelec->wg);
12491252
for(int ik=0; ik < occ_number_ks.nr; ++ik)
12501253
{
1251-
for(int inb=0; inb < occ_number_ks.nc; ++inb) { occ_number_ks(ik, inb) /= this->kv.wk[ik];
1252-
}
1254+
for(int inb=0; inb < occ_number_ks.nc; ++inb) occ_number_ks(ik, inb) /= this->kv.wk[ik];
12531255
}
12541256
this->rdmft_solver.update_elec(occ_number_ks, *(this->psi));
12551257

source/module_rdmft/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ if(ENABLE_LCAO)
44
OBJECT
55
rdmft.cpp
66
rdmft_tools.cpp
7-
rdmft_test.cpp
87
)
98
endif()
109

source/module_rdmft/rdmft.cpp

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ void RDMFT<TK, TR>::init(Gint_Gamma& GG_in, Gint_k& GK_in, Parallel_Orbitals& Pa
193193
#ifdef __EXX
194194
if( GlobalC::exx_info.info_global.cal_exx )
195195
{
196+
exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1);
197+
if (exx_spacegroup_symmetry)
198+
{
199+
const std::array<int, 3>& period = RI_Util::get_Born_vonKarmen_period(*kv);
200+
this->symrot_exx.find_irreducible_sector(ucell->symm, ucell->atoms, ucell->st,
201+
RI_Util::get_Born_von_Karmen_cells(period), period, ucell->lat);
202+
this->symrot_exx.cal_Ms(*kv, *ucell, *ParaV);
203+
}
204+
196205
if (GlobalC::exx_info.info_ri.real_number)
197206
{
198207
Vxc_fromRI_d = new Exx_LRI<double>(GlobalC::exx_info.info_ri);
@@ -571,16 +580,6 @@ void RDMFT<TK, TR>::cal_V_hartree()
571580
template <typename TK, typename TR>
572581
void RDMFT<TK, TR>::cal_V_XC()
573582
{
574-
HR_dft_XC->set_zero();
575-
HR_exx_XC->set_zero();
576-
577-
std::vector< std::vector<TK> > DM_XC(nk_total, std::vector<TK>(ParaV->nloc));
578-
std::vector< const std::vector<TK>* > DM_XC_pointer(nk_total);
579-
for(int ik=0; ik<nk_total; ++ik) { DM_XC_pointer[ik] = &DM_XC[ik];
580-
}
581-
582-
get_DM_XC(DM_XC);
583-
584583
// // //test
585584
// DM_XC_pass = DM_XC;
586585

@@ -609,6 +608,7 @@ void RDMFT<TK, TR>::cal_V_XC()
609608

610609
if( !only_exx_type )
611610
{
611+
HR_dft_XC->set_zero();
612612
if( PARAM.inp.gamma_only )
613613
{
614614
// this can be optimized, use potXC.update_from_charge()
@@ -661,17 +661,35 @@ void RDMFT<TK, TR>::cal_V_XC()
661661
#ifdef __EXX
662662
if(GlobalC::exx_info.info_global.cal_exx)
663663
{
664+
HR_exx_XC->set_zero();
665+
666+
std::vector< std::vector<TK> > DM_XC(nk_total, std::vector<TK>(ParaV->nloc));
667+
get_DM_XC(DM_XC);
668+
// get DM_XC of all k points
669+
if( exx_spacegroup_symmetry )
670+
{
671+
DM_XC = symrot_exx.restore_dm(*this->kv, DM_XC, *ParaV); // class vector could be auto resize()
672+
}
673+
std::vector< const std::vector<TK>* > DM_XC_pointer(DM_XC.size());
674+
for(int ik=0; ik<DM_XC.size(); ++ik) DM_XC_pointer[ik] = &DM_XC[ik];
675+
664676
if (GlobalC::exx_info.info_ri.real_number)
665677
{
666678
// transfer the DM_XC to appropriate format
667-
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<double>>>> Ds_XC_d =
668-
RI_2D_Comm::split_m2D_ktoR<double>(*kv, DM_XC_pointer, *ParaV, nspin);
679+
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<double>>>>
680+
Ds_XC_d = std::is_same<TK, double>::value //gamma_only_local
681+
? RI_2D_Comm::split_m2D_ktoR<double>(*kv, DM_XC_pointer, *ParaV, nspin)
682+
: RI_2D_Comm::split_m2D_ktoR<double>(*kv, DM_XC_pointer, *ParaV, nspin, this->exx_spacegroup_symmetry);
669683

670684
// provide the Ds_XC to Vxc_fromRI(V_exx_XC)
671-
// Vxc_fromRI_d = new Exx_LRI<double>(GlobalC::exx_info.info_ri);
672-
// Vxc_fromRI_d->init(MPI_COMM_WORLD, *kv);
673-
// Vxc_fromRI_d->cal_exx_ions();
674-
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, *ParaV);
685+
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
686+
{
687+
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, *ParaV, &this->symrot_exx);
688+
}
689+
else
690+
{
691+
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, *ParaV);
692+
}
675693

676694
// when we doing V_exx_XC.contributeHk(ik), we get HK_XC constructed by the special DM_XC
677695
V_exx_XC = new hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>>(
@@ -682,24 +700,24 @@ void RDMFT<TK, TR>::cal_V_XC()
682700
nullptr,
683701
hamilt::Add_Hexx_Type::k
684702
);
685-
// V_exx_XC = new hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>>(
686-
// hsk_exx_XC,
687-
// HR_exx_XC,
688-
// *kv
689-
// );
690-
691703
}
692704
else
693705
{
694706
// transfer the DM_XC to appropriate format
695-
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<std::complex<double>>>>> Ds_XC_c =
696-
RI_2D_Comm::split_m2D_ktoR<std::complex<double>>(*kv, DM_XC_pointer, *ParaV, nspin);
697-
698-
// provide the Ds_XC to Vxc_fromRI(V_exx_XC)
699-
// Vxc_fromRI_c = new Exx_LRI<std::complex<double>>(GlobalC::exx_info.info_ri);
700-
// Vxc_fromRI_c->init(MPI_COMM_WORLD, *kv);
701-
// Vxc_fromRI_c->cal_exx_ions();
702-
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, *ParaV);
707+
std::vector<std::map<int,std::map<std::pair<int,std::array<int,3>>,RI::Tensor<std::complex<double>>>>>
708+
Ds_XC_c = std::is_same<TK, double>::value //gamma_only_local
709+
? RI_2D_Comm::split_m2D_ktoR<std::complex<double>>(*kv, DM_XC_pointer, *ParaV, nspin)
710+
: RI_2D_Comm::split_m2D_ktoR<std::complex<double>>(*kv, DM_XC_pointer, *ParaV, nspin, this->exx_spacegroup_symmetry);
711+
712+
// // provide the Ds_XC to Vxc_fromRI(V_exx_XC)
713+
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
714+
{
715+
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, *ParaV, &this->symrot_exx);
716+
}
717+
else
718+
{
719+
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, *ParaV);
720+
}
703721

704722
// when we doing V_exx_XC.contributeHk(ik), we get HK_XC constructed by the special DM_XC
705723
V_exx_XC = new hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>>(
@@ -840,6 +858,8 @@ void RDMFT<TK, TR>::cal_Energy(const int cal_type)
840858
double E_deband_KS = pelec->f_en.deband;
841859
double E_deband_harris_KS = pelec->f_en.deband_harris;
842860

861+
double E_exxType_rdmft = 0.0; // delete in the future
862+
843863
if( cal_type == 1 )
844864
{
845865
// for E_TV
@@ -862,6 +882,7 @@ void RDMFT<TK, TR>::cal_Energy(const int cal_type)
862882
occNum_Mul_wfcHwfc(wk_fun_occNum, wfcHwfc_exx_XC, Exc_n_k, 1);
863883
E_RDMFT[2] = getEnergy(Exc_n_k);
864884
Parallel_Reduce::reduce_all(E_RDMFT[2]);
885+
E_exxType_rdmft = E_RDMFT[2];
865886
}
866887
#endif
867888
E_RDMFT[2] += etxc;
@@ -934,7 +955,8 @@ void RDMFT<TK, TR>::cal_Energy(const int cal_type)
934955
<< "\nE_descf: " << E_descf
935956
<< "\n\nEtotal_RDMFT: " << Etotal
936957
<< "\n\nExc_ksdft: " << E_xc_KS
937-
<< "\nE_exx_ksdft: " << E_exx_KS
958+
<< "\nE_exx_ksdft: " << E_exx_KS
959+
<< "\nE_exxType_rdmft: " << E_exxType_rdmft
938960
<<"\n******\n" << std::endl;
939961
}
940962
std::cout << std::defaultfloat;

source/module_rdmft/rdmft.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "module_ri/Exx_LRI.h"
4242
#include "module_ri/RI_2D_Comm.h"
4343
#include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.h"
44+
#include "module_ri/module_exx_symmetry/symmetry_rotation.h"
4445
#endif
4546

4647
// there are some operator reload to print data in different formats
@@ -179,6 +180,8 @@ class RDMFT
179180
#ifdef __EXX
180181
Exx_LRI<double>* Vxc_fromRI_d = nullptr;
181182
Exx_LRI<std::complex<double>>* Vxc_fromRI_c = nullptr;
183+
ModuleSymmetry::Symmetry_rotation symrot_exx;
184+
bool exx_spacegroup_symmetry = false;
182185
#endif
183186

184187
double Etotal = 0.0;

0 commit comments

Comments
 (0)