Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion source/source_lcao/module_hcontainer/test/test_add_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ class AddValueTest : public ::testing::Test
{
auto* hc = new hamilt::HContainer<double>(&paraV);
insert_all_pairs(hc);
for (auto& [i, j, vals] : fill)
for (auto& item : fill)
{
int i = std::get<0>(item);
int j = std::get<1>(item);
const std::vector<double>& vals = std::get<2>(item);
double* ptr = hc->find_matrix(i, j, 0, 0, 0)->get_pointer();
for (int k = 0; k < (int)vals.size(); k++)
ptr[k] = vals[k];
Expand Down
7 changes: 4 additions & 3 deletions source/source_lcao/module_ri/Exx_LRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ class Exx_LRI
ModuleBase::matrix force_exx;
ModuleBase::matrix stress_exx;

int abfs_Lmax() const { return abfs_Lmax_; }
const Exx_Info_RI& get_info_ri() const { return info; }

private:
// WARNING: reference to Exx_Info_RI, which holds references into Exx_Info_Global.
// Must not outlive GlobalC::exx_info. See exx_info.h for details.
const Exx_Info_RI &info;
Exx_Info_RI info;
int abfs_Lmax_ = 0;
MPI_Comm mpi_comm;
const K_Vectors *p_kv = nullptr;
std::shared_ptr<ORB_gaunt_table> MGT;
Expand Down
13 changes: 9 additions & 4 deletions source/source_lcao/module_ri/Exx_LRI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in,
Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running);

for( size_t T=0; T!=this->abfs.size(); ++T )
{ GlobalC::exx_info.info_ri.abfs_Lmax = std::max( GlobalC::exx_info.info_ri.abfs_Lmax, static_cast<int>(this->abfs[T].size())-1 ); }
{
this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast<int>(this->abfs[T].size())-1);
}

this->exx_objs.clear();
this->coulomb_settings = RI_Util::update_coulomb_settings(this->info.coulomb_param, ucell, this->p_kv);
Expand All @@ -77,11 +79,14 @@ void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in,
this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb,
this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp,
this->info.kmesh_times, this->MGT, settings_list.second.first );
this->exx_objs[settings_list.first].cv.set_info_ri(&this->info);
if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald)
{
const int evq_abfs_Lmax = this->abfs_Lmax_;
this->exx_objs[settings_list.first].evq.init(ucell, orb,
this->mpi_comm, this->p_kv, this->lcaos, this->abfs,
settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times);
settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times,
evq_abfs_Lmax);
}
}

Expand Down Expand Up @@ -125,8 +130,7 @@ void Exx_LRI<Tdata>::init_spencer(

for (size_t T = 0; T != this->abfs.size(); ++T)
{
GlobalC::exx_info.info_ri.abfs_Lmax
= std::max(GlobalC::exx_info.info_ri.abfs_Lmax, static_cast<int>(this->abfs[T].size()) - 1);
this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast<int>(this->abfs[T].size()) - 1);
}

this->exx_objs.clear();
Expand All @@ -152,6 +156,7 @@ void Exx_LRI<Tdata>::init_spencer(
this->info.kmesh_times,
this->MGT,
center2_settings->second.first);
this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_info_ri(&this->info);

ModuleBase::timer::end("Exx_LRI", "init_spencer");
}
Expand Down
12 changes: 10 additions & 2 deletions source/source_lcao/module_ri/Exx_LRI_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.h"
#include "source_estate/module_dm/density_matrix.h" // mohan add 2025-11-04
#include "source_hamilt/hamilt.h"
#include "source_hamilt/module_xc/exx_info_global.h"
#include <memory>

class LCAO_Matrix;
Expand Down Expand Up @@ -39,9 +40,10 @@ class Exx_LRI_Interface
using TAC = std::pair<TA, TC>;

/// @brief Constructor for Exx_LRI_Interface
Exx_LRI_Interface(const Exx_Info_RI& info)
Exx_LRI_Interface(const Exx_Info_RI& info_ri, const Exx_Info_Global& info_global)
{
this->exx_ptr = std::make_shared<Exx_LRI<Tdata>>(info);
this->exx_ptr = std::make_shared<Exx_LRI<Tdata>>(info_ri);
this->info_global = info_global;
}
Exx_LRI_Interface() = delete;

Expand Down Expand Up @@ -138,12 +140,18 @@ class Exx_LRI_Interface
double etot_last_outer_loop = 0.0;
elecstate::DensityMatrix<T, double>* dm_last_step;

size_t hybrid_step() const { return hybrid_step_; }
void set_hybrid_step(size_t s) { hybrid_step_ = s; }

std::shared_ptr<Exx_LRI<Tdata>> exx_ptr;

private:

Mix_DMk_2D<T> mix_DMk_2D;

Exx_Info_Global info_global;
size_t hybrid_step_ = 1;

bool exx_spacegroup_symmetry = false;
ModuleSymmetry::Symmetry_rotation symrot_;

Expand Down
41 changes: 20 additions & 21 deletions source/source_lcao/module_ri/Exx_LRI_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "source_base/formatter.h"
#include "source_base/parallel_common.h"
#include "source_estate/elecstate_lcao.h"
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
#include "source_hamilt/module_xc/xc_functional.h"
#include "source_io/module_hs/write_HS_sparse.h"
#include "source_io/module_output/csr_reader.h"
Expand Down Expand Up @@ -136,7 +135,7 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const int istep,
{
ModuleBase::TITLE("Exx_LRI_Interface","exx_beforescf");
#ifdef __MPI
if (GlobalC::exx_info.info_global.cal_exx)
if (this->info_global.cal_exx)
{
if ((GlobalC::restart.info_load.load_H_finish && !GlobalC::restart.info_load.restart_exx)
|| (istep > 0)
Expand All @@ -153,15 +152,15 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const int istep,
}

// set initial parameter for mix_DMk_2D
if(GlobalC::exx_info.info_global.cal_exx)
if(this->info_global.cal_exx)
{
if (this->exx_spacegroup_symmetry)
{ this->mix_DMk_2D.set_nks(kv.get_nkstot_full() * (PARAM.inp.nspin == 2 ? 2 : 1)); }
else
{ this->mix_DMk_2D.set_nks(kv.get_nks()); }

if (GlobalC::exx_info.info_global.separate_loop)
{ this->mix_DMk_2D.set_mixing_plain(GlobalC::exx_info.info_global.mixing_beta_for_loop1); }
if (this->info_global.separate_loop)
{ this->mix_DMk_2D.set_mixing_plain(this->info_global.mixing_beta_for_loop1); }
else
{ this->mix_DMk_2D.set_mixing(chgmix.get_mixing()); }

Expand All @@ -179,13 +178,13 @@ void Exx_LRI_Interface<T, Tdata>::exx_eachiterinit(const int istep,
const int& iter)
{
ModuleBase::TITLE("Exx_LRI_Interface","exx_eachiterinit");
if (GlobalC::exx_info.info_global.cal_exx)
if (this->info_global.cal_exx)
{
if (!GlobalC::exx_info.info_global.separate_loop
if (!this->info_global.separate_loop
&& (this->two_level_step
|| istep > 0
|| PARAM.inp.init_wfc == "file") // non separate loop case
|| (GlobalC::exx_info.info_global.separate_loop
|| (this->info_global.separate_loop
&& PARAM.inp.init_wfc == "file"
&& this->two_level_step == 0
&& iter == 1)
Expand All @@ -207,7 +206,7 @@ void Exx_LRI_Interface<T, Tdata>::exx_eachiterinit(const int istep,
*dm_in.get_paraV_pointer(),
PARAM.inp.nspin,
this->exx_spacegroup_symmetry);
if(this->exx_spacegroup_symmetry && GlobalC::exx_info.info_ri.exx_symmetry_realspace)
if(this->exx_spacegroup_symmetry && this->exx_ptr->info.exx_symmetry_realspace)
{ this->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer(), &this->symrot_); }
else
{ this->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer()); }
Expand Down Expand Up @@ -241,10 +240,10 @@ void Exx_LRI_Interface<T, Tdata>::exx_hamilt2rho(elecstate::ElecState& elec, con
{ std::cout << "WARNING: Cannot read Eexx from disk, the energy of the 1st loop will be wrong, sbut it does not influence the subsequent loops." << std::endl; }
}
Parallel_Common::bcast_double(this->exx_ptr->Eexx);
this->exx_ptr->Eexx /= GlobalC::exx_info.info_global.hybrid_alpha;
this->exx_ptr->Eexx /= this->info_global.hybrid_alpha;
}
bool cal_exx = GlobalC::exx_info.info_global.cal_exx;
double hybrid_alpha = GlobalC::exx_info.info_global.hybrid_alpha;
bool cal_exx = this->info_global.cal_exx;
double hybrid_alpha = this->info_global.hybrid_alpha;
elec.set_exx(this->get_Eexx(), cal_exx, hybrid_alpha);
}
else
Expand All @@ -267,7 +266,7 @@ void Exx_LRI_Interface<T, Tdata>::exx_iter_finish(const K_Vectors& kv,
{
ModuleBase::TITLE("Exx_LRI_Interface","exx_iter_finish");
if (GlobalC::restart.info_save.save_H && (this->two_level_step > 0 || istep > 0)
&& (!GlobalC::exx_info.info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly
&& (!this->info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly
{
////////// for Add_Hexx_Type::k
/*
Expand Down Expand Up @@ -296,13 +295,13 @@ void Exx_LRI_Interface<T, Tdata>::exx_iter_finish(const K_Vectors& kv,
}
}

if (GlobalC::exx_info.info_global.cal_exx && conv_esolver)
if (this->info_global.cal_exx && conv_esolver)
{
// Kerker mixing does not work for the density matrix.
// In the separate loop case, it can still work in the subsequent inner loops where Hexx(DM) is fixed.
// In the non-separate loop case where Hexx(DM) is updated in every iteration of the 2nd loop, it should be
// closed.
if (!GlobalC::exx_info.info_global.separate_loop)
if (!this->info_global.separate_loop)
{
chgmix.close_kerker_gg0();
}
Expand Down Expand Up @@ -333,7 +332,7 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
const int& istep,
const double& etot,
const double& scf_ene_thr)
{ // only called if (GlobalC::exx_info.info_global.cal_exx)
{ // only called if (this->info_global.cal_exx)
ModuleBase::TITLE("Exx_LRI_Interface","exx_after_converge");
auto restart_reset = [this]()
{ // avoid calling restart related procedure in the subsequent ion steps
Expand All @@ -342,9 +341,9 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
};

// no separate_loop case
if (!GlobalC::exx_info.info_global.separate_loop)
if (!this->info_global.separate_loop)
{
GlobalC::exx_info.info_global.hybrid_step = 1;
this->hybrid_step_ = 1;

// in no_separate_loop case, scf loop only did twice
// in first scf loop, exx updated once in beginning,
Expand All @@ -371,7 +370,7 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
if (two_level_step)
{ std::cout << FmtCore::format(" deltaE (eV) from outer loop: %.8e \n", ediff); }
// exx converged or get max exx steps
if (this->two_level_step == GlobalC::exx_info.info_global.hybrid_step
if (this->two_level_step == this->hybrid_step_
|| (iter == 1 && this->two_level_step != 0) // density convergence of outer loop
|| (ediff < scf_ene_thr && this->two_level_step != 0)) //energy convergence of outer loop
{
Expand Down Expand Up @@ -403,7 +402,7 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
*dm.get_paraV_pointer(),
nspin,
this->exx_spacegroup_symmetry);
if(this->exx_spacegroup_symmetry && GlobalC::exx_info.info_ri.exx_symmetry_realspace)
if(this->exx_spacegroup_symmetry && this->exx_ptr->info.exx_symmetry_realspace)
{ this->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer(), &this->symrot_); }
else
{ this->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer()); } // restore DM but not Hexx
Expand All @@ -418,7 +417,7 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
<< std::defaultfloat << " (s)" << std::endl;
return false;
}
} // if(GlobalC::exx_info.info_global.separate_loop)
} // if(this->info_global.separate_loop)
restart_reset();
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions source/source_lcao/module_ri/LRI_CV.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "source_basis/module_ao/ORB_atomic_lm.h"
#include "abfs-vector3_order.h"
#include "source_base/element_basis_index.h"
#include "source_hamilt/module_xc/exx_info_ri.h"

#include <RI/global/Tensor.h>
#include <RI/global/Global_Func-2.h>
Expand All @@ -33,6 +34,8 @@ class LRI_CV
LRI_CV();
~LRI_CV();

void set_info_ri(const Exx_Info_RI* p) { p_info_ri = p; }

void set_orbitals(
const UnitCell &ucell,
const LCAO_Orbitals& orb,
Expand Down Expand Up @@ -72,6 +75,7 @@ class LRI_CV
ModuleBase::Element_Basis_Index::IndexLNM index_abfs;
std::vector<double> lcaos_rcut;
std::vector<double> abfs_ccp_rcut;
const Exx_Info_RI* p_info_ri = nullptr;

public:
std::map<int,std::map<int,std::map<Abfs::Vector3_Order<double>,RI::Tensor<Tdata>>>> Vws;
Expand Down
12 changes: 7 additions & 5 deletions source/source_lcao/module_ri/LRI_CV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "../../source_basis/module_ao/element_basis_index-ORB.h"
#include "../../source_base/tool_title.h"
#include "../../source_base/timer.h"
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
#include "source_hamilt/module_xc/exx_info_ri.h"
#include <RI/global/Global_Func-1.h>
#include <omp.h>

Expand Down Expand Up @@ -353,8 +353,9 @@ LRI_CV<Tdata>::DPcal_C_dC(
Matrix_Orbs21::Matrix_Order::A1A2B);
const RI::Tensor<Tdata> V = this->DPcal_V(it0, it0, {0, 0, 0}, {{"writable_Vws", true}});
RI::Tensor<Tdata> L;
if (GlobalC::exx_info.info_ri.Cs_inv_thr > 0)
L = LRI_CV_Tools::cal_I(V, Inverse_Matrix<Tdata>::Method::syev, GlobalC::exx_info.info_ri.Cs_inv_thr);
const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0;
if (cs_inv_thr > 0)
L = LRI_CV_Tools::cal_I(V, Inverse_Matrix<Tdata>::Method::syev, cs_inv_thr);
else
L = LRI_CV_Tools::cal_I(V);

Expand Down Expand Up @@ -405,8 +406,9 @@ LRI_CV<Tdata>::DPcal_C_dC(
DPcal_V(it1, it1, {0,0,0}, {{"writable_Vws",true}})}};

std::vector<std::vector<RI::Tensor<Tdata>>> L;
if (GlobalC::exx_info.info_ri.Cs_inv_thr > 0)
L = LRI_CV_Tools::cal_I(V, Inverse_Matrix<Tdata>::Method::syev, GlobalC::exx_info.info_ri.Cs_inv_thr);
const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0;
if (cs_inv_thr > 0)
L = LRI_CV_Tools::cal_I(V, Inverse_Matrix<Tdata>::Method::syev, cs_inv_thr);
else
L = LRI_CV_Tools::cal_I(V);

Expand Down
5 changes: 1 addition & 4 deletions source/source_lcao/module_ri/RPA_LRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ template <typename T, typename Tdata> class RPA_LRI
Tdata Erpa;

private:
// WARNING: reference to Exx_Info_RI, which holds references into Exx_Info_Global.
// Must not outlive GlobalC::exx_info. See exx_info.h for details.
const Exx_Info_RI &info;
Exx_Info_RI info;
const K_Vectors *p_kv=nullptr;
MPI_Comm mpi_comm;
std::vector<double> orb_cutoff_;
Expand All @@ -109,7 +107,6 @@ template <typename T, typename Tdata> class RPA_LRI
Exx_LRI<double>* exx_cut_coulomb = nullptr;
Exx_LRI<double>* exx_full_coulomb = nullptr;
};
Exx_LRI<double> exx_lri_rpa(GlobalC::exx_info.info_ri);
#include "RPA_LRI.hpp"

#endif
Loading
Loading