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, calc_mode_id) result(system)
82 class(system_factory_t), intent(in) :: this
83 type(namespace_t), intent(in) :: namespace
84 integer, intent(in) :: type
85 integer, intent(in) :: calc_mode_id
86 class(system_t), pointer :: system
87
88 integer :: n_replicas
89 character(len=128), allocatable :: names(:)
90 integer, allocatable :: types(:)
91
92 push_sub(system_factory_create)
93
94 !%Variable Systems
95 !%Type block
96 !%Section System
97 !%Description
98 !% List of systems that will be treated in the calculation.
99 !% The first column should be a string containing the system name.
100 !% The second column should be the system type. See below for a list of
101 !% available system types.
102 !%Option electronic 1
103 !% An electronic system. (not fully implemented yet)
104 !%Option maxwell 2
105 !% A maxwell system.
106 !%Option classical_particle 3
107 !% A classical particle. Used for testing purposes only.
108 !%Option charged_particle 4
109 !% A charged classical particle.
110 !%Option dftbplus 5
111 !% A DFTB+ system
112 !%Option linear_medium 6
113 !% A linear medium for classical electrodynamics.
114 !%Option matter 7
115 !% A matter system containing electrons and classical ions.
116 !%Option dispersive_medium 8
117 !% (Experimental) A dispersive medium for classical electrodynamics.
118 !%Option multisystem 9
119 !% A system containing other systems.
120 !%Option ions 10
121 !% An ensemble of classical charged particles.
122 !%Option ensemble 11
123 !% An ensemble for multitrajectory runs
124 !%End
125 select case (type)
126 case (system_multisystem)
127
128 call parse_subsystems(namespace, names, types)
129
130 system => multisystem_basic_t(namespace, names, types, this, calc_mode_id)
131
132 safe_deallocate_a(names)
133 safe_deallocate_a(types)
134
135 case (system_electronic)
136 system => electrons_t(namespace, calc_mode_id)
137 case (system_maxwell)
138 system => maxwell_t(namespace)
140 system => classical_particle_t(namespace)
142 system => charged_particle_t(namespace)
143 case (system_dftbplus)
144 system => dftb_t(namespace)
146 system => linear_medium_t(namespace)
147 case (system_matter)
148 system => matter_t(namespace)
150 system => dispersive_medium_t(namespace)
151 call messages_experimental('dispersive_medium', namespace=namespace)
152 case (system_ions)
153 system => ions_t(namespace)
154 case (system_ensemble)
155 !%Variable NumberOfReplicas
156 !%Type integer
157 !%Default 1
158 !%Section System
159 !%Description
160 !% Number of replicas to be created for the ensemble.
161 !%End
162 call parse_variable(namespace, 'NumberOfReplicas', 1, n_replicas)
163 if (debug%info) then
164 write(message(1), '(a,i5,a)') "The ensemble has ", n_replicas, " replicas"
165 call messages_info(1, namespace=namespace)
166 end if
168 call parse_subsystems(namespace, names, types)
169
170 system => ensemble_t(namespace, n_replicas, this, names, types, calc_mode_id)
171
172 safe_deallocate_a(names)
173 safe_deallocate_a(types)
174
175 case default
176 call messages_input_error(namespace, 'Systems', 'Unknown system type.')
177 end select
178
179 pop_sub(system_factory_create)
180 end function system_factory_create
181
182
183 subroutine parse_subsystems(namespace, names, types)
184 type(namespace_t), intent(in) :: namespace
185 character(len=128), allocatable, intent(out) :: names(:)
186 integer, allocatable, intent(out) :: types(:)
187
188 integer :: n_systems, is, ic, iother
189 type(block_t) :: blk
190
191 ! Parse the input file to get the list of subsystems
192 if (parse_block(namespace, 'Systems', blk) == 0) then
193
194 n_systems = parse_block_n(blk)
195 safe_allocate(names(1:n_systems))
196 safe_allocate(types(1:n_systems))
197
198 do is = 1, n_systems
199 ! Parse system name and type
200 call parse_block_string(blk, is - 1, 0, names(is))
201 if (len_trim(names(is)) == 0) then
202 call messages_input_error(namespace, 'Systems', 'All systems must have a name')
203 end if
205 if (index(trim(names(is)), parser_varname_excluded_characters(ic:ic)) /= 0) then
206 call messages_input_error(namespace, 'Systems', &
207 'Illegal character "' // parser_varname_excluded_characters(ic:ic) // '" in system name', row=is-1, column=0)
208 end if
209 end do
210 call parse_block_integer(blk, is - 1, 1, types(is))
211
212 ! Check that the system name is unique
213 do iother = 1, is-1
214 if (names(is) == names(iother)) then
215 call messages_input_error(namespace, 'Systems', 'Duplicated system in multi-system', &
216 row=is-1, column=0)
217 end if
218 end do
219
220 end do
221 call parse_block_end(blk)
222 else
223 call messages_input_error(namespace, 'Systems', 'Missing Systems block')
224 end if
225
226 end subroutine parse_subsystems
227
228
229end module system_factory_oct_m
230
231!! Local Variables:
232!! mode: f90
233!! coding: utf-8
234!! End:
type(debug_t), save, public debug
Definition: debug.F90:158
This module implements the ensemble class.
Definition: ensemble.F90:109
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:118
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1063
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
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:158
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
Definition: parser.F90:810
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:615
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)
recursive class(system_t) function, pointer system_factory_create(this, namespace, type, calc_mode_id)
create a new system.
integer, parameter, public system_linear_medium
linear medium for Maxwell calculations (linear_medium_oct_m::linear_medium_t)
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:120
class for a charged classical particle
class for a neutral classical particle
class for a tight binding
Definition: dftb.F90:160
dispersive medium for classical electrodynamics calculations
Class describing the electron system.
Definition: electrons.F90:220
the ensemble class
Definition: ensemble.F90:140
linear medium for classical electrodynamics
container class for for electrons and ions
Definition: matter.F90:138
Class describing Maxwell systems.
Definition: maxwell.F90:197
Container class for lists of system_oct_m::system_t.
factory for classes, derived from the abstract system_cot_m::system_t class