Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather Balloon script crash #654

Open
bcoconni opened this issue Jun 11, 2022 Discussed in #643 · 5 comments
Open

Weather Balloon script crash #654

bcoconni opened this issue Jun 11, 2022 Discussed in #643 · 5 comments
Labels

Comments

@bcoconni
Copy link
Member

bcoconni commented Jun 11, 2022

Discussed in #643

Originally posted by @dpculp June 5, 2022
When executing the script weather-balloon.xml as supplied by the repo I get a core dump "Floating point exception" after about 4980 seconds of virtual time. This is at the point in the flight around 92K feet where the balloon is deflating and beginning descent.

I changed the termination event to stop execution at 80K feet of altitude and the script ran perfectly.

It seems the transition from ascent to descent is not working presently in the weather balloon (gas cell) model. I'll investigate further.

@bcoconni bcoconni added the bug label Jun 11, 2022
@bcoconni
Copy link
Member Author

bcoconni commented Jun 12, 2022

The program crashes at src/models/FGGasCell.cpp line 323 due a division by zero because GasVolume is 0.0.

// First compute the difference in pressure between the gas in the
// cell and the air above it.
// FixMe: CellHeight should depend on current volume.
const double CellHeight = 2 * Zradius + Zwidth; // [ft]
const double GasMass = Contents * M_gas(); // [slug]
const double GasVolume = Contents * R * Temperature / Pressure; // [ft^3]
const double GasDensity = GasMass / GasVolume;
const double DeltaPressure =
Pressure + CellHeight * g * (AirDensity - GasDensity) - AirPressure;
const double VolumeValved =
ValveOpen * ValveCoefficient * DeltaPressure * dt;
Contents =
max(0.0, Contents - Pressure * VolumeValved / (R * Temperature));
}

By setting a minimum value of 1E-8 for Contents the crash is fixed:

    Contents =
-      max(0.0, Contents - Pressure * VolumeValved / (R * Temperature));
+      max(1E-8, Contents - Pressure * VolumeValved / (R * Temperature));

@bcoconni
Copy link
Member Author

Setting the minimum content to 10-8 is a workaround to avoid the crash. The mere fact that this formula can empty the balloon until its interior volume is zero makes it questionable.

@andgi I know you wrote a disclaimer in the code about the formula you used to compute the valved flow of a balloon, but I am surprised that the weight of the column of air CellHeight * g * (AirDensity - GasDensity) is involved in such a formula ?

In addition, I have the feeling that the sign of AirDensity - GasDensity is incorrect: the air column weight should push the ambient air inside the balloon because the ambient air is heavier:

$$P_{air}=P_0+\rho_{air}gh$$

$$P_{gas}=P_0+\rho_{gas}gh$$

since $\rho_{air}>\rho_{gas}$ then $P_{air}>P_{gas}$ whatever $P_0$ is. As the air moves from high pressures to low pressures, this formula should result in air moving from the outside to the inside of the balloon which is exactly the opposite of what the valve is expected to do.

@bcoconni
Copy link
Member Author

bcoconni commented Jun 12, 2022

Actually I am now certain the formula is wrong because AirDensity should have the same sign than AirPressure in the code below:

const double DeltaPressure =
Pressure + CellHeight * g * (AirDensity - GasDensity) - AirPressure;

Indeed the computation of $\Delta P$ is subtracting two $P+\rho gh$:

$$P_{air}=P^0_{air}+\rho_{air}gh$$

$$P_{gas}=P^0_{gas}+\rho_{gas}gh$$

which gives:

$$\Delta P=P_{gas}-P_{air}=P^0_{gas}+\rho_{gas}gh-P^0_{air}-\rho_{air}gh$$

$$\Delta P=(P^0_{gas}-P^0_{air})+(\rho_{gas}-\rho_{air})gh$$

So the air quantities $P^0_{air}$ and $\rho_{air}$ have the same sign which they don't in FGGasCell.cpp as shown above. And as I wrote previously the air column weight should be pushing ambient air inside the balloon.

@andgi
Copy link
Collaborator

andgi commented Jun 12, 2022 via email

@bcoconni
Copy link
Member Author

bcoconni commented Jun 13, 2022

Hi Anders,

The "standard" pressure in the gas cell is computed for the bottom of the cell (and at least as large as the air pressure). The pressure difference at the top is the difference in gas and air pressure at the bottom plus the difference from the height of the gas cell.

Thanks for the explanation. I think I got the idea: CellHeight is the absolute value of the column height i.e. the code uses the formula $P=P^0-\rho\times g\times(-h)$ where $-h$ is stored in CellHeight which is positive since $h<0$ because the valve is assumed to be at the top.

This makes me realize that I had assumed that the valve was located at a position below the reference pressure $P^0$. This must be a reminiscence of the draining water tank exercise that is taught in fluid mechanics 😄.

It remains that the physics is somehow wrongly simulated in FGGasCell since balloon deflation cannot reach a state where not a single molecule of gas is remaining inside the ballon envelope (which is what Contents == 0.0means).

Since the mass flow is generated by the pressure difference $\Delta P$ between the ambient air and the gas inside the balloon envelope, at some point $\Delta P$ should vanish before Contents reaches zero. So I still have this intuition that there is something wrong with the computation of DeltaPressure.

bcoconni added a commit that referenced this issue Jun 18, 2022
bcoconni added a commit that referenced this issue Jun 18, 2022
bcoconni added a commit that referenced this issue Jun 19, 2022
bcoconni added a commit to bcoconni/jsbsim that referenced this issue Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants