我正在尝试解决以下涉及向量泊松方程的“测试问题”:
不均匀性给出为:
例如是指向以原点为中心的长度为 0.2 个单位的立方体中的 x 方向的向量。
我尝试使用下面列出的 Python 代码来解决这个问题。不幸的是,代码总是会产生一条错误消息(也在下面列出),说,定义为a=inner(grad(A),grad(v))*dx,不是双线性形式。有谁知道我如何解决这个问题?
谢谢
Python代码:
from fenics import *
from mshr import *
#define the domain
domain=Box(Point(-1,-1,-1),Point(1,1,1))
mesh = generate_mesh(domain, 32)
V=VectorFunctionSpace(mesh,"P",1)
#plot(mesh)
#define the boundary conditions
def boundary(x,on_boundary):
return on_boundary
A_D=Constant((0,0,0))
bc=DirichletBC(V,A_D,boundary)
#define the inhomogenity J
codex="x[0]>-ext&&x[0]<ext&&x[1]>-ext&&x[1]<ext&&x[2]>-ext&&x[2]<ext?1:0"
codex=codex.replace("ext","0.1")
codey=codez="0"
#define variational problem
A=TrialFunction(V)
v=TestFunction(V)
J=Expression((codex,codey,codez),degree=1)
a=inner(grad(A),grad(v))*dx
L=dot(J,v)*dx
#solve the system
A=Function(V)
solve(L==a,A,bc)
plot(A)
错误信息:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to define linear variational problem a(u, v) == L(v) for all v.
*** Reason: Expecting the left-hand side to be a bilinear form (not rank 1).
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
***
*** DOLFIN version: 2018.1.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
