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 global_oct_m
25 use grid_oct_m
27 use io_oct_m
28 use ions_oct_m
30 use, intrinsic :: iso_fortran_env
32 use loct_oct_m
33 use mesh_oct_m
37 use output_oct_m
39 use parser_oct_m
42 use space_oct_m
46 use td_oct_m
47
48 implicit none
49
50 private
51 public :: &
57
58
59contains
60
61 ! ----------------------------------------------------------------------
63 subroutine target_init_exclude(mesh, namespace, space, tg, td, restart, kpoints)
64 class(mesh_t), intent(in) :: mesh
65 type(namespace_t), intent(in) :: namespace
66 class(space_t), intent(in) :: space
67 type(target_t), intent(inout) :: tg
68 type(td_t), intent(in) :: td
69 type(restart_t), intent(inout) :: restart
70 type(kpoints_t), intent(in) :: kpoints
71
72 push_sub(target_init_exclude)
73
74 tg%move_ions = td%ions_dyn%ions_move()
75 tg%dt = td%dt
76
77 message(1) = 'Info: The target functional is the exclusion of a number of states defined by'
78 message(2) = ' "OCTExcludedStates".'
79 call messages_info(2, namespace=namespace)
80 !%Variable OCTExcludedStates
81 !%Type string
82 !%Section Calculation Modes::Optimal Control
83 !%Description
84 !% If the target is the exclusion of several targets, ("OCTTargetOperator = oct_exclude_states")
85 !% then you must declare which states are to be excluded, by setting the OCTExcludedStates variable.
86 !% It must be a string in "list" format: "1-8", or "2,3,4-9", for example. Be careful to include
87 !% in this list only states that have been calculated in a previous "gs" or "unocc" calculation,
88 !% or otherwise the error will be silently ignored.
89 !%End
90 call parse_variable(namespace, 'OCTExcludedStates', '1', tg%excluded_states_list)
92
93 call states_elec_look_and_load(restart, namespace, space, tg%st, mesh, kpoints)
94
95 pop_sub(target_init_exclude)
96 end subroutine target_init_exclude
97
98
99 ! ----------------------------------------------------------------------
101 subroutine target_end_exclude()
102 push_sub(target_end_exclude)
103
104 pop_sub(target_end_exclude)
105 end subroutine target_end_exclude
106
107
108 ! ----------------------------------------------------------------------
109 subroutine target_output_exclude(tg, namespace, space, gr, dir, ions, hm, outp)
110 type(target_t), intent(in) :: tg
111 type(namespace_t), intent(in) :: namespace
112 class(space_t), intent(in) :: space
113 type(grid_t), intent(in) :: gr
114 character(len=*), intent(in) :: dir
115 type(ions_t), intent(in) :: ions
116 type(hamiltonian_elec_t), intent(in) :: hm
117 type(output_t), intent(in) :: outp
118
119 push_sub(target_output_exclude)
120
121 call io_mkdir(trim(dir), namespace)
122 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
123
124 pop_sub(target_output_exclude)
125 end subroutine target_output_exclude
126 ! ----------------------------------------------------------------------
127
128
129 ! ----------------------------------------------------------------------
131 real(real64) function target_j1_exclude(gr, tg, psi) result(j1)
132 type(grid_t), intent(in) :: gr
133 type(target_t), intent(in) :: tg
134 type(states_elec_t), intent(in) :: psi
135
136 integer :: ist
137 complex(real64), allocatable :: zpsi1(:, :), zpsi(:, :)
138
139 push_sub(target_j1_exclude)
140
141 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
142 safe_allocate(zpsi1(1:gr%np, 1:tg%st%d%dim))
143
144 call states_elec_get_state(psi, gr, 1, 1, zpsi1)
145
146 j1 = m_one
147 do ist = 1, tg%st%nst
148 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
149 call states_elec_get_state(tg%st, gr, ist, 1, zpsi)
150 j1 = j1 - abs(zmf_dotp(gr, psi%d%dim, zpsi, zpsi1))**2
151 end if
152 end do
153
154 safe_deallocate_a(zpsi)
155 safe_deallocate_a(zpsi1)
157 pop_sub(target_j1_exclude)
158 end function target_j1_exclude
159
160
161 ! ----------------------------------------------------------------------
163 subroutine target_chi_exclude(tg, gr, psi_in, chi_out)
164 type(target_t), intent(in) :: tg
165 type(grid_t), intent(in) :: gr
166 type(states_elec_t), intent(in) :: psi_in
167 type(states_elec_t), intent(inout) :: chi_out
168
169 integer :: ist, ib
170 complex(real64) :: olap
171 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
172 push_sub(target_chi_exclude)
173
174 do ib = chi_out%group%block_start, chi_out%group%block_end
175 call psi_in%group%psib(ib, 1)%copy_data_to(gr%np, chi_out%group%psib(ib, 1))
176 end do
177
178 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
179 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
180 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
181
182 call states_elec_get_state(chi_out, gr, 1, 1, zchi)
183
184 do ist = 1, tg%st%nst
185 if (loct_isinstringlist(ist, tg%excluded_states_list)) then
186 call states_elec_get_state(psi_in, gr, ist, 1, zpsi)
187 call states_elec_get_state(tg%st, gr, ist, 1, zst)
188 olap = zmf_dotp(gr, psi_in%d%dim, zst, zpsi)
189 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)
190 end if
191 end do
192
193 call states_elec_set_state(chi_out, gr, 1, 1, zchi)
195 safe_deallocate_a(zpsi)
196 safe_deallocate_a(zst)
197 safe_deallocate_a(zchi)
198
199 pop_sub(target_chi_exclude)
200 end subroutine target_chi_exclude
201
203
204!! Local Variables:
205!! mode: f90
206!! coding: utf-8
207!! End:
real(real64), parameter, public m_one
Definition: global.F90:189
This module implements the underlying real-space grid.
Definition: grid.F90:117
Definition: io.F90:114
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:311
logical function, public loct_isinstringlist(a, s)
Definition: loct.F90:316
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:616
this module contains the low-level part of the output system
Definition: output_low.F90:115
this module contains the output system
Definition: output.F90:115
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1888
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, is_complex, packed)
subroutine, public target_init_exclude(mesh, namespace, space, tg, td, restart, kpoints)
subroutine, public target_end_exclude()
real(real64) function, public target_j1_exclude(gr, tg, psi)
subroutine, public target_chi_exclude(tg, gr, psi_in, chi_out)
subroutine, public target_output_exclude(tg, namespace, space, gr, dir, ions, hm, outp)
Definition: td.F90:114