Octopus
clock.F90
Go to the documentation of this file.
1!! Copyright (C) 2023 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
21module clock_oct_m
22 use, intrinsic :: iso_fortran_env
23 use global_oct_m
25
26 implicit none
27
28 private
29
30 public :: clock_t, &
32
52 real(real64), parameter :: CLOCK_MINIMUM_DT = 1.0e-13_real64
53
54 interface clock_t
55 module procedure clock_constructor
56 end interface clock_t
57
58contains
59
60 ! ---------------------------------------------------------
74 type(iteration_counter_t) pure function clock_constructor(time_step, initial_iteration) result(clock)
75 real(real64), optional, intent(in) :: time_step
76 integer, optional, intent(in) :: initial_iteration
77
78 if (present(initial_iteration)) then
79 clock%iteration = initial_iteration
80 end if
81 if (present(time_step)) then
82 if (time_step > m_zero) then
83 clock%step = int(time_step/clock_minimum_dt, int64)
84 else
85 clock%step = 1
86 end if
87 end if
88 clock%global_iteration = clock%step * clock%iteration
89
90 clock%value => clock_time
91
92 end function clock_constructor
93
94 ! ---------------------------------------------------------
95 pure real(real64) function clock_time(this)
96 class(iteration_counter_t), intent(in) :: this
97
98 clock_time = this%global_iteration * clock_minimum_dt
99
100 end function clock_time
101
102end module clock_oct_m
103
104!! Local Variables:
105!! mode: f90
106!! coding: utf-8
107!! End:
type(iteration_counter_t) pure function clock_constructor(time_step, initial_iteration)
Initialize the clock with a given time step.
Definition: clock.F90:168
pure real(real64) function clock_time(this)
Definition: clock.F90:189
real(real64), parameter, public clock_minimum_dt
This CLOCK_MINIMUM_DT parameter defines what is the time-step in the common reference frame of all cl...
Definition: clock.F90:145
real(real64), parameter, public m_zero
Definition: global.F90:188