Skip to content

Commit

Permalink
Change update interface, rename to step
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Nov 10, 2021
1 parent 55edc69 commit 6eeb21c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
25 changes: 12 additions & 13 deletions integration_tests/utils/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ include("parameter_set.jl")
include("Cases.jl")
import .Cases

struct State{P, A, T}
prog::P
aux::A
tendencies::T
end

struct Simulation1d
io_nt::NamedTuple
grid
Expand Down Expand Up @@ -310,7 +304,7 @@ function Simulation1d(namelist)
aux = CC.Fields.FieldVector(cent = aux_cent_fields, face = aux_face_fields)
diagnostics = CC.Fields.FieldVector(cent = diagnostic_cent_fields, face = diagnostic_face_fields)

state = State(prog, aux, tendencies)
state = TC.State(prog, aux, tendencies)

TC.compute_ref_state!(state, grid, param_set; ref_params...)

Expand Down Expand Up @@ -347,14 +341,19 @@ function run(sim::Simulation1d)
iter = 0
grid = sim.grid
state = sim.state
tendencies = state.tendencies
prog = state.prog
aux = state.aux
TS = sim.TS
diagnostics = sim.diagnostics
sim.skip_io || TC.open_files(sim.Stats) # #removeVarsHack
while sim.TS.t <= sim.TS.t_max
TC.update(sim.Turb, grid, state, sim.GMV, sim.Case, sim.TS)
TC.update(sim.TS)
params = (; edmf = sim.Turb, grid = grid, gm = sim.GMV, case = sim.Case, TS = TS, aux = aux)
while TS.t <= TS.t_max
TC.step!(tendencies, prog, params, TS.t)
TC.update(TS)

if mod(iter, 100) == 0
progress = sim.TS.t / sim.TS.t_max
progress = TS.t / TS.t_max
@show progress
end

Expand All @@ -366,14 +365,14 @@ function run(sim::Simulation1d)
# https://github.com/Alexander-Barth/NCDatasets.jl/issues/135
# opening/closing files every step should be okay. #removeVarsHack
# TurbulenceConvection.io(sim) # #removeVarsHack
TC.write_simulation_time(sim.Stats, sim.TS.t) # #removeVarsHack
TC.write_simulation_time(sim.Stats, TS.t) # #removeVarsHack

TC.io(sim.io_nt.diagnostics, sim.Stats)
TC.io(sim.io_nt.aux, sim.Stats)

TC.io(sim.GMV, grid, state, sim.Stats) # #removeVarsHack
TC.io(sim.Case, grid, state, sim.Stats) # #removeVarsHack
TC.io(sim.Turb, grid, state, sim.Stats, sim.TS, sim.param_set) # #removeVarsHack
TC.io(sim.Turb, grid, state, sim.Stats, TS, sim.param_set) # #removeVarsHack
end
iter += 1
end
Expand Down
13 changes: 8 additions & 5 deletions src/Turbulence_PrognosticTKE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ function compute_diffusive_fluxes(
end

# Perform the update of the scheme
function update(edmf::EDMF_PrognosticTKE, grid, state, gm::GridMeanVariables, Case::CasesBase, TS::TimeStepping)
function step!(tendencies, prog, params, t)
UnPack.@unpack edmf, grid, gm, case, aux, TS = params

state = State(prog, aux, tendencies)

gm = gm
up = edmf.UpdVar
Expand All @@ -267,8 +270,8 @@ function update(edmf::EDMF_PrognosticTKE, grid, state, gm::GridMeanVariables, Ca
# Some of these methods should probably live in `compute_tendencies`, when written, but we'll
# treat them as auxiliary variables for now, until we disentangle the tendency computations.

compute_updraft_surface_bc(edmf, grid, state, Case)
update_aux!(edmf, gm, grid, state, Case, param_set, TS)
compute_updraft_surface_bc(edmf, grid, state, case)
update_aux!(edmf, gm, grid, state, case, param_set, TS)

parent(state.tendencies) .= 0
tendencies_gm = center_tendencies_grid_mean(state)
Expand All @@ -284,7 +287,7 @@ function update(edmf::EDMF_PrognosticTKE, grid, state, gm::GridMeanVariables, Ca
end

# compute tendencies
compute_gm_tendencies!(edmf, grid, state, Case, gm, TS)
compute_gm_tendencies!(edmf, grid, state, case, gm, TS)
compute_updraft_tendencies(edmf, grid, state, gm)

compute_en_tendencies!(edmf, grid, state, param_set, TS, Val(:tke), Val(:ρatke))
Expand Down Expand Up @@ -331,7 +334,7 @@ function update(edmf::EDMF_PrognosticTKE, grid, state, gm::GridMeanVariables, Ca
###
### Filters
###
set_edmf_surface_bc(edmf, grid, state, up, Case.Sur)
set_edmf_surface_bc(edmf, grid, state, up, case.Sur)
filter_updraft_vars(edmf, grid, state, gm)
@inbounds for k in real_center_indices(grid)
prog_en.ρatke[k] = max(prog_en.ρatke[k], 0.0)
Expand Down
6 changes: 6 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,9 @@ mutable struct EDMF_PrognosticTKE{N_up, A1}
end
end
parameter_set(obj) = obj.param_set

struct State{P, A, T}
prog::P
aux::A
tendencies::T
end

0 comments on commit 6eeb21c

Please sign in to comment.