29 use,
intrinsic :: iso_fortran_env
53 character(len=4096) :: classical_input_string
54 character(len=1024),
allocatable :: mom_der_array(:,:)
55 character(len=1024),
allocatable :: pos_der_array(:,:)
69 subroutine target_init_classical(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
70 class(target_classical_t),
intent(inout) :: tg
71 type(grid_t),
intent(in) :: gr
72 type(kpoints_t),
intent(in) :: kpoints
73 type(namespace_t),
intent(in) :: namespace
74 class(space_t),
intent(in) :: space
75 type(ions_t),
intent(in) :: ions
76 type(opt_control_state_t),
intent(inout) :: qcs
77 type(td_t),
intent(in) :: td
78 real(real64),
intent(in) :: w0
79 type(oct_t),
intent(in) :: oct
80 type(epot_t),
intent(inout) :: ep
81 type(restart_t),
intent(inout) :: restart
83 integer :: jj, ist, jst
85 character(len=1024) :: expression
88 tg%move_ions = td%ions_dyn%ions_move()
107 if (
parse_block(namespace,
'OCTClassicalTarget', blk) == 0)
then
108 tg%classical_input_string =
" "
111 tg%classical_input_string = trim(tg%classical_input_string) // trim(expression)
115 message(1) =
'If OCTTargetOperator = oct_tg_classical, then you must give the shape'
116 message(2) =
'of this target in the block "OCTClassicalTarget".'
130 if (
parse_block(namespace,
'OCTMomentumDerivatives', blk) == 0)
then
131 safe_allocate(tg%mom_der_array(1:ions%natoms,1:ions%space%dim))
132 do ist = 0, ions%natoms - 1
133 do jst = 0, ions%space%dim - 1
138 else if (oct%algorithm == option__octscheme__oct_cg .or. oct%algorithm == option__octscheme__oct_bfgs)
then
139 message(1) =
'If "OCTTargetOperator = oct_classical" and "OCTScheme = oct_cg" or'
140 message(2) =
'"OCTScheme = oct_bfgs", then you must define the blocks "OCTClassicalTarget",'
141 message(3) =
'"OCTPositionDerivatives" AND "OCTMomentumDerivatives"'
155 if (
parse_block(namespace,
'OCTPositionDerivatives', blk) == 0)
then
156 safe_allocate(tg%pos_der_array(1:ions%natoms,1:ions%space%dim))
157 do ist = 0, ions%natoms-1
158 do jst = 0, ions%space%dim-1
163 else if (oct%algorithm == option__octscheme__oct_cg .or. oct%algorithm == option__octscheme__oct_bfgs)
then
164 message(1) =
'If "OCTTargetOperator = oct_tg_classical" and "OCTScheme = oct_cg" or'
165 message(2) =
'"OCTScheme = oct_bfgs", then you must define the blocks "OCTClassicalTarget",'
166 message(3) =
'"OCTPositionDerivatives" AND "OCTMomentumDerivatives"'
178 type(
oct_t),
intent(in) :: oct
182 safe_deallocate_a(tg%pos_der_array)
183 safe_deallocate_a(tg%mom_der_array)
195 class(
space_t),
intent(in) :: space
196 type(
grid_t),
intent(in) :: gr
197 character(len=*),
intent(in) :: dir
198 type(
ions_t),
intent(in) :: ions
210 real(real64) function target_j1_classical(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
213 type(
grid_t),
intent(in) :: gr
216 type(
ions_t),
optional,
intent(in) :: ions
218 real(real64),
pointer :: q(:, :), p(:, :)
219 real(real64) :: dummy(3)
220 character(len=4096) :: inp_string
222 push_sub(target_j1_classical)
227 inp_string = tg%classical_input_string
231 call parse_expression(j1, dummy(1), 1, dummy(1:3), dummy(1), dummy(1), inp_string)
235 pop_sub(target_j1_classical)
244 type(namespace_t),
intent(in) :: namespace
245 type(grid_t),
intent(in) :: gr
246 type(kpoints_t),
intent(in) :: kpoints
247 type(opt_control_state_t),
target,
intent(inout) :: qcpsi_in
248 type(opt_control_state_t),
target,
intent(inout) :: qcchi_out
249 type(ions_t),
intent(in) :: ions
251 integer :: ist, jst, ib, iqn
252 character(len=1024) :: temp_string
253 real(real64) :: df_dv, dummy(3)
254 real(real64),
pointer :: q(:, :), p(:, :), tq(:, :), tp(:, :)
255 type(states_elec_t),
pointer :: chi
258 tq => opt_control_point_q(qcchi_out)
259 tp => opt_control_point_p(qcchi_out)
260 q => opt_control_point_q(qcpsi_in)
261 p => opt_control_point_p(qcpsi_in)
265 do ist = 1, ions%natoms
266 do jst=1, ions%space%dim
267 temp_string = tg%mom_der_array(ist, jst)
268 call parse_array(temp_string, p,
'p')
269 call parse_array(temp_string, q,
'q')
270 call conv_to_c_string(temp_string)
271 call parse_expression(df_dv, dummy(1), 1, dummy(1:3), dummy(1), dummy(1), temp_string)
272 tq(ist, jst) = -df_dv
276 do ist = 1, ions%natoms
277 do jst=1, ions%space%dim
278 temp_string = tg%pos_der_array(ist, jst)
279 call parse_array(temp_string, p,
'p')
280 call parse_array(temp_string, q,
'q')
281 call conv_to_c_string(temp_string)
282 call parse_expression(df_dv, dummy(1), 1, dummy(1:3), dummy(1), dummy(1), temp_string)
287 chi => opt_control_point_qs(qcchi_out)
290 do iqn = chi%d%kpt%start, chi%d%kpt%end
291 do ib = chi%group%block_start, chi%group%block_end
292 call batch_set_zero(chi%group%psib(ib, iqn))
This module implements common operations on batches of mesh functions.
This module implements the underlying real-space grid.
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 holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
real(real64) function, dimension(:, :), pointer, public opt_control_point_p(ocs)
real(real64) function, dimension(:, :), pointer, public opt_control_point_q(ocs)
this module contains the low-level part of the output system
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
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
subroutine target_output_classical(tg, namespace, space, gr, dir, ions, hm, outp)
The classical target has no associated grid output.
subroutine target_init_classical(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_end_classical(tg, oct)
subroutine target_chi_classical(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
real(real64) function target_j1_classical(tg, namespace, gr, kpoints, qcpsi, ions)
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 classical degrees of freedom.
Abstract optimal-control target.