Octopus
minimizer_factory.F90
Go to the documentation of this file.
1!! Copyright (C) 2024 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
24
26 use, intrinsic :: iso_fortran_env
29 use debug_oct_m
31 use global_oct_m
39 use parser_oct_m
42 use system_oct_m
43 implicit none
44
45 private
46 public :: minimizer_factory_t
47
48 ! Known multisystem minimizers
49 integer, public, parameter :: &
50 GROUND_STATE_STATIC = 0, &
52
53
56 private
57 integer :: max_iter
58 contains
59 procedure :: create => minimizer_factory_create
60 procedure :: create_static => minimizer_factory_create_static
61 end type minimizer_factory_t
62
63 interface minimizer_factory_t
64 module procedure minimizer_factory_constructor
65 end interface minimizer_factory_t
66
67
68contains
69 ! ---------------------------------------------------------------------------------------
73 !
74 function minimizer_factory_constructor(namespace) result(factory)
75 type(namespace_t), intent(in) :: namespace
76 type(minimizer_factory_t) :: factory
77
79
80 ! Get the maximum number of iterations
81 ! This variable is also defined (and properly documented) in scf/scf.F90.
82 call parse_variable(namespace, 'MaximumIter', 200, factory%max_iter)
83
86
87 ! ---------------------------------------------------------------------------------------
89 !
90 function minimizer_factory_create(this, system) result(algorithm)
91 class(minimizer_factory_t), intent(in) :: this
92 class(interaction_partner_t), intent(in), target :: system
93 class(algorithm_t), pointer :: algorithm
94
95 integer :: default, algo_type
96 class(minimizer_algorithm_t), pointer :: algo
97
99
100 !%Variable GroundStateAlgorithm
101 !%Type integer
102 !%Section SCF
103 !%Description
104 !% A variable to set the algorithm for the ground state.
105 !%Option static 0
106 !% Do not change during the SCF iterations. Default for anything apart electrons.
107 !%Option scf 1
108 !% Self-consistent field. Default for electrons.
109 !%End
110 default = ground_state_static
111 select type(system)
112 type is(electrons_t)
113 default = ground_state_scf
114 end select
115 call parse_variable(system%namespace, 'GroundStateAlgorithm',default, algo_type)
116 if (.not. varinfo_valid_option('GroundStateAlgorithm', algo_type)) then
117 call messages_input_error(system%namespace, 'GroundStateAlgorithm')
118 end if
119 call messages_print_with_emphasis(msg='System algorithm', namespace=system%namespace)
120 call messages_print_var_option('GroundStateAlgorithm', algo_type, namespace=system%namespace)
121
122 select case (algo_type)
123 case (ground_state_static)
124 algo => minimizer_static_t()
125 case (ground_state_scf)
126 algo => minimizer_scf_t()
127 case default
128 call messages_input_error(system%namespace, 'GroudStateAlgorithm')
129 end select
130
131 call messages_print_with_emphasis(namespace=system%namespace)
132
133 algo%max_iter = this%max_iter
134
135 select type (system)
136 class is (system_t)
137 algo%system => system
138 class default
139 assert(.false.)
140 end select
141
142 algorithm => algo
143
145 end function minimizer_factory_create
146
147 ! ---------------------------------------------------------------------------------------
154 function minimizer_factory_create_static(this, system) result(algorithm)
155 class(minimizer_factory_t), intent(in) :: this
156 class(interaction_partner_t), intent(in), target :: system
157 class(algorithm_t), pointer :: algorithm
158
159 class(minimizer_algorithm_t), pointer :: minimizer
160
162
163 minimizer => minimizer_static_t()
164 minimizer%max_iter = this%max_iter
165
166 select type (system)
167 class is (system_t)
168 minimizer%system => system
169 class default
170 assert(.false.)
171 end select
172
173 algorithm => minimizer
174
177
178
180
181!! Local Variables:
182!! mode: f90
183!! coding: utf-8
184!! End:
This module defines the abstract interfact for algorithm factories.
This module implements the basic elements defining algorithms.
Definition: algorithm.F90:141
This module defines classes and functions for interaction partners.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:920
character(len=512), private msg
Definition: messages.F90:165
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:713
This module implements the basic minimizer framework.
This module implements the factory for ground state algorithm.
type(minimizer_factory_t) function minimizer_factory_constructor(namespace)
Constructor for the minimizer factory.
class(algorithm_t) function, pointer minimizer_factory_create_static(this, system)
Create a static minimizer.
integer, parameter, public ground_state_scf
class(algorithm_t) function, pointer minimizer_factory_create(this, system)
Create a ground-state algorithm.
This module implements the basic mulsisystem class, a container system for other systems.
This module implements the abstract system type.
Definition: system.F90:118
This module defines the unit system, used for input and output.
Abstract class for the algorithm factories.
An algorithm is a list of algorithmic operations executed sequentially.
Definition: algorithm.F90:200
Class describing the electron system.
Definition: electrons.F90:218
abstract class for general interaction partners
Abstract class implementing minimizers.
This class defines the factory for minimizers.
Implements a minimizer algorithm for SCF calculations.
Implements a static minimizer that keeps the state of the system constant.
Abstract class for systems.
Definition: system.F90:172