ValueError: too many values to unpack

Can anyone help me in fixing this error.
ValueError: too many values to unpack (expected 2)

mesh = UnitSquareMesh(10,10)
RT1 = FiniteElement("RT", mesh.ufl_cell(), 1)
CG1 = FiniteElement("CG", mesh.ufl_cell(), 1)
mixed_A = MixedElement([RT1, CG1, RT1])
mixed_B = MixedElement([RT1, CG1])
W_A = FunctionSpace(mesh, mixed_A)
W_B = FunctionSpace(mesh, mixed_B)
(vpsi, vphi, vbigphi) = TestFunctions(W_A)
(vq, vu ) = TestFunctions(W_B)
trials_1A = TrialFunction(W_A)
trials_1B = TrialFunction(W_B) 
Sol_A, Sol0_A = Function(W_A) , Function(W_A)
Sol_B, Sol0_B = Function(W_B) , Function(W_B)
(psi, phi, bigphi) = split(Sol_A)
(q, u) = split(Sol_B)
(psi0, phi0, bigphi0) = split(Sol0_A)
(q0, u0) = split(Sol0_B)
(psi_1, phi_1, bigphi_1) = split(trials_1A)
(q_1, u_1) = split(trials_1B)
def sigma(u):
  return u**2
def beta_new(u):
  return u**2
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
phi00 = Expression(" 1 + sin (x[1] + x[0] - t )", degree = 2, t = 0)
bc1 = DirichletBC(W_B.sub(1), Constant(0.0), boundary)
bc2 = DirichletBC(W_A.sub(1), phi00, boundary)
phi0 = interpolate(phi00, W_A.sub(1).collapse())
uinitial = Expression(" exp(x[1] + x[0] - t)", t = 0, degree = 2)
u0 = interpolate(uinitial, W_B.sub(1).collapse())
f1 = Expression(" - 3*exp(x[0] - t + x[1]) ", degree = 3, t=0)
f2 = Expression("2*sin(t + x[0] + x[1])", degree = 2, t=0 )
t = 0
dt = 0.1
T = 1
t = dt
A1 = inner(psi_1, vbigphi)*dx + div(vbigphi)*phi_1*dx - inner(sigma(u0)*psi_1, vpsi)*dx + inner(bigphi_1, vpsi)*dx + div(bigphi_1)*vphi*dx
nn = FacetNormal(mesh)
nrelems = mesh.num_cells()  ## computes number of elements
nrsides = mesh.num_edges() ## computes number of sides
pp = Expression(" 1 + sin (x[1] + x[0] - t )", degree = 2, t = 0)
while t <= T:
  f2.t = t
  b1_3 = inner(f2, vphi)*dx
  pp.t = t
  b1_1 = -pp*dot(nn, vbigphi)*ds
  B1 = b1_3 + b1_1
  solve(A1 == B1, Sol_A)
  psi= Sol_A.split(0)
  phi = Sol_A.split(1)
  bigphi = Sol_A.split(2)
  u00 = Constant(0.0)
  A2 = inner(q_1, vq)*dx + div(vq)*u_1*dx - dt*div(q_1)*vu*dx + u_1*vu*dx
  ## 2nd set (q, u) >> 2nd eqn >> 3rd term (u^{n-1} , u)
  DD = dt*beta_new(u0)*dot(bigphi_1,bigphi_1)
  b_2 = dt*(inner(DD,vu)*dx) + u0*vu*dx
  f1.t = t
  b_21 = dt*(inner(f1, vu)*dx)
  B2 = ( b_21 + b_2)
  solve(A2 == B2, Sol_B, bc1)
  u = Sol_B.split(1)
  q = Sol_B.split(0)
  phi0.assign(phi)
  psi0.assign(psi)
  bigphi0.assign(bigphi)
  u0.assign(u)
  q0.assign(q)
  t += dt
'''

Dear @Nisha_Sharma,
Please follow this forums suggestions (Read before posting: How do I get my question answered?) by posting a minimal code example, and not your full code.
Remove every line not required to produce the error message (and especially the while loop). Please do also remove all variables not used in the code.

For instance, to produce your error message, you only need to define the functions, testfunctions and trial functions used in your second PDE (A2==B2). You do not need to solve A1== B1, and should therefore remove the variational form of A1 == B1, and all variables not used in A2==B2.

Python functions can return multiple variables . These variables can be stored in variables directly. This is a unique property of Python , other programming languages such as C++ or Java do not support this by default.

The valueerror: too many values to unpack occurs during a multiple-assignment where you either don’t have enough objects to assign to the variables or you have more objects to assign than variables. If for example myfunction() returned an iterable with three items instead of the expected two then you would have more objects than variables necessary to assign to.

1 Like