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
25 use grid_oct_m
27 use ions_oct_m
28 use, intrinsic :: iso_fortran_env
36 use parser_oct_m
39 use space_oct_m
41 use target_oct_m
42 use td_oct_m
43
44 implicit none
45
46 private
47 public :: target_spin_t
48
50 type, extends(target_t) :: target_spin_t
51 private
52 complex(real64) :: spin_matrix(2, 2)
53 contains
54 procedure :: init => target_init_spin
55 procedure :: j1 => target_j1_spin
56 procedure :: apply_chi => target_chi_spin
57 procedure :: output => target_output_spin
58 end type target_spin_t
59
60
61contains
62
63 ! ----------------------------------------------------------------------
65 subroutine target_init_spin(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
66 class(target_spin_t), intent(inout) :: tg
67 type(grid_t), intent(in) :: gr
68 type(kpoints_t), intent(in) :: kpoints
69 type(namespace_t), intent(in) :: namespace
70 class(space_t), intent(in) :: space
71 type(ions_t), intent(in) :: ions
72 type(opt_control_state_t), intent(inout) :: qcs
73 type(td_t), intent(in) :: td
74 real(real64), intent(in) :: w0
75 type(oct_t), intent(in) :: oct
76 type(epot_t), intent(inout) :: ep
77 type(restart_t), intent(inout) :: restart
78
79 type(block_t) :: blk
80 integer :: jst
81 complex(real64) :: alpha(3)
82
83 push_sub(target_init_spin)
84
85
86 message(1) = 'Info: Using a spin target'
87 call messages_info(1, namespace=namespace)
88
89 !%Variable OCTTargetSpin
90 !%Type block
91 !%Section Calculation Modes::Optimal Control
92 !%Description
93 !% (Experimental) Specify the targeted spin as a 3-component vector. It will be normalized.
94 !%End
95 if (parse_is_defined(namespace, 'OCTTargetSpin')) then
96 if (parse_block(namespace, 'OCTTargetSpin', blk) == 0) then
97 alpha = m_z0
98 do jst = 1, parse_block_cols(blk, 0)
99 call parse_block_cmplx(blk, 0, jst - 1, alpha(jst))
100 end do
101 call parse_block_end(blk)
102
103 alpha = alpha/norm2(abs(alpha))
104
105 tg%spin_matrix(1, 1) = alpha(3)
106 tg%spin_matrix(2, 2) = -alpha(3)
107 tg%spin_matrix(1, 2) = alpha(1) - m_zi * alpha(2)
108 tg%spin_matrix(2, 1) = alpha(1) + m_zi * alpha(2)
109
110 else
111 call messages_variable_is_block(namespace, 'OCTTargetSpin')
112 end if
113
114 else
115 message(1) = 'If "OCTTargetOperator = oct_tg_spin", then you must'
116 message(2) = 'supply a "OCTTargetSpin" block.'
117 call messages_fatal(2, namespace=namespace)
118 end if
119
120
121 pop_sub(target_init_spin)
122 end subroutine target_init_spin
123
124
125 ! ----------------------------------------------------------------------
127 subroutine target_output_spin(tg, namespace, space, gr, dir, ions, hm, outp)
128 class(target_spin_t), intent(inout) :: tg
129 type(namespace_t), intent(in) :: namespace
130 class(space_t), intent(in) :: space
131 type(grid_t), intent(in) :: gr
132 character(len=*), intent(in) :: dir
133 type(ions_t), intent(in) :: ions
134 type(hamiltonian_elec_t), intent(in) :: hm
135 type(output_t), intent(in) :: outp
136
137 push_sub(target_output_spin)
138 pop_sub(target_output_spin)
139 end subroutine target_output_spin
140 ! ----------------------------------------------------------------------
141
142
143 ! ----------------------------------------------------------------------
145 real(real64) function target_j1_spin(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
146 class(target_spin_t), intent(inout) :: tg
147 type(namespace_t), intent(in) :: namespace
148 type(grid_t), intent(in) :: gr
149 type(kpoints_t), intent(in) :: kpoints
150 type(opt_control_state_t), intent(inout) :: qcpsi
151 type(ions_t), optional, intent(in) :: ions
153 integer :: i, j
154 complex(real64), allocatable :: zpsi(:, :)
155 type(states_elec_t), pointer :: psi
156
157 push_sub(target_j1_spin)
158
159 psi => opt_control_point_qs(qcpsi)
161 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
162
163 call states_elec_get_state(psi, gr, 1, 1, zpsi)
164
165 j1 = m_zero
166 do i = 1, 2
167 do j = 1, 2
168 j1 = j1 + real(tg%spin_matrix(i,j)*zmf_dotp(gr, zpsi(:, i), zpsi(:, j)), real64)
169 end do
170 end do
171
172 safe_deallocate_a(zpsi)
173
174 nullify(psi)
175 pop_sub(target_j1_spin)
176 end function target_j1_spin
177
178
179
180 ! ----------------------------------------------------------------------
182 subroutine target_chi_spin(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
183 class(target_spin_t), intent(inout) :: tg
184 type(namespace_t), intent(in) :: namespace
185 type(grid_t), intent(in) :: gr
186 type(kpoints_t), intent(in) :: kpoints
187 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
188 type(opt_control_state_t), target, intent(inout) :: qcchi_out
189 type(ions_t), intent(in) :: ions
190
191 integer :: i, j
192 complex(real64), allocatable :: zpsi(:, :), zchi(:, :)
193 type(states_elec_t), pointer :: psi_in, chi_out
194
195 push_sub(target_chi_spin)
196
197 psi_in => opt_control_point_qs(qcpsi_in)
198 chi_out => opt_control_point_qs(qcchi_out)
199
200 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
201 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
202
203 call states_elec_get_state(psi_in, gr, 1, 1, zpsi)
204
205 zchi(1:gr%np, 1:tg%st%d%dim) = 0.0_real64
206
207 do i = 1, 2
208 do j = 1, 2
209 zchi(1:gr%np, i) = zchi(1:gr%np, i) + tg%spin_matrix(i, j)*zpsi(1:gr%np, j)
210 end do
211 end do
212
213 call states_elec_set_state(chi_out, gr, 1, 1, zchi)
214
215 safe_deallocate_a(zpsi)
216 safe_deallocate_a(zchi)
217
218 nullify(psi_in)
219 nullify(chi_out)
220 pop_sub(target_chi_spin)
221 end subroutine target_chi_spin
223end module target_spin_oct_m
224
225!! Local Variables:
226!! mode: f90
227!! coding: utf-8
228!! 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.