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 :: &
53
54contains
55
56 ! ---------------------------------------------------------
57 subroutine electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, fromScratch)
58 type(namespace_t), intent(in) :: namespace
59 type(multicomm_t), intent(in) :: mc
60 type(grid_t), intent(inout) :: gr
61 type(ions_t), intent(inout) :: ions
62 type(partner_list_t), intent(in) :: ext_partners
63 type(states_elec_t), intent(inout) :: st
64 type(v_ks_t), intent(inout) :: ks
65 type(hamiltonian_elec_t), intent(inout) :: hm
66 type(output_t), intent(in) :: outp
67 type(electron_space_t), intent(in) :: space
68 logical, intent(inout) :: fromScratch
69
70 type(scf_t) :: scfv
71 type(restart_t) :: restart_load, restart_dump
72 integer :: ierr
73 type(rdm_t) :: rdm
74 logical :: restart_init_dump
75
76 push_sub(ground_state_run_legacy)
77
78 call messages_write('Info: Allocating ground state wave-functions')
79 call messages_info(namespace=namespace)
80
81 if (st%parallel_in_states) then
82 call messages_experimental('State parallelization for ground state calculations', namespace=namespace)
83 end if
84
85 if (hm%pcm%run_pcm) then
86 if (.not. is_close(hm%pcm%epsilon_infty, hm%pcm%epsilon_0) .and. hm%pcm%tdlevel /= pcm_td_eq) then
87 message(1) = 'Non-equilbrium PCM is not active in a time-independent run.'
88 message(2) = 'You set epsilon_infty /= epsilon_0, but epsilon_infty is not relevant for CalculationMode = gs.'
89 message(3) = 'By definition, the ground state is in equilibrium with the solvent.'
90 message(4) = 'Therefore, the only relevant dielectric constant is the static one.'
91 message(5) = 'Nevertheless, the dynamical PCM response matrix is evaluated for benchamarking purposes.'
92 call messages_warning(5, namespace=namespace)
93 end if
94 end if
95
96 call states_elec_allocate_wfns(st, gr, packed=.true.)
97
98 ! sometimes a deadlock can occur here (if some nodes can allocate and other cannot)
99 if (st%dom_st_kpt_mpi_grp%comm /= mpi_comm_undefined &
100 .and. st%dom_st_kpt_mpi_grp%comm /= mpi_comm_null) then
101 call st%dom_st_kpt_mpi_grp%barrier()
102 end if
103 call messages_write('Info: Ground-state allocation done.')
104 call messages_info(namespace=namespace)
105
106 if (.not. fromscratch) then
107 ! load wavefunctions
108 ! in RDMFT we need the full ground state
109 call restart_init(restart_load, namespace, restart_gs, restart_type_load, mc, ierr, mesh=gr, &
110 exact = (ks%theory_level == rdmft))
111 if (ierr == 0) then
112 call states_elec_load(restart_load, namespace, space, st, gr, hm%kpoints, ierr)
113 end if
115 if (ierr /= 0) then
116 call messages_write("Unable to read wavefunctions.")
117 call messages_new_line()
118 call messages_write("Starting from scratch!")
119 call messages_warning(namespace=namespace)
120 fromscratch = .true.
121 end if
122 end if
123
124 call write_canonicalized_xyz_file("exec", "initial_coordinates", space, ions%latt, ions%pos, ions%atom, &
125 gr%box, namespace)
126
127 if (ks%theory_level /= rdmft) then
128 call scf_init(scfv, namespace, gr, ions, st, mc, hm, space)
129 ! only initialize dumping restart files for more than one iteration
130 restart_init_dump = scfv%max_iter > 0
131 else
132 restart_init_dump = .true.
133 end if
134
135 if (fromscratch .and. ks%theory_level /= rdmft) then
136 call lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, lmm_r = scfv%lmm_r)
137 else
138 ! setup Hamiltonian
139 call messages_write('Info: Setting up Hamiltonian.')
140 call messages_info(namespace=namespace)
141 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
142 calc_eigenval = .false., calc_current = .false.)
143 end if
144
145 if (restart_init_dump) then
146 call restart_init(restart_dump, namespace, restart_gs, restart_type_dump, mc, ierr, mesh=gr)
147 end if
148
149 ! run self-consistency
150 call scf_state_info(namespace, st)
151
152 if (st%pack_states .and. hm%apply_packed()) then
153 call st%pack()
154 end if
155
156 ! self-consistency for occupation numbers and natural orbitals in RDMFT
157 if (ks%theory_level == rdmft) then
158 call rdmft_init(rdm, namespace, gr, st, mc, space, fromscratch)
159 call scf_rdmft(rdm, namespace, space, gr, ions, ext_partners, st, ks, hm, outp, restart_dump)
160 call rdmft_end(rdm)
161 else
162 if (.not. fromscratch) then
163 if (restart_init_dump) then
164 call scf_run(scfv, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, &
165 restart_load=restart_load, restart_dump=restart_dump)
166 else
167 call scf_run(scfv, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, restart_load=restart_load)
168 end if
169 call restart_end(restart_load)
170 else
171 if (restart_init_dump) then
172 call scf_run(scfv, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp, restart_dump=restart_dump)
173 else
174 call scf_run(scfv, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp=outp)
175 end if
176 end if
177
178 call scf_end(scfv)
179 end if
180
181 if (restart_init_dump) then
182 call restart_end(restart_dump)
183 end if
184
185 if (st%pack_states .and. hm%apply_packed()) then
186 call st%unpack()
187 end if
188
189 ! clean up
191
192 pop_sub(ground_state_run_legacy)
193 end subroutine electrons_ground_state_run
194
196
197!! Local Variables:
198!! mode: f90
199!! coding: utf-8
200!! End:
subroutine, public electrons_ground_state_run(namespace, mc, gr, ions, ext_partners, st, ks, hm, outp, space, 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:799
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_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
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
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_gs
Definition: restart.F90:229
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:514
integer, parameter, public restart_type_dump
Definition: restart.F90:225
integer, parameter, public restart_type_load
Definition: restart.F90:225
subroutine, public restart_end(restart)
Definition: restart.F90:720
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1428
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_load, restart_dump)
Definition: scf.F90:574
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:237
subroutine, public scf_end(scf)
Definition: scf.F90:526
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
int true(void)