Skip to content

Commit 45f8a4f

Browse files
Merge branch 'develop' into push-the-wall-patch-1
2 parents ceac065 + 8040017 commit 45f8a4f

File tree

13 files changed

+559
-446
lines changed

13 files changed

+559
-446
lines changed

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,28 @@ void ESolver_KS_PW<T, Device>::hamilt2density_single(const int istep, const int
359359
}
360360
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
361361

362+
//---------------------------------------------------------------------------------------------------------------
363+
//---------------------------------for psi init guess!!!!--------------------------------------------------------
364+
//---------------------------------------------------------------------------------------------------------------
365+
if (!PARAM.inp.psi_initializer && PARAM.inp.basis_type == "pw" && this->init_psi == false)
366+
{
367+
for (int ik = 0; ik < this->pw_wfc->nks; ++ik)
368+
{
369+
//! Update Hamiltonian from other kpoint to the given one
370+
this->p_hamilt->updateHk(ik);
371+
372+
//! Fix the wavefunction to initialize at given kpoint
373+
this->kspw_psi->fix_k(ik);
374+
375+
/// for psi init guess!!!!
376+
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(this->kspw_psi), this->pw_wfc, &this->wf, this->p_hamilt);
377+
}
378+
}
379+
//---------------------------------------------------------------------------------------------------------------
380+
//---------------------------------END: for psi init guess!!!!--------------------------------------------------------
381+
//---------------------------------------------------------------------------------------------------------------
382+
362383
hsolver::HSolverPW<T, Device> hsolver_pw_obj(this->pw_wfc,
363-
&this->wf,
364384
PARAM.inp.calculation,
365385
PARAM.inp.basis_type,
366386
PARAM.inp.ks_solver,
@@ -370,8 +390,7 @@ void ESolver_KS_PW<T, Device>::hamilt2density_single(const int istep, const int
370390
hsolver::DiagoIterAssist<T, Device>::SCF_ITER,
371391
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX,
372392
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR,
373-
hsolver::DiagoIterAssist<T, Device>::need_subspace,
374-
this->init_psi);
393+
hsolver::DiagoIterAssist<T, Device>::need_subspace);
375394

376395
hsolver_pw_obj.solve(this->p_hamilt,
377396
this->kspw_psi[0],

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,35 @@ void ESolver_SDFT_PW<T, Device>::hamilt2density_single(int istep, int iter, doub
190190
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR = ethr;
191191
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX = PARAM.inp.pw_diag_nmax;
192192

193+
//---------------------------------------------------------------------------------------------------------------
194+
//---------------------------------for psi init guess!!!!--------------------------------------------------------
195+
//---------------------------------------------------------------------------------------------------------------
196+
if (!PARAM.inp.psi_initializer && PARAM.inp.basis_type == "pw" && this->init_psi == false)
197+
{
198+
for (int ik = 0; ik < this->pw_wfc->nks; ++ik)
199+
{
200+
//! Update Hamiltonian from other kpoint to the given one
201+
this->p_hamilt->updateHk(ik);
202+
203+
if (this->kspw_psi->get_nbands() > 0 && GlobalV::MY_STOGROUP == 0)
204+
{
205+
//! Fix the wavefunction to initialize at given kpoint
206+
this->kspw_psi->fix_k(ik);
207+
208+
/// for psi init guess!!!!
209+
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(this->kspw_psi), this->pw_wfc, &this->wf, this->p_hamilt);
210+
}
211+
212+
}
213+
}
214+
//---------------------------------------------------------------------------------------------------------------
215+
//---------------------------------END: for psi init guess!!!!--------------------------------------------------------
216+
//---------------------------------------------------------------------------------------------------------------
217+
218+
193219
// hsolver only exists in this function
194220
hsolver::HSolverPW_SDFT<T, Device> hsolver_pw_sdft_obj(&this->kv,
195221
this->pw_wfc,
196-
&this->wf,
197222
this->stowf,
198223
this->stoche,
199224
this->p_hamilt_sto,
@@ -206,8 +231,7 @@ void ESolver_SDFT_PW<T, Device>::hamilt2density_single(int istep, int iter, doub
206231
hsolver::DiagoIterAssist<T, Device>::SCF_ITER,
207232
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX,
208233
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR,
209-
hsolver::DiagoIterAssist<T, Device>::need_subspace,
210-
this->init_psi);
234+
hsolver::DiagoIterAssist<T, Device>::need_subspace);
211235

212236
hsolver_pw_sdft_obj.solve(this->p_hamilt,
213237
this->kspw_psi[0],

source/module_hamilt_lcao/module_gint/gint.h

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
#ifndef GINT_INTERFACE
22
#define GINT_INTERFACE
33

4-
// This class provides a unified interface to the
5-
// grid intergration operation used to calculate
6-
// electron density, and the contribution of local potential
7-
// to Hamiltonian and force/stress
8-
// There are two derived classes of this class
9-
// namely Gint_k and Gint_Gamma, which contains some
10-
// specific operations for gamma point/multi-k calculations
11-
124
#include "gint_tools.h"
135
#include "module_cell/module_neighbor/sltk_grid_driver.h"
146
#include "module_hamilt_lcao/module_gint/grid_technique.h"
157
#include "module_hamilt_lcao/module_hcontainer/hcontainer.h"
16-
178
#include <functional>
189

10+
//----------------------------------------------------------
11+
//!This class provides a unified interface to the
12+
//!grid intergration operation used to calculate
13+
//!electron density, and the contribution of local
14+
//!potential to Hamiltonian and force/stress.
15+
//!There are two derived classes of this class
16+
//! namely Gint_Gamma and Gint_k, which contain
17+
//! specific operations for gamma point/multi-k calculations
18+
//----------------------------------------------------------
19+
1920
class Gint {
2021
public:
2122
~Gint();
2223

23-
/// move operator for the next ESolver to directly use its infomation
24+
//! move operator for the next ESolver to directly use its infomation
2425
Gint& operator=(Gint&& rhs);
2526

2627
hamilt::HContainer<double>* get_hRGint() const { return hRGint; }
28+
2729
std::vector<hamilt::HContainer<double>*> get_DMRGint() const { return DMRGint; }
30+
2831
int get_ncxyz() const { return ncxyz; }
2932

30-
// the unified interface to grid integration
33+
//! the unified interface to grid integration
3134
void cal_gint(Gint_inout* inout);
3235

33-
// preparing FFT grid
36+
//! preparing FFT grid
3437
void prep_grid(const Grid_Technique& gt,
3538
const int& nbx_in,
3639
const int& nby_in,
@@ -79,66 +82,81 @@ class Gint {
7982
const std::vector<int> &block_size,
8083
const std::vector<int> &block_index,
8184
const ModuleBase::Array_Pool<bool> &cal_flag)>;
85+
8286
T_psir_func psir_func_1 = nullptr;
8387
T_psir_func psir_func_2 = nullptr;
8488

8589
protected:
86-
// variables related to FFT grid
90+
91+
//! variables related to FFT grid
8792
int nbx;
8893
int nby;
8994
int nbz;
9095
int ncxyz;
9196
int nbz_start;
92-
int bx, by, bz, bxyz;
97+
int bx;
98+
int by;
99+
int bz;
100+
int bxyz;
93101
int nbxx;
94-
int ny, nplane, startz_current; // from rhopw
102+
int ny;
103+
int nplane;
104+
int startz_current; // from rhopw
95105

96-
// in cal_gint_gpu.cpp
106+
//! in cal_gint_gpu.cpp
97107
void gpu_vlocal_interface(Gint_inout* inout);
98108

99109
void gpu_rho_interface(Gint_inout* inout);
100110

101111
void gpu_force_interface(Gint_inout* inout);
102112

103-
// in cal_gint_cpu.cpp
104-
113+
//! in cal_gint_cpu.cpp
105114
void gint_kernel_vlocal(Gint_inout* inout);
106115

107-
// calculate < phi_0 | vlocal | dphi_R >
116+
//! calculate H_mu_nu(local)=<phi_0|vlocal|dphi_R>
108117
void gint_kernel_dvlocal(Gint_inout* inout);
109118

119+
//! calculate vlocal in meta-GGA functionals
110120
void gint_kernel_vlocal_meta(Gint_inout* inout);
111121

122+
//! calculate charge density rho(r)=\int D_munu \phi_mu \phi_nu
112123
void gint_kernel_rho(Gint_inout* inout);
113124

125+
//! used in meta-GGA functional
114126
void gint_kernel_tau(Gint_inout* inout);
115127

128+
//! compute forces
116129
void gint_kernel_force(Gint_inout* inout);
117130

131+
//! compute forces related to meta-GGA functionals
118132
void gint_kernel_force_meta(Gint_inout* inout);
119133

134+
//! calculate local potential contribution to the Hamiltonian
135+
//! na_grid: how many atoms on this (i,j,k) grid
136+
//! block_iw: dim is [na_grid], index of wave function for each block
137+
//! block_size: dim is [block_size], number of columns of a band
138+
//! block_index: dim is [na_grid+1], total number of atomic orbitals
139+
//! grid_index: index of grid group, for tracing iat
140+
//! cal_flag: dim is [bxyz][na_grid], whether the atom-grid distance is larger than cutoff
141+
//! psir_ylm: dim is [bxyz][LD_pool]
142+
//! psir_vlbr3: dim is [bxyz][LD_pool]
143+
//! hR: HContainer for storing the <phi_0|V|phi_R> matrix elements
144+
120145
void cal_meshball_vlocal(
121-
const int na_grid, // how many atoms on this (i,j,k) grid
146+
const int na_grid,
122147
const int LD_pool,
123-
const int* const block_iw, // block_iw[na_grid], index of wave
124-
// functions for each block
125-
const int* const
126-
block_size, // block_size[na_grid], number of columns of a band
127-
const int* const block_index, // block_index[na_grid+1], count total
128-
// number of atomis orbitals
129-
const int grid_index, // index of grid group, for tracing iat
130-
const bool* const* const
131-
cal_flag, // cal_flag[bxyz][na_grid], whether the atom-grid
132-
// distance is larger than cutoff
133-
const double* const* const psir_ylm, // psir_ylm[bxyz][LD_pool]
134-
const double* const* const psir_vlbr3, // psir_vlbr3[bxyz][LD_pool]
135-
hamilt::HContainer<double>* hR); // HContainer for storing the <phi_0 |
136-
// V | phi_R> matrix element.
137-
138-
//------------------------------------------------------
139-
// in gint_fvl.cpp
140-
//------------------------------------------------------
141-
// calculate vl contributuion to force & stress via grid integrals
148+
const int* const block_iw,
149+
const int* const block_size,
150+
const int* const block_index,
151+
const int grid_index,
152+
const bool* const* const cal_flag,
153+
const double* const* const psir_ylm,
154+
const double* const* const psir_vlbr3,
155+
hamilt::HContainer<double>* hR);
156+
157+
158+
//! in gint_fvl.cpp
159+
//! calculate vl contributuion to force & stress via grid integrals
142160
void gint_kernel_force(const int na_grid,
143161
const int grid_index,
144162
const double delta_r,
@@ -150,6 +168,9 @@ class Gint {
150168
ModuleBase::matrix* svl_dphi,
151169
const UnitCell& ucell);
152170

171+
//! in gint_fvl.cpp
172+
//! calculate vl contributuion to force & stress via grid integrals
173+
//! used in meta-GGA calculations
153174
void gint_kernel_force_meta(const int na_grid,
154175
const int grid_index,
155176
const double delta_r,
@@ -162,31 +183,38 @@ class Gint {
162183
ModuleBase::matrix* svl_dphi,
163184
const UnitCell& ucell);
164185

186+
//! Use grid integrals to compute the atomic force contributions
187+
//! na_grid: how many atoms on this (i,j,k) grid
188+
//! block_size: dim is [na_grid], number of columns of a band
189+
//! block_index: dim is [na_grid+1], total number of atomis orbitals
190+
//! psir_vlbr3_DMR: dim is [bxyz][LD_pool]
191+
//! dpsir_x: dim is [bxyz][LD_pool]
192+
//! dpsir_y: dim is [bxyz][LD_pool]
193+
//! dpsir_z: dim is [bxyz][LD_pool]
165194
void cal_meshball_force(
166195
const int grid_index,
167-
const int na_grid, // how many atoms on this (i,j,k) grid
168-
const int* const
169-
block_size, // block_size[na_grid], number of columns of a band
170-
const int* const block_index, // block_index[na_grid+1], count total
171-
// number of atomis orbitals
172-
const double* const* const psir_vlbr3_DMR, // psir_vlbr3[bxyz][LD_pool]
196+
const int na_grid,
197+
const int* const block_size,
198+
const int* const block_index,
199+
const double* const* const psir_vlbr3_DMR,
173200
const double* const* const dpsir_x, // psir_vlbr3[bxyz][LD_pool]
174201
const double* const* const dpsir_y, // psir_vlbr3[bxyz][LD_pool]
175202
const double* const* const dpsir_z, // psir_vlbr3[bxyz][LD_pool]
176203
ModuleBase::matrix* force);
177204

205+
//! Use grid integrals to compute the stress contributions
206+
//! na_grid: how many atoms on this (i,j,k) grid
207+
//! block_index: dim is [na_grid+1], total number of atomis orbitals
178208
void cal_meshball_stress(
179-
const int na_grid, // how many atoms on this (i,j,k) grid
180-
const int*const block_index, // block_index[na_grid+1], count total number of atomis orbitals
209+
const int na_grid,
210+
const int*const block_index,
181211
const double*const psir_vlbr3_DMR,
182212
const double*const dpsirr,
183213
ModuleBase::matrix *stress);
184-
185-
//------------------------------------------------------
186-
// in gint_k_rho.cpp
187-
//------------------------------------------------------
188-
// calculate the charge density & kinetic energy density (tau) via grid
189-
// integrals
214+
215+
//! Use grid integrals to compute charge density
216+
//! in gint_k_rho.cpp
217+
//! calculate the charge density & kinetic energy density (tau) via grid integrals
190218
void gint_kernel_rho(const int na_grid,
191219
const int grid_index,
192220
const double delta_r,
@@ -195,13 +223,16 @@ class Gint {
195223
const UnitCell& ucell,
196224
Gint_inout* inout);
197225

226+
//! Use grid integrals to compute charge density in a meshball
198227
void cal_meshball_rho(const int na_grid,
199228
const int*const block_index,
200229
const int*const vindex,
201230
const double*const*const psir_ylm,
202231
const double*const*const psir_DMR,
203232
double*const rho);
204233

234+
//! Use grid integrals to compute kinetic energy density tau
235+
//!in meta-GGA functional
205236
void gint_kernel_tau(const int na_grid,
206237
const int grid_index,
207238
const double delta_r,
@@ -210,6 +241,8 @@ class Gint {
210241
Gint_inout* inout,
211242
const UnitCell& ucell);
212243

244+
//! Use grid integrals to compute kinetic energy density tau
245+
//!in a meshball, used in meta-GGA functional calculations
213246
void cal_meshball_tau(const int na_grid,
214247
int* block_index,
215248
int* vindex,
@@ -221,16 +254,22 @@ class Gint {
221254
double** dpsiz_dm,
222255
double* rho);
223256

224-
// save the < phi_0i | V | phi_Rj > in sparse H matrix.
225-
hamilt::HContainer<double>* hRGint
226-
= nullptr; // stores Hamiltonian in sparse format
227-
std::vector<hamilt::HContainer<double>*> hRGint_tmp; // size of vec is 4, only used when nspin = 4
228-
hamilt::HContainer<std::complex<double>>* hRGintCd
229-
= nullptr; // stores Hamiltonian in sparse format
230-
std::vector<hamilt::HContainer<double>*>
231-
DMRGint; // stores DMR in sparse format
232-
hamilt::HContainer<double>* DMRGint_full
233-
= nullptr; // tmp tools used in transfer_DM2DtoGrid
257+
//! save the < phi_0i | V | phi_Rj > in sparse H matrix.
258+
//! stores Hamiltonian in sparse format
259+
hamilt::HContainer<double>* hRGint = nullptr;
260+
261+
//! size of vec is 4, only used when nspin = 4
262+
std::vector<hamilt::HContainer<double>*> hRGint_tmp;
263+
264+
//! stores Hamiltonian in sparse format
265+
hamilt::HContainer<std::complex<double>>* hRGintCd = nullptr;
266+
267+
//! stores DMR in sparse format
268+
std::vector<hamilt::HContainer<double>*> DMRGint;
269+
270+
//! tmp tools used in transfer_DM2DtoGrid
271+
hamilt::HContainer<double>* DMRGint_full = nullptr;
272+
234273
std::vector<hamilt::HContainer<double>> pvdpRx_reduced;
235274
std::vector<hamilt::HContainer<double>> pvdpRy_reduced;
236275
std::vector<hamilt::HContainer<double>> pvdpRz_reduced;

source/module_hamilt_pw/hamilt_pwdft/wf_atomic.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ void WF_atomic::random_t(std::complex<FPTYPE>* psi,
643643
const FPTYPE gk2 = wfc_basis->getgk2(ik,ig);
644644
ppsi[ig+startig] = std::complex<FPTYPE>(rr * cos(arg), rr * sin(arg)) / FPTYPE(gk2 + 1.0);
645645
}
646+
for(int ig=ng ;ig<npwx;++ig)
647+
{
648+
ppsi[ig+startig] = std::complex<FPTYPE>(0.0, 0.0);
649+
}
646650
startig += npwx;
647651
}
648652
}
@@ -734,6 +738,10 @@ void WF_atomic::atomicrandom(ModuleBase::ComplexMatrix& psi,
734738
const double arg= ModuleBase::TWO_PI * tmparg[wfc_basis->ig2isz[ig]];
735739
psi(iw,startig+ig) *= (1.0 + 0.05 * std::complex<double>(rr * cos(arg), rr * sin(arg)));
736740
}
741+
for(int ig=ng ;ig<npwx;++ig)
742+
{
743+
psi(iw,startig+ig) = std::complex<double>(0.0, 0.0);
744+
}
737745
startig += npwx;
738746
}
739747
}

0 commit comments

Comments
 (0)