@@ -5,11 +5,14 @@ struct NcFiles
5
5
sst:: Union{NcFile,Nothing} # tracer / sea surface temperature
6
6
q:: Union{NcFile,Nothing} # potentival vorticity
7
7
ζ:: Union{NcFile,Nothing} # relative vorticity
8
+ du:: Union{NcFile,Nothing} # tendency of u [m^2/s^2]
9
+ dv:: Union{NcFile,Nothing} # tendency of v [m^2/s^2]
10
+ dη:: Union{NcFile,Nothing} # tendency of η [m^2/s]
8
11
iout:: Array{Integer,1} # output index, stored in array for mutability
9
12
end
10
13
11
14
""" Generator function for "empty" NcFiles struct."""
12
- NcFiles (x:: Nothing ) = NcFiles (x,x,x,x,x,x,[0 ])
15
+ NcFiles (x:: Nothing ) = NcFiles (x,x,x,x,x,x,x,x,x, [0 ])
13
16
14
17
""" Generator function for NcFiles struct, creating the underlying netCDF files."""
15
18
function NcFiles (feedback:: Feedback ,S:: ModelSetup )
@@ -28,16 +31,19 @@ function NcFiles(feedback::Feedback,S::ModelSetup)
28
31
ncsst = if " sst" in output_vars nc_create (x_T,y_T," sst" ,runpath," 1" ," sea surface temperature" ) else nothing end
29
32
ncq = if " q" in output_vars nc_create (x_q,y_q," q" ,runpath," 1/(ms)" ," potential vorticity" ) else nothing end
30
33
ncζ = if " ζ" in output_vars nc_create (x_q,y_q," relvort" ,runpath," 1" ," relative vorticity" ) else nothing end
34
+ ncdu = if " du" in output_vars nc_create (x_u,y_u," du" ,runpath," m^2/s^2" ," zonal velocity tendency" ) else nothing end
35
+ ncdv = if " dv" in output_vars nc_create (x_v,y_v," dv" ,runpath," m^2/s^2" ," meridional velocity tendency" ) else nothing end
36
+ ncdη = if " dη" in output_vars nc_create (x_T,y_T," deta" ,runpath," m^2/s" ," sea surface height tendency" ) else nothing end
31
37
32
- for nc in (ncu,ncv,ncη,ncsst,ncq,ncζ)
38
+ for nc in (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη )
33
39
if nc != nothing
34
40
NetCDF. putatt (nc," t" ,Dict (" units" => " s" ," long_name" => " time" ))
35
41
NetCDF. putatt (nc," x" ,Dict (" units" => " m" ," long_name" => " zonal coordinate" ))
36
42
NetCDF. putatt (nc," y" ,Dict (" units" => " m" ," long_name" => " meridional coordinate" ))
37
43
end
38
44
end
39
45
40
- return NcFiles (ncu,ncv,ncη,ncsst,ncq,ncζ,[0 ])
46
+ return NcFiles (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη, [0 ])
41
47
else
42
48
return NcFiles (nothing )
43
49
end
@@ -87,6 +93,9 @@ function output_nc!(i::Int,
87
93
@views η = Prog. η[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη]
88
94
@views sst = Prog. sst[halosstx+ 1 : end - halosstx,halossty+ 1 : end - halossty]
89
95
@views ζ = (dvdx[2 : end - 1 ,2 : end - 1 ]- dudy[2 + ep: end - 1 ,2 : end - 1 ]). / abs .(f_q)
96
+ @views du = Diag. Tendencies. du[halo+ 1 : end - halo,halo+ 1 : end - halo]
97
+ @views dv = Diag. Tendencies. dv[halo+ 1 : end - halo,halo+ 1 : end - halo]
98
+ @views dη = Diag. Tendencies. dη[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη]
90
99
91
100
# WRITING THE VARIABLES
92
101
if ncs. u != nothing
@@ -107,9 +116,19 @@ function output_nc!(i::Int,
107
116
if ncs. ζ != nothing
108
117
NetCDF. putvar (ncs. ζ," relvort" ,Float32 .(ζ),start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
109
118
end
119
+ if ncs. du != nothing
120
+ NetCDF. putvar (ncs. du," du" ,Float32 .(du),start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
121
+ end
122
+ if ncs. dv != nothing
123
+ NetCDF. putvar (ncs. dv," dv" ,Float32 .(dv),start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
124
+ end
125
+ if ncs. dη != nothing
126
+ NetCDF. putvar (ncs. dη," deta" ,Float32 .(dη),start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
127
+ end
128
+
110
129
111
130
# WRITING THE TIME
112
- for nc in (ncs. u,ncs. v,ncs. η,ncs. sst,ncs. q,ncs. ζ)
131
+ for nc in (ncs. u,ncs. v,ncs. η,ncs. sst,ncs. q,ncs. ζ,ncs . du,ncs . dv,ncs . dη )
113
132
if nc != nothing
114
133
NetCDF. putvar (nc," t" ,Int64[i* dtint],start= [iout])
115
134
NetCDF. sync (nc) # sync to view netcdf while model is still running
@@ -124,7 +143,7 @@ function output_close!(ncs::NcFiles,feedback::Feedback,S::ModelSetup)
124
143
@unpack output = S. parameters
125
144
126
145
if output
127
- for nc in (ncs. u,ncs. v,ncs. η,ncs. sst,ncs. q,ncs. ζ)
146
+ for nc in (ncs. u,ncs. v,ncs. η,ncs. sst,ncs. q,ncs. ζ,ncs . du,ncs . dv,ncs . dη )
128
147
if nc != nothing
129
148
NetCDF. close (nc)
130
149
end
148
167
function get_run_id_path (S:: ModelSetup )
149
168
150
169
@unpack output,outpath,get_id_mode = S. parameters
151
-
170
+
152
171
if output
153
172
runlist = filter (x-> startswith (x," run" ),readdir (outpath))
154
173
existing_runs = [parse (Int,id[4 : end ]) for id in runlist]
@@ -184,101 +203,3 @@ function get_run_id_path(S::ModelSetup)
184
203
return 0 ," no runpath"
185
204
end
186
205
end
187
-
188
- # #TODO in ensemble mode, the .jl files might have changed since the start and do not correspond to what
189
- # #TODO is actually executed!
190
- # """Archives all .jl files of juls in the output folder to make runs reproducible."""
191
- # function scripts_output()
192
- # if output #&& prank == 0
193
- # # copy all files in juls main folder
194
- # mkdir(runpath*"scripts")
195
- # for juliafile in filter(x->endswith(x,".jl"),readdir())
196
- # cp(juliafile,runpath*"scripts/"*juliafile)
197
- # end
198
- #
199
- # # and also in the src folder
200
- # mkdir(runpath*"scripts/src")
201
- # for juliafile in filter(x->endswith(x,".jl"),readdir("src"))
202
- # cp("src/"*juliafile,runpath*"scripts/src/"*juliafile)
203
- # end
204
- # end
205
- # end
206
- #
207
- # """Creates a dictionary with many parameter constants to be included in the nc files."""
208
- # function output_dict()
209
- # # Attributes for nc
210
- # Dictu = Dict{String,Any}("description"=>"Data from shallow-water model juls.")
211
- # Dictu["details"] = "Cartesian coordinates, f or beta-plane, Arakawa C-grid"
212
- # Dictu["reference"] = "github.com/milankl/juls"
213
- #
214
- # Dictu["nx"] = nx
215
- # Dictu["Lx"] = Lx
216
- # Dictu["L_ratio"] = L_ratio
217
- # Dictu["delta"] = Δ
218
- #
219
- # Dictu["halo"] = halo
220
- # Dictu["haloeta"] = haloη
221
- # Dictu["halosstx"] = halosstx
222
- # Dictu["halossty"] = halossty
223
- #
224
- # Dictu["g"] = gravity
225
- # Dictu["water_depth"] = water_depth
226
- # Dictu["phi"] = ϕ
227
- # Dictu["density"] = ρ
228
- #
229
- # Dictu["wind_forcing_x"] = wind_forcing_x
230
- # Dictu["wind_forcing_y"] = wind_forcing_y
231
- # Dictu["Fx0"] = Fx0
232
- # Dictu["Fy0"] = Fy0
233
- #
234
- # Dictu["topography_feature"] = topography_feature
235
- # Dictu["topofeat_height"] = topofeat_height
236
- # Dictu["topofeat_width"] = topofeat_width
237
- #
238
- # Dictu["surface_forcing"] = string(surface_forcing)
239
- # Dictu["t_relax"] = t_relax
240
- # Dictu["eta_refh"] = η_refh
241
- # Dictu["η_refw"] = η_refw
242
- #
243
- # Dictu["Numtype"] = string(Numtype)
244
- # Dictu["output_dt"] = output_dt
245
- # Dictu["nout"] = nout
246
- # Dictu["nadvstep"] = nadvstep
247
- # Dictu["nstep_diff"] = nstep_diff
248
- # Dictu["nstep_advcor"] = nstep_advcor
249
- #
250
- # Dictu["RKo"] = RKo
251
- # Dictu["cfl"] = cfl
252
- # Dictu["Ndays"] = Ndays
253
- #
254
- # Dictu["bc_x"] = bc_x
255
- # Dictu["lbc"] = lbc
256
- #
257
- # Dictu["adv_scheme"] = adv_scheme
258
- # Dictu["dynamics"] = dynamics
259
- #
260
- # Dictu["bottom_friction"] = bottom_friction
261
- # Dictu["drag"] = drag
262
- # Dictu["taudrag"] = τdrag
263
- #
264
- # Dictu["diffusion"] = diffusion
265
- # Dictu["nuConst"] = ν_const
266
- # Dictu["c_smag"] = c_smag
267
- #
268
- # Dictu["tracer_advcetion"] = string(tracer_advection)
269
- # Dictu["tracer_relaxation"] = string(tracer_relaxation)
270
- # Dictu["injection_region"] = injection_region
271
- # Dictu["sstrestart"] = string(sstrestart)
272
- # Dictu["Uadv"] = Uadv
273
- # Dictu["SSTmax"] = SSTmax
274
- # Dictu["SSTmin"] = SSTmin
275
- # Dictu["tauSST"] = τSST
276
- # Dictu["SSTw"] = SSTw
277
- # Dictu["SSTphi"] = SSTϕ
278
- #
279
- # Dictu["initial_cond"] = initial_cond
280
- # Dictu["init_run_id"] = init_run_id
281
- # Dictu["initpath"] = initpath
282
- #
283
- # return Dictu
284
- # end
0 commit comments