vkf_clock Module

The simulation clock: simulation time from wall-clock time, with a time scale, pause and a time range, as in OpenFrames' WindowProxy.

While running, time = offset + (wall - wall_ref) * scale, limited to the time range. Setting the time, pausing and changing the scale restart the count from the current time (offset = time, wall_ref = now). A clock can be synchronized to another one (synchronize), whose time it then reports and whose settings it changes.

Wall time is in seconds from system_clock, unless given explicitly with the optional wall arguments (for tests, or for driving the clock from a host).


Uses

  • module~~vkf_clock~~UsesGraph module~vkf_clock vkf_clock iso_fortran_env iso_fortran_env module~vkf_clock->iso_fortran_env module~vkf_math vkf_math module~vkf_clock->module~vkf_math module~vkf_math->iso_fortran_env

Used by

  • module~~vkf_clock~~UsedByGraph module~vkf_clock vkf_clock module~vkf_window vkf_window module~vkf_window->module~vkf_clock module~vkframes vkframes module~vkframes->module~vkf_clock module~vkframes->module~vkf_window

Derived Types

type, public ::  SimulationClock

A simulation clock (see the module documentation).

Components

Type Visibility Attributes Name Initial
real(kind=wp), private :: offset = 0.0_wp

simulation time at wall_ref (s)

logical, private :: paused_ = .false.

true while paused

real(kind=wp), private :: scale_ = 1.0_wp

simulation seconds per wall second

logical, private :: started = .false.

false until counting first started (set_time or update)

type(SimulationClock), private, pointer :: sync => null()

the clock this one is synchronized to (not owned)

real(kind=wp), private :: t_max = huge(1.0_wp)

end of the time range (s; default unlimited)

real(kind=wp), private :: t_min = -huge(1.0_wp)

start of the time range (s; default unlimited)

real(kind=wp), private :: time_ = 0.0_wp

the current simulation time (s)

real(kind=wp), private :: wall_ref = 0.0_wp

wall time (s) at which counting restarted

Type-Bound Procedures

procedure, public :: is_paused
procedure, public :: pause
procedure, public :: set_time
procedure, public :: set_time_range
procedure, public :: set_time_scale
procedure, public :: synchronize
procedure, public :: synchronized_to
procedure, public :: time
procedure, public :: time_range
procedure, public :: time_scale
procedure, public :: update

Functions

private recursive function is_paused(self)

True if the simulation time is paused.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(in) :: self

Return Value logical

private function now(wall)

The wall time (s): wall if present, else wall_time().

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), optional :: wall

wall time (s)

Return Value real(kind=wp)

private function same_clock(a, b)

True if a points to the clock b.

Arguments

Type IntentOptional Attributes Name
type(SimulationClock), intent(in), pointer :: a

the clock pointer (may be null)

class(SimulationClock), intent(in), target :: b

the clock

Return Value logical

private recursive function synchronize(self, master, wall) result(ok)

Follow master's time (it must stay alive while synchronized), or stop following (master not associated, or this clock itself), keeping the master's current time and settings. Returns false, and changes nothing, if this would make a cycle.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout), target :: self
type(SimulationClock), intent(in), pointer :: master

the clock to follow (null: stop following)

real(kind=wp), intent(in), optional :: wall

wall time (s; default: wall_time())

Return Value logical

private function synchronized_to(self) result(master)

The clock this one is synchronized to (null if none).

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(in) :: self

Return Value type(SimulationClock), pointer

private recursive function time(self)

The simulation time at the last update (or as last set).

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(in) :: self

Return Value real(kind=wp)

private recursive function time_scale(self)

Simulation seconds per wall-clock second.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(in) :: self

Return Value real(kind=wp)

private function update(self, wall) result(t)

Advance the clock to the current wall time (call once per frame) and return the simulation time.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout) :: self
real(kind=wp), intent(in), optional :: wall

wall time (s; default: wall_time())

Return Value real(kind=wp)

public function wall_time()

Wall-clock time in seconds (system_clock), for the clock's default.

Arguments

None

Return Value real(kind=wp)


Subroutines

private recursive subroutine pause(self, paused, wall)

Pause (true) or resume (false) the simulation time.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout) :: self
logical, intent(in) :: paused

true: pause; false: resume

real(kind=wp), intent(in), optional :: wall

wall time (s; default: wall_time())

private recursive subroutine set_time(self, t, wall)

Set the simulation time (limited to the time range) and restart counting from it.

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout) :: self
real(kind=wp), intent(in) :: t

simulation time (s)

real(kind=wp), intent(in), optional :: wall

wall time (s; default: wall_time())

private recursive subroutine set_time_range(self, t_min, t_max)

Limit the simulation time to [t_min, t_max] (ignored if t_max < t_min).

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout) :: self
real(kind=wp), intent(in) :: t_min

the time range (s)

real(kind=wp), intent(in) :: t_max

the time range (s)

private recursive subroutine set_time_scale(self, scale, wall)

Simulation seconds per wall-clock second (may be 0 or negative).

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(inout) :: self
real(kind=wp), intent(in) :: scale

simulation seconds per wall-clock second

real(kind=wp), intent(in), optional :: wall

wall time (s; default: wall_time())

private recursive subroutine time_range(self, t_min, t_max)

The time range the simulation time is limited to (s; +-huge() if unlimited).

Arguments

Type IntentOptional Attributes Name
class(SimulationClock), intent(in) :: self
real(kind=wp), intent(out) :: t_min

the time range (s)

real(kind=wp), intent(out) :: t_max

the time range (s)