62 CHARACTER(len=*),
PARAMETER :: routinen =
'calc_dipsurf_potential'
64 INTEGER :: handle, i, idir_surfdip, ilayer_min, &
65 ilow, irho, ispin, isurf, iup, jsurf, &
67 INTEGER,
DIMENSION(3) :: ngrid
68 INTEGER,
DIMENSION(:, :),
POINTER :: bo
69 REAL(
dp) :: cutoff, dh(3, 3), dip_fac, dip_hh, &
70 dsurf, height_min, hh, pos_surf_dip, &
71 rhoav_min, surfarea, vdip, vdip_fac
72 REAL(
dp),
ALLOCATABLE,
DIMENSION(:) :: rhoavsurf
85 CALL timeset(routinen, handle)
86 NULLIFY (cell, dft_control, rho, pw_env, auxbas_pw_pool, &
87 pw_pools, subsys, v_hartree_rspace, rho_r)
90 dft_control=dft_control, &
93 rho0_s_gs=rho0_s_gs, &
97 v_hartree_rspace=v_hartree_rspace)
99 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
101 CALL auxbas_pw_pool%create_pw(wf_r)
102 CALL auxbas_pw_pool%create_pw(vdip_r)
104 IF (dft_control%qs_control%gapw)
THEN
105 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw)
THEN
106 CALL pw_axpy(rho_core, rho0_s_gs)
108 CALL pw_axpy(rho_core, rho0_s_gs, -1.0_dp)
116 DO ispin = 1, dft_control%nspins
117 CALL pw_axpy(rho_r(ispin), wf_r)
120 ngrid(1:3) = wf_r%pw_grid%npts(1:3)
121 idir_surfdip = dft_control%dir_surf_dip
126 IF (i /= idir_surfdip)
THEN
127 IF (abs(wf_r%pw_grid%dh(idir_surfdip, i)) > 1.e-7_dp)
THEN
129 CALL cp_abort(__location__, &
130 "Dipole correction only for surface perpendicular to one Cartesian axis")
138 ilow = wf_r%pw_grid%bounds(1, idir_surfdip)
139 iup = wf_r%pw_grid%bounds(2, idir_surfdip)
141 ALLOCATE (rhoavsurf(ilow:iup))
144 bo => wf_r%pw_grid%bounds_local
147 CALL pw_scale(wf_r, wf_r%pw_grid%vol)
148 IF (idir_surfdip == 3)
THEN
152 DO i = bo(1, 3), bo(2, 3)
153 rhoavsurf(i) =
accurate_sum(wf_r%array(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), i))
156 ELSEIF (idir_surfdip == 2)
THEN
160 DO i = bo(1, 2), bo(2, 2)
161 rhoavsurf(i) =
accurate_sum(wf_r%array(bo(1, 1):bo(2, 1), i, bo(1, 3):bo(2, 3)))
167 DO i = bo(1, 1), bo(2, 1)
168 rhoavsurf(i) =
accurate_sum(wf_r%array(i, bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3)))
171 CALL pw_scale(wf_r, 1.0_dp/wf_r%pw_grid%vol)
172 rhoavsurf = rhoavsurf/wf_r%pw_grid%vol
174 surfarea = cell%hmat(isurf, isurf)*cell%hmat(jsurf, jsurf) - &
175 cell%hmat(isurf, jsurf)*cell%hmat(jsurf, isurf)
176 dsurf = surfarea/real(ngrid(isurf)*ngrid(jsurf),
dp)
179 CALL wf_r%pw_grid%para%group%sum(rhoavsurf)
181 rhoavsurf(ilow:iup) = dsurf*rhoavsurf(ilow:iup)
184 rhoavsurf(ilow:iup) = rhoavsurf(ilow:iup)/surfarea
186 IF (dft_control%pos_dir_surf_dip < 0.0_dp)
THEN
187 ilayer_min = ilow - 1 + minloc(abs(rhoavsurf(ilow:iup)), 1)
189 pos_surf_dip = dft_control%pos_dir_surf_dip*
bohr
190 ilayer_min = ilow - 1 + nint(pos_surf_dip/dh(idir_surfdip, idir_surfdip)) + 1
192 rhoav_min = abs(rhoavsurf(ilayer_min))
193 IF (rhoav_min >= 1.e-5_dp)
THEN
194 cpabort(
" Dipole correction needs more vacuum space above the surface ")
197 height_min = real((ilayer_min - ilow),
dp)*dh(idir_surfdip, idir_surfdip)
202 dip_fac = wf_r%pw_grid%vol*dh(idir_surfdip, idir_surfdip)/real(ngrid(idir_surfdip),
dp)
204 DO i = ilayer_min + 1, ilayer_min + ngrid(idir_surfdip)
205 hh = real((i - ilayer_min),
dp)
207 irho = i - ngrid(idir_surfdip)
212 IF (abs(irho - ilayer_min) > width)
THEN
215 cutoff = abs(sin(0.5_dp*
pi*real(abs(irho - ilayer_min),
dp)/real(width,
dp)))
217 dip_hh = dip_hh + rhoavsurf(irho)*hh*dip_fac*cutoff
220 DEALLOCATE (rhoavsurf)
222 qs_env%surface_dipole_moment = dip_hh/
bohr
226 vdip_fac = dip_hh*4.0_dp*
pi
228 DO i = ilayer_min + 1, ilayer_min + ngrid(idir_surfdip)
229 hh = real((i - ilayer_min),
dp)*dh(idir_surfdip, idir_surfdip)
230 vdip = vdip_fac*(-0.5_dp + (hh/cell%hmat(idir_surfdip, idir_surfdip)))* &
231 v_hartree_rspace%pw_grid%dvol/surfarea
233 irho = i - ngrid(idir_surfdip)
238 IF (abs(irho - ilayer_min) > width)
THEN
241 cutoff = abs(sin(0.5_dp*
pi*real(abs(irho - ilayer_min),
dp)/real(width,
dp)))
245 IF (idir_surfdip == 3)
THEN
246 vdip_r%array(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), irho) = &
247 vdip_r%array(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), irho) + vdip
248 ELSEIF (idir_surfdip == 2)
THEN
249 IF (irho >= bo(1, 2) .AND. irho <= bo(2, 2))
THEN
250 vdip_r%array(bo(1, 1):bo(2, 1), irho, bo(1, 3):bo(2, 3)) = &
251 vdip_r%array(bo(1, 1):bo(2, 1), irho, bo(1, 3):bo(2, 3)) + vdip
254 IF (irho >= bo(1, 1) .AND. irho <= bo(2, 1))
THEN
255 vdip_r%array(irho, bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3)) = &
256 vdip_r%array(irho, bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3)) + vdip
263 energy%surf_dipole = 0.5_dp*
pw_integral_ab(vdip_r, wf_r, just_sum=.true.)
266 CALL pw_axpy(vdip_r, v_hartree_rspace)
268 CALL auxbas_pw_pool%give_back_pw(wf_r)
269 CALL auxbas_pw_pool%give_back_pw(vdip_r)
271 CALL timestop(handle)
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.