Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write python code Write python code Write python code Write python code Write python code A pipe-flow fluids problem: Oil with a density (=950 kg/m3)

Write python code

Write python code

Write python code

Write python code

Write python code

A pipe-flow fluids problem: Oil with a density (=950 kg/m3) and kinematic viscosity (=210-5m2/s) flows through a 30-cm-diameter (d=0.3m) pipe that is 100 m long with a head loss of hf = 8 m. The roughness ratio of the pipe is (/d=0.0002) and we can assume the flow is turbulent. Find the average velocity (V) and flow rate (Q=VA) for the oil. g=9.81 m/s2 We can calculate the head loss using the Darcy friction factor as: where, the friction factor is given by: where,

a. Write a function def Reynolds(V,nu,d): to calculate Reynolds number

b. Write a function def FrictionFactor(relrough, Re): to calculate the friction factor

c. Write a function def AvgVel(nu, dia, length): to calculate the average velocity of the oil

d. Write a function def main(): to call AvgVel with the appropriate parameters and print to the screen the average oil velocity and volumetric flow rate (with units). e. Finally, in your main function, determine the diameter of pipe necessary for a head loss of only 6m in a 100m long pipe, keeping viscosity and flow rate constant. Notes: The velocity V is unknown in parts a., b., and c as are the friction factor and Reynolds numbers. You will likely need to use your secant method to iteratively find the solution. According to the Moody diagram for friction factors, 0.008

Stem code:

import math # the secant method to find the root of a function def Secant(fcn, x0, x1, maxiter=10, xtol=1e-5): ''' Secant method finds delta(n+1)=x(n+1)-x(n)=-f(x(n))/[f(x(n)-f(n-1))/delta(n)] :param fcn: function to find root of :param x0: initial guess for the root :param x1: second initial guess for the root :param maxiter: maximum number of iterations :param xtol: exit tolerance if better than :return: the root ''' pass # part a def Reynolds(V, nu, dia): ''' Simple calculation of Reynolds number :param V: average velocity (m/s) :param nu: kinematic viscosity (m^2/s) :param dia: pipe diameter (m) :return: reynolds number (dimensionless) ''' pass # part b def FrictionFactor(relrough, Re): ''' This function calculates a friction factor for a pipe given a Re and roughness. It requires passing the function ffc to secant as a callback. :param relrough: the relative pipe roughness :param Re: The reynolds number :return: the value for the friction factor ''' def ffc(ff): # I use this as a callback for the secant function ''' This is my friction factor calculation. Because ff occurs on both sides of the equation (see assignment), I use secant method to find root of the equation (i.e., ff that makes right hand side -left hand side ==0) :param ff: the friction factor :return: LHS-RHS -> 0 when guess correct ff ''' pass f = # use the secant method to find the friction factor return f # part c def AvgVel(nu, dia, length, loss): ''' Given a head loss, pipe diameter, viscosity and pipe length, I use the secant method to match the head loss (see eqn on assignment) to the given/desired head loss by changing the velocity. Of course, changing velocity also changes Re and f, so those need to be recalculated for every value of velocity that the secant method tries. :param nu: the kinematic viscosity :param dia: the pipe diameter :param length: the pipe length :param loss: the given head loss :return: the average velocity of the fluid in the pipe ''' relrough = 0.0002 # pipe roughness (see assignment) g = 9.81 # gravity def FindV(V): # I'll make this a callback function for Secant pass AV = # use secant method to find average velocity return AV # part d def main(): ''' Main function for solving parts d) and e). We have three equations given. Each has V in it. We need to use the secant method to find the root (i.e., correct value of V) to match the given head loss in part d) to that calculated by the first equation (hl=(f*L*V**2)/(d*2*g)). Of course, changing V also changes Re and f, so those need to be recalculated for every guess of V in the secant method search for the correct value of V. In part e), Q is fixed, but we seek to find the pipe diameter that will reduce the head loss to only 6m (i.e., potentially selecting a new pipe for a new pipeline design). Increasing pipe diameter will reduce V and thus, change f and Re, so these three values will have to be recalculated each time I guess a new diameter in the secant function. :return: ''' # Part d): first find the average velocity for head loss of 8m nu = 2E-5 # the kinematic viscosity in m^2/s dia = 0.30 # the original pipe diameter in m L = 100 # the pipe length in m loss = 8 # the original head loss in m g = 9.81 # acceleration of gravith m/s^2 V = # call to calculate the average velocity of oil in the pipe print("Average Velocity = {:0.4f} m/s".format(V)) Q = # calculate the volumetric flow rate in m^3/sec print("The flow rate = {:0.4f} m^3/s".format(Q)) # Part e: now, use the Secant method to find a diameter that gives 6m of head loss for the same Q target = 6 relrough = 0.0002 def hl(d): # a function to calculate head loss given Q and d ''' Here, we are varying d and calculating head loss for a fixed Q. Varying d changes V, Re, f, and head loss :param d: the pipe diameter :return: head loss ''' pass fcn = lambda d: # use this function (difference between hl(d) and target) as the callback for secant function dL = #use secant function to find value for diameter to match target head loss print("Diameter for {:0.1f} m of head loss = {:0.3f} m".format(target, dL)) main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions