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
27 use grid_oct_m
29 use io_oct_m
30 use ions_oct_m
32 use, intrinsic :: iso_fortran_env
34 use loct_oct_m
35 use mesh_oct_m
41 use output_oct_m
43 use parser_oct_m
46 use space_oct_m
49 use target_oct_m
50 use td_oct_m
51
52 implicit none
53
54 private
55 public :: target_exclude_t
56
58 type, extends(target_t) :: target_exclude_t
59 private
60 character(len=80) :: excluded_states_list
61 contains
62 procedure :: init => target_init_exclude
63 procedure :: j1 => target_j1_exclude
64 procedure :: apply_chi => target_chi_exclude
65 procedure :: output => target_output_exclude
66 end type target_exclude_t
67
68
69contains
70
71 ! ----------------------------------------------------------------------
73 subroutine target_init_exclude(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
74 class(target_exclude_t), intent(inout) :: tg
75 type(grid_t), intent(in) :: gr
76 type(kpoints_t), intent(in) :: kpoints
77 type(namespace_t), intent(in) :: namespace
78 class(space_t), intent(in) :: space
79 type(ions_t), intent(in) :: ions
80 type(opt_control_state_t), intent(inout) :: qcs
81 type(td_t), intent(in) :: td
82 real(real64), intent(in) :: w0
83 type(oct_t), intent(in) :: oct
84 type(epot_t), intent(inout) :: ep
85 type(restart_t), intent(inout) :: restart
86
87 push_sub(target_init_exclude)
88
89 tg%move_ions = td%ions_dyn%ions_move()
90 tg%dt = td%dt
91
92 message(1) = 'Info: The target functional is the exclusion of a number of states defined by'
93 message(2) = ' "OCTExcludedStates".'
94 call messages_info(2, namespace=namespace)
95 !%Variable OCTExcludedStates
96 !%Type string
97 !%Section Calculation Modes::Optimal Control
98 !%Description
99 !% If the target is the exclusion of several targets, ("OCTTargetOperator = oct_exclude_states")
100 !% then you must declare which states are to be excluded, by setting the OCTExcludedStates variable.
101 !% It must be a string in "list" format: "1-8", or "2,3,4-9", for example. Be careful to include
102 !% in this list only states that have been calculated in a previous "gs" or "unocc" calculation,
103 !% or otherwise the error will be silently ignored.
104 !%End
105 call parse_variable(namespace, 'OCTExcludedStates', '1', tg%excluded_states_list)
107
108 call states_elec_look_and_load(restart, namespace, space, tg%st, gr, kpoints, fixed_occ=.true.)
109
110 pop_sub(target_init_exclude)
111 end subroutine target_init_exclude
112
113
114 ! ----------------------------------------------------------------------
115 subroutine target_output_exclude(tg, namespace, space, gr, dir, ions, hm, outp)
116 class(target_exclude_t), intent(inout) :: tg
117 type(namespace_t), intent(in) :: namespace
118 class(space_t), intent(in) :: space
119 type(grid_t), intent(in) :: gr
120 character(len=*), intent(in) :: dir
121 type(ions_t), intent(in) :: ions
122 type(hamiltonian_elec_t), intent(in) :: hm
123 type(output_t), intent(in) :: outp
124
125 push_sub(target_output_exclude)
126
127 call io_mkdir(trim(dir), namespace)
128 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
129
130 pop_sub(target_output_exclude)
131 end subroutine target_output_exclude
132 ! ----------------------------------------------------------------------
133
134
135 ! ----------------------------------------------------------------------
137 real(real64) function target_j1_exclude(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
138 class(target_exclude_t), intent(inout) :: tg
139 type(namespace_t), intent(in) :: namespace
140 type(grid_t), intent(in) :: gr
141 type(kpoints_t), intent(in) :: kpoints
142 type(opt_control_state_t), intent(inout) :: qcpsi
143 type(ions_t), optional, intent(in) :: ions
144
145 integer :: ist
146 complex(real64), allocatable :: zpsi1(:, :), zpsi(:, :)
147 type(states_elec_t), pointer :: psi
148
149 push_sub(target_j1_exclude)
150
151 psi => opt_control_point_qs(qcpsi)
152
153 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
154 safe_allocate(zpsi1(1:gr%np, 1:tg%st%d%dim))
156 call states_elec_get_state(psi, gr, 1, 1, zpsi1)
158 j1 = m_one
159 do ist = 1, tg%st%nst
160 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
161 call states_elec_get_state(tg%st, gr, ist, 1, zpsi)
162 j1 = j1 - abs(zmf_dotp(gr, psi%d%dim, zpsi, zpsi1))**2
163 end if
164 end do
165
166 safe_deallocate_a(zpsi)
167 safe_deallocate_a(zpsi1)
169 nullify(psi)
170 pop_sub(target_j1_exclude)
171 end function target_j1_exclude
172
173
174 ! ----------------------------------------------------------------------
176 subroutine target_chi_exclude(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
177 class(target_exclude_t), intent(inout) :: tg
178 type(namespace_t), intent(in) :: namespace
179 type(grid_t), intent(in) :: gr
180 type(kpoints_t), intent(in) :: kpoints
181 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
182 type(opt_control_state_t), target, intent(inout) :: qcchi_out
183 type(ions_t), intent(in) :: ions
184
185 integer :: ist, ib
186 complex(real64) :: olap
187 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
188 type(states_elec_t), pointer :: psi_in, chi_out
189 push_sub(target_chi_exclude)
190
191 psi_in => opt_control_point_qs(qcpsi_in)
192 chi_out => opt_control_point_qs(qcchi_out)
193
194 do ib = chi_out%group%block_start, chi_out%group%block_end
195 call psi_in%group%psib(ib, 1)%copy_data_to(gr%np, chi_out%group%psib(ib, 1))
196 end do
197
198 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
199 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
200 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
201
202 call states_elec_get_state(chi_out, gr, 1, 1, zchi)
203
204 do ist = 1, tg%st%nst
205 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
206 call states_elec_get_state(psi_in, gr, ist, 1, zpsi)
207 call states_elec_get_state(tg%st, gr, ist, 1, zst)
208 olap = zmf_dotp(gr, psi_in%d%dim, zst, zpsi)
209 call lalg_axpy(gr%np, tg%st%d%dim, -olap, zst, zchi)
210 end if
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(zst)
217 safe_deallocate_a(zchi)
218
219 nullify(psi_in)
220 nullify(chi_out)
221 pop_sub(target_chi_exclude)
222 end subroutine target_chi_exclude
223
224end module target_exclude_oct_m
225
226!! Local Variables:
227!! mode: f90
228!! coding: utf-8
229!! 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)