14 USE ieee_arithmetic,
ONLY: ieee_is_finite
30#include "./base/base_uses.f90"
37 REAL(KIND=
dp),
PARAMETER,
PRIVATE :: hartree_to_ev = 27.211386245988_dp
39 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_electrons_workfunction'
52 SUBROUTINE planar_hartree_average(v_hartree_rspace, para_env, axis, minimum_A, maximum_A, &
54 TYPE(pw_r3d_rs_type),
POINTER :: v_hartree_rspace
55 TYPE(mp_para_env_type),
POINTER :: para_env
56 INTEGER,
INTENT(IN) :: axis
57 REAL(KIND=
dp),
INTENT(IN) :: minimum_a, maximum_a
58 REAL(KIND=
dp),
INTENT(OUT) :: v_avg_hartree
60 INTEGER :: grid_index, ix, iy, iz
61 INTEGER,
DIMENSION(2, 3) :: bounds_global, bounds_local
62 REAL(KIND=
dp) :: cell_hmat(3, 3), coordinate_bohr, cross_product(3), face_norm, height_bohr, &
63 local_count, local_sum, maximum_bohr, minimum_bohr, udvol
65 IF (.NOT.
ASSOCIATED(para_env))
THEN
66 cpabort(
"Planar-potential average could not access para_env.")
68 IF (.NOT.
ASSOCIATED(v_hartree_rspace))
THEN
69 cpabort(
"Planar-potential average could not access the Hartree potential grid.")
71 IF (.NOT.
ASSOCIATED(v_hartree_rspace%array))
THEN
72 cpabort(
"Planar-potential average found an unallocated Hartree potential grid.")
74 IF (.NOT.
ASSOCIATED(v_hartree_rspace%pw_grid))
THEN
75 cpabort(
"Planar-potential average found a Hartree potential grid without metadata.")
77 IF (v_hartree_rspace%pw_grid%dvol <= 0.0_dp)
THEN
78 cpabort(
"Planar-potential average found an invalid Hartree potential grid volume.")
81 minimum_bohr = minimum_a*
bohr
82 maximum_bohr = maximum_a*
bohr
83 IF (axis < 1 .OR. axis > 3)
THEN
84 cpabort(
"Planar-potential average received an invalid averaging axis.")
86 IF (maximum_bohr <= minimum_bohr)
THEN
87 cpabort(
"Planar-potential average requires potential_average_max_A > min_A.")
90 cell_hmat(:, 1) = v_hartree_rspace%pw_grid%dh(:, 1)* &
91 REAL(v_hartree_rspace%pw_grid%npts(1), KIND=
dp)
92 cell_hmat(:, 2) = v_hartree_rspace%pw_grid%dh(:, 2)* &
93 REAL(v_hartree_rspace%pw_grid%npts(2), KIND=
dp)
94 cell_hmat(:, 3) = v_hartree_rspace%pw_grid%dh(:, 3)* &
95 REAL(v_hartree_rspace%pw_grid%npts(3), KIND=
dp)
98 cross_product(1) = cell_hmat(2, 2)*cell_hmat(3, 3) - cell_hmat(3, 2)*cell_hmat(2, 3)
99 cross_product(2) = cell_hmat(3, 2)*cell_hmat(1, 3) - cell_hmat(1, 2)*cell_hmat(3, 3)
100 cross_product(3) = cell_hmat(1, 2)*cell_hmat(2, 3) - cell_hmat(2, 2)*cell_hmat(1, 3)
102 cross_product(1) = cell_hmat(2, 3)*cell_hmat(3, 1) - cell_hmat(3, 3)*cell_hmat(2, 1)
103 cross_product(2) = cell_hmat(3, 3)*cell_hmat(1, 1) - cell_hmat(1, 3)*cell_hmat(3, 1)
104 cross_product(3) = cell_hmat(1, 3)*cell_hmat(2, 1) - cell_hmat(2, 3)*cell_hmat(1, 1)
106 cross_product(1) = cell_hmat(2, 1)*cell_hmat(3, 2) - cell_hmat(3, 1)*cell_hmat(2, 2)
107 cross_product(2) = cell_hmat(3, 1)*cell_hmat(1, 2) - cell_hmat(1, 1)*cell_hmat(3, 2)
108 cross_product(3) = cell_hmat(1, 1)*cell_hmat(2, 2) - cell_hmat(2, 1)*cell_hmat(1, 2)
110 face_norm = sqrt(sum(cross_product**2))
111 IF (.NOT. ieee_is_finite(face_norm) .OR. face_norm <= 0.0_dp)
THEN
112 cpabort(
"Planar-potential average found a singular cell face.")
114 height_bohr = v_hartree_rspace%pw_grid%vol/face_norm
115 IF (.NOT. ieee_is_finite(height_bohr) .OR. height_bohr <= 0.0_dp)
THEN
116 cpabort(
"Planar-potential average found an invalid cell height.")
118 IF (minimum_bohr < -1.0e-10_dp .OR. maximum_bohr > height_bohr + 1.0e-10_dp)
THEN
119 cpabort(
"CP2K potential_average_region lies outside the cell")
122 udvol = 1.0_dp/v_hartree_rspace%pw_grid%dvol
126 bounds_global = v_hartree_rspace%pw_grid%bounds
127 bounds_local = v_hartree_rspace%pw_grid%bounds_local
129 DO iz = bounds_local(1, 3), bounds_local(2, 3)
130 DO iy = bounds_local(1, 2), bounds_local(2, 2)
131 DO ix = bounds_local(1, 1), bounds_local(2, 1)
134 grid_index = ix - bounds_global(1, 1)
136 grid_index = iy - bounds_global(1, 2)
138 grid_index = iz - bounds_global(1, 3)
140 coordinate_bohr = real(grid_index, kind=
dp)/ &
141 REAL(v_hartree_rspace%pw_grid%npts(axis), KIND=
dp)*height_bohr
142 IF (coordinate_bohr >= minimum_bohr .AND. coordinate_bohr <= maximum_bohr)
THEN
143 local_sum = local_sum + v_hartree_rspace%array(ix, iy, iz)*udvol
144 local_count = local_count + 1.0_dp
150 CALL para_env%sum(local_sum)
151 CALL para_env%sum(local_count)
152 IF (local_count <= 0.0_dp)
THEN
153 cpabort(
"Planar-potential average found no grid points in the requested region.")
156 v_avg_hartree = local_sum/local_count
157 END SUBROUTINE planar_hartree_average
171 fermi_level_eV, workfunction_eV)
173 INTEGER,
INTENT(IN) :: axis
174 REAL(kind=
dp),
INTENT(IN) :: minimum_a, maximum_a
175 REAL(kind=
dp),
INTENT(OUT) :: fermi_level_ev, workfunction_ev
177 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_electrons_compute_workfunction'
179 INTEGER :: handle, homo, ispin, nmo, nspin
180 REAL(kind=
dp) :: fermi_hartree, v_avg_hartree
181 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
191 CALL timeset(routinen, handle)
193 IF (axis < 1 .OR. axis > 3)
THEN
194 cpabort(
"workfunction axis must be x, y, or z.")
196 IF (maximum_a <= minimum_a)
THEN
197 cpabort(
"workfunction region requires maximum_A > minimum_A.")
202 IF (.NOT.
ASSOCIATED(qs_env))
THEN
203 cpabort(
"workfunction update requires a QS force environment.")
206 NULLIFY (energy, mos, dft_control, matrix_ks, mo_coeff, mo_eigenvalues, para_env, &
208 CALL get_qs_env(qs_env, energy=energy, mos=mos, dft_control=dft_control, matrix_ks=matrix_ks, &
209 para_env=para_env, v_hartree_rspace=v_hartree_rspace)
210 IF (.NOT.
ASSOCIATED(energy))
THEN
211 cpabort(
"workfunction update could not access QS energy data.")
215 fermi_hartree = energy%efermi
216 IF (fermi_hartree == 0.0_dp)
THEN
218 IF (.NOT.
ASSOCIATED(mos))
THEN
219 cpabort(
"Fermi level unset; no MO data available.")
221 IF (
SIZE(mos) <= 0) cpabort(
"MO array is empty.")
223 fermi_hartree = 0.0_dp
225 IF (.NOT. ieee_is_finite(mos(ispin)%mu))
THEN
226 cpabort(
"MO chemical potential not finite.")
228 fermi_hartree = fermi_hartree + mos(ispin)%mu
230 fermi_hartree = fermi_hartree/real(nspin, kind=
dp)
233 IF (abs(fermi_hartree) <= 10.0_dp*epsilon(fermi_hartree))
THEN
240 IF (.NOT.
ASSOCIATED(mos) .OR. .NOT.
ASSOCIATED(matrix_ks))
THEN
241 cpabort(
"OT fallback needs MO and KS-matrix data.")
243 IF (
SIZE(matrix_ks) <
SIZE(mos))
THEN
244 cpabort(
"OT fallback found too few KS matrices.")
246 IF (
ASSOCIATED(dft_control))
THEN
247 IF (dft_control%do_admm)
THEN
248 cpabort(
"OT fallback does not support ADMM.")
252 fermi_hartree = -huge(0.0_dp)
254 NULLIFY (mo_coeff, mo_eigenvalues)
257 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, &
258 eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
259 IF (.NOT.
ASSOCIATED(mo_coeff) .OR. .NOT.
ASSOCIATED(mo_eigenvalues))
THEN
260 cpabort(
"OT fallback could not access orbitals.")
262 IF (homo <= 0 .OR. homo > nmo .OR. homo >
SIZE(mo_eigenvalues))
THEN
263 cpabort(
"OT fallback found an invalid HOMO index.")
266 ks_matrix=matrix_ks(ispin)%matrix, &
267 evals_arg=mo_eigenvalues, &
269 IF (.NOT. ieee_is_finite(mo_eigenvalues(homo)))
THEN
270 cpabort(
"OT HOMO energy not finite.")
272 fermi_hartree = max(fermi_hartree, mo_eigenvalues(homo))
276 IF (.NOT. ieee_is_finite(fermi_hartree))
THEN
277 cpabort(
"Fermi level not finite.")
279 IF (abs(fermi_hartree) <= 10.0_dp*epsilon(fermi_hartree))
THEN
280 cpabort(
"Fermi level unset after OT fallback.")
282 fermi_level_ev = fermi_hartree*hartree_to_ev
286 CALL planar_hartree_average(v_hartree_rspace, para_env, axis, minimum_a, maximum_a, &
288 workfunction_ev = v_avg_hartree*hartree_to_ev - fermi_level_ev
290 CALL timestop(handle)
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
represent a full matrix distributed on many processors
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Definition of physical constants:
real(kind=dp), parameter, public bohr
Work function and Fermi level readback from the converged SCF, using the planar average of the Hartre...
subroutine, public qs_electrons_compute_workfunction(force_env, axis, minimum_a, maximum_a, fermi_level_ev, workfunction_ev)
Compute the work function (vacuum Hartree level minus Fermi level, in eV) from the planar average of ...
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
collects routines that perform operations directly related to MOs
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
wrapper to abstract the force evaluation of the various methods
stores all the informations relevant to an mpi environment