(git:7fc1fe1)
Loading...
Searching...
No Matches
nlo_read_input.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8!> \author Jan Wilhelm, with help from ChatGPT
9
11!&<
12 USE bibliography, ONLY: cheng2015
13 USE cp_units, ONLY: cp_unit_to_cp2k
14 USE ieee_arithmetic, ONLY: ieee_is_finite
24 USE input_val_types, ONLY: char_t, &
25 integer_t, &
26 real_t, &
28 USE kinds, ONLY: default_string_length, &
29 dp
30 USE nlo_types, ONLY: nlo_frequency_type, &
35!&>
36#include "../base/base_uses.f90"
37
38 IMPLICIT NONE
39
40 PRIVATE
41
42 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'nlo_read_input'
43
46
47CONTAINS
48
49! **************************************************************************************************
50!> \brief Define the nonlinear susceptibility model, conventions, and input parameters.
51!> \param section Created NONLINEAR_OPTICS section of the input tree.
52! **************************************************************************************************
54 TYPE(section_type), POINTER :: section
55
56 CHARACTER(LEN=6) :: frequency_name
57 INTEGER :: i_frequency
58 TYPE(keyword_type), POINTER :: keyword
59
60 NULLIFY (keyword)
61 cpassert(.NOT. ASSOCIATED(section))
62 CALL section_create(section, __location__, name="NONLINEAR_OPTICS", &
63 description= &
64 "Frequency-dependent nonlinear optical response of an insulating "// &
65 "periodic Kohn-Sham system in the independent-particle "// &
66 "approximation (no explicit excited-state treatment, in particular"// &
67 " no TDDFT, GW-BSE or excitonic effects). The induced polarization"// &
68 " is expanded in powers of the electric field. With $E(t)=\sum_ω "// &
69 "E(ω)e^{-iωt}"//"$, the second- through fifth-order "// &
70 "contributions are "// &
71 achar(10)//achar(10)// &
72 "$$P_i^{(2)}(Ω)=ε_0\sum_{ab}\sum_{ω_1+ω_2=Ω} "// &
73 "χ_{i;ab}^{(2)}(ω_1,ω_2)E_a(ω_1)E_b(ω_2),$$"// &
74 achar(10)//achar(10)// &
75 achar(10)//achar(10)// &
76 "$$P_i^{(3)}(Ω)=ε_0\sum_{abc} \sum_{ω_1+ω_2+ω_3=Ω} "// &
77 "χ_{i;abc}^{(3)}(ω_1,ω_2,ω_3) E_a(ω_1)E_b(ω_2)E_c(ω_3),$$"// &
78 achar(10)// &
79 achar(10)//achar(10)//achar(10)// &
80 "$$P_i^{(4)}(Ω)=ε_0\sum_{abcd} \sum_{ω_1+ω_2+ω_3+ω_4=Ω} "// &
81 "χ_{i;abcd}^{(4)}(ω_1,ω_2,ω_3,ω_4) "// &
82 "E_a(ω_1)E_b(ω_2)E_c(ω_3)E_d(ω_4),$$"// &
83 achar(10)//achar(10)//achar(10)// &
84 achar(10)// &
85 "$$P_i^{(5)}(Ω)=ε_0\sum_{abcde} \sum_{ω_1+ω_2+ω_3+ω_4+ω_5=Ω} "// &
86 "χ_{i;abcde}^{(5)}(ω_1,ω_2,ω_3,ω_4,ω_5) "// &
87 "E_a(ω_1)E_b(ω_2)E_c(ω_3)E_d(ω_4)E_e(ω_5).$$"// &
88 achar(10)//achar(10)// &
89 "Here i,a,... denote Cartesian directions and ε_0 is the vacuum "// &
90 "permittivity. Each tensor is averaged over all simultaneous "// &
91 "permutations of its incident frequency-direction pairs. The "// &
92 "frequency sums include ordered tuples, so no extra factorial "// &
93 "occurs in these formulas. Negative frequencies describe "// &
94 "complex-conjugate fields; harmonic generation uses equal positive"// &
95 " frequencies. The input specifies photon energies ℏω_j in eV, "// &
96 "with Ω≠0. The density matrix is expanded recursively in the "// &
97 "fields, using all AO bands and analytic derivatives with respect "// &
98 "to k. In the energy eigenbasis the usual "// &
99 "population and coherence relaxation terms are "//achar(10)//achar(10)// &
100 "$$\left.\dot{ρ}_{mn}\right|_{\mathrm{rel}}= "// &
101 "-δ_{mn}(ρ_{nn}-f_n)/T_1 -(1-δ_{mn})ρ_{mn}/T_2.$$"//achar(10)// &
102 achar(10)// &
103 "Here $f_n$ is the equilibrium occupation. With T1_T2, "// &
104 "$T_1=T_2=T$ and the relaxation is "// &
105 "$-(ρ-ρ_{\mathrm{eq}})/T$. With separate T1 and T2, "// &
106 "the rate for bands m and n changes smoothly with their energy "// &
107 "difference Δε: "//achar(10)//achar(10)// &
108 "$$γ_{mn}=1/T_1+(1/T_2-1/T_1) "// &
109 "[1-\exp(-(Δε/w)^2)],\qquad Δε=ε_m-ε_n.$$"//achar(10)//achar(10)// &
110 "The width w is T1_T2_SMOOTHING_WIDTH. At exact degeneracy the "// &
111 "rate is 1/T1 for all matrices within the degenerate band "// &
112 "subspace. The Gaussian function of the Hamiltonian commutator "// &
113 "gives a basis-covariant transition without band grouping. "// &
114 "At each response step, denominators are "// &
115 "$ε_m-ε_n-ℏΩ-iγ_{mn}$. The "// &
116 "current includes the field-dependent contribution "// &
117 "required by the projected position operator. In "// &
118 "atomic units, with r_i=i∂_{k_i}+A_i, "//achar(10)//achar(10)// &
119 "$$F_{ia}=∂_{k_i}A_a-∂_{k_a}A_i-i[A_i,A_a], \qquad "// &
120 "v_i(E)=i[H+E_ar_a, r_i]=v_i(0)+E_aF_{ia}.$$"//achar(10)//achar(10)// &
121 "Let I^{(n)} denote the cell-integrated current response, "// &
122 "including the Brillouin-zone weights and spin "// &
123 "occupations, in SI units. The volume normalization and "// &
124 "conversion to susceptibility are "//achar(10)//achar(10)// &
125 "$$V=|\det(\mathbf a_1,\mathbf a_2,\mathbf a_3)|, \qquad "// &
126 "j^{(n)}=I^{(n)}/V,\qquad χ_{\mathrm{3D}}^{(n)}= "// &
127 "σ_{\mathrm{3D}}^{(n)}/(-iΩε_0),$$"//achar(10)//achar(10)// &
128 "where $σ^{(n)}"//"$ is the coefficient of the n field factors in "// &
129 "$j^{(n)}"//"$. For a two-dimensional slab with vacuum along "// &
130 "nonperiodic z, the following sheet quantities remove the "// &
131 "dependence on the chosen vacuum height: "//achar(10)//achar(10)// &
132 "$$A=|\mathbf a_1\times\mathbf a_2|,\qquad L_z=V/A, \qquad "// &
133 "P_{\mathrm{2D}}^{(n)}=L_zP_{\mathrm{3D}}^{(n)}, \qquad "// &
134 "χ_{\mathrm{2D}}^{(n)}=L_z χ_{\mathrm{3D}}^{(n)}.$$"//achar(10)// &
135 achar(10)// &
136 "The units are $(m/V)^{n-1}"//"$ for $χ_{3D}"//"$ and "// &
137 "$m^n/V^{n-1}"//"$ for "// &
138 "$χ_{2D}"//"$. Converge the basis set, the k mesh in the SCF "// &
139 "calculation, and the k mesh used for the NLO susceptibility "// &
140 "separately. Higher-order susceptibilities "// &
141 "usually require large optical k meshes.", &
142 n_keywords=10, n_subsections=0, repeats=.false.)
143
144 CALL keyword_create(keyword, __location__, name="_SECTION_PARAMETERS_", &
145 description= &
146 "Activates the nonlinear optical susceptibility calculation.", &
147 default_l_val=.false., lone_keyword_l_val=.true.)
148 CALL section_add_keyword(section, keyword)
149 CALL keyword_release(keyword)
150
151 CALL keyword_create(keyword, __location__, name="ORDER", &
152 description= &
153 "Order n of the electric-field response $χ^{(n)}"//"$; "// &
154 "supported values are 2, 3, 4, and 5. Exactly "// &
155 "FREQ_1 through FREQ_n must be set.", &
156 usage="ORDER 2", type_of_var=integer_t, n_var=1, default_i_val=2)
157 CALL section_add_keyword(section, keyword)
158 CALL keyword_release(keyword)
159
160 CALL keyword_create(keyword, __location__, name="ELEMENTS", &
161 description= &
162 "Susceptibility elements to compute and print. Use -1 alone for "// &
163 "all elements (default), or a list of Cartesian index strings. "// &
164 "Each string has ORDER+1 letters X, Y, or Z: the output direction "// &
165 "followed by the input directions in FREQ_1 through FREQ_ORDER "// &
166 "order. For example, YXX selects $χ^{(2)}_{y;xx}"//"$, and XYYYX "// &
167 "selects $χ^{(4)}_{x;yyyx}"//"$. Uppercase and "// &
168 "lowercase are accepted."// &
169 " Repeat the keyword to continue a long list. Duplicate entries "// &
170 "are computed once. Only selected elements and their required "// &
171 "intermediate responses are evaluated; unselected "// &
172 "elements are omitted from the output. Do not "// &
173 "combine -1 with explicit elements.", &
174 usage="ELEMENTS YXX YYY", type_of_var=char_t, n_var=-1, &
175 repeats=.true., default_c_vals=["-1"])
176 CALL section_add_keyword(section, keyword)
177 CALL keyword_release(keyword)
178
179 DO i_frequency = 1, 5
180 WRITE (frequency_name, '(A,I1)') "FREQ_", i_frequency
181 CALL keyword_create(keyword, __location__, name=trim(frequency_name), &
182 description= &
183 "Input photon energy in eV. VALUE specifies one energy; RANGE "// &
184 "gives inclusive start, end, and positive step; SAME_AS and "// &
185 "MINUS_OF reference an earlier input frequency. "// &
186 "Independent ranges produce every combination. The sum "// &
187 "of input energies must be nonzero.", &
188 usage=trim(frequency_name)//" RANGE 0.5 1.0 0.01", &
189 type_of_var=char_t, n_var=-1)
190 CALL section_add_keyword(section, keyword)
191 CALL keyword_release(keyword)
192 END DO
193
194 CALL keyword_create(keyword, __location__, name="T1_T2", &
195 description= &
196 "Common relaxation time $T_1=T_2=T$. Usually T₁ relaxes band "// &
197 "occupations (the diagonal density-matrix elements $ρ_{nn}"//"$) "// &
198 "towards equilibrium; T₂ describes decoherence, damping "// &
199 "off-diagonal elements $ρ_{mn}"//"$ to zero in the energy "// &
200 "eigenbasis. "// &
201 "Using one time gives $-(ρ-ρ_{eq})/T$ and removes the "// &
202 "basis-dependent distinction between populations and coherences "// &
203 "inside degenerate subspaces. This provides a simple, numerically "// &
204 "robust first approximation near band degeneracies and close "// &
205 "bands. It does not establish that the physical lifetimes are "// &
206 "equal. For relaxation-dependent singularities near the graphene "// &
207 "Dirac point, see Cheng, Vermeulen and Sipe (2015). The "// &
208 "broadening is $Γ=ℏ/T_2$. Must be positive; the default is 30 fs.", &
209 usage="T1_T2 [fs] 30", type_of_var=real_t, n_var=1, unit_str="fs", &
210 default_r_val=cp_unit_to_cp2k(value=30.0_dp, unit_str="fs"), &
211 citations=[cheng2015])
212 CALL section_add_keyword(section, keyword)
213 CALL keyword_release(keyword)
214
215 CALL keyword_create(keyword, __location__, name="T1", &
216 description= &
217 "Relaxation time for diagonal band occupations. Set together with "// &
218 "T2 to use separate population and coherence times. Must satisfy "// &
219 "T1 >= T2 > 0. Do not combine with an explicitly set T1_T2.", &
220 usage="T1 [fs] 300", type_of_var=real_t, n_var=1, unit_str="fs")
221 CALL section_add_keyword(section, keyword)
222 CALL keyword_release(keyword)
223
224 CALL keyword_create(keyword, __location__, name="T2", &
225 description= &
226 "Decoherence time for well-separated bands. Set together with T1. "// &
227 "Near degenerate bands the relaxation rate changes smoothly to 1/T1.", &
228 usage="T2 [fs] 30", type_of_var=real_t, n_var=1, unit_str="fs")
229 CALL section_add_keyword(section, keyword)
230 CALL keyword_release(keyword)
231
232 CALL keyword_create(keyword, __location__, name="T1_T2_SMOOTHING_WIDTH", &
233 description= &
234 "Positive energy width w of the smooth transition between population "// &
235 "and coherence relaxation. The band-pair rate is "// &
236 "1/T1 + (1/T2 - 1/T1)[1 - exp(-((epsilon_m-epsilon_n)/w)^2)]. "// &
237 "The default 0.025 eV is a model choice to converge for each system.", &
238 usage="T1_T2_SMOOTHING_WIDTH [eV] 0.025", type_of_var=real_t, &
239 n_var=1, unit_str="eV", &
240 default_r_val=cp_unit_to_cp2k(value=0.025_dp, unit_str="eV"))
241 CALL section_add_keyword(section, keyword)
242 CALL keyword_release(keyword)
243
244 CALL keyword_create(keyword, __location__, name="K_MESH", &
245 description= &
246 "Monkhorst-Pack-type uniform k mesh, shifted to include Γ, for the"// &
247 " Brillouin-zone integration required for $χ^{(n)}"//"$. Fractional "// &
248 "coordinates are k_i=j_i/N_i with j_i=0,...,N_i-1; no symmetry "// &
249 "reduction is used. This mesh can differ from the required k-point"// &
250 " SCF mesh. Higher-order nonlinear susceptibilities usually "// &
251 "require denser k meshes. Every entry must be "// &
252 "positive; use one in each nonperiodic direction.", &
253 usage="K_MESH 24 24 1", type_of_var=integer_t, n_var=3)
254 CALL section_add_keyword(section, keyword)
255 CALL keyword_release(keyword)
256
258
259! **************************************************************************************************
260!> \brief Read the activated input into nlo_env and reject invalid frequency combinations.
261!> \param qs_env Converged QS environment containing the parsed input.
262!> \param nlo_env Validated settings for the nonlinear response.
263! **************************************************************************************************
264 SUBROUTINE read_nlo_input(qs_env, nlo_env)
265 TYPE(qs_environment_type), POINTER :: qs_env
266 TYPE(nlo_type), INTENT(OUT) :: nlo_env
267
268 CHARACTER(len=*), PARAMETER :: routinen = 'read_nlo_input'
269
270 INTEGER :: handle, i_case
271 LOGICAL :: zero_output
272 REAL(kind=dp) :: energy_ev(5)
273 TYPE(section_vals_type), POINTER :: input, section
274
275 CALL timeset(routinen, handle)
276
277 CALL get_qs_env(qs_env, input=input)
278 section => section_vals_get_subs_vals(input, 'PROPERTIES%NONLINEAR_OPTICS')
279 CALL read_nlo_values(section, nlo_env)
280 DO i_case = 1, nlo_env%n_frequency_combinations
281 CALL nlo_frequency_case(nlo_env%frequency, nlo_env%order, i_case, energy_ev, zero_output)
282 IF (zero_output) cpabort('NLO output frequency must be nonzero.')
283 END DO
284
285 CALL timestop(handle)
286
287 END SUBROUTINE read_nlo_input
288
289! **************************************************************************************************
290!> \brief Read and validate the NONLINEAR_OPTICS input before the first response calculation.
291!> \param section Activated NONLINEAR_OPTICS input section.
292!> \param nlo_env Validated response settings and selected elements.
293! **************************************************************************************************
294 SUBROUTINE read_nlo_values(section, nlo_env)
295 TYPE(section_vals_type), POINTER :: section
296 TYPE(nlo_type), INTENT(OUT) :: nlo_env
297
298 CHARACTER(len=6) :: frequency_name
299 CHARACTER(len=default_string_length), POINTER :: words(:)
300 INTEGER :: i_frequency
301 LOGICAL :: common_explicit, t1_explicit, &
302 t2_explicit
303 INTEGER, POINTER :: mesh(:)
304 TYPE(val_type), POINTER :: input_value
305
306 nlo_env = nlo_type()
307 IF (.NOT. ASSOCIATED(section)) cpabort('NLO input section is missing.')
308 NULLIFY (input_value, mesh, words)
309 CALL section_vals_val_get(section, 'ORDER', i_val=nlo_env%order)
310 IF (nlo_env%order < 2 .OR. nlo_env%order > 5) THEN
311 cpabort('NLO ORDER must be between 2 and 5.')
312 END IF
313 CALL read_nlo_elements(section, nlo_env)
314 CALL section_vals_val_get(section, 'T1_T2', r_val=nlo_env%t1_au)
315 IF (.NOT. ieee_is_finite(nlo_env%t1_au) .OR. nlo_env%t1_au <= 0.0_dp) THEN
316 cpabort('NONLINEAR_OPTICS T1_T2 must be a positive, finite time.')
317 END IF
318 CALL section_vals_val_get(section, 'T1_T2', explicit=common_explicit)
319 CALL section_vals_val_get(section, 'T1', explicit=t1_explicit)
320 CALL section_vals_val_get(section, 'T2', explicit=t2_explicit)
321 IF (t1_explicit .NEQV. t2_explicit) THEN
322 cpabort('NONLINEAR_OPTICS requires both T1 and T2 when either is set.')
323 END IF
324 IF (t1_explicit .AND. common_explicit) THEN
325 cpabort('NONLINEAR_OPTICS cannot combine T1_T2 with T1 and T2.')
326 END IF
327 nlo_env%t2_au = nlo_env%t1_au
328 IF (t1_explicit) THEN
329 CALL section_vals_val_get(section, 'T1', r_val=nlo_env%t1_au)
330 CALL section_vals_val_get(section, 'T2', r_val=nlo_env%t2_au)
331 END IF
332 IF (.NOT. ieee_is_finite(nlo_env%t1_au) .OR. &
333 .NOT. ieee_is_finite(nlo_env%t2_au)) THEN
334 cpabort('NONLINEAR_OPTICS T1 and T2 must be finite times.')
335 END IF
336 IF (nlo_env%t2_au <= 0.0_dp .OR. nlo_env%t1_au < nlo_env%t2_au) THEN
337 cpabort('NONLINEAR_OPTICS requires T1 >= T2 > 0.')
338 END IF
339 CALL section_vals_val_get(section, 'T1_T2_SMOOTHING_WIDTH', &
340 r_val=nlo_env%transition_width_au)
341 IF (.NOT. ieee_is_finite(nlo_env%transition_width_au) .OR. &
342 nlo_env%transition_width_au <= 0.0_dp) THEN
343 cpabort('NONLINEAR_OPTICS requires a positive, finite transition width.')
344 END IF
345 CALL section_vals_val_get(section, 'K_MESH', val=input_value)
346 IF (.NOT. ASSOCIATED(input_value)) cpabort('NONLINEAR_OPTICS requires K_MESH.')
347 CALL section_vals_val_get(section, 'K_MESH', i_vals=mesh)
348 IF (.NOT. ASSOCIATED(mesh)) cpabort('NLO requires three K_MESH entries.')
349 IF (SIZE(mesh) /= 3) cpabort('NLO requires three K_MESH entries.')
350 IF (any(mesh <= 0)) cpabort('NONLINEAR_OPTICS K_MESH entries must be positive.')
351 nlo_env%k_mesh = mesh
352 DO i_frequency = 1, 5
353 WRITE (frequency_name, '(A,I1)') 'FREQ_', i_frequency
354 NULLIFY (input_value)
355 CALL section_vals_val_get(section, frequency_name, val=input_value)
356 IF (i_frequency > nlo_env%order) THEN
357 IF (ASSOCIATED(input_value)) THEN
358 cpabort('Do not set input frequencies beyond NONLINEAR_OPTICS ORDER.')
359 END IF
360 cycle
361 END IF
362 IF (.NOT. ASSOCIATED(input_value)) cpabort('Set all FREQ_1 through FREQ_ORDER.')
363 NULLIFY (words)
364 CALL section_vals_val_get(section, frequency_name, c_vals=words)
365 IF (.NOT. ASSOCIATED(words)) cpabort('NLO frequency specification is empty.')
366 CALL parse_nlo_frequency(words, i_frequency, nlo_env%frequency(i_frequency))
367 END DO
368 ! Number of independent frequency tuples: product_j N(FREQ_j).
369 CALL nlo_frequency_case_count(nlo_env%frequency, nlo_env%order, &
370 nlo_env%n_frequency_combinations)
371
372 END SUBROUTINE read_nlo_values
373
374! **************************************************************************************************
375!> \brief Combine repeated ELEMENTS lists without imposing a limit on their length.
376!> \param section Input section containing the ELEMENTS keywords.
377!> \param nlo_env Response settings receiving the selected elements.
378! **************************************************************************************************
379 SUBROUTINE read_nlo_elements(section, nlo_env)
380 TYPE(section_vals_type), POINTER :: section
381 TYPE(nlo_type), INTENT(INOUT) :: nlo_env
382
383 CHARACTER(len=default_string_length), POINTER :: words(:)
384 INTEGER :: i_rep, n_rep
385 LOGICAL, ALLOCATABLE :: elements(:, :)
386
387 ALLOCATE (nlo_env%elements(3, 3**nlo_env%order), elements(3, 3**nlo_env%order))
388 nlo_env%elements = .false.
389 CALL section_vals_val_get(section, 'ELEMENTS', n_rep_val=n_rep)
390 DO i_rep = 1, max(1, n_rep)
391 NULLIFY (words)
392 CALL section_vals_val_get(section, 'ELEMENTS', i_rep_val=i_rep, c_vals=words)
393 IF (.NOT. ASSOCIATED(words)) cpabort('NLO ELEMENTS list is empty.')
394 IF (any(words == '-1') .AND. n_rep > 1) THEN
395 cpabort('NLO ELEMENTS: -1 cannot be repeated.')
396 END IF
397 CALL parse_nlo_elements(words, nlo_env%order, elements)
398 nlo_env%elements(:, :) = nlo_env%elements .OR. elements
399 END DO
400
401 END SUBROUTINE read_nlo_elements
402
403! **************************************************************************************************
404!> \brief Decode Cartesian output/input strings into the selected tensor elements.
405!> \param tokens Cartesian tensor-index strings from an ELEMENTS keyword.
406!> \param order Number of incident electric fields.
407!> \param elements Unique, validated tensor-index selections.
408!> \note elements(c,1+sum_j(a_j-1)*3**(j-1)) selects χ_(c;a_1,...,a_order).
409! **************************************************************************************************
410 SUBROUTINE parse_nlo_elements(tokens, order, elements)
411 CHARACTER(len=*), INTENT(IN) :: tokens(:)
412 INTEGER, INTENT(IN) :: order
413 LOGICAL, INTENT(OUT) :: elements(:, :)
414
415 CHARACTER(len=6) :: element
416 INTEGER :: i_code, i_direction, i_letter, i_out, &
417 i_token
418
419 elements = .false.
420 IF (order < 2 .OR. order > 5) THEN
421 cpabort('NONLINEAR_OPTICS ELEMENTS requires ORDER 2 through 5.')
422 END IF
423 IF (any(shape(elements) /= [3, 3**order]) .OR. SIZE(tokens) == 0) THEN
424 cpabort('NLO ELEMENTS list is empty.')
425 END IF
426 IF (any(tokens == '-1')) THEN
427 IF (SIZE(tokens) /= 1) cpabort('NLO ELEMENTS: -1 must appear alone.')
428 elements = .true.
429 RETURN
430 END IF
431 DO i_token = 1, SIZE(tokens)
432 IF (len_trim(tokens(i_token)) /= order + 1) THEN
433 cpabort('NLO ELEMENTS: use ORDER+1 letters, output first.')
434 END IF
435 element = tokens(i_token)
436 CALL uppercase(element)
437 i_out = 0
438 i_code = 1
439 DO i_letter = 1, order + 1
440 i_direction = index('XYZ', element(i_letter:i_letter))
441 IF (i_direction == 0) THEN
442 cpabort('NONLINEAR_OPTICS ELEMENTS: use only X, Y, Z in each element.')
443 END IF
444 IF (i_letter == 1) THEN
445 i_out = i_direction
446 ELSE
447 i_code = i_code + (i_direction - 1)*3**(i_letter - 2)
448 END IF
449 END DO
450 elements(i_out, i_code) = .true.
451 END DO
452
453 END SUBROUTINE parse_nlo_elements
454
455! **************************************************************************************************
456!> \brief Parse VALUE, RANGE, SAME_AS or MINUS_OF for input frequency i_frequency.
457!> \param tokens Values of the incident-frequency keyword.
458!> \param i_frequency One-based index of the incident frequency.
459!> \param frequency Parsed single, ranged, or linked incident frequency.
460! **************************************************************************************************
461 SUBROUTINE parse_nlo_frequency(tokens, i_frequency, frequency)
462 CHARACTER(len=*), INTENT(IN) :: tokens(:)
463 INTEGER, INTENT(IN) :: i_frequency
464 TYPE(nlo_frequency_type), INTENT(OUT) :: frequency
465
466 CHARACTER(len=32) :: mode, reference_name
467 INTEGER :: i_reference, io_error
468 REAL(kind=dp) :: end_ev, interval_count
469
470 frequency = nlo_frequency_type()
471 IF (i_frequency < 1 .OR. i_frequency > 5 .OR. SIZE(tokens) < 1) THEN
472 cpabort('Invalid FREQ index or empty frequency specification.')
473 END IF
474 mode = tokens(1)
475 CALL uppercase(mode)
476 SELECT CASE (trim(mode))
477 CASE ('VALUE')
478 IF (SIZE(tokens) /= 2) cpabort('FREQ VALUE needs one energy in eV.')
479 READ (tokens(2), *, iostat=io_error) frequency%start_ev
480 IF (io_error /= 0) cpabort('FREQ VALUE requires a finite photon energy in eV.')
481 IF (.NOT. ieee_is_finite(frequency%start_ev)) THEN
482 cpabort('FREQ VALUE requires a finite photon energy in eV.')
483 END IF
484 frequency%n_values = 1
485 CASE ('RANGE')
486 IF (SIZE(tokens) /= 4) cpabort('FREQ RANGE requires start, end and step in eV.')
487 READ (tokens(2), *, iostat=io_error) frequency%start_ev
488 IF (io_error /= 0) cpabort('Invalid FREQ RANGE start energy.')
489 READ (tokens(3), *, iostat=io_error) end_ev
490 IF (io_error /= 0) cpabort('Invalid FREQ RANGE end energy.')
491 READ (tokens(4), *, iostat=io_error) frequency%step_ev
492 IF (io_error /= 0) cpabort('Invalid FREQ RANGE step energy.')
493 IF (.NOT. ieee_is_finite(frequency%start_ev) .OR. .NOT. ieee_is_finite(end_ev) .OR. &
494 .NOT. ieee_is_finite(frequency%step_ev)) THEN
495 cpabort('FREQ RANGE energies and step must be finite.')
496 END IF
497 IF (frequency%step_ev <= 0.0_dp .OR. end_ev < frequency%start_ev) THEN
498 cpabort('FREQ RANGE requires positive step and end >= start.')
499 END IF
500 interval_count = (end_ev - frequency%start_ev)/frequency%step_ev
501 IF (.NOT. ieee_is_finite(interval_count) &
502 .OR. interval_count >= real(huge(frequency%n_values) - 1, kind=dp)) THEN
503 cpabort('FREQ RANGE contains too many values.')
504 END IF
505 frequency%n_values = 1 + floor(interval_count + &
506 32.0_dp*epsilon(interval_count)*max(1.0_dp, interval_count))
507 CASE ('SAME_AS', 'MINUS_OF')
508 IF (SIZE(tokens) /= 2) cpabort('FREQ relation needs one earlier index.')
509 reference_name = tokens(2)
510 CALL uppercase(reference_name)
511 IF (len_trim(reference_name) /= 6 .OR. reference_name(1:5) /= 'FREQ_') THEN
512 cpabort('Frequency reference must be FREQ_1, FREQ_2, etc.')
513 END IF
514 READ (reference_name(6:6), *, iostat=io_error) i_reference
515 IF (io_error /= 0) cpabort('Invalid frequency reference index.')
516 IF (i_reference < 1 .OR. i_reference >= i_frequency) THEN
517 cpabort('Frequency references must point to an earlier FREQ.')
518 END IF
519 frequency%reference = i_reference
520 IF (trim(mode) == 'MINUS_OF') frequency%sign = -1
521 CASE DEFAULT
522 cpabort('FREQ must use VALUE, RANGE, SAME_AS or MINUS_OF.')
523 END SELECT
524
525 END SUBROUTINE parse_nlo_frequency
526
527! **************************************************************************************************
528!> \brief Count independent frequency combinations without materializing the Cartesian product.
529!> \param frequencies Parsed incident-frequency definitions.
530!> \param order Number of active incident frequencies.
531!> \param n_frequency_combinations Product of independent range lengths.
532! **************************************************************************************************
533 SUBROUTINE nlo_frequency_case_count(frequencies, order, n_frequency_combinations)
534 TYPE(nlo_frequency_type), INTENT(IN) :: frequencies(5)
535 INTEGER, INTENT(IN) :: order
536 INTEGER, INTENT(OUT) :: n_frequency_combinations
537
538 INTEGER :: i_frequency
539
540 n_frequency_combinations = 1
541 IF (order < 2 .OR. order > 5) cpabort('NLO ORDER must be between 2 and 5.')
542 DO i_frequency = 1, order
543 IF (frequencies(i_frequency)%reference > 0) THEN
544 IF (frequencies(i_frequency)%reference >= i_frequency) THEN
545 cpabort('Frequency reference must point to an earlier FREQ.')
546 END IF
547 ELSE
548 IF (frequencies(i_frequency)%n_values < 1) THEN
549 cpabort('Every input frequency through ORDER must be specified.')
550 END IF
551 IF (n_frequency_combinations > &
552 huge(n_frequency_combinations)/frequencies(i_frequency)%n_values) THEN
553 cpabort('Too many independent frequency combinations.')
554 END IF
555 n_frequency_combinations = n_frequency_combinations*frequencies(i_frequency)%n_values
556 END IF
557 END DO
558
559 END SUBROUTINE nlo_frequency_case_count
560
561! **************************************************************************************************
562!> \brief Resolve one Cartesian-product case, preserving SAME_AS and MINUS_OF links.
563!> \param frequencies Parsed incident-frequency definitions.
564!> \param order Number of active incident frequencies.
565!> \param i_case One-based index of the requested range combination.
566!> \param energy_ev Resolved incident photon energies in eV.
567!> \param zero_output Whether the sum of incident photon energies is zero.
568! **************************************************************************************************
569 SUBROUTINE nlo_frequency_case(frequencies, order, i_case, energy_ev, zero_output)
570 TYPE(nlo_frequency_type), INTENT(IN) :: frequencies(5)
571 INTEGER, INTENT(IN) :: order, i_case
572 REAL(kind=dp), INTENT(OUT) :: energy_ev(5)
573 LOGICAL, INTENT(OUT) :: zero_output
574
575 INTEGER :: case_offset, i_frequency, i_value, &
576 n_frequency_combinations
577 REAL(kind=dp) :: scale
578
579 energy_ev = 0.0_dp
580 zero_output = .false.
581 CALL nlo_frequency_case_count(frequencies, order, n_frequency_combinations)
582 IF (i_case < 1 .OR. i_case > n_frequency_combinations) THEN
583 cpabort('Frequency case index is out of range.')
584 END IF
585 case_offset = i_case - 1
586 DO i_frequency = 1, order
587 IF (frequencies(i_frequency)%reference > 0) THEN
588 energy_ev(i_frequency) &
589 = frequencies(i_frequency)%sign*energy_ev(frequencies(i_frequency)%reference)
590 ELSE
591 i_value = mod(case_offset, frequencies(i_frequency)%n_values)
592 case_offset = case_offset/frequencies(i_frequency)%n_values
593 energy_ev(i_frequency) = frequencies(i_frequency)%start_ev &
594 + i_value*frequencies(i_frequency)%step_ev
595 END IF
596 END DO
597 scale = max(1.0_dp, sum(abs(energy_ev(1:order))))
598 zero_output = abs(sum(energy_ev(1:order))) <= 64.0_dp*epsilon(scale)*scale
599
600 END SUBROUTINE nlo_frequency_case
601
602END MODULE nlo_read_input
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public cheng2015
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
Definition cp_units.F:1282
represents keywords in an input
subroutine, public keyword_release(keyword)
releases the given keyword (see doc/ReferenceCounting.html)
subroutine, public keyword_create(keyword, location, name, description, usage, type_of_var, n_var, repeats, variants, default_val, default_l_val, default_r_val, default_lc_val, default_c_val, default_i_val, default_l_vals, default_r_vals, default_c_vals, default_i_vals, lone_keyword_val, lone_keyword_l_val, lone_keyword_r_val, lone_keyword_c_val, lone_keyword_i_val, lone_keyword_l_vals, lone_keyword_r_vals, lone_keyword_c_vals, lone_keyword_i_vals, enum_c_vals, enum_i_vals, enum, enum_strict, enum_desc, unit_str, citations, deprecation_notice, removed)
creates a keyword object
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_create(section, location, name, description, n_keywords, n_subsections, repeats, citations, deprecation_notice)
creates a list of keywords
subroutine, public section_add_keyword(section, keyword)
adds a keyword to the given section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
a wrapper for basic fortran types.
integer, parameter, public real_t
integer, parameter, public char_t
integer, parameter, public integer_t
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
subroutine, public read_nlo_input(qs_env, nlo_env)
Read the activated input into nlo_env and reject invalid frequency combinations.
subroutine, public nlo_frequency_case(frequencies, order, i_case, energy_ev, zero_output)
Resolve one Cartesian-product case, preserving SAME_AS and MINUS_OF links.
subroutine, public create_nonlinear_optics_section(section)
Define the nonlinear susceptibility model, conventions, and input parameters.
subroutine, public nlo_frequency_case_count(frequencies, order, n_frequency_combinations)
Count independent frequency combinations without materializing the Cartesian product.
Nonlinear optical environment: input parameters and data shared by calculation stages.
Definition nlo_types.F:10
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.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
represent a keyword in the input
represent a section of the input file
a type to have a wrapper that stores any basic fortran type