Skip to content

Commit 4686033

Browse files
committed
refactor: add pw_basis for esolver_fp
fix: Makefile cannot compile change the name of repeated files: hamilt_pw.cpp diago_cg.cpp diago_david.cpp basis_pw.cpp to hamilt_pw_old.cpp diago_cg_old.cpp diago_david_old.cpp basis_pw_old.cpp
1 parent e5f1af2 commit 4686033

File tree

20 files changed

+122
-67
lines changed

20 files changed

+122
-67
lines changed

source/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ VPATH=./src_global\
1414
:./module_cell\
1515
:./module_base\
1616
:./module_md\
17+
:./module_pw\
1718
:./module_surchem\
1819
:./module_deepks\
1920
:./module_xc\
2021
:./module_esolver\
22+
:./module_hsolver\
23+
:./module_elecstate\
24+
:./module_psi\
25+
:./module_hamilt\
2126
:./src_pw\
2227
:./src_lcao\
2328
:./src_ions\

source/Makefile.Objects

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,47 @@ xc_functional_wrapper_tauxc.o \
260260
xc_functional_wrapper_xc.o \
261261
xc_functional.o \
262262

263+
OBJ_PLANEWAVE=fft.o\
264+
pw_basis.o\
265+
pw_basis_k.o\
266+
pw_distributeg.o\
267+
pw_distributeg_method1.o\
268+
pw_distributeg_method2.o\
269+
pw_distributer.o\
270+
pw_init.o\
271+
pw_operation.o\
272+
pw_transform.o\
273+
pw_transform_k.o
274+
275+
OBJ_HSOLVER=diago_blas.o\
276+
diago_cg.o\
277+
diago_david.o\
278+
diago_elpa.o\
279+
diago_iter_assist.o\
280+
hsolver_lcao.o\
281+
hsolver_pw.o\
282+
283+
OBJ_ELECSTATES=elecstate.o\
284+
dm2d_to_grid.o\
285+
elecstate_lcao.o\
286+
elecstate_pw.o\
287+
288+
OBJ_PSI=psi.o
289+
290+
OBJ_HAMILT=hamilt_lcao.o\
291+
hamilt_pw.o
292+
263293
OBJS_FIRST_PRINCIPLES=$(OBJS_MAIN)\
264294
$(OBJS_PW)\
265295
$(OBJS_LCAO)\
266296
$(OBJS_ESOLVER)\
267297
$(OBJS_XC)\
268298
$(OBJS_SURCHEM)\
299+
$(OBJ_PLANEWAVE)\
300+
$(OBJ_HSOLVER)\
301+
$(OBJ_ELECSTATES)\
302+
$(OBJ_PSI)\
303+
${OBJ_HAMILT}\
269304
charge.o \
270305
charge_mixing.o \
271306
charge_pulay.o \
@@ -323,14 +358,14 @@ dmft.o \
323358

324359
OBJS_COMMON=atom_spec.o \
325360
unitcell.o \
326-
pw_basis.o\
361+
pw_basis_old.o\
327362
bspline_sf.o\
328363
hamilt.o \
329364
pw_complement.o\
330365
wf_local.o \
331-
hamilt_pw.o \
332-
diago_david.o\
333-
diago_cg.o\
366+
hamilt_pw_old.o \
367+
diago_david_old.o\
368+
diago_cg_old.o\
334369
output.o \
335370
run_md_classic.o\
336371
LJ_potential.o\

source/module_elecstate/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ remove_definitions(-D__ROCM)
66
AddTest(
77
TARGET EState_updaterhok_pw
88
LIBS ${math_libs} base
9-
SOURCES updaterhok_pw_test.cpp ../../src_pw/charge.cpp ../../src_parallel/parallel_reduce.cpp ../../src_parallel/ft.cpp ../../src_pw/pw_basis.cpp ../../src_pw/pw_complement.cpp ../../src_pw/klist.cpp ../../src_parallel/parallel_kpoints.cpp ../../src_pw/occupy.cpp ../../module_elecstate/elecstate_pw.cpp ../../module_elecstate/elecstate.cpp
9+
SOURCES updaterhok_pw_test.cpp ../../src_pw/charge.cpp ../../src_parallel/parallel_reduce.cpp ../../src_parallel/ft.cpp ../../src_pw/pw_basis_old.cpp ../../src_pw/pw_complement.cpp ../../src_pw/klist.cpp ../../src_parallel/parallel_kpoints.cpp ../../src_pw/occupy.cpp ../../module_elecstate/elecstate_pw.cpp ../../module_elecstate/elecstate.cpp
1010
)
1111

1212
install(DIRECTORY support DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "esolver_fp.h"
2+
#include "../module_base/global_variable.h"
3+
namespace ModuleESolver
4+
{
5+
void ESolver_FP::Init(Input& inp, UnitCell_pseudo& cell)
6+
{
7+
this->pw_rho.initgrids(cell.lat0, cell.latvec, 4 * inp.ecutwfc, GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL);
8+
this->pw_rho.initparameters(false, 4 * inp.ecutwfc);
9+
this->pw_rho.setuptransform();
10+
this->pw_rho.collect_local_pw();
11+
}
12+
}

source/module_esolver/esolver_fp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#ifndef ESOLVER_FP_H
22
#define ESOLVER_FP_H
33
#include "./esolver.h"
4+
#include "../module_pw/pw_basis.h"
45
// #include "hamilt.h"
56
namespace ModuleESolver
67
{
78
class ESolver_FP : public ESolver
89
{
910
public:
11+
ModulePW::PW_Basis pw_rho;
12+
virtual void Init(Input& inp, UnitCell_pseudo& cell) override;
1013
// Hamilt* phamilt;
1114
};
1215
}

source/module_pw/pw_basis.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ class PW_Basis
5353

5454
//Init the grids for FFT
5555
void initgrids(
56-
double lat0_in, //unit length (unit in bohr)
57-
ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0)
58-
double gridecut, //unit in Ry, ecut to set up grids
59-
int poolnproc_in, // Number of processors in this pool
60-
int poolrank_in // Rank in this pool
56+
const double lat0_in, //unit length (unit in bohr)
57+
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0)
58+
const double gridecut, //unit in Ry, ecut to set up grids
59+
const int poolnproc_in, // Number of processors in this pool
60+
const int poolrank_in // Rank in this pool
6161
);
6262
//Init the grids for FFT
6363
void initgrids(
64-
double lat0_in,
65-
ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
66-
int nx_in, int bigny_in, int nz_in,
67-
int poolnproc_in, // Number of processors in this pool
68-
int poolrank_in // Rank in this pool
64+
const double lat0_in,
65+
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
66+
const int nx_in, int bigny_in, int nz_in,
67+
const int poolnproc_in, // Number of processors in this pool
68+
const int poolrank_in // Rank in this pool
6969
);
7070

7171
//Init some parameters
7272
void initparameters(
73-
bool gamma_only_in,
74-
double pwecut_in, //unit in Ry, ecut to decides plane waves
75-
int distribution_type_in
73+
const bool gamma_only_in,
74+
const double pwecut_in, //unit in Ry, ecut to decides plane waves
75+
const int distribution_type_in = 1
7676
);
7777

7878
//===============================================
@@ -112,7 +112,8 @@ class PW_Basis
112112

113113
//distribute plane waves and grids and set up fft
114114
void setuptransform();
115-
115+
116+
protected:
116117
//distribute plane waves to different processors
117118
void distribute_g();
118119

@@ -123,7 +124,7 @@ class PW_Basis
123124
void getstartgr();
124125

125126

126-
127+
public:
127128
//prepare for transforms between real and reciprocal spaces
128129
void collect_local_pw();
129130

@@ -147,6 +148,7 @@ class PW_Basis
147148
int poolrank;
148149
//distribute plane waves to different processors
149150

151+
protected:
150152
//method 1: first consider number of plane waves
151153
void distribution_method1();
152154
// Distribute sticks to cores in method 1.
@@ -218,6 +220,7 @@ class PW_Basis
218220
void recip2real(std::complex<float> * in, float *out); //in:(nz, ns) ; out(nplane,nx*ny)
219221
void recip2real(std::complex<float> * in, std::complex<float> * out); //in:(nz, ns) ; out(nplane,nx*ny)
220222
#endif
223+
protected:
221224
//gather planes and scatter sticks of all processors
222225
template<typename T>
223226
void gatherp_scatters(std::complex<T> *in, std::complex<T> *out);

source/module_pw/pw_basis_k.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ PW_Basis_K::~PW_Basis_K()
2020
}
2121

2222
void PW_Basis_K:: initparameters(
23-
bool gamma_only_in,
24-
double gk_ecut_in,
25-
int nks_in, //number of k points in this pool
26-
ModuleBase::Vector3<double> *kvec_d_in, // Direct coordinates of k points
27-
int distribution_type_in
23+
const bool gamma_only_in,
24+
const double gk_ecut_in,
25+
const int nks_in, //number of k points in this pool
26+
const ModuleBase::Vector3<double> *kvec_d_in, // Direct coordinates of k points
27+
const int distribution_type_in
2828
)
2929
{
3030
this->nks = nks_in;

source/module_pw/pw_basis_k.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class PW_Basis_K : public PW_Basis
4949

5050
//init parameters of pw_basis_k class
5151
void initparameters(
52-
bool gamma_only_in,
53-
double ecut_in,
54-
int nk_in, //number of k points in this pool
55-
ModuleBase::Vector3<double> *kvec_d, // Direct coordinates of k points
56-
int distribution_type_in
52+
const bool gamma_only_in,
53+
const double ecut_in,
54+
const int nk_in, //number of k points in this pool
55+
const ModuleBase::Vector3<double> *kvec_d, // Direct coordinates of k points
56+
const int distribution_type_in
5757
);
5858

5959

@@ -68,15 +68,16 @@ class PW_Basis_K : public PW_Basis
6868
public:
6969
//prepare for transforms between real and reciprocal spaces
7070
void setuptransform();
71-
72-
//create igl2isz_k map array for fft
73-
void setupIndGk();
7471

7572
int *igl2isz_k; //[npwk_max*nks] map (ig,ik) to (is,iz)
7673

7774
//create Direct coordinate, Cartesian coordinate, norm2 of plane waves in each processor
7875
void collect_local_pw();
7976

77+
private:
78+
//create igl2isz_k map array for fft
79+
void setupIndGk();
80+
8081
public:
8182
void real2recip(double * in, std::complex<double> * out, int ik); //in:(nplane,nx*ny) ; out(nz, ns)
8283
void real2recip(std::complex<double> * in, std::complex<double> * out, int ik); //in:(nplane,nx*ny) ; out(nz, ns)

source/module_pw/pw_init.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace ModulePW
1313
/// Output: nx, ny, nz, nxyz, latvec, G, GT, GGT
1414
///
1515
void PW_Basis:: initgrids(
16-
double lat0_in, //unit length (unit in bohr)
17-
ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
18-
double gridecut,
19-
int poolnproc_in,
20-
int poolrank_in
16+
const double lat0_in, //unit length (unit in bohr)
17+
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
18+
const double gridecut,
19+
const int poolnproc_in,
20+
const int poolrank_in
2121
)
2222
{
2323
//init lattice
@@ -34,24 +34,24 @@ void PW_Basis:: initgrids(
3434
//-------------------------init grids-------------------------
3535
//------------------------------------------------------------
3636
double tpiba2 = ModuleBase::TWO_PI * ModuleBase::TWO_PI / this->lat0 / this->lat0;
37-
gridecut = gridecut / tpiba2;
37+
const double gridecut_lat = gridecut / tpiba2;
3838
ModuleBase::Vector3<double> lat;
3939
int *ibox = new int[3];// ibox[i] are the minimal FFT dimensions,
4040

4141
lat.x = latvec.e11;
4242
lat.y = latvec.e12;
4343
lat.z = latvec.e13;
44-
ibox[0] = int(sqrt(gridecut) * sqrt(lat * lat)) + 1;
44+
ibox[0] = int(sqrt(gridecut_lat) * sqrt(lat * lat)) + 1;
4545

4646
lat.x = latvec.e21;
4747
lat.y = latvec.e22;
4848
lat.z = latvec.e23;
49-
ibox[1] = int(sqrt(gridecut) * sqrt(lat * lat)) + 1;
49+
ibox[1] = int(sqrt(gridecut_lat) * sqrt(lat * lat)) + 1;
5050

5151
lat.x = latvec.e31;
5252
lat.y = latvec.e32;
5353
lat.z = latvec.e33;
54-
ibox[2] = int(sqrt(gridecut) * sqrt(lat * lat)) + 1;
54+
ibox[2] = int(sqrt(gridecut_lat) * sqrt(lat * lat)) + 1;
5555

5656
int n1,n2,n3;
5757
n1 = n2 = n3 = 0;
@@ -66,7 +66,7 @@ void PW_Basis:: initgrids(
6666
f.y = igy;
6767
f.z = igz;
6868
double modulus = f * (this->GGT * f);
69-
if(modulus <= gridecut)
69+
if(modulus <= gridecut_lat)
7070
{
7171
if(n1 < abs(igx)) n1 = abs(igx);
7272
if(n2 < abs(igy)) n2 = abs(igy);
@@ -146,11 +146,11 @@ void PW_Basis:: initgrids(
146146
/// Output: nx, ny, nz, nxyz, latvec, G, GT, GGT
147147
///
148148
void PW_Basis:: initgrids(
149-
double lat0_in,
150-
ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
151-
int nx_in, int bigny_in, int nz_in,
152-
int poolnproc_in,
153-
int poolrank_in
149+
const double lat0_in,
150+
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
151+
const int nx_in, int bigny_in, int nz_in,
152+
const int poolnproc_in,
153+
const int poolrank_in
154154
)
155155
{
156156
this->lat0 = lat0_in;
@@ -172,9 +172,9 @@ void PW_Basis:: initgrids(
172172

173173
//Init some parameters
174174
void PW_Basis:: initparameters(
175-
bool gamma_only_in,
176-
double pwecut_in,
177-
int distribution_type_in
175+
const bool gamma_only_in,
176+
const double pwecut_in,
177+
const int distribution_type_in
178178
)
179179
{
180180
this->gamma_only = gamma_only_in;

source/module_pw/test/test1-1-1.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ TEST_F(PWTEST,test1_1_1)
2525

2626
pwtest.initgrids(lat0, latvec, wfcecut,nproc_in_pool, rank_in_pool);
2727
pwtest.initparameters(gamma_only, wfcecut, distribution_type);
28-
pwtest.distribute_r();
29-
pwtest.distribute_g();
28+
pwtest.setuptransform();
3029
pwtest.collect_local_pw();
3130
ModuleBase::Matrix3 GT,G,GGT;
3231
GT = latvec.Inverse();

0 commit comments

Comments
 (0)