diff --git a/source/source_basis/module_pw/pw_basis.h b/source/source_basis/module_pw/pw_basis.h index d476e59a54..4f30f5089d 100644 --- a/source/source_basis/module_pw/pw_basis.h +++ b/source/source_basis/module_pw/pw_basis.h @@ -97,6 +97,22 @@ class PW_Basis const bool xprime_in = true ); + //Serial basis assembly: the plain production sequence (initgrids -> + //initparameters -> default FFT mode -> setuptransform -> collect_local_pw) + //without any parallel/device context (no initmpi, default distribution). + //NOTE: this no-initmpi use requires the PW sources to be compiled + //without __MPI -- with __MPI the initgrids overloads reduce over this + //object's communicator, which is MPI_COMM_NULL on a fresh basis that + //never called initmpi. The reusable form of the setup chain for serial + //utilities and unit tests (compiled with __MPI disabled, like the DFPT + //serial test targets); the parallel production path stays in + //setup_pwrho. + void init_serial( + const double lat0_in, //unit length (unit in bohr) + const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0) + const double gridecut //unit in Ry, ecut to set up grids + ); + //Set parameters about full planewave, only used in OFDFT for now. void setfullpw( const bool inpt_full_pw = false, diff --git a/source/source_basis/module_pw/pw_basis_k.cpp b/source/source_basis/module_pw/pw_basis_k.cpp index 2c2d02bf92..3b15a0c16f 100644 --- a/source/source_basis/module_pw/pw_basis_k.cpp +++ b/source/source_basis/module_pw/pw_basis_k.cpp @@ -529,4 +529,20 @@ double* PW_Basis_K::get_gk2_data() const return this->d_gk2; } +void PW_Basis_K::init_serial(const double lat0_in, + const ModuleBase::Matrix3 latvec_in, + const int nx_in, + const int ny_in, + const int nz_in, + const double ecut_in, + const int nk_in, + const ModuleBase::Vector3* kvec_d) +{ + initgrids(lat0_in, latvec_in, nx_in, ny_in, nz_in); + initparameters(false, ecut_in, nk_in, kvec_d); + this->fft_bundle.initfftmode(0); + setuptransform(); + collect_local_pw(); +} + } // namespace ModulePW \ No newline at end of file diff --git a/source/source_basis/module_pw/pw_basis_k.h b/source/source_basis/module_pw/pw_basis_k.h index 65e332b8a2..1a5e9cc825 100644 --- a/source/source_basis/module_pw/pw_basis_k.h +++ b/source/source_basis/module_pw/pw_basis_k.h @@ -70,6 +70,27 @@ class PW_Basis_K : public PW_Basis const bool xprime_in = true ); + //Serial basis assembly on a given FFT box (usually the rho grid's + //nx/ny/nz so the two bases share the box): initgrids -> initparameters + //with the k list -> default FFT mode -> setuptransform -> + //collect_local_pw, without any parallel/device context. NOTE: this + //no-initmpi use requires the PW sources to be compiled without __MPI + //-- with __MPI the initgrids overloads reduce over this object's + //communicator, which is MPI_COMM_NULL on a fresh basis that never + //called initmpi. The reusable form of the setup chain for serial + //utilities and unit tests (compiled with __MPI disabled, like the + //DFPT serial test targets); the parallel production path stays in + //setup_pwwfc. + void init_serial( + const double lat0_in, + const ModuleBase::Matrix3 latvec_in, + const int nx_in, + const int ny_in, + const int nz_in, + const double ecut_in, + const int nk_in, + const ModuleBase::Vector3* kvec_d); + public: int nks=0;//number of k points in this pool ModuleBase::Vector3 *kvec_d=nullptr; // Direct coordinates of k points diff --git a/source/source_basis/module_pw/pw_init.cpp b/source/source_basis/module_pw/pw_init.cpp index 5240d35b12..d534214c8f 100644 --- a/source/source_basis/module_pw/pw_init.cpp +++ b/source/source_basis/module_pw/pw_init.cpp @@ -235,13 +235,26 @@ void PW_Basis:: initparameters( this->ggecut = pwecut_in / this->tpiba2; //ggecut should be no larger than gridecut - if(this->ggecut > this->gridecut_lat) + if(this->ggecut > this->gridecut_lat) { this->ggecut = this->gridecut_lat; } this->distribution_type = distribution_type_in; } +void PW_Basis:: init_serial( + const double lat0_in, + const ModuleBase::Matrix3 latvec_in, + const double gridecut +) +{ + initgrids(lat0_in, latvec_in, gridecut); + initparameters(false, gridecut); + this->fft_bundle.initfftmode(0); + setuptransform(); + collect_local_pw(); +} + // Set parameters about full planewave, used only in OFDFT for now. sunliang added 2022-08-30 void PW_Basis::setfullpw( const bool inpt_full_pw, diff --git a/source/source_pw/module_dfpt/test_serial/dfpt_serial_fixture.cpp b/source/source_pw/module_dfpt/test_serial/dfpt_serial_fixture.cpp index aa8ed63926..24db0e4533 100644 --- a/source/source_pw/module_dfpt/test_serial/dfpt_serial_fixture.cpp +++ b/source/source_pw/module_dfpt/test_serial/dfpt_serial_fixture.cpp @@ -38,18 +38,12 @@ void DFPTSerialBase::SetupBases(const ModuleBase::Vector3& k_d, int nbands) { G_ = ucell_.G; - pw_rho_.initgrids(lat0_, latvec_, rho_mult_ * ecutwfc_); - pw_rho_.initparameters(false, rho_mult_ * ecutwfc_); - pw_rho_.fft_bundle.initfftmode(0); - pw_rho_.setuptransform(); - pw_rho_.collect_local_pw(); - + // the serial assembly chains live in the PW_Basis / PW_Basis_K + // sources (init_serial); this fixture only supplies the geometry + // and the (k, q) data + pw_rho_.init_serial(lat0_, latvec_, rho_mult_ * ecutwfc_); const ModuleBase::Vector3 klist[1] = {k_d}; - pw_wfc_.initgrids(lat0_, latvec_, pw_rho_.nx, pw_rho_.ny, pw_rho_.nz); - pw_wfc_.initparameters(false, ecutwfc_, 1, klist); - pw_wfc_.fft_bundle.initfftmode(0); - pw_wfc_.setuptransform(); - pw_wfc_.collect_local_pw(); + pw_wfc_.init_serial(lat0_, latvec_, pw_rho_.nx, pw_rho_.ny, pw_rho_.nz, ecutwfc_, 1, klist); qlist_.nkstot = 1; qlist_.kvec_d.clear();