1
1
using Parameters # lets you have defaults for fields
2
2
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
+ """
3
17
@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
- """
18
18
K:: Int = 9
19
19
J:: Int = 8
20
20
hx:: Float64 = - 0.8
@@ -24,22 +24,21 @@ using Parameters # lets you have defaults for fields
24
24
G = nothing
25
25
end
26
26
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.
37
31
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)
40
36
41
- """
37
+ Output:
38
+ - `rhs` : RHS computed at `z`
42
39
40
+ """
41
+ function full (rhs:: Array{<:Real,1} , z:: Array{<:Real,1} , p:: L96m , t)
43
42
K = p. K
44
43
J = p. J
45
44
x = @view (z[1 : K])
@@ -83,22 +82,21 @@ function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, p::L96m, t)
83
82
return rhs
84
83
end
85
84
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.
96
89
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)
99
94
100
- """
95
+ Output:
96
+ - `rhs` : balanced RHS computed at `x`
101
97
98
+ """
99
+ function balanced (rhs:: Array{<:Real,1} , x:: Array{<:Real,1} , p:: L96m , t)
102
100
K = p. K
103
101
104
102
# three boundary cases
@@ -115,23 +113,22 @@ function balanced(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
115
113
return rhs
116
114
end
117
115
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.
129
121
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)
132
126
133
- """
127
+ Output:
128
+ - `rhs` : regressed RHS computed at `x`
134
129
130
+ """
131
+ function regressed (rhs:: Array{<:Real,1} , x:: Array{<:Real,1} , p:: L96m , t)
135
132
K = p. K
136
133
137
134
# three boundary cases
@@ -151,32 +148,32 @@ function regressed(rhs::Array{<:Real,1}, x::Array{<:Real,1}, p::L96m, t)
151
148
return rhs
152
149
end
153
150
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
+ """
154
155
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
- """
159
156
return dropdims (
160
157
sum ( reshape (z[p. K+ 1 : end ], p. J, p. K), dims = 1 ),
161
158
dims = 1
162
159
) / p. J
163
160
end
164
161
162
+ """
163
+ Set the closure `p.G` to a linear one with slope `slope`.
164
+ If unspecified, slope is equal to `p.hy`.
165
+ """
165
166
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
- """
170
167
if (slope == nothing ) || (! isa (slope, Real))
171
168
slope = p. hy
172
169
end
173
170
p. G = x -> slope * x
174
171
end
175
172
173
+ """
174
+ Wrapper for set_G0(p::L96m; slope = nothing).
175
+ """
176
176
function set_G0 (p:: L96m , slope:: Real )
177
- """
178
- Wrapper for set_G0(p::L96m; slope = nothing).
179
- """
180
177
set_G0 (p, slope = slope)
181
178
end
182
179
0 commit comments