Octopus
system_factory.F90
Go to the documentation of this file.
1!! Copyright (C) 2020, 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
24 use debug_oct_m
25 use dftb_oct_m
29 use global_oct_m
30 use ions_oct_m
32 use matter_oct_m
37 use parser_oct_m
40 use system_oct_m
42 implicit none
43
44 private
45 public :: &
47
48
49 !# doc_start system_types
50 integer, parameter, public :: &
51 SYSTEM_ELECTRONIC = 1, & !< electronic system (electrons_oct_m::electrons_t)
52 system_maxwell = 2, &
55 system_dftbplus = 5, &
57 system_matter = 7, &
59 ! !! (dispersive_medium_oct_m::dispersive_medium_t)
60 system_multisystem = 9, &
61 system_ions = 10, &
62 system_ensemble = 11
63 !# doc_end
64
71 contains
72 procedure :: create => system_factory_create
73 end type system_factory_t
74
75contains
76
77 ! ---------------------------------------------------------------------------------------
81 recursive function system_factory_create(this, namespace, type) result(system)
82 class(system_factory_t), intent(in) :: this
83 type(namespace_t), intent(in) :: namespace
84 integer, intent(in) :: type
85 class(system_t), pointer :: system
86
87 integer :: n_replicas
88 character(len=128), allocatable :: names(:)
89 integer, allocatable :: types(:)
90
91 push_sub(system_factory_create)
92
93 !%Variable Systems
94 !%Type block
95 !%Section System
96 !%Description
97 !% List of systems that will be treated in the calculation.
98 !% The first column should be a string containing the system name.
99 !% The second column should be the system type. See below for a list of
100 !% available system types.
101 !%Option electronic 1
102 !% An electronic system. (not fully implemented yet)
103 !%Option maxwell 2
104 !% A maxwell system.
105 !%Option classical_particle 3
106 !% A classical particle. Used for testing purposes only.
107 !%Option charged_particle 4
108 !% A charged classical particle.
109 !%Option dftbplus 5
110 !% A DFTB+ system
111 !%Option linear_medium 6
112 !% A linear medium for classical electrodynamics.
113 !%Option matter 7
114 !% A matter system containing electrons and classical ions.
115 !%Option dispersive_medium 8
116 !% (Experimental) A dispersive medium for classical electrodynamics.
117 !%Option multisystem 9
118 !% A system containing other systems.
119 !%Option ions 10
120 !% An ensemble of classical charged particles.
121 !%Option ensemble 11
122 !% An ensemble for multitrajectory runs
123 !%End
124 select case (type)
125 case (system_multisystem)
126
127 call parse_subsystems(namespace, names, types)
128
129 system => multisystem_basic_t(namespace, names, types, this)
130
131 safe_deallocate_a(names)
132 safe_deallocate_a(types)
133
134 case (system_electronic)
135 system => electrons_t(namespace)
136 case (system_maxwell)
137 system => maxwell_t(namespace)
139 system => classical_particle_t(namespace)
141 system => charged_particle_t(namespace)
142 case (system_dftbplus)
143 system => dftb_t(namespace)
145 system => linear_medium_t(namespace)
146 case (system_matter)
147 system => matter_t(namespace)
149 system => dispersive_medium_t(namespace)
150 call messages_experimental('dispersive_medium', namespace=namespace)
151 case (system_ions)
152 system => ions_t(namespace)
153 case (system_ensemble)
154 !%Variable NumberOfReplicas
155 !%Type integer
156 !%Default 1
157 !%Section System
158 !%Description
159 !% Number of replicas to be created for the ensemble.
160 !%End
161 call parse_variable(namespace, 'NumberOfReplicas', 1, n_replicas)
162 if (debug%info) then
163 write(message(1), '(a,i5,a)') "The ensemble has ", n_replicas, " replicas"
164 call messages_info(1, namespace=namespace)
165 end if
166
167 call parse_subsystems(namespace, names, types)
168
169 system => ensemble_t(namespace, n_replicas, this, names, types)
170
171 safe_deallocate_a(names)
172 safe_deallocate_a(types)
173
174 case default
175 call messages_input_error(namespace, 'Systems', 'Unknown system type.')
176 end select
177
178 pop_sub(system_factory_create)
179 end function system_factory_create
180
181
182 subroutine parse_subsystems(namespace, names, types)
183 type(namespace_t), intent(in) :: namespace
184 character(len=128), allocatable, intent(out) :: names(:)
185 integer, allocatable, intent(out) :: types(:)
186
187 integer :: n_systems, is, ic, iother
188 type(block_t) :: blk
189
190 ! Parse the input file to get the list of subsystems
191 if (parse_block(namespace, 'Systems', blk) == 0) then
192
193 n_systems = parse_block_n(blk)
194 safe_allocate(names(1:n_systems))
195 safe_allocate(types(1:n_systems))
196
197 do is = 1, n_systems
198 ! Parse system name and type
199 call parse_block_string(blk, is - 1, 0, names(is))
200 if (len_trim(names(is)) == 0) then
201 call messages_input_error(namespace, 'Systems', 'All systems must have a name')
202 end if
204 if (index(trim(names(is)), parser_varname_excluded_characters(ic:ic)) /= 0) then
205 call messages_input_error(namespace, 'Systems', &
206 'Illegal character "' // parser_varname_excluded_characters(ic:ic) // '" in system name', row=is-1, column=0)
207 end if
208 end do
209 call parse_block_integer(blk, is - 1, 1, types(is))
210
211 ! Check that the system name is unique
212 do iother = 1, is-1
213 if (names(is) == names(iother)) then
214 call messages_input_error(namespace, 'Systems', 'Duplicated system in multi-system', &
215 row=is-1, column=0)
216 end if
217 end do
218
219 end do
220 call parse_block_end(blk)
221 else
222 call messages_input_error(namespace, 'Systems', 'Missing Systems block')
223 end if
224
225 end subroutine parse_subsystems
226
227
228end module system_factory_oct_m
229
230!! Local Variables:
231!! mode: f90
232!! coding: utf-8
233!! End:
type(debug_t), save, public debug
Definition: debug.F90:156
This module implements the ensemble class.
Definition: ensemble.F90:107
This module defines a linear medium for use in classical electrodynamics calculations.
This module defines a container system for electrons and ions.
Definition: matter.F90:116
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:713
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1085
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:616
This module implements the basic mulsisystem class, a container system for other systems.
character(len=27), parameter, public parser_varname_excluded_characters
The following characters should not be allowed in variable names.
Definition: parser.F90:154
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
This module defines the abstract class for the system factory.
integer, parameter, public system_matter
electrons including ions (matter_oct_m::matter_t)
integer, parameter, public system_ions
ensemble of charged classical particles (ions_oct_m::ions_t)
integer, parameter, public system_ensemble
ensemble container (ensemble_oct_m::ensemble_t)
integer, parameter, public system_linear_medium
linear medium for Maxwell calculations (linear_medium_oct_m::linear_medium_t)
recursive class(system_t) function, pointer system_factory_create(this, namespace, type)
create a new system.
integer, parameter, public system_classical_particle
single classical particle (classical_particle_oct_m::classical_particle_t)
integer, parameter, public system_charged_particle
single charged classical particle (charged_particle_oct_m::charged_particle_t)
subroutine parse_subsystems(namespace, names, types)
integer, parameter, public system_dispersive_medium
dispersive medium for classical electrodynamics
integer, parameter, public system_multisystem
container system. (multisystem_basic_oct_m::multisystem_basic_t)
integer, parameter, public system_dftbplus
tight binding system (dftb_oct_m::dftb_t)
integer, parameter, public system_maxwell
maxwell system, (maxwell_oct_m::maxwell_t)
This module implements the abstract system type.
Definition: system.F90:118
class for a charged classical particle
class for a neutral classical particle
class for a tight binding
Definition: dftb.F90:158
dispersive medium for classical electrodynamics calculations
Class describing the electron system.
Definition: electrons.F90:218
the ensemble class
Definition: ensemble.F90:138
linear medium for classical electrodynamics
container class for for electrons and ions
Definition: matter.F90:136
Class describing Maxwell systems.
Definition: maxwell.F90:195
Container class for lists of system_oct_m::system_t.
factory for classes, derived from the abstract system_cot_m::system_t class