I How to calculate the mass of gas in a tank?

  • Thread starter Thread starter Leopold89
  • Start date Start date
  • Tags Tags
    Gas Mass Tank
Click For Summary
The discussion revolves around calculating the remaining gas mass or particle number in a pressurized air tank, considering factors such as temperature, pressure, and phase changes. The user has time series data for gas pressure and room temperature but lacks direct temperature measurements of the gas. They explore the complexities of transitioning between liquid and gas phases and the impact of thermal inertia and heat transfer on their calculations. The conversation includes various thermodynamic equations and models to estimate the gas mass, emphasizing the need for accurate initial conditions and the use of steam tables for properties of substances. Ultimately, the user seeks clarification on integrating thermodynamic principles and the correct application of equations to derive the desired results.
  • #91
Leopold89 said:
View attachment 350488
Sorry about the x-axis. I wrote that measurements take place every 2 minutes, so I got lazy and omitted the x-axis. The first row is direct sensor data for temperature and pressure. The x axis is the same for all plots, which is why I now only wrote it at the bottom.

The jagginess is only observable in CO##_2## and not in any other gas, but you see the same jagginess in all two CO##_2## tanks. That is why I think a defect or noise is unlikely, but on the other hand the other gases do not show this pattern. The slow rising pressure is, as far as I understand, the result of weather. Guessing the discharges might be difficult, because small amounts of this one gas are discharged.
The jagginess might also be only of secondary concern, because if the mass is calculated correctly, you should be able to smoothen this pattern away.

OK. So the long-term trends could be influenced by the weather. Would it be possible to plot this with a timestamp (e.g., day, hour, minute, or just day and hour)?

It would be feasible if you know the time at each time step, or you could assume the peak temperature represents the hottest time of day to see if that provides a clear pattern.

It might also help to understand how heat is transferred to the tank. For instance, I'd expect the tank temperature to rise around 15:00 when the room temperature is highest.

In addition to the temperature sensor you've mentioned, do you have another one to monitor the room from which the tank is absorbing heat?

However, those sudden pressure increments don't make sense. I can't figure out what's causing them. I could understand sudden drops in pressure if you're opening the valves to release pressure, but not the opposite. And even that should not cause such jaggedness since you mentioned that the valves only open a couple of times a day.

Can you find out how long the valves remain open? Is it a matter of seconds, minutes, or hours? You said they release small amounts, but I want to see if these releases could overlap with the long-term trends we're attributing to the weather.

Finally, can you share your pressure and temperature (P and T) data from the last plot in the same format you previously used to share the saturation bell for CO2? Ideally, with the timestamp included as well.
 
Science news on Phys.org
  • #92
Leopold89 said:
View attachment 350488
Sorry about the x-axis. I wrote that measurements take place every 2 minutes, so I got lazy and omitted the x-axis. The first row is direct sensor data for temperature and pressure. The x axis is the same for all plots, which is why I now only wrote it at the bottom.

The jagginess is only observable in CO##_2## and not in any other gas, but you see the same jagginess in all two CO##_2## tanks. That is why I think a defect or noise is unlikely, but on the other hand the other gases do not show this pattern. The slow rising pressure is, as far as I understand, the result of weather. Guessing the discharges might be difficult, because small amounts of this one gas are discharged.
The jagginess might also be only of secondary concern, because if the mass is calculated correctly, you should be able to smoothen this pattern away.
How can the mass increase if the tank is only vented.
 
  • Like
Likes Vanadium 50 and Juanda
  • #93
Chestermiller said:
How can the mass increase if the tank is only vented.
Here is the kind of pressure regulator I am using to vent gas, but in German. Mass should therefore not flow inside. I would not think mass is increasing, but instead that too many simplifications were made or a miscalculation happened somewhere, which is why I posted my code.

If mass increases, ##\Delta m \propto \frac{p_1}{T_1}-\frac{p_2}{T_2}##, I would guess that either the pressure ##p_2## is smaller than it should be or the temperature ##T_2## is larger than it should be. The last case makes sense and for me it means that the heat transfer from room to gas takes time that is not negligible.

Another one of my fruitless ideas is to plot a histogram of enthropy or enthalpy. After each release the peak should move further away and this new expectation value could be used to determine the system variables in equilibrium, but the enthalpy curve looks just like the temperature curve.
 
  • #94
Leopold89 said:
Here is the kind of pressure regulator I am using to vent gas, but in German. Mass should therefore not flow inside. I would not think mass is increasing, but instead that too many simplifications were made or a miscalculation happened somewhere, which is why I posted my code.

If mass increases, ##\Delta m \propto \frac{p_1}{T_1}-\frac{p_2}{T_2}##, I would guess that either the pressure ##p_2## is smaller than it should be or the temperature ##T_2## is larger than it should be. The last case makes sense and for me it means that the heat transfer from room to gas takes time that is not negligible.

Another one of my fruitless ideas is to plot a histogram of enthropy or enthalpy. After each release the peak should move further away and this new expectation value could be used to determine the system variables in equilibrium, but the enthalpy curve looks just like the temperature curve.

With that kind of valve, the mass flow should only be towards the exit (only discharges happening).
And it should only depend on the forces ##F_1## and ##F_2## which are defined by the difference in pressure between the chambers (inside the tank and room pressure for simplification) and the springs installed.
1724847507400.png


In summary, once the pressure tank goes beyond a certain pressure limit defined by the ambient pressure and the springs, the valve will open.

In this case, since the input energy that could cause the valve opening simply comes from the heat in the room, I believe the released mass will be very small until pressure equilibrium is reached again.
The content of the tank might not even go inside the bell because of how small is the release. As you suggested in a previous post your program is not aborting the calculation so the content seems to be 100% gas all the time.
Leopold89 said:
For the bell check I used this CO##_2## table attached here and interpolated it with scipy.interpolate. This way I get a pressure for a given temperature and can check if the measurements are below this limit. If not the program aborts.

So you might release some mass at the beginning when the tank is full but you won't release any mass in future days because the heat input from the room won't be enough to increase the pressure to the point to force the valve opening again now that there is less mass inside. This is unless the next day is significantly hotter than the previous day.

Again, if you supply your temperature and pressure data I'd like to attempt to calculate the mass myself only using the compressibility factor ##Z##.
Assuming that the content doesn't turn to liquid, you don't need differential equations to know the mass at any moment. The procedure established in#73 should suffice. I don't understand why you're using Van-der-Waals-equation and ODEs.
And even if it does transform to liquid during discharges, you could calculate the mass assuming it doesn't. You might get weird values in the time steps where there is liquid in the chamber but that liquid should turn into gas soon so you should see periods of time where the mass is constant which correspond to those times where there is 100% gas in the tank and the valves are closed. However, your pressure and temperature sensors must give you reliable data for that calculation to be accurate.
 
  • #95
Let’s see what you get if you plot the measured outside temperature at time t as a function of the measured inside pressure at time t.
 
  • #96
Juanda said:
Would it be possible to plot this with a timestamp (e.g., day, hour, minute, or just day and hour)?
data2.png

Juanda said:
It might also help to understand how heat is transferred to the tank. For instance, I'd expect the tank temperature to rise around 15:00 when the room temperature is highest.
In above plot I believe to see how the temperature is maximal between 12:00 and 16:00, but the pressure is maximal at around 16:00, maybe a little later than the temperature.
Juanda said:
In addition to the temperature sensor you've mentioned, do you have another one to monitor the room from which the tank is absorbing heat?
Do you mean the room that affects the pressure regulator? I don't think the cable is long enough to get the second one there.
Juanda said:
Finally, can you share your pressure and temperature (P and T) data from the last plot in the same format you previously used to share the saturation bell for CO2? Ideally, with the timestamp included as well.
pt3d.png

Did you mean something like this? The z-axis is still time in minutes though.
Chestermiller said:
Let’s see what you get if you plot the measured outside temperature at time t as a function of the measured inside pressure at time t.
pTplot.png

I switched the axes, because it fits better with the phase diagrams I know. Orange is the interpolated vapour-liquid-limit from my table.

Juanda said:
Again, if you supply your temperature and pressure data I'd like to attempt to calculate the mass myself only using the compressibility factor Z.
Oh, I thought you meant plots, not a data file. Attached here.
 

Attachments

  • #97
Leopold89 said:
For the bell check I used this CO##_2## table attached (...)
What's the meaning of ##r##?
1724867408582.png


I think I don't need it for the way I want to solve it but I'd like to know.
 
  • #98
Leopold89 said:
View attachment 350501

In above plot I believe to see how the temperature is maximal between 12:00 and 16:00, but the pressure is maximal at around 16:00, maybe a little later than the temperature.

Do you mean the room that affects the pressure regulator? I don't think the cable is long enough to get the second one there.

View attachment 350504
Did you mean something like this? The z-axis is still time in minutes though.

View attachment 350502
I switched the axes, because it fits better with the phase diagrams I know. Orange is the interpolated vapour-liquid-limit from my table.
This graph seems to suggest that, since the pressure is less than the equilibrium vapor pressure at each temperature, the gas is always superheated. That would mean that there is a single phase at all times. (I assume you have plotted the absolute pressures, not the gauge pressures, which are 0.1 MPa lower). Under these circumstances, the equation of state indicated by Juanda applies: $$\frac{m}{V}=\frac{PM}{zRT}$$where m is in grams, and R=8.314 J/mole-K. So you can calculate how m varies with time in your example (assuming the temperature in the tank has equilibrated with the outside temperature at each time). What do you calculate?
 
  • #99
Chestermiller said:
I assume you have plotted the absolute pressures, not the gauge pressures, which are 0.1 MPa lower
Oh, no. I plotted the gauge pressures. The absolute pressures are only in post #71.
Chestermiller said:
What do you calculate?
I calculate precisely this in post #88. It is the bottom right graph.
 
  • #100
Leopold89 said:
Oh, no. I plotted the gauge pressures. The absolute pressures are only in post #71.
:(
That could change the problem significantly. I did everything assuming we're talking about absolute pressures.

Leopold89 said:
I calculate precisely this in post #88. It is the bottom right graph.
If that's true, then all I can think of is two things:
  • either the new data regarding absolute pressures changes the problem significantly because you're inside the bell although you mentioned you're checking if that's the case and it seems it's gas all the time
  • or your sensors are not accurate.
My bet is that your temperature sensor is not accurate to describe the gas' temperature since it's not inside the tank. Could you at least attach it to an outside wall of the tank and cover it with an insulating paste of some kind?
However, it's also true that the jaggedness is introduced by the pressure sensor... I really don't know what's going on and I'm running out of ideas.
Maybe some sort of resonance between the springs in the valve and the compressed gas? I'd be very surprised it's not dissipated quickly and also the period is too long. I'm throwing ideas to the wall and seeing what sticks at this point.

By the way, I didn't know you already tried my approach on post #88 so I did it too although I'm using the values from #73 where I assumed we're talking about absolute pressures.
In theory, the problem should be doable just with Pyromat because you can get the specific volume from the pressure and temperature but I got a different result compared to what was done in #73. I guess I'm not experienced enough with that library and I'm committing a mistake. I calculated the mass again using the gascompressibility library to find ##Z## (after a few awful unit conversions) and then I did get the same results as in post #73.
1724879077859.png


So the red one is the one I trust for now. I can't find what I did wrong with Pyromat because I told it to use the SI units.

I won't be able to invest more time in this for a few days. And even if I did I feel I have nothing else to add. I'll keep my eyes open in case the mysteries are solved somehow. Again, I think you'd get some actual temperature readings from inside the tank if you want to proceed with this method. If the manufacturer insists on it not being possible then you'll have to fight him or find an alternative method. Maybe even checking your pressure sensors to see if they're working correctly.

Here is the associated code and text file containing the pressure and temperature history.
NOTE: I once tried to copy code from the Forum to Spyder and it didn't work very well. If you have that issue, try pasting it on ChatGPT and it'll give you the code back in a format you can easily paste on Spyder.
[CODE lang="python" title="MassCalculation"]import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pyromat as pm
import gascompressibility as gc

pm.config['unit_pressure']='Pa'
pm.config['unit_temperature']='K'
pm.config['unit_mass']='kg'
pm.config['unit_volume']='m3'


co2 = pm.get('ig.CO2')
V = 0.05 # Tank's volume [m3]

# Specify the path to the file
# Pressure and temperature at a given time step by the sensors
file_path_1 = 'D:\Datos de Usuario\Descargas\SmallDataSet_Juanda.txt'
dataPTt = pd.read_csv(file_path_1, sep=';')

Time_sensor_array = dataPTt['Time [date, hour]'].to_numpy() #[date, hour]
Temperature_sensor_array = dataPTt['Temperature [K]'].to_numpy() #[K]
Pressure_sensor_array = dataPTt['Pressure [Pa]'].to_numpy() #[Pa]

def create_incrementing_array(input_array):
# Measure the size of the input array
size = len(input_array)

# Create a new array starting from 0 and incrementing by 2 until it's the same size as the input array
new_array = [i * 2 for i in range(size)]

return new_array

Time_sensor_array_2min = create_incrementing_array(Time_sensor_array)

# Using pyromat to find the specific volume [m3/kg]. It gives of a different result than in post #73 using compressibility (I thought it was absolute pressures)
Specific_volume_pyromat = co2.v(T=Temperature_sensor_array, p=Pressure_sensor_array) #[m3/kg]
# print(Specific_volume_pyromat[0])
m_pyromat = V/Specific_volume_pyromat


P_cr_CO2 = 7.39*10**6 # Critical pressure (top of the bell) [Pa]
T_cr_CO2 = 304.2 # Critical temperature (top of the bell) [K]
R = 188.9 # Gas constant [J/kgK]

P_R_CO2 = Pressure_sensor_array/P_cr_CO2
T_R_CO2 = Temperature_sensor_array/T_cr_CO2

Pressure_sensor_array_PSGI = (Pressure_sensor_array-(0.1*10**6))/6895
Temperature_sensor_array_F = (Temperature_sensor_array - 273.15) * 9 / 5 + 32

Z_0 = gc.calc_z(sg=1, P=Pressure_sensor_array_PSGI[0], T=Temperature_sensor_array_F[0], H2S=None, CO2=1, N2=None, Pr=P_R_CO2[0], Tr=T_R_CO2[0], pmodel='piper')
# print(Z_0)

def compute_compressibility_factors(pressure_array, temperature_array, Pr_array, Tr_array):
"""
Compute the compressibility factor Z for each coordinate in the input vectors.

Parameters:
- pressure_array: Array of pressure values in PSGI.
- temperature_array: Array of temperature values in Fahrenheit.
- Pr_array: Array of reduced pressures for each coordinate.
- Tr_array: Array of reduced temperatures for each coordinate.

Returns:
- A NumPy array of compressibility factors Z.
"""
# Compute Z for each coordinate and collect the results in a list
Z_list = [gc.calc_z(
sg=1,
P=pressure_array,
T=temperature_array,
H2S=None,
CO2=1,
N2=None,
Pr=Pr_array,
Tr=Tr_array,
pmodel='piper'
) for i in range(len(pressure_array))]

# Convert the list of Z values to a NumPy array
return np.array(Z_list)


Z_values = compute_compressibility_factors(
Pressure_sensor_array_PSGI,
Temperature_sensor_array_F,
P_R_CO2,
T_R_CO2
)

# print(Z_values[0])


# Using compressibility (import gascompressibility as gc) to find the specific volume [m3/kg]. I get the same as in #73 (assuming absolute pressures)
Specific_volume_compressibility = (Z_values*R*Temperature_sensor_array)/Pressure_sensor_array #[m3/kg]
m_gascompressibility = V/Specific_volume_compressibility
# print(m_gascompressibility[0])


# Ensure Time_sensor_array_2min has the same length as m_pyromat and m_gascompressibility
# If Time_sensor_array_2min does not match the lengths of m_pyromat and m_gascompressibility, adjust accordingly.

# Create the plot
plt.figure(figsize=(12, 6))

# Plot m_pyromat
plt.plot(Time_sensor_array_2min, m_pyromat, label='m_pyromat', color='blue', marker='o')

# Plot m_gascompressibility
plt.plot(Time_sensor_array_2min, m_gascompressibility, label='m_gascompressibility', color='red', marker='x')

# Add labels and title
plt.xlabel('Time (min)')
plt.ylabel('Mass (kg)')
plt.title('Comparison of Mass Calculated with pyromat and gascompressibility')
plt.legend()
plt.grid(True)

# Display the plot
plt.show()[/CODE]
 

Attachments

  • #101
Leopold89 said:
Oh, no. I plotted the gauge pressures. The absolute pressures are only in post #71.

I calculate precisely this in post #88. It is the bottom right graph.
Well, obviously there is something wrong because the mass should never increase.
 
  • #102
Juanda said:
:(
That could change the problem significantly. I did everything assuming we're talking about absolute pressures.
Not really. The difference between absolute pressure and gauge pressure is only 0.1 MPa.
 
  • #103
Probably does not matter, but:
Juanda said:
In summary, once the pressure tank goes beyond a certain pressure limit defined by the ambient pressure and the springs, the valve will open.
Umm, not quite. 🫨
Juanda said:
1724847507400.png

It is designed to close when the tank being filled reaches a set pressure.

Note that the outlet pressure, not the source-tank pressure, acts on the diaphragm, closing the valve.

("absperrventil", on the right, is the "shut-off valve"
'Zum Brenner' translates as 'to the burner'.)

Cheers,
Tom
 
  • #104
Chestermiller said:
Well, obviously there is something wrong because the mass should never increase.
Juanda got increasing masses, too.

Juanda said:
What's the meaning of ##r##?
View attachment 350506

I think I don't need it for the way I want to solve it but I'd like to know.
These are the differences between the vapour and liquid enthalpies.
 
  • #105
Tom.G said:
The way this thread is going, it looks like that 'future' is rapidly approaching!

Since the tanks are from an outside source, try getting a scale for one of the tanks and have a tank delivered to it (or moved to it). Maybe you will have to make room somewhere, or put it in an inconvenient spot. Try it out to see how well it works.

You may even be able to rent a scale for testing.

Your product supplier will likely know how heavy a full tank is, and maybe an empty one too.

If your tanks are currently placed on a stand of some sort, maybe putting some strain gauges on the stand would turn them into a scale.

The strain guages measure the deflection of the stand, which is proportional to the weight.

I have also seen tanks for several thousand gallons of product being weighed by using a balance. They rest on a platform (or stand) mounted on a long bar. The pivot point is close to the tank and the bar extends several feet past the pivot. Then enough standard weights are hung on the far end of the bar to balance the tank weight. Think 'balance scale'.

Cheers,
Tom
Can anybody recommend a proper scale? One which I can connect to a (Linux) computer, can recalibrate myself and is cheap?
 
  • #106
In the earlier analysis I presented, if we include heat transfer between the tank gas and the surroundings, we obtain:
$$(F_3V-F_4m)\frac{dT}{dt}=\frac{dm}{dt}-\frac{UA}{(h_v-F_2)}(T-T_s)$$where A is the surface area of the tank, U is the overall heat transfer coefficient, and ##T_s## is the temperature of the surroundings; t is time.
 
  • #107
Leopold89 said:
Can anybody recommend a proper scale? One which I can connect to a (Linux) computer, can recalibrate myself and is cheap?
Not at the moment, but if somebody knew what weight range you needed, they could likely do a Google search and find a few. As you are the only one here that would have such information, who do you think would be the most appropriate to do the search? (hint, hint)
 
  • #108
I have now finally completed the computation with the new model by Chestermiller. As I could not find a clever substitution to seperate this differential equation into two seperate, I instead implemented this equation as minimization problem with the mass and temperature time serieses as optimization variables. This had the unfortunate consequence that I could not compute the change over a whole day in a timely fashion. Now I had to reduce the time series to the first 200 minutes. Over the next days I will also try to complete the rest of the day.
 

Attachments

  • newGasMass.png
    newGasMass.png
    17.6 KB · Views: 53
  • #109
Leopold89 said:
I have now finally completed the computation with the new model by Chestermiller. As I could not find a clever substitution to seperate this differential equation into two seperate, I instead implemented this equation as minimization problem with the mass and temperature time serieses as optimization variables. This had the unfortunate consequence that I could not compute the change over a whole day in a timely fashion. Now I had to reduce the time series to the first 200 minutes. Over the next days I will also try to complete the rest of the day.

But you're still seeing mass increments. Although the overall trend seems more realistic than previous results.
Maybe the sensors are not measuring correctly sometimes when things are happening too fast.
 
  • #110
Juanda said:
But you're still seeing mass increments. Although the overall trend seems more realistic than previous results.
Maybe the sensors are not measuring correctly sometimes when things are happening too fast.
Maybe it is not that realistic, because the gas temperature is essentially constant compared to room temperature, but the gauge pressure still rises, likely even more than justified, if you look at the plot in post #71. But I also had to adapt Chestermiller's formula a bit, because I do not have liquid phase under these conditions. I started with ##U=mu_V \Rightarrow \mathrm{d} U = m\mathrm{d}u_V + u_V\mathrm{d}m## and inserted it into ##\mathrm{d}U=h_V\mathrm{d}m - \alpha A\Delta T## and got ##m(\frac{\mathrm{d}u}{\mathrm{d} p} \dot p + \frac{\mathrm{d}u}{\mathrm{d}T}\dot T) + \alpha A(\dot T - \dot T_s) = (h-u)\dot m##. Maybe my derivation is wrong.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
8
Views
1K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
35
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K