Thread: Fluid Mechanics program help

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    19

    Fluid Mechanics program help

    Hey all, I have programming assignment in school.I need some mathematical help in it.
    I dont want you to do the whole programming assignment to me.I just have problem how is the calculation being done for the sample given.If I just understand how the calculation is done, I can sit and write the code myself.I just need this help.Thanks alot.


    The Walid acqua Company (WAC) manages water storage facilities. They are considering a system of storing water in a series of connected vertical tanks. Each tank has a horizontal cross-sectional area of one square meter, but the tanks have different heights. The base of each tank is at ground level. Each tank is connected by a pipe to the previous tank in the series and by another pipe to the next tank in the
    series. The pipes connecting the tanks are level and are at increasing heights (that is, the pipe connecting tank i to tank i+1 is at a higher level than the pipe connecting tank i to tank i-1.)
    Tank 1 is open so that air and water can flow into it freely at the top. All the other tanks are closed so that air and water can flow in and out only through the connecting pipes. The connecting pipes are large enough that water and air can
    flow through them freely and simultaneously but small enough that their dimensions can be ignored in this problem.
    The series of tanks is filled by pouring water slowly into the top of tank 1, continuing until the water level reaches the top of tank 1.
    As the water level rises above the connecting pipes, water flows among the tanks. WAC needs a program to compute the cubic meters of water that can be poured into the series of tanks before the water level reaches the top of tank 1.
    The figure below illustrates a simple case involving only two tanks. After the filling procedure is completed, the air in the upper part of the second tank is compressed (its air pressure is greater than one atmosphere), so the water level in the second tank is lower than the water level in the first tank.
    The following physical principles are helpful in solving this problem (some of these are approximations that are acceptable for the purposes of this problem):
    1. Water flows downhill.
    2. In an open space, the air pressure is equal to one atmosphere.
    3. Air is compressible (the volume occupied by a given amount of air depends on pressure). Water is not compressible (the volume occupied by a given amount of water is constant, independent of pressure).
    4. Air pressure is the same everywhere within a closed space. If the volume of the closed space changes, the product of the volume and the air pressure within the space remains constant. For example, suppose an enclosed airspace has an initial volume V1 and pressure P1. If the volume of the airspace changes to V2, then the new pressure P2 satisfies P1V1 = P2V2.
    5. In a column of water below an airspace, the water pressure at a level D meters below the water surface is equal to the air
    pressure at the surface plus 0.097·D atmospheres. This is true regardless of whether the airspace is open or enclosed.
    6. In a connected body of water (for example, when two or more tanks are connected by pipes below the water line), the water
    pressure is constant at any given level.
    Input
    The input consists of several test cases representing different series of water tanks. Each test case has three lines of data. The first line
    contains an integer N (2 ≤ N ≤ 10) which is the number of tanks in the test case. The second line contains N positive floating point
    numbers that are the heights, in meters, of tanks 1 through N. The third line contains N-1 floating point numbers. On this line, the kth
    number represents the height above the ground of the pipe that connects tank k and tank k+1. The numbers on the third line are
    increasing (each number is greater than the preceding number).
    The last test case is followed by a line containing the integer zero.
    Output
    For each test case, print a line containing the test case number (beginning with 1) followed by the amount of water, in cubic meters,
    that can be poured into tank 1 before the water level reaches the top of tank 1. Print the results with three digits to the right of the
    decimal point.
    Print a blank line after the output for each test case. Use the format of the sample output.


    Sample input
    2
    10.0 8.0
    4.0
    0

    Sample output for input:
    Case 1:15.260
    Last edited by Hajjo; 03-08-2008 at 10:13 AM.

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    SPOJ problems have an http address, maybe try posting a link to that problem. And besides the whole purpose of the SPOJ site, is that you dissect and analyze a problem and that is why it accepts a variety of languages as solutions, however C tends to provide the fastest...
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    I am not getting what you saying.
    Can you just show me mathematic calulction of the sample.

    there are 2 tanks, height of tank1 10.0 and height of tank 2 8.0. the length of pipe is 4.0.

    15.260 cubic meters can be poured into tank 1 before the water level reaches the top of tank1.

    how?

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    Code:
    		_____________
    |~~~~~~~~~~~|   |P        	|
    |:::::::::::|   |	        |
    |:::::::::::|   |~~~~~~~~~~~|
    |:::::::::::|   |:::::::::::|
    |::::::::::: ===::::::::::::|
    |:::::::::::|	|:::::::::::|
    -------------	-------------
    	tank1		tank2
    Unfortunately, tank2 is broken, but I think the below equations are enough to solve the problem:
    P = (rho * g * delta_h_water) + 1 atmosphere
    V = pi r^2 * h
    P2 = P1V1/V2

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    Quote Originally Posted by heras View Post
    Code:
    		_____________
    |~~~~~~~~~~~|   |P        	|
    |:::::::::::|   |	        |
    |:::::::::::|   |~~~~~~~~~~~|
    |:::::::::::|   |:::::::::::|
    |::::::::::: ===::::::::::::|
    |:::::::::::|	|:::::::::::|
    -------------	-------------
    	tank1		tank2
    Unfortunately, tank2 is broken, but I think the below equations are enough to solve the problem:
    P = (rho * g * delta_h_water) + 1 atmosphere
    V = pi r^2 * h
    P2 = P1V1/V2

    Can you tell me what each one of those variables are?
    Thanks for help.That is how is the computation being done?
    can you show it on the example given.
    Last edited by Hajjo; 03-08-2008 at 10:16 AM.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    If you use SI:
    P = pressure in N/m^2
    rho = density in kg/m^3
    h = height in m
    V = volume in m^3

    The math isn't that hard. Try two tanks first, with a pen and a piece of paper. If you get stuck, show how far you've got and where you got stuck.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    what is g , delta_h_water and r?

    g is 0.097 like given..and delta_h_water 4.0(considering the pipe is 4 meter above ground)..and what is r?

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    g = 9.8
    r = the radius of the tank
    delta = the difference between one thing and another (of the same kind)

  9. #9
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    rho is desnity , how can I get that number?
    v = 3.14 x 0.5 * 0.5* 10 for tank 1 which is equal to 7.85
    v = 3.14 * 0.5 *0.5 * 8 for tank 2 which is 6.sthg..

    whats the use of p's? whats rho? its 1???
    delta_h_water is 4 right?

    still am clueless, I need more hints.


    thank a lot heras

  10. #10
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    Quote Originally Posted by Hajjo View Post
    rho is desnity , how can I get that number?
    whats the use of p's? whats rho? its 1?
    1 what? Does 1 cubic meter of water weigh 1 kg? How much does 1 liter weigh?

    delta_h_water is the relative difference in water levels between the tanks.

    The volume V you care about is that of the trapped air in tank2. It is under pressure P.

  11. #11
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    1 cubic meter is 1000 kg
    p2 = 1000 * 9.8 * (10 - 1.72) +1 = s

    v20 = pi * pow(r, 2) * h; = 3.14 * 0.5*0.5 * 8 = 6.28

    p2 = x and v21 = 8 - 6.28 = 1.72


    v1 =( p2 * v21)/p1 = s * 1.72/p1

    is this the way to solve it?
    the relative difference how can I bring it. V1 is height 10, so i can fill 10..while v2 i can fill 1.72 as 6.28 is trapped air...

  12. #12
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    Hajjo, please note that I'm a C noob and am here for help also, so I do not understand your implementation or where all those magic numbers came from. I can only help you with the 'pen and paper' math. Additionally, I only skimmed your opening post the first time so I missed that "Each tank has a horizontal cross-sectional area of one square meter". This means that you may replace pi r^2 with 1 m^2 (which I will call A). The following is irrelevant but I'll point it out anyway:
    r = ((1 m^2 / pi)^0.5) = 0.564... and not 0.5

    Now,
    P1 = 1atm (~ 100.000 N/m^2)
    V1 = h1 * A
    V2 = h2 * A
    P2 = 1000 * 9.8 * h2 + P1

    Code:
                --------- ---
    |~~~~~~~|---|       |  ^
    |       | ^ | air   |  |
    |       | | |       |  |
    |       | h2|       |  |
    |       | | |       |  h1
    |       |---|~~~~~~~|  |
    | water |   |       |  |
    |       |   |       |  |
    |        ===        | ---
    |       |   | water |
    |       |   |       |
    ---------   ---------
    Last edited by heras; 03-09-2008 at 12:48 PM.

  13. #13
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    Man thanks for all help your providing.But I still cant do it.
    Can you please show me the how its done, so I get into the programming.I pretty much wasted big time thinking on the mathematical part.

    please, thanks.

  14. #14
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    Quote Originally Posted by Hajjo View Post
    Can you please show me the how its done
    I'm trying to. Perhaps you should do the same.

  15. #15
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    if you calculate p2, its a huge number.,
    h2 is 8..
    8 *9.8*1000 +1 is huge number..
    v1 = 10 * 0.564
    v2 = 8 * 0.564
    p1 = 1

    p1v1 is not equal to p2v2..in this case..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM