我有下面的偏微分方程
我想知道如何用fipypython表示源代码项。我试过以下方法
from fipy import *
nx = 50
ny = 1
dx = dy = 0.025 # grid spacing
L = dx * nx
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)
phi = CellVariable(name="solution variable", mesh=mesh, value=0.)
convCoeff = ((10.,), (10.,))
Gamma = 1.
eqX = TransientTerm() == DiffusionTerm(coeff=Gamma) - ConvectionTerm(coeff=convCoeff) + t*numerix(exp(x*y))
valueTopLeft = 0
valueBottomRight = 1
X, Y = mesh.faceCenters
facesTopLeft = ((mesh.facesLeft & (Y > L / 2)) | (mesh.facesTop & (X < L / 2)))
facesBottomRight = ((mesh.facesRight & (Y < L / 2)) |
(mesh.facesBottom & (X > L / 2)))
#
phi.constrain(valueTopLeft, facesTopLeft)
phi.constrain(valueBottomRight, facesBottomRight)
timeStepDuration = 10 * 0.9 * dx ** 2 / (2 * D)
steps = 10
results = []
for step in range(steps):
eqX.solve(var=phi, dt=timeStepDuration)
results.append(phi.value)
这是行不通的。根据fipy手册,我看到他们说源代码术语是以它们出现的方式表示的,建议使用numerix模块而不是numpy等其他模块。我不知道我在这个代码中丢失了什么。谢谢
我发现代码有很多问题
t
未定义numerix
和exp
是毫无意义的,并且给出了一个错误D
未定义要使源依赖于时间,
t
需要是Variable
,以便在时间改变时重新评估源。时间变量也需要在每一步更新下面是实际运行的代码的更正版本
相关问题 更多 >
编程相关推荐