34 use,
intrinsic :: iso_fortran_env
65 integer,
allocatable :: hhg_k(:)
66 real(real64),
allocatable :: hhg_alpha(:)
67 real(real64),
allocatable :: hhg_a(:)
68 real(real64) :: hhg_w0
69 real(real64),
allocatable :: td_fitness(:)
82 real(real64),
allocatable :: grad_local_pot(:,:,:)
83 real(real64),
allocatable :: rho(:)
84 complex(real64),
allocatable :: acc(:, :)
85 complex(real64),
allocatable :: vel(:, :)
86 complex(real64),
allocatable :: gvec(:, :)
87 real(real64),
allocatable :: alpha(:)
88 character(len=1000) :: plateau_string
89 real(real64),
allocatable :: td_fitness(:)
90 type(fft_t) :: fft_handler
109 subroutine target_init_hhg(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
110 class(target_hhg_t),
intent(inout) :: tg
111 type(grid_t),
intent(in) :: gr
112 type(kpoints_t),
intent(in) :: kpoints
113 type(namespace_t),
intent(in) :: namespace
114 class(space_t),
intent(in) :: space
115 type(ions_t),
intent(in) :: ions
116 type(opt_control_state_t),
intent(inout) :: qcs
117 type(td_t),
intent(in) :: td
118 real(real64),
intent(in) :: w0
119 type(oct_t),
intent(in) :: oct
120 type(epot_t),
intent(inout) :: ep
121 type(restart_t),
intent(inout) :: restart
127 tg%move_ions = td%ions_dyn%ions_move()
163 if (
parse_block(namespace,
'OCTOptimizeHarmonicSpectrum', blk) == 0)
then
165 safe_allocate( tg%hhg_k(1:tg%hhg_nks))
166 safe_allocate(tg%hhg_alpha(1:tg%hhg_nks))
167 safe_allocate( tg%hhg_a(1:tg%hhg_nks))
168 do jj = 1, tg%hhg_nks
175 message(1) =
'"OCTOptimizeHarmonicSpectrum" has to be specified as a block.'
180 write(
message(1),
'(a)')
'If "OCTTargetOperator = oct_tg_hhg", you must supply an'
181 write(
message(2),
'(a)')
'"OCTOptimizeHarmonicSpectrum" block.'
187 safe_allocate(tg%td_fitness(0:td%max_iter))
196 subroutine target_init_hhgnew(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
198 type(
grid_t),
intent(in) :: gr
201 class(
space_t),
intent(in) :: space
202 type(
ions_t),
intent(in) :: ions
205 real(real64),
intent(in) :: w0
206 type(
oct_t),
intent(in) :: oct
207 type(
epot_t),
intent(inout) :: ep
208 type(
restart_t),
intent(inout) :: restart
210 integer :: ist, jst, iunit, jj, nn(3), optimize_parity(3)
211 logical :: optimize(3)
212 real(real64) :: dw, psi_re, psi_im, ww
213 real(real64),
allocatable :: vl(:), vl_grad(:,:)
216 tg%move_ions = td%ions_dyn%ions_move()
219 safe_allocate(tg%vel(1:td%max_iter+1, 1:gr%box%dim))
220 safe_allocate(tg%acc(1:td%max_iter+1, 1:gr%box%dim))
221 safe_allocate(tg%gvec(1:td%max_iter+1, 1:gr%box%dim))
222 safe_allocate(tg%alpha(1:td%max_iter))
225 if (ions%natoms > 1)
then
226 message(1) =
'If "OCTTargetOperator = oct_tg_hhgnew", then you can only have one atom.'
231 if (ions%natoms > 1)
then
232 message(1) =
'If "OCTTargetOperator = oct_tg_hhgnew", then you can only have one atom.'
236 safe_allocate(tg%grad_local_pot(1:ions%natoms, 1:gr%np, 1:gr%box%dim))
237 safe_allocate(vl(1:gr%np_part))
238 safe_allocate(vl_grad(1:gr%np, 1:gr%box%dim))
239 safe_allocate(tg%rho(1:gr%np))
244 ions%pos(:, 1), 1, vl)
248 tg%grad_local_pot(1, ist, jst) = vl_grad(ist, jst)
272 call parse_variable(namespace,
'OCTHarmonicWeight',
'1', tg%plateau_string)
274 safe_allocate(tg%td_fitness(0:td%max_iter))
277 iunit =
io_open(
'.alpha', namespace, action=
'write')
278 dw = (
m_two *
m_pi) / (td%max_iter * tg%dt)
279 do jj = 0, td%max_iter - 1
282 tg%alpha(jj+1) = psi_re
283 write(iunit, *) ww, psi_re
287 nn(1:3) = (/ td%max_iter, 1, 1 /)
288 optimize(1:3) = .false.
289 optimize_parity(1:3) = -1
300 type(
oct_t),
intent(in) :: oct
304 safe_deallocate_a(tg%hhg_k)
305 safe_deallocate_a(tg%hhg_alpha)
306 safe_deallocate_a(tg%hhg_a)
307 safe_deallocate_a(tg%td_fitness)
317 class(
space_t),
intent(in) :: space
318 type(
grid_t),
intent(in) :: gr
319 character(len=*),
intent(in) :: dir
320 type(
ions_t),
intent(in) :: ions
327 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
338 class(
space_t),
intent(in) :: space
339 type(
grid_t),
intent(in) :: gr
340 character(len=*),
intent(in) :: dir
341 type(
ions_t),
intent(in) :: ions
348 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
359 type(
oct_t),
intent(in) :: oct
363 if ((oct%algorithm == option__octscheme__oct_cg) .or. (oct%algorithm == option__octscheme__oct_bfgs))
then
364 safe_deallocate_a(tg%grad_local_pot)
365 safe_deallocate_a(tg%rho)
366 safe_deallocate_a(tg%vel)
367 safe_deallocate_a(tg%acc)
368 safe_deallocate_a(tg%gvec)
369 safe_deallocate_a(tg%alpha)
370 safe_deallocate_a(tg%td_fitness)
380 real(real64) function target_j1_hhg(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
383 type(
grid_t),
intent(in) :: gr
386 type(
ions_t),
optional,
intent(in) :: ions
388 integer :: maxiter, jj
389 real(real64) :: aa, ww, maxhh, omega
390 complex(real64),
allocatable :: ddipole(:)
391 push_sub(target_j1_hhg)
393 maxiter =
size(tg%td_fitness) - 1
394 safe_allocate(ddipole(0:maxiter))
396 ddipole = tg%td_fitness
401 do jj = 1, tg%hhg_nks
402 aa = tg%hhg_a(jj) * tg%hhg_w0
403 ww = tg%hhg_k(jj) * tg%hhg_w0
405 j1 = j1 + tg%hhg_alpha(jj) *
log(-maxhh)
409 safe_deallocate_a(ddipole)
410 pop_sub(target_j1_hhg)
416 real(real64) function target_j1_hhgnew(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
418 type(namespace_t),
intent(in) :: namespace
419 type(grid_t),
intent(in) :: gr
420 type(kpoints_t),
intent(in) :: kpoints
421 type(opt_control_state_t),
intent(inout) :: qcpsi
422 type(ions_t),
optional,
intent(in) :: ions
424 integer :: maxiter, i
425 real(real64) :: dw, ww
428 maxiter =
size(tg%td_fitness) - 1
429 dw = (m_two * m_pi) / (maxiter * tg%dt)
431 do i = 0, maxiter - 1
433 j1 = j1 + dw * tg%alpha(i+1) * sum(abs(tg%vel(i+1, 1:gr%box%dim))**2)
442 subroutine target_chi_hhg(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
444 type(namespace_t),
intent(in) :: namespace
445 type(grid_t),
intent(in) :: gr
446 type(kpoints_t),
intent(in) :: kpoints
447 type(opt_control_state_t),
target,
intent(inout) :: qcpsi_in
448 type(opt_control_state_t),
target,
intent(inout) :: qcchi_out
449 type(ions_t),
intent(in) :: ions
452 type(states_elec_t),
pointer :: chi_out
455 chi_out => opt_control_point_qs(qcchi_out)
458 do ik = chi_out%d%kpt%start, chi_out%d%kpt%end
459 do ib = chi_out%group%block_start, chi_out%group%block_end
460 call batch_set_zero(chi_out%group%psib(ib, ik))
471 subroutine target_chi_hhgnew(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
473 type(namespace_t),
intent(in) :: namespace
474 type(grid_t),
intent(in) :: gr
475 type(kpoints_t),
intent(in) :: kpoints
476 type(opt_control_state_t),
target,
intent(inout) :: qcpsi_in
477 type(opt_control_state_t),
target,
intent(inout) :: qcchi_out
478 type(ions_t),
intent(in) :: ions
481 type(states_elec_t),
pointer :: chi_out
484 chi_out => opt_control_point_qs(qcchi_out)
487 do ik = chi_out%d%kpt%start, chi_out%d%kpt%end
488 do ib = chi_out%group%block_start, chi_out%group%block_end
489 call batch_set_zero(chi_out%group%psib(ib, ik))
516 type(states_elec_t),
intent(inout) :: psi
517 type(grid_t),
intent(in) :: gr
518 type(kpoints_t),
intent(in) :: kpoints
519 real(real64),
intent(in) :: time
520 type(states_elec_t),
intent(inout) :: inh
521 integer,
intent(in) :: iter
523 integer :: ik, ist, ip, idim
524 complex(real64),
allocatable :: zpsi(:)
525 complex(real64) :: gvec(gr%box%dim)
529 safe_allocate(zpsi(1:gr%np))
531 gvec(:) = real(tg%gvec(iter + 1, :), real64)
533 do ik = inh%d%kpt%start, inh%d%kpt%end
534 do ist = inh%st_start, inh%st_end
535 do idim = 1, inh%d%dim
536 call states_elec_get_state(psi, gr, idim, ist, ik, zpsi)
538 zpsi(ip) = -psi%occ(ist, ik)*m_two*sum(tg%grad_local_pot(1, ip, 1:gr%box%dim)*gvec(:))*zpsi(ip)
540 call states_elec_set_state(inh, gr, idim, ist, ik, zpsi)
545 safe_deallocate_a(zpsi)
555 subroutine target_tdcalc_hhgnew(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
557 type(namespace_t),
intent(in) :: namespace
558 class(space_t),
intent(in) :: space
559 type(hamiltonian_elec_t),
intent(inout) :: hm
560 type(grid_t),
intent(in) :: gr
561 type(ions_t),
intent(inout) :: ions
562 type(partner_list_t),
intent(in) :: ext_partners
563 type(states_elec_t),
intent(inout) :: psi
564 integer,
intent(in) :: time
565 integer,
intent(in) :: max_time
567 complex(real64),
allocatable :: opsi(:, :), zpsi(:, :)
568 integer :: iw, ia, ist, idim, ik
569 real(real64) :: acc(gr%box%dim), dt, dw
573 tg%td_fitness(time) = m_zero
576 if (.not. target_move_ions(tg))
then
578 safe_allocate(opsi(1:gr%np_part, 1))
579 safe_allocate(zpsi(1:gr%np_part, 1))
586 call states_elec_get_state(psi, gr, ist, ik, zpsi)
587 do idim = 1, gr%box%dim
588 opsi(1:gr%np, 1) = tg%grad_local_pot(1, 1:gr%np, idim)*zpsi(1:gr%np, 1)
589 acc(idim) = acc(idim) + real( psi%occ(ist, ik) * zmf_dotp(gr, psi%d%dim, opsi, zpsi), real64)
590 tg%acc(time+1, idim) = tg%acc(time+1, idim) + psi%occ(ist, ik)*zmf_dotp(gr, psi%d%dim, opsi, zpsi)
595 safe_deallocate_a(opsi)
596 safe_deallocate_a(zpsi)
601 dw = (m_two * m_pi/(max_time * tg%dt))
602 if (time == max_time)
then
603 tg%acc(1, 1:gr%box%dim) = m_half * (tg%acc(1, 1:gr%box%dim) + tg%acc(max_time+1, 1:gr%box%dim))
604 do ia = 1, gr%box%dim
605 call zfft_forward(tg%fft_handler, tg%acc(1:max_time, ia), tg%vel(1:max_time, ia))
607 tg%vel = tg%vel * tg%dt
611 tg%acc(iw, 1:gr%box%dim) = tg%vel(iw, 1:gr%box%dim) * tg%alpha(iw) *
exp(m_zi * (iw-1) * dw * m_half * dt)
613 do ia = 1, gr%box%dim
614 call zfft_backward(tg%fft_handler, tg%acc(1:max_time, ia), tg%gvec(1:max_time, ia))
616 tg%gvec(max_time + 1, 1:gr%box%dim) = tg%gvec(1, 1:gr%box%dim)
617 tg%gvec = tg%gvec * (m_two * m_pi/ tg%dt)
628 subroutine target_tdcalc_hhg(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
630 type(namespace_t),
intent(in) :: namespace
631 class(space_t),
intent(in) :: space
632 type(hamiltonian_elec_t),
intent(inout) :: hm
633 type(grid_t),
intent(in) :: gr
634 type(ions_t),
intent(inout) :: ions
635 type(partner_list_t),
intent(in) :: ext_partners
636 type(states_elec_t),
intent(inout) :: psi
637 integer,
intent(in) :: time
638 integer,
intent(in) :: max_time
640 real(real64) :: acc(space%dim)
644 call td_calc_tacc(namespace, space, gr, ions, ext_partners, psi, hm, acc, time*tg%dt)
645 tg%td_fitness(time) = acc(1)
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
This module implements common operations on batches of mesh functions.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
subroutine, public fft_init(this, nn, dim, type, library, optimize, optimize_parity, comm, mpi_grp, use_aligned)
subroutine, public fft_end(this)
integer, parameter, public fft_complex
integer, parameter, public fftlib_fftw
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
complex(real64), parameter, public m_z0
This module implements the underlying real-space grid.
This module defines classes and functions for interaction partners.
subroutine, public io_close(iunit, grp)
subroutine, public io_mkdir(fname, namespace, parents)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
This module defines various routines, operating on mesh functions.
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This module contains the definition of the oct_t data type, which contains some of the basic informat...
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
this module contains the output system
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
logical function, public parse_is_defined(namespace, name)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public spectrum_hsfunction_min(namespace, aa, bb, omega_min, func_min)
subroutine, public spectrum_hsfunction_init(dt, is, ie, niter, acc)
subroutine, public spectrum_hsfunction_end
subroutine target_init_hhgnew(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_tdcalc_hhgnew(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
subroutine target_output_hhgnew(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine target_end_hhgnew(tg, oct)
subroutine target_init_hhg(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
real(real64) function target_j1_hhg(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_end_hhg(tg, oct)
real(real64) function target_j1_hhgnew(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_chi_hhgnew(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
The HHG targets are time-dependent, so chi(T) = 0.
subroutine target_output_hhg(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine target_chi_hhg(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
The HHG targets are time-dependent, so chi(T) = 0.
subroutine target_tdcalc_hhg(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
subroutine target_inh_hhgnew(tg, psi, gr, kpoints, time, inh, iter)
Inhomogeneous term for the hhgnew target.
subroutine target_init_propagation_hhgnew(tg)
Per-propagation reset for the hhgnew target.
Optimal-control targets: abstract base class and public interface.
Description of the grid, containing information on derivatives, stencil, and symmetries.
!brief The oct_t datatype stores the basic information about how the OCT run is done.
This is the datatype that contains the objects that are propagated: in principle this could be both t...
Target on the harmonic emission spectrum (peak optimization).
Target on the harmonic spectrum integrated with a weight function.
Abstract optimal-control target.