Octopus
run.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2020 M. Oliveira
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
24module run_oct_m
25 use accel_oct_m
26 use casida_oct_m
30 use fft_oct_m
32 use global_oct_m
37 use lasers_oct_m
40 use mpi_oct_m
46 use parser_oct_m
51 use kdotp_oct_m
53 use pulpo_oct_m
57 use system_oct_m
58 use td_oct_m
59 use test_oct_m
62 use unocc_oct_m
64 use vdw_oct_m
65
66 implicit none
67
68 private
69 public :: &
70 run
71
72 integer, parameter :: LR = 1, fd = 2
73
74contains
75
76 ! ---------------------------------------------------------
78 integer function get_resp_method(namespace)
79 type(namespace_t), intent(in) :: namespace
80
81 push_sub(get_resp_method)
82
83 !%Variable ResponseMethod
84 !%Type integer
85 !%Default sternheimer
86 !%Section Linear Response
87 !%Description
88 !% Some response properties can be calculated either via
89 !% Sternheimer linear response or by using finite
90 !% differences. You can use this variable to select how you want
91 !% them to be calculated, it applies to <tt>em_resp</tt> and <tt>vib_modes</tt>
92 !% calculation modes. By default, the Sternheimer linear-response
93 !% technique is used.
94 !%Option sternheimer 1
95 !% The linear response is obtained by solving a self-consistent
96 !% Sternheimer equation for the variation of the orbitals. This
97 !% is the recommended method.
98 !%Option finite_differences 2
99 !% Properties are calculated as a finite-differences derivative of
100 !% the energy obtained by several ground-state calculations. This
101 !% method, slow and limited only to static response, is kept
102 !% mainly because it is simple and useful for testing purposes.
103 !%End
104
105 call parse_variable(namespace, 'ResponseMethod', lr, get_resp_method)
106
107 if (.not. varinfo_valid_option('ResponseMethod', get_resp_method)) then
108 call messages_input_error(namespace, 'ResponseMethod')
109 end if
110
111 pop_sub(get_resp_method)
112 end function get_resp_method
113
114 ! ---------------------------------------------------------
118 subroutine run(namespace, calc_mode_id)
119 type(namespace_t), intent(in) :: namespace
120 integer, intent(in) :: calc_mode_id
121
122 type(partner_list_t) :: partners
123 class(system_t), pointer :: systems
124 type(system_factory_t) :: system_factory
125 type(interactions_factory_t) :: interactions_factory
126 logical :: from_scratch
127 integer :: iunit_out
128 type(partner_iterator_t) :: iter
129 class(interaction_partner_t), pointer :: partner
130
131 push_sub(run)
132
133 call messages_print_with_emphasis(msg="Calculation Mode", namespace=namespace)
134 call messages_print_var_option("CalculationMode", calc_mode_id, namespace=namespace)
135 call messages_print_with_emphasis(namespace=namespace)
136
137 call calc_mode_init()
138
139 if (calc_mode_id == option__calculationmode__recipe) then
140 call pulpo_print()
141 pop_sub(run)
142 return
143 end if
144
145 call restart_module_init(namespace)
146
147 call unit_system_init(namespace)
148
149 call accel_init(mpi_world, namespace)
150
151 ! initialize FFTs
152 call fft_all_init(namespace)
153
154 if (calc_mode_id == option__calculationmode__test) then
155 call test_run(namespace)
156 call fft_all_end()
158 pop_sub(run)
159 return
160 end if
161
162 ! Create systems
163 if (parse_is_defined(namespace, "Systems")) then
164 ! We are running in multi-system mode
165 systems => system_factory%create(namespace, system_multisystem)
166 else
167 ! Fall back to old behaviour
168 systems => electrons_t(namespace, generate_epot = calc_mode_id /= option__calculationmode__dummy)
169 end if
170
171 ! initialize everything that needs parallelization
172 call systems%init_parallelization(mpi_world)
173
174 ! Create list of partners
175 select type (systems)
176 class is (multisystem_basic_t)
177 ! Systems are also partners
178 partners = systems%list
179 ! Add external potentials to partners list
180 call load_external_potentials(partners, namespace)
181
182 call load_external_waves(partners, namespace)
183
184 ! Add lasers to the partner list
185 call load_lasers(partners, namespace)
186
187 type is (electrons_t)
188 call partners%add(systems)
189 end select
190
191 ! Initialize algorithms (currently only propagators are supported)
192 select type (systems)
193 class is (multisystem_basic_t)
194 select case (calc_mode_id)
195 case (option__calculationmode__td)
196 call systems%init_algorithm(propagator_factory_t(systems%namespace))
197 end select
198 end select
199
200 ![create_interactions] !doxygen marker. Dont delete
201 ! Create and initialize interactions
202 !
203 ! This function is called recursively for all subsystems of systems.
204 ! If systems is a multisystem_basic_t container, the partners list contains all subsystems.
205 call systems%create_interactions(interactions_factory, partners)
206 ![create_interactions]
207
208 select type (systems)
209 class is (multisystem_basic_t)
210 ! Write the interaction graph as a DOT graph for debug
211 if ((debug%interaction_graph .or. debug%interaction_graph_full) .and. mpi_grp_is_root(mpi_world)) then
212 iunit_out = io_open('debug/interaction_graph.dot', systems%namespace, action='write')
213 write(iunit_out, '(a)') 'digraph {'
214 call systems%write_interaction_graph(iunit_out, debug%interaction_graph_full)
215 write(iunit_out, '(a)') '}'
216 call io_close(iunit_out)
217 end if
218 end select
219
220 if (.not. systems%process_is_slave()) then
221 call messages_write('Info: Octopus initialization completed.', new_line = .true.)
222 call messages_write('Info: Starting calculation mode.')
223 call messages_info(namespace=namespace)
224
225 !%Variable FromScratch
226 !%Type logical
227 !%Default false
228 !%Section Execution
229 !%Description
230 !% When this variable is set to true, <tt>Octopus</tt> will perform a
231 !% calculation from the beginning, without looking for restart
232 !% information.
233 !% NOTE: If available, mesh partitioning information will be used for
234 !% initializing the calculation regardless of the set value for this variable.
235 !%End
236 call parse_variable(namespace, 'FromScratch', .false., from_scratch)
237
238 call profiling_in("CALC_MODE")
239
240 select case (calc_mode_id)
241 case (option__calculationmode__gs)
242 call ground_state_run(systems, from_scratch)
243 case (option__calculationmode__unocc)
244 call unocc_run(systems, from_scratch)
245 case (option__calculationmode__td)
246 call time_dependent_run(systems, from_scratch)
247 case (option__calculationmode__go)
248 call geom_opt_run(systems, from_scratch)
249 case (option__calculationmode__opt_control)
250 call opt_control_run(systems)
251 case (option__calculationmode__em_resp)
252 select case (get_resp_method(namespace))
253 case (fd)
254 call static_pol_run(systems, from_scratch)
255 case (lr)
256 call em_resp_run(systems, from_scratch)
257 end select
258 case (option__calculationmode__casida)
259 call casida_run(systems, from_scratch)
260 case (option__calculationmode__vdw)
261 call vdw_run(systems, from_scratch)
262 case (option__calculationmode__vib_modes)
263 select case (get_resp_method(namespace))
264 case (fd)
265 call phonons_run(systems)
266 case (lr)
267 call phonons_lr_run(systems, from_scratch)
268 end select
269 case (option__calculationmode__one_shot)
270 message(1) = "CalculationMode = one_shot is obsolete. Please use gs with MaximumIter = 0."
271 call messages_fatal(1, namespace=namespace)
272 case (option__calculationmode__kdotp)
273 call kdotp_lr_run(systems, from_scratch)
274 case (option__calculationmode__dummy)
275 case (option__calculationmode__invert_ks)
276 call invert_ks_run(systems)
277 case (option__calculationmode__recipe)
278 assert(.false.) !this is handled before, if we get here, it is an error
279 end select
280
281 call profiling_out("CALC_MODE")
282 end if
283
284 select type (systems)
285 class is (multisystem_basic_t)
286 !Deallocate the external potentials
287 call iter%start(partners)
288 do while (iter%has_next())
289 select type(ptr => iter%get_next())
290 class is(external_potential_t)
291 partner => ptr
292 safe_deallocate_p(partner)
293 class is(external_waves_t)
294 partner => ptr
295 safe_deallocate_p(partner)
296 class is(lasers_t)
297 partner => ptr
298 safe_deallocate_p(partner)
299 end select
300 end do
301 end select
302
303 ! Finalize systems
304 safe_deallocate_p(systems)
305
306 call fft_all_end()
307
309
311
312 pop_sub(run)
313
314 contains
315
316 subroutine calc_mode_init()
317
318 push_sub(calc_mode_init)
319
320 select case (calc_mode_id)
321 case (option__calculationmode__gs, option__calculationmode__go, option__calculationmode__unocc)
323 case (option__calculationmode__td)
324 call td_run_init()
325 case (option__calculationmode__casida)
326 call casida_run_init()
327 end select
328
329 pop_sub(calc_mode_init)
330 end subroutine calc_mode_init
331
332 end subroutine run
333
334end module run_oct_m
335
336!! Local Variables:
337!! mode: f90
338!! coding: utf-8
339!! End:
subroutine, public accel_init(base_grp, namespace)
Definition: accel.F90:420
subroutine, public accel_end(namespace)
Definition: accel.F90:1056
This module implements the Casida equations for excited states.
Definition: casida.F90:118
subroutine, public casida_run_init()
Definition: casida.F90:284
subroutine, public casida_run(system, from_scratch)
Definition: casida.F90:313
subroutine, public em_resp_run(system, from_scratch)
Definition: em_resp.F90:232
subroutine, public load_external_potentials(external_potentials, namespace)
subroutine, public load_external_waves(partners, namespace)
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:118
subroutine, public fft_all_init(namespace)
initialize the table
Definition: fft.F90:277
subroutine, public fft_all_end()
delete all plans
Definition: fft.F90:390
subroutine, public geom_opt_run(system, from_scratch)
Definition: geom_opt.F90:207
subroutine, public ground_state_run_init()
subroutine, public ground_state_run(system, from_scratch)
This module defines classes and functions for interaction partners.
subroutine, public invert_ks_run(system)
Definition: invert_ks.F90:148
subroutine, public kdotp_lr_run(system, from_scratch)
Definition: kdotp.F90:184
subroutine, public load_lasers(partners, namespace)
Definition: lasers.F90:1224
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:930
character(len=512), private msg
Definition: messages.F90:165
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_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:420
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:723
subroutine, public mpi_debug_statistics()
Definition: mpi_debug.F90:205
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
Definition: mpi.F90:430
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:266
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
This module implements the basic mulsisystem class, a container system for other systems.
This module implements the multisystem debug functionality.
type(namespace_t), public global_namespace
Definition: namespace.F90:132
This module contains the main procedure ("opt_control_run") that is used when optimal control runs ar...
subroutine, public opt_control_run(system)
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:502
subroutine, public phonons_run(system)
Definition: phonons_fd.F90:154
subroutine, public phonons_lr_run(system, from_scratch)
Definition: phonons_lr.F90:170
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:623
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:552
This module implements the factory for propagators.
subroutine, public pulpo_print()
Definition: pulpo.F90:129
subroutine, public restart_module_init(namespace)
Definition: restart.F90:306
top level module for all calculation modes
Definition: run.F90:117
integer function get_resp_method(namespace)
query input file for the response mode.
Definition: run.F90:172
integer, parameter fd
Definition: run.F90:165
subroutine, public run(namespace, calc_mode_id)
main routine to run all calculations: This routine parses the input file, sets up the systems and int...
Definition: run.F90:212
subroutine, public static_pol_run(system, from_scratch)
Definition: static_pol.F90:157
integer, parameter, public system_multisystem
container system. (multisystem_basic_oct_m::multisystem_basic_t)
This module implements the abstract system type.
Definition: system.F90:118
Definition: td.F90:114
subroutine, public td_run_init()
Definition: td.F90:236
This module implements a unit-test like runmode for Octopus.
Definition: test.F90:116
subroutine, public test_run(namespace)
Definition: test.F90:206
subroutine, public time_dependent_run(system, from_scratch)
This module defines the unit system, used for input and output.
subroutine, public unit_system_init(namespace)
subroutine, public unocc_run(system, from_scratch)
Definition: unocc.F90:157
subroutine, public vdw_run(system, from_scratch)
Definition: vdw.F90:152
subroutine calc_mode_init()
Definition: run.F90:410
Container class for lists of system_oct_m::system_t.
This class defines the factory for propagators.
int true(void)