无法添加具有不同形状的表达式

2024-05-14 03:03:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在fenics使用混合配方。运行代码时,它给了我一个错误:UFLException:无法添加具有不同形状的表达式。我是费尼茨的新手。有人能帮我吗 完整的代码是

mesh = UnitSquareMesh(10,10)
RT1 = VectorElement("RT", mesh.ufl_cell(), 1)
CG1 = FiniteElement("CG", mesh.ufl_cell(), 1)
RT2 = VectorElement("RT", mesh.ufl_cell(), 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

Tags: or代码cellepsrtmeshdolfinufl