Octopus
propagator_elec.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use accel_oct_m
23 use debug_oct_m
29 use forces_oct_m
31 use grid_oct_m
32 use global_oct_m
36 use ions_oct_m
37 use, intrinsic :: iso_fortran_env
38 use lasers_oct_m
39 use lda_u_oct_m
41 use parser_oct_m
59 use scf_oct_m
61 use space_oct_m
63 use stress_oct_m
65 use v_ks_oct_m
67 use xc_oct_m
68
69 implicit none
70
71 private
72 public :: &
81
82contains
83
84 ! ---------------------------------------------------------
85 subroutine propagator_elec_copy(tro, tri)
86 type(propagator_base_t), intent(inout) :: tro
87 type(propagator_base_t), intent(in) :: tri
88
89 push_sub(propagator_elec_copy)
90
91 tro%method = tri%method
92
93 select case (tro%method)
95 tro%tdsk_size = tri%tdsk_size
96 call sparskit_solver_copy(tro%tdsk, tri%tdsk)
97
99 tro%tdsk_size = tri%tdsk_size
100 call sparskit_solver_copy(tro%tdsk, tri%tdsk)
101
102 case (prop_runge_kutta2)
103 tro%tdsk_size = tri%tdsk_size
104 call sparskit_solver_copy(tro%tdsk, tri%tdsk)
105
106 end select
107
108 call potential_interpolation_copy(tro%vks_old, tri%vks_old)
109
110 call exponential_copy(tro%te, tri%te)
111 tro%scf_propagation_steps = tri%scf_propagation_steps
112
113 tro%scf_threshold = tri%scf_threshold
114 pop_sub(propagator_elec_copy)
115 end subroutine propagator_elec_copy
116 ! ---------------------------------------------------------
117
118
119 ! ---------------------------------------------------------
120 subroutine propagator_elec_init(gr, namespace, st, tr, ks_pot, have_fields, family_is_mgga_with_exc, relax_cell)
121 type(grid_t), intent(in) :: gr
122 type(namespace_t), intent(in) :: namespace
123 type(states_elec_t), intent(in) :: st
124 type(propagator_base_t), intent(inout) :: tr
125 type(ks_potential_t), intent(in) :: ks_pot
129 logical, intent(in) :: have_fields
130 logical, intent(in) :: family_is_mgga_with_exc
131 logical, intent(in) :: relax_cell
132
133 push_sub(propagator_elec_init)
134
135 !%Variable TDPropagator
136 !%Type integer
137 !%Default etrs
138 !%Section Time-Dependent::Propagation
139 !%Description
140 !% This variable determines which algorithm will be used to approximate
141 !% the evolution operator <math>U(t+\delta t, t)</math>. That is, given
142 !% <math>\psi(\tau)</math> and <math>H(\tau)</math> for <math>\tau \le t</math>,
143 !% calculate <math>t+\delta t</math>. Note that in general the Hamiltonian
144 !% is not known at times in the interior of the interval <math>[t,t+\delta t]</math>.
145 !% This is due to the self-consistent nature of the time-dependent Kohn-Sham problem:
146 !% the Hamiltonian at a given time <math>\tau</math> is built from the
147 !% "solution" wavefunctions at that time.
148 !%
149 !% Some methods, however, do require the knowledge of the Hamiltonian at some
150 !% point of the interval <math>[t,t+\delta t]</math>. This problem is solved by making
151 !% use of extrapolation: given a number <math>l</math> of time steps previous to time
152 !% <math>t</math>, this information is used to build the Hamiltonian at arbitrary times
153 !% within <math>[t,t+\delta t]</math>. To be fully precise, one should then proceed
154 !% <i>self-consistently</i>: the obtained Hamiltonian at time <math>t+\delta t</math>
155 !% may then be used to interpolate the Hamiltonian, and repeat the evolution
156 !% algorithm with this new information. Whenever iterating the procedure does
157 !% not change the solution wavefunctions, the cycle is stopped. In practice,
158 !% in <tt>Octopus</tt> we perform a second-order extrapolation without a
159 !% self-consistency check, except for the first two iterations, where obviously
160 !% the extrapolation is not reliable.
161 !%
162 !% The proliferation of methods is certainly excessive. The reason for it is that
163 !% the propagation algorithm is currently a topic of active development. We
164 !% hope that in the future the optimal schemes are clearly identified. In the
165 !% mean time, if you do not feel like testing, use the default choices and
166 !% make sure the time step is small enough.
167 !%
168 !% More details about the propagation methods could be found in
169 !% A. Castro, M.A.L. Marques, and A. Rubio, J. Chem. Phys 121 3425-3433 (2004)
170 !% and
171 !% A. Pueyo et al., J. Chem. Theory Comput. 14, 6, 3040 (2018)
172 !%
173 !%Option etrs 2
174 !% The idea is to make use of time-reversal symmetry from the beginning:
175 !%
176 !% <math>
177 !% \exp \left(-i\delta t H_{n} / 2 \right)\psi_n = \exp \left(i\delta t H_{n+1} / 2 \right)\psi_{n+1},
178 !% </math>
179 !%
180 !% and then invert to obtain:
181 !%
182 !% <math>
183 !% \psi_{n+1} = \exp \left(-i\delta t H_{n+1} / 2 \right) \exp \left(-i\delta t H_{n} / 2 \right)\psi_{n}.
184 !% </math>
185 !%
186 !% But we need to know <math>H_{n+1}</math>, which can only be known exactly through the solution
187 !% <math>\psi_{n+1}</math>. What we do is to estimate it by performing a single exponential:
188 !% <math>\psi\^{\*}\_{n+1}=\exp \left( -i\delta t H_{n} \right) \psi_n</math>, and then
189 !% <math>H_{n+1} = H[\psi\^{\*}_{n+1}]</math>. Thus no extrapolation is performed in this case.
190 !%Option aetrs 3
191 !% Approximated Enforced Time-Reversal Symmetry (AETRS).
192 !% A modification of previous method to make it faster.
193 !% It is based on extrapolation of the time-dependent potentials. It is faster
194 !% by about 40%.
195 !% The only difference is the procedure to estimate <math>H_{n+1}</math>: in this case
196 !% it is extrapolated via a second-order polynomial by making use of the
197 !% Hamiltonian at time <math>t-2\delta t</math>, <math>t-\delta t</math> and <math>t</math>.
198 !%Option caetrs 12
199 !% (experimental) Corrected Approximated Enforced Time-Reversal
200 !% Symmetry (AETRS), this is the previous propagator but including
201 !% a correction step to the exponential.
202 !%Option exp_mid 4
203 !% Exponential Midpoint Rule (EM).
204 !% This is maybe the simplest method, but it is very well grounded theoretically:
205 !% it is unitary (if the exponential is performed correctly) and preserves
206 !% time-reversal symmetry (if the self-consistency problem is dealt with correctly).
207 !% It is defined as:
208 !% <math>
209 !% U_{\rm EM}(t+\delta t, t) = \exp \left( -i\delta t H_{t+\delta t/2}\right)\,.
210 !% </math>
211 !%Option crank_nicholson 5
212 !%Option crank_nicolson 5
213 !% Classical Crank-Nicolson propagator.
214 !% <math>
215 !% (1 + i\delta t H_{n+1/2} / 2) \psi_{n+1} = (1 - i\delta t H_{n+1/2} / 2) \psi_{n}
216 !% </math>
217 !%Option crank_nicholson_sparskit 6
218 !%Option crank_nicolson_sparskit 6
219 !% Classical Crank-Nicolson propagator. Requires the SPARSKIT library.
220 !% <math>
221 !% (1 + i\delta t H_{n+1/2} / 2) \psi_{n+1} = (1 - i\delta t H_{n+1/2} / 2) \psi_{n}
222 !% </math>
223 !%Option magnus 7
224 !% Magnus Expansion (M4).
225 !% This is the most sophisticated approach. It is a fourth-order scheme (a feature
226 !% which it shares with the ST scheme; the other schemes are in principle second-order).
227 !% It is tailored for making use of very large time steps, or equivalently,
228 !% dealing with problem with very high-frequency time-dependence.
229 !% It is still in a experimental state; we are not yet sure of when it is
230 !% advantageous.
231 !%Option qoct_tddft_propagator 10
232 !% WARNING: EXPERIMENTAL
233 !%Option runge_kutta4 13
234 !% WARNING: EXPERIMENTAL. Implicit Gauss-Legendre 4th order Runge-Kutta.
235 !%Option runge_kutta2 14
236 !% WARNING: EXPERIMENTAL. Implicit 2nd order Runge-Kutta (trapezoidal rule).
237 !% Similar, but not identical, to Crank-Nicolson method.
238 !%Option expl_runge_kutta4 15
239 !% WARNING: EXPERIMENTAL. Explicit RK4 method.
240 !%Option cfmagnus4 16
241 !% Commutator-free magnus expansion. This method has been developed for linear
242 !% systems and involves products of exponentials to avoid commutators. To apply it
243 !% to our non-linear equations, we extrapolate the potential from previous timesteps
244 !% to the times needed.The fourth-ordermethod implemented here follows equation 54
245 !% in Gómez Pueyo, A., Marques, M. A. L., Rubio, A. & Castro, A. Propagators for the
246 !% Time-Dependent Kohn–Sham Equations: Multistep, Runge–Kutta, Exponential Runge–Kutta,
247 !% and Commutator Free Magnus Methods. J. Chem. Theory Comput. 14, 3040–3052 (2018)
248 !% which corresponds to equation 43 in Blanes, S. & Moan, P. C. Fourth- and sixth-order
249 !% commutator-free Magnus integrators for linear and non-linear dynamical systems.
250 !% Applied Numerical Mathematics 56, 1519–1537 (2006):
251 !% <math>
252 !% \psi(t+\Delta t) = \exp(-i \Delta t ( \alpha_1 H(t_1) + \alpha_2 H(t_2) ) )
253 !% \exp(-i \Delta t ( \alpha_2 H(t_1) + \alpha_1 H(t_2) ) ) \psi(t),
254 !% </math>
255 !% with $\alpha_{1,2} = \frac{3\mp 2\sqrt{3}}{12}$ and $t_i = t_0 + c_i \Delta t$,
256 !% $c_{1,2} = \frac{1}{2} \mp \frac{\sqrt{3}}{6}$.
257 !% Still in experimental state.
258 !%Option exp_mid_predictor 17
259 !% Exponential Midpoint Rule (EM).
260 !% This is maybe the simplest method, but it is very well grounded theoretically:
261 !% it is unitary (if the exponential is performed correctly) and preserves
262 !% time-reversal symmetry (if the self-consistency problem is dealt with correctly).
263 !% It is defined as:
264 !% <math>
265 !% U_{\rm EM}(t+\delta t, t) = \exp \left( -i\delta t H_{t+\delta t/2}\right)\,.
266 !% </math>
267 !% As opposed to the exp_mid propagator, $H_{t+\delta t/2}$ is not obtained by
268 !% extrapolation from previous timesteps, but by predicting by applying the exponential with
269 !% $\delta t/2$ and computing the corresponding density and potential.
270 !% It is equivalent to an explicit Magnus integration of second order, see equation 20 in
271 !% Casas, F. & Iserles, A. Explicit Magnus expansions for nonlinear equations. J. Phys. A: Math. Gen. 39,
272 !% 5445 (2006) [https://dx.doi.org/10.1088/0305-4470/39/19/S07]
273 !%Option explicit_magnus3 18
274 !% Third-order explicit Magnus expansion.
275 !% This method follows equations 22 in
276 !% Casas, F. & Iserles, A. Explicit Magnus expansions for nonlinear equations.
277 !% J. Phys. A: Math. Gen. 39, 5445 (2006) [https://dx.doi.org/10.1088/0305-4470/39/19/S07]
278 !% Applying eq. 22 to our notation for the Schrödinger equation yields:
279 !% <math>
280 !% \psi_0 = \psi(t) \\
281 !% H_1 = H(t, \psi_0) \\
282 !% \psi_2 = \exp(-i \frac{\Delta t}{2} H_1) \psi_0 \\
283 !% H_2 = H(t+\frac{\Delta t}{2}, \psi_2) \\
284 !% \psi_3 = \exp(-i \frac{\Delta t}{4} (H_1 + H_2)) \psi_0 \\
285 !% H_3 = H(t+\frac{\Delta t}{2}, \psi_3) \\
286 !% \psi_4 = \exp(-i \Delta t H_2) \psi_0 \\
287 !% H_4 = H(t+\Delta t, \psi_4) \\
288 !% \psi(t+\Delta t) = \exp(-i \Delta t ( \frac{1}{6}(H_1 + 4 H_3 + H_4)
289 !% + \frac{i \Delta t}{12} ( [H_1 + H_2, H_3] + [H_2, H_4]))) \psi_0
290 !% </math>
291 !% Still in experimental state.
292 !%End
293 call messages_obsolete_variable(namespace, 'TDEvolutionMethod', 'TDPropagator')
294
295 call parse_variable(namespace, 'TDPropagator', prop_etrs, tr%method)
296 if (.not. varinfo_valid_option('TDPropagator', tr%method)) call messages_input_error(namespace, 'TDPropagator')
297
298 select case (tr%method)
299 case (prop_etrs)
300 case (prop_aetrs)
301 case (prop_caetrs)
302 call messages_experimental("CAETRS propagator", namespace=namespace)
306 ! set up pointer for zmf_dotu_aux, zmf_nrm2_aux
307 call mesh_init_mesh_aux(gr)
308 case (prop_runge_kutta4)
309 ! set up pointer for zmf_dotu_aux, zmf_nrm2_aux
310 call mesh_init_mesh_aux(gr)
312 tr%tdsk_size = 2 * st%d%dim * gr%np * (st%st_end - st%st_start + 1) * (st%d%kpt%end - st%d%kpt%start + 1)
313 call sparskit_solver_init(namespace, tr%tdsk_size, tr%tdsk, .true.)
314
315#ifndef HAVE_SPARSKIT
316 message(1) = 'Octopus was not compiled with support for the SPARSKIT library. This'
317 message(2) = 'library is required if the "runge_kutta4" propagator is selected.'
318 message(3) = 'Try using a different propagation scheme or recompile with SPARSKIT support.'
319 call messages_fatal(3, namespace=namespace)
320#endif
321
322 call messages_experimental("Runge-Kutta 4 propagator", namespace=namespace)
323 case (prop_runge_kutta2)
324
325 ! set up pointer for zmf_dotu_aux, zmf_nrm2_aux
326 call mesh_init_mesh_aux(gr)
328 tr%tdsk_size = st%d%dim * gr%np * (st%st_end - st%st_start + 1) * (st%d%kpt%end - st%d%kpt%start + 1)
329 call sparskit_solver_init(namespace, tr%tdsk_size, tr%tdsk, .true.)
330
331#ifndef HAVE_SPARSKIT
332 message(1) = 'Octopus was not compiled with support for the SPARSKIT library. This'
333 message(2) = 'library is required if the "runge_kutta2" propagator is selected.'
334 message(3) = 'Try using a different propagation scheme or recompile with SPARSKIT support.'
335 call messages_fatal(3, namespace=namespace)
336#endif
337
338 call messages_experimental("Runge-Kutta 2 propagator", namespace=namespace)
340 ! set up pointer for zmf_dotu_aux
341 call mesh_init_mesh_aux(gr)
343 tr%tdsk_size = st%d%dim*gr%np
344 call sparskit_solver_init(namespace, st%d%dim*gr%np, tr%tdsk, .true.)
345
346#ifndef HAVE_SPARSKIT
347 message(1) = 'Octopus was not compiled with support for the SPARSKIT library. This'
348 message(2) = 'library is required if the "crank_nicolson_sparskit" propagator is selected.'
349 message(3) = 'Try using a different propagation scheme or recompile with SPARSKIT support.'
350 call messages_fatal(3, namespace=namespace)
351#endif
352 case (prop_magnus)
353 call messages_experimental("Magnus propagator", namespace=namespace)
354 if (family_is_mgga_with_exc) then
355 message(1) = "Magnus propagator with MGGA"
356 call messages_fatal(1, namespace=namespace)
357 end if
359 call messages_experimental("QOCT+TDDFT propagator", namespace=namespace)
361 call messages_experimental("explicit Runge-Kutta 4 propagator", namespace=namespace)
362 case (prop_cfmagnus4)
363 call messages_experimental("Commutator-Free Magnus propagator", namespace=namespace)
365 call messages_experimental("Explicit Magnus 3 propagator", namespace=namespace)
366 case default
367 call messages_input_error(namespace, 'TDPropagator')
368 end select
369 call messages_print_var_option('TDPropagator', tr%method, namespace=namespace)
370
371 if (have_fields) then
372 if (tr%method /= prop_etrs .and. &
373 tr%method /= prop_aetrs .and. &
374 tr%method /= prop_exponential_midpoint .and. &
375 tr%method /= prop_exponential_midpoint_predictor .and. &
376 tr%method /= prop_cfmagnus4 .and. &
377 tr%method /= prop_explicit_magnus3 .and. &
378 tr%method /= prop_qoct_tddft_propagator .and. &
379 tr%method /= prop_crank_nicolson .and. &
380 tr%method /= prop_runge_kutta4 .and. &
381 tr%method /= prop_explicit_runge_kutta4 .and. &
382 tr%method /= prop_runge_kutta2 .and. &
383 tr%method /= prop_crank_nicolson_sparskit) then
384 message(1) = "To move the ions or put in a gauge field, use one of the following propagators:"
385 message(2) = "etrs, aetrs, cfmagnus4, crank-nicolson, rk2, rk4, or exp_mid."
386 call messages_fatal(2, namespace=namespace)
387 end if
388 end if
389
390 if (relax_cell) then
391 if (tr%method /= prop_etrs .and. &
392 tr%method /= prop_aetrs .and. &
393 tr%method /= prop_exponential_midpoint .and. &
394 tr%method /= prop_exponential_midpoint_predictor .and. &
395 tr%method /= prop_cfmagnus4 .and. &
396 tr%method /= prop_explicit_magnus3 .and. &
397 tr%method /= prop_crank_nicolson .and. &
398 tr%method /= prop_crank_nicolson_sparskit) then
399 message(1) = "To relax the cell, use the one of the following propagators:"
400 message(2) = "etrs, aetrs, cfmagnus4, crank-nicolson, or exp_mid."
401 call messages_fatal(2, namespace=namespace)
402 end if
403 end if
404
405 select case (tr%method)
406 case (prop_cfmagnus4)
407 call ks_pot%init_interpolation(tr%vks_old, order = 4)
408 case default
409 call ks_pot%init_interpolation(tr%vks_old)
410 end select
411
412 call exponential_init(tr%te, namespace) ! initialize propagator
413
414 ! Fences for ultrasoft/PAW real-time propagation.
415 if (st%requires_generalized_overlap) then
416 ! Only the exp_mid, exp_mid_predictor, etrs and aetrs propagators are wired through the
417 ! S^{-1}H operator (Castro et al., J. Chem. Phys. 121, 3425 (2004)).
418 if (tr%method /= prop_etrs .and. tr%method /= prop_aetrs .and. &
419 tr%method /= prop_exponential_midpoint .and. &
420 tr%method /= prop_exponential_midpoint_predictor) then
422 "TDDFT with ultrasoft/PAW for this propagator (use etrs, aetrs, exp_mid or exp_mid_predictor)", &
423 namespace=namespace)
424 end if
425
426 ! A = S^{-1}H is not Euclidean-Hermitian, so the Chebyshev expansion (which assumes a real
427 ! spectrum with known bounds) is not applicable. Taylor and Lanczos (Arnoldi) are fine.
428 if (tr%te%exp_method /= exp_taylor .and. tr%te%exp_method /= exp_lanczos) then
430 "Chebyshev exponential with ultrasoft/PAW (use taylor or lanczos)", namespace=namespace)
431 end if
432
433 if (accel_is_enabled()) then
434 call messages_not_implemented("TDDFT with ultrasoft/PAW on GPU/accelerators", namespace=namespace)
435 end if
436
437 ! Moving ions are fenced separately at the call site (where the ion-dynamics object is
438 ! available); cell relaxation is fenced here.
439 if (relax_cell) then
440 call messages_not_implemented("TDDFT with ultrasoft/PAW and cell relaxation", namespace=namespace)
441 end if
442 end if
443
444 call messages_obsolete_variable(namespace, 'TDSelfConsistentSteps', 'TDStepsWithSelfConsistency')
445
446 !%Variable TDStepsWithSelfConsistency
447 !%Type integer
448 !%Default 0
449 !%Section Time-Dependent::Propagation
450 !%Description
451 !% Since the KS propagator is non-linear, each propagation step
452 !% should be performed self-consistently. In practice, for most
453 !% purposes this is not necessary, except perhaps in the first
454 !% iterations. This variable holds the number of propagation steps
455 !% for which the propagation is done self-consistently.
456 !%
457 !% The special value <tt>all_steps</tt> forces self-consistency to
458 !% be imposed on all propagation steps. A value of 0 means that
459 !% self-consistency will not be imposed. The default is 0.
460 !%Option all_steps -1
461 !% Self-consistency is imposed for all propagation steps.
462 !%End
463
464 call parse_variable(namespace, 'TDStepsWithSelfConsistency', 0, tr%scf_propagation_steps)
465
466 if (tr%scf_propagation_steps == -1) tr%scf_propagation_steps = huge(tr%scf_propagation_steps)
467 if (tr%scf_propagation_steps < 0) call messages_input_error(namespace, 'TDStepsWithSelfConsistency', 'Cannot be negative')
468
469 if (tr%scf_propagation_steps /= 0) then
470 call messages_experimental('TDStepsWithSelfConsistency', namespace=namespace)
471
472 if (tr%method /= prop_etrs .and. tr%method /= prop_aetrs .and. tr%method /= prop_cfmagnus4) then
473 call messages_write('TDStepsWithSelfConsistency only works with the ETRS/AETRS/CFM4 propagators')
474 call messages_fatal(namespace=namespace)
475 end if
476 end if
477
478 !%Variable TDSCFThreshold
479 !%Type float
480 !%Default 1.0e-6
481 !%Section Time-Dependent::Propagation
482 !%Description
483 !% Since the KS propagator is non-linear, each propagation step
484 !% should be performed self-consistently. In practice, for most
485 !% purposes this is not necessary, except perhaps in the first
486 !% iterations. This variable holds the number of propagation steps
487 !% for which the propagation is done self-consistently.
488 !%
489 !% The self consistency has to be measured against some accuracy
490 !% threshold. This variable controls the value of that threshold.
491 !%End
492 call parse_variable(namespace, 'TDSCFThreshold', 1.0e-6_real64, tr%scf_threshold)
493
494 pop_sub(propagator_elec_init)
495 end subroutine propagator_elec_init
496 ! ---------------------------------------------------------
497
498
499 ! ---------------------------------------------------------
500 subroutine propagator_elec_set_scf_prop(tr, threshold)
501 type(propagator_base_t), intent(inout) :: tr
502 real(real64), optional, intent(in) :: threshold
503
505
506 tr%scf_propagation_steps = huge(1)
507 if (present(threshold)) then
508 tr%scf_threshold = threshold
509 end if
510
512 end subroutine propagator_elec_set_scf_prop
513 ! ---------------------------------------------------------
514
515
516 ! ---------------------------------------------------------
518 type(propagator_base_t), intent(inout) :: tr
519
521
522 tr%scf_propagation_steps = -1
523
526 ! ---------------------------------------------------------
527
528
529 ! ---------------------------------------------------------
530 subroutine propagator_elec_end(tr)
531 type(propagator_base_t), intent(inout) :: tr
532
533 push_sub(propagator_elec_end)
534
535 call potential_interpolation_end(tr%vks_old)
536
537 select case (tr%method)
539 call propagator_rk_end()
540 call sparskit_solver_end(tr%tdsk)
541
543 call sparskit_solver_end(tr%tdsk)
544
545 end select
546
547 if (allocated(tr%st)) then
548 call states_elec_end(tr%st)
549 safe_deallocate_a(tr%st)
550 end if
551
552 pop_sub(propagator_elec_end)
553 end subroutine propagator_elec_end
554 ! ---------------------------------------------------------
555
556
557 ! ---------------------------------------------------------
560 ! ---------------------------------------------------------
561 subroutine propagator_elec_dt(ks, namespace, space, hm, gr, st, tr, time, dt, nt, &
562 ions_dyn, ions, ext_partners, mc, outp, write_handler, scsteps, update_energy, qcchi, dmp)
563 type(v_ks_t), target, intent(inout) :: ks
564 type(namespace_t), intent(in) :: namespace
565 type(electron_space_t), intent(in) :: space
566 type(hamiltonian_elec_t), target, intent(inout) :: hm
567 type(grid_t), target, intent(inout) :: gr
568 type(states_elec_t), target, intent(inout) :: st
569 type(propagator_base_t), target, intent(inout) :: tr
570 real(real64), intent(in) :: time
571 real(real64), intent(in) :: dt
572 integer, intent(in) :: nt
573 type(ion_dynamics_t), intent(inout) :: ions_dyn
574 type(ions_t), intent(inout) :: ions
575 type(partner_list_t), intent(in) :: ext_partners
576 type(multicomm_t), intent(inout) :: mc
577 type(output_t), intent(in) :: outp
578 type(td_write_t), intent(in) :: write_handler
579 integer, optional, intent(out) :: scsteps
580 logical, optional, intent(in) :: update_energy
581 type(opt_control_state_t), optional, target, intent(inout) :: qcchi
582 type(dmp_t), optional, intent(inout) :: dmp
583 type(gauge_field_t), pointer :: gfield
584 type(lasers_t), pointer :: lasers
585 logical :: generate, update_energy_
586 real(real64) :: am(space%dim)
587
588 call profiling_in("TD_PROPAGATOR")
590
591 update_energy_ = optional_default(update_energy, .true.)
592
593 call hm%ks_pot%interpolation_new(tr%vks_old, time, dt)
594
595 if (present(scsteps)) scsteps = 1
596
597 select case (tr%method)
598 case (prop_etrs)
599 if (self_consistent_step()) then
600 call td_etrs_sc(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, &
601 ions_dyn, ions, mc, tr%scf_threshold, scsteps)
602 else
603 call td_etrs(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, &
604 ions_dyn, ions, mc)
605 end if
606 case (prop_aetrs)
607 if (self_consistent_step()) then
608 call td_aetrs_sc(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, &
609 ions_dyn, ions, mc, tr%scf_threshold, scsteps)
610 else
611 call td_aetrs(namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
612 end if
613 case (prop_caetrs)
614 call td_caetrs(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, ions_dyn, ions, mc)
616 call exponential_midpoint(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
618 call exponential_midpoint_predictor(hm, ks, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, &
619 ext_partners, mc)
621 call td_crank_nicolson(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, .false.)
622 case (prop_runge_kutta4)
623 call td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
624 case (prop_runge_kutta2)
625 call td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
627 call td_crank_nicolson(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, .true.)
628 case (prop_magnus)
629 call td_magnus(hm, ext_partners, gr, st, tr, namespace, time, dt)
631 call td_qoct_tddft_propagator(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
633 if (present(qcchi)) then
634 call td_explicit_runge_kutta4(ks, namespace, space, hm, gr, st, time, dt, ions_dyn, ions, ext_partners, qcchi)
635 else
636 call td_explicit_runge_kutta4(ks, namespace, space, hm, gr, st, time, dt, ions_dyn, ions, ext_partners)
637 end if
638 case (prop_cfmagnus4)
639 if (self_consistent_step()) then
640 call td_cfmagnus4_sc(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, &
641 nt, tr%scf_threshold, scsteps)
642 else
643 call td_cfmagnus4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, nt)
644 end if
646 call td_explicit_magnus3(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
647 end select
648
649 generate = .false.
650 if (ions_dyn%is_active()) then
651 if (.not. propagator_elec_ions_are_propagated(tr)) then
652 call propagation_ops_elec_propagate_ions_and_cell(gr, hm, st, namespace, space, &
653 ions_dyn, ions, mc, abs(nt*dt), ions_dyn%ionic_scale*dt)
654 generate = .true.
655 end if
656 end if
657
658 gfield => list_get_gauge_field(ext_partners)
659 if(associated(gfield)) then
660 if (gauge_field_is_propagated(gfield) .and. .not. propagator_elec_ions_are_propagated(tr)) then
662 call propagation_ops_elec_update_hamiltonian(namespace, space, st, gr, hm, ext_partners, time)
663 end if
664 end if
665
666 if (generate .or. ions%has_time_dependent_species()) then
667 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st, time = abs(nt*dt))
668 end if
669
670 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
671 calc_eigenval = update_energy_, time = abs(nt*dt), calc_energy = update_energy_)
672
673 if (present(dmp)) then
674 if (dmp%calculation_mode /= option__tddmpropagation__no_propagation) then
675 call dm_propagation_run(dmp, namespace, space, gr, ions, st, mc, hm, ks, nt, dt, ext_partners, &
676 update_energy = update_energy_)
677 end if
678 end if
679
680 ! compute time integral of the paramagnetic current
681 call ks%v_ks_photons%add_mean_field(ks%gr, space, hm%kpoints, st, abs(nt*dt), dt)
682
683 if (update_energy_) call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit = -1)
684
685 ! Recalculate forces, update velocities...
686 if ((ions_dyn%ions_move() .and. tr%method .ne. prop_explicit_runge_kutta4) .or. &
687 outp%what(option__output__forces) .or. write_handler%out(out_separate_forces)%write) then
688 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, t = abs(nt*dt), dt = dt)
689 end if
690
691 if (ions_dyn%cell_relax() .or. outp%what(option__output__stress)) then
692 call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
693 if(ions_dyn%cell_relax()) then
694 call ions_dyn%update_stress(ions%space, st%stress_tensors%total, ions%latt%rlattice, ions%latt%rcell_volume)
695 end if
696 end if
697
698 if( ions_dyn%is_active()) then
699 call ion_dynamics_propagate_vel(ions_dyn, ions, atoms_moved = generate)
700 call ions%update_kinetic_energy()
701 end if
702
703 if(associated(gfield)) then
704 if(gauge_field_is_propagated(gfield)) then
705 call gauge_field_get_force(gfield, gr, st%d%spin_channels, st%current, ks%xc%lrc)
707 end if
708 end if
709
710 !We update the occupation matrices
711 call lda_u_update_occ_matrices(hm%lda_u, namespace, gr, st, hm%phase, hm%energy, hm%aug_overlap)
712
713 !Updates Nondipole Vector potential
714 lasers => list_get_lasers(ext_partners)
715 if(associated(lasers)) then
716 if (lasers_with_nondipole_field(lasers)) then
717 call lasers_nondipole_laser_field_step(lasers, am, time)
718 call lasers_set_nondipole_parameters(lasers,am,time)
719 end if
720 end if
721 pop_sub(propagator_elec_dt)
722 call profiling_out("TD_PROPAGATOR")
723
724 contains
725
726 ! ---------------------------------------------------------
727 logical pure function self_consistent_step() result(scs)
728 scs = (hm%theory_level /= independent_particles) .and. (time <= tr%scf_propagation_steps*abs(dt) + m_epsilon)
729 end function self_consistent_step
730 ! ---------------------------------------------------------
731
732 end subroutine propagator_elec_dt
733 ! ---------------------------------------------------------
734
735
736
737
738 ! ---------------------------------------------------------
739 logical pure function propagator_elec_ions_are_propagated(tr) result(propagated)
740 type(propagator_base_t), intent(in) :: tr
741
742 select case (tr%method)
743 case (prop_etrs, prop_aetrs, prop_caetrs, prop_explicit_runge_kutta4)
744 propagated = .true.
745 case default
746 propagated = .false.
747 end select
748
750 ! ---------------------------------------------------------
751
752
753 ! ---------------------------------------------------------
754
755 subroutine propagator_elec_dt_bo(scf, namespace, space, gr, ks, st, hm, ions, ext_partners, mc, iter, dt, ions_dyn, scsteps)
756 type(scf_t), intent(inout) :: scf
757 type(namespace_t), intent(in) :: namespace
758 type(electron_space_t), intent(in) :: space
759 type(grid_t), intent(inout) :: gr
760 type(v_ks_t), intent(inout) :: ks
761 type(states_elec_t), intent(inout) :: st
762 type(hamiltonian_elec_t), intent(inout) :: hm
763 type(ions_t), intent(inout) :: ions
764 type(partner_list_t), intent(in) :: ext_partners
765 type(multicomm_t), intent(inout) :: mc
766 integer, intent(in) :: iter
767 real(real64), intent(in) :: dt
768 type(ion_dynamics_t), intent(inout) :: ions_dyn
769 integer, intent(inout) :: scsteps
770
771 type(gauge_field_t), pointer :: gfield
772
773 push_sub(propagator_elec_dt_bo)
774
775 ! move the hamiltonian to time t
776 call propagation_ops_elec_propagate_ions_and_cell(gr, hm, st, namespace, space, &
777 ions_dyn, ions, mc, iter*dt, dt)
778
779 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st, time = iter*dt)
780 ! now calculate the eigenfunctions
781 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, &
782 verbosity = verb_compact, iters_done = scsteps)
783
784 ! Stress tensor calculation and uptade
785 if (ions_dyn%cell_relax()) then
786 if (.not. scf%calc_stress) then
787 call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
788 end if
789 call ions_dyn%update_stress(ions%space, st%stress_tensors%total, ions%latt%rlattice, ions%latt%rcell_volume)
790 end if
791
792 gfield => list_get_gauge_field(ext_partners)
793 if(associated(gfield)) then
794 if (gauge_field_is_propagated(gfield)) then
795 call gauge_field_do_algorithmic_operation(gfield, op_verlet_compute_acc, dt, iter*dt)
796 end if
797 end if
798
799 !TODO: we should update the occupation matrices here
800 if (hm%lda_u_level /= dft_u_none) then
801 call messages_not_implemented("DFT+U with propagator_elec_dt_bo", namespace=namespace)
802 end if
803
804 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st, time = iter*dt)
805
806 ! update Hamiltonian and eigenvalues (fermi is *not* called)
807 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
808 calc_eigenval = .true., time = iter*dt, calc_energy = .true.)
809
810 ! Get the energies.
811 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit = -1)
812
813 call ion_dynamics_propagate_vel(ions_dyn, ions)
814 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st, time = iter*dt)
815 call ions%update_kinetic_energy()
816
817 if(associated(gfield)) then
818 if (gauge_field_is_propagated(gfield)) then
819 call gauge_field_do_algorithmic_operation(gfield, op_verlet_compute_vel, dt, iter*dt)
820 end if
821 end if
822
823 pop_sub(propagator_elec_dt_bo)
824 end subroutine propagator_elec_dt_bo
825
826end module propagator_elec_oct_m
828
829!! Local Variables:
830!! mode: f90
831!! coding: utf-8
832!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
subroutine, public dm_propagation_run(dmp, namespace, space, gr, ions, st, mc, hm, ks, iter, dt, ext_partners, update_energy)
Density matrix propagation.
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
subroutine, public exponential_copy(teo, tei)
subroutine, public exponential_init(te, namespace, full_batch)
integer, parameter, public exp_taylor
integer, parameter, public exp_lanczos
type(gauge_field_t) function, pointer, public list_get_gauge_field(partners)
type(lasers_t) function, pointer, public list_get_lasers(partners)
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
Definition: forces.F90:319
subroutine, public gauge_field_get_force(this, gr, spin_channels, current, lrc)
subroutine, public gauge_field_do_algorithmic_operation(this, operation, dt, time)
logical pure function, public gauge_field_is_propagated(this)
integer, parameter, public independent_particles
Theory level.
Definition: global.F90:223
real(real64), parameter, public m_epsilon
Definition: global.F90:189
This module implements the underlying real-space grid.
Definition: grid.F90:96
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
This module defines classes and functions for interaction partners.
subroutine, public ion_dynamics_propagate_vel(this, ions, atoms_moved)
A module to handle KS potential, without the external potential.
subroutine, public lasers_nondipole_laser_field_step(this, field, time)
Retrieves the NDSFA vector_potential correction. The nondipole field is obtained for consecutive time...
Definition: lasers.F90:1137
subroutine, public lasers_set_nondipole_parameters(this, ndfield, nd_integration_time)
Set parameters for nondipole SFA calculation.
Definition: lasers.F90:737
logical function, public lasers_with_nondipole_field(lasers)
Check if a nondipole SFA correction should be computed for the given laser.
Definition: lasers.F90:724
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy, aug_overlap)
Definition: lda_u.F90:915
This module defines various routines, operating on mesh functions.
integer, public sp_distdot_mode
subroutine, public mesh_init_mesh_aux(mesh)
Initialise a pointer to the grid/mesh, that is globally exposed, such that low level mesh operations ...
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
This module holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
this module contains the low-level part of the output system
Definition: output_low.F90:94
subroutine, public potential_interpolation_copy(vkso, vksi)
subroutine, public potential_interpolation_end(potential_interpolation)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
subroutine, public propagation_ops_elec_propagate_ions_and_cell(gr, hm, st, namespace, space, ions_dyn, ions, mc, time, dt_ions)
subroutine, public propagation_ops_elec_update_hamiltonian(namespace, space, st, mesh, hm, ext_partners, time)
integer, parameter, public prop_aetrs
integer, parameter, public prop_crank_nicolson_sparskit
integer, parameter, public prop_crank_nicolson
integer, parameter, public prop_runge_kutta2
integer, parameter, public prop_magnus
integer, parameter, public prop_cfmagnus4
integer, parameter, public prop_caetrs
integer, parameter, public prop_qoct_tddft_propagator
integer, parameter, public prop_exponential_midpoint
integer, parameter, public prop_explicit_magnus3
integer, parameter, public prop_runge_kutta4
integer, parameter, public prop_explicit_runge_kutta4
integer, parameter, public prop_etrs
integer, parameter, public prop_exponential_midpoint_predictor
subroutine, public td_crank_nicolson(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, use_sparskit)
Crank-Nicolson propagator.
subroutine, public propagator_elec_copy(tro, tri)
subroutine, public propagator_elec_dt(ks, namespace, space, hm, gr, st, tr, time, dt, nt, ions_dyn, ions, ext_partners, mc, outp, write_handler, scsteps, update_energy, qcchi, dmp)
Propagates st from time - dt to t. If dt<0, it propagates backwards from t+|dt| to t.
subroutine, public propagator_elec_dt_bo(scf, namespace, space, gr, ks, st, hm, ions, ext_partners, mc, iter, dt, ions_dyn, scsteps)
subroutine, public propagator_elec_set_scf_prop(tr, threshold)
subroutine, public propagator_elec_init(gr, namespace, st, tr, ks_pot, have_fields, family_is_mgga_with_exc, relax_cell)
subroutine, public propagator_elec_remove_scf_prop(tr)
logical pure function, public propagator_elec_ions_are_propagated(tr)
subroutine, public propagator_elec_end(tr)
subroutine, public td_aetrs(namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
Propagator with approximate enforced time-reversal symmetry.
subroutine, public td_etrs_sc(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, ions_dyn, ions, mc, sctol, scsteps)
Propagator with enforced time-reversal symmetry and self-consistency.
subroutine, public td_etrs(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, ions_dyn, ions, mc)
Propagator with enforced time-reversal symmetry, ETRS.
subroutine, public td_caetrs(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, ions_dyn, ions, mc)
Propagator with approximate enforced time-reversal symmetry.
subroutine, public td_aetrs_sc(ks, namespace, space, hm, ext_partners, gr, st, tr, time, dt, ions_dyn, ions, mc, sctol, scsteps)
Propagator with approximate enforced time-reversal symmetry and self-consistency.
subroutine, public exponential_midpoint_predictor(hm, ks, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
Exponential midpoint with prediction of the half time step This is equivalent to an explicit Magnus i...
subroutine, public exponential_midpoint(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
Exponential midpoint.
subroutine, public td_magnus(hm, ext_partners, gr, st, tr, namespace, time, dt)
Magnus propagator.
subroutine, public td_cfmagnus4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, iter)
Commutator-free Magnus propagator of order 4. This method has been developed for linear systems and i...
subroutine, public td_explicit_magnus3(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
Third-order explicit Magnus propagator. This implements equation (22) from Casas, F....
subroutine, public td_cfmagnus4_sc(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc, iter, sctol, scsteps)
Commutator-free Magnus propagator of order 4 with self-consistency.
subroutine, public td_qoct_tddft_propagator(hm, namespace, space, gr, st, tr, time, dt, ions_dyn, ions, ext_partners, mc)
Propagator specifically designed for the QOCT+TDDFT problem.
subroutine, public td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
subroutine, public td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
subroutine, public td_explicit_runge_kutta4(ks, namespace, space, hm, gr, st, time, dt, ions_dyn, ions, ext_partners, qcchi)
subroutine, public propagator_rk_end()
type(algorithmic_operation_t), parameter, public op_verlet_compute_acc
type(algorithmic_operation_t), parameter, public op_verlet_compute_vel
subroutine, public sparskit_solver_init(namespace, n, sk, is_complex)
Definition: sparskit.F90:217
subroutine, public sparskit_solver_end(sk)
Definition: sparskit.F90:415
subroutine, public sparskit_solver_copy(sko, ski)
Definition: sparskit.F90:428
subroutine, public states_elec_end(st)
finalize the states_elec_t object
This module implements the calculation of the stress tensor.
Definition: stress.F90:97
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
Definition: stress.F90:167
integer, parameter, public out_separate_forces
Definition: td_write.F90:187
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:775
Definition: xc.F90:97
logical pure function self_consistent_step()
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
Stores all communicators and groups.
Definition: multicomm.F90:185
This is the datatype that contains the objects that are propagated: in principle this could be both t...
output handler class
Definition: output_low.F90:143
The states_elec_t class contains all electronic wave functions.
Time-dependent Write Properties.
Definition: td_write.F90:307
int true(void)