MONC
cfltest.F90
Go to the documentation of this file.
1 
5 module cfltest_mod
9  use collections_mod, only : map_type
13  use grids_mod, only : z_index, y_index, x_index
14  use mpi, only : mpi_max, mpi_min
15  implicit none
16 
17 #ifndef TEST_MODE
18  private
19 #endif
20 
21  !! Configuration options - all are optional and have default values
22  real(kind=DEFAULT_PRECISION) :: tollerance, cvismax, cvelmax, dtmmax, dtmmin, rincmax
24 contains
25 
29  cfltest_get_descriptor%name="cfltest"
30  cfltest_get_descriptor%version=0.1
33  end function cfltest_get_descriptor
34 
37  subroutine initialisation_callback(current_state)
38  type(model_state_type), intent(inout), target :: current_state
39 
40  current_state%cfl_frequency=options_get_integer(current_state%options_database, "cfl_frequency")
41  tollerance=options_get_real(current_state%options_database, "cfl_tollerance")
42  cvismax=options_get_real(current_state%options_database, "cfl_cvismax")
43  cvelmax=options_get_real(current_state%options_database, "cfl_cvelmax")
44  dtmmax=options_get_real(current_state%options_database, "cfl_dtmmax")
45  dtmmin=options_get_real(current_state%options_database, "cfl_dtmmin")
46  rincmax=options_get_real(current_state%options_database, "cfl_rincmax")
47 
48  allocate(current_state%abswmax(current_state%local_grid%local_domain_end_index(z_index)))
49  end subroutine initialisation_callback
50 
54  subroutine timestep_callback(current_state)
55  type(model_state_type), intent(inout), target :: current_state
56 
57  real(kind=DEFAULT_PRECISION) :: cfl_number
58 
59  if (mod(current_state%timestep, current_state%cfl_frequency) == 1 .or. &
60  current_state%timestep-current_state%start_timestep .le. current_state%cfl_frequency) then
61  current_state%cvel=0.0_default_precision
62  current_state%cvel_x=0.0_default_precision
63  current_state%cvel_y=0.0_default_precision
64  current_state%cvel_z=0.0_default_precision
65 
67 
68  current_state%cvel=(current_state%cvel_x*current_state%global_grid%configuration%horizontal%cx+current_state%cvel_y*&
69  current_state%global_grid%configuration%horizontal%cy+current_state%cvel_z)*current_state%dtm
70  current_state%cvis=current_state%cvis*(current_state%dtm * 4)
71 
72  cfl_number=current_state%cvis/cvismax+current_state%cvel/cvelmax
73 
74  current_state%absolute_new_dtm=current_state%dtm
75  current_state%update_dtm=.false.
76  if (cfl_number .gt. 0.0_default_precision) then
77  if (cfl_number .lt. (1.0_default_precision-tollerance) .or. cfl_number .gt. (1.0_default_precision+tollerance)) then
78  current_state%absolute_new_dtm=current_state%dtm/cfl_number
79  end if
80  end if
81  end if
82  call update_dtm_based_on_absolute(current_state)
83  current_state%cvis=0.0_default_precision
84  end subroutine timestep_callback
85 
90  subroutine update_dtm_based_on_absolute(current_state)
91  type(model_state_type), intent(inout), target :: current_state
92 
93  if (current_state%dtm .ne. current_state%absolute_new_dtm .and. &
94  (current_state%dtm .ne. dtmmax .or. current_state%absolute_new_dtm .lt. dtmmax)) then
95  current_state%update_dtm=.true.
96  current_state%dtm_new=min(current_state%dtm*(1.0_default_precision+rincmax), current_state%absolute_new_dtm, dtmmax)
97  if (current_state%parallel%my_rank==0) then
98  if (log_get_logging_level() .eq. log_debug) then
99  call log_log(log_debug, "dtm changed from "//trim(conv_to_string(current_state%dtm, 5))//" to "//&
100  trim(conv_to_string(current_state%dtm_new, 5)))
101  end if
102  if (current_state%dtm_new .lt. dtmmin) then
103  call log_log(log_error, "Timestep too small, dtmnew="//trim(conv_to_string(current_state%dtm_new, 5))//&
104  " dtmmin="//trim(conv_to_string(dtmmin, 5)))
105  end if
106  end if
107  end if
108  end subroutine update_dtm_based_on_absolute
109 
114  type(model_state_type), intent(inout), target :: current_state
115 
116  integer :: k
117  real(kind=DEFAULT_PRECISION) :: global_zumin, global_zumax, global_zvmin, &
118  global_zvmax, global_cvel_z, global_cvis
119 
120 #ifdef U_ACTIVE
121  current_state%local_zumin=current_state%local_zumin+current_state%ugal ! _undo Gal-trfm
122  current_state%local_zumax=current_state%local_zumax+current_state%ugal
123 #else
124  current_state%local_zumin=0.0_default_precision
125  current_state%local_zumax=0.0_default_precision
126 #endif
127 #ifdef V_ACTIVE
128  current_state%local_zvmin=current_state%local_zvmin+current_state%vgal ! _undo Gal-trfm
129  current_state%local_zvmax=current_state%local_zvmax+current_state%vgal
130 #else
131  current_state%local_zvmin=0.0_default_precision
132  current_state%local_zvmax=0.0_default_precision
133 #endif
134 #ifdef W_ACTIVE
135  current_state%local_cvel_z=current_state%cvel_z
136  do k=2,current_state%local_grid%local_domain_end_index(z_index)-1
137  ! CVELZ will be multiplied by DTM in TESTCFL
138  current_state%local_cvel_z=max(current_state%local_cvel_z, &
139  current_state%abswmax(k)*current_state%global_grid%configuration%vertical%rdzn(k+1))
140  end do
141 #else
142  current_state%local_cvel_z=0.0_default_precision
143 #endif
144  call get_global_values(current_state%local_zumin, current_state%local_zumax, current_state%local_zvmin, &
145  current_state%local_zvmax, current_state%local_cvel_z, current_state%cvis, &
146  global_zumin, global_zumax, global_zvmin, global_zvmax, global_cvel_z, global_cvis, current_state%parallel)
147 
148  if (current_state%galilean_transformation) then
149  if (.not.current_state%fix_ugal)current_state%ugal=0.5_default_precision*(global_zumin+global_zumax)
150  if (.not.current_state%fix_vgal)current_state%vgal=0.5_default_precision*(global_zvmin+global_zvmax)
151  else
152  current_state%ugal=0.0_default_precision
153  current_state%vgal=0.0_default_precision
154  end if
155  current_state%cvel_z=global_cvel_z
156  current_state%cvel_x=max(abs(global_zumax-current_state%ugal), abs(global_zumin-current_state%ugal))
157  current_state%cvel_y=max(abs(global_zvmax-current_state%vgal), abs(global_zvmin-current_state%vgal))
158  current_state%cvis=global_cvis
160 
175  subroutine get_global_values(local_zumin, local_zumax, local_zvmin, local_zvmax, local_cvel_z, local_cvis, &
176  global_zumin, global_zumax, global_zvmin, global_zvmax, global_cvel_z, global_cvis, parallel_state)
177  type(parallel_state_type), intent(inout) :: parallel_state
178  real(kind=DEFAULT_PRECISION), intent(in) :: local_zumin, local_zumax, local_zvmin, local_zvmax, local_cvel_z, local_cvis
179  real(kind=DEFAULT_PRECISION), intent(out) :: global_zumin, global_zumax, global_zvmin, global_zvmax, global_cvel_z, global_cvis
180 
181  integer :: ierr
182 
183  call mpi_allreduce(local_zumax, global_zumax, 1, precision_type, mpi_max, parallel_state%monc_communicator, ierr)
184  call mpi_allreduce(local_zvmax, global_zvmax, 1, precision_type, mpi_max, parallel_state%monc_communicator, ierr)
185  call mpi_allreduce(local_cvel_z, global_cvel_z, 1, precision_type, mpi_max, parallel_state%monc_communicator, ierr)
186  call mpi_allreduce(local_cvis, global_cvis, 1, precision_type, mpi_max, parallel_state%monc_communicator, ierr)
187  call mpi_allreduce(local_zumin, global_zumin, 1, precision_type, mpi_min, parallel_state%monc_communicator, ierr)
188  call mpi_allreduce(local_zvmin, global_zvmin, 1, precision_type, mpi_min, parallel_state%monc_communicator, ierr)
189  end subroutine get_global_values
190 end module cfltest_mod
integer, public precision_type
Definition: datadefn.F90:19
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
real(kind=default_precision) dtmmin
Definition: cfltest.F90:22
Logging utility.
Definition: logging.F90:2
real(kind=default_precision) cvelmax
Definition: cfltest.F90:22
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
type(component_descriptor_type) function, public cfltest_get_descriptor()
Provides the descriptor back to the caller and is used in component registration. ...
Definition: cfltest.F90:29
real(kind=default_precision) dtmmax
Definition: cfltest.F90:22
subroutine update_dtm_based_on_absolute(current_state)
Updates the (new) dtm value, which is actioned after time step completion, based upon the absolute va...
Definition: cfltest.F90:91
Information about the parallel aspects of the system.
Definition: state.F90:21
real(kind=default_precision) cvismax
Definition: cfltest.F90:22
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
The ModelState which represents the current state of a run.
Definition: state.F90:39
integer, parameter, public log_debug
Log DEBUG, INFO, WARNING and ERROR messages.
Definition: logging.F90:14
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
subroutine initialisation_callback(current_state)
Called at initialisation, will read in configuration and use either configured or default values...
Definition: cfltest.F90:38
Converts data types to strings.
Definition: conversions.F90:36
subroutine, public log_log(level, message, str)
Logs a message at the specified level. If the level is above the current level then the message is ig...
Definition: logging.F90:75
Map data structure that holds string (length 20 maximum) key value pairs.
Definition: collections.F90:86
Interfaces and types that MONC components must specify.
Collection data structures.
Definition: collections.F90:7
integer, parameter, public log_warn
Log WARNING and ERROR messages.
Definition: logging.F90:12
real(kind=default_precision) rincmax
Definition: cfltest.F90:22
real(kind=default_precision) function, public options_get_real(options_database, key, index)
Retrieves a real value from the database that matches the provided key.
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
real(kind=default_precision) tollerance
Definition: cfltest.F90:22
integer function, public options_get_integer(options_database, key, index)
Retrieves an integer value from the database that matches the provided key.
Manages the options database. Contains administration functions and deduce runtime options from the c...
This contains the CFL test. It will perform the local advective CFL and Galilean transfromation calcu...
Definition: cfltest.F90:5
subroutine timestep_callback(current_state)
Called at each timestep, this will only do the CFL computation every nncfl timesteps (or every timest...
Definition: cfltest.F90:55
subroutine perform_cfl_and_galilean_transformation_calculation(current_state)
Performs the CFL and Galilean transformation calculations. First locally and then will determine the ...
Definition: cfltest.F90:114
subroutine get_global_values(local_zumin, local_zumax, local_zvmin, local_zvmax, local_cvel_z, local_cvis, global_zumin, global_zumax, global_zvmin, global_zvmax, global_cvel_z, global_cvis, parallel_state)
Gets the global reduction values based upon the local contributions of CFL and Galilean transformatio...
Definition: cfltest.F90:177
The model state which represents the current state of a run.
Definition: state.F90:2
integer function, public log_get_logging_level()
Retrieves the current logging level.
Definition: logging.F90:122
integer, parameter, public y_index
Definition: grids.F90:14
integer, parameter, public x_index
Definition: grids.F90:14