Numerical Solution of Plane Irrotational Flow APPH 4200 Physics of Fluids Columbia University Solve Laplace's equation for the streamfunction, y[x,y], for two relatively simple examples. Since Mathematica can solve thousands of simultaneous equations quickly, the only challenge to this problem is defining the computational grid and the boundary conditions on the flow. Two dimensional solutions to elliptical PDE's can be easily and accurately solved using today's computers. Define Laplace's Equation on a Grid In[1]:= Off@General::spell1D; Define Laplace's Equation… In[2]:= eqn@i_, j_D := H y@i + 1, jD - 2 y@i, jD + y@i - 1, jDL ê dx ^ 2 + Hy@i, j + 1D - 2 y@i, jD + y@i, j - 1DL ê dy ^ 2 ã 0 In[3]:= eqn@i, jD y@i, -1 + jD - 2 y@i, jD + y@i, 1 + jD Out[3]= dy2 + y@-1 + i, jD - 2 y@i, jD + y@1 + i, jD dx2 ã0 2 Numerical_Potential_Flow.nb Define a Grid In[4]:= height = 1.0 H* meter *L; length = 5.0 H* meter *L; wallHeight = 0.5 H* meter *L; wallLength = 0.5 H* meter *L; Grid points go from 1 to numX and from 1 to numY. In[8]:= numX = 80; numY = 60; Print@"Number of Grid Points = ", numX numYD; Number of Grid Points = 4800 In[11]:= In[13]:= Out[13]= In[14]:= Out[14]= In[15]:= In[16]:= In[17]:= Out[17]= In[18]:= Out[18]= In[19]:= Out[19]= In[20]:= Out[20]= dx = length ê HnumX - 1L; dy = height ê HnumY - 1L; wallLength ê dx 7.9 wallHeight ê dy 29.5 flow = 5.0 H* mês *L; grid = Table@ If@length ê 2 - wallLength ê 2 § Hix - 1L dx § length ê 2 + wallLength ê 2 && Hiy - 1L dy § wallHeight »» ix ã 1 »» ix == numX »» iy ã 1 »» iy == numY, 1, 0D, 8ix, 1, numX<, 8iy, 1, numY<D; 880, 60< Dimensions@gridD Count@Flatten@gridD, x_ ê; x ã 1D H* number of known grid values *L 508 Count@Flatten@gridD, x_ ê; x ã 0D H* number of unknown grid values *L 4292 Length@Flatten@gridDD 4800 Numerical_Potential_Flow.nb In[21]:= ArrayPlot@Transpose@gridD, Mesh Ø TrueD Out[21]= In[22]:= wallBound@ix_D := If@length ê 2 - wallLength ê 2 § Hix - 1L dx § length ê 2 + wallLength ê 2, Floor@wallHeight ê dyD + 1, 1D 3 4 Numerical_Potential_Flow.nb In[23]:= ListPlotBTableBwallBound@ixD, :ix, FloorB numX F, FloorB 3 numX 4 4 Frame Ø True, PlotStyle Ø [email protected]`D, Axes Ø False, F>F, FrameLabel Ø 8"x", "h", "Wall Boundary Index", ""<F Wall Boundary Index 30 25 h 20 Out[23]= 15 10 5 0 0 10 20 30 40 x Define Boundary Conditions In[24]:= Clear@yD; H* y is the variable used to store the streamfunction. *L Top and bottom… In[25]:= y@ix_, numYD = flow height; y@ix_, 1D = 0; Left and right sides… In[27]:= y@1, iy_D = flow Hiy - 1L dy; y@numX, iy_D = flow Hiy - 1L dy; The wall… In[29]:= Table@Table@y@ix, iyD = 0, 8iy, 1, wallBound@ixD<D, 8ix, 1, numX<D; Define the Equations Numerical_Potential_Flow.nb Define the Equations In[30]:= eqns = Flatten@Table@Table@eqn@ix, iyD, 8iy, wallBound@ixD + 1, numY - 1<D , 8ix, 2, numX - 1<DD ê. dx Ø dx ê. dy Ø dy; In[31]:= eqns = Simplify@eqnsD; In[32]:= Dimensions@eqnsD Out[32]= In[33]:= Out[33]= In[34]:= In[35]:= Out[35]= In[36]:= Out[36]= 84292< 81. y@2, 2D ã 0.00283543 + 0.466542 y@2, 3D + 0.0334581 y@3, 2D, 0.0121551 + 1. y@2, 2D + 1. y@2, 4D + 0.071715 y@3, 3D ã 2.14343 y@2, 3D, 0.0182326 + 1. y@2, 3D + 1. y@2, 5D + 0.071715 y@3, 4D ã 2.14343 y@2, 4D< eqnsP81, 2, 3<T unknowns = Flatten@Table@ Table@y@ix, iyD, 8iy, wallBound@ixD + 1, numY - 1<D , 8ix, 2, numX - 1<DD; 8y@2, 2D, y@2, 3D, y@2, 4D< unknownsP81, 2, 3<T 84292< Dimensions@unknownsD Finding the Solution In[37]:= Out[37]= In[38]:= Timing@sol = Flatten@Solve@eqns, unknownsDD;D 80.144978, Null< ySol = Interpolation@Flatten@Table@8Hix - 1L dx, Hiy - 1L dy, y@ix, iyD<, 8ix, 1, numX<, 8iy, 1, numY<D ê. sol, 1DD; 5 6 Numerical_Potential_Flow.nb In[39]:= Out[39]= ContourPlot@ySol@x, yD, 8x, 0, length<, 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, FrameLabel Ø 8"x", "y"<, PerformanceGoal Ø "Speed", PlotLabel Ø "Streamfunction Around Wall"D Numerical_Potential_Flow.nb In[40]:= 7 >, 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, AspectRatio Ø Automatic, FrameLabel Ø 8"x", "y"<, ContourPlotBySol@x, yD, :x, length - height , length + height PerformanceGoal Ø "Speed", PlotLabel Ø "Streamfunction Around Wall"F Out[40]= Computing the Velocity In[41]:= uX@xx_, yy_D = D@ySol@x, yD, yD ê. x Ø xx ê. y Ø yy; uY@xx_, yy_D = -D@ySol@x, yD, xD ê. x Ø xx ê. y Ø yy; u2@x_, y_D = uX@x, yD ^ 2 + uY@x, yD ^ 2; 8 Numerical_Potential_Flow.nb In[44]:= >, 2 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, PerformanceGoal Ø "Speed", AspectRatio Ø Automatic, ContourPlotB 1 u2@x, yD, :x, length - height , length + height FrameLabel Ø 8"x", "y"<, PlotLabel Ø "U^2ê2 Around Wall"F Out[44]= In[45]:= Cp@x_, y_D = 1 - u2@x, yD ê flow ^ 2; Numerical_Potential_Flow.nb In[46]:= 9 >, 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, PerformanceGoal Ø "Speed", AspectRatio Ø Automatic, ContourPlotBCp@x, yD, :x, length - height , length + height FrameLabel Ø 8"x", "y"<, PlotLabel Ø "Normalized Pressure"F Out[46]= 10 Numerical_Potential_Flow.nb In[47]:= Plot3DBCp@x, yD, :x, length 2 - height 2 , length Out[48]= height 2 >, 8y, 0, height<, PlotPoints Ø 80, PlotLabel Ø "Normalized Pressure"F Out[47]= In[48]:= 2 + Show@%, ViewPoint Ø 81.2`, 1.2`, 1.2`<D Numerical_Potential_Flow.nb In[49]:= PlotBCpB 11 length 2 - height 2 , yF, 8y, 0, height<, AxesLabel Ø 8"y", "Cp"<, PlotLabel Ø "Pressure Along Leading Wall Edge"F Pressure Along Leading Wall Edge Cp 0.5 Out[49]= 0.2 0.4 0.6 0.8 1.0 y -0.5 -1.0 In[50]:= Plot@Cp@x, wallHeightD, 8x, 0, length<, AxesLabel Ø 8"x", "Cp"<, PlotLabel Ø "Pressure Along Wall Height"D Pressure Along Wall Height Cp 1 -0.5 Out[50]= -1.0 -1.5 Flow Past a Cylinder 2 3 4 5 x 12 Numerical_Potential_Flow.nb Flow Past a Cylinder In[51]:= In[52]:= Clear@y, uX, uY, u2D; radius = 0.2 H* meter *L; centerY = height ê 2 H* meter *L; ‡ Define Boundary Conditions Top and bottom… In[54]:= y@ix_, numYD = flow height; y@ix_, 1D = 0; Left and right sides… In[56]:= y@1, iy_D = flow Hiy - 1L dy; y@numX, iy_D = flow Hiy - 1L dy; The cylinder In[58]:= Table@If@HHix - 1L dx - length ê 2L ^ 2 + HHiy - 1L dy - centerYL ^ 2 § radius ^ 2, y@ix, iyD = flow centerYD, 8iy, 1, numY<, 8ix, 1, numX<D; ‡ Define the Equations In[59]:= In[61]:= Out[61]= eqns = Flatten@Table@If@HHix - 1L dx - length ê 2L ^ 2 + HHiy - 1L dy - centerYL ^ 2 § radius ^ 2, -1, eqn@ix, iyDD, 8iy, 2, numY - 1<, 8ix, 2, numX - 1<DD ê. dx Ø dx ê. dy Ø dy; eqns = DeleteCases@eqns, _ ? NegativeD; 84408< Dimensions@eqnsD In[62]:= eqns = Simplify@eqnsD; In[63]:= eqnsP81, 2, 3<T Out[63]= 81. y@2, 2D ã 0.00283543 + 0.466542 y@2, 3D + 0.0334581 y@3, 2D, 1. y@2, 2D + 13.9441 y@3, 3D + 1. y@4, 2D ã 29.8882 y@3, 2D, 1. y@3, 2D + 13.9441 y@4, 3D + 1. y@5, 2D ã 29.8882 y@4, 2D< Numerical_Potential_Flow.nb In[64]:= In[66]:= Out[66]= In[67]:= Out[67]= unknowns = Flatten@Table@If@HHix - 1L dx - length ê 2L ^ 2 + HHiy - 1L dy - centerYL ^ 2 § radius ^ 2, -1, y@ix, iyDD, 8iy, 2, numY - 1<, 8ix, 2, numX - 1<DD; unknowns = DeleteCases@unknowns, _ ? NegativeD; 8y@2, 2D, y@3, 2D, y@4, 2D< unknownsP81, 2, 3<T 84408< Dimensions@unknownsD ‡ Solution The solution is found quickly using Mathematica's built-in Solve function. In[68]:= Out[68]= In[69]:= Timing@sol = Flatten@Solve@eqns, unknownsDD;D 80.137636, Null< ySol = Interpolation@Flatten@Table@8Hix - 1L dx, Hiy - 1L dy, y@ix, iyD<, 8ix, 1, numX<, 8iy, 1, numY<D ê. sol, 1DD; 13 14 Numerical_Potential_Flow.nb In[70]:= Out[70]= ContourPlot@ySol@x, yD, 8x, 0, length<, 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 24, FrameLabel Ø 8"x", "y"<, PerformanceGoal Ø "Speed", PlotLabel Ø "Streamfunction Around Cylinder"D Numerical_Potential_Flow.nb In[71]:= 15 >, 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, PerformanceGoal Ø "Speed", Contours Ø 24, FrameLabel Ø 8"x", "y"<, plt = ContourPlotBySol@x, yD, :x, length - height PlotLabel Ø "Streamfunction Around Cylinder"F Out[71]= , length + height 16 Numerical_Potential_Flow.nb In[72]:= Out[72]= cylinder = GraphicsB:[email protected]`D, CircleB: length 2 , centerY>, radiusF>F Numerical_Potential_Flow.nb In[73]:= Show@plt, cylinderD Out[73]= ‡ Computing the Velocity In[74]:= uX@xx_, yy_D = D@ySol@x, yD, yD ê. x Ø xx ê. y Ø yy; uY@xx_, yy_D = -D@ySol@x, yD, xD ê. x Ø xx ê. y Ø yy; u2@x_, y_D = uX@x, yD ^ 2 + uY@x, yD ^ 2; 17 18 Numerical_Potential_Flow.nb In[77]:= >, 2 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, PerformanceGoal Ø "Speed", AspectRatio Ø Automatic, ContourPlotB 1 u2@x, yD, :x, length - height , length + height FrameLabel Ø 8"x", "y"<, PlotLabel Ø "U^2ê2 Around Cylinder"F Out[77]= In[78]:= Cp@x_, y_D = 1 - u2@x, yD ê flow ^ 2; Numerical_Potential_Flow.nb In[79]:= 19 >, 2 2 2 2 8y, 0, height<, PlotPoints Ø 80, ContourShading Ø False, Contours Ø 18, PerformanceGoal Ø "Speed", AspectRatio Ø Automatic, ContourPlotBCp@x, yD, :x, length - height , length + height FrameLabel Ø 8"x", "y"<, PlotLabel Ø "Normalized Pressure"F Out[79]= 20 Numerical_Potential_Flow.nb In[80]:= Plot3DBCp@x, yD, :x, length 2 - height 2 , length Out[81]= height 2 >, 8y, 0, height<, PlotPoints Ø 80, PlotLabel Ø "Normalized Pressure"F Out[80]= In[81]:= 2 + Show@%, ViewPoint Ø 81.2`, 1.2`, 1.2`<D Numerical_Potential_Flow.nb In[82]:= 21 Show@%%, PlotRange Ø AllD Out[82]= In[83]:= PlotBCpB length 2 , yF, 8y, 0, height<, AxesLabel Ø 8"y", "Cp"<, PlotLabel Ø "Pressure Profile through Cylinder"F Pressure Profile through Cylinder Cp 1 0.2 -1 Out[83]= -2 -3 -4 -5 -6 0.4 0.6 0.8 1.0 y 22 Numerical_Potential_Flow.nb In[84]:= PlotBCpB length 2 + 1.1` radius Cos@qD, centerY + 1.1` radius Sin@qDF, 8q, 0, 2 p<, AxesLabel Ø 8"q", "Cp"<, Ticks Ø :RangeB0, 2 p, p 2 F, Automatic>, PlotLabel Ø "Pressure Profile around Cylinder"F Pressure Profile around Cylinder Cp 2 q 3p p p 2 2p -1 Out[84]= -2 -3 -4 Summary Two dimensional potential flow requires the solution of an elliptic partial differential equation. These problems can be solved very easily with today's computers.
© Copyright 2025 Paperzz