Last active
August 29, 2015 14:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.