34 use,
intrinsic :: iso_fortran_env
74 type(target_t),
intent(inout) :: tg
75 type(namespace_t),
intent(in) :: namespace
76 type(td_t),
intent(in) :: td
77 real(real64),
intent(in) :: w0
119 if (
parse_block(namespace,
'OCTOptimizeHarmonicSpectrum', blk) == 0)
then
121 safe_allocate( tg%hhg_k(1:tg%hhg_nks))
122 safe_allocate(tg%hhg_alpha(1:tg%hhg_nks))
123 safe_allocate( tg%hhg_a(1:tg%hhg_nks))
124 do jj = 1, tg%hhg_nks
131 message(1) =
'"OCTOptimizeHarmonicSpectrum" has to be specified as a block.'
136 write(
message(1),
'(a)')
'If "OCTTargetMode = oct_targetmode_hhg", you must supply an'
137 write(
message(2),
'(a)')
'"OCTOptimizeHarmonicSpectrum" block.'
143 safe_allocate(tg%td_fitness(0:td%max_iter))
153 type(grid_t),
intent(in) :: gr
154 type(namespace_t),
intent(in) :: namespace
155 type(target_t),
intent(inout) :: tg
156 type(td_t),
intent(in) :: td
157 type(ions_t),
intent(in) :: ions
158 type(epot_t),
intent(in) :: ep
160 integer :: ist, jst, iunit, jj, nn(3), optimize_parity(3)
161 logical :: optimize(3)
162 real(real64) :: dw, psi_re, psi_im, ww
163 real(real64),
allocatable :: vl(:), vl_grad(:,:)
169 safe_allocate(tg%vel(1:td%max_iter+1, 1:gr%box%dim))
170 safe_allocate(tg%acc(1:td%max_iter+1, 1:gr%box%dim))
171 safe_allocate(tg%gvec(1:td%max_iter+1, 1:gr%box%dim))
172 safe_allocate(tg%alpha(1:td%max_iter))
175 if (ions%natoms > 1)
then
176 message(1) =
'If "OCTTargetOperator = oct_tg_hhgnew", then you can only have one atom.'
181 if (ions%natoms > 1)
then
182 message(1) =
'If "OCTTargetOperator = oct_tg_hhgnew", then you can only have one atom.'
186 safe_allocate(tg%grad_local_pot(1:ions%natoms, 1:gr%np, 1:gr%box%dim))
187 safe_allocate(vl(1:gr%np_part))
188 safe_allocate(vl_grad(1:gr%np, 1:gr%box%dim))
189 safe_allocate(tg%rho(1:gr%np))
194 ions%pos(:, 1), 1, vl)
198 tg%grad_local_pot(1, ist, jst) = vl_grad(ist, jst)
222 call parse_variable(namespace,
'OCTHarmonicWeight',
'1', tg%plateau_string)
224 safe_allocate(tg%td_fitness(0:td%max_iter))
227 iunit =
io_open(
'.alpha', namespace, action=
'write')
228 dw = (
m_two *
m_pi) / (td%max_iter * tg%dt)
229 do jj = 0, td%max_iter - 1
232 tg%alpha(jj+1) = psi_re
233 write(iunit, *) ww, psi_re
237 nn(1:3) = (/ td%max_iter, 1, 1 /)
238 optimize(1:3) = .false.
239 optimize_parity(1:3) = -1
253 safe_deallocate_a(tg%hhg_k)
254 safe_deallocate_a(tg%hhg_alpha)
255 safe_deallocate_a(tg%hhg_a)
256 safe_deallocate_a(tg%td_fitness)
266 class(
space_t),
intent(in) :: space
267 type(
grid_t),
intent(in) :: gr
268 character(len=*),
intent(in) :: dir
269 type(
ions_t),
intent(in) :: ions
276 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
287 type(
oct_t),
intent(in) :: oct
291 if ((oct%algorithm == option__octscheme__oct_cg) .or. (oct%algorithm == option__octscheme__oct_bfgs))
then
292 safe_deallocate_a(tg%grad_local_pot)
293 safe_deallocate_a(tg%rho)
294 safe_deallocate_a(tg%vel)
295 safe_deallocate_a(tg%acc)
296 safe_deallocate_a(tg%gvec)
297 safe_deallocate_a(tg%alpha)
298 safe_deallocate_a(tg%td_fitness)
308 real(real64) function
target_j1_hhg(tg, namespace) result(j1)
312 integer :: maxiter, jj
313 real(real64) :: aa, ww, maxhh, omega
314 complex(real64),
allocatable :: ddipole(:)
317 maxiter =
size(tg%td_fitness) - 1
318 safe_allocate(ddipole(0:maxiter))
320 ddipole = tg%td_fitness
325 do jj = 1, tg%hhg_nks
326 aa = tg%hhg_a(jj) * tg%hhg_w0
327 ww = tg%hhg_k(jj) * tg%hhg_w0
329 j1 = j1 + tg%hhg_alpha(jj) *
log(-maxhh)
333 safe_deallocate_a(ddipole)
341 type(grid_t),
intent(in) :: gr
342 type(target_t),
intent(in) :: tg
344 integer :: maxiter, i
345 real(real64) :: dw, ww
348 maxiter =
size(tg%td_fitness) - 1
349 dw = (m_two * m_pi) / (maxiter * tg%dt)
351 do i = 0, maxiter - 1
353 j1 = j1 + dw * tg%alpha(i+1) * sum(abs(tg%vel(i+1, 1:gr%box%dim))**2)
363 type(states_elec_t),
intent(inout) :: chi_out
369 do ik = chi_out%d%kpt%start, chi_out%d%kpt%end
370 do ib = chi_out%group%block_start, chi_out%group%block_end
371 call batch_set_zero(chi_out%group%psib(ib, ik))
383 type(target_t),
intent(inout) :: tg
384 type(grid_t),
intent(in) :: gr
385 type(states_elec_t),
intent(in) :: psi
386 integer,
intent(in) :: time
387 integer,
intent(in) :: max_time
389 complex(real64),
allocatable :: opsi(:, :), zpsi(:, :)
390 integer :: iw, ia, ist, idim, ik
391 real(real64) :: acc(gr%box%dim), dt, dw
395 tg%td_fitness(time) = m_zero
398 if (.not. target_move_ions(tg))
then
400 safe_allocate(opsi(1:gr%np_part, 1))
401 safe_allocate(zpsi(1:gr%np_part, 1))
408 call states_elec_get_state(psi, gr, ist, ik, zpsi)
409 do idim = 1, gr%box%dim
410 opsi(1:gr%np, 1) = tg%grad_local_pot(1, 1:gr%np, idim)*zpsi(1:gr%np, 1)
411 acc(idim) = acc(idim) + real( psi%occ(ist, ik) * zmf_dotp(gr, psi%d%dim, opsi, zpsi), real64)
412 tg%acc(time+1, idim) = tg%acc(time+1, idim) + psi%occ(ist, ik)*zmf_dotp(gr, psi%d%dim, opsi, zpsi)
417 safe_deallocate_a(opsi)
418 safe_deallocate_a(zpsi)
423 dw = (m_two * m_pi/(max_time * tg%dt))
424 if (time == max_time)
then
425 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))
426 do ia = 1, gr%box%dim
427 call zfft_forward(tg%fft_handler, tg%acc(1:max_time, ia), tg%vel(1:max_time, ia))
429 tg%vel = tg%vel * tg%dt
433 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)
435 do ia = 1, gr%box%dim
436 call zfft_backward(tg%fft_handler, tg%acc(1:max_time, ia), tg%gvec(1:max_time, ia))
438 tg%gvec(max_time + 1, 1:gr%box%dim) = tg%gvec(1, 1:gr%box%dim)
439 tg%gvec = tg%gvec * (m_two * m_pi/ tg%dt)
450 subroutine target_tdcalc_hhg(tg, namespace, space, hm, gr, ions, ext_partners, psi, time)
451 type(target_t),
intent(inout) :: tg
452 type(namespace_t),
intent(in) :: namespace
453 class(space_t),
intent(in) :: space
454 type(hamiltonian_elec_t),
intent(in) :: hm
455 type(grid_t),
intent(in) :: gr
456 type(ions_t),
intent(inout) :: ions
457 type(partner_list_t),
intent(in) :: ext_partners
458 type(states_elec_t),
intent(in) :: psi
459 integer,
intent(in) :: time
461 real(real64) :: acc(space%dim)
465 call td_calc_tacc(namespace, space, gr, ions, ext_partners, psi, hm, acc, time*tg%dt)
466 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)
logical pure function, public ion_dynamics_ions_move(this)
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 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, public target_end_hhg(tg)
subroutine, public target_init_hhg(tg, namespace, td, w0)
subroutine, public target_tdcalc_hhgnew(tg, gr, psi, time, max_time)
subroutine, public target_tdcalc_hhg(tg, namespace, space, hm, gr, ions, ext_partners, psi, time)
subroutine, public target_chi_hhg(chi_out)
real(real64) function, public target_j1_hhg(tg, namespace)
subroutine, public target_init_hhgnew(gr, namespace, tg, td, ions, ep)
real(real64) function, public target_j1_hhgnew(gr, tg)
subroutine, public target_end_hhgnew(tg, oct)
subroutine, public target_output_hhg(tg, namespace, space, gr, dir, ions, hm, outp)
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.