Skip to content

Commit 4481063

Browse files
committed
simplify member function of biggrid_info
1 parent 5c39340 commit 4481063

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,21 @@ BigGridInfo::BigGridInfo(
4646
}
4747
}
4848

49+
Vec3i BigGridInfo::max_ext_bgrid_num(double r) const
50+
{
51+
const double g1 = sqrt(biggrid_GT_.e11 * biggrid_GT_.e11
52+
+ biggrid_GT_.e21 * biggrid_GT_.e21
53+
+ biggrid_GT_.e31 * biggrid_GT_.e31);
54+
const double g2 = sqrt(biggrid_GT_.e12 * biggrid_GT_.e12
55+
+ biggrid_GT_.e22 * biggrid_GT_.e22
56+
+ biggrid_GT_.e32 * biggrid_GT_.e32);
57+
const double g3 = sqrt(biggrid_GT_.e13 * biggrid_GT_.e13
58+
+ biggrid_GT_.e23 * biggrid_GT_.e23
59+
+ biggrid_GT_.e33 * biggrid_GT_.e33);
60+
int ext_x = static_cast<int>(r * g1) + 1;
61+
int ext_y = static_cast<int>(r * g2) + 1;
62+
int ext_z = static_cast<int>(r * g3) + 1;
63+
return Vec3i(ext_x, ext_y, ext_z);
64+
}
65+
4966
} // namespace ModuleGint

source/module_hamilt_lcao/module_gint/new_grid_tech/biggrid_info.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ class BigGridInfo
2222
Vec3d biggrid_vec3,
2323
int nmx, int nmy, int nmz);
2424

25-
// getter functions
26-
const Vec3d &get_vec1() const { return biggrid_vec1_; };
27-
const Vec3d &get_vec2() const { return biggrid_vec2_; };
28-
const Vec3d &get_vec3() const { return biggrid_vec3_; };
29-
const Matrix3 &get_latvec0() const { return biggrid_latvec0_; };
30-
const Matrix3 &get_GT() const { return biggrid_GT_; };
25+
Vec3d get_cartesian_coord(const Vec3d& index_3d) const { return index_3d * biggrid_latvec0_; };
26+
Vec3d get_cartesian_coord(const Vec3i& index_3d) const { return index_3d * biggrid_latvec0_; };
27+
const Vec3d get_direct_coord(const Vec3d& cart_coord) const { return cart_coord * biggrid_GT_; };
28+
29+
// Return the maximum number of big grids that can fit inside a sphere of radius r,
30+
// along the three lattice vector directions.
31+
Vec3i max_ext_bgrid_num(double r) const;
32+
33+
// get number of meshgrids along three lattice directions
3134
int get_nmx() const { return nmx_; };
3235
int get_nmy() const { return nmy_; };
3336
int get_nmz() const { return nmz_; };
3437
int get_nmxyz() const { return nmxyz_; };
38+
3539
const std::vector<Vec3d>& get_meshgrid_coords() const { return meshgrid_coords_; };
3640
const Vec3d& get_meshgrid_coord(int index_1d) const { return meshgrid_coords_[index_1d]; };
41+
3742
std::shared_ptr<const MeshGridInfo> get_meshgrid_info() const { return meshgrid_info_; };
3843

3944
// get the 3D index of a meshgrid in the big grid from the 1D index

source/module_hamilt_lcao/module_gint/new_grid_tech/gint_info.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital
6262
{
6363
ModuleBase::timer::tick("GintInfo", "init_atoms");
6464
int iat = 0;
65-
const Matrix3& biggrid_GT = unitcell_info_->get_biggrid_info()->get_GT();
66-
const double g1 = sqrt(biggrid_GT.e11 * biggrid_GT.e11
67-
+ biggrid_GT.e21 * biggrid_GT.e21
68-
+ biggrid_GT.e31 * biggrid_GT.e31);
69-
const double g2 = sqrt(biggrid_GT.e12 * biggrid_GT.e12
70-
+ biggrid_GT.e22 * biggrid_GT.e22
71-
+ biggrid_GT.e32 * biggrid_GT.e32);
72-
const double g3 = sqrt(biggrid_GT.e13 * biggrid_GT.e13
73-
+ biggrid_GT.e23 * biggrid_GT.e23
74-
+ biggrid_GT.e33 * biggrid_GT.e33);
75-
7665
is_atom_in_proc_.resize(ucell_->nat, false);
7766
atoms_.resize(ucell_->nat);
7867

@@ -83,9 +72,7 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital
8372
const auto *orb = &Phi[i];
8473

8574
// rcut extends to the maximum big grids in x, y, z directions
86-
int ext_bgrid_x = static_cast<int>(atom.Rcut * g1) + 1;
87-
int ext_bgrid_y = static_cast<int>(atom.Rcut * g2) + 1;
88-
int ext_bgrid_z = static_cast<int>(atom.Rcut * g3) + 1;
75+
Vec3i ext_bgrid = biggrid_info_->max_ext_bgrid_num(atom.Rcut);
8976

9077
for(int j = 0; j < atom.na; j++)
9178
{
@@ -99,18 +86,16 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital
9986
const Vec3d delta(fraction.x - atom_bgrid_idx.x,
10087
fraction.y - atom_bgrid_idx.y,
10188
fraction.z - atom_bgrid_idx.z);
102-
const Vec3d tau_in_biggrid = delta.x * unitcell_info_->get_biggrid_info()->get_vec1() +
103-
delta.y * unitcell_info_->get_biggrid_info()->get_vec2() +
104-
delta.z * unitcell_info_->get_biggrid_info()->get_vec3();
89+
const Vec3d tau_in_biggrid = biggrid_info_->get_cartesian_coord(delta);
10590

10691
const Vec3i ucell_idx_atom = unitcell_info_->get_unitcell_idx(atom_bgrid_idx);
10792
auto& r_to_atom = atoms_[iat];
10893

109-
for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid_x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid_x; bgrid_x++)
94+
for(int bgrid_x = atom_bgrid_idx.x - ext_bgrid.x; bgrid_x <= atom_bgrid_idx.x + ext_bgrid.x; bgrid_x++)
11095
{
111-
for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid_y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid_y; bgrid_y++)
96+
for(int bgrid_y = atom_bgrid_idx.y - ext_bgrid.y; bgrid_y <= atom_bgrid_idx.y + ext_bgrid.y; bgrid_y++)
11297
{
113-
for(int bgrid_z = atom_bgrid_idx.z - ext_bgrid_z; bgrid_z <= atom_bgrid_idx.z + ext_bgrid_z; bgrid_z++)
98+
for(int bgrid_z = atom_bgrid_idx.z - ext_bgrid.z; bgrid_z <= atom_bgrid_idx.z + ext_bgrid.z; bgrid_z++)
11499
{
115100
// get the extended biggrid idx of the affected biggrid
116101
const Vec3i ext_bgrid_idx(bgrid_x, bgrid_y, bgrid_z);

source/module_hamilt_lcao/module_gint/new_grid_tech/meshgrid_info.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class MeshGridInfo
3737
meshgrid_volume_ = std::abs(meshgrid_latvec0_.Det());
3838
};
3939

40-
const double get_volume() const { return meshgrid_volume_; };
41-
const Vec3d get_cartesian_coord(Vec3i index_3d) const { return index_3d * meshgrid_latvec0_; };
40+
double get_volume() const { return meshgrid_volume_; };
41+
Vec3d get_cartesian_coord(const Vec3i& index_3d) const { return index_3d * meshgrid_latvec0_; };
42+
Vec3d get_direct_coord(const Vec3d& cart_coord) const { return cart_coord * meshgrid_GT_; }
4243

4344
private:
4445
// basis vectors of meshgrid

source/module_hamilt_lcao/module_gint/new_grid_tech/unitcell_info.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class UnitCellInfo
2121
int nmx, int nmy, int nmz);
2222

2323
// getter functions
24-
const Vec3d &get_vec1() const { return unitcell_vec1_; };
25-
const Vec3d &get_vec2() const { return unitcell_vec2_; };
26-
const Vec3d &get_vec3() const { return unitcell_vec3_; };
2724
int get_nbx() const { return nbx_; };
2825
int get_nby() const { return nby_; };
2926
int get_nbz() const { return nbz_; };
@@ -54,7 +51,7 @@ class UnitCellInfo
5451
// get the cartesian coordinate of a big grid in the unit cell from the 3D index
5552
Vec3d get_biggrid_coord(Vec3i index_3d) const
5653
{
57-
return index_3d * biggrid_info_->get_latvec0();
54+
return biggrid_info_->get_cartesian_coord(index_3d);
5855
};
5956

6057
// get the cartesian coordinate of a big grid in the unit cell from the 1D index
@@ -66,11 +63,11 @@ class UnitCellInfo
6663
// get the 3D index of a big grid in the unit cell from the cartesian coordinate
6764
Vec3i get_biggrid_idx_3d(const Vec3d coord) const
6865
{
69-
Vec3d biggrid_idx_double = coord * biggrid_info_->get_GT();
66+
Vec3d direct_coord = biggrid_info_->get_direct_coord(coord);
7067
return Vec3i(
71-
static_cast<int>(floor(biggrid_idx_double.x)),
72-
static_cast<int>(floor(biggrid_idx_double.y)),
73-
static_cast<int>(floor(biggrid_idx_double.z)));
68+
static_cast<int>(floor(direct_coord.x)),
69+
static_cast<int>(floor(direct_coord.y)),
70+
static_cast<int>(floor(direct_coord.z)));
7471
};
7572

7673
// Get the relative Cartesian coordinates of big grid A relative to big grid B

0 commit comments

Comments
 (0)