forked from NOAA-GFDL/SIS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIS_tracer_flow_control.F90
249 lines (210 loc) · 13.5 KB
/
SIS_tracer_flow_control.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
module SIS_tracer_flow_control
!***********************************************************************
!* GNU General Public License *
!* This file is a part of SIS2. *
!* *
!* SIS2 is free software; you can redistribute it and/or modify it and *
!* are expected to follow the terms of the GNU General Public License *
!* as published by the Free Software Foundation; either version 2 of *
!* the License, or (at your option) any later version. *
!* *
!* SIS2 is distributed in the hope that it will be useful, but WITHOUT *
!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
!* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public *
!* License for more details. *
!* *
!* For the full text of the GNU General Public License, *
!* write to: Free Software Foundation, Inc., *
!* 675 Mass Ave, Cambridge, MA 02139, USA. *
!* or see: http://www.gnu.org/licenses/gpl.html *
!***********************************************************************
!********+*********+*********+*********+*********+*********+*********+**
!* *
!* By Andrew Shao, April 2016 *
!* Adapted from MOM6 code MOM_tracer_flow_control.F90 *
!* *
!* This module contains subroutines into which calls to the tracer *
!* specific functions should be called. To add a new tracer the *
!* calls should be added to each of the following subroutines. *
!* Use ice_age_tracer.F90 as a model on which to base new types of *
!* ice tracers. Generally, most tracer packages will want to *
!* define their own tracer control structures which will get *
!* pointed to by the main tracer registry in *
!* SIS_tracer_registry.F90. *
!* *
!* SIS_call_tracer_register: *
!* Allocates the tracer flow control structure and reads the *
!* parameter file SIS_input to identify which tracers will be *
!* included in the current run. Tracer packages should allocate *
!* their tracer arrays here, establish whether the tracer will *
!* be initialized from a restart file, and register the tracer *
!* for the advection module. *
!* *
!* SIS_tracer_flow_control_init: *
!* Sets the initial conditions for the tracer. Also, register *
!* tracer fields for output with the diag_manager. *
!* *
!* SIS_call_tracer_column_fns: *
!* Apply any special treatment of the tracer that may occur in *
!* a vertical column. For example, source and sink terms should *
!* be calculated and applied here *
!* *
!* SIS_call_tracer_stocks: *
!* NOTE: CURRENTLY NOT CALLED. This subroutine is intended to *
!* at some point calculate the inventory of each tracer and *
!* ready it for either output to a file or STDOUT *
!* *
!* SIS_tracer_flow_control_end: *
!* Deallocate arrays and prepare for model finalization *
!* *
!* *
!********+*********+*********+*********+*********+*********+*********+**
use SIS_diag_mediator, only : time_type, SIS_diag_ctrl
use MOM_error_handler, only : SIS_error=>MOM_error, FATAL, WARNING
use ice_grid, only : ice_grid_type
use SIS_tracer_registry, only : SIS_tracer_registry_type
use SIS_tracer_registry, only : register_SIS_tracer, register_SIS_tracer_pair
use SIS_hor_grid, only : SIS_hor_grid_type
use fms_io_mod, only : restart_file_type
use MOM_file_parser, only : get_param, log_version, param_file_type
#include <SIS2_memory.h>
! Add references to other user-provided tracer modules here.
use ice_age_tracer, only : register_ice_age_tracer, initialize_ice_age_tracer
use ice_age_tracer, only : ice_age_tracer_column_physics
use ice_age_tracer, only : ice_age_stock, ice_age_end
use ice_age_tracer, only : ice_age_tracer_CS
implicit none ; private
public SIS_call_tracer_register, SIS_tracer_flow_control_init
public SIS_call_tracer_column_fns, SIS_call_tracer_stocks, SIS_tracer_flow_control_end
type, public :: SIS_tracer_flow_control_CS ; private
logical :: use_ice_age = .false.
type(ice_age_tracer_CS), pointer :: ice_age_tracer_CSp => NULL()
end type SIS_tracer_flow_control_CS
contains
! The following subroutines and associated definitions provide the
! machinery to register and call the subroutines that initialize
! tracers and apply vertical column processes to tracers.
subroutine SIS_call_tracer_register(G, IG, param_file, CS, diag, TrReg, &
Ice_restart, restart_file)
type(SIS_hor_grid_type), intent(in) :: G
type(ice_grid_type), intent(in) :: IG
type(param_file_type), intent(in) :: param_file
type(SIS_tracer_flow_control_CS), pointer :: CS
type(SIS_diag_ctrl), target :: diag
type(SIS_tracer_registry_type), pointer :: TrReg
type(restart_file_type), intent(inout) :: Ice_restart
character(len=*), intent(in) :: restart_file
! Argument: G - The ice model's horizontal grid structure.
! (in) IG - The ice model's grid structure.
! (in) param_file - A structure indicating the open file to parse for
! model parameter values.
!
! (in/out) CS - A pointer that is set to point to the control structure
! for the tracer flow control
! (in) diag - A structure that is used to regulate diagnostic output.
! (in/out) TrReg - A pointer that is set to point to the control structure
! for the tracer advection and diffusion module.
! (in/out) Ice model restart file to be written to
! (in) Path to the restart file
!
! This include declares and sets the variable "version".
#include "version_variable.h"
character(len=40) :: mod = "SIS_tracer_flow_control" ! This module's name.
if (associated(CS)) then
call SIS_error(WARNING, "SIS_call_tracer_register called with an associated "// &
"control structure.")
return
else ; allocate(CS) ; endif
! Read all relevant parameters and write them to the model log.
call log_version(param_file, mod, version, "")
call get_param(param_file, mod, "USE_ICE_AGE_TRACER", CS%use_ice_age, &
"If true, use the concentration based age tracer package.", &
default=.false.)
! Add other user-provided calls to register tracers for restarting here. Each
! tracer package registration call returns a logical false if it cannot be run
! for some reason. This then overrides the run-time selection from above.
if (CS%use_ice_age) CS%use_ice_age = &
register_ice_age_tracer(G, IG, param_file, CS%ice_age_tracer_CSp, &
diag, TrReg, Ice_restart, restart_file)
end subroutine SIS_call_tracer_register
subroutine SIS_tracer_flow_control_init(day, G, IG, param_file, CS, is_restart)
type(time_type), target, intent(in) :: day
type(SIS_hor_grid_type), intent(inout) :: G
type(ice_grid_type), intent(in) :: IG
type(param_file_type), intent(in) :: param_file
type(SIS_tracer_flow_control_CS), pointer :: CS
logical, intent(in) :: is_restart
! This subroutine calls all registered tracer initialization
! subroutines.
! Arguments:
! (in) day - Time of the start of the run.
! (in) G - The ice model's horizontal grid structure.
! (in) IG - The ice model's vertical grid structure.
! (in) CS - The control structure returned by a previous call to
! call_tracer_register.
! (in) is_restart - flag for whether tracer should be initialized from restart
if (.not. associated(CS)) call SIS_error(FATAL, "tracer_flow_control_init: "// &
"Module must be initialized via call_tracer_register before it is used.")
! Add other user-provided calls here.
if (CS%use_ice_age) &
call initialize_ice_age_tracer(day, G, IG, CS%ice_age_tracer_CSp, is_restart)
end subroutine SIS_tracer_flow_control_init
subroutine SIS_call_tracer_column_fns(dt, G, IG, CS, mi, mi_old)
real, intent(in) :: dt
type(SIS_hor_grid_type), intent(in) :: G
type(ice_grid_type), intent(in) :: IG
type(SIS_tracer_flow_control_CS), pointer :: CS
real, dimension(SZI_(G),SZJ_(G),SZCAT_(IG)), intent(in) :: mi
real, dimension(SZI_(G),SZJ_(G),SZCAT_(IG)), intent(in) :: mi_old
! This subroutine calls all registered tracer column physics
! subroutines.
! Arguments:
! (in) dt - The amount of time covered by this call, in s.
! (in) G - The ice model's grid structure.
! (in) IG - The ice model's vertical grid structure.
if (.not. associated(CS)) call SIS_error(FATAL, "SIS_call_tracer_column_fns: "// &
"Module must be initialized via call_tracer_register before it is used.")
! Add calls to tracer column functions here.
if (CS%use_ice_age) &
call ice_age_tracer_column_physics(dt, G, IG, CS%ice_age_tracer_CSp, mi, mi_old)
end subroutine SIS_call_tracer_column_fns
subroutine SIS_call_tracer_stocks(G, IG, CS, mi)
type(SIS_hor_grid_type), intent(in) :: G
type(ice_grid_type), intent(in) :: IG
type(SIS_tracer_flow_control_CS), pointer :: CS
real, dimension(SZI_(G),SZJ_(G),SZCAT_(IG)), intent(in) :: mi
! This subroutine calls all registered tracer packages to enable them to
! add to the surface state returned to the coupler. These routines are optional.
! Arguments:
! (out) stock_values - The integrated amounts of a tracer on the current
! PE, usually in kg x concentration.
! (in) G - The ocean's grid structure.
! (in) IG - The ocean's vertical grid structure.
! (in) CS - The control structure returned by a previous call to
! call_tracer_register.
character(len=200), dimension(MAX_FIELDS_) :: names, units
character(len=200) :: set_pkg_name
real, dimension(MAX_FIELDS_) :: stocks
integer :: nstocks, m
if (.not. associated(CS)) call SIS_error(FATAL, "SIS_call_tracer_stocks: "// &
"Module must be initialized via call_tracer_register before it is used.")
nstocks = 0
stocks = 0.0
! Add other user-provided calls here.
if (CS%use_ice_age) then
call ice_age_stock(nstocks, stocks, names, units, G, IG, &
CS%ice_age_tracer_CSp, mi)
endif
if(nstocks>0) then
do m=1,nstocks
write(*,'(A,"Total ",A,A,ES24.16)') &
achar(9),trim(names(m)),achar(9),stocks(m)
enddo
endif
end subroutine SIS_call_tracer_stocks
subroutine SIS_tracer_flow_control_end(CS)
type(SIS_tracer_flow_control_CS), pointer :: CS
if (CS%use_ice_age) call ice_age_end(CS%ice_age_tracer_CSp)
if (associated(CS)) deallocate(CS)
end subroutine SIS_tracer_flow_control_end
end module SIS_tracer_flow_control