@@ -13,12 +13,17 @@ module dyed_obc_tracer
13
13
use MOM_io, only : file_exists, MOM_read_data, slasher, vardesc, var_desc, query_vardesc
14
14
use MOM_open_boundary, only : ocean_OBC_type
15
15
use MOM_restart, only : MOM_restart_CS
16
+ use MOM_restart, only : query_initialized, set_initialized
16
17
use MOM_time_manager, only : time_type
17
18
use MOM_tracer_registry, only : register_tracer, tracer_registry_type
18
19
use MOM_tracer_diabatic, only : tracer_vertdiff, applyTracerBoundaryFluxesInOut
19
20
use MOM_unit_scaling, only : unit_scale_type
20
21
use MOM_variables, only : surface
21
22
use MOM_verticalGrid, only : verticalGrid_type
23
+ use MOM_open_boundary, only : OBC_segment_type, register_segment_tracer
24
+ use MOM_tracer_registry, only : tracer_type
25
+ use MOM_tracer_registry, only : tracer_name_lookup
26
+ use MOM_tracer_advect_schemes, only : set_tracer_advect_scheme, TracerAdvectionSchemeDoc
22
27
23
28
implicit none ; private
24
29
@@ -36,6 +41,9 @@ module dyed_obc_tracer
36
41
type (tracer_registry_type), pointer :: tr_Reg = > NULL () ! < A pointer to the tracer registry
37
42
real , pointer :: tr(:,:,:,:) = > NULL () ! < The array of tracers used in this subroutine in [conc]
38
43
44
+ logical :: tracers_may_reinit ! < If true, these tracers be set up via the initialization code if
45
+ ! ! they are not found in the restart files.
46
+
39
47
integer , allocatable , dimension (:) :: ind_tr ! < Indices returned by atmos_ocn_coupler_flux if it is used and the
40
48
! ! surface tracer concentrations are to be provided to the coupler.
41
49
@@ -69,6 +77,10 @@ function register_dyed_obc_tracer(HI, GV, param_file, CS, tr_Reg, restart_CS)
69
77
real , pointer :: tr_ptr(:,:,:) = > NULL () ! The tracer concentration [conc]
70
78
logical :: register_dyed_obc_tracer
71
79
integer :: isd, ied, jsd, jed, nz, m
80
+ integer :: n_dye ! Number of regionsl dye tracers
81
+ integer :: advect_scheme ! Advection scheme value for this tracer
82
+ character (len= 256 ) :: mesg ! Advection scheme name for this tracer
83
+
72
84
isd = HI% isd ; ied = HI% ied ; jsd = HI% jsd ; jed = HI% jed ; nz = GV% ke
73
85
74
86
if (associated (CS)) then
@@ -79,9 +91,21 @@ function register_dyed_obc_tracer(HI, GV, param_file, CS, tr_Reg, restart_CS)
79
91
80
92
! Read all relevant parameters and write them to the model log.
81
93
call log_version(param_file, mdl, version, " " )
82
- call get_param(param_file, mdl, " NUM_DYE_TRACERS" , CS% ntr, &
83
- " The number of dye tracers in this run. Each tracer " // &
84
- " should have a separate boundary segment." , default= 0 )
94
+ call get_param(param_file, mdl, " NUM_DYED_TRACERS" , CS% ntr, &
95
+ " The number of dyed_obc tracers in this run. Each tracer " // &
96
+ " should have a separate boundary segment." // &
97
+ " If not present, use NUM_DYE_TRACERS." , default=- 1 )
98
+ if (CS% ntr == - 1 ) then
99
+ ! for backward compatibility
100
+ call get_param(param_file, mdl, " NUM_DYE_TRACERS" , CS% ntr, &
101
+ " The number of dye tracers in this run. Each tracer " // &
102
+ " should have a separate boundary segment." , default= 0 )
103
+ n_dye = 0
104
+ else
105
+ call get_param(param_file, mdl, " NUM_DYE_TRACERS" , n_dye, &
106
+ " The number of dye tracers in this run. Each tracer " // &
107
+ " should have a separate region." , default= 0 , do_not_log= .true. )
108
+ endif
85
109
allocate (CS% ind_tr(CS% ntr))
86
110
allocate (CS% tr_desc(CS% ntr))
87
111
@@ -97,10 +121,21 @@ function register_dyed_obc_tracer(HI, GV, param_file, CS, tr_Reg, restart_CS)
97
121
CS% tracer_IC_file)
98
122
endif
99
123
124
+ call get_param(param_file, mdl, " TRACERS_MAY_REINIT" , CS% tracers_may_reinit, &
125
+ " If true, tracers may go through the initialization code " // &
126
+ " if they are not found in the restart files. Otherwise " // &
127
+ " it is a fatal error if the tracers are not found in the " // &
128
+ " restart files of a restarted run." , default= .false. )
129
+
130
+ call get_param(param_file, mdl, " DYED_TRACER_ADVECTION_SCHEME" , mesg, &
131
+ desc= " The horizontal transport scheme for dyed_obc tracers:\n" // &
132
+ trim (TracerAdvectionSchemeDoc)// &
133
+ " \n Set to blank (the default) to use TRACER_ADVECTION_SCHEME." , default= " " )
134
+
100
135
allocate (CS% tr(isd:ied,jsd:jed,nz,CS% ntr), source= 0.0 )
101
136
102
137
do m= 1 ,CS% ntr
103
- write (name,' ("dye_",I2.2)' ) m
138
+ write (name,' ("dye_",I2.2)' ) m+ n_dye ! after regional dye tracers
104
139
write (longname,' ("Concentration of dyed_obc Tracer ",I2.2)' ) m
105
140
CS% tr_desc(m) = var_desc(name, units= " kg kg-1" , longname= longname, caller= mdl)
106
141
if (GV% Boussinesq) then ; flux_units = " kg kg-1 m3 s-1"
@@ -109,11 +144,14 @@ function register_dyed_obc_tracer(HI, GV, param_file, CS, tr_Reg, restart_CS)
109
144
! This is needed to force the compiler not to do a copy in the registration
110
145
! calls. Curses on the designers and implementers of Fortran90.
111
146
tr_ptr = > CS% tr(:,:,:,m)
147
+ ! Get the integer value of the tracer scheme
148
+ call set_tracer_advect_scheme(advect_scheme, mesg)
112
149
! Register the tracer for horizontal advection, diffusion, and restarts.
113
150
call register_tracer(tr_ptr, tr_Reg, param_file, HI, GV, &
114
151
name= name, longname= longname, units= " kg kg-1" , &
115
152
registry_diags= .true. , flux_units= flux_units, &
116
- restart_CS= restart_CS)
153
+ restart_CS= restart_CS, mandatory= .not. CS% tracers_may_reinit, &
154
+ advect_scheme= advect_scheme)
117
155
118
156
! Set coupled_tracers to be true (hard-coded above) to provide the surface
119
157
! values to the coupler (if any). This is meta-code and its arguments will
@@ -158,24 +196,24 @@ subroutine initialize_dyed_obc_tracer(restart, day, G, GV, h, diag, OBC, CS)
158
196
CS% Time = > day
159
197
CS% diag = > diag
160
198
161
- if (.not. restart) then
162
- if (len_trim (CS% tracer_IC_file) >= 1 ) then
163
- ! Read the tracer concentrations from a netcdf file.
164
- if (.not. file_exists(CS% tracer_IC_file, G% Domain)) &
165
- call MOM_error(FATAL, " dyed_obc_initialize_tracer: Unable to open " // &
166
- CS% tracer_IC_file)
167
- do m= 1 ,CS% ntr
199
+ do m= 1 ,CS% ntr
200
+ if ((.not. restart) .or. (CS% tracers_may_reinit .and. .not. &
201
+ query_initialized(CS% tr(:,:,:,m), name, CS% restart_CSp))) then
202
+ if (len_trim (CS% tracer_IC_file) >= 1 ) then
203
+ ! Read the tracer concentrations from a netcdf file.
204
+ if (.not. file_exists(CS% tracer_IC_file, G% Domain)) &
205
+ call MOM_error(FATAL, " dyed_obc_initialize_tracer: Unable to open " // &
206
+ CS% tracer_IC_file)
168
207
call query_vardesc(CS% tr_desc(m), name, caller= " initialize_dyed_obc_tracer" )
169
208
call MOM_read_data(CS% tracer_IC_file, trim (name), CS% tr(:,:,:,m), G% Domain)
170
- enddo
171
- else
172
- do m= 1 ,CS% ntr
209
+ else
173
210
do k= 1 ,nz ; do j= js,je ; do i= is,ie
174
211
CS% tr(i,j,k,m) = 0.0
175
212
enddo ; enddo ; enddo
176
- enddo
177
- endif
178
- endif ! restart
213
+ endif
214
+ call set_initialized(CS% tr(:,:,:,m), name, CS% restart_CSp)
215
+ endif ! restart
216
+ enddo ! Tracer loop
179
217
180
218
end subroutine initialize_dyed_obc_tracer
181
219
@@ -264,5 +302,9 @@ end subroutine dyed_obc_tracer_end
264
302
! ! their output and the subroutine that does any tracer physics or
265
303
! ! chemistry along with diapycnal mixing (included here because some
266
304
! ! tracers may float or swim vertically or dye diapycnal processes).
305
+ ! !
306
+ ! ! The advection scheme of these tracers can be set to be different
307
+ ! ! to that used by active tracers.
308
+
267
309
268
310
end module dyed_obc_tracer
0 commit comments