Skip to content

Commit c9abc7a

Browse files
author
Milan K
authored
Merge pull request #128 from milankl/Tcomm_test
Tcomm test
2 parents 68ca9de + acc1732 commit c9abc7a

File tree

3 files changed

+28
-107
lines changed

3 files changed

+28
-107
lines changed

src/DefaultParameters.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
# OUTPUT OPTIONS
9393
output::Bool=false # netcdf output?
94-
output_vars::Array{String,1}=["u","v","η","sst","q","ζ"] # which variables to output?
94+
output_vars::Array{String,1}=["u","v","η","sst","q","ζ"] # which variables to output? "du","dv","dη" also allowed
9595
output_dt::Real=6 # output time step [hours]
9696
outpath::String=pwd() # path to output folder
9797

src/GhostPoints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ function ghost_points_η_periodic!(::Type{Tcomm},η::Array{T,2}) where {Tcomm,T}
116116
@views @inbounds η[1,:] .= T.(Tcomm.(η[end-1,:]))
117117
@views @inbounds η[end,:] .= T.(Tcomm.(η[2,:]))
118118

119-
@views @inbounds η[:,1] .= T.(Tcomm.(η[:,2]))
120-
@views @inbounds η[:,end] .= T.(Tcomm.(η[:,end-1]))
119+
@views @inbounds η[:,1] .= η[:,2]
120+
@views @inbounds η[:,end] .= η[:,end-1]
121121
end
122122

123123
""" Copy ghost points for η from inside to the halo in the nonperiodic case. """

src/Output.jl

Lines changed: 25 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ struct NcFiles
55
sst::Union{NcFile,Nothing} # tracer / sea surface temperature
66
q::Union{NcFile,Nothing} # potentival vorticity
77
ζ::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+
::Union{NcFile,Nothing} # tendency of η [m^2/s]
811
iout::Array{Integer,1} # output index, stored in array for mutability
912
end
1013

1114
"""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])
1316

1417
"""Generator function for NcFiles struct, creating the underlying netCDF files."""
1518
function NcFiles(feedback::Feedback,S::ModelSetup)
@@ -28,16 +31,19 @@ function NcFiles(feedback::Feedback,S::ModelSetup)
2831
ncsst = if "sst" in output_vars nc_create(x_T,y_T,"sst",runpath,"1","sea surface temperature") else nothing end
2932
ncq = if "q" in output_vars nc_create(x_q,y_q,"q",runpath,"1/(ms)","potential vorticity") else nothing end
3033
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 "" in output_vars nc_create(x_T,y_T,"deta",runpath,"m^2/s","sea surface height tendency") else nothing end
3137

32-
for nc in (ncu,ncv,ncη,ncsst,ncq,ncζ)
38+
for nc in (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη)
3339
if nc != nothing
3440
NetCDF.putatt(nc,"t",Dict("units"=>"s","long_name"=>"time"))
3541
NetCDF.putatt(nc,"x",Dict("units"=>"m","long_name"=>"zonal coordinate"))
3642
NetCDF.putatt(nc,"y",Dict("units"=>"m","long_name"=>"meridional coordinate"))
3743
end
3844
end
3945

40-
return NcFiles(ncu,ncv,ncη,ncsst,ncq,ncζ,[0])
46+
return NcFiles(ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη,[0])
4147
else
4248
return NcFiles(nothing)
4349
end
@@ -87,6 +93,9 @@ function output_nc!(i::Int,
8793
@views η = Prog.η[haloη+1:end-haloη,haloη+1:end-haloη]
8894
@views sst = Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty]
8995
@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= Diag.Tendencies.dη[haloη+1:end-haloη,haloη+1:end-haloη]
9099

91100
# WRITING THE VARIABLES
92101
if ncs.u != nothing
@@ -107,9 +116,19 @@ function output_nc!(i::Int,
107116
if ncs.ζ != nothing
108117
NetCDF.putvar(ncs.ζ,"relvort",Float32.(ζ),start=[1,1,iout],count=[-1,-1,1])
109118
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.!= nothing
126+
NetCDF.putvar(ncs.dη,"deta",Float32.(dη),start=[1,1,iout],count=[-1,-1,1])
127+
end
128+
110129

111130
# 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.)
113132
if nc != nothing
114133
NetCDF.putvar(nc,"t",Int64[i*dtint],start=[iout])
115134
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)
124143
@unpack output = S.parameters
125144

126145
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.)
128147
if nc != nothing
129148
NetCDF.close(nc)
130149
end
@@ -148,7 +167,7 @@ end
148167
function get_run_id_path(S::ModelSetup)
149168

150169
@unpack output,outpath,get_id_mode = S.parameters
151-
170+
152171
if output
153172
runlist = filter(x->startswith(x,"run"),readdir(outpath))
154173
existing_runs = [parse(Int,id[4:end]) for id in runlist]
@@ -184,101 +203,3 @@ function get_run_id_path(S::ModelSetup)
184203
return 0,"no runpath"
185204
end
186205
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

Comments
 (0)