Skip to content

Commit 8f96574

Browse files
Merge branch 'develop' into rdmft_PR
2 parents 14973df + e0202e0 commit 8f96574

27 files changed

+564
-614
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,10 @@ OBJS_ESOLVER=esolver.o\
247247
esolver_of.o\
248248
esolver_of_tool.o\
249249
esolver_of_interface.o\
250-
pw_init_globalc.o\
251250
pw_others.o\
252251

253252
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
254253
esolver_ks_lcao_tddft.o\
255-
dpks_cal_e_delta_band.o\
256-
set_matrix_grid.o\
257254
lcao_before_scf.o\
258255
esolver_gets.o\
259256
lcao_others.o\

source/module_esolver/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ list(APPEND objects
1010
esolver_of.cpp
1111
esolver_of_interface.cpp
1212
esolver_of_tool.cpp
13-
pw_init_globalc.cpp
1413
pw_others.cpp
1514
)
1615
if(ENABLE_LCAO)
1716
list(APPEND objects
1817
esolver_ks_lcao.cpp
1918
esolver_ks_lcao_tddft.cpp
20-
dpks_cal_e_delta_band.cpp
21-
set_matrix_grid.cpp
2219
lcao_before_scf.cpp
2320
esolver_gets.cpp
2421
lcao_others.cpp

source/module_esolver/dpks_cal_e_delta_band.cpp

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

source/module_esolver/esolver_ks.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ ESolver_KS<T, Device>::ESolver_KS()
6767
///----------------------------------------------------------
6868
p_chgmix = new Charge_Mixing();
6969
p_chgmix->set_rhopw(this->pw_rho, this->pw_rhod);
70-
71-
///----------------------------------------------------------
72-
/// wavefunc
73-
///----------------------------------------------------------
74-
this->wf.init_wfc = PARAM.inp.init_wfc;
75-
this->wf.mem_saver = PARAM.inp.mem_saver;
76-
this->wf.out_wfc_pw = PARAM.inp.out_wfc_pw;
77-
this->wf.out_wfc_r = PARAM.inp.out_wfc_r;
7870
}
7971

8072
//------------------------------------------------------------------------------

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
560560
// mohan move it outside 2011-01-13
561561
// first need to calculate the weight according to
562562
// electrons number.
563-
if (istep == 0 && this->wf.init_wfc == "file")
563+
if (istep == 0 && PARAM.inp.init_wfc == "file")
564564
{
565565
if (iter == 1)
566566
{
@@ -892,7 +892,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
892892
const std::vector<std::vector<TK>>& dm
893893
= dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->get_DMK_vector();
894894

895-
this->dpks_cal_e_delta_band(dm);
895+
GlobalC::ld.dpks_cal_e_delta_band(dm, this->kv.get_nks());
896896
}
897897
#endif
898898

source/module_esolver/esolver_ks_lcao.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
9797
std::shared_ptr<Exx_LRI<std::complex<double>>> exx_lri_complex = nullptr;
9898
#endif
9999

100-
private:
101-
#ifdef __DEEPKS
102-
void dpks_cal_e_delta_band(const std::vector<std::vector<TK>>& dm) const;
103-
104-
void dpks_cal_projected_DM(
105-
const elecstate::DensityMatrix<TK, double>* dm) const;
106-
#endif
107100
friend class LR::ESolver_LR<double, double>;
108101
friend class LR::ESolver_LR<std::complex<double>, double>;
109102
};

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell&
7676

7777
void ESolver_KS_LCAO_TDDFT::hamilt2density_single(const int istep, const int iter, const double ethr)
7878
{
79-
if (wf.init_wfc == "file")
79+
if (PARAM.inp.init_wfc == "file")
8080
{
8181
if (istep >= 1)
8282
{
@@ -256,7 +256,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter)
256256
const int nlocal = PARAM.globalv.nlocal;
257257

258258
// store wfc and Hk laststep
259-
if (istep >= (wf.init_wfc == "file" ? 0 : 1) && this->conv_esolver)
259+
if (istep >= (PARAM.inp.init_wfc == "file" ? 0 : 1) && this->conv_esolver)
260260
{
261261
if (this->psi_laststep == nullptr)
262262
{
@@ -311,7 +311,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter)
311311
}
312312

313313
// calculate energy density matrix for tddft
314-
if (istep >= (wf.init_wfc == "file" ? 0 : 2) && module_tddft::Evolve_elec::td_edm == 0)
314+
if (istep >= (PARAM.inp.init_wfc == "file" ? 0 : 2) && module_tddft::Evolve_elec::td_edm == 0)
315315
{
316316
elecstate::cal_edm_tddft(this->pv, this->pelec, this->kv, this->p_hamilt);
317317
}

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "module_base/memory.h"
1919
#include "module_base/module_device/device.h"
2020
#include "module_elecstate/elecstate_pw.h"
21+
#include "module_elecstate/elecstate_pw_sdft.h"
2122
#include "module_hamilt_general/module_vdw/vdw.h"
2223
#include "module_hamilt_pw/hamilt_pwdft/elecond.h"
2324
#include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h"
@@ -136,14 +137,29 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
136137
// 3) initialize ElecState,
137138
if (this->pelec == nullptr)
138139
{
139-
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
140-
&(this->chr),
141-
&(this->kv),
142-
&ucell,
143-
&GlobalC::ppcell,
144-
this->pw_rhod,
145-
this->pw_rho,
146-
this->pw_big);
140+
if (inp.esolver_type == "sdft")
141+
{
142+
//! SDFT only supports double precision currently
143+
this->pelec = new elecstate::ElecStatePW_SDFT<std::complex<double>, Device>(this->pw_wfc,
144+
&(this->chr),
145+
&(this->kv),
146+
&ucell,
147+
&(GlobalC::ppcell),
148+
this->pw_rhod,
149+
this->pw_rho,
150+
this->pw_big);
151+
}
152+
else
153+
{
154+
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
155+
&(this->chr),
156+
&(this->kv),
157+
&ucell,
158+
&GlobalC::ppcell,
159+
this->pw_rhod,
160+
this->pw_rho,
161+
this->pw_big);
162+
}
147163
}
148164

149165
//! 4) inititlize the charge density.
@@ -165,12 +181,12 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
165181
}
166182

167183
//! 7) prepare some parameters for electronic wave functions initilization
168-
this->p_wf_init = new psi::WFInit<T, Device>(PARAM.inp.init_wfc,
169-
PARAM.inp.ks_solver,
170-
PARAM.inp.basis_type,
171-
PARAM.inp.psi_initializer,
172-
&this->wf,
173-
this->pw_wfc);
184+
this->p_wf_init = new psi::PSIInit<T, Device>(PARAM.inp.init_wfc,
185+
PARAM.inp.ks_solver,
186+
PARAM.inp.basis_type,
187+
PARAM.inp.psi_initializer,
188+
&this->wf,
189+
this->pw_wfc);
174190
this->p_wf_init->prepare_init(&(this->sf),
175191
&ucell,
176192
1,
@@ -180,8 +196,39 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
180196
#endif
181197
&GlobalC::ppcell);
182198

183-
//! 8) setup global classes
184-
this->Init_GlobalC(inp, ucell, GlobalC::ppcell);
199+
if (this->psi != nullptr)
200+
{
201+
delete this->psi;
202+
}
203+
204+
//! init pseudopotential
205+
GlobalC::ppcell.init(ucell.ntype, &this->sf, this->pw_wfc);
206+
207+
//! initalize local pseudopotential
208+
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rhod);
209+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
210+
211+
//! Initalize non-local pseudopotential
212+
GlobalC::ppcell.init_vnl(ucell, this->pw_rhod);
213+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL");
214+
215+
//! Allocate psi
216+
this->p_wf_init->allocate_psi(this->psi,
217+
this->kv.get_nkstot(),
218+
this->kv.get_nks(),
219+
this->kv.ngk.data(),
220+
this->pw_wfc->npwk_max,
221+
&(this->sf));
222+
223+
this->kspw_psi = PARAM.inp.device == "gpu" || PARAM.inp.precision == "single"
224+
? new psi::Psi<T, Device>(this->psi[0])
225+
: reinterpret_cast<psi::Psi<T, Device>*>(this->psi);
226+
227+
if (PARAM.inp.precision == "single")
228+
{
229+
ModuleBase::Memory::record("Psi_single", sizeof(T) * this->psi[0].size());
230+
}
231+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT BASIS");
185232

186233
//! 9) setup occupations
187234
if (PARAM.inp.ocp)
@@ -500,7 +547,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(const int istep, int& iter)
500547
}
501548

502549
// 4) Print out electronic wavefunctions
503-
if (this->wf.out_wfc_pw == 1 || this->wf.out_wfc_pw == 2)
550+
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
504551
{
505552
std::stringstream ssw;
506553
ssw << PARAM.globalv.global_out_dir << "WAVEFUNC";
@@ -526,7 +573,7 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
526573
ESolver_KS<T, Device>::after_scf(istep);
527574

528575
// 3) output wavefunctions
529-
if (this->wf.out_wfc_pw == 1 || this->wf.out_wfc_pw == 2)
576+
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
530577
{
531578
std::stringstream ssw;
532579
ssw << PARAM.globalv.global_out_dir << "WAVEFUNC";
@@ -774,7 +821,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners()
774821
}
775822

776823
//! 6) Print out electronic wave functions in real space
777-
if (this->wf.out_wfc_r == 1) // Peize Lin add 2021.11.21
824+
if (PARAM.inp.out_wfc_r == 1) // Peize Lin add 2021.11.21
778825
{
779826
ModuleIO::write_psi_r_1(this->psi[0], this->pw_wfc, "wfc_realspace", true, this->kv);
780827
}

source/module_esolver/esolver_ks_pw.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
4646

4747
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
4848

49-
// temporary, this will be removed in the future;
50-
// Init Global class
51-
void Init_GlobalC(const Input_para& inp, UnitCell& ucell, pseudopot_cell_vnl& ppcell);
52-
5349
virtual void allocate_hamilt();
5450
virtual void deallocate_hamilt();
5551

5652
//! hide the psi in ESolver_KS for tmp use
5753
psi::Psi<std::complex<double>, base_device::DEVICE_CPU>* psi = nullptr;
5854

5955
// psi_initializer controller
60-
psi::WFInit<T, Device>* p_wf_init = nullptr;
56+
psi::PSIInit<T, Device>* p_wf_init = nullptr;
6157

6258
Device* ctx = {};
6359

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,51 +50,9 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
5050
this->method_sto = inp.method_sto;
5151

5252
// 2) run "before_all_runners" in ESolver_KS
53-
ESolver_KS<T, Device>::before_all_runners(inp, ucell);
54-
55-
// 3) initialize the pointer for electronic states of SDFT
56-
this->pelec = new elecstate::ElecStatePW_SDFT<T, Device>(this->pw_wfc,
57-
&(this->chr),
58-
&(this->kv),
59-
&ucell,
60-
&(GlobalC::ppcell),
61-
this->pw_rhod,
62-
this->pw_rho,
63-
this->pw_big);
64-
65-
// 4) inititlize the charge density.
66-
this->pelec->charge->allocate(PARAM.inp.nspin);
67-
this->pelec->omega = ucell.omega;
68-
69-
// 5) initialize the potential.
70-
if (this->pelec->pot == nullptr)
71-
{
72-
this->pelec->pot = new elecstate::Potential(this->pw_rhod,
73-
this->pw_rho,
74-
&ucell,
75-
&(GlobalC::ppcell.vloc),
76-
&(this->sf),
77-
&(this->pelec->f_en.etxc),
78-
&(this->pelec->f_en.vtxc));
79-
}
80-
81-
// 6) prepare some parameters for electronic wave functions initilization
82-
this->p_wf_init = new psi::WFInit<T, Device>(PARAM.inp.init_wfc,
83-
PARAM.inp.ks_solver,
84-
PARAM.inp.basis_type,
85-
PARAM.inp.psi_initializer,
86-
&this->wf,
87-
this->pw_wfc);
88-
// 7) set occupatio, redundant?
89-
if (PARAM.inp.ocp)
90-
{
91-
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
92-
}
93-
94-
// 8) initialize the global classes
95-
this->Init_GlobalC(inp, ucell, GlobalC::ppcell); // temporary
53+
ESolver_KS_PW<T, Device>::before_all_runners(inp, ucell);
9654

97-
// 9) initialize the stochastic wave functions
55+
// 3) initialize the stochastic wave functions
9856
this->stowf.init(&this->kv, this->pw_wfc->npwk_max);
9957
if (inp.nbands_sto != 0)
10058
{
@@ -117,7 +75,7 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
11775
}
11876
this->stowf.sync_chi0();
11977

120-
// 10) allocate spaces for \sqrt(f(H))|chi> and |\tilde{chi}>
78+
// 4) allocate spaces for \sqrt(f(H))|chi> and |\tilde{chi}>
12179
size_t size = stowf.chi0->size();
12280
this->stowf.shchi
12381
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->wf.npwx, this->kv.ngk.data());

0 commit comments

Comments
 (0)