要了解FiPy的工作原理,我想使用固定端点来解决Euler–Bernoulli beam equation:
w''''(x) = q(x,t), w(0) = w(1) = 0, w'(0) = w'(1) = 0.
为简单起见,让q(x,t) = sin(x)
。
如何在FiPy中定义和解决它?如何相对于方程式中唯一的自变量指定源项sin(x)
?
from fipy import CellVariable, Grid1D, DiffusionTerm, ExplicitDiffusionTerm
from fipy.tools import numerix
nx = 50
dx = 1/nx
mesh = Grid1D(nx=nx, dx=dx)
w = CellVariable(name="deformation",mesh=mesh,value=0.0)
valueLeft = 0.0
valueRight = 0.0
w.constrain(valueLeft, mesh.facesLeft)
w.constrain(valueRight, mesh.facesRight)
w.faceGrad.constrain(valueLeft, mesh.facesLeft)
w.faceGrad.constrain(valueRight, mesh.facesRight)
# does not work:
eqX = DiffusionTerm((1.0, 1.0)) == numerix.sin(x)
eqX.solve(var=w)
答案 0 :(得分:1)
这似乎是您问题的可行版本
App.Current.Dispatcher.InvokeAsync(() => sendToDevice());
运行此命令后,FiPy解决方案似乎与分析结果非常接近。
OP实施中的两个重要更改。
使用from fipy import CellVariable, Grid1D, DiffusionTerm
from fipy.tools import numerix
from fipy.solvers.pysparse.linearPCGSolver import LinearPCGSolver
from fipy import Viewer
import numpy as np
L = 1.
nx = 500
dx = L / nx
mesh = Grid1D(nx=nx, dx=dx)
w = CellVariable(name="deformation",mesh=mesh,value=0.0)
valueLeft = 0.0
valueRight = 0.0
w.constrain(valueLeft, mesh.facesLeft)
w.constrain(valueRight, mesh.facesRight)
w.faceGrad.constrain(valueLeft, mesh.facesLeft)
w.faceGrad.constrain(valueRight, mesh.facesRight)
x = mesh.x
k_0 = 0
k_1 = -1
k_2 = 2 + np.cos(L) - 3 * np.sin(L)
k_3 = -1 + 2 * np.sin(L) - np.cos(L)
w_analytical = numerix.sin(x) + k_3 * x**3 + k_2 * x**2 + k_1 * x + k_0
w_analytical.name = 'analytical'
# does not work:
eqX = DiffusionTerm((1.0, 1.0)) == numerix.sin(x)
eqX.solve(var=w, solver=LinearPCGSolver(iterations=20000))
Viewer([w_analytical, w]).plot()
raw_input('stopped')
是引用用于FiPy方程的空间变量的正确方法。
指定求解器和迭代次数。该问题似乎收敛缓慢,因此需要大量迭代。根据我的经验,四阶空间方程通常需要良好的前置条件才能快速收敛。您可能会尝试将Trilinos求解程序包与Fipy结合使用,以使其更好地工作,因为它具有更多可用的预处理器。
为mesh.x
使用一个显式浮点数,以避免Python 2.7中的整数数学(从注释中编辑)