我一直在用runge 4和射击方法实现一个python程序,根据一个特殊的相似变量求解自然对流的数值方程。然而,当我绘制它的时候,我没有得到正确的解决方案。我在什么地方犯了错吗?
嗨!
从自然对流的特殊情况出发,我们得到了这些相似方程。
第一个描述流体流动,第二个描述热流。
"Pr“是Prandtl的意思,它基本上是流体力学(普兰德尔)中使用的无量纲数:

这些方程受以下边界值的影响,即板附近的温度大于边界层外的温度,且流体速度远离边界层0。

我一直试图用Runge 4和射击方法来解决这些问题,把边值问题转化为一个初值问题。打靶法的实现方法是牛顿法。
然而,我没有得到正确的解决方案。正如你在下面看到的,温度(红色)是上升的,因为我们正在远离板块,而它应该是指数下降。流体速度(蓝色)更一致,但我认为它应该上升得更快,然后下降得更快。这里的曲线更平滑。

事实上,我们有一个由2耦合的ODE组成的系统。但是,现在,我只想找到两个首字母值中的一个(例如f''(0) = a,试图找到a),这样我们就可以得到边值问题(射击法)的解。一旦找到,我想我们就有了解决整个问题的办法。
我想我应该管理这两个(f''(0) =a;theta'(0) = b),但是我不知道如何并行地管理这两个。最后想一想,如果我试图得到θ‘的初始值(所以θ’(0)),我就不能得到正确的热廓线。
以下是代码:
"""
The goal is to resolve a 3rd order non-linear ODE for the blasius problem.
It's made of 2 equations (flow / heat)
f''' = 3ff'' - 2(f')^2 + theta
3 Pr f theta' + theta'' = 0
RK4 + Shooting Method
"""
import numpy as np
import math
from scipy.integrate import odeint
from scipy.optimize import newton
from edo_solver.plot import plot
from constants import PRECISION
def blasius_edo(y, t, prandtl):
f = y[0:3]
theta = y[3:5]
return np.array([
# flow edo
f[1], # f' = df/dn
f[2], # f'' = d^2f/dn^2
- 3 * f[0] * f[2] + (2 * math.pow(f[1], 2)) - theta[0], # f''' = - 3ff'' + 2(f')^2 - theta,
# heat edo
theta[1], # theta' = dtheta/dn
- 3 * prandtl * f[0] * theta[1], # theta'' = - 3 Pr f theta'
])
def rk4(eta_range, shoot):
prandtl = 0.01
# initial values
f_init = [0, 0, shoot] # f(0), f'(0), f''(0)
theta_init = [1, shoot] # theta(0), theta'(0)
ci = f_init + theta_init # concatenate two ci
# note: tuple with single argument must have "," at the end of the tuple
return odeint(func=blasius_edo, y0=ci, t=eta_range, args=(prandtl,))
"""
if we have :
f'(t_0) = fprime_t0 ; f'(eta -> infty) = fprime_inf
we can transform it into :
f'(t_0) = fprime_t0 ; f''(t_0) = a
we define the function F(a) = f'(infty ; a) - fprime_inf
if F(a) has a root in "a",
then the solutions to the initial value problem with f''(t_0) = a
is also the solution the boundary problem with f'(eta -> infty) = fprime_inf
our goal is to find the root, we have the root...we have the solution.
it can be done with bissection method or newton method.
"""
def shooting(eta_range):
# boundary value
fprimeinf = 0 # f'(eta -> infty) = 0
# initial guess
# as far as I understand
# it has to be the good guess
# otherwise the result can be completely wrong
initial_guess = 10 # guess for f''(0)
# define our function to optimize
# our goal is to take big eta because eta should approach infty
# [-1, 1] : last row, second column => f'(eta_final) ~ f'(eta -> infty)
fun = lambda initial_guess: rk4(eta_range, initial_guess)[-1, 1] - fprimeinf
# newton method resolve the ODE system until eta_final
# then adjust the shoot and resolve again until we have a correct shoot
shoot = newton(func=fun, x0=initial_guess)
# resolve our system of ODE with the good "a"
y = rk4(eta_range, shoot)
return y
def compute_blasius_edo(title, eta_final):
ETA_0 = 0
ETA_INTERVAL = 0.1
ETA_FINAL = eta_final
# default values
title = title
x_label = "$\eta$"
y_label = "profil de vitesse $(f'(\eta))$ / profil de température $(\\theta)$"
legends = ["$f'(\eta)$", "$\\theta$"]
eta_range = np.arange(ETA_0, ETA_FINAL + ETA_INTERVAL, ETA_INTERVAL)
# shoot
y_set = shooting(eta_range)
plot(eta_range, y_set, title, legends, x_label, y_label)
compute_blasius_edo(
title="Convection naturelle - Solution de similitude",
eta_final=10
)发布于 2020-08-12 02:41:45
发布于 2020-08-12 08:10:28
您正在实现附加但错误的边界条件f''(0) = theta'(0),因为两个插槽在拍摄方法中获得相同的初始值。你需要将它们分开,给出2个自由变量,因此需要二维牛顿法或任何其他非标量函数的求解者。
您还可以使用solve_bvp例程进行合理的初始猜测。
https://stackoverflow.com/questions/61636155
复制相似问题