MONC
Functions/Subroutines | Variables
instantaneous_time_manipulation_mod Module Reference

Performs instantaneous time manipulation and only returns a value if the output frequency determines one should be. More...

Functions/Subroutines

subroutine, public init_instantaneous_manipulation ()
 Initialises the instantaneous time manipulation. More...
 
subroutine, public finalise_instantaneous_manipulation ()
 Finalises the instantaneous time manipulation. More...
 
logical function, public is_instantaneous_time_manipulation_ready_to_write (latest_time, output_frequency, write_time, latest_timestep, write_timestep)
 
type(data_values_type) function, public perform_instantaneous_time_manipulation (instant_values, output_frequency, field_name, timestep, time)
 Performs the instantaneous time manipulation and returns data only if this is to be written to the storage. Internally a state is maintained which tracks when the write was last done to allow for flexibility in the time criteria. More...
 
logical function deduce_whether_to_issue_values (field_name, output_frequency, time)
 Determines whether to issue values for write or not. This depends on the time and output frequency. More...
 
integer(kind=8) function, public prepare_to_serialise_instantaneous_state ()
 Prepares to serialise the instantaneous state, both determines the byte storage size and issues any locks. More...
 
subroutine, public serialise_instantaneous_state (byte_data)
 Will serialise the state of this manipulator so that it can be later restarted. Any locks issued during preparation are released here. More...
 
subroutine, public unserialise_instantaneous_state (byte_data)
 Unpacks some serialised byte data to initialise this manipulator to some previous state. More...
 

Variables

integer, volatile existing_instantaneous_writes_mutex
 
type(hashmap_type), volatile existing_instantaneous_writes
 

Detailed Description

Performs instantaneous time manipulation and only returns a value if the output frequency determines one should be.

Function/Subroutine Documentation

◆ deduce_whether_to_issue_values()

logical function instantaneous_time_manipulation_mod::deduce_whether_to_issue_values ( character(len=*), intent(in)  field_name,
real, intent(in)  output_frequency,
real(kind=default_precision), intent(in)  time 
)
private

Determines whether to issue values for write or not. This depends on the time and output frequency.

Parameters
field_nameThe field name that we are manipulating
output_frequencyConfigured output time frequency
timeThe current model time
Returns
Whether or not one should issue the instantaneous values to write

Definition at line 74 of file instantaneous_manipulation.F90.

74  character(len=*), intent(in) :: field_name
75  real, intent(in) :: output_frequency
76  real(kind=DEFAULT_PRECISION), intent(in) :: time
77 
78  real(kind=DEFAULT_PRECISION) :: previous_time_write, time_difference
79 
80  call check_thread_status(forthread_mutex_lock(existing_instantaneous_writes_mutex))
81  if (c_contains(existing_instantaneous_writes, field_name)) then
82  previous_time_write=c_get_real(existing_instantaneous_writes, field_name)
83  time_difference=(aint(time*10000000.0)-aint(previous_time_write*10000000.0))/10000000.0
84  else
85  ! Rethink this as only works if started at time=0
86  time_difference=time
87  end if
88  if (time_difference .ge. output_frequency) then
89  deduce_whether_to_issue_values=.true.
90  call c_put_real(existing_instantaneous_writes, field_name, time)
91  else
92  deduce_whether_to_issue_values=.false.
93  end if
94  call check_thread_status(forthread_mutex_unlock(existing_instantaneous_writes_mutex))
Here is the caller graph for this function:

◆ finalise_instantaneous_manipulation()

subroutine, public instantaneous_time_manipulation_mod::finalise_instantaneous_manipulation ( )

Finalises the instantaneous time manipulation.

Definition at line 34 of file instantaneous_manipulation.F90.

34  call check_thread_status(forthread_mutex_destroy(existing_instantaneous_writes_mutex))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_instantaneous_manipulation()

subroutine, public instantaneous_time_manipulation_mod::init_instantaneous_manipulation ( )

Initialises the instantaneous time manipulation.

Definition at line 29 of file instantaneous_manipulation.F90.

29  call check_thread_status(forthread_mutex_init(existing_instantaneous_writes_mutex, -1))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_instantaneous_time_manipulation_ready_to_write()

logical function, public instantaneous_time_manipulation_mod::is_instantaneous_time_manipulation_ready_to_write ( real, intent(in)  latest_time,
real, intent(in)  output_frequency,
real, intent(in)  write_time,
integer, intent(in)  latest_timestep,
integer, intent(in)  write_timestep 
)

Definition at line 39 of file instantaneous_manipulation.F90.

39  real, intent(in) :: latest_time, output_frequency, write_time
40  integer, intent(in) :: latest_timestep, write_timestep
41 
42  is_instantaneous_time_manipulation_ready_to_write=latest_time + output_frequency .gt. write_time

◆ perform_instantaneous_time_manipulation()

type(data_values_type) function, public instantaneous_time_manipulation_mod::perform_instantaneous_time_manipulation ( real(kind=default_precision), dimension(:), intent(in)  instant_values,
real, intent(in)  output_frequency,
character(len=*), intent(in)  field_name,
integer, intent(in)  timestep,
real(kind=default_precision), intent(in)  time 
)

Performs the instantaneous time manipulation and returns data only if this is to be written to the storage. Internally a state is maintained which tracks when the write was last done to allow for flexibility in the time criteria.

Parameters
instant_valuesThe instantaneous values to work with
output_frequencyThe output frequency configuration option
field_nameThe field name
timestepThe timestep
timeThe model time
Returns
An allocated array of reals if data is to be stored, otherwise this is unallocated

Definition at line 56 of file instantaneous_manipulation.F90.

56  real(kind=DEFAULT_PRECISION), dimension(:), intent(in) :: instant_values
57  real, intent(in) :: output_frequency
58  real(kind=DEFAULT_PRECISION), intent(in) :: time
59  character(len=*), intent(in) :: field_name
60  integer, intent(in) :: timestep
61 
62  if (deduce_whether_to_issue_values(field_name, output_frequency, time)) then
63  allocate(perform_instantaneous_time_manipulation%values(size(instant_values)))
64  perform_instantaneous_time_manipulation%values=instant_values
65  end if
Here is the call graph for this function:

◆ prepare_to_serialise_instantaneous_state()

integer(kind=8) function, public instantaneous_time_manipulation_mod::prepare_to_serialise_instantaneous_state ( )

Prepares to serialise the instantaneous state, both determines the byte storage size and issues any locks.

Returns
The number of bytes needed to store the serialised state

Definition at line 100 of file instantaneous_manipulation.F90.

100  real(kind=DEFAULT_PRECISION) :: a
101 
102  call check_thread_status(forthread_mutex_lock(existing_instantaneous_writes_mutex))
103  prepare_to_serialise_instantaneous_state=kind(prepare_to_serialise_instantaneous_state) + &
104  ((string_length + kind(a)) * c_size(existing_instantaneous_writes))
Here is the caller graph for this function:

◆ serialise_instantaneous_state()

subroutine, public instantaneous_time_manipulation_mod::serialise_instantaneous_state ( character, dimension(:), intent(inout), allocatable  byte_data)

Will serialise the state of this manipulator so that it can be later restarted. Any locks issued during preparation are released here.

Parameters
byte_dataThe state of this manipulator is written into here

Definition at line 111 of file instantaneous_manipulation.F90.

111  character, dimension(:), allocatable, intent(inout) :: byte_data
112 
113  integer :: current_data_point
114  type(mapentry_type) :: map_entry
115  type(iterator_type) :: iterator
116 
117  current_data_point=1
118  current_data_point=pack_scalar_field(byte_data, current_data_point, c_size(existing_instantaneous_writes))
119  iterator=c_get_iterator(existing_instantaneous_writes)
120  do while (c_has_next(iterator))
121  map_entry=c_next_mapentry(iterator)
122  current_data_point=pack_scalar_field(byte_data, current_data_point, string_value=map_entry%key)
123  current_data_point=pack_scalar_field(byte_data, current_data_point, double_real_value=c_get_real(map_entry))
124  end do
125  call check_thread_status(forthread_mutex_unlock(existing_instantaneous_writes_mutex))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unserialise_instantaneous_state()

subroutine, public instantaneous_time_manipulation_mod::unserialise_instantaneous_state ( character, dimension(:), intent(in), allocatable  byte_data)

Unpacks some serialised byte data to initialise this manipulator to some previous state.

Parameters
byte_dataThe byte data to unpack and reinitialise from

Definition at line 131 of file instantaneous_manipulation.F90.

131  character, dimension(:), allocatable, intent(in) :: byte_data
132 
133  integer :: current_data_point, number_entries, i
134 
135  current_data_point=1
136  number_entries=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
137  if (number_entries .gt. 0) then
138  do i=1, number_entries
139  call c_put_real(existing_instantaneous_writes, unpack_scalar_string_from_bytedata(byte_data, current_data_point), &
140  unpack_scalar_dp_real_from_bytedata(byte_data, current_data_point))
141  end do
142  end if
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ existing_instantaneous_writes

type(hashmap_type), volatile instantaneous_time_manipulation_mod::existing_instantaneous_writes
private

Definition at line 20 of file instantaneous_manipulation.F90.

20  type(hashmap_type), volatile :: existing_instantaneous_writes

◆ existing_instantaneous_writes_mutex

integer, volatile instantaneous_time_manipulation_mod::existing_instantaneous_writes_mutex
private

Definition at line 19 of file instantaneous_manipulation.F90.

19  integer, volatile :: existing_instantaneous_writes_mutex