Measuring Water in a Tank

Over the years, we have received a huge number of questions asking about how to find the amount of liquid (water, oil, …) in a tank, usually a horizontal cylindrical tank. The simplest case involves a rather complicated formula; from there, we can reverse the formula (finding the depth for a given volume), or we can add features to the tank. Here I will look at just a couple of these, with links to others, most of which include derivations.

The basic horizontal cylindrical tank

Here is a typical, well-written question, from 1999:

Horizontal Gas Tank Content Formula

I'm trying to find a chart that can be used by our drivers to check the content of a fuel tank by inserting a sort of yardstick into the tank and checking the inches of liquid in the fuel tank. The tanks are 97-gallon horizontal tanks. I have a horizontal tank content indicator chart but it is for larger tanks. I need something that a driver, given the length and height of the tank, can use to calculate the remaining fuel by measuring the height of the remaining fuel. Our objective is to reduce the amount of fuel purchased on the road and more accurately calculate the amount of fuel left on board. The smallest tank size on the chart I have is 300 gal. Thanks in advance for your help.

The calculation is sufficiently complicated that most people would find it easiest to use a chart. Today, I suppose they would be more likely to use a spreadsheet to do the calculations; the formula is available in many places. Doctor Anthony straightforwardly derived it:

The problem is not difficult. We simply need to calculate the area of a segment of a circle, representing the cross-section of the tank that contains the fuel. If this cross-sectional area is multiplied by L, the horizontal length of the tank, we have the volume.

Suppose r = the radius of the tank and h = the height of the fuel measured from the lowest point to the surface of the fuel (the dipstick reading):
Segment of a circle, with radii marked
If theta is the angle, in radians, between the vertical through the centre of the circle and a radius drawn from the centre to the point of contact of the fuel and the side of the tank, then

    cos(theta) = (r-h)/r 

So theta = cos^(-1)[(r-h)/r)]

Note that:

** area of sector of circle with angle 2 theta  =  r^2 theta 

** area of triangle to be subtracted = (1/2)r^2 sin(2 theta) 

Thus:

  Cross-section of fuel = r^2 theta - (1/2)r^2 sin(2 theta)
                        = r^2[theta - (1/2)sin(2 theta)]
                        = r^2[theta - sin(theta) cos(theta)]

And so:

  Volume of fuel  =  r^2 L[theta - sin(theta) cos(theta)]   

It is probably better to leave the formula in this form and use the other formula

  theta = cos^(-1)[(r-h)/r] radians

to complete the calculation. It becomes rather untidy if you express 
the whole thing in one big formula in terms of h. The sin(theta) term is the problem.

                 sqrt[r^2 - (r-h)^2]     sqrt(2rh - h^2)
   sin(theta) =  -------------------  =  ---------------
                          r                     r

and you end up with

  Volume = r^2 L[cos^(-1)[(r-h)/r] - sqrt(2rh-h^2)/r (r-h)/r]

         = r^2 L[cos^(-1)[(r-h)/r] - (r-h) sqrt(2rh-h^2)/r^2]

We will usually see this in a slightly different form,

\(
\displaystyle  V = L\left[r^2 \cos^{-1}\frac{r-h}{r} – (r-h) \sqrt{2rh-h^2}\right]\).

This (without the L) can also be found in the Formulas FAQ under Segment of a Circle.

We can factor out \(R^2\) and define \(f = \frac{h}{2r}\), then divide by the volume of the whole cylinder, yielding this nice formula for the percentage full in terms of the percentage depth:

\(
\displaystyle  V_{rel} = \frac{1}{\pi} \left(\cos^{-1}(1-2f) – 2(1-2f) \sqrt{(1-f)f}\right)\).

Let’s try an example. Suppose the radius r is 1 foot, and the length L is 4 feet. Then the volume of the whole tank is

\(V = \pi r^2 L = \pi\cdot12^2\cdot48 = 21,715 \text{ in}^3\),

which is  \(21,715/231 =  94\text{ gal}\).

Close enough to 97! If the fuel is 9 inches deep, we have 

\(V = 48\left[12^2 \cos^{-1}\frac{12-9}{12} – (12-9) \sqrt{2\cdot 12\cdot 9-9^2}\right] \) \(= 48\left[144 \cos^{-1} \frac{1}{4} – 3 \sqrt{135}\right] \) \(= 48\cdot 154.95 = 7438 \text{ in}^3 = 32 \text{ gal}\).

So the tank is about 1/3 full. (Don’t forget to set your calculator to radians.)

Using the second formula, the relative depth is 9/24 = 3/8, so the relative volume is

\(
\displaystyle \frac{1}{\pi} \left( \cos^{-1}\left(1-2\frac{3}{8}\right) – 2
\left(1-2\frac{3}{8}\right) \sqrt{ \frac{5}{8} \frac{3}{8} }\right){\pi} = 0.3425\)

For an earlier, and longer, discussion of this problem, see

Finding the Volume of a Horizontal Tank

The inverse problem: Making a dipstick

In the next question, from 2000, the “patient” Mark has derived that formula himself, but has a much harder problem. He wants to reverse it:

Volume of a Partially Filled Cylindrical Tank

I am trying to find the inverse for the equation used to find the area of a circle's segment. I have managed to derive the area formula, but finding its inverse seems impossible.

One version of the formula follows:

Given a circle of radius 5, and the distance from the center of the circle to the center of the chord defining the segment, h,

     a = 25arccos((5 - h) / 5) - (5 - h)sqrt(10h - h^2)

The formula itself is no trouble to find, being just the difference between the area of the sector the segment is part of and the triangle formed by the two endpoints of the chord and the circle's center. I need to transform it such that it is expressed in terms of h.

If the transformation is too difficult, it may help that this question is part of a bigger problem. Briefly, a tank, filled from the top and drained from the bottom, is made from a hemispherical prism, such that it lies with its axis parallel to the ground and its flat surface facing upwards (a D with the flat section upwards). The radius of the hemisphere is 5, and the tank is 10 deep. The problem is to design a dipstick such that it can be used to find the volume of liquid in the tank. I had planned to use the inverse to find h for convenient volumes of liquid, and use that value to specify markings on the dipstick. I have written a computer program that solves the problem using successive iterations to reduce error, but it is not really an acceptable solution.

I have done a little calculus (just differentiation and integration), but no solving of differential equations (which is what I think may be needed here, as the derivative of the area would be related to the derivative of h), so that is little help here unless I hit the books. 

Any suggestions?

We first had to be sure what he means by “hemispherical prism”. It turns out that he meant something more like “semicircular prism”, or more simply, half a cylinder lying on its side, with the flat surface up. So this is just a tank like the previous question, without its upper half. He got the formula right.

Doctor Jerry answered, first giving a different form of the same formula:

Consider a circle of radius a (the end of the tank) and imagine that the liquid has reached height h, measured from the lowest point on the circle. Note that 0 <= h <= 2a. The area A of the segment of the circle covered by the liquid is

     A = pi*a^2/2 - a^2*arcsin(1-h/a) - (a-h)*sqrt(h(2a-h))

The volume of liquid is just A*L, where L is the length of the tank.  From this, a dipstick can be calibrated.

This formula is related to the formula you gave, but it is expressed in terms of the depth of the liquid, which I think is useful.

It is not possible to solve either of our two formulas for h - at least not in "closed form."

After a discussion clarifying the shape, he pointed out that, in fact, an iterative approximation will be necessary; he showed how to do this more efficiently, using Newton’s Method as we recently discussed here:

Using the formula:

     V(h) = 10[pi*a^2/2 - a^2*arcsin(1-h/a) - (a-h)*sqrt(h(2a-h))]

for the volume of such a tank, where a = 5 and h, the depth of the liquid, lies between 0 and a = 5, our problem is to determine h when given various convenient values of V(h).

I find V(5) = 392.7 sq meters, approximately.

Suppose we want to determine h so that 

     V(h) = 350 sq meters.

I'll use Newton's method on the function 

     f(h) = V(h)-350.

Letting h_1 be our first guess, which we can take as, say, 4.5, the next guess comes from

     h_2 = h_1-f(h_1)/f'(h_1).

All other guesses follow the same pattern.

I find

     h_2 = 4.572538...
     h_3 = 4.572487...

So, it looks as if a depth of 4.57 yields 350 sq meters. You could, of course, specify an amount in liters and, before using the above formulas, convert the liters to square meters.

By f'(h_1) I mean the derivative (quite messy) of f, evaluated at h_1.

Mark asked for a simpler method; Doctor Jerry added:

I don't see an easier way of solving the problem. However, I can offer a simplified version of the iteration formula, with the differentiation already done.

           0.5*(5 + h_1 - (5*(-7 + 5*ArcCos[1 - h_1/5]))
     h_2 = ---------------------------------------------
                      Sqrt[-(-10 + h_1)*h_1])

As before, h_2 means "h sub 2" and h_1 means "h sub 1". h_{n+1} is obtained similarly from h_n.

With this I obtained the results I mentioned earlier.

The same sort of problem was raised in 2002 on Car Talk, and Dr. Ian discussed it here, with a reference to our FAQ:

1/4 Tank Dipstick Problem (from Car Talk)

Many of the links at the end of that are dead, but you can find the original Car Talk episode and listener discussions by searching.

When the ends aren’t flat

We have had many questions about tanks with “dished” ends of various shapes. They may be hemispherical, as here, where the tank stands vertically:

Gas in a Cylindrical Tank with Hemispheric Caps

For a horizontal tank with ellipsoidal ends (a generalization of hemispheres), see:

Volume of a Horizontal Cylindrical Tank with Elliptic Heads
Volume of a Rounded Horizontal Tank

The first of these refers to the following for the volume of a partially filled ellipsoid:

Variable Volumes in an Oblate Spheroid

The formula turns out to be

\(\displaystyle V = L\left(R^2 \cos^{-1}\left(\frac{R-h}{R}\right) – (R-h)\sqrt{2Rh-h^2}\right)
+ \frac{a}{R}\frac{\pi}{3}\left(3hR – h^2\right)h\)

where L is the length of the cylindrical part, R is the radius of the cylinder, h is the depth of fluid and a is the thickness of the ellipsoidal ends.

In relative terms, using my \(f = \frac{h}{2R}\) from above, this becomes

\(\displaystyle V = L R^2  \left(\cos^{-1}\left(1-2f\right) – 2(1-2f)\sqrt{f(1-f)}\right)+ \frac{4}{3} \pi aR^2 f^2(3-2f)\)

If a = R, the ends are hemispheres.

In contrast to that, here is an elliptical cylinder (flat ends, elliptical cross-section):

Liquid in an Elliptical Tank
Segment of an Ellipse

That style of tank may be quite common; but it is also likely that what many people think of as an ellipse might really be some other sort of oval, such as a rectangle with semicircular ends, which I don’t think we’ve ever covered.

Here is the formula from the first of these pages, with a = horizontal semiaxis and b = vertical  semiaxis, and d = depth:

\(\displaystyle V = L\frac{a}{b}\left[\frac{\pi b^2}{2} + (d – b) \sqrt{b^2-(d-b)^2} + b^2 \sin^{-1}\left(\frac{d}{b}-1\right)\right]\)

For consistency with our other formulas, let’s replace d with h, simplify, then use my f:

\(\displaystyle V = Lab\left[\frac{\pi}{2} + \left(1-\frac{h}{b}\right) \sqrt{2\frac{h}{b} – \left(\frac{h}{b}\right)^2} – \sin^{-1}\left(1 – \frac{h}{b}\right)\right]\) \(  = Lab\left[\cos^{-1}\left(1-2f\right) +2(1-2f) \sqrt{f(1-f)}\right]\)

This becomes the same as for an ordinary cylinder when we let a = b = R.

But the most frustrating case over the years has been the case of spherical cap ends. I think there have been dozens of questions about this case, where each end is a portion of a sphere, and we have found that the formula is too complicated to even try to post in the archives. (We have either given a table of values obtained from math software, or sent a PDF of the answer, which could not be easily posted, and which appears to be lost.) I have occasionally searched for existing sources on this case, and failed.

Just recently, however, I ran across a question (on another site) with a picture, and the caps looked to me more parabolic than spherical. I realized that even if they really are spherical, this might be easier to work with than the spherical cap, and I worked out an exact formula. It still isn’t pretty, but here it is:

\(\displaystyle V = LR^2\left(1+g\right)\cos^{-1}(1-2f) + 2(1-2f)
\sqrt{f(1-f)} \left(\frac{g(8f^2-8f-3)}{3}-1\right)\)

where L is the length of the cylinder, R is the radius, B is the “bulge” of the end, h is the depth of the liquid, \(f = \frac{h}{2R}\), and
\(g = \frac{B}{L}\) . I obtained this by integrating parabolic horizontal cross-sections, and again by integrating circular segment cross-sections (with a little help from WolframAlpha) for confirmation.

After working that out, I found the following detailed article from Oil News of 1920 (Computation of Gauge Tables for Horizontal Tanks, Carl D. Miller), including a simplified version of the formula:

Horizontal tank with dished ends
Explanation of formula

There, D is the diameter, h is the liquid depth, and \(A_T\) is the area of the segment of the circle expressed as a fraction of the area of the whole circle, which is \(\cos^{-1}\left(1-2\frac{h}{D}\right) – 
\left(1-2 \frac{h}{D} \right )-2\sqrt{\frac{h}{D} – \frac{h}{D}^2}\). I think there’s a small problem with this, as it gives close to 4 times what my formula gives, perhaps because they use the diameter. I don’t know how they did their approximation.

This post has taken more time than usual, as I compared various formulas and put them in consistent formats. Please let me know if you find any errors!

1 thought on “Measuring Water in a Tank”

  1. Pingback: A Tank with a Conical End – The Math Doctors

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.