# Too many values to unpack!

**URL:** <https://fenicsproject.discourse.group/t/too-many-values-to-unpack/9936>\
**Category:** General\
**Created:** [December 9, 2022, 7:02am UTC](https://fenicsproject.discourse.group/t/too-many-values-to-unpack/9936 "2022-12-09T07:02:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamad1365](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mohamad1365/32/1605_2.png) [@mohamad1365](https://fenicsproject.discourse.group/u/mohamad1365)\
**Post date:** [December 9, 2022, 7:02am UTC](https://fenicsproject.discourse.group/t/too-many-values-to-unpack/9936/1 "2022-12-09T07:02:26Z")

</div>

Hello’ I am trying to model a cantilever under distributed load considering large deformation assumption and voigt notation, but when I run the code, I received the following error message:

ValueError: too many values to unpack (expected 2)

I think it would be related to nonlinear terms that are existed in strain tensor!  
I would be appreciated if anyone can help me about this issue.  
here is the entire code:

from dolfin import \*  
import matplotlib.pyplot as plt  
import matplotlib.patches as mpatches  
from matplotlib.patches import Rectangle  
import numpy as np  
from ufl.core.multiindex import indices

# Problem definition

Len = 10;  
W = 1;  
t=0.1;  
Load=1150000.0

# Mesh for cantilever beam

mesh = BoxMesh(Point(0, 0, 0), Point(Len, W, t), 60, 4, 4)  
mesh.init()  
V = VectorFunctionSpace(mesh, ‘P’, 2) # displacements

# Define boundary condition

# Left boundary

class Left(SubDomain):  
def inside(self, x, on\_boundary):  
return near(x[0], 0.0)

# Right boundary

class Right(SubDomain):  
def inside(self, x, on\_boundary):  
return near(x[0], Len)

# Top boundary

class TopBoundary(SubDomain):  
def inside(self, x, on\_boundary):  
return on\_boundary and near(x[2], t)

#Boundary segments  
left = Left()  
top\_boundary = TopBoundary()  
boundaries = MeshFunction(“size\_t”, mesh,0)  
boundaries.set\_all(0)  
left.mark(boundaries, 1)  
top\_boundary.mark(boundaries, 2)

ds= Measure(“ds”, domain=mesh, subdomain\_data=boundaries)

# define variational variables

du=TrialFunction(V) # Incremental displacement  
del\_u=TestFunction(V) # Test function  
u=Function(V) # Displacement

# Geometric dimension

d = u.geometric\_dimension()

# d x d identiy matrix

# Kronecker delta

I = Identity(d)

#index notation  
i,j,k,l= indices(4)

# ----------------------Parameters------------

c\_11 = 2.695652e9  
c\_12 = 1.65217e9  
c\_13 = 1.65217e9  
c\_33 = 2.695652e9  
c\_22= 2.695652e9  
c\_23= 1.65217e9  
c\_55= 1.04347e9  
c\_44 = 1.04347e9  
c\_66= 1.04347e9

#---------------------------------------------  
#------------------Elasticity tensor c^E  
C = as\_tensor([[c\_11, c\_12, c\_13, 0., 0., 0.],  
[c\_12, c\_22, c\_23, 0., 0., 0.],  
[c\_13, c\_23, c\_33, 0., 0., 0.],  
[0., 0., 0., c\_44, 0., 0],  
[0., 0., 0., 0., c\_55, 0.],  
[0., 0., 0., 0., 0., c\_66]])

#-----------------rewrite the tensor into a vector using Voigt notation  
def strain\_voigt(ten):  
return as\_vector([ten[0,0],ten[1,1],ten[2,2],2_ten[1,2],2_ten[0,2],2\*ten[0,1]])

#------------------rewrite a vector into a tensor using Voigt notation  
def stress\_voigt(vec):  
return as\_tensor([[vec[0], vec[5], vec[4]],  
[vec[5], vec[1], vec[3]],  
[vec[4], vec[3], vec[2]]])

#----------------define the function for the strain tensor in fenics notation  
def epsilon(u):  
return as\_tensor((1./2._(u[i].dx(j)+u[j].dx(i))+(u[k].dx(i))_(u[k].dx(j))),[i,j])

# return as\_tensor((1./2.\*(u[i].dx(j)+u[j].dx(i))),[i,j])

def sigma(u):  
return stress\_voigt((dot(C, strain\_voigt(epsilon(u)))))

# loading in the surface normal direction , the traction vector in Pa

tr=Constant((0.0,0.0,Load))

# Body Force , the gravity acceleration in m/s^2

bf=Constant((0,0,0))   
left\_end\_displacement = Constant((0.0, 0.0, 0.0))   
bc = [DirichletBC(V, left\_end\_displacement, left)]

# variational formulation

Form=sigma(u)[i,j]\*epsilon(del\_u)[i,j]\*dx-bf[j]\*del\_u[j]\*dx + tr[j]\*del\_u[j]\*ds(2)

Gain=derivative(Form,u,du)

solve(Form == 0, u, bc, J=Gain,solver\_parameters={“newton\_solver”:{“linear\_solver”: “mumps”, “absolute\_tolerance”: 1E-9, “relative\_tolerance”: 1E-3, “maximum\_iterations”: 20, “error\_on\_nonconvergence”: True } },form\_compiler\_parameters={“cpp\_optimize”: True, “representation”: “quadrature”, “quadrature\_degree”: 2} )

print(‘min/max u:’,u.vector().get\_local().min(),u.vector().get\_local().max())

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [December 9, 2022, 7:44am UTC](https://fenicsproject.discourse.group/t/too-many-values-to-unpack/9936/2 "2022-12-09T07:44:52Z")

</div>

Please use markdown format on your code, i.e.

````python
```python
# place your code here

```

````

and make sure that the code is a minimal reproducible example, meaning that you only include sufficient code to reproduce the example.

---

<div class="post-metadata">

**Author:** ![mohamad1365](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mohamad1365/32/1605_2.png) [@mohamad1365](https://fenicsproject.discourse.group/u/mohamad1365)\
**Post date:** [December 9, 2022, 6:01pm UTC](https://fenicsproject.discourse.group/t/too-many-values-to-unpack/9936/3 "2022-12-09T18:01:38Z")

</div>

```python
from dolfin import *
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import Rectangle
import numpy as np
from ufl.core.multiindex import indices

# Problem definition
Len = 10;
W = 1;
t=0.1;
Load=1150000.0

# Mesh for cantilever beam
mesh = BoxMesh(Point(0, 0, 0), Point(Len, W, t), 60, 4, 4)
mesh.init()
V = VectorFunctionSpace(mesh, 'P', 2) # displacements
# Define boundary condition
# Left boundary
class Left(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0], 0.0)
# Right boundary
class Right(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0], Len)	
# Top boundary
      
class TopBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and near(x[2], t)		
		
 #Boundary segments
left = Left()
top_boundary = TopBoundary()
boundaries = MeshFunction("size_t", mesh,0)
boundaries.set_all(0)
left.mark(boundaries, 1)
top_boundary.mark(boundaries, 2)

ds= Measure("ds", domain=mesh, subdomain_data=boundaries)	

# define variational variables

du=TrialFunction(V) # Incremental displacement
del_u=TestFunction(V) # Test function
u=Function(V) # Displacement

# Geometric dimension
d = u.geometric_dimension()
# d x d identiy matrix

# Kronecker delta
I = Identity(d)

#index notation
i,j,k,l= indices(4)

# ----------------------Parameters------------
c_11 = 2.695652e9
c_12 = 1.65217e9
c_13 = 1.65217e9
c_33 = 2.695652e9
c_22= 2.695652e9
c_23= 1.65217e9
c_55= 1.04347e9
c_44 = 1.04347e9
c_66= 1.04347e9

#---------------------------------------------
#------------------Elasticity tensor c^E
C = as_tensor([[c_11, c_12, c_13, 0., 0., 0.],
               [c_12, c_22, c_23, 0., 0., 0.],
               [c_13, c_23, c_33, 0., 0., 0.],
               [0., 0., 0., c_44, 0., 0],
               [0., 0., 0., 0., c_55, 0.],
               [0., 0., 0., 0., 0., c_66]])

#-----------------rewrite the tensor into a vector using Voigt notation
def strain_voigt(ten):
    return as_vector([ten[0,0],ten[1,1],ten[2,2],2*ten[1,2],2*ten[0,2],2*ten[0,1]])

#------------------rewrite a vector into a tensor using Voigt notation
def stress_voigt(vec):
    return as_tensor([[vec[0], vec[5], vec[4]],
                      [vec[5], vec[1], vec[3]],
                      [vec[4], vec[3], vec[2]]])
		

#----------------define the function for the strain tensor in fenics notation
def epsilon(u):
    return as_tensor((1./2.*(u[i].dx(j)+u[j].dx(i))+(u[k].dx(i))*(u[k].dx(j))),[i,j])	
   # return as_tensor((1./2.*(u[i].dx(j)+u[j].dx(i))),[i,j])
    
def sigma(u):
    return stress_voigt((dot(C, strain_voigt(epsilon(u)))))

	
# loading in the surface normal direction , the traction vector in Pa
tr=Constant((0.0,0.0,Load))
# Body Force , the gravity acceleration in m/s^2
bf=Constant((0,0,0))	
left_end_displacement = Constant((0.0, 0.0, 0.0))	
bc = [DirichletBC(V, left_end_displacement, left)]
	
	
# variational formulation

Form=sigma(u)[i,j]*epsilon(del_u)[i,j]*dx-bf[j]*del_u[j]*dx + tr[j]*del_u[j]*ds(2)

Gain=derivative(Form,u,du)

solve(Form == 0, u, bc, J=Gain,solver_parameters={"newton_solver":{"linear_solver": "mumps", "absolute_tolerance": 1E-9, "relative_tolerance": 1E-3, "maximum_iterations": 20, "error_on_nonconvergence": True } },form_compiler_parameters={"cpp_optimize": True, "representation": "quadrature", "quadrature_degree": 2} )

print('min/max u:',u.vector().get_local().min(),u.vector().get_local().max())
```
