Octopus
electrons_ground_state.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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 use debug_oct_m
24 use global_oct_m
25 use grid_oct_m
29 use ions_oct_m
31 use lcao_oct_m
32 use math_oct_m
33 use mesh_oct_m
38 use pcm_oct_m
39 use rdmft_oct_m
41 use scf_oct_m
42 use space_oct_m
46 use v_ks_oct_m
47 use mpi_oct_m
48
49 implicit none
50
51 private
52 public :: &
57 gs_run, &
59
60contains
61
62 ! ---------------------------------------------------------
63 subroutine electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
64 type(namespace_t), intent(in) :: namespace
65 type(multicomm_t), intent(in) :: mc
66 type(grid_t), intent(inout) :: gr
67 type(ions_t), intent(inout) :: ions
68 type(partner_list_t), intent(in) :: ext_partners
69 type(states_elec_t), intent(inout) :: st
70 type(v_ks_t), intent(inout) :: ks
71 type(hamiltonian_elec_t), intent(inout) :: hm
72 type(output_t), intent(in) :: outp
73 type(electron_space_t), intent(in) :: space
74 logical, intent(inout) :: fromScratch
75
76 type(rdm_t) :: rdm
77 type(scf_t) :: scf
78
79 push_sub(ground_state_run_legacy)
80
81 call gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions, mc, space)
82
83 if (.not. fromscratch) then
84 call gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromscratch)
85 end if
86
87 call gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromscratch)
88
89 call gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
90
91 call gs_cleanup(ks, scf, rdm, st, hm)
92
93 pop_sub(ground_state_run_legacy)
94 end subroutine electrons_ground_state_run
95
96 ! ---------------------------------------------------------
97 subroutine gs_cleanup(ks, scf, rdm, st, hm)
98 type(v_ks_t), intent(inout) :: ks
99 type(scf_t), intent(inout) :: scf
100 type(rdm_t), intent(inout) :: rdm
101 type(states_elec_t), intent(inout) :: st
102 type(hamiltonian_elec_t), intent(inout) :: hm
103
104 push_sub(gs_cleanup)
105
106 if (ks%theory_level == rdmft) then
107 call rdmft_end(rdm)
108 else
109 call scf_end(scf)
110 end if
111
112 if (scf%restart_dump%get_data_type() /= restart_undefined) then
113 call restart_end(scf%restart_dump)
114 end if
115
116 if (st%pack_states .and. hm%apply_packed()) then
117 call st%unpack()
118 end if
119
120 ! clean up
122
123 pop_sub(gs_cleanup)
124 end subroutine gs_cleanup
125
126 ! ---------------------------------------------------------
127 subroutine gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions, mc, space)
128 type(namespace_t), intent(in) :: namespace
129 type(grid_t), intent(inout) :: gr
130 type(states_elec_t), intent(inout) :: st
131 type(hamiltonian_elec_t), intent(inout) :: hm
132 type(scf_t), intent(inout) :: scf
133 type(v_ks_t), intent(inout) :: ks
134 type(ions_t), intent(inout) :: ions
135 type(multicomm_t), intent(in) :: mc
136 type(electron_space_t), intent(in) :: space
137
139
140 call messages_write('Info: Allocating ground state wave-functions')
141 call messages_info(namespace=namespace)
142
143 if (st%parallel_in_states) then
144 call messages_experimental('State parallelization for ground state calculations', namespace=namespace)
145 end if
146
147 if (hm%pcm%run_pcm) then
148 if (.not. is_close(hm%pcm%epsilon_infty, hm%pcm%epsilon_0) .and. hm%pcm%tdlevel /= pcm_td_eq) then
149 message(1) = 'Non-equilbrium PCM is not active in a time-independent run.'
150 message(2) = 'You set epsilon_infty /= epsilon_0, but epsilon_infty is not relevant for CalculationMode = gs.'
151 message(3) = 'By definition, the ground state is in equilibrium with the solvent.'
152 message(4) = 'Therefore, the only relevant dielectric constant is the static one.'
153 message(5) = 'Nevertheless, the dynamical PCM response matrix is evaluated for benchamarking purposes.'
154 call messages_warning(5, namespace=namespace)
155 end if
156 end if
157
158 call states_elec_allocate_wfns(st, gr, packed=.true.)
159
160 ! sometimes a deadlock can occur here (if some nodes can allocate and other cannot)
161 if (st%dom_st_kpt_mpi_grp%comm /= mpi_comm_undefined &
162 .and. st%dom_st_kpt_mpi_grp%comm /= mpi_comm_null) then
163 call st%dom_st_kpt_mpi_grp%barrier()
164 end if
165 call messages_write('Info: Ground-state allocation done.')
166 call messages_info(namespace=namespace)
167
169 end subroutine gs_allocate_wavefunctions
170
171 ! ---------------------------------------------------------
172 subroutine gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
173 type(namespace_t), intent(in) :: namespace
174 type(scf_t), intent(inout) :: scf
175 type(grid_t), intent(inout) :: gr
176 type(multicomm_t), intent(in) :: mc
177 type(states_elec_t), intent(inout) :: st
178 type(hamiltonian_elec_t), intent(inout) :: hm
179 type(v_ks_t), intent(inout) :: ks
180 type(electron_space_t), intent(in) :: space
181 type(ions_t), intent(in) :: ions
182 type(partner_list_t), intent(in) :: ext_partners
183 logical, intent(inout) :: fromscratch
184
185 integer :: ierr
186
187 push_sub(gs_load_from_restart)
188
189 ! load wavefunctions
190 ! in RDMFT we need the full ground state
191 call restart_init(scf%restart_load, namespace, restart_gs, restart_type_load, mc, ierr, mesh=gr, &
192 exact = (ks%theory_level == rdmft))
193 if (ierr == 0) then
194 call states_elec_load(scf%restart_load, namespace, space, st, gr, hm%kpoints, ierr)
195 end if
196
197 if (ierr /= 0) then
198 call messages_write("Unable to read wavefunctions.")
199 call messages_new_line()
200 call messages_write("Starting from scratch!")
201 call messages_warning(namespace=namespace)
202 fromscratch = .true.
203 end if
204
205 pop_sub(gs_load_from_restart)
206 end subroutine gs_load_from_restart
207
208 ! ---------------------------------------------------------
209 subroutine gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
210 type(namespace_t), intent(in) :: namespace
211 type(scf_t), intent(inout) :: scf
212 type(rdm_t), intent(inout) :: rdm
213 type(grid_t), intent(inout) :: gr
214 type(multicomm_t), intent(in) :: mc
215 type(states_elec_t), intent(inout) :: st
216 type(hamiltonian_elec_t), intent(inout) :: hm
217 type(ions_t), intent(in) :: ions
218 type(v_ks_t), intent(inout) :: ks
219 type(electron_space_t), intent(in) :: space
220 type(partner_list_t), intent(in) :: ext_partners
221 logical, intent(in) :: fromscratch
222
223 integer :: ierr
224 logical :: restart_init_dump
225
226 push_sub(gs_initialize)
227
228 call write_canonicalized_xyz_file("exec", "initial_coordinates", space, ions%latt, ions%pos, ions%atom, &
229 gr%box, namespace)
230
231 if (ks%theory_level /= rdmft) then
232 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
233 ! only initialize dumping restart files for more than one iteration
234 restart_init_dump = scf%max_iter > 0
235 else
236 restart_init_dump = .true.
237 end if
238
239 if (fromscratch .and. ks%theory_level /= rdmft) then
240 call lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, lmm_r = scf%lmm_r)
241 else
242 ! setup Hamiltonian
243 call messages_write('Info: Setting up Hamiltonian.')
244 call messages_info(namespace=namespace)
245 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
246 calc_eigenval = .false., calc_current = .false.)
247 end if
248
249 if (restart_init_dump) then
250 call restart_init(scf%restart_dump, namespace, restart_gs, restart_type_dump, mc, ierr, mesh=gr)
251 end if
252
253 ! run self-consistency
254 call scf_state_info(namespace, st)
255
256 if (st%pack_states .and. hm%apply_packed()) then
257 call st%pack()
258 end if
259
260 if (ks%theory_level == rdmft) then
261 call rdmft_init(rdm, namespace, gr, st, mc, space, fromscratch)
262 end if
263
264 if (.not. fromscratch) then
265 call scf_load(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, scf%restart_load)
266 call restart_end(scf%restart_load)
267 end if
268 pop_sub(gs_initialize)
269 end subroutine gs_initialize
270
271 ! ---------------------------------------------------------
272 subroutine gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
273 type(namespace_t), intent(in) :: namespace
274 type(scf_t), intent(inout) :: scf
275 type(rdm_t), intent(inout) :: rdm
276 type(multicomm_t), intent(in) :: mc
277 type(grid_t), intent(inout) :: gr
278 type(ions_t), intent(inout) :: ions
279 type(partner_list_t), intent(in) :: ext_partners
280 type(states_elec_t), intent(inout) :: st
281 type(v_ks_t), intent(inout) :: ks
282 type(hamiltonian_elec_t), intent(inout) :: hm
283 type(output_t), intent(in) :: outp
284 type(electron_space_t), intent(in) :: space
285
286 push_sub(gs_run)
287
288 ! self-consistency for occupation numbers and natural orbitals in RDMFT
289 if (ks%theory_level == rdmft) then
290 call scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, scf%restart_dump)
291 else
292 if (scf%restart_dump%get_data_type() /= restart_undefined) then
293 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, &
294 restart_dump=scf%restart_dump)
295 else
296 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp)
297 end if
298 end if
299
300 pop_sub(gs_run)
301 end subroutine gs_run
303
305
306!! Local Variables:
307!! mode: f90
308!! coding: utf-8
309!! End:
subroutine, public electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
subroutine, public gs_cleanup(ks, scf, rdm, st, hm)
subroutine, public gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
subroutine, public gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
subroutine, public gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions, mc, space)
subroutine, public gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
This module implements the underlying real-space grid.
Definition: grid.F90:117
This module defines classes and functions for interaction partners.
subroutine, public write_canonicalized_xyz_file(dir, fname, space, latt, pos, atoms, box, namespace)
Write canonicalized xyz file with atom labels and positions in Angstroms. Includes information about ...
A module to handle KS potential, without the external potential.
integer, parameter, public rdmft
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
Definition: lcao.F90:796
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:537
subroutine, public messages_new_line()
Definition: messages.F90:1134
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1085
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:616
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:136
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
this module contains the low-level part of the output system
Definition: output_low.F90:115
integer, parameter, public pcm_td_eq
Definition: pcm.F90:273
subroutine, public rdmft_end(rdm)
Definition: rdmft.F90:346
subroutine, public rdmft_init(rdm, namespace, gr, st, mc, space, fromScratch)
Definition: rdmft.F90:212
subroutine, public scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, restart_dump)
Definition: rdmft.F90:376
integer, parameter, public restart_undefined
Definition: restart.F90:200
integer, parameter, public restart_gs
Definition: restart.F90:200
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:516
integer, parameter, public restart_type_dump
Definition: restart.F90:245
integer, parameter, public restart_type_load
Definition: restart.F90:245
subroutine, public restart_end(restart)
Definition: restart.F90:722
subroutine, public scf_load(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, restart_load)
Loading of restarting data of the SCF cycle.
Definition: scf.F90:590
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1540
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:254
subroutine, public scf_end(scf)
Definition: scf.F90:543
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_dump)
Legacy version of the SCF code.
Definition: scf.F90:819
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:677
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:168
Stores all communicators and groups.
Definition: multicomm.F90:206
output handler class
Definition: output_low.F90:164
some variables used for the SCF cycle
Definition: scf.F90:209
The states_elec_t class contains all electronic wave functions.
int true(void)