使用FiPy求解圆柱坐标中的扩散方程不正确

时间:2019-02-13 00:07:14

标签: python differential-equations fipy cylindrical

使用FiPy求解圆柱几何中扩散方程的稳态解与从其他软件(例如,Mathematica)获得的解有很大不同。

等式是:

$ 0 = \ frac {1} {r} \ frac {d} {dr} \ left(\ frac {r} {T ^ {1/2}} \ frac {dT} {dr} \ right)+ cte * T ^ {3/2} $

这意味着,通过使用CylindricalGrid1D网格,我们可以将公式写为:

mesh = CylindricalGrid1D(nr=100, dr=0.01, origin=0.0)
T = CellVariable(name='temperature', mesh=mesh, hasOld=True)
r = mesh.cellCenters()

#BC's
T.constrain(0., mesh.facesRight)
T.faceGrad.constrain(0.,mesh.facesLeft)

#initial temperature profile
T.setValue( 1-r**2)

eq = 0 == DiffusionTerm( coeff=T**(-1/2), var=T) + 20*ImplicitSourceTerm(coeff=T**(1/2), var=T)

viewer = Viewer(vars=T)
eq.solve()

viewer.plot()
raw_input(" Press <enter> to proceed...")

在这里,我设置cte = 20,但是无论此值是多少,问题仍然存在。我在左边得到解决方案,而Mathematica提供的解决方案在右边:

plots

然后,我尝试按照建议对此类非线性方程进行扫描。因此,我没有eq.solve(),而是这样做了:

current_residual = 1.0e100
desired_residual = 1e-5

while current_residual > desired_residual:

    current_residual = eq.sweep()
    T.updateOld()

但是我得到了错误:

/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/linearLUSolver.py:66: RuntimeWarning: overflow encountered in square
  error0 = numerix.sqrt(numerix.sum((L * x - b)**2))
/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/linearLUSolver.py:71: RuntimeWarning: overflow encountered in square
  if (numerix.sqrt(numerix.sum(errorVector**2)) / error0)  <= self.tolerance:
/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/linearLUSolver.py:71: RuntimeWarning: invalid value encountered in double_scalars
  if (numerix.sqrt(numerix.sum(errorVector**2)) / error0)  <= self.tolerance:
/home/antonio/.local/lib/python2.7/site-packages/fipy/tools/numerix.py:966: RuntimeWarning: overflow encountered in square
  return sqrt(add.reduce(arr**2))
/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/linearLUSolver.py:58: RuntimeWarning: overflow encountered in multiply
  b = b * (1 / maxdiag)
Traceback (most recent call last):
  File "stack.py", line 26, in <module>
    current_residual = eq.sweep()
  File "/home/antonio/.local/lib/python2.7/site-packages/fipy/terms/term.py", line 254, in sweep
    solver._solve()
  File "/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/scipySolver.py", line 61, in _solve
    self.var[:] = numerix.reshape(self._solve_(self.matrix, self.var.ravel(), numerix.array(self.RHSvector)), self.var.shape)   
  File "/home/antonio/.local/lib/python2.7/site-packages/fipy/solvers/scipy/linearLUSolver.py", line 64, in _solve_
    permc_spec=3)
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/dsolve/linsolve.py", line 257, in splu
    ilu=False, options=_options)
RuntimeError: Factor is exactly singular

最后,我通过使用变量V = T ^ {1/2}以等价形式重写了初始方程。很容易看到,随着V方程变为

$ 0 = \ frac {1} {r} \ frac {d} {dr} \ left(r \ frac {dV} {dr} \ right)+ \ frac {cte} {2} V ^ 3 $ < / p>

所以我然后使用了代码:

mesh = CylindricalGrid1D(nr=100, dr=0.01, origin=0.0)
V = CellVariable(name='V', mesh=mesh, hasOld = True)
r = mesh.cellCenters()

#BC's
V.constrain(0., mesh.facesRight)
V.faceGrad.constrain(0.,mesh.facesLeft)

#initial V profile
V.setValue( 1-r**2)

eqV = 0 == DiffusionTerm( coeff=1., var=V) + 20*0.5*ImplicitSourceTerm(coeff=V*V, var=V)

T = V*V
viewer = Viewer(vars=T)

eqV.solve()

viewer.plot()
raw_input(" Press <enter> to proceed...")

和获得的轮廓非常相似,但是第一个FiPy解决方案或Mathematica的y轴值都不相同!扫描产生的错误与以前相同。

1 个答案:

答案 0 :(得分:0)

我不认为这个问题除了T = 0之外没有其他解决方案。此外,对于初始条件和/或cte的不同值,该解决方案似乎不稳定。考虑到T形式的方程在T = 0时具有无限扩散性,因此这种不稳定性并不完全令人惊讶。

我怀疑Mathematica在执行第一组图形中的工作大致与FiPy所做的一样,这是显示此非线性问题的第一步。这不是答案;只是第一个猜测。但是,无论是解析还是数字,我对使用Mma解决PDE一无所知。

V解决方案经过一扫后的图看起来不一样,顺便说一句,因为您没有调整初始条件。应该是:

V.setValue( numerix.sqrt(1-r**2))