Skip to content

Commit 70445dc

Browse files
authored
simplify incompressible solver based on burgers solver (#169)
based on the previous burgers pr. Simplifies the get_interface_states function in incomp_interface.py from burgers/burgers_interface.py Also, let incompressible inherit from burgers to eliminate the method_compute_timestep function.
1 parent f91789a commit 70445dc

File tree

2 files changed

+79
-143
lines changed

2 files changed

+79
-143
lines changed

pyro/incompressible/incomp_interface.py

Lines changed: 76 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,29 @@ def mac_vels(grid, dt,
3232

3333
# get the full u and v left and right states (including transverse
3434
# 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)
4158

4259
# Riemann problem -- this follows Burger's equation. We don't use
4360
# any input velocity for the upwinding. Also, we only care about
@@ -82,13 +99,29 @@ def states(grid, dt,
8299
x and y velocities predicted to the interfaces
83100
"""
84101

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)
92125

93126
# upwind using the MAC velocity to determine which state exists on
94127
# the interface
@@ -100,128 +133,51 @@ def states(grid, dt,
100133
return u_xint, v_xint, u_yint, v_yint
101134

102135

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):
108142
r"""
109-
Compute the unsplit predictions of u and v on both the x- and
110-
y-interfaces. This includes the transverse terms.
111-
112143
Parameters
113144
----------
114145
grid : Grid2d
115146
The grid object
116147
dt : float
117148
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.
127157
Returns
128158
-------
129159
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.
132163
"""
133164

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
212166

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)
216170

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)
219174

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)
223178

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)
226182

227183
return u_xl, u_xr, u_yl, u_yr, v_xl, v_xr, v_yl, v_yr

pyro/incompressible/simulation.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import numpy as np
55

66
import pyro.mesh.array_indexer as ai
7+
from pyro.burgers import Simulation as burgers_simulation
78
from pyro.incompressible import incomp_interface
89
from pyro.mesh import patch, reconstruction
910
from pyro.multigrid import MG
1011
from pyro.particles import particles
11-
from pyro.simulation_null import NullSimulation, bc_setup, grid_setup
12+
from pyro.simulation_null import bc_setup, grid_setup
1213

1314

14-
class Simulation(NullSimulation):
15+
class Simulation(burgers_simulation):
1516

1617
def initialize(self):
1718
"""
@@ -51,27 +52,6 @@ def initialize(self):
5152
problem = importlib.import_module(f"pyro.incompressible.problems.{self.problem_name}")
5253
problem.init_data(self.cc_data, self.rp)
5354

54-
def method_compute_timestep(self):
55-
"""
56-
The timestep() function computes the advective timestep
57-
(CFL) constraint. The CFL constraint says that information
58-
cannot propagate further than one zone per timestep.
59-
60-
We use the driver.cfl parameter to control what fraction of the CFL
61-
step we actually take.
62-
"""
63-
64-
cfl = self.rp.get_param("driver.cfl")
65-
66-
u = self.cc_data.get_var("x-velocity")
67-
v = self.cc_data.get_var("y-velocity")
68-
69-
# the timestep is min(dx/|u|, dy|v|)
70-
xtmp = self.cc_data.grid.dx/(abs(u))
71-
ytmp = self.cc_data.grid.dy/(abs(v))
72-
73-
self.dt = cfl*float(min(xtmp.min(), ytmp.min()))
74-
7555
def preevolve(self):
7656
"""
7757
preevolve is called before we being the timestepping loop. For

0 commit comments

Comments
 (0)