Skip to content

Commit

Permalink
Revert "Move the cal_nnrg file and modify the variable length. (#4886)…
Browse files Browse the repository at this point in the history
…" (#4921)

* Revert "Move the cal_nnrg file and modify the variable length. (#4886)"

This reverts commit fa32970.

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
A-006 and pre-commit-ci-lite[bot] authored Aug 8, 2024
1 parent fb02c31 commit 5e0406f
Show file tree
Hide file tree
Showing 33 changed files with 352 additions and 217 deletions.
2 changes: 1 addition & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ OBJS_GINT=gint.o\
gint_force_cpu_interface.o\
gint_rho_cpu_interface.o\
gint_vl_cpu_interface.o\
cal_nnrg.o\
cal_psir_ylm.o\
cal_dpsir_ylm.o\
cal_ddpsir_ylm.o\
Expand Down Expand Up @@ -576,6 +575,7 @@ OBJS_LCAO=evolve_elec.o\
LCAO_set_fs.o\
LCAO_set_st.o\
LCAO_nl_mu.o\
LCAO_nnr.o\
LCAO_set_zero.o\
LCAO_allocate.o\
LCAO_set_mat2d.o\
Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/set_matrix_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void ESolver_KS_LCAO<TK, TR>::set_matrix_grid(Record_adj& ra)
this->pw_rho->nplane,
this->pw_rho->startz_current,
GlobalC::ucell,
GlobalC::GridD,
dr_uniform,
rcuts,
psi_u,
Expand Down
1 change: 1 addition & 0 deletions source/module_hamilt_lcao/hamilt_lcaodft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if(ENABLE_LCAO)
spar_hsr.cpp
spar_st.cpp
spar_u.cpp
LCAO_nnr.cpp
LCAO_set_fs.cpp
LCAO_set_st.cpp
LCAO_nl_mu.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "grid_technique.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"
#include "module_cell/module_neighbor/sltk_grid_driver.h"
#include "../hamilt_lcaodft/record_adj.h" //mohan add 2012-07-06
#include "record_adj.h" //mohan add 2012-07-06
#include "module_base/timer.h"
#include "module_base/tool_threading.h"
#include "module_cell/module_neighbor/sltk_grid_driver.h"
Expand All @@ -16,7 +15,7 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
{
ModuleBase::TITLE("LCAO_nnr","cal_nnrg");

this->max_box_index();
this->cal_max_box_index();

this->nnrg = 0;

Expand All @@ -25,22 +24,22 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
nad.clear();
this->nnrg_index.resize(0);

this->nad = std::vector<int>(ucell->nat, 0);
this->nlocdimg = std::vector<int>(ucell->nat, 0);
this->nlocstartg =std::vector<int>(ucell->nat, 0);
this->nad = std::vector<int>(GlobalC::ucell.nat, 0);
this->nlocdimg = std::vector<int>(GlobalC::ucell.nat, 0);
this->nlocstartg =std::vector<int>(GlobalC::ucell.nat, 0);

ModuleBase::Vector3<double> tau1, tau2, dtau;
ModuleBase::Vector3<double> dtau1, dtau2, tau0;
for (int T1 = 0; T1 < ucell->ntype; ++T1)
for (int T1 = 0; T1 < GlobalC::ucell.ntype; ++T1)
{
Atom* atom1 = &ucell->atoms[T1];
Atom* atom1 = &GlobalC::ucell.atoms[T1];
for (int I1 = 0; I1 < atom1->na; ++I1)
{
tau1 = atom1->tau[I1];

gd->Find_atom(*ucell, tau1, T1, I1);
GlobalC::GridD.Find_atom(GlobalC::ucell, tau1, T1, I1);

const int iat = ucell->itia2iat(T1,I1);
const int iat = GlobalC::ucell.itia2iat(T1,I1);

// for grid integration (on FFT box),
// we only need to consider <phi_i | phi_j>,
Expand All @@ -57,35 +56,35 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
this->nad[iat] = 0;

int count = 0;
for (int ad = 0; ad < gd->getAdjacentNum()+1; ++ad)
for (int ad = 0; ad < GlobalC::GridD.getAdjacentNum()+1; ++ad)
{
const int T2 = gd->getType(ad);
const int I2 = gd->getNatom(ad);
const int iat2 = ucell->itia2iat(T2, I2);
Atom* atom2 = &ucell->atoms[T2];
const int T2 = GlobalC::GridD.getType(ad);
const int I2 = GlobalC::GridD.getNatom(ad);
const int iat2 = GlobalC::ucell.itia2iat(T2, I2);
Atom* atom2 = &GlobalC::ucell.atoms[T2];

// if the adjacent atom is in this processor.
if(this->in_this_processor[iat2])
{
tau2 = gd->getAdjacentTau(ad);
dtau = gd->getAdjacentTau(ad) - tau1;
double distance = dtau.norm() * ucell->lat0;
double rcut = rcuts[T1] + rcuts[T2];
tau2 = GlobalC::GridD.getAdjacentTau(ad);
dtau = GlobalC::GridD.getAdjacentTau(ad) - tau1;
double distance = dtau.norm() * GlobalC::ucell.lat0;
double rcut = GlobalC::ORB.Phi[T1].getRcut() + GlobalC::ORB.Phi[T2].getRcut();


//if(distance < rcut)
// mohan reset this 2013-07-02 in Princeton
// we should make absolutely sure that the distance is smaller than rcut[it]
// we should make absolutely sure that the distance is smaller than GlobalC::ORB.Phi[it].getRcut
// this should be consistant with LCAO_nnr::cal_nnrg function
// typical example : 7 Bohr cutoff Si orbital in 14 Bohr length of cell.
// distance = 7.0000000000000000
// rcut[it] = 7.0000000000000008
// GlobalC::ORB.Phi[it].getRcut = 7.0000000000000008
if(distance < rcut - 1.0e-15)
{
//storing the indexed for nnrg
const int mu = pv->global2local_row(iat);
const int nu = pv->global2local_col(iat2);
this->nnrg_index.push_back(grid_integral::gridIndex{this->nnrg, mu, nu, gd->getBox(ad), atom1->nw, atom2->nw});
this->nnrg_index.push_back(gridIntegral::gridIndex{this->nnrg, mu, nu, GlobalC::GridD.getBox(ad), atom1->nw, atom2->nw});

const int nelement = atom1->nw * atom2->nw;
this->nnrg += nelement;
Expand All @@ -100,7 +99,8 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
}// end I1
}// end T1

if(GlobalV::OUT_LEVEL != "m") ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nnrg",this->nnrg);
if(GlobalV::OUT_LEVEL != "m") { ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nnrg",this->nnrg);
}

//--------------------------------------------------
// search again, to order each (iat2, b1, b2, b3)
Expand All @@ -117,10 +117,10 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
find_R2_sorted_index.clear();
allocate_find_R2 = false;
}
this->find_R2.resize(ucell->nat);
this->find_R2st.resize(ucell->nat);
this->find_R2_sorted_index.resize(ucell->nat);
for (int iat = 0; iat < ucell->nat; iat++)
this->find_R2.resize(GlobalC::ucell.nat);
this->find_R2st.resize(GlobalC::ucell.nat);
this->find_R2_sorted_index.resize(GlobalC::ucell.nat);
for (int iat = 0; iat < GlobalC::ucell.nat; iat++)
{
this->find_R2_sorted_index[iat].resize(nad[iat]);
std::fill(this->find_R2_sorted_index[iat].begin(), this->find_R2_sorted_index[iat].end(), 0);
Expand All @@ -132,47 +132,47 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)

allocate_find_R2 = true;

for (int T1 = 0; T1 < ucell->ntype; T1++)
for (int T1 = 0; T1 < GlobalC::ucell.ntype; T1++)
{
for (int I1 = 0; I1 < ucell->atoms[T1].na; I1++)
for (int I1 = 0; I1 < GlobalC::ucell.atoms[T1].na; I1++)
{
// std::cout << " T1=" << T1 << " I1=" << I1 << std::endl;
tau1 = ucell->atoms[T1].tau[I1];
gd->Find_atom(*ucell, tau1, T1, I1);
const int iat = ucell->itia2iat(T1,I1);
tau1 = GlobalC::ucell.atoms[T1].tau[I1];
GlobalC::GridD.Find_atom(GlobalC::ucell, tau1, T1, I1);
const int iat = GlobalC::ucell.itia2iat(T1,I1);

// std::cout << " Number of adjacent = " << gd->getAdjacentNum()+1 << std::endl;
// std::cout << " Number of adjacent = " << GlobalC::GridD.getAdjacentNum()+1 << std::endl;

int count=0;
for (int ad = 0; ad < gd->getAdjacentNum()+1; ad++)
for (int ad = 0; ad < GlobalC::GridD.getAdjacentNum()+1; ad++)
{
// std::cout << " ad=" << ad << std::endl;
const int T2 = gd->getType(ad);
const int I2 = gd->getNatom(ad);
const int iat2 = ucell->itia2iat(T2,I2);
const int T2 = GlobalC::GridD.getType(ad);
const int I2 = GlobalC::GridD.getNatom(ad);
const int iat2 = GlobalC::ucell.itia2iat(T2,I2);

// if this atom is in this processor.
if(this->in_this_processor[iat])
{
if(this->in_this_processor[iat2])
{
dtau = gd->getAdjacentTau(ad) - tau1;
double distance = dtau.norm() * ucell->lat0;
double rcut = rcuts[T1] + rcuts[T2];
dtau = GlobalC::GridD.getAdjacentTau(ad) - tau1;
double distance = dtau.norm() * GlobalC::ucell.lat0;
double rcut = GlobalC::ORB.Phi[T1].getRcut() + GlobalC::ORB.Phi[T2].getRcut();

const int b1 = gd->getBox(ad).x;
const int b2 = gd->getBox(ad).y;
const int b3 = gd->getBox(ad).z;
const int b1 = GlobalC::GridD.getBox(ad).x;
const int b2 = GlobalC::GridD.getBox(ad).y;
const int b3 = GlobalC::GridD.getBox(ad).z;

// mohan fix bug 2011-06-26, should be '<', not '<='
// if(distance < rcut)

// mohan reset this 2013-07-02 in Princeton
// we should make absolutely sure that the distance is smaller than rcut[it]
// we should make absolutely sure that the distance is smaller than GlobalC::ORB.Phi[it].getRcut
// this should be consistant with LCAO_nnr::cal_nnrg function
// typical example : 7 Bohr cutoff Si orbital in 14 Bohr length of cell.
// distance = 7.0000000000000000
// rcut[it] = 7.0000000000000008
// GlobalC::ORB.Phi[it].getRcut = 7.0000000000000008
if(distance < rcut - 1.0e-15)
{
// assert( count < nad[iat] );
Expand All @@ -190,7 +190,7 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
if( count + 1 < nad[iat] )
{
find_R2st[iat][count+1] = find_R2st[iat][count]
+ ucell->atoms[T1].nw * ucell->atoms[T2].nw; //modified by zhengdy-soc
+ GlobalC::ucell.atoms[T1].nw * GlobalC::ucell.atoms[T2].nw; //modified by zhengdy-soc
}
++count;
}
Expand All @@ -207,27 +207,27 @@ void Grid_Technique::cal_nnrg(Parallel_Orbitals* pv)
return;
}

void Grid_Technique::max_box_index(void)
void Grid_Technique::cal_max_box_index()
{
ModuleBase::TITLE("LCAO_nnr","max_box_index");
ModuleBase::TITLE("LCAO_nnr","cal_max_box_index");
this->maxB1 = this->maxB2 = this->maxB3 = -10000;
this->minB1 = this->minB2 = this->minB3 = 10000;
for (int T1 = 0; T1 < ucell->ntype; T1++)
for (int T1 = 0; T1 < GlobalC::ucell.ntype; T1++)
{
for (int I1 = 0; I1 < ucell->atoms[T1].na; I1++)
for (int I1 = 0; I1 < GlobalC::ucell.atoms[T1].na; I1++)
{
ModuleBase::Vector3<double> tau1 = ucell->atoms[T1].tau[I1];
//gd->Find_atom(tau1);
gd->Find_atom(*ucell, tau1, T1, I1);
for (int ad = 0; ad < gd->getAdjacentNum()+1; ad++)
ModuleBase::Vector3<double> tau1 = GlobalC::ucell.atoms[T1].tau[I1];
//GlobalC::GridD.Find_atom(tau1);
GlobalC::GridD.Find_atom(GlobalC::ucell, tau1, T1, I1);
for (int ad = 0; ad < GlobalC::GridD.getAdjacentNum()+1; ad++)
{
this->maxB1 = std::max( gd->getBox(ad).x, maxB1 );
this->maxB2 = std::max( gd->getBox(ad).y, maxB2 );
this->maxB3 = std::max( gd->getBox(ad).z, maxB3 );
this->maxB1 = std::max( GlobalC::GridD.getBox(ad).x, maxB1 );
this->maxB2 = std::max( GlobalC::GridD.getBox(ad).y, maxB2 );
this->maxB3 = std::max( GlobalC::GridD.getBox(ad).z, maxB3 );

this->minB1 = std::min( gd->getBox(ad).x, minB1 );
this->minB2 = std::min( gd->getBox(ad).y, minB2 );
this->minB3 = std::min( gd->getBox(ad).z, minB3 );
this->minB1 = std::min( GlobalC::GridD.getBox(ad).x, minB1 );
this->minB2 = std::min( GlobalC::GridD.getBox(ad).y, minB2 );
this->minB3 = std::min( GlobalC::GridD.getBox(ad).z, minB3 );
}
}
}
Expand Down Expand Up @@ -261,10 +261,10 @@ int Grid_Technique::cal_RindexAtom(const int &u1, const int &u2, const int &u3,
assert(x2>=0);
assert(x3>=0);

return (iat2 + (x3 + x2 * this->nB3 + x1 * this->nB2 * this->nB3) * ucell->nat);
return (iat2 + (x3 + x2 * this->nB3 + x1 * this->nB2 * this->nB3) * GlobalC::ucell.nat);
}

int Grid_Technique::bsf_R2_offset(int val, int iat) const
int Grid_Technique::binary_search_find_R2_offset(int val, int iat) const
{
auto findR2 = this->find_R2[iat];
auto findR2_index = this->find_R2_sorted_index[iat];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void Veff<OperatorLCAO<TK, TR>>::contributeHR()
}
}
}
this->GK->transfer_pvpR(this->hR,this->ucell);
this->GK->transfer_pvpR(this->hR,this->ucell,this->gd);

if(this->nspin == 2) { this->current_spin = 1 - this->current_spin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
this->cal_type = calculation_type::lcao_gint;

this->initialize_HR(ucell_in, GridD_in);
GK_in->initialize_pvpR(*ucell_in);
GK_in->initialize_pvpR(*ucell_in, GridD_in);
}
/**
* @brief Construct a new Veff object for Gamma-only calculation
Expand All @@ -65,7 +65,7 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
this->cal_type = calculation_type::lcao_gint;
this->initialize_HR(ucell_in, GridD_in);

GG_in->initialize_pvpR(*ucell_in);
GG_in->initialize_pvpR(*ucell_in, GridD_in);
}

~Veff<OperatorLCAO<TK, TR>>(){};
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void sparse_format::cal_dH(const Parallel_Orbitals& pv,
delete[] fsr_dh.DHloc_fixedR_z;

gint_k
.dvlocal_R_smat(current_spin, sparse_thr, HS_Arrays, &pv, GlobalC::ucell);
.cal_dvlocal_R_sparseMatrix(current_spin, sparse_thr, HS_Arrays, &pv, GlobalC::ucell, GlobalC::GridD);

return;
}
Expand Down
1 change: 0 additions & 1 deletion source/module_hamilt_lcao/module_gint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ list(APPEND objects
mult_psi_dm_new.cpp
mult_psi_dmr.cpp
init_orb.cpp
cal_nnrg.cpp
)

if(USE_CUDA)
Expand Down
Loading

0 comments on commit 5e0406f

Please sign in to comment.