Skip to content

Commit 087a9af

Browse files
committed
add setup_exx
1 parent 15fe01c commit 087a9af

File tree

6 files changed

+108
-89
lines changed

6 files changed

+108
-89
lines changed

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,7 @@ ESolver_KS_LCAO<TK, TR>::ESolver_KS_LCAO()
3535
{
3636
this->classname = "ESolver_KS_LCAO";
3737
this->basisname = "LCAO";
38-
39-
#ifdef __EXX
40-
// 1. currently this initialization must be put in constructor rather than `before_all_runners()`
41-
// because the latter is not reused by ESolver_LCAO_TDDFT,
42-
// which cause the failure of the subsequent procedure reused by ESolver_LCAO_TDDFT
43-
// 2. always construct but only initialize when if(cal_exx) is true
44-
// because some members like two_level_step are used outside if(cal_exx)
45-
if (GlobalC::exx_info.info_ri.real_number)
46-
{
47-
this->exd = std::make_shared<Exx_LRI_Interface<TK, double>>(GlobalC::exx_info.info_ri);
48-
}
49-
else
50-
{
51-
this->exc = std::make_shared<Exx_LRI_Interface<TK, std::complex<double>>>(GlobalC::exx_info.info_ri);
52-
}
53-
#endif
38+
this->exx_nao.init(); // mohan add 20251008
5439
}
5540

5641
template <typename TK, typename TR>
@@ -137,31 +122,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
137122
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->init_DM(&this->kv, &(this->pv), inp.nspin);
138123

139124
// 8) init exact exchange calculations
140-
#ifdef __EXX
141-
if (inp.calculation == "scf" || inp.calculation == "relax" || inp.calculation == "cell-relax"
142-
|| inp.calculation == "md")
143-
{
144-
if (GlobalC::exx_info.info_global.cal_exx)
145-
{
146-
if (inp.init_wfc != "file")
147-
{ // if init_wfc==file, directly enter the EXX loop
148-
XC_Functional::set_xc_first_loop(ucell);
149-
}
150-
151-
// initialize 2-center radial tables for EXX-LRI
152-
if (GlobalC::exx_info.info_ri.real_number)
153-
{
154-
this->exd->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
155-
this->exd->exx_before_all_runners(this->kv, ucell, this->pv);
156-
}
157-
else
158-
{
159-
this->exc->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
160-
this->exc->exx_before_all_runners(this->kv, ucell, this->pv);
161-
}
162-
}
163-
}
164-
#endif
125+
exx_nao.before_runner();
165126

166127
// 9) initialize DFT+U
167128
if (inp.dft_plus_u)
@@ -280,10 +241,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
280241
this->ld,
281242
"tot",
282243
#endif
283-
#ifdef __EXX
284-
*this->exd,
285-
*this->exc,
286-
#endif
244+
this->exx_nao,
287245
&ucell.symm);
288246

289247
// delete RA after cal_force
@@ -434,7 +392,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
434392
#ifdef __EXX
435393
// calculate exact-exchange
436394
if (PARAM.inp.calculation != "nscf")
437-
q
438395
{
439396
if (GlobalC::exx_info.info_ri.real_number)
440397
{

source/source_esolver/esolver_ks_lcao.h

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,17 @@
22
#define ESOLVER_KS_LCAO_H
33

44
#include "esolver_ks.h"
5-
6-
// for adjacent atoms
7-
#include "source_lcao/record_adj.h"
8-
9-
// for NAO basis
10-
#include "source_basis/module_nao/two_center_bundle.h"
11-
12-
// for grid integration
13-
#include "source_lcao/module_gint/gint_gamma.h"
14-
#include "source_lcao/module_gint/gint_k.h"
15-
#include "source_lcao/module_gint/temp_gint/gint.h"
5+
#include "source_lcao/record_adj.h" // adjacent atoms
6+
#include "source_basis/module_nao/two_center_bundle.h" // nao basis
7+
#include "source_lcao/module_gint/gint_gamma.h" // gint for gamma-only k-points
8+
#include "source_lcao/module_gint/gint_k.h" // gint for multi k-points
9+
#include "source_lcao/module_gint/temp_gint/gint.h" // gint
1610
#include "source_lcao/module_gint/temp_gint/gint_info.h"
17-
18-
// for DeePKS
1911
#ifdef __MLALGO
20-
#include "source_lcao/module_deepks/LCAO_deepks.h"
12+
#include "source_lcao/module_deepks/LCAO_deepks.h" // deepks
2113
#endif
22-
23-
// for EXX
24-
#ifdef __EXX
25-
#include "source_lcao/module_ri/Exx_LRI_interface.h"
26-
#include "source_lcao/module_ri/Mix_DMk_2D.h"
27-
#endif
28-
29-
// for RDMFT
30-
#include "source_lcao/module_rdmft/rdmft.h"
14+
#include "source_lcao/module_ri/setup_exx.h" // for exx, mohan add 20251008
15+
#include "source_lcao/module_rdmft/rdmft.h" // rdmft
3116

3217
#include <memory>
3318

@@ -118,10 +103,7 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>
118103
LCAO_Deepks<TK> ld;
119104
#endif
120105

121-
#ifdef __EXX
122-
std::shared_ptr<Exx_LRI_Interface<TK, double>> exd = nullptr;
123-
std::shared_ptr<Exx_LRI_Interface<TK, std::complex<double>>> exc = nullptr;
124-
#endif
106+
Exx_NAO exx_nao;
125107

126108
friend class LR::ESolver_LR<double, double>;
127109
friend class LR::ESolver_LR<std::complex<double>, double>;

source/source_lcao/FORCE_STRESS.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
5555
LCAO_Deepks<T>& ld,
5656
const std::string& dpks_out_type,
5757
#endif
58-
#ifdef __EXX
59-
Exx_LRI_Interface<T, double>& exd,
60-
Exx_LRI_Interface<T, std::complex<double>>& exc,
61-
#endif
58+
Exx_NAO &exx_nao,
6259
ModuleSymmetry::Symmetry* symm)
6360
{
6461
ModuleBase::TITLE("Force_Stress_LCAO", "getForceStress");
@@ -378,26 +375,26 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
378375
{
379376
if (GlobalC::exx_info.info_ri.real_number)
380377
{
381-
exd.cal_exx_force(ucell.nat);
382-
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exd.get_force();
378+
exx_nao.exd.cal_exx_force(ucell.nat);
379+
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_nao.exd.get_force();
383380
}
384381
else
385382
{
386-
exc.cal_exx_force(ucell.nat);
387-
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exc.get_force();
383+
exx_nao.exc.cal_exx_force(ucell.nat);
384+
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_nao.exc.get_force();
388385
}
389386
}
390387
if (isstress)
391388
{
392389
if (GlobalC::exx_info.info_ri.real_number)
393390
{
394-
exd.cal_exx_stress(ucell.omega, ucell.lat0);
395-
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exd.get_stress();
391+
exx_nao.exd.cal_exx_stress(ucell.omega, ucell.lat0);
392+
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_nao.exd.get_stress();
396393
}
397394
else
398395
{
399-
exc.cal_exx_stress(ucell.omega, ucell.lat0);
400-
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exc.get_stress();
396+
exx_nao.exc.cal_exx_stress(ucell.omega, ucell.lat0);
397+
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_nao.exc.get_stress();
401398
}
402399
}
403400
}

source/source_lcao/FORCE_STRESS.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "force_stress_arrays.h"
1717
#include "source_lcao/module_gint/gint_gamma.h"
1818
#include "source_lcao/module_gint/gint_k.h"
19+
#include "source_lcao/module_ri/setup_exx.h" // for exx, mohan add 20251008
20+
1921

2022
template <typename T>
2123
class Force_Stress_LCAO
@@ -53,10 +55,7 @@ class Force_Stress_LCAO
5355
LCAO_Deepks<T>& ld,
5456
const std::string& dpks_out_type,
5557
#endif
56-
#ifdef __EXX
57-
Exx_LRI_Interface<T, double>& exd,
58-
Exx_LRI_Interface<T, std::complex<double>>& exc,
59-
#endif
58+
Exx_NAO &exx_nao,
6059
ModuleSymmetry::Symmetry* symm);
6160

6261
private:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "source_lcao/module_ri/setup_exx.h"
2+
3+
void Exx_NAO::init0()
4+
{
5+
#ifdef __EXX
6+
// 1. currently this initialization must be put in constructor rather than `before_all_runners()`
7+
// because the latter is not reused by ESolver_LCAO_TDDFT,
8+
// which cause the failure of the subsequent procedure reused by ESolver_LCAO_TDDFT
9+
// 2. always construct but only initialize when if(cal_exx) is true
10+
// because some members like two_level_step are used outside if(cal_exx)
11+
if (GlobalC::exx_info.info_ri.real_number)
12+
{
13+
this->exd = std::make_shared<Exx_LRI_Interface<TK, double>>(GlobalC::exx_info.info_ri);
14+
}
15+
else
16+
{
17+
this->exc = std::make_shared<Exx_LRI_Interface<TK, std::complex<double>>>(GlobalC::exx_info.info_ri);
18+
}
19+
#endif
20+
}
21+
22+
void Exx_NAO::before_runner()
23+
{
24+
#ifdef __EXX
25+
if (inp.calculation == "scf" || inp.calculation == "relax" || inp.calculation == "cell-relax"
26+
|| inp.calculation == "md")
27+
{
28+
if (GlobalC::exx_info.info_global.cal_exx)
29+
{
30+
if (inp.init_wfc != "file")
31+
{ // if init_wfc==file, directly enter the EXX loop
32+
XC_Functional::set_xc_first_loop(ucell);
33+
}
34+
35+
// initialize 2-center radial tables for EXX-LRI
36+
if (GlobalC::exx_info.info_ri.real_number)
37+
{
38+
this->exd->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
39+
this->exd->exx_before_all_runners(this->kv, ucell, this->pv);
40+
}
41+
else
42+
{
43+
this->exc->init(MPI_COMM_WORLD, ucell, this->kv, orb_);
44+
this->exc->exx_before_all_runners(this->kv, ucell, this->pv);
45+
}
46+
}
47+
}
48+
#endif
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef SETUP_EXX_H
2+
#define SETUP_EXX_H
3+
4+
/*
5+
#include "source_cell/unitcell.h" // use unitcell
6+
#include "source_estate/elecstate_lcao.h"// use ElecStateLCAO
7+
#include "source_psi/psi.h" // use electronic wave functions
8+
#include "source_estate/module_charge/charge.h" // use charge
9+
*/
10+
11+
// for EXX
12+
#ifdef __EXX
13+
#include "source_lcao/module_ri/Exx_LRI_interface.h"
14+
#include "source_lcao/module_ri/Mix_DMk_2D.h"
15+
#endif
16+
17+
class Exx_NAO
18+
{
19+
public:
20+
21+
#ifdef __EXX
22+
std::shared_ptr<Exx_LRI_Interface<TK, double>> exd = nullptr;
23+
std::shared_ptr<Exx_LRI_Interface<TK, std::complex<double>>> exc = nullptr;
24+
#endif
25+
26+
void init0();
27+
28+
void before_runner();
29+
30+
31+
32+
};
33+
34+
35+
#endif

0 commit comments

Comments
 (0)