Skip to content

Commit 232cb5d

Browse files
committed
Refactor namespace Exx_Opt_Orb
1 parent 54659c6 commit 232cb5d

24 files changed

+631
-576
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <memory>
3333
#ifdef __EXX
3434
#include "module_io/restart_exx_csr.h"
35+
#include "module_ri/exx_opt_orb.h"
3536
#include "module_ri/RPA_LRI.h"
3637
#endif
3738

@@ -170,9 +171,15 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
170171
inp.lcao_rmax,
171172
ucell,
172173
two_center_bundle_,
173-
orb_);
174+
this->orb_);
174175
//------------------init Basis_lcao----------------------
175176

177+
if (PARAM.inp.calculation == "gen_opt_abfs")
178+
{
179+
Exx_Opt_Orb::generate_matrix(GlobalC::exx_info.info_opt_abfs, this->kv, this->orb_);
180+
return;
181+
}
182+
176183
// 5) initialize density matrix
177184
// DensityMatrix is allocated here, DMK is also initialized here
178185
// DMR is not initialized here, it will be constructed in each before_scf
@@ -188,7 +195,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
188195
// 6) initialize Hamilt in LCAO
189196
// * allocate H and S matrices according to computational resources
190197
// * set the 'trace' between local H/S and global H/S
191-
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local, pv, this->kv.get_nks(), orb_);
198+
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local, pv, this->kv.get_nks(), this->orb_);
192199

193200
#ifdef __EXX
194201
// 7) initialize exx
@@ -202,11 +209,11 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
202209
// initialize 2-center radial tables for EXX-LRI
203210
if (GlobalC::exx_info.info_ri.real_number)
204211
{
205-
this->exx_lri_double->init(MPI_COMM_WORLD, this->kv, orb_);
212+
this->exx_lri_double->init(MPI_COMM_WORLD, this->kv, this->orb_);
206213
}
207214
else
208215
{
209-
this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv, orb_);
216+
this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv, this->orb_);
210217
}
211218
}
212219
}
@@ -215,7 +222,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
215222
// 8) initialize DFT+U
216223
if (PARAM.inp.dft_plus_u)
217224
{
218-
GlobalC::dftu.init(ucell, &this->pv, this->kv.get_nks(), orb_);
225+
GlobalC::dftu.init(ucell, &this->pv, this->kv.get_nks(), this->orb_);
219226
}
220227

221228
// 9) initialize ppcell
@@ -244,7 +251,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
244251
// load the DeePKS model from deep neural network
245252
GlobalC::ld.load_model(PARAM.inp.deepks_model);
246253
// read pdm from file for NSCF or SCF-restart, do it only once in whole calculation
247-
GlobalC::ld.read_projected_DM((PARAM.inp.init_chg == "file"), PARAM.inp.deepks_equiv, *orb_.Alpha);
254+
GlobalC::ld.read_projected_DM((PARAM.inp.init_chg == "file"), PARAM.inp.deepks_equiv, *this->orb_.Alpha);
248255
}
249256
#endif
250257

@@ -313,7 +320,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(ModuleBase::matrix& force)
313320
this->GG, // mohan add 2024-04-01
314321
this->GK, // mohan add 2024-04-01
315322
two_center_bundle_,
316-
orb_,
323+
this->orb_,
317324
force,
318325
this->scs,
319326
this->sf,
@@ -466,7 +473,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
466473
this->GG,
467474
this->GK,
468475
this->kv,
469-
orb_.cutoffs(),
476+
this->orb_.cutoffs(),
470477
this->pelec->wg,
471478
GlobalC::GridD
472479
#ifdef __EXX
@@ -495,7 +502,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
495502
this->kv,
496503
this->pelec->wg,
497504
GlobalC::GridD,
498-
orb_.cutoffs(),
505+
this->orb_.cutoffs(),
499506
this->two_center_bundle_
500507
#ifdef __EXX
501508
,
@@ -1168,7 +1175,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
11681175
this->pelec->ekb,
11691176
this->pelec->klist->kvec_d,
11701177
GlobalC::ucell,
1171-
orb_,
1178+
this->orb_,
11721179
GlobalC::GridD,
11731180
&(this->pv),
11741181
*(this->psi),
@@ -1188,8 +1195,8 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
11881195
rpa_lri_double.cal_postSCF_exx(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
11891196
MPI_COMM_WORLD,
11901197
this->kv,
1191-
orb_);
1192-
rpa_lri_double.init(MPI_COMM_WORLD, this->kv, orb_.cutoffs());
1198+
this->orb_);
1199+
rpa_lri_double.init(MPI_COMM_WORLD, this->kv, this->orb_.cutoffs());
11931200
rpa_lri_double.out_for_RPA(this->pv, *(this->psi), this->pelec);
11941201
}
11951202
#endif
@@ -1278,7 +1285,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
12781285
this->kv.kvec_d,
12791286
&hR,
12801287
&GlobalC::ucell,
1281-
orb_.cutoffs(),
1288+
this->orb_.cutoffs(),
12821289
&GlobalC::GridD,
12831290
two_center_bundle_.kinetic_orb.get());
12841291

source/module_esolver/lcao_others.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ void ESolver_KS_LCAO<TK, TR>::others(const int istep)
5656
// return; // use 'return' will cause segmentation fault. by mohan
5757
// 2024-06-09
5858
}
59+
else if (cal_type == "gen_opt_abfs")
60+
{
61+
return;
62+
}
5963
else if (cal_type == "test_memory")
6064
{
6165
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "testing memory");

source/module_hamilt_general/module_xc/exx_info.h

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ struct Exx_Info
2323

2424
struct Exx_Info_Lip
2525
{
26-
const Conv_Coulomb_Pot_K::Ccp_Type& ccp_type;
27-
const double& hse_omega;
26+
const Conv_Coulomb_Pot_K::Ccp_Type &ccp_type;
27+
const double &hse_omega;
2828
double lambda = 0.3;
2929

3030
Exx_Info_Lip(const Exx_Info::Exx_Info_Global& info_global)
3131
:ccp_type(info_global.ccp_type),
32-
hse_omega(info_global.hse_omega) {}
32+
hse_omega(info_global.hse_omega) {}
3333
};
3434
Exx_Info_Lip info_lip;
3535

3636
struct Exx_Info_RI
3737
{
38-
const Conv_Coulomb_Pot_K::Ccp_Type& ccp_type;
39-
const double& hse_omega;
38+
const Conv_Coulomb_Pot_K::Ccp_Type &ccp_type;
39+
const double &hse_omega;
4040

4141
bool real_number = false;
4242

@@ -58,15 +58,28 @@ struct Exx_Info
5858
int abfs_Lmax = 0; // tmp
5959

6060
Exx_Info_RI(const Exx_Info::Exx_Info_Global& info_global)
61-
: ccp_type(info_global.ccp_type), hse_omega(info_global.hse_omega)
62-
{
63-
}
61+
:ccp_type(info_global.ccp_type),
62+
hse_omega(info_global.hse_omega) {}
6463
};
6564
Exx_Info_RI info_ri;
6665

67-
Exx_Info() : info_lip(this->info_global), info_ri(this->info_global)
66+
struct Exx_Info_Opt_ABFs
6867
{
69-
}
68+
//const Conv_Coulomb_Pot_K::Ccp_Type &ccp_type;
69+
//const double &hse_omega;
70+
71+
int abfs_Lmax = 0; // tmp
72+
double ecut_exx = 60;
73+
double tolerence = 1E-2;
74+
double kmesh_times = 4;
75+
76+
//Exx_Info_Opt_ABFs(const Exx_Info::Exx_Info_Global& info_global)
77+
// :ccp_type(info_global.ccp_type),
78+
// hse_omega(info_global.hse_omega) {}
79+
};
80+
Exx_Info_Opt_ABFs info_opt_abfs;
81+
82+
Exx_Info() : info_lip(this->info_global), info_ri(this->info_global) {}
7083
};
7184

7285
#endif

source/module_hamilt_general/module_xc/xc_functional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void XC_Functional::set_xc_type(const std::string xc_func_in)
192192
func_type = 4;
193193
use_libxc = false;
194194
}
195-
else if( xc_func == "OPT_ORB" || xc_func == "NONE" || xc_func == "NOX+NOC")
195+
else if( xc_func == "NONE" || xc_func == "NOX+NOC")
196196
{
197197
// not doing anything
198198
}

source/module_io/input_conv.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ void Input_Conv::Convert()
326326
ModuleBase::GlobalFunc::MAKE_DIR(GlobalC::restart.folder);
327327
if (dft_functional_lower == "hf" || dft_functional_lower == "pbe0"
328328
|| dft_functional_lower == "hse"
329-
|| dft_functional_lower == "opt_orb"
330329
|| dft_functional_lower == "scan0") {
331330
GlobalC::restart.info_save.save_charge = true;
332331
GlobalC::restart.info_save.save_H = true;
@@ -344,7 +343,6 @@ void Input_Conv::Convert()
344343
GlobalC::restart.folder = PARAM.globalv.global_readin_dir + "restart/";
345344
if (dft_functional_lower == "hf" || dft_functional_lower == "pbe0"
346345
|| dft_functional_lower == "hse"
347-
|| dft_functional_lower == "opt_orb"
348346
|| dft_functional_lower == "scan0") {
349347
GlobalC::restart.info_load.load_charge = true;
350348
GlobalC::restart.info_load.load_H = true;
@@ -373,14 +371,11 @@ void Input_Conv::Convert()
373371
GlobalC::exx_info.info_global.cal_exx = true;
374372
GlobalC::exx_info.info_global.ccp_type
375373
= Conv_Coulomb_Pot_K::Ccp_Type::Hse;
376-
} else if (dft_functional_lower == "opt_orb") {
377-
GlobalC::exx_info.info_global.cal_exx = false;
378-
Exx_Abfs::Jle::generate_matrix = true;
379374
} else {
380375
GlobalC::exx_info.info_global.cal_exx = false;
381376
}
382377

383-
if (GlobalC::exx_info.info_global.cal_exx || Exx_Abfs::Jle::generate_matrix || PARAM.inp.rpa)
378+
if (GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa)
384379
{
385380
// EXX case, convert all EXX related variables
386381
// GlobalC::exx_info.info_global.cal_exx = true;
@@ -407,9 +402,9 @@ void Input_Conv::Convert()
407402
GlobalC::exx_info.info_ri.cauchy_stress_threshold = PARAM.inp.exx_cauchy_stress_threshold;
408403
GlobalC::exx_info.info_ri.ccp_rmesh_times = std::stod(PARAM.inp.exx_ccp_rmesh_times);
409404

410-
Exx_Abfs::Jle::Lmax = PARAM.inp.exx_opt_orb_lmax;
411-
Exx_Abfs::Jle::Ecut_exx = PARAM.inp.exx_opt_orb_ecut;
412-
Exx_Abfs::Jle::tolerence = PARAM.inp.exx_opt_orb_tolerence;
405+
GlobalC::exx_info.info_opt_abfs.abfs_Lmax = PARAM.inp.exx_opt_orb_lmax;
406+
GlobalC::exx_info.info_opt_abfs.ecut_exx = PARAM.inp.exx_opt_orb_ecut;
407+
GlobalC::exx_info.info_opt_abfs.tolerence = PARAM.inp.exx_opt_orb_tolerence;
413408

414409
// EXX does not support symmetry for nspin==4
415410
if (PARAM.inp.calculation != "nscf" && PARAM.inp.symmetry == "1" && PARAM.inp.nspin == 4)

source/module_io/read_input_item_system.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void ReadInput::item_system()
6161
}
6262
{
6363
Input_Item item("calculation");
64-
item.annotation = "test; scf; relax; nscf; get_wf; get_pchg";
64+
item.annotation = "scf; relax; md; cell-relax; nscf; get_S; get_wf; get_pchg; gen_bessel; gen_opt_abfs; test_memory; test_neighbour";
6565
item.read_value = [](const Input_Item& item, Parameter& para) {
6666
para.input.calculation = strvalue;
6767
std::string& calculation = para.input.calculation;
@@ -78,7 +78,8 @@ void ReadInput::item_system()
7878
"get_S",
7979
"get_wf",
8080
"get_pchg",
81-
"gen_bessel"};
81+
"gen_bessel",
82+
"gen_opt_abfs"};
8283
if (!find_str(callist, calculation))
8384
{
8485
const std::string warningstr = nofound_str(callist, "calculation");

source/module_ri/Exx_LRI.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
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

@@ -59,19 +59,19 @@ class Exx_LRI
5959
void init(const MPI_Comm &mpi_comm_in, const K_Vectors &kv_in, const LCAO_Orbitals& orb);
6060
void cal_exx_force();
6161
void cal_exx_stress();
62-
std::vector<std::vector<int>> get_abfs_nchis() const;
62+
// std::vector<std::vector<int>> get_abfs_nchis() const;
6363

6464
std::vector< std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> Hexxs;
6565
double Eexx;
6666
ModuleBase::matrix force_exx;
6767
ModuleBase::matrix stress_exx;
68-
68+
6969

7070
private:
7171
const Exx_Info::Exx_Info_RI &info;
7272
MPI_Comm mpi_comm;
7373
const K_Vectors *p_kv = nullptr;
74-
std::vector<double> orb_cutoff_;
74+
std::vector<double> orb_cutoff_;
7575

7676
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> lcaos;
7777
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs;
@@ -99,4 +99,4 @@ class Exx_LRI
9999

100100
#include "Exx_LRI.hpp"
101101

102-
#endif
102+
#endif

0 commit comments

Comments
 (0)