29 use,
intrinsic :: iso_fortran_env
64 type(grid_t),
intent(in) :: gr
65 type(namespace_t),
intent(in) :: namespace
66 type(ions_t),
intent(in) :: ions
67 type(target_t),
intent(inout) :: tg
68 type(oct_t),
intent(in) :: oct
69 type(td_t),
intent(in) :: td
70 type(epot_t),
intent(in) :: ep
72 integer :: iatom, ist, jst, jj
73 real(real64),
allocatable :: vl(:), vl_grad(:,:)
75 character(len=1024) :: expression
130 if (
parse_block(namespace,
'OCTVelocityTarget', blk) == 0)
then
131 tg%vel_input_string =
" "
134 tg%vel_input_string = trim(tg%vel_input_string) // trim(expression)
138 message(1) =
'If OCTTargetOperator = oct_tg_velocity, then you must give the shape'
139 message(2) =
'of this target in the block "OCTVelocityTarget".'
144 if (tg%move_ions)
then
145 message(1) =
'If OCTTargetOperator = oct_tg_velocity, then you must not allow the ions'
146 message(2) =
'to move. If you want to move the ions, then you can get the same functionality'
147 message(3) =
'with OCTTargetOperator = oct_tg_classical.'
151 if (oct%algorithm == option__octscheme__oct_cg .or. oct%algorithm == option__octscheme__oct_bfgs)
then
152 if (
parse_block(namespace,
'OCTVelocityDerivatives', blk) == 0)
then
153 safe_allocate(tg%vel_der_array(1:ions%natoms,1:gr%box%dim))
154 do ist=0, ions%natoms-1
155 do jst=0, gr%box%dim-1
161 message(1) =
'If OCTTargetOperator = oct_tg_velocity, and'
162 message(2) =
'OCTScheme = oct_cg, or OCTScheme = oct_bfgs then you must define the'
163 message(3) =
'blocks "OCTVelocityTarget" AND "OCTVelocityDerivatives"'
168 safe_allocate(tg%grad_local_pot(1:ions%natoms, 1:gr%np, 1:gr%box%dim))
169 safe_allocate(vl(1:gr%np_part))
170 safe_allocate(vl_grad(1:gr%np, 1:gr%box%dim))
171 safe_allocate(tg%rho(1:gr%np))
174 do iatom = 1, ions%natoms
178 ions%pos(:, iatom), iatom, vl)
182 tg%grad_local_pot(iatom, ist, jst) = vl_grad(ist, jst)
186 safe_deallocate_a(vl)
187 safe_deallocate_a(vl_grad)
196 safe_allocate(tg%td_fitness(0:td%max_iter))
207 type(
oct_t),
intent(in) :: oct
211 if (oct%algorithm == option__octscheme__oct_cg .or. oct%algorithm == option__octscheme__oct_bfgs)
then
212 safe_deallocate_a(tg%vel_der_array)
213 safe_deallocate_a(tg%grad_local_pot)
214 safe_deallocate_a(tg%rho)
216 safe_deallocate_a(tg%td_fitness)
226 class(
space_t),
intent(in) :: space
227 type(
grid_t),
intent(in) :: gr
228 character(len=*),
intent(in) :: dir
229 type(
ions_t),
intent(in) :: ions
236 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
247 type(
ions_t),
intent(in) :: ions
250 real(real64) :: f_re, dummy(3)
251 real(real64),
allocatable :: x(:, :)
252 character(len=4096) :: inp_string
255 safe_allocate(x(1:ions%natoms, 1:ions%space%dim))
256 do i = 1, ions%natoms
257 x(i, :) = ions%vel(:, i)
262 inp_string = tg%vel_input_string
265 call parse_expression(f_re, dummy(1), 1, dummy(1:3), dummy(1), dummy(1), inp_string)
276 type(grid_t),
intent(in) :: gr
277 type(target_t),
intent(inout) :: tg
278 type(states_elec_t),
intent(inout) :: chi_out
279 type(ions_t),
intent(in) :: ions
281 integer :: ip, ist, jst, ik, ib
282 character(len=1024) :: temp_string
283 real(real64) :: df_dv, dummy(3)
284 real(real64),
allocatable :: x(:, :)
288 do ik = chi_out%d%kpt%start, chi_out%d%kpt%end
289 do ib = chi_out%group%block_start, chi_out%group%block_end
290 call batch_set_zero(chi_out%group%psib(ib, ik))
294 safe_allocate(x(1:ions%natoms, 1:ions%space%dim))
295 do ip = 1, ions%natoms
296 x(ip, :) = ions%vel(:, ip)
303 do ist = 1, ions%natoms
305 temp_string = tg%vel_der_array(ist, jst)
306 call parse_array(temp_string, x,
'v')
307 call conv_to_c_string(temp_string)
308 call parse_expression(df_dv, dummy(1), 1, dummy(1:3), dummy(1), dummy(1), temp_string)
309 tg%rho(:) = tg%rho(:) + df_dv*tg%grad_local_pot(ist,:,jst)/ions%mass(ist)
322 type(target_t),
intent(inout) :: tg
323 type(hamiltonian_elec_t),
intent(in) :: hm
324 type(grid_t),
intent(in) :: gr
325 type(ions_t),
intent(inout) :: ions
326 type(states_elec_t),
intent(in) :: psi
327 integer,
intent(in) :: time
328 integer,
intent(in) :: max_time
330 complex(real64),
allocatable :: opsi(:, :), zpsi(:, :)
331 integer :: iatom, ik, ist, idim
335 tg%td_fitness(time) = m_zero
337 safe_allocate(zpsi(1:gr%np_part, 1))
338 safe_allocate(opsi(1:gr%np_part, 1))
341 do iatom = 1, ions%natoms
342 ions%tot_force(:, iatom) = hm%ep%fii(1:gr%box%dim, iatom)
345 do idim = 1, gr%box%dim
346 call states_elec_get_state(psi, gr, ist, ik, zpsi)
347 opsi(1:gr%np, 1) = tg%grad_local_pot(iatom, 1:gr%np, idim)*zpsi(1:gr%np, 1)
348 ions%tot_force(idim, iatom) = ions%tot_force(idim, iatom) &
349 + real(psi%occ(ist, ik)*zmf_dotp(gr, psi%d%dim, opsi, zpsi), real64)
354 safe_deallocate_a(opsi)
355 safe_deallocate_a(zpsi)
358 if ((time == 0) .or. (time == max_time)) dt = tg%dt * m_half
359 do iatom = 1, ions%natoms
360 ions%vel(:, iatom) = ions%vel(:, iatom) + ions%tot_force(:, iatom) * dt / ions%mass(iatom)
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)
real(real64), parameter, public m_zero
This module implements the underlying real-space grid.
subroutine, public io_mkdir(fname, namespace, parents)
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)
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)
subroutine, public parse_array(inp_string, x, arraychar)
A very primitive way to "preprocess" a string that contains reference to the elements of a two-dimens...
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public conv_to_c_string(str)
converts to c string
real(real64) function, public target_j1_velocity(tg, ions)
subroutine, public target_chi_velocity(gr, tg, chi_out, ions)
subroutine, public target_output_velocity(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine, public target_tdcalc_velocity(tg, hm, gr, ions, psi, time, max_time)
subroutine, public target_init_velocity(gr, namespace, ions, tg, oct, td, ep)
subroutine, public target_end_velocity(tg, oct)
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.