diff options
author | hardythe1 | 2015-04-07 15:58:05 +0530 |
---|---|---|
committer | hardythe1 | 2015-04-07 15:58:05 +0530 |
commit | 92cca121f959c6616e3da431c1e2d23c4fa5e886 (patch) | |
tree | 205e68d0ce598ac5caca7de839a2934d746cce86 /sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb | |
parent | b14c13fcc6bb6d01c468805d612acb353ec168ac (diff) | |
download | Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.tar.gz Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.tar.bz2 Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.zip |
added books
Diffstat (limited to 'sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb')
-rwxr-xr-x | sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb | 556 |
1 files changed, 556 insertions, 0 deletions
diff --git a/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb new file mode 100755 index 00000000..251df967 --- /dev/null +++ b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb @@ -0,0 +1,556 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:65f02fae284344ccd8037c2004c0386b9cc4ee681cfc1240a77e3be2fe2aff5e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1: Introductory Concepts"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.1, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Express absolute viscosity of fluids in SI units and calculate the kinematic viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import numpy as np\n",
+ "from prettytable import PrettyTable\n",
+ "\n",
+ "# Given\n",
+ "\n",
+ "mu = np.array([1,0.018,100]) # Absolute viscosities in centipoise\n",
+ "mu_poise = np.array([1,0.018,100])/100 # Absolute viscosities in poise\n",
+ "rho = np.array([1.0,0.0012,0.930]) # Densities in gm/cm^3\n",
+ "mu_SI = mu/1000 # Absolute viscosities in SI units\n",
+ "rho_SI = rho*1000 # Densities in SI units\n",
+ "nu = mu_poise/rho # Kinematic viscosities in Stokes\n",
+ "nu_SI = mu_SI/rho_SI # Kinematic viscosities in SI units\n",
+ "\n",
+ "# Tabulate results\n",
+ "\n",
+ "table = PrettyTable([\"Property\", \"Water\", \"Air\", \"Lube Oil\"])\n",
+ "table.add_row(['Absolute Viscosity mu',' ',' ',' '])\n",
+ "table.add_row([\"centipoise cP\",mu[0],mu[1],mu[2]])\n",
+ "table.add_row([\"SI units (Ns/m^2)\",mu_SI[0],mu_SI[1],mu_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Mass Density rho',' ',' ',' '])\n",
+ "table.add_row([\"g/cm^3\",rho[0],rho[1],rho[2]])\n",
+ "table.add_row([\"SI units (kg/m^3)\",rho_SI[0],rho_SI[1],rho_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Kinematic Viscosity nu',' ',' ',' '])\n",
+ "table.add_row([\"St\",nu[0],nu[1],round(nu[2],2)])\n",
+ "table.add_row([\"SI units (m^2/s)\",nu_SI[0],nu_SI[1],\"{:.2e}\".format(nu_SI[2])])\n",
+ "print table"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+------------------------+--------+---------+----------+\n",
+ "| Property | Water | Air | Lube Oil |\n",
+ "+------------------------+--------+---------+----------+\n",
+ "| Absolute Viscosity mu | | | |\n",
+ "| centipoise cP | 1.0 | 0.018 | 100.0 |\n",
+ "| SI units (Ns/m^2) | 0.001 | 1.8e-05 | 0.1 |\n",
+ "| | | | |\n",
+ "| Mass Density rho | | | |\n",
+ "| g/cm^3 | 1.0 | 0.0012 | 0.93 |\n",
+ "| SI units (kg/m^3) | 1000.0 | 1.2 | 930.0 |\n",
+ "| | | | |\n",
+ "| Kinematic Viscosity nu | | | |\n",
+ "| St | 0.01 | 0.15 | 1.08 |\n",
+ "| SI units (m^2/s) | 1e-06 | 1.5e-05 | 1.08e-04 |\n",
+ "+------------------------+--------+---------+----------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.2, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the force and power required to maintain the velocity\n",
+ "\n",
+ "# Given\n",
+ "A = 0.1 # Area of the flat plate (m^2)\n",
+ "U = 0.3 # Velocity of the flat plate (m/s)\n",
+ "mu = 0.001 # viscosity of the fluid separating the plates (m)\n",
+ "du = U - 0 # relative velocity between the plates\n",
+ "dy = 0.0001 # relative distance between the plates\n",
+ "\n",
+ "tau = mu*du/dy # Shear stress (N/m^2)\n",
+ "F = tau * A # Shear force (N)\n",
+ "Power = F * U # Power required (W)\n",
+ "print(\"The force required to maintain the velocity is %.2f N.\" %F)\n",
+ "print(\"The power required is %.2f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required to maintain the velocity is 0.30 N.\n",
+ "The power required is 0.09 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine the torque and power\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import math \n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "l = 0.10 # length of the shaft (m)\n",
+ "d = 0.05 # diameter of the shaft (m)\n",
+ "D = 0.051 # diameter of the concentric bearing (m)\n",
+ "N = 500 # Rotational speed of the shaft (rpm)\n",
+ "mu = 0.1 # Viscosity of the lubricating oil (Ns/m^2)\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "u = round(math.pi*d*N/60,2) # Peripheral speed of the shaft (m/s)\n",
+ "du = u - 0 \n",
+ "dy = (D-d)/2\n",
+ "tau = round(mu*du/dy,0) # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*d/2*d/2*l,(theta,0,2*math.pi)) # Torque required to turn the shaft (Nm)\n",
+ "omega = u/(d/2) # Angular speed of the shaft\n",
+ "Power = round(T,3)*omega # Power required to turn the shaft (W)\n",
+ "\n",
+ "print(\"The power required to turn the shaft is %1.3f W.\" %Power)\n",
+ "# Wrong rounding-off of Torque T in textbook. Hence, the difference in value of power. Textbook answer Power = 5.387 W"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power required to turn the shaft is 5.397 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# The power dissipated in the bearing\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "R = 0.1/2 # Radius of the bearing (m)\n",
+ "mu = 0.08 # Viscosity of oil film (Ns/m^2)\n",
+ "dy = 0.0015 # separation distance (m)\n",
+ "N = 100 # Rotational speed of the bearing (rpm)\n",
+ "r = sympy.Symbol('r')\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "omega = round(2*math.pi*100/60,2) # Angular velocity of the bearing (rad/s)\n",
+ "u = r*omega # Linear velocity of the bearing (m/s)\n",
+ "du = u - 0 # Relative velocity \n",
+ "tau = mu * du/dy # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*r*r,(theta,0,2*math.pi),(r,0,R)) # Total torque on the shaft (Nm)\n",
+ "Power = round(T,5)*omega # Power dissipated (W)\n",
+ "print(\"The power dissipated by the bearing is %.4f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power dissipated by the bearing is 0.0574 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine shear stress for r/R ratios and calculate drag force per meter length of the pipe\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "import math\n",
+ "from tabulate import tabulate\n",
+ "\n",
+ "# Given\n",
+ "r = sympy.Symbol('r') # Radial distance for the point\n",
+ "R = sympy.Symbol('R') # Radial distance for the wall\n",
+ "U = 10 # Centreline velocity (m/s)\n",
+ "mu = 0.002 # Viscosity (Ns/m^2)\n",
+ "r_R = [0.0,0.2,0.5,0.8,1.0] # r/R ratios\n",
+ "u = U*(1-(r/R)**2) # Expression for velocity in a pipe-flow\n",
+ "y = R-r # Distance from the wall\n",
+ "\n",
+ "du = sympy.diff(u,r) # Derivative of 'u' expression\n",
+ "dy = sympy.diff(y,r) \n",
+ "tau = mu*du/dy # Newton's law of viscosity (N/m^2)\n",
+ "F = 2*math.pi*R*tau # Drag force (N)\n",
+ "\n",
+ "# Substitution of r/R ratios\n",
+ "table = []\n",
+ "for i, r_R in enumerate(r_R): \n",
+ " table.append([r_R,round(tau.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4),\n",
+ " round(F.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4)])\n",
+ "print tabulate(table, headers=['r/R', 'Shear stress, tau (N/m^2)', 'Drag force, F (N)'],tablefmt='grid',numalign=\"center\")\n",
+ "# The Drag force printed in the textbook for the r/R = 0.8 is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+-------+-----------------------------+---------------------+\n",
+ "| r/R | Shear stress, tau (N/m^2) | Drag force, F (N) |\n",
+ "+=======+=============================+=====================+\n",
+ "| 0 | 0 | 0 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.2 | 0.016 | 0.0503 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.5 | 0.04 | 0.1257 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.8 | 0.064 | 0.2011 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 1 | 0.08 | 0.2513 |\n",
+ "+-------+-----------------------------+---------------------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine average thickness of the film\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "n = 800 # Normal reaction by the ice on the skater (N)\n",
+ "f = 0.02 # Coefficient of friction between the skates and the ice \n",
+ "u = 54*1000/3600 # Speed of the skater (m/s)\n",
+ "A = 10e-4 # Skating area (m^2)\n",
+ "mu = 0.001 # Viscosity of water (Ns/m^2)\n",
+ "h = sympy.Symbol('h') # average thickness of the film\n",
+ "\n",
+ "F = f*n # Frictional reaction (N)\n",
+ "du_dy = (u-0)/h # Velocity gradient\n",
+ "tau = mu*du_dy # Shear stress (N/m^2)\n",
+ "print('The average thickness of the film is %.3e m.'\n",
+ " %sympy.solve(sympy.Eq(tau*A,F),h)[0]) # Solve for h by equating drag force to frictional reaction"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average thickness of the film is 9.375e-07 m.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine necessary increase of pressure\n",
+ "\n",
+ "# Given\n",
+ "K = 2.07e6 # Bulk modulus of water (kN/m^2)\n",
+ "gamma = 1.4 # Specific heat ratio\n",
+ "p = 101.324 # Atmospheric pressure (kN/m^2)\n",
+ "vol_red = 0.01 # Volume reduction \n",
+ "\n",
+ "# (a) At same temperature\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for water is %d kN/m^2.' %dp)\n",
+ "# (b) isentropic compression of air\n",
+ "K = gamma * p # Bulk modulus of air (kN/m^2)\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for air is %.2f kN/m^2.' %dp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The increase in pressure required for water is 20700 kN/m^2.\n",
+ "The increase in pressure required for air is 1.42 kN/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Height of capillary rise\n",
+ "\n",
+ "# Import required modules\n",
+ "import math\n",
+ "\n",
+ "# Given\n",
+ "sigma = 0.0736 # Surface tension between water and glass (N/m)\n",
+ "theta = 0 # Angle of contact\n",
+ "d = 2e-3 # Diameter of the glass tube (m)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "\n",
+ "h = 4*sigma*math.cos(theta)/(rho*g*d) # height of capillary rise (m)\n",
+ "print('The water in the glass tube rises through a height of %0.3f m'%h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The water in the glass tube rises through a height of 0.015 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gauge pressure and absolute pressure within a droplet and a jet\n",
+ "\n",
+ "# Given\n",
+ "d_droplet = 0.004 # Diamter of the droplet (m)\n",
+ "d_jet = 0.004 # Diameter of the jet (m)\n",
+ "sigma = 0.073 # Viscosity of water (Ns/m^2)\n",
+ "P_atm = 101300 # Atmospheric pressure (N/m^2)\n",
+ "\n",
+ "# (a) For the droplet\n",
+ "P_gauge = 4*sigma/d_droplet # Gauge pressure for droplet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a droplet is %d N/m^2 and %.3f kN/m^2 respectively.' %(P_gauge,P_abs/1000))\n",
+ "\n",
+ "# (a) For the jet\n",
+ "P_gauge = 2*sigma/d_jet # Gauge pressure for jet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a jet is %.1f N/m^2 and %.2f kN/m^2 respectively.' %(P_gauge,P_abs/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gauge pressure and absolute pressure within a droplet is 73 N/m^2 and 101.373 kN/m^2 respectively.\n",
+ "The gauge pressure and absolute pressure within a jet is 36.5 N/m^2 and 101.34 kN/m^2 respectively.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Difference in level of the miniscii\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "d_1 = 1.0e-3 # Diameter of capillary (m)\n",
+ "d_2 = 1.5e-3 # Diameter of another capillary (m)\n",
+ "sigma = 0.0075 # Surface tension of water (Ns/m^2)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "h = sympy.Symbol('h') # Difference in level of the miniscii (m)\n",
+ "\n",
+ "h = sympy.solve(sympy.Eq(math.pi*d_2*sigma-math.pi*d_1*sigma,math.pi*d_2**2*h*rho*g/4),h)[0]*1000 # Solve for h\n",
+ "print('The difference in level of the miniscii is %.2f mm' %h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The difference in level of the miniscii is 0.68 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.10, Page number 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Shear stress calculation and estimate the viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "U_max = 0.2 # Maximum velocity (m/s)\n",
+ "h = 0.01 # film thickness (m)\n",
+ "mu = 0.5 # Viscosity of the non-Newtonian fluid (Ns/m^2)\n",
+ "y = sympy.Symbol('y') \n",
+ "u = sympy.Symbol('u') \n",
+ "u = U_max * (2*(y/h)-(y/h)**3/3) # Expression for velocity\n",
+ "\n",
+ "# (a) Shear stress calculation\n",
+ "du_dy = sympy.diff(u,y) # Velocity gradient\n",
+ "tau = mu*(round(du_dy.subs(y,h)))**1.3 # Shear stress of the non-Newtonian fluid (N/m^2)\n",
+ "print('The shear stress at the solid surface is %.2f N/m^2.' %tau)\n",
+ "\n",
+ "# (b) Estimation of the viscosity of the Newtonian fluid\n",
+ "mu = sympy.Symbol('mu')\n",
+ "mu = sympy.solve(sympy.Eq(round(tau,2),mu*round(du_dy.subs(y,h))))[0] # Solve for mu for the same shear stress using Newton's law of viscosity\n",
+ "print('The viscosity of a Newtonian fluid to induce the same shear stress is %.2f Ns/m^2.' %mu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The shear stress at the solid surface is 24.56 N/m^2.\n",
+ "The viscosity of a Newtonian fluid to induce the same shear stress is 1.23 Ns/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |