Octopus
perturbation_ionic.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
25 use comm_oct_m
26 use debug_oct_m
28 use epot_oct_m
29 use global_oct_m
30 use grid_oct_m
33 use ions_oct_m
35 use math_oct_m
36 use mesh_oct_m
40 use mpi_oct_m
45 use space_oct_m
51
52 implicit none
53
54 private
55 public :: &
59
60 type, extends(perturbation_t) :: perturbation_ionic_t
61 private
62
63 type(ions_t), pointer :: ions => null()
64
69 logical :: pure_dir
70 integer :: atom1, atom2
71 real(real64), allocatable :: mix1(:,:)
72 real(real64), allocatable :: mix2(:,:)
73
74 contains
75 procedure :: copy_to => perturbation_ionic_copy
76 generic :: assignment(=) => copy_to
77 procedure :: info => perturbation_ionic_info
78 procedure :: dapply => dperturbation_ionic_apply
79 procedure :: zapply => zperturbation_ionic_apply
80 procedure :: dapply_order_2 => dperturbation_ionic_apply_order_2
81 procedure :: zapply_order_2 => zperturbation_ionic_apply_order_2
82 procedure :: setup_dir => perturbation_ionic_setup_dir
83 procedure :: setup_atom => perturbation_ionic_setup_atom
84 procedure :: setup_mix_dir => perturbation_ionic_setup_mixed_dir
87
88 interface perturbation_ionic_t
89 procedure perturbation_ionic_constructor
90 end interface perturbation_ionic_t
91
92contains
93
94 ! ---------------------------------------------------------
99 function perturbation_ionic_constructor(namespace, ions) result(pert)
100 class(perturbation_ionic_t), pointer :: pert
101 type(namespace_t), intent(in) :: namespace
102 type(ions_t), target, intent(in) :: ions
103
105
106 safe_allocate(pert)
107
108 call perturbation_ionic_init(pert, namespace, ions)
109
112
113
114 ! --------------------------------------------------------------------
115 subroutine perturbation_ionic_init(this, namespace, ions)
116 type(perturbation_ionic_t), intent(out) :: this
117 type(namespace_t), intent(in) :: namespace
118 type(ions_t), target, intent(in) :: ions
119
121
122 this%dir = -1
123 this%dir2 = -1
124 this%atom1 = -1
125 this%atom2 = -1
126
127 this%ions => ions
128
129 this%pure_dir = .false.
130
131 safe_allocate(this%mix1(1:ions%natoms, 1:ions%space%dim))
132 safe_allocate(this%mix2(1:ions%natoms, 1:ions%space%dim))
133
135 end subroutine perturbation_ionic_init
136
137 ! --------------------------------------------------------------------
138 subroutine perturbation_ionic_copy(this, source)
139 class(perturbation_ionic_t), intent(out) :: this
140 class(perturbation_ionic_t), intent(in) :: source
141
143
144 call perturbation_copy(this, source)
145 this%atom1 = source%atom1
146 this%atom2 = source%atom2
147 this%ions => source%ions
148
149 this%pure_dir = source%pure_dir
150
151 safe_allocate(this%mix1(1:source%ions%natoms, 1:source%ions%space%dim))
152 safe_allocate(this%mix2(1:source%ions%natoms, 1:source%ions%space%dim))
153 this%mix1 = source%mix1
154 this%mix2 = source%mix2
155
157 end subroutine perturbation_ionic_copy
158
159
160 ! --------------------------------------------------------------------
161 subroutine perturbation_ionic_finalize(this)
162 type(perturbation_ionic_t), intent(inout) :: this
166 safe_deallocate_a(this%mix1)
167 safe_deallocate_a(this%mix2)
172 ! --------------------------------------------------------------------
173 subroutine perturbation_ionic_info(this)
174 class(perturbation_ionic_t), intent(in) :: this
179 end subroutine perturbation_ionic_info
180
181 ! --------------------------------------------------------------------
182 subroutine perturbation_ionic_setup_dir(this, dir, dir2)
183 class(perturbation_ionic_t), intent(inout) :: this
184 integer, intent(in) :: dir
185 integer, optional, intent(in) :: dir2
186
188
189 this%dir = dir
190 if (present(dir2)) this%dir2 = dir2
191
192 this%pure_dir = .true.
193
194 this%mix1 = m_zero
195 this%mix2 = m_zero
196
197 if (this%dir > 0 .and. this%atom1 > 0) this%mix1(this%atom1, this%dir ) = m_one
198 if (this%dir2 > 0 .and. this%atom2 > 0) this%mix2(this%atom2, this%dir2) = m_one
199
201 end subroutine perturbation_ionic_setup_dir
202
203 ! --------------------------------------------------------------------
204 subroutine perturbation_ionic_setup_atom(this, iatom, iatom2)
205 class(perturbation_ionic_t), intent(inout) :: this
206 integer, intent(in) :: iatom
207 integer, optional, intent(in) :: iatom2
210
211 this%atom1 = iatom
212 if (present(iatom2)) this%atom2 = iatom2
213
214 this%pure_dir = .true.
215
216 this%mix1 = m_zero
217 this%mix2 = m_zero
218
219 if (this%dir > 0 .and. this%atom1 > 0) this%mix1(this%atom1, this%dir ) = m_one
220 if (this%dir2 > 0 .and. this%atom2 > 0) this%mix2(this%atom2, this%dir2) = m_one
221
223 end subroutine perturbation_ionic_setup_atom
224
225 ! --------------------------------------------------------------------
226 subroutine perturbation_ionic_setup_mixed_dir(this, iatom, idir, val, jatom, jdir, valuej)
227 class(perturbation_ionic_t), intent(inout) :: this
228 integer, intent(in) :: iatom
229 integer, intent(in) :: idir
230 real(real64), intent(in) :: val
231 integer, optional, intent(in) :: jatom
232 integer, optional, intent(in) :: jdir
233 real(real64), optional, intent(in) :: valuej
234
235 logical :: have_dir_2
236
238
239 this%pure_dir = .false.
240
241 this%mix1(iatom, idir) = val
242
243 have_dir_2 = present(jatom) .and. present(jdir) .and. present(jatom)
244
245 if (have_dir_2) then
246 this%mix1(jatom, jdir) = valuej
247 else
248 assert(.not. present(jatom) .and. .not. present(jdir) .and. .not. present(jatom))
249 end if
250
253
255
256#include "undef.F90"
257#include "real.F90"
258#include "perturbation_ionic_inc.F90"
259
260#include "undef.F90"
261#include "complex.F90"
262#include "perturbation_ionic_inc.F90"
263
265
266!! Local Variables:
267!! mode: f90
268!! coding: utf-8
269!! End:
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:116
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:122
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64), parameter, public m_zero
Definition: global.F90:187
real(real64), parameter, public m_one
Definition: global.F90:188
This module implements the underlying real-space grid.
Definition: grid.F90:117
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:116
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine perturbation_ionic_setup_mixed_dir(this, iatom, idir, val, jatom, jdir, valuej)
subroutine, public zionic_pert_matrix_elements_2(gr, namespace, space, ions, hm, ik, st, vib, matrix)
Computes the second order term.
subroutine perturbation_ionic_setup_atom(this, iatom, iatom2)
subroutine perturbation_ionic_init(this, namespace, ions)
subroutine perturbation_ionic_copy(this, source)
subroutine dperturbation_ionic_apply(this, namespace, space, gr, hm, ik, f_in, f_out, set_bc)
Returns f_out = H' f_in, where H' is perturbation Hamiltonian Note that e^ikr phase is applied to f_i...
subroutine, public dionic_pert_matrix_elements_2(gr, namespace, space, ions, hm, ik, st, vib, matrix)
Computes the second order term.
subroutine perturbation_ionic_info(this)
subroutine zperturbation_ionic_apply_order_2(this, namespace, space, gr, hm, ik, f_in, f_out)
subroutine zperturbation_ionic_apply(this, namespace, space, gr, hm, ik, f_in, f_out, set_bc)
Returns f_out = H' f_in, where H' is perturbation Hamiltonian Note that e^ikr phase is applied to f_i...
subroutine perturbation_ionic_finalize(this)
subroutine perturbation_ionic_setup_dir(this, dir, dir2)
class(perturbation_ionic_t) function, pointer perturbation_ionic_constructor(namespace, ions)
The factory routine (or constructor) allocates a pointer of the corresponding type and then calls the...
subroutine dperturbation_ionic_apply_order_2(this, namespace, space, gr, hm, ik, f_in, f_out)
subroutine, public perturbation_copy(this, source)
This module handles spin dimensions of the states and the k-point distribution.
int true(void)