Skip to content

Commit 95509be

Browse files
authored
creating an interface module to the advection problem (#166)
This will allow us to better inherit from this solver to customize
1 parent aa189b0 commit 95509be

3 files changed

Lines changed: 48 additions & 40 deletions

File tree

pyro/advection/advective_fluxes.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from pyro.mesh import reconstruction
1+
def unsplit_fluxes(my_data, rp, dt, scalar_name, interface):
22

3-
4-
def unsplit_fluxes(my_data, rp, dt, scalar_name):
53
r"""
64
Construct the fluxes through the interfaces for the linear advection
75
equation:
@@ -53,45 +51,11 @@ def unsplit_fluxes(my_data, rp, dt, scalar_name):
5351
"""
5452

5553
myg = my_data.grid
56-
5754
a = my_data.get_var(scalar_name)
5855

59-
# get the advection velocities
60-
u = rp.get_param("advection.u")
61-
v = rp.get_param("advection.v")
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)
56+
#Compute the velocities on each direction and the interface states a_{i+1/2}^{n+1/2}.
7457

75-
a_x = myg.scratch_array()
76-
77-
# upwind
78-
if u < 0:
79-
# a_x[i,j] = a[i,j] - 0.5*(1.0 + cx)*ldelta_a[i,j]
80-
a_x.v(buf=1)[:, :] = a.v(buf=1) - 0.5*(1.0 + cx)*ldelta_ax.v(buf=1)
81-
else:
82-
# a_x[i,j] = a[i-1,j] + 0.5*(1.0 - cx)*ldelta_a[i-1,j]
83-
a_x.v(buf=1)[:, :] = a.ip(-1, buf=1) + 0.5*(1.0 - cx)*ldelta_ax.ip(-1, buf=1)
84-
85-
# y-direction
86-
a_y = myg.scratch_array()
87-
88-
# upwind
89-
if v < 0:
90-
# a_y[i,j] = a[i,j] - 0.5*(1.0 + cy)*ldelta_a[i,j]
91-
a_y.v(buf=1)[:, :] = a.v(buf=1) - 0.5*(1.0 + cy)*ldelta_ay.v(buf=1)
92-
else:
93-
# a_y[i,j] = a[i,j-1] + 0.5*(1.0 - cy)*ldelta_a[i,j-1]
94-
a_y.v(buf=1)[:, :] = a.jp(-1, buf=1) + 0.5*(1.0 - cy)*ldelta_ay.jp(-1, buf=1)
58+
u, v, a_x, a_y = interface(a, myg, rp, dt)
9559

9660
# compute the transverse flux differences. The flux is just (u a)
9761
# HOTF

pyro/advection/interface.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from pyro.mesh import reconstruction
2+
3+
4+
def linear_interface(a, myg, rp, dt):
5+
6+
# get the advection velocities
7+
u = rp.get_param("advection.u")
8+
v = rp.get_param("advection.v")
9+
10+
cx = u*dt/myg.dx
11+
cy = v*dt/myg.dy
12+
13+
# --------------------------------------------------------------------------
14+
# monotonized central differences
15+
# --------------------------------------------------------------------------
16+
17+
limiter = rp.get_param("advection.limiter")
18+
19+
ldelta_ax = reconstruction.limit(a, myg, 1, limiter)
20+
ldelta_ay = reconstruction.limit(a, myg, 2, limiter)
21+
22+
a_x = myg.scratch_array()
23+
24+
# upwind
25+
if u < 0:
26+
# a_x[i,j] = a[i,j] - 0.5*(1.0 + cx)*ldelta_a[i,j]
27+
a_x.v(buf=1)[:, :] = a.v(buf=1) - 0.5*(1.0 + cx)*ldelta_ax.v(buf=1)
28+
else:
29+
# a_x[i,j] = a[i-1,j] + 0.5*(1.0 - cx)*ldelta_a[i-1,j]
30+
a_x.v(buf=1)[:, :] = a.ip(-1, buf=1) + 0.5*(1.0 - cx)*ldelta_ax.ip(-1, buf=1)
31+
32+
# y-direction
33+
a_y = myg.scratch_array()
34+
35+
# upwind
36+
if v < 0:
37+
# a_y[i,j] = a[i,j] - 0.5*(1.0 + cy)*ldelta_a[i,j]
38+
a_y.v(buf=1)[:, :] = a.v(buf=1) - 0.5*(1.0 + cy)*ldelta_ay.v(buf=1)
39+
else:
40+
# a_y[i,j] = a[i,j-1] + 0.5*(1.0 - cy)*ldelta_a[i,j-1]
41+
a_y.v(buf=1)[:, :] = a.jp(-1, buf=1) + 0.5*(1.0 - cy)*ldelta_ay.jp(-1, buf=1)
42+
43+
return u, v, a_x, a_y

pyro/advection/simulation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66

77
import pyro.advection.advective_fluxes as flx
8+
from pyro.advection.interface import linear_interface
89
from pyro.mesh import patch
910
from pyro.particles import particles
1011
from pyro.simulation_null import NullSimulation, bc_setup, grid_setup
@@ -66,7 +67,7 @@ def evolve(self):
6667
dtdx = self.dt/self.cc_data.grid.dx
6768
dtdy = self.dt/self.cc_data.grid.dy
6869

69-
flux_x, flux_y = flx.unsplit_fluxes(self.cc_data, self.rp, self.dt, "density")
70+
flux_x, flux_y = flx.unsplit_fluxes(self.cc_data, self.rp, self.dt, "density", linear_interface)
7071

7172
"""
7273
do the differencing for the fluxes now. Here, we use slices so we

0 commit comments

Comments
 (0)