@@ -24,30 +24,30 @@ 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} , _s :: L96m , t)
27
+ function full (rhs:: Array{<:Real,1} , z:: Array{<:Real,1} , p :: L96m , t)
28
28
"""
29
29
Compute full RHS of the Lorenz '96 multiscale system.
30
30
The convention is that the first K variables are slow, while the rest K*J
31
31
variables are fast.
32
32
33
33
Input:
34
34
- `z` : vector of size (K + K*J)
35
- - `_s` : parameters
35
+ - `p` : parameters
36
36
- `t` : time (not used here since L96m is autonomous)
37
37
38
38
Output:
39
39
- `rhs` : RHS computed at `z`
40
40
41
41
"""
42
42
43
- K = _s . K
44
- J = _s . J
43
+ K = p . K
44
+ J = p . J
45
45
x = @view (z[1 : K])
46
46
y = @view (z[K+ 1 : end ])
47
47
48
48
# ## slow variables subsystem ###
49
49
# compute Yk averages
50
- Yk = compute_Yk (_s , z)
50
+ Yk = compute_Yk (p , z)
51
51
52
52
# three boundary cases
53
53
rhs[1 ] = - x[K] * (x[K- 1 ] - x[2 ]) - x[1 ]
@@ -58,10 +58,10 @@ function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, _s::L96m, t)
58
58
rhs[3 : K- 1 ] = - x[2 : K- 2 ] .* (x[1 : K- 3 ] - x[4 : K]) - x[3 : K- 1 ]
59
59
60
60
# add forcing
61
- rhs[1 : K] .+ = _s . F
61
+ rhs[1 : K] .+ = p . F
62
62
63
63
# add coupling w/ fast variables via averages
64
- rhs[1 : K] .+ = _s . hx * Yk
64
+ rhs[1 : K] .+ = p . hx * Yk
65
65
66
66
# ## fast variables subsystem ###
67
67
# three boundary cases
@@ -74,56 +74,56 @@ function full(rhs::Array{<:Real,1}, z::Array{<:Real,1}, _s::L96m, t)
74
74
75
75
# add coupling w/ slow variables
76
76
for k in 1 : K
77
- rhs[K+ 1 + (k- 1 )* J : K + k* J] .+ = _s . hy * x[k]
77
+ rhs[K+ 1 + (k- 1 )* J : K + k* J] .+ = p . hy * x[k]
78
78
end
79
79
80
80
# divide by epsilon
81
- rhs[K+ 1 : end ] ./= _s . eps
81
+ rhs[K+ 1 : end ] ./= p . eps
82
82
83
83
return rhs
84
84
end
85
85
86
- function balanced (rhs:: Array{<:Real,1} , x:: Array{<:Real,1} , _s :: L96m , t)
86
+ function balanced (rhs:: Array{<:Real,1} , x:: Array{<:Real,1} , p :: L96m , t)
87
87
"""
88
88
Compute balanced RHS of the Lorenz '96 multiscale system; i.e. only slow
89
89
variables with the linear closure.
90
- Both `rhs` and `x` are vectors of size _s .K.
90
+ Both `rhs` and `x` are vectors of size p .K.
91
91
92
92
Input:
93
93
- `x` : vector of size K
94
- - `_s` : parameters
94
+ - `p` : parameters
95
95
- `t` : time (not used here since L96m is autonomous)
96
96
97
97
Output:
98
98
- `rhs` : balanced RHS computed at `x`
99
99
100
100
"""
101
101
102
- K = _s . K
102
+ K = p . K
103
103
104
104
# three boundary cases
105
- rhs[1 ] = - x[K] * (x[K- 1 ] - x[2 ]) - (1 - _s . hx* _s . hy) * x[1 ]
106
- rhs[2 ] = - x[1 ] * (x[K] - x[3 ]) - (1 - _s . hx* _s . hy) * x[2 ]
107
- rhs[K] = - x[K- 1 ] * (x[K- 2 ] - x[1 ]) - (1 - _s . hx* _s . hy) * x[K]
105
+ rhs[1 ] = - x[K] * (x[K- 1 ] - x[2 ]) - (1 - p . hx* p . hy) * x[1 ]
106
+ rhs[2 ] = - x[1 ] * (x[K] - x[3 ]) - (1 - p . hx* p . hy) * x[2 ]
107
+ rhs[K] = - x[K- 1 ] * (x[K- 2 ] - x[1 ]) - (1 - p . hx* p . hy) * x[K]
108
108
109
109
# general case
110
- rhs[3 : K- 1 ] = - x[2 : K- 2 ] .* (x[1 : K- 3 ] - x[4 : K]) - (1 - _s . hx* _s . hy) * x[3 : K- 1 ]
110
+ rhs[3 : K- 1 ] = - x[2 : K- 2 ] .* (x[1 : K- 3 ] - x[4 : K]) - (1 - p . hx* p . hy) * x[3 : K- 1 ]
111
111
112
112
# add forcing
113
- rhs .+ = _s . F
113
+ rhs .+ = p . F
114
114
115
115
return rhs
116
116
end
117
117
118
- function compute_Yk (_s :: L96m , z:: Array{<:Real,1} )
118
+ function compute_Yk (p :: L96m , z:: Array{<:Real,1} )
119
119
"""
120
120
Reshape a vector of y_{j,k} into a matrix, then sum along one dim and divide
121
121
by J to get averages
122
122
"""
123
123
return dropdims (
124
- sum ( reshape (z[_s . K+ 1 : end ], _s . J, _s . K), dims = 1 ),
124
+ sum ( reshape (z[p . K+ 1 : end ], p . J, p . K), dims = 1 ),
125
125
dims = 1
126
- ) / _s . J
126
+ ) / p . J
127
127
end
128
128
129
129
0 commit comments