@@ -32,12 +32,29 @@ def mac_vels(grid, dt,
32
32
33
33
# get the full u and v left and right states (including transverse
34
34
# terms) on both the x- and y-interfaces
35
- # pylint: disable-next=unused-variable
36
- u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = get_interface_states (grid , dt ,
37
- u , v ,
38
- ldelta_ux , ldelta_vx ,
39
- ldelta_uy , ldelta_vy ,
40
- gradp_x , gradp_y )
35
+
36
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
37
+ burgers_interface .get_interface_states (grid , dt ,
38
+ u , v ,
39
+ ldelta_ux , ldelta_vx ,
40
+ ldelta_uy , ldelta_vy )
41
+
42
+ # apply transverse terms on both x- and y- interfaces
43
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
44
+ burgers_interface .apply_transverse_corrections (grid , dt ,
45
+ u_xl , u_xr ,
46
+ u_yl , u_yr ,
47
+ v_xl , v_xr ,
48
+ v_yl , v_yr )
49
+
50
+ # apply pressure gradient correction terms to the interface state
51
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
52
+ apply_gradp_corrections (dt ,
53
+ u_xl , u_xr ,
54
+ u_yl , u_yr ,
55
+ v_xl , v_xr ,
56
+ v_yl , v_yr ,
57
+ gradp_x , gradp_y )
41
58
42
59
# Riemann problem -- this follows Burger's equation. We don't use
43
60
# any input velocity for the upwinding. Also, we only care about
@@ -82,13 +99,29 @@ def states(grid, dt,
82
99
x and y velocities predicted to the interfaces
83
100
"""
84
101
85
- # get the full u and v left and right states (including transverse
86
- # terms) on both the x- and y-interfaces
87
- u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = get_interface_states (grid , dt ,
88
- u , v ,
89
- ldelta_ux , ldelta_vx ,
90
- ldelta_uy , ldelta_vy ,
91
- gradp_x , gradp_y )
102
+ # get the full u and v left and right states without transverse terms and gradp
103
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
104
+ burgers_interface .get_interface_states (grid , dt ,
105
+ u , v ,
106
+ ldelta_ux , ldelta_vx ,
107
+ ldelta_uy , ldelta_vy )
108
+
109
+ # apply transverse terms on both x- and y- interfaces
110
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
111
+ burgers_interface .apply_transverse_corrections (grid , dt ,
112
+ u_xl , u_xr ,
113
+ u_yl , u_yr ,
114
+ v_xl , v_xr ,
115
+ v_yl , v_yr )
116
+
117
+ # apply pressure gradient correction terms to the interface state
118
+ u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr = \
119
+ apply_gradp_corrections (dt ,
120
+ u_xl , u_xr ,
121
+ u_yl , u_yr ,
122
+ v_xl , v_xr ,
123
+ v_yl , v_yr ,
124
+ gradp_x , gradp_y )
92
125
93
126
# upwind using the MAC velocity to determine which state exists on
94
127
# the interface
@@ -100,128 +133,51 @@ def states(grid, dt,
100
133
return u_xint , v_xint , u_yint , v_yint
101
134
102
135
103
- def get_interface_states (grid , dt ,
104
- u , v ,
105
- ldelta_ux , ldelta_vx ,
106
- ldelta_uy , ldelta_vy ,
107
- gradp_x , gradp_y ):
136
+ def apply_gradp_corrections (dt ,
137
+ u_xl , u_xr ,
138
+ u_yl , u_yr ,
139
+ v_xl , v_xr ,
140
+ v_yl , v_yr ,
141
+ gradp_x , gradp_y ):
108
142
r"""
109
- Compute the unsplit predictions of u and v on both the x- and
110
- y-interfaces. This includes the transverse terms.
111
-
112
143
Parameters
113
144
----------
114
145
grid : Grid2d
115
146
The grid object
116
147
dt : float
117
148
The timestep
118
- u, v : ndarray
119
- x-velocity and y-velocity
120
- ldelta_ux, ldelta_uy: ndarray
121
- Limited slopes of the x-velocity in the x and y directions
122
- ldelta_vx, ldelta_vy: ndarray
123
- Limited slopes of the y-velocity in the x and y directions
124
- gradp_x, gradp_y : ndarray
125
- Pressure gradients in the x and y directions
126
-
149
+ u_xl, u_xr : ndarray ndarray
150
+ left and right states of x-velocity in x-interface.
151
+ u_yl, u_yr : ndarray ndarray
152
+ left and right states of x-velocity in y-interface.
153
+ v_xl, v_xr : ndarray ndarray
154
+ left and right states of y-velocity in x-interface.
155
+ v_yl, u_yr : ndarray ndarray
156
+ left and right states of y-velocity in y-interface.
127
157
Returns
128
158
-------
129
159
out : ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray
130
- unsplit predictions of u and v on both the x- and
131
- y-interfaces
160
+ correct the interface states of the left and right states of u and v on
161
+ both the x- and y-interfaces interface states with the pressure gradient
162
+ terms.
132
163
"""
133
164
134
- u_xl = grid .scratch_array ()
135
- u_xr = grid .scratch_array ()
136
- u_yl = grid .scratch_array ()
137
- u_yr = grid .scratch_array ()
138
-
139
- v_xl = grid .scratch_array ()
140
- v_xr = grid .scratch_array ()
141
- v_yl = grid .scratch_array ()
142
- v_yr = grid .scratch_array ()
143
-
144
- # first predict u and v to both interfaces, considering only the normal
145
- # part of the predictor. These are the 'hat' states.
146
-
147
- dtdx = dt / grid .dx
148
- dtdy = dt / grid .dy
149
-
150
- # u on x-edges
151
- u_xl .ip (1 , buf = 2 )[:, :] = u .v (buf = 2 ) + \
152
- 0.5 * (1.0 - dtdx * u .v (buf = 2 )) * ldelta_ux .v (buf = 2 )
153
- u_xr .v (buf = 2 )[:, :] = u .v (buf = 2 ) - \
154
- 0.5 * (1.0 + dtdx * u .v (buf = 2 )) * ldelta_ux .v (buf = 2 )
155
-
156
- # v on x-edges
157
- v_xl .ip (1 , buf = 2 )[:, :] = v .v (buf = 2 ) + \
158
- 0.5 * (1.0 - dtdx * u .v (buf = 2 )) * ldelta_vx .v (buf = 2 )
159
- v_xr .v (buf = 2 )[:, :] = v .v (buf = 2 ) - \
160
- 0.5 * (1.0 + dtdx * u .v (buf = 2 )) * ldelta_vx .v (buf = 2 )
161
-
162
- # u on y-edges
163
- u_yl .jp (1 , buf = 2 )[:, :] = u .v (buf = 2 ) + \
164
- 0.5 * (1.0 - dtdy * v .v (buf = 2 )) * ldelta_uy .v (buf = 2 )
165
- u_yr .v (buf = 2 )[:, :] = u .v (buf = 2 ) - \
166
- 0.5 * (1.0 + dtdy * v .v (buf = 2 )) * ldelta_uy .v (buf = 2 )
167
-
168
- # v on y-edges
169
- v_yl .jp (1 , buf = 2 )[:, :] = v .v (buf = 2 ) + \
170
- 0.5 * (1.0 - dtdy * v .v (buf = 2 )) * ldelta_vy .v (buf = 2 )
171
- v_yr .v (buf = 2 )[:, :] = v .v (buf = 2 ) - \
172
- 0.5 * (1.0 + dtdy * v .v (buf = 2 )) * ldelta_vy .v (buf = 2 )
173
-
174
- # now get the normal advective velocities on the interfaces by solving
175
- # the Riemann problem.
176
- uhat_adv = burgers_interface .riemann (grid , u_xl , u_xr )
177
- vhat_adv = burgers_interface .riemann (grid , v_yl , v_yr )
178
-
179
- # now that we have the advective velocities, upwind the left and right
180
- # states using the appropriate advective velocity.
181
-
182
- # on the x-interfaces, we upwind based on uhat_adv
183
- u_xint = burgers_interface .upwind (grid , u_xl , u_xr , uhat_adv )
184
- v_xint = burgers_interface .upwind (grid , v_xl , v_xr , uhat_adv )
185
-
186
- # on the y-interfaces, we upwind based on vhat_adv
187
- u_yint = burgers_interface .upwind (grid , u_yl , u_yr , vhat_adv )
188
- v_yint = burgers_interface .upwind (grid , v_yl , v_yr , vhat_adv )
189
-
190
- # at this point, these states are the `hat' states -- they only
191
- # considered the normal to the interface portion of the predictor.
192
-
193
- ubar = grid .scratch_array ()
194
- vbar = grid .scratch_array ()
195
-
196
- ubar .v (buf = 2 )[:, :] = 0.5 * (uhat_adv .v (buf = 2 ) + uhat_adv .ip (1 , buf = 2 ))
197
- vbar .v (buf = 2 )[:, :] = 0.5 * (vhat_adv .v (buf = 2 ) + vhat_adv .jp (1 , buf = 2 ))
198
-
199
- # v du/dy is the transerse term for the u states on x-interfaces
200
- vu_y = grid .scratch_array ()
201
- vu_y .v (buf = 2 )[:, :] = vbar .v (buf = 2 ) * (u_yint .jp (1 , buf = 2 ) - u_yint .v (buf = 2 ))
202
-
203
- u_xl .ip (1 , buf = 2 )[:, :] += - 0.5 * dtdy * vu_y .v (buf = 2 ) - 0.5 * dt * gradp_x .v (buf = 2 )
204
- u_xr .v (buf = 2 )[:, :] += - 0.5 * dtdy * vu_y .v (buf = 2 ) - 0.5 * dt * gradp_x .v (buf = 2 )
205
-
206
- # v dv/dy is the transverse term for the v states on x-interfaces
207
- vv_y = grid .scratch_array ()
208
- vv_y .v (buf = 2 )[:, :] = vbar .v (buf = 2 ) * (v_yint .jp (1 , buf = 2 ) - v_yint .v (buf = 2 ))
209
-
210
- v_xl .ip (1 , buf = 2 )[:, :] += - 0.5 * dtdy * vv_y .v (buf = 2 ) - 0.5 * dt * gradp_y .v (buf = 2 )
211
- v_xr .v (buf = 2 )[:, :] += - 0.5 * dtdy * vv_y .v (buf = 2 ) - 0.5 * dt * gradp_y .v (buf = 2 )
165
+ # Apply pressure gradient correction terms
212
166
213
- # u dv/dx is the transverse term for the v states on y -interfaces
214
- uv_x = grid . scratch_array ( )
215
- uv_x .v (buf = 2 )[:, :] = ubar . v ( buf = 2 ) * ( v_xint . ip ( 1 , buf = 2 ) - v_xint .v (buf = 2 ) )
167
+ # transverse term for the u states on x -interfaces
168
+ u_xl . ip ( 1 , buf = 2 )[:, :] += - 0.5 * dt * gradp_x . v ( buf = 2 )
169
+ u_xr .v (buf = 2 )[:, :] += - 0.5 * dt * gradp_x .v (buf = 2 )
216
170
217
- v_yl .jp (1 , buf = 2 )[:, :] += - 0.5 * dtdx * uv_x .v (buf = 2 ) - 0.5 * dt * gradp_y .v (buf = 2 )
218
- v_yr .v (buf = 2 )[:, :] += - 0.5 * dtdx * uv_x .v (buf = 2 ) - 0.5 * dt * gradp_y .v (buf = 2 )
171
+ # transverse term for the v states on x-interfaces
172
+ v_xl .ip (1 , buf = 2 )[:, :] += - 0.5 * dt * gradp_y .v (buf = 2 )
173
+ v_xr .v (buf = 2 )[:, :] += - 0.5 * dt * gradp_y .v (buf = 2 )
219
174
220
- # u du/dx is the transverse term for the u states on y-interfaces
221
- uu_x = grid . scratch_array ( )
222
- uu_x .v (buf = 2 )[:, :] = ubar . v ( buf = 2 ) * ( u_xint . ip ( 1 , buf = 2 ) - u_xint .v (buf = 2 ) )
175
+ # transverse term for the v states on y-interfaces
176
+ v_yl . jp ( 1 , buf = 2 )[:, :] += - 0.5 * dt * gradp_y . v ( buf = 2 )
177
+ v_yr .v (buf = 2 )[:, :] += - 0.5 * dt * gradp_y .v (buf = 2 )
223
178
224
- u_yl .jp (1 , buf = 2 )[:, :] += - 0.5 * dtdx * uu_x .v (buf = 2 ) - 0.5 * dt * gradp_x .v (buf = 2 )
225
- u_yr .v (buf = 2 )[:, :] += - 0.5 * dtdx * uu_x .v (buf = 2 ) - 0.5 * dt * gradp_x .v (buf = 2 )
179
+ # transverse term for the u states on y-interfaces
180
+ u_yl .jp (1 , buf = 2 )[:, :] += - 0.5 * dt * gradp_x .v (buf = 2 )
181
+ u_yr .v (buf = 2 )[:, :] += - 0.5 * dt * gradp_x .v (buf = 2 )
226
182
227
183
return u_xl , u_xr , u_yl , u_yr , v_xl , v_xr , v_yl , v_yr
0 commit comments