This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
/
dump_state.jl
72 lines (62 loc) · 1.98 KB
/
dump_state.jl
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
"""
setup_dump_state_diagnostics(
::ClimateMachineConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing a diagnostic that
simply dumps the conservative state variables at the specified
`interval` after being interpolated, into NetCDF files prefixed by
`out_prefix`.
"""
function setup_dump_state_diagnostics(
::ClimateMachineConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert !isnothing(interpol)
return DiagnosticsGroup(
"DumpState",
Diagnostics.dump_state_init,
Diagnostics.dump_state_fini,
Diagnostics.dump_state_collect,
interval,
out_prefix,
writer,
interpol,
)
end
dump_state_init(dgngrp, currtime) = dump_init(dgngrp, currtime, Prognostic())
function dump_state_collect(dgngrp, currtime)
interpol = dgngrp.interpol
mpicomm = Settings.mpicomm
dg = Settings.dg
Q = Settings.Q
FT = eltype(Q.data)
bl = dg.balance_law
mpirank = MPI.Comm_rank(mpicomm)
istate = similar(Q.data, interpol.Npl, number_states(bl, Prognostic()))
interpolate_local!(interpol, Q.data, istate)
if interpol isa InterpolationCubedSphere
# TODO: get indices here without hard-coding them
_ρu, _ρv, _ρw = 2, 3, 4
project_cubed_sphere!(interpol, istate, (_ρu, _ρv, _ρw))
end
all_state_data = accumulate_interpolated_data(mpicomm, interpol, istate)
if mpirank == 0
statenames = flattenednames(vars_state(bl, Prognostic(), FT))
varvals = OrderedDict()
for (vari, varname) in enumerate(statenames)
varvals[varname] = all_state_data[:, :, :, vari]
end
append_data(dgngrp.writer, varvals, currtime)
end
MPI.Barrier(mpicomm)
return nothing
end
function dump_state_fini(dgngrp, currtime) end