1 回答
TA贡献1788条经验 获得超4个赞
像使用扩散接口方法一样平滑 Dirac delta 函数可能是一个好主意(请参见此处的方程 11、12 和 13 )。所以,这是一种选择
def delta_func(x, epsilon):
return ((x < epsilon) & (x > -epsilon)) * \
(1 + numerix.cos(numerix.pi * x / epsilon)) / 2 / epsilon
2 * epsilon是狄拉克三角函数的宽度,选择为几个网格间距宽。您也可以只使用1 / dx并选择离狄拉克三角函数位置最近的网格点。但是,我认为这变得更加依赖网格。这是一维的工作代码。
from fipy import *
nx = 50
dx = dy = 0.025 # grid spacing
L = dx * nx
mesh = Grid1D(dx=dx, nx=nx)
phi = CellVariable(name="solution variable", mesh=mesh, value=0.)
Gamma=1
def delta_func(x, epsilon):
return ((x < epsilon) & (x > -epsilon)) * \
(1 + numerix.cos(numerix.pi * x / epsilon)) / 2 / epsilon
x0 = L / 2.
eqG = TransientTerm() == DiffusionTerm(coeff=Gamma)+ delta_func(mesh.x - x0, 2 * dx)
valueTopLeft = 0
valueBottomRight = 1
timeStepDuration = 10 * 0.9 * dx ** 2 / (2 * 0.8)
steps = 100
viewer = Viewer(phi)
for step in range(steps):
res = eqG.solve(var=phi, dt=timeStepDuration)
print(step)
viewer.plot()
input('stopped')
在这里,epsilon = 2 * dx,任意选择,并且 delta 函数以 为中心L / 2。2D 只需要乘以函数。
添加回答
举报
