Skip to content

Commit 30d0796

Browse files
author
wenfei-li
committed
gint_k : add interface for new force implementation (not done yet)
1 parent 54ad81c commit 30d0796

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed

source/src_lcao/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ list(APPEND objects
3737
gint_gamma_vl.cpp
3838
gint_k.cpp
3939
gint_k_fvl.cpp
40+
gint_k_fvl_new.cpp
4041
gint_k_init.cpp
4142
gint_k_rho.cpp
4243
gint_k_vl.cpp

source/src_lcao/FORCE_k.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void Force_LCAO_k::ftable_k (
7070
// doing on the real space grid.
7171
// ---------------------------------------
7272
this->cal_fvl_dphi_k(dm2d, isforce, isstress, fvl_dphi, svl_dphi);
73+
//this->cal_fvl_dphi_k_new(isforce, isstress, fvl_dphi, svl_dphi);
7374

7475
this->calFvnlDbeta(dm2d, isforce, isstress, fvnl_dbeta, svnl_dbeta, GlobalV::vnl_method);
7576

@@ -1152,6 +1153,50 @@ void Force_LCAO_k::cal_fvl_dphi_k(
11521153
return;
11531154
}
11541155

1156+
// calculate the force due to < phi | Vlocal | dphi >
1157+
void Force_LCAO_k::cal_fvl_dphi_k_new(
1158+
const bool isforce,
1159+
const bool isstress,
1160+
ModuleBase::matrix& fvl_dphi,
1161+
ModuleBase::matrix& svl_dphi)
1162+
{
1163+
ModuleBase::TITLE("Force_LCAO_k","cal_fvl_dphi_k_new");
1164+
ModuleBase::timer::tick("Force_LCAO_k","cal_fvl_dphi_k_new");
1165+
1166+
if(!isforce&&!isstress)
1167+
{
1168+
ModuleBase::timer::tick("Force_LCAO_k","cal_fvl_dphi_k_new");
1169+
return;
1170+
}
1171+
1172+
int istep = 1;
1173+
1174+
// if Vna potential is not used.
1175+
GlobalC::pot.init_pot(istep, GlobalC::pw.strucFac);
1176+
1177+
1178+
for(int is=0; is<GlobalV::NSPIN; ++is)
1179+
{
1180+
GlobalV::CURRENT_SPIN = is;
1181+
for(int ir=0; ir<GlobalC::pw.nrxx; ir++)
1182+
{
1183+
GlobalC::pot.vr_eff1[ir] = GlobalC::pot.vr_eff(GlobalV::CURRENT_SPIN, ir);
1184+
}
1185+
1186+
//--------------------------------
1187+
// Grid integration here.
1188+
//--------------------------------
1189+
// fvl_dphi can not be set to zero here if Vna is used
1190+
if(isstress||isforce)
1191+
{
1192+
this->UHM->GK.cal_force_k(isforce, isstress, fvl_dphi,svl_dphi,GlobalC::pot.vr_eff1);
1193+
}
1194+
}
1195+
1196+
ModuleBase::timer::tick("Force_LCAO_k","cal_fvl_dphi_k_new");
1197+
return;
1198+
}
1199+
11551200
void Force_LCAO_k::calFvnlDbeta(
11561201
double** dm2d,
11571202
const bool &isforce,

source/src_lcao/FORCE_k.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Force_LCAO_k : public Force_LCAO_gamma
6060

6161
// calculate the force due to < phi | Vlocal | dphi >
6262
void cal_fvl_dphi_k(double** dm2d, const bool isforce, const bool isstress, ModuleBase::matrix& fvl_dphi, ModuleBase::matrix& svl_dphi);
63+
void cal_fvl_dphi_k_new(const bool isforce, const bool isstress, ModuleBase::matrix& fvl_dphi, ModuleBase::matrix& svl_dphi);
6364

6465
// old method to calculate the force due to < phi | dbeta > < beta | phi >
6566
void cal_fvnl_dbeta_k(double** dm2d, const bool isforce, const bool isstress, ModuleBase::matrix& fvnl_dbeta, ModuleBase::matrix& svnl_dbeta);

source/src_lcao/gint_k.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ class Gint_k : public Gint_k_init
109109
//mohan add 2011-06-19
110110
//zhengdy add 2016-10-18
111111

112+
void cal_force_k(
113+
const bool isforce,
114+
const bool isstress,
115+
ModuleBase::matrix& fvl_dphi,
116+
ModuleBase::matrix& svl_dphi,
117+
const double* vl);
118+
112119
private:
113120

114121
//------------------------------------------------------

source/src_lcao/gint_k_fvl_new.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include "gint_k.h"
2+
#include "../src_pw/global.h"
3+
#include "global_fp.h" // mohan add 2021-01-30
4+
5+
#include "../module_base/ylm.h"
6+
#include "../module_base/timer.h"
7+
8+
void Gint_k::cal_force_k(
9+
const bool isforce,
10+
const bool isstress,
11+
ModuleBase::matrix& fvl_dphi,
12+
ModuleBase::matrix& svl_dphi,
13+
const double *vl)
14+
{
15+
ModuleBase::TITLE("Gint_k","cal_force_k");
16+
ModuleBase::timer::tick("Gint_k","cal_force_k");
17+
18+
const int max_size = GlobalC::GridT.max_atom;
19+
20+
if(max_size)
21+
{
22+
const int nbx = GlobalC::GridT.nbx;
23+
const int nby = GlobalC::GridT.nby;
24+
const int nbz_start = GlobalC::GridT.nbzp_start;
25+
const int nbz = GlobalC::GridT.nbzp;
26+
const double dv = GlobalC::ucell.omega/GlobalC::pw.ncxyz;
27+
28+
const int ncyz = GlobalC::pw.ncy*GlobalC::pw.nczp; // mohan add 2012-03-25
29+
30+
for (int i=0; i<nbx; i++)
31+
{
32+
const int ibx = i*GlobalC::pw.bx;
33+
for (int j=0; j<nby; j++)
34+
{
35+
const int jby = j*GlobalC::pw.by;
36+
for (int k=nbz_start; k<nbz_start+nbz; k++)
37+
{
38+
const int kbz = k*GlobalC::pw.bz-GlobalC::pw.nczp_start;
39+
40+
const int grid_index = (k-nbz_start) + j * nbz + i * nby * nbz;
41+
42+
// get the value: how many atoms has orbital value on this grid.
43+
const int na_grid = GlobalC::GridT.how_many_atoms[ grid_index ];
44+
if(na_grid==0) continue;
45+
46+
// it's a uniform grid to save orbital values, so the delta_r is a constant.
47+
const double delta_r = GlobalC::ORB.dr_uniform;
48+
49+
// here vindex refers to local potentials
50+
int* vindex = Gint_Tools::get_vindex(ncyz, ibx, jby, kbz);
51+
52+
int * block_iw, * block_index, * block_size;
53+
Gint_Tools::get_block_info(na_grid, grid_index, block_iw, block_index, block_size);
54+
55+
//------------------------------------------------------
56+
// whether the atom-grid distance is larger than cutoff
57+
//------------------------------------------------------
58+
bool **cal_flag = Gint_Tools::get_cal_flag(na_grid, grid_index);
59+
60+
// set up band matrix psir_ylm and psir_DM
61+
const int LD_pool = max_size*GlobalC::ucell.nwmax;
62+
63+
Gint_Tools::Array_Pool<double> psir_ylm(GlobalC::pw.bxyz, LD_pool);
64+
Gint_Tools::Array_Pool<double> dpsir_ylm_x(GlobalC::pw.bxyz, LD_pool);
65+
Gint_Tools::Array_Pool<double> dpsir_ylm_y(GlobalC::pw.bxyz, LD_pool);
66+
Gint_Tools::Array_Pool<double> dpsir_ylm_z(GlobalC::pw.bxyz, LD_pool);
67+
68+
Gint_Tools::cal_dpsir_ylm(
69+
na_grid, grid_index, delta_r,
70+
block_index, block_size,
71+
cal_flag,
72+
psir_ylm.ptr_2D,
73+
dpsir_ylm_x.ptr_2D,
74+
dpsir_ylm_y.ptr_2D,
75+
dpsir_ylm_z.ptr_2D
76+
);
77+
78+
double *vldr3 = Gint_Tools::get_vldr3(vl, ncyz, ibx, jby, kbz, dv);
79+
const Gint_Tools::Array_Pool<double> psir_vlbr3 = Gint_Tools::get_psir_vlbr3(
80+
na_grid, LD_pool,
81+
block_index, cal_flag,
82+
vldr3, psir_ylm.ptr_2D);
83+
84+
Gint_Tools::Array_Pool<double> psir_vlbr3_DM(GlobalC::pw.bxyz, LD_pool);
85+
if(isforce)
86+
{
87+
}
88+
if(isstress)
89+
{
90+
}
91+
92+
free(vldr3); vldr3=nullptr;
93+
delete[] block_iw;
94+
delete[] block_index;
95+
delete[] block_size;
96+
97+
for(int ib=0; ib<GlobalC::pw.bxyz; ++ib)
98+
free(cal_flag[ib]);
99+
free(cal_flag); cal_flag=nullptr;
100+
}//k
101+
}//j
102+
}//i
103+
}//max_size
104+
105+
106+
ModuleBase::timer::tick("Gint_k","cal_force_k");
107+
return;
108+
}
109+
110+

0 commit comments

Comments
 (0)