@@ -25,7 +25,11 @@ void Evolve_OFDFT::cal_Hpsi(elecstate::ElecState* pelec,
2525 }
2626
2727 pelec->pot ->update_from_charge (&chr, &ucell); // Hartree + XC + external
28- this ->cal_tf_potential (chr.rho ,pw_rho ,pelec->pot ->get_effective_v ()); // TF potential
28+ this ->cal_tf_potential (chr.rho , pw_rho, pelec->pot ->get_effective_v ()); // TF potential
29+ if (PARAM.inp .of_cd )
30+ {
31+ this ->cal_CD_potential (psi_, pw_rho, pelec->pot ->get_effective_v (), PARAM.inp .of_mCD_alpha ); // CD potential
32+ }
2933
3034#ifdef _OPENMP
3135#pragma omp parallel for
@@ -72,6 +76,9 @@ void Evolve_OFDFT::cal_vw_potential_phi(std::vector<std::complex<double>> pphi,
7276 ModulePW::PW_Basis* pw_rho,
7377 std::vector<std::complex <double >> Hpsi)
7478{
79+ if (PARAM.inp .nspin <= 0 ) {
80+ ModuleBase::WARNING_QUIT (" Evolve_OFDFT" ," nspin must be positive" );
81+ }
7582 std::complex <double >** rLapPhi = new std::complex <double >*[PARAM.inp .nspin ];
7683#ifdef _OPENMP
7784#pragma omp parallel for
@@ -118,13 +125,96 @@ void Evolve_OFDFT::cal_vw_potential_phi(std::vector<std::complex<double>> pphi,
118125
119126void Evolve_OFDFT::cal_CD_potential (std::vector<std::complex <double >> psi_,
120127 ModulePW::PW_Basis* pw_rho,
121- ModuleBase::matrix& rpot)
128+ ModuleBase::matrix& rpot,
129+ double mCD_para )
122130{
131+ std::complex <double > imag (0.0 ,1.0 );
132+
133+ if (PARAM.inp .nspin <= 0 ) {
134+ ModuleBase::WARNING_QUIT (" Evolve_OFDFT" ," nspin must be positive" );
135+ }
136+ std::complex <double >** recipPhi = new std::complex <double >*[PARAM.inp .nspin ];
137+ std::complex <double >** rPhi = new std::complex <double >*[PARAM.inp .nspin ];
138+ #ifdef _OPENMP
139+ #pragma omp parallel for
140+ #endif
141+ for (int is = 0 ; is < PARAM.inp .nspin ; ++is) {
142+ rPhi[is] = new std::complex <double >[pw_rho->nrxx ];
143+ for (int ir = 0 ; ir < pw_rho->nrxx ; ++ir)
144+ {
145+ rPhi[is][ir]=psi_[is * pw_rho->nrxx + ir];
146+ }
147+ }
148+
149+ #ifdef _OPENMP
150+ #pragma omp parallel for
151+ #endif
123152 for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
124153 {
125- // recipCurrent = new std::complex<double>[pw_rho->npw];
126- // delete[] recipCurrent;
154+ std::complex <double > *recipCurrent_x=new std::complex <double >[pw_rho->npw ];
155+ std::complex <double > *recipCurrent_y=new std::complex <double >[pw_rho->npw ];
156+ std::complex <double > *recipCurrent_z=new std::complex <double >[pw_rho->npw ];
157+ std::complex <double > *recipCDPotential=new std::complex <double >[pw_rho->npw ];
158+ std::complex <double > *rCurrent_x=new std::complex <double >[pw_rho->nrxx ];
159+ std::complex <double > *rCurrent_y=new std::complex <double >[pw_rho->nrxx ];
160+ std::complex <double > *rCurrent_z=new std::complex <double >[pw_rho->nrxx ];
161+ std::complex <double > *kF_r =new std::complex <double >[pw_rho->nrxx ];
162+ std::complex <double > *rCDPotential=new std::complex <double >[pw_rho->nrxx ];
163+ recipPhi[is] = new std::complex <double >[pw_rho->npw ];
164+
165+ for (int ir = 0 ; ir < pw_rho->nrxx ; ++ir)
166+ {
167+ kF_r [ir]=std::pow (3 *std::pow (ModuleBase::PI*std::abs (rPhi[is][ir]),2 ),1 /3 );
168+ }
169+
170+ pw_rho->real2recip (rPhi[is], recipPhi[is]);
171+ for (int ik = 0 ; ik < pw_rho->npw ; ++ik)
172+ {
173+ recipCurrent_x[ik]=imag*pw_rho->gcar [ik].x *recipPhi[is][ik]* pw_rho->tpiba ;
174+ recipCurrent_y[ik]=imag*pw_rho->gcar [ik].y *recipPhi[is][ik]* pw_rho->tpiba ;
175+ recipCurrent_z[ik]=imag*pw_rho->gcar [ik].z *recipPhi[is][ik]* pw_rho->tpiba ;
176+ }
177+ pw_rho->recip2real (recipCurrent_x,rCurrent_x);
178+ pw_rho->recip2real (recipCurrent_y,rCurrent_y);
179+ pw_rho->recip2real (recipCurrent_z,rCurrent_z);
180+ for (int ir = 0 ; ir < pw_rho->nrxx ; ++ir)
181+ {
182+ rCurrent_x[ir]=std::imag (rCurrent_x[ir]*std::conj (rPhi[is][ir]));
183+ rCurrent_y[ir]=std::imag (rCurrent_y[ir]*std::conj (rPhi[is][ir]));
184+ rCurrent_z[ir]=std::imag (rCurrent_z[ir]*std::conj (rPhi[is][ir]));
185+ }
186+ pw_rho->real2recip (rCurrent_x,recipCurrent_x);
187+ pw_rho->real2recip (rCurrent_y,recipCurrent_y);
188+ pw_rho->real2recip (rCurrent_z,recipCurrent_z);
189+ for (int ik = 0 ; ik < pw_rho->npw ; ++ik)
190+ {
191+ recipCDPotential[ik]=recipCurrent_x[ik]*pw_rho->gcar [ik].x +recipCurrent_y[ik]*pw_rho->gcar [ik].y +recipCurrent_z[ik]*pw_rho->gcar [ik].z ;
192+ recipCDPotential[ik]*=imag/pw_rho->gg [ik];
193+ }
194+ pw_rho->recip2real (recipCDPotential,rCDPotential);
195+
196+ for (int ir = 0 ; ir < pw_rho->nrxx ; ++ir)
197+ {
198+ rpot (0 , ir) -= mCD_para *2.0 *std::real (rCDPotential[ir])*std::pow (ModuleBase::PI,3 ) / (2.0 *std::pow (std::real (kF_r [ir]),2 ));
199+ }
200+ delete[] recipCurrent_x;
201+ delete[] recipCurrent_y;
202+ delete[] recipCurrent_z;
203+ delete[] rCurrent_x;
204+ delete[] rCurrent_y;
205+ delete[] rCurrent_z;
127206 }
207+
208+ #ifdef _OPENMP
209+ #pragma omp parallel for
210+ #endif
211+ for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
212+ {
213+ delete[] recipPhi[is];
214+ delete[] rPhi[is];
215+ }
216+ delete[] recipPhi;
217+ delete[] rPhi;
128218}
129219
130220void Evolve_OFDFT::propagate_psi (elecstate::ElecState* pelec,
0 commit comments