Skip to content

Commit e0823be

Browse files
authored
Update initialization of pw_wfc in esolver_ks.cpp, also some old gint has been deleted, E_bandgap has been changed to E_gap(k), struct efermi has been changed to Efermi (#6617)
* add update_pot in source_estate * split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter * fix bugs * update * update esolver_ks * small updates * small bug fixed * update E_bandgap to E_gap(k) * delete rho_restart file * change setup_parameters to print_parameters * move setup_pw.cpp to setup_pwwfc.cpp in module_pwdft * update esolver, small things * delete some old_gint codes in esolver * fix bugs, update outputs * fix bug in tests * change efermi to Efermi in fp_energy.h * fix bugs * fix exd and exc in ctrl_runner_lcao * fix cmake * fix bug
1 parent 2df3712 commit e0823be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+464
-666
lines changed

source/Makefile.Objects

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ OBJS_ESOLVER=esolver.o\
274274
esolver_of_tool.o\
275275
esolver_of_interface.o\
276276
pw_others.o\
277-
pw_setup.o\
278277

279278
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
280279
esolver_ks_lcao_tddft.o\
@@ -547,7 +546,7 @@ OBJS_IO=input_conv.o\
547546
cal_test.o\
548547
write_dos_pw.o\
549548
nscf_fermi_surf.o\
550-
nscf_band.o\
549+
write_bands.o\
551550
cal_dos.o\
552551
cal_pdos_gamma.o\
553552
cal_pdos_multik.o\
@@ -580,6 +579,7 @@ OBJS_IO=input_conv.o\
580579
write_elecstat_pot.o\
581580
write_elf.o\
582581
write_dipole.o\
582+
write_init.o\
583583
td_current_io.o\
584584
write_libxc_r.o\
585585
output_log.o\
@@ -725,6 +725,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
725725
fp_energy.o\
726726
setup_pot.o\
727727
setup_pwrho.o\
728+
setup_pwwfc.o\
728729
forces.o\
729730
forces_us.o\
730731
forces_nl.o\

source/source_esolver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ list(APPEND objects
1313
esolver_of_interface.cpp
1414
esolver_of_tool.cpp
1515
pw_others.cpp
16-
pw_setup.cpp
1716
)
1817
if(ENABLE_LCAO)
1918
list(APPEND objects

source/source_esolver/esolver_fp.cpp

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
#include "source_io/print_info.h"
1414
#include "source_io/rhog_io.h"
1515
#include "source_io/module_parameter/parameter.h"
16-
#include "source_io/ctrl_output_fp.h"
1716

1817
#include "source_pw/module_pwdft/setup_pwrho.h" // mohan 20251005
1918
#include "source_hamilt/module_xc/xc_functional.h" // mohan 20251005
19+
#include "source_io/ctrl_output_fp.h"
20+
#include "source_io/write_init.h" // write_chg_init, write_pot_init
2021

2122
namespace ModuleESolver
2223
{
@@ -145,64 +146,9 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
145146
//! set direction of magnetism, used in non-collinear case
146147
elecstate::cal_ux(ucell);
147148

148-
//! output the initial charge density
149-
const int nspin = PARAM.inp.nspin;
150-
if (PARAM.inp.out_chg[0] == 2)
151-
{
152-
for (int is = 0; is < nspin; is++)
153-
{
154-
std::stringstream ss;
155-
ss << PARAM.globalv.global_out_dir << "chg";
156-
157-
if(nspin==1)
158-
{
159-
ss << "ini.cube";
160-
}
161-
else if(nspin==2 || nspin==4)
162-
{
163-
ss << "s" << is + 1 << "ini.cube";
164-
}
165-
166-
ModuleIO::write_vdata_palgrid(this->Pgrid,
167-
this->chr.rho[is],
168-
is,
169-
nspin,
170-
istep,
171-
ss.str(),
172-
this->pelec->eferm.ef,
173-
&(ucell));
174-
}
175-
}
176-
177-
//! output total local potential of the initial charge density
178-
if (PARAM.inp.out_pot == 3)
179-
{
180-
for (int is = 0; is < nspin; is++)
181-
{
182-
std::stringstream ss;
183-
ss << PARAM.globalv.global_out_dir << "pot";
184-
185-
if(nspin==1)
186-
{
187-
ss << "ini.cube";
188-
}
189-
else if(nspin==2 || nspin==4)
190-
{
191-
ss << "s" << is + 1 << "ini.cube";
192-
}
193-
194-
ModuleIO::write_vdata_palgrid(this->Pgrid,
195-
this->pelec->pot->get_effective_v(is),
196-
is,
197-
nspin,
198-
istep,
199-
ss.str(),
200-
0.0, // efermi
201-
&(ucell),
202-
11, // precsion
203-
0); // out_fermi
204-
}
205-
}
149+
//! output the initial charge density and potential
150+
ModuleIO::write_chg_init(ucell, this->Pgrid, this->chr, this->pelec->eferm, istep, PARAM.inp);
151+
// ModuleIO::write_pot_init(ucell, this->Pgrid, this->pelec, istep, PARAM.inp);
206152

207153
return;
208154
}

source/source_esolver/esolver_gets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void ESolver_GetS::before_all_runners(UnitCell& ucell, const Input_para& inp)
4343
this->kv.set(ucell, ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
4444
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
4545

46-
ModuleIO::setup_parameters(ucell, this->kv);
46+
ModuleIO::print_parameters(ucell, this->kv, inp);
4747

4848
// 2) init ElecState
4949
// autoset nbands in ElecState, it should before basis_init (for Psi 2d division)

source/source_esolver/esolver_ks.cpp

Lines changed: 35 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
#include "esolver_ks.h"
2-
#include "pw_setup.h" // setup plane wave
32

4-
#include "source_base/timer.h"
5-
#include "source_base/global_variable.h"
6-
#include "source_pw/module_pwdft/global.h"
7-
#include "source_io/module_parameter/parameter.h"
8-
#include "source_lcao/module_dftu/dftu.h"
9-
10-
#include "source_cell/cal_atoms_info.h"
11-
#include "source_estate/elecstate_print.h"
12-
#include "source_hamilt/module_xc/xc_functional.h"
13-
#include "source_hsolver/hsolver.h"
14-
#include "source_io/cube_io.h"
15-
16-
// for NSCF calculations of band structures
17-
#include "source_io/nscf_band.h"
18-
// for output log information
19-
#include "source_io/output_log.h"
20-
#include "source_io/print_info.h"
21-
#include "source_io/write_eig_occ.h"
223
// for jason output information
234
#include "source_io/json_output/init_info.h"
245
#include "source_io/json_output/output_info.h"
256

267
#include "source_estate/update_pot.h" // mohan add 20251016
278
#include "source_estate/module_charge/chgmixing.h" // mohan add 20251018
9+
#include "source_pw/module_pwdft/setup_pwwfc.h" // mohan add 20251018
10+
#include "source_hsolver/hsolver.h"
11+
#include "source_io/write_eig_occ.h"
12+
#include "source_io/write_bands.h"
13+
#include "source_hamilt/module_xc/xc_functional.h"
14+
#include "source_io/output_log.h" // use write_head
15+
#include "source_estate/elecstate_print.h" // print_etot
16+
#include "source_io/print_info.h" // print_parameters
2817

2918
namespace ModuleESolver
3019
{
@@ -40,10 +29,12 @@ ESolver_KS<T, Device>::~ESolver_KS()
4029
// do not add any codes in this deconstructor funcion
4130
//****************************************************
4231
delete this->psi;
43-
delete this->pw_wfc;
4432
delete this->p_hamilt;
4533
delete this->p_chgmix;
4634
this->ppcell.release_memory();
35+
36+
// mohan add 2025-10-18, should be put int clean() function
37+
pw::teardown_pwwfc(this->pw_wfc);
4738
}
4839

4940

@@ -59,74 +50,53 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
5950
classname = "ESolver_KS";
6051
basisname = "";
6152

62-
scf_thr = inp.scf_thr;
63-
scf_ene_thr = inp.scf_ene_thr;
64-
maxniter = inp.scf_nmax;
65-
niter = maxniter;
66-
drho = 0.0;
67-
68-
std::string fft_device = inp.device;
53+
this->scf_thr = inp.scf_thr;
54+
this->scf_ene_thr = inp.scf_ene_thr;
55+
this->maxniter = inp.scf_nmax;
56+
this->niter = maxniter;
57+
this->drho = 0.0;
6958

70-
//! 3) setup pw_wfc
71-
// currently LCAO doesn't support GPU acceleration of FFT
72-
if(inp.basis_type == "lcao")
73-
{
74-
fft_device = "cpu";
75-
}
76-
std::string fft_precision = inp.precision;
77-
#ifdef __ENABLE_FLOAT_FFTW
78-
if (inp.cal_cond && inp.esolver_type == "sdft")
79-
{
80-
fft_precision = "mixing";
81-
}
82-
#endif
83-
84-
pw_wfc = new ModulePW::PW_Basis_K_Big(fft_device, fft_precision);
85-
ModulePW::PW_Basis_K_Big* tmp = static_cast<ModulePW::PW_Basis_K_Big*>(pw_wfc);
86-
87-
tmp->setbxyz(inp.bx, inp.by, inp.bz);
59+
// cell_factor
60+
this->ppcell.cell_factor = inp.cell_factor;
8861

89-
//! 4) setup charge mixing
62+
//! 3) setup charge mixing
9063
p_chgmix = new Charge_Mixing();
9164
p_chgmix->set_rhopw(this->pw_rho, this->pw_rhod);
9265

93-
// cell_factor
94-
this->ppcell.cell_factor = inp.cell_factor;
95-
9666
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL");
9767

98-
//! 5) setup Exc for the first element '0', because all elements have same exc
68+
//! 4) setup Exc for the first element '0', because all elements have same exc
9969
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
10070

101-
//! 6) setup the charge mixing parameters
71+
//! 5) setup the charge mixing parameters
10272
p_chgmix->set_mixing(inp.mixing_mode, inp.mixing_beta, inp.mixing_ndim,
10373
inp.mixing_gg0, inp.mixing_tau, inp.mixing_beta_mag, inp.mixing_gg0_mag,
10474
inp.mixing_gg0_min, inp.mixing_angle, inp.mixing_dmr, ucell.omega, ucell.tpiba);
10575

10676
p_chgmix->init_mixing();
10777

108-
//! 7) symmetry analysis should be performed every time the cell is changed
78+
//! 6) symmetry analysis should be performed every time the cell is changed
10979
if (ModuleSymmetry::Symmetry::symm_flag == 1)
11080
{
11181
ucell.symm.analy_sys(ucell.lat, ucell.st, ucell.atoms, GlobalV::ofs_running);
11282
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
11383
}
11484

115-
//! 8) Setup the k points according to symmetry.
85+
//! 7) Setup the k points according to symmetry.
11686
this->kv.set(ucell,ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
11787
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
11888

119-
//! 9) print information
120-
ModuleIO::setup_parameters(ucell, this->kv);
89+
//! 8) print information
90+
ModuleIO::print_parameters(ucell, this->kv, inp);
12191

122-
//! 10) setup plane wave for electronic wave functions
123-
ModuleESolver::pw_setup(inp, ucell, *this->pw_rho, this->kv, *this->pw_wfc);
92+
//! 9) setup plane wave for electronic wave functions
93+
pw::setup_pwwfc(inp, ucell, *this->pw_rho, this->kv, this->pw_wfc);
12494

125-
//! 11) parallel of FFT grid
95+
//! 10) parallel of FFT grid
12696
Pgrid.init(this->pw_rhod->nx, this->pw_rhod->ny, this->pw_rhod->nz,
12797
this->pw_rhod->nplane, this->pw_rhod->nrxx, pw_big->nbz, pw_big->bz);
12898

129-
//! 12) calculate the structure factor
99+
//! 11) calculate the structure factor
130100
this->sf.setup_structure_factor(&ucell, Pgrid, this->pw_rhod);
131101
}
132102

@@ -303,13 +273,13 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
303273
}
304274

305275
// 1.2) print out eigenvalues and occupations
306-
if(iter % PARAM.inp.out_freq_elec == 0)
307-
{
308-
if (PARAM.inp.out_band[0] || iter == PARAM.inp.scf_nmax || conv_esolver)
276+
if (PARAM.inp.out_band[0])
277+
{
278+
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || conv_esolver)
309279
{
310280
ModuleIO::write_eig_iter(this->pelec->ekb,this->pelec->wg,*this->pelec->klist);
311281
}
312-
}
282+
}
313283

314284
// 2.1) compute magnetization, only for spin==2
315285
ucell.magnet.compute_mag(ucell.omega, this->chr.nrxx, this->chr.nxyz, this->chr.rho,
@@ -388,32 +358,9 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
388358
// 3) write eigenvalues and occupations to eig_occ.txt
389359
ModuleIO::write_eig_file(this->pelec->ekb, this->pelec->wg, this->kv, istep);
390360

391-
// 3) write band information to band.txt
392-
if (PARAM.inp.out_band[0])
393-
{
394-
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
395-
for (int is = 0; is < nspin0; is++)
396-
{
397-
std::stringstream ss;
398-
ss << PARAM.globalv.global_out_dir << "band";
399-
400-
if(nspin0==1)
401-
{
402-
// do nothing
403-
}
404-
else if(nspin0==2)
405-
{
406-
ss << "s" << is + 1;
407-
}
408-
409-
ss << ".txt";
361+
// 4) write band information to band.txt
362+
ModuleIO::write_bands(PARAM.inp, this->pelec->ekb, this->kv);
410363

411-
const double eshift = 0.0;
412-
ModuleIO::nscf_band(is, ss.str(), PARAM.inp.nbands,
413-
eshift, PARAM.inp.out_band[1], // precision
414-
this->pelec->ekb, this->kv);
415-
}
416-
}
417364
}
418365

419366
template <typename T, typename Device>

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
286286
this->gd, this->psi, this->chr, hamilt_lcao,
287287
this->two_center_bundle_, this->GG, this->GK,
288288
this->orb_, this->pw_rho, this->pw_rhod,
289-
this->sf, this->locpp.vloc,
290-
#ifdef __EXX
291-
this->exx_nao.exd,
292-
this->exx_nao.exc,
293-
#endif
294-
this->solvent);
289+
this->sf, this->locpp.vloc, this->exx_nao, this->solvent);
295290

296291
ModuleBase::timer::tick("ESolver_KS_LCAO", "after_all_runners");
297292
}
@@ -305,9 +300,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
305300
ESolver_KS<TK>::iter_init(ucell, istep, iter);
306301

307302
// cast pointers
308-
309303
auto* estate = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
310-
311304
if(!estate)
312305
{
313306
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::iter_init","pelec does not exist");

source/source_esolver/esolver_ks_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>
7676
//! Grid integration: used to store some basic information
7777
Grid_Technique GridT;
7878

79-
#ifndef __OLD_GINT
8079
//! GintInfo: used to store some basic infomation about module_gint
8180
std::unique_ptr<ModuleGint::GintInfo> gint_info_;
82-
#endif
8381

8482
//! NAO orbitals: two-center integrations
8583
TwoCenterBundle two_center_bundle_;

0 commit comments

Comments
 (0)