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