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