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();
43 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>
45 if(this->info.files_abfs.empty())
46 { this->abfs = abfs_same_atom;}
51 for(
size_t T=0;
T!=this->abfs.size(); ++
T )
57 for(
const auto &settings_list : this->coulomb_settings)
60 this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb,
61 this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp,
62 this->info.kmesh_times, this->MGT, init_MGT, settings_list.second.first );
69template<
typename Tdata>
81 std::vector<TA> atoms(ucell.
nat);
82 for(
int iat=0; iat<ucell.
nat; ++iat)
84 std::map<TA,TatomR> atoms_pos;
85 for(
int iat=0; iat<ucell.
nat; ++iat)
87 const std::array<TatomR,Ndim> latvec
91 const std::array<Tcell,Ndim> period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]};
93 this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);
96 const std::array<Tcell,Ndim> period_Vs = LRI_CV_Tools::cal_latvec_range<Tcell>(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_);
97 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
98 list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2,
false);
100 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Vs;
101 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>> dVs;
102 for(
const auto &settings_list : this->coulomb_settings)
104 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>
105 Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell,
106 list_As_Vs.first, list_As_Vs.second[0],
107 {{
"writable_Vws",
true}});
113 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>>
114 dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell,
115 list_As_Vs.first, list_As_Vs.second[0],
116 {{
"writable_dVws",true}});
123 this->exx_lri.set_Vs(std::move(Vs), this->info.V_threshold);
127 std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
129 this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold);
132 std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dVRs =
LRI_CV_Tools::cal_dMRs(ucell,dVs_order);
133 this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold);
137 const std::array<Tcell,Ndim> period_Cs = LRI_CV_Tools::cal_latvec_range<Tcell>(2, ucell,orb_cutoff_);
138 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
139 list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2,
false);
141 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Cs;
142 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> dCs;
143 for(
const auto &settings_list : this->coulomb_settings)
145 if(settings_list.second.first)
147 std::pair<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
148 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
149 Cs_dCs = this->exx_objs[settings_list.first].cv.cal_Cs_dCs(
151 list_As_Cs.first, list_As_Cs.second[0],
152 {{
"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress},
153 {
"writable_Cws",true}, {
"writable_dCws",true}, {
"writable_Vws",false}, {
"writable_dVws",false}});
154 std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> &Cs_temp = std::get<0>(Cs_dCs);
160 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> &dCs_temp = std::get<1>(Cs_dCs);
168 this->exx_lri.set_Cs(std::move(Cs), this->info.C_threshold);
172 std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
174 this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold);
177 std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dCRs =
LRI_CV_Tools::cal_dMRs(ucell,dCs_order);
178 this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold);
184template<
typename Tdata>
198 { this->exx_lri.set_symmetry(
false, {}); }
206 this->exx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix);
207 this->exx_lri.cal_Hs({
"",
"",suffix });
211 this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first(
212 this->mpi_comm, std::move(this->exx_lri.Hs), std::get<0>(judge[is]), std::get<1>(judge[is]));
217 auto Hs_a2D = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs);
221 this->exx_lri.energy = this->exx_lri.post_2D.cal_energy(
222 this->exx_lri.post_2D.saves[
"Ds_" + suffix],
223 this->exx_lri.post_2D.set_tensors_map2(Hs_a2D));
225 this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first(
226 this->mpi_comm, std::move(Hs_a2D), std::get<0>(judge[is]), std::get<1>(judge[is]));
228 this->Eexx += std::real(this->exx_lri.energy);
229 post_process_Hexx(this->Hexxs[is]);
231 this->Eexx = post_process_Eexx(this->Eexx);
232 this->exx_lri.set_symmetry(
false, {});
236template<
typename Tdata>
240 constexpr Tdata frac = -1 * 2;
241 const std::function<void(RI::Tensor<Tdata>&)>
242 multiply_frac = [&frac](RI::Tensor<Tdata> &t)
244 RI::Map_Operator::for_each( Hexxs_io, multiply_frac );
247template<
typename Tdata>
251 const double SPIN_multiple = std::map<int, double>{ {1,2}, {2,1}, {4,1} }.at(
PARAM.
inp.
nspin);
252 const double frac = -SPIN_multiple;
253 return frac * Eexx_in;
273template<
typename Tdata>
279 this->force_exx.create(nat, Ndim);
282 this->exx_lri.cal_force({
"",
"",std::to_string(is),
"",
""});
283 for(std::size_t idim=0; idim<Ndim; ++idim) {
284 for(
const auto &force_item : this->exx_lri.force[idim]) {
285 this->force_exx(force_item.first, idim) += std::real(force_item.second);
289 const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(
PARAM.
inp.
nspin);
290 const double frac = -2 * SPIN_multiple;
291 this->force_exx *= frac;
296template<
typename Tdata>
302 this->stress_exx.create(Ndim, Ndim);
305 this->exx_lri.cal_stress({
"",
"",std::to_string(is),
"",
""});
306 for(std::size_t idim0=0; idim0<Ndim; ++idim0) {
307 for(std::size_t idim1=0; idim1<Ndim; ++idim1) {
308 this->stress_exx(idim0,idim1) += std::real(this->exx_lri.stress(idim0,idim1));
312 const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(
PARAM.
inp.
nspin);
313 const double frac = 2 * SPIN_multiple / omega * lat0;
314 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:474
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:14
void post_process_Hexx(std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Hexxs_io) const
Definition Exx_LRI.hpp:237
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:185
double post_process_Eexx(const double &Eexx_in) const
Definition Exx_LRI.hpp:248
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:70
void cal_exx_force(const int &nat)
Definition Exx_LRI.hpp:274
void cal_exx_stress(const double &omega, const double &lat0)
Definition Exx_LRI.hpp:297
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:57
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:47
Atom * atoms
Definition unitcell.h:18
ModuleSymmetry::Symmetry symm
Definition unitcell.h:55
int & nat
Definition unitcell.h:46
ModuleBase::Vector3< double > & a2
Definition unitcell.h:36
ModuleBase::Vector3< double > & a3
Definition unitcell.h:36
int *& iat2ia
Definition unitcell.h:48
ModuleBase::Vector3< double > & a1
Definition unitcell.h:36
Statistics st
Definition unitcell.h:44
#define T
Definition exp.cpp:237
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)
Exx_Info exx_info
Definition test_xc.cpp:29
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
int abfs_Lmax
Definition exx_info.h:71
Exx_Info_RI info_ri
Definition exx_info.h:78
std::string global_out_dir
global output directory
Definition system_parameter.h:42