Skip to content

Commit 47bae11

Browse files
authored
Merge pull request #50 from taataam/master
New solver for slotted-type advection problems
2 parents 024fc3c + af5db5a commit 47bae11

28 files changed

Lines changed: 842 additions & 3 deletions

.coveragerc

100644100755
File mode changed.

.flake8

100644100755
File mode changed.

.gitignore

100644100755
File mode changed.

.pylintrc

100644100755
File mode changed.

.pytest_cache/v/cache/lastfailed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compressible/tests/test_compressible.py": true,
3+
"compressible/tests/test_eos.py": true,
4+
"compressible_rk/tests/test_compressible_rk.py": true,
5+
"swe/tests/test_swe.py": true
6+
}

.pytest_cache/v/cache/nodeids

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"advection_nonuniform/tests/test_advection_nonuniform.py::TestSimulation::()::test_initializationst"
3+
]

.travis.yml

100644100755
File mode changed.

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

0 commit comments

Comments
 (0)