我想知道如何将狄拉克三角函数表示为Fipy中的源项。我想解下面的方程
我尝试了以下代码
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.)
Gamma=1
delta=1 # I want knowing how to make this right.
eqG = TransientTerm() == DiffusionTerm(coeff=Gamma)+delta
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 * 0.8)
steps = 100
results=[]
for step in range(steps):
eqG.solve(var=phi, dt=timeStepDuration)
results.append(phi.value)
代码正在运行,但我想要确切的狄拉克三角函数。我查了numerix模块,但找不到这样的函数。Sx1和Sy1是常数。我正在使用Python2.7
像扩散界面方法一样平滑Dirac delta函数可能是一个好主意(见方程11、12和13here)。所以,这是一个选择
2 * epsilon
是Dirac delta函数的宽度,被选择为几个网格间距。也可以使用1 / dx
并选择距离Dirac delta函数位置最近的网格点。但是,我认为这会变得更加依赖于网格。这是1D中的工作代码这里,
epsilon = 2 * dx
是一个任意选择,delta函数以L / 2
为中心。2D只需要将函数相乘。你知道吗相关问题 更多 >
编程相关推荐