Octopus
algorithm.F90
Go to the documentation of this file.
1!! Copyright (C) 2020 M. Oliveira
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
22module algorithm_oct_m
23 use clock_oct_m
24 use debug_oct_m
25 use global_oct_m
27 use loct_oct_m
30
31 implicit none
32
33 private
34 public :: &
38
39 integer, parameter, public :: ALGO_LABEL_LEN = 50
40
46 character(len=ALGO_LABEL_LEN) :: id
48 character(len=ALGO_LABEL_LEN) :: label
50
51 !# doc_start generic_algorithmic_operations
52 ! Operations that can be used by any algorithm and, therefore, should be
53 ! implemented by all systems.
54 character(len=ALGO_LABEL_LEN), public, parameter :: &
55 SKIP = 'SKIP', &
56 update_interactions = 'UPDATE_INTERACTIONS', &
57 step_done = 'STEP_DONE', &
58 rewind_algorithm = 'REWIND_ALGORITHM'
59
60 type(algorithmic_operation_t), public, parameter :: &
61 OP_SKIP = algorithmic_operation_t(skip, 'Skipping algorithmic step'), &
62 op_update_interactions = algorithmic_operation_t(update_interactions, 'Algorithmic step - Updating interactions'), &
63 op_step_done = algorithmic_operation_t(step_done, 'Propagation step finished'), &
65 !# doc_end
66
67
70 private
71 contains
72 procedure :: get_next => algorithm_iterator_get_next
74
75
79 type, extends(linked_list_t), abstract :: algorithm_t
80 private
81 type(algorithm_iterator_t), public :: iter
82 type(algorithmic_operation_t) :: current_ops
83
84 type(algorithmic_operation_t), public :: start_step
85 type(algorithmic_operation_t), public :: final_step
86
87 integer, public :: algo_steps
88 float, public :: dt
89
90 logical :: step_done
91 logical, public :: inside_scf = .false.
92
93 type(clock_t), public :: clock
94 float :: start_time = m_zero
95 float, public :: elapsed_time = m_zero
96
97 logical, public :: is_static = .false.
98 contains
99 procedure :: add_operation => algorithm_add_operation
100 procedure :: do_operation => algorithm_do_operation
101 procedure :: update_elapsed_time => algorithm_update_elapsed_time
102 procedure :: rewind => algorithm_rewind
103 procedure :: next => algorithm_next
104 procedure :: get_current_operation => algorithm_get_current_operation
105 procedure(algorithm_finished), deferred :: finished
106 end type algorithm_t
108 abstract interface
109 logical function algorithm_finished(this)
110 import :: algorithm_t
111 class(algorithm_t), intent(in) :: this
112 end function algorithm_finished
113 end interface
114
115contains
116
117 ! ---------------------------------------------------------
118 subroutine algorithm_add_operation(this, operation)
119 class(algorithm_t), intent(inout) :: this
120 type(algorithmic_operation_t), intent(in) :: operation
121
123
124 call this%add_copy(operation)
125
127 end subroutine algorithm_add_operation
128
129 ! ---------------------------------------------------------
130 logical function algorithm_do_operation(this, operation) result(done)
131 class(algorithm_t), intent(inout) :: this
132 type(algorithmic_operation_t), intent(in) :: operation
134 ! By default no algorithm specific operation is implemented in the algorithm
135 ! class. Child classes that wish to change this behaviour should override
136 ! this method.
137 done = .false.
138
140
141 ! ---------------------------------------------------------
142 subroutine algorithm_update_elapsed_time(this)
143 class(algorithm_t), intent(inout) :: this
144
146
147 this%elapsed_time = loct_clock() - this%start_time
148
150 end subroutine algorithm_update_elapsed_time
151
152 ! ---------------------------------------------------------
153 subroutine algorithm_rewind(this)
154 class(algorithm_t), intent(inout) :: this
155
158 call this%iter%start(this)
159 call this%next()
160 this%start_time = loct_clock()
161
163 end subroutine algorithm_rewind
165 ! ---------------------------------------------------------
166 subroutine algorithm_next(this)
167 class(algorithm_t), intent(inout) :: this
168
171 this%current_ops = this%iter%get_next()
174 end subroutine algorithm_next
176 ! ---------------------------------------------------------
177 type(algorithmic_operation_t) function algorithm_get_current_operation(this) result(operation)
178 class(algorithm_t), intent(in) :: this
181
182 operation = this%current_ops
183
187 ! ---------------------------------------------------------
188 function algorithm_iterator_get_next(this) result(operation)
189 class(algorithm_iterator_t), intent(inout) :: this
190 type(algorithmic_operation_t) :: operation
191
193
194 select type (ptr => this%get_next_ptr())
195 class is (algorithmic_operation_t)
196 operation = ptr
197 class default
198 assert(.false.)
199 end select
200
202 end function algorithm_iterator_get_next
204end module algorithm_oct_m
205
206!! Local Variables:
207!! mode: f90
208!! coding: utf-8
209!! End:
The basic elements defining algorithms.
Definition: algorithm.F90:107
character(len=algo_label_len), parameter, public update_interactions
Definition: algorithm.F90:139
character(len=algo_label_len), parameter, public rewind_algorithm
Definition: algorithm.F90:139
type(algorithmic_operation_t), parameter, public op_rewind_algorithm
Definition: algorithm.F90:145
type(algorithmic_operation_t) function algorithm_get_current_operation(this)
Definition: algorithm.F90:263
subroutine algorithm_rewind(this)
Definition: algorithm.F90:239
character(len=algo_label_len), parameter, public step_done
Definition: algorithm.F90:139
type(algorithmic_operation_t) function algorithm_iterator_get_next(this)
Definition: algorithm.F90:274
subroutine algorithm_add_operation(this, operation)
Definition: algorithm.F90:204
type(algorithmic_operation_t), parameter, public op_step_done
Definition: algorithm.F90:145
subroutine algorithm_update_elapsed_time(this)
Definition: algorithm.F90:228
subroutine algorithm_next(this)
Definition: algorithm.F90:252
logical function algorithm_do_operation(this, operation)
Definition: algorithm.F90:216
type(algorithmic_operation_t), parameter, public op_update_interactions
Definition: algorithm.F90:145
real(8), parameter, public m_zero
Definition: global.F90:170
This module implements fully polymorphic linked lists, and some specializations thereof.
subroutine, public push_sub(sub_name)
Definition: messages.F90:1046
subroutine, public pop_sub(sub_name)
Definition: messages.F90:1101
Iterator to loop over the algorithmic operations of an algorithm.
Definition: algorithm.F90:154
An algorithm is a list of algorithmic operations executed sequentially. This is implemented as a link...
Definition: algorithm.F90:164
Descriptor of one algorithmic operation.
Definition: algorithm.F90:130
This class implements an iterator for the polymorphic linked list.
This class implements a linked list of unlimited polymorphic values.