MOM6
MESO_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 !* MESO_wind_forcing should set the surface wind stresses (taux and *
38 !* tauy) perhaps along with the surface friction velocity (ustar). *
39 !* *
40 !* MESO_buoyancy forcing is used to set the surface buoyancy *
41 !* forcing, which may include a number of fresh water flux fields *
42 !* (evap, liq_precip, froz_precip, liq_runoff, froz_runoff, 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, slasher
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 :: meso_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  real, dimension(:,:), pointer :: &
98  t_restore(:,:) => null(), & ! The temperature to restore the SST to, in C.
99  s_restore(:,:) => null(), & ! The salinity to restore the sea surface salnity
100  ! toward, in PSU.
101  pme(:,:) => null(), & ! The prescribed precip minus evap, in m s-1.
102  solar(:,:) => null(), & ! The shortwave forcing into the ocean, in W m-2 m s-1.
103  heat(:,:) => null() ! The prescribed longwave, latent and sensible
104  ! heat flux into the ocean, in W m-2.
105  character(len=200) :: inputdir ! The directory where NetCDF input files are.
106  character(len=200) :: salinityrestore_file, sstrestore_file
107  character(len=200) :: solar_file, heating_file, pme_file
108  type(diag_ctrl), pointer :: diag ! A structure that is used to regulate the
109  ! timing of diagnostic output.
111 
112 logical :: first_call = .true.
113 
114 contains
115 
116 subroutine meso_wind_forcing(state, fluxes, day, G, CS)
117  type(surface), intent(inout) :: state
118  type(forcing), intent(inout) :: fluxes
119  type(time_type), intent(in) :: day
120  type(ocean_grid_type), intent(inout) :: G !< The ocean's grid structure
121  type(meso_surface_forcing_cs), pointer :: CS
122 
123 ! This subroutine sets the surface wind stresses, fluxes%taux and fluxes%tauy.
124 ! These are the stresses in the direction of the model grid (i.e. the same
125 ! direction as the u- and v- velocities.) They are both in Pa.
126 ! In addition, this subroutine can be used to set the surface friction
127 ! velocity, fluxes%ustar, in m s-1. This is needed with a bulk mixed layer.
128 !
129 ! Arguments: state - A structure containing fields that describe the
130 ! surface state of the ocean.
131 ! (out) fluxes - A structure containing pointers to any possible
132 ! forcing fields. Unused fields have NULL ptrs.
133 ! (in) day - Time of the fluxes.
134 ! (in) G - The ocean's grid structure.
135 ! (in) CS - A pointer to the control structure returned by a previous
136 ! call to MESO_surface_forcing_init
137 
138  integer :: i, j, is, ie, js, je, Isq, Ieq, Jsq, Jeq
139  integer :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
140 
141  ! When modifying the code, comment out this error message. It is here
142  ! so that the original (unmodified) version is not accidentally used.
143  call mom_error(fatal, "MESO_wind_surface_forcing: " // &
144  "User forcing routine called without modification." )
145 
146  is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
147  isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
148  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
149  isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
150 
151  ! Allocate the forcing arrays, if necessary.
152  call allocate_forcing_type(g, fluxes, stress=.true., ustar=.true.)
153 
154  ! Set the surface wind stresses, in units of Pa. A positive taux
155  ! accelerates the ocean to the (pseudo-)east.
156 
157  ! The i-loop extends to is-1 so that taux can be used later in the
158  ! calculation of ustar - otherwise the lower bound would be Isq.
159  do j=js,je ; do i=is-1,ieq
160  fluxes%taux(i,j) = g%mask2dCu(i,j) * 0.0 ! Change this to the desired expression.
161  enddo ; enddo
162  do j=js-1,jeq ; do i=is,ie
163  fluxes%tauy(i,j) = g%mask2dCv(i,j) * 0.0 ! Change this to the desired expression.
164  enddo ; enddo
165 
166  ! Set the surface friction velocity, in units of m s-1. ustar
167  ! is always positive.
168  if (associated(fluxes%ustar)) then ; do j=js,je ; do i=is,ie
169  ! This expression can be changed if desired, but need not be.
170  fluxes%ustar(i,j) = g%mask2dT(i,j) * sqrt(cs%gust_const/cs%Rho0 + &
171  sqrt(0.5*(fluxes%taux(i-1,j)**2 + fluxes%taux(i,j)**2) + &
172  0.5*(fluxes%tauy(i,j-1)**2 + fluxes%tauy(i,j)**2))/cs%Rho0)
173  enddo ; enddo ; endif
174 
175 end subroutine meso_wind_forcing
176 
177 subroutine meso_buoyancy_forcing(state, fluxes, day, dt, G, CS)
178  type(surface), intent(inout) :: state
179  type(forcing), intent(inout) :: fluxes
180  type(time_type), intent(in) :: day
181  real, intent(in) :: dt !< The amount of time over which
182  !! the fluxes apply, in s
183  type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure
184  type(meso_surface_forcing_cs), pointer :: CS
185 
186 ! This subroutine specifies the current surface fluxes of buoyancy or
187 ! temperature and fresh water. It may also be modified to add
188 ! surface fluxes of user provided tracers.
189 
190 ! When temperature is used, there are long list of fluxes that need to be
191 ! set - essentially the same as for a full coupled model, but most of these
192 ! can be simply set to zero. The net fresh water flux should probably be
193 ! set in fluxes%evap and fluxes%lprec, with any salinity restoring
194 ! appearing in fluxes%vprec, and the other water flux components
195 ! (fprec, lrunoff and frunoff) left as arrays full of zeros.
196 ! Evap is usually negative and precip is usually positive. All heat fluxes
197 ! are in W m-2 and positive for heat going into the ocean. All fresh water
198 ! fluxes are in kg m-2 s-1 and positive for water moving into the ocean.
199 
200 ! Arguments: state - A structure containing fields that describe the
201 ! surface state of the ocean.
202 ! (out) fluxes - A structure containing pointers to any possible
203 ! forcing fields. Unused fields have NULL ptrs.
204 ! (in) day_start - Start time of the fluxes.
205 ! (in) day_interval - Length of time over which these fluxes
206 ! will be applied.
207 ! (in) G - The ocean's grid structure.
208 ! (in) CS - A pointer to the control structure returned by a previous
209 ! call to MESO_surface_forcing_init
210 
211  real :: Temp_restore ! The temperature that is being restored toward, in C.
212  real :: Salin_restore ! The salinity that is being restored toward, in PSU.
213  real :: density_restore ! The potential density that is being restored
214  ! toward, in kg m-3.
215  real :: rhoXcp ! The mean density times the heat capacity, in J m-3 K-1.
216  real :: buoy_rest_const ! A constant relating density anomalies to the
217  ! restoring buoyancy flux, in m5 s-3 kg-1.
218 
219  integer :: i, j, is, ie, js, je
220  integer :: isd, ied, jsd, jed
221 
222  is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
223  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
224 
225  ! When modifying the code, comment out this error message. It is here
226  ! so that the original (unmodified) version is not accidentally used.
227 
228  ! Allocate and zero out the forcing arrays, as necessary. This portion is
229  ! usually not changed.
230  if (cs%use_temperature) then
231  call alloc_if_needed(fluxes%evap, isd, ied, jsd, jed)
232  call alloc_if_needed(fluxes%lprec, isd, ied, jsd, jed)
233  call alloc_if_needed(fluxes%fprec, isd, ied, jsd, jed)
234  call alloc_if_needed(fluxes%lrunoff, isd, ied, jsd, jed)
235  call alloc_if_needed(fluxes%frunoff, isd, ied, jsd, jed)
236  call alloc_if_needed(fluxes%vprec, isd, ied, jsd, jed)
237 
238  call alloc_if_needed(fluxes%sw, isd, ied, jsd, jed)
239  call alloc_if_needed(fluxes%lw, isd, ied, jsd, jed)
240  call alloc_if_needed(fluxes%latent, isd, ied, jsd, jed)
241  call alloc_if_needed(fluxes%sens, isd, ied, jsd, jed)
242  call alloc_if_needed(fluxes%heat_content_lprec, isd, ied, jsd, jed)
243  else ! This is the buoyancy only mode.
244  call alloc_if_needed(fluxes%buoy, isd, ied, jsd, jed)
245  endif
246 
247 
248  ! MODIFY THE CODE IN THE FOLLOWING LOOPS TO SET THE BUOYANCY FORCING TERMS.
249  if (cs%restorebuoy .and. first_call) then !### .or. associated(CS%ctrl_forcing_CSp)) then
250  call alloc_if_needed(cs%T_Restore, isd, ied, jsd, jed)
251  call alloc_if_needed(cs%S_Restore, isd, ied, jsd, jed)
252  call alloc_if_needed(cs%Heat, isd, ied, jsd, jed)
253  call alloc_if_needed(cs%PmE, isd, ied, jsd, jed)
254  call alloc_if_needed(cs%Solar, isd, ied, jsd, jed)
255 
256  call read_data(trim(cs%inputdir)//trim(cs%SSTrestore_file), "SST", &
257  cs%T_Restore(:,:), domain=g%Domain%mpp_domain)
258  call read_data(trim(cs%inputdir)//trim(cs%salinityrestore_file), "SAL", &
259  cs%S_Restore(:,:), domain=g%Domain%mpp_domain)
260  call read_data(trim(cs%inputdir)//trim(cs%heating_file), "Heat", &
261  cs%Heat(:,:), domain=g%Domain%mpp_domain)
262  call read_data(trim(cs%inputdir)//trim(cs%PmE_file), "PmE", &
263  cs%PmE(:,:), domain=g%Domain%mpp_domain)
264  call read_data(trim(cs%inputdir)//trim(cs%Solar_file), "NET_SOL", &
265  cs%Solar(:,:), domain=g%Domain%mpp_domain)
266  first_call = .false.
267  endif
268 
269  if ( cs%use_temperature ) then
270  ! Set whichever fluxes are to be used here. Any fluxes that
271  ! are always zero do not need to be changed here.
272  do j=js,je ; do i=is,ie
273  ! Fluxes of fresh water through the surface are in units of kg m-2 s-1
274  ! and are positive downward - i.e. evaporation should be negative.
275  fluxes%evap(i,j) = -0.0 * g%mask2dT(i,j)
276  fluxes%lprec(i,j) = cs%PmE(i,j) * cs%Rho0 * g%mask2dT(i,j)
277 
278  ! vprec will be set later, if it is needed for salinity restoring.
279  fluxes%vprec(i,j) = 0.0
280 
281  ! Heat fluxes are in units of W m-2 and are positive into the ocean.
282  fluxes%lw(i,j) = 0.0 * g%mask2dT(i,j)
283  fluxes%latent(i,j) = 0.0 * g%mask2dT(i,j)
284  fluxes%sens(i,j) = cs%Heat(i,j) * g%mask2dT(i,j)
285  fluxes%sw(i,j) = cs%Solar(i,j) * g%mask2dT(i,j)
286  enddo ; enddo
287  else ! This is the buoyancy only mode.
288  do j=js,je ; do i=is,ie
289  ! fluxes%buoy is the buoyancy flux into the ocean in m2 s-3. A positive
290  ! buoyancy flux is of the same sign as heating the ocean.
291  fluxes%buoy(i,j) = 0.0 * g%mask2dT(i,j)
292  enddo ; enddo
293  endif
294 
295  if (cs%restorebuoy) then
296  if (cs%use_temperature) then
297  call alloc_if_needed(fluxes%heat_added, isd, ied, jsd, jed)
298  ! When modifying the code, comment out this error message. It is here
299  ! so that the original (unmodified) version is not accidentally used.
300 ! call MOM_error(FATAL, "MESO_buoyancy_surface_forcing: " // &
301 ! "Temperature and salinity restoring used without modification." )
302 
303  rhoxcp = cs%Rho0 * fluxes%C_p
304  do j=js,je ; do i=is,ie
305  ! Set Temp_restore and Salin_restore to the temperature (in C) and
306  ! salinity (in PSU) that are being restored toward.
307  if (g%mask2dT(i,j) > 0) then
308  fluxes%heat_added(i,j) = g%mask2dT(i,j) * &
309  ((cs%T_Restore(i,j) - state%SST(i,j)) * rhoxcp * cs%Flux_const)
310  fluxes%vprec(i,j) = - (cs%Rho0*cs%Flux_const) * &
311  (cs%S_Restore(i,j) - state%SSS(i,j)) / &
312  (0.5*(state%SSS(i,j) + cs%S_Restore(i,j)))
313  else
314  fluxes%heat_added(i,j) = 0.0
315  fluxes%vprec(i,j) = 0.0
316  endif
317  enddo ; enddo
318  else
319  ! When modifying the code, comment out this error message. It is here
320  ! so that the original (unmodified) version is not accidentally used.
321  call mom_error(fatal, "MESO_buoyancy_surface_forcing: " // &
322  "Buoyancy restoring used without modification." )
323 
324  ! The -1 is because density has the opposite sign to buoyancy.
325  buoy_rest_const = -1.0 * (cs%G_Earth * cs%Flux_const) / cs%Rho0
326  do j=js,je ; do i=is,ie
327  ! Set density_restore to an expression for the surface potential
328  ! density in kg m-3 that is being restored toward.
329  density_restore = 1030.0
330 
331  fluxes%buoy(i,j) = g%mask2dT(i,j) * buoy_rest_const * &
332  (density_restore - state%sfc_density(i,j))
333  enddo ; enddo
334  endif
335  endif ! end RESTOREBUOY
336 
337 end subroutine meso_buoyancy_forcing
338 
339 subroutine alloc_if_needed(ptr, isd, ied, jsd, jed)
340  ! If ptr is not associated, this routine allocates it with the given size
341  ! and zeros out its contents. This is equivalent to safe_alloc_ptr in
342  ! MOM_diag_mediator, but is here so as to be completely transparent.
343  real, pointer :: ptr(:,:)
344  integer :: isd, ied, jsd, jed
345  if (.not.ASSOCIATED(ptr)) then
346  allocate(ptr(isd:ied,jsd:jed))
347  ptr(:,:) = 0.0
348  endif
349 end subroutine alloc_if_needed
350 
351 subroutine meso_surface_forcing_init(Time, G, param_file, diag, CS)
352  type(time_type), intent(in) :: Time
353  type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure
354  type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
355  type(diag_ctrl), target, intent(in) :: diag
356  type(meso_surface_forcing_cs), pointer :: CS
357 ! Arguments: Time - The current model time.
358 ! (in) G - The ocean's grid structure.
359 ! (in) param_file - A structure indicating the open file to parse for
360 ! model parameter values.
361 ! (in) diag - A structure that is used to regulate diagnostic output.
362 ! (in/out) CS - A pointer that is set to point to the control structure
363 ! for this module
364 
365 ! This include declares and sets the variable "version".
366 #include "version_variable.h"
367  character(len=40) :: mdl = "MESO_surface_forcing" ! This module's name.
368 
369  if (associated(cs)) then
370  call mom_error(warning, "MESO_surface_forcing_init called with an associated "// &
371  "control structure.")
372  return
373  endif
374  allocate(cs)
375  cs%diag => diag
376 
377  ! Read all relevant parameters and write them to the model log.
378  call log_version(param_file, mdl, version, "")
379  call get_param(param_file, mdl, "ENABLE_THERMODYNAMICS", cs%use_temperature, &
380  "If true, Temperature and salinity are used as state \n"//&
381  "variables.", default=.true.)
382 
383  call get_param(param_file, mdl, "G_EARTH", cs%G_Earth, &
384  "The gravitational acceleration of the Earth.", &
385  units="m s-2", default = 9.80)
386  call get_param(param_file, mdl, "RHO_0", cs%Rho0, &
387  "The mean ocean density used with BOUSSINESQ true to \n"//&
388  "calculate accelerations and the mass for conservation \n"//&
389  "properties, or with BOUSSINSEQ false to convert some \n"//&
390  "parameters from vertical units of m to kg m-2.", &
391  units="kg m-3", default=1035.0)
392  call get_param(param_file, mdl, "GUST_CONST", cs%gust_const, &
393  "The background gustiness in the winds.", units="Pa", &
394  default=0.02)
395 
396  call get_param(param_file, mdl, "RESTOREBUOY", cs%restorebuoy, &
397  "If true, the buoyancy fluxes drive the model back \n"//&
398  "toward some specified surface state with a rate \n"//&
399  "given by FLUXCONST.", default= .false.)
400 
401  if (cs%restorebuoy) then
402  call get_param(param_file, mdl, "FLUXCONST", cs%Flux_const, &
403  "The constant that relates the restoring surface fluxes \n"//&
404  "to the relative surface anomalies (akin to a piston \n"//&
405  "velocity). Note the non-MKS units.", units="m day-1", &
406  fail_if_missing=.true.)
407  ! Convert CS%Flux_const from m day-1 to m s-1.
408  cs%Flux_const = cs%Flux_const / 86400.0
409 
410  call get_param(param_file, mdl, "SSTRESTORE_FILE", cs%SSTrestore_file, &
411  "The file with the SST toward which to restore in \n"//&
412  "variable TEMP.", fail_if_missing=.true.)
413  call get_param(param_file, mdl, "SALINITYRESTORE_FILE", cs%salinityrestore_file, &
414  "The file with the surface salinity toward which to \n"//&
415  "restore in variable SALT.", fail_if_missing=.true.)
416  call get_param(param_file, mdl, "SENSIBLEHEAT_FILE", cs%heating_file, &
417  "The file with the non-shortwave heat flux in \n"//&
418  "variable Heat.", fail_if_missing=.true.)
419  call get_param(param_file, mdl, "PRECIP_FILE", cs%PmE_file, &
420  "The file with the net precipiation minus evaporation \n"//&
421  "in variable PmE.", fail_if_missing=.true.)
422  call get_param(param_file, mdl, "SHORTWAVE_FILE", cs%Solar_file, &
423  "The file with the shortwave heat flux in \n"//&
424  "variable NET_SOL.", fail_if_missing=.true.)
425  call get_param(param_file, mdl, "INPUTDIR", cs%inputdir, default=".")
426  cs%inputdir = slasher(cs%inputdir)
427 
428  endif
429 
430 end subroutine meso_surface_forcing_init
431 
432 end module meso_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
subroutine, public meso_buoyancy_forcing(state, fluxes, day, dt, G, CS)
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 alloc_if_needed(ptr, isd, ied, jsd, jed)
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
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 meso_surface_forcing_init(Time, G, param_file, diag, CS)
subroutine, public meso_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)