MONC
Data Types | Functions/Subroutines | Variables
timeaveraged_time_manipulation_mod Module Reference

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

Data Types

type  time_averaged_completed_type
 The completed time averaged values. More...
 

Functions/Subroutines

subroutine, public init_time_averaged_manipulation ()
 Initialises the reduction action. More...
 
subroutine, public finalise_time_averaged_manipulation ()
 Finalises the reduction action, waiting for all outstanding requests and then freeing data. More...
 
logical function, public is_time_averaged_time_manipulation_ready_to_write (latest_time, output_frequency, write_time, latest_timestep, write_timestep)
 
type(data_values_type) function, public perform_timeaveraged_time_manipulation (instant_values, output_frequency, field_name, timestep, time)
 Performs the time averaged manipulation and only returns values if these are to be stored (i.e. past an output frequency) More...
 
subroutine time_average (timeaveraged_value, instant_values, time)
 Does the time averaging itself. More...
 
integer(kind=8) function, public prepare_to_serialise_time_averaged_state ()
 Prepares to serialise the time averaged state values. Both determines the storage size required and also issue locks. More...
 
subroutine, public serialise_time_averaged_state (byte_data)
 Serialises the state of this manipulator so that it can be restarted later on. Releases any locks issue during preparation. More...
 
subroutine, public unserialise_time_averaged_state (byte_data)
 Unserialises some byte data to initialise the state from some previous version. More...
 
integer(kind=8) function prepare_to_serialise_time_averaged_completed_value (time_av_value)
 Prepares to serialise a time averaged completed value, both determines the storage size and also issue any locks. More...
 
subroutine serialise_time_averaged_completed_value (time_av_value, byte_data, current_data_point)
 Serialises a specific time averaged completed value, releases any locks issued during preparation. More...
 
type(time_averaged_completed_type) function, pointer unserialise_time_averaged_completed_value (byte_data)
 Will create a specific time averaged completed value based upon the provided serialised data. More...
 
type(time_averaged_completed_type) function, pointer find_or_add_timeaveraged_value (timestep, field_name)
 Retrieves or creates (and retrieves) a time averaged value based upon the information provided. More...
 
type(time_averaged_completed_type) function, pointer find_timeaveraged_value (field_name, issue_read_lock)
 Finds a time averaged value based upon its field name. More...
 

Variables

type(hashmap_type), volatile timeaveraged_values
 
integer, volatile timeaveraged_value_rw_lock
 

Detailed Description

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

Function/Subroutine Documentation

◆ finalise_time_averaged_manipulation()

subroutine, public timeaveraged_time_manipulation_mod::finalise_time_averaged_manipulation

Finalises the reduction action, waiting for all outstanding requests and then freeing data.

Parameters
io_configurationConfiguration state of the IO server

Definition at line 45 of file timeaveraged_manipulation.F90.

46  call check_thread_status(forthread_rwlock_destroy(timeaveraged_value_rw_lock))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_or_add_timeaveraged_value()

type(time_averaged_completed_type) function, pointer timeaveraged_time_manipulation_mod::find_or_add_timeaveraged_value ( integer, intent(in)  timestep,
character(len=*), intent(in)  field_name 
)
private

Retrieves or creates (and retrieves) a time averaged value based upon the information provided.

Parameters
timestepThe corresponding timestep
field_nameThe corresponding field name
Returns
A matching or new time averaged value

Definition at line 280 of file timeaveraged_manipulation.F90.

281  integer, intent(in) :: timestep
282  character(len=*), intent(in) :: field_name
283  type(time_averaged_completed_type), pointer :: find_or_add_timeaveraged_value
284 
285  class(*), pointer :: generic
286  type(time_averaged_completed_type), pointer :: new_entry
287 
288  find_or_add_timeaveraged_value=>find_timeaveraged_value(field_name)
289  if (.not. associated(find_or_add_timeaveraged_value)) then
290  call check_thread_status(forthread_rwlock_wrlock(timeaveraged_value_rw_lock))
291  find_or_add_timeaveraged_value=>find_timeaveraged_value(field_name, .false.)
292  if (.not. associated(find_or_add_timeaveraged_value)) then
293  allocate(new_entry)
294  new_entry%field_name=field_name
295  new_entry%start_time=0.0_default_precision
296  new_entry%previous_time=0.0_default_precision
297  new_entry%empty_values=.true.
298  new_entry%previous_output_time=0.0_default_precision
299  call check_thread_status(forthread_mutex_init(new_entry%mutex, -1))
300  generic=>new_entry
301  call c_put_generic(timeaveraged_values, field_name, generic, .false.)
302  find_or_add_timeaveraged_value=>new_entry
303  end if
304  call check_thread_status(forthread_rwlock_unlock(timeaveraged_value_rw_lock))
305  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_timeaveraged_value()

type(time_averaged_completed_type) function, pointer timeaveraged_time_manipulation_mod::find_timeaveraged_value ( character(len=*), intent(in)  field_name,
logical, intent(in), optional  issue_read_lock 
)
private

Finds a time averaged value based upon its field name.

Parameters
field_nameThe corresponding field name
issue_read_lockOptional flag whether we should issue a read lock during this operation, if omitted then issues lock
Returns
The matching time averaged value or null if none is found

Definition at line 312 of file timeaveraged_manipulation.F90.

313  character(len=*), intent(in) :: field_name
314  type(time_averaged_completed_type), pointer :: find_timeaveraged_value
315  logical, intent(in), optional :: issue_read_lock
316 
317  class(*), pointer :: generic
318  logical :: do_read_lock
319 
320  if (present(issue_read_lock)) then
321  do_read_lock=issue_read_lock
322  else
323  do_read_lock=.true.
324  end if
325 
326  if (do_read_lock) call check_thread_status(forthread_rwlock_rdlock(timeaveraged_value_rw_lock))
327  generic=>c_get_generic(timeaveraged_values, field_name)
328  if (do_read_lock) call check_thread_status(forthread_rwlock_unlock(timeaveraged_value_rw_lock))
329  if (associated(generic)) then
330  select type(generic)
331  type is (time_averaged_completed_type)
332  find_timeaveraged_value=>generic
333  end select
334  else
335  find_timeaveraged_value=>null()
336  end if
Here is the caller graph for this function:

◆ init_time_averaged_manipulation()

subroutine, public timeaveraged_time_manipulation_mod::init_time_averaged_manipulation

Initialises the reduction action.

Definition at line 39 of file timeaveraged_manipulation.F90.

40  call check_thread_status(forthread_rwlock_init(timeaveraged_value_rw_lock, -1))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_time_averaged_time_manipulation_ready_to_write()

logical function, public timeaveraged_time_manipulation_mod::is_time_averaged_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 49 of file timeaveraged_manipulation.F90.

51  real, intent(in) :: latest_time, output_frequency, write_time
52  integer, intent(in) :: latest_timestep, write_timestep
53 
54  is_time_averaged_time_manipulation_ready_to_write=latest_time + output_frequency .gt. write_time

◆ perform_timeaveraged_time_manipulation()

type(data_values_type) function, public timeaveraged_time_manipulation_mod::perform_timeaveraged_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 time averaged manipulation and only returns values if these are to be stored (i.e. past an output frequency)

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 64 of file timeaveraged_manipulation.F90.

66  real(kind=default_precision), dimension(:), intent(in) :: instant_values
67  real, intent(in) :: output_frequency
68  real(kind=default_precision), intent(in) :: time
69  character(len=*), intent(in) :: field_name
70  integer, intent(in) :: timestep
71 
72  type(time_averaged_completed_type), pointer :: timeaveraged_value
73 
74  timeaveraged_value=>find_or_add_timeaveraged_value(timestep, field_name)
75 
76  call check_thread_status(forthread_mutex_lock(timeaveraged_value%mutex))
77  call time_average(timeaveraged_value, instant_values, time)
78 
79  if ((aint(time*10000000.0)-aint(timeaveraged_value%previous_output_time*10000000.0))/10000000.0 .ge. output_frequency) then
80  timeaveraged_value%previous_output_time=time
81  allocate(perform_timeaveraged_time_manipulation%values(size(timeaveraged_value%time_averaged_values)))
82  perform_timeaveraged_time_manipulation%values=timeaveraged_value%time_averaged_values
83  timeaveraged_value%time_averaged_values=0.0_default_precision
84  timeaveraged_value%start_time=time
85  timeaveraged_value%previous_time=time
86  timeaveraged_value%empty_values=.true.
87  end if
88  call check_thread_status(forthread_mutex_unlock(timeaveraged_value%mutex))
Here is the call graph for this function:

◆ prepare_to_serialise_time_averaged_completed_value()

integer(kind=8) function timeaveraged_time_manipulation_mod::prepare_to_serialise_time_averaged_completed_value ( type(time_averaged_completed_type), intent(inout)  time_av_value)
private

Prepares to serialise a time averaged completed value, both determines the storage size and also issue any locks.

Parameters
time_av_valueThe time averaged completed value to prepare for serialisation
Returns
The number of bytes needed to store the serialised state

Definition at line 213 of file timeaveraged_manipulation.F90.

214  type(time_averaged_completed_type), intent(inout) :: time_av_value
215 
216  call check_thread_status(forthread_mutex_lock(time_av_value%mutex))
217 
218  prepare_to_serialise_time_averaged_completed_value=(kind(time_av_value%start_time) * 3) + kind(time_av_value%empty_values) + &
219  (size(time_av_value%time_averaged_values) * kind(time_av_value%time_averaged_values)) + &
220  (kind(prepare_to_serialise_time_averaged_completed_value) * 2) + len(time_av_value%field_name)
Here is the caller graph for this function:

◆ prepare_to_serialise_time_averaged_state()

integer(kind=8) function, public timeaveraged_time_manipulation_mod::prepare_to_serialise_time_averaged_state

Prepares to serialise the time averaged state values. Both determines the storage size required and also issue locks.

Returns
The number of bytes needed to store the serialised state

Definition at line 127 of file timeaveraged_manipulation.F90.

128  type(mapentry_type) :: map_entry
129  type(iterator_type) :: iterator
130  class(*), pointer :: generic
131 
132  call check_thread_status(forthread_rwlock_rdlock(timeaveraged_value_rw_lock))
133 
134  prepare_to_serialise_time_averaged_state=kind(prepare_to_serialise_time_averaged_state)
135  iterator=c_get_iterator(timeaveraged_values)
136  do while (c_has_next(iterator))
137  map_entry=c_next_mapentry(iterator)
138  generic=>c_get_generic(map_entry)
139  if (associated(generic)) then
140  select type(generic)
141  type is (time_averaged_completed_type)
142  prepare_to_serialise_time_averaged_state=prepare_to_serialise_time_averaged_state+&
143  prepare_to_serialise_time_averaged_completed_value(generic)+&
144  (kind(prepare_to_serialise_time_averaged_state)*2)+len(trim(map_entry%key))
145  end select
146  end if
147  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialise_time_averaged_completed_value()

subroutine timeaveraged_time_manipulation_mod::serialise_time_averaged_completed_value ( type(time_averaged_completed_type), intent(inout)  time_av_value,
character, dimension(:), intent(inout), allocatable  byte_data,
integer, intent(inout)  current_data_point 
)
private

Serialises a specific time averaged completed value, releases any locks issued during preparation.

Parameters
time_av_valueThe time averaged completed value to serialise
byte_dataResulting byte data that holds a representation of this
current_data_pointThe current write point in the byte data, is updated during call so represents next point on return

Definition at line 227 of file timeaveraged_manipulation.F90.

228  type(time_averaged_completed_type), intent(inout) :: time_av_value
229  character, dimension(:), allocatable, intent(inout) :: byte_data
230  integer, intent(inout) :: current_data_point
231 
232  integer :: i
233 
234  current_data_point=pack_scalar_field(byte_data, current_data_point, double_real_value=time_av_value%start_time)
235  current_data_point=pack_scalar_field(byte_data, current_data_point, double_real_value=time_av_value%previous_time)
236  current_data_point=pack_scalar_field(byte_data, current_data_point, double_real_value=time_av_value%previous_output_time)
237  current_data_point=pack_scalar_field(byte_data, current_data_point, logical_value=time_av_value%empty_values)
238  current_data_point=pack_scalar_field(byte_data, current_data_point, len(trim(time_av_value%field_name)))
239  byte_data(current_data_point:current_data_point+len(trim(time_av_value%field_name))-1) = transfer(&
240  trim(time_av_value%field_name), byte_data(current_data_point:current_data_point+len(trim(time_av_value%field_name))-1))
241  current_data_point=current_data_point+len(trim(time_av_value%field_name))
242  current_data_point=pack_scalar_field(byte_data, current_data_point, size(time_av_value%time_averaged_values))
243  current_data_point=pack_array_field(byte_data, current_data_point, real_array_1d=time_av_value%time_averaged_values)
244  call check_thread_status(forthread_mutex_unlock(time_av_value%mutex))
Here is the caller graph for this function:

◆ serialise_time_averaged_state()

subroutine, public timeaveraged_time_manipulation_mod::serialise_time_averaged_state ( character, dimension(:), intent(inout), allocatable  byte_data)

Serialises the state of this manipulator so that it can be restarted later on. Releases any locks issue during preparation.

Parameters
byte_dataThe byte data that represents the serialised state

Definition at line 152 of file timeaveraged_manipulation.F90.

153  character, dimension(:), allocatable, intent(inout) :: byte_data
154 
155  integer :: current_data_point, prev_pt
156  type(mapentry_type) :: map_entry
157  type(iterator_type) :: iterator
158  class(*), pointer :: generic
159 
160  current_data_point=1
161  current_data_point=pack_scalar_field(byte_data, current_data_point, c_size(timeaveraged_values))
162 
163  iterator=c_get_iterator(timeaveraged_values)
164  do while (c_has_next(iterator))
165  map_entry=c_next_mapentry(iterator)
166  generic=>c_get_generic(map_entry)
167  if (associated(generic)) then
168  select type(generic)
169  type is (time_averaged_completed_type)
170  current_data_point=pack_scalar_field(byte_data, current_data_point, len(trim(map_entry%key)))
171  byte_data(current_data_point:current_data_point+len(trim(map_entry%key))-1) = transfer(trim(map_entry%key), &
172  byte_data(current_data_point:current_data_point+len(trim(map_entry%key))-1))
173  current_data_point=current_data_point+len(trim(map_entry%key))
174 
175  prev_pt=current_data_point
176  current_data_point=current_data_point+kind(current_data_point)
177  call serialise_time_averaged_completed_value(generic, byte_data, current_data_point)
178  prev_pt=pack_scalar_field(byte_data, prev_pt, (current_data_point-kind(current_data_point)) - prev_pt)
179  end select
180  end if
181  end do
182  call check_thread_status(forthread_rwlock_unlock(timeaveraged_value_rw_lock))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ time_average()

subroutine timeaveraged_time_manipulation_mod::time_average ( type(time_averaged_completed_type), intent(inout)  timeaveraged_value,
real(kind=default_precision), dimension(:), intent(in)  instant_values,
real(kind=default_precision), intent(in)  time 
)
private

Does the time averaging itself.

Parameters
timeaveraged_valueThe time averaged value to update
instant_valuesThe instant values to integrate in
timeThe model time

Definition at line 95 of file timeaveraged_manipulation.F90.

96  type(time_averaged_completed_type), intent(inout) :: timeaveraged_value
97  real(kind=default_precision), dimension(:), intent(in) :: instant_values
98  real(kind=default_precision), intent(in) :: time
99 
100  integer :: i
101  real(kind=default_precision) :: timeav, timedg, combined_add
102 
103  timeav=time-timeaveraged_value%start_time
104  timedg=time-timeaveraged_value%previous_time
105  combined_add=timeav+timedg
106 
107  if (.not. allocated(timeaveraged_value%time_averaged_values)) then
108  allocate(timeaveraged_value%time_averaged_values(size(instant_values)))
109  timeaveraged_value%time_averaged_values=0.0_default_precision
110  end if
111 
112  if (timeaveraged_value%empty_values) then
113  timeaveraged_value%empty_values=.false.
114  timeaveraged_value%time_averaged_values=instant_values
115  else
116  do i=1, size(instant_values)
117  timeaveraged_value%time_averaged_values(i)=(timeav*timeaveraged_value%time_averaged_values(i)+&
118  timedg*instant_values(i)) / combined_add
119  end do
120  end if
121 
122  timeaveraged_value%previous_time=time
Here is the caller graph for this function:

◆ unserialise_time_averaged_completed_value()

type(time_averaged_completed_type) function, pointer timeaveraged_time_manipulation_mod::unserialise_time_averaged_completed_value ( character, dimension(:), intent(in)  byte_data)
private

Will create a specific time averaged completed value based upon the provided serialised data.

Parameters
byte_dataThe serialised byte data to read and initialise from

Definition at line 249 of file timeaveraged_manipulation.F90.

250  character, dimension(:), intent(in) :: byte_data
251  type(time_averaged_completed_type), pointer :: unserialise_time_averaged_completed_value
252 
253  integer :: current_data_point, i, values_size, byte_size, str_size
254 
255  allocate(unserialise_time_averaged_completed_value)
256  current_data_point=1
257  unserialise_time_averaged_completed_value%start_time=unpack_scalar_dp_real_from_bytedata(byte_data, current_data_point)
258  unserialise_time_averaged_completed_value%previous_time=unpack_scalar_dp_real_from_bytedata(byte_data, current_data_point)
259  unserialise_time_averaged_completed_value%previous_output_time=&
260  unpack_scalar_dp_real_from_bytedata(byte_data, current_data_point)
261  unserialise_time_averaged_completed_value%empty_values=unpack_scalar_logical_from_bytedata(byte_data, current_data_point)
262  str_size=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
263  unserialise_time_averaged_completed_value%field_name=&
264  transfer(byte_data(current_data_point:current_data_point+str_size-1), &
265  unserialise_time_averaged_completed_value%field_name)
266  unserialise_time_averaged_completed_value%field_name(str_size+1:)=" "
267  current_data_point=current_data_point+str_size
268  values_size=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
269  allocate(unserialise_time_averaged_completed_value%time_averaged_values(values_size))
270  byte_size=values_size*kind(unserialise_time_averaged_completed_value%time_averaged_values)
271  unserialise_time_averaged_completed_value%time_averaged_values=transfer(byte_data(current_data_point:&
272  current_data_point+byte_size-1), unserialise_time_averaged_completed_value%time_averaged_values)
273  call check_thread_status(forthread_mutex_init(unserialise_time_averaged_completed_value%mutex, -1))
Here is the caller graph for this function:

◆ unserialise_time_averaged_state()

subroutine, public timeaveraged_time_manipulation_mod::unserialise_time_averaged_state ( character, dimension(:), intent(in)  byte_data)

Unserialises some byte data to initialise the state from some previous version.

Parameters
byte_dataThe byte data to read from and initialise from

Definition at line 187 of file timeaveraged_manipulation.F90.

188  character, dimension(:), intent(in) :: byte_data
189 
190  integer :: current_data_point, number_entries, i, key_size, byte_size
191  character(len=STRING_LENGTH) :: value_key
192  class(*), pointer :: generic
193 
194  current_data_point=1
195  number_entries=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
196  if (number_entries .gt. 0) then
197  do i=1, number_entries
198  key_size=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
199  value_key=transfer(byte_data(current_data_point:current_data_point+key_size-1), value_key)
200  value_key(key_size+1:)=" "
201  current_data_point=current_data_point+key_size
202  byte_size=unpack_scalar_integer_from_bytedata(byte_data, current_data_point)
203  generic=>unserialise_time_averaged_completed_value(byte_data(current_data_point:current_data_point+byte_size-1))
204  call c_put_generic(timeaveraged_values, value_key, generic, .false.)
205  current_data_point=current_data_point+byte_size
206  end do
207  end if
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ timeaveraged_value_rw_lock

integer, volatile timeaveraged_time_manipulation_mod::timeaveraged_value_rw_lock
private

Definition at line 31 of file timeaveraged_manipulation.F90.

31  integer, volatile :: timeaveraged_value_rw_lock

◆ timeaveraged_values

type(hashmap_type), volatile timeaveraged_time_manipulation_mod::timeaveraged_values
private

Definition at line 30 of file timeaveraged_manipulation.F90.

30  type(hashmap_type), volatile :: timeaveraged_values
datadefn_mod::default_precision
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17