22#include <RI/distribute/Distribute_Equally.h>
23#include <RI/global/Map_Operator-3.h>
28template<
typename Tdata>
37 this->mpi_comm = mpi_comm_in;
39 this->orb_cutoff_ = orb.
cutoffs();
44 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>
46 if(this->info.files_abfs.empty())
47 { this->abfs = abfs_same_atom;}
55 std::shared_ptr<ORB_gaunt_table> MGT = std::make_shared<ORB_gaunt_table>();
56 for(
const auto &settings_list : this->coulomb_settings)
59 this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb,
60 this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp,
61 this->info.kmesh_times, MGT, settings_list.second.first );
67template<
typename Tdata>
74 std::vector<TA> atoms(ucell.
nat);
75 for(
int iat=0; iat<ucell.
nat; ++iat)
77 std::map<TA,TatomR> atoms_pos;
78 for(
int iat=0; iat<ucell.
nat; ++iat)
80 const std::array<TatomR,Ndim> latvec
84 const std::array<Tcell,Ndim> period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]};
86 this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);
89 const std::array<Tcell,Ndim> period_Vs = LRI_CV_Tools::cal_latvec_range<Tcell>(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_);
90 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
91 list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2,
false);
93 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Vs;
94 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>> dVs;
95 for(
const auto &settings_list : this->coulomb_settings)
97 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>
98 Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell,
99 list_As_Vs.first, list_As_Vs.second[0],
100 {{
"writable_Vws",
true}});
106 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>>
107 dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell,
108 list_As_Vs.first, list_As_Vs.second[0],
109 {{
"writable_dVws",true}});
116 this->exx_lri.set_Vs(std::move(Vs), this->info.V_threshold);
120 std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
122 this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold);
125 std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dVRs =
LRI_CV_Tools::cal_dMRs(ucell,dVs_order);
126 this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold);
130 const std::array<Tcell,Ndim> period_Cs = LRI_CV_Tools::cal_latvec_range<Tcell>(2, ucell,orb_cutoff_);
131 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
132 list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2,
false);
134 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Cs;
135 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> dCs;
136 for(
const auto &settings_list : this->coulomb_settings)
138 if(settings_list.second.first)
140 std::pair<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
141 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
142 Cs_dCs = this->exx_objs[settings_list.first].cv.cal_Cs_dCs(
144 list_As_Cs.first, list_As_Cs.second[0],
145 {{
"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress},
146 {
"writable_Cws",true}, {
"writable_dCws",true}, {
"writable_Vws",false}, {
"writable_dVws",false}});
147 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> &Cs_temp = std::get<0>(Cs_dCs);
153 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> &dCs_temp = std::get<1>(Cs_dCs);
161 this->exx_lri.set_Cs(std::move(Cs), this->info.C_threshold);
165 std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
167 this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold);
170 std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dCRs =
LRI_CV_Tools::cal_dMRs(ucell,dCs_order);
171 this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold);
177template<
typename Tdata>
191 { this->exx_lri.set_symmetry(
false, {}); }
199 this->exx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix);
200 this->exx_lri.cal_Hs({
"",
"",suffix });
204 this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first(
205 this->mpi_comm, std::move(this->exx_lri.Hs), std::get<0>(judge[is]), std::get<1>(judge[is]));
210 auto Hs_a2D = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs);
214 this->exx_lri.energy = this->exx_lri.post_2D.cal_energy(
215 this->exx_lri.post_2D.saves[
"Ds_" + suffix],
216 this->exx_lri.post_2D.set_tensors_map2(Hs_a2D));
218 this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first(
219 this->mpi_comm, std::move(Hs_a2D), std::get<0>(judge[is]), std::get<1>(judge[is]));
221 this->Eexx += std::real(this->exx_lri.energy);
222 post_process_Hexx(this->Hexxs[is]);
224 this->Eexx = post_process_Eexx(this->Eexx);
225 this->exx_lri.set_symmetry(
false, {});
229template<
typename Tdata>
233 constexpr Tdata frac = -1 * 2;
234 const std::function<void(RI::Tensor<Tdata>&)>
235 multiply_frac = [&frac](RI::Tensor<Tdata> &t)
237 RI::Map_Operator::for_each( Hexxs_io, multiply_frac );
240template<
typename Tdata>
244 const double SPIN_multiple = std::map<int, double>{ {1,2}, {2,1}, {4,1} }.at(
PARAM.
inp.
nspin);
245 const double frac = -SPIN_multiple;
246 return frac * Eexx_in;
266template<
typename Tdata>
272 this->force_exx.create(nat, Ndim);
275 this->exx_lri.cal_force({
"",
"",std::to_string(is),
"",
""});
276 for(std::size_t idim=0; idim<Ndim; ++idim) {
277 for(
const auto &force_item : this->exx_lri.force[idim]) {
278 this->force_exx(force_item.first, idim) += std::real(force_item.second);
282 const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(
PARAM.
inp.
nspin);
283 const double frac = -2 * SPIN_multiple;
284 this->force_exx *= frac;
289template<
typename Tdata>
295 this->stress_exx.create(Ndim, Ndim);
298 this->exx_lri.cal_stress({
"",
"",std::to_string(is),
"",
""});
299 for(std::size_t idim0=0; idim0<Ndim; ++idim0) {
300 for(std::size_t idim1=0; idim1<Ndim; ++idim1) {
301 this->stress_exx(idim0,idim1) += std::real(this->exx_lri.stress(idim0,idim1));
305 const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(
PARAM.
inp.
nspin);
306 const double frac = 2 * SPIN_multiple / omega * lat0;
307 this->stress_exx *= frac;
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:36
static void print_orbs_size(const UnitCell &ucell, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orbs, std::ostream &os)
Definition exx_abfs-construct_orbs.cpp:476
static void filter_empty_orbs(std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orbs)
Definition exx_abfs-construct_orbs.cpp:546
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > abfs_same_atom(const UnitCell &ucell, const LCAO_Orbitals &orb, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &lcaos, const double kmesh_times_mot, const double times_threshold=0)
Definition exx_abfs-construct_orbs.cpp:81
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > change_orbs(const LCAO_Orbitals &orb_in, const double kmesh_times)
Definition exx_abfs-construct_orbs.cpp:11
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > construct_abfs(const LCAO_Orbitals &orbs, const std::vector< std::string > &files_abfs, const double kmesh_times=1)
Definition exx_abfs-io.cpp:13
void post_process_Hexx(std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Hexxs_io) const
Definition Exx_LRI.hpp:230
void init(const MPI_Comm &mpi_comm_in, const UnitCell &ucell, const K_Vectors &kv_in, const LCAO_Orbitals &orb)
Definition Exx_LRI.hpp:29
void cal_exx_elec(const std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > &Ds, const UnitCell &ucell, const Parallel_Orbitals &pv, const ModuleSymmetry::Symmetry_rotation *p_symrot=nullptr)
Definition Exx_LRI.hpp:178
double post_process_Eexx(const double &Eexx_in) const
Definition Exx_LRI.hpp:241
std::pair< TA, TC > TAC
Definition Exx_LRI.h:57
int TA
Definition Exx_LRI.h:53
void cal_exx_ions(const UnitCell &ucell, const bool write_cv=false)
Definition Exx_LRI.hpp:68
void cal_exx_force(const int &nat)
Definition Exx_LRI.hpp:267
void cal_exx_stress(const double &omega, const double &lat0)
Definition Exx_LRI.hpp:290
std::vector< double > cutoffs() const
Definition ORB_read.cpp:40
static void tick(const std::string &class_name_in, const std::string &name_in)
Use twice at a time: the first time, set start_flag to false; the second time, calculate the time dur...
Definition timer.cpp:62
Definition symmetry_rotation.h:16
std::map< int, std::map< std::pair< int, TC >, RI::Tensor< Tdata > > > restore_HR(const Symmetry &symm, const Atom *atoms, const Statistics &st, const char mode, const std::map< int, std::map< std::pair< int, TC >, RI::Tensor< Tdata > > > &HR_irreduceble) const
Definition symmetry_rotation_R.hpp:40
const std::map< Tap, std::set< TC > > & get_irreducible_sector() const
Definition symmetry_rotation.h:23
Definition parallel_orbitals.h:9
const Input_para & inp
Definition parameter.h:26
const System_para & globalv
Definition parameter.h:30
int *& iat2it
Definition unitcell.h:49
Atom * atoms
Definition unitcell.h:19
ModuleSymmetry::Symmetry symm
Definition unitcell.h:57
int & nat
Definition unitcell.h:48
ModuleBase::Vector3< double > & a2
Definition unitcell.h:38
ModuleBase::Vector3< double > & a3
Definition unitcell.h:38
int *& iat2ia
Definition unitcell.h:50
ModuleBase::Vector3< double > & a1
Definition unitcell.h:38
Statistics st
Definition unitcell.h:46
T cal_orbs_ccp(const T &orbs, const std::map< Conv_Coulomb_Pot_K::Coulomb_Type, std::vector< std::map< std::string, std::string > > > &coulomb_param, const double rmesh_times)
int MY_RANK
global index of process
Definition global_variable.cpp:21
std::ofstream ofs_running
Definition global_variable.cpp:38
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
std::vector< std::tuple< std::set< TA >, std::set< TA > > > get_2D_judge(const UnitCell &ucell, const Parallel_2D &pv)
Definition RI_2D_Comm.cpp:15
std::array< Tcell, 3 > Vector3_to_array3(const ModuleBase::Vector3< Tcell > &v)
Definition RI_Util.h:32
std::map< Conv_Coulomb_Pot_K::Coulomb_Method, std::pair< bool, std::map< Conv_Coulomb_Pot_K::Coulomb_Type, std::vector< std::map< std::string, std::string > > > > > update_coulomb_settings(const std::map< Conv_Coulomb_Pot_K::Coulomb_Type, std::vector< std::map< std::string, std::string > > > &coulomb_param, const UnitCell &ucell, const K_Vectors *p_kv)
Definition RI_Util.hpp:105
Parameter PARAM
Definition parameter.cpp:3
std::string global_out_dir
global output directory
Definition system_parameter.h:42