Skip to content

Commit

Permalink
remove nspin dependence form Gint
Browse files Browse the repository at this point in the history
  • Loading branch information
maki49 committed Oct 18, 2024
1 parent 1a11dac commit e170b49
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 73 deletions.
6 changes: 3 additions & 3 deletions source/module_elecstate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho);
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_k->cal_gint(&inout);

if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
Expand Down Expand Up @@ -113,7 +113,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)

this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint

Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho);
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);

this->gint_gamma->cal_gint(&inout);

Expand Down Expand Up @@ -178,7 +178,7 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho);
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout);
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
Expand Down
4 changes: 2 additions & 2 deletions source/module_elecstate/elecstate_lcao_cal_tau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<do
{
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
this->gint_k->cal_gint(&inout1);

ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
Expand All @@ -32,7 +32,7 @@ void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
{
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout1);

ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/elecstate_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void ElecStateLCAO_TDDFT::psiToRho_td(const psi::Psi<std::complex<double>>& psi)

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho); // rho calculation
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); // rho calculation
this->gint_k->cal_gint(&inout);

this->charge->renormalize_rho();
Expand Down
30 changes: 16 additions & 14 deletions source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
pot_in->pot_register(pot_register_in);
// effective potential term
Operator<TK>* veff = new Veff<OperatorLCAO<TK, TR>>(GG_in,
this->hsk,
this->kv->kvec_d,
pot_in,
this->hR, // no explicit call yet
&GlobalC::ucell,
orb.cutoffs(),
&GlobalC::GridD
this->hsk,
this->kv->kvec_d,
pot_in,
this->hR, // no explicit call yet
&GlobalC::ucell,
orb.cutoffs(),
&GlobalC::GridD,
PARAM.inp.nspin
);
this->getOperator()->add(veff);
}
Expand Down Expand Up @@ -242,13 +243,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
pot_in->pot_register(pot_register_in);
// Veff term
this->getOperator() = new Veff<OperatorLCAO<TK, TR>>(GK_in,
this->hsk,
kv->kvec_d,
pot_in,
this->hR,
&GlobalC::ucell,
orb.cutoffs(),
&GlobalC::GridD);
this->hsk,
kv->kvec_d,
pot_in,
this->hR,
&GlobalC::ucell,
orb.cutoffs(),
&GlobalC::GridD,
PARAM.inp.nspin);
// reset spin index and real space Hamiltonian matrix
int start_spin = -1;
GK_in->reset_spin(start_spin);
Expand Down
34 changes: 18 additions & 16 deletions source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,41 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
* @param GK_in: the pointer of Gint_k object, used for grid integration
*/
Veff<OperatorLCAO<TK, TR>>(Gint_k* GK_in,
HS_Matrix_K<TK>* hsk_in,
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
elecstate::Potential* pot_in,
hamilt::HContainer<TR>* hR_in,
const UnitCell* ucell_in,
const std::vector<double>& orb_cutoff,
Grid_Driver* GridD_in)
HS_Matrix_K<TK>* hsk_in,
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
elecstate::Potential* pot_in,
hamilt::HContainer<TR>* hR_in,
const UnitCell* ucell_in,
const std::vector<double>& orb_cutoff,
Grid_Driver* GridD_in,
const int& nspin)
: GK(GK_in), orb_cutoff_(orb_cutoff), pot(pot_in), ucell(ucell_in),
gd(GridD_in), OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in)
{
this->cal_type = calculation_type::lcao_gint;

this->initialize_HR(ucell_in, GridD_in);
GK_in->initialize_pvpR(*ucell_in, GridD_in);
GK_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
}
/**
* @brief Construct a new Veff object for Gamma-only calculation
* @param GG_in: the pointer of Gint_Gamma object, used for grid integration
*/
Veff<OperatorLCAO<TK, TR>>(Gint_Gamma* GG_in,
HS_Matrix_K<TK>* hsk_in,
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
elecstate::Potential* pot_in,
hamilt::HContainer<TR>* hR_in,
const UnitCell* ucell_in,
const std::vector<double>& orb_cutoff,
Grid_Driver* GridD_in)
HS_Matrix_K<TK>* hsk_in,
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
elecstate::Potential* pot_in,
hamilt::HContainer<TR>* hR_in,
const UnitCell* ucell_in,
const std::vector<double>& orb_cutoff,
Grid_Driver* GridD_in,
const int& nspin)
: GG(GG_in), orb_cutoff_(orb_cutoff), pot(pot_in), OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in)
{
this->cal_type = calculation_type::lcao_gint;
this->initialize_HR(ucell_in, GridD_in);

GG_in->initialize_pvpR(*ucell_in, GridD_in);
GG_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
}

~Veff<OperatorLCAO<TK, TR>>(){};
Expand Down
10 changes: 5 additions & 5 deletions source/module_hamilt_lcao/module_gint/gint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ void Gint::prep_grid(const Grid_Technique& gt,
return;
}

void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd, const int& nspin) {
ModuleBase::TITLE("Gint", "initialize_pvpR");

int npol = 1;
// there is the only resize code of DMRGint
if (this->DMRGint.size() == 0) {
this->DMRGint.resize(PARAM.inp.nspin);
this->DMRGint.resize(nspin);
}
if (PARAM.inp.nspin != 4) {
if (nspin != 4) {
if (this->hRGint != nullptr) {
delete this->hRGint;
}
Expand All @@ -153,7 +153,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
}
this->hRGintCd
= new hamilt::HContainer<std::complex<double>>(ucell_in.nat);
for (int is = 0; is < PARAM.inp.nspin; is++) {
for (int is = 0; is < nspin; is++) {
if (this->DMRGint[is] != nullptr) {
delete this->DMRGint[is];
}
Expand Down Expand Up @@ -186,7 +186,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
}
}

if (PARAM.globalv.gamma_only_local && PARAM.inp.nspin != 4) {
if (PARAM.globalv.gamma_only_local && nspin != 4) {
this->hRGint->fix_gamma();
}
for (int T1 = 0; T1 < ucell_in.ntype; ++T1) {
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_lcao/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Gint {
* @brief calculate the neighbor atoms of each atom in this processor
* size of BaseMatrix with be the non-parallel version
*/
void initialize_pvpR(const UnitCell& unitcell, Grid_Driver* gd);
void initialize_pvpR(const UnitCell& unitcell, Grid_Driver* gd, const int& nspin);

/**
* @brief transfer DMR (2D para) to DMR (Grid para) in elecstate_lcao.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Gint::gint_kernel_rho(Gint_inout* inout) {
cal_flag.get_ptr_2D(),
psir_ylm.get_ptr_2D());

for (int is = 0; is < PARAM.inp.nspin; ++is)
for (int is = 0; is < inout->nspin_rho; ++is)
{
ModuleBase::Array_Pool<double> psir_DM(this->bxyz, LD_pool);
ModuleBase::GlobalFunc::ZEROS(psir_DM.get_ptr_1D(), this->bxyz * LD_pool);
Expand Down
13 changes: 3 additions & 10 deletions source/module_hamilt_lcao/module_gint/gint_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Gint_inout
bool isforce;
bool isstress;
int ispin;
int nspin_rho; // usually, but not always, equal to global nspin
bool if_symm = false; // if true, use dsymv in gint_kernel_rho; if false, use dgemv.

// output
Expand All @@ -48,10 +49,11 @@ class Gint_inout
Gint_Tools::job_type job;

// electron density and kin_r, multi-k
Gint_inout(double** rho_in, Gint_Tools::job_type job_in, bool if_symm_in = true)
Gint_inout(double** rho_in, Gint_Tools::job_type job_in, const int& nspin_rho_in, bool if_symm_in = true)
{
rho = rho_in;
job = job_in;
nspin_rho = nspin_rho_in;
if_symm = if_symm_in;
}

Expand Down Expand Up @@ -110,15 +112,6 @@ class Gint_inout
job = job_in;
}

// electron density and kin_r, gamma point
Gint_inout(double*** DM_in, double** rho_in, Gint_Tools::job_type job_in, bool if_symm_in = true)
{
DM = DM_in;
rho = rho_in;
job = job_in;
if_symm = if_symm_in;
}

// vlocal, gamma point
Gint_inout(const double* vl_in, Gint_Tools::job_type job_in)
{
Expand Down
12 changes: 6 additions & 6 deletions source/module_io/get_pchg_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ void IState_Charge::begin(Gint_Gamma& gg,

DM.init_DMR(GridD_in, ucell_in);
DM.cal_DMR();
gg.initialize_pvpR(*ucell_in, GridD_in);
gg.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
gg.transfer_DM2DtoGrid(DM.get_DMR_vector());
Gint_inout inout((double***)nullptr, rho, Gint_Tools::job_type::rho);
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
gg.cal_gint(&inout);

// A solution to replace the original implementation of the following code:
Expand Down Expand Up @@ -243,9 +243,9 @@ void IState_Charge::begin(Gint_k& gk,

DM.init_DMR(GridD_in, ucell_in);
DM.cal_DMR(ik);
gk.initialize_pvpR(*ucell_in, GridD_in);
gk.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
gk.transfer_DM2DtoGrid(DM.get_DMR_vector());
Gint_inout inout(rho, Gint_Tools::job_type::rho);
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
gk.cal_gint(&inout);

// Using std::vector to replace the original double** rho_save
Expand Down Expand Up @@ -298,9 +298,9 @@ void IState_Charge::begin(Gint_k& gk,

DM.init_DMR(GridD_in, ucell_in);
DM.cal_DMR();
gk.initialize_pvpR(*ucell_in, GridD_in);
gk.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
gk.transfer_DM2DtoGrid(DM.get_DMR_vector());
Gint_inout inout(rho, Gint_Tools::job_type::rho);
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
gk.cal_gint(&inout);

// Using std::vector to replace the original double** rho_save
Expand Down
4 changes: 2 additions & 2 deletions source/module_io/write_eband_terms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace ModuleIO
hamilt::HContainer<TR> v_pp_local_R_ao(pv);
if_gamma_fix(v_pp_local_R_ao);
std::vector<std::vector<double>> e_orb_pp_local;
hamilt::Veff<hamilt::OperatorLCAO<TK, TR>> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd);
hamilt::Veff<hamilt::OperatorLCAO<TK, TR>> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd, nspin);
v_pp_local_op.contributeHR();
for (int ik = 0;ik < kv.get_nks();++ik)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ namespace ModuleIO
for (int is = 0; is < nspin0; ++is)
{
v_hartree_op[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(gint,
&v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd);
&v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin);
v_hartree_op[is]->contributeHR();
}
std::vector<std::vector<double>> e_orb_hartree;
Expand Down
8 changes: 1 addition & 7 deletions source/module_io/write_vxc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,7 @@ void write_Vxc(const int nspin,
for (int is = 0; is < nspin0; ++is)
{
vxcs_op_ao[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(gint,
&vxc_k_ao,
kv.kvec_d,
potxc,
&vxcs_R_ao[is],
&ucell,
orb_cutoff,
&gd);
&vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin);

vxcs_op_ao[is]->contributeHR();
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_lr/esolver_lrtd_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
this->pw_rho->startz_current,
&ucell,
&orb);
this->gint_->initialize_pvpR(ucell, &GlobalC::GridD);
this->gint_->initialize_pvpR(ucell, &GlobalC::GridD, 1); // always use nspin=1 for transition density

// if EXX from scratch, init 2-center integral and calculate Cs, Vs
#ifdef __EXX
Expand Down
2 changes: 1 addition & 1 deletion source/module_lr/lr_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void LR::LR_Spectrum<T>::cal_gint_rho(double** rho, const int& nspin_solve, cons
for (int is = 0;is < nspin_solve;++is) {
ModuleBase::GlobalFunc::ZEROS(rho[is], nrxx);
}
Gint_inout inout_rho(rho, Gint_Tools::job_type::rho, false);
Gint_inout inout_rho(rho, Gint_Tools::job_type::rho, 1, false);
this->gint->cal_gint(&inout_rho);
}

Expand Down
6 changes: 3 additions & 3 deletions source/module_lr/operator_casida/operator_lr_hxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ namespace LR
double** rho_trans;
const int& nrxx = this->pot.lock()->nrxx;
// LR_Util::new_p2(rho_trans, nspin_solve, nrxx);
LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor
LR_Util::new_p2(rho_trans, 1, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor
for (int is = 0;is < nspin_solve;++is)ModuleBase::GlobalFunc::ZEROS(rho_trans[is], nrxx);
Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, false);
Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, 1, false);
this->gint->cal_gint(&inout_rho);

// 3. v_hxc = f_hxc * rho_trans
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace LR
// LR_Util::new_p2(rho_trans, nspin_solve, nrxx);
LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor
for (int is = 0;is < nspin_solve;++is)ModuleBase::GlobalFunc::ZEROS(rho_trans[is], nrxx);
Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, false);
Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, 1, false);
this->gint->cal_gint(&inout_rho);
// print_grid_nonzero(rho_trans[0], nrxx, 10, "rho_trans");

Expand Down

0 comments on commit e170b49

Please sign in to comment.