Skip to content

Commit 97053ba

Browse files
committed
Merge branch 'new-exx' into develop
2 parents 0654086 + 4070dd0 commit 97053ba

File tree

17 files changed

+179
-138
lines changed

17 files changed

+179
-138
lines changed

examples/relax/lcao_output/INPUT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ out_band 0
4040
out_stru 0
4141
out_app_flag 0
4242

43-
out_interval 1

source/Makefile.Objects

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ OBJS_LCAO=evolve_elec.o\
669669
LCAO_allocate.o\
670670
LCAO_set_mat2d.o\
671671
LCAO_init_basis.o\
672+
setup_exx.o\
672673
center2_orb.o\
673674
center2_orb-orb11.o\
674675
center2_orb-orb21.o\
@@ -677,13 +678,13 @@ OBJS_LCAO=evolve_elec.o\
677678
wavefunc_in_pw.o\
678679

679680
OBJS_MODULE_RI=conv_coulomb_pot_k.o\
680-
exx_abfs-abfs_index.o \
681-
exx_abfs-jle.o \
682-
exx_abfs-io.o \
683-
exx_abfs-construct_orbs.o \
684-
ABFs_Construct-PCA.o \
685-
exx_opt_orb.o \
686-
exx_opt_orb-print.o \
681+
exx_abfs-abfs_index.o\
682+
exx_abfs-jle.o\
683+
exx_abfs-io.o\
684+
exx_abfs-construct_orbs.o\
685+
ABFs_Construct-PCA.o\
686+
exx_opt_orb-print.o\
687+
exx_opt_orb.o\
687688
Matrix_Orbs11.o\
688689
Matrix_Orbs21.o\
689690
Matrix_Orbs22.o\

source/source_esolver/esolver_double_xc.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
162162
#ifdef __EXX
163163
,
164164
istep,
165-
GlobalC::exx_info.info_ri.real_number ? &this->exd->two_level_step : &this->exc->two_level_step,
166-
GlobalC::exx_info.info_ri.real_number ? &this->exd->get_Hexxs() : nullptr,
167-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exc->get_Hexxs()
165+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
166+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
167+
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
168168
#endif
169169
);
170170
}
@@ -415,11 +415,8 @@ void ESolver_DoubleXC<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& fo
415415
this->ld,
416416
"base",
417417
#endif
418-
#ifdef __EXX
419-
*this->exd,
420-
*this->exc,
421-
#endif
422-
&ucell.symm);
418+
this->exx_nao,
419+
&ucell.symm);
423420
// restore to original xc
424421
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
425422

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 12 additions & 54 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+
this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, PARAM.inp);
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
@@ -349,8 +307,8 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
349307
this->orb_, this->pw_rho, this->pw_rhod,
350308
this->sf, this->locpp.vloc,
351309
#ifdef __EXX
352-
this->exd,
353-
this->exc,
310+
this->exx_nao.exd,
311+
this->exx_nao.exc,
354312
#endif
355313
this->solvent);
356314

@@ -389,7 +347,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
389347
{
390348
// the following steps are only needed in the first outer exx loop
391349
exx_two_level_step
392-
= GlobalC::exx_info.info_ri.real_number ? this->exd->two_level_step : this->exc->two_level_step;
350+
= GlobalC::exx_info.info_ri.real_number ? this->exx_nao.exd->two_level_step : this->exx_nao.exc->two_level_step;
393351
}
394352
#endif
395353
// elecstate::setup_dm<TK>(ucell, estate, this->psi, this->chr, iter, exx_two_level_step);
@@ -437,11 +395,11 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
437395
{
438396
if (GlobalC::exx_info.info_ri.real_number)
439397
{
440-
this->exd->exx_eachiterinit(istep, ucell, *dm, this->kv, iter);
398+
this->exx_nao.exd->exx_eachiterinit(istep, ucell, *dm, this->kv, iter);
441399
}
442400
else
443401
{
444-
this->exc->exx_eachiterinit(istep, ucell, *dm, this->kv, iter);
402+
this->exx_nao.exc->exx_eachiterinit(istep, ucell, *dm, this->kv, iter);
445403
}
446404
}
447405
#endif
@@ -528,11 +486,11 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
528486
{
529487
if (GlobalC::exx_info.info_ri.real_number)
530488
{
531-
this->exd->exx_hamilt2rho(*this->pelec, this->pv, iter);
489+
this->exx_nao.exd->exx_hamilt2rho(*this->pelec, this->pv, iter);
532490
}
533491
else
534492
{
535-
this->exc->exx_hamilt2rho(*this->pelec, this->pv, iter);
493+
this->exx_nao.exc->exx_hamilt2rho(*this->pelec, this->pv, iter);
536494
}
537495
}
538496
#endif
@@ -651,8 +609,8 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
651609
this->ld,
652610
#endif
653611
#ifdef __EXX
654-
*this->exd,
655-
*this->exc,
612+
*this->exx_nao.exd,
613+
*this->exx_nao.exc,
656614
#endif
657615
iter, istep, conv_esolver, this->scf_ene_thr);
658616

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/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<TK> exx_nao;
125107

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

source/source_esolver/lcao_after_scf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
6565
this->ld,
6666
#endif
6767
#ifdef __EXX
68-
*this->exd,
69-
*this->exc,
68+
*this->exx_nao.exd,
69+
*this->exx_nao.exc,
7070
#endif
7171
istep);
7272
}

source/source_esolver/lcao_before_scf.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,11 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
2828
ESolver_KS<TK>::before_scf(ucell, istep);
2929

3030
auto* estate = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
31-
auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
32-
3331
if(!estate)
3432
{
3533
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf","pelec does not exist");
3634
}
3735

38-
if(!hamilt_lcao)
39-
{
40-
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf","p_hamilt does not exist");
41-
}
4236

4337
//! 2) find search radius
4438
double search_radius = atom_arrange::set_sr_NL(GlobalV::ofs_running,
@@ -143,9 +137,9 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
143137
#ifdef __EXX
144138
,
145139
istep,
146-
GlobalC::exx_info.info_ri.real_number ? &this->exd->two_level_step : &this->exc->two_level_step,
147-
GlobalC::exx_info.info_ri.real_number ? &this->exd->get_Hexxs() : nullptr,
148-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exc->get_Hexxs()
140+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
141+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
142+
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
149143
#endif
150144
);
151145
}
@@ -185,11 +179,11 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
185179
{
186180
if (GlobalC::exx_info.info_ri.real_number)
187181
{
188-
this->exd->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
182+
this->exx_nao.exd->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
189183
}
190184
else
191185
{
192-
this->exc->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
186+
this->exx_nao.exc->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
193187
}
194188
}
195189
#endif
@@ -199,6 +193,11 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
199193

200194
// 13) initalize DMR
201195
// DMR should be same size with Hamiltonian(R)
196+
auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
197+
if(!hamilt_lcao)
198+
{
199+
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf","p_hamilt does not exist");
200+
}
202201
estate->get_DM()->init_DMR(*hamilt_lcao->getHR());
203202

204203
#ifdef __MLALGO

source/source_esolver/lcao_others.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
238238
#ifdef __EXX
239239
,
240240
istep,
241-
GlobalC::exx_info.info_ri.real_number ? &this->exd->two_level_step : &this->exc->two_level_step,
242-
GlobalC::exx_info.info_ri.real_number ? &this->exd->get_Hexxs() : nullptr,
243-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exc->get_Hexxs()
241+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
242+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
243+
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
244244
#endif
245245
);
246246
}

source/source_lcao/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if(ENABLE_LCAO)
4141
LCAO_allocate.cpp
4242
LCAO_set_mat2d.cpp
4343
LCAO_init_basis.cpp
44+
setup_exx.cpp
4445
record_adj.cpp
4546
center2_orb.cpp
4647
center2_orb-orb11.cpp

source/source_lcao/FORCE.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_FORCE_H
2-
#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_FORCE_H
1+
#ifndef LCAO_FORCE_H
2+
#define LCAO_FORCE_H
33

44
#include "source_base/global_function.h"
55
#include "source_base/global_variable.h"

0 commit comments

Comments
 (0)