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.
  • #61
Leopold89 said:
Volume of the tank is 50 liters, the outer diameter is 229 mm and length is 1655 mm. No sketch available. Why is this important?

I have tried to compute the differential equation by @Juanda in the attached image, but for a pure CO##_2## gas: ##\dot m = \frac{\dot q -c_V \dot T}{c_VT - h_\mathrm{out} -q}m##
It starts out well, but somewhere seems to be an error and the mass jumps around 0. What seems strange to me is that the specific enthalpies and internal energies are below zero. I get those from the Python package pyromat.

Edit: Found the implementation error. The ode should now be computed correctly, but the result is still implausible.
What are your initial conditions for the CO2 case you ran?
Temperature
Pressure
Mass
 
Science news on Phys.org
  • #62
Tom.G said:
The other implementation is feed the thermocouple thru the top of the tank using a gland fitting. This has the advantage that you can place the thermo-couple at various adjustable positions within the tank.
You gave a lot of input. I don't understand how exactly I can insert a thermocouple into the tank, because as I understand it I would need an empty tank. But I get full tanks from the manufacturer and did not see him offer these thermocouples.
Chestermiller said:
What are your initial conditions for the CO2 case you ran?
Temperature
Pressure
Mass
I first computed the specific heat from the change in specific internal energy and ##h_\mathrm{out}## from the change in specific enthalpies ##h_{i-1} -h_{i}##, so I got a n-1 long time series. Then I passed on the temperature and pressure without the first entry and calculated the initial mass with the equation for ideal gases given the second temperature-pressure pair in the time series.
 
Last edited:
  • #63
Leopold89 said:
You gave a lot of input. I don't understand how exactly I can insert a thermocouple into the tank, because as I understand it I would need an empty tank. But I get full tanks from the manufacturer and did not see him offer these thermocouples.

I first computed the specific heat from the change in specific internal energy and ##h_\mathrm{out}## from the change in specific enthalpies ##h_{i-1} -h_{i}##, so I got a n-1 long time series. Then I passed on the temperature and pressure without the first entry and calculated the initial mass with the equation for ideal gases given the second temperature-pressure pair in the time series.
All I'm asking for are the initial conditions in the tank (initial parameter values).
 
  • #64
Chestermiller said:
All I'm asking for are the initial conditions in the tank (initial parameter values).
##T=297.138375\mathrm{K}, p=5438467.5\mathrm{Pa}, m_0= 4.84398743373488\mathrm{kg}##
 
  • #65
Leopold89 said:
##T=297.138375\mathrm{K}, p=5438467.5\mathrm{Pa}, m_0= 4.84398743373488\mathrm{kg}##
At that temperature, the equilibrium vapor pressure of CO2 is 6.3 MPa, not 5.4 MPa. Are you saying that, initially, you have all vapor below the saturation pressure?
 
  • #66
Chestermiller said:
At that temperature, the equilibrium vapor pressure of CO2 is 6.3 MPa, not 5.4 MPa. Are you saying that, initially, you have all vapor below the saturation pressure?
Leopold89 said:
Not in all tanks, but in one I believe yes. For most chemicals I did a mistake like for CO2, where I followed Wiki, where they said you have liquid carbondioxide above 5.2bar and below 31°C, but after Chestermiller's explanation, I have corrected my mistake.
Yes. After your explanation I checked my data over the last three months and found that for example the CO##_2## tank has a maximum pressure of 6.1MPa.
 
  • #67
Leopold89 said:
4.84398743373488 kg
If you need to know the mass to a picogram, we can stop right now. Not going to happen.
 
  • #68
Leopold89 said:
Yes. After your explanation I checked my data over the last three months and found that for example the CO##_2## tank has a maximum pressure of 6.1MPa.
297 K and 5.4 MPa are inconsistent with 4.84 kg iii a 20 liter tank.

You initially have a superheated vapor, and the gas in the tank decreases in temperature and pressure isentropically as the tank empties until you hit the equilibbium bell. At that point, a liquid phase begins to form.
 
  • #69
Vanadium 50 said:
If you need to know the mass to a picogram, we can stop right now. Not going to happen.
I was just copy-pasting python output. It is not meant as desired precision.
Chestermiller said:
297 K and 5.4 MPa are inconsistent with 4.84 kg iii a 20 liter tank.
Leopold89 said:
Volume of the tank is 50 liters, the outer diameter is 229 mm and length is 1655 mm.
 
  • #70
Leopold89 said:
I was just copy-pasting python output. It is not meant as desired precision.
4.84 kg is not consistent with 50 liters, 297K and 5.84 MPa either.
 
  • #71
I tried something new and corrected the measured pressure of the CO##_2## tank with the atmospheric pressure. I expected to see a saw like pattern and hopefully small peaks dissapear, but got the plots attached here. The x axis is the Unix epoch time and the y axis is the difference between tank pressure and atmospheric pressure. Unfortunately the atmospheric pressure sensor is some 300 meters apart from the tanks.
I am rather discouraged, because we see a rising pressure over a few days and over three months the pressure difference never gets to 0, where I expect a change of tanks to have happened.

Maybe the whole experimental setup is faulty and needs revisiting?
 

Attachments

  • PressureDifference.png
    PressureDifference.png
    23.5 KB · Views: 68
  • PressureDifferenceZoom.png
    PressureDifferenceZoom.png
    11.8 KB · Views: 58
  • #73
Leopold89 said:
##T=297.138375\mathrm{K}, p=5438467.5\mathrm{Pa}, m_0= 4.84398743373488\mathrm{kg}##
Leopold89 said:
Yes. After your explanation (from ChesterMiller) I checked my data over the last three months and found that for example the CO##_2## tank has a maximum pressure of 6.1MPa.


From this data, we have established that the mass is initially all in the gaseous state according to this table of saturated ##\mathrm{CO_2}## because at 24ºC (297 K) you're below the saturation pressure.
1724691853391.png


I'm not yet ready to study the evolution of the system as you discharge the content of the tank but I think I can calculate the initial mass from the experimental data you have.
Leopold89 said:
I'm using a different approach to the one you used there and got a different result too.

Using the ideal gas law being so close to the saturation bell doesn't give accurate results but there is an adapted formula for that.

1724692153792.png


1724692163335.png

1724692170159.png


The critical-point of ##\mathrm{CO_2}## is ##P_{cr}=7.39 \ \mathrm{MPa}## and ##T_{cr}=304.2 \ \mathrm{K}##.
1724692790448.png


Therefore, from your data, the reduced pressure and reduced temperature are:
$$T_R = \frac{T}{T_{cr}}=\frac{297.1}{304.2}=0.98$$
$$P_R = \frac{P}{P_{cr}}=\frac{5.43}{7.39}=0.75$$
So your compressibility factor ##Z## should be around ##Z=0.64##.
1724693504711.png


From the definition of ##Z##, it is possible to obtain the specific volume of the gas.
(Using SI units whenever units don't cancel)
$$Z = \frac{Pv}{RT} \rightarrow v = \frac{ZRT}{P}=\frac{0.64*188.9*297.1}{5.43*10^6}=0.006615 \ \mathrm{m^3/kg}$$
Lastly, knowing the tank's volume is ##V = 0.05 \ \mathrm{m^3}## we can find the actual mass.
$$v=V/m \rightarrow m=V/v=\frac{0.05}{0.006615}=7.56 \ \mathrm{kg}$$
I'm not sure if it's my first or second time in my life doing these calculations but I followed the book "Thermodynamics An Engineering Approach" by the letter so I believe it'd be OK. Feel free to point out any errors or comments.
 
Last edited:
  • #74
Juanda said:
I'm not yet ready to study the evolution of the system as you discharge the content of the tank but I think I can calculate the initial mass from the experimental data you have.
As long as the content inside the tank is entirely gas, the approach from #73 should be valid—assuming what I wrote there is correct. Since you have pressure and temperature data from your sensors, you have all the information needed to determine the mass, which I believe is your primary concern. If you can incorporate the compressibility factor into your Python code, you'll be able to calculate the mass at each time step.
It would be helpful to add checks in your code to ensure that, as it runs, it verifies whether you're inside or outside the saturation bell. This way, you'll know if you're using the correct set of equations. Since the starting point doesn't have enough pressure to condense the gas, and you're releasing pressure over time, I believe you'll be able to use these equations most of the time because, once thermal equilibrium is reached, the content will likely be entirely gaseous.

I believe those green curves defining ##Z## correspond to a 3D surface ##Z(P, T)##. If you can find this surface, it should be fairly straightforward to add it to the code. If not, you could try approximating it with the level of detail necessary for your application.
 

Attachments

  • 1724696089229.png
    1724696089229.png
    4.2 KB · Views: 43
  • 1724696109964.png
    1724696109964.png
    4.9 KB · Views: 44
  • #75
Juanda said:
From this data, we have established that the mass is initially all in the gaseous state according to this table of saturated ##\mathrm{CO_2}## because at 24ºC (297 K) you're below the saturation pressure.
View attachment 350427

I'm not yet ready to study the evolution of the system as you discharge the content of the tank but I think I can calculate the initial mass from the experimental data you have.

I'm using a different approach to the one you used there and got a different result too.

Using the ideal gas law being so close to the saturation bell doesn't give accurate results but there is an adapted formula for that.

View attachment 350428

View attachment 350429
View attachment 350430

The critical-point of ##\mathrm{CO_2}## is ##P_{cr}=7.39 \ \mathrm{MPa}## and ##T_{cr}=304.2 \ \mathrm{K}##.
View attachment 350431

Therefore, from your data, the reduced pressure and reduced temperature are:
$$T_R = \frac{T}{T_cr}=\frac{297.1}{304.2}=0.98$$
$$P_R = \frac{P}{P_cr}=\frac{5.43}{7.39}=0.75$$
So your compressibility factor ##Z## should be around ##Z=0.64##.
View attachment 350432

From the definition of ##Z##, it is possible to obtain the specific volume of the gas.
(Using SI units whenever units don't cancel)
$$Z = \frac{Pv}{RT} \rightarrow v = \frac{ZRT}{P}=\frac{0.64*188.9*297.1}{5.43*10^6}=0.006615 \ \mathrm{m^3/kg}$$
Lastly, knowing the tank's volume is ##V = 0.05 \ \mathrm{m^3}## we can find the actual mass.
$$v=V/m \rightarrow m=V/v=\frac{0.05}{0.006615}=7.56 \ \mathrm{kg}$$
I'm not sure if it's my first or second time in my life doing these calculations but I followed the book "Thermodynamics An Engineering Approach" by the letter so I believe it'd be OK. Feel free to point out any errors or comments.
This is much better. Another approach would be to use the conditions in the table that are close to the initial temperature and pressure to estimate z: T=297 K, P=6.29 MPa, v=0.004327 m^3/kg=0.00019039 m^3/mole
$$z=\frac{(6290000)(0.00019039)}{(8.314)(297)}=0.49$$
 
  • #76
Like I said earlier, the vapor for the initial condition of CO2 is superheated. Therefore, as the tank begins to expel gas, the gas remaining in the tank will experience an isentropic expansion until the 2 phase envelope is readhed. Moran et al, Fundamentals of Engineering Thermodynamics, presents a pressure-enthalpy diagram for CO2 that can be used to follow the isentropic line down to the 2 phase envelope.
 
  • #77
Chestermiller said:
Like I said earlier, the vapor for the initial condition of CO2 is superheated. Therefore, as the tank begins to expel gas, the gas remaining in the tank will experience an isentropic expansion until the 2 phase envelope is readhed. Moran et al, Fundamentals of Engineering Thermodynamics, presents a pressure-enthalpy diagram for CO2 that can be used to follow the isentropic line down to the 2 phase envelope.

Is this the diagram you're referring to? It says R744 but that should be the same as CO2.
1724710325317.png


I'm still unsure of how to solve it but, from what you said, I can find the starting point from the known pressure and temperature.
Once it starts discharging, follow the isentropic line reducing pressure up to the new point read by the sensor.
From that, it'd be possible to know the vapor quality right after the release so we can find the portion of liquid and volume inside the tank. The densities of both are known since it's saturated and pressure and temperature are known so it's possible to calculate the mass.
During that process, I think I'd ignore the temperature sensor. We're already assuming it's got the same entropy so the temperature data is not necessary. My reason for ignoring it is its readings are indirect. I'd trust it when it has enough time to reach thermal equilibrium but not in cases like this.

1724711055788.png


We assumed an isentropic expansion which I believe also means it's adiabatic. It can be assumed that the heat input is not too significant during the discharging process. However, once the release is done and time passes, the tank will keep absorbing heat from the room because it's significantly cooler. As it absorbs heat, all the content will be transformed into gas now that the pressure is lower so it'd be possible to calculate the mass again but using the compressibility factor as mentioned in the previous post.

All this process (this and the procedure from post #73) completely bypasses the need for differential equations. However, to calculate everything in your Python code from your sensor data you'd need to add the functions from the diagrams we used. That is:
  • ##Z(P, T)##
  • All the properties that define the p-h diagram with the isolines.




PS.
In a closed system with a known mixture of saturated liquid and vapor at a known fixed volume, if I add a known amount of heat, what process does the mixture undergo? It can't be isochoric because, for that to happen, the system would need to be 100% vapor from the start. This detail is irrelevant for this exercise because sensors are available to obtain the necessary data (P and T). However, could I determine the path the mixture follows within the bell curve while heat is added at a fixed volume?
Perhaps I should start a new discussion to explore this point in more detail, rather than complicating this one further.
 
  • #78
Juanda said:
Before diving into thermodynamic properties and equations, would it be possible just to weigh the loaded and unloaded tank?

Leopold89 said:
But I get full tanks from the manufacturer
Leopold89 said:
In theory at some point in the future one could measure these masses, but not in the short term.
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
 
  • #79
Juanda said:
Is this the diagram you're referring to?
Yes.
Juanda said:
It says R744 but that should be the same as CO2.
View attachment 350443

I'm still unsure of how to solve it but, from what you said, I can find the starting point from the known pressure and temperature.
Once it starts discharging, follow the isentropic line reducing pressure up to the new point read by the sensor.
Once the tank contents reaches the 2 phase region, the behavior of the contents remaining in the tank is no longer isentropic. This is because pure vapor is being removed from the valve, rather than a representative mixture of liquid and vapor from the tank. That was the idea of the analysis I did.
 
  • #80
Juanda said:
Is this the diagram you're referring to? It says R744 but that should be the same as CO2.
View attachment 350443

I'm still unsure of how to solve it but, from what you said, I can find the starting point from the known pressure and temperature.
Once it starts discharging, follow the isentropic line reducing pressure up to the new point read by the sensor.
From that, it'd be possible to know the vapor quality right after the release so we can find the portion of liquid and volume inside the tank. The densities of both are known since it's saturated and pressure and temperature are known so it's possible to calculate the mass.
During that process, I think I'd ignore the temperature sensor. We're already assuming it's got the same entropy so the temperature data is not necessary. My reason for ignoring it is its readings are indirect. I'd trust it when it has enough time to reach thermal equilibrium but not in cases like this.

View attachment 350445

We assumed an isentropic expansion which I believe also means it's adiabatic. It can be assumed that the heat input is not too significant during the discharging process. However, once the release is done and time passes, the tank will keep absorbing heat from the room because it's significantly cooler. As it absorbs heat, all the content will be transformed into gas now that the pressure is lower so it'd be possible to calculate the mass again but using the compressibility factor as mentioned in the previous post.

All this process (this and the procedure from post #73) completely bypasses the need for differential equations. However, to calculate everything in your Python code from your sensor data you'd need to add the functions from the diagrams we used. That is:
  • ##Z(P, T)##
  • All the properties that define the p-h diagram with the isolines.




PS.
In a closed system with a known mixture of saturated liquid and vapor at a known fixed volume, if I add a known amount of heat, what process does the mixture undergo? It can't be isochoric because, for that to happen, the system would need to be 100% vapor from the start. This detail is irrelevant for this exercise because sensors are available to obtain the necessary data (P and T). However, could I determine the path the mixture follows within the bell curve while heat is added at a fixed volume?
Perhaps I should start a new discussion to explore this point in more detail, rather than complicating this one further.
I used the Python package gascompressibility for the compressibility factor and got ~0.61 for the initial values. I calculated the spezific enthropy based on the initial values and then assumed it stayed constant and then calculated the temperature based on pressure and spezific enthropy, all using pyromat. From this calculated temperature I computed the compressibility and used the formula in post #73. In the below plots you see the result in the bottom right corner. Bottom left is the ODE solution with different initial mass based on my 0.61 compressibility. Changing the initial mass manually to the ~7.6kg does not change the shape and just shifts the plot down. The middle graph on the right is based on this. The middle graph on the left is the calculated temperature with constant spezific enthropy. I also checked for the liquid phase with interpolation and can confirm that in this data set no liquid is formed.
We can see that the temperature based on constant spezific enthropy is larger than room temperature T_T
[CODE lang="python" title="Python code for temperature calculation"]pyromat.config['unit_pressure']='Pa'
pyromat.config['unit_temperature']='K'
co2 = pyromat.get('ig.CO2')
isentropicTemperature = co2.T(p=pressureData, s=co2.s(T=temperatureData[0], p=pressureData[0]))[/CODE]
 

Attachments

  • IsentropicApproach.png
    IsentropicApproach.png
    28.8 KB · Views: 52
Last edited:
  • #81
Leopold89 said:
I used the Python package gascompressibility for the compressibility factor and got ~0.61 for the initial values.
I guess that small difference is acceptable. I was eyeballing the values from the diagram. Python takes the exact values from the data.

Leopold89 said:
I calculated the spezific enthropy based on the initial values and then assumed it stayed constant and then calculated the temperature based on pressure and spezific enthropy, all using pyromat.
Did you need to calculate the entropy? I would have expected that value to be taken from a table. Or taken from a Python library just like ##Z##.

Secondly, did you read Chester's input on #79? What I did to describe the expansion of the content of the tank is only valid when we're outside the bell and it seems that you'd go into it during the isentropic expansion.
Chestermiller said:
Once the tank contents reaches the 2 phase region, the behavior of the contents remaining in the tank is no longer isentropic. This is because pure vapor is being removed from the valve, rather than a representative mixture of liquid and vapor from the tank. That was the idea of the analysis I did.

However, I still think you'd be able to calculate the mass as thermal equilibrium is reached as explained in #77.
Juanda said:
We assumed an isentropic expansion which I believe also means it's adiabatic. It can be assumed that the heat input is not too significant during the discharging process. However, once the release is done and time passes, the tank will keep absorbing heat from the room because it's significantly cooler. As it absorbs heat, all the content will be transformed into gas now that the pressure is lower so it'd be possible to calculate the mass again but using the compressibility factor as mentioned in the previous post.
From the equations I proposed you may not be able to calculate the mass when it's inside the bell as explained by Chester. You'd need the equations he proposed before but I don't understand them yet. I need to invest more time in them.

However, as soon as the content fully evaporates (which should do so as it absorbs heat from the ambient), you can repeat the process you did to find the initial mass when it was all vapor.

In summary, assuming that
  • you're mainly interested in the mass content of the tank and
  • the elapsed time between discharges is long enough for the content to evaporate completely
you could ditch the differential equations and calculate the mass of the tank using the compressibility factor from the readings produced by your sensors. The most accurate mass readings would be done right before the discharges since that's when the tank has had the most time to achieve thermal equilibrium so you can be sure the content is 100% vapor.
You wouldn't be able to have nice plots regarding how the mass content varies continuously with time but that data is irrelevant in the first place, right?
Your mass diagram would look something like this:
1724760590695.png


  1. The initial point we have established is known and it's all gas.
  2. Assuming 1 was already in thermal equilibrium with the room, from 1→2 nothing happens. If it wasn't in thermal equilibrium, we could have calculated the mass at 2 where, since enough time to evaporate completely has elapsed, the compressibility can be used. Since mass is conserved between 1 and 2, the mass is the same.
  3. The process 2→3 is a discharge. Hard stuff to do. At 3 there most likely is a mix of liquid and vapor within the tank due to the cooling effect of the isentropic expansion. I'll choose to ignore that process because I don't have the knowledge to tackle it yet. The important point to notice is from 3→4 the mass is preserved. Remember, mass is what we care about due to how the problem was originally defined and reiterated during the thread.
  4. The mass can be calculated at 4 because enough time has passed for the tank to reach thermal equilibrium at room temperature. Or at least, it has absorbed enough heat to completely evaporate its content.
  5. The process 4→5 is an intake. Since we have established the content at 4 is all gas, I believe this process can be assumed to be an isentropic compression of the previous content. However, that's not relevant to calculate the mass which is what we care about. At 5, the content should all be gas so you can use the previous equation again.
  6. The valves are closed from 5→6 so mass is preserved. Still, you can calculate the mass again to compare it with 5 because it's all gas just in case to check your numbers.
Remember, what I'm proposing should work because of the starting conditions you mentioned about your CO2 tank. Even in its historical peak pressure, at thermal equilibrium with the room, it's all gas. As long as you're below that, this method could be a good enough approximation for the mass content of the tank.
 
  • #82
Juanda said:
Did you need to calculate the entropy? I would have expected that value to be taken from a table. Or taken from a Python library just like Z.
As I wrote, I used the pyromat library for this.

Juanda said:
Secondly, did you read Chester's input on #79? What I did to describe the expansion of the content of the tank is only valid when we're outside the bell and it seems that you'd go into it during the isentropic expansion.
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.
 

Attachments

  • #83
Juanda said:
The most accurate mass readings would be done right before the discharges since that's when the tank has had the most time to achieve thermal equilibrium so you can be sure the content is 100% vapor.
That is the problem. I tried to find the time frames, where no discharge was happening by subtracting atmospheric pressure and gas pressure, but I did not get time frames with constant pressure.
 
  • #84
Leopold89 said:
As I wrote, I used the pyromat library for this.
All right. You said calculate so I thought you were getting the value through other means.

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.
I tried plotting some values from the document you provided and it seems accurate when I compare it to plots from the internet.
1724763901967.png


1724764011196.png


Where did you get that table?


Leopold89 said:
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.
Your sensors are reading the pressure inside the tank. Why are you trusting the temperature sensors in each time step instead? Due to your set up, they are indirect measurements of the tank.
I would rather trust the pressure sensors and only trust the temperature sensors when enough time has passed between discharges.
Also, are you saying your code doesn't register you're going inside the bell? I find it surprising because the initial conditions were very close to the bell but if you're always outside it makes the calculations simpler. You can use ##Z## all the way.
 

Attachments

  • 1724763861517.png
    1724763861517.png
    5.8 KB · Views: 58
  • #85
Leopold89 said:
That is the problem. I tried to find the time frames, where no discharge was happening by subtracting atmospheric pressure and gas pressure, but I did not get time frames with constant pressure.
How is the valve actuated? If it's electronically actuated, you can add the information to the time history.
Otherwise, even if you're not seeing when pressure is constant, you're seeing sudden peaks in pressure which should correspond to the charges and discharges. Try calculating the derivative ##\frac{dP}{dt}## and when it goes beyond a certain threshold you can assume it's a discharge/charge process. You'll have to tweak that threshold for both processes but it might work. Hopefully, the changes introduced by the valves admitting or outputting gas will be faster than the changes introduced by the system trying to reach equilibrium once the valves are closed.

If you're not seeing time intervals where pressure and temperature are constant it means the content has not had enough time to reach equilibrium. That's all right because we don't need it to be in equilibrium for our calculations, we just need it to be 100% gas.

I think the main thing you're missing is a reliable temperature sensor inside the tank.
 
  • #86
When you have 2 phases present inside, knowledge of the inside pressure tells you the inside temperature since the heat transfer is slow and the contents are thus very close to thermodynamic equilibrium. You can then determine the mass of CO2 in the tank using the saturated CO2 tables which give the liquid and vapor specific volumes at each saturation condition.

I have trouble understanding how the mass of CO2 inside the tank can increase if the valve only discharges mass.
 
  • #87
Juanda said:
Why are you trusting the temperature sensors in each time step instead?
First we assumed that the temperatures will get in an equilibrium fast and now with the isentropic approach I used calculated temperature values.
Juanda said:
How is the valve actuated? If it's electronically actuated, you can add the information to the time history.
Otherwise, even if you're not seeing when pressure is constant, you're seeing sudden peaks in pressure which should correspond to the charges and discharges. Try calculating the derivative ##\frac{dP}{dt}## and when it goes beyond a certain threshold you can assume it's a discharge/charge process. You'll have to tweak that threshold for both processes but it might work. Hopefully, the changes introduced by the valves admitting or outputting gas will be faster than the changes introduced by the system trying to reach equilibrium once the valves are closed.

If you're not seeing time intervals where pressure and temperature are constant it means the content has not had enough time to reach equilibrium. That's all right because we don't need it to be in equilibrium for our calculations, we just need it to be 100% gas.

I think the main thing you're missing is a reliable temperature sensor inside the tank.
The valve is actuated mechanically. And the sudden, small peaks do not correspond to discharges, because we only discharge around two times a day, I just learned. (BTW the tanks do not get charged only discharged)
I also asked the manufacturer and it is not possible to get a temperature sensor inside the tank.
Edit:
"Where did you get that table?"
I copied it from an old German textbook.
 
  • #88
Chestermiller said:
When you have 2 phases present inside, knowledge of the inside pressure tells you the inside temperature since the heat transfer is slow and the contents are thus very close to thermodynamic equilibrium. You can then determine the mass of CO2 in the tank using the saturated CO2 tables which give the liquid and vapor specific volumes at each saturation condition.

I have trouble understanding how the mass of CO2 inside the tank can increase if the valve only discharges mass.
Maybe some implementation error. I post my code, too:
[CODE lang="python" title="Van-der-Waals-equation"]def vanDerWaals_a(inGas):
return 27/64.0*math.pow(constants.R*criticalTemperature[inGas], 2)/criticalPressure[inGas]

def vanDerWaals_b(inGas):
return constants.R*criticalTemperature[inGas]/8.0/criticalPressure[inGas]

def solveCubic(a, b, c, d):
delta0 = b*b-3*a*c
delta1 = 2*math.pow(b, 3)-9*a*b*c+27*a*a*d
if delta0 == 0 and delta1 == 0:
return -b/3.0/a
if delta0 == 0:
tempResult = delta1**(1/3.0)
else:
tempResult = ((delta1+cmath.sqrt(delta1*delta1 - 4*math.pow(delta0,3)))/2.0)**(1/3.0)
rotAngle = (-1+cmath.sqrt(-3))/2.0
result = []
for i in range(0,2):
result.append(-1/3.0/a*(b+(rotAngle**i) *tempResult + delta0/(rotAngle**i)/tempResult))
return result

def calcParticles(tData, pData, fileName, volume):
n_samples = len(tData)
gasData=readSteamTable(fileName)
pLimit = pchip_interpolate(gasData.t, gasData.p, tData)*bar
adjustedN=np.zeros(n_samples)
a = vanDerWaals_a(Gas.CO2)
b = vanDerWaals_b(Gas.CO2)
for i in range(0,n_samples):
if pData<pLimit:
tempResult = solveCubic(1, -volume/b, (pData+constants.R*tData/b)*volume*volume/a, -pData*math.pow(volume, 3)/a/b)
if checkRoots(tempResult):
for root in tempResult:
if abs(root.imag)<1e-12 and root.real>0:
adjustedN=root
else:
sys.exit()
else:
sys.exit()
return adjustedN[/CODE]
This result is multiplied with ##0.0440098\frac{\mathrm{kg}}{\mathrm{mol}}##.

[CODE lang="python" title="Compressibility Approach"]def CalcCompressibility(tData, pData):
z=[]
gasData=readSteamTable("CO2_table.txt")
pLimit = pchip_interpolate(gasData.t, gasData.p, tData)*bar
for i in range(0,len(tData)):
if pData<pLimit:
z.append(gc.calc_z(T=kelvinToFahrenheit(tData), P=pData*0.0001450377, Tr=tData/criticalTemperature[Gas.CO2], Pr=pData/criticalPressure[Gas.CO2]))
else:
sys.exit()
return z

isentropicTemperature = co2.T(p=pressureData, s=co2.s(T=temperatureData[0], p=pressureData[0]))
masses = []
for i in range(0,len(z)):
masses.append(volume/(z*constants.R*isentropicTemperature/pressureData)*0.0440098)[/CODE]

And lastly:
[CODE lang="python" title="ODE"]def massDerivative(y, t, temperature, temperatureDot, pressure, hData, qData, qDotData, timeData):
pyromat.config['unit_pressure']='Pa'
pyromat.config['unit_temperature']='K'
co2 = pyromat.get('ig.CO2')
index = 0
for i in range(0,len(timeData)):
if t<timeData:
index = i
break
specHeatCap = co2.cv(T=temperature[index], p=pressure[index])
nom = (qDotData[index] - specHeatCap*temperatureDot[index])*y
denom = specHeatCap * temperature[index] - hData[index] - qData[index]
result = nom/denom
return result

uData = co2.e(T=temperatureData, p=pressureData)
hData = co2.h(T=temperatureData, p=pressureData)
timeData = np.linspace(0, 2*(len(temperatureData)-1), len(temperatureData))
hOutData = []
qData = []
for i in range(1, len(uData)):
qData.append(uData[i-1] - uData)
hOutData.append(hData[i-1] - hData)
qDotData = np.gradient(qData, timeData[1:])
tDotData = np.gradient(temperatureData, timeData)
initialMass=0.0440098*volume/(z[1]*constants.R*isentropicTemperature[1]/pressureData[1])
sol = odeint(massDerivative, initialMass, timeData[1:], tfirst = False, args=(temperatureData[1:], tDotData[1:], pressureData[1:], hOutData, qData, qDotData, timeData[1:]))
[/CODE]
Here the z[1] is the same as in the previous code block.

Edit: I forgot to use the isentropic temperature in the ODE approach but now attached the version using calculated temperature.
 

Attachments

  • IsentropicApproach2.png
    IsentropicApproach2.png
    23.5 KB · Views: 75
  • #89
Just to be clear, when you post these graphs, temperature and pressure are calculated from initial conditions or are they the values straight from your sensors?
1724789265259.png

(By the way, you'd be able to copy-paste pictures instead of attaching them if that's more comfortable for you)

You mentioned you have sensors for pressure and temperature. (Even if the temperature is not really from inside the tank, we can address that later)
Can you upload those graphs if you haven't done it already? Because I really can't understand how it's possible that, even if you're ONLY discharging from the tank, we're seeing how pressure rises. Nor I can understand where the jagginess of the curve comes from. I'd expect sudden changes when the valve is open and the smooth behavior towards the new equilibrium point. Could it be electrical noise?
How long does the discharge take? Could you plot the temperature and pressure readings for a couple of days or so? It's to try to guess where are those 4 discharges (2 discharges/day) that you mentioned.
Can you add units to the horizontal axis?
 
  • #90
Juanda said:
Just to be clear, when you post these graphs, temperature and pressure are calculated from initial conditions or are they the values straight from your sensors?
View attachment 350481
(By the way, you'd be able to copy-paste pictures instead of attaching them if that's more comfortable for you)

You mentioned you have sensors for pressure and temperature. (Even if the temperature is not really from inside the tank, we can address that later)
Can you upload those graphs if you haven't done it already? Because I really can't understand how it's possible that, even if you're ONLY discharging from the tank, we're seeing how pressure rises. Nor I can understand where the jagginess of the curve comes from. I'd expect sudden changes when the valve is open and the smooth behavior towards the new equilibrium point. Could it be electrical noise?
How long does the discharge take? Could you plot the temperature and pressure readings for a couple of days or so? It's to try to guess where are those 4 discharges (2 discharges/day) that you mentioned.
Can you add units to the horizontal axis?
IsentropicApproach3.png

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.
 
Last edited:

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