在 FENICS 中求解向量泊松方程

计算科学 泊松 芬尼克斯 向量
2021-12-11 16:06:23

我正在尝试解决以下涉及向量泊松方程的“测试问题”:

2A=JxΩ=[1,1]3
A=0xΩ

不均匀性J给出为:

J(x)=exifmax(abs(x1,x2,x3))<0.1

例如J是指向以原点为中心的长度为 0.2 个单位的立方体中的 x 方向的向量。

我尝试使用下面列出的 Python 代码来解决这个问题。不幸的是,代码总是会产生一条错误消息(也在下面列出),说a(A,v),定义为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
*** -------------------------------------------------------------------------
1个回答

好的,我会回答我自己的问题:

问题出在solve(L==a,A,bc)需要替换为solve(a==L,A,bc). 这两个版本似乎不可互换。B=project(curl(A),V)这样做会产生如下图所示的磁场:在此处输入图像描述