Octopus
target_spin.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
23 use epot_oct_m
24 use global_oct_m
26 use grid_oct_m
28 use ions_oct_m
29 use, intrinsic :: iso_fortran_env
37 use parser_oct_m
40 use space_oct_m
42 use target_oct_m
43 use td_oct_m
44
45 implicit none
46
47 private
48 public :: target_spin_t
49
51 type, extends(target_t) :: target_spin_t
52 private
53 complex(real64) :: spin_matrix(2, 2)
54 contains
55 procedure :: init => target_init_spin
56 procedure :: j1 => target_j1_spin
57 procedure :: apply_chi => target_chi_spin
58 procedure :: output => target_output_spin
59 end type target_spin_t
60
61
62contains
63
64 ! ----------------------------------------------------------------------
66 subroutine target_init_spin(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
67 class(target_spin_t), intent(inout) :: tg
68 type(grid_t), intent(in) :: gr
69 type(kpoints_t), intent(in) :: kpoints
70 type(namespace_t), intent(in) :: namespace
71 class(space_t), intent(in) :: space
72 type(ions_t), intent(in) :: ions
73 type(opt_control_state_t), intent(inout) :: qcs
74 type(td_t), intent(in) :: td
75 real(real64), intent(in) :: w0
76 type(oct_t), intent(in) :: oct
77 type(epot_t), intent(inout) :: ep
78 type(restart_t), intent(inout) :: restart
79
80 type(block_t) :: blk
81 integer :: jst
82 complex(real64) :: alpha(3)
83
84 push_sub(target_init_spin)
85
86
87 message(1) = 'Info: Using a spin target'
88 call messages_info(1, namespace=namespace)
89
90 !%Variable OCTTargetSpin
91 !%Type block
92 !%Section Calculation Modes::Optimal Control
93 !%Description
94 !% (Experimental) Specify the targeted spin as a 3-component vector. It will be normalized.
95 !%End
96 if (parse_is_defined(namespace, 'OCTTargetSpin')) then
97 if (parse_block(namespace, 'OCTTargetSpin', blk) == 0) then
98 alpha = m_z0
99 do jst = 1, parse_block_cols(blk, 0)
100 call parse_block_cmplx(blk, 0, jst - 1, alpha(jst))
101 end do
102 call parse_block_end(blk)
103
104 alpha = alpha/norm2(abs(alpha))
105
106 tg%spin_matrix(1, 1) = alpha(3)
107 tg%spin_matrix(2, 2) = -alpha(3)
108 tg%spin_matrix(1, 2) = alpha(1) - m_zi * alpha(2)
109 tg%spin_matrix(2, 1) = alpha(1) + m_zi * alpha(2)
110
111 else
112 call messages_variable_is_block(namespace, 'OCTTargetSpin')
113 end if
114
115 else
116 message(1) = 'If "OCTTargetOperator = oct_tg_spin", then you must'
117 message(2) = 'supply a "OCTTargetSpin" block.'
118 call messages_fatal(2, namespace=namespace)
119 end if
120
121
122 pop_sub(target_init_spin)
123 end subroutine target_init_spin
124
125
126 ! ----------------------------------------------------------------------
128 subroutine target_output_spin(tg, namespace, space, gr, dir, ions, hm, outp)
129 class(target_spin_t), intent(inout) :: tg
130 type(namespace_t), intent(in) :: namespace
131 class(space_t), intent(in) :: space
132 type(grid_t), intent(in) :: gr
133 character(len=*), intent(in) :: dir
134 type(ions_t), intent(in) :: ions
135 type(hamiltonian_elec_t), intent(in) :: hm
136 type(output_t), intent(in) :: outp
137
138 push_sub(target_output_spin)
139 pop_sub(target_output_spin)
140 end subroutine target_output_spin
141 ! ----------------------------------------------------------------------
142
143
144 ! ----------------------------------------------------------------------
146 real(real64) function target_j1_spin(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
147 class(target_spin_t), intent(inout) :: tg
148 type(namespace_t), intent(in) :: namespace
149 type(grid_t), intent(in) :: gr
150 type(kpoints_t), intent(in) :: kpoints
151 type(opt_control_state_t), intent(inout) :: qcpsi
152 type(ions_t), optional, intent(in) :: ions
154 integer :: i, j
155 complex(real64), allocatable :: zpsi(:, :)
156 type(states_elec_t), pointer :: psi
157
158 push_sub(target_j1_spin)
159
160 psi => opt_control_point_qs(qcpsi)
162 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
163
164 call states_elec_get_state(psi, gr, 1, 1, zpsi)
165
166 j1 = m_zero
167 do i = 1, 2
168 do j = 1, 2
169 j1 = j1 + real(tg%spin_matrix(i,j)*zmf_dotp(gr, zpsi(:, i), zpsi(:, j)), real64)
170 end do
171 end do
172
173 safe_deallocate_a(zpsi)
174
175 nullify(psi)
176 pop_sub(target_j1_spin)
177 end function target_j1_spin
178
179
180
181 ! ----------------------------------------------------------------------
183 subroutine target_chi_spin(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
184 class(target_spin_t), intent(inout) :: tg
185 type(namespace_t), intent(in) :: namespace
186 type(grid_t), intent(in) :: gr
187 type(kpoints_t), intent(in) :: kpoints
188 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
189 type(opt_control_state_t), target, intent(inout) :: qcchi_out
190 type(ions_t), intent(in) :: ions
191
192 integer :: i, j
193 complex(real64), allocatable :: zpsi(:, :), zchi(:, :)
194 type(states_elec_t), pointer :: psi_in, chi_out
195
196 push_sub(target_chi_spin)
197
198 psi_in => opt_control_point_qs(qcpsi_in)
199 chi_out => opt_control_point_qs(qcchi_out)
200
201 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
202 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
203
204 call states_elec_get_state(psi_in, gr, 1, 1, zpsi)
205
206 zchi(1:gr%np, 1:tg%st%d%dim) = 0.0_real64
207
208 do i = 1, 2
209 do j = 1, 2
210 call lalg_axpy(gr%np, tg%spin_matrix(i, j), zpsi(:, j), zchi(:, i))
211 end do
212 end do
213
214 call states_elec_set_state(chi_out, gr, 1, 1, zchi)
215
216 safe_deallocate_a(zpsi)
217 safe_deallocate_a(zchi)
218
219 nullify(psi_in)
220 nullify(chi_out)
221 pop_sub(target_chi_spin)
222 end subroutine target_chi_spin
224end module target_spin_oct_m
225
226!! Local Variables:
227!! mode: f90
228!! coding: utf-8
229!! End:
real(real64), parameter, public m_zero
Definition: global.F90:200
complex(real64), parameter, public m_z0
Definition: global.F90:210
complex(real64), parameter, public m_zi
Definition: global.F90:214
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines various routines, operating on mesh functions.
subroutine, public messages_variable_is_block(namespace, name)
Definition: messages.F90:1024
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
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.
type(states_elec_t) function, pointer, public opt_control_point_qs(ocs)
this module contains the low-level part of the output system
Definition: output_low.F90:117
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
subroutine target_init_spin(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_output_spin(tg, namespace, space, gr, dir, ions, hm, outp)
The spin target has no associated output.
real(real64) function target_j1_spin(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_chi_spin(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
Definition: td.F90:116
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
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.
Abstract optimal-control target.
Definition: target.F90:172
Target on the electronic spin.