45#include "../base/base_uses.f90"
51 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'nlo'
147 CHARACTER(len=*),
PARAMETER :: routinen =
'run_nlo'
150 LOGICAL :: nlo_present
157 IF (.NOT. nlo_present)
RETURN
159 CALL timeset(routinen, handle)
165 CALL nlo_prepare_environment(qs_env, nlo_env)
173 CALL nlo_write_susceptibility(nlo_env)
178 CALL timestop(handle)
187 SUBROUTINE nlo_prepare_environment(qs_env, nlo_env)
189 TYPE(
nlo_type),
INTENT(INOUT) :: nlo_env
191 CHARACTER(len=*),
PARAMETER :: routinen =
'nlo_prepare_environment'
193 INTEGER :: handle, ik, iw
194 LOGICAL :: scf_has_kpoints
195 TYPE(
dbcsr_p_type),
POINTER :: dr(:, :), hr(:, :), sr(:, :)
201 CALL timeset(routinen, handle)
203 CALL get_qs_env(qs_env, do_kpoints=scf_has_kpoints, dft_control=dft_control, &
204 scf_control=scf_control)
205 IF (scf_control%smear%do_smear) cpabort(
'NONLINEAR_OPTICS requires SCF without smearing.')
206 IF (.NOT. scf_has_kpoints)
THEN
207 cpabort(
'NONLINEAR_OPTICS requires k-point SCF; Gamma-only SCF is unsupported.')
209 SELECT CASE (dft_control%qs_control%method_id)
212 cpabort(
'NONLINEAR_OPTICS currently supports GPW/GAPW only.')
214 nlo_env%n_kpoints = 1
216 IF (nlo_env%n_kpoints > huge(nlo_env%n_kpoints)/nlo_env%k_mesh(ik))
THEN
217 cpabort(
'NONLINEAR_OPTICS K_MESH exceeds integer indexing.')
219 nlo_env%n_kpoints = nlo_env%n_kpoints*nlo_env%k_mesh(ik)
221 NULLIFY (nlo_env%images, dr)
222 CALL get_qs_env(qs_env, cell=nlo_env%cell, para_env=nlo_env%para_env, matrix_ks_kp=hr, &
223 matrix_s_kp=sr, sab_all=all_pairs, kpoints=scf, mos=nlo_env%mos)
224 IF (any(nlo_env%cell%perd == 0 .AND. nlo_env%k_mesh /= 1))
THEN
225 cpabort(
'NONLINEAR_OPTICS K_MESH must be one in each nonperiodic direction.')
227 IF (nlo_env%cell%deth <= 0.0_dp) cpabort(
'NONLINEAR_OPTICS requires positive cell volume.')
228 CALL dbcsr_get_info(sr(1, 1)%matrix, nfullrows_total=nlo_env%n_ao)
229 nlo_env%n_spin =
SIZE(hr, 1)
230 nlo_env%n_bands = nlo_env%n_ao
233 ALLOCATE (dr(3, nlo_env%n_images))
235 ALLOCATE (nlo_env%h_ao_R(nlo_env%n_spin, nlo_env%n_ao, nlo_env%n_ao, nlo_env%n_images), &
237 ALLOCATE (nlo_env%s_ao_R(1, nlo_env%n_ao, nlo_env%n_ao, nlo_env%n_images), source=0.0_dp)
238 ALLOCATE (nlo_env%d_ao_R(3, nlo_env%n_ao, nlo_env%n_ao, nlo_env%n_images), source=0.0_dp)
248 WRITE (iw,
'(T2,A,T69,I12)')
'NONLINEAR_OPTICS| Selected tensor elements:', &
249 count(nlo_env%elements)
250 WRITE (iw,
'(T2,A,T69,I12)')
'NONLINEAR_OPTICS| Bands in response:', nlo_env%n_bands
251 IF (nlo_env%t1_au == nlo_env%t2_au)
THEN
252 WRITE (iw,
'(T2,A,T70,F8.1,1X,A)')
'NONLINEAR_OPTICS| T1 = T2:', &
254 WRITE (iw,
'(T2,A,T73,F8.1,1X,A)')
'NONLINEAR_OPTICS| ℏ/T1 = ℏ/T2:', &
255 1000.0_dp*
evolt/nlo_env%t1_au,
'meV'
257 WRITE (iw,
'(T2,A,T70,F8.1,1X,A)')
'NONLINEAR_OPTICS| T1:', &
259 WRITE (iw,
'(T2,A,T70,F8.1,1X,A)')
'NONLINEAR_OPTICS| T2:', &
261 WRITE (iw,
'(T2,A,T71,F8.1,1X,A)')
'NONLINEAR_OPTICS| ℏ/T1:', &
262 1000.0_dp*
evolt/nlo_env%t1_au,
'meV'
263 WRITE (iw,
'(T2,A,T71,F8.1,1X,A)')
'NONLINEAR_OPTICS| ℏ/T2:', &
264 1000.0_dp*
evolt/nlo_env%t2_au,
'meV'
265 WRITE (iw,
'(T2,A,T69,F8.1,1X,A)')
'NONLINEAR_OPTICS| Band transition width:', &
266 1000.0_dp*nlo_env%transition_width_au*
evolt,
'meV'
270 CALL timestop(handle)
272 END SUBROUTINE nlo_prepare_environment
278 SUBROUTINE nlo_write_susceptibility(nlo_env)
279 TYPE(
nlo_type),
INTENT(INOUT) :: nlo_env
281 CHARACTER(len=*),
PARAMETER :: routinen =
'nlo_write_susceptibility'
282 CHARACTER(len=3),
PARAMETER :: &
283 omega_subscript(5) = [character(len=3) ::
'₁',
'₂',
'₃',
'₄',
'₅']
285 CHARACTER(len=80) :: heading_2d, heading_3d
286 COMPLEX(dp),
ALLOCATABLE :: chi_flat(:, :), current_flat_sum(:, :)
287 INTEGER :: a, c, code, handle, i_case, iw
288 LOGICAL :: zero_output
289 REAL(kind=
dp) :: area, energy_ev(5), factor, omega(5), &
292 CALL timeset(routinen, handle)
294 ALLOCATE (current_flat_sum(3, 3**nlo_env%order), chi_flat(3, 3**nlo_env%order))
295 SELECT CASE (nlo_env%order)
297 heading_3d =
'NONLINEAR_OPTICS| χ² 3D (m/V)'
298 heading_2d =
'NONLINEAR_OPTICS| χ² 2D (m²/V)'
300 heading_3d =
'NONLINEAR_OPTICS| χ³ 3D (m²/V²)'
301 heading_2d =
'NONLINEAR_OPTICS| χ³ 2D (m³/V²)'
303 heading_3d =
'NONLINEAR_OPTICS| χ⁴ 3D (m³/V³)'
304 heading_2d =
'NONLINEAR_OPTICS| χ⁴ 2D (m⁴/V³)'
306 heading_3d =
'NONLINEAR_OPTICS| χ⁵ 3D (m⁴/V⁴)'
307 heading_2d =
'NONLINEAR_OPTICS| χ⁵ 2D (m⁵/V⁴)'
309 DO i_case = 1, nlo_env%n_frequency_combinations
311 energy_ev, zero_output)
312 IF (zero_output) cpabort(
'Invalid NONLINEAR_OPTICS frequency case.')
314 omega(1:nlo_env%order) = energy_ev(1:nlo_env%order)/
evolt
315 current_flat_sum(:, :) = nlo_env%current_spectrum(:, :, i_case)
316 CALL nlo_env%para_env%sum(current_flat_sum)
317 factor =
e_charge**(nlo_env%order + 1)*
a_bohr**(nlo_env%order - 2)* &
319 chi_flat(:, :) = current_flat_sum*factor/cmplx(0.0_dp, -sum(omega),
dp)
321 nlo_env%cell%hmat(:, 2))**2))
322 IF (area <= 0.0_dp) cpabort(
'NONLINEAR_OPTICS requires nonzero in-plane area.')
323 sheet_height = nlo_env%cell%deth/area*
a_bohr
327 WRITE (iw,
'(T2,A,I0,A,I0)')
'NONLINEAR_OPTICS| Frequency case ', &
328 i_case,
' / ', nlo_env%n_frequency_combinations
330 DO a = 1, nlo_env%order
331 WRITE (iw,
'(T2,A,A,A,T72,F9.3,1X,A)')
'NONLINEAR_OPTICS| ω', &
332 omega_subscript(a),
' =', energy_ev(a),
'eV'
334 WRITE (iw,
'(T2,A,T70,F9.3,1X,A)')
'NONLINEAR_OPTICS| ω_out =', &
335 sum(energy_ev(1:nlo_env%order)),
'eV'
336 WRITE (iw,
'(T2,A,T50,A,T72,A)') trim(heading_3d),
'Real',
'Imag'
337 DO code = 1, 3**nlo_env%order
339 IF (.NOT. nlo_env%elements(c, code)) cycle
340 WRITE (iw,
'(T2,A,A6,T37,2ES22.12)')
'NONLINEAR_OPTICS| 3D ', &
341 nlo_tensor_indices(nlo_env%order, c, code), &
342 REAL(chi_flat(c, code), kind=
dp), aimag(chi_flat(c, code))
345 IF (all(nlo_env%cell%perd(1:2) /= 0) .AND. nlo_env%cell%perd(3) == 0)
THEN
346 WRITE (iw,
'(T2,A,T62,ES15.6,1X,A)') &
347 'NONLINEAR_OPTICS| Effective sheet height:', sheet_height,
'm'
348 WRITE (iw,
'(T2,A,T50,A,T72,A)') trim(heading_2d),
'Real',
'Imag'
349 DO code = 1, 3**nlo_env%order
351 IF (.NOT. nlo_env%elements(c, code)) cycle
352 WRITE (iw,
'(T2,A,A6,T37,2ES22.12)')
'NONLINEAR_OPTICS| 2D ', &
353 nlo_tensor_indices(nlo_env%order, c, code), &
354 REAL(chi_flat(c, code)*sheet_height, kind=
dp), &
355 aimag(chi_flat(c, code)*sheet_height)
361 CALL timestop(handle)
363 END SUBROUTINE nlo_write_susceptibility
372 PURE FUNCTION nlo_tensor_indices(order, output_direction, code)
RESULT(indices)
373 INTEGER,
INTENT(IN) :: order, output_direction, code
374 CHARACTER(len=6) :: indices
376 CHARACTER(len=*),
PARAMETER :: axes =
'XYZ'
378 INTEGER :: field, input_direction, remaining_code
381 indices(1:1) = axes(output_direction:output_direction)
382 remaining_code = code - 1
384 input_direction = mod(remaining_code, 3) + 1
385 indices(field + 1:field + 1) = axes(input_direction:input_direction)
386 remaining_code = remaining_code/3
389 END FUNCTION nlo_tensor_indices
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
DBCSR operations in CP2K.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
integer, parameter, public dp
Implements simple k-space/R-space transformations and Gamma-point MIC reconstruction.
subroutine, public replicate_rs_matrices(rs_dbcsr_in, kpoint_in, rs_array_out, cell_to_index_out)
Convert dbcsr matrices representing operators in real-space image cells to arrays.
Routines needed for kpoint calculation.
subroutine, public kpoint_init_cell_index(kpoint, sab_nl, para_env, nimages)
Generates the mapping of cell indices and linear RS index CELL (0,0,0) is always mapped to index 1.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Collection of simple mathematical functions and subroutines.
pure real(kind=dp) function, dimension(3), public vector_product(a, b)
Calculation of the vector product c = a x b.
subroutine, public nlo_bz_integration(nlo_env)
Integrate the density-response current over the Brillouin zone.
Nonlinear optical environment: input parameters and data shared by calculation stages.
subroutine, public release_nlo_environment(nlo_env)
Release NLO-owned matrices and the auxiliary k-point environment, if created.
subroutine, public run_nlo(qs_env)
Calculate frequency-dependent χ^(2) to χ^(5) after the ground-state SCF.
Definition of physical constants:
real(kind=dp), parameter, public mu_perm
real(kind=dp), parameter, public a_bohr
real(kind=dp), parameter, public e_charge
real(kind=dp), parameter, public femtoseconds
real(kind=dp), parameter, public c_light
real(kind=dp), parameter, public joule
real(kind=dp), parameter, public evolt
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.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
subroutine, public build_local_moment_matrix_rs_img(qs_env, moments_rs_img, rcc)
Calculate local moment matrix for a periodic system for all image cells.
Define the neighbor list data types and the corresponding functionality.
parameters that control an scf iteration
Contains information about kpoints.