@@ -129,7 +129,56 @@ psi::Psi<std::complex<double>>* PsiInitializer<T, Device>::allocate(const bool o
129129}
130130
131131template <typename T, typename Device>
132- void PsiInitializer<T, Device>::random_t (T* psi, const int iw_start, const int iw_end, const int ik)
132+ void PsiInitializer<T, Device>::_random_t_serial_impl(T* psi,
133+ const int iw_start,
134+ const int iw_end,
135+ const int ik)
136+ {
137+ assert (iw_start >= 0 );
138+ const int ng = this ->pw_wfc_ ->npwk [ik];
139+ if (PARAM.inp .pw_seed > 0 ) // qianrui add 2021-8-13
140+ {
141+ srand (unsigned (PARAM.inp .pw_seed + ik));
142+ }
143+ for (int iw = iw_start; iw < iw_end; iw++)
144+ {
145+ T* psi_slice = &(psi[iw * this ->pw_wfc_ ->npwk_max * PARAM.globalv .npol ]);
146+ for (int ig = 0 ; ig < ng; ig++)
147+ {
148+ const double rr = std::rand () / double (RAND_MAX); // qianrui add RAND_MAX
149+ const double arg = ModuleBase::TWO_PI * std::rand () / double (RAND_MAX);
150+ const double gk2 = this ->pw_wfc_ ->getgk2 (ik, ig);
151+ psi_slice[ig] = this ->template cast_to_T <T>(
152+ std::complex <double >(rr*cos (arg)/(gk2 + 1.0 ), rr*sin (arg)/(gk2 + 1.0 )));
153+ }
154+ if (PARAM.globalv .npol == 2 ) // if npol = 2, then fill the second polarization
155+ {
156+ for (int ig = this ->pw_wfc_ ->npwk_max ; ig < this ->pw_wfc_ ->npwk_max + ng; ig++)
157+ {
158+ const double rr = std::rand () / double (RAND_MAX);
159+ const double arg = ModuleBase::TWO_PI * std::rand () / double (RAND_MAX);
160+ const double gk2 = this ->pw_wfc_ ->getgk2 (ik, ig - this ->pw_wfc_ ->npwk_max );
161+ psi_slice[ig] = this ->template cast_to_T <T>(
162+ std::complex <double >(rr*cos (arg)/(gk2 + 1.0 ), rr*sin (arg)/(gk2 + 1.0 )));
163+ }
164+ }
165+ }
166+ }
167+
168+ template <typename T, typename Device>
169+ void PsiInitializer<T, Device>::_random_t_pal_impl(T* psi,
170+ const int iw_start,
171+ const int iw_end,
172+ const int ik)
173+ {
174+
175+ }
176+
177+ template <typename T, typename Device>
178+ void PsiInitializer<T, Device>::random_t (T* psi,
179+ const int iw_start,
180+ const int iw_end,
181+ const int ik)
133182{
134183 ModuleBase::timer::tick (" PsiInitializer" , " random_t" );
135184 assert (iw_start >= 0 );
0 commit comments