Skip to main content
10-Marble
September 17, 2021
Solved

Time to fill a pressure vessel, finite difference approximation is the solution?

  • September 17, 2021
  • 2 replies
  • 8232 views

Hi all, first post here.

 

I'm trying to learn a bit more of Mathcad, instead of solving problems on several lines of Excel for a finite discretization.

 

The problem I’m studying is a very real and common situation of cascade gas filling.

 

It consists of a source (infinity size for simplicity) feeding start-empty vessel (1atm) thought a regulator valve that obey a function critical or sub-critical flow rate f(Delta P), until both source and vessel pressure are equalized. Then plotting a Pressure Vs Time for that system. The pressure would ramp up (critical flow), then level horizontal to zero flow as the pressure accumulation at the end.

Screenshot 2021-09-17 175558.png

 

 

 

 

 

I want to keep the math simple, in the future to add z-factor for the gas compressibility factor.

 

p1=pressure source

p2=pressure vessel (to be filled)

T=temp (constant)

V=vessel volume

Cg=valve flow capacity

SG=relative density

MW=gas molecular mass

ni=mole at P_tank empty (1 atm)

nf=mole at P_tank full (P_tank=P_source)

P=n*(R*T*z)/V, (R,T,z)/V = constant C1)

 

For each infinitesimal time step, the flow rate will drop after entering sub-critical condition, as the pressure of the tank goes up until, it equalizes with 0 flow.

 

1) Flow rate (Qmol) is a function of p2.

2) p2 is a function of moles accumulated at the tank due to flow rate at a time interval.

 

I know how to write a simple equation to calculate time for accumulated moles during the critical flow (fixed flow), but the sub-critical regime flow is a function of the vessel pressure that is building up.

 

I'm stuck after some day reading posts, the math should not be difficult, but...

 

Can a differential equation be solved using a finite difference approximation? Should I try to learn program, so the pressure can be added like time steps?

 

I tried this example (c) "common sense":

http://comet.eng.unipr.it/~miccio/modelli_DCPC/EN%20with-solution/filling%20and%20overflow%20tank_EN.pdf

 

Attached my file up to where I could.

 

Many thanks in advance,

 

Fred.

 

Best answer by LucMeekes

You should not let 'an IF statement' scare you off from writing and solving a differential equation. See example below:

LucMeekes_0-1632160827961.png

 

I'm NOT saying that this is the solution to your specific problem. But I AM saying that if you can write your problem in terms of a differential equation, even if it involves a function with an IF statement, that Mathcad (and Prime) may be able to solve it.

I'm not fluent in gas flow, so I just took a (simple) differential equation to make my point.

 

Success!
Luc

2 replies

23-Emerald IV
September 18, 2021

Welcome to the forum, Frederico.

 

If you can write your problem in the form of a differential equation, Prime should be able to solve it for you. I don't see a differential equation yet...

 

Incidentally: If you are going to learn Prime, be sure to understand 'labels' of variables. You define R (the Gas constant) , but Prime already knows it, as:

LucMeekes_0-1631949545963.png

Note that the R is green and bold, it's labelled as a Constant, it's different from the R you defined:

LucMeekes_1-1631949603532.png

Which is labelled as a Variable.  You find labels in the Style section of the 'Math' ribbon... Take good care of those labels, since Prime always tries to auto-label what you type. And everything that goes automatic can go wrong automatically, and with Prime that happens more than you'd like: It happens with your i on page 2 where you define i as a range. That i is labelled as a Variable. Then when you define p2i, the i in the numerator is labelled as a "-", which means it's automatic, but this also means it's different from the range i.

That however is not the cause of the error you see there. The reason for that is that you've used a literal subscript for the i as part of the name p2i, If you want to use i as an index to p2, you have to use index notation which you get by typing p2[i.

 

Success!
Luc

10-Marble
September 18, 2021

Many thanks Luc,

 

With your help, I have now finally understood the another example using the correct index notation.

 

About the differential equation, I'm stuck, because I wrote it as an "if" programming for two functions, also in the future I could try to compute a real gas (compressibility=variable) and that would require an external solver, maybe I shouldn't try to write the math, instead rely on a "seeded iteration" to make a more user-friendly analogy to the vessel pressure increasing?

 

Found this, and I'm studying: https://community.ptc.com/t5/PTC-Mathcad/Seeded-Iteration-in-Mathcad/td-p/448391

 

Many thanks again,

 

Frederico.

LucMeekes23-Emerald IVAnswer
23-Emerald IV
September 20, 2021

You should not let 'an IF statement' scare you off from writing and solving a differential equation. See example below:

LucMeekes_0-1632160827961.png

 

I'm NOT saying that this is the solution to your specific problem. But I AM saying that if you can write your problem in terms of a differential equation, even if it involves a function with an IF statement, that Mathcad (and Prime) may be able to solve it.

I'm not fluent in gas flow, so I just took a (simple) differential equation to make my point.

 

Success!
Luc

23-Emerald I
September 18, 2021

There are various ways to solve differential equations; the one (perhaps) best suited to your approach is the one that Prime Express can still do.

 

Attached is a simple example, a damped harmonic oscillator.  The equation is solved by taking small time steps, the "trick" is the yellow highlighted vector set of equations.

10-Marble
September 20, 2021

Excellent hint. Many thanks Fred.

 

I'm taking inspiration to get to this level soon.

 

Best regards,

 

Frederico (also Fred).