Skip to content

Commit d4ed255

Browse files
committed
Refactor: remove GlobalC::Grid_D in hamilt_lcao
1 parent ee4ad57 commit d4ed255

File tree

10 files changed

+419
-375
lines changed

10 files changed

+419
-375
lines changed

source/module_cell/module_neighbor/sltk_grid.h

Lines changed: 88 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -53,70 +53,69 @@ class Grid
5353

5454
// Constructors and destructor
5555
// Grid is Global class,so init it with constant number
56-
Grid():test_grid(0){};
57-
Grid(const int &test_grid_in);
58-
virtual ~Grid();
59-
60-
void init(
61-
std::ofstream &ofs,
62-
const UnitCell &ucell,
63-
const Atom_input &input);
64-
65-
//2015-05-07
66-
void delete_vector(const Atom_input &input);
67-
68-
69-
//Static data
70-
static const double TOLERATE_ERROR;
71-
static const std::hash<int> INT_HASHER;
72-
static const char* const ERROR[3];
73-
74-
//Data
75-
int natom;// Total atoms.
76-
bool pbc; // periodic boundary condition
77-
bool expand_flag;
78-
double sradius;// searching radius
79-
double d_minX;// origin of all cells
80-
double d_minY;
81-
double d_minZ;
82-
int dx;
83-
int dy;
84-
int dz;
85-
int layer;
86-
double cell_x_length;
87-
double cell_y_length;
88-
double cell_z_length;
89-
CellSet ***Cell; //dx , dy ,dz is cell number in each direction,respectly.
90-
void delete_Cell() //it will replace by container soon!
91-
{
92-
if (this->init_cell_flag)
93-
{
94-
for (int i = 0;i < this->dx;i++)
95-
{
96-
for (int j = 0;j < this->dy;j++)
97-
{
98-
delete[] this->Cell[i][j];
99-
}
100-
}
101-
102-
for (int i = 0;i < this->dx;i++)
103-
{
104-
delete[] this->Cell[i];
105-
}
106-
107-
delete[] this->Cell;
108-
this->init_cell_flag = false;
109-
}
110-
}
111-
112-
double grid_length[3];
113-
double vec1[3];
114-
double vec2[3];
115-
double vec3[3];
116-
double lat_now;
117-
bool init_cell_flag;
118-
//LiuXh add 2019-07-15
119-
const double& getD_minX(void) const {return d_minX;}
56+
Grid() : test_grid(0) {};
57+
Grid(const int& test_grid_in);
58+
virtual ~Grid();
59+
60+
void init(std::ofstream& ofs, const UnitCell& ucell, const Atom_input& input);
61+
62+
// 2015-05-07
63+
void delete_vector(const Atom_input& input);
64+
65+
// Static data
66+
static const double TOLERATE_ERROR;
67+
static const std::hash<int> INT_HASHER;
68+
static const char* const ERROR[3];
69+
70+
// Data
71+
int natom; // Total atoms.
72+
bool pbc; // periodic boundary condition
73+
bool expand_flag;
74+
double sradius; // searching radius
75+
double d_minX; // origin of all cells
76+
double d_minY;
77+
double d_minZ;
78+
int dx;
79+
int dy;
80+
int dz;
81+
int layer;
82+
double cell_x_length;
83+
double cell_y_length;
84+
double cell_z_length;
85+
CellSet*** Cell; // dx , dy ,dz is cell number in each direction,respectly.
86+
void delete_Cell() // it will replace by container soon!
87+
{
88+
if (this->init_cell_flag)
89+
{
90+
for (int i = 0; i < this->dx; i++)
91+
{
92+
for (int j = 0; j < this->dy; j++)
93+
{
94+
delete[] this->Cell[i][j];
95+
}
96+
}
97+
98+
for (int i = 0; i < this->dx; i++)
99+
{
100+
delete[] this->Cell[i];
101+
}
102+
103+
delete[] this->Cell;
104+
this->init_cell_flag = false;
105+
}
106+
}
107+
108+
double grid_length[3];
109+
double vec1[3];
110+
double vec2[3];
111+
double vec3[3];
112+
double lat_now;
113+
bool init_cell_flag = false;
114+
// LiuXh add 2019-07-15
115+
const double& getD_minX(void) const
116+
{
117+
return d_minX;
118+
}
120119
const double& getD_minY(void) const {return d_minY;}
121120
const double& getD_minZ(void) const {return d_minZ;}
122121

@@ -128,38 +127,31 @@ class Grid
128127
protected:
129128
AtomLink* getHashCode(const UnitCell &ucell, const FAtom &atom)const; // Peize Lin delete const 2018-07-14
130129
// AtomLink* const getHashCode(const FAtom &atom)const;
131-
AtomLink* atomlink;
132-
AtomLink* cordon_p;// Warning! A guard! Don't delete it!
133-
134-
private:
135-
136-
const int test_grid;
137-
//==========================================================
138-
// MEMBER FUNCTIONS :
139-
// Three Main Steps:
140-
// NAME : setMemberVariables (read in datas from Atom_input,
141-
// init cells.)
142-
// NAME : setAtomLinkArray( set the AtomLinkArray twice,
143-
// first use Build_Hash,second use Fold_Hash)
144-
// NAME : setBoundaryAdjacent( Consider different situations,
145-
// if not_expand case : nature/periodic boundary
146-
// condition , if expand_case)
147-
//==========================================================
148-
void setMemberVariables(
149-
std::ofstream &ofs_in,
150-
const Atom_input &input);
151-
152-
void setAtomLinkArray(
153-
const UnitCell &ucell,
154-
const Atom_input &input);
155-
156-
void setBoundaryAdjacent(
157-
std::ofstream &ofs_in,
158-
const Atom_input &input);
159-
160-
//==========================================================
161-
//
162-
//==========================================================
130+
AtomLink* atomlink = nullptr;
131+
AtomLink* cordon_p = nullptr; // Warning! A guard! Don't delete it!
132+
133+
private:
134+
const int test_grid;
135+
//==========================================================
136+
// MEMBER FUNCTIONS :
137+
// Three Main Steps:
138+
// NAME : setMemberVariables (read in datas from Atom_input,
139+
// init cells.)
140+
// NAME : setAtomLinkArray( set the AtomLinkArray twice,
141+
// first use Build_Hash,second use Fold_Hash)
142+
// NAME : setBoundaryAdjacent( Consider different situations,
143+
// if not_expand case : nature/periodic boundary
144+
// condition , if expand_case)
145+
//==========================================================
146+
void setMemberVariables(std::ofstream& ofs_in, const Atom_input& input);
147+
148+
void setAtomLinkArray(const UnitCell& ucell, const Atom_input& input);
149+
150+
void setBoundaryAdjacent(std::ofstream& ofs_in, const Atom_input& input);
151+
152+
//==========================================================
153+
//
154+
//==========================================================
163155
AtomLink* Build_Cache(const UnitCell &ucell, const Atom_input &input);
164156
// Peize Lin delete const and throw(std::out_of_range, std::logic_error) 2018-07-14
165157

source/module_cell/module_neighbor/sltk_grid_driver.h

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,55 @@ class Grid_Driver : public Grid
3939
// adjacent of this atom,and store the information
4040
// in 'adj_num','ntype','natom'
4141
//==========================================================
42-
Grid_Driver():test_deconstructor(0){};
43-
Grid_Driver(
44-
const int &test_d_in,
45-
const int &test_grid_in);
42+
Grid_Driver() : test_deconstructor(0) {};
43+
Grid_Driver(const int& test_d_in, const int& test_grid_in);
4644

47-
~Grid_Driver();
45+
~Grid_Driver();
4846

49-
//==========================================================
50-
// EXPLAIN FOR default parameter `adjs = nullptr`
51-
//
52-
// This design make Grid_Driver compatible with multi-thread usage
53-
// 1. Find_atom store results in Grid_Driver::adj_info
54-
// by default.
55-
// 2. And store results into parameter adjs when adjs is
56-
// NOT NULL
57-
//==========================================================
58-
void Find_atom(
59-
const UnitCell &ucell,
60-
const ModuleBase::Vector3<double> &cartesian_posi,
61-
const int &ntype,
62-
const int &nnumber,
63-
AdjacentAtomInfo *adjs = nullptr);
47+
//==========================================================
48+
// EXPLAIN FOR default parameter `adjs = nullptr`
49+
//
50+
// This design make Grid_Driver compatible with multi-thread usage
51+
// 1. Find_atom store results in Grid_Driver::adj_info
52+
// by default.
53+
// 2. And store results into parameter adjs when adjs is
54+
// NOT NULL
55+
//==========================================================
56+
void Find_atom(const UnitCell& ucell,
57+
const ModuleBase::Vector3<double>& cartesian_posi,
58+
const int& ntype,
59+
const int& nnumber,
60+
AdjacentAtomInfo* adjs = nullptr);
6461

65-
//==========================================================
66-
// EXPLAIN : The adjacent information for the input
67-
// cartesian_pos
68-
// MEMBER VARIABLES :
69-
// NAME : getAdjacentNum
70-
// NAME : getNtype
71-
// NAME : getNatom
72-
// NAME : getAdjaentTau
73-
//==========================================================
74-
const int& getAdjacentNum(void)const { return adj_info.adj_num; }
75-
const int& getType(const int i) const { return adj_info.ntype[i]; }
76-
const int& getNatom(const int i) const { return adj_info.natom[i]; }
77-
const ModuleBase::Vector3<double>& getAdjacentTau(const int i) const { return adj_info.adjacent_tau[i]; }
78-
const ModuleBase::Vector3<int>& getBox(const int i) const {return adj_info.box[i];}
62+
//==========================================================
63+
// EXPLAIN : The adjacent information for the input
64+
// cartesian_pos
65+
// MEMBER VARIABLES :
66+
// NAME : getAdjacentNum
67+
// NAME : getNtype
68+
// NAME : getNatom
69+
// NAME : getAdjaentTau
70+
//==========================================================
71+
const int& getAdjacentNum(void) const
72+
{
73+
return adj_info.adj_num;
74+
}
75+
const int& getType(const int i) const
76+
{
77+
return adj_info.ntype[i];
78+
}
79+
const int& getNatom(const int i) const
80+
{
81+
return adj_info.natom[i];
82+
}
83+
const ModuleBase::Vector3<double>& getAdjacentTau(const int i) const
84+
{
85+
return adj_info.adjacent_tau[i];
86+
}
87+
const ModuleBase::Vector3<int>& getBox(const int i) const
88+
{
89+
return adj_info.box[i];
90+
}
7991

8092
private:
8193

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef CELL_DEPENDENCY
2+
#define CELL_DEPENDENCY
3+
4+
#include "module_cell/module_neighbor/sltk_atom_arrange.h"
5+
#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h"
6+
#include "module_lr/utils/lr_util.hpp"
7+
8+
#include <memory>
9+
10+
class Cell_Dependency
11+
{
12+
public:
13+
Cell_Dependency() {};
14+
~Cell_Dependency() {};
15+
16+
Record_adj ra;
17+
Grid_Driver grid_d;
18+
};
19+
20+
#endif // CELL_DEPENDENCY

source/module_esolver/esolver_gets.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
77
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h"
88
#include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h"
9+
#include "module_io/cal_r_overlap_R.h"
910
#include "module_io/print_info.h"
1011
#include "module_io/write_HS_R.h"
11-
#include "module_io/cal_r_overlap_R.h"
1212

1313
namespace ModuleESolver
1414
{
@@ -101,14 +101,15 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
101101
PARAM.inp.test_atom_input);
102102

103103
Record_adj RA;
104-
RA.for_2d(this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
104+
RA.for_2d(GlobalC::GridD, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
105105

106106
if (this->p_hamilt == nullptr)
107107
{
108108
if (PARAM.inp.nspin == 4)
109109
{
110110
this->p_hamilt
111-
= new hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>(&this->pv,
111+
= new hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>(GlobalC::GridD,
112+
&this->pv,
112113
this->kv,
113114
*(two_center_bundle_.overlap_orb),
114115
orb_.cutoffs());
@@ -117,7 +118,8 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
117118
}
118119
else
119120
{
120-
this->p_hamilt = new hamilt::HamiltLCAO<std::complex<double>, double>(&this->pv,
121+
this->p_hamilt = new hamilt::HamiltLCAO<std::complex<double>, double>(GlobalC::GridD,
122+
&this->pv,
121123
this->kv,
122124
*(two_center_bundle_.overlap_orb),
123125
orb_.cutoffs());

source/module_esolver/lcao_before_scf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
127127
// (2)For each atom, calculate the adjacent atoms in different cells
128128
// and allocate the space for H(R) and S(R).
129129
// If k point is used here, allocate HlocR after atom_arrange.
130-
this->RA.for_2d(this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
130+
this->RA.for_2d(GlobalC::GridD, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
131131

132132
// 2. density matrix extrapolation
133133

@@ -188,6 +188,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
188188
this->p_hamilt = new hamilt::HamiltLCAO<TK, TR>(
189189
PARAM.globalv.gamma_only_local ? &(this->GG) : nullptr,
190190
PARAM.globalv.gamma_only_local ? nullptr : &(this->GK),
191+
GlobalC::GridD,
191192
&this->pv,
192193
this->pelec->pot,
193194
this->kv,

source/module_esolver/lcao_others.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
128128
// (2)For each atom, calculate the adjacent atoms in different cells
129129
// and allocate the space for H(R) and S(R).
130130
// If k point is used here, allocate HlocR after atom_arrange.
131-
this->RA.for_2d(this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
131+
this->RA.for_2d(GlobalC::GridD, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
132132

133133
// 2. density matrix extrapolation
134134

@@ -189,6 +189,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
189189
this->p_hamilt = new hamilt::HamiltLCAO<TK, TR>(
190190
PARAM.globalv.gamma_only_local ? &(this->GG) : nullptr,
191191
PARAM.globalv.gamma_only_local ? nullptr : &(this->GK),
192+
GlobalC::GridD,
192193
&this->pv,
193194
this->pelec->pot,
194195
this->kv,

0 commit comments

Comments
 (0)