I saw the Poisson equation of two domains with boundaries in Multiphenics and wanted to write relevant code using mixedfunction
in Fenics. After applying the Lagrange multiplier at the boundary, the following problems occurred. Why is that?
from dolfin import *
import matplotlib.pyplot as plt
mesh = UnitSquareMesh(20,20)
mesh_dom = MeshFunction("size_t",mesh,mesh.topology().dim(),0)
marker = MeshFunction("size_t",mesh,mesh.topology().dim()-1,0)
for f in facets(mesh):
marker[f] = 0.5 - DOLFIN_EPS < f.midpoint().y() < 0.5 + DOLFIN_EPS
class zone1(SubDomain):
def inside(self,x,on_boundary):
return between(x[1],(0.5,1.))
zone1().mark(mesh_dom,1)
submesh1 = MeshView.create(marker,1)
submesh2 = MeshView.create(mesh_dom,0)
submesh3 = MeshView.create(mesh_dom,1)
# plot(submesh3)
# plot(submesh2)
# plot(submesh1)
# plt.show()
u = FunctionSpace(submesh2,"CG",1)
v = FunctionSpace(submesh3,"CG",1)
l = FunctionSpace(submesh1,"CG",1)
W = MixedFunctionSpace(u,v,l)
dU = Measure("dx",domain=W.sub_space(0).mesh())
dV = Measure("dx",domain=W.sub_space(1).mesh())
dL = Measure("dS",domain=W.sub_space(2).mesh())
(u1,v1,l1) = TrialFunctions(W)
(du,dv,dl) = TestFunctions(W)
w = Function(W)
def boundary(x):
return x[1] < DOLFIN_EPS
bc = DirichletBC(u, Constant(0.0), boundary)
#定义变分问题
a1 = inner(grad(u1),grad(du))*dU + l1("-")*du("-")*dL
a2 = inner(grad(v1),grad(dv))*dV - l1("+")*dv("+")*dL
a3 = u1("-")*dl("-")*dL - v1("+")*dl("+")*dL
a = a1+a2+a3
L = du*dU + dv*dV+Constant(0.)*dl*dL
Eu = a
solve(a2 == L,w,bc)
plot(w.sub(0))
The specific error forms are as follows
Traceback (most recent call last):
File "/mnt/d/pythonProject1/mixed_poisson.py", line 72, in <module>
solve(a2 == L,w,bc)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 233, in solve
_solve_varproblem(*args, **kwargs)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 258, in _solve_varproblem
problem = MixedLinearVariationalProblem(eq_lhs_forms, eq_rhs_forms, u._functions, bcs,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/problem.py", line 94, in __init__
assert (len(a) == len(u) * len(u))
^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
I found that the error might lie in the writing of the variational form. However, this variational form is almost the same as that in the original source code, which is really strange.
a = [[inner(grad(u1), grad(v1))*dx(1), 0 , l("-")*v1("-")*dS ],
[0 , inner(grad(u2), grad(v2))*dx(2), - l("+")*v2("+")*dS ],
[m("-")*u1("-")*dS , - m("+")*u2("+")*dS , 0 ]]
f = [v1*dx(1) , v2*dx(2) , 0 ]