这其实只是计算流体力学的一份作业,边做作业边学了一些关于 Sage 的新的东西,就发到博客上了。主要的内容都在代码注释里了,此处不再赘述。全部内容按照 CC-BY 3.0 协议发布。
# This program is a sage script, and NOT a standard python script, so you can only run it
# in sage, rather than just load the script into python interperater.
# f(x) is the shape function of the surface of the wing
f1(x) = 0.6 * (0.2969*sqrt(x) - 0.126*x - 0.3516*x^2 + 0.2843*x^3 - 0.1015*x^4)
f2(x) = 0
f = piecewise([[(0, 1), f1], [(1, 4), f2]])
# Description: generate points on which grid will be generated, and then
# map them to the upper plane of complex plane.
# Implementation: variable s is the real part of the point on which grid
# will be generated. w_i stores the mapped points of upper surface of
# the wing and the lower surface of the wing.
w1 = []; w2 = []
for j in range(100):
s = (j/50)^1.4
w1.append(sqrt(s+f(s).n()*I).n())
w2.append(sqrt(s+f(s).n()*(-1)*I).n()*(-1))