SimulationClock Derived Type

type, public :: SimulationClock

A simulation clock (see the module documentation).


Inherited by

type~~simulationclock~~InheritedByGraph type~simulationclock SimulationClock type~simulationclock->type~simulationclock sync type~windowproxy WindowProxy type~windowproxy->type~simulationclock clock_

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

  • 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

procedure, public :: pause

  • 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())

procedure, public :: set_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())

procedure, public :: set_time_range

  • 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)

procedure, public :: set_time_scale

  • 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())

procedure, public :: synchronize

  • 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

procedure, public :: synchronized_to

  • 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

procedure, public :: time

  • 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)

procedure, public :: time_range

  • 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)

procedure, public :: time_scale

  • 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)

procedure, public :: update

  • 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)

Source Code

    type, public :: SimulationClock
        private
        real(wp) :: time_ = 0.0_wp          !! the current simulation time (s)
        real(wp) :: offset = 0.0_wp         !! simulation time at wall_ref (s)
        real(wp) :: wall_ref = 0.0_wp       !! wall time (s) at which counting restarted
        real(wp) :: scale_ = 1.0_wp         !! simulation seconds per wall second
        real(wp) :: t_min = -huge(1.0_wp)   !! start of the time range (s; default unlimited)
        real(wp) :: t_max = huge(1.0_wp)    !! end of the time range (s; default unlimited)
        logical :: paused_ = .false.        !! true while paused
        logical :: started = .false.        !! false until counting first started (set_time or update)
        type(SimulationClock), pointer :: sync => null()    !! the clock this one is synchronized to (not owned)
    contains
        procedure :: update
        procedure :: time, set_time
        procedure :: set_time_range, time_range
        procedure :: pause, is_paused
        procedure :: set_time_scale, time_scale
        procedure :: synchronize, synchronized_to
    end type SimulationClock