Skip to content

Commit 38cef80

Browse files
authored
Refactor: split pseudopot_cell_vl and pseudopot_cell_vnl (#5743)
* Refactor: esolver_lj and esolver_dp * Refactor: split pseudopot_cell_vl and pseudopot_cell_vnl * Refactor: add head files
1 parent 68248c6 commit 38cef80

34 files changed

+218
-228
lines changed

source/module_cell/test/klist_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <iostream>
44
#include <streambuf>
55
#define private public
6-
#include "module_parameter/parameter.h"
76
#include "module_basis/module_ao/ORB_gaunt_table.h"
87
#include "module_cell/atom_pseudo.h"
98
#include "module_cell/atom_spec.h"
@@ -13,9 +12,11 @@
1312
#include "module_cell/setup_nonlocal.h"
1413
#include "module_cell/unitcell.h"
1514
#include "module_elecstate/magnetism.h"
15+
#include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h"
1616
#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h"
1717
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
1818
#include "module_io/berryphase.h"
19+
#include "module_parameter/parameter.h"
1920
#undef private
2021
#include "module_base/mathzone.h"
2122
#include "module_base/parallel_global.h"

source/module_cell/test/klist_test_para.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "module_cell/setup_nonlocal.h"
2020
#include "module_cell/unitcell.h"
2121
#include "module_elecstate/magnetism.h"
22+
#include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h"
2223
#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h"
2324
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
2425
#include "module_io/berryphase.h"

source/module_elecstate/test/elecstate_pw_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#undef private
88
#define protected public
99
#include "module_elecstate/elecstate_pw.h"
10+
#include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h"
1011
#undef protected
1112
// mock functions for testing
1213
namespace elecstate

source/module_esolver/cell_dependency.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

source/module_esolver/esolver_dp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ namespace ModuleESolver
3333

3434
void ESolver_DP::before_all_runners(UnitCell& ucell, const Input_para& inp)
3535
{
36-
ucell_ = &ucell;
3736
dp_potential = 0;
3837
dp_force.create(ucell.nat, 3);
3938
dp_virial.create(3, 3);
@@ -43,9 +42,7 @@ void ESolver_DP::before_all_runners(UnitCell& ucell, const Input_para& inp)
4342
"# Generated by ABACUS ModuleIO::CifParser",
4443
"data_?");
4544

46-
cell.resize(9);
4745
atype.resize(ucell.nat);
48-
coord.resize(3 * ucell.nat);
4946

5047
rescaling = inp.mdp.dp_rescaling;
5148
fparam = inp.mdp.dp_fparam;
@@ -62,6 +59,7 @@ void ESolver_DP::runner(UnitCell& ucell, const int istep)
6259
ModuleBase::TITLE("ESolver_DP", "runner");
6360
ModuleBase::timer::tick("ESolver_DP", "runner");
6461

62+
std::vector<double> cell(9, 0.0);
6563
cell[0] = ucell.latvec.e11 * ucell.lat0_angstrom;
6664
cell[1] = ucell.latvec.e12 * ucell.lat0_angstrom;
6765
cell[2] = ucell.latvec.e13 * ucell.lat0_angstrom;
@@ -72,6 +70,7 @@ void ESolver_DP::runner(UnitCell& ucell, const int istep)
7270
cell[7] = ucell.latvec.e32 * ucell.lat0_angstrom;
7371
cell[8] = ucell.latvec.e33 * ucell.lat0_angstrom;
7472

73+
std::vector<double> coord(3 * ucell.nat, 0.0);
7574
int iat = 0;
7675
for (int it = 0; it < ucell.ntype; ++it)
7776
{
@@ -130,7 +129,7 @@ double ESolver_DP::cal_energy()
130129
void ESolver_DP::cal_force(UnitCell& ucell, ModuleBase::matrix& force)
131130
{
132131
force = dp_force;
133-
ModuleIO::print_force(GlobalV::ofs_running, *ucell_, "TOTAL-FORCE (eV/Angstrom)", force, false);
132+
ModuleIO::print_force(GlobalV::ofs_running, ucell, "TOTAL-FORCE (eV/Angstrom)", force, false);
134133
}
135134

136135
void ESolver_DP::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)

source/module_esolver/esolver_dp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,13 @@ class ESolver_DP : public ESolver
108108
*/
109109

110110
std::string dp_file; ///< directory of DP model file
111-
std::vector<double> cell = {}; ///< lattice vectors
112111
std::vector<int> atype = {}; ///< atom type corresponding to DP model
113-
std::vector<double> coord = {}; ///< atomic positions
114112
std::vector<double> fparam = {}; ///< frame parameter for dp potential: dim_fparam
115113
std::vector<double> aparam = {}; ///< atomic parameter for dp potential: natoms x dim_aparam
116114
double rescaling = 1.0; ///< rescaling factor for DP model
117115
double dp_potential = 0.0; ///< computed potential energy
118116
ModuleBase::matrix dp_force; ///< computed atomic forces
119117
ModuleBase::matrix dp_virial; ///< computed lattice virials
120-
UnitCell* ucell_; ///< pointer to the unit cell object
121118
};
122119

123120
} // namespace ModuleESolver

source/module_esolver/esolver_fp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
286286
this->pw_rhod->collect_uniqgg();
287287
}
288288

289-
this->p_locpp->init_vloc(ucell,this->pw_rhod);
289+
this->locpp.init_vloc(ucell, this->pw_rhod);
290290
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
291291

292292
this->pelec->omega = ucell.omega;

source/module_esolver/esolver_fp.h

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,75 +7,80 @@
77
#include "module_elecstate/elecstate.h"
88
#include "module_elecstate/module_charge/charge_extra.h"
99
#include "module_hamilt_general/module_surchem/surchem.h"
10+
#include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h"
1011
#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h"
1112

1213
#include <fstream>
1314

1415
//! The First-Principles (FP) Energy Solver Class
1516
/**
16-
* This class represents components that needed in
17+
* This class represents components that needed in
1718
* first-principles energy solver, such as the plane
1819
* wave basis, the structure factors, and the k points.
1920
*
20-
*/
21+
*/
2122

2223
namespace ModuleESolver
2324
{
24-
class ESolver_FP : public ESolver
25-
{
26-
public:
27-
//! Constructor
28-
ESolver_FP();
25+
class ESolver_FP : public ESolver
26+
{
27+
public:
28+
//! Constructor
29+
ESolver_FP();
30+
31+
//! Deconstructor
32+
virtual ~ESolver_FP();
2933

30-
//! Deconstructor
31-
virtual ~ESolver_FP();
34+
//! Initialize of the first-principels energy solver
35+
virtual void before_all_runners(UnitCell& ucell, const Input_para& inp) override;
3236

33-
//! Initialize of the first-principels energy solver
34-
virtual void before_all_runners(UnitCell& ucell, const Input_para& inp) override;
37+
protected:
38+
//! Something to do before SCF iterations.
39+
virtual void before_scf(UnitCell& ucell, const int istep);
3540

36-
protected:
37-
//! Something to do before SCF iterations.
38-
virtual void before_scf(UnitCell& ucell, const int istep);
41+
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
42+
virtual void after_scf(UnitCell& ucell, const int istep);
3943

40-
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
41-
virtual void after_scf(UnitCell& ucell, const int istep);
44+
//! ------------------------------------------------------------------------------
45+
//! These pointers will be deleted in the free_pointers() function every ion step.
46+
//! ------------------------------------------------------------------------------
47+
elecstate::ElecState* pelec = nullptr; ///< Electronic states
4248

43-
//! Electronic states
44-
elecstate::ElecState* pelec = nullptr;
49+
//! ------------------------------------------------------------------------------
4550

46-
//! Electorn charge density
47-
Charge chr;
51+
//! Electorn charge density
52+
Charge chr;
4853

49-
//! Structure factors that used with plane-wave basis set
50-
Structure_Factor sf;
54+
//! Structure factors that used with plane-wave basis set
55+
Structure_Factor sf;
5156

52-
//! K points in Brillouin zone
53-
K_Vectors kv;
57+
//! K points in Brillouin zone
58+
K_Vectors kv;
5459

55-
//! Plane-wave basis set for charge density
56-
ModulePW::PW_Basis* pw_rho;
60+
//! Plane-wave basis set for charge density
61+
ModulePW::PW_Basis* pw_rho;
5762

58-
//! parallel for rho grid
59-
Parallel_Grid Pgrid;
63+
//! parallel for rho grid
64+
Parallel_Grid Pgrid;
6065

61-
//! pointer to pseudopotential
62-
pseudopot_cell_vl* p_locpp = nullptr;
66+
//! pointer to local pseudopotential
67+
pseudopot_cell_vl locpp;
6368

64-
/**
65-
* @brief same as pw_rho for ncpp. Here 'd' stands for 'dense'
66-
* dense grid for for uspp, used for ultrasoft augmented charge density.
67-
* charge density and potential are defined on dense grids,
68-
* but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi>
69-
*/
70-
ModulePW::PW_Basis* pw_rhod;
71-
ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class
69+
/**
70+
* @brief same as pw_rho for ncpp. Here 'd' stands for 'dense'
71+
* dense grid for for uspp, used for ultrasoft augmented charge density.
72+
* charge density and potential are defined on dense grids,
73+
* but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi>
74+
*/
75+
ModulePW::PW_Basis* pw_rhod;
76+
ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class
7277

73-
//! Charge extrapolation
74-
Charge_Extra CE;
78+
//! Charge extrapolation
79+
Charge_Extra CE;
7580

76-
// solvent model
77-
surchem solvent;
78-
};
79-
}
81+
// solvent model
82+
surchem solvent;
83+
};
84+
} // namespace ModuleESolver
8085

8186
#endif

source/module_esolver/esolver_ks.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ ESolver_KS<T, Device>::ESolver_KS()
6969
p_chgmix = new Charge_Mixing();
7070
p_chgmix->set_rhopw(this->pw_rho, this->pw_rhod);
7171
this->ppcell.cell_factor = PARAM.inp.cell_factor;
72-
this->p_locpp = &this->ppcell;
7372
}
7473

7574
//------------------------------------------------------------------------------

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
199199
}
200200

201201
// 8) initialize ppcell
202-
this->ppcell.init_vloc(ucell, this->pw_rho);
202+
this->locpp.init_vloc(ucell, this->pw_rho);
203203
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
204204

205205
// 9) inititlize the charge density
@@ -212,7 +212,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
212212
this->pelec->pot = new elecstate::Potential(this->pw_rhod,
213213
this->pw_rho,
214214
&ucell,
215-
&(this->ppcell.vloc),
215+
&(this->locpp.vloc),
216216
&(this->sf),
217217
&(this->solvent),
218218
&(this->pelec->f_en.etxc),
@@ -317,7 +317,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
317317
orb_,
318318
force,
319319
this->scs,
320-
this->ppcell,
320+
this->locpp,
321321
this->sf,
322322
this->kv,
323323
this->pw_rho,
@@ -465,7 +465,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
465465
this->solvent,
466466
*this->pw_rho,
467467
*this->pw_rhod,
468-
this->ppcell.vloc,
468+
this->locpp.vloc,
469469
*this->pelec->charge,
470470
this->GG,
471471
this->GK,
@@ -493,7 +493,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
493493
this->solvent,
494494
*this->pw_rho,
495495
*this->pw_rhod,
496-
this->ppcell.vloc,
496+
this->locpp.vloc,
497497
*this->pelec->charge,
498498
this->GG,
499499
this->GK,

0 commit comments

Comments
 (0)