-
Notifications
You must be signed in to change notification settings - Fork 24
/
scaling.jl
52 lines (49 loc) · 1.43 KB
/
scaling.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
"""
$(TYPEDSIGNATURES)
Scale the variable `var` inside `progn` with scalar `scale`.
"""
function scale!(
progn::PrognosticVariables,
var::Symbol,
scale::Real,
)
if var == :pres
for pres in progn.pres.timesteps
pres .*= scale
end
else
for layer in progn.layers
for step in layer.timesteps
variable = getfield(step, var)
variable .*= scale
end
end
end
end
"""
$(TYPEDSIGNATURES)
Scales the prognostic variables vorticity and divergence with
the Earth's radius which is used in the dynamical core."""
function scale!(progn::PrognosticVariables,
scale::Real)
new_scale = scale/progn.scale[] # undo previous scale and new scale in one go
scale!(progn, :vor, new_scale)
scale!(progn, :div, new_scale)
progn.scale[] = scale # store scaling information
end
"""
$(TYPEDSIGNATURES)
Undo the radius-scaling of vorticity and divergence from scale!(progn, scale::Real)."""
function unscale!(progn::PrognosticVariables)
inv_scale = inv(progn.scale[])
scale!(progn, :vor, inv_scale)
scale!(progn, :div, inv_scale)
progn.scale[] = 1 # set scale back to 1=unscaled
end
"""
$(TYPEDSIGNATURES)
Undo the radius-scaling for any variable. Method used for netcdf output."""
function unscale!( variable::AbstractArray,
scale::Real)
variable ./= scale
end