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
22
25 use debug_oct_m
26 use dftb_oct_m
30 use global_oct_m
31 use ions_oct_m
33 use matter_oct_m
38 use parser_oct_m
41 use system_oct_m
43 implicit none
44
45 private
46 public :: &
48
49
50 !# doc_start system_types
51 integer, parameter, public :: &
52 SYSTEM_ELECTRONIC = 1, & !< electronic system (electrons_oct_m::electrons_t)
53 system_maxwell = 2, &
56 system_dftbplus = 5, &
58 system_matter = 7, &
60 ! !! (dispersive_medium_oct_m::dispersive_medium_t)
61 system_multisystem = 9, &
62 system_ions = 10, &
63 system_ensemble = 11
64 !# doc_end
65
72 contains
73 procedure :: create => system_factory_create
74 end type system_factory_t
75
76contains
77
78 ! ---------------------------------------------------------------------------------------
82 recursive function system_factory_create(this, namespace, type, calc_mode_id) result(system)
83 class(system_factory_t), intent(in) :: this
84 type(namespace_t), intent(in) :: namespace
85 integer, intent(in) :: type
86 integer, intent(in) :: calc_mode_id
87 class(system_t), pointer :: system
88
89 integer :: n_replicas, first, last
90 character(len=128), allocatable :: names(:)
91 integer, allocatable :: types(:)
92
93 push_sub(system_factory_create)
94
95 !%Variable Systems
96 !%Type block
97 !%Section System
98 !%Description
99 !% List of systems that will be treated in the calculation.
100 !% The first column should be a string containing the system name.
101 !% The second column should be the system type. See below for a list of
102 !% available system types.
103 !%Option electronic 1
104 !% An electronic system. (not fully implemented yet)
105 !%Option maxwell 2
106 !% A maxwell system.
107 !%Option classical_particle 3
108 !% A classical particle. Used for testing purposes only.
109 !%Option charged_particle 4
110 !% A charged classical particle.
111 !%Option dftbplus 5
112 !% A DFTB+ system
113 !%Option linear_medium 6
114 !% A linear medium for classical electrodynamics.
115 !%Option matter 7
116 !% A matter system containing electrons and classical ions.
117 !%Option dispersive_medium 8
118 !% (Experimental) A dispersive medium for classical electrodynamics.
119 !%Option multisystem 9
120 !% A system containing other systems.
121 !%Option ions 10
122 !% An ensemble of classical charged particles.
123 !%Option ensemble 11
124 !% An ensemble for multitrajectory runs
125 !%End
126 select case (type)
127 case (system_multisystem)
128
129 call parse_subsystems(namespace, names, types)
130
131 system => multisystem_basic_t(namespace, names, types, this, calc_mode_id)
132
133 safe_deallocate_a(names)
134 safe_deallocate_a(types)
135
136 case (system_electronic)
137 system => electrons_t(namespace, calc_mode_id)
138 case (system_maxwell)
139 system => maxwell_t(namespace)
141 system => classical_particle_t(namespace)
143 system => charged_particle_t(namespace)
144 case (system_dftbplus)
145 system => dftb_t(namespace)
147 system => linear_medium_t(namespace)
148 case (system_matter)
149 system => matter_t(namespace)
151 system => dispersive_medium_t(namespace)
152 call messages_experimental('dispersive_medium', namespace=namespace)
153 case (system_ions)
154 system => ions_t(namespace)
155 case (system_ensemble)
156 !%Variable NumberOfReplicas
157 !%Type integer
158 !%Default 1
159 !%Section System
160 !%Description
161 !% Number of replicas to be created for the ensemble.
162 !%End
163 call parse_variable(namespace, 'NumberOfReplicas', 1, n_replicas)
164 if (debug%info) then
165 write(message(1), '(a,i5,a)') "The ensemble has ", n_replicas, " replicas"
166 call messages_info(1, namespace=namespace)
167 end if
169 !%Variable FirstReplica
170 !%Type integer
171 !%Default 1
172 !%Section Multi-Trajectory
173 !%Description
174 !% First replica to be calculated in this run.
175 !%End
176 call parse_variable(namespace, 'FirstReplica', 1, first)
178 !%Variable LastReplica
179 !%Type integer
180 !%Default 0
181 !%Section Multi-Trajectory
182 !%Description
183 !% Last replica to be calculated in this run.
184 !%End
185 call parse_variable(namespace, 'LastReplica', n_replicas, last)
186
187 call parse_subsystems(namespace, names, types)
188
189 system => ensemble_t(namespace, n_replicas, first, last, this, names, types, calc_mode_id)
190
191 safe_deallocate_a(names)
192 safe_deallocate_a(types)
193
194 case default
195 call messages_input_error(namespace, 'Systems', 'Unknown system type.')
196 end select
197
198 pop_sub(system_factory_create)
199 end function system_factory_create
200
201
202 subroutine parse_subsystems(namespace, names, types)
203 type(namespace_t), intent(in) :: namespace
204 character(len=128), allocatable, intent(out) :: names(:)
205 integer, allocatable, intent(out) :: types(:)
206
207 integer :: n_systems, is, ic, iother
208 type(block_t) :: blk
209
210 ! Parse the input file to get the list of subsystems
211 if (parse_block(namespace, 'Systems', blk) == 0) then
212
213 n_systems = parse_block_n(blk)
214 safe_allocate(names(1:n_systems))
215 safe_allocate(types(1:n_systems))
216
217 do is = 1, n_systems
218 ! Parse system name and type
219 call parse_block_string(blk, is - 1, 0, names(is))
220 if (len_trim(names(is)) == 0) then
221 call messages_input_error(namespace, 'Systems', 'All systems must have a name')
222 end if
224 if (index(trim(names(is)), parser_varname_excluded_characters(ic:ic)) /= 0) then
225 call messages_input_error(namespace, 'Systems', &
226 'Illegal character "' // parser_varname_excluded_characters(ic:ic) // '" in system name', row=is-1, column=0)
227 end if
228 end do
229 call parse_block_integer(blk, is - 1, 1, types(is))
230
231 ! Check that the system name is unique
232 do iother = 1, is-1
233 if (names(is) == names(iother)) then
234 call messages_input_error(namespace, 'Systems', 'Duplicated system in multi-system', &
235 row=is-1, column=0)
236 end if
237 end do
238
239 end do
240 call parse_block_end(blk)
241 else
242 call messages_input_error(namespace, 'Systems', 'Missing Systems block')
243 end if
244
245 end subroutine parse_subsystems
246
247
248end module system_factory_oct_m
249
250!! Local Variables:
251!! mode: f90
252!! coding: utf-8
253!! 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