Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Time to fill a pressure vessel, finite difference ...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

09-17-2021
05:00 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2021
05:00 PM

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.

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":

Attached my file up to where I could.

Many thanks in advance,

Fred.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

09-20-2021
02:03 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2021
02:03 PM

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

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

10 REPLIES 10

09-18-2021
03:31 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2021
03:31 AM

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:

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

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

09-18-2021
09:18 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2021
09:18 AM

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.

09-20-2021
02:03 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2021
02:03 PM

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

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

09-20-2021
04:46 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2021
04:46 PM

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.

Many thanks,

Frederico.

09-20-2021
05:14 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2021
05:14 PM

I gave it another try:

Now we can solve p2 pressure over time:

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

Success!

Luc

09-23-2021
08:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-23-2021
08:33 AM

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

09-26-2021
03:28 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-26-2021
03:28 PM

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.

09-18-2021
10:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2021
10:34 AM

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.

09-18-2021
07:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2021
07:07 AM

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.

09-20-2021
04:48 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2021
04:48 PM

Excellent hint. Many thanks Fred.

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

Best regards,

Frederico (also Fred).