MOM6
user_initialization.F90
1 !> A template of a user to code up customized initial conditions.
3 
4 ! This file is part of MOM6. See LICENSE.md for the license.
5 
6 use mom_error_handler, only : mom_mesg, mom_error, fatal, is_root_pe
9 use mom_get_input, only : directories
10 use mom_grid, only : ocean_grid_type
11 use mom_open_boundary, only : ocean_obc_type, obc_none, obc_simple
12 use mom_open_boundary, only : obc_direction_e, obc_direction_w, obc_direction_n
13 use mom_open_boundary, only : obc_direction_s
14 use mom_sponge, only : set_up_sponge_field, initialize_sponge, sponge_cs
20 implicit none ; private
21 
22 #include <MOM_memory.h>
23 
24 public user_set_coord, user_initialize_topography, user_initialize_thickness
25 public user_initialize_velocity, user_init_temperature_salinity
26 public user_initialize_sponges, user_set_obc_data, user_set_rotation
27 
28 ! A note on unit descriptions in comments: MOM6 uses units that can be rescaled for dimensional
29 ! consistency testing. These are noted in comments with units like Z, H, L, and T, along with
30 ! their mks counterparts with notation like "a velocity [Z T-1 ~> m s-1]". If the units
31 ! vary with the Boussinesq approximation, the Boussinesq variant is given first.
32 
33 !> A module variable that should not be used.
34 !! \todo Move this module variable into a control structure.
35 logical :: first_call = .true.
36 
37 contains
38 
39 !> Set vertical coordinates.
40 subroutine user_set_coord(Rlay, g_prime, GV, US, param_file, eqn_of_state)
41  type(verticalgrid_type), intent(in) :: gv !< The ocean's vertical grid structure
42  real, dimension(GV%ke), intent(out) :: rlay !< Layer potential density [R ~> kg m-3].
43  real, dimension(GV%ke+1), intent(out) :: g_prime !< The reduced gravity at each
44  !! interface [L2 Z-1 T-2 ~> m s-2].
45  type(unit_scale_type), intent(in) :: us !< A dimensional unit scaling type
46  type(param_file_type), intent(in) :: param_file !< A structure indicating the
47  !! open file to parse for model
48  !! parameter values.
49  type(eos_type), pointer :: eqn_of_state !< Equation of state structure
50 
51  call mom_error(fatal, &
52  "USER_initialization.F90, USER_set_coord: " // &
53  "Unmodified user routine called - you must edit the routine to use it")
54  rlay(:) = 0.0
55  g_prime(:) = 0.0
56 
57  if (first_call) call write_user_log(param_file)
58 
59 end subroutine user_set_coord
60 
61 !> Initialize topography.
62 subroutine user_initialize_topography(D, G, param_file, max_depth, US)
63  type(dyn_horgrid_type), intent(in) :: g !< The dynamic horizontal grid type
64  real, dimension(G%isd:G%ied,G%jsd:G%jed), &
65  intent(out) :: d !< Ocean bottom depth in m or Z if US is present
66  type(param_file_type), intent(in) :: param_file !< Parameter file structure
67  real, intent(in) :: max_depth !< Maximum model depth in the units of D
68  type(unit_scale_type), optional, intent(in) :: us !< A dimensional unit scaling type
69 
70  call mom_error(fatal, &
71  "USER_initialization.F90, USER_initialize_topography: " // &
72  "Unmodified user routine called - you must edit the routine to use it")
73 
74  d(:,:) = 0.0
75 
76  if (first_call) call write_user_log(param_file)
77 
78 end subroutine user_initialize_topography
79 
80 !> initialize thicknesses.
81 subroutine user_initialize_thickness(h, G, GV, param_file, just_read_params)
82  type(ocean_grid_type), intent(in) :: g !< The ocean's grid structure.
83  type(verticalgrid_type), intent(in) :: gv !< The ocean's vertical grid structure.
84  real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
85  intent(out) :: h !< The thicknesses being initialized [H ~> m or kg m-2].
86  type(param_file_type), intent(in) :: param_file !< A structure indicating the open
87  !! file to parse for model parameter values.
88  logical, optional, intent(in) :: just_read_params !< If present and true, this call will
89  !! only read parameters without changing h.
90 
91  logical :: just_read ! If true, just read parameters but set nothing.
92 
93  call mom_error(fatal, &
94  "USER_initialization.F90, USER_initialize_thickness: " // &
95  "Unmodified user routine called - you must edit the routine to use it")
96 
97  just_read = .false. ; if (present(just_read_params)) just_read = just_read_params
98 
99  if (just_read) return ! All run-time parameters have been read, so return.
100 
101  h(:,:,1) = 0.0 ! h should be set [H ~> m or kg m-2].
102 
103  if (first_call) call write_user_log(param_file)
104 
105 end subroutine user_initialize_thickness
106 
107 !> initialize velocities.
108 subroutine user_initialize_velocity(u, v, G, US, param_file, just_read_params)
109  type(ocean_grid_type), intent(in) :: g !< Ocean grid structure.
110  real, dimension(SZIB_(G), SZJ_(G), SZK_(G)), intent(out) :: u !< i-component of velocity [L T-1 ~> m s-1]
111  real, dimension(SZI_(G), SZJB_(G), SZK_(G)), intent(out) :: v !< j-component of velocity [L T-1 ~> m s-1]
112  type(unit_scale_type), intent(in) :: us !< A dimensional unit scaling type
113  type(param_file_type), intent(in) :: param_file !< A structure indicating the
114  !! open file to parse for model
115  !! parameter values.
116  logical, optional, intent(in) :: just_read_params !< If present and true, this call will
117  !! only read parameters without changing h.
118 
119  logical :: just_read ! If true, just read parameters but set nothing.
120 
121  call mom_error(fatal, &
122  "USER_initialization.F90, USER_initialize_velocity: " // &
123  "Unmodified user routine called - you must edit the routine to use it")
124 
125  just_read = .false. ; if (present(just_read_params)) just_read = just_read_params
126 
127  if (just_read) return ! All run-time parameters have been read, so return.
128 
129  u(:,:,1) = 0.0
130  v(:,:,1) = 0.0
131 
132  if (first_call) call write_user_log(param_file)
133 
134 end subroutine user_initialize_velocity
135 
136 !> This function puts the initial layer temperatures and salinities
137 !! into T(:,:,:) and S(:,:,:).
138 subroutine user_init_temperature_salinity(T, S, G, param_file, eqn_of_state, just_read_params)
139  type(ocean_grid_type), intent(in) :: g !< Ocean grid structure.
140  real, dimension(SZI_(G),SZJ_(G), SZK_(G)), intent(out) :: t !< Potential temperature [degC].
141  real, dimension(SZI_(G),SZJ_(G), SZK_(G)), intent(out) :: s !< Salinity [ppt].
142  type(param_file_type), intent(in) :: param_file !< A structure indicating the
143  !! open file to parse for model
144  !! parameter values.
145  type(eos_type), pointer :: eqn_of_state !< Equation of state structure
146  logical, optional, intent(in) :: just_read_params !< If present and true, this call will only
147  !! read parameters without changing T & S.
148 
149  logical :: just_read ! If true, just read parameters but set nothing.
150 
151  call mom_error(fatal, &
152  "USER_initialization.F90, USER_init_temperature_salinity: " // &
153  "Unmodified user routine called - you must edit the routine to use it")
154 
155  just_read = .false. ; if (present(just_read_params)) just_read = just_read_params
156 
157  if (just_read) return ! All run-time parameters have been read, so return.
158 
159  t(:,:,1) = 0.0
160  s(:,:,1) = 0.0
161 
162  if (first_call) call write_user_log(param_file)
163 
164 end subroutine user_init_temperature_salinity
165 
166 !> Set up the sponges.
167 subroutine user_initialize_sponges(G, GV, use_temp, tv, param_file, CSp, h)
168  type(ocean_grid_type), intent(in) :: g !< Ocean grid structure.
169  type(verticalgrid_type), intent(in) :: gv !< The ocean's vertical grid structure.
170  logical, intent(in) :: use_temp !< If true, temperature and salinity are state variables.
171  type(thermo_var_ptrs), intent(in) :: tv !< A structure containing pointers
172  !! to any available thermodynamic
173  !! fields, potential temperature and
174  !! salinity or mixed layer density.
175  !! Absent fields have NULL ptrs.
176  type(param_file_type), intent(in) :: param_file !< A structure indicating the
177  !! open file to parse for model
178  !! parameter values.
179  type(sponge_cs), pointer :: csp !< A pointer to the sponge control structure.
180  real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
181  intent(in) :: h !< Layer thicknesses [H ~> m or kg m-2].
182  call mom_error(fatal, &
183  "USER_initialization.F90, USER_initialize_sponges: " // &
184  "Unmodified user routine called - you must edit the routine to use it")
185 
186  if (first_call) call write_user_log(param_file)
187 
188 end subroutine user_initialize_sponges
189 
190 !> This subroutine sets the properties of flow at open boundary conditions.
191 subroutine user_set_obc_data(OBC, tv, G, param_file, tr_Reg)
192  type(ocean_obc_type), pointer :: obc !< This open boundary condition type specifies
193  !! whether, where, and what open boundary
194  !! conditions are used.
195  type(thermo_var_ptrs), intent(in) :: tv !< A structure containing pointers to any
196  !! available thermodynamic fields, including potential
197  !! temperature and salinity or mixed layer density. Absent
198  !! fields have NULL ptrs.
199  type(ocean_grid_type), intent(in) :: g !< The ocean's grid structure.
200  type(param_file_type), intent(in) :: param_file !< A structure indicating the
201  !! open file to parse for model
202  !! parameter values.
203  type(tracer_registry_type), pointer :: tr_reg !< Tracer registry.
204 ! call MOM_error(FATAL, &
205 ! "USER_initialization.F90, USER_set_OBC_data: " // &
206 ! "Unmodified user routine called - you must edit the routine to use it")
207 
208  if (first_call) call write_user_log(param_file)
209 
210 end subroutine user_set_obc_data
211 
212 subroutine user_set_rotation(G, param_file)
213  type(ocean_grid_type), intent(inout) :: g !< The ocean's grid structure
214  type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
215  call mom_error(fatal, &
216  "USER_initialization.F90, USER_set_rotation: " // &
217  "Unmodified user routine called - you must edit the routine to use it")
218 
219  if (first_call) call write_user_log(param_file)
220 
221 end subroutine user_set_rotation
222 
223 !> Write output about the parameter values being used.
224 subroutine write_user_log(param_file)
225  type(param_file_type), intent(in) :: param_file !< A structure indicating the
226  !! open file to parse for model
227  !! parameter values.
228 
229 ! This include declares and sets the variable "version".
230 #include "version_variable.h"
231  character(len=40) :: mdl = "user_initialization" ! This module's name.
232 
233  call log_version(param_file, mdl, version)
234  first_call = .false.
235 
236 end subroutine write_user_log
237 
238 !> \namespace user_initialization
239 !!
240 !! This subroutine initializes the fields for the simulations.
241 !! The one argument passed to initialize, Time, is set to the
242 !! current time of the simulation. The fields which might be initialized
243 !! here are:
244 !! - u - Zonal velocity [Z T-1 ~> m s-1].
245 !! - v - Meridional velocity [Z T-1 ~> m s-1].
246 !! - h - Layer thickness [H ~> m or kg m-2]. (Must be positive.)
247 !! - G%bathyT - Basin depth [Z ~> m]. (Must be positive.)
248 !! - G%CoriolisBu - The Coriolis parameter [T-1 ~> s-1].
249 !! - GV%g_prime - The reduced gravity at each interface [L2 Z-1 T-2 ~> m s-2].
250 !! - GV%Rlay - Layer potential density (coordinate variable) [R ~> kg m-3].
251 !! If ENABLE_THERMODYNAMICS is defined:
252 !! - T - Temperature [degC].
253 !! - S - Salinity [psu].
254 !! If BULKMIXEDLAYER is defined:
255 !! - Rml - Mixed layer and buffer layer potential densities [R ~> kg m-3].
256 !! If SPONGE is defined:
257 !! - A series of subroutine calls are made to set up the damping
258 !! rates and reference profiles for all variables that are damped
259 !! in the sponge.
260 !!
261 !! Any user provided tracer code is also first linked through this
262 !! subroutine.
263 !!
264 !! These variables are all set in the set of subroutines (in this
265 !! file) USER_initialize_bottom_depth, USER_initialize_thickness,
266 !! USER_initialize_velocity, USER_initialize_temperature_salinity,
267 !! USER_initialize_mixed_layer_density, USER_initialize_sponges,
268 !! USER_set_coord, and USER_set_ref_profile.
269 !!
270 !! The names of these subroutines should be self-explanatory. They
271 !! start with "USER_" to indicate that they will likely have to be
272 !! modified for each simulation to set the initial conditions and
273 !! boundary conditions. Most of these take two arguments: an integer
274 !! argument specifying whether the fields are to be calculated
275 !! internally or read from a NetCDF file; and a string giving the
276 !! path to that file. If the field is initialized internally, the
277 !! path is ignored.
278 
279 end module user_initialization
Ocean grid type. See mom_grid for details.
Definition: MOM_grid.F90:26
Calculates density of sea water from T, S and P.
Definition: MOM_EOS.F90:68
Reads the only Fortran name list needed to boot-strap the model.
A structure that can be parsed to read and document run-time parameters.
Provides the ocean grid type.
Definition: MOM_grid.F90:2
Describes the horizontal ocean grid with only dynamic memory arrays.
The MOM6 facility to parse input files for runtime parameters.
A template of a user to code up customized initial conditions.
Describes various unit conversion factors.
This module contains the tracer_registry_type and the subroutines that handle registration of tracers...
Provides a transparent unit rescaling type to facilitate dimensional consistency testing.
Type to carry basic tracer information.
Routines for error handling and I/O management.
This control structure holds memory and parameters for the MOM_sponge module.
Definition: MOM_sponge.F90:41
Implements sponge regions in isopycnal mode.
Definition: MOM_sponge.F90:2
Calculate the derivatives of density with temperature and salinity from T, S, and P.
Definition: MOM_EOS.F90:81
Provides subroutines for quantities specific to the equation of state.
Definition: MOM_EOS.F90:2
An overloaded interface to log version information about modules.
Describes the vertical ocean grid, including unit conversion factors.
Container for paths and parameter file names.
Pointers to an assortment of thermodynamic fields that may be available, including potential temperat...
Contains a shareable dynamic type for describing horizontal grids and metric data and utilty routines...
Controls where open boundary conditions are applied.
Provides a transparent vertical ocean grid type and supporting routines.
Provides transparent structures with groups of MOM6 variables and supporting routines.
An overloaded interface to read and log the values of various types of parameters.
A control structure for the equation of state.
Definition: MOM_EOS.F90:108