0

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

petesing
  • 13
  • 3
  • Can you tell us what you've tried? Have you looked at FiPy's examples? – jeguyer Apr 19 '21 at 17:16
  • I did, but there is no example of a system where both variables (rho and u in that case) are passed as variables in the ConvectionTerm – petesing Apr 19 '21 at 22:15
  • ??? That's what a `ConvectionTerm` is. https://www.ctcms.nist.gov/fipy/documentation/numerical/discret.html#convection-term-nabla-cdot-left-vec-u-phi-right. The field rho is "blown" by the velocity u. *All* of the examples with a `ConvectionTerm` show this. Show us what you've tried and we'll help get it working. – jeguyer Apr 19 '21 at 22:29
  • @jeguyer just edited it! I am not sure if i can treat rho as variable in the first euqation and as a constant in the second equation (although I don't know how to treat in in the dp/dx term) – petesing Apr 20 '21 at 23:52

1 Answers1

0

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.

jeguyer
  • 2,379
  • 1
  • 11
  • 15
  • Thank you a lot! I have tried to simplify this problem, I will be posting the new set of equations (very similar, but a lot easier to solve it seems) and my code anytime soon – petesing Apr 23 '21 at 13:44