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