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)
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)
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
141
142 call messages_write('Info: Allocating ground state wave-functions')
143 call messages_info(namespace=namespace)
144
145 if (st%parallel_in_states) then
146 call messages_experimental('State parallelization for ground state calculations', namespace=namespace)
147 end if
148
149 if (hm%pcm%run_pcm) then
150 if (.not. is_close(hm%pcm%epsilon_infty, hm%pcm%epsilon_0) .and. hm%pcm%tdlevel /= pcm_td_eq) then
151 message(1) = 'Non-equilbrium PCM is not active in a time-independent run.'
152 message(2) = 'You set epsilon_infty /= epsilon_0, but epsilon_infty is not relevant for CalculationMode = gs.'
153 message(3) = 'By definition, the ground state is in equilibrium with the solvent.'
154 message(4) = 'Therefore, the only relevant dielectric constant is the static one.'
155 message(5) = 'Nevertheless, the dynamical PCM response matrix is evaluated for benchamarking purposes.'
156 call messages_warning(5, namespace=namespace)
157 end if
158 end if
159
160 call states_elec_allocate_wfns(st, gr, packed=.true.)
162 ! sometimes a deadlock can occur here (if some nodes can allocate and other cannot)
163 if (st%dom_st_kpt_mpi_grp%comm /= mpi_comm_undefined &
164 .and. st%dom_st_kpt_mpi_grp%comm /= mpi_comm_null) then
165 call st%dom_st_kpt_mpi_grp%barrier()
166 end if
167 call messages_write('Info: Ground-state allocation done.')
168 call messages_info(namespace=namespace)
169
172
173 ! ---------------------------------------------------------
174 subroutine electrons_gs_load_from_restart(namespace, scf, gr, mc, st, hm, ks, space, ions, ext_partners, fromScratch)
175 type(namespace_t), intent(in) :: namespace
176 type(scf_t), intent(inout) :: scf
177 type(grid_t), intent(inout) :: gr
178 type(multicomm_t), intent(in) :: mc
179 type(states_elec_t), intent(inout) :: st
180 type(hamiltonian_elec_t), intent(inout) :: hm
181 type(v_ks_t), intent(inout) :: ks
182 type(electron_space_t), intent(in) :: space
183 type(ions_t), intent(in) :: ions
184 type(partner_list_t), intent(in) :: ext_partners
185 logical, intent(inout) :: fromscratch
186
187 integer :: ierr
188
190
191 ! load wavefunctions
192 ! in RDMFT we need the full ground state
193 call scf%restart_load%init(namespace, restart_gs, restart_type_load, mc, ierr, mesh=gr, &
194 exact = (ks%theory_level == rdmft))
195 if (ierr == 0) then
196 call states_elec_load(scf%restart_load, namespace, space, st, gr, hm%kpoints, ierr)
197 end if
198
199 if (ierr /= 0) then
200 call messages_write("Unable to read wavefunctions.")
201 call messages_new_line()
202 call messages_write("Starting from scratch!")
203 call messages_warning(namespace=namespace)
204 fromscratch = .true.
205 end if
206
208 end subroutine electrons_gs_load_from_restart
209
210 ! ---------------------------------------------------------
211 subroutine electrons_gs_initialize(namespace, scf, rdm, gr, mc, st, hm, ions, ks, space, ext_partners, fromScratch)
212 type(namespace_t), intent(in) :: namespace
213 type(scf_t), intent(inout) :: scf
214 type(rdm_t), intent(inout) :: rdm
215 type(grid_t), intent(inout) :: gr
216 type(multicomm_t), intent(in) :: mc
217 type(states_elec_t), intent(inout) :: st
218 type(hamiltonian_elec_t), intent(inout) :: hm
219 type(ions_t), intent(in) :: ions
220 type(v_ks_t), intent(inout) :: ks
221 type(electron_space_t), intent(in) :: space
222 type(partner_list_t), intent(in) :: ext_partners
223 logical, intent(in) :: fromscratch
224
225 integer :: ierr
226 logical :: restart_init_data_type_dump
227
229
230 call write_canonicalized_xyz_file("exec", "initial_coordinates", space, ions%latt, ions%pos, ions%atom, &
231 gr%box, namespace)
232
233 if (ks%theory_level /= rdmft) then
234 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
235 ! only initialize dumping restart files for more than one iteration
236 restart_init_data_type_dump = scf%max_iter > 0
237 else
238 restart_init_data_type_dump = .true.
239 end if
240
241 if (fromscratch .and. ks%theory_level /= rdmft) then
242 call lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, lmm_r = scf%lmm_r)
243 else
244 ! setup Hamiltonian
245 call messages_write('Info: Setting up Hamiltonian.')
246 call messages_info(namespace=namespace)
247
248 ! v_ks_h_setup calls states_fermi, that uses the eigenvalues, which are uninitialized at this stage
249 if (fromscratch .and. ks%theory_level == rdmft) st%eigenval = default_eigenval
250
251 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
252 calc_eigenval = .false., calc_current = .false.)
253 end if
254
255 if (restart_init_data_type_dump) then
256 call scf%restart_dump%init(namespace, restart_gs, restart_type_dump, mc, ierr, mesh=gr)
257 end if
258
259 ! run self-consistency
260 call scf_state_info(namespace, st)
261
262 if (st%pack_states .and. hm%apply_packed()) then
263 call st%pack()
264 end if
265
266 if (ks%theory_level == rdmft) then
267 call rdmft_init(rdm, namespace, gr, st, hm, mc, space, fromscratch)
268 end if
270 if (.not. fromscratch) then
271 call scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, scf%restart_load)
272 call scf%restart_load%end()
273 end if
275 end subroutine electrons_gs_initialize
276
277 ! ---------------------------------------------------------
278 subroutine electrons_gs_run(namespace, scf, rdm, mc, gr, ions, ext_partners, st, ks, hm, outp, space)
279 type(namespace_t), intent(in) :: namespace
280 type(scf_t), intent(inout) :: scf
281 type(rdm_t), intent(inout) :: rdm
282 type(multicomm_t), intent(in) :: mc
283 type(grid_t), intent(inout) :: gr
284 type(ions_t), intent(inout) :: ions
285 type(partner_list_t), intent(in) :: ext_partners
286 type(states_elec_t), intent(inout) :: st
287 type(v_ks_t), intent(inout) :: ks
288 type(hamiltonian_elec_t), intent(inout) :: hm
289 type(output_t), intent(in) :: outp
290 type(electron_space_t), intent(in) :: space
291
292 push_sub(electrons_gs_run)
293
294 ! self-consistency for occupation numbers and natural orbitals in RDMFT
295 if (ks%theory_level == rdmft) then
296 call scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, scf%restart_dump)
297 else
298 if (scf%restart_dump%get_data_type() /= restart_undefined) then
299 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, &
300 restart_dump=scf%restart_dump)
301 else
302 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp)
303 end if
304 end if
305
307 end subroutine electrons_gs_run
308
309
311
312!! Local Variables:
313!! mode: f90
314!! coding: utf-8
315!! 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_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_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:237
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.
real(real64), parameter, public default_eigenval
Definition: lcao.F90:245
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
Definition: lcao.F90:770
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:525
subroutine, public messages_new_line()
Definition: messages.F90:1112
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:1063
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
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, gr, ions, ext_partners, st, ks, hm, restart_load)
Loading of restarting data of the SCF cycle.
Definition: scf.F90:573
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1492
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:256
subroutine, public scf_end(scf)
Definition: scf.F90:526
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:800
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:695
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:211
The states_elec_t class contains all electronic wave functions.
int true(void)