Calculating the Volume of Irregular-Shaped Tanks

This is a quick demo and code listing I used to calculate the volume of a tank that is a combination of box, cylinder, and sphere shapes.  The controller is a Red Lion G3 Graphite.

float TankCalcs.FindVolume(int TankType, float FluidHeight)

//define local variables
float TankRadius;
float TankLength;
float TankD;
float LegSize;
float LegHeight;
float LegStaticVol;
float FluidArea;
float VolumeF;
float VolumeL;
//units are inches and gallons
//set tank parameters based on TankType 
switch( TankType ) { 
  case 225: 
    TankRadius := 18.75;
    TankLength := 41.75;
    TankD := 37.5;
    LegSize := 38.0;
    LegHeight := 19.0;
    LegStaticVol := 10.42;
    break; 
  case 335: 
    TankRadius := 22.0;
    TankLength := 43.5;
    TankD := 43.5;
    LegSize := 43.0;
    LegHeight := 22.0;
    LegStaticVol := 12.06;
    break;
  default: 
    TankRadius := 0.0;
    TankLength := 0.0;
    TankD := 0.0;
    LegSize := 0.0;
    LegHeight := 0.0;
    LegStaticVol := 0.0; 
    break;
 }
//calculate the area of the fluid based on level and radius of tank
FluidArea := TankRadius*TankRadius*acos((TankRadius-FluidHeight)/TankRadius)-(TankRadius-FluidHeight)*Sqrt(2*TankRadius*FluidHeight-FluidHeight*FluidHeight);
//calculate the volume of the part of the tank based on ASME flanged and dished formula
VolumeF := (TankLength*FluidArea+0.215483*FluidHeight*FluidHeight*(1.5*TankD-FluidHeight))*0.00433;
//calculate the volume of the leg portion of the tank
if( FluidHeight <= LegHeight )
 VolumeL := ((FluidHeight*LegSize-FluidArea)*15)*0.00433; 
 else VolumeL := LegStaticVol; 
//total volume 
return VolumeF + VolumeL;
This entry was posted in Industrial Automation and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

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