Skip to content

Commit 400cfc9

Browse files
committed
New solver for slotted-type advection problems where velocity field is constant but nonuniform
1 parent 9de6e24 commit 400cfc9

19 files changed

Lines changed: 694 additions & 0 deletions

advection_nonuniform/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""The pyro advection solver. This implements a second-order,
2+
unsplit method for linear advection based on the Colella 1990 paper.
3+
4+
"""
5+
6+
__all__ = ['simulation']
7+
from .simulation import *

advection_nonuniform/_defaults

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[driver]
2+
cfl = 0.8 ; advective CFL number
3+
4+
5+
[advection]
6+
u = 1.0 ; advective velocity in x-direction
7+
v = 1.0 ; advective velocity in y-direction
8+
9+
limiter = 2 ; limiter (0 = none, 1 = 2nd order, 2 = 4th order)
10+
11+
12+
[particles]
13+
do_particles = 0
14+
particle_generator = grid
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import mesh.reconstruction as reconstruction
2+
import numpy as np
3+
4+
def unsplit_fluxes(my_data, rp, dt, scalar_name):
5+
"""
6+
Construct the fluxes through the interfaces for the linear advection
7+
equation:
8+
9+
.. math::
10+
11+
a_t + u a_x + v a_y = 0
12+
13+
We use a second-order (piecewise linear) unsplit Godunov method
14+
(following Colella 1990).
15+
16+
In the pure advection case, there is no Riemann problem we need to
17+
solve -- we just simply do upwinding. So there is only one 'state'
18+
at each interface, and the zone the information comes from depends
19+
on the sign of the velocity.
20+
21+
Our convection is that the fluxes are going to be defined on the
22+
left edge of the computational zones::
23+
24+
| | | |
25+
| | | |
26+
-+------+------+------+------+------+------+--
27+
| i-1 | i | i+1 |
28+
29+
a_l,i a_r,i a_l,i+1
30+
31+
32+
a_r,i and a_l,i+1 are computed using the information in
33+
zone i,j.
34+
35+
Parameters
36+
----------
37+
my_data : CellCenterData2d object
38+
The data object containing the grid and advective scalar that
39+
we are advecting.
40+
rp : RuntimeParameters object
41+
The runtime parameters for the simulation
42+
dt : float
43+
The timestep we are advancing through.
44+
scalar_name : str
45+
The name of the variable contained in my_data that we are
46+
advecting
47+
48+
Returns
49+
-------
50+
out : ndarray, ndarray
51+
The fluxes on the x- and y-interfaces
52+
53+
"""
54+
55+
myg = my_data.grid
56+
57+
a = my_data.get_var(scalar_name)
58+
59+
u = my_data.get_var("x-velocity")
60+
v = my_data.get_var("y-velocity")
61+
62+
cx = myg.scratch_array()
63+
cy = myg.scratch_array()
64+
65+
cx.v(buf=1)[:, :] = u.v(buf=1)*dt/myg.dx
66+
cy.v(buf=1)[:, :] = v.v(buf=1)*dt/myg.dy
67+
68+
#--------------------------------------------------------------------------
69+
# monotonized central differences
70+
#--------------------------------------------------------------------------
71+
72+
limiter = rp.get_param("advection.limiter")
73+
74+
ldelta_ax = reconstruction.limit(a, myg, 1, limiter)
75+
ldelta_ay = reconstruction.limit(a, myg, 2, limiter)
76+
77+
# x-direction
78+
a_x = myg.scratch_array()
79+
shift_x = my_data.get_var("x-shift").astype(int)
80+
81+
for index,vel in np.ndenumerate(u.v(buf=1)):
82+
# upwind
83+
if vel < 0:
84+
a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] - \
85+
0.5*(1.0 + cx.v(buf=1)[index])* \
86+
ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index]
87+
else:
88+
a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] + \
89+
0.5*(1.0 - cx.v(buf=1)[index])* \
90+
ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index]
91+
92+
# y-direction
93+
a_y = myg.scratch_array()
94+
shift_y = my_data.get_var("y-shift").astype(int)
95+
96+
for index,vel in np.ndenumerate(v.v(buf=1)):
97+
# upwind
98+
if vel < 0:
99+
a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] - \
100+
0.5*(1.0 + cy.v(buf=1)[index])* \
101+
ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index]
102+
else:
103+
a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] + \
104+
0.5*(1.0 - cy.v(buf=1)[index])* \
105+
ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index]
106+
107+
# compute the transverse flux differences. The flux is just (u a)
108+
# HOTF
109+
F_xt = u*a_x
110+
F_yt = v*a_y
111+
112+
F_x = myg.scratch_array()
113+
F_y = myg.scratch_array()
114+
115+
# the zone where we grab the transverse flux derivative from
116+
# depends on the sign of the advective velocity
117+
dtdx2 = 0.5*dt/myg.dx
118+
dtdy2 = 0.5*dt/myg.dy
119+
120+
for index, vel in np.ndenumerate(u.v(buf=1)):
121+
F_x.v(buf=1)[index] = vel*(a_x.v(buf=1)[index] -
122+
dtdy2*(F_yt.ip_jp(shift_x.v(buf=1)[index], 1, buf=1)[index] -
123+
F_yt.ip(shift_x.v(buf=1)[index], buf=1)[index]))
124+
125+
for index, vel in np.ndenumerate(v.v(buf=1)):
126+
F_y.v(buf=1)[index] = vel*(a_y.v(buf=1)[index] -
127+
dtdx2*(F_xt.ip_jp(1, shift_y.v(buf=1)[index], buf=1)[index] -
128+
F_xt.jp(shift_y.v(buf=1)[index], buf=1)[index]))
129+
return F_x, F_y
130+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ['smooth', 'tophat', 'test', 'slotted']
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[slotted]
2+
omega = 0.5 ;angular velocity
3+
offset = 0.25 ;offset of the slot center from domain center
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[smooth]
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tophat]
2+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# simple inputs files for the unsplit CTU hydro scheme
2+
3+
[driver]
4+
max_steps = 500
5+
tmax = 12.5664
6+
7+
max_dt_change = 1.e33
8+
init_tstep_factor = 1.0
9+
10+
11+
[driver]
12+
cfl = 0.8
13+
14+
[io]
15+
basename = slotted_
16+
dt_out = 0.2
17+
18+
[mesh]
19+
nx = 64
20+
ny = 64
21+
xmax = 1.0
22+
ymax = 1.0
23+
24+
xlboundary = periodic
25+
xrboundary = periodic
26+
27+
ylboundary = periodic
28+
yrboundary = periodic
29+
30+
31+
[advection]
32+
u = 1.0
33+
v = 1.0
34+
35+
limiter = 2
36+
37+
[particles]
38+
do_particles = 0
39+
particle_generator = grid
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# simple inputs files for the unsplit CTU hydro scheme
2+
3+
[driver]
4+
max_steps = 500
5+
tmax = 1.0
6+
7+
max_dt_change = 1.e33
8+
init_tstep_factor = 1.0
9+
10+
11+
[driver]
12+
cfl = 0.8
13+
14+
[io]
15+
basename = smooth_
16+
dt_out = 0.2
17+
18+
[mesh]
19+
nx = 32
20+
ny = 32
21+
xmax = 1.0
22+
ymax = 1.0
23+
24+
xlboundary = periodic
25+
xrboundary = periodic
26+
27+
ylboundary = periodic
28+
yrboundary = periodic
29+
30+
31+
[advection]
32+
u = 1.0
33+
v = 1.0
34+
35+
limiter = 2
36+
37+
[particles]
38+
do_particles = 1
39+
particle_generator = grid
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# simple inputs files for the unsplit CTU hydro scheme
2+
3+
[driver]
4+
max_steps = 500
5+
tmax = 1.0
6+
7+
max_dt_change = 1.e33
8+
init_tstep_factor = 1.0
9+
10+
cfl = 0.8
11+
12+
13+
[io]
14+
basename = tophat_
15+
n_out = 10
16+
17+
[mesh]
18+
nx = 32
19+
ny = 32
20+
xmax = 1.0
21+
ymax = 1.0
22+
23+
xlboundary = periodic
24+
xrboundary = periodic
25+
26+
ylboundary = periodic
27+
yrboundary = periodic
28+
29+
30+
[advection]
31+
u = 1.0
32+
v = 1.0
33+
34+
limiter = 2

0 commit comments

Comments
 (0)