Octopus
target_exclude.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
20#include "global.h"
21
23 use debug_oct_m
24 use epot_oct_m
25 use global_oct_m
26 use grid_oct_m
28 use io_oct_m
29 use ions_oct_m
31 use, intrinsic :: iso_fortran_env
33 use loct_oct_m
34 use mesh_oct_m
40 use output_oct_m
42 use parser_oct_m
45 use space_oct_m
48 use target_oct_m
49 use td_oct_m
50
51 implicit none
52
53 private
54 public :: target_exclude_t
55
57 type, extends(target_t) :: target_exclude_t
58 private
59 character(len=80) :: excluded_states_list
60 contains
61 procedure :: init => target_init_exclude
62 procedure :: j1 => target_j1_exclude
63 procedure :: apply_chi => target_chi_exclude
64 procedure :: output => target_output_exclude
65 end type target_exclude_t
66
67
68contains
69
70 ! ----------------------------------------------------------------------
72 subroutine target_init_exclude(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
73 class(target_exclude_t), intent(inout) :: tg
74 type(grid_t), intent(in) :: gr
75 type(kpoints_t), intent(in) :: kpoints
76 type(namespace_t), intent(in) :: namespace
77 class(space_t), intent(in) :: space
78 type(ions_t), intent(in) :: ions
79 type(opt_control_state_t), intent(inout) :: qcs
80 type(td_t), intent(in) :: td
81 real(real64), intent(in) :: w0
82 type(oct_t), intent(in) :: oct
83 type(epot_t), intent(inout) :: ep
84 type(restart_t), intent(inout) :: restart
85
86 push_sub(target_init_exclude)
87
88 tg%move_ions = td%ions_dyn%ions_move()
89 tg%dt = td%dt
90
91 message(1) = 'Info: The target functional is the exclusion of a number of states defined by'
92 message(2) = ' "OCTExcludedStates".'
93 call messages_info(2, namespace=namespace)
94 !%Variable OCTExcludedStates
95 !%Type string
96 !%Section Calculation Modes::Optimal Control
97 !%Description
98 !% If the target is the exclusion of several targets, ("OCTTargetOperator = oct_exclude_states")
99 !% then you must declare which states are to be excluded, by setting the OCTExcludedStates variable.
100 !% It must be a string in "list" format: "1-8", or "2,3,4-9", for example. Be careful to include
101 !% in this list only states that have been calculated in a previous "gs" or "unocc" calculation,
102 !% or otherwise the error will be silently ignored.
103 !%End
104 call parse_variable(namespace, 'OCTExcludedStates', '1', tg%excluded_states_list)
106
107 call states_elec_look_and_load(restart, namespace, space, tg%st, gr, kpoints, fixed_occ=.true.)
108
109 pop_sub(target_init_exclude)
110 end subroutine target_init_exclude
111
112
113 ! ----------------------------------------------------------------------
114 subroutine target_output_exclude(tg, namespace, space, gr, dir, ions, hm, outp)
115 class(target_exclude_t), intent(inout) :: tg
116 type(namespace_t), intent(in) :: namespace
117 class(space_t), intent(in) :: space
118 type(grid_t), intent(in) :: gr
119 character(len=*), intent(in) :: dir
120 type(ions_t), intent(in) :: ions
121 type(hamiltonian_elec_t), intent(in) :: hm
122 type(output_t), intent(in) :: outp
123
124 push_sub(target_output_exclude)
125
126 call io_mkdir(trim(dir), namespace)
127 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
128
129 pop_sub(target_output_exclude)
130 end subroutine target_output_exclude
131 ! ----------------------------------------------------------------------
132
133
134 ! ----------------------------------------------------------------------
136 real(real64) function target_j1_exclude(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
137 class(target_exclude_t), intent(inout) :: tg
138 type(namespace_t), intent(in) :: namespace
139 type(grid_t), intent(in) :: gr
140 type(kpoints_t), intent(in) :: kpoints
141 type(opt_control_state_t), intent(inout) :: qcpsi
142 type(ions_t), optional, intent(in) :: ions
143
144 integer :: ist
145 complex(real64), allocatable :: zpsi1(:, :), zpsi(:, :)
146 type(states_elec_t), pointer :: psi
147
148 push_sub(target_j1_exclude)
149
150 psi => opt_control_point_qs(qcpsi)
151
152 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
153 safe_allocate(zpsi1(1:gr%np, 1:tg%st%d%dim))
155 call states_elec_get_state(psi, gr, 1, 1, zpsi1)
157 j1 = m_one
158 do ist = 1, tg%st%nst
159 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
160 call states_elec_get_state(tg%st, gr, ist, 1, zpsi)
161 j1 = j1 - abs(zmf_dotp(gr, psi%d%dim, zpsi, zpsi1))**2
162 end if
163 end do
164
165 safe_deallocate_a(zpsi)
166 safe_deallocate_a(zpsi1)
168 nullify(psi)
169 pop_sub(target_j1_exclude)
170 end function target_j1_exclude
171
172
173 ! ----------------------------------------------------------------------
175 subroutine target_chi_exclude(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
176 class(target_exclude_t), intent(inout) :: tg
177 type(namespace_t), intent(in) :: namespace
178 type(grid_t), intent(in) :: gr
179 type(kpoints_t), intent(in) :: kpoints
180 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
181 type(opt_control_state_t), target, intent(inout) :: qcchi_out
182 type(ions_t), intent(in) :: ions
183
184 integer :: ist, ib
185 complex(real64) :: olap
186 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
187 type(states_elec_t), pointer :: psi_in, chi_out
188 push_sub(target_chi_exclude)
189
190 psi_in => opt_control_point_qs(qcpsi_in)
191 chi_out => opt_control_point_qs(qcchi_out)
192
193 do ib = chi_out%group%block_start, chi_out%group%block_end
194 call psi_in%group%psib(ib, 1)%copy_data_to(gr%np, chi_out%group%psib(ib, 1))
195 end do
196
197 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
198 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
199 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
200
201 call states_elec_get_state(chi_out, gr, 1, 1, zchi)
202
203 do ist = 1, tg%st%nst
204 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
205 call states_elec_get_state(psi_in, gr, ist, 1, zpsi)
206 call states_elec_get_state(tg%st, gr, ist, 1, zst)
207 olap = zmf_dotp(gr, psi_in%d%dim, zst, zpsi)
208 zchi(1:gr%np, 1:tg%st%d%dim) = zchi(1:gr%np, 1:tg%st%d%dim) - olap*zst(1:gr%np, 1:tg%st%d%dim)
209 end if
210 end do
211
212 call states_elec_set_state(chi_out, gr, 1, 1, zchi)
213
214 safe_deallocate_a(zpsi)
215 safe_deallocate_a(zst)
216 safe_deallocate_a(zchi)
217
218 nullify(psi_in)
219 nullify(chi_out)
220 pop_sub(target_chi_exclude)
221 end subroutine target_chi_exclude
222
223end module target_exclude_oct_m
224
225!! Local Variables:
226!! mode: f90
227!! coding: utf-8
228!! End:
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
Definition: io.F90:116
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
System information (time, memory, sysname)
Definition: loct.F90:117
logical function, public loct_isinstringlist(a, s)
Definition: loct.F90:288
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
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
this module contains the output system
Definition: output.F90:117
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1091
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_look_and_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, is_complex, packed)
real(real64) function target_j1_exclude(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_init_exclude(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_output_exclude(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine target_chi_exclude(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
Definition: td.F90:116
Target projecting onto the complement of a set of states.
Abstract optimal-control target.
Definition: target.F90:172
int true(void)