Skip to content

Commit 429e1f3

Browse files
authored
Merge pull request #913 from wenfei-li/develop
gint : removed more unused codes; unify the interfaces a little bit
2 parents 2db26f6 + cc119fc commit 429e1f3

22 files changed

+280
-376
lines changed

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi<std::complex<double>>& psi)
9494
//------------------------------------------------------------
9595

9696
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
97-
this->uhm->GK.cal_rho_k(this->loc->DM_R);
97+
this->uhm->GK.cal_rho_k(this->loc->DM_R, this->charge);
9898

9999
this->charge->renormalize_rho();
100100

@@ -142,7 +142,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi<double>& psi)
142142
// calculate the charge density on real space grid.
143143
//------------------------------------------------------------
144144
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
145-
this->uhm->GG.cal_rho(this->loc->DM);
145+
this->uhm->GG.cal_rho(this->loc->DM, this->charge);
146146

147147
this->charge->renormalize_rho();
148148

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ namespace ModuleESolver
124124
// calculate the charge density
125125
if (GlobalV::GAMMA_ONLY_LOCAL)
126126
{
127-
this->UHM.GG.cal_rho(this->LOC.DM);
127+
this->UHM.GG.cal_rho(this->LOC.DM, (Charge*)(&GlobalC::CHR));
128128
}
129129
else
130130
{
131-
this->UHM.GK.cal_rho_k(this->LOC.DM_R);
131+
this->UHM.GK.cal_rho_k(this->LOC.DM_R, (Charge*)(&GlobalC::CHR));
132132
}
133133

134134
// renormalize the charge density

source/src_io/istate_charge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void IState_Charge::begin(Gint_Gamma &gg)
136136

137137
// (4) calculate charge density for a particular
138138
// band.
139-
gg.cal_rho(this->loc->DM);
139+
gg.cal_rho(this->loc->DM, (Charge*)(&GlobalC::CHR));
140140
GlobalC::CHR.save_rho_before_sum_band(); //xiaohui add 2014-12-09
141141
std::stringstream ss;
142142
std::stringstream ss1;

source/src_lcao/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ list(APPEND objects
3636
gint_gamma_vl.cpp
3737
gint_k.cpp
3838
gint_k_fvl.cpp
39+
gint_k_fvl_new.cpp
3940
gint_k_init.cpp
4041
gint_k_rho.cpp
4142
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/LCAO_hamilt.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ void LCAO_Hamilt::set_lcao_matrices(void)
3434
ModuleBase::timer::tick("LCAO_Hamilt","set_lcao_matrices");
3535

3636
if(GlobalV::GAMMA_ONLY_LOCAL)
37-
{
38-
// mohan add 2012-03-29
39-
// calculate the grid integration of 'Vl' matrix for gamma algorithms.
40-
this->GG.prepare(GlobalC::ucell.latvec, GlobalC::ucell.lat0);
41-
37+
{
4238
// calulate the 'S', 'T' and 'Vnl' matrix for gamma algorithms.
4339
this->calculate_STNR_gamma();
4440

@@ -50,7 +46,6 @@ void LCAO_Hamilt::set_lcao_matrices(void)
5046

5147
// calculate the grid integration of 'Vl' matrix for l-points algorithms.
5248
this->GK.init(GlobalC::pw.nbx, GlobalC::pw.nby, GlobalC::pw.nbzp, GlobalC::pw.nbzp_start, GlobalC::pw.ncxyz, this->LM);
53-
5449
}
5550

5651
// initial the overlap matrix is done.

source/src_lcao/gint_gamma.cpp

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55

66
Gint_Gamma::Gint_Gamma()
77
{
8-
ylm1 = new double[100];
9-
ylm2 = new double[100]; // can used for L=9
10-
iq = new int[1];
11-
x0 = new double[1];
12-
x1 = new double[1];
13-
x2 = new double[1];
14-
x3 = new double[1];
15-
x12 = new double[1];
16-
x03 = new double[1];
17-
8+
189
sender_index_size = 1;
1910
sender_local_index = new int[1];
2011
sender_size_process = new int[1];
@@ -32,15 +23,6 @@ Gint_Gamma::Gint_Gamma()
3223

3324
Gint_Gamma::~Gint_Gamma()
3425
{
35-
delete[] ylm1;
36-
delete[] ylm2;
37-
delete[] iq;
38-
delete[] x0;
39-
delete[] x1;
40-
delete[] x2;
41-
delete[] x3;
42-
delete[] x12;
43-
delete[] x03;
4426

4527
delete[] sender_local_index;
4628
delete[] sender_size_process;
@@ -51,61 +33,4 @@ Gint_Gamma::~Gint_Gamma()
5133
delete[] receiver_size_process;
5234
delete[] receiver_displacement_process;
5335
delete[] receiver_buffer;
54-
}
55-
56-
57-
void Gint_Gamma::save_atoms_on_grid(const Grid_Technique &gt)
58-
{
59-
ModuleBase::TITLE("Grid_Integral","save_atoms_on_grid");
60-
61-
// mohan change.
62-
max_size = gt.max_atom;
63-
64-
if(max_size == 0)
65-
{
66-
// mohan add return 2011-03-15
67-
GlobalV::ofs_warning << " processor " << GlobalV::MY_RANK << ": no atom on sub-fft-grid." << std::endl;
68-
return;
69-
}
70-
71-
delete[] iq;
72-
delete[] x0;
73-
delete[] x1;
74-
delete[] x2;
75-
delete[] x3;
76-
delete[] x12;
77-
delete[] x03;
78-
this->iq = new int[max_size];
79-
this->x0 = new double[max_size];
80-
this->x1 = new double[max_size];
81-
this->x2 = new double[max_size];
82-
this->x3 = new double[max_size];
83-
this->x12 = new double[max_size];
84-
this->x03 = new double[max_size];
85-
86-
ModuleBase::GlobalFunc::ZEROS(iq, max_size);
87-
ModuleBase::GlobalFunc::ZEROS(x0, max_size);
88-
ModuleBase::GlobalFunc::ZEROS(x1, max_size);
89-
ModuleBase::GlobalFunc::ZEROS(x2, max_size);
90-
ModuleBase::GlobalFunc::ZEROS(x3, max_size);
91-
ModuleBase::GlobalFunc::ZEROS(x12, max_size);
92-
ModuleBase::GlobalFunc::ZEROS(x03, max_size);
93-
94-
this->vfactor = std::abs(this->latvec0.Det())/gt.ncxyz;
95-
96-
return;
97-
}
98-
99-
void Gint_Gamma::prepare(
100-
const ModuleBase::Matrix3 &latvec_in,
101-
const double& lat0_in)
102-
{
103-
ModuleBase::TITLE("Grid_Base_Beta","prepare");
104-
105-
this->lat0 = lat0_in;
106-
107-
this->latvec0 = latvec_in;
108-
this->latvec0 *= this->lat0;
109-
110-
return;
11136
}

source/src_lcao/gint_gamma.h

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../module_base/global_variable.h"
1212
#include "grid_technique.h"
1313
#include "LCAO_matrix.h"
14+
#include "../src_pw/charge.h"
1415
#include <omp.h>
1516

1617
//=========================================================
@@ -30,7 +31,7 @@ class Gint_Gamma
3031
void cal_vlocal( const double*const vlocal, LCAO_Matrix &lm);
3132

3233
// (2) calculate charge density
33-
double cal_rho(double*** DM_in);
34+
void cal_rho(double*** DM_in, Charge* chr);
3435

3536
// (3) calcualte the forces related to grid
3637
void cal_force(double*** DM_in, const double*const vlocal,
@@ -42,36 +43,13 @@ class Gint_Gamma
4243

4344
// (5) calculate the Mulliken charge
4445
void cal_mulliken(double** mulliken);
45-
46-
void prepare(
47-
const ModuleBase::Matrix3 &latvec_in,
48-
const double& lat0_in);
4946

5047
private:
5148

52-
double vfactor;
53-
ModuleBase::Matrix3 latvec0;
54-
double lat0;
5549
double*** DM; //pointer to LOC.DM
56-
double* transformer;
57-
double psiv1;
58-
double psiv2;
59-
double* ylm1;
60-
double* ylm2;
6150

6251
int grid_index; // may delete?
6352
int max_size;
64-
65-
// these parameters are for interpolation.
66-
// we store these parameters at first to speed
67-
// up the calculation.
68-
double *x0;
69-
double *x1;
70-
double *x2;
71-
double *x3;
72-
double* x12;
73-
double* x03;
74-
int *iq;
7553

7654
///===============================
7755
/// Use MPI_Alltoallv to convert a grid distributed matrix
@@ -90,32 +68,17 @@ class Gint_Gamma
9068
int *receiver_size_process;
9169
int *receiver_displacement_process;
9270
double* receiver_buffer;
93-
94-
void save_atoms_on_grid(const Grid_Technique& gt);
9571

9672
// for calculation of < phi_i | Vlocal | phi_j >
9773
// Input: vlocal[ir]
9874
// Output: GridVlocal.ptr_2D[iw1_lo][iw2_lo]
9975
Gint_Tools::Array_Pool<double> gamma_vlocal(const double*const vlocal) const;
100-
101-
// for calculation of charege
102-
// Input: DM[is][iw1_lo][iw2_lo]
103-
// Output: rho.ptr_2D[is][ir]
104-
Gint_Tools::Array_Pool<double> gamma_charge(const double*const*const*const DM) const;
105-
10676
// for calculation of Mulliken charge.
10777
void gamma_mulliken(double** mulliken);
10878

10979
// for calculation of envelope functions.
11080
void gamma_envelope(const double* wfc, double* rho);// mohan add 2011-07-01
11181

112-
113-
// for calculatin of < dphi_i | Vlocal | phi_j > for foce calculation
114-
// on regular FFT real space grid.
115-
void gamma_force(const double*const*const*const DM, const double*const vlocal,
116-
ModuleBase::matrix& force, ModuleBase::matrix& stress,
117-
const bool is_force, const bool is_stress);
118-
11982
void cal_meshball_vlocal(
12083
const int na_grid, // how many atoms on this (i,j,k) grid
12184
const int LD_pool,
@@ -139,7 +102,7 @@ class Gint_Gamma
139102
const double*const*const psir_ylm, // psir_ylm[GlobalC::pw.bxyz][LD_pool]
140103
const int*const vindex, // vindex[GlobalC::pw.bxyz]
141104
const double*const*const*const DM, // DM[GlobalV::NSPIN][lgd_now][lgd_now]
142-
Gint_Tools::Array_Pool<double> &rho) const; // rho[GlobalV::NSPIN][GlobalC::pw.nrxx]
105+
Charge* chr) const; // rho[GlobalV::NSPIN][GlobalC::pw.nrxx]
143106

144107
void cal_meshball_force(
145108
const int grid_index,

source/src_lcao/gint_gamma_env.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void Gint_Gamma::cal_env(const double* wfc, double* rho)
1010
ModuleBase::TITLE("Gint_Gamma","cal_env");
1111
ModuleBase::timer::tick("Gint_Gamma","cal_env");
1212

13-
this->save_atoms_on_grid(GlobalC::GridT);
13+
this->max_size = GlobalC::GridT.max_atom;
1414
this->gamma_envelope(wfc, rho);
1515

1616
ModuleBase::timer::tick("Gint_Gamma","cal_env");
@@ -141,15 +141,7 @@ void Gint_Gamma::gamma_envelope(const double* wfc, double* rho)
141141
// we can get the parameters we need to do interpolation and
142142
// store them first!! these can save a lot of effort.
143143
const double position = distance[ib][id] / delta_r;
144-
/*
145-
this->iq[id] = static_cast<int>(position);
146-
this->x0[id] = position - static_cast<double>(iq[id]);
147-
this->x1[id] = 1.0 - x0[id];
148-
this->x2[id] = 2.0 - x0[id];
149-
this->x3[id] = 3.0 - x0[id];
150-
this->x12[id] = x1[id]*x2[id] / 6.0;
151-
this->x03[id] = x0[id]*x3[id] / 2.0;
152-
*/
144+
153145
int ip;
154146
double dx, dx2, dx3;
155147
double c1, c2, c3, c4;

0 commit comments

Comments
 (0)