Octopus
scissor.F90
Go to the documentation of this file.
1!! Copyright (C) 2016 X. Andrade, N. Tancogne-Dejean
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., 59 Temple Place - Suite 330, Boston, MA
16!! 02111-1307, USA.
17
18#include "global.h"
19
20module scissor_oct_m
21 use batch_oct_m
23 use debug_oct_m
24 use global_oct_m
28 use mesh_oct_m
33 use parser_oct_m
34 use phase_oct_m
37 use space_oct_m
43
44 implicit none
45
46 private
47
48 public :: &
49 scissor_t, &
55
56 type scissor_t
57 private
58 logical, public :: apply = .false.
59 real(real64) :: gap
60 type(states_elec_t) :: gs_st
61 end type scissor_t
62
63 interface scissor_commute_r
65 end interface
66
67contains
68
69 subroutine scissor_init(this, namespace, space, st, mesh, kpoints, phase, gap, mc)
70 type(scissor_t), intent(inout) :: this
71 type(namespace_t), intent(in) :: namespace
72 class(space_t), intent(in) :: space
73 type(states_elec_t), intent(in) :: st
74 class(mesh_t), intent(in) :: mesh
75 type(kpoints_t), intent(in) :: kpoints
76 type(phase_t), intent(in) :: phase
77 real(real64), intent(in) :: gap
78 type(multicomm_t), intent(in) :: mc
79
80 type(restart_t) :: restart_gs
81 integer :: ierr
82 integer :: ib, ist, ik
83 complex(real64), allocatable :: temp_state(:,:)
84
85 push_sub(scissor_init)
86
87 assert(.not. this%apply)
88 assert(.not. states_are_real(st))
89
90 call messages_print_with_emphasis(msg="TDScissor", namespace=namespace)
91
92 if (st%parallel_in_states) then
93 call messages_not_implemented("Scissor operator parallel in states", namespace=namespace)
94 end if
95 if (mesh%parallel_in_domains) then
96 call messages_not_implemented("Scissor operator parallel in domains", namespace=namespace)
97 end if
98
99 this%apply = .true.
100 this%gap = gap
101
102 write(message(1),'(a)') 'Start loading GS states.'
103 call messages_info(1, namespace=namespace)
104 !We need to load GS states and to store them in this%gs_st
105 call states_elec_copy(this%gs_st, st)
106
107 call restart_gs%init(namespace, restart_proj, restart_type_load, mc, ierr, mesh=mesh)
108 if (ierr /= 0) then
109 message(1) = "Unable to read states information."
110 call messages_fatal(1, namespace=namespace)
111 end if
112
113 call states_elec_load(restart_gs, namespace, space, this%gs_st, mesh, kpoints, &
114 fixed_occ=.true., ierr=ierr, label = ': gs for TDScissor')
115 if (ierr /= 0 .and. ierr /= (this%gs_st%st_end-this%gs_st%st_start+1)*this%gs_st%nik*this%gs_st%d%dim) then
116 message(1) = "Unable to read wavefunctions for TDScissor."
117 call messages_fatal(1, namespace=namespace)
118 end if
119 call restart_gs%end()
120
121 if (space%is_periodic() .and. .not. (kpoints_number(kpoints) == 1 .and. kpoints_point_is_gamma(kpoints, 1))) then
122
123 write(message(1),'(a)') 'Adding the phase for GS states.'
124 call messages_info(1, namespace=namespace)
125
126 safe_allocate(temp_state(1:mesh%np_part, 1:this%gs_st%d%dim))
127 ! We apply the phase to these states, as we need it for the projectors later
128 do ik=this%gs_st%d%kpt%start, this%gs_st%d%kpt%end
129
130 do ist = this%gs_st%st_start, this%gs_st%st_end
131 call states_elec_get_state(this%gs_st, mesh, ist, ik, temp_state)
132 call phase%apply_to_single(temp_state, mesh%np, this%gs_st%d%dim, ik, .false.)
133 call states_elec_set_state(this%gs_st, mesh, ist, ik,temp_state)
134 end do
135
136 end do
137
138 safe_deallocate_a(temp_state)
139 end if
140
141 ! Keep the memory on CPU to avoid unecessary transfers
142 do ik = this%gs_st%d%kpt%start, this%gs_st%d%kpt%end
143 do ib = this%gs_st%group%block_start, this%gs_st%group%block_end
144 call this%gs_st%group%psib(ib, ik)%do_pack(batch_packed)
145 end do
146 end do
147
148 call messages_print_with_emphasis(namespace=namespace)
149
150 pop_sub(scissor_init)
151 end subroutine scissor_init
152
153 subroutine scissor_end(this)
154 type(scissor_t), intent(inout) :: this
156 push_sub(scissor_end)
157
158 this%apply = .false.
159 call states_elec_end(this%gs_st)
160
161 pop_sub(scissor_end)
162 end subroutine scissor_end
163
164#include "undef.F90"
165#include "real.F90"
166#include "scissor_inc.F90"
167
168#include "undef.F90"
169#include "complex.F90"
170#include "scissor_inc.F90"
171end module scissor_oct_m
172
173!! Local Variables:
174!! mode: f90
175!! coding: utf-8
176!! End:
This module implements batches of mesh functions.
Definition: batch.F90:135
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
Definition: batch.F90:286
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
logical pure function, public kpoints_point_is_gamma(this, ik)
Definition: kpoints.F90:1720
integer pure function, public kpoints_number(this)
Definition: kpoints.F90:1213
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
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 handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
integer, parameter, public restart_proj
Definition: restart.F90:156
integer, parameter, public restart_type_load
Definition: restart.F90:184
subroutine zscissor_commute_r(this, mesh, ik, psi, gpsi)
Definition: scissor.F90:560
subroutine, public zscissor_apply(this, mesh, psib, hpsib)
Definition: scissor.F90:515
subroutine dscissor_commute_r(this, mesh, ik, psi, gpsi)
Definition: scissor.F90:371
subroutine, public dscissor_apply(this, mesh, psib, hpsib)
Definition: scissor.F90:326
subroutine, public scissor_end(this)
Definition: scissor.F90:249
subroutine, public scissor_init(this, namespace, space, st, mesh, kpoints, phase, gap, mc)
Definition: scissor.F90:165
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
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...
int true(void)