Octopus
target_groundstate.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 io_oct_m
28 use ions_oct_m
30 use, intrinsic :: iso_fortran_env
32 use mesh_oct_m
38 use output_oct_m
42 use space_oct_m
45 use target_oct_m
46 use td_oct_m
47
48 implicit none
49
50 private
51 public :: target_ground_state_t
52
54 type, extends(target_t) :: target_ground_state_t
55 contains
56 procedure :: init => target_init_groundstate
57 procedure :: j1 => target_j1_groundstate
58 procedure :: apply_chi => target_chi_groundstate
59 procedure :: output => target_output_groundstate
61
62
63contains
64
65 ! ----------------------------------------------------------------------
67 subroutine target_init_groundstate(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
68 class(target_ground_state_t), intent(inout) :: tg
69 type(grid_t), intent(in) :: gr
70 type(kpoints_t), intent(in) :: kpoints
71 type(namespace_t), intent(in) :: namespace
72 class(space_t), intent(in) :: space
73 type(ions_t), intent(in) :: ions
74 type(opt_control_state_t), intent(inout) :: qcs
75 type(td_t), intent(in) :: td
76 real(real64), intent(in) :: w0
77 type(oct_t), intent(in) :: oct
78 type(epot_t), intent(inout) :: ep
79 type(restart_t), intent(inout) :: restart
80
81 integer :: ierr
82
84
85 message(1) = 'Info: Using Ground State for TargetOperator'
86 call messages_info(1, namespace=namespace)
87
88 call states_elec_load(restart, namespace, space, tg%st, gr, kpoints, fixed_occ=.true., ierr=ierr)
89 if (ierr /= 0) then
90 message(1) = "Unable to read wavefunctions."
91 call messages_fatal(1, namespace=namespace)
92 end if
93
94 tg%move_ions = td%ions_dyn%ions_move()
95 tg%dt = td%dt
96
98 end subroutine target_init_groundstate
99
100
101 ! ----------------------------------------------------------------------
102 subroutine target_output_groundstate(tg, namespace, space, gr, dir, ions, hm, outp)
103 class(target_ground_state_t), intent(inout) :: tg
104 type(namespace_t), intent(in) :: namespace
105 class(space_t), intent(in) :: space
106 type(grid_t), intent(in) :: gr
107 character(len=*), intent(in) :: dir
108 type(ions_t), intent(in) :: ions
109 type(hamiltonian_elec_t), intent(in) :: hm
110 type(output_t), intent(in) :: outp
111
113
114 call io_mkdir(trim(dir), namespace)
115 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
118 end subroutine target_output_groundstate
119 ! ----------------------------------------------------------------------
120
121
122 ! ----------------------------------------------------------------------
124 real(real64) function target_j1_groundstate(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
125 class(target_ground_state_t), intent(inout) :: tg
126 type(namespace_t), intent(in) :: namespace
127 type(grid_t), intent(in) :: gr
128 type(kpoints_t), intent(in) :: kpoints
129 type(opt_control_state_t), intent(inout) :: qcpsi
130 type(ions_t), optional, intent(in) :: ions
131
132 integer :: ist, ik
133 complex(real64), allocatable :: zpsi(:, :), zst(:, :)
134 type(states_elec_t), pointer :: psi
135
136 push_sub(target_j1_groundstate)
137
138 psi => opt_control_point_qs(qcpsi)
139
140 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
141 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
142
143 j1 = m_zero
144
145 do ik = 1, psi%nik
146 do ist = psi%st_start, psi%st_end
147 call states_elec_get_state(psi, gr, ist, ik, zpsi)
148 call states_elec_get_state(tg%st, gr, ist, ik, zst)
150 j1 = j1 + psi%occ(ist, ik)*abs(zmf_dotp(gr, psi%d%dim, zpsi, zst))**2
152 end do
153 end do
155 safe_deallocate_a(zpsi)
156 safe_deallocate_a(zst)
157
158 nullify(psi)
159 pop_sub(target_j1_groundstate)
160 end function target_j1_groundstate
161
163 ! ----------------------------------------------------------------------
165 subroutine target_chi_groundstate(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
166 class(target_ground_state_t), intent(inout) :: tg
167 type(namespace_t), intent(in) :: namespace
168 type(grid_t), intent(in) :: gr
169 type(kpoints_t), intent(in) :: kpoints
170 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
171 type(opt_control_state_t), target, intent(inout) :: qcchi_out
172 type(ions_t), intent(in) :: ions
173
174 integer :: ik, ist
175 complex(real64) :: olap
176 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
177 type(states_elec_t), pointer :: psi_in, chi_out
178
179 push_sub(target_chi_groundstate)
180
181 psi_in => opt_control_point_qs(qcpsi_in)
182 chi_out => opt_control_point_qs(qcchi_out)
183
184 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
185 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
186 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
187
188 do ik = 1, psi_in%nik
189 do ist = psi_in%st_start, psi_in%st_end
190
191 call states_elec_get_state(psi_in, gr, ist, ik, zpsi)
192 call states_elec_get_state(tg%st, gr, ist, ik, zst)
193
194 olap = zmf_dotp(gr, zst(:, 1), zpsi(:, 1))
195 zchi(1:gr%np, 1:tg%st%d%dim) = olap*zst(1:gr%np, 1:tg%st%d%dim)
196
197 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
198
199 end do
200 end do
201
202 safe_deallocate_a(zpsi)
203 safe_deallocate_a(zst)
204 safe_deallocate_a(zchi)
205
206 nullify(psi_in)
207 nullify(chi_out)
209 end subroutine target_chi_groundstate
210
212
213!! Local Variables:
214!! mode: f90
215!! coding: utf-8
216!! End:
real(real64), parameter, public m_zero
Definition: global.F90:200
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
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_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
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
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine target_chi_groundstate(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
subroutine target_init_groundstate(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_output_groundstate(tg, namespace, space, gr, dir, ions, hm, outp)
real(real64) function target_j1_groundstate(tg, namespace, gr, kpoints, qcpsi, ions)
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
Definition: td.F90:116
Target projecting onto the ground state.
Abstract optimal-control target.
Definition: target.F90:172
int true(void)