Skip to content

Commit

Permalink
remove GlobalC::rhopw from Gint and Grid_Technique
Browse files Browse the repository at this point in the history
  • Loading branch information
maki49 committed May 20, 2023
1 parent d2dd71f commit 14ea1d2
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 41 deletions.
3 changes: 2 additions & 1 deletion source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace ModuleESolver
GlobalC::rhopw->nx, GlobalC::rhopw->ny, GlobalC::rhopw->nz,
GlobalC::bigpw->bx, GlobalC::bigpw->by, GlobalC::bigpw->bz,
GlobalC::bigpw->nbx, GlobalC::bigpw->nby, GlobalC::bigpw->nbz,
GlobalC::bigpw->nbxx, GlobalC::bigpw->nbzp_start, GlobalC::bigpw->nbzp);
GlobalC::bigpw->nbxx, GlobalC::bigpw->nbzp_start, GlobalC::bigpw->nbzp,
GlobalC::rhopw->ny, GlobalC::rhopw->nplane,GlobalC::rhopw->startz_current);

// (2)For each atom, calculate the adjacent atoms in different cells
// and allocate the space for H(R) and S(R).
Expand Down
6 changes: 4 additions & 2 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ void LCAO_Hamilt::grid_prepare(void)
if(GlobalV::GAMMA_ONLY_LOCAL)
{
this->GG.prep_grid(GlobalC::bigpw->nbx, GlobalC::bigpw->nby, GlobalC::bigpw->nbzp, GlobalC::bigpw->nbzp_start,
GlobalC::rhopw->nxyz, GlobalC::bigpw->bx, GlobalC::bigpw->by, GlobalC::bigpw->bz, GlobalC::bigpw->bxyz, GlobalC::bigpw->nbxx);
GlobalC::rhopw->nxyz, GlobalC::bigpw->bx, GlobalC::bigpw->by, GlobalC::bigpw->bz, GlobalC::bigpw->bxyz, GlobalC::bigpw->nbxx,
GlobalC::rhopw->ny, GlobalC::rhopw->nplane, GlobalC::rhopw->startz_current);

}
else // multiple k-points
{
// calculate the grid integration of 'Vl' matrix for l-points algorithms.
this->GK.prep_grid(GlobalC::bigpw->nbx, GlobalC::bigpw->nby, GlobalC::bigpw->nbzp, GlobalC::bigpw->nbzp_start,
GlobalC::rhopw->nxyz, GlobalC::bigpw->bx, GlobalC::bigpw->by, GlobalC::bigpw->bz, GlobalC::bigpw->bxyz, GlobalC::bigpw->nbxx);
GlobalC::rhopw->nxyz, GlobalC::bigpw->bx, GlobalC::bigpw->by, GlobalC::bigpw->bz, GlobalC::bigpw->bxyz, GlobalC::bigpw->nbxx,
GlobalC::rhopw->ny, GlobalC::rhopw->nplane, GlobalC::rhopw->startz_current);
}

ModuleBase::timer::tick("LCAO_Hamilt","grid_prepare");
Expand Down
37 changes: 23 additions & 14 deletions source/module_hamilt_lcao/module_gint/gint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Gint::cal_gint(Gint_inout *inout)
#endif
{
//prepare some constants
const int ncyz = GlobalC::rhopw->ny*GlobalC::rhopw->nplane; // mohan add 2012-03-25
const int ncyz = this->ny*this->nplane; // mohan add 2012-03-25
const double dv = GlobalC::ucell.omega/this->ncxyz;

// it's a uniform grid to save orbital values, so the delta_r is a constant.
Expand Down Expand Up @@ -135,21 +135,21 @@ void Gint::cal_gint(Gint_inout *inout)
{
//int* vindex = Gint_Tools::get_vindex(ncyz, ibx, jby, kbz);
int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz);
this->gint_kernel_rho(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
delete[] vindex;
}
else if(inout->job == Gint_Tools::job_type::tau)
{
int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz);
this->gint_kernel_tau(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
delete[] vindex;
}
else if(inout->job == Gint_Tools::job_type::force)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz, dv);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double** DM_in;
if(GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM[GlobalV::CURRENT_SPIN];
if(!GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM_R;
Expand All @@ -167,7 +167,7 @@ void Gint::cal_gint(Gint_inout *inout)
else if(inout->job==Gint_Tools::job_type::vlocal)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz, dv);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
#ifdef _OPENMP
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
{
Expand All @@ -190,7 +190,7 @@ void Gint::cal_gint(Gint_inout *inout)
else if(inout->job==Gint_Tools::job_type::dvlocal)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz, dv);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
#ifdef _OPENMP
this->gint_kernel_dvlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
pvdpRx_thread, pvdpRy_thread, pvdpRz_thread);
Expand All @@ -202,10 +202,10 @@ void Gint::cal_gint(Gint_inout *inout)
}
else if(inout->job==Gint_Tools::job_type::vlocal_meta)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bx, this->by, this->bz,
this->bxyz, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vkdr3 = Gint_Tools::get_vldr3(inout->vofk, this->bx, this->by, this->bz,
this->bxyz, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bxyz, this->bx, this->by, this->bz,
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vkdr3 = Gint_Tools::get_vldr3(inout->vofk,this->bxyz, this->bx, this->by, this->bz,
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
#ifdef _OPENMP
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
{
Expand All @@ -229,9 +229,9 @@ void Gint::cal_gint(Gint_inout *inout)
else if(inout->job == Gint_Tools::job_type::force_meta)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz, dv);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vkdr3 = Gint_Tools::get_vldr3(inout->vofk, this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz, dv);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double** DM_in;
if(GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM[GlobalV::CURRENT_SPIN];
if(!GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM_R;
Expand Down Expand Up @@ -313,7 +313,10 @@ void Gint::prep_grid(
const int& by_in,
const int& bz_in,
const int& bxyz_in,
const int& nbxx_in)
const int& nbxx_in,
const int& ny_in,
const int& nplane_in,
const int& startz_current_in)
{
ModuleBase::TITLE(GlobalV::ofs_running,"Gint_k","prep_grid");

Expand All @@ -327,6 +330,9 @@ void Gint::prep_grid(
this->bz = bz_in;
this->bxyz = bxyz_in;
this->nbxx = nbxx_in;
this->ny = ny_in;
this->nplane = nplane_in;
this->startz_current = startz_current_in;
assert(nbx > 0);
assert(nby>0);
assert(nbz>=0);
Expand All @@ -335,7 +341,10 @@ void Gint::prep_grid(
assert(by > 0);
assert(bz > 0);
assert(bxyz > 0);
assert(nbxx > 0);
assert(nbxx >= 0);
assert(ny > 0);
assert(nplane >= 0);
assert(startz_current >= 0);

assert( GlobalC::ucell.omega > 0.0);

Expand Down
6 changes: 5 additions & 1 deletion source/module_hamilt_lcao/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class Gint
const int& by_in,
const int& bz_in,
const int& bxyz_in,
const int& nbxx_in);
const int& nbxx_in,
const int& ny_in,
const int& nplane_in,
const int& startz_current_in);

protected:
// variables related to FFT grid
Expand All @@ -40,6 +43,7 @@ class Gint
int nbz_start;
int bx, by, bz, bxyz;
int nbxx;
int ny, nplane, startz_current; // from rhopw

//------------------------------------------------------
// in gint_vl.cpp
Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_lcao/module_gint/gint_gamma_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Gint_Gamma::cal_env(const double* wfc, double* rho)
const int nby = GlobalC::GridT.nby;
const int nbz_start = GlobalC::GridT.nbzp_start;
const int nbz = GlobalC::GridT.nbzp;
const int ncyz = GlobalC::rhopw->ny*GlobalC::rhopw->nplane; // mohan add 2012-03-25
const int ncyz = this->ny*this->nplane; // mohan add 2012-03-25

for(int grid_index = 0; grid_index < this->nbxx; grid_index++)
{
Expand All @@ -43,7 +43,7 @@ void Gint_Gamma::cal_env(const double* wfc, double* rho)
psir_ylm.ptr_2D);

int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz);

for (int ia1=0; ia1<size; ia1++)
{
Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_lcao/module_gint/gint_k_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Gint_k::cal_env_k(int ik,
const int nby = GlobalC::GridT.nby;
const int nbz_start = GlobalC::GridT.nbzp_start;
const int nbz = GlobalC::GridT.nbzp;
const int ncyz = GlobalC::rhopw->ny*GlobalC::rhopw->nplane; // mohan add 2012-03-25
const int ncyz = this->ny*this->nplane; // mohan add 2012-03-25

for(int grid_index = 0; grid_index < this->nbxx; grid_index++)
{
Expand All @@ -47,7 +47,7 @@ void Gint_k::cal_env_k(int ik,
psir_ylm.ptr_2D);

int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
GlobalC::GridT.start_ind[grid_index], ncyz);
this->nplane, GlobalC::GridT.start_ind[grid_index], ncyz);

for (int ia1 = 0; ia1 < size; ia1++)
{
Expand Down
12 changes: 8 additions & 4 deletions source/module_hamilt_lcao/module_gint/gint_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Gint_Tools
const int bx,
const int by,
const int bz,
const int nplane,
const int start_ind,
const int ncyz)
{
Expand All @@ -26,7 +27,7 @@ namespace Gint_Tools
const int ipart = ii*ncyz;
for(int jj=0; jj<by; jj++)
{
const int jpart = jj*GlobalC::rhopw->nplane + ipart;
const int jpart = jj*nplane + ipart;
for(int kk=0; kk<bz; kk++)
{
vindex[bindex] = start_ind + kk + jpart;
Expand All @@ -43,6 +44,7 @@ namespace Gint_Tools
const int bx,
const int by,
const int bz,
const int nplane,
const int ncyz,
const int ibx,
const int jby,
Expand All @@ -58,7 +60,7 @@ namespace Gint_Tools
for(int jj=0; jj<by; jj++)
{
// jpart can be obtained by using a previously stored array
const int jpart = (jby+jj)*GlobalC::rhopw->nplane + ipart;
const int jpart = (jby+jj)*nplane + ipart;
for(int kk=0; kk<bz; kk++)
{
vindex[bindex] = kbz+kk + jpart;
Expand All @@ -76,14 +78,15 @@ namespace Gint_Tools
const int bx,
const int by,
const int bz,
const int nplane,
const int ncyz,
const int ibx,
const int jby,
const int kbz,
const double dv)
{
// set the index for obtaining local potentials
int* vindex = Gint_Tools::get_vindex(bxyz, bx, by, bz, ncyz, ibx, jby, kbz);
int* vindex = Gint_Tools::get_vindex(bxyz, bx, by, bz, nplane, ncyz, ibx, jby, kbz);
double *vldr3 = new double[bxyz];
for(int ib=0; ib<bxyz; ib++)
{
Expand All @@ -99,12 +102,13 @@ namespace Gint_Tools
const int bx,
const int by,
const int bz,
const int nplane,
const int start_ind,
const int ncyz,
const double dv)
{
// set the index for obtaining local potentials
int* vindex = Gint_Tools::get_vindex(bxyz, bx, by, bz, start_ind, ncyz);
int* vindex = Gint_Tools::get_vindex(bxyz, bx, by, bz, nplane, start_ind, ncyz);
double *vldr3 = new double[bxyz];
for(int ib=0; ib<bxyz; ib++)
{
Expand Down
8 changes: 4 additions & 4 deletions source/module_hamilt_lcao/module_gint/gint_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,21 @@ namespace Gint_Tools
};

// vindex[pw.bxyz]
int* get_vindex(const int bxyz, const int bx, const int by, const int bz,
int* get_vindex(const int bxyz, const int bx, const int by, const int bz, const int nplane,
const int ncyz, const int ibx, const int jby, const int kbz);

int* get_vindex(const int bxyz, const int bx, const int by, const int bz,
int* get_vindex(const int bxyz, const int bx, const int by, const int bz, const int nplane,
const int start_ind, const int ncyz);

// extract the local potentials.
// vldr3[bxyz]
double* get_vldr3(const double* const vlocal,
const int bxyz, const int bx, const int by, const int bz,
const int bxyz, const int bx, const int by, const int bz, const int nplane,
const int ncyz, const int ibx, const int jby, const int kbz,
const double dv);

double* get_vldr3(const double* const vlocal,
const int bxyz, const int bx, const int by, const int bz,
const int bxyz, const int bx, const int by, const int bz, const int nplane,
const int start_ind, const int ncyz, const double dv);

//------------------------------------------------------
Expand Down
17 changes: 10 additions & 7 deletions source/module_hamilt_lcao/module_gint/grid_technique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ void Grid_Technique::set_pbc_grid(
const int &nbz_in,
const int &nbxx_in,
const int &nbzp_start_in,
const int &nbzp_in)
const int &nbzp_in,
const int& ny,
const int& nplane,
const int& startz_current)
{
ModuleBase::TITLE("Grid_Technique","init");
ModuleBase::timer::tick("Grid_Technique","init");
Expand Down Expand Up @@ -111,15 +114,15 @@ void Grid_Technique::set_pbc_grid(

this->init_meshball();

this->init_atoms_on_grid();
this->init_atoms_on_grid(ny, nplane, startz_current);

this->cal_trace_lo();

ModuleBase::timer::tick("Grid_Technique","init");
return;
}

void Grid_Technique::get_startind(void)
void Grid_Technique::get_startind(const int& ny, const int& nplane, const int& startz_current)
{
ModuleBase::TITLE("Grid_Technique","get_startind");

Expand Down Expand Up @@ -151,9 +154,9 @@ void Grid_Technique::get_startind(void)

ix = ibx * this->bx;
iy = iby * this->by;
iz = (ibz + nbzp_start) * this->bz - GlobalC::rhopw->startz_current;
iz = (ibz + nbzp_start) * this->bz - startz_current;

int ind = iz + iy * GlobalC::rhopw->nplane + ix * GlobalC::rhopw->ny*GlobalC::rhopw->nplane;
int ind = iz + iy * nplane + ix * ny*nplane;

start_ind[i] = ind;
}
Expand All @@ -164,12 +167,12 @@ void Grid_Technique::get_startind(void)
// PLEASE update this 'init_atoms_on_grid' to make
// it adapted to 'cuboid' shape of grid
// mohan add 2021-04-06
void Grid_Technique::init_atoms_on_grid(void)
void Grid_Technique::init_atoms_on_grid(const int& ny, const int& nplane, const int& startz_current)
{
ModuleBase::TITLE("Grid_Technique","init_atoms_on_grid");

assert(nbxx>=0);
this->get_startind();
this->get_startind(ny, nplane, startz_current);

// (1) prepare data.
// counting the number of atoms whose orbitals have
Expand Down
11 changes: 7 additions & 4 deletions source/module_hamilt_lcao/module_gint/grid_technique.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ class Grid_Technique : public Grid_MeshBall
const int &nbz_in,
const int &nbxx_in,
const int &nbzp_start_in,
const int &nbzp_in);

const int& nbzp_in,
const int& ny,
const int& nplane,
const int& startz_current);

/// number of elements(basis-pairs) in this processon
/// on all adjacent atoms-pairs(Grid division)
void cal_nnrg(Parallel_Orbitals* pv);
Expand All @@ -112,12 +115,12 @@ class Grid_Technique : public Grid_MeshBall
int nbox;

// atoms on meshball
void init_atoms_on_grid(void);
void init_atoms_on_grid(const int& ny, const int& nplane, const int& startz_current);
void init_atoms_on_grid2(const int* index2normal);
void cal_grid_integration_index(void);
void cal_trace_lo(void);
void check_bigcell(int* &ind_bigcell, bool* &bigcell_on_processor);
void get_startind(void);
void get_startind(const int& ny, const int& nplane, const int& startz_current);
};

namespace GlobalC
Expand Down

0 comments on commit 14ea1d2

Please sign in to comment.