是否有方程式的代码
或者对于二维的正弦戈登方程,因为我想改变一些边界值来查看结果?
是否有方程式的代码
这实际上在 Dolfin 中很容易做到:
from dolfin import *
# define mesh, function space (piecewise linear)
mesh = UnitSquareMesh(64,64)
V = FunctionSpace(mesh,'CG',1)
# inhomogeneous boundary conditions (otherwise the solution is trivial)
bc = DirichletBC(V, Constant(1.0), lambda x,on_boundary: on_boundary)
# define bi(non)linear form
# note that nonlinear problems need u to be a Function, not TestFunction
u = Function(V)
v = TestFunction(V)
F = inner(grad(u),grad(v))*dx + sin(u)*v*dx
# solve using Newton method (Jacobian is computed automatically)
solve(F==0,u,bc)
plot(u,interactive=True)
目录下还有一个nonlinear-poissondemo demo/undocumented,也展示了如何进入定义更复杂的非线性形式以及如何控制求解器参数。