cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

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

frederico.cms
10-Marble

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

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.

 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:frederico.cms)

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

View solution in original post

10 REPLIES 10
LucMeekes
23-Emerald III
(To:frederico.cms)

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

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.

LucMeekes
23-Emerald III
(To:frederico.cms)

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

Again many thanks Luc,

 

Indeed, I was scared without reason. Trying to solve symbolic gave an error that made me stop before digging deeper.

 

Your solution looks very neat and elegant, I will get inspiration on that.

 

I think I got it right after rewriting the flow equation for mol "substance", instead of the pressure building. Used a constant name C1 to gather V/(RTz), so the pressure is linear related to the mol flow. That gave me mol/s, and the differential equation was easy integrating.

 

Screenshot 2021-09-20 173748.png

 

Many thanks,

 

Frederico.

 

 

LucMeekes
23-Emerald III
(To:frederico.cms)

I gave it another try:

LucMeekes_0-1632172281235.png

Now we can solve p2 pressure over time:

LucMeekes_1-1632172337905.png

Note that the end time is between 2984 and 2985 seconds, that is 0.83 hr.

 

Success!

Luc

Applying some of the things I was taught resulted in a slightly longer time.

 

Wonderfully made, Fred. It gives a new perspective using the sonic equation and Cp/Cv.

 

The gas on the example was natural gas, and the regulator does have a very small orifice, I used this small size to create a very slow compression and keep the process isothermal for a typical 100L tank. At my stage of learning MathCAD, I would not even consider dealing with change at Temperature (and also z) during pressure build to compare to a real-life application.

 

Again, many thanks. It was great to learn with your help.

 

Frederico.

Many thanks Luc,

 

With your help, I learned the index instead of subscript from the other example I was studying.

 

The reason I can't find the differential equation in my sheet is because it is an "if" programming for two conditions (or my math skill?).

 

In Excel, I would divide time in rows of small steps (dt), calculate the new pressure accumulated from the "if" flow equation (p1, start pressure of p2), multiply by (dt), hold this small pressure increase (dp2) and feed it to the next line. Row by row, the pressure will buildup until there is no more flow, as the pressures p1 and p2 equalizes. Then sum all the (dt).

 

Should I look for a seeded interaction? I guided example?

 

Many thanks,

 

Frederico.

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.

Excellent hint. Many thanks Fred.

 

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

 

Best regards,

 

Frederico (also Fred).

Announcements

Top Tags