Skip to content

Commit 4f4b1d8

Browse files
wenfei-liwenfei-li
andauthored
Feature : support PAW in PW calculations (in progress) (#2891)
* Feature : add paw_vnl_psi and test * Feature : added (S+I)|psi> * add input variable "use_paw" * added global class paw_cell * fix some bugs * fix macro and cmake * fix cmake * fix cmake * add set_paw_k and init_paw_cell in main program * put get_vkb into main program * added accumulate_rhoij to main program * added set_rhoij * added prepare_libpaw * add set_rho_core_paw * added init_rho * fix test_paw3 * modify preparation of paw * add get_nhat * change ecut * bug fix * fix bug * fix some errors * modify v_hartree * fix bug * fix bug --------- Co-authored-by: wenfei-li <liwenfei@gmail.com>
1 parent 1158c14 commit 4f4b1d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+217194
-523
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,12 @@ target_link_libraries(${ABACUS_BIN_NAME}
612612
container
613613
)
614614

615+
if(ENABLE_PAW)
616+
target_link_libraries(${ABACUS_BIN_NAME}
617+
paw
618+
)
619+
endif()
620+
615621
if(ENABLE_LCAO)
616622
target_link_libraries(${ABACUS_BIN_NAME}
617623
hamilt_lcao

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ OBJS_ELECSTAT=elecstate.o\
176176
potential_new.o\
177177
potential_types.o\
178178
pot_local.o\
179+
pot_local_paw.o\
179180
H_Hartree_pw.o\
180181
H_TDDFT_pw.o\
181182
pot_xc.o\

source/module_base/global_variable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ int RELAX_NMAX = 20;
6060
int md_prec_level = 0;
6161
int SCF_NMAX = 100;
6262

63+
bool use_paw = false;
64+
6365
std::string BASIS_TYPE = "pw"; // xiaohui add 2013-09-01
6466
std::string KS_SOLVER = "cg"; // xiaohui add 2013-09-01
6567
double SEARCH_RADIUS = -1.0;

source/module_base/global_variable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extern int OUT_FREQ_ION;
5858
extern double relax_scale_force;
5959
extern bool relax_new;
6060

61+
extern bool use_paw;
62+
6163
extern bool fixed_atoms;
6264

6365
extern int RELAX_NMAX; // 8.3

source/module_basis/module_pw/pw_basis_k.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,55 @@ void PW_Basis_K::get_ig2ixyz_k()
330330
#endif
331331
}
332332

333+
std::vector<int> PW_Basis_K::get_ig2ix(const int ik) const
334+
{
335+
std::vector<int> ig_to_ix;
336+
ig_to_ix.resize(npwk[ik]);
337+
338+
for(int ig = 0; ig < npwk[ik]; ig++)
339+
{
340+
int isz = this->igl2isz_k[ig + ik * npwk_max];
341+
int is = isz / this->nz;
342+
int ixy = this->is2fftixy[is];
343+
int ix = ixy / this->ny;
344+
if (ix < (nx / 2) + 1) ix += nx;
345+
ig_to_ix[ig] = ix;
346+
}
347+
return ig_to_ix;
348+
}
349+
350+
std::vector<int> PW_Basis_K::get_ig2iy(const int ik) const
351+
{
352+
std::vector<int> ig_to_iy;
353+
ig_to_iy.resize(npwk[ik]);
354+
355+
for(int ig = 0; ig < npwk[ik]; ig++)
356+
{
357+
int isz = this->igl2isz_k[ig + ik * npwk_max];
358+
int is = isz / this->nz;
359+
int ixy = this->is2fftixy[is];
360+
int iy = ixy % this->ny;
361+
if (iy < (ny / 2) + 1) iy += ny;
362+
ig_to_iy[ig] = iy;
363+
}
364+
return ig_to_iy;
365+
}
366+
367+
std::vector<int> PW_Basis_K::get_ig2iz(const int ik) const
368+
{
369+
std::vector<int> ig_to_iz;
370+
ig_to_iz.resize(npwk[ik]);
371+
372+
for(int ig = 0; ig < npwk[ik]; ig++)
373+
{
374+
int isz = this->igl2isz_k[ig + ik * npwk_max];
375+
int iz = isz % this->nz;
376+
if (iz < (nz / 2) + 1) iz += nz;
377+
ig_to_iz[ig] = iz;
378+
}
379+
return ig_to_iz;
380+
}
381+
333382
template <>
334383
float * PW_Basis_K::get_kvec_c_data() const {
335384
return this->s_kvec_c;

source/module_basis/module_pw/pw_basis_k.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ class PW_Basis_K : public PW_Basis
156156
//get igl2ig_k or igk(ik,ig) in older ABACUS
157157
int& getigl2ig(const int ik, const int igl) const;
158158

159+
//get ig_to_ix
160+
std::vector<int> get_ig2ix(const int ik) const;
161+
//get ig_to_iy
162+
std::vector<int> get_ig2iy(const int ik) const;
163+
//get ig_to_iz
164+
std::vector<int> get_ig2iz(const int ik) const;
165+
159166
template <typename FPTYPE> FPTYPE * get_gk2_data() const;
160167
template <typename FPTYPE> FPTYPE * get_gcar_data() const;
161168
template <typename FPTYPE> FPTYPE * get_kvec_c_data() const;

source/module_cell/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
add_subdirectory(module_symmetry)
22
add_subdirectory(module_neighbor)
3-
add_subdirectory(module_paw)
3+
if(ENABLE_PAW)
4+
add_subdirectory(module_paw)
5+
endif()
46

57
add_library(
68
cell

source/module_cell/module_paw/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ add_library(
55
paw_sphbes.cpp
66
paw_cell.cpp
77
paw_cell_libpaw.cpp
8+
paw_atom.cpp
89
)
910

11+
target_link_libraries(paw libpaw_interface -lifcore)
12+
add_dependencies(paw libpaw_interface)
13+
1014
if(ENABLE_COVERAGE)
1115
add_coverage(paw)
1216
endif()

source/module_cell/module_paw/paw_atom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void Paw_Atom::convert_rhoij()
5959
{
6060
if(std::abs(rhoij[i]) > 1e-10)
6161
{
62-
rhoijselect[nrhoijsel] = i;
62+
rhoijselect[nrhoijsel] = i+1; //index in fortran
6363
rhoijp[nrhoijsel] = rhoij[i];
6464
nrhoijsel ++;
6565
}

source/module_cell/module_paw/paw_cell.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#include "paw_cell.h"
22
#include "module_base/tool_title.h"
33
#include "module_base/tool_quit.h"
4+
#ifdef __MPI
5+
#include "module_base/parallel_reduce.h"
6+
#endif
7+
8+
namespace GlobalC
9+
{
10+
Paw_Cell paw_cell;
11+
}
412

513
void Paw_Cell::init_paw_cell(
614
const double ecutwfc_in, const double cell_factor_in,
715
const double omega_in,
816
const int nat_in, const int ntyp_in,
917
const int * atom_type_in, const double ** atom_coord_in,
10-
const std::vector<std::string> & filename_list_in,
11-
const int nx_in, const int ny_in, const int nz_in,
12-
const std::complex<double> * eigts1_in, const std::complex<double> * eigts2_in, const std::complex<double> * eigts3_in)
18+
const std::vector<std::string> & filename_list_in)
1319
{
1420
ModuleBase::TITLE("Paw_Element","init_paw_cell");
1521

1622
this -> nat = nat_in;
1723
this -> ntyp = ntyp_in;
18-
this -> nx = nx_in;
19-
this -> ny = ny_in;
20-
this -> nz = nz_in;
2124
this -> omega = omega_in;
2225

2326
atom_coord.resize(nat);
@@ -71,6 +74,16 @@ void Paw_Cell::init_paw_cell(
7174
int nproj = paw_element_list[it].get_mstates();
7275
paw_atom_list[iat].init_paw_atom(nproj);
7376
}
77+
}
78+
79+
void Paw_Cell::set_eigts(const int nx_in, const int ny_in, const int nz_in,
80+
const std::complex<double> * eigts1_in,
81+
const std::complex<double> * eigts2_in,
82+
const std::complex<double> * eigts3_in)
83+
{
84+
this -> nx = nx_in;
85+
this -> ny = ny_in;
86+
this -> nz = nz_in;
7487

7588
eigts1.resize(nat);
7689
eigts2.resize(nat);
@@ -422,6 +435,14 @@ void Paw_Cell::get_vkb()
422435
}
423436
}
424437

438+
void Paw_Cell::reset_rhoij()
439+
{
440+
for(int iat = 0; iat < nat; iat ++)
441+
{
442+
paw_atom_list[iat].reset_rhoij();
443+
}
444+
}
445+
425446
void Paw_Cell::accumulate_rhoij(const std::complex<double> * psi, const double weight)
426447
{
427448
ModuleBase::TITLE("Paw_Cell","accumulate_rhoij");
@@ -451,9 +472,9 @@ void Paw_Cell::accumulate_rhoij(const std::complex<double> * psi, const double w
451472
}
452473
}
453474

454-
// ca should be summed over MPI ranks since planewave basis is distributed
455-
// but not for now (I'll make sure serial version works first)
456-
// Parallel_Reduce::reduce_complex_double_pool(ca.data(), nproj);
475+
#ifdef __MPI
476+
Parallel_Reduce::reduce_complex_double_pool(ca.data(), nproj);
477+
#endif
457478

458479
paw_atom_list[iat].set_ca(ca, weight);
459480
paw_atom_list[iat].accumulate_rhoij();
@@ -530,9 +551,9 @@ void Paw_Cell::paw_nl_psi(const int mode, const std::complex<double> * psi, std:
530551
}
531552
}
532553

533-
// ca should be summed over MPI ranks since planewave basis is distributed
534-
// but not for now (I'll make sure serial version works first)
535-
// Parallel_Reduce::reduce_complex_double_pool(ca.data(), nproj);
554+
#ifdef __MPI
555+
Parallel_Reduce::reduce_complex_double_pool(ca.data(), nproj);
556+
#endif
536557

537558
// sum_ij D_ij ca_j
538559
std::vector<std::complex<double>> v_ca;

0 commit comments

Comments
 (0)