From 469cfb4b447a0664cb0cd1b242611890cbc6e412 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 27 Nov 2024 15:33:12 +0800 Subject: [PATCH 01/47] remove redundant parameters --- .../module_hamilt_lcao/module_gint/grid_technique.cpp | 11 +++++------ .../module_hamilt_lcao/module_gint/grid_technique.h | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index 009b13e7ad..5f2facd31d 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -114,7 +114,7 @@ void Grid_Technique::set_pbc_grid(const int& ncx_in, this->init_meshball(); - this->init_atoms_on_grid(ny, nplane, startz_current, ucell); + this->init_atoms_on_grid(ny, nplane, ucell); this->init_ijr_and_nnrg(ucell, gd); this->cal_trace_lo(ucell); @@ -129,8 +129,7 @@ void Grid_Technique::set_pbc_grid(const int& ncx_in, } void Grid_Technique::get_startind(const int& ny, - const int& nplane, - const int& startz_current) { + const int& nplane) { ModuleBase::TITLE("Grid_Technique", "get_startind"); assert(nbxx >= 0); @@ -155,7 +154,7 @@ void Grid_Technique::get_startind(const int& ny, ix = ibx * this->bx; iy = iby * this->by; - iz = (ibz + nbzp_start) * this->bz - startz_current; + iz = ibz * this->bz; int ind = iz + iy * nplane + ix * ny * nplane; @@ -170,12 +169,11 @@ void Grid_Technique::get_startind(const int& ny, // mohan add 2021-04-06 void Grid_Technique::init_atoms_on_grid(const int& ny, const int& nplane, - const int& startz_current, const UnitCell& ucell) { ModuleBase::TITLE("Grid_Technique", "init_atoms_on_grid"); assert(nbxx >= 0); - this->get_startind(ny, nplane, startz_current); + this->get_startind(ny, nplane); // (1) prepare data. // counting the number of atoms whose orbitals have @@ -438,6 +436,7 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, } } assert(count == total_atoms_on_grid); + printf("total_atoms_on_grid = %d\n", total_atoms_on_grid); return; } diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.h b/source/module_hamilt_lcao/module_gint/grid_technique.h index 6c3c26aba9..caa05cb310 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.h +++ b/source/module_hamilt_lcao/module_gint/grid_technique.h @@ -133,7 +133,6 @@ class Grid_Technique : public Grid_MeshBall { // atoms on meshball void init_atoms_on_grid(const int& ny, const int& nplane, - const int& startz_current, const UnitCell& ucell); void init_atoms_on_grid2(const int* index2normal, const UnitCell& ucell); // initialize the ijr_info and nnrg @@ -142,8 +141,7 @@ class Grid_Technique : public Grid_MeshBall { void cal_trace_lo(const UnitCell& ucell); void check_bigcell(int* ind_bigcell, char* bigcell_on_processor); void get_startind(const int& ny, - const int& nplane, - const int& startz_current); + const int& nplane); #if ((defined __CUDA) /* || (defined __ROCM) */) public: From 3a67b8fb8c3e8b3bacbf1410c7d5c159f84c8ed8 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sun, 1 Dec 2024 20:50:14 +0800 Subject: [PATCH 02/47] version 0.0 --- .../module_gint/biggrid_info.cpp | 48 ++++++ .../module_gint/biggrid_info.h | 107 ++++++++++++ .../module_gint/gint_helper.h | 28 ++++ .../module_gint/localcell_info.cpp | 79 +++++++++ .../module_gint/localcell_info.h | 106 ++++++++++++ .../module_gint/meshball_info.h | 14 ++ .../module_gint/meshgrid_info.h | 66 ++++++++ .../module_gint/unitcell_info.cpp | 79 +++++++++ .../module_gint/unitcell_info.h | 156 ++++++++++++++++++ 9 files changed, 683 insertions(+) create mode 100644 source/module_hamilt_lcao/module_gint/biggrid_info.cpp create mode 100644 source/module_hamilt_lcao/module_gint/biggrid_info.h create mode 100644 source/module_hamilt_lcao/module_gint/gint_helper.h create mode 100644 source/module_hamilt_lcao/module_gint/localcell_info.cpp create mode 100644 source/module_hamilt_lcao/module_gint/localcell_info.h create mode 100644 source/module_hamilt_lcao/module_gint/meshball_info.h create mode 100644 source/module_hamilt_lcao/module_gint/meshgrid_info.h create mode 100644 source/module_hamilt_lcao/module_gint/unitcell_info.cpp create mode 100644 source/module_hamilt_lcao/module_gint/unitcell_info.h diff --git a/source/module_hamilt_lcao/module_gint/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/biggrid_info.cpp new file mode 100644 index 0000000000..24d5745bf0 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/biggrid_info.cpp @@ -0,0 +1,48 @@ +#include "biggrid_info.h" +#include "gint_helper.h" + +namespace Gint +{ + +BigGridInfo::BigGridInfo( + const Vector3& biggrid_vec1, + const Vector3& biggrid_vec2, + const Vector3& biggrid_vec3, + const int nmx, const int nmy, const int nmz) + : biggrid_vec1_(biggrid_vec1), + biggrid_vec2_(biggrid_vec2), + biggrid_vec3_(biggrid_vec3), + nmx_(nmx), nmy_(nmy), nmz_(nmz), nmxyz_(nmx*nmy*nmz) + { + // initialize the biggrid_latvec0_ + biggrid_latvec0_.e11 = biggrid_vec1_.x; + biggrid_latvec0_.e12 = biggrid_vec1_.y; + biggrid_latvec0_.e13 = biggrid_vec1_.z; + + biggrid_latvec0_.e21 = biggrid_vec2_.x; + biggrid_latvec0_.e22 = biggrid_vec2_.y; + biggrid_latvec0_.e23 = biggrid_vec2_.z; + + biggrid_latvec0_.e31 = biggrid_vec3_.x; + biggrid_latvec0_.e32 = biggrid_vec3_.y; + biggrid_latvec0_.e33 = biggrid_vec3_.z; + + // initialize the GT matrix + biggrid_GT_ = biggrid_latvec0_.Inverse(); + + // initialize the meshgrid_info_ + meshgrid_info_ = std::make_shared( + biggrid_vec1_ / static_cast(nmx), + biggrid_vec2_ / static_cast(nmy), + biggrid_vec3_ / static_cast(nmz)); + + // initialize the meshgrid_coords_ + meshgrid_coords_.resize(nmxyz_); + for(int index_1d = 0; index_1d < nmxyz_; index_1d++) + { + meshgrid_coords_[index_1d] = + this->get_meshgrid_coord(index_1d); + } + } + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/biggrid_info.h b/source/module_hamilt_lcao/module_gint/biggrid_info.h new file mode 100644 index 0000000000..76cea8b213 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/biggrid_info.h @@ -0,0 +1,107 @@ +#ifndef BIGGIRD_INFO_H +#define BIGGIRD_INFO_H + +#include +#include "module_base/vector3.h" +#include "module_base/matrix3.h" +#include "meshgrid_info.h" + +namespace Gint +{ + +/** + * @class BigGridInfo + * @brief This class stores some basic properties common to all big grids. + */ +class BigGridInfo +{ + public: + // constructor + BigGridInfo( + const Vector3& biggrid_vec1, + const Vector3& biggrid_vec2, + const Vector3& biggrid_vec3, + const int nmx, const int nmy, const int nmz); + + // getter functions + const Vector3 &get_vec1() const { return biggrid_vec1_; }; + const Vector3 &get_vec2() const { return biggrid_vec2_; }; + const Vector3 &get_vec3() const { return biggrid_vec3_; }; + const Matrix3 &get_latvec0() const { return biggrid_latvec0_; }; + const Matrix3 &get_GT() const { return biggrid_GT_; }; + int get_nmx() const { return nmx_; }; + int get_nmy() const { return nmy_; }; + int get_nmz() const { return nmz_; }; + int get_nmxyz() const { return nmxyz_; }; + const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; + std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; + + // get the 3D index of a meshgrid in the big grid from the 1D index + ModuleBase::Vector3 meshgrid_idx_1Dto3D(int index_1d) const + { + return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + }; + + // get the 1D index of a meshgrid in the big grid from the 3D index + int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + }; + + // get the cartesian coordinate of a meshgrid in the big grid from the 3D index + Vector3 get_meshgrid_coord(ModuleBase::Vector3 index_3d) const + { + return index_3d * meshgrid_info_->get_latvec0(); + }; + + // get the cartesian coordinate of a meshgrid in the big grid from the 1D index + Vector3 get_meshgrid_coord(int index_1d) const + { + return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); + }; + + private: + // basis vectors of the big grid + Vector3 biggrid_vec1_; + Vector3 biggrid_vec2_; + Vector3 biggrid_vec3_; + + // used to convert the (i, j, k) index of the big grid to the Cartesian coordinate + // if biggrid_vec1_ is row vector, + // then biggrid_latvec0_ = [biggrid_vec1_; biggrid_vec2_; biggrid_vec3_], + // (i, j, k) * biggrid_latvec0_ = (x, y, z) + Matrix3 biggrid_latvec0_; + + // used to convert the Cartesian coordinate to the (i, j, k) index of the big grid + // biggrid_GT_ = biggrid_latvec0_.Inverse() + // (x, y, z) * biggrid_GT_ = (i, j, k) + Matrix3 biggrid_GT_; + + //------------------------------------------- + // some member variables related to meshgrid + //------------------------------------------- + + // basic attributes of meshgrid + std::shared_ptr meshgrid_info_; + + // the number of meshgrids of a biggrid along the first basis vector + // nmx may be a confusing name, because it is not the number of meshgrids along x axis + // but it's used in the original code, so I keep it, maybe it will be changed later + int nmx_; + + // the number of meshgrids of a biggrid along the second basis vector + int nmy_; + + // the number of meshgrids of a biggrid along the third basis vector + int nmz_; + + // total number of meshgrids in the biggrid + int nmxyz_; + + // store the relative Cartesian coordinates of all meshgrids in the biggrid + // the size of vector is nbxyz_ + std::vector meshgrid_coords_; +}; + +} +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/gint_helper.h b/source/module_hamilt_lcao/module_gint/gint_helper.h new file mode 100644 index 0000000000..c2e29c7365 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/gint_helper.h @@ -0,0 +1,28 @@ +#ifndef GINT_HELPER_H +#define GINT_HELPER_H + +#include "module_base/vector3.h" + +namespace Gint +{ + // Define the alias for the Vector3 and Matrix3 + using Vector3 = ModuleBase::Vector3; + using Matrix3 = ModuleBase::Matrix3; + + inline int index3Dto1D(const int id_x, const int id_y, const int id_z, + const int dim_x, const int dim_y, const int dim_z) + { + return id_z + id_y * dim_z + id_x * dim_y * dim_z; + }; + + inline ModuleBase::Vector3 index1Dto3D(const int index_1d, + const int dim_x, const int dim_y, const int dim_z) + { + int id_x = index_1d / (dim_y * dim_z); + int id_y = (index_1d - id_x * dim_y * dim_z) / dim_z; + int id_z = index_1d % dim_z; + return ModuleBase::Vector3(id_x, id_y, id_z); + }; +} + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/localcell_info.cpp new file mode 100644 index 0000000000..14267c5dbe --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/localcell_info.cpp @@ -0,0 +1,79 @@ +#include "localcell_info.h" + +namespace Gint +{ + LocalCellInfo::LocalCellInfo( + const int startind_bx, const int startind_by, const int startind_bz, + const int nbx, const int nby, const int nbz, + std::shared_ptr unitcell_info) + : startind_bx_(startind_bx), startind_by_(startind_by), startind_bz_(startind_bz), + nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), + unitcell_info_(unitcell_info) + { + startind_mx_ = startind_bx_ * unitcell_info_->get_biggrid_info()->get_nmx(); + startind_my_ = startind_by_ * unitcell_info_->get_biggrid_info()->get_nmy(); + startind_mz_ = startind_bz_ * unitcell_info_->get_biggrid_info()->get_nmz(); + nmx_ = nbx_ * unitcell_info_->get_biggrid_info()->get_nmx(); + nmy_ = nby_ * unitcell_info_->get_biggrid_info()->get_nmy(); + nmz_ = nbz_ * unitcell_info_->get_biggrid_info()->get_nmz(); + nmxyz_ = nmx_ * nmy_ * nmz_; + } + + //---------------------------------- + // functions related to the big grid + //---------------------------------- + + int LocalCellInfo::biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); + } + + ModuleBase::Vector3 LocalCellInfo::biggrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); + } + + ModuleBase::Vector3 LocalCellInfo::get_biggrid_global_idx(const ModuleBase::Vector3 index_3d) const + { + return ModuleBase::Vector3( + startind_bx_ + index_3d.x, + startind_by_ + index_3d.y, + startind_bz_ + index_3d.z); + } + + int LocalCellInfo::get_biggrid_global_idx(const int index_1d) const + { + ModuleBase::Vector3 global_idx_3d = get_biggrid_global_idx(biggrid_idx_1Dto3D(index_1d)); + return unitcell_info_->biggrid_idx_3Dto1D(global_idx_3d); + } + + //---------------------------------- + // functions related to the meshgrid + //---------------------------------- + + int LocalCellInfo::meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + } + + ModuleBase::Vector3 LocalCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + } + + ModuleBase::Vector3 LocalCellInfo::get_meshgrid_global_idx(const ModuleBase::Vector3 index_3d) const + { + return ModuleBase::Vector3( + startind_mx_ + index_3d.x, + startind_my_ + index_3d.y, + startind_mz_ + index_3d.z); + } + + int LocalCellInfo::get_meshgrid_global_idx(const int index_1d) const + { + ModuleBase::Vector3 global_idx_3d = get_meshgrid_global_idx(meshgrid_idx_1Dto3D(index_1d)); + return unitcell_info_->meshgrid_idx_3Dto1D(global_idx_3d); + } + + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/localcell_info.h b/source/module_hamilt_lcao/module_gint/localcell_info.h new file mode 100644 index 0000000000..392cca82fe --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/localcell_info.h @@ -0,0 +1,106 @@ +#ifndef LOCALCELL_INFO_H +#define LOCALCELL_INFO_H + +#include +#include "module_base/vector3.h" +#include "unitcell_info.h" + +namespace Gint +{ + +class LocalCellInfo +{ + public: + // constructor + LocalCellInfo( + const int startind_x, const int startind_y, const int startind_z, + const int nbx, const int nby, const int nbz, + std::shared_ptr unitcell_info); + + // getter functions + const int get_startind_bx() const { return startind_bx_; }; + const int get_startind_by() const { return startind_by_; }; + const int get_startind_bz() const { return startind_bz_; }; + const int get_nbx() const { return nbx_; }; + const int get_nby() const { return nby_; }; + const int get_nbz() const { return nbz_; }; + const int get_nbxyz() const { return nbxyz_; }; + std::shared_ptr get_unitcell_info() const { return unitcell_info_; }; + + //---------------------------------- + // functions related to the big grid + //---------------------------------- + + // transform the 3D index of a big grid in the local cell to the 3D index in the local cell + int biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const; + + // transform the 1D index of a big grid in the local cell to the 1D index in the local cell + ModuleBase::Vector3 biggrid_idx_1Dto3D(const int index_1d) const; + + // transform the 3D index of a big grid in the local cell to the 3D index in the unit cell + ModuleBase::Vector3 get_biggrid_global_idx(const ModuleBase::Vector3 index_3d) const; + + // transform the 1D index of a big grid in the local cell to the 1D index in the unit cell + int get_biggrid_global_idx(const int index_1d) const; + + + //----------------------------------- + // functions related to the meshgrid + //----------------------------------- + + // transform the 3D index of a meshgrid in the local cell to the 3D index in the local cell + int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const; + + // transform the 1D index of a meshgrid in the local cell to the 1D index in the local cell + ModuleBase::Vector3 meshgrid_idx_1Dto3D(const int index_1d) const; + + // transform the 3D index of a meshgrid in the local cell to the 3D index in the unit cell + ModuleBase::Vector3 get_meshgrid_global_idx(const ModuleBase::Vector3 index_3d) const; + + // transform the 1D index of a meshgrid in the local cell to the 1D index in the unit cell + int get_meshgrid_global_idx(const int index_1d) const; + + private: + //------------------------------- + // information about the big grid + //------------------------------- + + // 3D index of the first big grid in the local cell within the unit cell + int startind_bx_; + int startind_by_; + int startind_bz_; + + // Number of big grids in the local cell along the three basis vectors of the local cell + int nbx_; + int nby_; + int nbz_; + + // Total number of big grids in the local cell + int nbxyz_; + + //-------------------------------- + // information about the meshgrid + //-------------------------------- + + // 3D index of the first meshgrid in the local cell within the unit cell + int startind_mx_; + int startind_my_; + int startind_mz_; + + // Number of meshgrids in the local cell along the three basis vectors of the local cell + int nmx_; + int nmy_; + int nmz_; + + // Total number of meshgrids in the local cell + int nmxyz_; + + //-------------------------------- + // information about the Unitcell + //-------------------------------- + std::shared_ptr unitcell_info_; + +} + +} +#endif // LOCALCELL_INFO_H \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/meshball_info.h b/source/module_hamilt_lcao/module_gint/meshball_info.h new file mode 100644 index 0000000000..9411ab0b95 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/meshball_info.h @@ -0,0 +1,14 @@ +#ifndef MESHBALL_H +#define MESHBALL_H + +namespace Gint +{ + +class MeshBall +{ + private: +} + +} + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/meshgrid_info.h new file mode 100644 index 0000000000..342a2cee23 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/meshgrid_info.h @@ -0,0 +1,66 @@ +#ifndef MESH_GRID_INFO_H +#define MESH_GRID_INFO_H + +#include "module_base/vector3.h" +#include "module_base/matrix3.h" +#include "module_cell/unitcell.h" + +namespace Gint +{ + +class MeshGridInfo +{ + public: + // constructor + MeshGridInfo( + const Vector3& meshgrid_vec1, + const Vector3& meshgrid_vec2, + const Vector3& meshgrid_vec3) + : meshgrid_vec1_(meshgrid_vec1), + meshgrid_vec2_(meshgrid_vec2), + meshgrid_vec3_(meshgrid_vec3) + { + // initialize the meshgrid_latvec0_ + meshgrid_latvec0_.e11 = meshgrid_vec1_.x; + meshgrid_latvec0_.e12 = meshgrid_vec1_.y; + meshgrid_latvec0_.e13 = meshgrid_vec1_.z; + + meshgrid_latvec0_.e21 = meshgrid_vec2_.x; + meshgrid_latvec0_.e22 = meshgrid_vec2_.y; + meshgrid_latvec0_.e23 = meshgrid_vec2_.z; + + meshgrid_latvec0_.e31 = meshgrid_vec3_.x; + meshgrid_latvec0_.e32 = meshgrid_vec3_.y; + meshgrid_latvec0_.e33 = meshgrid_vec3_.z; + + // initialize the GT matrix + meshgrid_GT_ = meshgrid_latvec0_.Inverse(); + }; + + // getter functions + const Vector3 &get_vec1() const { return meshgrid_vec1_; }; + const Vector3 &get_vec2() const { return meshgrid_vec2_; }; + const Vector3 &get_vec3() const { return meshgrid_vec3_; }; + const Matrix3 &get_latvec0() const { return meshgrid_latvec0_; }; + const Matrix3 &get_GT() const { return meshgrid_GT_; }; + + private: + // basis vectors of meshgrid + Vector3 meshgrid_vec1_; + Vector3 meshgrid_vec2_; + Vector3 meshgrid_vec3_; + + // used to convert the (i, j, k) index of the meshgrid to the Cartesian coordinate + // if meshrid_vec1_ is row vector, + // then meshgrid_latvec0_ = [meshgrid_vec1_; meshgrid_vec2_; meshgrid_vec3_], + // (i, j, k) * meshgrid_latvec0_ = (x, y, z) + Matrix3 meshgrid_latvec0_; + + // used to convert the Cartesian coordinate to the (i, j, k) index of the mesh grid + // meshgrid_GT_ = meshgrid_latvec0_.Inverse() + // (x, y, z) * meshgrid_GT_ = (i, j, k) + Matrix3 meshgrid_GT_; +}; + +} +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/unitcell_info.cpp new file mode 100644 index 0000000000..7513edb9b0 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/unitcell_info.cpp @@ -0,0 +1,79 @@ +#include "unitcell_info.h" +#include "gint_helper.h" + +namespace Gint +{ + UnitCellInfo::UnitCellInfo( + const Vector3& unitcell_vec1, + const Vector3& unitcell_vec2, + const Vector3& unitcell_vec3, + const int nbx, const int nby, const int nbz, + const int nmx, const int nmy, const int nmz) + : unitcell_vec1_(unitcell_vec1), + unitcell_vec2_(unitcell_vec2), + unitcell_vec3_(unitcell_vec3), + nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), + nmx_(nmx), nmy_(nmy), nmz_(nmz), nmxyz_(nmx*nmy*nmz) + { + // initialize the biggrid_info_ + biggrid_info_ = std::make_shared( + unitcell_vec1_ / static_cast(nbx), + unitcell_vec2_ / static_cast(nby), + unitcell_vec3_ / static_cast(nbz), + nmx/nbx, nmy/nby, nmz/nbz); + } + + //---------------------------------- + // functions related to the big grid + //---------------------------------- + + ModuleBase::Vector3 UnitCellInfo::biggrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); + } + + int UnitCellInfo::biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); + } + + Vector3 UnitCellInfo::get_biggrid_coord(ModuleBase::Vector3 index_3d) const + { + return index_3d * biggrid_info_->get_latvec0(); + } + + Vector3 UnitCellInfo::get_biggrid_coord(int index_1d) const + { + return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); + } + + Vector3 UnitCellInfo::get_relative_coord(int index_1d_a, int index_1d_b) const + { + return get_biggrid_coord(index_1d_a) - get_biggrid_coord(index_1d_b); + } + + //---------------------------------- + // functions related to the meshgrid + //---------------------------------- + + ModuleBase::Vector3 UnitCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + } + + int UnitCellInfo::meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + } + + Vector3 UnitCellInfo::get_meshgrid_coord(ModuleBase::Vector3 index_3d) const + { + return index_3d * biggrid_info_->get_meshgrid_info()->get_latvec0(); + } + + Vector3 UnitCellInfo::get_meshgrid_coord(int index_1d) const + { + return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); + } + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/unitcell_info.h b/source/module_hamilt_lcao/module_gint/unitcell_info.h new file mode 100644 index 0000000000..6f259ed73b --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/unitcell_info.h @@ -0,0 +1,156 @@ +#ifndef UNITCELL_INFO_H +#define UNITCELL_INFO_H + +#include +#include "module_base/vector3.h" +#include "module_base/matrix3.h" +#include "biggrid_info.h" +#include "gint_helper.h" + +namespace Gint +{ + +class UnitCellInfo +{ + public: + // constructor + UnitCellInfo( + const Vector3& unitcell_vec1, + const Vector3& unitcell_vec2, + const Vector3& unitcell_vec3, + const int nbx, const int nby, const int nbz, + const int nmx, const int nmy, const int nmz); + + // getter functions + const Vector3 &get_vec1() const { return unitcell_vec1_; }; + const Vector3 &get_vec2() const { return unitcell_vec2_; }; + const Vector3 &get_vec3() const { return unitcell_vec3_; }; + int get_nbx() const { return nbx_; }; + int get_nby() const { return nby_; }; + int get_nbz() const { return nbz_; }; + int get_nbxyz() const { return nbxyz_; }; + + // get the number of meshcells along the first lattice vector of the unit cell + int get_nmx() const { return nbx_ * biggrid_info_->get_nmx(); }; + + // get the number of meshcells along the second lattice vector of the unit cell + int get_nmy() const { return nby_ * biggrid_info_->get_nmy(); }; + + // get the number of meshcells along the third lattice vector of the unit cell + int get_nmz() const { return nbz_ * biggrid_info_->get_nmz(); }; + + // get the total number of meshcells in the unit cell + int get_nmxyz() const { return nbxyz_ * biggrid_info_->get_nmxyz(); }; + + std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; + std::shared_ptr get_meshgrid_info() const { return biggrid_info_->get_meshgrid_info(); }; + + //---------------------------------- + // functions related to the big grid + //---------------------------------- + + // transform the 1D index of a big grid in the unit cell to the 3D index + ModuleBase::Vector3 biggrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); + }; + + // transform the 3D index of a biggrid in the unit cell to the 1D index + int biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); + }; + + // get the cartesian coordinate of a big grid in the unit cell from the 3D index + Vector3 get_biggrid_coord(ModuleBase::Vector3 index_3d) const + { + return index_3d * biggrid_info_->get_latvec0(); + }; + + // get the cartesian coordinate of a big grid in the unit cell from the 1D index + Vector3 get_biggrid_coord(int index_1d) const + { + return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); + }; + + // Get the relative Cartesian coordinates of big grid A relative to big grid B + // returned vector = coordinates of point A - coordinates of point B + Vector3 get_relative_coord(int index_1d_a, int index_1d_b) const + { + return get_biggrid_coord(index_1d_a) - get_biggrid_coord(index_1d_b); + }; + + //---------------------------------- + // functions related to the meshgrid + //---------------------------------- + + // transform the 1D index of a meshgrid in the unit cell to the 3D index + ModuleBase::Vector3 meshgrid_idx_1Dto3D(const int index_1d) const + { + return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + } + + // transform the 3D index of a meshgrid in the unit cell to the 1D index + int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + { + return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + } + + // get the cartesian coordinate of a meshgrid in the unit cell from the 3D index + Vector3 get_meshgrid_coord(ModuleBase::Vector3 index_3d) const + { + return index_3d * biggrid_info_->get_meshgrid_info()->get_latvec0(); + }; + + // get the cartesian coordinate of a meshgrid in the unit cell from the 1D index + Vector3 get_meshgrid_coord(int index_1d) const + { + return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); + } + + private: + // basis vectors of the unit cell + Vector3 unitcell_vec1_; + Vector3 unitcell_vec2_; + Vector3 unitcell_vec3_; + + //---------------------------------------------- + // member variables related to the Big Grid + //---------------------------------------------- + + // the number of big cells along the first lattice vector + int nbx_; + + // the number of big cells along the second lattice vector + int nby_; + + // the number of big cells along the third lattice vector + int nbz_; + + // the total number of big cells + int nbxyz_; + + // basic attributes of the big grid + std::shared_ptr biggrid_info_; + + //------------------------------------------- + // member variables related to meshgrid + //------------------------------------------- + + // the number of meshgrids along the first lattice vector + int nmx_; + + // the number of meshgrids along the second lattice vector + int nmy_; + + // the number of meshgrids along the third lattice vector + int nmz_; + + // the total number of meshgrids in the unitcell + int nmxyz_; + +} + +} + +#endif \ No newline at end of file From df7306542b2628fdc175c218684506142776c118 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sun, 1 Dec 2024 20:51:01 +0800 Subject: [PATCH 03/47] inline some simple functions --- .../module_gint/unitcell_info.cpp | 54 +------------------ 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/unitcell_info.cpp index 7513edb9b0..c97e709e72 100644 --- a/source/module_hamilt_lcao/module_gint/unitcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/unitcell_info.cpp @@ -3,6 +3,7 @@ namespace Gint { + UnitCellInfo::UnitCellInfo( const Vector3& unitcell_vec1, const Vector3& unitcell_vec2, @@ -23,57 +24,4 @@ namespace Gint nmx/nbx, nmy/nby, nmz/nbz); } - //---------------------------------- - // functions related to the big grid - //---------------------------------- - - ModuleBase::Vector3 UnitCellInfo::biggrid_idx_1Dto3D(const int index_1d) const - { - return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); - } - - int UnitCellInfo::biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const - { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); - } - - Vector3 UnitCellInfo::get_biggrid_coord(ModuleBase::Vector3 index_3d) const - { - return index_3d * biggrid_info_->get_latvec0(); - } - - Vector3 UnitCellInfo::get_biggrid_coord(int index_1d) const - { - return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); - } - - Vector3 UnitCellInfo::get_relative_coord(int index_1d_a, int index_1d_b) const - { - return get_biggrid_coord(index_1d_a) - get_biggrid_coord(index_1d_b); - } - - //---------------------------------- - // functions related to the meshgrid - //---------------------------------- - - ModuleBase::Vector3 UnitCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const - { - return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); - } - - int UnitCellInfo::meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const - { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); - } - - Vector3 UnitCellInfo::get_meshgrid_coord(ModuleBase::Vector3 index_3d) const - { - return index_3d * biggrid_info_->get_meshgrid_info()->get_latvec0(); - } - - Vector3 UnitCellInfo::get_meshgrid_coord(int index_1d) const - { - return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); - } - } \ No newline at end of file From c681070dcb6a73b5e701b503ee80d7f91b791238 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 2 Dec 2024 16:41:29 +0800 Subject: [PATCH 04/47] change type alias --- .../module_gint/meshball_info.h | 14 ------- .../{ => new_grid_tech}/biggrid_info.cpp | 6 +-- .../{ => new_grid_tech}/biggrid_info.h | 30 +++++++-------- .../{ => new_grid_tech}/gint_helper.h | 9 +++-- .../{ => new_grid_tech}/localcell_info.cpp | 28 +++++++------- .../{ => new_grid_tech}/localcell_info.h | 16 ++++---- .../{ => new_grid_tech}/meshgrid_info.h | 18 ++++----- .../new_grid_tech/unitcell_info.cpp | 27 +++++++++++++ .../{ => new_grid_tech}/unitcell_info.h | 38 +++++++++---------- .../module_gint/unitcell_info.cpp | 27 ------------- 10 files changed, 100 insertions(+), 113 deletions(-) delete mode 100644 source/module_hamilt_lcao/module_gint/meshball_info.h rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/biggrid_info.cpp (93%) rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/biggrid_info.h (78%) rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/gint_helper.h (68%) rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/localcell_info.cpp (62%) rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/localcell_info.h (83%) rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/meshgrid_info.h (81%) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp rename source/module_hamilt_lcao/module_gint/{ => new_grid_tech}/unitcell_info.h (79%) delete mode 100644 source/module_hamilt_lcao/module_gint/unitcell_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/meshball_info.h b/source/module_hamilt_lcao/module_gint/meshball_info.h deleted file mode 100644 index 9411ab0b95..0000000000 --- a/source/module_hamilt_lcao/module_gint/meshball_info.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MESHBALL_H -#define MESHBALL_H - -namespace Gint -{ - -class MeshBall -{ - private: -} - -} - -#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp similarity index 93% rename from source/module_hamilt_lcao/module_gint/biggrid_info.cpp rename to source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index 24d5745bf0..ce2a65dddc 100644 --- a/source/module_hamilt_lcao/module_gint/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -5,9 +5,9 @@ namespace Gint { BigGridInfo::BigGridInfo( - const Vector3& biggrid_vec1, - const Vector3& biggrid_vec2, - const Vector3& biggrid_vec3, + const Vec3d& biggrid_vec1, + const Vec3d& biggrid_vec2, + const Vec3d& biggrid_vec3, const int nmx, const int nmy, const int nmz) : biggrid_vec1_(biggrid_vec1), biggrid_vec2_(biggrid_vec2), diff --git a/source/module_hamilt_lcao/module_gint/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h similarity index 78% rename from source/module_hamilt_lcao/module_gint/biggrid_info.h rename to source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index 76cea8b213..c3479786b5 100644 --- a/source/module_hamilt_lcao/module_gint/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -18,53 +18,53 @@ class BigGridInfo public: // constructor BigGridInfo( - const Vector3& biggrid_vec1, - const Vector3& biggrid_vec2, - const Vector3& biggrid_vec3, + const Vec3d& biggrid_vec1, + const Vec3d& biggrid_vec2, + const Vec3d& biggrid_vec3, const int nmx, const int nmy, const int nmz); // getter functions - const Vector3 &get_vec1() const { return biggrid_vec1_; }; - const Vector3 &get_vec2() const { return biggrid_vec2_; }; - const Vector3 &get_vec3() const { return biggrid_vec3_; }; + const Vec3d &get_vec1() const { return biggrid_vec1_; }; + const Vec3d &get_vec2() const { return biggrid_vec2_; }; + const Vec3d &get_vec3() const { return biggrid_vec3_; }; const Matrix3 &get_latvec0() const { return biggrid_latvec0_; }; const Matrix3 &get_GT() const { return biggrid_GT_; }; int get_nmx() const { return nmx_; }; int get_nmy() const { return nmy_; }; int get_nmz() const { return nmz_; }; int get_nmxyz() const { return nmxyz_; }; - const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; + const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; // get the 3D index of a meshgrid in the big grid from the 1D index - ModuleBase::Vector3 meshgrid_idx_1Dto3D(int index_1d) const + Vec3i meshgrid_idx_1Dto3D(int index_1d) const { return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); }; // get the 1D index of a meshgrid in the big grid from the 3D index - int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + int meshgrid_idx_3Dto1D(const Vec3i index_3d) const { return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); }; // get the cartesian coordinate of a meshgrid in the big grid from the 3D index - Vector3 get_meshgrid_coord(ModuleBase::Vector3 index_3d) const + Vec3d get_meshgrid_coord(Vec3i index_3d) const { return index_3d * meshgrid_info_->get_latvec0(); }; // get the cartesian coordinate of a meshgrid in the big grid from the 1D index - Vector3 get_meshgrid_coord(int index_1d) const + Vec3d get_meshgrid_coord(int index_1d) const { return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); }; private: // basis vectors of the big grid - Vector3 biggrid_vec1_; - Vector3 biggrid_vec2_; - Vector3 biggrid_vec3_; + Vec3d biggrid_vec1_; + Vec3d biggrid_vec2_; + Vec3d biggrid_vec3_; // used to convert the (i, j, k) index of the big grid to the Cartesian coordinate // if biggrid_vec1_ is row vector, @@ -100,7 +100,7 @@ class BigGridInfo // store the relative Cartesian coordinates of all meshgrids in the biggrid // the size of vector is nbxyz_ - std::vector meshgrid_coords_; + std::vector meshgrid_coords_; }; } diff --git a/source/module_hamilt_lcao/module_gint/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h similarity index 68% rename from source/module_hamilt_lcao/module_gint/gint_helper.h rename to source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index c2e29c7365..db49c0ba8e 100644 --- a/source/module_hamilt_lcao/module_gint/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -6,8 +6,9 @@ namespace Gint { // Define the alias for the Vector3 and Matrix3 - using Vector3 = ModuleBase::Vector3; using Matrix3 = ModuleBase::Matrix3; + using Vec3d = ModuleBase::Vector3; + using Vec3i = ModuleBase::Vector3; inline int index3Dto1D(const int id_x, const int id_y, const int id_z, const int dim_x, const int dim_y, const int dim_z) @@ -15,13 +16,13 @@ namespace Gint return id_z + id_y * dim_z + id_x * dim_y * dim_z; }; - inline ModuleBase::Vector3 index1Dto3D(const int index_1d, - const int dim_x, const int dim_y, const int dim_z) + inline Vec3i index1Dto3D(const int index_1d, + const int dim_x, const int dim_y, const int dim_z) { int id_x = index_1d / (dim_y * dim_z); int id_y = (index_1d - id_x * dim_y * dim_z) / dim_z; int id_z = index_1d % dim_z; - return ModuleBase::Vector3(id_x, id_y, id_z); + return Vec3i(id_x, id_y, id_z); }; } diff --git a/source/module_hamilt_lcao/module_gint/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp similarity index 62% rename from source/module_hamilt_lcao/module_gint/localcell_info.cpp rename to source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index 14267c5dbe..a86f297bf9 100644 --- a/source/module_hamilt_lcao/module_gint/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -23,56 +23,56 @@ namespace Gint // functions related to the big grid //---------------------------------- - int LocalCellInfo::biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + int LocalCellInfo::biggrid_idx_3Dto1D(const Vec3i index_3d) const { return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); } - ModuleBase::Vector3 LocalCellInfo::biggrid_idx_1Dto3D(const int index_1d) const + Vec3i LocalCellInfo::biggrid_idx_1Dto3D(const int index_1d) const { return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); } - ModuleBase::Vector3 LocalCellInfo::get_biggrid_global_idx(const ModuleBase::Vector3 index_3d) const + Vec3i LocalCellInfo::get_biggrid_ucell_idx(const Vec3i index_3d) const { - return ModuleBase::Vector3( + return Vec3i( startind_bx_ + index_3d.x, startind_by_ + index_3d.y, startind_bz_ + index_3d.z); } - int LocalCellInfo::get_biggrid_global_idx(const int index_1d) const + int LocalCellInfo::get_biggrid_ucell_idx(const int index_1d) const { - ModuleBase::Vector3 global_idx_3d = get_biggrid_global_idx(biggrid_idx_1Dto3D(index_1d)); - return unitcell_info_->biggrid_idx_3Dto1D(global_idx_3d); + Vec3i ucell_idx_3d = get_biggrid_ucell_idx(biggrid_idx_1Dto3D(index_1d)); + return unitcell_info_->biggrid_idx_3Dto1D(ucell_idx_3d); } //---------------------------------- // functions related to the meshgrid //---------------------------------- - int LocalCellInfo::meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + int LocalCellInfo::meshgrid_idx_3Dto1D(const Vec3i index_3d) const { return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } - ModuleBase::Vector3 LocalCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const + Vec3i LocalCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const { return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); } - ModuleBase::Vector3 LocalCellInfo::get_meshgrid_global_idx(const ModuleBase::Vector3 index_3d) const + Vec3i LocalCellInfo::get_meshgrid_ucell_idx(const Vec3i index_3d) const { - return ModuleBase::Vector3( + return Vec3i( startind_mx_ + index_3d.x, startind_my_ + index_3d.y, startind_mz_ + index_3d.z); } - int LocalCellInfo::get_meshgrid_global_idx(const int index_1d) const + int LocalCellInfo::get_meshgrid_ucell_idx(const int index_1d) const { - ModuleBase::Vector3 global_idx_3d = get_meshgrid_global_idx(meshgrid_idx_1Dto3D(index_1d)); - return unitcell_info_->meshgrid_idx_3Dto1D(global_idx_3d); + Vec3i ucell_idx_3d = get_meshgrid_ucell_idx(meshgrid_idx_1Dto3D(index_1d)); + return unitcell_info_->meshgrid_idx_3Dto1D(ucell_idx_3d); } diff --git a/source/module_hamilt_lcao/module_gint/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h similarity index 83% rename from source/module_hamilt_lcao/module_gint/localcell_info.h rename to source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 392cca82fe..e799ce36e1 100644 --- a/source/module_hamilt_lcao/module_gint/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -32,16 +32,16 @@ class LocalCellInfo //---------------------------------- // transform the 3D index of a big grid in the local cell to the 3D index in the local cell - int biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const; + int biggrid_idx_3Dto1D(const Vec3i index_3d) const; // transform the 1D index of a big grid in the local cell to the 1D index in the local cell - ModuleBase::Vector3 biggrid_idx_1Dto3D(const int index_1d) const; + Vec3i biggrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a big grid in the local cell to the 3D index in the unit cell - ModuleBase::Vector3 get_biggrid_global_idx(const ModuleBase::Vector3 index_3d) const; + Vec3i get_biggrid_ucell_idx(const Vec3i index_3d) const; // transform the 1D index of a big grid in the local cell to the 1D index in the unit cell - int get_biggrid_global_idx(const int index_1d) const; + int get_biggrid_ucell_idx(const int index_1d) const; //----------------------------------- @@ -49,16 +49,16 @@ class LocalCellInfo //----------------------------------- // transform the 3D index of a meshgrid in the local cell to the 3D index in the local cell - int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const; + int meshgrid_idx_3Dto1D(const Vec3i index_3d) const; // transform the 1D index of a meshgrid in the local cell to the 1D index in the local cell - ModuleBase::Vector3 meshgrid_idx_1Dto3D(const int index_1d) const; + Vec3i meshgrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a meshgrid in the local cell to the 3D index in the unit cell - ModuleBase::Vector3 get_meshgrid_global_idx(const ModuleBase::Vector3 index_3d) const; + Vec3i get_meshgrid_ucell_idx(const Vec3i index_3d) const; // transform the 1D index of a meshgrid in the local cell to the 1D index in the unit cell - int get_meshgrid_global_idx(const int index_1d) const; + int get_meshgrid_ucell_idx(const int index_1d) const; private: //------------------------------- diff --git a/source/module_hamilt_lcao/module_gint/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h similarity index 81% rename from source/module_hamilt_lcao/module_gint/meshgrid_info.h rename to source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index 342a2cee23..bcaea339ec 100644 --- a/source/module_hamilt_lcao/module_gint/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -13,9 +13,9 @@ class MeshGridInfo public: // constructor MeshGridInfo( - const Vector3& meshgrid_vec1, - const Vector3& meshgrid_vec2, - const Vector3& meshgrid_vec3) + const Vec3d& meshgrid_vec1, + const Vec3d& meshgrid_vec2, + const Vec3d& meshgrid_vec3) : meshgrid_vec1_(meshgrid_vec1), meshgrid_vec2_(meshgrid_vec2), meshgrid_vec3_(meshgrid_vec3) @@ -38,17 +38,17 @@ class MeshGridInfo }; // getter functions - const Vector3 &get_vec1() const { return meshgrid_vec1_; }; - const Vector3 &get_vec2() const { return meshgrid_vec2_; }; - const Vector3 &get_vec3() const { return meshgrid_vec3_; }; + const Vec3d &get_vec1() const { return meshgrid_vec1_; }; + const Vec3d &get_vec2() const { return meshgrid_vec2_; }; + const Vec3d &get_vec3() const { return meshgrid_vec3_; }; const Matrix3 &get_latvec0() const { return meshgrid_latvec0_; }; const Matrix3 &get_GT() const { return meshgrid_GT_; }; private: // basis vectors of meshgrid - Vector3 meshgrid_vec1_; - Vector3 meshgrid_vec2_; - Vector3 meshgrid_vec3_; + Vec3d meshgrid_vec1_; + Vec3d meshgrid_vec2_; + Vec3d meshgrid_vec3_; // used to convert the (i, j, k) index of the meshgrid to the Cartesian coordinate // if meshrid_vec1_ is row vector, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp new file mode 100644 index 0000000000..ad62eff103 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp @@ -0,0 +1,27 @@ +#include "unitcell_info.h" +#include "gint_helper.h" + +namespace Gint +{ + +UnitCellInfo::UnitCellInfo( + const Vec3d& unitcell_vec1, + const Vec3d& unitcell_vec2, + const Vec3d& unitcell_vec3, + const int nbx, const int nby, const int nbz, + const int nmx, const int nmy, const int nmz) + : unitcell_vec1_(unitcell_vec1), + unitcell_vec2_(unitcell_vec2), + unitcell_vec3_(unitcell_vec3), + nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), + nmx_(nmx), nmy_(nmy), nmz_(nmz), nmxyz_(nmx*nmy*nmz) + { + // initialize the biggrid_info_ + biggrid_info_ = std::make_shared( + unitcell_vec1_ / static_cast(nbx), + unitcell_vec2_ / static_cast(nby), + unitcell_vec3_ / static_cast(nbz), + nmx/nbx, nmy/nby, nmz/nbz); + } + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h similarity index 79% rename from source/module_hamilt_lcao/module_gint/unitcell_info.h rename to source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index 6f259ed73b..1fae657f87 100644 --- a/source/module_hamilt_lcao/module_gint/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -15,16 +15,16 @@ class UnitCellInfo public: // constructor UnitCellInfo( - const Vector3& unitcell_vec1, - const Vector3& unitcell_vec2, - const Vector3& unitcell_vec3, + const Vec3d& unitcell_vec1, + const Vec3d& unitcell_vec2, + const Vec3d& unitcell_vec3, const int nbx, const int nby, const int nbz, const int nmx, const int nmy, const int nmz); // getter functions - const Vector3 &get_vec1() const { return unitcell_vec1_; }; - const Vector3 &get_vec2() const { return unitcell_vec2_; }; - const Vector3 &get_vec3() const { return unitcell_vec3_; }; + const Vec3d &get_vec1() const { return unitcell_vec1_; }; + const Vec3d &get_vec2() const { return unitcell_vec2_; }; + const Vec3d &get_vec3() const { return unitcell_vec3_; }; int get_nbx() const { return nbx_; }; int get_nby() const { return nby_; }; int get_nbz() const { return nbz_; }; @@ -50,34 +50,34 @@ class UnitCellInfo //---------------------------------- // transform the 1D index of a big grid in the unit cell to the 3D index - ModuleBase::Vector3 biggrid_idx_1Dto3D(const int index_1d) const + Vec3i biggrid_idx_1Dto3D(const int index_1d) const { return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); }; // transform the 3D index of a biggrid in the unit cell to the 1D index - int biggrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + int biggrid_idx_3Dto1D(const Vec3i index_3d) const { return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); }; // get the cartesian coordinate of a big grid in the unit cell from the 3D index - Vector3 get_biggrid_coord(ModuleBase::Vector3 index_3d) const + Vec3d get_biggrid_coord(Vec3i index_3d) const { return index_3d * biggrid_info_->get_latvec0(); }; // get the cartesian coordinate of a big grid in the unit cell from the 1D index - Vector3 get_biggrid_coord(int index_1d) const + Vec3d get_biggrid_coord(int index_1d) const { return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); }; // Get the relative Cartesian coordinates of big grid A relative to big grid B // returned vector = coordinates of point A - coordinates of point B - Vector3 get_relative_coord(int index_1d_a, int index_1d_b) const + Vec3d get_relative_coord(Vec3i index_3d_a, Vec3i index_3d_b) const { - return get_biggrid_coord(index_1d_a) - get_biggrid_coord(index_1d_b); + return get_biggrid_coord(index_3d_a - index_3d_b); }; //---------------------------------- @@ -85,34 +85,34 @@ class UnitCellInfo //---------------------------------- // transform the 1D index of a meshgrid in the unit cell to the 3D index - ModuleBase::Vector3 meshgrid_idx_1Dto3D(const int index_1d) const + Vec3i meshgrid_idx_1Dto3D(const int index_1d) const { return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); } // transform the 3D index of a meshgrid in the unit cell to the 1D index - int meshgrid_idx_3Dto1D(const ModuleBase::Vector3 index_3d) const + int meshgrid_idx_3Dto1D(const Vec3i index_3d) const { return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } // get the cartesian coordinate of a meshgrid in the unit cell from the 3D index - Vector3 get_meshgrid_coord(ModuleBase::Vector3 index_3d) const + Vec3d get_meshgrid_coord(Vec3i index_3d) const { return index_3d * biggrid_info_->get_meshgrid_info()->get_latvec0(); }; // get the cartesian coordinate of a meshgrid in the unit cell from the 1D index - Vector3 get_meshgrid_coord(int index_1d) const + Vec3d get_meshgrid_coord(int index_1d) const { return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); } private: // basis vectors of the unit cell - Vector3 unitcell_vec1_; - Vector3 unitcell_vec2_; - Vector3 unitcell_vec3_; + Vec3d unitcell_vec1_; + Vec3d unitcell_vec2_; + Vec3d unitcell_vec3_; //---------------------------------------------- // member variables related to the Big Grid diff --git a/source/module_hamilt_lcao/module_gint/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/unitcell_info.cpp deleted file mode 100644 index c97e709e72..0000000000 --- a/source/module_hamilt_lcao/module_gint/unitcell_info.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "unitcell_info.h" -#include "gint_helper.h" - -namespace Gint -{ - - UnitCellInfo::UnitCellInfo( - const Vector3& unitcell_vec1, - const Vector3& unitcell_vec2, - const Vector3& unitcell_vec3, - const int nbx, const int nby, const int nbz, - const int nmx, const int nmy, const int nmz) - : unitcell_vec1_(unitcell_vec1), - unitcell_vec2_(unitcell_vec2), - unitcell_vec3_(unitcell_vec3), - nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), - nmx_(nmx), nmy_(nmy), nmz_(nmz), nmxyz_(nmx*nmy*nmz) - { - // initialize the biggrid_info_ - biggrid_info_ = std::make_shared( - unitcell_vec1_ / static_cast(nbx), - unitcell_vec2_ / static_cast(nby), - unitcell_vec3_ / static_cast(nbz), - nmx/nbx, nmy/nby, nmz/nbz); - } - -} \ No newline at end of file From 1b9477eaadc32ad636c3afb912404ecdafbfb995 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 11 Dec 2024 10:20:43 +0800 Subject: [PATCH 05/47] version 0.1 --- source/module_base/array_pool.h | 2 +- .../module_gint/gint_force_cpu_interface.cpp | 2 +- .../module_gint/new_grid_tech/biggrid.cpp | 130 +++++++++ .../module_gint/new_grid_tech/biggrid.h | 103 +++++++ .../new_grid_tech/biggrid_info.cpp | 9 +- .../module_gint/new_grid_tech/biggrid_info.h | 24 +- .../module_gint/new_grid_tech/divide_info.cpp | 24 ++ .../module_gint/new_grid_tech/divide_info.h | 54 ++++ .../module_gint/new_grid_tech/get_ddpsi.cpp | 270 ++++++++++++++++++ .../module_gint/new_grid_tech/gint_atom.cpp | 217 ++++++++++++++ .../module_gint/new_grid_tech/gint_atom.h | 113 ++++++++ .../module_gint/new_grid_tech/gint_helper.h | 38 ++- .../module_gint/new_grid_tech/gint_info.cpp | 123 ++++++++ .../module_gint/new_grid_tech/gint_info.h | 50 ++++ .../module_gint/new_grid_tech/gint_type.h | 8 + .../new_grid_tech/localcell_info.cpp | 90 ++++-- .../new_grid_tech/localcell_info.h | 82 +++--- .../module_gint/new_grid_tech/meshgrid_info.h | 15 +- .../new_grid_tech/psi_operator.cpp | 148 ++++++++++ .../module_gint/new_grid_tech/psi_operator.h | 72 +++++ .../new_grid_tech/unitcell_info.cpp | 10 +- .../module_gint/new_grid_tech/unitcell_info.h | 81 +++--- 22 files changed, 1527 insertions(+), 138 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h diff --git a/source/module_base/array_pool.h b/source/module_base/array_pool.h index 0d9d175c1d..68f7d7162f 100644 --- a/source/module_base/array_pool.h +++ b/source/module_base/array_pool.h @@ -40,7 +40,7 @@ namespace ModuleBase : nr(nr_in), nc(nc_in) { - this->ptr_1D = new T[nr * nc]; + this->ptr_1D = new T[nr * nc]{0}; this->ptr_2D = new T*[nr]; for (int ir = 0; ir < nr; ++ir) this->ptr_2D[ir] = &this->ptr_1D[ir * nc]; diff --git a/source/module_hamilt_lcao/module_gint/gint_force_cpu_interface.cpp b/source/module_hamilt_lcao/module_gint/gint_force_cpu_interface.cpp index 0222f0234b..0c08ac019f 100644 --- a/source/module_hamilt_lcao/module_gint/gint_force_cpu_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_force_cpu_interface.cpp @@ -107,7 +107,7 @@ void Gint::gint_kernel_force(Gint_inout* inout) { //do integration to get stress this-> cal_meshball_stress(na_grid, block_index.data(), psir_vlbr3_DM.get_ptr_1D(), - dpsirr_ylm.get_ptr_1D(), svl_dphi_thread); + dpsirr_ylm.get_ptr_1D(), svl_dphi_thread); } } #pragma omp critical(gint) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp new file mode 100644 index 0000000000..fcb51a5141 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -0,0 +1,130 @@ +#include "biggrid.h" + +namespace Gint +{ + +BigGrid::BigGrid(int idx, std::shared_ptr localcell_info) + : idx_(idx), localcell_info_(localcell_info), + unitcell_info_(localcell_info->get_unitcell_info()), + biggrid_info_(localcell_info_->get_biggrid_info()) {} + +void BigGrid::add_atom(std::shared_ptr atom) +{ + atoms_.push_back(atom); +} + +int BigGrid::get_mgrid_psi_len() const +{ + int len = 0; + for(const auto& atom : atoms_) + { + len += atom->get_nw(); + } + return len; +} + +std::vector BigGrid::get_atom_startidx() const +{ + std::vector startidx(atoms_.size()); + startidx[0] = 0; + for(int i = 1; i < atoms_.size(); ++i) + { + startidx[i] = startidx[i-1] + atoms_[i-1]->get_nw(); + } + return startidx; +} + +std::vector BigGrid::get_atom_psi_len() const +{ + std::vector psi_len(atoms_.size()); + for(int i = 0; i < atoms_.size(); ++i) + { + psi_len[i] = atoms_[i]->get_nw(); + } + return psi_len; +} + +std::vector BigGrid::get_mgrid_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const +{ + Vec3i this_bgrid_idx = localcell_info_->get_bgrid_global_idx_3D(idx_); + + // the relative coordinates of this big grid and the atom + Vec3d bgrid_relative_coords + = unitcell_info_->get_relative_coord(bgrid_idx, this_bgrid_idx) + tau_in_bgrid; + + std::vector coords(biggrid_info_->get_nmxyz()); + for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) + { + Vec3d mcell_coords = biggrid_info_->get_meshgrid_coord(im); + coords[im] = mcell_coords - bgrid_relative_coords; + } + return coords; +} + + +std::vector BigGrid::get_mgrid_coords(const GintAtom& atom) const +{ + return get_mgrid_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid()); +} + +std::vector> BigGrid::get_is_atom_on_mgrid() const +{ + std::vector> if_on_mcell; + for(const auto& atom : atoms_) + { + std::vector mcell_coords = get_mgrid_coords(*atom); + std::vector atom_if_on_mcell; + for(const auto& coord : mcell_coords) + { + coord.norm() < atom->get_rcut() ? atom_if_on_mcell.push_back(true) : atom_if_on_mcell.push_back(false); + } + if_on_mcell.push_back(atom_if_on_mcell); + } + return ; +} + +void BigGrid::get_psi(const std::vector coords, double * psi) const +{ + int psi_len = get_mgrid_psi_len(); + for(const auto& atom : atoms_) + { + atom->get_psi(coords, psi_len, psi); + psi += atom->get_nw(); + } +} + +void BigGrid::get_psi_dpsir( + const std::vector coords, + double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z) const +{ + int psi_len = get_mgrid_psi_len(); + for(const auto& atom : atoms_) + { + atom->get_psi_dpsir(coords, psi_len, psi, dpsi_x, dpsi_y, dpsi_z); + psi += atom->get_nw(); + dpsi_x += atom->get_nw(); + dpsi_y += atom->get_nw(); + dpsi_z += atom->get_nw(); + } +} + +void BigGrid::get_ddpsir( + const std::vector coords, + double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, + double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz) const +{ + int psi_len = get_mgrid_psi_len(); + for(const auto& atom : atoms_) + { + atom->get_ddpsir(coords, psi_len, ddpsi_xx, ddpsi_xy, ddpsi_xz, ddpsi_yy, ddpsi_yz, ddpsi_zz); + ddpsi_xx += atom->get_nw(); + ddpsi_xy += atom->get_nw(); + ddpsi_xz += atom->get_nw(); + ddpsi_yy += atom->get_nw(); + ddpsi_yz += atom->get_nw(); + ddpsi_zz += atom->get_nw(); + } +} + + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h new file mode 100644 index 0000000000..47e44696c0 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -0,0 +1,103 @@ +#pragma once + +#include +#include +#include "gint_type.h" +#include "biggrid_info.h" +#include "localcell_info.h" +#include "unitcell_info.h" +#include "gint_atom.h" + +namespace Gint +{ + +class BigGrid +{ + public: + // constructor + BigGrid(int idx, std::shared_ptr localcell_info); + + // getter functions + int get_idx() const { return idx_; }; + std::shared_ptr get_localcell_info() const { return localcell_info_; }; + std::shared_ptr get_unitcell_info() const {return unitcell_info_; }; + std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; + const std::vector>& get_atoms() const { return atoms_; }; + + // get the number of meshgrids in the big grid + int get_meshgrid_num() const { return biggrid_info_->get_nmxyz(); }; + + // get the number of atoms that can affect the big grid + int get_atom_num() const { return atoms_.size(); }; + + // add an atom to the big grid + void add_atom(std::shared_ptr atom); + + // get the total number of psi of a meshgrid + // return: (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + int get_mgrid_psi_len() const; + + // get the start index of the psi of each atom + // return: vector[i] = \sum_{j=0}^{i-1} atoms_[j]->nw + vector get_atom_startidx() const; + + // get the length of psi of each atom + vector get_atom_psi_len() const; + + /** + * @brief Get the coordinates of the meshgrids of the big grid relative to an atom + * + * @param bgrid_idx the 3D index of the big grid, which contains the atom, in the unitcell + * @param tau_in_bgrid the cartesian coordinate of the atom relative to the big grid containing it + */ + std::vector get_mgrid_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const; + + // get the coordinates of the meshgrids of the big grid relative to the atom + std::vector get_mgrid_coords(const GintAtom& atom) const; + + /** + * @brief Get a boolean array to indicate whether the atom affects the meshgrid + * + * @note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, + * it may only affect a part of them. + * + * @return a boolean array, the dimension of the array is atoms_->size() * biggrid_info_->get_nmxyz() + * array[i][j] = true if the ith atom affects the jth meshgrid,otherwise false. + */ + std::vector> get_is_atom_on_mgrid() const; + + // get psi of the big grid + // the dimension of psi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void get_psi(const std::vector coords, double * psi) const; + + // get psi and the gradient of psi of the big grid + // the dimension of psi and dpsi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void get_psi_dpsir( + const std::vector coords, + double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z) const; + + // get the hessian of the wave function values of the big grid + // the dimension of ddpsi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void get_ddpsir( + const std::vector coords, + double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, + double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz) const; + + private: + // atoms that can affect the big grid + std::vector> atoms_; + + // the 1D index of the big grid in the local cell + const int idx_; + + // local cell info + std::shared_ptr localcell_info_; + + // unitcell info + std::shared_ptr unitcell_info_; + + // the big grid info + std::shared_ptr biggrid_info_; +} + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index ce2a65dddc..7f9bc858b3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -1,14 +1,15 @@ #include "biggrid_info.h" #include "gint_helper.h" +#include "gint_type.h" namespace Gint { BigGridInfo::BigGridInfo( - const Vec3d& biggrid_vec1, - const Vec3d& biggrid_vec2, - const Vec3d& biggrid_vec3, - const int nmx, const int nmy, const int nmz) + Vec3d biggrid_vec1, + Vec3d biggrid_vec2, + Vec3d biggrid_vec3, + int nmx, int nmy, int nmz) : biggrid_vec1_(biggrid_vec1), biggrid_vec2_(biggrid_vec2), biggrid_vec3_(biggrid_vec3), diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index c3479786b5..c14f766175 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -1,9 +1,8 @@ -#ifndef BIGGIRD_INFO_H -#define BIGGIRD_INFO_H +#pragma once #include -#include "module_base/vector3.h" -#include "module_base/matrix3.h" +#include "gint_type.h" +#include "gint_helper.h" #include "meshgrid_info.h" namespace Gint @@ -18,10 +17,10 @@ class BigGridInfo public: // constructor BigGridInfo( - const Vec3d& biggrid_vec1, - const Vec3d& biggrid_vec2, - const Vec3d& biggrid_vec3, - const int nmx, const int nmy, const int nmz); + Vec3d biggrid_vec1, + Vec3d biggrid_vec2, + Vec3d biggrid_vec3, + int nmx, int nmy, int nmz); // getter functions const Vec3d &get_vec1() const { return biggrid_vec1_; }; @@ -77,12 +76,12 @@ class BigGridInfo // (x, y, z) * biggrid_GT_ = (i, j, k) Matrix3 biggrid_GT_; - //------------------------------------------- + //====================================================== // some member variables related to meshgrid - //------------------------------------------- + //====================================================== // basic attributes of meshgrid - std::shared_ptr meshgrid_info_; + std::shared_ptr meshgrid_info_; // the number of meshgrids of a biggrid along the first basis vector // nmx may be a confusing name, because it is not the number of meshgrids along x axis @@ -103,5 +102,4 @@ class BigGridInfo std::vector meshgrid_coords_; }; -} -#endif \ No newline at end of file +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp new file mode 100644 index 0000000000..0b200f6bcc --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp @@ -0,0 +1,24 @@ +#include "devide_info.h" + +namespace Gint +{ + +DivideInfo::DivideInfo( + int startidx_bx_old, int startidx_by_old, int startidx_bz_old, + int nbx_old, int nby_old, int nbz_old, + std::shared_ptr unitcell_info, bool is_redevided) + : startidx_bx_old(startidx_bx_old), startidx_by_old(startidx_by_old), startidx_bz_old(startidx_bz_old), + nbx_old(nbx_old), nby_old(nby_old), nbz_old(nbz_old), + startidx_bx_new(startidx_bx_old), startidx_by_new(startidx_by_old), startidx_bz_new(startidx_bz_old), + nbx_new(nbx_old), nby_new(nby_old), nbz_new(nbz_old), + unitcell_info(unitcell_info), is_redevided(is_redevided) + { + if(!is_redvided) + { + localcell_info = std::make_shared(startidx_bx_new_, startidx_by_new_, startidx_bz_new_, + nbx_new_, nby_new_, nbz_new_, unitcell_info_); + } + // TODO: "implement the redivide function"; + } + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h new file mode 100644 index 0000000000..444e572352 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h @@ -0,0 +1,54 @@ +#pragma once + +#include "biggrid_info.h" +#include "unitcell_info.h" +#include "localcell_info.h" + +namespace Gint +{ + +class DivideInfo +{ + public: + // constructor + DivideInfo( + int startidx_bx_old, int startidx_by_old, int startidx_bz_old, + int nbx_old, int nby_old, int nbz_old, + std::shared_ptr unitcell_info, bool is_redevided = false); + + // getter functions + std::shared_ptr get_localcell_info() const { return localcell_info_; } + bool get_is_redevided() const { return is_redevided_; } + + private: + // if the grid is redivided, is_redevided_ is true + bool is_redevided_; + + // the old start index of the local cell + int startidx_bx_old_; + int startidx_by_old_; + int startidx_bz_old_; + + // the old number of big grids in the local cell + int nbx_old_; + int nby_old_; + int nbz_old_; + + // the new start index of the local cell + int startidx_bx_new_; + int startidx_by_new_; + int startidx_bz_new_; + + // the new number of big grids in the local cell + int nbx_new_; + int nby_new_; + int nbz_new_; + + // the unitcell info + std::shared_ptr unitcell_info_; + + // the localcell info + std::shared_ptr localcell_info_; +} + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp new file mode 100644 index 0000000000..47fa3aee80 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp @@ -0,0 +1,270 @@ +#include "gint_atom.h" + +namespace Gint +{ + +template +void GintAtom::get_ddpsir( + const std::vector coords, const int stride, + T* ddpsi_xx, T* ddpsi_xy, T* ddpsi_xz, + T* ddpsi_yy, T* ddpsi_yz, T* ddpsi_zz) +{ + ModuleBase::timer::tick("GintAtom", "get_ddpsir"); + + const int num_mgrids = coords.size(); + + // orb_ does not have the member variable dr_uniform + const double dr_uniform = orb_->PhiLN(0, 0).dr_uniform; + + // store the pointer to reduce repeated address fetching + std::vector p_psi_uniform(atom_->nw); + std::vector p_dpsi_uniform(atom_->nw); + std::vector p_d2psi_uniform(atom_->nw); + std::vector psi_nr_uniform(atom_->nw); + for (int iw=0; iw< atom->nw; ++iw) + { + if ( atom->iw2_new[iw] ) + { + int l = atom_->iw2l[iw]; + int n = atom_->iw2n[iw]; + p_psi_uniform[iw] = orb_->PhiLN(l, n).psi_uniform.data(); + p_dpsi_uniform[iw] = orb_->PhiLN(l, n).dpsi_uniform.data(); + p_d2psi_uniform[iw] = orb_->PhiLN(l, n).d2psi_uniform.data(); + psi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; + } + } + + std::vector rly(std::pow(atom_->nwl + 1, 2)); + ModuleBase::Array_Pool grly(std::pow(atom_->nwl + 1, 2), 3); + // TODO: A better data structure such as a 3D tensor can be used to store dpsi + std::vector> dpsi(6, ModuleBase::Array_Pool(6, 3)); + std::vector coord1(3); + ModuleBase::Array_Pool displ(6, 3); + displ[0][0] = 0.0001; // in x direction + displ[1][0] = -0.0001; + displ[2][1] = 0.0001; // in y direction + displ[3][1] = -0.0001; + displ[4][2] = 0.0001; // in z direction + displ[5][2] = -0.0001; + + for(int im = 0; im < num_mgrids; im++) + { + const Vec3d& coord = coords[im]; + const double dist = coord.norm(); + + // avoid division by zero + if(dist < 1e-9) + { + dist = 1e-9; + } + + if(dist > orb_->getRcut()) + { + // if the distance is larger than the cutoff radius, + // the wave function values are all zeros + ModuleBase::GlobalFunc::ZEROS(ddpsi_xx + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddpsi_xy + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddpsi_xz + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddpsi_yy + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddpsi_yz + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddpsi_zz + im * stride, atom_->nw); + continue; + } + + for(int i = 0; i < 6; i++) + { + coord1[0] = coord[0] + displ[i][0]; + coord1[1] = coord[1] + displ[i][1]; + coord1[2] = coord[2] + displ[i][2]; + + // sphereical harmonics + ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord1[0], coord1[1], coord1[2], rly, grly.get_ptr_2D()); + + const double dist1 = coord1.norm(); + + if(dist1 < 1e-9) + { + dist1 = 1e-9; + } + + const double position = dist1 / dr_uniform; + const int ip = static_cast(position); + const double x0 = position - ip; + const double x1 = 1.0 - x0; + const double x2 = 2.0 - x0; + const double x3 = 3.0 - x0; + const double x12 = x1 * x2 / 6; + const double x03 = x0 * x3 / 2; + + double tmp, dtmp; + + for(int iw = 0; iw < atom_->nw; ++iw) + { + if(atom_->iw2_new[iw]) + { + auto psi_uniform = p_psi_uniform[iw]; + auto dpsi_uniform = p_dpsi_uniform[iw]; + + if(ip >= psi_nr_uniform[iw] - 4) + { + tmp = dtmp = 0.0; + } + else + { + // use Polynomia Interpolation method to get the + // wave functions + + tmp = x12 * (psi_uniform[ip] * x3 + psi_uniform[ip + 3] * x0) + + x03 * (psi_uniform[ip + 1] * x2 - psi_uniform[ip + 2] * x1); + + dtmp = x12 * (dpsi_uniform[ip] * x3 + dpsi_uniform[ip + 3] * x0) + + x03 * (dpsi_uniform[ip + 1] * x2 - dpsi_uniform[ip + 2] * x1); + } + } + + // get the 'l' of this localized wave function + const int ll = atom_->iw2l[iw]; + const int idx_lm = atom_->iw2_ylm[iw]; + + const double rl = pow_int(dist1, ll); + + // derivative of wave functions with respect to atom positions. + const double tmpdphi_rly = (dtmp - tmp * ll / dist1) / rl * rly[idx_lm] / dist1; + const double tmprl = tmp / rl; + + dpsi[iw][i][0] = tmpdphi_rly * coord1[0] + tmprl * grly[idx_lm][0]; + dpsi[iw][i][1] = tmpdphi_rly * coord1[1] + tmprl * grly[idx_lm][1]; + dpsi[iw][i][2] = tmpdphi_rly * coord1[2] + tmprl * grly[idx_lm][2]; + } // end iw + } // end i + + for(int iw = 0; iw < atom_->nw; iw++) + { + int idx = im * stride + iw; + ddpsi_xx[idx] = (dpsi[iw][0][0] - dpsi[iw][1][0]) / 0.0002; + ddpsi_xy[idx] + = ((dpsi[iw][2][0] - dpsi[iw][3][0]) + (dpsi[iw][0][1] - dpsi[iw][1][1])) / 0.0004; + ddpsi_xz[idx] + = ((dpsi[iw][4][0] - dpsi[iw][5][0]) + (dpsi[iw][0][2] - dpsi[iw][1][2])) / 0.0004; + ddpsi_yy[idx] = (dpsi[iw][2][1] - dpsi[iw][3][1]) / 0.0002; + ddpsi_yz[idx] + = ((dpsi[iw][4][1] - dpsi[iw][5][1]) + (dpsi[iw][2][2] - dpsi[iw][3][2])) / 0.0004; + ddpsi_zz[idx] = (dpsi[iw][4][2] - dpsi[iw][5][2]) / 0.0002; + } + + // else + // // the analytical method for evaluating 2nd derivatives + // // it is not used currently + // { + // // Add it here, but do not run it. If there is a need to run this code + // // in the future, include it in the previous initialization process. + // for (int iw=0; iw< atom->nw; ++iw) + // { + // if ( atom->iw2_new[iw] ) + // { + // it_d2psi_uniform[iw] = gt.d2psi_u[it*gt.nwmax + iw].data(); + // } + // } + // // End of code addition section. + + // std::vector> hrly; + // ModuleBase::Ylm::grad_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], rly, grly.get_ptr_2D()); + // ModuleBase::Ylm::hes_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], hrly); + // const double position = distance / delta_r; + + // const double iq = static_cast(position); + // const int ip = static_cast(position); + // const double x0 = position - iq; + // const double x1 = 1.0 - x0; + // const double x2 = 2.0 - x0; + // const double x3 = 3.0 - x0; + // const double x12 = x1 * x2 / 6; + // const double x03 = x0 * x3 / 2; + + // double tmp, dtmp, ddtmp; + + // for (int iw = 0; iw < atom->nw; ++iw) + // { + // // this is a new 'l', we need 1D orbital wave + // // function from interpolation method. + // if (atom->iw2_new[iw]) + // { + // auto psi_uniform = it_psi_uniform[iw]; + // auto dpsi_uniform = it_dpsi_uniform[iw]; + // auto ddpsi_uniform = it_d2psi_uniform[iw]; + + // // if ( iq[id] >= philn.nr_uniform-4) + // if (iq >= it_psi_nr_uniform[iw]-4) + // { + // tmp = dtmp = ddtmp = 0.0; + // } + // else + // { + // // use Polynomia Interpolation method to get the + // // wave functions + + // tmp = x12 * (psi_uniform[ip] * x3 + psi_uniform[ip + 3] * x0) + // + x03 * (psi_uniform[ip + 1] * x2 - psi_uniform[ip + 2] * x1); + + // dtmp = x12 * (dpsi_uniform[ip] * x3 + dpsi_uniform[ip + 3] * x0) + // + x03 * (dpsi_uniform[ip + 1] * x2 - dpsi_uniform[ip + 2] * x1); + + // ddtmp = x12 * (ddpsi_uniform[ip] * x3 + ddpsi_uniform[ip + 3] * x0) + // + x03 * (ddpsi_uniform[ip + 1] * x2 - ddpsi_uniform[ip + 2] * x1); + // } + // } // new l is used. + + // // get the 'l' of this localized wave function + // const int ll = atom->iw2l[iw]; + // const int idx_lm = atom->iw2_ylm[iw]; + + // const double rl = pow_int(distance, ll); + // const double r_lp2 =rl * distance * distance; + + // // d/dr (R_l / r^l) + // const double tmpdphi = (dtmp - tmp * ll / distance) / rl; + // const double term1 = ddtmp / r_lp2; + // const double term2 = (2 * ll + 1) * dtmp / r_lp2 / distance; + // const double term3 = ll * (ll + 2) * tmp / r_lp2 / distance / distance; + // const double term4 = tmpdphi / distance; + // const double term5 = term1 - term2 + term3; + + // // hessian of (R_l / r^l) + // const double term_xx = term4 + dr[0] * dr[0] * term5; + // const double term_xy = dr[0] * dr[1] * term5; + // const double term_xz = dr[0] * dr[2] * term5; + // const double term_yy = term4 + dr[1] * dr[1] * term5; + // const double term_yz = dr[1] * dr[2] * term5; + // const double term_zz = term4 + dr[2] * dr[2] * term5; + + // // d/dr (R_l / r^l) * alpha / r + // const double term_1x = dr[0] * term4; + // const double term_1y = dr[1] * term4; + // const double term_1z = dr[2] * term4; + + // p_ddpsi_xx[iw] + // = term_xx * rly[idx_lm] + 2.0 * term_1x * grly[idx_lm][0] + tmp / rl * hrly[idx_lm][0]; + // p_ddpsi_xy[iw] = term_xy * rly[idx_lm] + term_1x * grly[idx_lm][1] + term_1y * grly[idx_lm][0] + // + tmp / rl * hrly[idx_lm][1]; + // p_ddpsi_xz[iw] = term_xz * rly[idx_lm] + term_1x * grly[idx_lm][2] + term_1z * grly[idx_lm][0] + // + tmp / rl * hrly[idx_lm][2]; + // p_ddpsi_yy[iw] + // = term_yy * rly[idx_lm] + 2.0 * term_1y * grly[idx_lm][1] + tmp / rl * hrly[idx_lm][3]; + // p_ddpsi_yz[iw] = term_yz * rly[idx_lm] + term_1y * grly[idx_lm][2] + term_1z * grly[idx_lm][1] + // + tmp / rl * hrly[idx_lm][4]; + // p_ddpsi_zz[iw] + // = term_zz * rly[idx_lm] + 2.0 * term_1z * grly[idx_lm][2] + tmp / rl * hrly[idx_lm][5]; + + // } // iw + // } // end if + } + + ModuleBase::timer::tick("GintAtom", "get_ddpsir"); +} + +// explicit instantiation +template void GintAtom::get_ddpsir(const std::vector coords, const int stride, + double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, + double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz); + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp new file mode 100644 index 0000000000..cad4ffe92c --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -0,0 +1,217 @@ +#include "gint_atom.h" +#include "module_base/timer.h" +#include "module_base/ylm.h" +#include "module_base/array_pool.h" + +namespace Gint +{ + +template +void GintAtom::get_psi(const std::vector coords, const int stride, T* psi) +{ + ModuleBase::timer::tick("GintAtom", "get_psi"); + + const int num_mgrids = coords.size(); + + // orb_ does not have the member variable dr_uniform + const double dr_uniform = orb_->PhiLN(0, 0).dr_uniform; + + // store the pointer to reduce repeated address fetching + std::vector p_psi_uniform(atom_->nw); + std::vector p_dpsi_uniform(atom_->nw); + for(int iw = 0; iw < atom_->nw; iw++) + { + if(atom_->iw2_new[iw]) + { + int l = atom_->iw2l[iw]; + int n = atom_->iw2n[iw]; + p_psi_uniform[iw] = orb_->PhiLN(l, n).psi_uniform.data(); + p_dpsi_uniform[iw] = orb_->PhiLN(l, n).dpsi_uniform.data(); + } + } + + // store the spherical harmonics + // it's outside the loop to reduce the vector allocation overhead + std::vector ylma; + + for(int im = 0; im < num_mgrids; im++) + { + const Vec3d& coord = coords[im]; + const double dist = coord.norm(); + + // avoid division by zero + if(dist < 1e-9) + { + dist = 1e-9; + } + + if(dist > orb_->getRcut()) + { + // if the distance is larger than the cutoff radius, + // the wave function values are all zeros + ModuleBase::GlobalFunc::ZEROS(psi + im * stride, atom_->nw); + } + else + { + // spherical harmonics + // TODO: vectorize the sph_harm function, + // the vectorized function can be called once for all meshgrids in a biggrid + ModuleBase::Ylm::sph_harm(atom_->nwl, coord.x/dist, coord.y/dist, coord.z/dist, ylma); + + // interpolation + + // these parameters are related to interpolation + // because once the distance from atom to grid point is known, + // we can obtain the parameters for interpolation and + // store them first! these operations can save lots of efforts. + const double position = dist / dr_uniform; + const int ip = static_cast(position); + const double dx = position - ip; + const double dx2 = dx * dx; + const double dx3 = dx2 * dx; + + const double c3 = 3.0 * dx2 - 2.0 * dx3; + const double c1 = 1.0 - c3; + const double c2 = (dx - 2.0 * dx2 + dx3) * dr_uniform; + const double c4 = (dx3 - dx2) * dr_uniform; + + double phi = 0; + + for(int iw = 0; iw < atom_->nw; iw++) + { + if(atom_->iw2_new[iw]) + { + auto psi_uniform = p_psi_uniform[iw]; + auto dpsi_uniform = p_dpsi_uniform[iw]; + phi = c1 * psi_uniform[ip] + c2 * dpsi_uniform[ip] + + c3 * psi_uniform[ip + 1] + c4 * dpsi_uniform[ip + 1]; + } + psi[im * stride + iw] = phi * ylma[atom_->iw2_ylm[iw]]; + } + } + } + + ModuleBase::timer::tick("GintAtom", "get_psi"); +} + +template +void GintAtom::get_psi_dpsir( + const std::vector coords, const int stride, + T* psi, T* dpsi_x, T* dpsi_y, T* dpsi_z) +{ + ModuleBase::timer::tick("GintAtom", "get_psi_dpsir"); + + const int num_mgrids = coords.size(); + + // orb_ does not have the member variable dr_uniform + const double dr_uniform = orb_->PhiLN(0, 0).dr_uniform; + + // store the pointer to reduce repeated address fetching + std::vector p_psi_uniform(atom_->nw); + std::vector p_dpsi_uniform(atom_->nw); + std::vector psi_nr_uniform(atom_->nw); + for (int iw=0; iw< atom->nw; ++iw) + { + if ( atom->iw2_new[iw] ) + { + int l = atom_->iw2l[iw]; + int n = atom_->iw2n[iw]; + p_psi_uniform[iw] = orb_->PhiLN(l, n).psi_uniform.data(); + p_dpsi_uniform[iw] = orb_->PhiLN(l, n).dpsi_uniform.data(); + psi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; + } + } + + std::vector rly(std::pow(atom_->nwl + 1, 2)); + ModuleBase::Array_Pool grly(std::pow(atom_->nwl + 1, 2), 3); + + for(int im = 0; im < num_mgrids; im++) + { + const Vec3d& coord = coords[im]; + const double dist = coord.norm(); + + // avoid division by zero + if(dist < 1e-9) + { + dist = 1e-9; + } + + if(dist > orb_->getRcut()) + { + // if the distance is larger than the cutoff radius, + // the wave function values are all zeros + ModuleBase::GlobalFunc::ZEROS(dpsi_x + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(dpsi_y + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(dpsi_z + im * stride, atom_->nw); + } + else + { + // spherical harmonics + // TODO: vectorize the sph_harm function, + // the vectorized function can be called once for all meshgrids in a biggrid + ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord.x, coord.y, coord.z, rly, grly.get_ptr_2D()); + + // interpolation + const double position = dist / dr_uniform; + const int ip = static_cast(position); + const double x0 = position - ip; + const double x1 = 1.0 - x0; + const double x2 = 2.0 - x0; + const double x3 = 3.0 - x0; + const double x12 = x1 * x2 / 6; + const double x03 = x0 * x3 / 2; + + double tmp, dtmp; + for(int iw = 0; iw < atom_->nw; ++iw) + { + // this is a new 'l', we need 1D orbital wave + // function from interpolation method. + if(atom_->iw2_new[iw]) + { + auto psi_uniform = p_psi_uniform[iw]; + auto dpsi_uniform = p_dpsi_uniform[iw]; + + if(ip >= psi_nr_uniform[iw] - 4) + { + tmp = dtmp = 0.0; + } + else + { + // use Polynomia Interpolation method to get the + // wave functions + + tmp = x12 * (psi_uniform[ip] * x3 + psi_uniform[ip + 3] * x0) + + x03 * (psi_uniform[ip + 1] * x2 - psi_uniform[ip + 2] * x1); + + dtmp = x12 * (dpsi_uniform[ip] * x3 + dpsi_uniform[ip + 3] * x0) + + x03 * (dpsi_uniform[ip + 1] * x2 - dpsi_uniform[ip + 2] * x1); + } + } // new l is used. + + // get the 'l' of this localized wave function + const int ll = atom_->iw2l[iw]; + const int idx_lm = atom_->iw2_ylm[iw]; + + const double rl = pow_int(dist, ll); + const double tmprl = tmp / rl; + + // 3D wave functions + psi[im * stride + iw] = tmprl * rly[idx_lm]; + + // derivative of wave functions with respect to atom positions. + const double tmpdphi_rly = (dtmp - tmp * ll / dist) / rl * rly[idx_lm] / dist; + + dpsi_x[im * stride + iw] = tmpdphi_rly * coord.x + tmprl * grly[idx_lm][0]; + dpsi_y[im * stride + iw] = tmpdphi_rly * coord.y + tmprl * grly[idx_lm][1]; + dpsi_z[im * stride + iw] = tmpdphi_rly * coord.z + tmprl * grly[idx_lm][2]; + } + } + } + + ModuleBase::timer::tick("GintAtom", "get_psi_dpsir"); +} + +// explicit instantiation +template void GintAtom::get_psi(const std::vector coords, const int stride, double* psi); +template void GintAtom::get_psi_dpsir(const std::vector coords, const int stride, double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z); +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h new file mode 100644 index 0000000000..94a0722348 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h @@ -0,0 +1,113 @@ +#pragma once + +#include "module_cell/atom_spec.h" +#include "module_basis/module_ao/ORB_atomic.h" +#include "gint_type.h" + +namespace Gint +{ + +class GintAtom +{ + public: + // constructor + GintAtom( + const Atom* atom, + int iat, + Vec3i biggrid_idx, + Vec3i unitcell_idx, + Vec3d tau_in_biggrid, + const Numerical_Orbital* orb) + : atom_(atom), iat_(iat), biggrid_idx_(biggrid_idx), + unitcell_idx_(unitcell_idx), tau_in_biggrid_(tau_in_biggrid), + orb_(orb){}; + + // getter functions + const Atom* get_atom() const { return atom_; }; + const int get_iat() const { return iat_; }; + const Vec3i& get_biggrid_idx() const { return biggrid_idx_; }; + const Vec3i& get_unitcell_idx() const { return unitcell_idx_; }; + const Vec3i& get_r() const { return unitcell_idx_; }; + const Vec3d& get_tau_in_biggrid() const { return tau_in_biggrid_; }; + const Numerical_Orbital* get_orb() const { return orb_; }; + + const int get_nw() const { return atom_->nw; }; + const double get_rcut() const { return orb_->getRcut(); }; + + /** + * @brief Get the wave function values of the atom at a meshgrid. + * + * psi[(n-1)*stride] ~ psi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid + * + * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom + * @param stride the stride of the psi array between two adjacent meshgrids + * @param psi array to store the wave function values + */ + template + void get_psi(const std::vector coords, const int stride, T* psi); + + /** + * @brief Get the wave function values and its derivative + * + * The reason for combining the functions to solve the wave function values + * and wave function derivatives into one function is to improve efficiency. + * psi[(n-1)*stride] ~ psi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid + * + * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom + * @param stride the stride of the psi array between two adjacent meshgrids + * @param psi array to store the wave function values + * @param dpsi_x array to store the derivative wave functions in x direction + * @param dpsi_y array to store the derivative wave functions in y direction + * @param dpsi_z array to store the derivative wave functions in z direction + */ + template + void get_psi_dpsir( + const std::vector coords, const int stride, + T* psi, T* dpsi_x, T* dpsi_y, T* dpsi_z); + + /** + * @brief Get the wave function values and its second derivative + * + * ddpsi[(n-1)*stride] ~ ddpsi[(n-1)*stride + nw] store the second derivative of + * wave function values of the atom at the first meshgrid + * + * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom + * @param stride the stride of the psi array between two adjacent meshgrids + * @param ddpsi_xx array to store the second derivative wave functions in xx direction + * @param ddpsi_xy array to store the second derivative wave functions in xy direction + * @param ddpsi_xz array to store the second derivative wave functions in xz direction + * @param ddpsi_yy array to store the second derivative wave functions in yy direction + * @param ddpsi_yz array to store the second derivative wave functions in yz direction + * @param ddpsi_zz array to store the second derivative wave functions in zz direction + */ + template + void get_ddpsir( + const std::vector coords, const int stride, + T* ddpsi_xx, T* ddpsi_xy, T* ddpsi_xz, + T* ddpsi_yy, T* ddpsi_yz, T* ddpsi_zz); + + private: + // the atom object + const Atom* atom_; + + // the global index of the atom + int iat_; + + // the index of big grid which contains this atom + Vec3i biggrid_idx_; + + // the index of the unitcell which contains this atom + Vec3i unitcell_idx_; + + // the relative Cartesian coordinates of this atom + // with respect to the big grid that contains it + Vec3d tau_in_biggrid_; + + // the numerical orbitals of this atom + // In fact, I think the Numerical_Orbital class + // should be a member of the Atom class, not the GintAtom class + const Numerical_Orbital* orb_; + +} + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index db49c0ba8e..9d85d8f907 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -1,15 +1,9 @@ -#ifndef GINT_HELPER_H -#define GINT_HELPER_H +#pragma once -#include "module_base/vector3.h" +#include "gint_type.h" namespace Gint { - // Define the alias for the Vector3 and Matrix3 - using Matrix3 = ModuleBase::Matrix3; - using Vec3d = ModuleBase::Vector3; - using Vec3i = ModuleBase::Vector3; - inline int index3Dto1D(const int id_x, const int id_y, const int id_z, const int dim_x, const int dim_y, const int dim_z) { @@ -24,6 +18,30 @@ namespace Gint int id_z = index_1d % dim_z; return Vec3i(id_x, id_y, id_z); }; -} -#endif \ No newline at end of file + // if exponent is an integer between 0 and 5 (the most common cases in gint), + // pow_int is much faster than std::pow + inline double pow_int(const double base, const int exp) + { + switch (exp) + { + case 0: + return 1.0; + case 1: + return base; + case 2: + return base * base; + case 3: + return base * base * base; + case 4: + return base * base * base * base; + case 5: + return base * base * base * base * base; + default: + double result = std::pow(base, exp); + return result; + } + }; + + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp new file mode 100644 index 0000000000..f4f72bc92f --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -0,0 +1,123 @@ +#include +#include +#include "gint_info.h" +#include "gint_type.h" + +namespace Gint +{ + +GintInfo::GintInfo( + Vec3d unitcell_vec1, + Vec3d unitcell_vec2, + Vec3d unitcell_vec3, + int nbx, int nby, int nbz, + int nmx, int nmy, int nmz, + int startidx_bx, int startidx_by, int startidx_bz, + int nbx_local, int nby_local, int nbz_local, + int ntype, Atom* atoms, Numerical_Orbital* Phi) +{ + // initialize the unitcell information + unitcell_info_ = std::make_shared(unitcell_vec1, unitcell_vec2, unitcell_vec3, + nbx, nby, nbz, nmx, nmy, nmz); + + // initialize the divide information + divide_info_ = std::make_shared(startidx_bx, startidx_by, startidx_bz, + nbx, nby, nbz, unitcell_info_, false); + + // initialize the localcell information + localcell_info_ = divide_info_->get_localcell_info(); + + // initialize the biggrids + for (int i = 0; i < localcell_info_->get_biggrid_num(); i++) + { + biggrids_.emplace_back( + std::make_shared(localcell_info_->get_bgrid_global_idx_1D(i), localcell_info_)); + } + + // initialize the atoms + init_atoms_(ntype, atoms, Phi); +} + +void GintInfo::init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi) +{ + int iat = 0; + const Matrix3 biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); + const double g1 = sqrt(biggrid_GT.e11 * biggrid_GT.e11 + + biggrid_GT.e21 * biggrid_GT.e21 + + biggrid_GT.e31 * biggrid_GT.e31); + const double g2 = sqrt(biggrid_GT.e12 * biggrid_GT.e12 + + biggrid_GT.e22 * biggrid_GT.e22 + + biggrid_GT.e32 * biggrid_GT.e32); + const double g3 = sqrt(biggrid_GT.e13 * biggrid_GT.e13 + + biggrid_GT.e23 * biggrid_GT.e23 + + biggrid_GT.e33 * biggrid_GT.e33); + +#pragma omp parallel for schedule(dynamic) + for(int i = 0; i < ntype; i++) + { + const auto atom = atoms[i]; + const auto *orb = &Phi[i]; + // rcut extends to the maximum big grids in x, y, z directions + int rcut_bgrid_x = static_cast(atom.Rcut * g1) + 1; + int rcut_bgrid_y = static_cast(atom.Rcut * g2) + 1; + int rcut_bgrid_z = static_cast(atom.Rcut * g3) + 1; + + double rcut_ucell_x = rcut_bgrid_x / (double)unitcell_info_->get_nbx(); + double rcut_ucell_y = rcut_bgrid_y / (double)unitcell_info_->get_nby(); + double rcut_ucell_z = rcut_bgrid_z / (double)unitcell_info_->get_nbz(); + + for(int j = 0; j < atom.na; j++) + { + const Vec3i biggrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); + const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(biggrid_idx); + int min_x = static_cast(std::floor(atom.taud[j].x - rcut_ucell_x)); + int max_x = static_cast(std::floor(atom.taud[j].x + rcut_ucell_x)); + int min_y = static_cast(std::floor(atom.taud[j].y - rcut_ucell_y)); + int max_y = static_cast(std::floor(atom.taud[j].y + rcut_ucell_y)); + int min_z = static_cast(std::floor(atom.taud[j].z - rcut_ucell_z)); + int max_z = static_cast(std::floor(atom.taud[j].z + rcut_ucell_z)); + for(int k = min_x; k <= max_x; k++) + { + for(int l = min_y; l <= max_y; l++) + { + for(int m = min_z; m <= max_z; m++) + { + const Vec3i atom_idx_ext(biggrid_idx.x + k * unitcell_info_->get_nbx(), + biggrid_idx.y + l * unitcell_info_->get_nby(), + biggrid_idx.z + m * unitcell_info_->get_nbz()); + const Vec3i unitcell_idx(k, l, m); + auto gint_atom = std::make_shared(&atom, iat, atom_idx_ext, unitcell_idx, tau_in_biggrid, orb); + #pragma omp critical + { atoms_.push_back(gint_atom); } + for(int bx = atom_idx_ext.x - rcut_bgrid_x; bx <= atom_idx_ext.x + rcut_bgrid_x; bx++) + { + for(int by = atom_idx_ext.y - rcut_bgrid_y; by <= atom_idx_ext.y + rcut_bgrid_y; by++) + { + for(int bz = atom_idx_ext.z - rcut_bgrid_z; bz <= atom_idx_ext.z + rcut_bgrid_z; bz++) + { + const Vec3i biggrid_idx = unitcell_info_->map_ext_idx_to_ucell(Vec3i(bx, by, bz)); + if (localcell_info_->is_bgrid_in_lcell(biggrid_idx)) + { + const auto biggrid = biggrids_[localcell_info_->get_bgrid_local_idx_1D(biggrid_idx)]; + const auto meshgrid_coords = biggrid->get_mgrid_coords(*gint_atom); + for(const auto& coord : meshgrid_coords) + { + if(coord.norm() < atom.Rcut) + { + #pragma omp critical + { biggrid->add_atom(gint_atom);} + break; + } + } + } + } + } + } + } + } + } + iat++; + } + } +} +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h new file mode 100644 index 0000000000..9f3427a869 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include "module_cell/atom_spec.h" +#include "gint_type.h" +#include "biggrid.h" +#include "gint_atom.h" +#include "unitcell_info.h" +#include "localcell_info.h" +#include "divide_info.h" + +namespace Gint +{ + +class GintInfo +{ + public: + // constructor + GintInfo( + Vec3d unitcell_vec1, + Vec3d unitcell_vec2, + Vec3d unitcell_vec3, + int nbx, int nby, int nbz, + int nmx, int nmy, int nmz, + int startidx_bx, int startidx_by, int startidx_bz, + int nbx_local, int nby_local, int nbz_local, + int ntype, Atom* atoms, Numerical_Orbital* Phi); + + private: + // initialize the atoms + void init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi); + + // the unitcell information + std::shared_ptr unitcell_info_; + + // the divide information + std::shared_ptr divide_info_; + + // the localcell information + std::shared_ptr localcell_info_; + + // the big grids on this processor + std::vector> biggrids_; + + // the total atoms in the unitcell(include extended unitcell) + std::vector> atoms_; +} + +} // namespace Gint diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h new file mode 100644 index 0000000000..2d32369dfa --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h @@ -0,0 +1,8 @@ +#pragma once + +#include "module_base/vector3.h" +#include "module_base/matrix3.h" + +using Matrix3 = ModuleBase::Matrix3; +using Vec3d = ModuleBase::Vector3; +using Vec3i = ModuleBase::Vector3; \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index a86f297bf9..355b033b56 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -3,25 +3,25 @@ namespace Gint { LocalCellInfo::LocalCellInfo( - const int startind_bx, const int startind_by, const int startind_bz, - const int nbx, const int nby, const int nbz, - std::shared_ptr unitcell_info) - : startind_bx_(startind_bx), startind_by_(startind_by), startind_bz_(startind_bz), + int startidx_bx, int startidx_by, int startidx_bz, + int nbx, int nby, int nbz, + std::shared_ptr unitcell_info) + : startidx_bx_(startidx_bx), startidx_by_(startidx_by), startidx_bz_(startidx_bz), nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), - unitcell_info_(unitcell_info) + unitcell_info_(unitcell_info), biggrid_info_(unitcell_info->get_biggrid_info()) { - startind_mx_ = startind_bx_ * unitcell_info_->get_biggrid_info()->get_nmx(); - startind_my_ = startind_by_ * unitcell_info_->get_biggrid_info()->get_nmy(); - startind_mz_ = startind_bz_ * unitcell_info_->get_biggrid_info()->get_nmz(); - nmx_ = nbx_ * unitcell_info_->get_biggrid_info()->get_nmx(); - nmy_ = nby_ * unitcell_info_->get_biggrid_info()->get_nmy(); - nmz_ = nbz_ * unitcell_info_->get_biggrid_info()->get_nmz(); + startidx_mx_ = startidx_bx_ * biggrid_info_->get_nmx(); + startidx_my_ = startidx_by_ * biggrid_info_->get_nmy(); + startidx_mz_ = startidx_bz_ * biggrid_info_->get_nmz(); + nmx_ = nbx_ * biggrid_info_->get_nmx(); + nmy_ = nby_ * biggrid_info_->get_nmy(); + nmz_ = nbz_ * biggrid_info_->get_nmz(); nmxyz_ = nmx_ * nmy_ * nmz_; } - //---------------------------------- + //==================================================================== // functions related to the big grid - //---------------------------------- + //==================================================================== int LocalCellInfo::biggrid_idx_3Dto1D(const Vec3i index_3d) const { @@ -33,23 +33,58 @@ namespace Gint return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); } - Vec3i LocalCellInfo::get_biggrid_ucell_idx(const Vec3i index_3d) const + Vec3i LocalCellInfo::get_bgrid_global_idx_3D(const Vec3i index_3d) const { return Vec3i( - startind_bx_ + index_3d.x, - startind_by_ + index_3d.y, - startind_bz_ + index_3d.z); + startidx_bx_ + index_3d.x, + startidx_by_ + index_3d.y, + startidx_bz_ + index_3d.z); } - int LocalCellInfo::get_biggrid_ucell_idx(const int index_1d) const + Vec3i LocalCellInfo::get_bgrid_global_idx_3D(const int index_1d) const { - Vec3i ucell_idx_3d = get_biggrid_ucell_idx(biggrid_idx_1Dto3D(index_1d)); + return get_bgrid_global_idx_3D(biggrid_idx_1Dto3D(index_1d)); + } + + int LocalCellInfo::get_bgrid_global_idx_1D(const int index_1d) const + { + Vec3i ucell_idx_3d = get_bgrid_global_idx_3D(biggrid_idx_1Dto3D(index_1d)); return unitcell_info_->biggrid_idx_3Dto1D(ucell_idx_3d); } - //---------------------------------- + + Vec3i LocalCellInfo::get_bgrid_local_idx_3D(const Vec3i index_3d) const + { + int x = index_3d.x - startidx_bx_; + int y = index_3d.y - startidx_by_; + int z = index_3d.z - startidx_bz_; + assert(x >= 0 && x < nbx_); + assert(y >= 0 && y < nby_); + assert(z >= 0 && z < nbz_); + return Vec3i(x, y, z); + } + + int LocalCellInfo::get_bgrid_local_idx_1D(const Vec3i index_3d) const + { + return biggrid_idx_3Dto1D(get_bgrid_local_idx_3D(index_3d)); + } + + int LocalCellInfo::get_bgrid_local_idx_1D(const int index_1d) const + { + Vec3i idx_3d = unitcell_info_->biggrid_idx_1Dto3D(index_1d); + return biggrid_idx_3Dto1D(get_bgrid_local_idx_3D(idx_3d)); + } + + bool LocalCellInfo::is_bgrid_in_lcell(const Vec3i index_3d) const + { + return (index_3d.x >= startidx_bx_ && index_3d.x < startidx_bx_ + nbx_ && + index_3d.y >= startidx_by_ && index_3d.y < startidx_by_ + nby_ && + index_3d.z >= startidx_bz_ && index_3d.z < startidx_bz_ + nbz_); + } + + //==================================================================== // functions related to the meshgrid - //---------------------------------- + //==================================================================== int LocalCellInfo::meshgrid_idx_3Dto1D(const Vec3i index_3d) const { @@ -61,19 +96,18 @@ namespace Gint return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); } - Vec3i LocalCellInfo::get_meshgrid_ucell_idx(const Vec3i index_3d) const + Vec3i LocalCellInfo::get_mgrid_global_idx_3D(const Vec3i index_3d) const { return Vec3i( - startind_mx_ + index_3d.x, - startind_my_ + index_3d.y, - startind_mz_ + index_3d.z); + startidx_mx_ + index_3d.x, + startidx_my_ + index_3d.y, + startidx_mz_ + index_3d.z); } - int LocalCellInfo::get_meshgrid_ucell_idx(const int index_1d) const + int LocalCellInfo::get_mgrid_global_idx_1D(const int index_1d) const { - Vec3i ucell_idx_3d = get_meshgrid_ucell_idx(meshgrid_idx_1Dto3D(index_1d)); + Vec3i ucell_idx_3d = get_mgrid_global_idx_3D(meshgrid_idx_1Dto3D(index_1d)); return unitcell_info_->meshgrid_idx_3Dto1D(ucell_idx_3d); } - } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index e799ce36e1..274f3d7d76 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -1,8 +1,7 @@ -#ifndef LOCALCELL_INFO_H -#define LOCALCELL_INFO_H +#pragma once #include -#include "module_base/vector3.h" +#include "gint_type.h" #include "unitcell_info.h" namespace Gint @@ -13,23 +12,24 @@ class LocalCellInfo public: // constructor LocalCellInfo( - const int startind_x, const int startind_y, const int startind_z, - const int nbx, const int nby, const int nbz, - std::shared_ptr unitcell_info); + int startidx_x, int startidx_y, int startidx_z, + int nbx, int nby, int nbz, + std::shared_ptr unitcell_info); // getter functions - const int get_startind_bx() const { return startind_bx_; }; - const int get_startind_by() const { return startind_by_; }; - const int get_startind_bz() const { return startind_bz_; }; + const int get_startidx_bx() const { return startidx_bx_; }; + const int get_startidx_by() const { return startidx_by_; }; + const int get_startidx_bz() const { return startidx_bz_; }; const int get_nbx() const { return nbx_; }; const int get_nby() const { return nby_; }; const int get_nbz() const { return nbz_; }; - const int get_nbxyz() const { return nbxyz_; }; + const int get_biggrid_num() const { return nbxyz_; }; std::shared_ptr get_unitcell_info() const { return unitcell_info_; }; + std::shared_ptr get_biggrid_info() const { return unitcell_info_->get_biggrid_info(); }; - //---------------------------------- + //==================================================================== // functions related to the big grid - //---------------------------------- + //==================================================================== // transform the 3D index of a big grid in the local cell to the 3D index in the local cell int biggrid_idx_3Dto1D(const Vec3i index_3d) const; @@ -38,15 +38,31 @@ class LocalCellInfo Vec3i biggrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a big grid in the local cell to the 3D index in the unit cell - Vec3i get_biggrid_ucell_idx(const Vec3i index_3d) const; + Vec3i get_bgrid_global_idx_3D(const Vec3i index_3d) const; + + // transform the 1D index of a big grid in the local cell to the 3D index in the unit cell + Vec3i get_bgrid_global_idx_3D(const int index_1d) const; // transform the 1D index of a big grid in the local cell to the 1D index in the unit cell - int get_biggrid_ucell_idx(const int index_1d) const; + int get_bgrid_global_idx_1D(const int index_1d) const; + + // transform the 3D index of a big grid in the unit cell to the 3D index in the local cell + Vec3i get_bgrid_local_idx_3D(const Vec3i index_3d) const; + + // transform the 1D index of a big grid in the unit cell to the 1D index in the local cell + int get_bgrid_local_idx_1D(const int index_1d) const; + + // transform the 3D index of a big grid in the unit cell to the 1D index in the local cell + int get_bgrid_local_idx_1D(const Vec3i index_3d) const; + // the input is the 3D index of a big grid in the unitcell + // return true if the big grid is in the local cell + bool is_bgrid_in_lcell(const Vec3i index_3d) const; - //----------------------------------- + + //==================================================================== // functions related to the meshgrid - //----------------------------------- + //==================================================================== // transform the 3D index of a meshgrid in the local cell to the 3D index in the local cell int meshgrid_idx_3Dto1D(const Vec3i index_3d) const; @@ -55,20 +71,20 @@ class LocalCellInfo Vec3i meshgrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a meshgrid in the local cell to the 3D index in the unit cell - Vec3i get_meshgrid_ucell_idx(const Vec3i index_3d) const; + Vec3i get_mgrid_global_idx_3D(const Vec3i index_3d) const; // transform the 1D index of a meshgrid in the local cell to the 1D index in the unit cell - int get_meshgrid_ucell_idx(const int index_1d) const; + int get_mgrid_global_idx_1D(const int index_1d) const; private: - //------------------------------- + //==================================================================== // information about the big grid - //------------------------------- + //==================================================================== // 3D index of the first big grid in the local cell within the unit cell - int startind_bx_; - int startind_by_; - int startind_bz_; + int startidx_bx_; + int startidx_by_; + int startidx_bz_; // Number of big grids in the local cell along the three basis vectors of the local cell int nbx_; @@ -78,14 +94,14 @@ class LocalCellInfo // Total number of big grids in the local cell int nbxyz_; - //-------------------------------- + //==================================================================== // information about the meshgrid - //-------------------------------- + //==================================================================== // 3D index of the first meshgrid in the local cell within the unit cell - int startind_mx_; - int startind_my_; - int startind_mz_; + int startidx_mx_; + int startidx_my_; + int startidx_mz_; // Number of meshgrids in the local cell along the three basis vectors of the local cell int nmx_; @@ -95,12 +111,12 @@ class LocalCellInfo // Total number of meshgrids in the local cell int nmxyz_; - //-------------------------------- // information about the Unitcell - //-------------------------------- - std::shared_ptr unitcell_info_; + std::shared_ptr unitcell_info_; + + // information about the big grid + std::shared_ptr biggrid_info_; } -} -#endif // LOCALCELL_INFO_H \ No newline at end of file +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index bcaea339ec..f397396929 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -1,8 +1,6 @@ -#ifndef MESH_GRID_INFO_H -#define MESH_GRID_INFO_H +#pragma once -#include "module_base/vector3.h" -#include "module_base/matrix3.h" +#include "gint_type.h" #include "module_cell/unitcell.h" namespace Gint @@ -13,9 +11,9 @@ class MeshGridInfo public: // constructor MeshGridInfo( - const Vec3d& meshgrid_vec1, - const Vec3d& meshgrid_vec2, - const Vec3d& meshgrid_vec3) + Vec3d meshgrid_vec1, + Vec3d meshgrid_vec2, + Vec3d meshgrid_vec3) : meshgrid_vec1_(meshgrid_vec1), meshgrid_vec2_(meshgrid_vec2), meshgrid_vec3_(meshgrid_vec3) @@ -62,5 +60,4 @@ class MeshGridInfo Matrix3 meshgrid_GT_; }; -} -#endif \ No newline at end of file +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp new file mode 100644 index 0000000000..da530bb2e7 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp @@ -0,0 +1,148 @@ +#include "psi_operator.h" +#include "module_base/blas_connector.h" + +namespace Gint +{ + +int PsiOperator::atom_pair_startidx_(int a, int b) const +{ + for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + { + if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) + { + return i; + } + } +} + +int PsiOperator::atom_pair_endidx_(int a, int b) const +{ + for(int i = biggrid_->get_meshgrid_num() - 1; i >= 0; --i) + { + if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) + { + return i; + } + } +} + +PsiOperator::PsiOperator(std::shared_ptr biggrid) +: biggrid_(biggrid) +{ + rows_ = biggrid_->get_biggrid_info()->get_nmxyz(); + cols_ = biggrid_->get_mgrid_psi_len(); + is_atom_on_mgrid_ = biggrid_->get_is_atom_on_mgrid(); + atom_startidx_ = biggrid_->get_atom_startidx(); + atom_psi_len_ = biggrid_->get_atom_psi_len(); +} + +void PsiOperator::psi_times_dm(const hamilt::HContainer& DM, const double* const* psi, double** result, const bool is_symm) const +{ + // parameters for lapack subroutines + constexpr char side = 'L'; + constexpr char uplo = 'U'; + const char trans = 'N'; + const double alpha = 1.0; + const double beta = 1.0; + const double alpha1 = is_symm ? 2.0 : 1.0; + + for(int i = 0; i < biggrid_->get_atom_num(); ++i) + { + const auto atom_i = biggrid_->get_atoms()[i]; + const auto r_i = atom_i->get_r(); + + if(is_symm) + { + const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_i->get_iat(), 0, 0, 0); + dsymm_(&side, &uplo, &atom_psi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atom_psi_len_[i], + &psi[0][atom_startidx_[i]], &cols_, &beta, &result[0][atom_startidx_[i]], &cols_); + } + + const int start = is_symm ? i + 1 : 0; + + for(int j = start; j < biggrid_->get_atom_num(); ++j) + { + const auto atom_j = biggrid_->get_atoms()[j]; + const auto r_j = atom_j->get_r(); + // FIXME may be r = r_j - r_i + const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_j->get_iat(), r_i-r_j); + + // if dm_mat is nullptr, it means this atom pair does not affect any meshgrid in the unitcell + if(dm_mat == nullptr) + { + continue; + } + + const int start_idx = atom_pair_startidx_(i, j); + const int end_idx = atom_pair_endidx_(i, j); + const int len = end_idx - start_idx + 1; + + // if len == 0, it means this atom pair does not affect any meshgrid in this biggrid + if(len == 0) + { + continue; + } + + dgemm_(&trans, &trans, &atom_psi_len_[j], &len, &atom_psi_len_[i], &alpha1, dm_mat->get_pointer(), &atom_psi_len_[j], + &psi[start_idx][atom_startidx_[i]], &cols_, &beta, &result[start_idx][atom_startidx_[j]], &cols_); + } + } +} + +void PsiOperator::psi_times_vldr3(const double* vldr3, const double* const* psi, double** result) const +{ + for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) + { + for(int j = 0; j < biggrid_->get_atom_num(); j++) + { + for(int k = 0; k < atom_psi_len_[j]; k++) + { + const int idx = atom_startidx_[j]; + result[i][idx + k] = psi[i][idx + k] * vldr3[i]; + } + } + } +} + +void PsiOperator::psi_times_psi_vldr3( + const double* const* psi, + const double* const* psi_vldr3, + hamilt::HContainer* hr) const +{ + const char transa='N', transb='T'; + const double alpha=1, beta=1; + + for(int i = 0; i < biggrid_->get_atom_num(); ++i) + { + const auto atom_i = biggrid_->get_atoms()[i]; + const auto r_i = atom_i->get_r(); + + for(int j = i; j < biggrid_->get_atom_num(); ++j) + { + const auto atom_j = biggrid_->get_atoms()[j]; + const auto r_j = atom_j->get_r(); + // FIXME may be r = r_j - r_i + const auto result = hr->find_matrix(atom_i->get_iat(), atom_j->get_iat(), r_i-r_j); + + if(result == nullptr) + { + continue; + } + + const int start_idx = atom_pair_startidx_(i, j); + const int end_idx = atom_pair_endidx_(i, j); + const int len = end_idx - start_idx + 1; + + if(len == 0) + { + continue; + } + + dgemm_(&transa, &transb, &atom_psi_len_[j], &atom_psi_len_[i], &len, &alpha, &psi_vldr3[start_idx][atom_startidx_[j]], + &cols_,&psi[start_idx][atom_startidx_[i]], &cols_, &beta, result->get_pointer(), &atom_psi_len_[j]); + } + } +} + + +} // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h new file mode 100644 index 0000000000..4805b6a8be --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#include "biggrid.h" + +namespace Gint +{ + +/** + * @brief The class PsiOperator is used to perform operations on the wave function matrix psi, dpsi, etc. + * + * In fact, the variables and functions of this class could be placed in the BigGrid class, but the lifecycle of the BigGrid class is relatively long. + * We do not want the BigGrid to contain too many member variables, as this could lead to excessive memory usage. + * Therefore, we separate this class out, so it can be destroyed after use. + */ +class PsiOperator +{ + public: + // constructor + PsiOperator(std::shared_ptr biggrid); + + void psi_times_dm( + const hamilt::HContainer& DM, + const double* const* psi, + double** result, + const bool is_symm) const; + + void psi_times_vldr3( + const double* vldr3, + const double* const* psi, + double** result) const; + + void psi_times_psi_vldr3( + const double* const* psi, + const double* const* psi_vldr3, + hamilt::HContainer* hr) const; + + + private: + + // get the index of the first meshgrid that both atom a and atom b affect + int atom_pair_startidx_(int a, int b) const; + + // get the index of the last meshgrid that both atom a and atom b affect + int atom_pair_endidx_(int a, int b) const; + + // the row number of the psi matrix + // rows_ = biggrid_->get_meshgrid_num() + int rows_; + + // the column number of the psi matrix + // cols_ = biggrid_->get_mgrid_psi_len() + int cols_; + + // the big grid that the psi matrix is associated with + std::shared_ptr biggrid_; + + // record whether the atom affects the meshgrid + // is_atom_on_mgrid_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false + std::vector> is_atom_on_mgrid_; + + // the start index of the psi of each atom + std::vector atom_startidx_; + + // the length of psi of each atom + // atom_psi_len_[i] = biggrid_->get_atoms()[i]->get_nw() + std::vector atom_psi_len_; +} + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp index ad62eff103..1fc7eb2acf 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp @@ -5,11 +5,11 @@ namespace Gint { UnitCellInfo::UnitCellInfo( - const Vec3d& unitcell_vec1, - const Vec3d& unitcell_vec2, - const Vec3d& unitcell_vec3, - const int nbx, const int nby, const int nbz, - const int nmx, const int nmy, const int nmz) + Vec3d unitcell_vec1, + Vec3d unitcell_vec2, + Vec3d unitcell_vec3, + int nbx, int nby, int nbz, + int nmx, int nmy, int nmz) : unitcell_vec1_(unitcell_vec1), unitcell_vec2_(unitcell_vec2), unitcell_vec3_(unitcell_vec3), diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index 1fae657f87..71a19be246 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -1,11 +1,10 @@ -#ifndef UNITCELL_INFO_H -#define UNITCELL_INFO_H +#pragma once #include -#include "module_base/vector3.h" -#include "module_base/matrix3.h" +#include #include "biggrid_info.h" #include "gint_helper.h" +#include "gint_type.h" namespace Gint { @@ -15,11 +14,11 @@ class UnitCellInfo public: // constructor UnitCellInfo( - const Vec3d& unitcell_vec1, - const Vec3d& unitcell_vec2, - const Vec3d& unitcell_vec3, - const int nbx, const int nby, const int nbz, - const int nmx, const int nmy, const int nmz); + Vec3d unitcell_vec1, + Vec3d unitcell_vec2, + Vec3d unitcell_vec3, + int nbx, int nby, int nbz, + int nmx, int nmy, int nmz); // getter functions const Vec3d &get_vec1() const { return unitcell_vec1_; }; @@ -29,25 +28,16 @@ class UnitCellInfo int get_nby() const { return nby_; }; int get_nbz() const { return nbz_; }; int get_nbxyz() const { return nbxyz_; }; - - // get the number of meshcells along the first lattice vector of the unit cell - int get_nmx() const { return nbx_ * biggrid_info_->get_nmx(); }; - - // get the number of meshcells along the second lattice vector of the unit cell - int get_nmy() const { return nby_ * biggrid_info_->get_nmy(); }; - - // get the number of meshcells along the third lattice vector of the unit cell - int get_nmz() const { return nbz_ * biggrid_info_->get_nmz(); }; - - // get the total number of meshcells in the unit cell - int get_nmxyz() const { return nbxyz_ * biggrid_info_->get_nmxyz(); }; - + int get_nmx() const { return nmx_; }; + int get_nmy() const { return nmy_; }; + int get_nmz() const { return nmz_; }; + int get_nmxyz() const { return nmxyz_; }; std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; std::shared_ptr get_meshgrid_info() const { return biggrid_info_->get_meshgrid_info(); }; - //---------------------------------- + //==================================================================== // functions related to the big grid - //---------------------------------- + //==================================================================== // transform the 1D index of a big grid in the unit cell to the 3D index Vec3i biggrid_idx_1Dto3D(const int index_1d) const @@ -73,16 +63,41 @@ class UnitCellInfo return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); }; + // get the 3D index of a big grid in the unit cell from the cartesian coordinate + Vec3i get_biggrid_idx_3d(const Vec3d coord) const + { + Vec3d biggrid_idx_double = coord * biggrid_info_->get_GT(); + return Vec3i( + static_cast(floor(biggrid_idx_double.x)), + static_cast(floor(biggrid_idx_double.y)), + static_cast(floor(biggrid_idx_double.z))); + }; + // Get the relative Cartesian coordinates of big grid A relative to big grid B // returned vector = coordinates of point A - coordinates of point B + // this function is more efficient than obtaining two 3D coordinates separately + // through two 3D indices and then subtracting them Vec3d get_relative_coord(Vec3i index_3d_a, Vec3i index_3d_b) const { return get_biggrid_coord(index_3d_a - index_3d_b); }; - //---------------------------------- + // get the extended unitcell index of a big grid + Vec3i get_extcell_idx(const Vec3i index_3d) const + { + return Vec3i(index_3d.x / nbx_, index_3d.y / nby_, index_3d.z / nbz_); + }; + + // map the extended big grid index to the big grid index in unitcell + Vec3i map_ext_idx_to_ucell(const Vec3i index_3d) const + { + return Vec3i(index_3d.x % nbx_, index_3d.y % nby_, index_3d.z % nbz_); + }; + + + //==================================================================== // functions related to the meshgrid - //---------------------------------- + //==================================================================== // transform the 1D index of a meshgrid in the unit cell to the 3D index Vec3i meshgrid_idx_1Dto3D(const int index_1d) const @@ -114,9 +129,9 @@ class UnitCellInfo Vec3d unitcell_vec2_; Vec3d unitcell_vec3_; - //---------------------------------------------- + //==================================================================== // member variables related to the Big Grid - //---------------------------------------------- + //==================================================================== // the number of big cells along the first lattice vector int nbx_; @@ -131,11 +146,11 @@ class UnitCellInfo int nbxyz_; // basic attributes of the big grid - std::shared_ptr biggrid_info_; + std::shared_ptr biggrid_info_; - //------------------------------------------- + //==================================================================== // member variables related to meshgrid - //------------------------------------------- + //==================================================================== // the number of meshgrids along the first lattice vector int nmx_; @@ -151,6 +166,4 @@ class UnitCellInfo } -} - -#endif \ No newline at end of file +} // namespace Gint \ No newline at end of file From 0b84ed37af42275261d469957a645b435aa4d528 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sun, 15 Dec 2024 23:51:21 +0800 Subject: [PATCH 06/47] version 0.2 --- source/module_base/vector3.h | 16 ++ .../module_gint/CMakeLists.txt | 13 ++ .../module_gint/new_grid_tech/biggrid.cpp | 88 +++----- .../module_gint/new_grid_tech/biggrid.h | 48 ++--- .../module_gint/new_grid_tech/divide_info.cpp | 16 +- .../module_gint/new_grid_tech/divide_info.h | 10 +- .../module_gint/new_grid_tech/gint_atom.cpp | 73 +++---- .../module_gint/new_grid_tech/gint_atom.h | 57 ++--- .../module_gint/new_grid_tech/gint_helper.h | 4 +- .../module_gint/new_grid_tech/gint_info.cpp | 195 +++++++++++++----- .../module_gint/new_grid_tech/gint_info.h | 34 ++- .../module_gint/new_grid_tech/gint_vl.cpp | 90 ++++++++ .../module_gint/new_grid_tech/gint_vl.h | 48 +++++ .../new_grid_tech/localcell_info.cpp | 6 + .../new_grid_tech/localcell_info.h | 5 +- .../{psi_operator.cpp => phi_operator.cpp} | 115 ++++++++--- .../module_gint/new_grid_tech/phi_operator.h | 93 +++++++++ .../module_gint/new_grid_tech/psi_operator.h | 72 ------- .../{get_ddpsi.cpp => set_ddphi.cpp} | 112 +++++----- .../module_gint/new_grid_tech/unitcell_info.h | 4 +- 20 files changed, 708 insertions(+), 391 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h rename source/module_hamilt_lcao/module_gint/new_grid_tech/{psi_operator.cpp => phi_operator.cpp} (51%) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h delete mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h rename source/module_hamilt_lcao/module_gint/new_grid_tech/{get_ddpsi.cpp => set_ddphi.cpp} (74%) diff --git a/source/module_base/vector3.h b/source/module_base/vector3.h index fda97c5482..3540018ae0 100644 --- a/source/module_base/vector3.h +++ b/source/module_base/vector3.h @@ -365,6 +365,22 @@ template inline Vector3 cross(const Vector3 &u, const Vector3 // (u.z * (v.x * w.y - v.y * w.x))); // } +// Overload the < operator for sorting +template bool operator<(const Vector3 &u, const Vector3 &v) +{ + if (u.x < v.x) + return true; + if (u.x > v.x) + return false; + if (u.y < v.y) + return true; + if (u.y > v.y) + return false; + if (u.z < v.z) + return true; + return false; +} + // whether m1 != m2 template inline bool operator!=(const Vector3 &u, const Vector3 &v) { diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index e0e1e2e4cb..a5596b19bc 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -29,6 +29,19 @@ list(APPEND objects init_orb.cpp ) +list(APPEND objects + new_grid_tech/biggrid_info.cpp + new_grid_tech/biggrid.cpp + new_grid_tech/divide_info.cpp + new_grid_tech/gint_atom.cpp + new_grid_tech/gint_info.cpp + new_grid_tech/gint_vl.cpp + new_grid_tech/localcell_info.cpp + new_grid_tech/phi_operator.cpp + new_grid_tech/set_ddphi.cpp + new_grid_tech/unitcell_info.cpp + ) + if(USE_CUDA) list(APPEND objects gint_gpu_interface.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index fcb51a5141..e74ac79348 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -13,7 +13,7 @@ void BigGrid::add_atom(std::shared_ptr atom) atoms_.push_back(atom); } -int BigGrid::get_mgrid_psi_len() const +int BigGrid::get_mgrid_phi_len() const { int len = 0; for(const auto& atom : atoms_) @@ -34,17 +34,28 @@ std::vector BigGrid::get_atom_startidx() const return startidx; } -std::vector BigGrid::get_atom_psi_len() const +std::vector BigGrid::get_atom_phi_len() const { - std::vector psi_len(atoms_.size()); + std::vector phi_len(atoms_.size()); for(int i = 0; i < atoms_.size(); ++i) { - psi_len[i] = atoms_[i]->get_nw(); + phi_len[i] = atoms_[i]->get_nw(); } - return psi_len; + return phi_len; } -std::vector BigGrid::get_mgrid_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const +std::vector BigGrid::get_mgrid_coords() const +{ + std::vector coords(biggrid_info_->get_nmxyz()); + Vec3d this_bgrid_coord = localcell_info_->get_bgrid_global_coord_3D(idx_); + for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) + { + coords[im] = biggrid_info_->get_meshgrid_coord(im) + this_bgrid_coord; + } + return coords; +} + +std::vector BigGrid::get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const { Vec3i this_bgrid_idx = localcell_info_->get_bgrid_global_idx_3D(idx_); @@ -62,69 +73,36 @@ std::vector BigGrid::get_mgrid_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid } -std::vector BigGrid::get_mgrid_coords(const GintAtom& atom) const +std::vector BigGrid::get_atom_relative_coords(const GintAtom& atom) const { - return get_mgrid_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid()); + return get_atom_relative_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid()); } -std::vector> BigGrid::get_is_atom_on_mgrid() const +bool BigGrid::is_atom_on_bgrid(const GintAtom& atom) const { - std::vector> if_on_mcell; - for(const auto& atom : atoms_) + for(const auto& dist : get_atom_relative_coords(atom)) { - std::vector mcell_coords = get_mgrid_coords(*atom); - std::vector atom_if_on_mcell; - for(const auto& coord : mcell_coords) + if(dist.norm() <= atom.get_rcut()) { - coord.norm() < atom->get_rcut() ? atom_if_on_mcell.push_back(true) : atom_if_on_mcell.push_back(false); + return true; } - if_on_mcell.push_back(atom_if_on_mcell); - } - return ; -} - -void BigGrid::get_psi(const std::vector coords, double * psi) const -{ - int psi_len = get_mgrid_psi_len(); - for(const auto& atom : atoms_) - { - atom->get_psi(coords, psi_len, psi); - psi += atom->get_nw(); - } -} - -void BigGrid::get_psi_dpsir( - const std::vector coords, - double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z) const -{ - int psi_len = get_mgrid_psi_len(); - for(const auto& atom : atoms_) - { - atom->get_psi_dpsir(coords, psi_len, psi, dpsi_x, dpsi_y, dpsi_z); - psi += atom->get_nw(); - dpsi_x += atom->get_nw(); - dpsi_y += atom->get_nw(); - dpsi_z += atom->get_nw(); } + return false; } -void BigGrid::get_ddpsir( - const std::vector coords, - double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, - double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz) const +std::vector> BigGrid::get_is_atom_on_mgrids() const { - int psi_len = get_mgrid_psi_len(); + std::vector> if_on_mcell; for(const auto& atom : atoms_) { - atom->get_ddpsir(coords, psi_len, ddpsi_xx, ddpsi_xy, ddpsi_xz, ddpsi_yy, ddpsi_yz, ddpsi_zz); - ddpsi_xx += atom->get_nw(); - ddpsi_xy += atom->get_nw(); - ddpsi_xz += atom->get_nw(); - ddpsi_yy += atom->get_nw(); - ddpsi_yz += atom->get_nw(); - ddpsi_zz += atom->get_nw(); + std::vector mcell_coords = get_atom_relative_coords(*atom); + std::vector atom_if_on_mcell; + for(const auto& coord : mcell_coords) + { + coord.norm() <= atom->get_rcut() ? atom_if_on_mcell.push_back(true) : atom_if_on_mcell.push_back(false); + } + if_on_mcell.push_back(atom_if_on_mcell); } } - } // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index 47e44696c0..f60cb44eed 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -33,16 +33,19 @@ class BigGrid // add an atom to the big grid void add_atom(std::shared_ptr atom); - // get the total number of psi of a meshgrid + // get the total number of phi of a meshgrid // return: (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) - int get_mgrid_psi_len() const; + int get_mgrid_phi_len() const; - // get the start index of the psi of each atom + // get the start index of the phi of each atom // return: vector[i] = \sum_{j=0}^{i-1} atoms_[j]->nw vector get_atom_startidx() const; - // get the length of psi of each atom - vector get_atom_psi_len() const; + // get the length of phi of each atom + vector get_atom_phi_len() const; + + // get the coordinates of the meshgrids of the big grid + vector get_mgrid_coords() const; /** * @brief Get the coordinates of the meshgrids of the big grid relative to an atom @@ -50,38 +53,23 @@ class BigGrid * @param bgrid_idx the 3D index of the big grid, which contains the atom, in the unitcell * @param tau_in_bgrid the cartesian coordinate of the atom relative to the big grid containing it */ - std::vector get_mgrid_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const; + std::vector get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const; // get the coordinates of the meshgrids of the big grid relative to the atom - std::vector get_mgrid_coords(const GintAtom& atom) const; + std::vector get_atom_relative_coords(const GintAtom& atom) const; + + // if the atom affects the big grid, return true, otherwise false + // note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, + // it may only affect a part of them. + bool is_atom_on_bgrid(const GintAtom& atom) const; /** - * @brief Get a boolean array to indicate whether the atom affects the meshgrid - * - * @note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, - * it may only affect a part of them. + * @brief Get a boolean array to indicate whether the atom affects the meshgrids * * @return a boolean array, the dimension of the array is atoms_->size() * biggrid_info_->get_nmxyz() * array[i][j] = true if the ith atom affects the jth meshgrid,otherwise false. */ - std::vector> get_is_atom_on_mgrid() const; - - // get psi of the big grid - // the dimension of psi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) - void get_psi(const std::vector coords, double * psi) const; - - // get psi and the gradient of psi of the big grid - // the dimension of psi and dpsi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) - void get_psi_dpsir( - const std::vector coords, - double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z) const; - - // get the hessian of the wave function values of the big grid - // the dimension of ddpsi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) - void get_ddpsir( - const std::vector coords, - double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, - double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz) const; + std::vector> get_is_atom_on_mgrids() const; private: // atoms that can affect the big grid @@ -98,6 +86,6 @@ class BigGrid // the big grid info std::shared_ptr biggrid_info_; -} +}; } // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp index 0b200f6bcc..20a0c45e42 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp @@ -1,4 +1,4 @@ -#include "devide_info.h" +#include "divide_info.h" namespace Gint { @@ -7,15 +7,15 @@ DivideInfo::DivideInfo( int startidx_bx_old, int startidx_by_old, int startidx_bz_old, int nbx_old, int nby_old, int nbz_old, std::shared_ptr unitcell_info, bool is_redevided) - : startidx_bx_old(startidx_bx_old), startidx_by_old(startidx_by_old), startidx_bz_old(startidx_bz_old), - nbx_old(nbx_old), nby_old(nby_old), nbz_old(nbz_old), - startidx_bx_new(startidx_bx_old), startidx_by_new(startidx_by_old), startidx_bz_new(startidx_bz_old), - nbx_new(nbx_old), nby_new(nby_old), nbz_new(nbz_old), - unitcell_info(unitcell_info), is_redevided(is_redevided) + : startidx_bx_old_(startidx_bx_old), startidx_by_old_(startidx_by_old), startidx_bz_old_(startidx_bz_old), + nbx_old_(nbx_old), nby_old_(nby_old), nbz_old_(nbz_old), + startidx_bx_new_(startidx_bx_old), startidx_by_new_(startidx_by_old), startidx_bz_new_(startidx_bz_old), + nbx_new_(nbx_old), nby_new_(nby_old), nbz_new_(nbz_old), + unitcell_info_(unitcell_info), is_redivided_(is_redevided) { - if(!is_redvided) + if(!is_redivided_) { - localcell_info = std::make_shared(startidx_bx_new_, startidx_by_new_, startidx_bz_new_, + localcell_info_ = std::make_shared(startidx_bx_new_, startidx_by_new_, startidx_bz_new_, nbx_new_, nby_new_, nbz_new_, unitcell_info_); } // TODO: "implement the redivide function"; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h index 444e572352..c3770fb846 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h @@ -14,15 +14,15 @@ class DivideInfo DivideInfo( int startidx_bx_old, int startidx_by_old, int startidx_bz_old, int nbx_old, int nby_old, int nbz_old, - std::shared_ptr unitcell_info, bool is_redevided = false); + std::shared_ptr unitcell_info, bool is_redivided = false); // getter functions std::shared_ptr get_localcell_info() const { return localcell_info_; } - bool get_is_redevided() const { return is_redevided_; } + bool get_is_redivided() const { return is_redivided_; } private: - // if the grid is redivided, is_redevided_ is true - bool is_redevided_; + // if the grid is redivided, is_redeiided_ is true + bool is_redivided_; // the old start index of the local cell int startidx_bx_old_; @@ -49,6 +49,6 @@ class DivideInfo // the localcell info std::shared_ptr localcell_info_; -} +}; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index cad4ffe92c..bee2585e9d 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -1,15 +1,16 @@ -#include "gint_atom.h" #include "module_base/timer.h" #include "module_base/ylm.h" #include "module_base/array_pool.h" +#include "gint_atom.h" +#include "gint_helper.h" namespace Gint { template -void GintAtom::get_psi(const std::vector coords, const int stride, T* psi) +void GintAtom::set_phi(const std::vector coords, const int stride, T* phi) { - ModuleBase::timer::tick("GintAtom", "get_psi"); + ModuleBase::timer::tick("GintAtom", "set_phi"); const int num_mgrids = coords.size(); @@ -37,19 +38,15 @@ void GintAtom::get_psi(const std::vector coords, const int stride, T* psi for(int im = 0; im < num_mgrids; im++) { const Vec3d& coord = coords[im]; - const double dist = coord.norm(); - // avoid division by zero - if(dist < 1e-9) - { - dist = 1e-9; - } + // 1e-9 is to avoid division by zero + const double dist = coord.norm() < 1e-9 ? 1e-9 : coord.norm(); if(dist > orb_->getRcut()) { // if the distance is larger than the cutoff radius, // the wave function values are all zeros - ModuleBase::GlobalFunc::ZEROS(psi + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(phi + im * stride, atom_->nw); } else { @@ -75,7 +72,8 @@ void GintAtom::get_psi(const std::vector coords, const int stride, T* psi const double c2 = (dx - 2.0 * dx2 + dx3) * dr_uniform; const double c4 = (dx3 - dx2) * dr_uniform; - double phi = 0; + // I'm not sure if the variable name 'psi' is appropriate + double psi = 0; for(int iw = 0; iw < atom_->nw; iw++) { @@ -83,23 +81,23 @@ void GintAtom::get_psi(const std::vector coords, const int stride, T* psi { auto psi_uniform = p_psi_uniform[iw]; auto dpsi_uniform = p_dpsi_uniform[iw]; - phi = c1 * psi_uniform[ip] + c2 * dpsi_uniform[ip] + psi = c1 * psi_uniform[ip] + c2 * dpsi_uniform[ip] + c3 * psi_uniform[ip + 1] + c4 * dpsi_uniform[ip + 1]; } - psi[im * stride + iw] = phi * ylma[atom_->iw2_ylm[iw]]; + phi[im * stride + iw] = psi * ylma[atom_->iw2_ylm[iw]]; } } } - ModuleBase::timer::tick("GintAtom", "get_psi"); + ModuleBase::timer::tick("GintAtom", "set_phi"); } template -void GintAtom::get_psi_dpsir( +void GintAtom::set_phi_dphi( const std::vector coords, const int stride, - T* psi, T* dpsi_x, T* dpsi_y, T* dpsi_z) + T* phi, T* dphi_x, T* dphi_y, T* dphi_z) { - ModuleBase::timer::tick("GintAtom", "get_psi_dpsir"); + ModuleBase::timer::tick("GintAtom", "set_phi_dphi"); const int num_mgrids = coords.size(); @@ -109,16 +107,16 @@ void GintAtom::get_psi_dpsir( // store the pointer to reduce repeated address fetching std::vector p_psi_uniform(atom_->nw); std::vector p_dpsi_uniform(atom_->nw); - std::vector psi_nr_uniform(atom_->nw); - for (int iw=0; iw< atom->nw; ++iw) + std::vector phi_nr_uniform(atom_->nw); + for (int iw=0; iw< atom_->nw; ++iw) { - if ( atom->iw2_new[iw] ) + if ( atom_->iw2_new[iw] ) { int l = atom_->iw2l[iw]; int n = atom_->iw2n[iw]; p_psi_uniform[iw] = orb_->PhiLN(l, n).psi_uniform.data(); p_dpsi_uniform[iw] = orb_->PhiLN(l, n).dpsi_uniform.data(); - psi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; + phi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; } } @@ -128,28 +126,23 @@ void GintAtom::get_psi_dpsir( for(int im = 0; im < num_mgrids; im++) { const Vec3d& coord = coords[im]; - const double dist = coord.norm(); - - // avoid division by zero - if(dist < 1e-9) - { - dist = 1e-9; - } + // 1e-9 is to avoid division by zero + const double dist = coord.norm() < 1e-9 ? 1e-9 : coord.norm(); if(dist > orb_->getRcut()) { // if the distance is larger than the cutoff radius, // the wave function values are all zeros - ModuleBase::GlobalFunc::ZEROS(dpsi_x + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(dpsi_y + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(dpsi_z + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(dphi_x + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(dphi_y + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(dphi_z + im * stride, atom_->nw); } else { // spherical harmonics // TODO: vectorize the sph_harm function, // the vectorized function can be called once for all meshgrids in a biggrid - ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord.x, coord.y, coord.z, rly, grly.get_ptr_2D()); + ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord.x, coord.y, coord.z, rly.data(), grly.get_ptr_2D()); // interpolation const double position = dist / dr_uniform; @@ -171,7 +164,7 @@ void GintAtom::get_psi_dpsir( auto psi_uniform = p_psi_uniform[iw]; auto dpsi_uniform = p_dpsi_uniform[iw]; - if(ip >= psi_nr_uniform[iw] - 4) + if(ip >= phi_nr_uniform[iw] - 4) { tmp = dtmp = 0.0; } @@ -196,22 +189,22 @@ void GintAtom::get_psi_dpsir( const double tmprl = tmp / rl; // 3D wave functions - psi[im * stride + iw] = tmprl * rly[idx_lm]; + phi[im * stride + iw] = tmprl * rly[idx_lm]; // derivative of wave functions with respect to atom positions. const double tmpdphi_rly = (dtmp - tmp * ll / dist) / rl * rly[idx_lm] / dist; - dpsi_x[im * stride + iw] = tmpdphi_rly * coord.x + tmprl * grly[idx_lm][0]; - dpsi_y[im * stride + iw] = tmpdphi_rly * coord.y + tmprl * grly[idx_lm][1]; - dpsi_z[im * stride + iw] = tmpdphi_rly * coord.z + tmprl * grly[idx_lm][2]; + dphi_x[im * stride + iw] = tmpdphi_rly * coord.x + tmprl * grly[idx_lm][0]; + dphi_y[im * stride + iw] = tmpdphi_rly * coord.y + tmprl * grly[idx_lm][1]; + dphi_z[im * stride + iw] = tmpdphi_rly * coord.z + tmprl * grly[idx_lm][2]; } } } - ModuleBase::timer::tick("GintAtom", "get_psi_dpsir"); + ModuleBase::timer::tick("GintAtom", "set_phi_dphi"); } // explicit instantiation -template void GintAtom::get_psi(const std::vector coords, const int stride, double* psi); -template void GintAtom::get_psi_dpsir(const std::vector coords, const int stride, double* psi, double* dpsi_x, double* dpsi_y, double* dpsi_z); +template void GintAtom::set_phi(const std::vector coords, const int stride, double* phi); +template void GintAtom::set_phi_dphi(const std::vector coords, const int stride, double* phi, double* dphi_x, double* dphi_y, double* dphi_z); } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h index 94a0722348..118cf16b07 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h @@ -13,17 +13,19 @@ class GintAtom // constructor GintAtom( const Atom* atom, + int ia, int iat, Vec3i biggrid_idx, Vec3i unitcell_idx, Vec3d tau_in_biggrid, const Numerical_Orbital* orb) - : atom_(atom), iat_(iat), biggrid_idx_(biggrid_idx), + : atom_(atom), ia_(ia), iat_(iat), biggrid_idx_(biggrid_idx), unitcell_idx_(unitcell_idx), tau_in_biggrid_(tau_in_biggrid), - orb_(orb){}; + orb_(orb) {}; // getter functions const Atom* get_atom() const { return atom_; }; + const int get_ia() const { return ia_; }; const int get_iat() const { return iat_; }; const Vec3i& get_biggrid_idx() const { return biggrid_idx_; }; const Vec3i& get_unitcell_idx() const { return unitcell_idx_; }; @@ -37,54 +39,54 @@ class GintAtom /** * @brief Get the wave function values of the atom at a meshgrid. * - * psi[(n-1)*stride] ~ psi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid + * phi[(n-1)*stride] ~ phi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid * * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom - * @param stride the stride of the psi array between two adjacent meshgrids - * @param psi array to store the wave function values + * @param stride the stride of the phi array between two adjacent meshgrids + * @param phi array to store the wave function values */ template - void get_psi(const std::vector coords, const int stride, T* psi); + void set_phi(const std::vector coords, const int stride, T* phi); /** * @brief Get the wave function values and its derivative * * The reason for combining the functions to solve the wave function values * and wave function derivatives into one function is to improve efficiency. - * psi[(n-1)*stride] ~ psi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid + * phi[(n-1)*stride] ~ phi[(n-1)*stride + nw] store the wave function values of the first atom at the nth meshgrid * * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom - * @param stride the stride of the psi array between two adjacent meshgrids - * @param psi array to store the wave function values - * @param dpsi_x array to store the derivative wave functions in x direction - * @param dpsi_y array to store the derivative wave functions in y direction - * @param dpsi_z array to store the derivative wave functions in z direction + * @param stride the stride of the phi array between two adjacent meshgrids + * @param phi array to store the wave function values + * @param dphi_x array to store the derivative wave functions in x direction + * @param dphi_y array to store the derivative wave functions in y direction + * @param dphi_z array to store the derivative wave functions in z direction */ template - void get_psi_dpsir( + void set_phi_dphi( const std::vector coords, const int stride, - T* psi, T* dpsi_x, T* dpsi_y, T* dpsi_z); + T* phi, T* dphi_x, T* dphi_y, T* dphi_z); /** * @brief Get the wave function values and its second derivative * - * ddpsi[(n-1)*stride] ~ ddpsi[(n-1)*stride + nw] store the second derivative of + * ddphi[(n-1)*stride] ~ ddphi[(n-1)*stride + nw] store the second derivative of * wave function values of the atom at the first meshgrid * * @param coords the cartesian coordinates of the meshgrids of a biggrid relative to the atom - * @param stride the stride of the psi array between two adjacent meshgrids - * @param ddpsi_xx array to store the second derivative wave functions in xx direction - * @param ddpsi_xy array to store the second derivative wave functions in xy direction - * @param ddpsi_xz array to store the second derivative wave functions in xz direction - * @param ddpsi_yy array to store the second derivative wave functions in yy direction - * @param ddpsi_yz array to store the second derivative wave functions in yz direction - * @param ddpsi_zz array to store the second derivative wave functions in zz direction + * @param stride the stride of the phi array between two adjacent meshgrids + * @param ddphi_xx array to store the second derivative wave functions in xx direction + * @param ddphi_xy array to store the second derivative wave functions in xy direction + * @param ddphi_xz array to store the second derivative wave functions in xz direction + * @param ddphi_yy array to store the second derivative wave functions in yy direction + * @param ddphi_yz array to store the second derivative wave functions in yz direction + * @param ddphi_zz array to store the second derivative wave functions in zz direction */ template - void get_ddpsir( + void set_ddphi( const std::vector coords, const int stride, - T* ddpsi_xx, T* ddpsi_xy, T* ddpsi_xz, - T* ddpsi_yy, T* ddpsi_yz, T* ddpsi_zz); + T* ddphi_xx, T* ddphi_xy, T* ddphi_xz, + T* ddphi_yy, T* ddphi_yz, T* ddphi_zz); private: // the atom object @@ -93,6 +95,9 @@ class GintAtom // the global index of the atom int iat_; + // the global index of the atom among the same type of atoms + int ia_; + // the index of big grid which contains this atom Vec3i biggrid_idx_; @@ -108,6 +113,6 @@ class GintAtom // should be a member of the Atom class, not the GintAtom class const Numerical_Orbital* orb_; -} +}; } // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index 9d85d8f907..6fceda0627 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -1,6 +1,7 @@ #pragma once #include "gint_type.h" +#include "module_base/timer.h" namespace Gint { @@ -19,7 +20,8 @@ namespace Gint return Vec3i(id_x, id_y, id_z); }; - // if exponent is an integer between 0 and 5 (the most common cases in gint), + // if exponent is an integer between 0 and 5 (the most common cases in gint) and + // and exp is a variable that cannot be determined at compile time (which means the compiler cannot optimize the code), // pow_int is much faster than std::pow inline double pow_int(const double base, const int exp) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index f4f72bc92f..39189fde03 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include "module_parameter/parameter.h" #include "gint_info.h" #include "gint_type.h" @@ -7,17 +8,16 @@ namespace Gint { GintInfo::GintInfo( - Vec3d unitcell_vec1, - Vec3d unitcell_vec2, - Vec3d unitcell_vec3, int nbx, int nby, int nbz, int nmx, int nmy, int nmz, int startidx_bx, int startidx_by, int startidx_bz, int nbx_local, int nby_local, int nbz_local, - int ntype, Atom* atoms, Numerical_Orbital* Phi) + const Numerical_Orbital* Phi, + const UnitCell& ucell, Grid_Driver& gd) + : ucell_(&ucell) { // initialize the unitcell information - unitcell_info_ = std::make_shared(unitcell_vec1, unitcell_vec2, unitcell_vec3, + unitcell_info_ = std::make_shared(ucell_->a1, ucell_->a2, ucell_->a3, nbx, nby, nbz, nmx, nmy, nmz); // initialize the divide information @@ -30,15 +30,33 @@ GintInfo::GintInfo( // initialize the biggrids for (int i = 0; i < localcell_info_->get_biggrid_num(); i++) { - biggrids_.emplace_back( + biggrids_.push_back( std::make_shared(localcell_info_->get_bgrid_global_idx_1D(i), localcell_info_)); } + is_atom_in_proc_ = std::vector(ucell.nat, false); + // initialize the atoms - init_atoms_(ntype, atoms, Phi); + init_atoms_(ucell_->ntype, ucell_->atoms, Phi); + + // initialize the ijr_info + init_ijr_info_(ucell, gd); +} + +template +std::shared_ptr> GintInfo::get_hr(int npol) const +{ + auto p_hr = std::make_shared>(ucell_->nat); + if(PARAM.inp.gamma_only) + { + p_hr->fix_gamma(); + } + p_hr->insert_ijrs(&ijr_info_, *ucell_, npol); + p_hr->allocate(nullptr, true); + return p_hr; } -void GintInfo::init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi) +void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital* Phi) { int iat = 0; const Matrix3 biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); @@ -52,64 +70,64 @@ void GintInfo::init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi) + biggrid_GT.e23 * biggrid_GT.e23 + biggrid_GT.e33 * biggrid_GT.e33); -#pragma omp parallel for schedule(dynamic) +// TODO: USE OPENMP TO PARALLELIZE THIS LOOP for(int i = 0; i < ntype; i++) { const auto atom = atoms[i]; const auto *orb = &Phi[i]; - // rcut extends to the maximum big grids in x, y, z directions - int rcut_bgrid_x = static_cast(atom.Rcut * g1) + 1; - int rcut_bgrid_y = static_cast(atom.Rcut * g2) + 1; - int rcut_bgrid_z = static_cast(atom.Rcut * g3) + 1; - double rcut_ucell_x = rcut_bgrid_x / (double)unitcell_info_->get_nbx(); - double rcut_ucell_y = rcut_bgrid_y / (double)unitcell_info_->get_nby(); - double rcut_ucell_z = rcut_bgrid_z / (double)unitcell_info_->get_nbz(); + // rcut extends to the maximum big grids in x, y, z directions + int ext_bgrid_x = static_cast(atom.Rcut * g1) + 1; + int ext_bgrid_y = static_cast(atom.Rcut * g2) + 1; + int ext_bgrid_z = static_cast(atom.Rcut * g3) + 1; for(int j = 0; j < atom.na; j++) { - const Vec3i biggrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); - const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(biggrid_idx); - int min_x = static_cast(std::floor(atom.taud[j].x - rcut_ucell_x)); - int max_x = static_cast(std::floor(atom.taud[j].x + rcut_ucell_x)); - int min_y = static_cast(std::floor(atom.taud[j].y - rcut_ucell_y)); - int max_y = static_cast(std::floor(atom.taud[j].y + rcut_ucell_y)); - int min_z = static_cast(std::floor(atom.taud[j].z - rcut_ucell_z)); - int max_z = static_cast(std::floor(atom.taud[j].z + rcut_ucell_z)); - for(int k = min_x; k <= max_x; k++) + const Vec3i atom_bgrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); + const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(atom_bgrid_idx); + std::map> gint_atom_map; + for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++) { - for(int l = min_y; l <= max_y; l++) + for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid_y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid_y; bgrid_y++) { - for(int m = min_z; m <= max_z; m++) + for(int bgrid_z = atom_bgrid_idx.z - ext_bgrid_z; bgrid_z <= atom_bgrid_idx.z + ext_bgrid_z; bgrid_z++) { - const Vec3i atom_idx_ext(biggrid_idx.x + k * unitcell_info_->get_nbx(), - biggrid_idx.y + l * unitcell_info_->get_nby(), - biggrid_idx.z + m * unitcell_info_->get_nbz()); - const Vec3i unitcell_idx(k, l, m); - auto gint_atom = std::make_shared(&atom, iat, atom_idx_ext, unitcell_idx, tau_in_biggrid, orb); - #pragma omp critical - { atoms_.push_back(gint_atom); } - for(int bx = atom_idx_ext.x - rcut_bgrid_x; bx <= atom_idx_ext.x + rcut_bgrid_x; bx++) + // get the extended biggrid idx of the affected biggrid + const Vec3i ext_bgrid_idx(bgrid_x, bgrid_y, bgrid_z); + const Vec3i normal_bgrid_idx = unitcell_info_->map_ext_idx_to_ucell(ext_bgrid_idx); + if(localcell_info_->is_bgrid_in_lcell(normal_bgrid_idx) == false) + { + continue; + } + const int bgrid_local_idx = localcell_info_->get_bgrid_local_idx_1D(normal_bgrid_idx); + // get the unitcell idx of the extended atom + const Vec3i unitcell_idx = - unitcell_info_->get_unitcell_idx(ext_bgrid_idx); + auto it = gint_atom_map.find(unitcell_idx); + // if the gint_atom is not in the map, + // it means this is the first time we find this atom may affect some biggrids. + if(it == gint_atom_map.end()) + { + Vec3i ext_atom_bgrid_idx(atom_bgrid_idx.x + unitcell_idx.x * unitcell_info_->get_nbx(), + atom_bgrid_idx.y + unitcell_idx.y * unitcell_info_->get_nby(), + atom_bgrid_idx.z + unitcell_idx.z * unitcell_info_->get_nbz()); + auto gint_atom = std::make_shared(&atom, j, iat, ext_atom_bgrid_idx, unitcell_idx, tau_in_biggrid, orb); + gint_atom_map[unitcell_idx] = gint_atom; + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom)) + { + #pragma omp critical + { + biggrids_[bgrid_local_idx]->add_atom(gint_atom); + atoms_.push_back(gint_atom); + is_atom_in_proc_[iat] = true; + } + } + } else { - for(int by = atom_idx_ext.y - rcut_bgrid_y; by <= atom_idx_ext.y + rcut_bgrid_y; by++) + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[unitcell_idx])) { - for(int bz = atom_idx_ext.z - rcut_bgrid_z; bz <= atom_idx_ext.z + rcut_bgrid_z; bz++) + #pragma omp critical { - const Vec3i biggrid_idx = unitcell_info_->map_ext_idx_to_ucell(Vec3i(bx, by, bz)); - if (localcell_info_->is_bgrid_in_lcell(biggrid_idx)) - { - const auto biggrid = biggrids_[localcell_info_->get_bgrid_local_idx_1D(biggrid_idx)]; - const auto meshgrid_coords = biggrid->get_mgrid_coords(*gint_atom); - for(const auto& coord : meshgrid_coords) - { - if(coord.norm() < atom.Rcut) - { - #pragma omp critical - { biggrid->add_atom(gint_atom);} - break; - } - } - } + biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[unitcell_idx]); } } } @@ -120,4 +138,75 @@ void GintInfo::init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi) } } } + +void GintInfo::init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd) +{ + hamilt::HContainer hRGint_local(ucell.nat); + + // prepare the row_index and col_index for construct AtomPairs, they are + // same, name as orb_index + std::vector orb_index(ucell.nat + 1); + orb_index[0] = 0; + for (int i = 1; i < orb_index.size(); i++) { + int type = ucell.iat2it[i - 1]; + orb_index[i] = orb_index[i - 1] + ucell.atoms[type].nw; + } + + for (int T1 = 0; T1 < ucell.ntype; ++T1) { + const Atom* atom1 = &(ucell.atoms[T1]); + for (int I1 = 0; I1 < atom1->na; ++I1) { + auto& tau1 = atom1->tau[I1]; + const int iat1 = ucell.itia2iat(T1, I1); + // whether this atom is in this processor. + if (this->is_atom_in_proc_[iat1]) { + gd.Find_atom(ucell, tau1, T1, I1); + for (int ad = 0; ad < gd.getAdjacentNum() + 1; ++ad) { + const int T2 = gd.getType(ad); + const int I2 = gd.getNatom(ad); + const int iat2 = ucell.itia2iat(T2, I2); + const Atom* atom2 = &(ucell.atoms[T2]); + + // NOTE: hRGint wil save total number of atom pairs, + // if only upper triangle is saved, the lower triangle will + // be lost in 2D-block parallelization. if the adjacent atom + // is in this processor. + if (this->is_atom_in_proc_[iat2]) { + Vec3d dtau = gd.getAdjacentTau(ad) - tau1; + double distance = dtau.norm() * ucell.lat0; + double rcut = atom1->Rcut + atom2->Rcut; + + // if(distance < rcut) + // mohan reset this 2013-07-02 in Princeton + // we should make absolutely sure that the distance is + // smaller than rcuts[it] 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 + // rcuts[it] = 7.0000000000000008 + if (distance < rcut - 1.0e-15) { + // calculate R index + auto& R_index = gd.getBox(ad); + // insert this atom-pair into this->hRGint + hamilt::AtomPair tmp_atom_pair( + iat1, + iat2, + R_index.x, + R_index.y, + R_index.z, + orb_index.data(), + orb_index.data(), + ucell.nat); + hRGint_local.insert_pair(tmp_atom_pair); + } + } + } + } + } + } + this->ijr_info_ = hRGint_local.get_ijr_info(); + return; +} + +template std::shared_ptr> GintInfo::get_hr(int npol) const; +template std::shared_ptr>> GintInfo::get_hr>(int npol) const; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index 9f3427a869..c852defbd5 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -2,7 +2,10 @@ #include #include +#include "module_cell/module_neighbor/sltk_grid_driver.h" +#include "module_cell/unitcell.h" #include "module_cell/atom_spec.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "gint_type.h" #include "biggrid.h" #include "gint_atom.h" @@ -18,18 +21,30 @@ class GintInfo public: // constructor GintInfo( - Vec3d unitcell_vec1, - Vec3d unitcell_vec2, - Vec3d unitcell_vec3, int nbx, int nby, int nbz, int nmx, int nmy, int nmz, int startidx_bx, int startidx_by, int startidx_bz, int nbx_local, int nby_local, int nbz_local, - int ntype, Atom* atoms, Numerical_Orbital* Phi); + const Numerical_Orbital* Phi, + const UnitCell& ucell, Grid_Driver& gd); + // getter functions + std::vector> get_biggrids() const { return biggrids_; }; + + //========================================= + // functions about hcontainer + //========================================= + template + std::shared_ptr> get_hr(int npol = 1) const; + private: // initialize the atoms - void init_atoms_(int ntype, Atom* atoms, Numerical_Orbital* Phi); + void init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital* Phi); + + // initialize the ijr_info + void init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd); + + const UnitCell* ucell_; // the unitcell information std::shared_ptr unitcell_info_; @@ -44,7 +59,14 @@ class GintInfo std::vector> biggrids_; // the total atoms in the unitcell(include extended unitcell) + // Not Used Now std::vector> atoms_; -} + + // if the iat-th(global index) atom is in this processor, return true + std::vector is_atom_in_proc_; + + // format for storing atomic pair information in hcontainer, used for initializing hcontainer + std::vector ijr_info_; +}; } // namespace Gint diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp new file mode 100644 index 0000000000..ce64e8c475 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -0,0 +1,90 @@ +#include "module_base/array_pool.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" +#include "gint_vl.h" +#include "phi_operator.h" + +namespace Gint +{ + +void Gint_vl::cal_gint() +{ + init_hRGint_(); + cal_hRGint_(); + compose_hRGint_(); + transfer_hRGint_to_hR_(); +} + +//======================== +// Private functions +//======================== + +void Gint_vl::init_hRGint_() +{ + hRGint_ = gint_info_->get_hr(); +} + +void Gint_vl::cal_hRGint_() +{ + for(const auto& biggrid: gint_info_->get_biggrids()) + { + PhiOperator phi_op(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi(phi.get_ptr_1D()); + phi_op.phi_mul_vldr3(vr_eff_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), hRGint_.get()); + } +} + +void Gint_vl::compose_hRGint_() +{ + for (int iap = 0; iap < hRGint_->size_atom_pairs(); iap++) + { + auto& ap = hRGint_->get_atom_pair(iap); + const int iat1 = ap.get_atom_i(); + const int iat2 = ap.get_atom_j(); + if (iat1 > iat2) + { + // fill lower triangle matrix with upper triangle matrix + // the upper is + const hamilt::AtomPair* upper_ap = hRGint_->find_pair(iat2, iat1); + const hamilt::AtomPair* lower_ap = hRGint_->find_pair(iat1, iat2); +#ifdef __DEBUG + assert(upper_ap != nullptr); +#endif + for (int ir = 0; ir < ap.get_R_size(); ir++) + { + auto R_index = ap.get_R_index(ir); + auto upper_mat = upper_ap->find_matrix(-R_index); + auto lower_mat = lower_ap->find_matrix(R_index); + for (int irow = 0; irow < upper_mat->get_row_size(); ++irow) + { + for (int icol = 0; icol < upper_mat->get_col_size(); ++icol) + { + lower_mat->get_value(icol, irow) = upper_ap->get_value(irow, icol); + } + } + } + } + } +} + +void Gint_vl::transfer_hRGint_to_hR_() +{ +#ifdef __MPI + int size = 0; + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size == 1) + { + hR_->add(*hRGint_); + } + else + { + hamilt::transferSerials2Parallels(*hRGint_, hR_); + } +#else + hR_->add(*hRGint_); +#endif +} + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h new file mode 100644 index 0000000000..b17e93389f --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint_info.h" + +namespace Gint +{ + +class Gint_vl +{ + public: + Gint_vl( + std::shared_ptrgint_info, + double* vr_eff, + hamilt::HContainer* hR) + : gint_info_(gint_info), vr_eff_(vr_eff), hR_(hR){}; + + void cal_gint(); + + private: + + void init_hRGint_(); + + // note that only the upper triangle matrix of hR is calculated + // that's why we need compose_hRGint_() to fill the lower triangle matrix. + void cal_hRGint_(); + + void compose_hRGint_(); + + void transfer_hRGint_to_hR_(); + + std::shared_ptr gint_info_; + + // input + double* vr_eff_; + + // output + hamilt::HContainer* hR_; + + //======================== + // Intermediate variables + //======================== + std::shared_ptr> hRGint_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index 355b033b56..94a5b0ab9f 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -75,6 +75,12 @@ namespace Gint return biggrid_idx_3Dto1D(get_bgrid_local_idx_3D(idx_3d)); } + Vec3d LocalCellInfo::get_bgrid_global_coord_3D(const int index_1d) const + { + Vec3i ucell_idx_3d = get_bgrid_global_idx_3D(index_1d); + return unitcell_info_->get_biggrid_coord(ucell_idx_3d); + } + bool LocalCellInfo::is_bgrid_in_lcell(const Vec3i index_3d) const { return (index_3d.x >= startidx_bx_ && index_3d.x < startidx_bx_ + nbx_ && diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 274f3d7d76..56736a134e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -55,6 +55,9 @@ class LocalCellInfo // transform the 3D index of a big grid in the unit cell to the 1D index in the local cell int get_bgrid_local_idx_1D(const Vec3i index_3d) const; + // get the cartesian coordinate of a big grid in the unit cell from the 1D index + Vec3d get_bgrid_global_coord_3D(const int index_1d) const; + // the input is the 3D index of a big grid in the unitcell // return true if the big grid is in the local cell bool is_bgrid_in_lcell(const Vec3i index_3d) const; @@ -117,6 +120,6 @@ class LocalCellInfo // information about the big grid std::shared_ptr biggrid_info_; -} +}; } // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp similarity index 51% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp rename to source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index da530bb2e7..57d7fc8e40 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -1,42 +1,58 @@ -#include "psi_operator.h" +#include "phi_operator.h" #include "module_base/blas_connector.h" namespace Gint { -int PsiOperator::atom_pair_startidx_(int a, int b) const +PhiOperator::PhiOperator(std::shared_ptr biggrid) +: biggrid_(biggrid) { - for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + rows_ = biggrid_->get_biggrid_info()->get_nmxyz(); + cols_ = biggrid_->get_mgrid_phi_len(); + is_atom_on_mgrids_ = biggrid_->get_is_atom_on_mgrids(); + meshgrid_coords_ = biggrid_->get_mgrid_coords(); + atom_startidx_ = biggrid_->get_atom_startidx(); + atom_phi_len_ = biggrid_->get_atom_phi_len(); +} + +void PhiOperator::set_phi(double* phi) const +{ + for(const auto& atom : biggrid_->get_atoms()) { - if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) - { - return i; - } + atom->set_phi(meshgrid_coords_, cols_, phi); + phi += atom->get_nw(); } } -int PsiOperator::atom_pair_endidx_(int a, int b) const +void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const { - for(int i = biggrid_->get_meshgrid_num() - 1; i >= 0; --i) + for(const auto& atom : biggrid_->get_atoms()) { - if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) - { - return i; - } + atom->set_phi_dphi(meshgrid_coords_, cols_, phi, dphi_x, dphi_y, dphi_z); + phi += atom->get_nw(); + dphi_x += atom->get_nw(); + dphi_y += atom->get_nw(); + dphi_z += atom->get_nw(); } } -PsiOperator::PsiOperator(std::shared_ptr biggrid) -: biggrid_(biggrid) +void PhiOperator::set_ddphi( + double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, + double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const { - rows_ = biggrid_->get_biggrid_info()->get_nmxyz(); - cols_ = biggrid_->get_mgrid_psi_len(); - is_atom_on_mgrid_ = biggrid_->get_is_atom_on_mgrid(); - atom_startidx_ = biggrid_->get_atom_startidx(); - atom_psi_len_ = biggrid_->get_atom_psi_len(); + for(const auto& atom : biggrid_->get_atoms()) + { + atom->set_ddphi(meshgrid_coords_, cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); + ddphi_xx += atom->get_nw(); + ddphi_xy += atom->get_nw(); + ddphi_xz += atom->get_nw(); + ddphi_yy += atom->get_nw(); + ddphi_yz += atom->get_nw(); + ddphi_zz += atom->get_nw(); + } } -void PsiOperator::psi_times_dm(const hamilt::HContainer& DM, const double* const* psi, double** result, const bool is_symm) const +void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* const* phi, double** result, const bool is_symm) const { // parameters for lapack subroutines constexpr char side = 'L'; @@ -54,8 +70,8 @@ void PsiOperator::psi_times_dm(const hamilt::HContainer& DM, const doubl if(is_symm) { const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_i->get_iat(), 0, 0, 0); - dsymm_(&side, &uplo, &atom_psi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atom_psi_len_[i], - &psi[0][atom_startidx_[i]], &cols_, &beta, &result[0][atom_startidx_[i]], &cols_); + dsymm_(&side, &uplo, &atom_phi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atom_phi_len_[i], + &phi[0][atom_startidx_[i]], &cols_, &beta, &result[0][atom_startidx_[i]], &cols_); } const int start = is_symm ? i + 1 : 0; @@ -83,30 +99,30 @@ void PsiOperator::psi_times_dm(const hamilt::HContainer& DM, const doubl continue; } - dgemm_(&trans, &trans, &atom_psi_len_[j], &len, &atom_psi_len_[i], &alpha1, dm_mat->get_pointer(), &atom_psi_len_[j], - &psi[start_idx][atom_startidx_[i]], &cols_, &beta, &result[start_idx][atom_startidx_[j]], &cols_); + dgemm_(&trans, &trans, &atom_phi_len_[j], &len, &atom_phi_len_[i], &alpha1, dm_mat->get_pointer(), &atom_phi_len_[j], + &phi[start_idx][atom_startidx_[i]], &cols_, &beta, &result[start_idx][atom_startidx_[j]], &cols_); } } } -void PsiOperator::psi_times_vldr3(const double* vldr3, const double* const* psi, double** result) const +void PhiOperator::phi_mul_vldr3(const double* vldr3, const double* const* phi, double** result) const { for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) { for(int j = 0; j < biggrid_->get_atom_num(); j++) { - for(int k = 0; k < atom_psi_len_[j]; k++) + for(int k = 0; k < atom_phi_len_[j]; k++) { const int idx = atom_startidx_[j]; - result[i][idx + k] = psi[i][idx + k] * vldr3[i]; + result[i][idx + k] = phi[i][idx + k] * vldr3[i]; } } } } -void PsiOperator::psi_times_psi_vldr3( - const double* const* psi, - const double* const* psi_vldr3, +void PhiOperator::phi_mul_phi_vldr3( + const double* const* phi, + const double* const* phi_vldr3, hamilt::HContainer* hr) const { const char transa='N', transb='T'; @@ -116,11 +132,20 @@ void PsiOperator::psi_times_psi_vldr3( { const auto atom_i = biggrid_->get_atoms()[i]; const auto r_i = atom_i->get_r(); + const int iat_i = atom_i->get_iat(); for(int j = i; j < biggrid_->get_atom_num(); ++j) { const auto atom_j = biggrid_->get_atoms()[j]; const auto r_j = atom_j->get_r(); + const int iat_j = atom_j->get_iat(); + + // only calculate the upper triangle matrix + if(iat_i > iat_j) + { + continue; + } + // FIXME may be r = r_j - r_i const auto result = hr->find_matrix(atom_i->get_iat(), atom_j->get_iat(), r_i-r_j); @@ -138,11 +163,35 @@ void PsiOperator::psi_times_psi_vldr3( continue; } - dgemm_(&transa, &transb, &atom_psi_len_[j], &atom_psi_len_[i], &len, &alpha, &psi_vldr3[start_idx][atom_startidx_[j]], - &cols_,&psi[start_idx][atom_startidx_[i]], &cols_, &beta, result->get_pointer(), &atom_psi_len_[j]); + dgemm_(&transa, &transb, &atom_phi_len_[j], &atom_phi_len_[i], &len, &alpha, &phi_vldr3[start_idx][atom_startidx_[j]], + &cols_,&phi[start_idx][atom_startidx_[i]], &cols_, &beta, result->get_pointer(), &atom_phi_len_[j]); + } + } +} + +//=============================== +// private methods +//=============================== +int PhiOperator::atom_pair_startidx_(int a, int b) const +{ + for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + { + if(is_atom_on_mgrids_[a][i] && is_atom_on_mgrids_[b][i]) + { + return i; } } } +int PhiOperator::atom_pair_endidx_(int a, int b) const +{ + for(int i = biggrid_->get_meshgrid_num() - 1; i >= 0; --i) + { + if(is_atom_on_mgrids_[a][i] && is_atom_on_mgrids_[b][i]) + { + return i; + } + } +} } // namespace Gint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h new file mode 100644 index 0000000000..34c2ac028f --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include +#include +#include "biggrid.h" + +namespace Gint +{ + +/** + * @brief The class phiOperator is used to perform operations on the wave function matrix phi, dphi, etc. + * + * In fact, the variables and functions of this class could be placed in the BigGrid class, but the lifecycle of the BigGrid class is relatively long. + * We do not want the BigGrid to contain too many member variables, as this could lead to excessive memory usage. + * Therefore, we separate this class out, so it can be destroyed after use. + */ +class PhiOperator +{ + public: + // constructor + PhiOperator(std::shared_ptr biggrid); + + // getter + int get_rows() const {return rows_;}; + int get_cols() const {return cols_;}; + + // get phi of the big grid + // the dimension of phi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void set_phi(double* phi) const; + + // get phi and the gradient of phi of the big grid + // the dimension of phi and dphi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const; + + // get the hessian of the wave function values of the big grid + // the dimension of ddphi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + void set_ddphi( + double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, + double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const; + + void phi_mul_dm( + const hamilt::HContainer& DM, + const double* const* phi, + double** result, + const bool is_symm) const; + + void phi_mul_vldr3( + const double* vldr3, + const double* const* phi, + double** result) const; + + void phi_mul_phi_vldr3( + const double* const* phi, + const double* const* phi_vldr3, + hamilt::HContainer* hr) const; + + + private: + + // get the index of the first meshgrid that both atom a and atom b affect + int atom_pair_startidx_(int a, int b) const; + + // get the index of the last meshgrid that both atom a and atom b affect + int atom_pair_endidx_(int a, int b) const; + + // the row number of the phi matrix + // rows_ = biggrid_->get_meshgrid_num() + int rows_; + + // the column number of the phi matrix + // cols_ = biggrid_->get_mgrid_phi_len() + int cols_; + + // the coordinates of the meshgrids + std::vector meshgrid_coords_; + + // the big grid that the phi matrix is associated with + std::shared_ptr biggrid_; + + // record whether the atom affects the meshgrid + // is_atom_on_mgrids_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false + std::vector> is_atom_on_mgrids_; + + // the start index of the phi of each atom + std::vector atom_startidx_; + + // the length of phi of each atom + // atom_phi_len_[i] = biggrid_->get_atoms()[i]->get_nw() + std::vector atom_phi_len_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h deleted file mode 100644 index 4805b6a8be..0000000000 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/psi_operator.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include -#include -#include -#include "biggrid.h" - -namespace Gint -{ - -/** - * @brief The class PsiOperator is used to perform operations on the wave function matrix psi, dpsi, etc. - * - * In fact, the variables and functions of this class could be placed in the BigGrid class, but the lifecycle of the BigGrid class is relatively long. - * We do not want the BigGrid to contain too many member variables, as this could lead to excessive memory usage. - * Therefore, we separate this class out, so it can be destroyed after use. - */ -class PsiOperator -{ - public: - // constructor - PsiOperator(std::shared_ptr biggrid); - - void psi_times_dm( - const hamilt::HContainer& DM, - const double* const* psi, - double** result, - const bool is_symm) const; - - void psi_times_vldr3( - const double* vldr3, - const double* const* psi, - double** result) const; - - void psi_times_psi_vldr3( - const double* const* psi, - const double* const* psi_vldr3, - hamilt::HContainer* hr) const; - - - private: - - // get the index of the first meshgrid that both atom a and atom b affect - int atom_pair_startidx_(int a, int b) const; - - // get the index of the last meshgrid that both atom a and atom b affect - int atom_pair_endidx_(int a, int b) const; - - // the row number of the psi matrix - // rows_ = biggrid_->get_meshgrid_num() - int rows_; - - // the column number of the psi matrix - // cols_ = biggrid_->get_mgrid_psi_len() - int cols_; - - // the big grid that the psi matrix is associated with - std::shared_ptr biggrid_; - - // record whether the atom affects the meshgrid - // is_atom_on_mgrid_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false - std::vector> is_atom_on_mgrid_; - - // the start index of the psi of each atom - std::vector atom_startidx_; - - // the length of psi of each atom - // atom_psi_len_[i] = biggrid_->get_atoms()[i]->get_nw() - std::vector atom_psi_len_; -} - -} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp similarity index 74% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp rename to source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index 47fa3aee80..fc8962d1f3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/get_ddpsi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -1,15 +1,19 @@ +#include "module_base/array_pool.h" +#include "module_base/timer.h" +#include "module_base/ylm.h" #include "gint_atom.h" +#include "gint_helper.h" namespace Gint { template -void GintAtom::get_ddpsir( +void GintAtom::set_ddphi( const std::vector coords, const int stride, - T* ddpsi_xx, T* ddpsi_xy, T* ddpsi_xz, - T* ddpsi_yy, T* ddpsi_yz, T* ddpsi_zz) + T* ddphi_xx, T* ddphi_xy, T* ddphi_xz, + T* ddphi_yy, T* ddphi_yz, T* ddphi_zz) { - ModuleBase::timer::tick("GintAtom", "get_ddpsir"); + ModuleBase::timer::tick("GintAtom", "set_ddphi"); const int num_mgrids = coords.size(); @@ -19,26 +23,26 @@ void GintAtom::get_ddpsir( // store the pointer to reduce repeated address fetching std::vector p_psi_uniform(atom_->nw); std::vector p_dpsi_uniform(atom_->nw); - std::vector p_d2psi_uniform(atom_->nw); - std::vector psi_nr_uniform(atom_->nw); - for (int iw=0; iw< atom->nw; ++iw) + std::vector p_ddpsi_uniform(atom_->nw); + std::vector phi_nr_uniform(atom_->nw); + for (int iw=0; iw< atom_->nw; ++iw) { - if ( atom->iw2_new[iw] ) + if ( atom_->iw2_new[iw] ) { int l = atom_->iw2l[iw]; int n = atom_->iw2n[iw]; p_psi_uniform[iw] = orb_->PhiLN(l, n).psi_uniform.data(); p_dpsi_uniform[iw] = orb_->PhiLN(l, n).dpsi_uniform.data(); - p_d2psi_uniform[iw] = orb_->PhiLN(l, n).d2psi_uniform.data(); - psi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; + p_ddpsi_uniform[iw] = orb_->PhiLN(l, n).ddpsi_uniform.data(); + phi_nr_uniform[iw] = orb_->PhiLN(l, n).nr_uniform; } } std::vector rly(std::pow(atom_->nwl + 1, 2)); ModuleBase::Array_Pool grly(std::pow(atom_->nwl + 1, 2), 3); - // TODO: A better data structure such as a 3D tensor can be used to store dpsi - std::vector> dpsi(6, ModuleBase::Array_Pool(6, 3)); - std::vector coord1(3); + // TODO: A better data structure such as a 3D tensor can be used to store dphi + std::vector>> dphi(6, std::vector>(6, std::vector(3))); + Vec3d coord1; ModuleBase::Array_Pool displ(6, 3); displ[0][0] = 0.0001; // in x direction displ[1][0] = -0.0001; @@ -50,24 +54,19 @@ void GintAtom::get_ddpsir( for(int im = 0; im < num_mgrids; im++) { const Vec3d& coord = coords[im]; - const double dist = coord.norm(); - - // avoid division by zero - if(dist < 1e-9) - { - dist = 1e-9; - } + // 1e-9 is to avoid division by zero + const double dist = coord.norm() < 1e-9 ? 1e-9 : coord.norm(); if(dist > orb_->getRcut()) { // if the distance is larger than the cutoff radius, // the wave function values are all zeros - ModuleBase::GlobalFunc::ZEROS(ddpsi_xx + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(ddpsi_xy + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(ddpsi_xz + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(ddpsi_yy + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(ddpsi_yz + im * stride, atom_->nw); - ModuleBase::GlobalFunc::ZEROS(ddpsi_zz + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_xx + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_xy + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_xz + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_yy + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_yz + im * stride, atom_->nw); + ModuleBase::GlobalFunc::ZEROS(ddphi_zz + im * stride, atom_->nw); continue; } @@ -78,14 +77,9 @@ void GintAtom::get_ddpsir( coord1[2] = coord[2] + displ[i][2]; // sphereical harmonics - ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord1[0], coord1[1], coord1[2], rly, grly.get_ptr_2D()); + ModuleBase::Ylm::grad_rl_sph_harm(atom_->nwl, coord1[0], coord1[1], coord1[2], rly.data(), grly.get_ptr_2D()); - const double dist1 = coord1.norm(); - - if(dist1 < 1e-9) - { - dist1 = 1e-9; - } + const double dist1 = coord1.norm() < 1e-9 ? 1e-9 : coord1.norm(); const double position = dist1 / dr_uniform; const int ip = static_cast(position); @@ -105,7 +99,7 @@ void GintAtom::get_ddpsir( auto psi_uniform = p_psi_uniform[iw]; auto dpsi_uniform = p_dpsi_uniform[iw]; - if(ip >= psi_nr_uniform[iw] - 4) + if(ip >= phi_nr_uniform[iw] - 4) { tmp = dtmp = 0.0; } @@ -132,24 +126,24 @@ void GintAtom::get_ddpsir( const double tmpdphi_rly = (dtmp - tmp * ll / dist1) / rl * rly[idx_lm] / dist1; const double tmprl = tmp / rl; - dpsi[iw][i][0] = tmpdphi_rly * coord1[0] + tmprl * grly[idx_lm][0]; - dpsi[iw][i][1] = tmpdphi_rly * coord1[1] + tmprl * grly[idx_lm][1]; - dpsi[iw][i][2] = tmpdphi_rly * coord1[2] + tmprl * grly[idx_lm][2]; + dphi[iw][i][0] = tmpdphi_rly * coord1[0] + tmprl * grly[idx_lm][0]; + dphi[iw][i][1] = tmpdphi_rly * coord1[1] + tmprl * grly[idx_lm][1]; + dphi[iw][i][2] = tmpdphi_rly * coord1[2] + tmprl * grly[idx_lm][2]; } // end iw } // end i for(int iw = 0; iw < atom_->nw; iw++) { int idx = im * stride + iw; - ddpsi_xx[idx] = (dpsi[iw][0][0] - dpsi[iw][1][0]) / 0.0002; - ddpsi_xy[idx] - = ((dpsi[iw][2][0] - dpsi[iw][3][0]) + (dpsi[iw][0][1] - dpsi[iw][1][1])) / 0.0004; - ddpsi_xz[idx] - = ((dpsi[iw][4][0] - dpsi[iw][5][0]) + (dpsi[iw][0][2] - dpsi[iw][1][2])) / 0.0004; - ddpsi_yy[idx] = (dpsi[iw][2][1] - dpsi[iw][3][1]) / 0.0002; - ddpsi_yz[idx] - = ((dpsi[iw][4][1] - dpsi[iw][5][1]) + (dpsi[iw][2][2] - dpsi[iw][3][2])) / 0.0004; - ddpsi_zz[idx] = (dpsi[iw][4][2] - dpsi[iw][5][2]) / 0.0002; + ddphi_xx[idx] = (dphi[iw][0][0] - dphi[iw][1][0]) / 0.0002; + ddphi_xy[idx] + = ((dphi[iw][2][0] - dphi[iw][3][0]) + (dphi[iw][0][1] - dphi[iw][1][1])) / 0.0004; + ddphi_xz[idx] + = ((dphi[iw][4][0] - dphi[iw][5][0]) + (dphi[iw][0][2] - dphi[iw][1][2])) / 0.0004; + ddphi_yy[idx] = (dphi[iw][2][1] - dphi[iw][3][1]) / 0.0002; + ddphi_yz[idx] + = ((dphi[iw][4][1] - dphi[iw][5][1]) + (dphi[iw][2][2] - dphi[iw][3][2])) / 0.0004; + ddphi_zz[idx] = (dphi[iw][4][2] - dphi[iw][5][2]) / 0.0002; } // else @@ -162,7 +156,7 @@ void GintAtom::get_ddpsir( // { // if ( atom->iw2_new[iw] ) // { - // it_d2psi_uniform[iw] = gt.d2psi_u[it*gt.nwmax + iw].data(); + // it_ddpsi_uniform[iw] = gt.d2phi_u[it*gt.nwmax + iw].data(); // } // } // // End of code addition section. @@ -191,10 +185,10 @@ void GintAtom::get_ddpsir( // { // auto psi_uniform = it_psi_uniform[iw]; // auto dpsi_uniform = it_dpsi_uniform[iw]; - // auto ddpsi_uniform = it_d2psi_uniform[iw]; + // auto ddpsi_uniform = it_ddpsi_uniform[iw]; // // if ( iq[id] >= philn.nr_uniform-4) - // if (iq >= it_psi_nr_uniform[iw]-4) + // if (iq >= it_phi_nr_uniform[iw]-4) // { // tmp = dtmp = ddtmp = 0.0; // } @@ -242,29 +236,29 @@ void GintAtom::get_ddpsir( // const double term_1y = dr[1] * term4; // const double term_1z = dr[2] * term4; - // p_ddpsi_xx[iw] + // p_ddphi_xx[iw] // = term_xx * rly[idx_lm] + 2.0 * term_1x * grly[idx_lm][0] + tmp / rl * hrly[idx_lm][0]; - // p_ddpsi_xy[iw] = term_xy * rly[idx_lm] + term_1x * grly[idx_lm][1] + term_1y * grly[idx_lm][0] + // p_ddphi_xy[iw] = term_xy * rly[idx_lm] + term_1x * grly[idx_lm][1] + term_1y * grly[idx_lm][0] // + tmp / rl * hrly[idx_lm][1]; - // p_ddpsi_xz[iw] = term_xz * rly[idx_lm] + term_1x * grly[idx_lm][2] + term_1z * grly[idx_lm][0] + // p_ddphi_xz[iw] = term_xz * rly[idx_lm] + term_1x * grly[idx_lm][2] + term_1z * grly[idx_lm][0] // + tmp / rl * hrly[idx_lm][2]; - // p_ddpsi_yy[iw] + // p_ddphi_yy[iw] // = term_yy * rly[idx_lm] + 2.0 * term_1y * grly[idx_lm][1] + tmp / rl * hrly[idx_lm][3]; - // p_ddpsi_yz[iw] = term_yz * rly[idx_lm] + term_1y * grly[idx_lm][2] + term_1z * grly[idx_lm][1] + // p_ddphi_yz[iw] = term_yz * rly[idx_lm] + term_1y * grly[idx_lm][2] + term_1z * grly[idx_lm][1] // + tmp / rl * hrly[idx_lm][4]; - // p_ddpsi_zz[iw] + // p_ddphi_zz[iw] // = term_zz * rly[idx_lm] + 2.0 * term_1z * grly[idx_lm][2] + tmp / rl * hrly[idx_lm][5]; // } // iw // } // end if } - ModuleBase::timer::tick("GintAtom", "get_ddpsir"); + ModuleBase::timer::tick("GintAtom", "set_ddphi"); } // explicit instantiation -template void GintAtom::get_ddpsir(const std::vector coords, const int stride, - double* ddpsi_xx, double* ddpsi_xy, double* ddpsi_xz, - double* ddpsi_yy, double* ddpsi_yz, double* ddpsi_zz); +template void GintAtom::set_ddphi(const std::vector coords, const int stride, + double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, + double* ddphi_yy, double* ddphi_yz, double* ddphi_zz); } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index 71a19be246..e66efe6379 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -83,7 +83,7 @@ class UnitCellInfo }; // get the extended unitcell index of a big grid - Vec3i get_extcell_idx(const Vec3i index_3d) const + Vec3i get_unitcell_idx(const Vec3i index_3d) const { return Vec3i(index_3d.x / nbx_, index_3d.y / nby_, index_3d.z / nbz_); }; @@ -164,6 +164,6 @@ class UnitCellInfo // the total number of meshgrids in the unitcell int nmxyz_; -} +}; } // namespace Gint \ No newline at end of file From ad14583046825a085d460a7d5a9b819cd5d00ba0 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 18 Dec 2024 22:47:42 +0800 Subject: [PATCH 07/47] for test --- source/module_esolver/esolver_ks_lcao.h | 3 + source/module_esolver/lcao_before_scf.cpp | 18 +++ .../hamilt_lcaodft/hamilt_lcao.cpp | 4 + .../hamilt_lcaodft/hamilt_lcao.h | 4 + .../operator_lcao/veff_lcao.cpp | 9 +- .../hamilt_lcaodft/operator_lcao/veff_lcao.h | 2 + .../module_gint/gint_tools.cpp | 3 +- .../module_gint/grid_bigcell.cpp | 1 - .../module_gint/grid_technique.cpp | 20 +++ .../module_gint/new_grid_tech/biggrid.cpp | 24 +++- .../module_gint/new_grid_tech/biggrid.h | 7 +- .../new_grid_tech/biggrid_info.cpp | 14 +- .../module_gint/new_grid_tech/biggrid_info.h | 8 +- .../module_gint/new_grid_tech/divide_info.cpp | 2 +- .../module_gint/new_grid_tech/divide_info.h | 2 +- .../module_gint/new_grid_tech/gint_atom.cpp | 2 +- .../module_gint/new_grid_tech/gint_atom.h | 4 +- .../module_gint/new_grid_tech/gint_helper.h | 116 +++++++++++------ .../module_gint/new_grid_tech/gint_info.cpp | 123 ++++++++++++++---- .../module_gint/new_grid_tech/gint_info.h | 5 +- .../module_gint/new_grid_tech/gint_vl.cpp | 8 +- .../module_gint/new_grid_tech/gint_vl.h | 10 +- .../new_grid_tech/localcell_info.cpp | 32 ++++- .../new_grid_tech/localcell_info.h | 7 +- .../module_gint/new_grid_tech/meshgrid_info.h | 9 +- .../new_grid_tech/phi_operator.cpp | 41 +++--- .../module_gint/new_grid_tech/phi_operator.h | 13 +- .../module_gint/new_grid_tech/set_ddphi.cpp | 2 +- .../new_grid_tech/unitcell_info.cpp | 2 +- .../module_gint/new_grid_tech/unitcell_info.h | 20 +-- source/module_io/write_eband_terms.hpp | 12 +- source/module_io/write_vxc.hpp | 6 +- 32 files changed, 380 insertions(+), 153 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index ed2c180bed..6585bb1d30 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -5,6 +5,7 @@ // for grid integration #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" #ifdef __DEEPKS #include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" #endif @@ -75,6 +76,8 @@ class ESolver_KS_LCAO : public ESolver_KS Grid_Technique GridT; + std::shared_ptr gint_info; + TwoCenterBundle two_center_bundle_; rdmft::RDMFT rdmft_solver; // added by jghan for rdmft calculation, 2024-03-16 diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 2637fe41d8..51e3f1d2ac 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -115,6 +115,24 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) dpsi_u, d2psi_u, PARAM.inp.nstream); + + this->gint_info = std::make_shared( + this->pw_big->nbx, + this->pw_big->nby, + this->pw_big->nbz, + this->pw_rho->nx, + this->pw_rho->ny, + this->pw_rho->nz, + 0, + 0, + this->pw_big->nbzp_start, + this->pw_big->nbx, + this->pw_big->nby, + this->pw_big->nbzp, + orb_.Phi, + ucell, + GlobalC::GridD); + psi_u.clear(); psi_u.shrink_to_fit(); dpsi_u.clear(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 69e90ea3b9..3568d8cb15 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -40,6 +40,8 @@ #include "operator_lcao/td_nonlocal_lcao.h" #include "operator_lcao/veff_lcao.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" +#include namespace hamilt { @@ -102,6 +104,8 @@ HamiltLCAO::HamiltLCAO(Gint_Gamma* GG_in, this->sR = new HContainer(paraV); this->hsk = new HS_Matrix_K(paraV); + this->gint_info = gint_info_in; + // Effective potential term (\sum_r ) is registered without template std::vector pot_register_in; if (PARAM.inp.vl_in_h) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index b1603ac93e..6d71c1fb20 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -21,6 +21,8 @@ #ifdef __EXX #include "module_ri/Exx_LRI.h" #endif +#include +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" namespace hamilt { @@ -142,6 +144,8 @@ class HamiltLCAO : public Hamilt const int istep = 0; + std::shared_ptr gint_info; + // sk and hk will be refactored to HamiltLCAO later // std::vector sk; // std::vector hk; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index aeb5d55c01..6de1676e95 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -4,6 +4,7 @@ #include "module_base/tool_title.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_cell/unitcell.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h" namespace hamilt { @@ -148,10 +149,12 @@ void Veff>::contributeHR(void) } else { - Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); - this->GG->cal_vlocal(&inout, this->new_e_iteration); + // Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); + // this->GG->cal_vlocal(&inout, this->new_e_iteration); + ModuleGint::Gint_vl gint_vl(this->gint_info, vr_eff1, this->hR); + gint_vl.cal_gint(); } - this->GG->transfer_pvpR(this->hR,this->ucell); + // this->GG->transfer_pvpR(this->hR,this->ucell); this->new_e_iteration = false; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h index 65f6de8e27..d235c893c7 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h @@ -4,10 +4,12 @@ #include "module_elecstate/potentials/potential_new.h" #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" #include "operator_lcao.h" #include "module_cell/module_neighbor/sltk_grid_driver.h" #include "module_cell/unitcell.h" #include +#include namespace hamilt { diff --git a/source/module_hamilt_lcao/module_gint/gint_tools.cpp b/source/module_hamilt_lcao/module_gint/gint_tools.cpp index 04bf875599..4979947505 100644 --- a/source/module_hamilt_lcao/module_gint/gint_tools.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_tools.cpp @@ -32,7 +32,8 @@ void get_vindex(const int bxyz, const int bx, const int by, const int bz, } } } - } + +} // here vindex refers to local potentials diff --git a/source/module_hamilt_lcao/module_gint/grid_bigcell.cpp b/source/module_hamilt_lcao/module_gint/grid_bigcell.cpp index 2db31ab94b..7f47218096 100644 --- a/source/module_hamilt_lcao/module_gint/grid_bigcell.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_bigcell.cpp @@ -131,7 +131,6 @@ void Grid_BigCell::init_grid_expansion(const UnitCell& ucell,double* rcut) this->dxe = static_cast( this->orbital_rmax * g1) +1; this->dye = static_cast( this->orbital_rmax * g2) +1; this->dze = static_cast( this->orbital_rmax * g3) +1; - //xiaohui add 'PARAM.inp.out_level' line, 2015-09-16 if(PARAM.inp.out_level != "m") ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"extended fft grid",dxe,dye,dze); diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index 5f2facd31d..9b3acd8890 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -10,6 +10,8 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_hsolver/kernels/cuda/helper_cuda.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h" + Grid_Technique::Grid_Technique() { #if ((defined __CUDA) /* || (defined __ROCM) */) if (PARAM.inp.device == "gpu") { @@ -376,8 +378,11 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, int count = 0; this->how_many_atoms = std::vector(nbxx, 0); ModuleBase::Memory::record("GT::how many atoms", sizeof(int) * nbxx); + std::vector coord_x(total_atoms_on_grid* bxyz, 0.0); + std::vector coords3(bxyz * 3, 0.0); for(int iat = 0; iat < ucell.nat; iat++) { + // printf("tau_in_bigcell[%d] = %f %f %f\n", iat, this->tau_in_bigcell[iat][0], this->tau_in_bigcell[iat][1], this->tau_in_bigcell[iat][2]); const int it = ucell.iat2it[iat]; const double rcut_square = this->rcuts[it] * this->rcuts[it]; // zero bigcell of meshball indicate ? @@ -429,14 +434,29 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, this->which_atom[index] = iat; this->which_bigcell[index] = im; this->which_unitcell[index] = index2ucell[extgrid]; + for(int imcell = 0; imcell < this -> bxyz; imcell++) + { + const double dr_x = this->meshcell_pos[imcell][0] + dr_x_part; + coord_x[index * bxyz + imcell] = dr_x; + } ++count; ++how_many_atoms[bcell_idx_on_proc]; } } } + for(int i = 0; i < this->bxyz; i++) + { + for(int j = 0; j < 3; j++) + { + coords3[i * 3 + j] = this->meshcell_pos[i][j]; + } + } assert(count == total_atoms_on_grid); printf("total_atoms_on_grid = %d\n", total_atoms_on_grid); + // writeArrayToFile(this->which_atom.data(), this->which_atom.size(), "which_atom2.txt"); + // writeArrayToFile(coord_x.data(), coord_x.size(), "coord_x2.txt"); + // writeArrayToFile(coords3.data(), coords3.size(), "coords3.txt"); return; } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index e74ac79348..a908bb0cc8 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -1,6 +1,6 @@ #include "biggrid.h" -namespace Gint +namespace ModuleGint { BigGrid::BigGrid(int idx, std::shared_ptr localcell_info) @@ -55,19 +55,24 @@ std::vector BigGrid::get_mgrid_coords() const return coords; } +std::vector BigGrid::get_mgrids_local_idx() const +{ + return localcell_info_->get_mgrids_local_idx_1D(idx_); +} + std::vector BigGrid::get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const { Vec3i this_bgrid_idx = localcell_info_->get_bgrid_global_idx_3D(idx_); // the relative coordinates of this big grid and the atom - Vec3d bgrid_relative_coords + Vec3d bgrid_relative_coord = unitcell_info_->get_relative_coord(bgrid_idx, this_bgrid_idx) + tau_in_bgrid; std::vector coords(biggrid_info_->get_nmxyz()); for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) { - Vec3d mcell_coords = biggrid_info_->get_meshgrid_coord(im); - coords[im] = mcell_coords - bgrid_relative_coords; + Vec3d mcell_coord = biggrid_info_->get_meshgrid_coord(im); + coords[im] = mcell_coord - bgrid_relative_coord; } return coords; } @@ -96,13 +101,18 @@ std::vector> BigGrid::get_is_atom_on_mgrids() const for(const auto& atom : atoms_) { std::vector mcell_coords = get_atom_relative_coords(*atom); - std::vector atom_if_on_mcell; + std::vector atom_if_on_mcell(mcell_coords.size()); for(const auto& coord : mcell_coords) { - coord.norm() <= atom->get_rcut() ? atom_if_on_mcell.push_back(true) : atom_if_on_mcell.push_back(false); + for(int i = 0; i < mcell_coords.size(); ++i) + { + auto coord = mcell_coords[i]; + atom_if_on_mcell[i] = coord.norm() <= atom->get_rcut(); + } } if_on_mcell.push_back(atom_if_on_mcell); } + return if_on_mcell; } -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index f60cb44eed..e22f0c921b 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -8,7 +8,7 @@ #include "unitcell_info.h" #include "gint_atom.h" -namespace Gint +namespace ModuleGint { class BigGrid @@ -47,6 +47,9 @@ class BigGrid // get the coordinates of the meshgrids of the big grid vector get_mgrid_coords() const; + // get the 1D index of the meshgrids in the local cell + vector get_mgrids_local_idx() const; + /** * @brief Get the coordinates of the meshgrids of the big grid relative to an atom * @@ -88,4 +91,4 @@ class BigGrid std::shared_ptr biggrid_info_; }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index 7f9bc858b3..43bd304ab8 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -2,7 +2,7 @@ #include "gint_helper.h" #include "gint_type.h" -namespace Gint +namespace ModuleGint { BigGridInfo::BigGridInfo( @@ -28,6 +28,16 @@ BigGridInfo::BigGridInfo( biggrid_latvec0_.e32 = biggrid_vec3_.y; biggrid_latvec0_.e33 = biggrid_vec3_.z; + printf("biggrid_latvec0_e11 = %.8f\n", biggrid_latvec0_.e11); + printf("biggrid_latvec0_e12 = %.8f\n", biggrid_latvec0_.e12); + printf("biggrid_latvec0_e13 = %.8f\n", biggrid_latvec0_.e13); + printf("biggrid_latvec0_e21 = %f\n", biggrid_latvec0_.e21); + printf("biggrid_latvec0_e22 = %f\n", biggrid_latvec0_.e22); + printf("biggrid_latvec0_e23 = %f\n", biggrid_latvec0_.e23); + printf("biggrid_latvec0_e31 = %f\n", biggrid_latvec0_.e31); + printf("biggrid_latvec0_e32 = %f\n", biggrid_latvec0_.e32); + printf("biggrid_latvec0_e33 = %f\n", biggrid_latvec0_.e33); + // initialize the GT matrix biggrid_GT_ = biggrid_latvec0_.Inverse(); @@ -46,4 +56,4 @@ BigGridInfo::BigGridInfo( } } -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index c14f766175..2d904ee0ff 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -5,7 +5,7 @@ #include "gint_helper.h" #include "meshgrid_info.h" -namespace Gint +namespace ModuleGint { /** @@ -38,13 +38,13 @@ class BigGridInfo // get the 3D index of a meshgrid in the big grid from the 1D index Vec3i meshgrid_idx_1Dto3D(int index_1d) const { - return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + return index1Dto3D(index_1d, nmx_, nmy_, nmz_); }; // get the 1D index of a meshgrid in the big grid from the 3D index int meshgrid_idx_3Dto1D(const Vec3i index_3d) const { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); }; // get the cartesian coordinate of a meshgrid in the big grid from the 3D index @@ -102,4 +102,4 @@ class BigGridInfo std::vector meshgrid_coords_; }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp index 20a0c45e42..c4a5b2a738 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp @@ -1,6 +1,6 @@ #include "divide_info.h" -namespace Gint +namespace ModuleGint { DivideInfo::DivideInfo( diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h index c3770fb846..374831eeef 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h @@ -4,7 +4,7 @@ #include "unitcell_info.h" #include "localcell_info.h" -namespace Gint +namespace ModuleGint { class DivideInfo diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index bee2585e9d..ab0cfe7a89 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -4,7 +4,7 @@ #include "gint_atom.h" #include "gint_helper.h" -namespace Gint +namespace ModuleGint { template diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h index 118cf16b07..165a68ac98 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h @@ -4,7 +4,7 @@ #include "module_basis/module_ao/ORB_atomic.h" #include "gint_type.h" -namespace Gint +namespace ModuleGint { class GintAtom @@ -115,4 +115,4 @@ class GintAtom }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index 6fceda0627..f7628eecca 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -1,49 +1,83 @@ #pragma once +#include #include "gint_type.h" #include "module_base/timer.h" -namespace Gint +inline int index3Dto1D(const int id_x, const int id_y, const int id_z, + const int dim_x, const int dim_y, const int dim_z) { - inline int index3Dto1D(const int id_x, const int id_y, const int id_z, - const int dim_x, const int dim_y, const int dim_z) - { - return id_z + id_y * dim_z + id_x * dim_y * dim_z; - }; + return id_z + id_y * dim_z + id_x * dim_y * dim_z; +}; - inline Vec3i index1Dto3D(const int index_1d, - const int dim_x, const int dim_y, const int dim_z) - { - int id_x = index_1d / (dim_y * dim_z); - int id_y = (index_1d - id_x * dim_y * dim_z) / dim_z; - int id_z = index_1d % dim_z; - return Vec3i(id_x, id_y, id_z); - }; - - // if exponent is an integer between 0 and 5 (the most common cases in gint) and - // and exp is a variable that cannot be determined at compile time (which means the compiler cannot optimize the code), - // pow_int is much faster than std::pow - inline double pow_int(const double base, const int exp) +inline Vec3i index1Dto3D(const int index_1d, + const int dim_x, const int dim_y, const int dim_z) +{ + int id_x = index_1d / (dim_y * dim_z); + int id_y = (index_1d - id_x * dim_y * dim_z) / dim_z; + int id_z = index_1d % dim_z; + return Vec3i(id_x, id_y, id_z); +}; + +// if exponent is an integer between 0 and 5 (the most common cases in gint) and +// and exp is a variable that cannot be determined at compile time (which means the compiler cannot optimize the code), +// pow_int is much faster than std::pow +inline double pow_int(const double base, const int exp) +{ + switch (exp) { - switch (exp) - { - case 0: - return 1.0; - case 1: - return base; - case 2: - return base * base; - case 3: - return base * base * base; - case 4: - return base * base * base * base; - case 5: - return base * base * base * base * base; - default: - double result = std::pow(base, exp); - return result; - } - }; - - -} // namespace Gint \ No newline at end of file + case 0: + return 1.0; + case 1: + return base; + case 2: + return base * base; + case 3: + return base * base * base; + case 4: + return base * base * base * base; + case 5: + return base * base * base * base * base; + default: + double result = std::pow(base, exp); + return result; + } +}; + +inline int floor_div(const int a, const int b) +{ + // a ^ b < 0 is equivalent to a and b have different signs + return a / b - (a % b != 0 && (a ^ b) < 0); +}; + +inline int ceil_div(const int a, const int b) +{ + return a / b + (a % b != 0 && (a ^ b) > 0); +}; + +// for debug +#include +#include +#include + +template +void writeArrayToFile(T* array, int n, const std::string& filename) { + // 打开文件,使用 ofstream 来写入数据 + std::ofstream outFile(filename); + + // 检查文件是否成功打开 + if (!outFile.is_open()) { + std::cerr << "无法打开或创建文件: " << filename << std::endl; + return; + } + + // 写入数组的前n个元素到文件中 + for (int i = 0; i < n; ++i) { + outFile <(ucell_->a1, ucell_->a2, ucell_->a3, + unitcell_info_ = std::make_shared(ucell_->a1 * ucell_->lat0, ucell_->a2 * ucell_->lat0, ucell_->a3 * ucell_->lat0, nbx, nby, nbz, nmx, nmy, nmz); // initialize the divide information divide_info_ = std::make_shared(startidx_bx, startidx_by, startidx_bz, - nbx, nby, nbz, unitcell_info_, false); + nbx_local, nby_local, nbz_local, unitcell_info_, false); // initialize the localcell information localcell_info_ = divide_info_->get_localcell_info(); + Vec3d diff_1 = unitcell_info_->get_vec1() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec1(); + Vec3d diff_2 = unitcell_info_->get_vec2() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec2(); + Vec3d diff_3 = unitcell_info_->get_vec3() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec3(); + diff_1.print(); + diff_2.print(); + diff_3.print(); // initialize the biggrids for (int i = 0; i < localcell_info_->get_biggrid_num(); i++) { biggrids_.push_back( - std::make_shared(localcell_info_->get_bgrid_global_idx_1D(i), localcell_info_)); + std::make_shared(i, localcell_info_)); } is_atom_in_proc_ = std::vector(ucell.nat, false); // initialize the atoms init_atoms_(ucell_->ntype, ucell_->atoms, Phi); + + int total_atoms_on_proc = 0; + int biggrid_num = 0; + for(const auto& biggrid: biggrids_) + { + biggrid_num++; + total_atoms_on_proc += biggrid->get_atom_num(); + } + // printf("biggrid_num = %d\n", biggrid_num); + printf("total_atoms_on_proc = %d\n", total_atoms_on_proc); + // exit(0); + // std::vector which_atom; + // std::vector coords_x; + // std::vector mcell_coords3; + // auto mcell_cord = unitcell_info_->get_biggrid_info()->get_meshgrid_coords(); + // for(auto &coord: mcell_cord) + // { + // mcell_coords3.push_back(coord.x); + // mcell_coords3.push_back(coord.y); + // mcell_coords3.push_back(coord.z); + // } + // for(const auto& biggrid : biggrids_) + // { + // for(int i = 0; i < biggrid->get_atom_num(); i++) + // { + // // which_atom.push_back(biggrid->get_atoms()[i]->get_iat()); + // for(const auto coord: biggrid->get_atom_relative_coords(*biggrid->get_atoms()[i])) + // { + // coords_x.push_back(coord.x); + // }; + // } + // } + + // writeArrayToFile(which_atom.data(), which_atom.size(), "which_atom.txt"); + // writeArrayToFile(coords_x.data(), coords_x.size(), "coords_x.txt"); + // writeArrayToFile(mcell_coords3.data(), mcell_coords3.size(), "mcell_cord.txt"); + // exit(0); + // writeArrayToFile(coords_x.data(), coords_x.size(), "coords_x.txt"); // initialize the ijr_info init_ijr_info_(ucell, gd); @@ -59,7 +103,7 @@ std::shared_ptr> GintInfo::get_hr(int npol) const void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital* Phi) { int iat = 0; - const Matrix3 biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); + const Matrix3& biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); const double g1 = sqrt(biggrid_GT.e11 * biggrid_GT.e11 + biggrid_GT.e21 * biggrid_GT.e21 + biggrid_GT.e31 * biggrid_GT.e31); @@ -73,7 +117,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital // TODO: USE OPENMP TO PARALLELIZE THIS LOOP for(int i = 0; i < ntype; i++) { - const auto atom = atoms[i]; + const auto& atom = atoms[i]; const auto *orb = &Phi[i]; // rcut extends to the maximum big grids in x, y, z directions @@ -83,9 +127,37 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital for(int j = 0; j < atom.na; j++) { - const Vec3i atom_bgrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); - const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(atom_bgrid_idx); + Vec3d fraction; + fraction.x = atom.taud[j].x * unitcell_info_->get_nbx(); + fraction.y = atom.taud[j].y * unitcell_info_->get_nby(); + fraction.z = atom.taud[j].z * unitcell_info_->get_nbz(); + const Vec3i atom_bgrid_idx(static_cast(fraction.x), + static_cast(fraction.y), + static_cast(fraction.z)); + const Vec3d delta(fraction.x - atom_bgrid_idx.x, + fraction.y - atom_bgrid_idx.y, + fraction.z - atom_bgrid_idx.z); + const Vec3d tau_in_biggrid = delta.x * unitcell_info_->get_biggrid_info()->get_vec1() + + delta.y * unitcell_info_->get_biggrid_info()->get_vec2() + + delta.z * unitcell_info_->get_biggrid_info()->get_vec3(); + // const Vec3i atom_bgrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); + // int b1 = static_cast(atom.taud[j].x * unitcell_info_->get_nbx()); + // int b2 = static_cast(atom.taud[j].y * unitcell_info_->get_nby()); + // int b3 = static_cast(atom.taud[j].z * unitcell_info_->get_nbz()); + // if(true) + // { + // printf("atom_bgrid_idx (%d) = %d %d %d\n", iat, atom_bgrid_idx.x, atom_bgrid_idx.y, atom_bgrid_idx.z); + // printf("atom.taud (%d) = %f %f %f\n", iat, atom.taud[j].x, atom.taud[j].y, atom.taud[j].z); + // printf("atom.tau (%d) = %f %f %f\n", iat, atom.tau[j].x, atom.tau[j].y, atom.tau[j].z); + // printf("b1 b2 b3 = %d %d %d\n", b1, b2, b3); + // } + // const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(atom_bgrid_idx); + // const Vec3d tau_in_biggrid(0, 0, 0); + + printf("tau_in_biggrid (%d)= %f %f %f\n", iat, tau_in_biggrid.x, tau_in_biggrid.y, tau_in_biggrid.z); + const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); std::map> gint_atom_map; + for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++) { for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid_y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid_y; bgrid_y++) @@ -100,35 +172,32 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital continue; } const int bgrid_local_idx = localcell_info_->get_bgrid_local_idx_1D(normal_bgrid_idx); - // get the unitcell idx of the extended atom - const Vec3i unitcell_idx = - unitcell_info_->get_unitcell_idx(ext_bgrid_idx); - auto it = gint_atom_map.find(unitcell_idx); + // get the unitcell idx of the big grid + const Vec3i ucell_idx_bgrid = unitcell_info_->get_unitcell_idx(ext_bgrid_idx); + + // The index of the unitcell containing the biggrid relative to the unitcell containing the atom. + const Vec3i ucell_idx_relative = ucell_idx_bgrid - ucell_idx_atom; + auto it = gint_atom_map.find(ucell_idx_relative); // if the gint_atom is not in the map, // it means this is the first time we find this atom may affect some biggrids. if(it == gint_atom_map.end()) { - Vec3i ext_atom_bgrid_idx(atom_bgrid_idx.x + unitcell_idx.x * unitcell_info_->get_nbx(), - atom_bgrid_idx.y + unitcell_idx.y * unitcell_info_->get_nby(), - atom_bgrid_idx.z + unitcell_idx.z * unitcell_info_->get_nbz()); - auto gint_atom = std::make_shared(&atom, j, iat, ext_atom_bgrid_idx, unitcell_idx, tau_in_biggrid, orb); - gint_atom_map[unitcell_idx] = gint_atom; + Vec3i ext_atom_bgrid_idx(atom_bgrid_idx.x - ucell_idx_bgrid.x * unitcell_info_->get_nbx(), + atom_bgrid_idx.y - ucell_idx_bgrid.y * unitcell_info_->get_nby(), + atom_bgrid_idx.z - ucell_idx_bgrid.z * unitcell_info_->get_nbz()); + auto gint_atom = std::make_shared(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb); + gint_atom_map[ucell_idx_relative] = gint_atom; if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom)) { - #pragma omp critical - { - biggrids_[bgrid_local_idx]->add_atom(gint_atom); - atoms_.push_back(gint_atom); - is_atom_in_proc_[iat] = true; - } + biggrids_[bgrid_local_idx]->add_atom(gint_atom); + atoms_.push_back(gint_atom); + is_atom_in_proc_[iat] = true; } } else { - if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[unitcell_idx])) + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[ucell_idx_relative])) { - #pragma omp critical - { - biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[unitcell_idx]); - } + biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[ucell_idx_relative]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index c852defbd5..b8d1cf62d4 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -13,7 +13,7 @@ #include "localcell_info.h" #include "divide_info.h" -namespace Gint +namespace ModuleGint { class GintInfo @@ -30,6 +30,7 @@ class GintInfo // getter functions std::vector> get_biggrids() const { return biggrids_; }; + double get_mgrid_volume() const { return unitcell_info_->get_meshgrid_info()->get_volume(); }; //========================================= // functions about hcontainer @@ -69,4 +70,4 @@ class GintInfo std::vector ijr_info_; }; -} // namespace Gint +} // namespace ModuleGint diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index ce64e8c475..5ffed6e3c3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -3,7 +3,7 @@ #include "gint_vl.h" #include "phi_operator.h" -namespace Gint +namespace ModuleGint { void Gint_vl::cal_gint() @@ -27,11 +27,15 @@ void Gint_vl::cal_hRGint_() { for(const auto& biggrid: gint_info_->get_biggrids()) { + if(biggrid->get_atoms().size() == 0) + { + continue; + } PhiOperator phi_op(biggrid); ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); phi_op.set_phi(phi.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), hRGint_.get()); } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h index b17e93389f..fbe7f5c145 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h @@ -5,7 +5,7 @@ #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "gint_info.h" -namespace Gint +namespace ModuleGint { class Gint_vl @@ -13,9 +13,9 @@ class Gint_vl public: Gint_vl( std::shared_ptrgint_info, - double* vr_eff, + const double* vr_eff, hamilt::HContainer* hR) - : gint_info_(gint_info), vr_eff_(vr_eff), hR_(hR){}; + : gint_info_(gint_info), vr_eff_(vr_eff), hR_(hR), dr3_(gint_info->get_mgrid_volume()){}; void cal_gint(); @@ -34,7 +34,7 @@ class Gint_vl std::shared_ptr gint_info_; // input - double* vr_eff_; + const double* vr_eff_; // output hamilt::HContainer* hR_; @@ -42,6 +42,8 @@ class Gint_vl //======================== // Intermediate variables //======================== + double dr3_; + std::shared_ptr> hRGint_; }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index 94a5b0ab9f..7adccefa7a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -1,6 +1,6 @@ #include "localcell_info.h" -namespace Gint +namespace ModuleGint { LocalCellInfo::LocalCellInfo( int startidx_bx, int startidx_by, int startidx_bz, @@ -25,12 +25,12 @@ namespace Gint int LocalCellInfo::biggrid_idx_3Dto1D(const Vec3i index_3d) const { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); + return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); } Vec3i LocalCellInfo::biggrid_idx_1Dto3D(const int index_1d) const { - return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); + return index1Dto3D(index_1d, nbx_, nby_, nbz_); } Vec3i LocalCellInfo::get_bgrid_global_idx_3D(const Vec3i index_3d) const @@ -94,12 +94,12 @@ namespace Gint int LocalCellInfo::meshgrid_idx_3Dto1D(const Vec3i index_3d) const { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } Vec3i LocalCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const { - return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + return index1Dto3D(index_1d, nmx_, nmy_, nmz_); } Vec3i LocalCellInfo::get_mgrid_global_idx_3D(const Vec3i index_3d) const @@ -116,4 +116,26 @@ namespace Gint return unitcell_info_->meshgrid_idx_3Dto1D(ucell_idx_3d); } + std::vector LocalCellInfo::get_mgrids_local_idx_1D(const int index_1d) const + { + std::vector local_idx; + auto index_3d = biggrid_idx_1Dto3D(index_1d); + Vec3i startidx( + index_3d.x * biggrid_info_->get_nmx(), + index_3d.y * biggrid_info_->get_nmy(), + index_3d.z * biggrid_info_->get_nmz()); + for(int ix = 0; ix < biggrid_info_->get_nmx(); ++ix) + { + for(int iy = 0; iy < biggrid_info_->get_nmy(); ++iy) + { + for(int iz = 0; iz < biggrid_info_->get_nmz(); ++iz) + { + Vec3i idx_3d = Vec3i(startidx.x + ix, startidx.y + iy, startidx.z + iz); + local_idx.push_back(meshgrid_idx_3Dto1D(idx_3d)); + } + } + } + return local_idx; + } + } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 56736a134e..3efc145914 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -4,7 +4,7 @@ #include "gint_type.h" #include "unitcell_info.h" -namespace Gint +namespace ModuleGint { class LocalCellInfo @@ -79,6 +79,9 @@ class LocalCellInfo // transform the 1D index of a meshgrid in the local cell to the 1D index in the unit cell int get_mgrid_global_idx_1D(const int index_1d) const; + // get the local index of meshgrids of the index_1d th biggrid + std::vector get_mgrids_local_idx_1D(const int index_1d) const; + private: //==================================================================== // information about the big grid @@ -122,4 +125,4 @@ class LocalCellInfo }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index f397396929..7bcc6ffbfd 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -3,7 +3,7 @@ #include "gint_type.h" #include "module_cell/unitcell.h" -namespace Gint +namespace ModuleGint { class MeshGridInfo @@ -33,6 +33,8 @@ class MeshGridInfo // initialize the GT matrix meshgrid_GT_ = meshgrid_latvec0_.Inverse(); + + meshgrid_volume_ = std::abs(meshgrid_latvec0_.Det()); }; // getter functions @@ -41,6 +43,7 @@ class MeshGridInfo const Vec3d &get_vec3() const { return meshgrid_vec3_; }; const Matrix3 &get_latvec0() const { return meshgrid_latvec0_; }; const Matrix3 &get_GT() const { return meshgrid_GT_; }; + const double get_volume() const { return meshgrid_volume_; }; private: // basis vectors of meshgrid @@ -58,6 +61,8 @@ class MeshGridInfo // meshgrid_GT_ = meshgrid_latvec0_.Inverse() // (x, y, z) * meshgrid_GT_ = (i, j, k) Matrix3 meshgrid_GT_; + + double meshgrid_volume_; }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 57d7fc8e40..e697d34a42 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -1,7 +1,7 @@ #include "phi_operator.h" #include "module_base/blas_connector.h" -namespace Gint +namespace ModuleGint { PhiOperator::PhiOperator(std::shared_ptr biggrid) @@ -10,7 +10,7 @@ PhiOperator::PhiOperator(std::shared_ptr biggrid) rows_ = biggrid_->get_biggrid_info()->get_nmxyz(); cols_ = biggrid_->get_mgrid_phi_len(); is_atom_on_mgrids_ = biggrid_->get_is_atom_on_mgrids(); - meshgrid_coords_ = biggrid_->get_mgrid_coords(); + meshgrids_local_idx_ = biggrid_->get_mgrids_local_idx(); atom_startidx_ = biggrid_->get_atom_startidx(); atom_phi_len_ = biggrid_->get_atom_phi_len(); } @@ -19,16 +19,22 @@ void PhiOperator::set_phi(double* phi) const { for(const auto& atom : biggrid_->get_atoms()) { - atom->set_phi(meshgrid_coords_, cols_, phi); + atom->set_phi(biggrid_->get_atom_relative_coords(*atom), cols_, phi); phi += atom->get_nw(); } + if(biggrid_->get_idx() == 0) + { + printf("cols_ = %d\n", cols_); + writeArrayToFile(phi, rows_*cols_, "phi.txt"); + } + exit(0); } void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const { for(const auto& atom : biggrid_->get_atoms()) { - atom->set_phi_dphi(meshgrid_coords_, cols_, phi, dphi_x, dphi_y, dphi_z); + atom->set_phi_dphi(biggrid_->get_atom_relative_coords(*atom), cols_, phi, dphi_x, dphi_y, dphi_z); phi += atom->get_nw(); dphi_x += atom->get_nw(); dphi_y += atom->get_nw(); @@ -42,7 +48,7 @@ void PhiOperator::set_ddphi( { for(const auto& atom : biggrid_->get_atoms()) { - atom->set_ddphi(meshgrid_coords_, cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); + atom->set_ddphi(biggrid_->get_atom_relative_coords(*atom), cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); ddphi_xx += atom->get_nw(); ddphi_xy += atom->get_nw(); ddphi_xz += atom->get_nw(); @@ -93,8 +99,8 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* const int end_idx = atom_pair_endidx_(i, j); const int len = end_idx - start_idx + 1; - // if len == 0, it means this atom pair does not affect any meshgrid in this biggrid - if(len == 0) + // if len<=0, it means this atom pair does not affect any meshgrid in this biggrid + if(len <= 0) { continue; } @@ -105,17 +111,14 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* } } -void PhiOperator::phi_mul_vldr3(const double* vldr3, const double* const* phi, double** result) const +void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double* const* phi, double** result) const { for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) { - for(int j = 0; j < biggrid_->get_atom_num(); j++) + double vldr3_mgrid = vl[meshgrids_local_idx_[i]] * dr3; + for(int j = 0; j < cols_; j++) { - for(int k = 0; k < atom_phi_len_[j]; k++) - { - const int idx = atom_startidx_[j]; - result[i][idx + k] = phi[i][idx + k] * vldr3[i]; - } + result[i][j] = phi[i][j] * vldr3_mgrid; } } } @@ -131,13 +134,13 @@ void PhiOperator::phi_mul_phi_vldr3( for(int i = 0; i < biggrid_->get_atom_num(); ++i) { const auto atom_i = biggrid_->get_atoms()[i]; - const auto r_i = atom_i->get_r(); + const auto& r_i = atom_i->get_r(); const int iat_i = atom_i->get_iat(); for(int j = i; j < biggrid_->get_atom_num(); ++j) { const auto atom_j = biggrid_->get_atoms()[j]; - const auto r_j = atom_j->get_r(); + const auto& r_j = atom_j->get_r(); const int iat_j = atom_j->get_iat(); // only calculate the upper triangle matrix @@ -158,7 +161,7 @@ void PhiOperator::phi_mul_phi_vldr3( const int end_idx = atom_pair_endidx_(i, j); const int len = end_idx - start_idx + 1; - if(len == 0) + if(len <= 0) { continue; } @@ -181,6 +184,7 @@ int PhiOperator::atom_pair_startidx_(int a, int b) const return i; } } + return biggrid_->get_meshgrid_num(); } int PhiOperator::atom_pair_endidx_(int a, int b) const @@ -192,6 +196,7 @@ int PhiOperator::atom_pair_endidx_(int a, int b) const return i; } } + return -1; } -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 34c2ac028f..2a917c2de2 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -5,7 +5,7 @@ #include #include "biggrid.h" -namespace Gint +namespace ModuleGint { /** @@ -46,7 +46,8 @@ class PhiOperator const bool is_symm) const; void phi_mul_vldr3( - const double* vldr3, + const double* vl, + const double dr3, const double* const* phi, double** result) const; @@ -71,12 +72,12 @@ class PhiOperator // the column number of the phi matrix // cols_ = biggrid_->get_mgrid_phi_len() int cols_; - - // the coordinates of the meshgrids - std::vector meshgrid_coords_; + + // the local index of the meshgrids + std::vector meshgrids_local_idx_; // the big grid that the phi matrix is associated with - std::shared_ptr biggrid_; + std::shared_ptr biggrid_; // record whether the atom affects the meshgrid // is_atom_on_mgrids_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index fc8962d1f3..8652651c0a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -4,7 +4,7 @@ #include "gint_atom.h" #include "gint_helper.h" -namespace Gint +namespace ModuleGint { template diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp index 1fc7eb2acf..6c376a2fa1 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp @@ -1,7 +1,7 @@ #include "unitcell_info.h" #include "gint_helper.h" -namespace Gint +namespace ModuleGint { UnitCellInfo::UnitCellInfo( diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index e66efe6379..6a4cf05b6a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -6,7 +6,7 @@ #include "gint_helper.h" #include "gint_type.h" -namespace Gint +namespace ModuleGint { class UnitCellInfo @@ -42,13 +42,13 @@ class UnitCellInfo // transform the 1D index of a big grid in the unit cell to the 3D index Vec3i biggrid_idx_1Dto3D(const int index_1d) const { - return Gint::index1Dto3D(index_1d, nbx_, nby_, nbz_); + return index1Dto3D(index_1d, nbx_, nby_, nbz_); }; // transform the 3D index of a biggrid in the unit cell to the 1D index int biggrid_idx_3Dto1D(const Vec3i index_3d) const { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); + return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); }; // get the cartesian coordinate of a big grid in the unit cell from the 3D index @@ -85,13 +85,17 @@ class UnitCellInfo // get the extended unitcell index of a big grid Vec3i get_unitcell_idx(const Vec3i index_3d) const { - return Vec3i(index_3d.x / nbx_, index_3d.y / nby_, index_3d.z / nbz_); + return Vec3i(floor_div(index_3d.x, nbx_), + floor_div(index_3d.y, nby_), + floor_div(index_3d.z, nbz_)); }; // map the extended big grid index to the big grid index in unitcell Vec3i map_ext_idx_to_ucell(const Vec3i index_3d) const { - return Vec3i(index_3d.x % nbx_, index_3d.y % nby_, index_3d.z % nbz_); + return Vec3i(index_3d.x - floor_div(index_3d.x, nbx_) * nbx_, + index_3d.y - floor_div(index_3d.y, nby_) * nby_, + index_3d.z - floor_div(index_3d.z, nbz_) * nbz_); }; @@ -102,13 +106,13 @@ class UnitCellInfo // transform the 1D index of a meshgrid in the unit cell to the 3D index Vec3i meshgrid_idx_1Dto3D(const int index_1d) const { - return Gint::index1Dto3D(index_1d, nmx_, nmy_, nmz_); + return index1Dto3D(index_1d, nmx_, nmy_, nmz_); } // transform the 3D index of a meshgrid in the unit cell to the 1D index int meshgrid_idx_3Dto1D(const Vec3i index_3d) const { - return Gint::index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); + return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } // get the cartesian coordinate of a meshgrid in the unit cell from the 3D index @@ -166,4 +170,4 @@ class UnitCellInfo }; -} // namespace Gint \ No newline at end of file +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_io/write_eband_terms.hpp b/source/module_io/write_eband_terms.hpp index eff46a20b9..15ee737b24 100644 --- a/source/module_io/write_eband_terms.hpp +++ b/source/module_io/write_eband_terms.hpp @@ -89,12 +89,12 @@ void write_eband_terms(const int nspin, hamilt::HContainer v_pp_local_R_ao(pv); if_gamma_fix(v_pp_local_R_ao); std::vector> e_orb_pp_local; - hamilt::Veff> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd, nspin); - v_pp_local_op.contributeHR(); + // hamilt::Veff> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd, nspin); + // v_pp_local_op.contributeHR(); for (int ik = 0;ik < kv.get_nks();++ik) { v_pp_local_k_ao.set_zero_hk(); - dynamic_cast*>(&v_pp_local_op)->contributeHk(ik); + // dynamic_cast*>(&v_pp_local_op)->contributeHk(ik); e_orb_pp_local.emplace_back(orbital_energy(ik, nbands, cVc(v_pp_local_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d)); } @@ -143,9 +143,9 @@ void write_eband_terms(const int nspin, std::vector>*> v_hartree_op(nspin0); for (int is = 0; is < nspin0; ++is) { - v_hartree_op[is] = new hamilt::Veff>(gint, - &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin); - v_hartree_op[is]->contributeHR(); + // v_hartree_op[is] = new hamilt::Veff>(gint, + // &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin); + // v_hartree_op[is]->contributeHR(); } std::vector> e_orb_hartree; for (int ik = 0;ik < kv.get_nks();++ik) diff --git a/source/module_io/write_vxc.hpp b/source/module_io/write_vxc.hpp index fa9da0ec62..f5c4188005 100644 --- a/source/module_io/write_vxc.hpp +++ b/source/module_io/write_vxc.hpp @@ -240,10 +240,10 @@ void write_Vxc(const int nspin, std::vector>*> vxcs_op_ao(nspin0); for (int is = 0; is < nspin0; ++is) { - vxcs_op_ao[is] = new hamilt::Veff>(gint, - &vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin); + // vxcs_op_ao[is] = new hamilt::Veff>(gint, + // &vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin); - vxcs_op_ao[is]->contributeHR(); + // vxcs_op_ao[is]->contributeHR(); } std::vector> e_orb_locxc; // orbital energy (local XC) std::vector> e_orb_tot; // orbital energy (total) From a62c3dd7e3a5dbc50b7e0e93e7345b1d0bb5e305 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Tue, 24 Dec 2024 19:17:23 +0800 Subject: [PATCH 08/47] fix some bugs, the first correct version --- source/module_base/array_pool.h | 2 +- .../module_gint/CMakeLists.txt | 1 + .../module_gint/grid_technique.cpp | 3 +- .../new_grid_tech/biggrid_info.cpp | 10 --- .../module_gint/new_grid_tech/gint_atom.cpp | 16 ++--- .../module_gint/new_grid_tech/gint_common.cpp | 62 +++++++++++++++++++ .../module_gint/new_grid_tech/gint_common.h | 12 ++++ .../module_gint/new_grid_tech/gint_info.cpp | 34 +++------- .../module_gint/new_grid_tech/gint_vl.cpp | 56 +---------------- .../module_gint/new_grid_tech/gint_vl.h | 4 -- .../new_grid_tech/phi_operator.cpp | 10 +-- .../module_gint/new_grid_tech/phi_operator.h | 1 + 12 files changed, 98 insertions(+), 113 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h diff --git a/source/module_base/array_pool.h b/source/module_base/array_pool.h index 68f7d7162f..5fde2c4176 100644 --- a/source/module_base/array_pool.h +++ b/source/module_base/array_pool.h @@ -40,7 +40,7 @@ namespace ModuleBase : nr(nr_in), nc(nc_in) { - this->ptr_1D = new T[nr * nc]{0}; + this->ptr_1D = new T[nr * nc](); this->ptr_2D = new T*[nr]; for (int ir = 0; ir < nr; ++ir) this->ptr_2D[ir] = &this->ptr_1D[ir * nc]; diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index a5596b19bc..cd5765fed6 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -40,6 +40,7 @@ list(APPEND objects new_grid_tech/phi_operator.cpp new_grid_tech/set_ddphi.cpp new_grid_tech/unitcell_info.cpp + new_grid_tech/gint_common.cpp ) if(USE_CUDA) diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index 9b3acd8890..754db76e0a 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -453,7 +453,7 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, } } assert(count == total_atoms_on_grid); - printf("total_atoms_on_grid = %d\n", total_atoms_on_grid); + printf("total_atoms_on_proc_old = %d\n", total_atoms_on_grid); // writeArrayToFile(this->which_atom.data(), this->which_atom.size(), "which_atom2.txt"); // writeArrayToFile(coord_x.data(), coord_x.size(), "coord_x2.txt"); // writeArrayToFile(coords3.data(), coords3.size(), "coords3.txt"); @@ -562,7 +562,6 @@ void Grid_Technique::init_ijr_and_nnrg(const UnitCell& ucell, const Grid_Driver& ModuleBase::TITLE("Grid_Technique", "init_ijr_and_nnrg"); hamilt::HContainer hRGint_tmp(ucell.nat); - // prepare the row_index and col_index for construct AtomPairs, they are // same, name as orb_index std::vector orb_index(ucell.nat + 1); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index 43bd304ab8..5e99adc9ea 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -28,16 +28,6 @@ BigGridInfo::BigGridInfo( biggrid_latvec0_.e32 = biggrid_vec3_.y; biggrid_latvec0_.e33 = biggrid_vec3_.z; - printf("biggrid_latvec0_e11 = %.8f\n", biggrid_latvec0_.e11); - printf("biggrid_latvec0_e12 = %.8f\n", biggrid_latvec0_.e12); - printf("biggrid_latvec0_e13 = %.8f\n", biggrid_latvec0_.e13); - printf("biggrid_latvec0_e21 = %f\n", biggrid_latvec0_.e21); - printf("biggrid_latvec0_e22 = %f\n", biggrid_latvec0_.e22); - printf("biggrid_latvec0_e23 = %f\n", biggrid_latvec0_.e23); - printf("biggrid_latvec0_e31 = %f\n", biggrid_latvec0_.e31); - printf("biggrid_latvec0_e32 = %f\n", biggrid_latvec0_.e32); - printf("biggrid_latvec0_e33 = %f\n", biggrid_latvec0_.e33); - // initialize the GT matrix biggrid_GT_ = biggrid_latvec0_.Inverse(); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index ab0cfe7a89..3ff731e8fb 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -1,4 +1,3 @@ -#include "module_base/timer.h" #include "module_base/ylm.h" #include "module_base/array_pool.h" #include "gint_atom.h" @@ -10,8 +9,6 @@ namespace ModuleGint template void GintAtom::set_phi(const std::vector coords, const int stride, T* phi) { - ModuleBase::timer::tick("GintAtom", "set_phi"); - const int num_mgrids = coords.size(); // orb_ does not have the member variable dr_uniform @@ -41,7 +38,7 @@ void GintAtom::set_phi(const std::vector coords, const int stride, T* phi // 1e-9 is to avoid division by zero const double dist = coord.norm() < 1e-9 ? 1e-9 : coord.norm(); - + // printf("coord.x = %.10f, coord.y = %.10f, coord.z = %.10f, dist = %f\n", coord.x, coord.y, coord.z, dist); if(dist > orb_->getRcut()) { // if the distance is larger than the cutoff radius, @@ -54,7 +51,6 @@ void GintAtom::set_phi(const std::vector coords, const int stride, T* phi // TODO: vectorize the sph_harm function, // the vectorized function can be called once for all meshgrids in a biggrid ModuleBase::Ylm::sph_harm(atom_->nwl, coord.x/dist, coord.y/dist, coord.z/dist, ylma); - // interpolation // these parameters are related to interpolation @@ -85,11 +81,13 @@ void GintAtom::set_phi(const std::vector coords, const int stride, T* phi + c3 * psi_uniform[ip + 1] + c4 * dpsi_uniform[ip + 1]; } phi[im * stride + iw] = psi * ylma[atom_->iw2_ylm[iw]]; + // printf("phi[%d] = %.10f\n", im * stride + iw, phi[im * stride + iw]); + // printf("ylma[%d] = %.10f\n", atom_->iw2_ylm[iw], ylma[atom_->iw2_ylm[iw]]); + // printf("psi = %.10f\n", psi); } + // exit(0); } } - - ModuleBase::timer::tick("GintAtom", "set_phi"); } template @@ -97,8 +95,6 @@ void GintAtom::set_phi_dphi( const std::vector coords, const int stride, T* phi, T* dphi_x, T* dphi_y, T* dphi_z) { - ModuleBase::timer::tick("GintAtom", "set_phi_dphi"); - const int num_mgrids = coords.size(); // orb_ does not have the member variable dr_uniform @@ -200,8 +196,6 @@ void GintAtom::set_phi_dphi( } } } - - ModuleBase::timer::tick("GintAtom", "set_phi_dphi"); } // explicit instantiation diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp new file mode 100644 index 0000000000..cccb88dfc5 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -0,0 +1,62 @@ +#include "gint_common.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" + +namespace ModuleGint +{ + +void compose_hRGint(hamilt::HContainer* hR) +{ + for (int iap = 0; iap < hR->size_atom_pairs(); iap++) + { + auto& ap = hR->get_atom_pair(iap); + const int iat1 = ap.get_atom_i(); + const int iat2 = ap.get_atom_j(); + if (iat1 > iat2) + { + // fill lower triangle matrix with upper triangle matrix + // the upper is + const hamilt::AtomPair* upper_ap = hR->find_pair(iat2, iat1); + const hamilt::AtomPair* lower_ap = hR->find_pair(iat1, iat2); +#ifdef __DEBUG + assert(upper_ap != nullptr); +#endif + for (int ir = 0; ir < ap.get_R_size(); ir++) + { + auto R_index = ap.get_R_index(ir); + auto upper_mat = upper_ap->find_matrix(-R_index); + auto lower_mat = lower_ap->find_matrix(R_index); + for (int irow = 0; irow < upper_mat->get_row_size(); ++irow) + { + for (int icol = 0; icol < upper_mat->get_col_size(); ++icol) + { + lower_mat->get_value(icol, irow) = upper_ap->get_value(irow, icol); + } + } + } + } + } +} + +template +void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR) +{ +#ifdef __MPI + int size = 0; + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size == 1) + { + hR->add(*hRGint); + } + else + { + hamilt::transferSerials2Parallels(*hRGint, hR); + } +#else + hR->add(*hRGint); +#endif +} + +template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); +template void transfer_hRGint_to_hR(const hamilt::HContainer>* hRGint, hamilt::HContainer>* hR); +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h new file mode 100644 index 0000000000..2f83d2f3cb --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h @@ -0,0 +1,12 @@ +#pragma once +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" + +namespace ModuleGint +{ + // fill the lower triangle matrix with the upper triangle matrix + void compose_hRGint(hamilt::HContainer* hR); + + template + void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); + +} diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 734e92c7b5..5d1845a8e7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -27,21 +27,12 @@ GintInfo::GintInfo( // initialize the localcell information localcell_info_ = divide_info_->get_localcell_info(); - Vec3d diff_1 = unitcell_info_->get_vec1() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec1(); - Vec3d diff_2 = unitcell_info_->get_vec2() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec2(); - Vec3d diff_3 = unitcell_info_->get_vec3() - (double)24 * unitcell_info_->get_biggrid_info()->get_vec3(); - diff_1.print(); - diff_2.print(); - diff_3.print(); // initialize the biggrids for (int i = 0; i < localcell_info_->get_biggrid_num(); i++) { - biggrids_.push_back( - std::make_shared(i, localcell_info_)); + biggrids_.push_back(std::make_shared(i, localcell_info_)); } - is_atom_in_proc_ = std::vector(ucell.nat, false); - // initialize the atoms init_atoms_(ucell_->ntype, ucell_->atoms, Phi); @@ -53,7 +44,7 @@ GintInfo::GintInfo( total_atoms_on_proc += biggrid->get_atom_num(); } // printf("biggrid_num = %d\n", biggrid_num); - printf("total_atoms_on_proc = %d\n", total_atoms_on_proc); + printf("total_atoms_on_proc_new = %d\n", total_atoms_on_proc); // exit(0); // std::vector which_atom; // std::vector coords_x; @@ -84,6 +75,7 @@ GintInfo::GintInfo( // writeArrayToFile(coords_x.data(), coords_x.size(), "coords_x.txt"); // initialize the ijr_info + // this step needs to be done after init_atoms_, because it requires the information of is_atom_on_bgrid init_ijr_info_(ucell, gd); } @@ -114,6 +106,8 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital + biggrid_GT.e23 * biggrid_GT.e23 + biggrid_GT.e33 * biggrid_GT.e33); + is_atom_in_proc_ = std::vector(ucell_->nat, false); + // TODO: USE OPENMP TO PARALLELIZE THIS LOOP for(int i = 0; i < ntype; i++) { @@ -154,7 +148,6 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital // const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(atom_bgrid_idx); // const Vec3d tau_in_biggrid(0, 0, 0); - printf("tau_in_biggrid (%d)= %f %f %f\n", iat, tau_in_biggrid.x, tau_in_biggrid.y, tau_in_biggrid.z); const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); std::map> gint_atom_map; @@ -187,18 +180,12 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital atom_bgrid_idx.z - ucell_idx_bgrid.z * unitcell_info_->get_nbz()); auto gint_atom = std::make_shared(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb); gint_atom_map[ucell_idx_relative] = gint_atom; - if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom)) - { - biggrids_[bgrid_local_idx]->add_atom(gint_atom); - atoms_.push_back(gint_atom); - is_atom_in_proc_[iat] = true; - } - } else + atoms_.push_back(gint_atom); + } + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[ucell_idx_relative])) { - if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[ucell_idx_relative])) - { - biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[ucell_idx_relative]); - } + biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[ucell_idx_relative]); + is_atom_in_proc_[iat] = true; } } } @@ -211,7 +198,6 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital void GintInfo::init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd) { hamilt::HContainer hRGint_local(ucell.nat); - // prepare the row_index and col_index for construct AtomPairs, they are // same, name as orb_index std::vector orb_index(ucell.nat + 1); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 5ffed6e3c3..1cdb4dd357 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -1,5 +1,6 @@ #include "module_base/array_pool.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" +#include "gint_common.h" #include "gint_vl.h" #include "phi_operator.h" @@ -10,8 +11,8 @@ void Gint_vl::cal_gint() { init_hRGint_(); cal_hRGint_(); - compose_hRGint_(); - transfer_hRGint_to_hR_(); + compose_hRGint(hRGint_.get()); + transfer_hRGint_to_hR(hRGint_.get(), hR_); } //======================== @@ -40,55 +41,4 @@ void Gint_vl::cal_hRGint_() } } -void Gint_vl::compose_hRGint_() -{ - for (int iap = 0; iap < hRGint_->size_atom_pairs(); iap++) - { - auto& ap = hRGint_->get_atom_pair(iap); - const int iat1 = ap.get_atom_i(); - const int iat2 = ap.get_atom_j(); - if (iat1 > iat2) - { - // fill lower triangle matrix with upper triangle matrix - // the upper is - const hamilt::AtomPair* upper_ap = hRGint_->find_pair(iat2, iat1); - const hamilt::AtomPair* lower_ap = hRGint_->find_pair(iat1, iat2); -#ifdef __DEBUG - assert(upper_ap != nullptr); -#endif - for (int ir = 0; ir < ap.get_R_size(); ir++) - { - auto R_index = ap.get_R_index(ir); - auto upper_mat = upper_ap->find_matrix(-R_index); - auto lower_mat = lower_ap->find_matrix(R_index); - for (int irow = 0; irow < upper_mat->get_row_size(); ++irow) - { - for (int icol = 0; icol < upper_mat->get_col_size(); ++icol) - { - lower_mat->get_value(icol, irow) = upper_ap->get_value(irow, icol); - } - } - } - } - } -} - -void Gint_vl::transfer_hRGint_to_hR_() -{ -#ifdef __MPI - int size = 0; - MPI_Comm_size(MPI_COMM_WORLD, &size); - if (size == 1) - { - hR_->add(*hRGint_); - } - else - { - hamilt::transferSerials2Parallels(*hRGint_, hR_); - } -#else - hR_->add(*hRGint_); -#endif -} - } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h index fbe7f5c145..89194ba757 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h @@ -27,10 +27,6 @@ class Gint_vl // that's why we need compose_hRGint_() to fill the lower triangle matrix. void cal_hRGint_(); - void compose_hRGint_(); - - void transfer_hRGint_to_hR_(); - std::shared_ptr gint_info_; // input diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index e697d34a42..92b9eff4b9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -22,12 +22,6 @@ void PhiOperator::set_phi(double* phi) const atom->set_phi(biggrid_->get_atom_relative_coords(*atom), cols_, phi); phi += atom->get_nw(); } - if(biggrid_->get_idx() == 0) - { - printf("cols_ = %d\n", cols_); - writeArrayToFile(phi, rows_*cols_, "phi.txt"); - } - exit(0); } void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const @@ -137,7 +131,7 @@ void PhiOperator::phi_mul_phi_vldr3( const auto& r_i = atom_i->get_r(); const int iat_i = atom_i->get_iat(); - for(int j = i; j < biggrid_->get_atom_num(); ++j) + for(int j = 0; j < biggrid_->get_atom_num(); ++j) { const auto atom_j = biggrid_->get_atoms()[j]; const auto& r_j = atom_j->get_r(); @@ -150,7 +144,7 @@ void PhiOperator::phi_mul_phi_vldr3( } // FIXME may be r = r_j - r_i - const auto result = hr->find_matrix(atom_i->get_iat(), atom_j->get_iat(), r_i-r_j); + const auto result = hr->find_matrix(iat_i, iat_j, r_i-r_j); if(result == nullptr) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 2a917c2de2..42ee425cef 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -81,6 +81,7 @@ class PhiOperator // record whether the atom affects the meshgrid // is_atom_on_mgrids_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false + // FIXME,std::vector> is not a efficient data structure, we can use a 1D array to replace it. std::vector> is_atom_on_mgrids_; // the start index of the phi of each atom From db36b26cc86a06332efffa2dd74c3d6224869c3c Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 25 Dec 2024 16:23:41 +0800 Subject: [PATCH 09/47] improve efficiency ang rename some variables --- .../module_gint/grid_technique.cpp | 4 - .../module_gint/new_grid_tech/biggrid.cpp | 72 +++++++++--------- .../module_gint/new_grid_tech/biggrid.h | 34 ++++----- .../module_gint/new_grid_tech/gint_atom.cpp | 15 ++-- .../module_gint/new_grid_tech/gint_atom.h | 12 +-- .../module_gint/new_grid_tech/gint_info.cpp | 38 ---------- .../module_gint/new_grid_tech/gint_vl.cpp | 3 +- .../new_grid_tech/localcell_info.cpp | 22 ------ .../new_grid_tech/localcell_info.h | 3 - .../new_grid_tech/phi_operator.cpp | 74 +++++++++++-------- .../module_gint/new_grid_tech/phi_operator.h | 22 ++++-- .../module_gint/new_grid_tech/set_ddphi.cpp | 8 +- 12 files changed, 124 insertions(+), 183 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index 754db76e0a..394e96b844 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -453,10 +453,6 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, } } assert(count == total_atoms_on_grid); - printf("total_atoms_on_proc_old = %d\n", total_atoms_on_grid); - // writeArrayToFile(this->which_atom.data(), this->which_atom.size(), "which_atom2.txt"); - // writeArrayToFile(coord_x.data(), coord_x.size(), "coord_x2.txt"); - // writeArrayToFile(coords3.data(), coords3.size(), "coords3.txt"); return; } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index a908bb0cc8..2d74da97d9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -23,44 +23,57 @@ int BigGrid::get_mgrid_phi_len() const return len; } -std::vector BigGrid::get_atom_startidx() const +void BigGrid::set_atoms_startidx(std::vector& startidx) const { - std::vector startidx(atoms_.size()); + startidx.resize(atoms_.size()); startidx[0] = 0; for(int i = 1; i < atoms_.size(); ++i) { startidx[i] = startidx[i-1] + atoms_[i-1]->get_nw(); } - return startidx; } -std::vector BigGrid::get_atom_phi_len() const +void BigGrid::set_atoms_phi_len(std::vector& phi_len) const { - std::vector phi_len(atoms_.size()); + phi_len.resize(atoms_.size()); for(int i = 0; i < atoms_.size(); ++i) { phi_len[i] = atoms_[i]->get_nw(); } - return phi_len; } -std::vector BigGrid::get_mgrid_coords() const +void BigGrid::set_mgrids_coord(std::vector& coord) const { - std::vector coords(biggrid_info_->get_nmxyz()); + coord.resize(biggrid_info_->get_nmxyz()); Vec3d this_bgrid_coord = localcell_info_->get_bgrid_global_coord_3D(idx_); for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) { - coords[im] = biggrid_info_->get_meshgrid_coord(im) + this_bgrid_coord; + coord[im] = biggrid_info_->get_meshgrid_coord(im) + this_bgrid_coord; } - return coords; } -std::vector BigGrid::get_mgrids_local_idx() const +void BigGrid::set_mgrids_local_idx(std::vector& mgrids_idx) const { - return localcell_info_->get_mgrids_local_idx_1D(idx_); + auto index_3d = localcell_info_->biggrid_idx_1Dto3D(idx_); + Vec3i startidx( + index_3d.x * biggrid_info_->get_nmx(), + index_3d.y * biggrid_info_->get_nmy(), + index_3d.z * biggrid_info_->get_nmz()); + mgrids_idx.resize(0); + for(int ix = 0; ix < biggrid_info_->get_nmx(); ++ix) + { + for(int iy = 0; iy < biggrid_info_->get_nmy(); ++iy) + { + for(int iz = 0; iz < biggrid_info_->get_nmz(); ++iz) + { + Vec3i idx_3d(startidx.x + ix, startidx.y + iy, startidx.z + iz); + mgrids_idx.push_back(localcell_info_->meshgrid_idx_3Dto1D(idx_3d)); + } + } + } } -std::vector BigGrid::get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const +void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in_bgrid, std::vector& atom_coord) const { Vec3i this_bgrid_idx = localcell_info_->get_bgrid_global_idx_3D(idx_); @@ -68,24 +81,25 @@ std::vector BigGrid::get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_ Vec3d bgrid_relative_coord = unitcell_info_->get_relative_coord(bgrid_idx, this_bgrid_idx) + tau_in_bgrid; - std::vector coords(biggrid_info_->get_nmxyz()); + atom_coord.resize(biggrid_info_->get_nmxyz()); for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) { Vec3d mcell_coord = biggrid_info_->get_meshgrid_coord(im); - coords[im] = mcell_coord - bgrid_relative_coord; + atom_coord[im] = mcell_coord - bgrid_relative_coord; } - return coords; } -std::vector BigGrid::get_atom_relative_coords(const GintAtom& atom) const +void BigGrid::set_atom_relative_coords(const GintAtom& atom, std::vector& atom_coord) const { - return get_atom_relative_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid()); + return set_atom_relative_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid(), atom_coord); } bool BigGrid::is_atom_on_bgrid(const GintAtom& atom) const { - for(const auto& dist : get_atom_relative_coords(atom)) + std::vector coords; + this->set_atom_relative_coords(atom, coords); + for(const auto& dist : coords) { if(dist.norm() <= atom.get_rcut()) { @@ -95,24 +109,4 @@ bool BigGrid::is_atom_on_bgrid(const GintAtom& atom) const return false; } -std::vector> BigGrid::get_is_atom_on_mgrids() const -{ - std::vector> if_on_mcell; - for(const auto& atom : atoms_) - { - std::vector mcell_coords = get_atom_relative_coords(*atom); - std::vector atom_if_on_mcell(mcell_coords.size()); - for(const auto& coord : mcell_coords) - { - for(int i = 0; i < mcell_coords.size(); ++i) - { - auto coord = mcell_coords[i]; - atom_if_on_mcell[i] = coord.norm() <= atom->get_rcut(); - } - } - if_on_mcell.push_back(atom_if_on_mcell); - } - return if_on_mcell; -} - } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index e22f0c921b..b8a674292e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -23,6 +23,7 @@ class BigGrid std::shared_ptr get_unitcell_info() const {return unitcell_info_; }; std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; const std::vector>& get_atoms() const { return atoms_; }; + std::shared_ptr get_atom(int i) const { return atoms_[i]; }; // get the number of meshgrids in the big grid int get_meshgrid_num() const { return biggrid_info_->get_nmxyz(); }; @@ -37,42 +38,35 @@ class BigGrid // return: (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) int get_mgrid_phi_len() const; - // get the start index of the phi of each atom + // set the start index of the phi of each atom // return: vector[i] = \sum_{j=0}^{i-1} atoms_[j]->nw - vector get_atom_startidx() const; + void set_atoms_startidx(std::vector& startidx) const; - // get the length of phi of each atom - vector get_atom_phi_len() const; + // set the length of phi of each atom + void set_atoms_phi_len(std::vector& phi_len) const; - // get the coordinates of the meshgrids of the big grid - vector get_mgrid_coords() const; + // set the coordinates of the meshgrids of the big grid + void set_mgrids_coord(std::vector& coord) const; - // get the 1D index of the meshgrids in the local cell - vector get_mgrids_local_idx() const; + // set the 1D index of the meshgrids in the local cell + void set_mgrids_local_idx(std::vector& mgrids_idx) const; /** - * @brief Get the coordinates of the meshgrids of the big grid relative to an atom + * @brief Set the coordinates of the meshgrids of the big grid relative to an atom * * @param bgrid_idx the 3D index of the big grid, which contains the atom, in the unitcell * @param tau_in_bgrid the cartesian coordinate of the atom relative to the big grid containing it + * @param atom_coord the relative cartesian coordinates of the atom and the meshgrids */ - std::vector get_atom_relative_coords(Vec3i bgrid_idx, Vec3d tau_in_bgrid) const; + void set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in_bgrid, std::vector& atom_coord) const; - // get the coordinates of the meshgrids of the big grid relative to the atom - std::vector get_atom_relative_coords(const GintAtom& atom) const; + // a wrapper function to get the relative coordinates of the atom and the meshgrids + void set_atom_relative_coords(const GintAtom& atom, std::vector& atom_coord) const; // if the atom affects the big grid, return true, otherwise false // note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, // it may only affect a part of them. bool is_atom_on_bgrid(const GintAtom& atom) const; - - /** - * @brief Get a boolean array to indicate whether the atom affects the meshgrids - * - * @return a boolean array, the dimension of the array is atoms_->size() * biggrid_info_->get_nmxyz() - * array[i][j] = true if the ith atom affects the jth meshgrid,otherwise false. - */ - std::vector> get_is_atom_on_mgrids() const; private: // atoms that can affect the big grid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index 3ff731e8fb..db184c5a35 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -7,7 +7,7 @@ namespace ModuleGint { template -void GintAtom::set_phi(const std::vector coords, const int stride, T* phi) +void GintAtom::set_phi(const std::vector& coords, const int stride, T* phi) const { const int num_mgrids = coords.size(); @@ -38,7 +38,6 @@ void GintAtom::set_phi(const std::vector coords, const int stride, T* phi // 1e-9 is to avoid division by zero const double dist = coord.norm() < 1e-9 ? 1e-9 : coord.norm(); - // printf("coord.x = %.10f, coord.y = %.10f, coord.z = %.10f, dist = %f\n", coord.x, coord.y, coord.z, dist); if(dist > orb_->getRcut()) { // if the distance is larger than the cutoff radius, @@ -81,19 +80,15 @@ void GintAtom::set_phi(const std::vector coords, const int stride, T* phi + c3 * psi_uniform[ip + 1] + c4 * dpsi_uniform[ip + 1]; } phi[im * stride + iw] = psi * ylma[atom_->iw2_ylm[iw]]; - // printf("phi[%d] = %.10f\n", im * stride + iw, phi[im * stride + iw]); - // printf("ylma[%d] = %.10f\n", atom_->iw2_ylm[iw], ylma[atom_->iw2_ylm[iw]]); - // printf("psi = %.10f\n", psi); } - // exit(0); } } } template void GintAtom::set_phi_dphi( - const std::vector coords, const int stride, - T* phi, T* dphi_x, T* dphi_y, T* dphi_z) + const std::vector& coords, const int stride, + T* phi, T* dphi_x, T* dphi_y, T* dphi_z) const { const int num_mgrids = coords.size(); @@ -199,6 +194,6 @@ void GintAtom::set_phi_dphi( } // explicit instantiation -template void GintAtom::set_phi(const std::vector coords, const int stride, double* phi); -template void GintAtom::set_phi_dphi(const std::vector coords, const int stride, double* phi, double* dphi_x, double* dphi_y, double* dphi_z); +template void GintAtom::set_phi(const std::vector& coords, const int stride, double* phi) const; +template void GintAtom::set_phi_dphi(const std::vector& coords, const int stride, double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h index 165a68ac98..6a257c5bd5 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h @@ -29,7 +29,7 @@ class GintAtom const int get_iat() const { return iat_; }; const Vec3i& get_biggrid_idx() const { return biggrid_idx_; }; const Vec3i& get_unitcell_idx() const { return unitcell_idx_; }; - const Vec3i& get_r() const { return unitcell_idx_; }; + const Vec3i& get_R() const { return unitcell_idx_; }; const Vec3d& get_tau_in_biggrid() const { return tau_in_biggrid_; }; const Numerical_Orbital* get_orb() const { return orb_; }; @@ -46,7 +46,7 @@ class GintAtom * @param phi array to store the wave function values */ template - void set_phi(const std::vector coords, const int stride, T* phi); + void set_phi(const std::vector& coords, const int stride, T* phi) const; /** * @brief Get the wave function values and its derivative @@ -64,8 +64,8 @@ class GintAtom */ template void set_phi_dphi( - const std::vector coords, const int stride, - T* phi, T* dphi_x, T* dphi_y, T* dphi_z); + const std::vector& coords, const int stride, + T* phi, T* dphi_x, T* dphi_y, T* dphi_z) const; /** * @brief Get the wave function values and its second derivative @@ -84,9 +84,9 @@ class GintAtom */ template void set_ddphi( - const std::vector coords, const int stride, + const std::vector& coords, const int stride, T* ddphi_xx, T* ddphi_xy, T* ddphi_xz, - T* ddphi_yy, T* ddphi_yz, T* ddphi_zz); + T* ddphi_yy, T* ddphi_yz, T* ddphi_zz) const; private: // the atom object diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 5d1845a8e7..8d587f4298 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -35,44 +35,6 @@ GintInfo::GintInfo( // initialize the atoms init_atoms_(ucell_->ntype, ucell_->atoms, Phi); - - int total_atoms_on_proc = 0; - int biggrid_num = 0; - for(const auto& biggrid: biggrids_) - { - biggrid_num++; - total_atoms_on_proc += biggrid->get_atom_num(); - } - // printf("biggrid_num = %d\n", biggrid_num); - printf("total_atoms_on_proc_new = %d\n", total_atoms_on_proc); - // exit(0); - // std::vector which_atom; - // std::vector coords_x; - // std::vector mcell_coords3; - // auto mcell_cord = unitcell_info_->get_biggrid_info()->get_meshgrid_coords(); - // for(auto &coord: mcell_cord) - // { - // mcell_coords3.push_back(coord.x); - // mcell_coords3.push_back(coord.y); - // mcell_coords3.push_back(coord.z); - // } - // for(const auto& biggrid : biggrids_) - // { - // for(int i = 0; i < biggrid->get_atom_num(); i++) - // { - // // which_atom.push_back(biggrid->get_atoms()[i]->get_iat()); - // for(const auto coord: biggrid->get_atom_relative_coords(*biggrid->get_atoms()[i])) - // { - // coords_x.push_back(coord.x); - // }; - // } - // } - - // writeArrayToFile(which_atom.data(), which_atom.size(), "which_atom.txt"); - // writeArrayToFile(coords_x.data(), coords_x.size(), "coords_x.txt"); - // writeArrayToFile(mcell_coords3.data(), mcell_coords3.size(), "mcell_cord.txt"); - // exit(0); - // writeArrayToFile(coords_x.data(), coords_x.size(), "coords_x.txt"); // initialize the ijr_info // this step needs to be done after init_atoms_, because it requires the information of is_atom_on_bgrid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 1cdb4dd357..1281d514c3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -26,13 +26,14 @@ void Gint_vl::init_hRGint_() void Gint_vl::cal_hRGint_() { + PhiOperator phi_op; for(const auto& biggrid: gint_info_->get_biggrids()) { if(biggrid->get_atoms().size() == 0) { continue; } - PhiOperator phi_op(biggrid); + phi_op.set_bgrid(biggrid); ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); phi_op.set_phi(phi.get_ptr_1D()); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index 7adccefa7a..598a371928 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -116,26 +116,4 @@ namespace ModuleGint return unitcell_info_->meshgrid_idx_3Dto1D(ucell_idx_3d); } - std::vector LocalCellInfo::get_mgrids_local_idx_1D(const int index_1d) const - { - std::vector local_idx; - auto index_3d = biggrid_idx_1Dto3D(index_1d); - Vec3i startidx( - index_3d.x * biggrid_info_->get_nmx(), - index_3d.y * biggrid_info_->get_nmy(), - index_3d.z * biggrid_info_->get_nmz()); - for(int ix = 0; ix < biggrid_info_->get_nmx(); ++ix) - { - for(int iy = 0; iy < biggrid_info_->get_nmy(); ++iy) - { - for(int iz = 0; iz < biggrid_info_->get_nmz(); ++iz) - { - Vec3i idx_3d = Vec3i(startidx.x + ix, startidx.y + iy, startidx.z + iz); - local_idx.push_back(meshgrid_idx_3Dto1D(idx_3d)); - } - } - } - return local_idx; - } - } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 3efc145914..45642c87a6 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -79,9 +79,6 @@ class LocalCellInfo // transform the 1D index of a meshgrid in the local cell to the 1D index in the unit cell int get_mgrid_global_idx_1D(const int index_1d) const; - // get the local index of meshgrids of the index_1d th biggrid - std::vector get_mgrids_local_idx_1D(const int index_1d) const; - private: //==================================================================== // information about the big grid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 92b9eff4b9..4ddcb8c1a3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -4,31 +4,46 @@ namespace ModuleGint { -PhiOperator::PhiOperator(std::shared_ptr biggrid) -: biggrid_(biggrid) +void PhiOperator::set_bgrid(std::shared_ptr biggrid) { - rows_ = biggrid_->get_biggrid_info()->get_nmxyz(); + biggrid_ = biggrid; + rows_ = biggrid_->get_meshgrid_num(); cols_ = biggrid_->get_mgrid_phi_len(); - is_atom_on_mgrids_ = biggrid_->get_is_atom_on_mgrids(); - meshgrids_local_idx_ = biggrid_->get_mgrids_local_idx(); - atom_startidx_ = biggrid_->get_atom_startidx(); - atom_phi_len_ = biggrid_->get_atom_phi_len(); + + biggrid_->set_atoms_startidx(atoms_startidx_); + biggrid_->set_atoms_phi_len(atoms_phi_len_); + biggrid_->set_mgrids_local_idx(meshgrids_local_idx_); + + int atoms_num = biggrid_->get_atom_num(); + atoms_relative_coords_.resize(atoms_num); + is_atom_on_mgrid_.resize(atoms_num); + for(int i = 0; i < atoms_num; ++i) + { + biggrid_->set_atom_relative_coords(*biggrid_->get_atom(i), atoms_relative_coords_[i]); + is_atom_on_mgrid_[i].resize(rows_); + for(int j = 0; j < rows_; ++j) + { + is_atom_on_mgrid_[i][j] = atoms_relative_coords_[i][j].norm() <= biggrid_->get_atom(i)->get_rcut(); + } + } } void PhiOperator::set_phi(double* phi) const { - for(const auto& atom : biggrid_->get_atoms()) + for(int i = 0; i < biggrid_->get_atom_num(); ++i) { - atom->set_phi(biggrid_->get_atom_relative_coords(*atom), cols_, phi); + const auto atom = biggrid_->get_atom(i); + atom->set_phi(atoms_relative_coords_[i], cols_, phi); phi += atom->get_nw(); } } void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const { - for(const auto& atom : biggrid_->get_atoms()) + for(int i = 0; i < biggrid_->get_atom_num(); ++i) { - atom->set_phi_dphi(biggrid_->get_atom_relative_coords(*atom), cols_, phi, dphi_x, dphi_y, dphi_z); + const auto atom = biggrid_->get_atom(i); + atom->set_phi_dphi(atoms_relative_coords_[i], cols_, phi, dphi_x, dphi_y, dphi_z); phi += atom->get_nw(); dphi_x += atom->get_nw(); dphi_y += atom->get_nw(); @@ -40,9 +55,10 @@ void PhiOperator::set_ddphi( double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const { - for(const auto& atom : biggrid_->get_atoms()) + for(int i = 0; i < biggrid_->get_atom_num(); ++i) { - atom->set_ddphi(biggrid_->get_atom_relative_coords(*atom), cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); + const auto atom = biggrid_->get_atom(i); + atom->set_ddphi(atoms_relative_coords_[i], cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); ddphi_xx += atom->get_nw(); ddphi_xy += atom->get_nw(); ddphi_xz += atom->get_nw(); @@ -64,22 +80,22 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* for(int i = 0; i < biggrid_->get_atom_num(); ++i) { - const auto atom_i = biggrid_->get_atoms()[i]; - const auto r_i = atom_i->get_r(); + const auto atom_i = biggrid_->get_atom(i); + const auto r_i = atom_i->get_R(); if(is_symm) { const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_i->get_iat(), 0, 0, 0); - dsymm_(&side, &uplo, &atom_phi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atom_phi_len_[i], - &phi[0][atom_startidx_[i]], &cols_, &beta, &result[0][atom_startidx_[i]], &cols_); + dsymm_(&side, &uplo, &atoms_phi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atoms_phi_len_[i], + &phi[0][atoms_startidx_[i]], &cols_, &beta, &result[0][atoms_startidx_[i]], &cols_); } const int start = is_symm ? i + 1 : 0; for(int j = start; j < biggrid_->get_atom_num(); ++j) { - const auto atom_j = biggrid_->get_atoms()[j]; - const auto r_j = atom_j->get_r(); + const auto atom_j = biggrid_->get_atom(j); + const auto r_j = atom_j->get_R(); // FIXME may be r = r_j - r_i const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_j->get_iat(), r_i-r_j); @@ -99,8 +115,8 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* continue; } - dgemm_(&trans, &trans, &atom_phi_len_[j], &len, &atom_phi_len_[i], &alpha1, dm_mat->get_pointer(), &atom_phi_len_[j], - &phi[start_idx][atom_startidx_[i]], &cols_, &beta, &result[start_idx][atom_startidx_[j]], &cols_); + dgemm_(&trans, &trans, &atoms_phi_len_[j], &len, &atoms_phi_len_[i], &alpha1, dm_mat->get_pointer(), &atoms_phi_len_[j], + &phi[start_idx][atoms_startidx_[i]], &cols_, &beta, &result[start_idx][atoms_startidx_[j]], &cols_); } } } @@ -127,14 +143,14 @@ void PhiOperator::phi_mul_phi_vldr3( for(int i = 0; i < biggrid_->get_atom_num(); ++i) { - const auto atom_i = biggrid_->get_atoms()[i]; - const auto& r_i = atom_i->get_r(); + const auto atom_i = biggrid_->get_atom(i); + const auto& r_i = atom_i->get_R(); const int iat_i = atom_i->get_iat(); for(int j = 0; j < biggrid_->get_atom_num(); ++j) { - const auto atom_j = biggrid_->get_atoms()[j]; - const auto& r_j = atom_j->get_r(); + const auto atom_j = biggrid_->get_atom(j); + const auto& r_j = atom_j->get_R(); const int iat_j = atom_j->get_iat(); // only calculate the upper triangle matrix @@ -160,8 +176,8 @@ void PhiOperator::phi_mul_phi_vldr3( continue; } - dgemm_(&transa, &transb, &atom_phi_len_[j], &atom_phi_len_[i], &len, &alpha, &phi_vldr3[start_idx][atom_startidx_[j]], - &cols_,&phi[start_idx][atom_startidx_[i]], &cols_, &beta, result->get_pointer(), &atom_phi_len_[j]); + dgemm_(&transa, &transb, &atoms_phi_len_[j], &atoms_phi_len_[i], &len, &alpha, &phi_vldr3[start_idx][atoms_startidx_[j]], + &cols_,&phi[start_idx][atoms_startidx_[i]], &cols_, &beta, result->get_pointer(), &atoms_phi_len_[j]); } } } @@ -173,7 +189,7 @@ int PhiOperator::atom_pair_startidx_(int a, int b) const { for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) { - if(is_atom_on_mgrids_[a][i] && is_atom_on_mgrids_[b][i]) + if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) { return i; } @@ -185,7 +201,7 @@ int PhiOperator::atom_pair_endidx_(int a, int b) const { for(int i = biggrid_->get_meshgrid_num() - 1; i >= 0; --i) { - if(is_atom_on_mgrids_[a][i] && is_atom_on_mgrids_[b][i]) + if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) { return i; } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 42ee425cef..56f299357a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -19,7 +19,10 @@ class PhiOperator { public: // constructor - PhiOperator(std::shared_ptr biggrid); + PhiOperator()=default; + + // set the big grid that the phiOperator is associated with + void set_bgrid(std::shared_ptr biggrid); // getter int get_rows() const {return rows_;}; @@ -77,19 +80,24 @@ class PhiOperator std::vector meshgrids_local_idx_; // the big grid that the phi matrix is associated with - std::shared_ptr biggrid_; + std::shared_ptr biggrid_; + + // the relative coordinates of the atoms and the meshgrids + // atoms_relative_coords_[i][j] is the relative coordinate of the jth meshgrid and the ith atom + std::vector> atoms_relative_coords_; // record whether the atom affects the meshgrid - // is_atom_on_mgrids_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false + // is_atom_on_mgrid_[i][j] = true if the ith atom affects the jth meshgrid, otherwise false // FIXME,std::vector> is not a efficient data structure, we can use a 1D array to replace it. - std::vector> is_atom_on_mgrids_; + std::vector> is_atom_on_mgrid_; // the start index of the phi of each atom - std::vector atom_startidx_; + std::vector atoms_startidx_; // the length of phi of each atom - // atom_phi_len_[i] = biggrid_->get_atoms()[i]->get_nw() - std::vector atom_phi_len_; + // atoms_phi_len_[i] = biggrid_->get_atom(i)->get_nw() + // TODO: remove it + std::vector atoms_phi_len_; }; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index 8652651c0a..5ed1afef33 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -9,9 +9,9 @@ namespace ModuleGint template void GintAtom::set_ddphi( - const std::vector coords, const int stride, + const std::vector& coords, const int stride, T* ddphi_xx, T* ddphi_xy, T* ddphi_xz, - T* ddphi_yy, T* ddphi_yz, T* ddphi_zz) + T* ddphi_yy, T* ddphi_yz, T* ddphi_zz) const { ModuleBase::timer::tick("GintAtom", "set_ddphi"); @@ -257,8 +257,8 @@ void GintAtom::set_ddphi( } // explicit instantiation -template void GintAtom::set_ddphi(const std::vector coords, const int stride, +template void GintAtom::set_ddphi(const std::vector& coords, const int stride, double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, - double* ddphi_yy, double* ddphi_yz, double* ddphi_zz); + double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const; } \ No newline at end of file From bfcc2fba4d1cb6209f45fb3fae259b07b8826543 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 25 Dec 2024 17:06:11 +0800 Subject: [PATCH 10/47] small change --- .../module_gint/new_grid_tech/biggrid.cpp | 10 +++++----- .../module_gint/new_grid_tech/biggrid.h | 4 ++-- .../module_gint/new_grid_tech/gint_info.cpp | 2 +- .../module_gint/new_grid_tech/phi_operator.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index 2d74da97d9..4ff1e548e6 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -84,24 +84,24 @@ void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in atom_coord.resize(biggrid_info_->get_nmxyz()); for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) { - Vec3d mcell_coord = biggrid_info_->get_meshgrid_coord(im); + const Vec3d& mcell_coord = biggrid_info_->get_meshgrid_coord(im); atom_coord[im] = mcell_coord - bgrid_relative_coord; } } -void BigGrid::set_atom_relative_coords(const GintAtom& atom, std::vector& atom_coord) const +void BigGrid::set_atom_relative_coords(std::shared_ptr atom, std::vector& atom_coord) const { - return set_atom_relative_coords(atom.get_biggrid_idx(), atom.get_tau_in_biggrid(), atom_coord); + return set_atom_relative_coords(atom->get_biggrid_idx(), atom->get_tau_in_biggrid(), atom_coord); } -bool BigGrid::is_atom_on_bgrid(const GintAtom& atom) const +bool BigGrid::is_atom_on_bgrid(std::shared_ptr atom) const { std::vector coords; this->set_atom_relative_coords(atom, coords); for(const auto& dist : coords) { - if(dist.norm() <= atom.get_rcut()) + if(dist.norm() <= atom->get_rcut()) { return true; } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index b8a674292e..1869de76a6 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -61,12 +61,12 @@ class BigGrid void set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in_bgrid, std::vector& atom_coord) const; // a wrapper function to get the relative coordinates of the atom and the meshgrids - void set_atom_relative_coords(const GintAtom& atom, std::vector& atom_coord) const; + void set_atom_relative_coords(std::shared_ptr atom, std::vector& atom_coord) const; // if the atom affects the big grid, return true, otherwise false // note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, // it may only affect a part of them. - bool is_atom_on_bgrid(const GintAtom& atom) const; + bool is_atom_on_bgrid(std::shared_ptr atom) const; private: // atoms that can affect the big grid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 8d587f4298..fd755a539c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -144,7 +144,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital gint_atom_map[ucell_idx_relative] = gint_atom; atoms_.push_back(gint_atom); } - if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(*gint_atom_map[ucell_idx_relative])) + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(gint_atom_map[ucell_idx_relative])) { biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[ucell_idx_relative]); is_atom_in_proc_[iat] = true; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 4ddcb8c1a3..7ee2142a8f 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -19,7 +19,7 @@ void PhiOperator::set_bgrid(std::shared_ptr biggrid) is_atom_on_mgrid_.resize(atoms_num); for(int i = 0; i < atoms_num; ++i) { - biggrid_->set_atom_relative_coords(*biggrid_->get_atom(i), atoms_relative_coords_[i]); + biggrid_->set_atom_relative_coords(biggrid_->get_atom(i), atoms_relative_coords_[i]); is_atom_on_mgrid_[i].resize(rows_); for(int j = 0; j < rows_; ++j) { From c1e5b4d7a211e0e59faca21ffa723a04a574a12c Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 25 Dec 2024 17:28:39 +0800 Subject: [PATCH 11/47] add openmp support to gint_vl --- .../module_gint/new_grid_tech/gint_vl.cpp | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 1281d514c3..7f2cb08069 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -1,5 +1,7 @@ #include "module_base/array_pool.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" +#include "module_base/blas_connector.h" #include "gint_common.h" #include "gint_vl.h" #include "phi_operator.h" @@ -26,19 +28,31 @@ void Gint_vl::init_hRGint_() void Gint_vl::cal_hRGint_() { - PhiOperator phi_op; - for(const auto& biggrid: gint_info_->get_biggrids()) +// be careful!! +// each thread will have a copy of hRGint_, this may cause a lot of memory usage +#pragma omp parallel { - if(biggrid->get_atoms().size() == 0) + PhiOperator phi_op; + hamilt::HContainer hRGint_local(*hRGint_); +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) { - continue; + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi(phi.get_ptr_1D()); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_local); + } +#pragma omp critical + { + BlasConnector::axpy(hRGint_local.get_nnr(), 1.0, hRGint_local.get_wrapper(), + 1, hRGint_->get_wrapper(), 1); } - phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi(phi.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), hRGint_.get()); } } From 4ecfb0c35fa7def50981fea75f30e82376ff481b Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 25 Dec 2024 17:32:33 +0800 Subject: [PATCH 12/47] remove some comments --- .../module_gint/new_grid_tech/gint_info.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index fd755a539c..7b2a8a7fbd 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -96,19 +96,6 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital const Vec3d tau_in_biggrid = delta.x * unitcell_info_->get_biggrid_info()->get_vec1() + delta.y * unitcell_info_->get_biggrid_info()->get_vec2() + delta.z * unitcell_info_->get_biggrid_info()->get_vec3(); - // const Vec3i atom_bgrid_idx = unitcell_info_->get_biggrid_idx_3d(atom.tau[j]); - // int b1 = static_cast(atom.taud[j].x * unitcell_info_->get_nbx()); - // int b2 = static_cast(atom.taud[j].y * unitcell_info_->get_nby()); - // int b3 = static_cast(atom.taud[j].z * unitcell_info_->get_nbz()); - // if(true) - // { - // printf("atom_bgrid_idx (%d) = %d %d %d\n", iat, atom_bgrid_idx.x, atom_bgrid_idx.y, atom_bgrid_idx.z); - // printf("atom.taud (%d) = %f %f %f\n", iat, atom.taud[j].x, atom.taud[j].y, atom.taud[j].z); - // printf("atom.tau (%d) = %f %f %f\n", iat, atom.tau[j].x, atom.tau[j].y, atom.tau[j].z); - // printf("b1 b2 b3 = %d %d %d\n", b1, b2, b3); - // } - // const Vec3d tau_in_biggrid = atom.tau[j] - unitcell_info_->get_biggrid_coord(atom_bgrid_idx); - // const Vec3d tau_in_biggrid(0, 0, 0); const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); std::map> gint_atom_map; From ef8f3f19f59cd1f0b61f88c43f00eff0f132a687 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 25 Dec 2024 17:35:44 +0800 Subject: [PATCH 13/47] remove some comments --- .../module_gint/new_grid_tech/gint_helper.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index f7628eecca..3779cf0344 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -46,7 +46,7 @@ inline double pow_int(const double base, const int exp) inline int floor_div(const int a, const int b) { - // a ^ b < 0 is equivalent to a and b have different signs + // a ^ b < 0 means a and b have different signs return a / b - (a % b != 0 && (a ^ b) < 0); }; @@ -62,22 +62,18 @@ inline int ceil_div(const int a, const int b) template void writeArrayToFile(T* array, int n, const std::string& filename) { - // 打开文件,使用 ofstream 来写入数据 std::ofstream outFile(filename); - // 检查文件是否成功打开 if (!outFile.is_open()) { - std::cerr << "无法打开或创建文件: " << filename << std::endl; + std::cerr << "can't open file: " << filename << std::endl; return; } - // 写入数组的前n个元素到文件中 for (int i = 0; i < n; ++i) { outFile < Date: Wed, 25 Dec 2024 22:05:28 +0800 Subject: [PATCH 14/47] remove some unused code related to spin in gint_k --- .gitignore | 6 ++++++ deps/LibComm | 1 + deps/LibRI | 1 + 3 files changed, 8 insertions(+) create mode 160000 deps/LibComm create mode 160000 deps/LibRI diff --git a/.gitignore b/.gitignore index 4d8d089055..561b23ab20 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,9 @@ time.json __pycache__ abacus.json *.npy +r0*/* +tests/* +TD*/* +cmake/* +*.nsys-rep +*.sh \ No newline at end of file diff --git a/deps/LibComm b/deps/LibComm new file mode 160000 index 0000000000..ec984514b4 --- /dev/null +++ b/deps/LibComm @@ -0,0 +1 @@ +Subproject commit ec984514b44480e98bd1578bcacca7a19c849724 diff --git a/deps/LibRI b/deps/LibRI new file mode 160000 index 0000000000..bd299faeaa --- /dev/null +++ b/deps/LibRI @@ -0,0 +1 @@ +Subproject commit bd299faeaa184b912e4bdf5c0e182dfb7f47272a From 036cf8567bd41247897c254b19f67f1a4c74035a Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 30 Dec 2024 16:40:57 +0800 Subject: [PATCH 15/47] enable rho calculation --- source/module_elecstate/elecstate_lcao.cpp | 15 ++-- source/module_esolver/esolver_ks_lcao.h | 3 +- source/module_esolver/lcao_before_scf.cpp | 3 +- .../hamilt_lcaodft/hamilt_lcao.cpp | 3 - .../hamilt_lcaodft/hamilt_lcao.h | 3 - .../operator_lcao/veff_lcao.cpp | 2 +- .../hamilt_lcaodft/operator_lcao/veff_lcao.h | 2 - .../module_gint/CMakeLists.txt | 2 + .../module_gint/new_grid_tech/gint.cpp | 8 +++ .../module_gint/new_grid_tech/gint.h | 27 ++++++++ .../module_gint/new_grid_tech/gint_common.cpp | 69 +++++++++++++++++++ .../module_gint/new_grid_tech/gint_common.h | 6 ++ .../module_gint/new_grid_tech/gint_info.h | 1 + .../module_gint/new_grid_tech/gint_rho.cpp | 54 +++++++++++++++ .../module_gint/new_grid_tech/gint_rho.h | 41 +++++++++++ .../module_gint/new_grid_tech/gint_vl.cpp | 5 ++ .../module_gint/new_grid_tech/gint_vl.h | 12 ++-- .../new_grid_tech/localcell_info.h | 1 + .../new_grid_tech/phi_operator.cpp | 21 +++++- .../module_gint/new_grid_tech/phi_operator.h | 9 ++- 20 files changed, 258 insertions(+), 29 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index 748ef7a9b8..c30802cca2 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -10,6 +10,8 @@ #include "module_parameter/parameter.h" #include "elecstate_lcao_cal_tau.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h" + #include namespace elecstate @@ -60,8 +62,10 @@ void ElecStateLCAO>::psiToRho(const psi::Psigint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint - Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); - this->gint_k->cal_gint(&inout); + // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); + // this->gint_k->cal_gint(&inout); + ModuleGint::Gint_rho gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); + gint_rho.cal_gint(); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { @@ -94,9 +98,12 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint - Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); + // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); - this->gint_gamma->cal_gint(&inout); + // this->gint_gamma->cal_gint(&inout); + ModuleGint::Gint_rho gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); + gint_rho.cal_gint(); + if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index 6585bb1d30..a00bdffadf 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -6,6 +6,7 @@ #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" #include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint.h" #ifdef __DEEPKS #include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" #endif @@ -76,8 +77,6 @@ class ESolver_KS_LCAO : public ESolver_KS Grid_Technique GridT; - std::shared_ptr gint_info; - TwoCenterBundle two_center_bundle_; rdmft::RDMFT rdmft_solver; // added by jghan for rdmft calculation, 2024-03-16 diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 51e3f1d2ac..8b866cfc84 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -116,7 +116,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) d2psi_u, PARAM.inp.nstream); - this->gint_info = std::make_shared( + auto gint_info = std::make_shared( this->pw_big->nbx, this->pw_big->nby, this->pw_big->nbz, @@ -132,6 +132,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) orb_.Phi, ucell, GlobalC::GridD); + ModuleGint::Gint::set_gint_info(gint_info); psi_u.clear(); psi_u.shrink_to_fit(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 3568d8cb15..2026e07cda 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -40,7 +40,6 @@ #include "operator_lcao/td_nonlocal_lcao.h" #include "operator_lcao/veff_lcao.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" #include namespace hamilt { @@ -104,8 +103,6 @@ HamiltLCAO::HamiltLCAO(Gint_Gamma* GG_in, this->sR = new HContainer(paraV); this->hsk = new HS_Matrix_K(paraV); - this->gint_info = gint_info_in; - // Effective potential term (\sum_r ) is registered without template std::vector pot_register_in; if (PARAM.inp.vl_in_h) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index 6d71c1fb20..1483831ab7 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -22,7 +22,6 @@ #include "module_ri/Exx_LRI.h" #endif #include -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" namespace hamilt { @@ -144,8 +143,6 @@ class HamiltLCAO : public Hamilt const int istep = 0; - std::shared_ptr gint_info; - // sk and hk will be refactored to HamiltLCAO later // std::vector sk; // std::vector hk; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 6de1676e95..7903fa8379 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -151,7 +151,7 @@ void Veff>::contributeHR(void) { // Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); // this->GG->cal_vlocal(&inout, this->new_e_iteration); - ModuleGint::Gint_vl gint_vl(this->gint_info, vr_eff1, this->hR); + ModuleGint::Gint_vl gint_vl(vr_eff1, this->hR); gint_vl.cal_gint(); } // this->GG->transfer_pvpR(this->hR,this->ucell); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h index d235c893c7..65f6de8e27 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h @@ -4,12 +4,10 @@ #include "module_elecstate/potentials/potential_new.h" #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" #include "operator_lcao.h" #include "module_cell/module_neighbor/sltk_grid_driver.h" #include "module_cell/unitcell.h" #include -#include namespace hamilt { diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index cd5765fed6..227940c269 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -35,7 +35,9 @@ list(APPEND objects new_grid_tech/divide_info.cpp new_grid_tech/gint_atom.cpp new_grid_tech/gint_info.cpp + new_grid_tech/gint.cpp new_grid_tech/gint_vl.cpp + new_grid_tech/gint_rho.cpp new_grid_tech/localcell_info.cpp new_grid_tech/phi_operator.cpp new_grid_tech/set_ddphi.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp new file mode 100644 index 0000000000..e766c46d9f --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp @@ -0,0 +1,8 @@ +#include "gint.h" + +namespace ModuleGint +{ + +std::shared_ptr Gint::gint_info_ = nullptr; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h new file mode 100644 index 0000000000..9fd1a567ab --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h @@ -0,0 +1,27 @@ +#pragma once +#include +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint +{ + public: + Gint() = default; + virtual ~Gint() = default; + + virtual void cal_gint() = 0; + + // note that gint_info_ is a static member variable + // it is shared by all instances of Gint + static void set_gint_info(std::shared_ptr gint_info) + { + gint_info_ = gint_info; + } + + protected: + static std::shared_ptr gint_info_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp index cccb88dfc5..75591050f3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -1,6 +1,7 @@ #include "gint_common.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" +#include "module_parameter/parameter.h" namespace ModuleGint { @@ -57,6 +58,74 @@ void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContain #endif } +// gint_info should not have been a parameter, but it was added to initialize DMRGint_full +// In the future, we might try to remove the gint_info parameter +void transfer_DM_to_DMGint( + std::shared_ptr gint_info, + std::vector*> DM, + std::vector>> DMRGint) +{ + // To check whether input parameter DM2D has been initialized +#ifdef __DEBUG + assert(PARAM.inp.nspin == DM.size() + && "The size of DM should be equal to the number of spins!"); +#endif + + if (PARAM.inp.nspin != 4) + { + for (int is = 0; is < PARAM.inp.nspin; is++) + { +#ifdef __MPI + hamilt::transferParallels2Serials(*DM[is], DMRGint[is].get()); +#else + DMRGint[is]->set_zero(); + DMRGint[is]->add(*DM[is]); +#endif + } + } else // NSPIN=4 case + { +#ifdef __MPI + std::shared_ptr> DM_full = gint_info->get_hr(2); + hamilt::transferParallels2Serials(*DM[0], DM_full.get()); +#else + hamilt::HContainer* DM_full = DM[0]; +#endif + std::vector tmp_pointer(4, nullptr); + for (int iap = 0; iap < DM_full->size_atom_pairs(); iap++) + { + auto& ap = DM_full->get_atom_pair(iap); + const int iat1 = ap.get_atom_i(); + const int iat2 = ap.get_atom_j(); + for (int ir = 0; ir < ap.get_R_size(); ir++) + { + const ModuleBase::Vector3 r_index = ap.get_R_index(ir); + for (int is = 0; is < 4; is++) + { + tmp_pointer[is] = + DMRGint[is]->find_matrix(iat1, iat2, r_index)->get_pointer(); + } + double* data_full = ap.get_pointer(ir); + for (int irow = 0; irow < ap.get_row_size(); irow += 2) + { + for (int icol = 0; icol < ap.get_col_size(); icol += 2) + { + *(tmp_pointer[0])++ = data_full[icol]; + *(tmp_pointer[1])++ = data_full[icol + 1]; + } + data_full += ap.get_col_size(); + for (int icol = 0; icol < ap.get_col_size(); icol += 2) + { + *(tmp_pointer[2])++ = data_full[icol]; + *(tmp_pointer[3])++ = data_full[icol + 1]; + } + data_full += ap.get_col_size(); + } + } + } + } +} + + template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); template void transfer_hRGint_to_hR(const hamilt::HContainer>* hRGint, hamilt::HContainer>* hR); } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h index 2f83d2f3cb..f4b79818e7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h @@ -1,5 +1,6 @@ #pragma once #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" namespace ModuleGint { @@ -9,4 +10,9 @@ namespace ModuleGint template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); + void transfer_DM_to_DMGint( + std::shared_ptr gint_info, + std::vector*> DM, + std::vector>> DMRGint); + } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index b8d1cf62d4..176e4db946 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -30,6 +30,7 @@ class GintInfo // getter functions std::vector> get_biggrids() const { return biggrids_; }; + double get_local_mgrid_num() const { return localcell_info_->get_mgrid_num(); }; double get_mgrid_volume() const { return unitcell_info_->get_meshgrid_info()->get_volume(); }; //========================================= diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp new file mode 100644 index 0000000000..72eb658e90 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp @@ -0,0 +1,54 @@ +#include "module_base/array_pool.h" +#include "module_base/global_function.h" +#include "gint_rho.h" +#include "gint_common.h" +#include "phi_operator.h" + +namespace ModuleGint +{ + +void Gint_rho::cal_gint() +{ + init_DMRGint_(); + transfer_DM_to_DMGint(gint_info_, DMR_vec_, DMRGint_vec_); + cal_rho_(); +} + +void Gint_rho::init_DMRGint_() +{ + DMRGint_vec_.resize(nspin_); + for (int is = 0; is < nspin_; is++) + { + const int npol = (nspin_ == 4 ? 2 : 1); + DMRGint_vec_[is] = gint_info_->get_hr(npol); + } +} + +void Gint_rho::cal_rho_() +{ +#pragma omp parallel + { + PhiOperator phi_op; +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_DMR(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi(phi.get_ptr_1D()); + for (int is = 0; is < nspin_; is++) + { + ModuleBase::zeros(phi_DMR.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_dm(phi.get_ptr_2D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_2D()); + phi_op.phi_dot_phi_dm(phi.get_ptr_2D(), phi_DMR.get_ptr_2D(), rho_[is]); + } + } + } +} + + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h new file mode 100644 index 0000000000..319665de4f --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_rho : public Gint +{ + public: + Gint_rho( + const std::vector*>& DMR_vec, + const int nspin, + double **rho) + : DMR_vec_(DMR_vec), nspin_(nspin), rho_(rho) {}; + + void cal_gint(); + + private: + void init_DMRGint_(); + + void cal_rho_(); + + // input + const std::vector*> DMR_vec_; + const int nspin_; + + // output + double **rho_; + + //======================== + // Intermediate variables + //======================== + std::vector>> DMRGint_vec_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 7f2cb08069..7bb45e87e8 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -1,4 +1,5 @@ #include "module_base/array_pool.h" +#include "module_base/timer.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" #include "module_base/blas_connector.h" @@ -11,10 +12,14 @@ namespace ModuleGint void Gint_vl::cal_gint() { + ModuleBase::timer::tick("Gint_vl", "cal_gint"); + init_hRGint_(); cal_hRGint_(); compose_hRGint(hRGint_.get()); transfer_hRGint_to_hR(hRGint_.get(), hR_); + + ModuleBase::timer::tick("Gint_vl", "cal_gint"); } //======================== diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h index 89194ba757..a7ca034295 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h @@ -3,32 +3,30 @@ #include #include #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" #include "gint_info.h" namespace ModuleGint { -class Gint_vl +class Gint_vl : public Gint { public: Gint_vl( - std::shared_ptrgint_info, const double* vr_eff, hamilt::HContainer* hR) - : gint_info_(gint_info), vr_eff_(vr_eff), hR_(hR), dr3_(gint_info->get_mgrid_volume()){}; + : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; - void cal_gint(); + void cal_gint() override; private: void init_hRGint_(); // note that only the upper triangle matrix of hR is calculated - // that's why we need compose_hRGint_() to fill the lower triangle matrix. + // that's why we need compose_hRGint() to fill the lower triangle matrix. void cal_hRGint_(); - std::shared_ptr gint_info_; - // input const double* vr_eff_; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 45642c87a6..25125a54b0 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -24,6 +24,7 @@ class LocalCellInfo const int get_nby() const { return nby_; }; const int get_nbz() const { return nbz_; }; const int get_biggrid_num() const { return nbxyz_; }; + const int get_mgrid_num() const { return nmxyz_; }; std::shared_ptr get_unitcell_info() const { return unitcell_info_; }; std::shared_ptr get_biggrid_info() const { return unitcell_info_->get_biggrid_info(); }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 7ee2142a8f..5cda758add 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -68,7 +68,10 @@ void PhiOperator::set_ddphi( } } -void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* const* phi, double** result, const bool is_symm) const +void PhiOperator::phi_mul_dm( + const double* const* phi, + const hamilt::HContainer& DM, + const bool is_symm, double** phi_dm) const { // parameters for lapack subroutines constexpr char side = 'L'; @@ -87,7 +90,7 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* { const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_i->get_iat(), 0, 0, 0); dsymm_(&side, &uplo, &atoms_phi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atoms_phi_len_[i], - &phi[0][atoms_startidx_[i]], &cols_, &beta, &result[0][atoms_startidx_[i]], &cols_); + &phi[0][atoms_startidx_[i]], &cols_, &beta, &phi_dm[0][atoms_startidx_[i]], &cols_); } const int start = is_symm ? i + 1 : 0; @@ -116,7 +119,7 @@ void PhiOperator::phi_mul_dm(const hamilt::HContainer& DM, const double* } dgemm_(&trans, &trans, &atoms_phi_len_[j], &len, &atoms_phi_len_[i], &alpha1, dm_mat->get_pointer(), &atoms_phi_len_[j], - &phi[start_idx][atoms_startidx_[i]], &cols_, &beta, &result[start_idx][atoms_startidx_[j]], &cols_); + &phi[start_idx][atoms_startidx_[i]], &cols_, &beta, &phi_dm[start_idx][atoms_startidx_[j]], &cols_); } } } @@ -182,6 +185,18 @@ void PhiOperator::phi_mul_phi_vldr3( } } +void PhiOperator::phi_dot_phi_dm( + const double* const* phi, + const double* const* phi_dm, + double* rho) const +{ + const int inc = 1; + for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + { + rho[meshgrids_local_idx_[i]] += ddot_(&cols_, phi[i], &inc, phi_dm[i], &inc); + } +} + //=============================== // private methods //=============================== diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 56f299357a..bb73eb2a8a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -43,10 +43,9 @@ class PhiOperator double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const; void phi_mul_dm( - const hamilt::HContainer& DM, const double* const* phi, - double** result, - const bool is_symm) const; + const hamilt::HContainer& DM, + const bool is_symm, double** phi_dm) const; void phi_mul_vldr3( const double* vl, @@ -59,6 +58,10 @@ class PhiOperator const double* const* phi_vldr3, hamilt::HContainer* hr) const; + void phi_dot_phi_dm( + const double* const* phi, + const double* const* phi_dm, + double* rho) const; private: From f2231534884815da1e11eafb012b304d7b74ad7c Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 30 Dec 2024 23:44:26 +0800 Subject: [PATCH 16/47] support fvl calculation --- .../pulay_force_stress_gint.hpp | 21 +++-- .../module_gint/CMakeLists.txt | 1 + .../module_gint/new_grid_tech/gint_common.cpp | 3 +- .../module_gint/new_grid_tech/gint_fvl.cpp | 91 +++++++++++++++++++ .../module_gint/new_grid_tech/gint_fvl.h | 52 +++++++++++ .../module_gint/new_grid_tech/gint_rho.cpp | 3 +- .../module_gint/new_grid_tech/gint_rho.h | 2 +- .../module_gint/new_grid_tech/gint_tau.cpp | 51 +++++++++++ .../module_gint/new_grid_tech/gint_tau.h | 39 ++++++++ .../new_grid_tech/phi_operator.cpp | 65 +++++++++++++ .../module_gint/new_grid_tech/phi_operator.h | 14 +++ 11 files changed, 331 insertions(+), 11 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index feb567eca2..ca733aa08c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -3,6 +3,7 @@ #include "module_hamilt_lcao/hamilt_lcaodft/stress_tools.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_parameter/parameter.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h" namespace PulayForceStress { template @@ -19,22 +20,28 @@ namespace PulayForceStress { if (set_dmr_gint) { gint.transfer_DM2DtoGrid(dm.get_DMR_vector()); } // 2d block to grid const int nspin = PARAM.inp.nspin; - for (int is = 0; is < nspin; ++is) + if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - const double* vr_eff1 = pot->get_effective_v(is); - const double* vofk_eff1 = nullptr; - if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) + for (int is = 0; is < nspin; ++is) { + const double* vr_eff1 = pot->get_effective_v(is); + const double* vofk_eff1 = nullptr; vofk_eff1 = pot->get_effective_vofk(is); Gint_inout inout(is, vr_eff1, vofk_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force_meta); gint.cal_gint(&inout); } - else + } + else + { + std::vector vr_eff(nspin, nullptr); + for(int is = 0; is < nspin; ++is) { - Gint_inout inout(is, vr_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force); - gint.cal_gint(&inout); + vr_eff[is] = pot->get_effective_v(is); } + ModuleGint::Gint_fvl gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s); + gint_fvl.cal_gint(); } + if (isstress) { StressTools::stress_fill(-1.0, ucell.omega, s); } } } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 227940c269..7b4e0532be 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -38,6 +38,7 @@ list(APPEND objects new_grid_tech/gint.cpp new_grid_tech/gint_vl.cpp new_grid_tech/gint_rho.cpp + new_grid_tech/gint_fvl.cpp new_grid_tech/localcell_info.cpp new_grid_tech/phi_operator.cpp new_grid_tech/set_ddphi.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp index 75591050f3..c58494b2e9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -85,7 +85,8 @@ void transfer_DM_to_DMGint( } else // NSPIN=4 case { #ifdef __MPI - std::shared_ptr> DM_full = gint_info->get_hr(2); + const int npol = 2; + std::shared_ptr> DM_full = gint_info->get_hr(npol); hamilt::transferParallels2Serials(*DM[0], DM_full.get()); #else hamilt::HContainer* DM_full = DM[0]; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp new file mode 100644 index 0000000000..4860b5bd8b --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp @@ -0,0 +1,91 @@ +#include "module_base/array_pool.h" +#include "module_base/global_function.h" +#include "gint_fvl.h" +#include "gint_common.h" +#include "phi_operator.h" + +namespace ModuleGint +{ + +void Gint_fvl::cal_gint() +{ + init_DMRGint_(); + transfer_DM_to_DMGint(gint_info_, DMR_vec_, DMRGint_vec_); + cal_fvl_svl_(); +} + +void Gint_fvl::init_DMRGint_() +{ + DMRGint_vec_.resize(nspin_); + for (int is = 0; is < nspin_; is++) + { + DMRGint_vec_[is] = gint_info_->get_hr(); + } +} + +void Gint_fvl::cal_fvl_svl_() +{ +#pragma omp parallel + { + PhiOperator phi_op; + ModuleBase::matrix* fvl_thread = nullptr; + ModuleBase::matrix* svl_thread = nullptr; + if(isforce_) + { + fvl_thread = new ModuleBase::matrix(*fvl_); + fvl_thread->zero_out(); + } + if(isstress_) + { + svl_thread = new ModuleBase::matrix(*svl_); + svl_thread->zero_out(); + } +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + for (int is = 0; is < nspin_; is++) + { + ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(phi_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_dm(phi_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_2D()); + if(isforce_) + { + phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), fvl_thread); + } + if(isstress_) + { + phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), svl_thread); + } + } + } +#pragma omp critical + { + if(isforce_) + { + fvl_[0] += fvl_thread[0]; + delete fvl_thread; + } + if(isstress_) + { + svl_[0] += svl_thread[0]; + delete svl_thread; + } + } + } +} + + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h new file mode 100644 index 0000000000..365e5e4c11 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_base/matrix.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_fvl : public Gint +{ + public: + Gint_fvl( + const int nspin, + const std::vector& vr_eff, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl) + : nspin_(nspin), vr_eff_(vr_eff), DMR_vec_(DMR_vec), + isforce_(isforce), isstress_(isstress), fvl_(fvl), svl_(svl), + dr3_(gint_info_->get_mgrid_volume()) {}; + + void cal_gint() override; + + private: + void init_DMRGint_(); + + void cal_fvl_svl_(); + + // input + const int nspin_; + std::vector vr_eff_; + std::vector*> DMR_vec_; + const bool isforce_; + const bool isstress_; + + // output + ModuleBase::matrix* fvl_; + ModuleBase::matrix* svl_; + + // intermediate variables + std::vector>> DMRGint_vec_; + + double dr3_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp index 72eb658e90..66d95abd8c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp @@ -19,8 +19,7 @@ void Gint_rho::init_DMRGint_() DMRGint_vec_.resize(nspin_); for (int is = 0; is < nspin_; is++) { - const int npol = (nspin_ == 4 ? 2 : 1); - DMRGint_vec_[is] = gint_info_->get_hr(npol); + DMRGint_vec_[is] = gint_info_->get_hr(); } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h index 319665de4f..3b3dbcca31 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h @@ -18,7 +18,7 @@ class Gint_rho : public Gint double **rho) : DMR_vec_(DMR_vec), nspin_(nspin), rho_(rho) {}; - void cal_gint(); + void cal_gint() override; private: void init_DMRGint_(); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp new file mode 100644 index 0000000000..2a8319e470 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp @@ -0,0 +1,51 @@ +#include "module_base/array_pool.h" +#include "gint_tau.h" +#include "gint_common.h" +#include "phi_operator.h" + +namespace ModuleGint +{ + +void Gint_tau::cal_gint() +{ + init_DMRGint_(); + transfer_DM_to_DMGint(gint_info_, DMR_vec_, DMRGint_vec_); + cal_tau_(); +} + +void Gint_tau::init_DMRGint_() +{ + DMRGint_vec_.resize(nspin_); + for (int is = 0; is < nspin_; is++) + { + const int npol = (nspin_ == 4 ? 2 : 1); + DMRGint_vec_[is] = gint_info_->get_hr(npol); + } +} + +void Gint_tau::cal_tau_() +{ +#pragma omp parallel + { + PhiOperator phi_op; +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_DMR(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi(phi.get_ptr_1D()); + for (int is = 0; is < nspin_; is++) + { + phi_op.phi_mul_dm(phi.get_ptr_2D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_2D()); + phi_op.phi_dot_phi_dm(phi.get_ptr_2D(), phi_DMR.get_ptr_2D(), tau[is]); + } + } + } +} + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h new file mode 100644 index 0000000000..69de8e3df2 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_tau : public Gint +{ + public: + gint_tau( + const std::vector& DMR_vec, + const int nspin, + std::vector& tau); + + void cal_gint() override; + + private: + void init_DMRGint_(); + + void cal_tau_(); + + // input + const std::vector*> DMR_vec_; + const int nspin_; + + // output + double **kin_; + + //======================== + // Intermediate variables + //======================== + std::vector>> DMRGint_vec_; +}; + +} // namespace ModuleGint diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 5cda758add..044d52a4e9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -1,5 +1,6 @@ #include "phi_operator.h" #include "module_base/blas_connector.h" +#include "module_base/matrix.h" namespace ModuleGint { @@ -197,6 +198,70 @@ void PhiOperator::phi_dot_phi_dm( } } +void PhiOperator::phi_dot_dphi( + const double* const* phi, + const double* const* dphi_x, + const double* const* dphi_y, + const double* const* dphi_z, + ModuleBase::matrix *fvl) const +{ + for(int i = 0; i < biggrid_->get_atom_num(); ++i) + { + const int start_idx = atoms_startidx_[i]; + const int phi_len = atoms_phi_len_[i]; + double rx = 0, ry = 0, rz = 0; + for(int j = 0; j < biggrid_->get_meshgrid_num(); ++j) + { + for(int k = 0; k < phi_len; ++k) + { + const double phi_val = phi[j][start_idx + k]; + rx += phi_val * dphi_x[j][start_idx + k]; + ry += phi_val * dphi_y[j][start_idx + k]; + rz += phi_val * dphi_z[j][start_idx + k]; + } + } + fvl[0](i, 0) += rx * 2; + fvl[0](i, 1) += ry * 2; + fvl[0](i, 2) += rz * 2; + } +} + +void PhiOperator::phi_dot_dphi_r( + const double* const *phi, + const double* const *dphi_x, + const double* const *dphi_y, + const double* const *dphi_z, + ModuleBase::matrix *svl) const +{ + double sxx = 0, sxy = 0, sxz = 0, syy = 0, syz = 0, szz = 0; + for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + { + for(int j = 0; j < biggrid_->get_atom_num(); ++j) + { + const int start_idx = atoms_startidx_[j]; + for(int k = 0; k < atoms_phi_len_[j]; ++k) + { + const int col_idx = start_idx + k; + const double phi_val = phi[i][col_idx]; + const Vec3d& r3 = atoms_relative_coords_[j][i]; + sxx += phi_val * dphi_x[i][col_idx] * r3[0]; + sxy += phi_val * dphi_x[i][col_idx] * r3[1]; + sxz += phi_val * dphi_x[i][col_idx] * r3[2]; + syy += phi_val * dphi_y[i][col_idx] * r3[1]; + syz += phi_val * dphi_y[i][col_idx] * r3[2]; + szz += phi_val * dphi_z[i][col_idx] * r3[2]; + } + } + } + svl[0](0, 0) += sxx * 2; + svl[0](0, 1) += sxy * 2; + svl[0](0, 2) += sxz * 2; + svl[0](1, 1) += syy * 2; + svl[0](1, 2) += syz * 2; + svl[0](2, 2) += szz * 2; +} + + //=============================== // private methods //=============================== diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index bb73eb2a8a..c7d2d9f4b8 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -63,6 +63,20 @@ class PhiOperator const double* const* phi_dm, double* rho) const; + void phi_dot_dphi( + const double* const* phi, + const double* const* dphi_x, + const double* const* dphi_y, + const double* const* dphi_z, + ModuleBase::matrix *fvl) const; + + void phi_dot_dphi_r( + const double* const* phi, + const double* const* dphi_x, + const double* const* dphi_y, + const double* const* dphi_z, + ModuleBase::matrix *svl) const; + private: // get the index of the first meshgrid that both atom a and atom b affect From 747ade54834aecd31834de09e52a1b1ab02223b4 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 1 Jan 2025 16:08:39 +0800 Subject: [PATCH 17/47] add nspin=4 support and change interface --- source/module_elecstate/elecstate_lcao.cpp | 8 +- .../operator_lcao/veff_lcao.cpp | 122 +++++++++--------- .../pulay_force_stress_gint.hpp | 5 +- .../module_gint/CMakeLists.txt | 2 + .../module_gint/new_grid_tech/gint_atom.cpp | 7 +- .../module_gint/new_grid_tech/gint_common.cpp | 64 +++++++++ .../module_gint/new_grid_tech/gint_common.h | 3 + .../new_grid_tech/gint_interface.cpp | 48 +++++++ .../new_grid_tech/gint_interface.h | 33 +++++ .../new_grid_tech/gint_vl_nspin4.cpp | 73 +++++++++++ .../new_grid_tech/gint_vl_nspin4.h | 48 +++++++ 11 files changed, 342 insertions(+), 71 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index c30802cca2..6c99cb9b3a 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -10,7 +10,7 @@ #include "module_parameter/parameter.h" #include "elecstate_lcao_cal_tau.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" #include @@ -64,8 +64,7 @@ void ElecStateLCAO>::psiToRho(const psi::Psigint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); // this->gint_k->cal_gint(&inout); - ModuleGint::Gint_rho gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); - gint_rho.cal_gint(); + ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { @@ -101,8 +100,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); // this->gint_gamma->cal_gint(&inout); - ModuleGint::Gint_rho gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); - gint_rho.cal_gint(); + ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 7903fa8379..abf7332c43 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -4,7 +4,7 @@ #include "module_base/tool_title.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_cell/unitcell.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" namespace hamilt { @@ -56,10 +56,8 @@ void Veff>::initialize_HR(const UnitCell* ucell_in, const G ModuleBase::timer::tick("Veff", "initialize_HR"); } - - -template -void Veff>::contributeHR() +template<> +void Veff>::contributeHR() { ModuleBase::TITLE("Veff", "contributeHR"); ModuleBase::timer::tick("Veff", "contributeHR"); @@ -70,14 +68,6 @@ void Veff>::contributeHR() double* vr_eff1 = this->pot->get_effective_v(this->current_spin); double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin); - //-------------------------------------------- - //(2) check if we need to calculate - // pvpR = < phi0 | v(spin) | phiR> for a new spin. - //-------------------------------------------- - // GlobalV::ofs_running << " (spin change)" << std::endl; - - // if you change the place of the following code, - // rememeber to delete the #include if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta); @@ -85,82 +75,92 @@ void Veff>::contributeHR() } else { - // vlocal = Vh[rho] + Vxc[rho] + Vl(pseudo) - Gint_inout inout(vr_eff1, 0, Gint_Tools::job_type::vlocal); - this->GK->cal_gint(&inout); + ModuleGint::cal_gint_vl(vr_eff1, this->hR); } - // added by zhengdy-soc, for non-collinear case - // integral 4 times, is there any method to simplify? - if (this->nspin == 4) + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - for (int is = 1; is < 4; is++) - { - vr_eff1 = this->pot->get_effective_v(is); - if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) - { - vofk_eff1 = this->pot->get_effective_vofk(is); - } - - if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) - { - Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta); - this->GK->cal_gint(&inout); - } - else - { - Gint_inout inout(vr_eff1, is, Gint_Tools::job_type::vlocal); - this->GK->cal_gint(&inout); - } - } + this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); } - this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); - if(this->nspin == 2) { this->current_spin = 1 - this->current_spin; -} + if(this->nspin == 2) + { + this->current_spin = 1 - this->current_spin; + } ModuleBase::timer::tick("Veff", "contributeHR"); return; } -// special case of gamma-only template<> -void Veff>::contributeHR(void) +void Veff, double>>::contributeHR() { ModuleBase::TITLE("Veff", "contributeHR"); ModuleBase::timer::tick("Veff", "contributeHR"); - //----------------------------------------- //(1) prepare data for this k point. // copy the local potential from array. //----------------------------------------- - const double* vr_eff1 = this->pot->get_effective_v(this->current_spin); - const double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin); - - //-------------------------------------------- - // (3) folding matrix, - // and diagonalize the H matrix (T+Vl+Vnl). - //-------------------------------------------- + double* vr_eff1 = this->pot->get_effective_v(this->current_spin); + double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin); if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - Gint_inout inout(vr_eff1, vofk_eff1, Gint_Tools::job_type::vlocal_meta); - this->GG->cal_vlocal(&inout, this->new_e_iteration); + Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta); + this->GK->cal_gint(&inout); } else { - // Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); - // this->GG->cal_vlocal(&inout, this->new_e_iteration); - ModuleGint::Gint_vl gint_vl(vr_eff1, this->hR); - gint_vl.cal_gint(); + ModuleGint::cal_gint_vl(vr_eff1, this->hR); + } + + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); } - // this->GG->transfer_pvpR(this->hR,this->ucell); - this->new_e_iteration = false; + if(this->nspin == 2) + { + this->current_spin = 1 - this->current_spin; + } - if(this->nspin == 2) this->current_spin = 1 - this->current_spin; + ModuleBase::timer::tick("Veff", "contributeHR"); + return; +} +template<> +void Veff, std::complex>>::contributeHR() +{ + ModuleBase::TITLE("Veff", "contributeHR"); ModuleBase::timer::tick("Veff", "contributeHR"); + + std::vector vr_eff(4, nullptr); + for (int is = 0; is < 4; is++) + { + const double* vr_eff1 = this->pot->get_effective_v(is); + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + const double* vofk_eff1 = this->pot->get_effective_vofk(is); + Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta); + this->GK->cal_gint(&inout); + } + else + { + vr_eff[is] = vr_eff1; + if(is == 3) + { + ModuleGint::cal_gint_vl(vr_eff, this->hR); + } + } + } + + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); + } + + ModuleBase::timer::tick("Veff", "contributeHR"); + return; } // definition of class template should in the end of file to avoid compiling warning @@ -169,4 +169,4 @@ template class Veff>; template class Veff, double>>; template class Veff, std::complex>>; -} +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index ca733aa08c..bf39b25e21 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -3,7 +3,7 @@ #include "module_hamilt_lcao/hamilt_lcaodft/stress_tools.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_parameter/parameter.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" namespace PulayForceStress { template @@ -38,8 +38,7 @@ namespace PulayForceStress { vr_eff[is] = pot->get_effective_v(is); } - ModuleGint::Gint_fvl gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s); - gint_fvl.cal_gint(); + ModuleGint::cal_gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s); } if (isstress) { StressTools::stress_fill(-1.0, ucell.omega, s); } diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 7b4e0532be..5582584e72 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -37,6 +37,7 @@ list(APPEND objects new_grid_tech/gint_info.cpp new_grid_tech/gint.cpp new_grid_tech/gint_vl.cpp + new_grid_tech/gint_vl_nspin4.cpp new_grid_tech/gint_rho.cpp new_grid_tech/gint_fvl.cpp new_grid_tech/localcell_info.cpp @@ -44,6 +45,7 @@ list(APPEND objects new_grid_tech/set_ddphi.cpp new_grid_tech/unitcell_info.cpp new_grid_tech/gint_common.cpp + new_grid_tech/gint_interface.cpp ) if(USE_CUDA) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index db184c5a35..305742fd88 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -180,8 +180,11 @@ void GintAtom::set_phi_dphi( const double tmprl = tmp / rl; // 3D wave functions - phi[im * stride + iw] = tmprl * rly[idx_lm]; - + if(phi != nullptr) + { + phi[im * stride + iw] = tmprl * rly[idx_lm]; + } + // derivative of wave functions with respect to atom positions. const double tmpdphi_rly = (dtmp - tmp * ll / dist) / rl * rly[idx_lm] / dist; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp index c58494b2e9..50e6327cc4 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -39,6 +39,70 @@ void compose_hRGint(hamilt::HContainer* hR) } } +void compose_hRGint(std::vector>> hRGint_part, + std::shared_ptr>> hRGint_full) +{ + for (int iap = 0; iap < hRGint_full->size_atom_pairs(); iap++) + { + auto* ap = &hRGint_full->get_atom_pair(iap); + const int iat1 = ap->get_atom_i(); + const int iat2 = ap->get_atom_j(); + if (iat1 <= iat2) + { + hamilt::AtomPair>* upper_ap = ap; + hamilt::AtomPair>* lower_ap = hRGint_full->find_pair(iat2, iat1); + const hamilt::AtomPair* ap_nspin_0 = hRGint_part[0]->find_pair(iat1, iat2); + const hamilt::AtomPair* ap_nspin_3 = hRGint_part[3]->find_pair(iat1, iat2); + for (int ir = 0; ir < upper_ap->get_R_size(); ir++) + { + const auto R_index = upper_ap->get_R_index(ir); + auto upper_mat = upper_ap->find_matrix(R_index); + auto mat_nspin_0 = ap_nspin_0->find_matrix(R_index); + auto mat_nspin_3 = ap_nspin_3->find_matrix(R_index); + + // The row size and the col size of upper_matrix is double that of matrix_nspin_0 + for (int irow = 0; irow < mat_nspin_0->get_row_size(); ++irow) + { + for (int icol = 0; icol < mat_nspin_0->get_col_size(); ++icol) + { + upper_mat->get_value(2*irow, 2*icol) = mat_nspin_0->get_value(irow, icol) + mat_nspin_3->get_value(irow, icol); + upper_mat->get_value(2*irow+1, 2*icol+1) = mat_nspin_0->get_value(irow, icol) - mat_nspin_3->get_value(irow, icol); + } + } + + if (PARAM.globalv.domag) + { + const hamilt::AtomPair* ap_nspin_1 = hRGint_part[1]->find_pair(iat1, iat2); + const hamilt::AtomPair* ap_nspin_2 = hRGint_part[2]->find_pair(iat1, iat2); + const auto mat_nspin_1 = ap_nspin_1->find_matrix(R_index); + const auto mat_nspin_2 = ap_nspin_2->find_matrix(R_index); + for (int irow = 0; irow < mat_nspin_1->get_row_size(); ++irow) + { + for (int icol = 0; icol < mat_nspin_1->get_col_size(); ++icol) + { + upper_mat->get_value(2*irow, 2*icol+1) = mat_nspin_1->get_value(irow, icol) + std::complex(0.0, 1.0) * mat_nspin_2->get_value(irow, icol); + upper_mat->get_value(2*irow+1, 2*icol) = mat_nspin_1->get_value(irow, icol) - std::complex(0.0, 1.0) * mat_nspin_2->get_value(irow, icol); + } + } + } + + // fill the lower triangle matrix + if (iat1 < iat2) + { + auto lower_mat = lower_ap->find_matrix(-R_index); + for (int irow = 0; irow < upper_mat->get_row_size(); ++irow) + { + for (int icol = 0; icol < upper_mat->get_col_size(); ++icol) + { + lower_mat->get_value(icol, irow) = conj(upper_mat->get_value(irow, icol)); + } + } + } + } + } + } +} + template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h index f4b79818e7..eef81b7316 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h @@ -6,6 +6,9 @@ namespace ModuleGint { // fill the lower triangle matrix with the upper triangle matrix void compose_hRGint(hamilt::HContainer* hR); + // for nspin=4 case + void compose_hRGint(std::vector>> hRGint_part, + std::shared_ptr>> hRGint_full); template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp new file mode 100644 index 0000000000..0f083fce31 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -0,0 +1,48 @@ +#include "gint_interface.h" +#include "gint_vl.h" +#include "gint_vl_nspin4.h" +#include "gint_fvl.h" +#include "gint_rho.h" + +namespace ModuleGint +{ + +void cal_gint_vl( + const double* vr_eff, + hamilt::HContainer* hR) +{ + Gint_vl gint_vl(vr_eff, hR); + gint_vl.cal_gint(); +} + +void cal_gint_vl( + std::vector vr_eff, + hamilt::HContainer>* hR) +{ + Gint_vl_nspin4 gint_vl_nspin4(vr_eff, hR); + gint_vl_nspin4.cal_gint(); +} + +void cal_gint_rho( + const std::vector*>& DMR_vec, + const int nspin, + double **rho) +{ + Gint_rho gint_rho(DMR_vec, nspin, rho); + gint_rho.cal_gint(); +} + +void cal_gint_fvl( + const int nspin, + const std::vector& vr_eff, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl) +{ + Gint_fvl gint_fvl(nspin, vr_eff, DMR_vec, isforce, isstress, fvl, svl); + gint_fvl.cal_gint(); +} + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h new file mode 100644 index 0000000000..da855f58c8 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" + + +namespace ModuleGint +{ + +void cal_gint_vl( + const double* vr_eff, + hamilt::HContainer* hR); + +void cal_gint_vl( + std::vector vr_eff, + hamilt::HContainer>* hR); + +void cal_gint_rho( + const std::vector*>& DMR_vec, + const int nspin, + double **rho); + +void cal_gint_fvl( + const int nspin, + const std::vector& vr_eff, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl); + + + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp new file mode 100644 index 0000000000..3e1fc94d01 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -0,0 +1,73 @@ +#include "module_base/array_pool.h" +#include "module_base/timer.h" +#include "module_base/global_function.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" +#include "module_base/blas_connector.h" +#include "gint_common.h" +#include "gint_vl_nspin4.h" +#include "phi_operator.h" + +namespace ModuleGint +{ +void Gint_vl_nspin4::cal_gint() +{ + ModuleBase::timer::tick("Gint_vl_nspin4", "cal_gint"); + + init_hRGint_(); + cal_hRGint_(); + compose_hRGint(hRGint_part_, hRGint_full_); + transfer_hRGint_to_hR(hRGint_full_.get(), hR_); + + ModuleBase::timer::tick("Gint_vl_nspin4", "cal_gint"); +} + +void Gint_vl_nspin4::init_hRGint_() +{ + hRGint_part_.resize(nspin_); + for(int i = 0; i < nspin_; i++) + { + hRGint_part_[i] = gint_info_->get_hr(); + } + const int npol = 2; + hRGint_full_ = gint_info_->get_hr>(npol); +} + +void Gint_vl_nspin4::cal_hRGint_() +{ +#pragma omp parallel + { + PhiOperator phi_op; + std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi(phi.get_ptr_1D()); + for(int is = 0; is < nspin_; is++) + { + ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + } + } +#pragma omp critical + { + for(int is = 0; is < nspin_; is++) + { + { + BlasConnector::axpy(hRGint_part_thread[is].get_nnr(), 1.0, hRGint_part_thread[is].get_wrapper(), + 1, hRGint_part_[is]->get_wrapper(), 1); + } + } + } + } +} + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h new file mode 100644 index 0000000000..3aefa3d49e --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_vl_nspin4 : public Gint +{ + public: + Gint_vl_nspin4( + std::vector vr_eff, + hamilt::HContainer>* hR) + : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; + + void cal_gint() override; + + private: + + void init_hRGint_(); + + // note that only the upper triangle matrix of hR is calculated + // that's why we need compose_hRGint() to fill the lower triangle matrix. + void cal_hRGint_(); + + // input + std::vector vr_eff_; + + // output + hamilt::HContainer>* hR_; + + //======================== + // Intermediate variables + //======================== + const double dr3_; + + const int nspin_ = 4; + + std::vector>> hRGint_part_; + std::shared_ptr>> hRGint_full_; + +}; + +} // namespace ModuleGint \ No newline at end of file From 45a428cd903f0072c341b8170e02eacd7712447c Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 1 Jan 2025 17:19:11 +0800 Subject: [PATCH 18/47] change some raw pointer to shared_ptr --- .../module_gint/new_grid_tech/gint_common.cpp | 16 ++++++++-------- .../module_gint/new_grid_tech/gint_common.h | 4 ++-- .../module_gint/new_grid_tech/gint_helper.h | 7 +++++++ .../module_gint/new_grid_tech/gint_vl.cpp | 5 +++-- .../module_gint/new_grid_tech/gint_vl_nspin4.cpp | 3 ++- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp index 50e6327cc4..6eafe6672d 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -6,19 +6,19 @@ namespace ModuleGint { -void compose_hRGint(hamilt::HContainer* hR) +void compose_hRGint(std::shared_ptr> hRGint) { - for (int iap = 0; iap < hR->size_atom_pairs(); iap++) + for (int iap = 0; iap < hRGint->size_atom_pairs(); iap++) { - auto& ap = hR->get_atom_pair(iap); + auto& ap = hRGint->get_atom_pair(iap); const int iat1 = ap.get_atom_i(); const int iat2 = ap.get_atom_j(); if (iat1 > iat2) { // fill lower triangle matrix with upper triangle matrix // the upper is - const hamilt::AtomPair* upper_ap = hR->find_pair(iat2, iat1); - const hamilt::AtomPair* lower_ap = hR->find_pair(iat1, iat2); + const hamilt::AtomPair* upper_ap = hRGint->find_pair(iat2, iat1); + const hamilt::AtomPair* lower_ap = hRGint->find_pair(iat1, iat2); #ifdef __DEBUG assert(upper_ap != nullptr); #endif @@ -104,7 +104,7 @@ void compose_hRGint(std::vector>> hRG } template -void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR) +void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR) { #ifdef __MPI int size = 0; @@ -191,6 +191,6 @@ void transfer_DM_to_DMGint( } -template void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); -template void transfer_hRGint_to_hR(const hamilt::HContainer>* hRGint, hamilt::HContainer>* hR); +template void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR); +template void transfer_hRGint_to_hR(std::shared_ptr>> hRGint, hamilt::HContainer>* hR); } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h index eef81b7316..735aa086cd 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h @@ -5,13 +5,13 @@ namespace ModuleGint { // fill the lower triangle matrix with the upper triangle matrix - void compose_hRGint(hamilt::HContainer* hR); + void compose_hRGint(std::shared_ptr> hRGint); // for nspin=4 case void compose_hRGint(std::vector>> hRGint_part, std::shared_ptr>> hRGint_full); template - void transfer_hRGint_to_hR(const hamilt::HContainer* hRGint, hamilt::HContainer* hR); + void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR); void transfer_DM_to_DMGint( std::shared_ptr gint_info, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h index 3779cf0344..c3a64438c3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h @@ -1,9 +1,16 @@ #pragma once +#include #include #include "gint_type.h" #include "module_base/timer.h" +template +std::shared_ptr toConstSharedPtr(std::shared_ptr ptr) { + return std::static_pointer_cast(ptr); +} + + inline int index3Dto1D(const int id_x, const int id_y, const int id_z, const int dim_x, const int dim_y, const int dim_z) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 7bb45e87e8..78ce0ad0b3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -6,6 +6,7 @@ #include "gint_common.h" #include "gint_vl.h" #include "phi_operator.h" +#include "gint_helper.h" namespace ModuleGint { @@ -16,8 +17,8 @@ void Gint_vl::cal_gint() init_hRGint_(); cal_hRGint_(); - compose_hRGint(hRGint_.get()); - transfer_hRGint_to_hR(hRGint_.get(), hR_); + compose_hRGint(hRGint_); + transfer_hRGint_to_hR(toConstSharedPtr(hRGint_), hR_); ModuleBase::timer::tick("Gint_vl", "cal_gint"); } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 3e1fc94d01..22c99c8548 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -7,6 +7,7 @@ #include "gint_common.h" #include "gint_vl_nspin4.h" #include "phi_operator.h" +#include "gint_helper.h" namespace ModuleGint { @@ -17,7 +18,7 @@ void Gint_vl_nspin4::cal_gint() init_hRGint_(); cal_hRGint_(); compose_hRGint(hRGint_part_, hRGint_full_); - transfer_hRGint_to_hR(hRGint_full_.get(), hR_); + transfer_hRGint_to_hR(toConstSharedPtr(hRGint_full_), hR_); ModuleBase::timer::tick("Gint_vl_nspin4", "cal_gint"); } From b813dd35b5815f15de64993e51c9278979fdb3cd Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 1 Jan 2025 17:25:05 +0800 Subject: [PATCH 19/47] rename hamilt::HContainer --- .../module_gint/new_grid_tech/gint.h | 1 + .../module_gint/new_grid_tech/gint_common.cpp | 20 +++++++++---------- .../module_gint/new_grid_tech/gint_common.h | 12 +++++------ .../module_gint/new_grid_tech/gint_fvl.h | 6 +++--- .../module_gint/new_grid_tech/gint_info.cpp | 10 +++++----- .../module_gint/new_grid_tech/gint_info.h | 2 +- .../new_grid_tech/gint_interface.cpp | 8 ++++---- .../new_grid_tech/gint_interface.h | 9 +++++---- .../module_gint/new_grid_tech/gint_rho.h | 6 +++--- .../module_gint/new_grid_tech/gint_tau.h | 4 ++-- .../module_gint/new_grid_tech/gint_type.h | 6 +++++- .../module_gint/new_grid_tech/gint_vl.cpp | 2 +- .../module_gint/new_grid_tech/gint_vl.h | 6 +++--- .../new_grid_tech/gint_vl_nspin4.cpp | 2 +- .../new_grid_tech/gint_vl_nspin4.h | 8 ++++---- .../new_grid_tech/phi_operator.cpp | 4 ++-- .../module_gint/new_grid_tech/phi_operator.h | 4 ++-- 17 files changed, 58 insertions(+), 52 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h index 9fd1a567ab..2d8a1c1cba 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h @@ -1,6 +1,7 @@ #pragma once #include #include "gint_info.h" +#include "gint_type.h" namespace ModuleGint { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp index 6eafe6672d..0bf8ad7726 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp @@ -6,7 +6,7 @@ namespace ModuleGint { -void compose_hRGint(std::shared_ptr> hRGint) +void compose_hRGint(std::shared_ptr> hRGint) { for (int iap = 0; iap < hRGint->size_atom_pairs(); iap++) { @@ -39,8 +39,8 @@ void compose_hRGint(std::shared_ptr> hRGint) } } -void compose_hRGint(std::vector>> hRGint_part, - std::shared_ptr>> hRGint_full) +void compose_hRGint(std::vector>> hRGint_part, + std::shared_ptr>> hRGint_full) { for (int iap = 0; iap < hRGint_full->size_atom_pairs(); iap++) { @@ -104,7 +104,7 @@ void compose_hRGint(std::vector>> hRG } template -void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR) +void transfer_hRGint_to_hR(std::shared_ptr> hRGint, HContainer* hR) { #ifdef __MPI int size = 0; @@ -126,8 +126,8 @@ void transfer_hRGint_to_hR(std::shared_ptr> hRGint, // In the future, we might try to remove the gint_info parameter void transfer_DM_to_DMGint( std::shared_ptr gint_info, - std::vector*> DM, - std::vector>> DMRGint) + std::vector*> DM, + std::vector>> DMRGint) { // To check whether input parameter DM2D has been initialized #ifdef __DEBUG @@ -150,10 +150,10 @@ void transfer_DM_to_DMGint( { #ifdef __MPI const int npol = 2; - std::shared_ptr> DM_full = gint_info->get_hr(npol); + std::shared_ptr> DM_full = gint_info->get_hr(npol); hamilt::transferParallels2Serials(*DM[0], DM_full.get()); #else - hamilt::HContainer* DM_full = DM[0]; + HContainer* DM_full = DM[0]; #endif std::vector tmp_pointer(4, nullptr); for (int iap = 0; iap < DM_full->size_atom_pairs(); iap++) @@ -191,6 +191,6 @@ void transfer_DM_to_DMGint( } -template void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR); -template void transfer_hRGint_to_hR(std::shared_ptr>> hRGint, hamilt::HContainer>* hR); +template void transfer_hRGint_to_hR(std::shared_ptr> hRGint, HContainer* hR); +template void transfer_hRGint_to_hR(std::shared_ptr>> hRGint, HContainer>* hR); } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h index 735aa086cd..74f42427d4 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h @@ -5,17 +5,17 @@ namespace ModuleGint { // fill the lower triangle matrix with the upper triangle matrix - void compose_hRGint(std::shared_ptr> hRGint); + void compose_hRGint(std::shared_ptr> hRGint); // for nspin=4 case - void compose_hRGint(std::vector>> hRGint_part, - std::shared_ptr>> hRGint_full); + void compose_hRGint(std::vector>> hRGint_part, + std::shared_ptr>> hRGint_full); template - void transfer_hRGint_to_hR(std::shared_ptr> hRGint, hamilt::HContainer* hR); + void transfer_hRGint_to_hR(std::shared_ptr> hRGint, HContainer* hR); void transfer_DM_to_DMGint( std::shared_ptr gint_info, - std::vector*> DM, - std::vector>> DMRGint); + std::vector*> DM, + std::vector>> DMRGint); } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h index 365e5e4c11..aec01a835b 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h @@ -16,7 +16,7 @@ class Gint_fvl : public Gint Gint_fvl( const int nspin, const std::vector& vr_eff, - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const bool isforce, const bool isstress, ModuleBase::matrix* fvl, @@ -35,7 +35,7 @@ class Gint_fvl : public Gint // input const int nspin_; std::vector vr_eff_; - std::vector*> DMR_vec_; + std::vector*> DMR_vec_; const bool isforce_; const bool isstress_; @@ -44,7 +44,7 @@ class Gint_fvl : public Gint ModuleBase::matrix* svl_; // intermediate variables - std::vector>> DMRGint_vec_; + std::vector>> DMRGint_vec_; double dr3_; }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 7b2a8a7fbd..01c21b0c6c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -42,9 +42,9 @@ GintInfo::GintInfo( } template -std::shared_ptr> GintInfo::get_hr(int npol) const +std::shared_ptr> GintInfo::get_hr(int npol) const { - auto p_hr = std::make_shared>(ucell_->nat); + auto p_hr = std::make_shared>(ucell_->nat); if(PARAM.inp.gamma_only) { p_hr->fix_gamma(); @@ -146,7 +146,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital void GintInfo::init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd) { - hamilt::HContainer hRGint_local(ucell.nat); + HContainer hRGint_local(ucell.nat); // prepare the row_index and col_index for construct AtomPairs, they are // same, name as orb_index std::vector orb_index(ucell.nat + 1); @@ -211,6 +211,6 @@ void GintInfo::init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd) return; } -template std::shared_ptr> GintInfo::get_hr(int npol) const; -template std::shared_ptr>> GintInfo::get_hr>(int npol) const; +template std::shared_ptr> GintInfo::get_hr(int npol) const; +template std::shared_ptr>> GintInfo::get_hr>(int npol) const; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index 176e4db946..724c60121c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -37,7 +37,7 @@ class GintInfo // functions about hcontainer //========================================= template - std::shared_ptr> get_hr(int npol = 1) const; + std::shared_ptr> get_hr(int npol = 1) const; private: // initialize the atoms diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp index 0f083fce31..295ba04366 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -9,7 +9,7 @@ namespace ModuleGint void cal_gint_vl( const double* vr_eff, - hamilt::HContainer* hR) + HContainer* hR) { Gint_vl gint_vl(vr_eff, hR); gint_vl.cal_gint(); @@ -17,14 +17,14 @@ void cal_gint_vl( void cal_gint_vl( std::vector vr_eff, - hamilt::HContainer>* hR) + HContainer>* hR) { Gint_vl_nspin4 gint_vl_nspin4(vr_eff, hR); gint_vl_nspin4.cal_gint(); } void cal_gint_rho( - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const int nspin, double **rho) { @@ -35,7 +35,7 @@ void cal_gint_rho( void cal_gint_fvl( const int nspin, const std::vector& vr_eff, - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const bool isforce, const bool isstress, ModuleBase::matrix* fvl, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h index da855f58c8..5d6004ca27 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h @@ -1,6 +1,7 @@ #pragma once #include #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint_type.h" namespace ModuleGint @@ -8,21 +9,21 @@ namespace ModuleGint void cal_gint_vl( const double* vr_eff, - hamilt::HContainer* hR); + HContainer* hR); void cal_gint_vl( std::vector vr_eff, - hamilt::HContainer>* hR); + HContainer>* hR); void cal_gint_rho( - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const int nspin, double **rho); void cal_gint_fvl( const int nspin, const std::vector& vr_eff, - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const bool isforce, const bool isstress, ModuleBase::matrix* fvl, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h index 3b3dbcca31..227f604f84 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h @@ -13,7 +13,7 @@ class Gint_rho : public Gint { public: Gint_rho( - const std::vector*>& DMR_vec, + const std::vector*>& DMR_vec, const int nspin, double **rho) : DMR_vec_(DMR_vec), nspin_(nspin), rho_(rho) {}; @@ -26,7 +26,7 @@ class Gint_rho : public Gint void cal_rho_(); // input - const std::vector*> DMR_vec_; + const std::vector*> DMR_vec_; const int nspin_; // output @@ -35,7 +35,7 @@ class Gint_rho : public Gint //======================== // Intermediate variables //======================== - std::vector>> DMRGint_vec_; + std::vector>> DMRGint_vec_; }; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h index 69de8e3df2..b1288bf778 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h @@ -24,7 +24,7 @@ class Gint_tau : public Gint void cal_tau_(); // input - const std::vector*> DMR_vec_; + const std::vector*> DMR_vec_; const int nspin_; // output @@ -33,7 +33,7 @@ class Gint_tau : public Gint //======================== // Intermediate variables //======================== - std::vector>> DMRGint_vec_; + std::vector>> DMRGint_vec_; }; } // namespace ModuleGint diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h index 2d32369dfa..c6e9369ad2 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h @@ -1,8 +1,12 @@ #pragma once +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_base/vector3.h" #include "module_base/matrix3.h" using Matrix3 = ModuleBase::Matrix3; using Vec3d = ModuleBase::Vector3; -using Vec3i = ModuleBase::Vector3; \ No newline at end of file +using Vec3i = ModuleBase::Vector3; + +template +using HContainer = hamilt::HContainer; \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 78ce0ad0b3..af47af4826 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -39,7 +39,7 @@ void Gint_vl::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; - hamilt::HContainer hRGint_local(*hRGint_); + HContainer hRGint_local(*hRGint_); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h index a7ca034295..b68cb1a4a7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h @@ -14,7 +14,7 @@ class Gint_vl : public Gint public: Gint_vl( const double* vr_eff, - hamilt::HContainer* hR) + HContainer* hR) : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; void cal_gint() override; @@ -31,14 +31,14 @@ class Gint_vl : public Gint const double* vr_eff_; // output - hamilt::HContainer* hR_; + HContainer* hR_; //======================== // Intermediate variables //======================== double dr3_; - std::shared_ptr> hRGint_; + std::shared_ptr> hRGint_; }; } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 22c99c8548..55882ecd4b 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -39,7 +39,7 @@ void Gint_vl_nspin4::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; - std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); + std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h index 3aefa3d49e..3f4a725459 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h @@ -14,7 +14,7 @@ class Gint_vl_nspin4 : public Gint public: Gint_vl_nspin4( std::vector vr_eff, - hamilt::HContainer>* hR) + HContainer>* hR) : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; void cal_gint() override; @@ -31,7 +31,7 @@ class Gint_vl_nspin4 : public Gint std::vector vr_eff_; // output - hamilt::HContainer>* hR_; + HContainer>* hR_; //======================== // Intermediate variables @@ -40,8 +40,8 @@ class Gint_vl_nspin4 : public Gint const int nspin_ = 4; - std::vector>> hRGint_part_; - std::shared_ptr>> hRGint_full_; + std::vector>> hRGint_part_; + std::shared_ptr>> hRGint_full_; }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 044d52a4e9..cf790c2bb9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -71,7 +71,7 @@ void PhiOperator::set_ddphi( void PhiOperator::phi_mul_dm( const double* const* phi, - const hamilt::HContainer& DM, + const HContainer& DM, const bool is_symm, double** phi_dm) const { // parameters for lapack subroutines @@ -140,7 +140,7 @@ void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double void PhiOperator::phi_mul_phi_vldr3( const double* const* phi, const double* const* phi_vldr3, - hamilt::HContainer* hr) const + HContainer* hr) const { const char transa='N', transb='T'; const double alpha=1, beta=1; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index c7d2d9f4b8..b3e0033ea7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -44,7 +44,7 @@ class PhiOperator void phi_mul_dm( const double* const* phi, - const hamilt::HContainer& DM, + const HContainer& DM, const bool is_symm, double** phi_dm) const; void phi_mul_vldr3( @@ -56,7 +56,7 @@ class PhiOperator void phi_mul_phi_vldr3( const double* const* phi, const double* const* phi_vldr3, - hamilt::HContainer* hr) const; + HContainer* hr) const; void phi_dot_phi_dm( const double* const* phi, From 06f8ead6ba2de1c874ef420c58fe8f0b055c4171 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Wed, 1 Jan 2025 19:24:22 +0800 Subject: [PATCH 20/47] support tau calculation --- source/module_elecstate/elecstate_lcao.cpp | 3 +-- .../elecstate_lcao_cal_tau.cpp | 7 +++--- .../module_gint/CMakeLists.txt | 1 + .../new_grid_tech/gint_interface.cpp | 10 ++++++++ .../new_grid_tech/gint_interface.h | 5 ++++ .../module_gint/new_grid_tech/gint_tau.cpp | 25 +++++++++++++------ .../module_gint/new_grid_tech/gint_tau.h | 7 +++--- .../module_gint/new_grid_tech/phi_operator.h | 1 + 8 files changed, 43 insertions(+), 16 deletions(-) diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index 6c99cb9b3a..e494bae387 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -172,8 +172,7 @@ void ElecStateLCAO::dmToRho(std::vector pexsi_DM, std::vectorcharge->kin_r[0], this->charge->nrxx); } - Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau); - this->gint_gamma->cal_gint(&inout1); + ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); } this->charge->renormalize_rho(); diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.cpp b/source/module_elecstate/elecstate_lcao_cal_tau.cpp index c7d83bd1e9..32aed5e7e4 100644 --- a/source/module_elecstate/elecstate_lcao_cal_tau.cpp +++ b/source/module_elecstate/elecstate_lcao_cal_tau.cpp @@ -1,4 +1,5 @@ #include "elecstate_lcao.h" +#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" #include "elecstate_lcao_cal_tau.h" #include "module_base/timer.h" @@ -15,8 +16,7 @@ void lcao_cal_tau_k(Gint_k* gint_k, { ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx); } - Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin); - gint_k->cal_gint(&inout1); + ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); return; @@ -32,8 +32,7 @@ void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma, { ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx); } - Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin); - gint_gamma->cal_gint(&inout1); + ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); return; diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 5582584e72..95a1a68243 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND objects new_grid_tech/gint_vl.cpp new_grid_tech/gint_vl_nspin4.cpp new_grid_tech/gint_rho.cpp + new_grid_tech/gint_tau.cpp new_grid_tech/gint_fvl.cpp new_grid_tech/localcell_info.cpp new_grid_tech/phi_operator.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp index 295ba04366..1b6019bc71 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -3,6 +3,7 @@ #include "gint_vl_nspin4.h" #include "gint_fvl.h" #include "gint_rho.h" +#include "gint_tau.h" namespace ModuleGint { @@ -32,6 +33,15 @@ void cal_gint_rho( gint_rho.cal_gint(); } +void cal_gint_tau( + const std::vector*>& DMR_vec, + const int nspin, + double** tau) +{ + Gint_tau gint_tau(DMR_vec, nspin, tau); + gint_tau.cal_gint(); +} + void cal_gint_fvl( const int nspin, const std::vector& vr_eff, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h index 5d6004ca27..d701c77027 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h @@ -20,6 +20,11 @@ void cal_gint_rho( const int nspin, double **rho); +void cal_gint_tau( + const std::vector*>& DMR_vec, + const int nspin, + double**tau); + void cal_gint_fvl( const int nspin, const std::vector& vr_eff, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp index 2a8319e470..4da7394c42 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp @@ -1,4 +1,5 @@ #include "module_base/array_pool.h" +#include "module_base/global_function.h" #include "gint_tau.h" #include "gint_common.h" #include "phi_operator.h" @@ -18,8 +19,7 @@ void Gint_tau::init_DMRGint_() DMRGint_vec_.resize(nspin_); for (int is = 0; is < nspin_; is++) { - const int npol = (nspin_ == 4 ? 2 : 1); - DMRGint_vec_[is] = gint_info_->get_hr(npol); + DMRGint_vec_[is] = gint_info_->get_hr(); } } @@ -36,13 +36,24 @@ void Gint_tau::cal_tau_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_DMR(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi(phi.get_ptr_1D()); + ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z_DM(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi_dphi(nullptr, dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); for (int is = 0; is < nspin_; is++) { - phi_op.phi_mul_dm(phi.get_ptr_2D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_2D()); - phi_op.phi_dot_phi_dm(phi.get_ptr_2D(), phi_DMR.get_ptr_2D(), tau[is]); + ModuleBase::zeros(dphi_x_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_y_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_z_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_dm(dphi_x.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_2D()); + phi_op.phi_mul_dm(dphi_y.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_2D()); + phi_op.phi_mul_dm(dphi_z.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_2D()); + phi_op.phi_dot_phi_dm(dphi_x.get_ptr_2D(), dphi_x_DM.get_ptr_2D(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_y.get_ptr_2D(), dphi_y_DM.get_ptr_2D(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_z.get_ptr_2D(), dphi_z_DM.get_ptr_2D(), kin_[is]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h index b1288bf778..65bb4620c7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h @@ -11,10 +11,11 @@ namespace ModuleGint class Gint_tau : public Gint { public: - gint_tau( - const std::vector& DMR_vec, + Gint_tau( + const std::vector*>& DMR_vec, const int nspin, - std::vector& tau); + double** tau) + : DMR_vec_(DMR_vec), nspin_(nspin), kin_(tau) {}; void cal_gint() override; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index b3e0033ea7..90009b002d 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -34,6 +34,7 @@ class PhiOperator // get phi and the gradient of phi of the big grid // the dimension of phi and dphi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) + // if you do not need phi, you can set phi to nullptr. void set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const; // get the hessian of the wave function values of the big grid From 17a2f626db327b6252e061ff5692f8d22944ab13 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Thu, 2 Jan 2025 16:25:25 +0800 Subject: [PATCH 21/47] fix a bug --- .../module_gint/new_grid_tech/phi_operator.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index cf790c2bb9..fa33a5afbb 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -45,7 +45,10 @@ void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, doub { const auto atom = biggrid_->get_atom(i); atom->set_phi_dphi(atoms_relative_coords_[i], cols_, phi, dphi_x, dphi_y, dphi_z); - phi += atom->get_nw(); + if(phi != nullptr) + { + phi += atom->get_nw(); + } dphi_x += atom->get_nw(); dphi_y += atom->get_nw(); dphi_z += atom->get_nw(); From 10c2bb4b0cc7194851a4ecb986a5a031f9ad7956 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 3 Jan 2025 00:21:12 +0800 Subject: [PATCH 22/47] add vlocal metagga support --- .../operator_lcao/veff_lcao.cpp | 16 +---- .../module_gint/CMakeLists.txt | 1 + .../new_grid_tech/gint_interface.cpp | 10 +++ .../new_grid_tech/gint_interface.h | 5 ++ .../module_gint/new_grid_tech/gint_vl.cpp | 7 -- .../new_grid_tech/gint_vl_metagga.cpp | 70 +++++++++++++++++++ .../new_grid_tech/gint_vl_metagga.h | 47 +++++++++++++ .../new_grid_tech/gint_vl_nspin4.cpp | 5 -- 8 files changed, 135 insertions(+), 26 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index abf7332c43..871681411b 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -70,19 +70,13 @@ void Veff>::contributeHR() if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta); - this->GK->cal_gint(&inout); + ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR); } else { ModuleGint::cal_gint_vl(vr_eff1, this->hR); } - if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) - { - this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); - } - if(this->nspin == 2) { this->current_spin = 1 - this->current_spin; @@ -106,19 +100,13 @@ void Veff, double>>::contributeHR() if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta); - this->GK->cal_gint(&inout); + ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR); } else { ModuleGint::cal_gint_vl(vr_eff1, this->hR); } - if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) - { - this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); - } - if(this->nspin == 2) { this->current_spin = 1 - this->current_spin; diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 95a1a68243..29c23886c8 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -37,6 +37,7 @@ list(APPEND objects new_grid_tech/gint_info.cpp new_grid_tech/gint.cpp new_grid_tech/gint_vl.cpp + new_grid_tech/gint_vl_metagga.cpp new_grid_tech/gint_vl_nspin4.cpp new_grid_tech/gint_rho.cpp new_grid_tech/gint_tau.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp index 1b6019bc71..ca0900f061 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -1,5 +1,6 @@ #include "gint_interface.h" #include "gint_vl.h" +#include "gint_vl_metagga.h" #include "gint_vl_nspin4.h" #include "gint_fvl.h" #include "gint_rho.h" @@ -24,6 +25,15 @@ void cal_gint_vl( gint_vl_nspin4.cal_gint(); } +void cal_gint_vl_metagga( + const double* vr_eff, + const double* vfork, + HContainer* hR) +{ + Gint_vl_metagga gint_vl_metagga(vr_eff, vfork, hR); + gint_vl_metagga.cal_gint(); +} + void cal_gint_rho( const std::vector*>& DMR_vec, const int nspin, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h index d701c77027..f49addea6a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h @@ -15,6 +15,11 @@ void cal_gint_vl( std::vector vr_eff, HContainer>* hR); +void cal_gint_vl_metagga( + const double* vr_eff, + const double* vfork, + HContainer* hR); + void cal_gint_rho( const std::vector*>& DMR_vec, const int nspin, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index af47af4826..d9b7450cc8 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -1,7 +1,4 @@ #include "module_base/array_pool.h" -#include "module_base/timer.h" -#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" -#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" #include "module_base/blas_connector.h" #include "gint_common.h" #include "gint_vl.h" @@ -13,14 +10,10 @@ namespace ModuleGint void Gint_vl::cal_gint() { - ModuleBase::timer::tick("Gint_vl", "cal_gint"); - init_hRGint_(); cal_hRGint_(); compose_hRGint(hRGint_); transfer_hRGint_to_hR(toConstSharedPtr(hRGint_), hR_); - - ModuleBase::timer::tick("Gint_vl", "cal_gint"); } //======================== diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp new file mode 100644 index 0000000000..b18b7e6a3c --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp @@ -0,0 +1,70 @@ +#include "module_base/array_pool.h" +#include "module_base/blas_connector.h" +#include "gint_common.h" +#include "gint_vl_metagga.h" +#include "phi_operator.h" +#include "gint_helper.h" + +namespace ModuleGint +{ + +void Gint_vl_metagga::cal_gint() +{ + init_hRGint_(); + cal_hRGint_(); + compose_hRGint(hRGint_); + transfer_hRGint_to_hR(toConstSharedPtr(hRGint_), hR_); +} + +//======================== +// Private functions +//======================== + +void Gint_vl_metagga::init_hRGint_() +{ + hRGint_ = gint_info_->get_hr(); +} + +void Gint_vl_metagga::cal_hRGint_() +{ +// be careful!! +// each thread will have a copy of hRGint_, this may cause a lot of memory usage +#pragma omp parallel + { + PhiOperator phi_op; + HContainer hRGint_local(*hRGint_); +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D(), &hRGint_local); + } +#pragma omp critical + { + BlasConnector::axpy(hRGint_local.get_nnr(), 1.0, hRGint_local.get_wrapper(), + 1, hRGint_->get_wrapper(), 1); + } + } +} + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h new file mode 100644 index 0000000000..4fef9c85af --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_vl_metagga : public Gint +{ + public: + Gint_vl_metagga( + const double* vr_eff, + const double* vofk, + HContainer* hR) + : vr_eff_(vr_eff), vofk_(vofk), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; + + void cal_gint() override; + + private: + + void init_hRGint_(); + + // note that only the upper triangle matrix of hR is calculated + // that's why we need compose_hRGint() to fill the lower triangle matrix. + void cal_hRGint_(); + + // input + const double* vr_eff_; + const double* vofk_; + + // output + HContainer* hR_; + + //======================== + // Intermediate variables + //======================== + double dr3_; + + std::shared_ptr> hRGint_; + +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 55882ecd4b..0447049267 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -1,5 +1,4 @@ #include "module_base/array_pool.h" -#include "module_base/timer.h" #include "module_base/global_function.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" @@ -13,14 +12,10 @@ namespace ModuleGint { void Gint_vl_nspin4::cal_gint() { - ModuleBase::timer::tick("Gint_vl_nspin4", "cal_gint"); - init_hRGint_(); cal_hRGint_(); compose_hRGint(hRGint_part_, hRGint_full_); transfer_hRGint_to_hR(toConstSharedPtr(hRGint_full_), hR_); - - ModuleBase::timer::tick("Gint_vl_nspin4", "cal_gint"); } void Gint_vl_nspin4::init_hRGint_() From 4b0adb287217523f694372df928761e1d424963e Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sat, 4 Jan 2025 01:31:07 +0800 Subject: [PATCH 23/47] support force metagga calculation --- .../operator_lcao/veff_lcao.cpp | 17 +-- .../pulay_force_stress_gint.hpp | 12 +- .../module_gint/CMakeLists.txt | 2 + .../new_grid_tech/gint_fvl_meta.cpp | 122 ++++++++++++++++++ .../module_gint/new_grid_tech/gint_fvl_meta.h | 53 ++++++++ .../new_grid_tech/gint_interface.cpp | 25 ++++ .../new_grid_tech/gint_interface.h | 15 +++ .../new_grid_tech/gint_vl_metagga_nspin4.cpp | 84 ++++++++++++ .../new_grid_tech/gint_vl_metagga_nspin4.h | 45 +++++++ .../new_grid_tech/gint_vl_nspin4.cpp | 1 - .../new_grid_tech/phi_operator.cpp | 7 +- .../module_gint/new_grid_tech/set_ddphi.cpp | 2 +- 12 files changed, 363 insertions(+), 22 deletions(-) create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp create mode 100644 source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 871681411b..50d27ef9a3 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -123,18 +123,20 @@ void Veff, std::complex>>::contributeH ModuleBase::timer::tick("Veff", "contributeHR"); std::vector vr_eff(4, nullptr); + std::vector vofk_eff(4, nullptr); for (int is = 0; is < 4; is++) { - const double* vr_eff1 = this->pot->get_effective_v(is); + vr_eff[is] = this->pot->get_effective_v(is); if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - const double* vofk_eff1 = this->pot->get_effective_vofk(is); - Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta); - this->GK->cal_gint(&inout); + vofk_eff[is] = this->pot->get_effective_vofk(is); + if(is == 3) + { + ModuleGint::cal_gint_vl_metagga(vr_eff, vofk_eff, this->hR); + } } else { - vr_eff[is] = vr_eff1; if(is == 3) { ModuleGint::cal_gint_vl(vr_eff, this->hR); @@ -142,11 +144,6 @@ void Veff, std::complex>>::contributeH } } - if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) - { - this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); - } - ModuleBase::timer::tick("Veff", "contributeHR"); return; } diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index bf39b25e21..2df7c5f461 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -18,22 +18,20 @@ namespace PulayForceStress const bool& isstress, const bool& set_dmr_gint) { - if (set_dmr_gint) { gint.transfer_DM2DtoGrid(dm.get_DMR_vector()); } // 2d block to grid const int nspin = PARAM.inp.nspin; + std::vector vr_eff(nspin, nullptr); + std::vector vofk_eff(nspin, nullptr); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { for (int is = 0; is < nspin; ++is) { - const double* vr_eff1 = pot->get_effective_v(is); - const double* vofk_eff1 = nullptr; - vofk_eff1 = pot->get_effective_vofk(is); - Gint_inout inout(is, vr_eff1, vofk_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force_meta); - gint.cal_gint(&inout); + vr_eff[is] = pot->get_effective_v(is); + vofk_eff[is] = pot->get_effective_vofk(is); } + ModuleGint::cal_gint_fvl_meta(nspin, vr_eff, vofk_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s); } else { - std::vector vr_eff(nspin, nullptr); for(int is = 0; is < nspin; ++is) { vr_eff[is] = pot->get_effective_v(is); diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 29c23886c8..38665d83b0 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -39,9 +39,11 @@ list(APPEND objects new_grid_tech/gint_vl.cpp new_grid_tech/gint_vl_metagga.cpp new_grid_tech/gint_vl_nspin4.cpp + new_grid_tech/gint_vl_metagga_nspin4.cpp new_grid_tech/gint_rho.cpp new_grid_tech/gint_tau.cpp new_grid_tech/gint_fvl.cpp + new_grid_tech/gint_fvl_meta.cpp new_grid_tech/localcell_info.cpp new_grid_tech/phi_operator.cpp new_grid_tech/set_ddphi.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp new file mode 100644 index 0000000000..a6c9d11d5a --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp @@ -0,0 +1,122 @@ +#include "module_base/array_pool.h" +#include "module_base/global_function.h" +#include "gint_fvl_meta.h" +#include "gint_common.h" +#include "phi_operator.h" + +namespace ModuleGint +{ + +void Gint_fvl_meta::cal_gint() +{ + init_DMRGint_(); + transfer_DM_to_DMGint(gint_info_, DMR_vec_, DMRGint_vec_); + cal_fvl_svl_(); +} + +void Gint_fvl_meta::init_DMRGint_() +{ + DMRGint_vec_.resize(nspin_); + for (int is = 0; is < nspin_; is++) + { + DMRGint_vec_[is] = gint_info_->get_hr(); + } +} + +void Gint_fvl_meta::cal_fvl_svl_() +{ +#pragma omp parallel + { + PhiOperator phi_op; + ModuleBase::matrix* fvl_thread = nullptr; + ModuleBase::matrix* svl_thread = nullptr; + if(isforce_) + { + fvl_thread = new ModuleBase::matrix(*fvl_); + fvl_thread->zero_out(); + } + if(isstress_) + { + svl_thread = new ModuleBase::matrix(*svl_); + svl_thread->zero_out(); + } +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_xx(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_xy(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_xz(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_yy(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_yz(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool ddphi_zz(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + phi_op.set_ddphi(ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), + ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + for (int is = 0; is < nspin_; is++) + { + ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(phi_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_x_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_y_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_z_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_x_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_y_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_z_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); + phi_op.phi_mul_dm(phi_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_2D()); + phi_op.phi_mul_dm(dphi_x_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.get_ptr_2D()); + phi_op.phi_mul_dm(dphi_y_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.get_ptr_2D()); + phi_op.phi_mul_dm(dphi_z_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.get_ptr_2D()); + if(isforce_) + { + phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_x_vldr3_DM.get_ptr_2D(), ddphi_xx.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_xz.get_ptr_2D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_y_vldr3_DM.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_yy.get_ptr_2D(), ddphi_yz.get_ptr_2D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_z_vldr3_DM.get_ptr_2D(), ddphi_xz.get_ptr_2D(), ddphi_yz.get_ptr_2D(), ddphi_zz.get_ptr_2D(), fvl_thread); + } + if(isstress_) + { + phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.get_ptr_2D(), ddphi_xx.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_xz.get_ptr_2D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_yy.get_ptr_2D(), ddphi_yz.get_ptr_2D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.get_ptr_2D(), ddphi_xz.get_ptr_2D(), ddphi_yz.get_ptr_2D(), ddphi_zz.get_ptr_2D(), svl_thread); + } + } + } +#pragma omp critical + { + if(isforce_) + { + fvl_[0] += fvl_thread[0]; + delete fvl_thread; + } + if(isstress_) + { + svl_[0] += svl_thread[0]; + delete svl_thread; + } + } + } +} + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h new file mode 100644 index 0000000000..063e7971d1 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_base/matrix.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ +class Gint_fvl_meta : public Gint +{ + public: + Gint_fvl_meta( + const int nspin, + const std::vector& vr_eff, + const std::vector& vofk, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl) + : nspin_(nspin), vr_eff_(vr_eff), vofk_(vofk), DMR_vec_(DMR_vec), + isforce_(isforce), isstress_(isstress), fvl_(fvl), svl_(svl), + dr3_(gint_info_->get_mgrid_volume()) {}; + + void cal_gint() override; + + private: + void init_DMRGint_(); + + void cal_fvl_svl_(); + + // input + const int nspin_; + std::vector vr_eff_; + std::vector vofk_; + std::vector*> DMR_vec_; + const bool isforce_; + const bool isstress_; + + // output + ModuleBase::matrix* fvl_; + ModuleBase::matrix* svl_; + + // intermediate variables + std::vector>> DMRGint_vec_; + + double dr3_; +}; + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp index ca0900f061..22875e08b3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -2,7 +2,9 @@ #include "gint_vl.h" #include "gint_vl_metagga.h" #include "gint_vl_nspin4.h" +#include "gint_vl_metagga_nspin4.h" #include "gint_fvl.h" +#include "gint_fvl_meta.h" #include "gint_rho.h" #include "gint_tau.h" @@ -34,6 +36,15 @@ void cal_gint_vl_metagga( gint_vl_metagga.cal_gint(); } +void cal_gint_vl_metagga( + std::vector vr_eff, + std::vector vofk, + HContainer>* hR) +{ + Gint_vl_metagga_nspin4 gint_vl_metagga_nspin4(vr_eff, vofk, hR); + gint_vl_metagga_nspin4.cal_gint(); +} + void cal_gint_rho( const std::vector*>& DMR_vec, const int nspin, @@ -65,4 +76,18 @@ void cal_gint_fvl( gint_fvl.cal_gint(); } +void cal_gint_fvl_meta( + const int nspin, + const std::vector& vr_eff, + const std::vector& vofk, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl) +{ + Gint_fvl_meta gint_fvl_meta(nspin, vr_eff, vofk, DMR_vec, isforce, isstress, fvl, svl); + gint_fvl_meta.cal_gint(); +} + } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h index f49addea6a..a4c33bb14a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h @@ -20,6 +20,11 @@ void cal_gint_vl_metagga( const double* vfork, HContainer* hR); +void cal_gint_vl_metagga( + std::vector vr_eff, + std::vector vofk, + HContainer>* hR); + void cal_gint_rho( const std::vector*>& DMR_vec, const int nspin, @@ -39,6 +44,16 @@ void cal_gint_fvl( ModuleBase::matrix* fvl, ModuleBase::matrix* svl); +void cal_gint_fvl_meta( + const int nspin, + const std::vector& vr_eff, + const std::vector& vofk, + const std::vector*>& DMR_vec, + const bool isforce, + const bool isstress, + ModuleBase::matrix* fvl, + ModuleBase::matrix* svl); + } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp new file mode 100644 index 0000000000..4d8997fc5d --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp @@ -0,0 +1,84 @@ +#include "module_base/array_pool.h" +#include "module_base/global_function.h" +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "module_base/blas_connector.h" +#include "gint_common.h" +#include "gint_vl_metagga_nspin4.h" +#include "phi_operator.h" +#include "gint_helper.h" + +namespace ModuleGint +{ + +void Gint_vl_metagga_nspin4::cal_gint() +{ + init_hRGint_(); + cal_hRGint_(); + compose_hRGint(hRGint_part_, hRGint_full_); + transfer_hRGint_to_hR(toConstSharedPtr(hRGint_full_), hR_); +} + +void Gint_vl_metagga_nspin4::init_hRGint_() +{ + hRGint_part_.resize(nspin_); + for(int i = 0; i < nspin_; i++) + { + hRGint_part_[i] = gint_info_->get_hr(); + } + const int npol = 2; + hRGint_full_ = gint_info_->get_hr>(npol); +} + +void Gint_vl_metagga_nspin4::cal_hRGint_() +{ +#pragma omp parallel + { + PhiOperator phi_op; + std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); +#pragma omp for schedule(dynamic) + for(const auto& biggrid: gint_info_->get_biggrids()) + { + if(biggrid->get_atoms().size() == 0) + { + continue; + } + phi_op.set_bgrid(biggrid); + ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); + ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); + phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + for(int is = 0; is < nspin_; is++) + { + ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_x_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_y_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + ModuleBase::zeros(dphi_z_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + } + } +#pragma omp critical + { + for(int is = 0; is < nspin_; is++) + { + { + BlasConnector::axpy(hRGint_part_thread[is].get_nnr(), 1.0, hRGint_part_thread[is].get_wrapper(), + 1, hRGint_part_[is]->get_wrapper(), 1); + } + } + } + } +} + +} // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h new file mode 100644 index 0000000000..d8033e4be6 --- /dev/null +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include "module_hamilt_lcao/module_hcontainer/hcontainer.h" +#include "gint.h" +#include "gint_info.h" + +namespace ModuleGint +{ + +class Gint_vl_metagga_nspin4 : public Gint +{ + public: + Gint_vl_metagga_nspin4( + std::vector vr_eff, + std::vector vofk, + HContainer>* hR) + : vr_eff_(vr_eff), vofk_(vofk), hR_(hR), dr3_(gint_info_->get_mgrid_volume()){}; + + void cal_gint() override; + + private: + void init_hRGint_(); + + void cal_hRGint_(); + + // input + std::vector vr_eff_; + std::vector vofk_; + // output + HContainer>* hR_; + + //======================== + // Intermediate variables + //======================== + const double dr3_; + + const int nspin_ = 4; + + std::vector>> hRGint_part_; + std::shared_ptr>> hRGint_full_; +}; + +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 0447049267..035d48c391 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -1,7 +1,6 @@ #include "module_base/array_pool.h" #include "module_base/global_function.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" -#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h" #include "module_base/blas_connector.h" #include "gint_common.h" #include "gint_vl_nspin4.h" diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index fa33a5afbb..dc8d84e211 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -210,6 +210,7 @@ void PhiOperator::phi_dot_dphi( { for(int i = 0; i < biggrid_->get_atom_num(); ++i) { + const int iat = biggrid_->get_atom(i)->get_iat(); const int start_idx = atoms_startidx_[i]; const int phi_len = atoms_phi_len_[i]; double rx = 0, ry = 0, rz = 0; @@ -223,9 +224,9 @@ void PhiOperator::phi_dot_dphi( rz += phi_val * dphi_z[j][start_idx + k]; } } - fvl[0](i, 0) += rx * 2; - fvl[0](i, 1) += ry * 2; - fvl[0](i, 2) += rz * 2; + fvl[0](iat, 0) += rx * 2; + fvl[0](iat, 1) += ry * 2; + fvl[0](iat, 2) += rz * 2; } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index 5ed1afef33..e0f9c803a3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -41,7 +41,7 @@ void GintAtom::set_ddphi( std::vector rly(std::pow(atom_->nwl + 1, 2)); ModuleBase::Array_Pool grly(std::pow(atom_->nwl + 1, 2), 3); // TODO: A better data structure such as a 3D tensor can be used to store dphi - std::vector>> dphi(6, std::vector>(6, std::vector(3))); + std::vector>> dphi(atom_->nw, std::vector>(6, std::vector(3))); Vec3d coord1; ModuleBase::Array_Pool displ(6, 3); displ[0][0] = 0.0001; // in x direction From ad9157e4018aad2eeba93339ea51eac80989e5d7 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 10 Jan 2025 00:14:28 +0800 Subject: [PATCH 24/47] change shared_ptr to raw pointer of GintAtom --- .../module_gint/new_grid_tech/biggrid.cpp | 6 +++--- .../module_gint/new_grid_tech/biggrid.h | 12 ++++++------ .../module_gint/new_grid_tech/gint_info.cpp | 17 +++++++++++++---- .../module_gint/new_grid_tech/gint_info.h | 5 +++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index 4ff1e548e6..e7a857f4a1 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -8,7 +8,7 @@ BigGrid::BigGrid(int idx, std::shared_ptr localcell_info) unitcell_info_(localcell_info->get_unitcell_info()), biggrid_info_(localcell_info_->get_biggrid_info()) {} -void BigGrid::add_atom(std::shared_ptr atom) +void BigGrid::add_atom(const GintAtom* atom) { atoms_.push_back(atom); } @@ -90,12 +90,12 @@ void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in } -void BigGrid::set_atom_relative_coords(std::shared_ptr atom, std::vector& atom_coord) const +void BigGrid::set_atom_relative_coords(const GintAtom* atom, std::vector& atom_coord) const { return set_atom_relative_coords(atom->get_biggrid_idx(), atom->get_tau_in_biggrid(), atom_coord); } -bool BigGrid::is_atom_on_bgrid(std::shared_ptr atom) const +bool BigGrid::is_atom_on_bgrid(const GintAtom* atom) const { std::vector coords; this->set_atom_relative_coords(atom, coords); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index 1869de76a6..86fcff5101 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -22,8 +22,8 @@ class BigGrid std::shared_ptr get_localcell_info() const { return localcell_info_; }; std::shared_ptr get_unitcell_info() const {return unitcell_info_; }; std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; - const std::vector>& get_atoms() const { return atoms_; }; - std::shared_ptr get_atom(int i) const { return atoms_[i]; }; + const std::vector& get_atoms() const { return atoms_; }; + const GintAtom* get_atom(int i) const { return atoms_[i]; }; // get the number of meshgrids in the big grid int get_meshgrid_num() const { return biggrid_info_->get_nmxyz(); }; @@ -32,7 +32,7 @@ class BigGrid int get_atom_num() const { return atoms_.size(); }; // add an atom to the big grid - void add_atom(std::shared_ptr atom); + void add_atom(const GintAtom* atom); // get the total number of phi of a meshgrid // return: (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw) @@ -61,16 +61,16 @@ class BigGrid void set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in_bgrid, std::vector& atom_coord) const; // a wrapper function to get the relative coordinates of the atom and the meshgrids - void set_atom_relative_coords(std::shared_ptr atom, std::vector& atom_coord) const; + void set_atom_relative_coords(const GintAtom* atom, std::vector& atom_coord) const; // if the atom affects the big grid, return true, otherwise false // note when we say an atom affects a big grid, it does not mean that the atom affects all the meshgrid on the big grid, // it may only affect a part of them. - bool is_atom_on_bgrid(std::shared_ptr atom) const; + bool is_atom_on_bgrid(const GintAtom* atom) const; private: // atoms that can affect the big grid - std::vector> atoms_; + std::vector atoms_; // the 1D index of the big grid in the local cell const int idx_; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 01c21b0c6c..abfc47d9e2 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -41,6 +41,14 @@ GintInfo::GintInfo( init_ijr_info_(ucell, gd); } +GintInfo::~GintInfo() +{ + for (auto& atom: atoms_) + { + delete atom; + } +} + template std::shared_ptr> GintInfo::get_hr(int npol) const { @@ -98,7 +106,8 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital delta.z * unitcell_info_->get_biggrid_info()->get_vec3(); const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); - std::map> gint_atom_map; + // a map to store the atom in different unitcells + std::map gint_atom_map; for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++) { @@ -126,10 +135,10 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital { Vec3i ext_atom_bgrid_idx(atom_bgrid_idx.x - ucell_idx_bgrid.x * unitcell_info_->get_nbx(), atom_bgrid_idx.y - ucell_idx_bgrid.y * unitcell_info_->get_nby(), - atom_bgrid_idx.z - ucell_idx_bgrid.z * unitcell_info_->get_nbz()); - auto gint_atom = std::make_shared(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb); - gint_atom_map[ucell_idx_relative] = gint_atom; + atom_bgrid_idx.z - ucell_idx_bgrid.z * unitcell_info_->get_nbz()); + GintAtom* gint_atom = new GintAtom(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb); atoms_.push_back(gint_atom); + gint_atom_map[ucell_idx_relative] = gint_atom; } if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(gint_atom_map[ucell_idx_relative])) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index 724c60121c..d411120f14 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -27,6 +27,8 @@ class GintInfo int nbx_local, int nby_local, int nbz_local, const Numerical_Orbital* Phi, const UnitCell& ucell, Grid_Driver& gd); + + ~GintInfo(); // getter functions std::vector> get_biggrids() const { return biggrids_; }; @@ -61,8 +63,7 @@ class GintInfo std::vector> biggrids_; // the total atoms in the unitcell(include extended unitcell) - // Not Used Now - std::vector> atoms_; + std::vector atoms_; // if the iat-th(global index) atom is in this processor, return true std::vector is_atom_in_proc_; From 0bf9da2bf28212ef435cb9c912e7a95c326d19fe Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 10 Jan 2025 00:56:42 +0800 Subject: [PATCH 25/47] improve performance --- .../module_gint/new_grid_tech/biggrid_info.cpp | 2 +- .../module_gint/new_grid_tech/biggrid_info.h | 13 +------------ .../module_gint/new_grid_tech/meshgrid_info.h | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index 5e99adc9ea..ba66b4fc1d 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -42,7 +42,7 @@ BigGridInfo::BigGridInfo( for(int index_1d = 0; index_1d < nmxyz_; index_1d++) { meshgrid_coords_[index_1d] = - this->get_meshgrid_coord(index_1d); + meshgrid_info_->get_cartesian_coord(meshgrid_idx_1Dto3D(index_1d)); } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index 2d904ee0ff..97154a49b4 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -33,6 +33,7 @@ class BigGridInfo int get_nmz() const { return nmz_; }; int get_nmxyz() const { return nmxyz_; }; const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; + const Vec3d& get_meshgrid_coord(int index_1d) const { return meshgrid_coords_[index_1d]; }; std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; // get the 3D index of a meshgrid in the big grid from the 1D index @@ -46,18 +47,6 @@ class BigGridInfo { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); }; - - // get the cartesian coordinate of a meshgrid in the big grid from the 3D index - Vec3d get_meshgrid_coord(Vec3i index_3d) const - { - return index_3d * meshgrid_info_->get_latvec0(); - }; - - // get the cartesian coordinate of a meshgrid in the big grid from the 1D index - Vec3d get_meshgrid_coord(int index_1d) const - { - return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); - }; private: // basis vectors of the big grid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index 7bcc6ffbfd..700ce63aa6 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -44,7 +44,7 @@ class MeshGridInfo const Matrix3 &get_latvec0() const { return meshgrid_latvec0_; }; const Matrix3 &get_GT() const { return meshgrid_GT_; }; const double get_volume() const { return meshgrid_volume_; }; - + const Vec3d get_cartesian_coord(Vec3i index_3d) const { return index_3d * meshgrid_latvec0_; }; private: // basis vectors of meshgrid Vec3d meshgrid_vec1_; From 453206fe576dadeeca74f3df609c118fad60728f Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 10 Jan 2025 11:46:36 +0800 Subject: [PATCH 26/47] remove destructor --- .../module_gint/new_grid_tech/gint_info.cpp | 30 +++++++------------ .../module_gint/new_grid_tech/gint_info.h | 9 +++--- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index abfc47d9e2..f9378d47a0 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -41,14 +41,6 @@ GintInfo::GintInfo( init_ijr_info_(ucell, gd); } -GintInfo::~GintInfo() -{ - for (auto& atom: atoms_) - { - delete atom; - } -} - template std::shared_ptr> GintInfo::get_hr(int npol) const { @@ -76,7 +68,8 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital + biggrid_GT.e23 * biggrid_GT.e23 + biggrid_GT.e33 * biggrid_GT.e33); - is_atom_in_proc_ = std::vector(ucell_->nat, false); + is_atom_in_proc_.resize(ucell_->nat, false); + atoms_.resize(ucell_->nat); // TODO: USE OPENMP TO PARALLELIZE THIS LOOP for(int i = 0; i < ntype; i++) @@ -106,8 +99,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital delta.z * unitcell_info_->get_biggrid_info()->get_vec3(); const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); - // a map to store the atom in different unitcells - std::map gint_atom_map; + auto& r_to_atom = atoms_[iat]; for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++) { @@ -128,21 +120,21 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital // The index of the unitcell containing the biggrid relative to the unitcell containing the atom. const Vec3i ucell_idx_relative = ucell_idx_bgrid - ucell_idx_atom; - auto it = gint_atom_map.find(ucell_idx_relative); + auto it = r_to_atom.find(ucell_idx_relative); // if the gint_atom is not in the map, - // it means this is the first time we find this atom may affect some biggrids. - if(it == gint_atom_map.end()) + // it means this is the first time we find this atom may affect some biggrids, + // add it to the r_to_atom map + if(it == r_to_atom.end()) { Vec3i ext_atom_bgrid_idx(atom_bgrid_idx.x - ucell_idx_bgrid.x * unitcell_info_->get_nbx(), atom_bgrid_idx.y - ucell_idx_bgrid.y * unitcell_info_->get_nby(), atom_bgrid_idx.z - ucell_idx_bgrid.z * unitcell_info_->get_nbz()); - GintAtom* gint_atom = new GintAtom(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb); - atoms_.push_back(gint_atom); - gint_atom_map[ucell_idx_relative] = gint_atom; + r_to_atom.insert(std::make_pair(ucell_idx_relative, + GintAtom(&atom, j, iat, ext_atom_bgrid_idx, ucell_idx_relative, tau_in_biggrid, orb))); } - if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(gint_atom_map[ucell_idx_relative])) + if(biggrids_[bgrid_local_idx]->is_atom_on_bgrid(&r_to_atom.at(ucell_idx_relative))) { - biggrids_[bgrid_local_idx]->add_atom(gint_atom_map[ucell_idx_relative]); + biggrids_[bgrid_local_idx]->add_atom(&r_to_atom.at(ucell_idx_relative)); is_atom_in_proc_[iat] = true; } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index d411120f14..efdcb5b21f 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -27,8 +27,6 @@ class GintInfo int nbx_local, int nby_local, int nbz_local, const Numerical_Orbital* Phi, const UnitCell& ucell, Grid_Driver& gd); - - ~GintInfo(); // getter functions std::vector> get_biggrids() const { return biggrids_; }; @@ -62,8 +60,11 @@ class GintInfo // the big grids on this processor std::vector> biggrids_; - // the total atoms in the unitcell(include extended unitcell) - std::vector atoms_; + // the total atoms in the unitcell(include extended unitcell) on this processor + // atoms[iat][Vec3i] is the atom with index iat in the unitcell with index Vec3i + // Note: Since GintAtom does not implement a default constructor, + // the map should not be accessed using [], but rather using the at function + std::vector> atoms_; // if the iat-th(global index) atom is in this processor, return true std::vector is_atom_in_proc_; From d1fe00df48cdc50c563c60b2a6b0127cfef45cc0 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 10 Jan 2025 11:49:18 +0800 Subject: [PATCH 27/47] add timer --- .../new_grid_tech/gint_interface.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp index 22875e08b3..61f99f9118 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp @@ -1,4 +1,5 @@ #include "gint_interface.h" +#include "module_base/timer.h" #include "gint_vl.h" #include "gint_vl_metagga.h" #include "gint_vl_nspin4.h" @@ -15,16 +16,20 @@ void cal_gint_vl( const double* vr_eff, HContainer* hR) { + ModuleBase::timer::tick("Gint", "cal_gint_vl"); Gint_vl gint_vl(vr_eff, hR); gint_vl.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_vl"); } void cal_gint_vl( std::vector vr_eff, HContainer>* hR) { + ModuleBase::timer::tick("Gint", "cal_gint_vl"); Gint_vl_nspin4 gint_vl_nspin4(vr_eff, hR); gint_vl_nspin4.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_vl"); } void cal_gint_vl_metagga( @@ -32,8 +37,10 @@ void cal_gint_vl_metagga( const double* vfork, HContainer* hR) { + ModuleBase::timer::tick("Gint", "cal_gint_vl_metagga"); Gint_vl_metagga gint_vl_metagga(vr_eff, vfork, hR); gint_vl_metagga.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_vl_metagga"); } void cal_gint_vl_metagga( @@ -41,8 +48,10 @@ void cal_gint_vl_metagga( std::vector vofk, HContainer>* hR) { + ModuleBase::timer::tick("Gint", "cal_gint_vl_metagga"); Gint_vl_metagga_nspin4 gint_vl_metagga_nspin4(vr_eff, vofk, hR); gint_vl_metagga_nspin4.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_vl_metagga"); } void cal_gint_rho( @@ -50,8 +59,10 @@ void cal_gint_rho( const int nspin, double **rho) { + ModuleBase::timer::tick("Gint", "cal_gint_rho"); Gint_rho gint_rho(DMR_vec, nspin, rho); gint_rho.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_rho"); } void cal_gint_tau( @@ -59,8 +70,10 @@ void cal_gint_tau( const int nspin, double** tau) { + ModuleBase::timer::tick("Gint", "cal_gint_tau"); Gint_tau gint_tau(DMR_vec, nspin, tau); gint_tau.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_tau"); } void cal_gint_fvl( @@ -72,8 +85,10 @@ void cal_gint_fvl( ModuleBase::matrix* fvl, ModuleBase::matrix* svl) { + ModuleBase::timer::tick("Gint", "cal_gint_fvl"); Gint_fvl gint_fvl(nspin, vr_eff, DMR_vec, isforce, isstress, fvl, svl); gint_fvl.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_fvl"); } void cal_gint_fvl_meta( @@ -86,8 +101,10 @@ void cal_gint_fvl_meta( ModuleBase::matrix* fvl, ModuleBase::matrix* svl) { + ModuleBase::timer::tick("Gint", "cal_gint_fvl_meta"); Gint_fvl_meta gint_fvl_meta(nspin, vr_eff, vofk, DMR_vec, isforce, isstress, fvl, svl); gint_fvl_meta.cal_gint(); + ModuleBase::timer::tick("Gint", "cal_gint_fvl_meta"); } } // namespace ModuleGint \ No newline at end of file From db719d21da2f2c9bf9c3ba60d6b2bed78fbcbc44 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Fri, 10 Jan 2025 16:21:48 +0800 Subject: [PATCH 28/47] add timer --- .../module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index f9378d47a0..0f35e6eeec 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -1,6 +1,7 @@ #include #include #include "module_parameter/parameter.h" +#include "module_base/timer.h" #include "gint_info.h" #include "gint_type.h" @@ -56,6 +57,7 @@ std::shared_ptr> GintInfo::get_hr(int npol) const void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital* Phi) { + ModuleBase::timer::tick("GintInfo", "init_atoms"); int iat = 0; const Matrix3& biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); const double g1 = sqrt(biggrid_GT.e11 * biggrid_GT.e11 @@ -143,6 +145,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital iat++; } } + ModuleBase::timer::tick("GintInfo", "init_atoms"); } void GintInfo::init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd) From a525613a6640445997c7512ae86c6a0df6e0a1d1 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 15:43:01 +0800 Subject: [PATCH 29/47] improve performance --- .../new_grid_tech/phi_operator.cpp | 58 ++++++++++++------- .../module_gint/new_grid_tech/phi_operator.h | 18 ++++-- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index dc8d84e211..0e59af6df3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -15,6 +15,7 @@ void PhiOperator::set_bgrid(std::shared_ptr biggrid) biggrid_->set_atoms_phi_len(atoms_phi_len_); biggrid_->set_mgrids_local_idx(meshgrids_local_idx_); + // init is_atom_on_mgrid_ and atoms_relative_coords_ int atoms_num = biggrid_->get_atom_num(); atoms_relative_coords_.resize(atoms_num); is_atom_on_mgrid_.resize(atoms_num); @@ -27,6 +28,9 @@ void PhiOperator::set_bgrid(std::shared_ptr biggrid) is_atom_on_mgrid_[i][j] = atoms_relative_coords_[i][j].norm() <= biggrid_->get_atom(i)->get_rcut(); } } + + // init atom_pair_start_end_idx_ + init_atom_pair_start_end_idx_(); } void PhiOperator::set_phi(double* phi) const @@ -112,8 +116,8 @@ void PhiOperator::phi_mul_dm( continue; } - const int start_idx = atom_pair_startidx_(i, j); - const int end_idx = atom_pair_endidx_(i, j); + int start_idx = get_atom_pair_start_end_idx_(i, j).first; + int end_idx = get_atom_pair_start_end_idx_(i, j).second; const int len = end_idx - start_idx + 1; // if len<=0, it means this atom pair does not affect any meshgrid in this biggrid @@ -174,8 +178,8 @@ void PhiOperator::phi_mul_phi_vldr3( continue; } - const int start_idx = atom_pair_startidx_(i, j); - const int end_idx = atom_pair_endidx_(i, j); + int start_idx = get_atom_pair_start_end_idx_(i, j).first; + int end_idx = get_atom_pair_start_end_idx_(i, j).second; const int len = end_idx - start_idx + 1; if(len <= 0) @@ -269,28 +273,40 @@ void PhiOperator::phi_dot_dphi_r( //=============================== // private methods //=============================== -int PhiOperator::atom_pair_startidx_(int a, int b) const +void PhiOperator::init_atom_pair_start_end_idx_() { - for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) - { - if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) - { - return i; - } - } - return biggrid_->get_meshgrid_num(); -} - -int PhiOperator::atom_pair_endidx_(int a, int b) const -{ - for(int i = biggrid_->get_meshgrid_num() - 1; i >= 0; --i) + int atoms_num = biggrid_->get_atom_num(); + atom_pair_start_end_idx_.resize(atoms_num * (atoms_num + 1) / 2); + int mgrids_num = biggrid_->get_meshgrid_num(); + int atom_pair_idx = 0; + for(int i = 0; i < atoms_num; ++i) { - if(is_atom_on_mgrid_[a][i] && is_atom_on_mgrid_[b][i]) + // only calculate the upper triangle matrix + for(int j = i; j < atoms_num; ++j) { - return i; + int start_idx = mgrids_num; + int end_idx = -1; + for(int mgrid_idx = 0; mgrid_idx < mgrids_num; ++mgrid_idx) + { + if(is_atom_on_mgrid_[i][mgrid_idx] && is_atom_on_mgrid_[j][mgrid_idx]) + { + start_idx = mgrid_idx; + break; + } + } + for(int mgrid_idx = mgrids_num - 1; mgrid_idx >= 0; --mgrid_idx) + { + if(is_atom_on_mgrid_[i][mgrid_idx] && is_atom_on_mgrid_[j][mgrid_idx]) + { + end_idx = mgrid_idx; + break; + } + } + atom_pair_start_end_idx_[atom_pair_idx].first = start_idx; + atom_pair_start_end_idx_[atom_pair_idx].second = end_idx; + atom_pair_idx++; } } - return -1; } } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 90009b002d..cdbfc930df 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -2,6 +2,7 @@ #include #include +#include #include #include "biggrid.h" @@ -79,12 +80,16 @@ class PhiOperator ModuleBase::matrix *svl) const; private: + void init_atom_pair_start_end_idx_(); - // get the index of the first meshgrid that both atom a and atom b affect - int atom_pair_startidx_(int a, int b) const; - - // get the index of the last meshgrid that both atom a and atom b affect - int atom_pair_endidx_(int a, int b) const; + // get the index of the first and the last meshgrid that both atom a and atom b affect + // Note that atom_pair_start_end_idx_ only stores the cases where a <= b, so this function is needed to retrieve the value + const std::pair& get_atom_pair_start_end_idx_(int a, int b) const + { + int x = std::min(a, b); + int y = std::abs(a - b); + return atom_pair_start_end_idx_[(2 * biggrid_->get_atom_num() - x + 1) * x / 2 + y]; + }; // the row number of the phi matrix // rows_ = biggrid_->get_meshgrid_num() @@ -116,6 +121,9 @@ class PhiOperator // atoms_phi_len_[i] = biggrid_->get_atom(i)->get_nw() // TODO: remove it std::vector atoms_phi_len_; + + // This data structure is used to store the index of the first and last meshgrid affected by each atom pair + std::vector> atom_pair_start_end_idx_; }; } \ No newline at end of file From d276af07350d29f4d5bb590a7ce43d0efda5032f Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 16:43:22 +0800 Subject: [PATCH 30/47] change 2D ptr to 1D ptr --- .../module_gint/new_grid_tech/gint_fvl.cpp | 8 +-- .../new_grid_tech/gint_fvl_meta.cpp | 32 ++++----- .../module_gint/new_grid_tech/gint_rho.cpp | 4 +- .../module_gint/new_grid_tech/gint_tau.cpp | 12 ++-- .../module_gint/new_grid_tech/gint_vl.cpp | 4 +- .../new_grid_tech/gint_vl_metagga.cpp | 16 ++--- .../new_grid_tech/gint_vl_metagga_nspin4.cpp | 16 ++--- .../new_grid_tech/gint_vl_nspin4.cpp | 4 +- .../new_grid_tech/phi_operator.cpp | 69 ++++++++++--------- .../module_gint/new_grid_tech/phi_operator.h | 32 ++++----- .../module_gint/new_grid_tech/set_ddphi.cpp | 2 +- 11 files changed, 101 insertions(+), 98 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp index 4860b5bd8b..a103007f3e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp @@ -59,15 +59,15 @@ void Gint_fvl::cal_fvl_svl_() { ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(phi_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_dm(phi_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_2D()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D()); if(isforce_) { - phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), fvl_thread); + phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread); } if(isstress_) { - phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), svl_thread); + phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp index a6c9d11d5a..2c8939b60b 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp @@ -79,27 +79,27 @@ void Gint_fvl_meta::cal_fvl_svl_() ModuleBase::zeros(dphi_x_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_y_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_z_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); - phi_op.phi_mul_dm(phi_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_2D()); - phi_op.phi_mul_dm(dphi_x_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.get_ptr_2D()); - phi_op.phi_mul_dm(dphi_y_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.get_ptr_2D()); - phi_op.phi_mul_dm(dphi_z_vldr3.get_ptr_2D(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.get_ptr_2D()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); + phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D()); + phi_op.phi_mul_dm(dphi_x_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.get_ptr_1D()); + phi_op.phi_mul_dm(dphi_y_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.get_ptr_1D()); + phi_op.phi_mul_dm(dphi_z_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.get_ptr_1D()); if(isforce_) { - phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_x_vldr3_DM.get_ptr_2D(), ddphi_xx.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_xz.get_ptr_2D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_y_vldr3_DM.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_yy.get_ptr_2D(), ddphi_yz.get_ptr_2D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_z_vldr3_DM.get_ptr_2D(), ddphi_xz.get_ptr_2D(), ddphi_yz.get_ptr_2D(), ddphi_zz.get_ptr_2D(), fvl_thread); + phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), fvl_thread); + phi_op.phi_dot_dphi(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), fvl_thread); } if(isstress_) { - phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_2D(), dphi_x.get_ptr_2D(), dphi_y.get_ptr_2D(), dphi_z.get_ptr_2D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.get_ptr_2D(), ddphi_xx.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_xz.get_ptr_2D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.get_ptr_2D(), ddphi_xy.get_ptr_2D(), ddphi_yy.get_ptr_2D(), ddphi_yz.get_ptr_2D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.get_ptr_2D(), ddphi_xz.get_ptr_2D(), ddphi_yz.get_ptr_2D(), ddphi_zz.get_ptr_2D(), svl_thread); + phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), svl_thread); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp index 66d95abd8c..9c1b0f87dc 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp @@ -42,8 +42,8 @@ void Gint_rho::cal_rho_() for (int is = 0; is < nspin_; is++) { ModuleBase::zeros(phi_DMR.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_dm(phi.get_ptr_2D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_2D()); - phi_op.phi_dot_phi_dm(phi.get_ptr_2D(), phi_DMR.get_ptr_2D(), rho_[is]); + phi_op.phi_mul_dm(phi.get_ptr_1D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_1D()); + phi_op.phi_dot_phi_dm(phi.get_ptr_1D(), phi_DMR.get_ptr_1D(), rho_[is]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp index 4da7394c42..04c4a5cd31 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp @@ -48,12 +48,12 @@ void Gint_tau::cal_tau_() ModuleBase::zeros(dphi_x_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_y_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_z_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_dm(dphi_x.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_2D()); - phi_op.phi_mul_dm(dphi_y.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_2D()); - phi_op.phi_mul_dm(dphi_z.get_ptr_2D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_2D()); - phi_op.phi_dot_phi_dm(dphi_x.get_ptr_2D(), dphi_x_DM.get_ptr_2D(), kin_[is]); - phi_op.phi_dot_phi_dm(dphi_y.get_ptr_2D(), dphi_y_DM.get_ptr_2D(), kin_[is]); - phi_op.phi_dot_phi_dm(dphi_z.get_ptr_2D(), dphi_z_DM.get_ptr_2D(), kin_[is]); + phi_op.phi_mul_dm(dphi_x.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_1D()); + phi_op.phi_mul_dm(dphi_y.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_1D()); + phi_op.phi_mul_dm(dphi_z.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_1D()); + phi_op.phi_dot_phi_dm(dphi_x.get_ptr_1D(), dphi_x_DM.get_ptr_1D(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_y.get_ptr_1D(), dphi_y_DM.get_ptr_1D(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_z.get_ptr_1D(), dphi_z_DM.get_ptr_1D(), kin_[is]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index d9b7450cc8..5f3b9b1fff 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -44,8 +44,8 @@ void Gint_vl::cal_hRGint_() ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); phi_op.set_phi(phi.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_local); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_local); } #pragma omp critical { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp index b18b7e6a3c..84cad840ce 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp @@ -50,14 +50,14 @@ void Gint_vl_metagga::cal_hRGint_() ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D(), &hRGint_local); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D(), &hRGint_local); } #pragma omp critical { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp index 4d8997fc5d..63d65b1f1d 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp @@ -58,14 +58,14 @@ void Gint_vl_metagga_nspin4::cal_hRGint_() ModuleBase::zeros(dphi_x_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_y_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); ModuleBase::zeros(dphi_z_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_2D(), dphi_x_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_2D(), dphi_y_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_2D(), dphi_z_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); } } #pragma omp critical diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 035d48c391..8a6c76e140 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -48,8 +48,8 @@ void Gint_vl_nspin4::cal_hRGint_() for(int is = 0; is < nspin_; is++) { ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_2D(), phi_vldr3.get_ptr_2D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_2D(), phi_vldr3.get_ptr_2D(), &hRGint_part_thread[is]); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); + phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); } } #pragma omp critical diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 0e59af6df3..526ed51796 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -77,9 +77,9 @@ void PhiOperator::set_ddphi( } void PhiOperator::phi_mul_dm( - const double* const* phi, + const double* phi, const HContainer& DM, - const bool is_symm, double** phi_dm) const + const bool is_symm, double*phi_dm) const { // parameters for lapack subroutines constexpr char side = 'L'; @@ -98,7 +98,7 @@ void PhiOperator::phi_mul_dm( { const auto dm_mat = DM.find_matrix(atom_i->get_iat(), atom_i->get_iat(), 0, 0, 0); dsymm_(&side, &uplo, &atoms_phi_len_[i], &rows_, &alpha, dm_mat->get_pointer(), &atoms_phi_len_[i], - &phi[0][atoms_startidx_[i]], &cols_, &beta, &phi_dm[0][atoms_startidx_[i]], &cols_); + &phi[0 * cols_ + atoms_startidx_[i]], &cols_, &beta, &phi_dm[0 * cols_ + atoms_startidx_[i]], &cols_); } const int start = is_symm ? i + 1 : 0; @@ -127,26 +127,28 @@ void PhiOperator::phi_mul_dm( } dgemm_(&trans, &trans, &atoms_phi_len_[j], &len, &atoms_phi_len_[i], &alpha1, dm_mat->get_pointer(), &atoms_phi_len_[j], - &phi[start_idx][atoms_startidx_[i]], &cols_, &beta, &phi_dm[start_idx][atoms_startidx_[j]], &cols_); + &phi[start_idx * cols_ + atoms_startidx_[i]], &cols_, &beta, &phi_dm[start_idx * cols_ + atoms_startidx_[j]], &cols_); } } } -void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double* const* phi, double** result) const +void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double* phi, double* result) const { + int idx = 0; for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) { double vldr3_mgrid = vl[meshgrids_local_idx_[i]] * dr3; for(int j = 0; j < cols_; j++) { - result[i][j] = phi[i][j] * vldr3_mgrid; + result[idx] = phi[idx] * vldr3_mgrid; + idx++; } } } void PhiOperator::phi_mul_phi_vldr3( - const double* const* phi, - const double* const* phi_vldr3, + const double* phi, + const double* phi_vldr3, HContainer* hr) const { const char transa='N', transb='T'; @@ -187,29 +189,29 @@ void PhiOperator::phi_mul_phi_vldr3( continue; } - dgemm_(&transa, &transb, &atoms_phi_len_[j], &atoms_phi_len_[i], &len, &alpha, &phi_vldr3[start_idx][atoms_startidx_[j]], - &cols_,&phi[start_idx][atoms_startidx_[i]], &cols_, &beta, result->get_pointer(), &atoms_phi_len_[j]); + dgemm_(&transa, &transb, &atoms_phi_len_[j], &atoms_phi_len_[i], &len, &alpha, &phi_vldr3[start_idx * cols_ + atoms_startidx_[j]], + &cols_,&phi[start_idx * cols_ + atoms_startidx_[i]], &cols_, &beta, result->get_pointer(), &atoms_phi_len_[j]); } } } void PhiOperator::phi_dot_phi_dm( - const double* const* phi, - const double* const* phi_dm, + const double* phi, + const double* phi_dm, double* rho) const { const int inc = 1; for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) { - rho[meshgrids_local_idx_[i]] += ddot_(&cols_, phi[i], &inc, phi_dm[i], &inc); + rho[meshgrids_local_idx_[i]] += ddot_(&cols_, &phi[i * cols_], &inc, &phi_dm[i * cols_], &inc); } } void PhiOperator::phi_dot_dphi( - const double* const* phi, - const double* const* dphi_x, - const double* const* dphi_y, - const double* const* dphi_z, + const double* phi, + const double* dphi_x, + const double* dphi_y, + const double* dphi_z, ModuleBase::matrix *fvl) const { for(int i = 0; i < biggrid_->get_atom_num(); ++i) @@ -222,10 +224,11 @@ void PhiOperator::phi_dot_dphi( { for(int k = 0; k < phi_len; ++k) { - const double phi_val = phi[j][start_idx + k]; - rx += phi_val * dphi_x[j][start_idx + k]; - ry += phi_val * dphi_y[j][start_idx + k]; - rz += phi_val * dphi_z[j][start_idx + k]; + int idx = j * cols_ + start_idx + k; + const double phi_val = phi[idx]; + rx += phi_val * dphi_x[idx]; + ry += phi_val * dphi_y[idx]; + rz += phi_val * dphi_z[idx]; } } fvl[0](iat, 0) += rx * 2; @@ -235,10 +238,10 @@ void PhiOperator::phi_dot_dphi( } void PhiOperator::phi_dot_dphi_r( - const double* const *phi, - const double* const *dphi_x, - const double* const *dphi_y, - const double* const *dphi_z, + const double* phi, + const double* dphi_x, + const double* dphi_y, + const double* dphi_z, ModuleBase::matrix *svl) const { double sxx = 0, sxy = 0, sxz = 0, syy = 0, syz = 0, szz = 0; @@ -249,15 +252,15 @@ void PhiOperator::phi_dot_dphi_r( const int start_idx = atoms_startidx_[j]; for(int k = 0; k < atoms_phi_len_[j]; ++k) { - const int col_idx = start_idx + k; - const double phi_val = phi[i][col_idx]; + const int idx = i * cols_ + start_idx + k; const Vec3d& r3 = atoms_relative_coords_[j][i]; - sxx += phi_val * dphi_x[i][col_idx] * r3[0]; - sxy += phi_val * dphi_x[i][col_idx] * r3[1]; - sxz += phi_val * dphi_x[i][col_idx] * r3[2]; - syy += phi_val * dphi_y[i][col_idx] * r3[1]; - syz += phi_val * dphi_y[i][col_idx] * r3[2]; - szz += phi_val * dphi_z[i][col_idx] * r3[2]; + const double phi_val = phi[idx]; + sxx += phi_val * dphi_x[idx] * r3[0]; + sxy += phi_val * dphi_x[idx] * r3[1]; + sxz += phi_val * dphi_x[idx] * r3[2]; + syy += phi_val * dphi_y[idx] * r3[1]; + syz += phi_val * dphi_y[idx] * r3[2]; + szz += phi_val * dphi_z[idx] * r3[2]; } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index cdbfc930df..25c4f291ef 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -45,38 +45,38 @@ class PhiOperator double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const; void phi_mul_dm( - const double* const* phi, + const double* phi, const HContainer& DM, - const bool is_symm, double** phi_dm) const; + const bool is_symm, double* phi_dm) const; void phi_mul_vldr3( const double* vl, const double dr3, - const double* const* phi, - double** result) const; + const double* phi, + double* result) const; void phi_mul_phi_vldr3( - const double* const* phi, - const double* const* phi_vldr3, + const double* phi, + const double* phi_vldr3, HContainer* hr) const; void phi_dot_phi_dm( - const double* const* phi, - const double* const* phi_dm, + const double* phi, + const double* phi_dm, double* rho) const; void phi_dot_dphi( - const double* const* phi, - const double* const* dphi_x, - const double* const* dphi_y, - const double* const* dphi_z, + const double* phi, + const double* dphi_x, + const double* dphi_y, + const double* dphi_z, ModuleBase::matrix *fvl) const; void phi_dot_dphi_r( - const double* const* phi, - const double* const* dphi_x, - const double* const* dphi_y, - const double* const* dphi_z, + const double* phi, + const double* dphi_x, + const double* dphi_y, + const double* dphi_z, ModuleBase::matrix *svl) const; private: diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index e0f9c803a3..e62332da35 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -162,7 +162,7 @@ void GintAtom::set_ddphi( // // End of code addition section. // std::vector> hrly; - // ModuleBase::Ylm::grad_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], rly, grly.get_ptr_2D()); + // ModuleBase::Ylm::grad_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], rly, grly.get_ptr_1D()); // ModuleBase::Ylm::hes_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], hrly); // const double position = distance / delta_r; From 9de506cb9c089acf1ff7026c51530c19c59ac1c2 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 16:52:25 +0800 Subject: [PATCH 31/47] modify zeros function --- .../module_gint/new_grid_tech/gint_fvl.cpp | 2 -- .../module_gint/new_grid_tech/gint_fvl_meta.cpp | 8 -------- .../module_gint/new_grid_tech/gint_rho.cpp | 1 - .../module_gint/new_grid_tech/gint_tau.cpp | 3 --- .../module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp | 4 ---- .../module_gint/new_grid_tech/gint_vl_nspin4.cpp | 1 - .../module_gint/new_grid_tech/phi_operator.cpp | 5 ++++- 7 files changed, 4 insertions(+), 20 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp index a103007f3e..68c260bf49 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp @@ -57,8 +57,6 @@ void Gint_fvl::cal_fvl_svl_() phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); for (int is = 0; is < nspin_; is++) { - ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(phi_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D()); if(isforce_) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp index 2c8939b60b..ec5b9b02b0 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp @@ -71,14 +71,6 @@ void Gint_fvl_meta::cal_fvl_svl_() ModuleBase::Array_Pool dphi_z_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); for (int is = 0; is < nspin_; is++) { - ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(phi_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_x_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_y_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_z_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_x_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_y_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_z_vldr3_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp index 9c1b0f87dc..078611b2ea 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp @@ -41,7 +41,6 @@ void Gint_rho::cal_rho_() phi_op.set_phi(phi.get_ptr_1D()); for (int is = 0; is < nspin_; is++) { - ModuleBase::zeros(phi_DMR.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_dm(phi.get_ptr_1D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_1D()); phi_op.phi_dot_phi_dm(phi.get_ptr_1D(), phi_DMR.get_ptr_1D(), rho_[is]); } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp index 04c4a5cd31..22113b2564 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp @@ -45,9 +45,6 @@ void Gint_tau::cal_tau_() phi_op.set_phi_dphi(nullptr, dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); for (int is = 0; is < nspin_; is++) { - ModuleBase::zeros(dphi_x_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_y_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_z_DM.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_dm(dphi_x.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_1D()); phi_op.phi_mul_dm(dphi_y.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_1D()); phi_op.phi_mul_dm(dphi_z.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_1D()); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp index 63d65b1f1d..1086a7a34e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp @@ -54,10 +54,6 @@ void Gint_vl_metagga_nspin4::cal_hRGint_() phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); for(int is = 0; is < nspin_; is++) { - ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_x_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_y_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); - ModuleBase::zeros(dphi_z_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 8a6c76e140..920da95fee 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -47,7 +47,6 @@ void Gint_vl_nspin4::cal_hRGint_() phi_op.set_phi(phi.get_ptr_1D()); for(int is = 0; is < nspin_; is++) { - ModuleBase::zeros(phi_vldr3.get_ptr_1D(), phi_op.get_rows()*phi_op.get_cols()); phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index 526ed51796..f933a96cdf 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -1,5 +1,6 @@ #include "phi_operator.h" #include "module_base/blas_connector.h" +#include "module_base/global_function.h" #include "module_base/matrix.h" namespace ModuleGint @@ -79,8 +80,9 @@ void PhiOperator::set_ddphi( void PhiOperator::phi_mul_dm( const double* phi, const HContainer& DM, - const bool is_symm, double*phi_dm) const + const bool is_symm, double* phi_dm) const { + ModuleBase::GlobalFunc::ZEROS(phi_dm, rows_ * cols_); // parameters for lapack subroutines constexpr char side = 'L'; constexpr char uplo = 'U'; @@ -134,6 +136,7 @@ void PhiOperator::phi_mul_dm( void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double* phi, double* result) const { + ModuleBase::GlobalFunc::ZEROS(result, rows_ * cols_); int idx = 0; for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) { From d86de0f9d4a97d21de343d8b4d8140f6d7a7c56e Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 20:42:47 +0800 Subject: [PATCH 32/47] replace array pool with vector --- .../module_gint/new_grid_tech/gint_atom.cpp | 1 + .../module_gint/new_grid_tech/gint_fvl.cpp | 30 +++--- .../new_grid_tech/gint_fvl_meta.cpp | 94 +++++++++++-------- .../module_gint/new_grid_tech/gint_info.cpp | 3 + .../module_gint/new_grid_tech/gint_info.h | 8 +- .../module_gint/new_grid_tech/gint_rho.cpp | 14 +-- .../module_gint/new_grid_tech/gint_tau.cpp | 34 ++++--- .../module_gint/new_grid_tech/gint_vl.cpp | 14 +-- .../new_grid_tech/gint_vl_metagga.cpp | 44 +++++---- .../new_grid_tech/gint_vl_metagga_nspin4.cpp | 44 +++++---- .../new_grid_tech/gint_vl_nspin4.cpp | 14 +-- .../module_gint/new_grid_tech/set_ddphi.cpp | 2 +- 12 files changed, 182 insertions(+), 120 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index 305742fd88..0f791e58e9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -112,6 +112,7 @@ void GintAtom::set_phi_dphi( } std::vector rly(std::pow(atom_->nwl + 1, 2)); + // TODO: replace array_pool with std::vector ModuleBase::Array_Pool grly(std::pow(atom_->nwl + 1, 2), 3); for(int im = 0; im < num_mgrids; im++) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp index 68c260bf49..adbffddf91 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "gint_fvl.h" #include "gint_common.h" @@ -28,6 +27,12 @@ void Gint_fvl::cal_fvl_svl_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; + std::vector phi_vldr3_DM; + std::vector dphi_x; + std::vector dphi_y; + std::vector dphi_z; ModuleBase::matrix* fvl_thread = nullptr; ModuleBase::matrix* svl_thread = nullptr; if(isforce_) @@ -48,24 +53,25 @@ void Gint_fvl::cal_fvl_svl_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + phi_vldr3_DM.resize(phi_len); + dphi_x.resize(phi_len); + dphi_y.resize(phi_len); + dphi_z.resize(phi_len); + phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data()); for (int is = 0; is < nspin_; is++) { - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_dm(phi_vldr3.data(), *DMRGint_vec_[is], false, phi_vldr3_DM.data()); if(isforce_) { - phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread); + phi_op.phi_dot_dphi(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), fvl_thread); } if(isstress_) { - phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread); + phi_op.phi_dot_dphi_r(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), svl_thread); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp index ec5b9b02b0..852669b264 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "gint_fvl_meta.h" #include "gint_common.h" @@ -28,6 +27,24 @@ void Gint_fvl_meta::cal_fvl_svl_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; + std::vector phi_vldr3_DM; + std::vector dphi_x; + std::vector dphi_y; + std::vector dphi_z; + std::vector dphi_x_vldr3; + std::vector dphi_y_vldr3; + std::vector dphi_z_vldr3; + std::vector dphi_x_vldr3_DM; + std::vector dphi_y_vldr3_DM; + std::vector dphi_z_vldr3_DM; + std::vector ddphi_xx; + std::vector ddphi_xy; + std::vector ddphi_xz; + std::vector ddphi_yy; + std::vector ddphi_yz; + std::vector ddphi_zz; ModuleBase::matrix* fvl_thread = nullptr; ModuleBase::matrix* svl_thread = nullptr; if(isforce_) @@ -48,50 +65,51 @@ void Gint_fvl_meta::cal_fvl_svl_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_xx(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_xy(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_xz(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_yy(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_yz(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool ddphi_zz(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); - phi_op.set_ddphi(ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), - ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z_vldr3_DM(phi_op.get_rows(), phi_op.get_cols()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + phi_vldr3_DM.resize(phi_len); + dphi_x.resize(phi_len); + dphi_y.resize(phi_len); + dphi_z.resize(phi_len); + dphi_x_vldr3.resize(phi_len); + dphi_y_vldr3.resize(phi_len); + dphi_z_vldr3.resize(phi_len); + dphi_x_vldr3_DM.resize(phi_len); + dphi_y_vldr3_DM.resize(phi_len); + dphi_z_vldr3_DM.resize(phi_len); + ddphi_xx.resize(phi_len); + ddphi_xy.resize(phi_len); + ddphi_xz.resize(phi_len); + ddphi_yy.resize(phi_len); + ddphi_yz.resize(phi_len); + ddphi_zz.resize(phi_len); + phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data()); + phi_op.set_ddphi(ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(), + ddphi_yy.data(), ddphi_yz.data(), ddphi_zz.data()); for (int is = 0; is < nspin_; is++) { - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); - phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D()); - phi_op.phi_mul_dm(dphi_x_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.get_ptr_1D()); - phi_op.phi_mul_dm(dphi_y_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.get_ptr_1D()); - phi_op.phi_mul_dm(dphi_z_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.get_ptr_1D()); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.data(), dphi_x_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.data(), dphi_y_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.data(), dphi_z_vldr3.data()); + phi_op.phi_mul_dm(phi_vldr3.data(), *DMRGint_vec_[is], false, phi_vldr3_DM.data()); + phi_op.phi_mul_dm(dphi_x_vldr3.data(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.data()); + phi_op.phi_mul_dm(dphi_y_vldr3.data(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.data()); + phi_op.phi_mul_dm(dphi_z_vldr3.data(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.data()); if(isforce_) { - phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), fvl_thread); - phi_op.phi_dot_dphi(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), fvl_thread); + phi_op.phi_dot_dphi(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), fvl_thread); + phi_op.phi_dot_dphi(dphi_x_vldr3_DM.data(), ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(), fvl_thread); + phi_op.phi_dot_dphi(dphi_y_vldr3_DM.data(), ddphi_xy.data(), ddphi_yy.data(), ddphi_yz.data(), fvl_thread); + phi_op.phi_dot_dphi(dphi_z_vldr3_DM.data(), ddphi_xz.data(), ddphi_yz.data(), ddphi_zz.data(), fvl_thread); } if(isstress_) { - phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), svl_thread); - phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), svl_thread); + phi_op.phi_dot_dphi_r(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.data(), ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.data(), ddphi_xy.data(), ddphi_yy.data(), ddphi_yz.data(), svl_thread); + phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.data(), ddphi_xz.data(), ddphi_yz.data(), ddphi_zz.data(), svl_thread); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 0f35e6eeec..b5ba0d6362 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -21,6 +21,9 @@ GintInfo::GintInfo( unitcell_info_ = std::make_shared(ucell_->a1 * ucell_->lat0, ucell_->a2 * ucell_->lat0, ucell_->a3 * ucell_->lat0, nbx, nby, nbz, nmx, nmy, nmz); + biggrid_info_ = unitcell_info_->get_biggrid_info(); + meshgrid_info_ = biggrid_info_->get_meshgrid_info(); + // initialize the divide information divide_info_ = std::make_shared(startidx_bx, startidx_by, startidx_bz, nbx_local, nby_local, nbz_local, unitcell_info_, false); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index efdcb5b21f..87a2e97543 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -31,7 +31,7 @@ class GintInfo // getter functions std::vector> get_biggrids() const { return biggrids_; }; double get_local_mgrid_num() const { return localcell_info_->get_mgrid_num(); }; - double get_mgrid_volume() const { return unitcell_info_->get_meshgrid_info()->get_volume(); }; + double get_mgrid_volume() const { return meshgrid_info_->get_volume(); }; //========================================= // functions about hcontainer @@ -51,6 +51,12 @@ class GintInfo // the unitcell information std::shared_ptr unitcell_info_; + // the biggrid information + std::shared_ptr biggrid_info_; + + // the meshgrid information + std::shared_ptr meshgrid_info_; + // the divide information std::shared_ptr divide_info_; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp index 078611b2ea..00655353bc 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "gint_rho.h" #include "gint_common.h" @@ -28,6 +27,8 @@ void Gint_rho::cal_rho_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_DMR; #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) { @@ -36,13 +37,14 @@ void Gint_rho::cal_rho_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_DMR(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi(phi.get_ptr_1D()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_DMR.resize(phi_len); + phi_op.set_phi(phi.data()); for (int is = 0; is < nspin_; is++) { - phi_op.phi_mul_dm(phi.get_ptr_1D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_1D()); - phi_op.phi_dot_phi_dm(phi.get_ptr_1D(), phi_DMR.get_ptr_1D(), rho_[is]); + phi_op.phi_mul_dm(phi.data(), *DMRGint_vec_[is], true, phi_DMR.data()); + phi_op.phi_dot_phi_dm(phi.data(), phi_DMR.data(), rho_[is]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp index 22113b2564..89374fbf00 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "gint_tau.h" #include "gint_common.h" @@ -28,6 +27,12 @@ void Gint_tau::cal_tau_() #pragma omp parallel { PhiOperator phi_op; + std::vector dphi_x; + std::vector dphi_y; + std::vector dphi_z; + std::vector dphi_x_DM; + std::vector dphi_y_DM; + std::vector dphi_z_DM; #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) { @@ -36,21 +41,22 @@ void Gint_tau::cal_tau_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y_DM(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z_DM(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi_dphi(nullptr, dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + dphi_x.resize(phi_len); + dphi_y.resize(phi_len); + dphi_z.resize(phi_len); + dphi_x_DM.resize(phi_len); + dphi_y_DM.resize(phi_len); + dphi_z_DM.resize(phi_len); + phi_op.set_phi_dphi(nullptr, dphi_x.data(), dphi_y.data(), dphi_z.data()); for (int is = 0; is < nspin_; is++) { - phi_op.phi_mul_dm(dphi_x.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_1D()); - phi_op.phi_mul_dm(dphi_y.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_1D()); - phi_op.phi_mul_dm(dphi_z.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_1D()); - phi_op.phi_dot_phi_dm(dphi_x.get_ptr_1D(), dphi_x_DM.get_ptr_1D(), kin_[is]); - phi_op.phi_dot_phi_dm(dphi_y.get_ptr_1D(), dphi_y_DM.get_ptr_1D(), kin_[is]); - phi_op.phi_dot_phi_dm(dphi_z.get_ptr_1D(), dphi_z_DM.get_ptr_1D(), kin_[is]); + phi_op.phi_mul_dm(dphi_x.data(), *DMRGint_vec_[is], true, dphi_x_DM.data()); + phi_op.phi_mul_dm(dphi_y.data(), *DMRGint_vec_[is], true, dphi_y_DM.data()); + phi_op.phi_mul_dm(dphi_z.data(), *DMRGint_vec_[is], true, dphi_z_DM.data()); + phi_op.phi_dot_phi_dm(dphi_x.data(), dphi_x_DM.data(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_y.data(), dphi_y_DM.data(), kin_[is]); + phi_op.phi_dot_phi_dm(dphi_z.data(), dphi_z_DM.data(), kin_[is]); } } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp index 5f3b9b1fff..4553f73e76 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/blas_connector.h" #include "gint_common.h" #include "gint_vl.h" @@ -32,6 +31,8 @@ void Gint_vl::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; HContainer hRGint_local(*hRGint_); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) @@ -41,11 +42,12 @@ void Gint_vl::cal_hRGint_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi(phi.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_local); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + phi_op.set_phi(phi.data()); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_phi_vldr3(phi.data(), phi_vldr3.data(), &hRGint_local); } #pragma omp critical { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp index 84cad840ce..2c5351c338 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/blas_connector.h" #include "gint_common.h" #include "gint_vl_metagga.h" @@ -32,6 +31,14 @@ void Gint_vl_metagga::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; + std::vector dphi_x; + std::vector dphi_y; + std::vector dphi_z; + std::vector dphi_x_vldr3; + std::vector dphi_y_vldr3; + std::vector dphi_z_vldr3; HContainer hRGint_local(*hRGint_); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) @@ -41,23 +48,24 @@ void Gint_vl_metagga::cal_hRGint_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); - phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D(), &hRGint_local); - phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D(), &hRGint_local); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + dphi_x.resize(phi_len); + dphi_y.resize(phi_len); + dphi_z.resize(phi_len); + dphi_x_vldr3.resize(phi_len); + dphi_y_vldr3.resize(phi_len); + dphi_z_vldr3.resize(phi_len); + phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data()); + phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_x.data(), dphi_x_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_y.data(), dphi_y_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_, dr3_, dphi_z.data(), dphi_z_vldr3.data()); + phi_op.phi_mul_phi_vldr3(phi.data(), phi_vldr3.data(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_x.data(), dphi_x_vldr3.data(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_y.data(), dphi_y_vldr3.data(), &hRGint_local); + phi_op.phi_mul_phi_vldr3(dphi_z.data(), dphi_z_vldr3.data(), &hRGint_local); } #pragma omp critical { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp index 1086a7a34e..9ee94b466c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_base/blas_connector.h" @@ -34,6 +33,14 @@ void Gint_vl_metagga_nspin4::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; + std::vector dphi_x; + std::vector dphi_y; + std::vector dphi_z; + std::vector dphi_x_vldr3; + std::vector dphi_y_vldr3; + std::vector dphi_z_vldr3; std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) @@ -43,25 +50,26 @@ void Gint_vl_metagga_nspin4::cal_hRGint_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + dphi_x.resize(phi_len); + dphi_y.resize(phi_len); + dphi_z.resize(phi_len); + dphi_x_vldr3.resize(phi_len); + dphi_y_vldr3.resize(phi_len); + dphi_z_vldr3.resize(phi_len); + phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data()); for(int is = 0; is < nspin_; is++) { - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D()); - phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); - phi_op.phi_mul_phi_vldr3(dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.data(), dphi_x_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.data(), dphi_y_vldr3.data()); + phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.data(), dphi_z_vldr3.data()); + phi_op.phi_mul_phi_vldr3(phi.data(), phi_vldr3.data(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_x.data(), dphi_x_vldr3.data(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_y.data(), dphi_y_vldr3.data(), &hRGint_part_thread[is]); + phi_op.phi_mul_phi_vldr3(dphi_z.data(), dphi_z_vldr3.data(), &hRGint_part_thread[is]); } } #pragma omp critical diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp index 920da95fee..b9501940bf 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp @@ -1,4 +1,3 @@ -#include "module_base/array_pool.h" #include "module_base/global_function.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_base/blas_connector.h" @@ -33,6 +32,8 @@ void Gint_vl_nspin4::cal_hRGint_() #pragma omp parallel { PhiOperator phi_op; + std::vector phi; + std::vector phi_vldr3; std::vector> hRGint_part_thread(nspin_, *hRGint_part_[0]); #pragma omp for schedule(dynamic) for(const auto& biggrid: gint_info_->get_biggrids()) @@ -42,13 +43,14 @@ void Gint_vl_nspin4::cal_hRGint_() continue; } phi_op.set_bgrid(biggrid); - ModuleBase::Array_Pool phi(phi_op.get_rows(), phi_op.get_cols()); - ModuleBase::Array_Pool phi_vldr3(phi_op.get_rows(), phi_op.get_cols()); - phi_op.set_phi(phi.get_ptr_1D()); + const int phi_len = phi_op.get_rows() * phi_op.get_cols(); + phi.resize(phi_len); + phi_vldr3.resize(phi_len); + phi_op.set_phi(phi.data()); for(int is = 0; is < nspin_; is++) { - phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D()); - phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_part_thread[is]); + phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data()); + phi_op.phi_mul_phi_vldr3(phi.data(), phi_vldr3.data(), &hRGint_part_thread[is]); } } #pragma omp critical diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp index e62332da35..dd0b77f18f 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp @@ -162,7 +162,7 @@ void GintAtom::set_ddphi( // // End of code addition section. // std::vector> hrly; - // ModuleBase::Ylm::grad_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], rly, grly.get_ptr_1D()); + // ModuleBase::Ylm::grad_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], rly, grly.data()); // ModuleBase::Ylm::hes_rl_sph_harm(ucell.atoms[it].nwl, dr[0], dr[1], dr[2], hrly); // const double position = distance / delta_r; From e0fb5513e7ff5d6525739bc06dc66df7b572b152 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 22:16:44 +0800 Subject: [PATCH 33/47] Revert "Refactor:remove cal_tau from ElecStateLCAO (#5802)" This reverts commit 414446ac18aa79385a143f9861f10e49575937ec. --- source/module_elecstate/elecstate_lcao.cpp | 5 ++- source/module_elecstate/elecstate_lcao.h | 1 + .../elecstate_lcao_cal_tau.cpp | 31 +++++-------------- .../module_elecstate/elecstate_lcao_cal_tau.h | 21 ------------- source/module_esolver/esolver_ks_lcao.cpp | 4 +-- source/module_rdmft/update_state_rdmft.cpp | 6 ++-- 6 files changed, 16 insertions(+), 52 deletions(-) delete mode 100644 source/module_elecstate/elecstate_lcao_cal_tau.h diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index e494bae387..6cf08f12f1 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -8,7 +8,6 @@ #include "module_hamilt_lcao/module_gint/grid_technique.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_parameter/parameter.h" -#include "elecstate_lcao_cal_tau.h" #include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" @@ -68,7 +67,7 @@ void ElecStateLCAO>::psiToRho(const psi::Psicharge); + this->cal_tau(psi); } this->charge->renormalize_rho(); @@ -105,7 +104,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - elecstate::lcao_cal_tau_gamma(gint_gamma, this->charge); + this->cal_tau(psi); } this->charge->renormalize_rho(); diff --git a/source/module_elecstate/elecstate_lcao.h b/source/module_elecstate/elecstate_lcao.h index c85f6e27e5..4beeb017f0 100644 --- a/source/module_elecstate/elecstate_lcao.h +++ b/source/module_elecstate/elecstate_lcao.h @@ -46,6 +46,7 @@ class ElecStateLCAO : public ElecState // virtual void psiToRho(const psi::Psi& psi) override; // return current electronic density rho, as a input for constructing Hamiltonian // const double* getRho(int spin) const override; + virtual void cal_tau(const psi::Psi& psi) override; // update charge density for next scf step // void getNewRho() override; diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.cpp b/source/module_elecstate/elecstate_lcao_cal_tau.cpp index 32aed5e7e4..5668098478 100644 --- a/source/module_elecstate/elecstate_lcao_cal_tau.cpp +++ b/source/module_elecstate/elecstate_lcao_cal_tau.cpp @@ -1,20 +1,20 @@ #include "elecstate_lcao.h" #include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" -#include "elecstate_lcao_cal_tau.h" + #include "module_base/timer.h" namespace elecstate { // calculate the kinetic energy density tau, multi-k case -void lcao_cal_tau_k(Gint_k* gint_k, - Charge* charge) +template <> +void ElecStateLCAO>::cal_tau(const psi::Psi>& psi) { ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); for (int is = 0; is < PARAM.inp.nspin; is++) { - ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx); + ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx); } ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); @@ -23,33 +23,18 @@ void lcao_cal_tau_k(Gint_k* gint_k, } // calculate the kinetic energy density tau, gamma-only case -void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma, - Charge* charge) +template <> +void ElecStateLCAO::cal_tau(const psi::Psi& psi) { ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); for (int is = 0; is < PARAM.inp.nspin; is++) { - ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx); + ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx); } ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); return; } -template <> -void lcao_cal_tau(Gint_Gamma* gint_gamma, - Gint_k* gint_k, - Charge* charge) -{ - lcao_cal_tau_gamma(gint_gamma, charge); -} -template <> -void lcao_cal_tau>(Gint_Gamma* gint_gamma, - Gint_k* gint_k, - Charge* charge) -{ - lcao_cal_tau_k(gint_k, charge); -} - -} // namespace elecstate \ No newline at end of file +} \ No newline at end of file diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.h b/source/module_elecstate/elecstate_lcao_cal_tau.h deleted file mode 100644 index c0cfbc078a..0000000000 --- a/source/module_elecstate/elecstate_lcao_cal_tau.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ELECSTATE_LCAO_CAL_TAU_H -#define ELECSTATE_LCAO_CAL_TAU_H -#include "module_elecstate/module_charge/charge.h" -#include "module_hamilt_lcao/module_gint/gint_gamma.h" -#include "module_hamilt_lcao/module_gint/gint_k.h" -namespace elecstate -{ - - void lcao_cal_tau_k(Gint_k* gint_k, - Charge* charge); - - void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma, - Charge* charge); - - template - void lcao_cal_tau(Gint_Gamma* gint_gamma, - Gint_k* gint_k, - Charge* charge); - -} -#endif \ No newline at end of file diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 922d3e19bf..898cd55592 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -34,7 +34,6 @@ #include "module_base/global_function.h" #include "module_cell/module_neighbor/sltk_grid_driver.h" #include "module_elecstate/cal_ux.h" -#include "module_elecstate/elecstate_lcao_cal_tau.h" #include "module_elecstate/module_charge/symmetry_rho.h" #include "module_elecstate/occupy.h" #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need DeePKS_init @@ -933,7 +932,8 @@ void ESolver_KS_LCAO::after_scf(UnitCell& ucell, const int istep) // 1) calculate the kinetic energy density tau, sunliang 2024-09-18 if (PARAM.inp.out_elf[0] > 0) { - elecstate::lcao_cal_tau(&(this->GG), &(this->GK), this->pelec->charge); + assert(this->psi != nullptr); + this->pelec->cal_tau(*(this->psi)); } //! 2) call after_scf() of ESolver_KS diff --git a/source/module_rdmft/update_state_rdmft.cpp b/source/module_rdmft/update_state_rdmft.cpp index dc0398e8c9..abe56d71c3 100644 --- a/source/module_rdmft/update_state_rdmft.cpp +++ b/source/module_rdmft/update_state_rdmft.cpp @@ -8,7 +8,7 @@ #include "module_elecstate/module_dm/cal_dm_psi.h" #include "module_elecstate/module_dm/density_matrix.h" #include "module_elecstate/module_charge/symmetry_rho.h" -#include "module_elecstate/elecstate_lcao_cal_tau.h" + namespace rdmft { @@ -118,7 +118,7 @@ void RDMFT::update_charge(UnitCell& ucell) // } // Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau); // GG->cal_gint(&inout1); - elecstate::lcao_cal_tau_gamma(GG, charge); + this->pelec->cal_tau(wfc); } charge->renormalize_rho(); @@ -148,7 +148,7 @@ void RDMFT::update_charge(UnitCell& ucell) // } // Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau); // GK->cal_gint(&inout1); - elecstate::lcao_cal_tau_k(GK, charge); + this->pelec->cal_tau(wfc); } charge->renormalize_rho(); From 12edd12f09dfd224facee7d5248f15f9847ce422 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 13 Jan 2025 22:23:53 +0800 Subject: [PATCH 34/47] fix a bug --- source/module_esolver/lcao_before_scf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 8b866cfc84..1d2dc4aa92 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -131,7 +131,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) this->pw_big->nbzp, orb_.Phi, ucell, - GlobalC::GridD); + this->gd); ModuleGint::Gint::set_gint_info(gint_info); psi_u.clear(); From 5c39340675cfe918bd395856cb37abb79fa92aa0 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Thu, 16 Jan 2025 11:41:38 +0800 Subject: [PATCH 35/47] remove some rudundant functions --- .../module_gint/new_grid_tech/meshgrid_info.h | 7 +------ .../module_gint/new_grid_tech/unitcell_info.cpp | 2 ++ .../module_gint/new_grid_tech/unitcell_info.h | 6 ++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index 700ce63aa6..c01e4f0a36 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -37,14 +37,9 @@ class MeshGridInfo meshgrid_volume_ = std::abs(meshgrid_latvec0_.Det()); }; - // getter functions - const Vec3d &get_vec1() const { return meshgrid_vec1_; }; - const Vec3d &get_vec2() const { return meshgrid_vec2_; }; - const Vec3d &get_vec3() const { return meshgrid_vec3_; }; - const Matrix3 &get_latvec0() const { return meshgrid_latvec0_; }; - const Matrix3 &get_GT() const { return meshgrid_GT_; }; const double get_volume() const { return meshgrid_volume_; }; const Vec3d get_cartesian_coord(Vec3i index_3d) const { return index_3d * meshgrid_latvec0_; }; + private: // basis vectors of meshgrid Vec3d meshgrid_vec1_; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp index 6c376a2fa1..5c383bc11e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp @@ -22,6 +22,8 @@ UnitCellInfo::UnitCellInfo( unitcell_vec2_ / static_cast(nby), unitcell_vec3_ / static_cast(nbz), nmx/nbx, nmy/nby, nmz/nbz); + + meshgrid_info_ = biggrid_info_->get_meshgrid_info(); } } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index 6a4cf05b6a..b7df14c45c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -33,7 +33,7 @@ class UnitCellInfo int get_nmz() const { return nmz_; }; int get_nmxyz() const { return nmxyz_; }; std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; - std::shared_ptr get_meshgrid_info() const { return biggrid_info_->get_meshgrid_info(); }; + std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; //==================================================================== // functions related to the big grid @@ -118,7 +118,7 @@ class UnitCellInfo // get the cartesian coordinate of a meshgrid in the unit cell from the 3D index Vec3d get_meshgrid_coord(Vec3i index_3d) const { - return index_3d * biggrid_info_->get_meshgrid_info()->get_latvec0(); + return meshgrid_info_->get_cartesian_coord(index_3d); }; // get the cartesian coordinate of a meshgrid in the unit cell from the 1D index @@ -152,6 +152,8 @@ class UnitCellInfo // basic attributes of the big grid std::shared_ptr biggrid_info_; + std::shared_ptr meshgrid_info_; + //==================================================================== // member variables related to meshgrid //==================================================================== From 448106345ba27cc041a2557da41d7a3ec0fde69f Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Thu, 16 Jan 2025 15:36:32 +0800 Subject: [PATCH 36/47] simplify member function of biggrid_info --- .../new_grid_tech/biggrid_info.cpp | 17 +++++++++++++ .../module_gint/new_grid_tech/biggrid_info.h | 17 ++++++++----- .../module_gint/new_grid_tech/gint_info.cpp | 25 ++++--------------- .../module_gint/new_grid_tech/meshgrid_info.h | 5 ++-- .../module_gint/new_grid_tech/unitcell_info.h | 13 ++++------ 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index ba66b4fc1d..f66451a71a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -46,4 +46,21 @@ BigGridInfo::BigGridInfo( } } + Vec3i BigGridInfo::max_ext_bgrid_num(double r) const + { + const double g1 = sqrt(biggrid_GT_.e11 * biggrid_GT_.e11 + + biggrid_GT_.e21 * biggrid_GT_.e21 + + biggrid_GT_.e31 * biggrid_GT_.e31); + const double g2 = sqrt(biggrid_GT_.e12 * biggrid_GT_.e12 + + biggrid_GT_.e22 * biggrid_GT_.e22 + + biggrid_GT_.e32 * biggrid_GT_.e32); + const double g3 = sqrt(biggrid_GT_.e13 * biggrid_GT_.e13 + + biggrid_GT_.e23 * biggrid_GT_.e23 + + biggrid_GT_.e33 * biggrid_GT_.e33); + int ext_x = static_cast(r * g1) + 1; + int ext_y = static_cast(r * g2) + 1; + int ext_z = static_cast(r * g3) + 1; + return Vec3i(ext_x, ext_y, ext_z); + } + } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index 97154a49b4..df74f900f2 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -22,18 +22,23 @@ class BigGridInfo Vec3d biggrid_vec3, int nmx, int nmy, int nmz); - // getter functions - const Vec3d &get_vec1() const { return biggrid_vec1_; }; - const Vec3d &get_vec2() const { return biggrid_vec2_; }; - const Vec3d &get_vec3() const { return biggrid_vec3_; }; - const Matrix3 &get_latvec0() const { return biggrid_latvec0_; }; - const Matrix3 &get_GT() const { return biggrid_GT_; }; + Vec3d get_cartesian_coord(const Vec3d& index_3d) const { return index_3d * biggrid_latvec0_; }; + Vec3d get_cartesian_coord(const Vec3i& index_3d) const { return index_3d * biggrid_latvec0_; }; + const Vec3d get_direct_coord(const Vec3d& cart_coord) const { return cart_coord * biggrid_GT_; }; + + // Return the maximum number of big grids that can fit inside a sphere of radius r, + // along the three lattice vector directions. + Vec3i max_ext_bgrid_num(double r) const; + + // get number of meshgrids along three lattice directions int get_nmx() const { return nmx_; }; int get_nmy() const { return nmy_; }; int get_nmz() const { return nmz_; }; int get_nmxyz() const { return nmxyz_; }; + const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; const Vec3d& get_meshgrid_coord(int index_1d) const { return meshgrid_coords_[index_1d]; }; + std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; // get the 3D index of a meshgrid in the big grid from the 1D index diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index b5ba0d6362..45fd6b2a97 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -62,17 +62,6 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital { ModuleBase::timer::tick("GintInfo", "init_atoms"); int iat = 0; - const Matrix3& biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT(); - const double g1 = sqrt(biggrid_GT.e11 * biggrid_GT.e11 - + biggrid_GT.e21 * biggrid_GT.e21 - + biggrid_GT.e31 * biggrid_GT.e31); - const double g2 = sqrt(biggrid_GT.e12 * biggrid_GT.e12 - + biggrid_GT.e22 * biggrid_GT.e22 - + biggrid_GT.e32 * biggrid_GT.e32); - const double g3 = sqrt(biggrid_GT.e13 * biggrid_GT.e13 - + biggrid_GT.e23 * biggrid_GT.e23 - + biggrid_GT.e33 * biggrid_GT.e33); - is_atom_in_proc_.resize(ucell_->nat, false); atoms_.resize(ucell_->nat); @@ -83,9 +72,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital const auto *orb = &Phi[i]; // rcut extends to the maximum big grids in x, y, z directions - int ext_bgrid_x = static_cast(atom.Rcut * g1) + 1; - int ext_bgrid_y = static_cast(atom.Rcut * g2) + 1; - int ext_bgrid_z = static_cast(atom.Rcut * g3) + 1; + Vec3i ext_bgrid = biggrid_info_->max_ext_bgrid_num(atom.Rcut); for(int j = 0; j < atom.na; j++) { @@ -99,18 +86,16 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital const Vec3d delta(fraction.x - atom_bgrid_idx.x, fraction.y - atom_bgrid_idx.y, fraction.z - atom_bgrid_idx.z); - const Vec3d tau_in_biggrid = delta.x * unitcell_info_->get_biggrid_info()->get_vec1() + - delta.y * unitcell_info_->get_biggrid_info()->get_vec2() + - delta.z * unitcell_info_->get_biggrid_info()->get_vec3(); + const Vec3d tau_in_biggrid = biggrid_info_->get_cartesian_coord(delta); const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx); auto& r_to_atom = atoms_[iat]; - for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++) + for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid.x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid.x; bgrid_x++) { - for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid_y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid_y; bgrid_y++) + for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid.y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid.y; bgrid_y++) { - for(int bgrid_z = atom_bgrid_idx.z - ext_bgrid_z; bgrid_z <= atom_bgrid_idx.z + ext_bgrid_z; bgrid_z++) + for(int bgrid_z = atom_bgrid_idx.z - ext_bgrid.z; bgrid_z <= atom_bgrid_idx.z + ext_bgrid.z; bgrid_z++) { // get the extended biggrid idx of the affected biggrid const Vec3i ext_bgrid_idx(bgrid_x, bgrid_y, bgrid_z); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h index c01e4f0a36..581c9944f7 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h @@ -37,8 +37,9 @@ class MeshGridInfo meshgrid_volume_ = std::abs(meshgrid_latvec0_.Det()); }; - const double get_volume() const { return meshgrid_volume_; }; - const Vec3d get_cartesian_coord(Vec3i index_3d) const { return index_3d * meshgrid_latvec0_; }; + double get_volume() const { return meshgrid_volume_; }; + Vec3d get_cartesian_coord(const Vec3i& index_3d) const { return index_3d * meshgrid_latvec0_; }; + Vec3d get_direct_coord(const Vec3d& cart_coord) const { return cart_coord * meshgrid_GT_; } private: // basis vectors of meshgrid diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index b7df14c45c..6e8fe79000 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -21,9 +21,6 @@ class UnitCellInfo int nmx, int nmy, int nmz); // getter functions - const Vec3d &get_vec1() const { return unitcell_vec1_; }; - const Vec3d &get_vec2() const { return unitcell_vec2_; }; - const Vec3d &get_vec3() const { return unitcell_vec3_; }; int get_nbx() const { return nbx_; }; int get_nby() const { return nby_; }; int get_nbz() const { return nbz_; }; @@ -54,7 +51,7 @@ class UnitCellInfo // get the cartesian coordinate of a big grid in the unit cell from the 3D index Vec3d get_biggrid_coord(Vec3i index_3d) const { - return index_3d * biggrid_info_->get_latvec0(); + return biggrid_info_->get_cartesian_coord(index_3d); }; // get the cartesian coordinate of a big grid in the unit cell from the 1D index @@ -66,11 +63,11 @@ class UnitCellInfo // get the 3D index of a big grid in the unit cell from the cartesian coordinate Vec3i get_biggrid_idx_3d(const Vec3d coord) const { - Vec3d biggrid_idx_double = coord * biggrid_info_->get_GT(); + Vec3d direct_coord = biggrid_info_->get_direct_coord(coord); return Vec3i( - static_cast(floor(biggrid_idx_double.x)), - static_cast(floor(biggrid_idx_double.y)), - static_cast(floor(biggrid_idx_double.z))); + static_cast(floor(direct_coord.x)), + static_cast(floor(direct_coord.y)), + static_cast(floor(direct_coord.z))); }; // Get the relative Cartesian coordinates of big grid A relative to big grid B From b6c17ce65688c0287d25aae88ca3e5d9963d7988 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Thu, 16 Jan 2025 15:53:27 +0800 Subject: [PATCH 37/47] rename some variables --- .../module_gint/new_grid_tech/biggrid.cpp | 12 ++++++------ .../module_gint/new_grid_tech/biggrid.h | 2 +- .../module_gint/new_grid_tech/biggrid_info.cpp | 2 +- .../module_gint/new_grid_tech/biggrid_info.h | 12 ++++++------ .../module_gint/new_grid_tech/gint_info.cpp | 2 +- .../module_gint/new_grid_tech/unitcell_info.cpp | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index e7a857f4a1..b7156e4c05 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -44,11 +44,11 @@ void BigGrid::set_atoms_phi_len(std::vector& phi_len) const void BigGrid::set_mgrids_coord(std::vector& coord) const { - coord.resize(biggrid_info_->get_nmxyz()); + coord.resize(biggrid_info_->get_mgrids_num()); Vec3d this_bgrid_coord = localcell_info_->get_bgrid_global_coord_3D(idx_); - for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) + for(int im = 0; im < biggrid_info_->get_mgrids_num(); ++im) { - coord[im] = biggrid_info_->get_meshgrid_coord(im) + this_bgrid_coord; + coord[im] = biggrid_info_->get_mgrid_coord(im) + this_bgrid_coord; } } @@ -81,10 +81,10 @@ void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in Vec3d bgrid_relative_coord = unitcell_info_->get_relative_coord(bgrid_idx, this_bgrid_idx) + tau_in_bgrid; - atom_coord.resize(biggrid_info_->get_nmxyz()); - for(int im = 0; im < biggrid_info_->get_nmxyz(); ++im) + atom_coord.resize(biggrid_info_->get_mgrids_num()); + for(int im = 0; im < biggrid_info_->get_mgrids_num(); ++im) { - const Vec3d& mcell_coord = biggrid_info_->get_meshgrid_coord(im); + const Vec3d& mcell_coord = biggrid_info_->get_mgrid_coord(im); atom_coord[im] = mcell_coord - bgrid_relative_coord; } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index 86fcff5101..7103b51fa2 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -26,7 +26,7 @@ class BigGrid const GintAtom* get_atom(int i) const { return atoms_[i]; }; // get the number of meshgrids in the big grid - int get_meshgrid_num() const { return biggrid_info_->get_nmxyz(); }; + int get_meshgrid_num() const { return biggrid_info_->get_mgrids_num(); }; // get the number of atoms that can affect the big grid int get_atom_num() const { return atoms_.size(); }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp index f66451a71a..f69a7ef0ec 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp @@ -42,7 +42,7 @@ BigGridInfo::BigGridInfo( for(int index_1d = 0; index_1d < nmxyz_; index_1d++) { meshgrid_coords_[index_1d] = - meshgrid_info_->get_cartesian_coord(meshgrid_idx_1Dto3D(index_1d)); + meshgrid_info_->get_cartesian_coord(mgrid_idx_1Dto3D(index_1d)); } } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h index df74f900f2..f8bcb79665 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h @@ -34,21 +34,21 @@ class BigGridInfo int get_nmx() const { return nmx_; }; int get_nmy() const { return nmy_; }; int get_nmz() const { return nmz_; }; - int get_nmxyz() const { return nmxyz_; }; + int get_mgrids_num() const { return nmxyz_; }; - const std::vector& get_meshgrid_coords() const { return meshgrid_coords_; }; - const Vec3d& get_meshgrid_coord(int index_1d) const { return meshgrid_coords_[index_1d]; }; + const std::vector& get_mgrids_coord() const { return meshgrid_coords_; }; + const Vec3d& get_mgrid_coord(int index_1d) const { return meshgrid_coords_[index_1d]; }; - std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; + std::shared_ptr get_mgrid_info() const { return meshgrid_info_; }; // get the 3D index of a meshgrid in the big grid from the 1D index - Vec3i meshgrid_idx_1Dto3D(int index_1d) const + Vec3i mgrid_idx_1Dto3D(int index_1d) const { return index1Dto3D(index_1d, nmx_, nmy_, nmz_); }; // get the 1D index of a meshgrid in the big grid from the 3D index - int meshgrid_idx_3Dto1D(const Vec3i index_3d) const + int mgrid_idx_3Dto1D(const Vec3i index_3d) const { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 45fd6b2a97..4dde511773 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -22,7 +22,7 @@ GintInfo::GintInfo( nbx, nby, nbz, nmx, nmy, nmz); biggrid_info_ = unitcell_info_->get_biggrid_info(); - meshgrid_info_ = biggrid_info_->get_meshgrid_info(); + meshgrid_info_ = biggrid_info_->get_mgrid_info(); // initialize the divide information divide_info_ = std::make_shared(startidx_bx, startidx_by, startidx_bz, diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp index 5c383bc11e..7818b3b08a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp @@ -23,7 +23,7 @@ UnitCellInfo::UnitCellInfo( unitcell_vec3_ / static_cast(nbz), nmx/nbx, nmy/nby, nmz/nbz); - meshgrid_info_ = biggrid_info_->get_meshgrid_info(); + meshgrid_info_ = biggrid_info_->get_mgrid_info(); } } \ No newline at end of file From 56cb9bbadfb6a709027fc9793ff51c0624525335 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Thu, 16 Jan 2025 16:10:46 +0800 Subject: [PATCH 38/47] unify some variables name --- .../module_gint/new_grid_tech/biggrid.cpp | 6 ++-- .../module_gint/new_grid_tech/biggrid.h | 12 ++++--- .../module_gint/new_grid_tech/gint_atom.h | 4 +-- .../module_gint/new_grid_tech/gint_info.cpp | 8 +++-- .../module_gint/new_grid_tech/gint_info.h | 2 +- .../new_grid_tech/localcell_info.cpp | 28 +++++++-------- .../new_grid_tech/localcell_info.h | 14 ++++---- .../new_grid_tech/phi_operator.cpp | 34 +++++++++---------- .../module_gint/new_grid_tech/phi_operator.h | 4 +-- .../module_gint/new_grid_tech/unitcell_info.h | 32 ++++++++--------- 10 files changed, 76 insertions(+), 68 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index b7156e4c05..82ed409391 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -54,7 +54,7 @@ void BigGrid::set_mgrids_coord(std::vector& coord) const void BigGrid::set_mgrids_local_idx(std::vector& mgrids_idx) const { - auto index_3d = localcell_info_->biggrid_idx_1Dto3D(idx_); + auto index_3d = localcell_info_->bgrid_idx_1Dto3D(idx_); Vec3i startidx( index_3d.x * biggrid_info_->get_nmx(), index_3d.y * biggrid_info_->get_nmy(), @@ -67,7 +67,7 @@ void BigGrid::set_mgrids_local_idx(std::vector& mgrids_idx) const for(int iz = 0; iz < biggrid_info_->get_nmz(); ++iz) { Vec3i idx_3d(startidx.x + ix, startidx.y + iy, startidx.z + iz); - mgrids_idx.push_back(localcell_info_->meshgrid_idx_3Dto1D(idx_3d)); + mgrids_idx.push_back(localcell_info_->mgrid_idx_3Dto1D(idx_3d)); } } } @@ -92,7 +92,7 @@ void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in void BigGrid::set_atom_relative_coords(const GintAtom* atom, std::vector& atom_coord) const { - return set_atom_relative_coords(atom->get_biggrid_idx(), atom->get_tau_in_biggrid(), atom_coord); + return set_atom_relative_coords(atom->get_bgrid_idx(), atom->get_tau_in_bgrid(), atom_coord); } bool BigGrid::is_atom_on_bgrid(const GintAtom* atom) const diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index 7103b51fa2..b1a0ab045a 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -15,21 +15,25 @@ class BigGrid { public: // constructor - BigGrid(int idx, std::shared_ptr localcell_info); + BigGrid(int idx); + + static void init_localcell_info(std::shared_ptr localcell_info) { localcell_info_ = localcell_info; }; + static void init_unitcell_info(std::shared_ptr unitcell_info) { unitcell_info_ = unitcell_info; }; + static void init_bgrid_info(std::shared_ptr biggrid_info) { biggrid_info_ = biggrid_info; }; // getter functions int get_idx() const { return idx_; }; std::shared_ptr get_localcell_info() const { return localcell_info_; }; std::shared_ptr get_unitcell_info() const {return unitcell_info_; }; - std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; + std::shared_ptr get_bgrid_info() const { return biggrid_info_; }; const std::vector& get_atoms() const { return atoms_; }; const GintAtom* get_atom(int i) const { return atoms_[i]; }; // get the number of meshgrids in the big grid - int get_meshgrid_num() const { return biggrid_info_->get_mgrids_num(); }; + int get_mgrids_num() const { return biggrid_info_->get_mgrids_num(); }; // get the number of atoms that can affect the big grid - int get_atom_num() const { return atoms_.size(); }; + int get_atoms_num() const { return atoms_.size(); }; // add an atom to the big grid void add_atom(const GintAtom* atom); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h index 6a257c5bd5..660aa0ceab 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h @@ -27,10 +27,10 @@ class GintAtom const Atom* get_atom() const { return atom_; }; const int get_ia() const { return ia_; }; const int get_iat() const { return iat_; }; - const Vec3i& get_biggrid_idx() const { return biggrid_idx_; }; + const Vec3i& get_bgrid_idx() const { return biggrid_idx_; }; const Vec3i& get_unitcell_idx() const { return unitcell_idx_; }; const Vec3i& get_R() const { return unitcell_idx_; }; - const Vec3d& get_tau_in_biggrid() const { return tau_in_biggrid_; }; + const Vec3d& get_tau_in_bgrid() const { return tau_in_biggrid_; }; const Numerical_Orbital* get_orb() const { return orb_; }; const int get_nw() const { return atom_->nw; }; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index 4dde511773..f5907ed5d6 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -21,7 +21,7 @@ GintInfo::GintInfo( unitcell_info_ = std::make_shared(ucell_->a1 * ucell_->lat0, ucell_->a2 * ucell_->lat0, ucell_->a3 * ucell_->lat0, nbx, nby, nbz, nmx, nmy, nmz); - biggrid_info_ = unitcell_info_->get_biggrid_info(); + biggrid_info_ = unitcell_info_->get_bgrid_info(); meshgrid_info_ = biggrid_info_->get_mgrid_info(); // initialize the divide information @@ -32,7 +32,11 @@ GintInfo::GintInfo( localcell_info_ = divide_info_->get_localcell_info(); // initialize the biggrids - for (int i = 0; i < localcell_info_->get_biggrid_num(); i++) + BigGrid::init_localcell_info(localcell_info_); + BigGrid::init_unitcell_info(unitcell_info_); + BigGrid::init_bgrid_info(biggrid_info_); + + for (int i = 0; i < localcell_info_->get_bgrids_num(); i++) { biggrids_.push_back(std::make_shared(i, localcell_info_)); } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h index 87a2e97543..00e6f85e2f 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h @@ -30,7 +30,7 @@ class GintInfo // getter functions std::vector> get_biggrids() const { return biggrids_; }; - double get_local_mgrid_num() const { return localcell_info_->get_mgrid_num(); }; + double get_local_mgrid_num() const { return localcell_info_->get_mgrids_num(); }; double get_mgrid_volume() const { return meshgrid_info_->get_volume(); }; //========================================= diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp index 598a371928..da9b5ec3a3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp @@ -8,7 +8,7 @@ namespace ModuleGint std::shared_ptr unitcell_info) : startidx_bx_(startidx_bx), startidx_by_(startidx_by), startidx_bz_(startidx_bz), nbx_(nbx), nby_(nby), nbz_(nbz), nbxyz_(nbx*nby*nbz), - unitcell_info_(unitcell_info), biggrid_info_(unitcell_info->get_biggrid_info()) + unitcell_info_(unitcell_info), biggrid_info_(unitcell_info->get_bgrid_info()) { startidx_mx_ = startidx_bx_ * biggrid_info_->get_nmx(); startidx_my_ = startidx_by_ * biggrid_info_->get_nmy(); @@ -23,12 +23,12 @@ namespace ModuleGint // functions related to the big grid //==================================================================== - int LocalCellInfo::biggrid_idx_3Dto1D(const Vec3i index_3d) const + int LocalCellInfo::bgrid_idx_3Dto1D(const Vec3i index_3d) const { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); } - Vec3i LocalCellInfo::biggrid_idx_1Dto3D(const int index_1d) const + Vec3i LocalCellInfo::bgrid_idx_1Dto3D(const int index_1d) const { return index1Dto3D(index_1d, nbx_, nby_, nbz_); } @@ -43,13 +43,13 @@ namespace ModuleGint Vec3i LocalCellInfo::get_bgrid_global_idx_3D(const int index_1d) const { - return get_bgrid_global_idx_3D(biggrid_idx_1Dto3D(index_1d)); + return get_bgrid_global_idx_3D(bgrid_idx_1Dto3D(index_1d)); } int LocalCellInfo::get_bgrid_global_idx_1D(const int index_1d) const { - Vec3i ucell_idx_3d = get_bgrid_global_idx_3D(biggrid_idx_1Dto3D(index_1d)); - return unitcell_info_->biggrid_idx_3Dto1D(ucell_idx_3d); + Vec3i ucell_idx_3d = get_bgrid_global_idx_3D(bgrid_idx_1Dto3D(index_1d)); + return unitcell_info_->bgrid_idx_3Dto1D(ucell_idx_3d); } @@ -66,19 +66,19 @@ namespace ModuleGint int LocalCellInfo::get_bgrid_local_idx_1D(const Vec3i index_3d) const { - return biggrid_idx_3Dto1D(get_bgrid_local_idx_3D(index_3d)); + return bgrid_idx_3Dto1D(get_bgrid_local_idx_3D(index_3d)); } int LocalCellInfo::get_bgrid_local_idx_1D(const int index_1d) const { - Vec3i idx_3d = unitcell_info_->biggrid_idx_1Dto3D(index_1d); - return biggrid_idx_3Dto1D(get_bgrid_local_idx_3D(idx_3d)); + Vec3i idx_3d = unitcell_info_->bgrid_idx_1Dto3D(index_1d); + return bgrid_idx_3Dto1D(get_bgrid_local_idx_3D(idx_3d)); } Vec3d LocalCellInfo::get_bgrid_global_coord_3D(const int index_1d) const { Vec3i ucell_idx_3d = get_bgrid_global_idx_3D(index_1d); - return unitcell_info_->get_biggrid_coord(ucell_idx_3d); + return unitcell_info_->get_bgrid_coord(ucell_idx_3d); } bool LocalCellInfo::is_bgrid_in_lcell(const Vec3i index_3d) const @@ -92,12 +92,12 @@ namespace ModuleGint // functions related to the meshgrid //==================================================================== - int LocalCellInfo::meshgrid_idx_3Dto1D(const Vec3i index_3d) const + int LocalCellInfo::mgrid_idx_3Dto1D(const Vec3i index_3d) const { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } - Vec3i LocalCellInfo::meshgrid_idx_1Dto3D(const int index_1d) const + Vec3i LocalCellInfo::mgrid_idx_1Dto3D(const int index_1d) const { return index1Dto3D(index_1d, nmx_, nmy_, nmz_); } @@ -112,8 +112,8 @@ namespace ModuleGint int LocalCellInfo::get_mgrid_global_idx_1D(const int index_1d) const { - Vec3i ucell_idx_3d = get_mgrid_global_idx_3D(meshgrid_idx_1Dto3D(index_1d)); - return unitcell_info_->meshgrid_idx_3Dto1D(ucell_idx_3d); + Vec3i ucell_idx_3d = get_mgrid_global_idx_3D(mgrid_idx_1Dto3D(index_1d)); + return unitcell_info_->mgrid_idx_3Dto1D(ucell_idx_3d); } } \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h index 25125a54b0..a39042e558 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h @@ -23,20 +23,20 @@ class LocalCellInfo const int get_nbx() const { return nbx_; }; const int get_nby() const { return nby_; }; const int get_nbz() const { return nbz_; }; - const int get_biggrid_num() const { return nbxyz_; }; - const int get_mgrid_num() const { return nmxyz_; }; + const int get_bgrids_num() const { return nbxyz_; }; + const int get_mgrids_num() const { return nmxyz_; }; std::shared_ptr get_unitcell_info() const { return unitcell_info_; }; - std::shared_ptr get_biggrid_info() const { return unitcell_info_->get_biggrid_info(); }; + std::shared_ptr get_bgrid_info() const { return unitcell_info_->get_bgrid_info(); }; //==================================================================== // functions related to the big grid //==================================================================== // transform the 3D index of a big grid in the local cell to the 3D index in the local cell - int biggrid_idx_3Dto1D(const Vec3i index_3d) const; + int bgrid_idx_3Dto1D(const Vec3i index_3d) const; // transform the 1D index of a big grid in the local cell to the 1D index in the local cell - Vec3i biggrid_idx_1Dto3D(const int index_1d) const; + Vec3i bgrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a big grid in the local cell to the 3D index in the unit cell Vec3i get_bgrid_global_idx_3D(const Vec3i index_3d) const; @@ -69,10 +69,10 @@ class LocalCellInfo //==================================================================== // transform the 3D index of a meshgrid in the local cell to the 3D index in the local cell - int meshgrid_idx_3Dto1D(const Vec3i index_3d) const; + int mgrid_idx_3Dto1D(const Vec3i index_3d) const; // transform the 1D index of a meshgrid in the local cell to the 1D index in the local cell - Vec3i meshgrid_idx_1Dto3D(const int index_1d) const; + Vec3i mgrid_idx_1Dto3D(const int index_1d) const; // transform the 3D index of a meshgrid in the local cell to the 3D index in the unit cell Vec3i get_mgrid_global_idx_3D(const Vec3i index_3d) const; diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index f933a96cdf..fc99ffc155 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -9,7 +9,7 @@ namespace ModuleGint void PhiOperator::set_bgrid(std::shared_ptr biggrid) { biggrid_ = biggrid; - rows_ = biggrid_->get_meshgrid_num(); + rows_ = biggrid_->get_mgrids_num(); cols_ = biggrid_->get_mgrid_phi_len(); biggrid_->set_atoms_startidx(atoms_startidx_); @@ -17,7 +17,7 @@ void PhiOperator::set_bgrid(std::shared_ptr biggrid) biggrid_->set_mgrids_local_idx(meshgrids_local_idx_); // init is_atom_on_mgrid_ and atoms_relative_coords_ - int atoms_num = biggrid_->get_atom_num(); + int atoms_num = biggrid_->get_atoms_num(); atoms_relative_coords_.resize(atoms_num); is_atom_on_mgrid_.resize(atoms_num); for(int i = 0; i < atoms_num; ++i) @@ -36,7 +36,7 @@ void PhiOperator::set_bgrid(std::shared_ptr biggrid) void PhiOperator::set_phi(double* phi) const { - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const auto atom = biggrid_->get_atom(i); atom->set_phi(atoms_relative_coords_[i], cols_, phi); @@ -46,7 +46,7 @@ void PhiOperator::set_phi(double* phi) const void PhiOperator::set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const { - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const auto atom = biggrid_->get_atom(i); atom->set_phi_dphi(atoms_relative_coords_[i], cols_, phi, dphi_x, dphi_y, dphi_z); @@ -64,7 +64,7 @@ void PhiOperator::set_ddphi( double* ddphi_xx, double* ddphi_xy, double* ddphi_xz, double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const { - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const auto atom = biggrid_->get_atom(i); atom->set_ddphi(atoms_relative_coords_[i], cols_, ddphi_xx, ddphi_xy, ddphi_xz, ddphi_yy, ddphi_yz, ddphi_zz); @@ -91,7 +91,7 @@ void PhiOperator::phi_mul_dm( const double beta = 1.0; const double alpha1 = is_symm ? 2.0 : 1.0; - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const auto atom_i = biggrid_->get_atom(i); const auto r_i = atom_i->get_R(); @@ -105,7 +105,7 @@ void PhiOperator::phi_mul_dm( const int start = is_symm ? i + 1 : 0; - for(int j = start; j < biggrid_->get_atom_num(); ++j) + for(int j = start; j < biggrid_->get_atoms_num(); ++j) { const auto atom_j = biggrid_->get_atom(j); const auto r_j = atom_j->get_R(); @@ -138,7 +138,7 @@ void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double { ModuleBase::GlobalFunc::ZEROS(result, rows_ * cols_); int idx = 0; - for(int i = 0; i < biggrid_->get_meshgrid_num(); i++) + for(int i = 0; i < biggrid_->get_mgrids_num(); i++) { double vldr3_mgrid = vl[meshgrids_local_idx_[i]] * dr3; for(int j = 0; j < cols_; j++) @@ -157,13 +157,13 @@ void PhiOperator::phi_mul_phi_vldr3( const char transa='N', transb='T'; const double alpha=1, beta=1; - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const auto atom_i = biggrid_->get_atom(i); const auto& r_i = atom_i->get_R(); const int iat_i = atom_i->get_iat(); - for(int j = 0; j < biggrid_->get_atom_num(); ++j) + for(int j = 0; j < biggrid_->get_atoms_num(); ++j) { const auto atom_j = biggrid_->get_atom(j); const auto& r_j = atom_j->get_R(); @@ -204,7 +204,7 @@ void PhiOperator::phi_dot_phi_dm( double* rho) const { const int inc = 1; - for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + for(int i = 0; i < biggrid_->get_mgrids_num(); ++i) { rho[meshgrids_local_idx_[i]] += ddot_(&cols_, &phi[i * cols_], &inc, &phi_dm[i * cols_], &inc); } @@ -217,13 +217,13 @@ void PhiOperator::phi_dot_dphi( const double* dphi_z, ModuleBase::matrix *fvl) const { - for(int i = 0; i < biggrid_->get_atom_num(); ++i) + for(int i = 0; i < biggrid_->get_atoms_num(); ++i) { const int iat = biggrid_->get_atom(i)->get_iat(); const int start_idx = atoms_startidx_[i]; const int phi_len = atoms_phi_len_[i]; double rx = 0, ry = 0, rz = 0; - for(int j = 0; j < biggrid_->get_meshgrid_num(); ++j) + for(int j = 0; j < biggrid_->get_mgrids_num(); ++j) { for(int k = 0; k < phi_len; ++k) { @@ -248,9 +248,9 @@ void PhiOperator::phi_dot_dphi_r( ModuleBase::matrix *svl) const { double sxx = 0, sxy = 0, sxz = 0, syy = 0, syz = 0, szz = 0; - for(int i = 0; i < biggrid_->get_meshgrid_num(); ++i) + for(int i = 0; i < biggrid_->get_mgrids_num(); ++i) { - for(int j = 0; j < biggrid_->get_atom_num(); ++j) + for(int j = 0; j < biggrid_->get_atoms_num(); ++j) { const int start_idx = atoms_startidx_[j]; for(int k = 0; k < atoms_phi_len_[j]; ++k) @@ -281,9 +281,9 @@ void PhiOperator::phi_dot_dphi_r( //=============================== void PhiOperator::init_atom_pair_start_end_idx_() { - int atoms_num = biggrid_->get_atom_num(); + int atoms_num = biggrid_->get_atoms_num(); atom_pair_start_end_idx_.resize(atoms_num * (atoms_num + 1) / 2); - int mgrids_num = biggrid_->get_meshgrid_num(); + int mgrids_num = biggrid_->get_mgrids_num(); int atom_pair_idx = 0; for(int i = 0; i < atoms_num; ++i) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h index 25c4f291ef..ebe3bf1fb3 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h @@ -88,11 +88,11 @@ class PhiOperator { int x = std::min(a, b); int y = std::abs(a - b); - return atom_pair_start_end_idx_[(2 * biggrid_->get_atom_num() - x + 1) * x / 2 + y]; + return atom_pair_start_end_idx_[(2 * biggrid_->get_atoms_num() - x + 1) * x / 2 + y]; }; // the row number of the phi matrix - // rows_ = biggrid_->get_meshgrid_num() + // rows_ = biggrid_->get_mgrids_num() int rows_; // the column number of the phi matrix diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h index 6e8fe79000..868f51d830 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h @@ -24,44 +24,44 @@ class UnitCellInfo int get_nbx() const { return nbx_; }; int get_nby() const { return nby_; }; int get_nbz() const { return nbz_; }; - int get_nbxyz() const { return nbxyz_; }; + int get_bgrids_num() const { return nbxyz_; }; int get_nmx() const { return nmx_; }; int get_nmy() const { return nmy_; }; int get_nmz() const { return nmz_; }; - int get_nmxyz() const { return nmxyz_; }; - std::shared_ptr get_biggrid_info() const { return biggrid_info_; }; - std::shared_ptr get_meshgrid_info() const { return meshgrid_info_; }; + int get_mgrids_num() const { return nmxyz_; }; + std::shared_ptr get_bgrid_info() const { return biggrid_info_; }; + std::shared_ptr get_mgrid_info() const { return meshgrid_info_; }; //==================================================================== // functions related to the big grid //==================================================================== // transform the 1D index of a big grid in the unit cell to the 3D index - Vec3i biggrid_idx_1Dto3D(const int index_1d) const + Vec3i bgrid_idx_1Dto3D(const int index_1d) const { return index1Dto3D(index_1d, nbx_, nby_, nbz_); }; // transform the 3D index of a biggrid in the unit cell to the 1D index - int biggrid_idx_3Dto1D(const Vec3i index_3d) const + int bgrid_idx_3Dto1D(const Vec3i index_3d) const { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nbx_, nby_, nbz_); }; // get the cartesian coordinate of a big grid in the unit cell from the 3D index - Vec3d get_biggrid_coord(Vec3i index_3d) const + Vec3d get_bgrid_coord(Vec3i index_3d) const { return biggrid_info_->get_cartesian_coord(index_3d); }; // get the cartesian coordinate of a big grid in the unit cell from the 1D index - Vec3d get_biggrid_coord(int index_1d) const + Vec3d get_bgrid_coord(int index_1d) const { - return get_biggrid_coord(biggrid_idx_1Dto3D(index_1d)); + return get_bgrid_coord(bgrid_idx_1Dto3D(index_1d)); }; // get the 3D index of a big grid in the unit cell from the cartesian coordinate - Vec3i get_biggrid_idx_3d(const Vec3d coord) const + Vec3i get_bgrid_idx_3d(const Vec3d coord) const { Vec3d direct_coord = biggrid_info_->get_direct_coord(coord); return Vec3i( @@ -76,7 +76,7 @@ class UnitCellInfo // through two 3D indices and then subtracting them Vec3d get_relative_coord(Vec3i index_3d_a, Vec3i index_3d_b) const { - return get_biggrid_coord(index_3d_a - index_3d_b); + return get_bgrid_coord(index_3d_a - index_3d_b); }; // get the extended unitcell index of a big grid @@ -101,27 +101,27 @@ class UnitCellInfo //==================================================================== // transform the 1D index of a meshgrid in the unit cell to the 3D index - Vec3i meshgrid_idx_1Dto3D(const int index_1d) const + Vec3i mgrid_idx_1Dto3D(const int index_1d) const { return index1Dto3D(index_1d, nmx_, nmy_, nmz_); } // transform the 3D index of a meshgrid in the unit cell to the 1D index - int meshgrid_idx_3Dto1D(const Vec3i index_3d) const + int mgrid_idx_3Dto1D(const Vec3i index_3d) const { return index3Dto1D(index_3d.x, index_3d.y, index_3d.z, nmx_, nmy_, nmz_); } // get the cartesian coordinate of a meshgrid in the unit cell from the 3D index - Vec3d get_meshgrid_coord(Vec3i index_3d) const + Vec3d get_mgrid_coord(Vec3i index_3d) const { return meshgrid_info_->get_cartesian_coord(index_3d); }; // get the cartesian coordinate of a meshgrid in the unit cell from the 1D index - Vec3d get_meshgrid_coord(int index_1d) const + Vec3d get_mgrid_coord(int index_1d) const { - return get_meshgrid_coord(meshgrid_idx_1Dto3D(index_1d)); + return get_mgrid_coord(mgrid_idx_1Dto3D(index_1d)); } private: From 6c488db7208df4ebb11e3945969c25b77ec799c2 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Tue, 14 Jan 2025 22:54:08 +0800 Subject: [PATCH 39/47] change some variable to static --- source/module_esolver/lcao_before_scf.cpp | 2 +- .../module_gint/new_grid_tech/biggrid.cpp | 8 ++++---- .../module_gint/new_grid_tech/biggrid.h | 6 +++--- .../module_hamilt_lcao/module_gint/new_grid_tech/gint.h | 2 +- .../module_gint/new_grid_tech/gint_info.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 1d2dc4aa92..a48c22b52f 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -132,7 +132,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) orb_.Phi, ucell, this->gd); - ModuleGint::Gint::set_gint_info(gint_info); + ModuleGint::Gint::init_gint_info(gint_info); psi_u.clear(); psi_u.shrink_to_fit(); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp index 82ed409391..014561f5bd 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp @@ -2,11 +2,11 @@ namespace ModuleGint { +std::shared_ptr BigGrid::localcell_info_ = nullptr; +std::shared_ptr BigGrid::unitcell_info_ = nullptr; +std::shared_ptr BigGrid::biggrid_info_ = nullptr; -BigGrid::BigGrid(int idx, std::shared_ptr localcell_info) - : idx_(idx), localcell_info_(localcell_info), - unitcell_info_(localcell_info->get_unitcell_info()), - biggrid_info_(localcell_info_->get_biggrid_info()) {} +BigGrid::BigGrid(int idx): idx_(idx){} void BigGrid::add_atom(const GintAtom* atom) { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h index b1a0ab045a..c1d5596e13 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h @@ -80,13 +80,13 @@ class BigGrid const int idx_; // local cell info - std::shared_ptr localcell_info_; + static std::shared_ptr localcell_info_; // unitcell info - std::shared_ptr unitcell_info_; + static std::shared_ptr unitcell_info_; // the big grid info - std::shared_ptr biggrid_info_; + static std::shared_ptr biggrid_info_; }; } // namespace ModuleGint \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h index 2d8a1c1cba..a14f014a6c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h @@ -16,7 +16,7 @@ class Gint // note that gint_info_ is a static member variable // it is shared by all instances of Gint - static void set_gint_info(std::shared_ptr gint_info) + static void init_gint_info(std::shared_ptr gint_info) { gint_info_ = gint_info; } diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp index f5907ed5d6..1443ad05e9 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp @@ -38,7 +38,7 @@ GintInfo::GintInfo( for (int i = 0; i < localcell_info_->get_bgrids_num(); i++) { - biggrids_.push_back(std::make_shared(i, localcell_info_)); + biggrids_.push_back(std::make_shared(i)); } // initialize the atoms From d11d4c76b9922abcbac5b8cf8d5508ed39ea3305 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sat, 18 Jan 2025 18:11:48 +0800 Subject: [PATCH 40/47] fix a bug and delete a redundant operation --- .../module_gint/new_grid_tech/gint_atom.cpp | 4 ++++ .../module_gint/new_grid_tech/phi_operator.cpp | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp index 0f791e58e9..2c8252092e 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp @@ -125,6 +125,10 @@ void GintAtom::set_phi_dphi( { // if the distance is larger than the cutoff radius, // the wave function values are all zeros + if(phi != nullptr) + { + ModuleBase::GlobalFunc::ZEROS(phi + im * stride, atom_->nw); + } ModuleBase::GlobalFunc::ZEROS(dphi_x + im * stride, atom_->nw); ModuleBase::GlobalFunc::ZEROS(dphi_y + im * stride, atom_->nw); ModuleBase::GlobalFunc::ZEROS(dphi_z + im * stride, atom_->nw); diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp index fc99ffc155..6e33e3a903 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp +++ b/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp @@ -136,7 +136,6 @@ void PhiOperator::phi_mul_dm( void PhiOperator::phi_mul_vldr3(const double* vl, const double dr3, const double* phi, double* result) const { - ModuleBase::GlobalFunc::ZEROS(result, rows_ * cols_); int idx = 0; for(int i = 0; i < biggrid_->get_mgrids_num(); i++) { From c9b37f21ed07bb620db7a25004006f2262a3ba27 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sat, 18 Jan 2025 19:02:31 +0800 Subject: [PATCH 41/47] add new gint interface --- CMakeLists.txt | 3 + source/module_elecstate/elecstate_lcao.cpp | 26 ++++++--- .../elecstate_lcao_cal_tau.cpp | 11 +++- source/module_esolver/lcao_before_scf.cpp | 3 +- .../operator_lcao/veff_lcao.cpp | 58 +++++++++++++++++++ .../pulay_force_stress_gint.hpp | 21 +++++++ .../module_gint/CMakeLists.txt | 46 ++++++++------- 7 files changed, 137 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d6e74f898..d1487af838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,9 @@ if(ENABLE_LCAO) add_compile_definitions(__PEXSI) set(CMAKE_CXX_STANDARD 14) endif() + if(NEW_GINT) + add_compile_definitions(__NEW_GINT) + endif() else() set(ENABLE_DEEPKS OFF) set(ENABLE_LIBRI OFF) diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index 6cf08f12f1..dd0cbc1eb4 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -60,10 +60,13 @@ void ElecStateLCAO>::psiToRho(const psi::Psigint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint - // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); - // this->gint_k->cal_gint(&inout); + Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); + this->gint_k->cal_gint(&inout); +#else ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); +#endif if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { @@ -94,13 +97,13 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) //------------------------------------------------------------ ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!"); +#ifndef __NEW_GINT this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint - - // Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); - - // this->gint_gamma->cal_gint(&inout); + Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); + this->gint_gamma->cal_gint(&inout); +#else ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); - +#endif if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { @@ -162,16 +165,25 @@ void ElecStateLCAO::dmToRho(std::vector pexsi_DM, std::vectorgint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); this->gint_gamma->cal_gint(&inout); +#else + ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho); +#endif if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx); } +#ifndef __NEW_GINT + Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau); + this->gint_gamma->cal_gint(&inout1); +#else ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); +#endif } this->charge->renormalize_rho(); diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.cpp b/source/module_elecstate/elecstate_lcao_cal_tau.cpp index 5668098478..465feae304 100644 --- a/source/module_elecstate/elecstate_lcao_cal_tau.cpp +++ b/source/module_elecstate/elecstate_lcao_cal_tau.cpp @@ -16,8 +16,12 @@ void ElecStateLCAO>::cal_tau(const psi::Psicharge->kin_r[is], this->charge->nrxx); } +#ifndef __NEW_GINT + Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin); + this->gint_k->cal_gint(&inout1); +#else ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); - +#endif ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); return; } @@ -32,7 +36,12 @@ void ElecStateLCAO::cal_tau(const psi::Psi& psi) { ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx); } +#ifndef __NEW_GINT + Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin); + this->gint_gamma->cal_gint(&inout1); +#else ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r); +#endif ModuleBase::timer::tick("ElecStateLCAO", "cal_tau"); return; diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index a48c22b52f..b1941046a4 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -116,6 +116,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) d2psi_u, PARAM.inp.nstream); +#ifdef __NEW_GINT auto gint_info = std::make_shared( this->pw_big->nbx, this->pw_big->nby, @@ -133,7 +134,7 @@ void ESolver_KS_LCAO::before_scf(UnitCell& ucell, const int istep) ucell, this->gd); ModuleGint::Gint::init_gint_info(gint_info); - +#endif psi_u.clear(); psi_u.shrink_to_fit(); dpsi_u.clear(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 50d27ef9a3..1487169aa5 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -68,6 +68,20 @@ void Veff>::contributeHR() double* vr_eff1 = this->pot->get_effective_v(this->current_spin); double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin); +#ifndef __NEW_GINT + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + Gint_inout inout(vr_eff1, vofk_eff1, Gint_Tools::job_type::vlocal_meta); + this->GG->cal_vlocal(&inout, this->new_e_iteration); + } + else + { + Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); + this->GG->cal_vlocal(&inout, this->new_e_iteration); + } + this->GG->transfer_pvpR(this->hR,this->ucell); + this->new_e_iteration = false; +#else if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR); @@ -76,6 +90,7 @@ void Veff>::contributeHR() { ModuleGint::cal_gint_vl(vr_eff1, this->hR); } +#endif if(this->nspin == 2) { @@ -98,6 +113,23 @@ void Veff, double>>::contributeHR() double* vr_eff1 = this->pot->get_effective_v(this->current_spin); double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin); +#ifndef __NEW_GINT + // if you change the place of the following code, + // rememeber to delete the #include + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta); + this->GK->cal_gint(&inout); + } + else + { + // vlocal = Vh[rho] + Vxc[rho] + Vl(pseudo) + Gint_inout inout(vr_eff1, 0, Gint_Tools::job_type::vlocal); + this->GK->cal_gint(&inout); + } + + this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); +#else if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR); @@ -106,6 +138,7 @@ void Veff, double>>::contributeHR() { ModuleGint::cal_gint_vl(vr_eff1, this->hR); } +#endif if(this->nspin == 2) { @@ -122,6 +155,30 @@ void Veff, std::complex>>::contributeH ModuleBase::TITLE("Veff", "contributeHR"); ModuleBase::timer::tick("Veff", "contributeHR"); +#ifndef __NEW_GINT + double* vr_eff1 = nullptr; + double* vofk_eff1 = nullptr; + for (int is = 0; is < 4; is++) + { + vr_eff1 = this->pot->get_effective_v(is); + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + vofk_eff1 = this->pot->get_effective_vofk(is); + } + + if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) + { + Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta); + this->GK->cal_gint(&inout); + } + else + { + Gint_inout inout(vr_eff1, is, Gint_Tools::job_type::vlocal); + this->GK->cal_gint(&inout); + } + } + this->GK->transfer_pvpR(this->hR,this->ucell,this->gd); +#else std::vector vr_eff(4, nullptr); std::vector vofk_eff(4, nullptr); for (int is = 0; is < 4; is++) @@ -143,6 +200,7 @@ void Veff, std::complex>>::contributeH } } } +#endif ModuleBase::timer::tick("Veff", "contributeHR"); return; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index 2df7c5f461..d259624bdc 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -19,6 +19,26 @@ namespace PulayForceStress const bool& set_dmr_gint) { const int nspin = PARAM.inp.nspin; + +#ifndef __NEW_GINT + if (set_dmr_gint) { gint.transfer_DM2DtoGrid(dm.get_DMR_vector()); } // 2d block to grid + for (int is = 0; is < nspin; ++is) + { + const double* vr_eff1 = pot->get_effective_v(is); + const double* vofk_eff1 = nullptr; + if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) + { + vofk_eff1 = pot->get_effective_vofk(is); + Gint_inout inout(is, vr_eff1, vofk_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force_meta); + gint.cal_gint(&inout); + } + else + { + Gint_inout inout(is, vr_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force); + gint.cal_gint(&inout); + } + } +#else std::vector vr_eff(nspin, nullptr); std::vector vofk_eff(nspin, nullptr); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) @@ -38,6 +58,7 @@ namespace PulayForceStress } ModuleGint::cal_gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s); } +#endif if (isstress) { StressTools::stress_fill(-1.0, ucell.omega, s); } } diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 38665d83b0..23acca739c 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -29,28 +29,30 @@ list(APPEND objects init_orb.cpp ) -list(APPEND objects - new_grid_tech/biggrid_info.cpp - new_grid_tech/biggrid.cpp - new_grid_tech/divide_info.cpp - new_grid_tech/gint_atom.cpp - new_grid_tech/gint_info.cpp - new_grid_tech/gint.cpp - new_grid_tech/gint_vl.cpp - new_grid_tech/gint_vl_metagga.cpp - new_grid_tech/gint_vl_nspin4.cpp - new_grid_tech/gint_vl_metagga_nspin4.cpp - new_grid_tech/gint_rho.cpp - new_grid_tech/gint_tau.cpp - new_grid_tech/gint_fvl.cpp - new_grid_tech/gint_fvl_meta.cpp - new_grid_tech/localcell_info.cpp - new_grid_tech/phi_operator.cpp - new_grid_tech/set_ddphi.cpp - new_grid_tech/unitcell_info.cpp - new_grid_tech/gint_common.cpp - new_grid_tech/gint_interface.cpp - ) +if(NEW_GINT) + list(APPEND objects + new_grid_tech/biggrid_info.cpp + new_grid_tech/biggrid.cpp + new_grid_tech/divide_info.cpp + new_grid_tech/gint_atom.cpp + new_grid_tech/gint_info.cpp + new_grid_tech/gint.cpp + new_grid_tech/gint_vl.cpp + new_grid_tech/gint_vl_metagga.cpp + new_grid_tech/gint_vl_nspin4.cpp + new_grid_tech/gint_vl_metagga_nspin4.cpp + new_grid_tech/gint_rho.cpp + new_grid_tech/gint_tau.cpp + new_grid_tech/gint_fvl.cpp + new_grid_tech/gint_fvl_meta.cpp + new_grid_tech/localcell_info.cpp + new_grid_tech/phi_operator.cpp + new_grid_tech/set_ddphi.cpp + new_grid_tech/unitcell_info.cpp + new_grid_tech/gint_common.cpp + new_grid_tech/gint_interface.cpp + ) +endif() if(USE_CUDA) list(APPEND objects From f20de93755d88cd4b5bb011cf61ceb2990284a44 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sat, 18 Jan 2025 19:25:11 +0800 Subject: [PATCH 42/47] change new_grid_tech to new_gint --- source/module_elecstate/elecstate_lcao.cpp | 2 +- .../elecstate_lcao_cal_tau.cpp | 2 +- source/module_esolver/esolver_ks_lcao.h | 4 +- .../operator_lcao/veff_lcao.cpp | 2 +- .../pulay_force_stress_gint.hpp | 2 +- .../module_gint/CMakeLists.txt | 40 +++++++++---------- .../module_gint/grid_technique.cpp | 3 +- .../{new_grid_tech => new_gint}/biggrid.cpp | 0 .../{new_grid_tech => new_gint}/biggrid.h | 0 .../biggrid_info.cpp | 0 .../biggrid_info.h | 0 .../divide_info.cpp | 0 .../{new_grid_tech => new_gint}/divide_info.h | 0 .../{new_grid_tech => new_gint}/gint.cpp | 0 .../{new_grid_tech => new_gint}/gint.h | 0 .../{new_grid_tech => new_gint}/gint_atom.cpp | 0 .../{new_grid_tech => new_gint}/gint_atom.h | 0 .../gint_common.cpp | 0 .../{new_grid_tech => new_gint}/gint_common.h | 2 +- .../{new_grid_tech => new_gint}/gint_fvl.cpp | 0 .../{new_grid_tech => new_gint}/gint_fvl.h | 0 .../gint_fvl_meta.cpp | 0 .../gint_fvl_meta.h | 0 .../{new_grid_tech => new_gint}/gint_helper.h | 0 .../{new_grid_tech => new_gint}/gint_info.cpp | 0 .../{new_grid_tech => new_gint}/gint_info.h | 0 .../gint_interface.cpp | 0 .../gint_interface.h | 0 .../{new_grid_tech => new_gint}/gint_rho.cpp | 0 .../{new_grid_tech => new_gint}/gint_rho.h | 0 .../{new_grid_tech => new_gint}/gint_tau.cpp | 0 .../{new_grid_tech => new_gint}/gint_tau.h | 0 .../{new_grid_tech => new_gint}/gint_type.h | 0 .../{new_grid_tech => new_gint}/gint_vl.cpp | 0 .../{new_grid_tech => new_gint}/gint_vl.h | 0 .../gint_vl_metagga.cpp | 0 .../gint_vl_metagga.h | 0 .../gint_vl_metagga_nspin4.cpp | 0 .../gint_vl_metagga_nspin4.h | 0 .../gint_vl_nspin4.cpp | 0 .../gint_vl_nspin4.h | 0 .../localcell_info.cpp | 0 .../localcell_info.h | 0 .../meshgrid_info.h | 0 .../phi_operator.cpp | 0 .../phi_operator.h | 0 .../{new_grid_tech => new_gint}/set_ddphi.cpp | 0 .../unitcell_info.cpp | 0 .../unitcell_info.h | 0 49 files changed, 28 insertions(+), 29 deletions(-) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/biggrid.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/biggrid.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/biggrid_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/biggrid_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/divide_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/divide_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_atom.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_atom.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_common.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_common.h (91%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_fvl.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_fvl.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_fvl_meta.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_fvl_meta.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_helper.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_interface.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_interface.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_rho.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_rho.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_tau.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_tau.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_type.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_metagga.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_metagga.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_metagga_nspin4.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_metagga_nspin4.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_nspin4.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/gint_vl_nspin4.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/localcell_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/localcell_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/meshgrid_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/phi_operator.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/phi_operator.h (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/set_ddphi.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/unitcell_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_grid_tech => new_gint}/unitcell_info.h (100%) diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index dd0cbc1eb4..c7b08a6998 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -9,7 +9,7 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_parameter/parameter.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" #include diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.cpp b/source/module_elecstate/elecstate_lcao_cal_tau.cpp index 465feae304..2ed343613b 100644 --- a/source/module_elecstate/elecstate_lcao_cal_tau.cpp +++ b/source/module_elecstate/elecstate_lcao_cal_tau.cpp @@ -1,5 +1,5 @@ #include "elecstate_lcao.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" #include "module_base/timer.h" diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index a00bdffadf..e9cdeb3476 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -5,8 +5,8 @@ // for grid integration #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_info.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint.h" #ifdef __DEEPKS #include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" #endif diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 1487169aa5..d3e7ada5af 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -4,7 +4,7 @@ #include "module_base/tool_title.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_cell/unitcell.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" namespace hamilt { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index d259624bdc..962d8a7071 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -3,7 +3,7 @@ #include "module_hamilt_lcao/hamilt_lcaodft/stress_tools.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_parameter/parameter.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" namespace PulayForceStress { template diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index 23acca739c..d27a197dac 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -31,26 +31,26 @@ list(APPEND objects if(NEW_GINT) list(APPEND objects - new_grid_tech/biggrid_info.cpp - new_grid_tech/biggrid.cpp - new_grid_tech/divide_info.cpp - new_grid_tech/gint_atom.cpp - new_grid_tech/gint_info.cpp - new_grid_tech/gint.cpp - new_grid_tech/gint_vl.cpp - new_grid_tech/gint_vl_metagga.cpp - new_grid_tech/gint_vl_nspin4.cpp - new_grid_tech/gint_vl_metagga_nspin4.cpp - new_grid_tech/gint_rho.cpp - new_grid_tech/gint_tau.cpp - new_grid_tech/gint_fvl.cpp - new_grid_tech/gint_fvl_meta.cpp - new_grid_tech/localcell_info.cpp - new_grid_tech/phi_operator.cpp - new_grid_tech/set_ddphi.cpp - new_grid_tech/unitcell_info.cpp - new_grid_tech/gint_common.cpp - new_grid_tech/gint_interface.cpp + new_gint/biggrid_info.cpp + new_gint/biggrid.cpp + new_gint/divide_info.cpp + new_gint/gint_atom.cpp + new_gint/gint_info.cpp + new_gint/gint.cpp + new_gint/gint_vl.cpp + new_gint/gint_vl_metagga.cpp + new_gint/gint_vl_nspin4.cpp + new_gint/gint_vl_metagga_nspin4.cpp + new_gint/gint_rho.cpp + new_gint/gint_tau.cpp + new_gint/gint_fvl.cpp + new_gint/gint_fvl_meta.cpp + new_gint/localcell_info.cpp + new_gint/phi_operator.cpp + new_gint/set_ddphi.cpp + new_gint/unitcell_info.cpp + new_gint/gint_common.cpp + new_gint/gint_interface.cpp ) endif() diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index 394e96b844..a60cdd95c7 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -10,7 +10,7 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_hsolver/kernels/cuda/helper_cuda.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_helper.h" Grid_Technique::Grid_Technique() { #if ((defined __CUDA) /* || (defined __ROCM) */) @@ -382,7 +382,6 @@ void Grid_Technique::init_atoms_on_grid2(const int* index2normal, std::vector coords3(bxyz * 3, 0.0); for(int iat = 0; iat < ucell.nat; iat++) { - // printf("tau_in_bigcell[%d] = %f %f %f\n", iat, this->tau_in_bigcell[iat][0], this->tau_in_bigcell[iat][1], this->tau_in_bigcell[iat][2]); const int it = ucell.iat2it[iat]; const double rcut_square = this->rcuts[it] * this->rcuts[it]; // zero bigcell of meshball indicate ? diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp b/source/module_hamilt_lcao/module_gint/new_gint/biggrid.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/biggrid.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h b/source/module_hamilt_lcao/module_gint/new_gint/biggrid.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid.h rename to source/module_hamilt_lcao/module_gint/new_gint/biggrid.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h b/source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp b/source/module_hamilt_lcao/module_gint/new_gint/divide_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/divide_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h b/source/module_hamilt_lcao/module_gint/new_gint/divide_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/divide_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/divide_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h b/source/module_hamilt_lcao/module_gint/new_gint/gint.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_atom.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_atom.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_atom.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_atom.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_atom.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_common.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_common.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_common.h similarity index 91% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_common.h index 74f42427d4..6bf105839c 100644 --- a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/new_gint/gint_common.h @@ -1,6 +1,6 @@ #pragma once #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" -#include "module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h" +#include "module_hamilt_lcao/module_gint/new_gint/gint_info.h" namespace ModuleGint { diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl_meta.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_helper.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_interface.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_interface.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_interface.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_interface.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_interface.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_rho.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_rho.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_rho.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_rho.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_tau.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_tau.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_tau.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_tau.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_type.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_type.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_type.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_metagga_nspin4.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl_nspin4.h rename to source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_gint/localcell_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/localcell_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h b/source/module_hamilt_lcao/module_gint/new_gint/localcell_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/localcell_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/localcell_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/new_gint/meshgrid_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/meshgrid_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/new_gint/phi_operator.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/phi_operator.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h b/source/module_hamilt_lcao/module_gint/new_gint/phi_operator.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/phi_operator.h rename to source/module_hamilt_lcao/module_gint/new_gint/phi_operator.h diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/new_gint/set_ddphi.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/set_ddphi.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/set_ddphi.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.cpp rename to source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h b/source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h rename to source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.h From 7cfd5ef04f5f12d4aee5105d2e4bba5622562b74 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Sat, 18 Jan 2025 19:34:07 +0800 Subject: [PATCH 43/47] revert some incorrect changes --- .gitignore | 6 ----- deps/LibComm | 1 - deps/LibRI | 1 - .../hamilt_lcaodft/hamilt_lcao.cpp | 1 - .../hamilt_lcaodft/hamilt_lcao.h | 1 - .../module_gint/new_gint/gint_helper.h | 25 +------------------ source/module_io/write_eband_terms.hpp | 12 ++++----- source/module_io/write_vxc.hpp | 6 ++--- 8 files changed, 10 insertions(+), 43 deletions(-) delete mode 160000 deps/LibComm delete mode 160000 deps/LibRI diff --git a/.gitignore b/.gitignore index 561b23ab20..4d8d089055 100644 --- a/.gitignore +++ b/.gitignore @@ -23,9 +23,3 @@ time.json __pycache__ abacus.json *.npy -r0*/* -tests/* -TD*/* -cmake/* -*.nsys-rep -*.sh \ No newline at end of file diff --git a/deps/LibComm b/deps/LibComm deleted file mode 160000 index ec984514b4..0000000000 --- a/deps/LibComm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ec984514b44480e98bd1578bcacca7a19c849724 diff --git a/deps/LibRI b/deps/LibRI deleted file mode 160000 index bd299faeaa..0000000000 --- a/deps/LibRI +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bd299faeaa184b912e4bdf5c0e182dfb7f47272a diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 2026e07cda..69e90ea3b9 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -40,7 +40,6 @@ #include "operator_lcao/td_nonlocal_lcao.h" #include "operator_lcao/veff_lcao.h" -#include namespace hamilt { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index 1483831ab7..b1603ac93e 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -21,7 +21,6 @@ #ifdef __EXX #include "module_ri/Exx_LRI.h" #endif -#include namespace hamilt { diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h b/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h index c3a64438c3..b1f72c5a11 100644 --- a/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h +++ b/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h @@ -60,27 +60,4 @@ inline int floor_div(const int a, const int b) inline int ceil_div(const int a, const int b) { return a / b + (a % b != 0 && (a ^ b) > 0); -}; - -// for debug -#include -#include -#include - -template -void writeArrayToFile(T* array, int n, const std::string& filename) { - std::ofstream outFile(filename); - - if (!outFile.is_open()) { - std::cerr << "can't open file: " << filename << std::endl; - return; - } - - for (int i = 0; i < n; ++i) { - outFile < v_pp_local_R_ao(pv); if_gamma_fix(v_pp_local_R_ao); std::vector> e_orb_pp_local; - // hamilt::Veff> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd, nspin); - // v_pp_local_op.contributeHR(); + hamilt::Veff> v_pp_local_op(gint, &v_pp_local_k_ao, kv.kvec_d, &pot_local, &v_pp_local_R_ao, &ucell, orb_cutoff, &gd, nspin); + v_pp_local_op.contributeHR(); for (int ik = 0;ik < kv.get_nks();++ik) { v_pp_local_k_ao.set_zero_hk(); - // dynamic_cast*>(&v_pp_local_op)->contributeHk(ik); + dynamic_cast*>(&v_pp_local_op)->contributeHk(ik); e_orb_pp_local.emplace_back(orbital_energy(ik, nbands, cVc(v_pp_local_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d)); } @@ -143,9 +143,9 @@ void write_eband_terms(const int nspin, std::vector>*> v_hartree_op(nspin0); for (int is = 0; is < nspin0; ++is) { - // v_hartree_op[is] = new hamilt::Veff>(gint, - // &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin); - // v_hartree_op[is]->contributeHR(); + v_hartree_op[is] = new hamilt::Veff>(gint, + &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin); + v_hartree_op[is]->contributeHR(); } std::vector> e_orb_hartree; for (int ik = 0;ik < kv.get_nks();++ik) diff --git a/source/module_io/write_vxc.hpp b/source/module_io/write_vxc.hpp index f5c4188005..fa9da0ec62 100644 --- a/source/module_io/write_vxc.hpp +++ b/source/module_io/write_vxc.hpp @@ -240,10 +240,10 @@ void write_Vxc(const int nspin, std::vector>*> vxcs_op_ao(nspin0); for (int is = 0; is < nspin0; ++is) { - // vxcs_op_ao[is] = new hamilt::Veff>(gint, - // &vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin); + vxcs_op_ao[is] = new hamilt::Veff>(gint, + &vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin); - // vxcs_op_ao[is]->contributeHR(); + vxcs_op_ao[is]->contributeHR(); } std::vector> e_orb_locxc; // orbital energy (local XC) std::vector> e_orb_tot; // orbital energy (total) From ea1755907190b7cdcb656cb5c726a058952b79f3 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 20 Jan 2025 15:20:57 +0800 Subject: [PATCH 44/47] add a unit test --- source/module_base/test/vector3_test.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/module_base/test/vector3_test.cpp b/source/module_base/test/vector3_test.cpp index 0ac51c72f8..9a1cf49254 100644 --- a/source/module_base/test/vector3_test.cpp +++ b/source/module_base/test/vector3_test.cpp @@ -64,6 +64,9 @@ * - VneV * - overload operator "!=" to assert * - the inequality between two 3d vectors + * - VltV + * - overload operator "<" to sort + * - the "less than" relationship between two 3d vectors * - StdOutV * - overload operator "<<" to print out * - a 3d vectors on standard output @@ -703,6 +706,22 @@ TEST_F(Vector3Test,VneV) EXPECT_TRUE(wp != w); } +TEST_F(Vector3Test, VltV) +{ + ModuleBase::Vector3 u, up; + u.set(da, db, dc); + up.set(dc, db, da); + EXPECT_TRUE(u < up); + ModuleBase::Vector3 v, vp; + v.set(fa, fb, fc); + vp.set(fa, fb, fc); + EXPECT_FALSE(v < vp); + ModuleBase::Vector3 w, wp; + w.set(ia, ib, ic); + wp.set(ib, ib, ic); + EXPECT_TRUE(w < wp); +} + TEST_F(Vector3Test,StdOutV) { // double Vector3 From b267ee6cb64f17afa62dc5f37c4d2635408d4da7 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 20 Jan 2025 15:52:14 +0800 Subject: [PATCH 45/47] change some names --- source/module_elecstate/elecstate_lcao.cpp | 2 +- .../elecstate_lcao_cal_tau.cpp | 2 +- source/module_esolver/esolver_ks_lcao.h | 4 +- .../operator_lcao/veff_lcao.cpp | 2 +- .../pulay_force_stress_gint.hpp | 2 +- .../module_gint/CMakeLists.txt | 40 +++++++++---------- .../module_gint/grid_technique.cpp | 2 +- .../biggrid.cpp => temp_gint/big_grid.cpp} | 2 +- .../biggrid.h => temp_gint/big_grid.h} | 0 .../{new_gint => temp_gint}/biggrid_info.cpp | 0 .../{new_gint => temp_gint}/biggrid_info.h | 0 .../{new_gint => temp_gint}/divide_info.cpp | 0 .../{new_gint => temp_gint}/divide_info.h | 0 .../{new_gint => temp_gint}/gint.cpp | 0 .../{new_gint => temp_gint}/gint.h | 0 .../{new_gint => temp_gint}/gint_atom.cpp | 0 .../{new_gint => temp_gint}/gint_atom.h | 0 .../{new_gint => temp_gint}/gint_common.cpp | 0 .../{new_gint => temp_gint}/gint_common.h | 2 +- .../{new_gint => temp_gint}/gint_fvl.cpp | 0 .../{new_gint => temp_gint}/gint_fvl.h | 0 .../{new_gint => temp_gint}/gint_fvl_meta.cpp | 0 .../{new_gint => temp_gint}/gint_fvl_meta.h | 0 .../{new_gint => temp_gint}/gint_helper.h | 0 .../{new_gint => temp_gint}/gint_info.cpp | 0 .../{new_gint => temp_gint}/gint_info.h | 2 +- .../gint_interface.cpp | 0 .../{new_gint => temp_gint}/gint_interface.h | 0 .../{new_gint => temp_gint}/gint_rho.cpp | 0 .../{new_gint => temp_gint}/gint_rho.h | 0 .../{new_gint => temp_gint}/gint_tau.cpp | 0 .../{new_gint => temp_gint}/gint_tau.h | 0 .../{new_gint => temp_gint}/gint_type.h | 0 .../{new_gint => temp_gint}/gint_vl.cpp | 0 .../{new_gint => temp_gint}/gint_vl.h | 0 .../gint_vl_metagga.cpp | 0 .../{new_gint => temp_gint}/gint_vl_metagga.h | 0 .../gint_vl_metagga_nspin4.cpp | 0 .../gint_vl_metagga_nspin4.h | 0 .../gint_vl_nspin4.cpp | 0 .../{new_gint => temp_gint}/gint_vl_nspin4.h | 0 .../localcell_info.cpp | 0 .../{new_gint => temp_gint}/localcell_info.h | 0 .../{new_gint => temp_gint}/meshgrid_info.h | 0 .../{new_gint => temp_gint}/phi_operator.cpp | 0 .../{new_gint => temp_gint}/phi_operator.h | 2 +- .../{new_gint => temp_gint}/set_ddphi.cpp | 0 .../{new_gint => temp_gint}/unitcell_info.cpp | 0 .../{new_gint => temp_gint}/unitcell_info.h | 0 49 files changed, 31 insertions(+), 31 deletions(-) rename source/module_hamilt_lcao/module_gint/{new_gint/biggrid.cpp => temp_gint/big_grid.cpp} (99%) rename source/module_hamilt_lcao/module_gint/{new_gint/biggrid.h => temp_gint/big_grid.h} (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/biggrid_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/biggrid_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/divide_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/divide_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_atom.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_atom.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_common.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_common.h (92%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_fvl.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_fvl.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_fvl_meta.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_fvl_meta.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_helper.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_info.h (99%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_interface.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_interface.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_rho.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_rho.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_tau.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_tau.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_type.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_metagga.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_metagga.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_metagga_nspin4.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_metagga_nspin4.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_nspin4.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/gint_vl_nspin4.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/localcell_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/localcell_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/meshgrid_info.h (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/phi_operator.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/phi_operator.h (99%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/set_ddphi.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/unitcell_info.cpp (100%) rename source/module_hamilt_lcao/module_gint/{new_gint => temp_gint}/unitcell_info.h (100%) diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index c7b08a6998..bae90aba79 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -9,7 +9,7 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_parameter/parameter.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h" #include diff --git a/source/module_elecstate/elecstate_lcao_cal_tau.cpp b/source/module_elecstate/elecstate_lcao_cal_tau.cpp index 2ed343613b..9f2c0bd40b 100644 --- a/source/module_elecstate/elecstate_lcao_cal_tau.cpp +++ b/source/module_elecstate/elecstate_lcao_cal_tau.cpp @@ -1,5 +1,5 @@ #include "elecstate_lcao.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h" #include "module_base/timer.h" diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index e9cdeb3476..8a620291f7 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -5,8 +5,8 @@ // for grid integration #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_hamilt_lcao/module_gint/gint_k.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_info.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_info.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint.h" #ifdef __DEEPKS #include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" #endif diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index d3e7ada5af..6e70b8c8fb 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -4,7 +4,7 @@ #include "module_base/tool_title.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_cell/unitcell.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h" namespace hamilt { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp index 962d8a7071..e3cdcaf2ee 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp @@ -3,7 +3,7 @@ #include "module_hamilt_lcao/hamilt_lcaodft/stress_tools.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_parameter/parameter.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h" namespace PulayForceStress { template diff --git a/source/module_hamilt_lcao/module_gint/CMakeLists.txt b/source/module_hamilt_lcao/module_gint/CMakeLists.txt index d27a197dac..7b43114adb 100644 --- a/source/module_hamilt_lcao/module_gint/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_gint/CMakeLists.txt @@ -31,26 +31,26 @@ list(APPEND objects if(NEW_GINT) list(APPEND objects - new_gint/biggrid_info.cpp - new_gint/biggrid.cpp - new_gint/divide_info.cpp - new_gint/gint_atom.cpp - new_gint/gint_info.cpp - new_gint/gint.cpp - new_gint/gint_vl.cpp - new_gint/gint_vl_metagga.cpp - new_gint/gint_vl_nspin4.cpp - new_gint/gint_vl_metagga_nspin4.cpp - new_gint/gint_rho.cpp - new_gint/gint_tau.cpp - new_gint/gint_fvl.cpp - new_gint/gint_fvl_meta.cpp - new_gint/localcell_info.cpp - new_gint/phi_operator.cpp - new_gint/set_ddphi.cpp - new_gint/unitcell_info.cpp - new_gint/gint_common.cpp - new_gint/gint_interface.cpp + temp_gint/biggrid_info.cpp + temp_gint/big_grid.cpp + temp_gint/divide_info.cpp + temp_gint/gint_atom.cpp + temp_gint/gint_info.cpp + temp_gint/gint.cpp + temp_gint/gint_vl.cpp + temp_gint/gint_vl_metagga.cpp + temp_gint/gint_vl_nspin4.cpp + temp_gint/gint_vl_metagga_nspin4.cpp + temp_gint/gint_rho.cpp + temp_gint/gint_tau.cpp + temp_gint/gint_fvl.cpp + temp_gint/gint_fvl_meta.cpp + temp_gint/localcell_info.cpp + temp_gint/phi_operator.cpp + temp_gint/set_ddphi.cpp + temp_gint/unitcell_info.cpp + temp_gint/gint_common.cpp + temp_gint/gint_interface.cpp ) endif() diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index a60cdd95c7..d97fde3a19 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -10,7 +10,7 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_hsolver/kernels/cuda/helper_cuda.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_helper.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_helper.h" Grid_Technique::Grid_Technique() { #if ((defined __CUDA) /* || (defined __ROCM) */) diff --git a/source/module_hamilt_lcao/module_gint/new_gint/biggrid.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp similarity index 99% rename from source/module_hamilt_lcao/module_gint/new_gint/biggrid.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp index 014561f5bd..fbfae1c26a 100644 --- a/source/module_hamilt_lcao/module_gint/new_gint/biggrid.cpp +++ b/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp @@ -1,4 +1,4 @@ -#include "biggrid.h" +#include "big_grid.h" namespace ModuleGint { diff --git a/source/module_hamilt_lcao/module_gint/new_gint/biggrid.h b/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/biggrid.h rename to source/module_hamilt_lcao/module_gint/temp_gint/big_grid.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/biggrid_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/biggrid_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/biggrid_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/biggrid_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/biggrid_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/divide_info.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/divide_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/divide_info.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/divide_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/divide_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/divide_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/divide_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/divide_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_atom.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_atom.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_atom.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_atom.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_atom.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_atom.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_atom.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_atom.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_common.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_common.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_common.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_common.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_common.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_common.h similarity index 92% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_common.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_common.h index 6bf105839c..aa47fdf351 100644 --- a/source/module_hamilt_lcao/module_gint/new_gint/gint_common.h +++ b/source/module_hamilt_lcao/module_gint/temp_gint/gint_common.h @@ -1,6 +1,6 @@ #pragma once #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" -#include "module_hamilt_lcao/module_gint/new_gint/gint_info.h" +#include "module_hamilt_lcao/module_gint/temp_gint/gint_info.h" namespace ModuleGint { diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_fvl.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl_meta.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl_meta.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl_meta.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_fvl_meta.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_fvl_meta.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_helper.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_helper.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_helper.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_info.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_info.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_info.h similarity index 99% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_info.h index 00e6f85e2f..326f35a21b 100644 --- a/source/module_hamilt_lcao/module_gint/new_gint/gint_info.h +++ b/source/module_hamilt_lcao/module_gint/temp_gint/gint_info.h @@ -7,7 +7,7 @@ #include "module_cell/atom_spec.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "gint_type.h" -#include "biggrid.h" +#include "big_grid.h" #include "gint_atom.h" #include "unitcell_info.h" #include "localcell_info.h" diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_interface.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_interface.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_interface.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_interface.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_interface.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_interface.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_interface.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_interface.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_rho.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_rho.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_rho.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_rho.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_rho.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_rho.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_rho.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_rho.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_tau.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_tau.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_tau.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_tau.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_tau.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_tau.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_tau.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_tau.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_type.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_type.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_type.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_type.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga_nspin4.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga_nspin4.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga_nspin4.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_metagga_nspin4.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_metagga_nspin4.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_nspin4.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_nspin4.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.h b/source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_nspin4.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/gint_vl_nspin4.h rename to source/module_hamilt_lcao/module_gint/temp_gint/gint_vl_nspin4.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/localcell_info.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/localcell_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/localcell_info.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/localcell_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/localcell_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/localcell_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/localcell_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/localcell_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/meshgrid_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/meshgrid_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/meshgrid_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/meshgrid_info.h diff --git a/source/module_hamilt_lcao/module_gint/new_gint/phi_operator.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/phi_operator.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/phi_operator.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/phi_operator.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/phi_operator.h b/source/module_hamilt_lcao/module_gint/temp_gint/phi_operator.h similarity index 99% rename from source/module_hamilt_lcao/module_gint/new_gint/phi_operator.h rename to source/module_hamilt_lcao/module_gint/temp_gint/phi_operator.h index ebe3bf1fb3..535e3a2f7e 100644 --- a/source/module_hamilt_lcao/module_gint/new_gint/phi_operator.h +++ b/source/module_hamilt_lcao/module_gint/temp_gint/phi_operator.h @@ -4,7 +4,7 @@ #include #include #include -#include "biggrid.h" +#include "big_grid.h" namespace ModuleGint { diff --git a/source/module_hamilt_lcao/module_gint/new_gint/set_ddphi.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/set_ddphi.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/set_ddphi.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/set_ddphi.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/unitcell_info.cpp similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.cpp rename to source/module_hamilt_lcao/module_gint/temp_gint/unitcell_info.cpp diff --git a/source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.h b/source/module_hamilt_lcao/module_gint/temp_gint/unitcell_info.h similarity index 100% rename from source/module_hamilt_lcao/module_gint/new_gint/unitcell_info.h rename to source/module_hamilt_lcao/module_gint/temp_gint/unitcell_info.h From af6f565894e96e4eb609f1fabc7016d786065673 Mon Sep 17 00:00:00 2001 From: dzzz2001 Date: Mon, 20 Jan 2025 15:52:30 +0800 Subject: [PATCH 46/47] check nullptr --- source/module_basis/module_ao/ORB_atomic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/module_basis/module_ao/ORB_atomic.h b/source/module_basis/module_ao/ORB_atomic.h index 66cd5fa8a6..2539e0a0c9 100644 --- a/source/module_basis/module_ao/ORB_atomic.h +++ b/source/module_basis/module_ao/ORB_atomic.h @@ -66,6 +66,7 @@ class Numerical_Orbital const inline Numerical_Orbital_Lm& PhiLN( const int &L, const int &N)const { + assert(this->phiLN != nullptr); return this->phiLN[ this->find_chi(L, N) ]; } From 78eef21b1f5d008ae19512ef3f91ac478dea1f6d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:23:59 +0000 Subject: [PATCH 47/47] [pre-commit.ci lite] apply automatic fixes --- source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp b/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp index fbfae1c26a..d972cd90bb 100644 --- a/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp +++ b/source/module_hamilt_lcao/module_gint/temp_gint/big_grid.cpp @@ -92,7 +92,7 @@ void BigGrid::set_atom_relative_coords(const Vec3i bgrid_idx, const Vec3d tau_in void BigGrid::set_atom_relative_coords(const GintAtom* atom, std::vector& atom_coord) const { - return set_atom_relative_coords(atom->get_bgrid_idx(), atom->get_tau_in_bgrid(), atom_coord); + set_atom_relative_coords(atom->get_bgrid_idx(), atom->get_tau_in_bgrid(), atom_coord); } bool BigGrid::is_atom_on_bgrid(const GintAtom* atom) const