Dear fipy-users and developers,
I am new to fipy and would like to solve Burgers' equation as a first
step. This problem involves a non-linear convection term. According to
the FAQs, for the diffusion term it is to program the nonlinearity using
coeff. I did the same for the convection term:
fipy.VanLeerConvectionTerm( coeff = (0.5 * phi, ), var = phi ). But
somehow it does not work out. I also tried with phi.faceValue.
Best regards
Sebastian
# -*- coding: utf-8 -*-
# fipy.__version__ = '3.1'
import fipy
import numpy as np
import time
L = 1.0
n = 50
cfl = 0.5
n_steps = 75
alpha = 20
beta = 1.2
phi_left = 0.5 * fipy.numerix.tanh( -alpha*(-L/4.0) ) + beta
t = fipy.Variable(value=0)
# mesh object
mesh = fipy.Grid1D(Lx = L, nx = n)
# coordinates of cell centers
x = mesh.cellCenters[0]
# solution variable
phi = fipy.CellVariable(name = "numerical solution", mesh = mesh, value = 0.0)
# initial condition
phi.setValue(0.5 * fipy.numerix.tanh( -alpha*(x-L/4.0) ) + beta)
# reservoir boundary condition
phi.constrain(phi_left, mesh.facesLeft)
# inlet-outlet boundary condition (not sure, if correct)
phi.faceGrad.constrain([ 0 ], mesh.facesRight)
if __name__ == '__main__':
viewer = fipy.Viewer(vars=phi,
datamin = 0., datamax = 1.2*phi_left)
viewer.plot()
# inviscid Burgers' equation: u_t + ( u^2 /2 )_x == 0
phiFace = phi.faceValue
eqn = fipy.TransientTerm(var = phi) +\
fipy.VanLeerConvectionTerm( coeff = (0.5 * phiFace, ), var = phi ) == 0
#eqn = fipy.TransientTerm(var = phi) +\
# fipy.VanLeerConvectionTerm( coeff = (0.5 * phi, ), var = phi ) == 0
step = 0
while (step < n_steps):
dt = cfl * np.min(mesh.cellVolumes) / np.max(phi.value)
eqn.solve(var=phi, dt=dt)
step += 1
t += dt
if __name__ == '__main__':
viewer.plot(filename="./pictures/burgers-{:04d}.png".format(step))
time.sleep(0.050)_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]