Octopus
criteria_factory.F90
Go to the documentation of this file.
1!! Copyright (C) 2020 N. Tancogne-Dejean
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
23 use debug_oct_m
27 use global_oct_m
28 use, intrinsic :: iso_fortran_env
31 use parser_oct_m
34 use unit_oct_m
36
37 implicit none
38
39 private
40 public :: &
42
43contains
44
45 ! ---------------------------------------------------------
46 subroutine criteria_factory_init(list, namespace, check_conv)
47 class(criterion_list_t), intent(inout) :: list
48 type(namespace_t), intent(in) :: namespace
49 logical, intent(out) :: check_conv
50
51 real(real64) :: conv_abs_dens, conv_rel_dens, conv_abs_ev, conv_rel_ev
52 real(real64) :: conv_energy_diff
53 class(convergence_criterion_t), pointer :: crit, other
54 type(criterion_iterator_t) :: iter
55
56 push_sub(criteria_factory_init)
57
58 !%Variable ConvEnergy
59 !%Type float
60 !%Default 0.0
61 !%Section SCF::Convergence
62 !%Description
63 !% Stop the SCF when the magnitude of change in energy during at
64 !% one SCF iteration is smaller than this value.
65 !%
66 !%A zero value (the default) means do not use this criterion.
67 !%
68 !% If this criterion is used, the SCF loop will only stop once it is
69 !% fulfilled for two consecutive iterations.
70 !%End
71 call parse_variable(namespace, 'ConvEnergy', m_zero, conv_energy_diff, unit = units_inp%energy)
72 crit => energy_criterion_t(conv_energy_diff, m_zero, units_out%energy)
73 call list%add(crit)
74
75 !%Variable ConvAbsDens
76 !%Type float
77 !%Default 0.0
78 !%Section SCF::Convergence
79 !%Description
80 !% Absolute convergence of the density:
81 !%
82 !% <math>\varepsilon = \int {\rm d}^3r \left| \rho^{out}(\bf r) -\rho^{inp}(\bf r) \right|</math>.
83 !%
84 !% A zero value (the default) means do not use this criterion.
85 !%
86 !% If this criterion is used, the SCF loop will only stop once it is
87 !% fulfilled for two consecutive iterations.
88 !%End
89 call parse_variable(namespace, 'ConvAbsDens', m_zero, conv_abs_dens)
90
91 !%Variable ConvRelDens
92 !%Type float
93 !%Default 1e-6
94 !%Section SCF::Convergence
95 !%Description
96 !% Relative convergence of the density:
97 !%
98 !% <math>\varepsilon = \frac{1}{N} \mathrm{ConvAbsDens}</math>.
99 !%
100 !% <i>N</i> is the total number of electrons in the problem. A
101 !% zero value means do not use this criterion.
102 !%
103 !% If you reduce this value, you should also reduce
104 !% <tt>EigensolverTolerance</tt> to a value of roughly 1/10 of
105 !% <tt>ConvRelDens</tt> to avoid convergence problems.
106 !%
107 !% If this criterion is used, the SCF loop will only stop once it is
108 !% fulfilled for two consecutive iterations.
109 !%End
110 call parse_variable(namespace, 'ConvRelDens', 1e-6_real64, conv_rel_dens)
111 crit => density_criterion_t(conv_abs_dens, conv_rel_dens)
112 call list%add(crit)
113
114 !%Variable ConvAbsEv
115 !%Type float
116 !%Default 0.0
117 !%Section SCF::Convergence
118 !%Description
119 !% Absolute convergence of the sum of the eigenvalues:
120 !%
121 !% <math> \varepsilon = \left| \sum_{j=1}^{N_{occ}} \varepsilon_j^{out} -
122 !% \sum_{j=1}^{N_{occ}} \varepsilon_j^{inp} \right| </math>
123 !%
124 !% A zero value (the default) means do not use this criterion.
125 !%
126 !% If this criterion is used, the SCF loop will only stop once it is
127 !% fulfilled for two consecutive iterations.
128 !%End
129 call parse_variable(namespace, 'ConvAbsEv', m_zero, conv_abs_ev, unit = units_inp%energy)
130
131 !%Variable ConvRelEv
132 !%Type float
133 !%Default 0.0
134 !%Section SCF::Convergence
135 !%Description
136 !% Relative convergence of the sum of the eigenvalues:
137 !%
138 !% <math>\varepsilon = \frac{ \left| \sum_{j=1}^{N_{occ}} ( \varepsilon_j^{out} - \varepsilon_j^{inp} ) \right|}
139 !% {\left| \sum_{j=1}^{N_{occ}} \varepsilon_j^{out} \right|} </math>
140 !%
141 !%A zero value (the default) means do not use this criterion.
142 !%
143 !% If this criterion is used, the SCF loop will only stop once it is
144 !% fulfilled for two consecutive iterations.
145 !%End
146 call parse_variable(namespace, 'ConvRelEv', m_zero, conv_rel_ev)
147 crit => eigenval_criterion_t(conv_abs_ev, conv_rel_ev, units_out%energy)
148 call list%add(crit)
149
150 call messages_obsolete_variable(namespace, 'ConvForce')
151 call messages_obsolete_variable(namespace, 'ConvAbsForce')
152 call messages_obsolete_variable(namespace, 'ConvRelForce')
153
154 call iter%start(list)
155 check_conv = iter%has_next() !If the list is empty, this fails
156 do while (iter%has_next())
157 other => iter%get_next()
158 check_conv = check_conv .or. (other%tol_abs > m_zero) .or. (other%tol_rel > m_zero)
159 end do
160
161 pop_sub(criteria_factory_init)
162 end subroutine criteria_factory_init
163
164end module criteria_factory_oct_m
subroutine, public criteria_factory_init(list, namespace, check_conv)
real(real64), parameter, public m_zero
Definition: global.F90:187
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1057
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:137
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing