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 this%quantities(charge)%updated_on_demand = .false.
76 this%quantities(charge)%always_available = .true.
77
78 this%supported_interactions = [this%supported_interactions, coulomb_force, lorentz_force]
79 this%supported_interactions_as_partner = [this%supported_interactions_as_partner, coulomb_force, current_to_mxll_field]
80
82 end subroutine charged_particles_init
83
84 ! ---------------------------------------------------------
85 subroutine charged_particles_copy(this, cp_in)
86 class(charged_particles_t), intent(out) :: this
87 class(charged_particles_t), intent(in) :: cp_in
88
90
91 call classical_particles_copy(this, cp_in)
92 safe_allocate_source_a(this%charge, cp_in%charge)
93
95 end subroutine charged_particles_copy
96
97 ! ---------------------------------------------------------
98 subroutine charged_particles_init_interaction(this, interaction)
99 class(charged_particles_t), target, intent(inout) :: this
100 class(interaction_surrogate_t), intent(inout) :: interaction
101
103
104 select type (interaction)
105 type is (coulomb_force_t)
106 call interaction%init(this%space%dim, this%np, this%charge, this%pos)
107 type is (lorentz_force_t)
108 call interaction%init(this%space%dim, this%np, this%charge, this%pos, this%vel, this%namespace)
109 class default
110 ! Other interactions should be handled by the parent class
111 call classical_particles_init_interaction(this, interaction)
112 end select
113
116
117 ! ---------------------------------------------------------
118 subroutine charged_particles_update_quantity(this, iq)
119 class(charged_particles_t), intent(inout) :: this
120 integer, intent(in) :: iq
121
123
124 ! We are only allowed to update quantities that can be updated on demand
125 assert(this%quantities(iq)%updated_on_demand)
126
127 select case (iq)
128 case(current)
129 ! Nothing to do
130 case default
131 ! Other quantities should be handled by the parent class
133 end select
134
137
138 ! ---------------------------------------------------------
139 subroutine charged_particles_init_interaction_as_partner(partner, interaction)
140 class(charged_particles_t), intent(in) :: partner
141 class(interaction_surrogate_t), intent(inout) :: interaction
145 select type (interaction)
147 interaction%partner_np = partner%np
148 safe_allocate(interaction%partner_charge(1:partner%np))
149 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1:partner%np))
150
152 interaction%partner_np = partner%np
153 interaction%grid_based_partner = .false.
154 safe_allocate(interaction%partner_charge(1:partner%np))
155 safe_allocate(interaction%partner_pos(1:partner%space%dim, 1:partner%np))
156 safe_allocate(interaction%partner_vel(1:partner%space%dim, 1:partner%np))
157
158 class default
159 ! Other interactions should be handled by the parent class
160 call classical_particles_init_interaction_as_partner(partner, interaction)
161 end select
162
165
166 ! ---------------------------------------------------------
167 subroutine charged_particles_copy_quantities_to_interaction(partner, interaction)
168 class(charged_particles_t), intent(inout) :: partner
169 class(interaction_surrogate_t), intent(inout) :: interaction
170
172
173 select type (interaction)
174 type is (coulomb_force_t)
175 interaction%partner_charge = partner%charge
176 interaction%partner_pos = partner%pos
177
179 interaction%partner_charge = partner%charge
180 interaction%partner_pos = partner%pos
181 interaction%partner_vel = partner%vel
182
183 class default
184 ! Other interactions should be handled by the parent class
186 end select
187
190
191 ! ---------------------------------------------------------
192 subroutine charged_particles_end(this)
193 class(charged_particles_t), intent(inout) :: this
194
195 push_sub(charged_particles_end)
196
197 call classical_particles_end(this)
198 safe_deallocate_a(this%charge)
199
200 pop_sub(charged_particles_end)
201 end subroutine charged_particles_end
202
204
205!! Local Variables:
206!! mode: f90
207!! coding: utf-8
208!! 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, iq)
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_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_update_quantity(this, iq)
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:187
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:137
integer, parameter, public current
Definition: quantity.F90:146
integer, parameter, public charge
Definition: quantity.F90:146
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)