问题描述
我正在研究混合制剂。在运行代码时,它给我一个错误:UFLException:无法添加具有不同形状的表达式。我是第一次接触fenics。有人可以帮我吗 完整的代码是
mesh = UnitSquareMesh(10,10)
RT1 = VectorElement("RT",mesh.ufl_cell(),1)
CG1 = FiniteElement("CG",1)
RT2 = VectorElement("RT",1)
mixed = MixedElement([RT1,CG1,RT1])
W = FunctionSpace(mesh,mixed)
(vpsi,vphi,vbigphi ) = TestFunctions(W)
trials_1 = TrialFunction(W)
Sol1,Sol0 = Function(W),Function(W)
(psi1,phi1,bigphi1) = split(Sol1)
(psi0,phi0,bigphi0) = split(Sol0)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS or
x[1] < DOLFIN_EPS or x[1] > 1.0 - DOLFIN_EPS
u00 = Constant(0.0)
bc1 = DirichletBC(V2,u00,boundary)
uinitial = Expression(" exp(x[1] + x[0] - t)",t = 0,degree = 2)
u0 = interpolate(uinitial,V2)
q0 = interpolate(grad(uinitial),V1)
a2 = (dot(bigphi1,vpsi) - ( 1/(1 + u0**2) + 1 )*dot(psi1,vpsi) )* dx
解决方法
我的代码与之合作
RT1 = FiniteElement("RT",mesh.ufl_cell(),1)
代替
RT1 = VectorElement("RT",1)