Skip to content

Commit f157fc5

Browse files
committed
Move docstrings outside functions/structs
1 parent b6b2975 commit f157fc5

File tree

1 file changed

+62
-65
lines changed

1 file changed

+62
-65
lines changed

examples/L96m/L96m.jl

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
using Parameters # lets you have defaults for fields
22

3+
"""
4+
Lorenz '96 multiscale
5+
6+
Parameters:
7+
- `K` : number of slow variables
8+
- `J` : number of fast variables per slow variable
9+
- `hx` : coupling term (in equations for slow variables)
10+
- `hy` : coupling term (in equations for fast variables)
11+
- `F` : forcing term for slow variables
12+
- `eps` : scale separation constant
13+
14+
Other:
15+
- `G` : functional closure for slow variables (usually a GPR-closure)
16+
"""
317
@with_kw mutable struct L96m
4-
"""
5-
Lorenz '96 multiscale
6-
7-
Parameters:
8-
- `K` : number of slow variables
9-
- `J` : number of fast variables per slow variable
10-
- `hx` : coupling term (in equations for slow variables)
11-
- `hy` : coupling term (in equations for fast variables)
12-
- `F` : forcing term for slow variables
13-
- `eps` : scale separation term
14-
15-
Other:
16-
- `G` : functional closure for slow variables (usually a GPR-closure)
17-
"""
1818
K::Int = 9
1919
J::Int = 8
2020
hx::Float64 = -0.8
@@ -24,22 +24,21 @@ using Parameters # lets you have defaults for fields
2424
G = nothing
2525
end
2626

27-
function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, p::L96m, t)
28-
"""
29-
Compute full RHS of the Lorenz '96 multiscale system.
30-
The convention is that the first K variables are slow, while the rest K*J
31-
variables are fast.
32-
33-
Input:
34-
- `z` : vector of size (K + K*J)
35-
- `p` : parameters
36-
- `t` : time (not used here since L96m is autonomous)
27+
"""
28+
Compute full RHS of the Lorenz '96 multiscale system.
29+
The convention is that the first K variables are slow, while the rest K*J
30+
variables are fast.
3731
38-
Output:
39-
- `rhs` : RHS computed at `z`
32+
Input:
33+
- `z` : vector of size (K + K*J)
34+
- `p` : parameters
35+
- `t` : time (not used here since L96m is autonomous)
4036
41-
"""
37+
Output:
38+
- `rhs` : RHS computed at `z`
4239
40+
"""
41+
function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, p::L96m, t)
4342
K = p.K
4443
J = p.J
4544
x = @view(z[1:K])
@@ -83,22 +82,21 @@ function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, p::L96m, t)
8382
return rhs
8483
end
8584

86-
function balanced(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
87-
"""
88-
Compute balanced RHS of the Lorenz '96 multiscale system; i.e. only slow
89-
variables with the linear closure.
90-
Both `rhs` and `x` are vectors of size p.K.
91-
92-
Input:
93-
- `x` : vector of size K
94-
- `p` : parameters
95-
- `t` : time (not used here since L96m is autonomous)
85+
"""
86+
Compute balanced RHS of the Lorenz '96 multiscale system; i.e. only slow
87+
variables with the linear closure.
88+
Both `rhs` and `x` are vectors of size p.K.
9689
97-
Output:
98-
- `rhs` : balanced RHS computed at `x`
90+
Input:
91+
- `x` : vector of size K
92+
- `p` : parameters
93+
- `t` : time (not used here since L96m is autonomous)
9994
100-
"""
95+
Output:
96+
- `rhs` : balanced RHS computed at `x`
10197
98+
"""
99+
function balanced(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
102100
K = p.K
103101

104102
# three boundary cases
@@ -115,23 +113,22 @@ function balanced(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
115113
return rhs
116114
end
117115

118-
function regressed(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
119-
"""
120-
Compute slow-variable closed RHS of the Lorenz '96 Multiscale system;
121-
i.e. only slow variables with some closure instead of Yk.
122-
Closure is taken from p.G.
123-
Both `rhs` and `x` are vectors of size p.K.
124-
125-
Input:
126-
- `x` : vector of size K
127-
- `p` : parameters
128-
- `t` : time (not used here since L96m is autonomous)
116+
"""
117+
Compute slow-variable closed RHS of the Lorenz '96 Multiscale system;
118+
i.e. only slow variables with some closure instead of Yk.
119+
Closure is taken from p.G.
120+
Both `rhs` and `x` are vectors of size p.K.
129121
130-
Output:
131-
- `rhs` : regressed RHS computed at `x`
122+
Input:
123+
- `x` : vector of size K
124+
- `p` : parameters
125+
- `t` : time (not used here since L96m is autonomous)
132126
133-
"""
127+
Output:
128+
- `rhs` : regressed RHS computed at `x`
134129
130+
"""
131+
function regressed(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
135132
K = p.K
136133

137134
# three boundary cases
@@ -151,32 +148,32 @@ function regressed(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
151148
return rhs
152149
end
153150

151+
"""
152+
Reshape a vector of y_{j,k} into a matrix, then sum along one dim and divide
153+
by J to get averages
154+
"""
154155
function compute_Yk(p::L96m, z::Array{<:Real,1})
155-
"""
156-
Reshape a vector of y_{j,k} into a matrix, then sum along one dim and divide
157-
by J to get averages
158-
"""
159156
return dropdims(
160157
sum( reshape(z[p.K+1:end], p.J, p.K), dims = 1 ),
161158
dims = 1
162159
) / p.J
163160
end
164161

162+
"""
163+
Set the closure `p.G` to a linear one with slope `slope`.
164+
If unspecified, slope is equal to `p.hy`.
165+
"""
165166
function set_G0(p::L96m; slope = nothing)
166-
"""
167-
Set the closure `p.G` to a linear one with slope `slope`.
168-
If unspecified, slope is equal to `p.hy`.
169-
"""
170167
if (slope == nothing) || (!isa(slope, Real))
171168
slope = p.hy
172169
end
173170
p.G = x -> slope * x
174171
end
175172

173+
"""
174+
Wrapper for set_G0(p::L96m; slope = nothing).
175+
"""
176176
function set_G0(p::L96m, slope::Real)
177-
"""
178-
Wrapper for set_G0(p::L96m; slope = nothing).
179-
"""
180177
set_G0(p, slope = slope)
181178
end
182179

0 commit comments

Comments
 (0)