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
23#include "global.h"
24
26 use debug_oct_m
28 use global_oct_m
29 use grid_oct_m
33 use ions_oct_m
35 use lcao_oct_m
36 use math_oct_m
37 use mesh_oct_m
42 use pcm_oct_m
43 use rdmft_oct_m
45 use scf_oct_m
46 use space_oct_m
50 use v_ks_oct_m
51 use mpi_oct_m
52
53 implicit none
54
55 private
56 public :: &
63
64contains
65
67 subroutine electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
68 type(namespace_t), intent(in) :: namespace
69 type(multicomm_t), intent(in) :: mc
70 type(grid_t), intent(inout) :: gr
71 type(ions_t), intent(inout) :: ions
72 type(partner_list_t), intent(in) :: ext_partners
73 type(states_elec_t), intent(inout) :: st
74 type(v_ks_t), intent(inout) :: ks
75 type(hamiltonian_elec_t), intent(inout) :: hm
76 type(output_t), intent(in) :: outp
77 type(electron_space_t), intent(in) :: space
78 logical, intent(inout) :: fromScratch
79
80 type(rdm_t) :: rdm
81 type(scf_t) :: scf
82
84
85 call electrons_gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions)
86
87 if (.not. fromscratch) then
88 call electrons_gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromscratch)
89 end if
90
91 call electrons_gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromscratch)
92
93 call electrons_gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
94
95 call electrons_gs_cleanup(ks, scf, rdm, st, hm)
96
98
99 end subroutine electrons_ground_state_run
100
101
102 subroutine electrons_gs_cleanup(ks, scf, rdm, st, hm)
103 type(v_ks_t), intent(inout) :: ks
104 type(scf_t), intent(inout) :: scf
105 type(rdm_t), intent(inout) :: rdm
106 type(states_elec_t), intent(inout) :: st
107 type(hamiltonian_elec_t), intent(inout) :: hm
108
109 push_sub(electrons_gs_cleanup)
110
111 if (ks%theory_level == rdmft) then
112 call rdmft_end(rdm)
113 else
114 call scf_end(scf)
115 end if
116
117 if (scf%restart_dump%get_data_type() /= restart_undefined) then
118 call scf%restart_dump%end()
119 end if
120
121 if (st%pack_states .and. hm%apply_packed()) then
122 call st%unpack()
123 end if
124
125 ! clean up
127
128 pop_sub(electrons_gs_cleanup)
129 end subroutine electrons_gs_cleanup
130
131 ! ---------------------------------------------------------
132 subroutine electrons_gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions)
133 type(namespace_t), intent(in) :: namespace
134 type(grid_t), intent(inout) :: gr
135 type(states_elec_t), intent(inout) :: st
136 type(hamiltonian_elec_t), intent(inout) :: hm
137 type(scf_t), intent(inout) :: scf
138 type(v_ks_t), intent(inout) :: ks
139 type(ions_t), intent(inout) :: ions
140
142
143 call messages_write('Info: Allocating ground state wave-functions')
144 call messages_info(namespace=namespace)
145
146 if (st%parallel_in_states) then
147 call messages_experimental('State parallelization for ground state calculations', namespace=namespace)
148 end if
149
150 if (hm%pcm%run_pcm) then
151 if (.not. is_close(hm%pcm%epsilon_infty, hm%pcm%epsilon_0) .and. hm%pcm%tdlevel /= pcm_td_eq) then
152 message(1) = 'Non-equilbrium PCM is not active in a time-independent run.'
153 message(2) = 'You set epsilon_infty /= epsilon_0, but epsilon_infty is not relevant for CalculationMode = gs.'
154 message(3) = 'By definition, the ground state is in equilibrium with the solvent.'
155 message(4) = 'Therefore, the only relevant dielectric constant is the static one.'
156 message(5) = 'Nevertheless, the dynamical PCM response matrix is evaluated for benchamarking purposes.'
157 call messages_warning(5, namespace=namespace)
158 end if
159 end if
160
161 call states_elec_allocate_wfns(st, gr, packed=.true.)
162
163 ! sometimes a deadlock can occur here (if some nodes can allocate and other cannot)
164 if (st%dom_st_kpt_mpi_grp%comm /= mpi_comm_undefined &
165 .and. st%dom_st_kpt_mpi_grp%comm /= mpi_comm_null) then
166 call st%dom_st_kpt_mpi_grp%barrier()
167 end if
168 call messages_write('Info: Ground-state allocation done.')
169 call messages_info(namespace=namespace)
170
173
174 ! ---------------------------------------------------------
175 subroutine electrons_gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
176 type(namespace_t), intent(in) :: namespace
177 type(scf_t), intent(inout) :: scf
178 type(grid_t), intent(inout) :: gr
179 type(multicomm_t), intent(in) :: mc
180 type(states_elec_t), intent(inout) :: st
181 type(hamiltonian_elec_t), intent(inout) :: hm
182 type(v_ks_t), intent(inout) :: ks
183 type(electron_space_t), intent(in) :: space
184 type(ions_t), intent(in) :: ions
185 type(partner_list_t), intent(in) :: ext_partners
186 logical, intent(inout) :: fromscratch
187
188 integer :: ierr
189
191
192 ! load wavefunctions
193 ! in RDMFT we need the full ground state
194 call scf%restart_load%init(namespace, restart_gs, restart_type_load, mc, ierr, mesh=gr, &
195 exact = (ks%theory_level == rdmft))
196 if (ierr == 0) then
197 call states_elec_load(scf%restart_load, namespace, space, st, gr, hm%kpoints, fixed_occ=.false., ierr=ierr)
198 end if
199
200 if (ierr /= 0) then
201 call messages_write("Unable to read wavefunctions.")
202 call messages_new_line()
203 call messages_write("Starting from scratch!")
204 call messages_warning(namespace=namespace)
205 fromscratch = .true.
206 end if
207
209 end subroutine electrons_gs_load_from_restart
210
211 ! ---------------------------------------------------------
212 subroutine electrons_gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
213 type(namespace_t), intent(in) :: namespace
214 type(scf_t), intent(inout) :: scf
215 type(rdm_t), intent(inout) :: rdm
216 type(grid_t), intent(inout) :: gr
217 type(multicomm_t), intent(in) :: mc
218 type(states_elec_t), intent(inout) :: st
219 type(hamiltonian_elec_t), intent(inout) :: hm
220 type(ions_t), intent(in) :: ions
221 type(v_ks_t), intent(inout) :: ks
222 type(electron_space_t), intent(in) :: space
223 type(partner_list_t), intent(in) :: ext_partners
224 logical, intent(in) :: fromscratch
225
226 integer :: ierr
227 logical :: restart_init_data_type_dump, known_lower_bound
228
230
231 call write_canonicalized_xyz_file("exec", "initial_coordinates", space, ions%latt, ions%pos, ions%atom, &
232 gr%box, namespace)
233
234 if (ks%theory_level /= rdmft) then
235 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
236 ! only initialize dumping restart files for more than one iteration
237 restart_init_data_type_dump = scf%max_iter > 0
238 else
239 restart_init_data_type_dump = .true.
240 end if
241
242 if (fromscratch .and. ks%theory_level /= rdmft) then
243 call lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, lmm_r = scf%lmm_r, &
244 known_lower_bound=known_lower_bound)
245 call scf_set_lower_bound_is_known(scf, known_lower_bound) ! Lower bound is known here
246 else
247 ! setup Hamiltonian
248 call messages_write('Info: Setting up Hamiltonian.')
249 call messages_info(namespace=namespace)
250
251 ! v_ks_h_setup calls states_fermi, that uses the eigenvalues, which are uninitialized at this stage
252 if (fromscratch .and. ks%theory_level == rdmft) st%eigenval = default_eigenval
253
254 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
255 calc_eigenval = .false., calc_current = .false.)
256
257 if (.not. fromscratch) call scf_set_lower_bound_is_known(scf, .true.) ! Lower bound is known here
258 end if
259
260 if (restart_init_data_type_dump) then
261 call scf%restart_dump%init(namespace, restart_gs, restart_type_dump, mc, ierr, mesh=gr)
262 end if
263
264 ! run self-consistency
265 call scf_state_info(namespace, st)
266
267 if (st%pack_states .and. hm%apply_packed()) then
268 call st%pack()
269 end if
270
271 if (ks%theory_level == rdmft) then
272 call rdmft_init(rdm, namespace, gr, st, hm, mc, space, fromscratch)
273 end if
274
275 if (.not. fromscratch) then
276 call scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, scf%restart_load)
277 call scf%restart_load%end()
278 end if
280 end subroutine electrons_gs_initialize
281
282 ! ---------------------------------------------------------
283 subroutine electrons_gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
284 type(namespace_t), intent(in) :: namespace
285 type(scf_t), intent(inout) :: scf
286 type(rdm_t), intent(inout) :: rdm
287 type(multicomm_t), intent(in) :: mc
288 type(grid_t), intent(inout) :: gr
289 type(ions_t), intent(inout) :: ions
290 type(partner_list_t), intent(in) :: ext_partners
291 type(states_elec_t), intent(inout) :: st
292 type(v_ks_t), intent(inout) :: ks
293 type(hamiltonian_elec_t), intent(inout) :: hm
294 type(output_t), intent(in) :: outp
295 type(electron_space_t), intent(in) :: space
296
297 push_sub(electrons_gs_run)
298
299 ! self-consistency for occupation numbers and natural orbitals in RDMFT
300 if (ks%theory_level == rdmft) then
301 call scf_rdmft(rdm, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, scf%restart_dump)
302 else
303 if (scf%restart_dump%get_data_type() /= restart_undefined) then
304 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, &
305 restart_dump=scf%restart_dump)
306 else
307 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp)
308 end if
309 end if
310
311 pop_sub(electrons_gs_run)
312 end subroutine electrons_gs_run
313
314
316
317!! Local Variables:
318!! mode: f90
319!! coding: utf-8
320!! End:
A set of subroutines for performing the parts of a ground state calculation with an electrons system....
subroutine, public electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
Run a ground state calculation for a system of electrons.
subroutine, public electrons_gs_allocate_wavefunctions(namespace, gr, st, hm, scf, ks, ions)
subroutine, public electrons_gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
subroutine, public electrons_gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
subroutine, public electrons_gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
subroutine, public electrons_gs_cleanup(ks, scf, rdm, st, hm)
integer, parameter, public rdmft
Definition: global.F90:223
This module implements the underlying real-space grid.
Definition: grid.F90:96
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.
A module to handle KS potential, without the external potential.
real(real64), parameter, public default_eigenval
Definition: lcao.F90:219
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r, known_lower_bound)
Definition: lcao.F90:744
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_new_line()
Definition: messages.F90:1069
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:115
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
this module contains the low-level part of the output system
Definition: output_low.F90:94
integer, parameter, public pcm_td_eq
Definition: pcm.F90:256
subroutine, public rdmft_end(rdm)
Definition: rdmft.F90:326
subroutine, public scf_rdmft(rdm, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, restart_dump)
Definition: rdmft.F90:356
subroutine, public rdmft_init(rdm, namespace, gr, st, hm, mc, space, fromScratch)
Definition: rdmft.F90:192
integer, parameter, public restart_undefined
Definition: restart.F90:133
integer, parameter, public restart_gs
Definition: restart.F90:133
integer, parameter, public restart_type_dump
Definition: restart.F90:161
integer, parameter, public restart_type_load
Definition: restart.F90:161
subroutine, public scf_set_lower_bound_is_known(scf, known_lower_bound)
Set the flag lower_bound_is_known.
Definition: scf.F90:1724
subroutine, public scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
Loading of restarting data of the SCF cycle.
Definition: scf.F90:614
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1586
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:239
subroutine, public scf_end(scf)
Definition: scf.F90:565
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:850
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, fixed_occ, 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:735
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:148
Stores all communicators and groups.
Definition: multicomm.F90:185
output handler class
Definition: output_low.F90:143
some variables used for the SCF cycle
Definition: scf.F90:190
The states_elec_t class contains all electronic wave functions.
int true(void)