Octopus
atom.F90
Go to the documentation of this file.
1#include "global.h"
2
3module atom_oct_m
10 use unit_oct_m
12
13 implicit none
14
15 private
16 public :: &
17 atom_init, &
24
25 type, public :: atom_t
26 !private
27 character(len=LABEL_LEN) :: label = ""
28 class(species_t), pointer :: species => null()
29 integer, allocatable :: c(:)
30
31 !Components of the force
32 real(real64), allocatable :: f_ii(:)
33 real(real64), allocatable :: f_vdw(:)
34 real(real64), allocatable :: f_loc(:)
35 real(real64), allocatable :: f_nl(:)
36 real(real64), allocatable :: f_fields(:)
37 real(real64), allocatable :: f_u(:)
38 real(real64), allocatable :: f_scf(:)
39 real(real64), allocatable :: f_nlcc(:)
40 real(real64), allocatable :: f_photons(:)
41 contains
42 procedure :: copy => atom_copy
43 generic :: assignment(=) => copy
44 final :: atom_finalize
45 end type atom_t
46
47 interface atom_same_species
48 module procedure atom_same_species_aa
49 module procedure atom_same_species_as
50 end interface atom_same_species
51
52contains
53
54 ! ---------------------------------------------------------
55 subroutine atom_init(this, dim, label, species)
56 type(atom_t), intent(out) :: this
57 integer, intent(in) :: dim
58 character(len=*), intent(in) :: label
59 class(species_t), target, optional, intent(in) :: species
60
61 push_sub(atom_init)
62
63 this%label = trim(adjustl(label))
64 this%species => null()
65 if (present(species)) this%species => species
66
67 safe_allocate(this%c(1:dim))
68 this%c = 0
69
70 safe_allocate(this%f_ii(1:dim))
71 safe_allocate(this%f_vdw(1:dim))
72 safe_allocate(this%f_loc(1:dim))
73 safe_allocate(this%f_nl(1:dim))
74 safe_allocate(this%f_fields(1:dim))
75 safe_allocate(this%f_u(1:dim))
76 safe_allocate(this%f_scf(1:dim))
77 safe_allocate(this%f_nlcc(1:dim))
78 safe_allocate(this%f_photons(1:dim))
79 this%f_ii = m_zero
80 this%f_vdw = m_zero
81 this%f_loc = m_zero
82 this%f_nl = m_zero
83 this%f_fields = m_zero
84 this%f_u = m_zero
85 this%f_scf = m_zero
86 this%f_nlcc = m_zero
87 this%f_photons = m_zero
88
89 pop_sub(atom_init)
90 end subroutine atom_init
91
92 ! ---------------------------------------------------------
93 subroutine atom_copy(atom_out, atom_in)
94 class(atom_t), intent(out) :: atom_out
95 class(atom_t), intent(in) :: atom_in
97 push_sub(atom_copy)
98
99 atom_out%label = atom_in%label
100 atom_out%species => atom_in%species
101
102 safe_allocate_source_a(atom_out%c, atom_in%c)
103 safe_allocate_source_a(atom_out%f_ii, atom_in%f_ii)
104 safe_allocate_source_a(atom_out%f_vdw, atom_in%f_vdw)
105 safe_allocate_source_a(atom_out%f_loc, atom_in%f_loc)
106 safe_allocate_source_a(atom_out%f_nl, atom_in%f_nl)
107 safe_allocate_source_a(atom_out%f_fields, atom_in%f_fields)
108 safe_allocate_source_a(atom_out%f_u, atom_in%f_u)
109 safe_allocate_source_a(atom_out%f_scf, atom_in%f_scf)
110 safe_allocate_source_a(atom_out%f_nlcc, atom_in%f_nlcc)
111 safe_allocate_source_a(atom_out%f_photons, atom_in%f_photons)
112
113 pop_sub(atom_copy)
114 end subroutine atom_copy
115
116 ! ---------------------------------------------------------
117 subroutine atom_finalize(this)
118 type(atom_t), intent(inout) :: this
119
122 this%label = ""
123 this%species => null()
124
125 safe_deallocate_a(this%c)
127 safe_deallocate_a(this%f_ii)
128 safe_deallocate_a(this%f_vdw)
129 safe_deallocate_a(this%f_loc)
130 safe_deallocate_a(this%f_nl)
131 safe_deallocate_a(this%f_fields)
132 safe_deallocate_a(this%f_u)
133 safe_deallocate_a(this%f_scf)
134 safe_deallocate_a(this%f_nlcc)
135 safe_deallocate_a(this%f_photons)
138 end subroutine atom_finalize
139
140 ! ---------------------------------------------------------
141
142 pure function atom_get_label(this) result(label)
143 type(atom_t), intent(in) :: this
144
145 character(len=len_trim(adjustl(this%label))) :: label
146
147 label=trim(adjustl(this%label))
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 = (atom_get_label(this) == atom_get_label(that))
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 = (atom_get_label(this) == 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
211
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:187
pure logical function, public all_species_are_jellium_slab(atom)
Check if all species are jellium slab.
Definition: atom.F90:292
pure character(len=len_trim(adjustl(this%label))) function, public atom_get_label(this)
Definition: atom.F90:236
subroutine atom_finalize(this)
Definition: atom.F90:211
elemental logical function atom_same_species_aa(this, that)
Definition: atom.F90:270
pure logical function, public any_species_is_jellium_sphere(atom)
Check if any species is a jellium sphere.
Definition: atom.F90:309
elemental logical function atom_same_species_as(this, species)
Definition: atom.F90:281
subroutine, public atom_init(this, dim, label, species)
Definition: atom.F90:149
subroutine, public atom_get_species(this, species)
Definition: atom.F90:258
subroutine, public atom_set_species(this, species)
Definition: atom.F90:246
real(real64), parameter, public m_zero
Definition: global.F90:187
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
This module defines the unit system, used for input and output.
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
Definition: species.F90:143
int true(void)