22 use,
intrinsic :: iso_fortran_env
60 integer :: iteration = 0
61 integer(int64) :: step = -1
62 integer(int64) :: global_iteration = 0
63 procedure(get_value),
pointer,
public ::
value => null()
80 generic ::
operator(+) => add
81 generic ::
operator(-) => subtract
82 generic ::
operator(.eq.) => is_equal
83 generic ::
operator(/=) => is_different
84 generic ::
operator(.lt.) => is_earlier
85 generic ::
operator(.gt.) => is_later
86 generic ::
operator(.le.) => is_equal_or_earlier
87 generic ::
operator(.ge.) => is_equal_or_later
105 integer(int64),
optional,
intent(in) :: step
106 integer,
optional,
intent(in) :: initial_iteration
108 if (
present(initial_iteration))
then
109 counter%iteration = initial_iteration
111 if (
present(step))
then
116 counter%global_iteration = counter%iteration * counter%step
128 if (mod(counter%global_iteration, this%step) /= 0)
then
129 message(1) =
'Cannot set iteration counter, as the new iteration is not commensurable with counter step.'
130 call messages_fatal(1)
133 this%iteration = int(counter%global_iteration / this%step)
134 this%global_iteration = counter%global_iteration
146 value = real(this%global_iteration, real64)
155 counter = this%iteration
170 integer,
intent(in) :: n
174 new_counter%iteration = new_counter%iteration + n
175 new_counter%global_iteration = new_counter%iteration * new_counter%step
182 integer,
intent(in) :: n
186 new_counter%iteration = new_counter%iteration - n
187 new_counter%global_iteration = new_counter%iteration * new_counter%step
196 this%global_iteration = 0
204 is_earlier = counter_a%global_iteration < counter_b%global_iteration
212 is_later = counter_a%global_iteration > counter_b%global_iteration
220 is_equal_or_earlier = counter_a%global_iteration <= counter_b%global_iteration
228 is_equal_or_later = counter_a%global_iteration >= counter_b%global_iteration
236 are_equal = counter_a%global_iteration == counter_b%global_iteration
244 are_diff = counter_a%global_iteration /= counter_b%global_iteration
251 character(len=*),
intent(in) :: filename
252 type(namespace_t),
intent(in) :: namespace
254 integer :: restart_file_unit
256 call io_mkdir(
"restart", namespace, parents=.
true.)
257 restart_file_unit = io_open(
"restart/"//filename, namespace, form=
"unformatted", action=
'write')
258 write(restart_file_unit) this%iteration, this%step
259 call io_close(restart_file_unit)
266 character(len=*),
intent(in) :: filename
267 type(namespace_t),
intent(in) :: namespace
269 integer :: restart_file_unit
271 restart_file_unit = io_open(
"restart/"//filename, namespace, form=
"unformatted", action=
'read', die=.false.)
272 if (restart_file_unit > 0)
then
273 read(restart_file_unit) this%iteration, this%step
274 call io_close(restart_file_unit)
276 this%global_iteration = this%iteration * this%step
277 restart_read = .
true.
280 restart_read = .false.
pure subroutine iteration_counter_reset(this)
elemental logical function iteration_counter_is_equal(counter_a, counter_b)
elemental logical function iteration_counter_is_equal_or_earlier(counter_a, counter_b)
elemental logical function iteration_counter_is_different(counter_a, counter_b)
pure integer(int64) function iteration_counter_global_step(this)
logical function iteration_counter_restart_read(this, filename, namespace)
pure real(real64) function iteration_counter_value(this)
Returns the value of the counter in the common reference frame.
pure integer function iteration_counter_counter(this)
Returns the value of the counter in the local reference frame.
subroutine iteration_counter_restart_write(this, filename, namespace)
elemental logical function iteration_counter_is_earlier(counter_a, counter_b)
pure type(iteration_counter_t) function iteration_counter_constructor(step, initial_iteration)
subroutine iteration_counter_set(this, counter)
type(iteration_counter_t) function iteration_counter_subtract(this, n)
elemental logical function iteration_counter_is_equal_or_later(counter_a, counter_b)
type(iteration_counter_t) function iteration_counter_add(this, n)
elemental logical function iteration_counter_is_later(counter_a, counter_b)
This class implements the iteration counter used by the multisystem algorithms. As any iteration coun...