37 use,
intrinsic :: iso_fortran_env
75 type(filter_t),
save :: filter
76 type(oct_t),
save :: oct
77 type(oct_iterator_t),
save :: iterator
78 type(target_t),
save :: oct_target
79 type(opt_control_state_t),
save :: initial_st
83 type(controlfunction_t),
save :: par_
84 type(electrons_t),
pointer :: sys_
85 type(hamiltonian_elec_t),
pointer :: hm_
86 type(td_t),
pointer :: td_
87 real(real64),
allocatable :: x_(:)
94 class(*),
intent(inout) :: system
100 message(1) =
"CalculationMode = opt_control not implemented for multi-system calculations"
112 type(electrons_t),
target,
intent(inout) :: sys
114 type(td_t),
target :: td
115 type(controlfunction_t) :: par, par_new, par_prev
118 type(oct_prop_t) :: prop_chi, prop_psi
119 type(states_elec_t) :: psi
121 type(lasers_t),
pointer :: lasers
125 if (sys%hm%pcm%run_pcm)
then
129 if (sys%kpoints%use_symmetries)
then
130 call messages_experimental(
"KPoints symmetries with CalculationMode = opt_control", namespace=sys%namespace)
139 call td_init(td, sys%namespace, sys%space, sys%gr, sys%ions, sys%st, sys%ks, sys%hm, sys%ext_partners, sys%outp)
157 if(
associated(lasers))
call laser_write_info(lasers%lasers, namespace=sys%namespace)
168 (oct%algorithm == option__octscheme__oct_zbr98), &
169 (oct%algorithm == option__octscheme__oct_cg) .or. &
170 (oct%algorithm == option__octscheme__oct_bfgs) .or. &
171 (oct%algorithm == option__octscheme__oct_nlopt_lbfgs))
175 call filter_init(td%max_iter, sys%namespace, td%dt, filter)
181 call target_init(sys%gr, sys%kpoints, sys%namespace, sys%space, sys%ions, initial_st, td, &
190 call output_states(sys%outp, sys%namespace, sys%space,
oct_dir//
'initial', psi, sys%gr, sys%ions, sys%hm, -1)
191 call target_output(oct_target, sys%namespace, sys%space, sys%gr,
oct_dir//
'target', sys%ions, sys%hm, sys%outp)
196 select case (oct%algorithm)
197 case (option__octscheme__oct_zbr98)
198 message(1) =
"Info: Starting OCT iteration using scheme: ZBR98"
201 case (option__octscheme__oct_wg05)
202 message(1) =
"Info: Starting OCT iteration using scheme: WG05"
205 case (option__octscheme__oct_zr98)
206 message(1) =
"Info: Starting OCT iteration using scheme: ZR98"
209 case (option__octscheme__oct_mt03)
210 message(1) =
"Info: Starting OCT iteration using scheme: MT03"
213 case (option__octscheme__oct_krotov)
214 message(1) =
"Info: Starting OCT iteration using scheme: KROTOV"
217 case (option__octscheme__oct_straight_iteration)
218 message(1) =
"Info: Starting OCT iterations using scheme: STRAIGHT ITERATION"
221 case (option__octscheme__oct_cg)
222 message(1) =
"Info: Starting OCT iterations using scheme: CONJUGATE GRADIENTS"
225 case (option__octscheme__oct_bfgs)
226 message(1) =
"Info: Starting OCT iterations using scheme: BFGS"
229 case (option__octscheme__oct_direct)
230 message(1) =
"Info: Starting OCT iterations using scheme: DIRECT OPTIMIZATION (NELDER-MEAD)"
233 case (option__octscheme__oct_nlopt_bobyqa)
234 message(1) =
"Info: Starting OCT iterations using scheme: DIRECT OPTIMIZATION (NLOPT - BOBYQA)"
237 case (option__octscheme__oct_nlopt_lbfgs)
238 message(1) =
"Info: Starting OCT iterations using scheme: DIRECT OPTIMIZATION (NLOPT - LBFGS)"
272 if (
clean_stop(sys%mc%master_comm) .or. stop_loop)
exit ctr_loop
289 call oct_prop_init(prop_chi, sys%namespace,
"chi", sys%gr, sys%mc)
290 call oct_prop_init(prop_psi, sys%namespace,
"psi", sys%gr, sys%mc)
295 call f_iter(sys, td, psi, par, prop_psi, prop_chi, j1)
297 if (
clean_stop(sys%mc%master_comm) .or. stop_loop)
exit ctr_loop
315 call oct_prop_init(prop_chi, sys%namespace,
"chi", sys%gr, sys%mc)
316 call oct_prop_init(prop_psi, sys%namespace,
"psi", sys%gr, sys%mc)
318 if (oct%mode_fixed_fluence)
then
327 call f_wg05(sys, td, psi, par, prop_psi, prop_chi, j1)
329 if (
clean_stop(sys%mc%master_comm) .or. stop_loop)
exit ctr_loop
349 call oct_prop_init(prop_chi, sys%namespace,
"chi", sys%gr, sys%mc)
350 call oct_prop_init(prop_psi, sys%namespace,
"psi", sys%gr, sys%mc)
354 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
367 call f_zbr98(sys, td, qcpsi, prop_psi, prop_chi, par)
368 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
370 if (
clean_stop(sys%mc%master_comm) .or. stop_loop)
exit ctr_loop
385 integer :: dof, ierr, maxiter
386 real(real64):: step, minvalue
387 real(real64),
allocatable :: theta(:)
388 real(real64),
allocatable :: x(:)
417 safe_allocate(x(1:dof))
418 safe_allocate(theta(1:dof))
422 step = oct%direct_step *
m_pi
425 select case (oct%algorithm)
426 case (option__octscheme__oct_bfgs)
428 real(oct_iterator_tolerance(iterator), real64),
real(oct_iterator_tolerance(iterator), real64), &
429 maxiter, opt_control_cg_calc, opt_control_cg_write_info, minvalue, ierr)
430 case (option__octscheme__oct_cg)
432 real(oct_iterator_tolerance(iterator), real64),
real(oct_iterator_tolerance(iterator), real64), &
433 maxiter, opt_control_cg_calc, opt_control_cg_write_info, minvalue, ierr)
437 if (ierr <= 1024)
then
438 message(1) =
"Error occurred during the GSL minimization procedure:"
442 message(1) =
"The optimization did not meet the convergence criterion."
449 safe_deallocate_a(theta)
457 integer :: ierr, maxiter
458 real(real64):: minvalue, step
459 real(real64),
allocatable :: theta(:)
460 real(real64),
allocatable :: x(:)
482 safe_allocate(x(1:dim))
483 safe_allocate(theta(1:dim))
498 step = oct%direct_step *
m_pi
502 real(oct_iterator_tolerance(iterator), real64) , maxiter, &
503 opt_control_direct_calc, opt_control_direct_message_info, minvalue, ierr)
506 if (ierr <= 1024)
then
507 message(1) =
"Error occurred during the GSL minimization procedure:"
511 message(1) =
"The OCT direct optimization did not meet the convergence criterion."
518 safe_deallocate_a(theta)
526#if defined(HAVE_NLOPT)
527 integer :: method, dim, maxiter, ierr
528 real(real64),
allocatable :: x(:), xl(:), xu(:)
529 real(real64) :: step, toldr, minimum, f
548 safe_allocate(x(dim))
549 safe_allocate(xl(1:dim))
550 safe_allocate(xu(1:dim))
565 step = oct%direct_step
566 select case (oct%algorithm)
567 case (option__octscheme__oct_nlopt_bobyqa)
569 case (option__octscheme__oct_nlopt_lbfgs)
574 call minimize_multidim_nlopt(ierr, method, dim, x, step, toldr, maxiter,
opt_control_nlopt_func, minimum, &
576 if (ierr < 1 .or. ierr > 4)
then
577 message(1) =
"The nlopt minimization procedure did not find convergence, or found an error"
578 write(
message(2),
'(a,i5)')
"Error code =", ierr
583 safe_deallocate_a(xl)
584 safe_deallocate_a(xu)
596 subroutine f_zbr98(sys, td, qcpsi, prop_psi, prop_chi, par)
598 type(
td_t),
intent(inout) :: td
614 call bwd_step(sys, td, oct_target, par, par_chi, qcchi, prop_chi, prop_psi)
616 call fwd_step(sys, td, oct_target, par, par_chi, qcpsi, prop_chi, prop_psi)
626 subroutine f_wg05(sys, td, qcpsi, par, prop_psi, prop_chi, j1)
628 type(
td_t),
intent(inout) :: td
633 real(real64),
intent(out) :: j1
635 real(real64) :: new_penalty
644 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
653 call target_chi(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi, qcchi, sys%ions)
654 call bwd_step(sys, td, oct_target, par, parp, qcchi, prop_chi, prop_psi)
659 if (oct%mode_fixed_fluence)
then
671 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
683 type(
td_t),
intent(inout) :: td
685 real(real64),
intent(out) :: j1
694 call oct_prop_init(prop_chi, sys%namespace,
"chi", sys%gr, sys%mc)
695 call oct_prop_init(prop_psi, sys%namespace,
"psi", sys%gr, sys%mc)
707 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi, sys%ions)
712 call target_chi(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi, qcchi, sys%ions)
716 call bwd_step_2(sys, td, oct_target, par, par_chi, qcchi, prop_chi, prop_psi)
734 subroutine f_iter(sys, td, qcpsi, par, prop_psi, prop_chi, j1)
736 type(
td_t),
intent(inout) :: td
741 real(real64),
intent(out) :: j1
751 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
760 call target_chi(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi, qcchi, sys%ions)
761 call bwd_step(sys, td, oct_target, par, par_chi, qcchi, prop_chi, prop_psi)
764 call fwd_step(sys, td, oct_target, par, par_chi, qcpsi, prop_chi, prop_psi)
766 j1 =
target_j1(oct_target, sys%namespace, sys%gr, sys%kpoints, qcpsi)
774#include "opt_control_c_inc.F90"
775#include "check_input_inc.F90"
776#include "finalcheck_inc.F90"
Define which routines can be seen from the outside.
double sqrt(double __x) __attribute__((__nothrow__
subroutine minimize_multidim(method, dim, x, step, line_tol, tolgrad, toldr, maxiter, f, write_iter_info, minimum, ierr)
This module contains the definition of the data type that holds a "control function" used for OCT run...
subroutine, public controlfunction_filter(par, filter)
subroutine, public controlfunction_apply_envelope(cp)
subroutine, public controlfunction_set_fluence(par)
subroutine, public controlfunction_bounds(par, lower_bounds, upper_bounds)
subroutine, public controlfunction_to_realtime(par)
integer pure function, public controlfunction_dof(par)
real(real64) function, public controlfunction_fluence(par)
subroutine, public controlfunction_set_alpha(par, alpha)
subroutine, public controlfunction_write(filename, cp, namespace)
subroutine, public controlfunction_prepare_initial(par)
"Prepares" the initial guess control field: maybe it has to be normalized to a certain fluence,...
real(real64) pure function, public controlfunction_w0(par)
subroutine, public controlfunction_end(cp)
subroutine, public controlfunction_get_theta(par, theta)
real(real64) function, public controlfunction_j2(par)
subroutine, public controlfunction_randomize(par)
real(real64) pure function, public controlfunction_alpha(par, ipar)
real(real64) pure function, public controlfunction_targetfluence()
subroutine, public controlfunction_copy(cp_out, cp_in)
subroutine, public controlfunction_set_rep(par)
Transforms the control function to frequency space, if this is the space in which the functions are d...
subroutine, public controlfunction_mod_close()
subroutine, public controlfunction_to_h(cp, ext_partners)
subroutine, public controlfunction_init(cp, dt, ntiter)
Before using an controlfunction_t variable, it needs to be initialized, either by calling controlfunc...
subroutine, public controlfunction_mod_init(ext_partners, namespace, dt, max_iter, mode_fixed_fluence)
Initializes the module, should be the first subroutine to be called (the last one should be controlfu...
subroutine, public controlfunction_set(cp, ext_partners)
The external fields defined in epot_t "ep" are transferred to the control functions described in "cp"...
type(lasers_t) function, pointer, public list_get_lasers(partners)
subroutine, public filter_init(steps, namespace, dt, filter)
subroutine, public filter_write(filter, namespace)
subroutine, public filter_end(filter)
real(real64), parameter, public m_pi
some mathematical constants
character(len= *), parameter, public oct_dir
This module implements the underlying real-space grid.
integer, parameter, public independent_particles
subroutine, public initial_state_init(sys, qcstate)
subroutine, public io_mkdir(fname, namespace, parents)
subroutine, public laser_write_info(lasers, namespace, dt, max_iter, iunit)
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
subroutine, public messages_not_implemented(feature, namespace)
character(len=512), private msg
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
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_experimental(name, namespace)
integer minmethod_nmsimplex
integer minmethod_nlopt_lbfgs
integer minmethod_nlopt_bobyqa
This module implements the basic mulsisystem class, a container system for other systems.
This module contains the definition of the oct_t data type, which contains some of the basic informat...
subroutine, public oct_read_inp(oct, namespace)
Reads, from the inp file, some global information about how the QOCT run should be.
logical function, public iteration_manager(namespace, j1, par, par_prev, iterator)
subroutine, public oct_iterator_init(iterator, namespace, par)
integer pure function, public oct_iterator_maxiter(iterator)
subroutine, public oct_iterator_end(iterator, namespace)
integer pure function, public oct_iterator_current(iterator)
subroutine, public iteration_manager_direct(j, par, iterator, sys, dx)
real(real64) pure function, public oct_iterator_tolerance(iterator)
This module contains the main procedure ("opt_control_run") that is used when optimal control runs ar...
subroutine, public opt_control_cg_calc(n, x, f, getgrad, df)
subroutine check_faulty_runmodes(sys, tr)
subroutine, public opt_control_run(system)
subroutine oct_finalcheck(sys, td)
subroutine, public opt_control_cg_write_info(iter, n, val, maxdx, maxdf, x)
interface is required by its being passed as dummy routine to minimize_multidim
subroutine f_striter(sys, td, par, j1)
subroutine, public opt_control_direct_message_info(iter, n, val, maxdx, x)
subroutine f_zbr98(sys, td, qcpsi, prop_psi, prop_chi, par)
subroutine f_iter(sys, td, qcpsi, par, prop_psi, prop_chi, j1)
subroutine opt_control_run_legacy(sys)
This is the main procedure for all types of optimal control runs. It is called from the "run" procedu...
subroutine f_wg05(sys, td, qcpsi, par, prop_psi, prop_chi, j1)
subroutine, public opt_control_function_forward(x, f)
subroutine opt_control_nlopt_func(val, n, x, grad, need_gradient, f_data)
subroutine, public opt_control_direct_calc(n, x, f)
No intents here is unfortunately required because this will be passed to newuoa routines as a dummy f...
This module holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
subroutine, public opt_control_state_end(ocs)
subroutine, public opt_control_state_null(ocs)
subroutine, public opt_control_state_copy(ocsout, ocsin)
subroutine, public opt_control_state_init(ocs, qstate, ions)
subroutine, public opt_control_get_qs(qstate, ocs)
this module contains the output system
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
subroutine, public propagation_mod_init(niter, eta, delta, number_checkpoints, zbr98, gradients)
This subroutine must be called before any QOCT propagations are done. It simply stores in the module ...
subroutine, public oct_prop_end(prop)
subroutine, public bwd_step(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
subroutine, public propagate_forward(sys, td, par, tg, qcpsi, prop, write_iter)
subroutine, public fwd_step(sys, td, tg, par, par_chi, qcpsi, prop_chi, prop_psi)
subroutine, public oct_prop_init(prop, namespace, dirname, mesh, mc)
subroutine, public bwd_step_2(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
subroutine, public propagator_elec_set_scf_prop(tr, threshold)
logical function, public clean_stop(comm)
returns true if a file named stop exists
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_end(st)
finalize the states_elec_t object
real(real64) function, public target_j1(tg, namespace, gr, kpoints, qcpsi, ions)
Calculates the J1 functional, i.e.: in the time-independent case, or else in the time-dependent cas...
subroutine, public target_init(gr, kpoints, namespace, space, ions, qcs, td, w0, tg, oct, ep, mc)
The target is initialized, mainly by reading from the inp file.
subroutine, public target_get_state(tg, st)
This just copies the states_elec_t variable present in target, into st.
subroutine, public target_output(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine, public target_chi(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
Calculate .
subroutine, public target_end(tg, oct)
subroutine, public td_end(td)
subroutine, public td_init(td, namespace, space, gr, ions, st, ks, hm, ext_partners, outp)
subroutine scheme_zbr98()
subroutine scheme_direct()
subroutine scheme_straight_iteration()
subroutine scheme_nlopt()
This is the data type used to hold a control function.
Class describing the electron system.
Container class for lists of system_oct_m::system_t.
This is the datatype that contains the objects that are propagated: in principle this could be both t...
The states_elec_t class contains all electronic wave functions.