Octopus
interactions_factory.F90
Go to the documentation of this file.
1!! Copyright (C) 2020 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
24 use debug_oct_m
25 use global_oct_m
39 use parser_oct_m
41 implicit none
42
43 private
45
47 contains
48 procedure :: create => interactions_factory_create
49 procedure, nopass :: options => interactions_factory_options
51
52contains
53
54 ! ---------------------------------------------------------------------------------------
59 !
60 function interactions_factory_create(this, type, partner) result(interaction)
61 class(interactions_factory_t), intent(in) :: this
62 integer, intent(in) :: type
63 class(interaction_partner_t), target, intent(inout) :: partner
64 class(interaction_t), pointer :: interaction
65
67
68 select case (type)
69 case (gravity)
70 interaction => gravity_t(partner)
71 case (coulomb_force)
72 interaction => coulomb_force_t(partner)
73 case (lorentz_force)
74 interaction => lorentz_force_t(partner)
76 interaction => linear_medium_to_em_field_t(partner)
78 interaction => current_to_mxll_field_t(partner)
80 interaction => mxll_e_field_to_matter_t(partner)
82 interaction => mxll_b_field_to_matter_t(partner)
84 interaction => mxll_vec_pot_to_matter_t(partner)
85 case (lennard_jones)
86 interaction => lennard_jones_t(partner)
87 case default
88 message(1) = "Unknown interaction in interactions_factory_create"
89 call messages_fatal(1)
90 end select
91
94
95 ! ---------------------------------------------------------------------------------------
100 !
101 function interactions_factory_options(namespace, interactions) result(options)
102 type(namespace_t), intent(in) :: namespace
103 integer, intent(in) :: interactions(:)
104 type(interactions_factory_options_t) :: options(size(interactions))
105
106 integer :: line, col, i, type, timing
107 type(block_t) :: blk
108
109 !%Variable InteractionTiming
110 !%Type integer
111 !%Default timing_exact
112 !%Section Time-Dependent::Propagation
113 !%Description
114 !% A parameter to determine if interactions should use the quantities
115 !% at the exact iteration or if retardation is allowed.
116 !%Option timing_exact 1
117 !% Only allow interactions at the exact iterations required by the algorithms behing executed
118 !%Option timing_retarded 2
119 !% Allow retarded interactions
120 !%End
121 call parse_variable(namespace, 'InteractionTiming', timing_exact, timing)
122 if (.not. varinfo_valid_option('InteractionTiming', timing)) then
123 call messages_input_error(namespace, 'InteractionTiming')
124 end if
125 call messages_print_var_option('InteractionTiming', timing, namespace=namespace)
126 options%timing = timing
127
128 ! Default modes for the interactions
129 do i = 1, size(interactions)
130 select case (interactions(i))
131 case (gravity, lennard_jones)
132 options(i)%mode = no_partners
133 case default
134 options(i)%mode = all_partners
135 end select
136 end do
137
138 !%Variable Interactions
139 !%Type block
140 !%Section System
141 !%Description
142 !% This input option controls the interactions between systems. It basically
143 !% allows to select which systems will interact with another system through
144 !% a given interaction type. The format of the block is the following:
145 !%
146 !% <br>%<tt>Namespace.Interactions
147 !% <br>&nbsp;&nbsp;interaction_type | interaction_mode | ...
148 !% <br>%</tt>
149 !%
150 !% Here is an example to better understand how this works:
151 !%
152 !% <br>%<tt>SystemA.Interactions
153 !% <br>&nbsp;&nbsp;gravity | all_except | "SystemB"
154 !% <br>%</tt>
155 !%
156 !% This means that SystemA and all the systems that belong to the same
157 !% namespace (i.e., all its subsystems) will interact through gravity with
158 !% all interaction partners that are also able to interact through gravity,
159 !% except with SystemB. Note that the opposite is not true so, although
160 !% clearly unphysical, this will not prevent SystemB from feeling the
161 !% gravity from SystemA (in <tt>Octopus</tt> the interactions are always
162 !% one-sided).
163 !%
164 !% NB: Each interaction type should only appear once in the block. Any
165 !% further instances beyond the first will be ignored.
166 !%
167 !% Available modes and interaction types:
168 !%Option no_partners -1
169 !% (interaction mode)
170 !% Do not interact with any partner.
171 !%Option all_partners -2
172 !% (interaction mode)
173 !% Interact with all available partners.
174 !%Option only_partners -3
175 !% (interaction mode)
176 !% Interact only with some specified partners. A list of partner names must
177 !% be given.
178 !%Option all_except -4
179 !% (interaction mode)
180 !% Interact with all available partners except with some specified
181 !% partners. A list of partner names to exclude must be given.
182 !%Option gravity 1
183 !% (interaction type)
184 !% Gravity interaction between two masses.
185 !%Option lorentz_force 2
186 !% (interaction type)
187 !% Lorentz force resulting from an EM field acting on a moving charge.
188 !%Option coulomb_force 3
189 !% (interaction type)
190 !% Coulomb force between two charged particles.
191 !%Option linear_medium_to_em_field 4
192 !% (interaction type)
193 !% Linear medium for propagation of EM fields.
194 !%Option current_to_mxll_field 5
195 !% (interaction type)
196 !% Drude dispersive linear medium for propagation of EM fields.
197 !%Option maxwell_e_field 6
198 !% (interaction type)
199 !% Electric field resulting from the Maxwell solver.
200 !%Option maxwell_b_field 7
201 !% (interaction type)
202 !% Magnetic field resulting from the Maxwell solver.
203 !%Option maxwell_vector_potential 8
204 !% (interaction type)
205 !% Vector potential resulting from the Maxwell solver.
206 !%Option lennard_jones 9
207 !% (interaction type)
208 !% Force resulting from a Lennard Jones potential between classical particles.
209 !%End
210 if (parse_block(namespace, "Interactions", blk) == 0) then
211 ! Loop over all interactions specified in the input file
212 do line = 0, parse_block_n(blk) - 1
213 ! Read the interaction type (first column)
214 call parse_block_integer(blk, line, 0, type)
215
216 ! Sanity check: the interaction type must be known and must not be mistaken for an interaction mode
217 if (.not. varinfo_valid_option("Interactions", type) .or. &
218 any(type == [all_partners, only_partners, no_partners, all_except])) then
219 call messages_input_error(namespace, "Interactions", details="Unknown interaction type", row=line, column=0)
220 end if
221
222 ! Is this interaction in the list of provided interactions?
223 i = findloc(interactions, type, dim=1)
224 if (i == 0) cycle
225
226 ! Read how this interaction should be treated (second column)
227 call parse_block_integer(blk, line, 1, options(i)%mode)
228 if (all(options(i)%mode /= [all_partners, only_partners, no_partners, all_except])) then
229 call messages_input_error(namespace, "Interactions", "Unknown interaction mode", row=line, column=1)
230 end if
231
232 select case (options(i)%mode)
234 ! In these two cases we need to read the names of the selected
235 ! partners (remaining columns) and handled them appropriately
236 allocate(options(i)%partners(parse_block_cols(blk, line) - 2))
237 do col = 2, parse_block_cols(blk, line) - 1
238 call parse_block_string(blk, line, col, options(i)%partners(col-1))
239 end do
240 end select
241 end do
242 call parse_block_end(blk)
243 end if
244
246
248
249!! Local Variables:
250!! mode: f90
251!! coding: utf-8
252!! End:
integer, parameter, public mxll_vec_pot_to_matter
integer, parameter, public linear_medium_to_em_field
integer, parameter, public lorentz_force
integer, parameter, public lennard_jones
integer, parameter, public gravity
integer, parameter, public mxll_b_field_to_matter
integer, parameter, public mxll_e_field_to_matter
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.
integer, parameter, public timing_exact
This module defines classes and functions for interaction partners.
This module defines the abstract class for the interaction factory.
integer, parameter, public only_partners
type(interactions_factory_options_t) function, dimension(size(interactions)) interactions_factory_options(namespace, interactions)
return a list of options to be used when creating the interactions
class(interaction_t) function, pointer interactions_factory_create(this, type, partner)
create an interaction of given type with specified partner
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:420
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:723
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
Coulomb interaction between two systems of particles.
Class to transfer a current to a Maxwell field.
Gravity interaction between two systems of particles. This should be used for testing purposes only....
Definition: gravity.F90:135
Lennard-Jones interaction between two systems of particles.
Lorenz force between a systems of particles and an electromagnetic field.
class to transfer a Maxwell B field to a matter system
class to transfer a Maxwell field to a medium
class to transfer a Maxwell vector potential to a medium