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