Octopus
modelmb_particles.F90
Go to the documentation of this file.
1!! Copyright (C) 2009 N. Helbig and M. Verstraete
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., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
25 use, intrinsic :: iso_fortran_env
26 use debug_oct_m
27 use global_oct_m
30 use parser_oct_m
32 use space_oct_m
33
34 implicit none
35
36 private
37
38 public :: &
44
49 private
50 integer, public :: ndim
52
53 integer, public :: ntype_of_particle
55 integer :: max_particles_per_type
56
57 integer, public :: nparticle = 0
58
59 integer :: ndensities_to_calculate
60
68 character(80), allocatable :: labels_particles(:)
69
70 integer, allocatable, public :: particletype(:)
71 integer, allocatable, public :: nparticles_per_type(:)
72 integer, allocatable, public :: particles_of_type(:,:)
73 integer, allocatable, public :: bosonfermion(:)
74
75 integer, allocatable :: exchange_symmetry(:,:,:)
76
77 real(real64), allocatable :: mass_particle(:)
78
79 real(real64), allocatable, public :: charge_particle(:)
80
88 character(80), allocatable :: labels_densities(:)
89
90 integer, allocatable :: particle_kept_densities(:)
91
92 integer, allocatable, public :: nspindown(:,:)
93 ! for each type and state
94 integer, allocatable, public :: iyoung(:,:)
95 real(real64), allocatable, public :: proj(:)
96
97 contains
98 procedure :: copy_masses => modelmb_copy_masses
99 end type modelmb_particle_t
100
101contains
102
106 subroutine modelmb_particles_init(this, namespace, space, nst)
107 type(modelmb_particle_t), intent(inout) :: this
108 type(namespace_t), intent(in) :: namespace
109 class(space_t), intent(in) :: space
110 integer, intent(in) :: nst
111
112 integer :: ipart, ncols, nline, itmp, jtmp, ntype
113 type(block_t) :: blk
114
115 push_sub(modelmb_particles_init)
116
117 ! read in scalar dimensions
118
119 !%Variable NParticleModelmb
120 !%Type integer
121 !%Section States::ModelMB
122 !%Default 0
123 !%Description
124 !% Number of particles in modelmb space.
125 !% Full Ndim = <tt>NDimModelmb</tt>*<tt>NParticleModelmb</tt>
126 !%End
127 call parse_variable(namespace, 'NParticleModelmb', 0, this%nparticle)
128
129 if (this%nparticle == 0) then
131 return
132 end if
133
134 call messages_print_var_value("NParticleModelmb", this%nparticle, namespace=namespace)
135
136 !%Variable NDimModelmb
137 !%Type integer
138 !%Section States::ModelMB
139 !%Default 1
140 !%Description
141 !% Number of dimensions for modelmb space.
142 !% Full Ndim = <tt>NDimModelmb</tt>*<tt>NParticleModelmb</tt>
143 !%
144 !%End
145 call parse_variable(namespace, 'NDimModelmb', 1, this%ndim)
146 call messages_print_var_value("NDimModelmb", this%ndim, namespace=namespace)
147
148 !%Variable NTypeParticleModelmb
149 !%Type integer
150 !%Section States::ModelMB
151 !%Default 1
152 !%Description
153 !% Number of different types of particles in modelmb space.
154 !%End
155 call parse_variable(namespace, 'NTypeParticleModelmb', 1, this%ntype_of_particle)
156 call messages_print_var_value("NTypeParticleModelmb", this%ntype_of_particle, namespace=namespace)
157 if (this%ntype_of_particle > this%nparticle) then
158 write (message(1), '(2a,2I6)') ' Number of types of modelmb particles should be <= Number of modelmb particles ', &
159 this%ntype_of_particle, this%nparticle
160 call messages_fatal(1, namespace=namespace)
161 end if
162
163 if (this%ndim*this%nparticle /= space%dim) then
164 message(1) = ' Number of modelmb particles * dimension of modelmb space must be = Ndim'
165 call messages_fatal(1, namespace=namespace)
166 end if
167
169 ! allocate stuff
170 ntype = this%ntype_of_particle
171 safe_allocate(this%labels_particles(1:this%nparticle))
172 safe_allocate(this%particletype(1:this%nparticle))
173 safe_allocate(this%mass_particle(1:this%nparticle))
174 safe_allocate(this%charge_particle(1:this%nparticle))
175 safe_allocate(this%bosonfermion(1:this%nparticle))
176 safe_allocate(this%nparticles_per_type(1:ntype))
177 safe_allocate(this%particles_of_type(1:this%nparticle, 1:ntype))
178
179 ! default all particles are electrons
180 this%labels_particles = 'electron'
181 this%particletype = 1
182 this%mass_particle = m_one
183 this%charge_particle = m_one
184 this%bosonfermion = 1 ! set to fermion
186 !%Variable DescribeParticlesModelmb
187 !%Type block
188 !%Section States::ModelMB
189 !%Description
190 !% Characterization of different modelmb particles in space%dim dimensional space.
191 !%
192 !% <tt>%DescribeParticlesModelmb
193 !% <br>&nbsp;&nbsp; "proton" | 1 | 1800. | 1. | fermion
194 !% <br>&nbsp;&nbsp; "proton" | 1 | 1800. | 1. | fermion
195 !% <br>&nbsp;&nbsp; "electron" | 2 | 1. | 1. | fermion
196 !% <br>%</tt>
197 !%
198 !% would tell <tt>Octopus</tt> that there are presently 3 particles, called proton, proton,
199 !% and electron, with types 1, 1, and 2, and corresponding masses and charges.
200 !% All particles should be fermions, and this can be later enforced on the spatial
201 !% part of the wavefunctions.
202 !% The label and charge are presently only for informational purposes and
203 !% are not checked or used in <tt>Octopus</tt>. The interaction has to take the
204 !% actual charge into account.
205 !%
206 !%Option fermion 1
207 !% Particle is a fermion.
208 !%Option boson 2
209 !% Particle is a boson.
210 !%Option anyon 3
211 !% Particle is neither fermion nor boson.
212 !%End
213 if (parse_block(namespace, 'DescribeParticlesModelmb', blk) == 0) then
214
215 call messages_experimental("Model many-body", namespace=namespace)
216
217 ncols = parse_block_cols(blk, 0)
218 if (ncols /= 5) then
219 call messages_input_error(namespace, "DescribeParticlesModelmb")
220 end if
221 nline = parse_block_n(blk)
222 if (nline /= this%nparticle) then
223 call messages_input_error(namespace, "DescribeParticlesModelmb")
224 end if
225
226 do ipart = 1, this%nparticle
227 call parse_block_string(blk, ipart - 1, 0, this%labels_particles(ipart))
228 call parse_block_integer(blk, ipart - 1, 1, this%particletype(ipart))
229 call parse_block_float(blk, ipart - 1, 2, this%mass_particle(ipart))
230 call parse_block_float(blk, ipart - 1, 3, this%charge_particle(ipart))
231 call parse_block_integer(blk, ipart - 1, 4, this%bosonfermion(ipart))
232
233 write (message(1),'(a,a)') 'labels_particles = ', this%labels_particles(ipart)
234 write (message(2),'(a,i6)') 'particletype = ', this%particletype(ipart)
235 write (message(3),'(a,E20.10)') 'mass_particle = ', this%mass_particle(ipart)
236 write (message(4),'(a,E20.10)') 'charge_particle = ', this%charge_particle(ipart)
237 write (message(5),'(a,i6)') 'bosonfermion = ', this%bosonfermion(ipart)
238 call messages_info(5, namespace=namespace)
239 end do
240 call parse_block_end(blk)
241
242 end if
243
244 this%nparticles_per_type = 0
245 this%particles_of_type = 0
246 do ipart = 1, this%nparticle
247 this%nparticles_per_type(this%particletype(ipart)) = &
248 this%nparticles_per_type(this%particletype(ipart)) + 1
249 this%particles_of_type(this%nparticles_per_type(this%particletype(ipart)), &
250 this%particletype(ipart)) = ipart
251 end do
252
253 this%max_particles_per_type = maxval(this%nparticles_per_type)
254 itmp = this%max_particles_per_type
255 jtmp = this%ntype_of_particle
256 safe_allocate(this%exchange_symmetry(1:itmp, 1:itmp, 1:jtmp))
257 this%exchange_symmetry = 0
258
259 if (this%nparticle > 0) then
260 ! FIXME: check why this is not initialized properly in the test, or why it is written out when not initialized
261 safe_allocate(this%nspindown(1:this%ntype_of_particle, 1:nst))
262 this%nspindown(:,:) = -1
263 safe_allocate(this%iyoung(1:this%ntype_of_particle, 1:nst))
264 this%iyoung(:,:) = -1
265 safe_allocate(this%proj(1:nst))
266 this%proj(:) = m_zero
267 end if
268
270
271 end subroutine modelmb_particles_init
272
273
274 subroutine modelmb_particles_end (this)
275 type(modelmb_particle_t),intent(inout) :: this
276
277 push_sub(modelmb_particles_end)
278
279 safe_deallocate_a(this%nspindown)
280 safe_deallocate_a(this%iyoung)
281 safe_deallocate_a(this%proj)
282
283 safe_deallocate_a(this%labels_particles)
284 safe_deallocate_a(this%particletype)
285 safe_deallocate_a(this%mass_particle)
286 safe_deallocate_a(this%charge_particle)
287 safe_deallocate_a(this%nparticles_per_type)
288 safe_deallocate_a(this%particles_of_type)
289 safe_deallocate_a(this%exchange_symmetry)
290 safe_deallocate_a(this%bosonfermion)
291
292 safe_deallocate_a(this%labels_densities)
293 safe_deallocate_a(this%particle_kept_densities)
294
295 pop_sub(modelmb_particles_end)
296 end subroutine modelmb_particles_end
297
298 subroutine modelmb_particles_copy(modelmb_out, modelmb_in)
299 type(modelmb_particle_t), intent(in) :: modelmb_in
300 type(modelmb_particle_t), intent(inout) :: modelmb_out
301
302 push_sub(modelmb_particles_copy)
303
304 call modelmb_particles_end(modelmb_out)
305
306 modelmb_out%ndim = modelmb_in%ndim
307 modelmb_out%ntype_of_particle = modelmb_in%ntype_of_particle
308 modelmb_out%max_particles_per_type = modelmb_in%max_particles_per_type
309 modelmb_out%nparticle = modelmb_in%nparticle
310 modelmb_out%ndensities_to_calculate = modelmb_in%ndensities_to_calculate
311
312 safe_allocate_source_a(modelmb_out%labels_particles,modelmb_in%labels_particles)
313 safe_allocate_source_a(modelmb_out%particletype,modelmb_in%particletype)
314 safe_allocate_source_a(modelmb_out%mass_particle,modelmb_in%mass_particle)
315 safe_allocate_source_a(modelmb_out%charge_particle,modelmb_in%charge_particle)
316 safe_allocate_source_a(modelmb_out%nparticles_per_type,modelmb_in%nparticles_per_type)
317 safe_allocate_source_a(modelmb_out%particles_of_type,modelmb_in%particles_of_type)
318 safe_allocate_source_a(modelmb_out%exchange_symmetry,modelmb_in%exchange_symmetry)
319 safe_allocate_source_a(modelmb_out%bosonfermion,modelmb_in%bosonfermion)
320
321 safe_allocate_source_a(modelmb_out%labels_densities,modelmb_in%labels_densities)
322 safe_allocate_source_a(modelmb_out%particle_kept_densities,modelmb_in%particle_kept_densities)
323
324 if (modelmb_in%nparticle > 0) then
325 safe_allocate_source_a(modelmb_out%nspindown, modelmb_in%nspindown)
326 safe_allocate_source_a(modelmb_out%iyoung, modelmb_in%iyoung)
327 safe_allocate_source_a(modelmb_out%proj, modelmb_in%proj)
328 end if
329
331
332 end subroutine modelmb_particles_copy
333
335 subroutine modelmb_copy_masses(this, masses)
336 class(modelmb_particle_t), intent(in) :: this
337 real(real64), intent(inout) :: masses(:)
338
339 real(real64), parameter :: tol_mass = 1.e-10_real64
340 integer :: dimcounter,ipart
341
342 push_sub(modelmb_copy_masses)
343
344 ! copy masses to gr%der%masses
345 dimcounter = 0
346 do ipart = 1,this%nparticle
347 if (abs(this%mass_particle(ipart)-1.0_real64) > tol_mass) then
348 masses(dimcounter+1:dimcounter+this%ndim) = this%mass_particle(ipart)
349 end if
350 dimcounter = dimcounter+this%ndim
351 end do
352
353 pop_sub(modelmb_copy_masses)
354 end subroutine modelmb_copy_masses
355
357
358!! Local Variables:
359!! mode: f90
360!! coding: utf-8
361!! End:
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:180
real(real64), parameter, public m_zero
Definition: global.F90:188
real(real64), parameter, public m_one
Definition: global.F90:189
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:414
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:696
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1068
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:599
general module for modelmb particles
subroutine, public modelmb_copy_masses(this, masses)
Copy masses for particles. To be used for the derivative object.
subroutine, public modelmb_particles_end(this)
subroutine, public modelmb_particles_init(this, namespace, space, nst)
==============================================================
subroutine, public modelmb_particles_copy(modelmb_out, modelmb_in)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
==============================================================