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
30 use lcao_oct_m
31 use math_oct_m
32 use mesh_oct_m
37 use pcm_oct_m
38 use rdmft_oct_m
40 use scf_oct_m
41 use space_oct_m
45 use v_ks_oct_m
46 use mpi_oct_m
47
48 implicit none
49
50 private
51 public :: &
56 gs_run, &
58
59contains
60
61 ! ---------------------------------------------------------
62 subroutine electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
63 type(namespace_t), intent(in) :: namespace
64 type(multicomm_t), intent(in) :: mc
65 type(grid_t), intent(inout) :: gr
66 type(ions_t), intent(inout) :: ions
67 type(partner_list_t), intent(in) :: ext_partners
68 type(states_elec_t), intent(inout) :: st
69 type(v_ks_t), intent(inout) :: ks
70 type(hamiltonian_elec_t), intent(inout) :: hm
71 type(output_t), intent(in) :: outp
72 type(electron_space_t), intent(in) :: space
73 logical, intent(inout) :: fromScratch
74
75 type(rdm_t) :: rdm
76 type(scf_t) :: scf
77
78 push_sub(ground_state_run_legacy)
79
80 call gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions, mc, space)
81
82 if (.not. fromscratch) then
83 call gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromscratch)
84 end if
85
86 call gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromscratch)
87
88 call gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
89
90 call gs_cleanup(ks, scf, rdm, st, hm)
91
92 pop_sub(ground_state_run_legacy)
93 end subroutine electrons_ground_state_run
94
95 ! ---------------------------------------------------------
96 subroutine gs_cleanup(ks, scf, rdm, st, hm)
97 type(v_ks_t), intent(inout) :: ks
98 type(scf_t), intent(inout) :: scf
99 type(rdm_t), intent(inout) :: rdm
100 type(states_elec_t), intent(inout) :: st
101 type(hamiltonian_elec_t), intent(inout) :: hm
102
103 push_sub(gs_cleanup)
104
105 if (ks%theory_level == rdmft) then
106 call rdmft_end(rdm)
107 else
108 call scf_end(scf)
109 end if
110
111 if (scf%restart_dump%get_data_type() /= restart_undefined) then
112 call restart_end(scf%restart_dump)
113 end if
115 if (st%pack_states .and. hm%apply_packed()) then
116 call st%unpack()
117 end if
118
119 ! clean up
121
122 pop_sub(gs_cleanup)
123 end subroutine gs_cleanup
124
125 ! ---------------------------------------------------------
126 subroutine gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions, mc, space)
127 type(namespace_t), intent(in) :: namespace
128 type(grid_t), intent(inout) :: gr
129 type(states_elec_t), intent(inout) :: st
130 type(hamiltonian_elec_t), intent(inout) :: hm
131 type(scf_t), intent(inout) :: scf
132 type(v_ks_t), intent(inout) :: ks
133 type(ions_t), intent(inout) :: ions
134 type(multicomm_t), intent(in) :: mc
135 type(electron_space_t), intent(in) :: space
136
138
139 call messages_write('Info: Allocating ground state wave-functions')
140 call messages_info(namespace=namespace)
141
142 if (st%parallel_in_states) then
143 call messages_experimental('State parallelization for ground state calculations', namespace=namespace)
144 end if
145
146 if (hm%pcm%run_pcm) then
147 if (.not. is_close(hm%pcm%epsilon_infty, hm%pcm%epsilon_0) .and. hm%pcm%tdlevel /= pcm_td_eq) then
148 message(1) = 'Non-equilbrium PCM is not active in a time-independent run.'
149 message(2) = 'You set epsilon_infty /= epsilon_0, but epsilon_infty is not relevant for CalculationMode = gs.'
150 message(3) = 'By definition, the ground state is in equilibrium with the solvent.'
151 message(4) = 'Therefore, the only relevant dielectric constant is the static one.'
152 message(5) = 'Nevertheless, the dynamical PCM response matrix is evaluated for benchamarking purposes.'
153 call messages_warning(5, namespace=namespace)
154 end if
155 end if
156
157 call states_elec_allocate_wfns(st, gr, packed=.true.)
158
159 ! sometimes a deadlock can occur here (if some nodes can allocate and other cannot)
160 if (st%dom_st_kpt_mpi_grp%comm /= mpi_comm_undefined &
161 .and. st%dom_st_kpt_mpi_grp%comm /= mpi_comm_null) then
162 call st%dom_st_kpt_mpi_grp%barrier()
163 end if
164 call messages_write('Info: Ground-state allocation done.')
165 call messages_info(namespace=namespace)
166
168 end subroutine gs_allocate_wavefunctions
169
170 ! ---------------------------------------------------------
171 subroutine gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
172 type(namespace_t), intent(in) :: namespace
173 type(scf_t), intent(inout) :: scf
174 type(grid_t), intent(inout) :: gr
175 type(multicomm_t), intent(in) :: mc
176 type(states_elec_t), intent(inout) :: st
177 type(hamiltonian_elec_t), intent(inout) :: hm
178 type(v_ks_t), intent(inout) :: ks
179 type(electron_space_t), intent(in) :: space
180 type(ions_t), intent(in) :: ions
181 type(partner_list_t), intent(in) :: ext_partners
182 logical, intent(inout) :: fromscratch
183
184 integer :: ierr
185
186 push_sub(gs_load_from_restart)
187
188 ! load wavefunctions
189 ! in RDMFT we need the full ground state
190 call restart_init(scf%restart_load, namespace, restart_gs, restart_type_load, mc, ierr, mesh=gr, &
191 exact = (ks%theory_level == rdmft))
192 if (ierr == 0) then
193 call states_elec_load(scf%restart_load, namespace, space, st, gr, hm%kpoints, ierr)
194 end if
195
196 if (ierr /= 0) then
197 call messages_write("Unable to read wavefunctions.")
198 call messages_new_line()
199 call messages_write("Starting from scratch!")
200 call messages_warning(namespace=namespace)
201 fromscratch = .true.
202 end if
203
204 pop_sub(gs_load_from_restart)
205 end subroutine gs_load_from_restart
206
207 ! ---------------------------------------------------------
208 subroutine gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
209 type(namespace_t), intent(in) :: namespace
210 type(scf_t), intent(inout) :: scf
211 type(rdm_t), intent(inout) :: rdm
212 type(grid_t), intent(inout) :: gr
213 type(multicomm_t), intent(in) :: mc
214 type(states_elec_t), intent(inout) :: st
215 type(hamiltonian_elec_t), intent(inout) :: hm
216 type(ions_t), intent(in) :: ions
217 type(v_ks_t), intent(inout) :: ks
218 type(electron_space_t), intent(in) :: space
219 type(partner_list_t), intent(in) :: ext_partners
220 logical, intent(in) :: fromscratch
221
222 integer :: ierr
223 logical :: restart_init_dump
224
225 push_sub(gs_initialize)
226
227 call write_canonicalized_xyz_file("exec", "initial_coordinates", space, ions%latt, ions%pos, ions%atom, &
228 gr%box, namespace)
229
230 if (ks%theory_level /= rdmft) then
231 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
232 ! only initialize dumping restart files for more than one iteration
233 restart_init_dump = scf%max_iter > 0
234 else
235 restart_init_dump = .true.
236 end if
237
238 if (fromscratch .and. ks%theory_level /= rdmft) then
239 call lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, lmm_r = scf%lmm_r)
240 else
241 ! setup Hamiltonian
242 call messages_write('Info: Setting up Hamiltonian.')
243 call messages_info(namespace=namespace)
244 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
245 calc_eigenval = .false., calc_current = .false.)
246 end if
247
248 if (restart_init_dump) then
249 call restart_init(scf%restart_dump, namespace, restart_gs, restart_type_dump, mc, ierr, mesh=gr)
250 end if
251
252 ! run self-consistency
253 call scf_state_info(namespace, st)
254
255 if (st%pack_states .and. hm%apply_packed()) then
256 call st%pack()
257 end if
258
259 if (ks%theory_level == rdmft) then
260 call rdmft_init(rdm, namespace, gr, st, mc, space, fromscratch)
261 end if
262
263 if (.not. fromscratch) then
264 call scf_load(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, scf%restart_load)
265 call restart_end(scf%restart_load)
266 end if
267 pop_sub(gs_initialize)
268 end subroutine gs_initialize
269
270 ! ---------------------------------------------------------
271 subroutine gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
272 type(namespace_t), intent(in) :: namespace
273 type(scf_t), intent(inout) :: scf
274 type(rdm_t), intent(inout) :: rdm
275 type(multicomm_t), intent(in) :: mc
276 type(grid_t), intent(inout) :: gr
277 type(ions_t), intent(inout) :: ions
278 type(partner_list_t), intent(in) :: ext_partners
279 type(states_elec_t), intent(inout) :: st
280 type(v_ks_t), intent(inout) :: ks
281 type(hamiltonian_elec_t), intent(inout) :: hm
282 type(output_t), intent(in) :: outp
283 type(electron_space_t), intent(in) :: space
284
285 push_sub(gs_run)
286
287 ! self-consistency for occupation numbers and natural orbitals in RDMFT
288 if (ks%theory_level == rdmft) then
289 call scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, scf%restart_dump)
290 else
291 if (scf%restart_dump%get_data_type() /= restart_undefined) then
292 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, &
293 restart_dump=scf%restart_dump)
294 else
295 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp)
296 end if
297 end if
298
299 pop_sub(gs_run)
300 end subroutine gs_run
302
304
305!! Local Variables:
306!! mode: f90
307!! coding: utf-8
308!! 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
integer, parameter, public rdmft
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 ...
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
Definition: lcao.F90:795
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:543
subroutine, public messages_new_line()
Definition: messages.F90:1146
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:1097
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:624
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 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:351
subroutine, public rdmft_init(rdm, namespace, gr, st, mc, space, fromScratch)
Definition: rdmft.F90:214
subroutine, public scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, restart_dump)
Definition: rdmft.F90:381
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:589
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1539
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:253
subroutine, public scf_end(scf)
Definition: scf.F90:542
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:818
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:679
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:163
some variables used for the SCF cycle
Definition: scf.F90:208
The states_elec_t class contains all electronic wave functions.
int true(void)