Octopus
atom.F90
Go to the documentation of this file.
1#include "global.h"
2
3module atom_oct_m
10 use unit_oct_m
11
12 implicit none
13
14 private
15 public :: &
16 atom_init, &
22
23 type, public :: atom_t
24 !private
25 character(len=LABEL_LEN) :: label = ""
26 class(species_t), pointer :: species => null()
27 integer, allocatable :: c(:)
28
29 !Components of the force
30 real(real64), allocatable :: f_ii(:)
31 real(real64), allocatable :: f_vdw(:)
32 real(real64), allocatable :: f_loc(:)
33 real(real64), allocatable :: f_nl(:)
34 real(real64), allocatable :: f_fields(:)
35 real(real64), allocatable :: f_u(:)
36 real(real64), allocatable :: f_scf(:)
37 real(real64), allocatable :: f_nlcc(:)
38 real(real64), allocatable :: f_photons(:)
39 contains
40 procedure :: copy => atom_copy
41 generic :: assignment(=) => copy
42 procedure :: get_label => atom_get_label
43 final :: atom_finalize
44 end type atom_t
45
46 interface atom_same_species
47 module procedure atom_same_species_aa
48 module procedure atom_same_species_as
49 end interface atom_same_species
50
51contains
52
53 ! ---------------------------------------------------------
54 subroutine atom_init(this, dim, label, species)
55 type(atom_t), intent(out) :: this
56 integer, intent(in) :: dim
57 character(len=*), intent(in) :: label
58 class(species_t), target, optional, intent(in) :: species
59
60 push_sub(atom_init)
61
62 this%label = trim(adjustl(label))
63 this%species => null()
64 if (present(species)) this%species => species
65
66 safe_allocate(this%c(1:dim))
67 this%c = 0
68
69 safe_allocate(this%f_ii(1:dim))
70 safe_allocate(this%f_vdw(1:dim))
71 safe_allocate(this%f_loc(1:dim))
72 safe_allocate(this%f_nl(1:dim))
73 safe_allocate(this%f_fields(1:dim))
74 safe_allocate(this%f_u(1:dim))
75 safe_allocate(this%f_scf(1:dim))
76 safe_allocate(this%f_nlcc(1:dim))
77 safe_allocate(this%f_photons(1:dim))
78 this%f_ii = m_zero
79 this%f_vdw = m_zero
80 this%f_loc = m_zero
81 this%f_nl = m_zero
82 this%f_fields = m_zero
83 this%f_u = m_zero
84 this%f_scf = m_zero
85 this%f_nlcc = m_zero
86 this%f_photons = m_zero
87
88 pop_sub(atom_init)
89 end subroutine atom_init
90
91 ! ---------------------------------------------------------
92 subroutine atom_copy(atom_out, atom_in)
93 class(atom_t), intent(out) :: atom_out
94 class(atom_t), intent(in) :: atom_in
95
96 push_sub(atom_copy)
97
98 atom_out%label = atom_in%label
99 atom_out%species => atom_in%species
100
101 safe_allocate_source_a(atom_out%c, atom_in%c)
102 safe_allocate_source_a(atom_out%f_ii, atom_in%f_ii)
103 safe_allocate_source_a(atom_out%f_vdw, atom_in%f_vdw)
104 safe_allocate_source_a(atom_out%f_loc, atom_in%f_loc)
105 safe_allocate_source_a(atom_out%f_nl, atom_in%f_nl)
106 safe_allocate_source_a(atom_out%f_fields, atom_in%f_fields)
107 safe_allocate_source_a(atom_out%f_u, atom_in%f_u)
108 safe_allocate_source_a(atom_out%f_scf, atom_in%f_scf)
109 safe_allocate_source_a(atom_out%f_nlcc, atom_in%f_nlcc)
110 safe_allocate_source_a(atom_out%f_photons, atom_in%f_photons)
111
112 pop_sub(atom_copy)
113 end subroutine atom_copy
114
115 ! ---------------------------------------------------------
116 impure elemental subroutine atom_finalize(this)
117 type(atom_t), intent(inout) :: this
119 push_sub(atom_finalize)
121 this%label = ""
122 this%species => null()
123
124 safe_deallocate_a(this%c)
126 safe_deallocate_a(this%f_ii)
127 safe_deallocate_a(this%f_vdw)
128 safe_deallocate_a(this%f_loc)
129 safe_deallocate_a(this%f_nl)
130 safe_deallocate_a(this%f_fields)
131 safe_deallocate_a(this%f_u)
132 safe_deallocate_a(this%f_scf)
133 safe_deallocate_a(this%f_nlcc)
134 safe_deallocate_a(this%f_photons)
137 end subroutine atom_finalize
139 ! ---------------------------------------------------------
140
142 pure function atom_get_label(this) result(label)
143 class(atom_t), intent(in) :: this
144
145 character(len=len_trim(adjustl(this%label))) :: label
146
147 label=trim(adjustl(this%label))
148
149 end function atom_get_label
150
151 ! ---------------------------------------------------------
152 subroutine atom_set_species(this, species)
153 type(atom_t), intent(inout) :: this
154 class(species_t), target, intent(in) :: species
155
156 push_sub(atom_set_species)
157
158 this%species => species
159 pop_sub(atom_set_species)
160
161 end subroutine atom_set_species
162
163 ! ---------------------------------------------------------
164 subroutine atom_get_species(this, species)
165 type(atom_t), target, intent(in) :: this
166 class(species_t), pointer, intent(out) :: species
167
168 ! NO PUSH_SUB, called too often
169
170 species => null()
171 if (associated(this%species)) species => this%species
172
173 end subroutine atom_get_species
174
175 ! ---------------------------------------------------------
176 elemental function atom_same_species_aa(this, that) result(is)
177 type(atom_t), intent(in) :: this
178 type(atom_t), intent(in) :: that
179
180 logical :: is
181
182 is = this%label == that%label
183
184 end function atom_same_species_aa
185
186 ! ---------------------------------------------------------
187 elemental function atom_same_species_as(this, species) result(is)
188 type(atom_t), intent(in) :: this
189 class(species_t), intent(in) :: species
190
191 logical :: is
192
193 is = this%label == species%get_label()
194
195 end function atom_same_species_as
196
198 pure logical function all_species_are_jellium_slab(atom)
199 type(atom_t), intent(in) :: atom(:)
200
201 integer :: i
202
204 do i = 1, size(atom)
205 select type(spec => atom(i)%species)
206 type is(jellium_slab_t)
207 class default
209 end select
210 enddo
213
215 pure logical function any_species_is_jellium_sphere(atom)
216 type(atom_t), intent(in) :: atom(:)
217
218 integer :: i
219
221 do i = 1, size(atom)
222 select type(spec => atom(i)%species)
223 type is(jellium_sphere_t)
225 end select
226 enddo
227
229
230end module atom_oct_m
231
232!! Local Variables:
233!! mode: f90
234!! coding: utf-8
235!! End:
subroutine atom_copy(atom_out, atom_in)
Definition: atom.F90:188
pure character(len=len_trim(adjustl(this%label))) function atom_get_label(this)
Getter for label attribute.
Definition: atom.F90:238
pure logical function, public all_species_are_jellium_slab(atom)
Check if all species are jellium slab.
Definition: atom.F90:294
elemental logical function atom_same_species_aa(this, that)
Definition: atom.F90:272
impure elemental subroutine atom_finalize(this)
Definition: atom.F90:212
pure logical function, public any_species_is_jellium_sphere(atom)
Check if any species is a jellium sphere.
Definition: atom.F90:311
elemental logical function atom_same_species_as(this, species)
Definition: atom.F90:283
subroutine, public atom_init(this, dim, label, species)
Definition: atom.F90:150
subroutine, public atom_get_species(this, species)
Definition: atom.F90:260
subroutine, public atom_set_species(this, species)
Definition: atom.F90:248
real(real64), parameter, public m_zero
Definition: global.F90:200
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
Definition: species.F90:147
int true(void)