MOM6
user_surface_forcing.F90
Go to the documentation of this file.
2 !***********************************************************************
3 !* GNU General Public License *
4 !* This file is a part of MOM. *
5 !* *
6 !* MOM is free software; you can redistribute it and/or modify it and *
7 !* are expected to follow the terms of the GNU General Public License *
8 !* as published by the Free Software Foundation; either version 2 of *
9 !* the License, or (at your option) any later version. *
10 !* *
11 !* MOM is distributed in the hope that it will be useful, but WITHOUT *
12 !* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
13 !* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public *
14 !* License for more details. *
15 !* *
16 !* For the full text of the GNU General Public License, *
17 !* write to: Free Software Foundation, Inc., *
18 !* 675 Mass Ave, Cambridge, MA 02139, USA. *
19 !* or see: http://www.gnu.org/licenses/gpl.html *
20 !***********************************************************************
21 !
22 !********+*********+*********+*********+*********+*********+*********+**
23 !* *
24 !* Rewritten by Robert Hallberg, June 2009 *
25 !* *
26 !* This file contains the subroutines that a user should modify to *
27 !* to set the surface wind stresses and fluxes of buoyancy or *
28 !* temperature and fresh water. They are called when the run-time *
29 !* parameters WIND_CONFIG or BUOY_CONFIG are set to "USER". The *
30 !* standard version has simple examples, along with run-time error *
31 !* messages that will cause the model to abort if this code has not *
32 !* been modified. This code is intended for use with relatively *
33 !* simple specifications of the forcing. For more complicated forms, *
34 !* it is probably a good idea to read the forcing from input files *
35 !* using "file" for WIND_CONFIG and BUOY_CONFIG. *
36 !* *
37 !* USER_wind_forcing should set the surface wind stresses (taux and *
38 !* tauy) perhaps along with the surface friction velocity (ustar). *
39 !* *
40 !* USER_buoyancy forcing is used to set the surface buoyancy *
41 !* forcing, which may include a number of fresh water flux fields *
42 !* (evap, lprec, fprec, lrunoff, frunoff, and *
43 !* vprec) and the surface heat fluxes (sw, lw, latent and sens) *
44 !* if temperature and salinity are state variables, or it may simply *
45 !* be the buoyancy flux if it is not. This routine also has coded a *
46 !* restoring to surface values of temperature and salinity. *
47 !* *
48 !* Macros written all in capital letters are defined in MOM_memory.h. *
49 !* *
50 !* A small fragment of the grid is shown below: *
51 !* *
52 !* j+1 x ^ x ^ x At x: q *
53 !* j+1 > o > o > At ^: v, tauy *
54 !* j x ^ x ^ x At >: u, taux *
55 !* j > o > o > At o: h, fluxes. *
56 !* j-1 x ^ x ^ x *
57 !* i-1 i i+1 At x & ^: *
58 !* i i+1 At > & o: *
59 !* *
60 !* The boundaries always run through q grid points (x). *
61 !* *
62 !********+*********+*********+*********+*********+*********+*********+**
65 use mom_domains, only : pass_var, pass_vector, agrid
66 use mom_error_handler, only : mom_error, fatal, warning, is_root_pe
69 use mom_grid, only : ocean_grid_type
70 use mom_io, only : file_exists, read_data
71 use mom_time_manager, only : time_type, operator(+), operator(/), get_time
74 use mom_variables, only : surface
75 
76 implicit none ; private
77 
79 
80 type, public :: user_surface_forcing_cs ; private
81  ! This control structure should be used to store any run-time variables
82  ! associated with the user-specified forcing. It can be readily modified
83  ! for a specific case, and because it is private there will be no changes
84  ! needed in other code (although they will have to be recompiled).
85  ! The variables in the cannonical example are used for some common
86  ! cases, but do not need to be used.
87 
88  logical :: use_temperature ! If true, temperature and salinity are used as
89  ! state variables.
90  logical :: restorebuoy ! If true, use restoring surface buoyancy forcing.
91  real :: rho0 ! The density used in the Boussinesq
92  ! approximation, in kg m-3.
93  real :: g_earth ! The gravitational acceleration in m s-2.
94  real :: flux_const ! The restoring rate at the surface, in m s-1.
95  real :: gust_const ! A constant unresolved background gustiness
96  ! that contributes to ustar, in Pa.
97 
98  type(diag_ctrl), pointer :: diag ! A structure that is used to regulate the
99  ! timing of diagnostic output.
101 
102 contains
103 
104 subroutine user_wind_forcing(state, fluxes, day, G, CS)
105  type(surface), intent(inout) :: state
106  type(forcing), intent(inout) :: fluxes
107  type(time_type), intent(in) :: day
108  type(ocean_grid_type), intent(inout) :: G !< The ocean's grid structure
109  type(user_surface_forcing_cs), pointer :: CS
110 
111 ! This subroutine sets the surface wind stresses, fluxes%taux and fluxes%tauy.
112 ! These are the stresses in the direction of the model grid (i.e. the same
113 ! direction as the u- and v- velocities.) They are both in Pa.
114 ! In addition, this subroutine can be used to set the surface friction
115 ! velocity, fluxes%ustar, in m s-1. This is needed with a bulk mixed layer.
116 !
117 ! Arguments: state - A structure containing fields that describe the
118 ! surface state of the ocean.
119 ! (out) fluxes - A structure containing pointers to any possible
120 ! forcing fields. Unused fields have NULL ptrs.
121 ! (in) day - Time of the fluxes.
122 ! (in) G - The ocean's grid structure.
123 ! (in) CS - A pointer to the control structure returned by a previous
124 ! call to user_surface_forcing_init
125 
126  integer :: i, j, is, ie, js, je, Isq, Ieq, Jsq, Jeq
127  integer :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
128 
129  ! When modifying the code, comment out this error message. It is here
130  ! so that the original (unmodified) version is not accidentally used.
131  call mom_error(fatal, "User_wind_surface_forcing: " // &
132  "User forcing routine called without modification." )
133 
134  is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
135  isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
136  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
137  isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
138 
139  ! Allocate the forcing arrays, if necessary.
140  call allocate_forcing_type(g, fluxes, stress=.true., ustar=.true.)
141 
142  ! Set the surface wind stresses, in units of Pa. A positive taux
143  ! accelerates the ocean to the (pseudo-)east.
144 
145  ! The i-loop extends to is-1 so that taux can be used later in the
146  ! calculation of ustar - otherwise the lower bound would be Isq.
147  do j=js,je ; do i=is-1,ieq
148  fluxes%taux(i,j) = g%mask2dCu(i,j) * 0.0 ! Change this to the desired expression.
149  enddo ; enddo
150  do j=js-1,jeq ; do i=is,ie
151  fluxes%tauy(i,j) = g%mask2dCv(i,j) * 0.0 ! Change this to the desired expression.
152  enddo ; enddo
153 
154  ! Set the surface friction velocity, in units of m s-1. ustar
155  ! is always positive.
156  if (associated(fluxes%ustar)) then ; do j=js,je ; do i=is,ie
157  ! This expression can be changed if desired, but need not be.
158  fluxes%ustar(i,j) = g%mask2dT(i,j) * sqrt(cs%gust_const/cs%Rho0 + &
159  sqrt(0.5*(fluxes%taux(i-1,j)**2 + fluxes%taux(i,j)**2) + &
160  0.5*(fluxes%tauy(i,j-1)**2 + fluxes%tauy(i,j)**2))/cs%Rho0)
161  enddo ; enddo ; endif
162 
163 end subroutine user_wind_forcing
164 
165 subroutine user_buoyancy_forcing(state, fluxes, day, dt, G, CS)
166  type(surface), intent(inout) :: state
167  type(forcing), intent(inout) :: fluxes
168  type(time_type), intent(in) :: day
169  real, intent(in) :: dt !< The amount of time over which
170  !! the fluxes apply, in s
171  type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure
172  type(user_surface_forcing_cs), pointer :: CS
173 
174 ! This subroutine specifies the current surface fluxes of buoyancy or
175 ! temperature and fresh water. It may also be modified to add
176 ! surface fluxes of user provided tracers.
177 
178 ! When temperature is used, there are long list of fluxes that need to be
179 ! set - essentially the same as for a full coupled model, but most of these
180 ! can be simply set to zero. The net fresh water flux should probably be
181 ! set in fluxes%evap and fluxes%lprec, with any salinity restoring
182 ! appearing in fluxes%vprec, and the other water flux components
183 ! (fprec, lrunoff and frunoff) left as arrays full of zeros.
184 ! Evap is usually negative and precip is usually positive. All heat fluxes
185 ! are in W m-2 and positive for heat going into the ocean. All fresh water
186 ! fluxes are in kg m-2 s-1 and positive for water moving into the ocean.
187 
188 ! Arguments: state - A structure containing fields that describe the
189 ! surface state of the ocean.
190 ! (out) fluxes - A structure containing pointers to any possible
191 ! forcing fields. Unused fields have NULL ptrs.
192 ! (in) day_start - Start time of the fluxes.
193 ! (in) day_interval - Length of time over which these fluxes
194 ! will be applied.
195 ! (in) G - The ocean's grid structure.
196 ! (in) CS - A pointer to the control structure returned by a previous
197 ! call to user_surface_forcing_init
198 
199  real :: Temp_restore ! The temperature that is being restored toward, in C.
200  real :: Salin_restore ! The salinity that is being restored toward, in PSU.
201  real :: density_restore ! The potential density that is being restored
202  ! toward, in kg m-3.
203  real :: rhoXcp ! The mean density times the heat capacity, in J m-3 K-1.
204  real :: buoy_rest_const ! A constant relating density anomalies to the
205  ! restoring buoyancy flux, in m5 s-3 kg-1.
206 
207  integer :: i, j, is, ie, js, je
208  integer :: isd, ied, jsd, jed
209 
210  is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
211  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
212 
213  ! When modifying the code, comment out this error message. It is here
214  ! so that the original (unmodified) version is not accidentally used.
215  call mom_error(fatal, "User_buoyancy_surface_forcing: " // &
216  "User forcing routine called without modification." )
217 
218  ! Allocate and zero out the forcing arrays, as necessary. This portion is
219  ! usually not changed.
220  if (cs%use_temperature) then
221  call alloc_if_needed(fluxes%evap, isd, ied, jsd, jed)
222  call alloc_if_needed(fluxes%lprec, isd, ied, jsd, jed)
223  call alloc_if_needed(fluxes%fprec, isd, ied, jsd, jed)
224  call alloc_if_needed(fluxes%lrunoff, isd, ied, jsd, jed)
225  call alloc_if_needed(fluxes%frunoff, isd, ied, jsd, jed)
226  call alloc_if_needed(fluxes%vprec, isd, ied, jsd, jed)
227 
228  call alloc_if_needed(fluxes%sw, isd, ied, jsd, jed)
229  call alloc_if_needed(fluxes%lw, isd, ied, jsd, jed)
230  call alloc_if_needed(fluxes%latent, isd, ied, jsd, jed)
231  call alloc_if_needed(fluxes%sens, isd, ied, jsd, jed)
232  else ! This is the buoyancy only mode.
233  call alloc_if_needed(fluxes%buoy, isd, ied, jsd, jed)
234  endif
235 
236 
237  ! MODIFY THE CODE IN THE FOLLOWING LOOPS TO SET THE BUOYANCY FORCING TERMS.
238 
239  if ( cs%use_temperature ) then
240  ! Set whichever fluxes are to be used here. Any fluxes that
241  ! are always zero do not need to be changed here.
242  do j=js,je ; do i=is,ie
243  ! Fluxes of fresh water through the surface are in units of kg m-2 s-1
244  ! and are positive downward - i.e. evaporation should be negative.
245  fluxes%evap(i,j) = -0.0 * g%mask2dT(i,j)
246  fluxes%lprec(i,j) = 0.0 * g%mask2dT(i,j)
247 
248  ! vprec will be set later, if it is needed for salinity restoring.
249  fluxes%vprec(i,j) = 0.0
250 
251  ! Heat fluxes are in units of W m-2 and are positive into the ocean.
252  fluxes%lw(i,j) = 0.0 * g%mask2dT(i,j)
253  fluxes%latent(i,j) = 0.0 * g%mask2dT(i,j)
254  fluxes%sens(i,j) = 0.0 * g%mask2dT(i,j)
255  fluxes%sw(i,j) = 0.0 * g%mask2dT(i,j)
256  enddo ; enddo
257  else ! This is the buoyancy only mode.
258  do j=js,je ; do i=is,ie
259  ! fluxes%buoy is the buoyancy flux into the ocean in m2 s-3. A positive
260  ! buoyancy flux is of the same sign as heating the ocean.
261  fluxes%buoy(i,j) = 0.0 * g%mask2dT(i,j)
262  enddo ; enddo
263  endif
264 
265  if (cs%restorebuoy) then
266  if (cs%use_temperature) then
267  call alloc_if_needed(fluxes%heat_added, isd, ied, jsd, jed)
268  ! When modifying the code, comment out this error message. It is here
269  ! so that the original (unmodified) version is not accidentally used.
270  call mom_error(fatal, "User_buoyancy_surface_forcing: " // &
271  "Temperature and salinity restoring used without modification." )
272 
273  rhoxcp = cs%Rho0 * fluxes%C_p
274  do j=js,je ; do i=is,ie
275  ! Set Temp_restore and Salin_restore to the temperature (in C) and
276  ! salinity (in PSU) that are being restored toward.
277  temp_restore = 0.0
278  salin_restore = 0.0
279 
280  fluxes%heat_added(i,j) = (g%mask2dT(i,j) * (rhoxcp * cs%Flux_const)) * &
281  (temp_restore - state%SST(i,j))
282  fluxes%vprec(i,j) = - (g%mask2dT(i,j) * (cs%Rho0*cs%Flux_const)) * &
283  ((salin_restore - state%SSS(i,j)) / &
284  (0.5 * (salin_restore + state%SSS(i,j))))
285  enddo ; enddo
286  else
287  ! When modifying the code, comment out this error message. It is here
288  ! so that the original (unmodified) version is not accidentally used.
289  call mom_error(fatal, "User_buoyancy_surface_forcing: " // &
290  "Buoyancy restoring used without modification." )
291 
292  ! The -1 is because density has the opposite sign to buoyancy.
293  buoy_rest_const = -1.0 * (cs%G_Earth * cs%Flux_const) / cs%Rho0
294  do j=js,je ; do i=is,ie
295  ! Set density_restore to an expression for the surface potential
296  ! density in kg m-3 that is being restored toward.
297  density_restore = 1030.0
298 
299  fluxes%buoy(i,j) = g%mask2dT(i,j) * buoy_rest_const * &
300  (density_restore - state%sfc_density(i,j))
301  enddo ; enddo
302  endif
303  endif ! end RESTOREBUOY
304 
305 end subroutine user_buoyancy_forcing
306 
307 subroutine alloc_if_needed(ptr, isd, ied, jsd, jed)
308  ! If ptr is not associated, this routine allocates it with the given size
309  ! and zeros out its contents. This is equivalent to safe_alloc_ptr in
310  ! MOM_diag_mediator, but is here so as to be completely transparent.
311  real, pointer :: ptr(:,:)
312  integer :: isd, ied, jsd, jed
313  if (.not.ASSOCIATED(ptr)) then
314  allocate(ptr(isd:ied,jsd:jed))
315  ptr(:,:) = 0.0
316  endif
317 end subroutine alloc_if_needed
318 
319 subroutine user_surface_forcing_init(Time, G, param_file, diag, CS)
320  type(time_type), intent(in) :: Time
321  type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure
322  type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
323  type(diag_ctrl), target, intent(in) :: diag
324  type(user_surface_forcing_cs), pointer :: CS
325 ! Arguments: Time - The current model time.
326 ! (in) G - The ocean's grid structure.
327 ! (in) param_file - A structure indicating the open file to parse for
328 ! model parameter values.
329 ! (in) diag - A structure that is used to regulate diagnostic output.
330 ! (in/out) CS - A pointer that is set to point to the control structure
331 ! for this module
332 
333 ! This include declares and sets the variable "version".
334 #include "version_variable.h"
335  character(len=40) :: mdl = "user_surface_forcing" ! This module's name.
336 
337  if (associated(cs)) then
338  call mom_error(warning, "USER_surface_forcing_init called with an associated "// &
339  "control structure.")
340  return
341  endif
342  allocate(cs)
343  cs%diag => diag
344 
345  ! Read all relevant parameters and write them to the model log.
346  call log_version(param_file, mdl, version, "")
347  call get_param(param_file, mdl, "ENABLE_THERMODYNAMICS", cs%use_temperature, &
348  "If true, Temperature and salinity are used as state \n"//&
349  "variables.", default=.true.)
350 
351  call get_param(param_file, mdl, "G_EARTH", cs%G_Earth, &
352  "The gravitational acceleration of the Earth.", &
353  units="m s-2", default = 9.80)
354  call get_param(param_file, mdl, "RHO_0", cs%Rho0, &
355  "The mean ocean density used with BOUSSINESQ true to \n"//&
356  "calculate accelerations and the mass for conservation \n"//&
357  "properties, or with BOUSSINSEQ false to convert some \n"//&
358  "parameters from vertical units of m to kg m-2.", &
359  units="kg m-3", default=1035.0)
360  call get_param(param_file, mdl, "GUST_CONST", cs%gust_const, &
361  "The background gustiness in the winds.", units="Pa", &
362  default=0.02)
363 
364  call get_param(param_file, mdl, "RESTOREBUOY", cs%restorebuoy, &
365  "If true, the buoyancy fluxes drive the model back \n"//&
366  "toward some specified surface state with a rate \n"//&
367  "given by FLUXCONST.", default= .false.)
368  if (cs%restorebuoy) then
369  call get_param(param_file, mdl, "FLUXCONST", cs%Flux_const, &
370  "The constant that relates the restoring surface fluxes \n"//&
371  "to the relative surface anomalies (akin to a piston \n"//&
372  "velocity). Note the non-MKS units.", units="m day-1", &
373  fail_if_missing=.true.)
374  ! Convert CS%Flux_const from m day-1 to m s-1.
375  cs%Flux_const = cs%Flux_const / 86400.0
376  endif
377 
378 end subroutine user_surface_forcing_init
379 
380 end module user_surface_forcing
The following structure contains pointers to various fields which may be used describe the surface st...
This module implements boundary forcing for MOM6.
Ocean grid type. See mom_grid for details.
Definition: MOM_grid.F90:19
The following data type a list of diagnostic fields an their variants, as well as variables that cont...
Provides the ocean grid type.
Definition: MOM_grid.F90:2
subroutine, public allocate_forcing_type(G, fluxes, stress, ustar, water, heat, shelf, press, iceberg)
Conditionally allocate fields within the forcing type.
This module contains I/O framework code.
Definition: MOM_io.F90:2
subroutine alloc_if_needed(ptr, isd, ied, jsd, jed)
logical function, public query_averaging_enabled(diag_cs, time_int, time_end)
subroutine, public call_tracer_set_forcing(state, fluxes, day_start, day_interval, G, CS)
This subroutine calls the individual tracer modules&#39; subroutines to specify or read quantities relate...
logical function, public is_root_pe()
Structure that contains pointers to the boundary forcing used to drive the liquid ocean simulated by ...
subroutine, public user_surface_forcing_init(Time, G, param_file, diag, CS)
subroutine, public user_buoyancy_forcing(state, fluxes, day, dt, G, CS)
subroutine, public user_wind_forcing(state, fluxes, day, G, CS)
integer function, public register_diag_field(module_name, field_name, axes, init_time, long_name, units, missing_value, range, mask_variant, standard_name, verbose, do_not_log, err_msg, interp_method, tile_count, cmor_field_name, cmor_long_name, cmor_units, cmor_standard_name, cell_methods, x_cell_method, y_cell_method, v_cell_method, conversion, v_extensive)
Returns the "diag_mediator" handle for a group (native, CMOR, z-coord, ...) of diagnostics derived fr...
subroutine, public mom_error(level, message, all_print)