0% found this document useful (0 votes)
32 views6 pages

2024 of Shooting

The document describes solving a boundary value problem for the Blasius equation using the shooting method in Python. The Blasius equation is a third-order nonlinear ODE that arises in fluid dynamics. It is reformulated as a first-order system and solved numerically using Runge-Kutta fourth order. The secant method is used to find the shooting parameter. The numerical solution converges as the domain size L increases. The code can be extended to compute velocity components from the solution, with applications to fluid stream problems discussed with PhD students.

Uploaded by

getachewbonga09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

2024 of Shooting

The document describes solving a boundary value problem for the Blasius equation using the shooting method in Python. The Blasius equation is a third-order nonlinear ODE that arises in fluid dynamics. It is reformulated as a first-order system and solved numerically using Runge-Kutta fourth order. The secant method is used to find the shooting parameter. The numerical solution converges as the domain size L increases. The code can be extended to compute velocity components from the solution, with applications to fluid stream problems discussed with PhD students.

Uploaded by

getachewbonga09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2024_of_Shooting

February 16, 2024

0.1 Non-linear ODE: Shooting Method using Python


0.1.1 Blasius’ boundary layer equation in fluid dynamics
The nonolinear third-order ODE
𝑑3 𝑓 𝑑2 𝑓
2 + 𝑓 = 0, 0<𝜂<∞
𝑑𝜂3 𝑑𝜂2
with boundary condition
𝑑𝑓 𝑑𝑓
𝑓(0) = 0, (0) = 0, (∞) = 1,
𝑑𝜂 𝑑𝜂
is a classical problem in fluid dynamics. From the solution 𝑓(𝜂), the velocity components
𝑢(𝑥, 𝑦)(𝑚/𝑠) and 𝑣(𝑥, 𝑦)(𝑚/𝑠) of the stream close to a plane wall can be computed:

𝑑𝑓 𝜈𝑢∞ 𝑑𝑓 𝑢∞
𝑢(𝑥, 𝑦) = 𝑢∞ (𝜂), 𝑣(𝑥, 𝑦) = √ (𝜂 (𝜂) − 𝑓(𝜂)), 𝜂 = 𝑦√
𝑑𝜂 4𝑥 𝑑𝜂 𝜈𝑥

where 𝑢∞ (𝑚/𝑠) is the free stream velocity far from the wall and 𝜈(𝑚2 /𝑠) is the kinematic viscosity.
Observe that one of the BCs is given at 𝜂 = ∞. #### Shooting method, The Blasius’ equation
can be formulated as a first-order system of ODEs. Let 𝑢1 = 𝑓, 𝑢2 = 𝑓 ′ and 𝑢3 = 𝑓 ″

𝑑𝑢1
= 𝑢2 , 𝑢1 (0) = 0
𝑑𝜂
𝑑𝑢2
= 𝑢3 , 𝑢2 (0) = 0
𝑑𝜂
𝑑𝑢3 1
= − 𝑢1 𝑢3 , 𝑢3 (0) = 𝑠
𝑑𝜂 2

where 𝑠, the shooting parameter is to be computed so that 𝑢2 (𝑠, 𝐿) = 1, where 𝐿 is large number.

Python Implimentation
[7]: #important modules
import sys
import numpy as np
import matplotlib.pyplot as plt

[8]: # We use Runge kutta order four for solving the sistem
def RungeKutta4(f, a, L, u, N):
"""

1
A function for numerical solution using RK4
Imputs:
=======
f : the right side fucntion of the system of ODE
a : eta = a in the domain interval [a, L]
L : eta = L
u : the initial condition
N : number of grid points
Returns:
========
grid points
numerical solution
"""
h = (L - a) / N # step size
result = [] # empty list for storing the numerical solution
grid = [] # empty list for storing the grid points
result.append(u)
grid.append(a)
x = a
for i in range(1, N + 1): # implementation of RK4 algorithm
k1 = f(x, u)
k2 = f(x + h / 2, u + h * k1 / 2)
k3 = f(x + h / 2, u + h * k2 / 2)
k4 = f(x + h, u + h * k3)
u = u + h * (k1 + 2 * k2 + 2 * k3 + k4)/6
x = x + h
result.append(u)
grid.append(x)
return np.array(grid), np.array(result)

[9]: # initial condition with the shooting parameter s,


def u0(s):
return np.array([0, 0, s])

[10]: # F(s) = u_2(s, L) - 1


def F(s, L):
u = u0(s)
grid, result = RungeKutta4(f, a, L, u, N)
F = result[-1,1] - b
#F = (result[-1])[1] - b
return F

[11]: #formulate as a first-order system and define the right side function for the␣
↪nonlinear ode

def f(t, u):


f = np.zeros(3)
f[0] = u[1]

2
f[1] = u[2]
f[2] = -0.5 * u[0] * u[2]
return f

[12]: # the secant method for solving the algebric equation F(s) = 0
def Secant(F, s0, s1, tol, itr, L):
global s
F0 = F(s0, L)
F1 = F(s1, L)
iteration_counter = 0

while abs(F1) > tol and iteration_counter < itr:


try:
denominator = (F1 - F0) / (s1 - s0)
s = s1 - F1 / denominator
except ZeroDivisionError:
print('Error! - denominator zero for s =', s1)
sys.exit(1) # Abort with error
s0 = s1
s1 = s
F0 = F1
F1 = F(s1, L)
iteration_counter = iteration_counter + 1
# here, either a solution is found or too many iterations
if abs(F(s,L)) > tol:
iteration_counter = -1
return s, iteration_counter

[13]: # Parameters
a = 0
b = 1
L = 6
N = 100 # number of grid points

# initializing the parameter s, and set the tollerance eps


s0 = 1.0
s1 = 2.0
eps = 1.0e-6
max_iteration = 100
s, no_iterations = Secant(F, s0, s1, eps, max_iteration, L)
print('s =', s)
print('number of iteration = ', no_iterations)

s = 0.33256594137380135
number of iteration = 6

3
[14]: # Now we use the approperaite shooting parameter in the initial condition and␣
↪solve for the system of ODE

u = u0(s)
grid, result = RungeKutta4(f, a, L, u, N)

[16]: # Ploting the results


plt.figure(figsize=(10, 6))
plt.plot(grid, result[:, 0], grid, result[:, 1], grid, result[:, 2])
plt.xlabel('$\eta$')
plt.ylabel("f")
plt.ylim([0,3])
plt.grid(True)
plt.title(" Blasius' Boundary layer ")
plt.legend(['f', "f'", "f''"])
plt.savefig('Shooting.png')
plt.show()

Comparing result for different values of 𝐿 (say 𝐿 = 1, 3, 6, 16) and check the convergence
of the 𝑓(𝜂)- curve.
[17]: Ls = [1, 3, 6, 16]
ss = []
no_iterationss = []
results = []

4
plt.figure(figsize=(12, 8))
for l in range(0,len(Ls)):
s, it = Secant(F, s0, s1, eps, max_iteration, Ls[l])
ss.append(s)
no_iterationss.append(it)
u = u0(s)
grid, result = RungeKutta4(f, a, Ls[l], u, N)
results.append(result) # here we store the solution of f for different␣
↪value of L

plt.subplot(2, 2, l+1)
plt.plot(grid, result[:, 1],'r')
plt.xlabel('$\eta$')
plt.ylabel("f")
plt.ylim([0,1.2])
plt.grid(True)
plt.legend(["f', where L = "+ str(Ls[l])])

plt.show()

5
0.2 Q: Extend the code to compute the velocity components using the formula
given in the slide. Discus the application with PhD students from fluid
streem.
[ ]:

[ ]:

You might also like