What will be the height of fluid columns in a variable width cylinder
-
Assume that there is a vertical cylinder with a diameters as follows 1cm at base 3cm at the height of 2cm 2cm at the height of 4cm 1cm at the height of 7cm etc etc Now, what would be the height of different colored fluid columns one over the other (Assuming there are no other forces). The columns are on top of each other and movable by drag and drop. Hence the calculation of each column depends on the bottom column. Its not necessary to consider volumetric analysis because the solution could be in 2D for area also. The function should take parameters of volume/area of each column at which it starts. This is required for a graphical application where the movement of a liquid is shown in 2D. I am looking for a faster alternative to "for" or "while" loops. It needs to be very fast so that a fluid motion could be achieved. Current algorithm is damn slow. my current solution looks like:
while (volumeToAdjust > 0)
{
volumeCovered = Min (volumeToAdjust, volumePossibleInCurrentWidth)if(volumeCovered>volumePossibleInCurrentWidth) height += heightForCurrentWidth else height += CalculateHeightForThisVolumeInCurrentWidth volumeToAdjust -= volumeCovered
}
This solution works fine for a single column of fluid. Multiple columns, multiple widths, the program slows down. Any better ideas?
-
Assume that there is a vertical cylinder with a diameters as follows 1cm at base 3cm at the height of 2cm 2cm at the height of 4cm 1cm at the height of 7cm etc etc Now, what would be the height of different colored fluid columns one over the other (Assuming there are no other forces). The columns are on top of each other and movable by drag and drop. Hence the calculation of each column depends on the bottom column. Its not necessary to consider volumetric analysis because the solution could be in 2D for area also. The function should take parameters of volume/area of each column at which it starts. This is required for a graphical application where the movement of a liquid is shown in 2D. I am looking for a faster alternative to "for" or "while" loops. It needs to be very fast so that a fluid motion could be achieved. Current algorithm is damn slow. my current solution looks like:
while (volumeToAdjust > 0)
{
volumeCovered = Min (volumeToAdjust, volumePossibleInCurrentWidth)if(volumeCovered>volumePossibleInCurrentWidth) height += heightForCurrentWidth else height += CalculateHeightForThisVolumeInCurrentWidth volumeToAdjust -= volumeCovered
}
This solution works fine for a single column of fluid. Multiple columns, multiple widths, the program slows down. Any better ideas?
Do the diameters change or can they be hard coded? What happens in between the values you gave? Is the diameter constant or tapered?
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
-
Do the diameters change or can they be hard coded? What happens in between the values you gave? Is the diameter constant or tapered?
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
Yes diameters can be changed. Also, the volume of each fluid column and their sequence can be changed by drag and drop. That is why the need of an algorithm to do it the fastest way. Diameters are not tapered.