Octopus
charged_particle.F90
Go to the documentation of this file.
1!! Copyright (C) 2020 H. Appel, S. Ohlmann, M. Oliveira, N. Tancogne-Dejean
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
26 use debug_oct_m
27 use global_oct_m
35 use parser_oct_m
38 use space_oct_m
39 use system_oct_m
40
41 implicit none
42
43 private
44 public :: &
47
51 ! Note that we exted classical_particle_t and not charged_particles_t. Both
52 ! choices have pros and cons. In the end extending classical_particle_t was
53 ! chosen because charged_particles_t was only introduced after
54 ! charged_particle_t.
55 private
56
57 real(real64) :: charge(1)
58
59 contains
60 procedure :: init_interaction => charged_particle_init_interaction
61 procedure :: initial_conditions => charged_particle_initial_conditions
62 procedure :: is_tolerance_reached => charged_particle_is_tolerance_reached
63 procedure :: update_quantity => charged_particle_update_quantity
64 procedure :: init_interaction_as_partner => charged_particle_init_interaction_as_partner
65 procedure :: copy_quantities_to_interaction => charged_particle_copy_quantities_to_interaction
66 end type charged_particle_t
67
68 interface charged_particle_t
69 procedure charged_particle_constructor
70 end interface charged_particle_t
71
72contains
73
74 ! ---------------------------------------------------------
79 function charged_particle_constructor(namespace) result(sys)
80 class(charged_particle_t), pointer :: sys
81 type(namespace_t), intent(in) :: namespace
82
84
85 allocate(sys)
86
87 call charged_particle_init(sys, namespace)
88
91
92 ! ---------------------------------------------------------
97 subroutine charged_particle_init(this, namespace)
98 class(charged_particle_t), intent(inout) :: this
99 type(namespace_t), intent(in) :: namespace
100
101 push_sub(charged_particle_init)
102
103 call classical_particle_init(this%classical_particle_t, namespace)
104
105 !%Variable ParticleCharge
106 !%Type float
107 !%Section ClassicalParticles
108 !%Description
109 !% Charge of classical particle
110 !%End
111 call parse_variable(namespace, 'ParticleCharge', m_one, this%charge(1))
112 call messages_print_var_value('ParticleCharge', this%charge(1), namespace=namespace)
113
114 this%supported_interactions = [this%supported_interactions, lorentz_force, coulomb_force]
115 this%supported_interactions_as_partner = [this%supported_interactions_as_partner, coulomb_force, current_to_mxll_field]
116
117 this%quantities(charge)%updated_on_demand = .false.
118 this%quantities(charge)%always_available = .true.
119
120
121 pop_sub(charged_particle_init)
122 end subroutine charged_particle_init
123
124 ! ---------------------------------------------------------
125 subroutine charged_particle_init_interaction(this, interaction)
126 class(charged_particle_t), target, intent(inout) :: this
127 class(interaction_t), intent(inout) :: interaction
128
130
131 select type (interaction)
132 type is (coulomb_force_t)
133 call interaction%init(this%space%dim, 1, this%charge, this%pos)
134 type is (lorentz_force_t)
135 call interaction%init(this%space%dim, 1, this%charge, this%pos, this%vel, this%namespace)
136 class default
137 call this%classical_particle_t%init_interaction(interaction)
138 end select
139
142
143 ! ---------------------------------------------------------
145 class(charged_particle_t), intent(inout) :: this
146
148
149 call this%classical_particle_t%initial_conditions()
154 ! ---------------------------------------------------------
155 logical function charged_particle_is_tolerance_reached(this, tol) result(converged)
156 class(charged_particle_t), intent(in) :: this
157 real(real64), intent(in) :: tol
160
161 converged = this%classical_particle_t%is_tolerance_reached(tol)
162
165
166 ! ---------------------------------------------------------
167 subroutine charged_particle_update_quantity(this, iq)
168 class(charged_particle_t), intent(inout) :: this
169 integer, intent(in) :: iq
170
173 select case (iq)
174 case (current)
175 ! we do not explicitly compute the current as it is only needed
176 ! by the current_to_mxll_field_t interaction where it is mapped
177 ! to a grid using charge, position and velocity
178 case default
179 ! Other quantities should be handled by the parent class
180 call this%classical_particle_t%update_quantity(iq)
181 end select
182
185
186 ! ---------------------------------------------------------
187 subroutine charged_particle_init_interaction_as_partner(partner, interaction)
188 class(charged_particle_t), intent(in) :: partner
189 class(interaction_surrogate_t), intent(inout) :: interaction
192
193 select type (interaction)
194 type is (coulomb_force_t)
195 interaction%partner_np = 1
196 safe_allocate(interaction%partner_charge(1))
197 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1))
199 interaction%partner_np = 1
200 interaction%grid_based_partner = .false.
201 safe_allocate(interaction%partner_charge(1))
202 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1))
203 safe_allocate(interaction%partner_vel(1:partner%space%dim, 1))
204 class default
205 ! Other interactions should be handled by the parent class
206 call partner%classical_particle_t%init_interaction_as_partner(interaction)
207 end select
208
211
212 ! ---------------------------------------------------------
213 subroutine charged_particle_copy_quantities_to_interaction(partner, interaction)
214 class(charged_particle_t), intent(inout) :: partner
215 class(interaction_surrogate_t), intent(inout) :: interaction
216
219 select type (interaction)
220 type is (coulomb_force_t)
221 interaction%partner_charge(1) = partner%charge(1)
222 interaction%partner_pos(:,1) = partner%pos(:, 1)
223
225 interaction%partner_charge(1) = partner%charge(1)
226 interaction%partner_pos(:,1) = partner%pos(:, 1)
227 interaction%partner_vel(:,1) = partner%vel(:, 1)
228 call interaction%do_mapping()
229
230 class default
231 call partner%classical_particle_t%copy_quantities_to_interaction(interaction)
232 end select
233
236
238
239!! Local Variables:
240!! mode: f90
241!! coding: utf-8
242!! End:
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:180
This module implements the basic elements defining algorithms.
Definition: algorithm.F90:141
subroutine charged_particle_update_quantity(this, iq)
subroutine charged_particle_init_interaction_as_partner(partner, interaction)
class(charged_particle_t) function, pointer charged_particle_constructor(namespace)
The factory routine (or constructor) allocates a pointer of the corresponding type and then calls the...
subroutine charged_particle_initial_conditions(this)
subroutine charged_particle_copy_quantities_to_interaction(partner, interaction)
subroutine charged_particle_init_interaction(this, interaction)
logical function charged_particle_is_tolerance_reached(this, tol)
subroutine, public charged_particle_init(this, namespace)
The init routine is a module level procedure This has the advantage that different classes can have d...
subroutine, public classical_particle_init(this, namespace)
The init routine is a module level procedure This has the advantage that different classes can have d...
real(real64), parameter, public m_one
Definition: global.F90:188
integer, parameter, public lorentz_force
integer, parameter, public current_to_mxll_field
integer, parameter, public coulomb_force
This module defines the abstract interaction_t class, and some auxiliary classes for interactions.
This module implements the multisystem debug functionality.
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:137
integer, parameter, public current
Definition: quantity.F90:146
integer, parameter, public charge
Definition: quantity.F90:146
This module implements the abstract system type.
Definition: system.F90:118
class for a charged classical particle
class for a neutral classical particle
Coulomb interaction between two systems of particles.
Class to transfer a current to a Maxwell field.
surrogate interaction class to avoid circular dependencies between modules.
Lorenz force between a systems of particles and an electromagnetic field.
int true(void)