Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 0 additions & 215 deletions source/source_hamilt/module_gint/gint_dvlocal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <map>
#include "gint_dvlocal.h"
#include "phi_operator.h"
#include "source_base/parallel_reduce.h"

namespace ModuleGint
{
Expand Down Expand Up @@ -58,217 +56,4 @@ void Gint_dvlocal::cal_hr_gint_()
}
}

void Gint_dvlocal::cal_dvlocal_R_sparse(
const int nspin,
const int cspin,
const int nlocal,
const double sparse_thr,
const Parallel_Orbitals& pv,
const UnitCell& ucell,
const Grid_Driver& gdriver,
LCAO_HS_Arrays& hs_arrays)
{
ModuleBase::TITLE("Gint", "cal_dvlocal_R_sparse");
ModuleBase::timer::start("Gint", "cal_dvlocal_R_sparse");
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, double>>> pvdpRx_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, double>>> pvdpRy_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, double>>> pvdpRz_sparse;

double tmp_d = 0.0;

Vec3d tau1, dtau;
for (int iap = 0; iap < pvdpRx.size_atom_pairs(); iap++)
{
const auto& ap = pvdpRx.get_atom_pair(iap);
const int iat1 = ap.get_atom_i();
const int iat2 = ap.get_atom_j();
const int it1 = ucell.iat2it[iat1];
const int it2 = ucell.iat2it[iat2];
const Atom* atom1 = &ucell.atoms[it1];
const Atom* atom2 = &ucell.atoms[it2];
const int start1 = ucell.itiaiw2iwt(it1, ucell.iat2ia[iat1], 0);
const int start2 = ucell.itiaiw2iwt(it2, ucell.iat2ia[iat2], 0);

for (int ir = 0; ir < ap.get_R_size(); ir++)
{
const ModuleBase::Vector3<int> R = ap.get_R_index(ir);
Abfs::Vector3_Order<int> dR(R.x, R.y, R.z);
double* p_pvdpRx = pvdpRx.get_atom_pair(iap).get_pointer(ir);
double* p_pvdpRy = pvdpRy.get_atom_pair(iap).get_pointer(ir);
double* p_pvdpRz = pvdpRz.get_atom_pair(iap).get_pointer(ir);

for (int iw = 0; iw < atom1->nw * npol_; iw++)
{
for (int iw2 = 0; iw2 < atom2->nw * npol_; iw2++)
{
const int nw = atom2->nw;
const int mug0 = iw / npol_;
const int nug0 = iw2 / npol_;
const int iw_nowg = mug0 * nw + nug0;

double temp_value = p_pvdpRx[iw_nowg];
if (std::abs(temp_value) > sparse_thr)
{
pvdpRx_sparse[dR][start1 + iw][start2 + iw2] = temp_value;
}
temp_value = p_pvdpRy[iw_nowg];
if (std::abs(temp_value) > sparse_thr)
{
pvdpRy_sparse[dR][start1 + iw][start2 + iw2] = temp_value;
}
temp_value = p_pvdpRz[iw_nowg];
if (std::abs(temp_value) > sparse_thr)
{
pvdpRz_sparse[dR][start1 + iw][start2 + iw2] = temp_value;
}
}
}
}
}
distribute_pvdpR_sparse(cspin, 0, nlocal, sparse_thr, pvdpRx_sparse, pv, hs_arrays);
distribute_pvdpR_sparse(cspin, 1, nlocal, sparse_thr, pvdpRy_sparse, pv, hs_arrays);
distribute_pvdpR_sparse(cspin, 2, nlocal, sparse_thr, pvdpRz_sparse, pv, hs_arrays);
ModuleBase::timer::end("Gint", "cal_dvlocal_R_sparse");
}


void Gint_dvlocal::distribute_pvdpR_sparse(
const int cspin,
const int dim,
const int nlocal,
const double sparse_thr,
const std::map<Abfs::Vector3_Order<int>,
std::map<size_t, std::map<size_t, double>>>&
pvdpR_sparse,
const Parallel_Orbitals& pv,
LCAO_HS_Arrays& hs_arrays)
{
int total_R_num = hs_arrays.all_R_coor.size();
std::vector<int> nonzero_num(total_R_num);
std::vector<int> minus_nonzero_num(total_R_num);
int count = 0;
for (const auto& R_coor: hs_arrays.all_R_coor)
{
auto iter = pvdpR_sparse.find(R_coor);
if (iter != pvdpR_sparse.end())
{
for (auto& row_loop: iter->second)
{
nonzero_num[count] += row_loop.second.size();
}
}

auto minus_R_coor = -1 * R_coor;

iter = pvdpR_sparse.find(minus_R_coor);
if (iter != pvdpR_sparse.end())
{
for (auto& row_loop: iter->second)
{
minus_nonzero_num[count] += row_loop.second.size();
}
}
count++;
}

Parallel_Reduce::reduce_all(nonzero_num.data(), total_R_num);
Parallel_Reduce::reduce_all(minus_nonzero_num.data(), total_R_num);

std::vector<double> tmp(nlocal);
count = 0;

const std::vector<int>& trace_lo = gint_info_->get_trace_lo();
for (const auto& R_coor: hs_arrays.all_R_coor)
{
if (nonzero_num[count] != 0 || minus_nonzero_num[count] != 0)
{
auto minus_R_coor = -1 * R_coor;

for (int row = 0; row < nlocal; ++row)
{
tmp.assign(tmp.size(), 0);

auto iter = pvdpR_sparse.find(R_coor);
if (iter != pvdpR_sparse.end())
{

if (trace_lo[row] >= 0)
{
auto row_iter = iter->second.find(row);
if (row_iter != iter->second.end())
{
for (auto& value: row_iter->second)
{
tmp[value.first] = value.second;
}
}
}
}

auto minus_R_iter = pvdpR_sparse.find(minus_R_coor);
if (minus_R_iter != pvdpR_sparse.end())
{
for (int col = 0; col < row; ++col)
{
if (trace_lo[col] >= 0)
{
auto row_iter = minus_R_iter->second.find(col);
if (row_iter != minus_R_iter->second.end())
{
auto col_iter = row_iter->second.find(row);
if (col_iter != row_iter->second.end())
{
tmp[col] = col_iter->second;
}
}
}
}
}

Parallel_Reduce::reduce_pool(tmp.data(), nlocal);

if (pv.global2local_row(row) >= 0)
{
for (int col = 0; col < nlocal; ++col)
{
if (pv.global2local_col(col) >= 0)
{
if (std::abs(tmp[col]) > sparse_thr)
{
if (dim == 0)
{
double& value = hs_arrays.dHRx_sparse[cspin][R_coor][row][col];
value += tmp[col];
if (std::abs(value) <= sparse_thr)
{
hs_arrays.dHRx_sparse[cspin][R_coor][row].erase(col);
}
}
if (dim == 1)
{
double& value = hs_arrays.dHRy_sparse[cspin][R_coor][row][col];
value += tmp[col];
if (std::abs(value) <= sparse_thr)
{
hs_arrays.dHRy_sparse[cspin][R_coor][row].erase(col);
}
}
if (dim == 2)
{
double& value = hs_arrays.dHRz_sparse[cspin][R_coor][row][col];
value += tmp[col];
if (std::abs(value) <= sparse_thr)
{
hs_arrays.dHRz_sparse[cspin][R_coor][row].erase(col);
}
}
}
}
}
}
}
}
count++;
}
}
}
23 changes: 0 additions & 23 deletions source/source_hamilt/module_gint/gint_dvlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <memory>
#include <vector>
#include "source_hamilt/module_hcontainer/hcontainer.h"
#include "source_lcao/lcao_hs_arrays.h"
#include "source_lcao/module_ri/abfs_vector3_order.h"
#include "gint.h"
#include "gint_info.h"

Expand All @@ -28,16 +26,6 @@ class Gint_dvlocal : public Gint

void cal_dvlocal();

void cal_dvlocal_R_sparse(
const int nspin,
const int cspin,
const int nlocal,
const double sparse_thr,
const Parallel_Orbitals& pv,
const UnitCell& ucell,
const Grid_Driver& gdriver,
LCAO_HS_Arrays& hs_arrays);

HContainer<double>* get_pvdpRx() { return &pvdpRx; }
HContainer<double>* get_pvdpRy() { return &pvdpRy; }
HContainer<double>* get_pvdpRz() { return &pvdpRz; }
Expand All @@ -47,17 +35,6 @@ class Gint_dvlocal : public Gint

void cal_hr_gint_();

void distribute_pvdpR_sparse(
const int cspin,
const int dim,
const int nlocal,
const double sparse_thr,
const std::map<Abfs::Vector3_Order<int>,
std::map<size_t, std::map<size_t, double>>>&
pvdpR_sparse,
const Parallel_Orbitals& pv,
LCAO_HS_Arrays& HS_Arrays);

// input
const double* vr_eff_ = nullptr;
int nspin_;
Expand Down
20 changes: 0 additions & 20 deletions source/source_hamilt/module_gint/gint_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "gint_rho.h"
#include "gint_drho.h"
#include "gint_tau.h"
#include "gint_dvlocal.h"

#ifdef __CUDA
#include "gint_vl_gpu.h"
Expand Down Expand Up @@ -191,23 +190,4 @@ void cal_gint_fvl_meta(
}
}

void cal_dvlocal_R_sparse(
const int nspin,
const int npol,
const int current_spin,
const int nlocal,
const double sparse_thr,
const double* vr_eff,
const Parallel_Orbitals& pv,
const UnitCell& ucell,
const Grid_Driver& gdriver,
LCAO_HS_Arrays& hs_arrays)
{
Gint_dvlocal gint_dvlocal(vr_eff, nspin, npol);
gint_dvlocal.cal_dvlocal();
gint_dvlocal.cal_dvlocal_R_sparse(
nspin, current_spin, nlocal, sparse_thr,
pv, ucell, gdriver, hs_arrays);
}

} // namespace ModuleGint
14 changes: 0 additions & 14 deletions source/source_hamilt/module_gint/gint_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class Parallel_Orbitals;
class UnitCell;
class Grid_Driver;
class LCAO_HS_Arrays;

namespace ModuleGint
{
Expand Down Expand Up @@ -71,19 +70,6 @@ void cal_gint_fvl_meta(
ModuleBase::matrix* fvl,
ModuleBase::matrix* svl);

void cal_dvlocal_R_sparse(
const int nspin,
const int npol,
const int current_spin,
const int nlocal,
const double sparse_thr,
const double* vr_eff,
const Parallel_Orbitals& pv,
const UnitCell& ucell,
const Grid_Driver& gdriver,
LCAO_HS_Arrays& hs_arrays);


} // namespace ModuleGint

#endif // ABACUS_SOURCE_HAMILT_MODULE_GINT_GINT_INTERFACE_H
2 changes: 1 addition & 1 deletion source/source_hamilt/module_vdw/vdwd2_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define VDWD2_PARAMETERS_H

#include "source_cell/unitcell.h"
#include "source_io/module_parameter/parameter.h"
#include "source_io/module_parameter/input_parameter.h"
#include "vdw_parameters.h"

#include <map>
Expand Down
2 changes: 1 addition & 1 deletion source/source_hamilt/module_xc/kernels/xc_functional_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define source_hamilt_MODULE_XC_KERNELS_H_

#include <complex>
#include <source_psi/psi.h>
#include <source_base/macros.h>
#include <source_base/module_device/types.h>

namespace hamilt {

Expand Down
Loading
Loading