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