MONC
get_and_test_socrates_options.F90
Go to the documentation of this file.
2 
4  use state_mod, only : model_state_type
6  use logging_mod, only : log_info, log_warn, log_error, &
13 
15 
16 
17 contains
18 
19  subroutine set_and_test_socrates_monc_options(current_state, socrates_opt)
20 
21  type(model_state_type), target, intent(inout) :: current_state
22 
23  type (str_socrates_options), intent(inout) :: socrates_opt
24 
25  ! First check the MONC switches are sensible to run socrates
26  !
27  ! check that lwrad_exp is not on, as this will double the cloud top
28  ! longwave cooling
29  if (is_component_enabled(current_state%options_database, "lwrad_exponential")) then
30  call log_master_log &
31  (log_error, "Socrates and lwrad_exponential both enabled, switch off on in config - STOP")
32  endif
33 
34  ! check whether potential temperature is active, if not stop run
35  if (.not. current_state%th%active) then
36  call log_master_log &
37  (log_error, "Socrates called with theta inactive, this is not supported - STOP")
38  endif
39  ! determine if the radiation is expecting cloud
40  socrates_opt%cloud_representation = &
41  options_get_integer(current_state%options_database, "i_cloud_representation")
42  if (socrates_opt%cloud_representation == 5) then
43  ! only clear sky radiation calculation, initialise vapour index
44  if (current_state%number_q_fields < 1) then
45  call log_master_log(log_error, "Socrates called for clear sky calc but no vapour field - STOP")
46  else
47  socrates_opt%iqv=get_q_index(standard_q_names%VAPOUR, 'socrates_couple')
48  endif
49  else if (socrates_opt%cloud_representation == 2 .or. socrates_opt%cloud_representation == 1) then
50  ! Do some tests to make sure config is sensible
51  ! (these tests are a bit overkill, better safe than sorry)
52  if (.not. is_component_enabled(current_state%options_database, "casim") &
53  .and. .not. is_component_enabled(current_state%options_database, "simplecloud")) then
54  call log_master_log &
55  (log_error, "Socrates called for cloudy sky but no microphysics scheme enabled - STOP")
56  endif
57  if (current_state%passive_q ) then
58  call log_master_log &
59  (log_error, "Socrates called for cloudy sky but q is passive so not cloud or vapour - STOP")
60  endif
61  if (current_state%number_q_fields < 2) then
62  call log_master_log &
63  (log_error, "Socrates called for clear and cloud sky calc but no vapour or cloud field - STOP")
64  endif
65  ! Now monc is happy the set-up seems OK, set-up the microphysics logicals and allocate
66  ! arrays
67  !
68  ! set vapour by default
69  socrates_opt%iqv=get_q_index(standard_q_names%VAPOUR, 'socrates_couple')
70  ! read from options database to see which hydrometeors are available
71  ! for radiation calculation. NOTE: This can differ from the number of hydrometeors
72  ! active in the microphysics scheme
73  socrates_opt%mphys_nq_l=options_get_integer(current_state%options_database, "mphys_nq_l")
74  socrates_opt%mphys_nd_l=options_get_integer(current_state%options_database, "mphys_nd_l")
75  socrates_opt%mphys_nq_r=options_get_integer(current_state%options_database, "mphys_nq_r")
76  socrates_opt%mphys_nq_i=options_get_integer(current_state%options_database, "mphys_nq_i")
77  socrates_opt%mphys_nq_s=options_get_integer(current_state%options_database, "mphys_nq_s")
78  socrates_opt%mphys_nq_g=options_get_integer(current_state%options_database, "mphys_nq_g")
79 
80  if (socrates_opt%mphys_nq_l > 0) &
81  socrates_opt%iql=get_q_index(standard_q_names%CLOUD_LIQUID_MASS, 'socrates_couple')
82  if (socrates_opt%mphys_nq_r > 0) &
83  socrates_opt%iqr=get_q_index(standard_q_names%RAIN_MASS, 'socrates_couple')
84  if (socrates_opt%mphys_nq_i > 0) &
85  socrates_opt%iqi=get_q_index(standard_q_names%ICE_MASS, 'socrates_couple')
86  if (socrates_opt%mphys_nq_s > 0) &
87  socrates_opt%iqs=get_q_index(standard_q_names%SNOW_MASS, 'socrates_couple')
88  if (socrates_opt%mphys_nq_g > 0) &
89  socrates_opt%iqg=get_q_index(standard_q_names%GRAUPEL_MASS, 'socrates_couple')
90  ! test for fixed effective radius in config
91  socrates_opt%l_fix_re = options_get_logical(current_state%options_database, "l_fix_re")
92  socrates_opt%l_use_ndrop = options_get_logical(current_state%options_database, "l_use_ndrop")
93  if ((socrates_opt%l_fix_re .and. socrates_opt%l_use_ndrop) .or. &
94  (.not. socrates_opt%l_fix_re .and. .not. socrates_opt%l_use_ndrop)) then
95  call log_master_log &
96  (log_error, "Socrates - l_fix_re and l_use_ndrop both true or both false, please pick one - STOP")
97  endif
98  if (socrates_opt%l_fix_re) then
99  socrates_opt%fixed_cloud_re = options_get_real(current_state%options_database, "fixed_cloud_re")
100  socrates_opt%fixed_ice_re = options_get_real(current_state%options_database, "fixed_ice_re")
101  call log_master_log &
102  (log_info, "Socrates - using fixed cloud effective radius"//trim(conv_to_string(socrates_opt%fixed_cloud_re)))
103  call log_master_log &
104  (log_info, "Socrates - using fixed ice effective radius"//trim(conv_to_string(socrates_opt%fixed_ice_re)))
105  endif
106  if (socrates_opt%l_use_ndrop) then
107  socrates_opt%rho_water = options_get_real(current_state%options_database, "rho_water")
108  socrates_opt%kparam = options_get_real(current_state%options_database, "kparam")
109  socrates_opt%l_use_liu_spec = options_get_logical(current_state%options_database, "l_use_liu_spec")
110  if (socrates_opt%mphys_nd_l > 0) then
111  if (is_component_enabled(current_state%options_database, "casim")) then
112  socrates_opt%inl = get_q_index(standard_q_names%CLOUD_LIQUID_NUMBER, 'socrates_couple')
113  socrates_opt%fixed_ice_re = options_get_real(current_state%options_database, "fixed_ice_re")
114  call log_master_log &
115  (log_info, "Socrates using prognostic cloud number from CASIM, fixed ice re="&
116  //trim(conv_to_string(socrates_opt%fixed_ice_re))//" microns")
117  else
118  call log_master_log &
119  (log_error, "Socrates - casim not enabled so no prognostic nd - STOP")
120  endif
121  else
122  socrates_opt%inl = 0
123  socrates_opt%fixed_cloud_number = options_get_real(current_state%options_database, "fixed_cloud_number")
124  socrates_opt%fixed_ice_re = options_get_real(current_state%options_database, "fixed_ice_re")
125  call log_master_log &
126  (log_info, "Socrates using prescribed fix_cloud_number="&
127  //trim(conv_to_string(socrates_opt%fixed_cloud_number))//" /cm3")
128  endif
129  endif
130  else
131  call log_master_log &
132  (log_error, "Socrates config using unrecognised i_cloud_representation, check config - STOP")
133  endif
134 
135  ! Get options for time and location variables. These are set in the MONC
136  ! configuration. By default they are set to -999.0, which will fail. Hence
137  ! user must set them appropriately
138  socrates_opt%l_360 = options_get_logical(current_state%options_database, "l_360")
139  socrates_opt%l_solar_fixed = &
140  options_get_logical(current_state%options_database, "l_solar_fixed")
141  socrates_opt%l_no_solar = &
142  options_get_logical(current_state%options_database, "l_no_solar")
143  socrates_opt%l_rad_calc = .false.
144 
145  if (socrates_opt%l_solar_fixed) then
146  socrates_opt%solar_fixed = options_get_real(current_state%options_database, "solar_fixed")
147  socrates_opt%sec_fixed = options_get_real(current_state%options_database, "sec_fixed")
148  if (socrates_opt%solar_fixed .lt. -1.0 .or. socrates_opt%sec_fixed .lt. -1.0) then
149  call log_master_log &
150  (log_error, "Socrates - l_solar_fixed but solar_fixed and/or sec_fixed not set, check config - STOP")
151  endif
152  socrates_opt%l_variable_srf_albedo = options_get_logical(current_state%options_database, "l_variable_srf_albedo")
153  if (socrates_opt%l_variable_srf_albedo) then
154  call log_master_log &
155  (log_info, "Socrates - solar_fixed but variable srf albedo, default to fixed srf albedo")
156  endif
157  socrates_opt%surface_albedo = options_get_real(current_state%options_database, "surface_albedo")
158  else ! solar angle will vary so get all the time variables
159  ! first get the radiation initial year, day and time variables and add to
160  socrates_opt%rad_year = options_get_real(current_state%options_database, "rad_start_year")
161  if (socrates_opt%rad_year < 0.0) then
162  call log_master_log &
163  (log_error, "Socrates - start year is negative, which is wrong, check config - STOP")
164  endif
165  !
166  socrates_opt%rad_start_day = options_get_real(current_state%options_database, "rad_start_day")
167  if (socrates_opt%rad_start_day < 0.0 .or. socrates_opt%rad_start_day > 360.0) then
168  call log_master_log &
169  (log_error, "Socrates - start day is outside sensible range, check config - STOP")
170  endif
171  !
172  socrates_opt%rad_start_time = options_get_real(current_state%options_database,"rad_start_time")
173  if (socrates_opt%rad_time_hours < 0.0 .or. socrates_opt%rad_time_hours > 24.0) then
174  call log_master_log &
175  (log_error, "Socrates - start time is outside sensible range, check config - STOP")
176  endif
177  !
178  socrates_opt%rad_int_time = options_get_real(current_state%options_database, "rad_int_time")
179  if (socrates_opt%rad_int_time <= 0.0) then
180  call log_master_log &
181  (log_warn, "Socrates - rad_int_time less than 0.0, SOCRATES will be called every timestep")
182  endif
183 
184  ! Now get the surface albedo variables
185  socrates_opt%l_variable_srf_albedo = options_get_logical(current_state%options_database, "l_variable_srf_albedo")
186  if (socrates_opt%l_variable_srf_albedo) then
187  call log_master_log &
188  (log_error, "Socrates config using variable surface albedo, but this has not been developed. Set to false - STOP")
189  endif
190  socrates_opt%surface_albedo = options_get_real(current_state%options_database, "surface_albedo")
191 
192  ! Now get the longitude and latitude variables
193  socrates_opt%latitude = options_get_real(current_state%options_database, "latitude")
194  if (socrates_opt%latitude < -90.0 .or. socrates_opt%latitude > 90.0) then
195  call log_master_log &
196  (log_error, "Socrates - latitude is outside sensible range, check config - STOP")
197  endif
198  socrates_opt%longitude = options_get_real(current_state%options_database, "longitude")
199  if (socrates_opt%longitude < -180.0 .or. socrates_opt%longitude > 180.0) then
200  call log_master_log &
201  (log_error, "Socrates - longitude is outside sensible range, check config - STOP")
202  endif
203  endif ! end l_solar_fixed
204 
205  if (socrates_opt%surface_albedo < 0.0 .or. socrates_opt%surface_albedo > 1.0) then
206  call log_master_log &
207  (log_error, "Socrates - surface albedo outside sensible range, check config - STOP")
208  endif
209  !
210  socrates_opt%default_solar_constant = &
211  options_get_real(current_state%options_database, "default_solar_constant")
212 
213  ! set the well mixed gases. Values are based on UM GA settings
214  ! This should be moved to configuration once reading well mixed
215  ! gases from configuration can be shown to bit compare (see #306)
216  !
217  socrates_opt%co2_mmr = 5.94100e-4
218  socrates_opt%n2o_mmr = 4.925e-7
219  socrates_opt%ch4_mmr = 9.994e-7
220  socrates_opt%o2_mmr = 0.2314
221  socrates_opt%cfc12_mmr = 1.129e-9
222  socrates_opt%cfc11_mmr = 2.225e-9
223  socrates_opt%cfc113_mmr = 0.0
224  socrates_opt%cfc114_mmr = 0.0
225  socrates_opt%hcfc22_mmr = 0.0
226  socrates_opt%hfc125_mmr = 0.0
227  socrates_opt%hfc134a_mmr = 0.0
228 
230 
231 
233 
registry_mod::is_component_enabled
logical function, public is_component_enabled(options_database, component_name)
Determines whether or not a specific component is registered and enabled.
Definition: registry.F90:334
logging_mod::log_error
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
conversions_mod
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
logging_mod::log_warn
integer, parameter, public log_warn
Log WARNING and ERROR messages.
Definition: logging.F90:12
optionsdatabase_mod::options_get_integer
integer function, public options_get_integer(options_database, key, index)
Retrieves an integer value from the database that matches the provided key.
Definition: optionsdatabase.F90:217
logging_mod::log_info
integer, parameter, public log_info
Log INFO, WARNING and ERROR messages.
Definition: logging.F90:13
logging_mod::log_log
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
logging_mod::log_get_logging_level
integer function, public log_get_logging_level()
Retrieves the current logging level.
Definition: logging.F90:122
logging_mod::log_debug
integer, parameter, public log_debug
Log DEBUG, INFO, WARNING and ERROR messages.
Definition: logging.F90:14
optionsdatabase_mod::options_get_string
character(len=string_length) function, public options_get_string(options_database, key, index)
Retrieves a string value from the database that matches the provided key.
Definition: optionsdatabase.F90:280
def_socrates_options::str_socrates_options
Definition: def_socrates_options.F90:7
conversions_mod::conv_to_string
Converts data types to strings.
Definition: conversions.F90:38
q_indices_mod::standard_q_names
type(standard_q_names_type), public standard_q_names
Definition: q_indices.F90:59
state_mod::model_state_type
The ModelState which represents the current state of a run.
Definition: state.F90:39
optionsdatabase_mod::options_get_logical
logical function, public options_get_logical(options_database, key, index)
Retrieves a logical value from the database that matches the provided key.
Definition: optionsdatabase.F90:154
q_indices_mod::get_q_index
integer function, public get_q_index(name, assigning_component)
Add in a new entry into the register if the name does not already exist or return the index of the pr...
Definition: q_indices.F90:112
logging_mod
Logging utility.
Definition: logging.F90:2
datadefn_mod
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
get_and_test_socrates_options_mod
Definition: get_and_test_socrates_options.F90:1
logging_mod::log_master_log
subroutine, public log_master_log(level, message)
Will log just from the master process.
Definition: logging.F90:47
get_and_test_socrates_options_mod::set_and_test_socrates_monc_options
subroutine set_and_test_socrates_monc_options(current_state, socrates_opt)
Definition: get_and_test_socrates_options.F90:20
q_indices_mod
This manages the Q variables and specifically the mapping between names and the index that they are s...
Definition: q_indices.F90:2
registry_mod
MONC component registry.
Definition: registry.F90:5
def_socrates_options
Definition: def_socrates_options.F90:1
optionsdatabase_mod
Manages the options database. Contains administration functions and deduce runtime options from the c...
Definition: optionsdatabase.F90:7
optionsdatabase_mod::options_get_real
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.
Definition: optionsdatabase.F90:91
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
state_mod
The model state which represents the current state of a run.
Definition: state.F90:2