Octopus
charged_particles.F90
Go to the documentation of this file.
1!! Copyright (C) 2022 M. Oliveira
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 debug_oct_m
26 use global_oct_m
33
34 implicit none
35
36 private
37 public :: &
46
47 type, extends(classical_particles_t), abstract :: charged_particles_t
48 private
49 real(real64), allocatable, public :: charge(:)
50 contains
51 procedure :: update_quantity => charged_particles_update_quantity
52 procedure :: init_interaction_as_partner => charged_particles_init_interaction_as_partner
53 procedure :: copy_quantities_to_interaction => charged_particles_copy_quantities_to_interaction
54 end type charged_particles_t
55
56
57contains
58
59 ! ---------------------------------------------------------
64 ! ---------------------------------------------------------
65 subroutine charged_particles_init(this, np)
66 class(charged_particles_t), intent(inout) :: this
67 integer, intent(in) :: np
68
70
71 call classical_particles_init(this, np)
72 safe_allocate(this%charge(1:np))
73 this%charge = m_zero
74
75 call this%quantities%add(quantity_t("charge", updated_on_demand = .false., always_available = .true.))
76
77 this%supported_interactions = [this%supported_interactions, coulomb_force, lorentz_force]
78 this%supported_interactions_as_partner = [this%supported_interactions_as_partner, coulomb_force, current_to_mxll_field]
79
81 end subroutine charged_particles_init
82
83 ! ---------------------------------------------------------
84 subroutine charged_particles_copy(this, cp_in)
85 class(charged_particles_t), intent(out) :: this
86 class(charged_particles_t), intent(in) :: cp_in
87
89
90 call classical_particles_copy(this, cp_in)
91 safe_allocate_source_a(this%charge, cp_in%charge)
92
94 end subroutine charged_particles_copy
95
96 ! ---------------------------------------------------------
97 subroutine charged_particles_init_interaction(this, interaction)
98 class(charged_particles_t), target, intent(inout) :: this
99 class(interaction_surrogate_t), intent(inout) :: interaction
100
102
103 select type (interaction)
104 type is (coulomb_force_t)
105 call interaction%init(this%space%dim, this%np, this%charge, this%pos)
106 type is (lorentz_force_t)
107 call interaction%init(this%space%dim, this%np, this%charge, this%pos, this%vel, this%namespace)
108 class default
109 ! Other interactions should be handled by the parent class
110 call classical_particles_init_interaction(this, interaction)
111 end select
112
115
116 ! ---------------------------------------------------------
117 subroutine charged_particles_update_quantity(this, label)
118 class(charged_particles_t), intent(inout) :: this
119 character(len=*), intent(in) :: label
120
122
123 select case (label)
124 case("current")
125 ! Nothing to do
126 case default
127 ! Other quantities should be handled by the parent class
129 end select
130
133
134 ! ---------------------------------------------------------
135 subroutine charged_particles_init_interaction_as_partner(partner, interaction)
136 class(charged_particles_t), intent(in) :: partner
137 class(interaction_surrogate_t), intent(inout) :: interaction
138
141 select type (interaction)
143 interaction%partner_np = partner%np
144 safe_allocate(interaction%partner_charge(1:partner%np))
145 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1:partner%np))
148 interaction%partner_np = partner%np
149 interaction%grid_based_partner = .false.
150 safe_allocate(interaction%partner_charge(1:partner%np))
151 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1:partner%np))
152 safe_allocate(interaction%partner_vel(1:partner%space%dim, 1:partner%np))
153
154 class default
155 ! Other interactions should be handled by the parent class
156 call classical_particles_init_interaction_as_partner(partner, interaction)
157 end select
161
162 ! ---------------------------------------------------------
163 subroutine charged_particles_copy_quantities_to_interaction(partner, interaction)
164 class(charged_particles_t), intent(inout) :: partner
165 class(interaction_surrogate_t), intent(inout) :: interaction
166
168
169 select type (interaction)
170 type is (coulomb_force_t)
171 interaction%partner_charge = partner%charge
172 interaction%partner_pos = partner%pos
173
175 interaction%partner_charge = partner%charge
176 interaction%partner_pos = partner%pos
177 interaction%partner_vel = partner%vel
178
179 class default
180 ! Other interactions should be handled by the parent class
182 end select
183
186
187 ! ---------------------------------------------------------
188 subroutine charged_particles_end(this)
189 class(charged_particles_t), intent(inout) :: this
191 push_sub(charged_particles_end)
192
193 call classical_particles_end(this)
194 safe_deallocate_a(this%charge)
195
196 pop_sub(charged_particles_end)
197 end subroutine charged_particles_end
198
200
201!! Local Variables:
202!! mode: f90
203!! coding: utf-8
204!! End:
subroutine, public charged_particles_copy(this, cp_in)
subroutine, public charged_particles_init_interaction_as_partner(partner, interaction)
subroutine, public charged_particles_update_quantity(this, label)
subroutine, public charged_particles_init_interaction(this, interaction)
subroutine, public charged_particles_copy_quantities_to_interaction(partner, interaction)
subroutine, public charged_particles_init(this, np)
The init routine is a module level procedure This has the advantage that different classes can have d...
subroutine, public charged_particles_end(this)
subroutine, public classical_particles_update_quantity(this, label)
subroutine, public classical_particles_init_interaction_as_partner(partner, interaction)
subroutine, public classical_particles_end(this)
subroutine, public classical_particles_init(this, np)
The init routine is a module level procedure This has the advantage that different classes can have d...
subroutine, public classical_particles_copy(this, cp_in)
subroutine, public classical_particles_copy_quantities_to_interaction(partner, interaction)
subroutine, public classical_particles_init_interaction(this, interaction)
real(real64), parameter, public m_zero
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 quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:138
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.
Systems (system_t) can expose quantities that can be used to calculate interactions with other system...
Definition: quantity.F90:171
int true(void)