Octopus
perturbation.F90
Go to the documentation of this file.
1!! Copyright (C) 2007 X. Andrade
2!! Copyright (C) 2021 N. Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
23 use batch_oct_m
26 use comm_oct_m
27 use debug_oct_m
29 use epot_oct_m
30 use global_oct_m
31 use grid_oct_m
33 use mpi_oct_m
34 use mesh_oct_m
39 use parser_oct_m
41 use space_oct_m
44 use types_oct_m
46
47 implicit none
48
49 private
50 public :: &
53
54 type, abstract :: perturbation_t
55 integer :: dir
56 integer :: dir2
57 contains
58 procedure :: setup_dir => perturbation_setup_dir
59 procedure :: apply_batch => perturbation_apply_batch
60 procedure :: dexpectation_value => dperturbation_expectation_value
61 procedure :: zexpectation_value => zperturbation_expectation_value
62 procedure :: dstates_elec_expectation_value => dperturbation_states_elec_expectation_value
63 procedure :: zstates_elec_expectation_value => zperturbation_states_elec_expectation_value
64 procedure :: dexpectation_density => dperturbation_expectation_density
65 procedure :: zexpectation_density => zperturbation_expectation_density
66 procedure(perturbation_info), deferred :: info
67 procedure(dperturbation_apply), deferred :: dapply
68 procedure(zperturbation_apply), deferred :: zapply
69 procedure(dperturbation_apply_order_2), deferred :: dapply_order_2
70 procedure(zperturbation_apply_order_2), deferred :: zapply_order_2
71 end type perturbation_t
72
73 abstract interface
74 ! ---------------------------------------------------------
75 subroutine dperturbation_apply(this, namespace, space, gr, hm, ik, f_in, f_out, set_bc)
76 import perturbation_t
77 import namespace_t
78 import space_t
79 import grid_t
81 import real64
82 class(perturbation_t), intent(in) :: this
83 type(namespace_t), intent(in) :: namespace
84 class(space_t), intent(in) :: space
85 type(grid_t), intent(in) :: gr
86 type(hamiltonian_elec_t), intent(in) :: hm
87 integer, intent(in) :: ik
88 real(real64), contiguous, intent(in) :: f_in(:, :)
89 real(real64), contiguous, intent(out) :: f_out(:, :)
90 logical, optional, intent(in) :: set_bc
91 end subroutine dperturbation_apply
92
93 ! ---------------------------------------------------------
94 subroutine zperturbation_apply(this, namespace, space, gr, hm, ik, f_in, f_out, set_bc)
95 import perturbation_t
96 import namespace_t
97 import space_t
98 import grid_t
100 import real64
101 class(perturbation_t), intent(in) :: this
102 type(namespace_t), intent(in) :: namespace
103 class(space_t), intent(in) :: space
104 type(grid_t), intent(in) :: gr
105 type(hamiltonian_elec_t), intent(in) :: hm
106 integer, intent(in) :: ik
107 complex(real64), contiguous, intent(in) :: f_in(:, :)
108 complex(real64), contiguous, intent(out) :: f_out(:, :)
109 logical, optional, intent(in) :: set_bc
110 end subroutine zperturbation_apply
111
112 ! ---------------------------------------------------------
113 subroutine dperturbation_apply_order_2(this, namespace, space, gr, hm, ik, f_in, f_out)
114 import perturbation_t
115 import namespace_t
116 import space_t
117 import grid_t
118 import hamiltonian_elec_t
119 import real64
120 class(perturbation_t), intent(in) :: this
121 type(namespace_t), intent(in) :: namespace
122 class(space_t), intent(in) :: space
123 type(grid_t), intent(in) :: gr
124 type(hamiltonian_elec_t), intent(in) :: hm
125 integer, intent(in) :: ik
126 real(real64), contiguous, intent(in) :: f_in(:, :)
127 real(real64), contiguous, intent(out) :: f_out(:, :)
128 end subroutine dperturbation_apply_order_2
129
130 ! ---------------------------------------------------------
131 subroutine zperturbation_apply_order_2(this, namespace, space, gr, hm, ik, f_in, f_out)
132 import perturbation_t
133 import namespace_t
134 import space_t
135 import grid_t
136 import hamiltonian_elec_t
137 import real64
138 class(perturbation_t), intent(in) :: this
139 type(namespace_t), intent(in) :: namespace
140 class(space_t), intent(in) :: space
141 type(grid_t), intent(in) :: gr
142 type(hamiltonian_elec_t), intent(in) :: hm
143 integer, intent(in) :: ik
144 complex(real64), contiguous, intent(in) :: f_in(:, :)
145 complex(real64), contiguous, intent(out) :: f_out(:, :)
146 end subroutine zperturbation_apply_order_2
147
148
149 ! ---------------------------------------------------------
150 subroutine perturbation_info(this)
152 class(perturbation_t), intent(in) :: this
153 end subroutine perturbation_info
154 end interface
156contains
158 ! --------------------------------------------------------------------
159 subroutine perturbation_copy(this, source)
160 class(perturbation_t), intent(out) :: this
161 class(perturbation_t), intent(in) :: source
165 this%dir = source%dir
166 this%dir2 = source%dir2
167
168 pop_sub(perturbation_copy)
169 end subroutine perturbation_copy
171 ! --------------------------------------------------------------------
172 subroutine perturbation_setup_dir(this, dir, dir2)
173 class(perturbation_t), intent(inout) :: this
174 integer, intent(in) :: dir
175 integer, optional, intent(in) :: dir2
176
177 push_sub(perturbation_setup_dir)
178
179 this%dir = dir
180 if (present(dir2)) then
181 this%dir2 = dir2
182 else
183 this%dir2 = -1
184 end if
185
187 end subroutine perturbation_setup_dir
188
189 ! --------------------------------------------------------------------------
190 subroutine perturbation_apply_batch(this, namespace, space, gr, hm, f_in, f_out)
191 class(perturbation_t), intent(in) :: this
192 type(namespace_t), intent(in) :: namespace
193 class(space_t), intent(in) :: space
194 type(grid_t), intent(in) :: gr
195 type(hamiltonian_elec_t), intent(in) :: hm
196 type(wfs_elec_t), intent(in) :: f_in
197 type(wfs_elec_t), intent(inout) :: f_out
198
199 integer :: ist
200 real(real64), allocatable :: dfi(:, :), dfo(:, :)
201 complex(real64), allocatable :: zfi(:, :), zfo(:, :)
202
204
205 assert(f_in%status() == f_out%status())
206
207 if (f_in%type() == type_float) then
208 safe_allocate(dfi(1:gr%np, 1:hm%d%dim))
209 safe_allocate(dfo(1:gr%np, 1:hm%d%dim))
210
211 do ist = 1, f_in%nst
212 call batch_get_state(f_in, ist, gr%np, dfi)
213 call this%dapply(namespace, space, gr, hm, f_in%ik, dfi, dfo)
214 call batch_set_state(f_out, ist, gr%np, dfo)
215 end do
216
217 safe_deallocate_a(dfi)
218 safe_deallocate_a(dfo)
219
220 else
221
222 safe_allocate(zfi(1:gr%np, 1:hm%d%dim))
223 safe_allocate(zfo(1:gr%np, 1:hm%d%dim))
224
225 do ist = 1, f_in%nst
226 call batch_get_state(f_in, ist, gr%np, zfi)
227 call this%zapply(namespace, space, gr, hm, f_in%ik, zfi, zfo)
228 call batch_set_state(f_out, ist, gr%np, zfo)
229 end do
230
231 safe_deallocate_a(zfi)
232 safe_deallocate_a(zfo)
233
234 end if
235
237 end subroutine perturbation_apply_batch
238
239
240#include "undef.F90"
241#include "real.F90"
242#include "perturbation_inc.F90"
243
244#include "undef.F90"
245#include "complex.F90"
246#include "perturbation_inc.F90"
247
248end module perturbation_oct_m
249
250!! Local Variables:
251!! mode: f90
252!! coding: utf-8
253!! End:
There are several ways how to call batch_set_state and batch_get_state:
Definition: batch_ops.F90:218
This module implements batches of mesh functions.
Definition: batch.F90:135
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:124
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
This module implements the underlying real-space grid.
Definition: grid.F90:119
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
real(real64) function dperturbation_expectation_value(this, namespace, space, gr, hm, st, psia, psib, perturbation_order)
subroutine zperturbation_expectation_density(this, namespace, space, gr, hm, st, psia, psib, density, perturbation_order)
This routine includes occupations for psib if perturbation_order == 2, correct if used as ....
subroutine perturbation_apply_batch(this, namespace, space, gr, hm, f_in, f_out)
complex(real64) function zperturbation_states_elec_expectation_value(this, namespace, space, gr, hm, st, perturbation_order)
subroutine, public perturbation_copy(this, source)
complex(real64) function zperturbation_expectation_value(this, namespace, space, gr, hm, st, psia, psib, perturbation_order)
subroutine perturbation_setup_dir(this, dir, dir2)
real(real64) function dperturbation_states_elec_expectation_value(this, namespace, space, gr, hm, st, perturbation_order)
subroutine dperturbation_expectation_density(this, namespace, space, gr, hm, st, psia, psib, density, perturbation_order)
This routine includes occupations for psib if perturbation_order == 2, correct if used as ....
This module handles spin dimensions of the states and the k-point distribution.
type(type_t), parameter, public type_float
Definition: types.F90:135
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
batches of electronic states
Definition: wfs_elec.F90:141