RuntimeError: Factor is exactly singular (and overflow encountered in square in FiPy)
RuntimeError: Factor is exactly singular (and overflow encountered in square in FiPy)
我试图在 python 中使用 FiPy 解决 pde。它显示 RuntimeError: Factor is exactly singular。在这些方程中不是这种情况,但在我计算的大多数方程中都是如此。
The equations are-
∂u/∂t = σu(1-u/C) - (1+αv)uv/(1+h(1+αv)u) +D∇^2 u and
∂v/∂t = (1+αv)uv/(1+h(1+αv)u) - v +D∇^2 v
from fipy import *
nx=ny=100
dx=dy=0.25
L=dx*nx
dt=0.01
sigma=10.0
h=0.1
C=0.8
alp=0.57 #alpha
mesh =Grid2D(dx=dx,dy=dy,nx=nx,ny=ny)
u=CellVariable(name='u Variable',mesh=mesh)
v=CellVariable(name='v Variable',mesh=mesh)
u.setValue(GaussianNoiseVariable(mesh=mesh,mean=0.18,variance=0.005))
v.setValue(GaussianNoiseVariable(mesh=mesh,mean=0.28,variance=0.005))
D=35
eq_u=(TransientTerm(coeff=1.0, var=u)==sigma*u*(1-v/C) -((1+alp*v)*v*u)/(1+(1+alp*v)*h*u) +ImplicitDiffusionTerm(coeff=D,var=u))
eq_v=(TransientTerm(coeff=1.0, var=v)==((1+alp*v)*v*u)/(1+(1+alp*v)*h*u) +v +ImplicitDiffusionTerm(coeff=1.0, var=v))
#creating viewer
if __name__ == "__main__":
viewer_u=Viewer(vars=u,datamin=0.,datamax=1.0)
viewer_u.plot()
viewer_v=Viewer(vars=v,datamin=0.,datamax=1.0)
viewer_v.plot()
#solving
steps=50000
for step in range(steps):
eq_u.solve(var=u,dt=dt)
eq_v.solve(var=v,dt=dt)
if __name__ == "__main__":
viewer_u.plot()
viewer_v.plot()
错误是-
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:41: RuntimeWarning: invalid value encountered in double_scalars
if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:36: RuntimeWarning: overflow encountered in square
error0 = numerix.sqrt(numerix.sum((L * x - b)**2))
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:41: RuntimeWarning: overflow encountered in square
if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\variables\variable.py:1122: RuntimeWarning: overflow encountered in multiply
return self._BinaryOperatorVariable(lambda a, b: a*b, other)
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\variables\variable.py:1122: RuntimeWarning: invalid value encountered in multiply
return self._BinaryOperatorVariable(lambda a, b: a*b, other)
Traceback (most recent call last):
File "e:\VS_Codes\Python\V_1.py", line 32, in <module>
eq_v.solve(var=v,dt=dt)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\terms\term.py", line 178, in solve
solver._solve()
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\scipySolver.py", line 26, in _solve
self.var[:] = numerix.reshape(self._solve_(self.matrix, self.var.ravel(), numerix.array(self.RHSvector)), self.var.shape)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py", line 34, in _solve_
permc_spec=3)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\sparse\linalg\dsolve\linsolve.py", line 326, in splu
ilu=False, options=_options)
RuntimeError: Factor is exactly singular
python有没有更好的pde求解器
谢谢
您的 FiPy 代码与您的方程不一致。你正在解决
如果我更正 FiPy 代码以与您的数学一致,那么问题会在结果出现分歧之前运行更长时间(这就是为什么您使用 scipy
LU 求解器(其他求解器)得到 Factor is exactly singular
有其他故障模式,但都不同))。分歧似乎是在 u
或 v
变得非常小或为负时。我并不完全清楚,因为系统似乎可以容忍一些接近零和负值。我不清楚 u
和 v
是否应该保持积极,但如果不保持积极,事情往往会变得很糟糕。
现在,我建议让你的方程更多 implicit, coupling them together, and sweeping,因为这些方程非常非线性,结果不太可能收敛。
我还建议您在调试时在 1D 中工作。更容易看到发生了什么。
我试图在 python 中使用 FiPy 解决 pde。它显示 RuntimeError: Factor is exactly singular。在这些方程中不是这种情况,但在我计算的大多数方程中都是如此。 The equations are-
∂u/∂t = σu(1-u/C) - (1+αv)uv/(1+h(1+αv)u) +D∇^2 u and
∂v/∂t = (1+αv)uv/(1+h(1+αv)u) - v +D∇^2 v
from fipy import *
nx=ny=100
dx=dy=0.25
L=dx*nx
dt=0.01
sigma=10.0
h=0.1
C=0.8
alp=0.57 #alpha
mesh =Grid2D(dx=dx,dy=dy,nx=nx,ny=ny)
u=CellVariable(name='u Variable',mesh=mesh)
v=CellVariable(name='v Variable',mesh=mesh)
u.setValue(GaussianNoiseVariable(mesh=mesh,mean=0.18,variance=0.005))
v.setValue(GaussianNoiseVariable(mesh=mesh,mean=0.28,variance=0.005))
D=35
eq_u=(TransientTerm(coeff=1.0, var=u)==sigma*u*(1-v/C) -((1+alp*v)*v*u)/(1+(1+alp*v)*h*u) +ImplicitDiffusionTerm(coeff=D,var=u))
eq_v=(TransientTerm(coeff=1.0, var=v)==((1+alp*v)*v*u)/(1+(1+alp*v)*h*u) +v +ImplicitDiffusionTerm(coeff=1.0, var=v))
#creating viewer
if __name__ == "__main__":
viewer_u=Viewer(vars=u,datamin=0.,datamax=1.0)
viewer_u.plot()
viewer_v=Viewer(vars=v,datamin=0.,datamax=1.0)
viewer_v.plot()
#solving
steps=50000
for step in range(steps):
eq_u.solve(var=u,dt=dt)
eq_v.solve(var=v,dt=dt)
if __name__ == "__main__":
viewer_u.plot()
viewer_v.plot()
错误是-
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:41: RuntimeWarning: invalid value encountered in double_scalars
if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:36: RuntimeWarning: overflow encountered in square
error0 = numerix.sqrt(numerix.sum((L * x - b)**2))
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py:41: RuntimeWarning: overflow encountered in square
if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\variables\variable.py:1122: RuntimeWarning: overflow encountered in multiply
return self._BinaryOperatorVariable(lambda a, b: a*b, other)
C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\variables\variable.py:1122: RuntimeWarning: invalid value encountered in multiply
return self._BinaryOperatorVariable(lambda a, b: a*b, other)
Traceback (most recent call last):
File "e:\VS_Codes\Python\V_1.py", line 32, in <module>
eq_v.solve(var=v,dt=dt)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\terms\term.py", line 178, in solve
solver._solve()
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\scipySolver.py", line 26, in _solve
self.var[:] = numerix.reshape(self._solve_(self.matrix, self.var.ravel(), numerix.array(self.RHSvector)), self.var.shape)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fipy\solvers\scipy\linearLUSolver.py", line 34, in _solve_
permc_spec=3)
File "C:\Users\Harshit Rathore\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\sparse\linalg\dsolve\linsolve.py", line 326, in splu
ilu=False, options=_options)
RuntimeError: Factor is exactly singular
python有没有更好的pde求解器 谢谢
您的 FiPy 代码与您的方程不一致。你正在解决
如果我更正 FiPy 代码以与您的数学一致,那么问题会在结果出现分歧之前运行更长时间(这就是为什么您使用 scipy
LU 求解器(其他求解器)得到 Factor is exactly singular
有其他故障模式,但都不同))。分歧似乎是在 u
或 v
变得非常小或为负时。我并不完全清楚,因为系统似乎可以容忍一些接近零和负值。我不清楚 u
和 v
是否应该保持积极,但如果不保持积极,事情往往会变得很糟糕。
现在,我建议让你的方程更多 implicit, coupling them together, and sweeping,因为这些方程非常非线性,结果不太可能收敛。
我还建议您在调试时在 1D 中工作。更容易看到发生了什么。