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 global_oct_m
24 use grid_oct_m
26 use io_oct_m
27 use ions_oct_m
29 use, intrinsic :: iso_fortran_env
31 use mesh_oct_m
35 use output_oct_m
39 use space_oct_m
43 use td_oct_m
44
45 implicit none
46
47 private
48 public :: &
53
54
55contains
56
57 ! ----------------------------------------------------------------------
59 subroutine target_init_groundstate(mesh, namespace, space, tg, td, restart, kpoints)
60 class(mesh_t), intent(in) :: mesh
61 type(namespace_t), intent(in) :: namespace
62 class(space_t), intent(in) :: space
63 type(target_t), intent(inout) :: tg
64 type(td_t), intent(in) :: td
65 type(restart_t), intent(in) :: restart
66 type(kpoints_t), intent(in) :: kpoints
67
68 integer :: ierr
69
71
72 message(1) = 'Info: Using Ground State for TargetOperator'
73 call messages_info(1, namespace=namespace)
74
75 call states_elec_load(restart, namespace, space, tg%st, mesh, kpoints, ierr)
76 if (ierr /= 0) then
77 message(1) = "Unable to read wavefunctions."
78 call messages_fatal(1, namespace=namespace)
79 end if
80
81 tg%move_ions = ion_dynamics_ions_move(td%ions_dyn)
82 tg%dt = td%dt
83
85 end subroutine target_init_groundstate
86
87
88 ! ----------------------------------------------------------------------
89 subroutine target_output_groundstate(tg, namespace, space, gr, dir, ions, hm, outp)
90 type(target_t), intent(in) :: tg
91 type(namespace_t), intent(in) :: namespace
92 class(space_t), intent(in) :: space
93 type(grid_t), intent(in) :: gr
94 character(len=*), intent(in) :: dir
95 type(ions_t), intent(in) :: ions
96 type(hamiltonian_elec_t), intent(in) :: hm
97 type(output_t), intent(in) :: outp
98
100
101 call io_mkdir(trim(dir), namespace)
102 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
103
105 end subroutine target_output_groundstate
106 ! ----------------------------------------------------------------------
107
108
109 ! ----------------------------------------------------------------------
111 real(real64) function target_j1_groundstate(tg, gr, psi) result(j1)
112 type(target_t), intent(in) :: tg
113 type(grid_t), intent(in) :: gr
114 type(states_elec_t), intent(in) :: psi
115
116 integer :: ist, ik
117 complex(real64), allocatable :: zpsi(:, :), zst(:, :)
118
119 push_sub(target_j1_groundstate)
120
121 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
122 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
123
124 j1 = m_zero
125
126 do ik = 1, psi%nik
127 do ist = psi%st_start, psi%st_end
128 call states_elec_get_state(psi, gr, ist, ik, zpsi)
129 call states_elec_get_state(tg%st, gr, ist, ik, zst)
130
131 j1 = j1 + psi%occ(ist, ik)*abs(zmf_dotp(gr, psi%d%dim, zpsi, zst))**2
132
133 end do
134 end do
135
136 safe_deallocate_a(zpsi)
137 safe_deallocate_a(zst)
138
139 pop_sub(target_j1_groundstate)
140 end function target_j1_groundstate
141
142
143 ! ----------------------------------------------------------------------
145 subroutine target_chi_groundstate(tg, gr, psi_in, chi_out)
146 type(target_t), intent(in) :: tg
147 type(grid_t), intent(in) :: gr
148 type(states_elec_t), intent(in) :: psi_in
149 type(states_elec_t), intent(inout) :: chi_out
150
151 integer :: ik, ist
152 complex(real64) :: olap
153 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
154
155 push_sub(target_chi_groundstate)
156
157 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
158 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
159 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
160
161 do ik = 1, psi_in%nik
162 do ist = psi_in%st_start, psi_in%st_end
163
164 call states_elec_get_state(psi_in, gr, ist, ik, zpsi)
165 call states_elec_get_state(tg%st, gr, ist, ik, zst)
166
167 olap = zmf_dotp(gr, zst(:, 1), zpsi(:, 1))
168 zchi(1:gr%np, 1:tg%st%d%dim) = olap*zst(1:gr%np, 1:tg%st%d%dim)
169
170 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
171
172 end do
173 end do
174
175 safe_deallocate_a(zpsi)
176 safe_deallocate_a(zst)
177 safe_deallocate_a(zchi)
178
180 end subroutine target_chi_groundstate
181
183
184!! Local Variables:
185!! mode: f90
186!! coding: utf-8
187!! End:
real(real64), parameter, public m_zero
Definition: global.F90:188
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 pure function, public ion_dynamics_ions_move(this)
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_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:414
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
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, 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, public target_output_groundstate(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine, public target_init_groundstate(mesh, namespace, space, tg, td, restart, kpoints)
subroutine, public target_chi_groundstate(tg, gr, psi_in, chi_out)
real(real64) function, public target_j1_groundstate(tg, gr, psi)
Definition: td.F90:114