Here is my minimal code:
mesh = Mesh(‘mesh.xml’)# a square mesh
ele_d = FiniteElement(“DG”, mesh.ufl_cell(), 0)
ele_h = FiniteElement(“BDM”, mesh.ufl_cell(), 1)
ele_u = VectorElement(“CG”, mesh.ufl_cell(), 1)
W = MixedElement([ele_d, ele_h, ele_u])
W = FunctionSpace(mesh, W)
(d,h,u)= TrialFunctions(W)
(q,k,v) = TestFunctions(W)
Xold = Function(W)
(dold,hold,uold)= Xold.split()
Xnew = Function(W)
(dnew,hnew,unew)= Xnew.split()
def sigma(u):
return 2.0muepsilon(u)+lmbda*tr(epsilon(u))*Identity(len(u))
class LeftBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0],-0.5) and
left_boundary = LeftBoundary()
class RightBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0],0.5)
right_boundary = RightBoundary()
class BottomBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[1],-0.5)
bottom_boundary = BottomBoundary()
class TopBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[1],0.5)
top_boundary = TopBoundary()
boundary_edge_function = MeshFunction(‘size_t’, mesh, 1)
boundary_edge_function.set_all(0)
left_boundary.mark(boundary_edge_function,1)
right_boundary.mark(boundary_edge_function,2)
bottom_boundary.mark(boundary_edge_function,3)
top_boundary.mark(boundary_edge_function,4)
ubctop = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 4)
ubcbot = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 3)
ubcleft = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 1)
ubcright = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 2)
bc_u = [ubctop, ubcbot,ubcleft,ubcright]
E_u = inner(sigma(u),grad(v))*dx
p_u = LinearVariationalProblem(lhs(E_u), rhs(E_u), unew, bc_u)
solver_u = LinearVariationalSolver(p_u)
conc_u = File ("./mixed0608/u.pvd")
while t<=150.0 :
t += deltaT
iter = 0
err = 1
while err > tol:
iter += 1
solver_u.solve()
err_disp = errornorm(unew,uold,norm_type = 'l2',mesh = None)
uold.assign(unew)
if err_disp < tol:
print ('Iterations:', iter, ', Total time', t)
if round(t*1e4) % 10 == 0:
conc_u << unew
print ('Simulation completed')
produced the following error:
Error: Unable to define linear variational problem a(u, v) = L(v) for all v.
*** Reason: Expecting the solution variable u to be a member of the trial space.
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
I shortened the exception a bit to make it more readable. Thank you for taking the time to help me out!