Skip to content

Commit 0eb5a8b

Browse files
committed
update LCAO_set, fix ref of pointer of psi
1 parent f438e2e commit 0eb5a8b

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#include "source_lcao/rho_tau_lcao.h" // mohan add 20251024
2222
#include "source_lcao/LCAO_set.h" // mohan add 20251111
2323

24+
25+
// tmp
26+
#include "source_psi/setup_psi.h" // use Setup_Psi
27+
#include "source_io/read_wfc_nao.h" // use read_wfc_nao
28+
#include "source_estate/elecstate_tools.h" // use fixed_weights
29+
30+
2431
namespace ModuleESolver
2532
{
2633

@@ -73,13 +80,66 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
7380
return;
7481
}
7582

76-
LCAO_domain::set_psi_occ_dm_chg<TK>(this->kv, this->psi, this->pv, this->pelec,
83+
LCAO_domain::set_psi_occ_dm_chg<TK>(this->kv, this->psi, this->pv, this->pelec,
7784
this->dmat, this->chr, inp);
7885

79-
LCAO_domain::set_pot<TK>(ucell, this->kv, this->sf, *this->pw_rho, *this->pw_rhod,
86+
LCAO_domain::set_pot<TK>(ucell, this->kv, this->sf, *this->pw_rho, *this->pw_rhod,
8087
this->pelec, this->orb_, this->pv, this->locpp, this->dftu,
8188
this->solvent, this->exx_nao, this->deepks, inp);
8289

90+
/*
91+
// 5) init electronic wave function psi
92+
Setup_Psi<TK>::allocate_psi(this->psi, this->kv, this->pv, inp);
93+
94+
//! read psi from file
95+
if (inp.init_wfc == "file" && inp.esolver_type != "tddft")
96+
{
97+
if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir,
98+
this->pv, *this->psi, this->pelec->ekb, this->pelec->wg, this->kv.ik2iktot,
99+
this->kv.get_nkstot(), inp.nspin))
100+
{
101+
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed");
102+
}
103+
}
104+
105+
// 7) init DMK, but DMR is constructed in before_scf()
106+
this->dmat.allocate_dm(&this->kv, &this->pv, inp.nspin);
107+
108+
// 8) init exact exchange calculations
109+
this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, inp);
110+
111+
// 9) initialize DFT+U
112+
if (inp.dft_plus_u)
113+
{
114+
this->dftu.init(ucell, &this->pv, this->kv.get_nks(), &orb_);
115+
}
116+
117+
// 10) init local pseudopotentials
118+
this->locpp.init_vloc(ucell, this->pw_rho);
119+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
120+
121+
// 11) init charge density
122+
this->chr.allocate(inp.nspin);
123+
124+
// 12) init potentials
125+
if (this->pelec->pot == nullptr)
126+
{
127+
this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho,
128+
&ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent),
129+
&(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc));
130+
}
131+
132+
// 13) init deepks
133+
this->deepks.before_runner(ucell, this->kv.get_nks(), this->orb_, this->pv, inp);
134+
135+
// 14) set occupations, tddft does not need to set occupations in the first scf
136+
if (inp.ocp && inp.esolver_type != "tddft")
137+
{
138+
elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec,
139+
this->pelec->klist, this->pelec->wg, this->pelec->skip_weights);
140+
}
141+
*/
142+
83143
//! if kpar is not divisible by nks, print a warning
84144
ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao);
85145

source/source_lcao/LCAO_set.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
template <typename TK>
88
void LCAO_domain::set_psi_occ_dm_chg(
99
const K_Vectors &kv, // k-points
10-
psi::Psi<TK>* psi, // coefficients of NAO basis
10+
psi::Psi<TK>* &psi, // coefficients of NAO basis
1111
const Parallel_Orbitals &pv, // parallel scheme of NAO basis
1212
elecstate::ElecState* pelec, // eigen values and weights
1313
LCAO_domain::Setup_DM<TK> &dmat, // density matrix
@@ -42,6 +42,8 @@ void LCAO_domain::set_psi_occ_dm_chg(
4242
//! 5) init charge density
4343
chr.allocate(inp.nspin);
4444

45+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "CHARGE");
46+
4547
return;
4648
}
4749

@@ -65,7 +67,6 @@ void LCAO_domain::set_pot(
6567
{
6668
//! 1) init local pseudopotentials
6769
locpp.init_vloc(ucell, &pw_rho);
68-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
6970

7071
//! 2) init potentials
7172
if (pelec->pot == nullptr)
@@ -88,14 +89,16 @@ void LCAO_domain::set_pot(
8889
//! 5) init deepks
8990
deepks.before_runner(ucell, kv.get_nks(), orb, pv, inp);
9091

92+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "POTENTIALS");
93+
9194
return;
9295
}
9396

9497

9598

9699
template void LCAO_domain::set_psi_occ_dm_chg<double>(
97100
const K_Vectors &kv, // k-points
98-
psi::Psi<double>* psi, // coefficients of NAO basis
101+
psi::Psi<double>* &psi, // coefficients of NAO basis
99102
const Parallel_Orbitals &pv, // parallel scheme of NAO basis
100103
elecstate::ElecState* pelec, // eigen values and weights
101104
LCAO_domain::Setup_DM<double> &dmat, // density matrix
@@ -104,7 +107,7 @@ template void LCAO_domain::set_psi_occ_dm_chg<double>(
104107

105108
template void LCAO_domain::set_psi_occ_dm_chg<std::complex<double>>(
106109
const K_Vectors &kv, // k-points
107-
psi::Psi<std::complex<double>>* psi, // coefficients of NAO basis
110+
psi::Psi<std::complex<double>>* &psi, // coefficients of NAO basis
108111
const Parallel_Orbitals &pv, // parallel scheme of NAO basis
109112
elecstate::ElecState* pelec, // eigen values and weights
110113
LCAO_domain::Setup_DM<std::complex<double>> &dmat, // density matrix

source/source_lcao/LCAO_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace LCAO_domain
2525
template <typename TK>
2626
void set_psi_occ_dm_chg(
2727
const K_Vectors &kv, // k-points
28-
psi::Psi<TK>* psi, // coefficients of NAO basis
28+
psi::Psi<TK>* &psi, // coefficients of NAO basis
2929
const Parallel_Orbitals &pv, // parallel scheme of NAO basis
3030
elecstate::ElecState* pelec, // eigen values and weights
3131
LCAO_domain::Setup_DM<TK> &dmat, // density matrix

0 commit comments

Comments
 (0)