Octopus
propagator.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 N. Tancogne-Dejean
2!! Copyright (C) 2020 M. Oliveira
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
26 use clock_oct_m
27 use debug_oct_m
28 use global_oct_m
32 use system_oct_m
33
34 implicit none
35
36 private
37 public :: &
39
45 type, extends(algorithm_t), abstract :: propagator_t
46 private
47 class(system_t), pointer, public :: system
48
49 type(algorithm_iterator_t) :: scf_start
52
53 float, public :: dt
54 float, public :: final_time = m_zero
55
56 ! Options related to predictor-corrector propagators
57 logical, public :: inside_scf = .false.
58 logical, public :: predictor_corrector = .false.
59 integer, public :: scf_count
60 integer, public :: max_scf_count
61 integer, public :: accumulated_loop_ticks
62 float, public :: scf_tol
63 contains
64 ! Below are the list of operations that needs to be implemented
65 procedure :: do_operation => propagator_do_operation
66 procedure :: finished => propagator_finished
67 procedure :: init_iteration_counters => propagator_init_iteration_counters
68 procedure :: save_scf_start => propagator_save_scf_start
69 procedure :: rewind_scf_loop => propagator_rewind_scf_loop
70 end type propagator_t
71
72 !# doc_start general_propagation_operations
73 ! Known propagation operations
74 character(len=ALGO_LABEL_LEN), public, parameter :: &
75 START_SCF_LOOP = 'START_SCF_LOOP', &
76 end_scf_loop = 'END_SCF_LOOP', &
77 store_current_status = 'STORE_CURRENT_STATUS'
78
79 type(algorithmic_operation_t), public, parameter :: &
80 OP_START_SCF_LOOP = algorithmic_operation_t(start_scf_loop, 'Starting SCF loop'), &
81 op_end_scf_loop = algorithmic_operation_t(end_scf_loop, 'End of SCF iteration'), &
83 !# doc_end
84
85
86contains
87
90 logical function propagator_do_operation(this, operation) result(done)
91 class(propagator_t), intent(inout) :: this
92 type(algorithmic_operation_t), intent(in) :: operation
93
94 done = .true.
95
96 select case (operation%id)
98 ! Update the accumulated loop ticks before executing this generic operation
99 this%accumulated_loop_ticks = this%accumulated_loop_ticks + 1
100 done = .false.
101
102 case (start_scf_loop)
103 assert(this%predictor_corrector)
104
105 call this%save_scf_start()
106 this%inside_scf = .true.
107 this%accumulated_loop_ticks = 0
109 if (debug%info) then
110 write(message(1), '(a,i3,a)') "Debug: -- SCF iter ", this%scf_count, " for '" + trim(this%system%namespace%get()) + "'"
111 call messages_info(1, namespace=this%system%namespace)
112 end if
113
114 case (end_scf_loop)
115 ! Here we first check if we did the maximum number of steps.
116 ! Otherwise, we need check the tolerance
117 if (this%scf_count == this%max_scf_count) then
118 if (debug%info) then
119 message(1) = "Debug: -- Max SCF Iter reached for '" + trim(this%system%namespace%get()) + "'"
120 call messages_info(1, namespace=this%system%namespace)
121 end if
122 this%inside_scf = .false.
123 call this%next()
124 else
125 ! We reset the pointer to the beginning of the scf loop
126 if (this%system%is_tolerance_reached(this%scf_tol)) then
127 if (debug%info) then
128 message(1) = "Debug: -- SCF tolerance reached for '" + trim(this%system%namespace%get()) + "'"
129 call messages_info(1, namespace=this%system%namespace)
130 end if
131 this%inside_scf = .false.
132 call this%next()
133 else
134 ! We rewind the instruction stack
135 call this%rewind_scf_loop()
136
137 ! We reset the clocks
138 call this%system%reset_iteration_counters(this%accumulated_loop_ticks)
139 this%accumulated_loop_ticks = 0
140 if (debug%info) then
141 write(message(1), '(a,i3,a,a)') "Debug: -- SCF iter ", this%scf_count, " for '" + trim(this%system%namespace%get()), "'"
142 call messages_info(1, namespace=this%system%namespace)
143 end if
144 end if
145 end if
147 case default
148 done = .false.
149 end select
153 ! ---------------------------------------------------------
156 logical function propagator_finished(this)
157 class(propagator_t), intent(in) :: this
159 type(iteration_counter_t) :: clock_
160
161 clock_ = this%system%iteration + 1
162 propagator_finished = clock_%value() > this%final_time
164 end function propagator_finished
165
166 ! ---------------------------------------------------------
172 class(propagator_t), intent(inout) :: this
173
174 this%iteration = clock_t(time_step=this%dt/this%algo_steps)
175 this%system%iteration = clock_t(time_step=this%dt)
176
178
180 !
181 subroutine propagator_save_scf_start(this)
182 class(propagator_t), intent(inout) :: this
183
185
186 this%scf_start = this%iter
187 call this%next()
188 this%scf_count = 0
189
191 end subroutine propagator_save_scf_start
192
193 ! ---------------------------------------------------------
195 !
196 subroutine propagator_rewind_scf_loop(this)
197 class(propagator_t), intent(inout) :: this
198
200
201 this%iter = this%scf_start
202 call this%next()
203 this%scf_count = this%scf_count + 1
204
206 end subroutine propagator_rewind_scf_loop
207
208end module propagator_oct_m
209
210
211!! Local Variables:
212!! mode: f90
213!! coding: utf-8
214!! End:
This module implements the basic elements defining algorithms.
Definition: algorithm.F90:132
character(len=algo_label_len), parameter, public update_interactions
Definition: algorithm.F90:163
type(debug_t), save, public debug
Definition: debug.F90:142
real(8), parameter, public m_zero
Definition: global.F90:167
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:603
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:151
This module implements the basic propagator framework.
Definition: propagator.F90:108
character(len=algo_label_len), parameter, public store_current_status
Definition: propagator.F90:158
type(algorithmic_operation_t), parameter, public op_store_current_status
Definition: propagator.F90:163
subroutine propagator_rewind_scf_loop(this)
Reset the iteration state to the beginning of the loop (START_SCF_LOOP) and move to next step.
Definition: propagator.F90:281
subroutine propagator_save_scf_start(this)
Save the current iteration state (START_SCF_LOOP) and move to next step.
Definition: propagator.F90:266
logical function propagator_do_operation(this, operation)
Try to perform one operation of the algorithm. Return .true. if sucessful.
Definition: propagator.F90:175
logical function propagator_finished(this)
indicate whether a propagation has reached the final time
Definition: propagator.F90:241
character(len=algo_label_len), parameter, public end_scf_loop
Definition: propagator.F90:158
subroutine propagator_init_iteration_counters(this)
Initialize the propagator and system clocks.
Definition: propagator.F90:256
type(algorithmic_operation_t), parameter, public op_end_scf_loop
Definition: propagator.F90:163
This module implements the abstract system type.
Definition: system.F90:109
An algorithm is a list of algorithmic operations executed sequentially.
Definition: algorithm.F90:191
Descriptor of one algorithmic operation.
Definition: algorithm.F90:154
This class implements the iteration counter used by the multisystem algorithms. As any iteration coun...
Abstract class implementing propagators.
Definition: propagator.F90:129
int true(void)