pythonpdefipy

Writing couple of PDE equations and solving them in FiPy


I am a beginner in FiPy and I am currently trying to solve the equations of the image. It represents a compressible isothermal 1D flow.

As boundary conditions, let's say that density rho is constant in the outlet (right), while u is constant in the inlet (left). Since three variables are present (rho, u and p), I'am adding a very simple correlation such as p = rhoconstant. How would I write and solve this system? Then, let's say that the 3rd equation is a little more complex such as p = rhof(p), what should change?

W/ much help I could obtain

#1. Domain
L = 10
nx = L
dx = .1

mesh = fi.Grid1D(nx = nx, dx=dx)
x = mesh.cellCenters[0]

#2. Parameters values (Arbitrary) 
Lambda = 0.5    # Friction factor
D = 25      # Pipe diameter
z = 0.1 # Comprensibility factor
R = 0.0001  # Specific gas constant
T = 0.005   # Gas Temperature
Z = 0.1

#3. Variables
## Rho. 
rho = fi.CellVariable(name="rho", 
                      hasOld=True, 
                      mesh=mesh, 
                      value=0.)
rho.setValue(1.) 

v = fi.CellVariable(name="gas vel", 
                    hasOld=True, 
                    mesh=mesh, 
                    value=0.)
v.setValue(1.)

#4. Zero flux boundary conditions
rho.constrain (20., where = mesh.facesLeft)
v.constrain (4., where = mesh.facesRight)

#5. PDE
eq1 = fi.TransientTerm(var=rho) == - fi.ConvectionTerm(coeff=[v], var=rho)
eq2 = fi.TransientTerm(coeff = rho, var=v) == - fi.ConvectionTerm(coeff=[rho], var=v**2) - fi.ConvectionTerm(coeff=[Z*R*T], var = rho) - Lambda * rho * v * np.abs(v) / (2 * D)

eqn = (eq1 & eq2)

timeStepDuration = .1
steps = 50

#Plot the system for each time t
for step in range(steps):
    rho.updateOld()
    v.updateOld()
    eqn.sweep(dt=timeStepDuration)
    
    plt.plot(np.linspace(0, 1, nx), rho.value)
    plt.xlim(0,1.1)
    plt.ylim(0, 2.5)
    plt.show()
    

Thank you in advance.

Couple of PDE equations


Solution

  • It is not a problem to solve for density in one equation and velocity in another (you shouldn't be treating density as a constant in the second, but rather as the scalar field solved by the first equation).

    We have a Stokes flow example that might help you get started.

    We have another example with a richer flow model, but there are a lot of other things going on there that may obscure what you're interested in.