Skip to content

Commit 8f02084

Browse files
committed
fix bug and update code format in exx
1 parent f7cb1d3 commit 8f02084

File tree

6 files changed

+255
-207
lines changed

6 files changed

+255
-207
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
183183
// initialize 2-center radial tables for EXX-LRI
184184
if (GlobalC::exx_info.info_ri.real_number)
185185
{
186-
this->exx_lri_double->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
186+
this->exd->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
187187
this->exd->exx_before_all_runners(this->kv, ucell, this->pv);
188188
}
189189
else
190190
{
191-
this->exx_lri_complex->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
191+
this->exc->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
192192
this->exc->exx_before_all_runners(this->kv, ucell, this->pv);
193193
}
194194
}

source/module_ri/Exx_LRI.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
#include "module_exx_symmetry/symmetry_rotation.h"
2222

2323
class Parallel_Orbitals;
24-
24+
2525
template<typename T, typename Tdata>
2626
class RPA_LRI;
2727

2828
template<typename T, typename Tdata>
2929
class Exx_LRI_Interface;
3030

31-
namespace LR
32-
{
33-
template<typename T, typename TR>
34-
class ESolver_LR;
31+
namespace LR
32+
{
33+
template<typename T, typename TR>
34+
class ESolver_LR;
3535

36-
template<typename T>
37-
class OperatorLREXX;
38-
}
36+
template<typename T>
37+
class OperatorLREXX;
38+
}
3939

4040
template<typename Tdata>
4141
class Exx_LRI
@@ -49,37 +49,37 @@ class Exx_LRI
4949
using TatomR = std::array<double,Ndim>; // tmp
5050

5151
public:
52-
Exx_LRI(const Exx_Info::Exx_Info_RI& info_in) :info(info_in) {}
53-
Exx_LRI operator=(const Exx_LRI&) = delete;
54-
Exx_LRI operator=(Exx_LRI&&);
52+
Exx_LRI(const Exx_Info::Exx_Info_RI& info_in) :info(info_in) {}
53+
Exx_LRI operator=(const Exx_LRI&) = delete;
54+
Exx_LRI operator=(Exx_LRI&&);
5555

56-
void reset_Cs(const std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>& Cs_in) { this->exx_lri.set_Cs(Cs_in, this->info.C_threshold); }
57-
void reset_Vs(const std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>& Vs_in) { this->exx_lri.set_Vs(Vs_in, this->info.V_threshold); }
56+
void reset_Cs(const std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>& Cs_in) { this->exx_lri.set_Cs(Cs_in, this->info.C_threshold); }
57+
void reset_Vs(const std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>& Vs_in) { this->exx_lri.set_Vs(Vs_in, this->info.V_threshold); }
5858

59-
void init(const MPI_Comm &mpi_comm_in,
59+
void init(const MPI_Comm &mpi_comm_in,
6060
const UnitCell &ucell,
61-
const K_Vectors &kv_in,
61+
const K_Vectors &kv_in,
6262
const LCAO_Orbitals& orb);
6363
void cal_exx_force(const int& nat);
64-
void cal_exx_stress(const double& omega, const double& lat0);
64+
void cal_exx_stress(const double& omega, const double& lat0);
6565
void cal_exx_ions(const UnitCell& ucell, const bool write_cv = false);
66-
void cal_exx_elec(const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Ds,
66+
void cal_exx_elec(const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Ds,
6767
const UnitCell& ucell,
68-
const Parallel_Orbitals& pv,
69-
const ModuleSymmetry::Symmetry_rotation* p_symrot = nullptr);
70-
std::vector<std::vector<int>> get_abfs_nchis() const;
68+
const Parallel_Orbitals& pv,
69+
const ModuleSymmetry::Symmetry_rotation* p_symrot = nullptr);
70+
std::vector<std::vector<int>> get_abfs_nchis() const;
7171

7272
std::vector< std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> Hexxs;
73-
double Eexx;
73+
double Eexx;
7474
ModuleBase::matrix force_exx;
7575
ModuleBase::matrix stress_exx;
76-
76+
7777

7878
private:
7979
const Exx_Info::Exx_Info_RI &info;
8080
MPI_Comm mpi_comm;
8181
const K_Vectors *p_kv = nullptr;
82-
std::vector<double> orb_cutoff_;
82+
std::vector<double> orb_cutoff_;
8383

8484
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> lcaos;
8585
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs;
@@ -89,16 +89,16 @@ class Exx_LRI
8989
RI::Exx<TA,Tcell,Ndim,Tdata> exx_lri;
9090

9191
void post_process_Hexx( std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> &Hexxs_io ) const;
92-
double post_process_Eexx(const double& Eexx_in) const;
92+
double post_process_Eexx(const double& Eexx_in) const;
9393

9494
friend class RPA_LRI<double, Tdata>;
9595
friend class RPA_LRI<std::complex<double>, Tdata>;
9696
friend class Exx_LRI_Interface<double, Tdata>;
9797
friend class Exx_LRI_Interface<std::complex<double>, Tdata>;
98-
friend class LR::ESolver_LR<double, double>;
99-
friend class LR::ESolver_LR<std::complex<double>, double>;
100-
friend class LR::OperatorLREXX<double>;
101-
friend class LR::OperatorLREXX<std::complex<double>>;
98+
friend class LR::ESolver_LR<double, double>;
99+
friend class LR::ESolver_LR<std::complex<double>, double>;
100+
friend class LR::OperatorLREXX<double>;
101+
friend class LR::OperatorLREXX<std::complex<double>>;
102102
};
103103

104104
#include "Exx_LRI.hpp"

source/module_ri/Exx_LRI.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include <string>
2727

2828
template<typename Tdata>
29-
void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in,
29+
void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in,
3030
const UnitCell &ucell,
31-
const K_Vectors &kv_in,
31+
const K_Vectors &kv_in,
3232
const LCAO_Orbitals& orb)
3333
{
3434
ModuleBase::TITLE("Exx_LRI","init");
@@ -130,7 +130,7 @@ void Exx_LRI<Tdata>::cal_exx_ions(const UnitCell& ucell,
130130
this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);
131131

132132
// std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour.
133-
const std::array<Tcell,Ndim> period_Vs = LRI_CV_Tools::cal_latvec_range<Tcell>(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_);
133+
const std::array<Tcell,Ndim> period_Vs = LRI_CV_Tools::cal_latvec_range<Tcell>(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_);
134134
const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
135135
list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false);
136136

@@ -237,7 +237,7 @@ void Exx_LRI<Tdata>::cal_exx_elec(const std::vector<std::map<TA, std::map<TAC, R
237237
}
238238
this->Eexx = post_process_Eexx(this->Eexx);
239239
this->exx_lri.set_symmetry(false, {});
240-
ModuleBase::timer::tick("Exx_LRI", "cal_exx_elec");
240+
ModuleBase::timer::tick("Exx_LRI", "cal_exx_elec");
241241
}
242242

243243
template<typename Tdata>
@@ -283,11 +283,6 @@ void Exx_LRI<Tdata>::cal_exx_force(const int& nat)
283283
ModuleBase::TITLE("Exx_LRI","cal_exx_force");
284284
ModuleBase::timer::tick("Exx_LRI", "cal_exx_force");
285285

286-
if (!this->exx_lri.flag_finish.D)
287-
{
288-
ModuleBase::WARNING_QUIT("Force_Stress_LCAO", "Cannot calculate EXX force when the first PBE loop is not converged.");
289-
}
290-
291286
this->force_exx.create(nat, Ndim);
292287
for(int is=0; is<PARAM.inp.nspin; ++is)
293288
{

source/module_ri/Exx_LRI_interface.h

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ class Exx_LRI_Interface
4444
void read_Hexxs_cereal(const std::string& file_name);
4545

4646
std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& get_Hexxs() const { return this->exx_ptr->Hexxs; }
47-
47+
4848
double& get_Eexx() const { return this->exx_ptr->Eexx; }
4949

50+
// Processes in ESolver_KS_LCAO
51+
/// @brief Exx_LRI::init()
52+
void init(const MPI_Comm &mpi_comm,
53+
const UnitCell &ucell,
54+
const K_Vectors &kv,
55+
const LCAO_Orbitals& orb);
56+
5057
// Processes in ESolver_KS_LCAO
5158
/// @brief in before_all_runners: set symmetry according to irreducible k-points
52-
/// since k-points are not reduced again after the variation of the cell and exx-symmetry must be consistent with k-points.
59+
/// since k-points are not reduced again after the variation of the cell and exx-symmetry must be consistent with k-points.
5360
/// In the future, we will reduce k-points again during cell-relax, then this setting can be moved to `exx_beforescf`.
5461
void exx_before_all_runners(const K_Vectors& kv, const UnitCell& ucell, const Parallel_2D& pv);
5562

@@ -58,23 +65,23 @@ class Exx_LRI_Interface
5865

5966
/// @brief in eachiterinit: do DM mixing and calculate Hexx when entering 2nd SCF
6067
void exx_eachiterinit(const int istep,
61-
const UnitCell& ucell,
68+
const UnitCell& ucell,
6269
const elecstate::DensityMatrix<T, double>& dm/**< double should be Tdata if complex-PBE-DM is supported*/,
63-
const K_Vectors& kv,
70+
const K_Vectors& kv,
6471
const int& iter);
6572

6673
/// @brief in hamilt2density: calculate Hexx and Eexx
6774
void exx_hamilt2density(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter);
6875

6976
/// @brief in iter_finish: write Hexx, do something according to whether SCF is converged
70-
void exx_iter_finish(const K_Vectors& kv,
77+
void exx_iter_finish(const K_Vectors& kv,
7178
const UnitCell& ucell,
72-
hamilt::Hamilt<T>& hamilt,
73-
elecstate::ElecState& elec,
79+
hamilt::Hamilt<T>& hamilt,
80+
elecstate::ElecState& elec,
7481
Charge_Mixing& chgmix,
75-
const double& scf_ene_thr,
76-
int& iter,
77-
const int istep,
82+
const double& scf_ene_thr,
83+
int& iter,
84+
const int istep,
7885
bool& conv_esolver);
7986
/// @brief: in do_after_converge: add exx operators; do DM mixing if seperate loop
8087
bool exx_after_converge(const UnitCell& ucell,
@@ -86,6 +93,13 @@ class Exx_LRI_Interface
8693
const int& istep,
8794
const double& etot,
8895
const double& scf_ene_thr);
96+
97+
/// @brief: in cal_exx_force: Exx_LRI::cal_exx_force()
98+
void cal_exx_force(const double& omega, const double& lat0);
99+
100+
/// @brief: in cal_exx_stress: Exx_LRI::cal_exx_stress()
101+
void cal_exx_stress(const double& omega, const double& lat0);
102+
89103
int two_level_step = 0;
90104
double etot_last_outer_loop = 0.0;
91105
elecstate::DensityMatrix<T, double>* dm_last_step;
@@ -95,6 +109,16 @@ class Exx_LRI_Interface
95109

96110
bool exx_spacegroup_symmetry = false;
97111
ModuleSymmetry::Symmetry_rotation symrot_;
112+
113+
struct Flag_Finish
114+
{
115+
bool init = false;
116+
bool ions = false;
117+
bool elec = false;
118+
bool force = false;
119+
bool stress = false;
120+
};
121+
Flag_Finish flag_finish;
98122
};
99123

100124
#include "Exx_LRI_interface.hpp"

0 commit comments

Comments
 (0)