7void get_wf_pw(
const std::vector<int>& out_wfc_norm,
8 const std::vector<int>& out_wfc_re_im,
13 const psi::Psi<std::complex<double>, Device>* kspw_psi,
17 const std::string& global_out_dir,
27 for (
int ip = 0; ip < kpar; ++ip)
35 std::vector<int> bands_picked_norm(nbands, 0);
36 std::vector<int> bands_picked_re_im(nbands, 0);
39 if (
static_cast<int>(out_wfc_norm.size()) > nbands ||
static_cast<int>(out_wfc_re_im.size()) > nbands)
42 "The number of bands specified by `out_wfc_norm` or `out_wfc_re_im` in the "
43 "INPUT file exceeds `nbands`!");
47 for (
int value: out_wfc_norm)
49 if (value != 0 && value != 1)
52 "The elements of `out_wfc_norm` must be either 0 or 1. "
53 "Invalid values found!");
56 for (
int value: out_wfc_re_im)
58 if (value != 0 && value != 1)
61 "The elements of `out_wfc_re_im` must be either 0 or 1. "
62 "Invalid values found!");
68 int length = std::min(
static_cast<int>(out_wfc_norm.size()), nbands);
69 for (
int i = 0; i < length; ++i)
72 bands_picked_norm[i] =
static_cast<int>(out_wfc_norm[i]);
74 length = std::min(
static_cast<int>(out_wfc_re_im.size()), nbands);
75 for (
int i = 0; i < length; ++i)
77 bands_picked_re_im[i] =
static_cast<int>(out_wfc_re_im[i]);
81 std::vector<std::complex<double>> wfcr_norm(nxyz);
82 std::vector<std::vector<double>> rho_band_norm(nspin, std::vector<double>(nxyz));
85 std::complex<double>* wfcr_norm_device =
nullptr;
86 if (!std::is_same<Device, base_device::DEVICE_CPU>::value)
91 for (
int ib = 0; ib < nbands; ++ib)
94 if (!bands_picked_norm[ib])
99 for (
int is = 0; is < nspin; ++is)
101 std::fill(rho_band_norm[is].begin(), rho_band_norm[is].end(), 0.0);
103 for (
int ik = 0; ik < nks; ++ik)
106 const int spin_index = kv.
isk[ik];
107 const int k_number = ikstot % (nkstot / nspin) + 1;
112 if (std::is_same<Device, base_device::DEVICE_CPU>::value)
114 pw_wfc->
recip_to_real(ctx, &kspw_psi[0](ib, 0), wfcr_norm.data(), ik);
118 pw_wfc->
recip_to_real(ctx, &kspw_psi[0](ib, 0), wfcr_norm_device, ik);
127 double wg_sum_k = 0.0;
139 "Real space wavefunction output currently do not support noncollinear "
140 "polarized calculation (nspin = 4)!");
143 double w1 =
static_cast<double>(wg_sum_k / ucell->
omega);
145 for (
int i = 0; i < nxyz; ++i)
147 rho_band_norm[spin_index][i] = std::abs(wfcr_norm[i]) * std::sqrt(w1);
150 std::stringstream ss_file;
151 ss_file << global_out_dir <<
"wfi" << ib + 1 <<
"s" << spin_index + 1 <<
"k" << k_number <<
".cube";
154 rho_band_norm[spin_index].data(),
168 std::vector<std::complex<double>> wfc_re_im(nxyz);
169 std::vector<std::vector<double>> rho_band_re(nspin, std::vector<double>(nxyz));
170 std::vector<std::vector<double>> rho_band_im(nspin, std::vector<double>(nxyz));
173 std::complex<double>* wfc_re_im_device =
nullptr;
174 if (!std::is_same<Device, base_device::DEVICE_CPU>::value)
179 for (
int ib = 0; ib < nbands; ++ib)
182 if (!bands_picked_re_im[ib])
187 for (
int is = 0; is < nspin; ++is)
189 std::fill(rho_band_re[is].begin(), rho_band_re[is].end(), 0.0);
190 std::fill(rho_band_im[is].begin(), rho_band_im[is].end(), 0.0);
192 for (
int ik = 0; ik < nks; ++ik)
195 const int spin_index = kv.
isk[ik];
196 const int k_number = ikstot % (nkstot / nspin) + 1;
201 if (std::is_same<Device, base_device::DEVICE_CPU>::value)
203 pw_wfc->
recip_to_real(ctx, &kspw_psi[0](ib, 0), wfc_re_im.data(), ik);
207 pw_wfc->
recip_to_real(ctx, &kspw_psi[0](ib, 0), wfc_re_im_device, ik);
216 double wg_sum_k = 0.0;
228 "Real space wavefunction output currently do not support noncollinear "
229 "polarized calculation (nspin = 4)!");
232 double w1 =
static_cast<double>(wg_sum_k / ucell->
omega);
234 for (
int i = 0; i < nxyz; ++i)
236 rho_band_re[spin_index][i] = std::real(wfc_re_im[i]) * std::sqrt(w1);
237 rho_band_im[spin_index][i] = std::imag(wfc_re_im[i]) * std::sqrt(w1);
240 std::stringstream ss_real;
241 ss_real << global_out_dir <<
"wfi" << ib + 1 <<
"s" << spin_index + 1 <<
"k" << k_number <<
"re.cube";
244 rho_band_re[spin_index].data(),
255 std::stringstream ss_imag;
256 ss_imag << global_out_dir <<
"wfi" << ib + 1 <<
"s" << spin_index + 1 <<
"k" << k_number <<
"im.cube";
259 rho_band_im[spin_index].data(),
void get_wf_pw(const std::vector< int > &out_wfc_norm, const std::vector< int > &out_wfc_re_im, const int nbands, const int nspin, const int nxyz, UnitCell *ucell, const psi::Psi< std::complex< double >, Device > *kspw_psi, const ModulePW::PW_Basis_K *pw_wfc, const Device *ctx, const Parallel_Grid &pgrid, const std::string &global_out_dir, const K_Vectors &kv, const int kpar, const int my_pool)
Definition get_wf_pw.h:7
void write_vdata_palgrid(const Parallel_Grid &pgrid, const double *const data, const int is, const int nspin, const int iter, const std::string &fn, const double ef, const UnitCell *const ucell, const int precision=11, const int out_fermi=1, const bool reduce_all_pool=false)
write volumetric data on the parallized grid into a .cube file
Definition write_cube.cpp:15