Skip to content

Commit

Permalink
Refactor: remove dHRx_soc_sparse, dHRy_soc_sparse, `dHRz_soc_spar…
Browse files Browse the repository at this point in the history
…se` from LCAO_Matrix class. (deepmodeling#4486)

* delete unused folding_vl_k()

* delete unused set_HSK()

* move dHRx_soc_sparse/dHRy_soc_sparse/dHRz_soc_sparse outside LCAO_Matrix.h

* modify destroy_dH_R_sparse

* add LCAO_HS_Arrays into distribute_pvdpR_soc_sparseMatrix and cal_dvlocal_R_sparseMatrix

* add LCAO_HS_Arrays into cal_dH

* add LCAO_HS_Arrays into output_dHR

* [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
WHUweiqingzhou and pre-commit-ci-lite[bot] authored Jun 26, 2024
1 parent 4a8fdad commit 7795d7e
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 671 deletions.
11 changes: 8 additions & 3 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_HS_arrays.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef LCAO_HS_ARRAYS_H
#define LCAO_HS_ARRAYS_H

#include <vector>
#include "module_base/abfs-vector3_order.h"

#include <complex>
#include <vector>

class LCAO_HS_Arrays
{
public:

public:
LCAO_HS_Arrays(){};
~LCAO_HS_Arrays(){};

Expand All @@ -21,6 +22,10 @@ class LCAO_HS_Arrays
// SlocR -> Sloc2,
//------------------------------
std::vector<double> Hloc_fixedR;

std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRx_soc_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRy_soc_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRz_soc_sparse;
};

#endif
33 changes: 4 additions & 29 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,6 @@ void LCAO_Matrix::set_HSgamma(const int& iw1_all, const int& iw2_all, const doub
return;
}

void LCAO_Matrix::set_HSk(const int& iw1_all,
const int& iw2_all,
const std::complex<double>& v,
const char& dtype,
const int spin)
{
if (dtype == 'S') // overlap Hamiltonian.
{
LCAO_Matrix::set_mat2d<std::complex<double>>(iw1_all, iw2_all, v, *this->ParaV, this->Sloc2.data());
}
else if (dtype == 'T' || dtype == 'N') // kinetic and nonlocal Hamiltonian.
{
LCAO_Matrix::set_mat2d<std::complex<double>>(iw1_all, iw2_all, v, *this->ParaV, this->Hloc_fixed2.data());
}
else if (dtype == 'L') // Local potential Hamiltonian.
{
LCAO_Matrix::set_mat2d<std::complex<double>>(iw1_all, iw2_all, v, *this->ParaV, this->Hloc2.data());
}
else
{
ModuleBase::WARNING_QUIT("LCAO_Matrix", "set_HSk");
}
return;
}

void LCAO_Matrix::zeros_HSgamma(const char& mtype)
{
auto zeros_HSgamma_ker = [&](int num_threads, int thread_id) {
Expand Down Expand Up @@ -398,7 +373,7 @@ void LCAO_Matrix::destroy_T_R_sparse()
return;
}

void LCAO_Matrix::destroy_dH_R_sparse()
void LCAO_Matrix::destroy_dH_R_sparse(LCAO_HS_Arrays& HS_Arrays)
{
ModuleBase::TITLE("LCAO_Matrix", "destroy_dH_R_sparse");

Expand Down Expand Up @@ -427,9 +402,9 @@ void LCAO_Matrix::destroy_dH_R_sparse()
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>>
empty_dHRz_soc_sparse;

dHRx_soc_sparse.swap(empty_dHRx_soc_sparse);
dHRy_soc_sparse.swap(empty_dHRy_soc_sparse);
dHRz_soc_sparse.swap(empty_dHRz_soc_sparse);
HS_Arrays.dHRx_soc_sparse.swap(empty_dHRx_soc_sparse);
HS_Arrays.dHRy_soc_sparse.swap(empty_dHRy_soc_sparse);
HS_Arrays.dHRz_soc_sparse.swap(empty_dHRz_soc_sparse);
}

return;
Expand Down
13 changes: 2 additions & 11 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "module_base/global_variable.h"
#include "module_base/vector3.h"
#include "module_basis/module_ao/parallel_orbitals.h"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_HS_arrays.hpp"

// add by jingan for map<> in 2021-12-2, will be deleted in the future
#include "module_base/abfs-vector3_order.h"
Expand Down Expand Up @@ -90,10 +91,6 @@ class LCAO_Matrix
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> SR_soc_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> TR_soc_sparse;

std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRx_soc_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRy_soc_sparse;
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> dHRz_soc_sparse;

// Record all R direct coordinate information, even if HR or SR is a zero matrix
std::set<Abfs::Vector3_Order<int>> all_R_coor;

Expand All @@ -106,12 +103,6 @@ class LCAO_Matrix

void set_HSgamma(const int& iw1_all, const int& iw2_all, const double& v, double* HSloc);

void set_HSk(const int& iw1_all,
const int& iw2_all,
const std::complex<double>& v,
const char& dtype,
const int spin = 0);

void set_HR_tr(const int& Rx,
const int& Ry,
const int& Rz,
Expand Down Expand Up @@ -141,7 +132,7 @@ class LCAO_Matrix

void destroy_T_R_sparse(void);

void destroy_dH_R_sparse(void);
void destroy_dH_R_sparse(LCAO_HS_Arrays& HS_Arrays);
};

#include "LCAO_matrix.hpp"
Expand Down
4 changes: 3 additions & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"

void sparse_format::cal_dH(LCAO_Matrix& lm,
LCAO_HS_Arrays& HS_Arrays,
Grid_Driver& grid,
const TwoCenterBundle& two_center_bundle,
const int& current_spin,
Expand Down Expand Up @@ -72,7 +73,8 @@ void sparse_format::cal_dH(LCAO_Matrix& lm,
delete[] fsr_dh.DHloc_fixedR_y;
delete[] fsr_dh.DHloc_fixedR_z;

gint_k.cal_dvlocal_R_sparseMatrix(current_spin, sparse_thr, &lm, lm.ParaV, GlobalC::ucell, GlobalC::GridD);
gint_k
.cal_dvlocal_R_sparseMatrix(current_spin, sparse_thr, &lm, HS_Arrays, lm.ParaV, GlobalC::ucell, GlobalC::GridD);

return;
}
Expand Down
6 changes: 4 additions & 2 deletions source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#ifndef SPARSE_FORMAT_DH_H
#define SPARSE_FORMAT_DH_H
#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_SPAR_DH_H
#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_SPAR_DH_H

#include "module_cell/module_neighbor/sltk_atom_arrange.h"
#include "module_cell/module_neighbor/sltk_grid_driver.h"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_HS_arrays.hpp"
#include "module_hamilt_lcao/hamilt_lcaodft/force_stress_arrays.h"
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"

namespace sparse_format
{
void cal_dH(LCAO_Matrix& lm,
LCAO_HS_Arrays& HS_Arrays,
Grid_Driver& grid,
const TwoCenterBundle& two_center_bundle,
const int& current_spin,
Expand Down
14 changes: 3 additions & 11 deletions source/module_hamilt_lcao/module_gint/gint_k.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "grid_technique.h"
#include "module_basis/module_ao/ORB_atomic_lm.h"
#include "module_elecstate/module_charge/charge.h"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_HS_arrays.hpp"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h"

// add by jingan for map<> in 2021-12-2, will be deleted in the future
Expand Down Expand Up @@ -61,17 +62,6 @@ class Gint_k : public Gint
// destroy the temporary <phi_0 | V | dphi_R> matrix element.
void destroy_pvdpR();

// folding the < phi_0 | V | phi_R> matrix to
// <phi_0i | V | phi_0j>
// V is (Vl + Vh + Vxc) if no Vna is used,
// and is (Vna + delta_Vh + Vxc) if Vna is used.
void folding_vl_k(const int& ik,
LCAO_Matrix* LM,
Parallel_Orbitals* pv,
const std::vector<ModuleBase::Vector3<double>>& kvec_d,
const UnitCell& ucell,
Grid_Driver& gd);

/**
* @brief transfer pvpR to this->hRGint
* then pass this->hRGint to Veff<OperatorLCAO>::hR
Expand Down Expand Up @@ -134,11 +124,13 @@ class Gint_k : public Gint
const std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>>&
pvdpR_soc_sparseMatrix,
LCAO_Matrix* LM,
LCAO_HS_Arrays& HS_Arrays,
Parallel_Orbitals* pv);

void cal_dvlocal_R_sparseMatrix(const int& current_spin,
const double& sparse_threshold,
LCAO_Matrix* LM,
LCAO_HS_Arrays& HS_Arrays,
Parallel_Orbitals* pv,
UnitCell& ucell,
Grid_Driver& gdriver);
Expand Down
Loading

0 comments on commit 7795d7e

Please sign in to comment.