Skip to content

Instantly share code, notes, and snippets.

@wd15
Last active August 29, 2015 14:09
Show Gist options
  • Save wd15/a08d8a6d6cbab2a24568 to your computer and use it in GitHub Desktop.
Save wd15/a08d8a6d6cbab2a24568 to your computer and use it in GitHub Desktop.
Demo of Van Leer convection term in FiPy showing how it preserves the shock quite well
from fipy import CellVariable, Grid1D, TransientTerm
from fipy import MatplotlibViewer, VanLeerConvectionTerm
from fipy import FaceVariable, ImplicitSourceTerm
length = 1.
nx = 100
dx = length/nx
mesh = Grid1D(dx=dx, nx=nx)
TG = CellVariable(mesh = mesh, hasOld = True, name = 'TG')
T_G_init = 20.0 + 273.15
TG.setValue(T_G_init)
T_G_in = 100.0 + 273.15
TG.constrain(T_G_in, mesh.facesLeft)
m_G_dot = 0.1
rho_G = 1.1
v = m_G_dot / rho_G
dt_CFL = dx/v
coeff = FaceVariable(mesh=mesh, value=[v], rank=1)
coeff.setValue([0], where=mesh.facesRight)
coeffRight = FaceVariable(mesh=mesh, value=[0.], rank=1)
coeffRight.setValue([v], where=mesh.facesRight)
eqn = TransientTerm() \
+ VanLeerConvectionTerm(coeff) \
+ ImplicitSourceTerm(coeffRight.divergence) == 0
iterTime = length/v
iterSteps = iterTime/dt_CFL
iterSteps = int(iterSteps)
viewer = MatplotlibViewer(vars=(TG),datamin=273.15, datamax=400)
for t in xrange(iterSteps + 20):
res = 1e+10
TG.updateOld()
while res > 1e-10:
res = eqn.sweep(var=TG, dt=dt_CFL)
viewer.plot()
@wd15
Copy link
Author

wd15 commented Nov 14, 2014

I updated the Gist this issue was that the right hand boundary condition again wasn't working correctly with the constraint. I am not sure what the issue is, but you can work around it by using an ImplicitSourceTerm to imitate an outflow condition on the right hand side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment