Skip to content

Commit 718e62e

Browse files
author
Milan K
authored
Merge pull request #130 from milankl/whatsnext
get it mode specific and tendency by u_n+1-u_n etc
2 parents 41a9dcd + 5fdc0f7 commit 718e62e

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

src/DefaultParameters.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
init_run_id::Int=0 # run id for restart from run number
102102
init_starti::Int=-1 # timestep to start from (-1 meaning last)
103103
get_id_mode::String="continue" # How to determine the run id: "continue" or "fill"
104+
run_id::Int=-1 # Output with a specific run id
104105

105106
# ASSERT - CHECK THAT THE INPUT PARAMETERS MAKE SENSE
106107
@assert all((nx,Lx,L_ratio) .> 0.) "nx, Lx, L_ratio have to be >0"
@@ -133,7 +134,7 @@
133134
@assert initial_cond in ["rest", "ncfile"] "Initial conditions '$initial_cond' unsupported."
134135
@assert init_run_id >= 0 "Initial condition run id, init_run_id, has to be >= 0, $init_run_id given."
135136
@assert init_starti > 0 || init_starti == -1 "Start index, init_starti, has to be >0 || -1, $init_starti given."
136-
@assert get_id_mode in ["continue","fill"] "get_id_mode $get_id_mode unsupported."
137+
@assert get_id_mode in ["continue","fill","specific"] "get_id_mode $get_id_mode unsupported."
137138
end
138139

139140
"""

src/Output.jl

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,55 @@ function output_nc!(i::Int,
8888
@unpack f_q,ep,dtint = S.grid
8989

9090
# CUT OFF HALOS
91-
@views u = Prog.u[halo+1:end-halo,halo+1:end-halo]
92-
@views v = Prog.v[halo+1:end-halo,halo+1:end-halo]
93-
@views η = Prog.η[haloη+1:end-haloη,haloη+1:end-haloη]
94-
@views sst = Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty]
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= Diag.Tendencies.dη[haloη+1:end-haloη,haloη+1:end-haloη]
91+
# @views u = Prog.u[halo+1:end-halo,halo+1:end-halo]
92+
# @views v = Prog.v[halo+1:end-halo,halo+1:end-halo]
93+
# @views η = Prog.η[haloη+1:end-haloη,haloη+1:end-haloη]
94+
# @views sst = Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty]
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η]
99+
100+
# As output is before copyto!(u,u0), take u0,v0,η0
101+
@views u = Float32.(Diag.RungeKutta.u0[halo+1:end-halo,halo+1:end-halo])
102+
@views v = Float32.(Diag.RungeKutta.v0[halo+1:end-halo,halo+1:end-halo])
103+
@views η = Float32.(Diag.RungeKutta.η0[haloη+1:end-haloη,haloη+1:end-haloη])
104+
105+
@views sst = Float32.(Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty])
106+
@views ζ = Float32.((dvdx[2:end-1,2:end-1]-dudy[2+ep:end-1,2:end-1])./abs.(f_q))
107+
108+
# Tendencies calculate from the last time step, du = u_n+1-u_n etc
109+
@views du = u-Float32.(Prog.u[halo+1:end-halo,halo+1:end-halo])
110+
@views dv = v-Float32.(Prog.v[halo+1:end-halo,halo+1:end-halo])
111+
@views= η-Float32.(Prog.η[haloη+1:end-haloη,haloη+1:end-haloη])
99112

100113
# WRITING THE VARIABLES
101114
if ncs.u != nothing
102-
NetCDF.putvar(ncs.u,"u",Float32.(u),start=[1,1,iout],count=[-1,-1,1])
115+
NetCDF.putvar(ncs.u,"u",u,start=[1,1,iout],count=[-1,-1,1])
103116
end
104117
if ncs.v != nothing
105-
NetCDF.putvar(ncs.v,"v",Float32.(v),start=[1,1,iout],count=[-1,-1,1])
118+
NetCDF.putvar(ncs.v,"v",v,start=[1,1,iout],count=[-1,-1,1])
106119
end
107120
if ncs.η != nothing
108-
NetCDF.putvar(ncs.η,"eta",Float32.(η),start=[1,1,iout],count=[-1,-1,1])
121+
NetCDF.putvar(ncs.η,"eta",η,start=[1,1,iout],count=[-1,-1,1])
109122
end
110123
if ncs.sst != nothing
111-
NetCDF.putvar(ncs.sst,"sst",Float32.(sst),start=[1,1,iout],count=[-1,-1,1])
124+
NetCDF.putvar(ncs.sst,"sst",sst,start=[1,1,iout],count=[-1,-1,1])
112125
end
113126
if ncs.q != nothing
114-
NetCDF.putvar(ncs.q,"q",Float32.(q),start=[1,1,iout],count=[-1,-1,1])
127+
NetCDF.putvar(ncs.q,"q",q,start=[1,1,iout],count=[-1,-1,1])
115128
end
116129
if ncs.ζ != nothing
117-
NetCDF.putvar(ncs.ζ,"relvort",Float32.(ζ),start=[1,1,iout],count=[-1,-1,1])
130+
NetCDF.putvar(ncs.ζ,"relvort",ζ,start=[1,1,iout],count=[-1,-1,1])
118131
end
119132
if ncs.du != nothing
120-
NetCDF.putvar(ncs.du,"du",Float32.(du),start=[1,1,iout],count=[-1,-1,1])
133+
NetCDF.putvar(ncs.du,"du",du,start=[1,1,iout],count=[-1,-1,1])
121134
end
122135
if ncs.dv != nothing
123-
NetCDF.putvar(ncs.dv,"dv",Float32.(dv),start=[1,1,iout],count=[-1,-1,1])
136+
NetCDF.putvar(ncs.dv,"dv",dv,start=[1,1,iout],count=[-1,-1,1])
124137
end
125138
if ncs.!= nothing
126-
NetCDF.putvar(ncs.dη,"deta",Float32.(dη),start=[1,1,iout],count=[-1,-1,1])
139+
NetCDF.putvar(ncs.dη,"deta",,start=[1,1,iout],count=[-1,-1,1])
127140
end
128141

129142

@@ -181,14 +194,15 @@ function get_run_id_path(S::ModelSetup)
181194
runpath = joinpath(outpath,"run"*@sprintf("%04d",run_id))
182195
mkdir(runpath)
183196

184-
# elseif order == "specific" # specify the run_id as input argument
185-
# runpath = joinpath(outpath,"run"*@sprintf("%04d",run_id))
186-
# try # create folder if not existent
187-
# mkdir(runpath)
188-
# catch # else rm folder and create new one
189-
# rm(runpath,recursive=true)
190-
# mkdir(runpath)
191-
# end
197+
elseif get_id_mode == "specific" # specify the run_id as input argument
198+
@unpack run_id = S.parameters
199+
runpath = joinpath(outpath,"run"*@sprintf("%04d",run_id))
200+
try # create folder if not existent
201+
mkdir(runpath)
202+
catch # else rm folder and create new one
203+
rm(runpath,recursive=true)
204+
mkdir(runpath)
205+
end
192206

193207
elseif get_id_mode == "continue" # find largest folder and count one up
194208
run_id = maximum(existing_runs)+1

src/TimeIntegration.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ function time_integration( Prog::PrognosticVars{Tprog},
8888
add_drag_diff_tendencies!(u0,v0,Diag,S)
8989
end
9090

91-
# RK3/4 copy back from substeps
92-
copyto!(u,u0)
93-
copyto!(v,v0)
94-
copyto!(η,η0)
9591
t += dtint
9692

9793
# TRACER ADVECTION
@@ -105,6 +101,11 @@ function time_integration( Prog::PrognosticVars{Tprog},
105101
if feedback.nans_detected
106102
break
107103
end
104+
105+
# RK3/4 copy back from substeps
106+
copyto!(u,u0)
107+
copyto!(v,v0)
108+
copyto!(η,η0)
108109
end
109110

110111
# finalise feedback and output

0 commit comments

Comments
 (0)