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 ! ---------------------------------------------------------
70 type(iteration_counter_t) pure function clock_constructor(time_step, initial_iteration) result(clock)
71 real(real64), optional, intent(in) :: time_step
72 integer, optional, intent(in) :: initial_iteration
73
74 if (present(initial_iteration)) then
75 clock%iteration = initial_iteration
76 end if
77 if (present(time_step)) then
78 if (time_step > m_zero) then
79 clock%step = int(time_step/clock_minimum_dt, int64)
80 else
81 clock%step = 1
82 end if
83 end if
84 clock%global_iteration = clock%step * clock%iteration
85
86 clock%value => clock_time
87
88 end function clock_constructor
89
90 ! ---------------------------------------------------------
91 pure real(real64) function clock_time(this)
92 class(iteration_counter_t), intent(in) :: this
93
94 clock_time = this%global_iteration * clock_minimum_dt
95
96 end function clock_time
97
98end module clock_oct_m
99
100!! Local Variables:
101!! mode: f90
102!! coding: utf-8
103!! End:
type(iteration_counter_t) pure function clock_constructor(time_step, initial_iteration)
Initialize the clock with a given time step.
Definition: clock.F90:164
pure real(real64) function clock_time(this)
Definition: clock.F90:185
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:187