# Extract stiffness tensor C

Hello guys !

So i wanna calculate the components of a 2D stiffness tensor and i already have all the values of the stress (sigma11,sigma22,sigma12) and strains (epsilon11,epsilon22,epsilon12). How can i do that ?

Any ideas about how can we solve that ?

Hi @CHAIkah,

It would help if you provide a little more detail about your problem. For example:

• Are you trying to solve a homogenization problem? (i.e. to find the effective stiffness tensor)
• What format do you have the stresses and strains in? For example, do you know the strains pointwise throughout some domain, e.g. as a FEniCS Function, or did you compute the volume average so that the strains are stored in an array?
• Are you studying plane stress or plane strain?
1 Like

Hey @conpierce8 !
Yes it’s a homogenization problem so I’m trying to extract the effective stiffness tensor.
It’s a 2D square divided into 10 phases each phase contains a different material under compression on the top and bottom boundaries.
I didn’t specify in the code if it’s plane strain/stress
It’s basically like what we have here Periodic Homogenization except that my model doesn’t have any periodic BC.

Hi @CHAIkah,

I’ll be able to help you more effectively if you provide a code example. In the meantime, note the following:

• You need to study three different load cases (uniaxial strain in x, uniaxial strain in y, and shear strain) to get the full 2D stiffness tensor. (This is the approach taken in the periodic homogenization demo.)
• If you prescribe unit strain on the boundary, the 2D stiffness tensor components are simply equal to the volume-averaged stress. You can compute the volume averaged stress using assemble as in the demo that you mentioned.

As an aside, you implicitly choose either plane strain or plane stress when you create the function sigma(v) that defines your constitutive model, as mentioned in the 2D linear elasticity demo.

1 Like

Hi @CHAIkah,

Since this isn’t a working code, I can’t provide a full solution. But, you should be able to use

sigma_fs = TensorFunctionSpace(mesh, "Real", 0)
sigma_test = TestFunction(sigma_fs)
sigma_avg = assemble(sum(inner(sigma(w, i), sigma_test)*dx(i) for i in range(nphases))) / area


to compute the average stress sigma_avg. You should repeat this analysis three times with three different affine boundary conditions u = \bar{\varepsilon}^{(i)} x\quad \forall x \in \partial \Omega, where:

\bar{\varepsilon} = \begin{bmatrix} \varepsilon_{11} \\ \varepsilon_{22} \\ \varepsilon_{12} \end{bmatrix} \\ \bar{\varepsilon}^{(1)} = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix},\quad \bar{\varepsilon}^{(2)} = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \quad \bar{\varepsilon}^{(3)} = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}

Then the average stress obtained for each case will give you the corresponding column of the 2D stiffness matrix.

you mean i need to study three different load cases (uniaxial strain in x , uniaxial strain in y , and shear strain and each time i’ll get a column of the tensor ?

That’s correct. The “effective stiffness” tensor C^{eff} is defined by the relation

\left< \sigma \right> = C^{eff} \left< \varepsilon \right>

where \left<\cdot\right> denotes the volume average. When you apply an affine boundary condition, the volume average of the strain \left< \varepsilon \right> is equal to the “boundary” strain \bar{\varepsilon}. Thus,

\left< \sigma \right> = C^{eff} \bar{\varepsilon}

If we take our 2D constitutive relation to be

C^{eff} = \begin{bmatrix} C^{eff}_{11} & C^{eff}_{12} & C^{eff}_{16} \\ C^{eff}_{12} & C^{eff}_{22} & C^{eff}_{26} \\ C^{eff}_{16} & C^{eff}_{26} & C^{eff}_{66} \end{bmatrix}

and apply a unit strain in the x-direction, for example, the volume average of the stress will be:

\left< \sigma \right> = \begin{bmatrix} C^{eff}_{11} & C^{eff}_{12} & C^{eff}_{16} \\ C^{eff}_{12} & C^{eff}_{22} & C^{eff}_{26} \\ C^{eff}_{16} & C^{eff}_{26} & C^{eff}_{66} \end{bmatrix} \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} C^{eff}_{11} \\ C^{eff}_{12} \\ C^{eff}_{16} \end{bmatrix}

Repeating for \bar{\varepsilon} = [0\,1\,0]^T and \bar{\varepsilon} = [0\,0\,1]^T gives the second and third columns of the effective stiffness tensor, respectively.

i understand now. Thank you it works !
but @conpierce8 this is what i got and i don’t understand why isn’t symmetrical.

-1.572410583195420555e-03 2.216522418232252676e+03 1.108260422906548456e+03
4.414543445680684272e+03 -6.237213042085443552e-04 2.207271410980084511e+03
-6.237146402310145103e-04 1.941621083991628257e+04 9.708105108099545760e+03

@CHAIkah can you share your complete code? I suspect there may be an error with your boundary conditions, since the third column is a linear combination of the first two columns (within discretization error).

Hi @CHAIkah,

1. Your affine Dirichlet boundary conditions should be applied on all boundaries.
2. In order to directly extract the stiffness tensor components from the average stress, you need to apply a unit strain. Otherwise you will need to divide the stress by the strain to find the stiffness tensor components. To achieve a unit strain, you can apply the following affine BCs (corresponding to uniaxial strain in x, uniaxial strain in y, and pure shear strain, respectively):
1. Be careful with the ordering of your stresses. FEniCS gives you the four components of \left< \sigma \right> as a vector:

Therefore, after you

AA = np.delete(AA, 2)


the ordering of the stresses in AA is:

AA[0] = sigma_xx
AA[1] = sigma_xy
AA[2] = sigma_yy


To achieve the familiar symmetric stiffness matrix, you must re-order AA (and BB and CC):

AA = np.delete(AA, 2)[[0, 2, 1]]


See the code below.

from dolfin import *
import numpy as np
import matplotlib.pyplot as plt
#Define geometry
fname = "lamin"
mesh = Mesh(fname + ".xml")
subdomains = MeshFunction("size_t", mesh, fname + "_physical_region.xml")
facets = MeshFunction("size_t", mesh, fname + "_facet_region.xml")
#define materials
Em, num = 50e3 , 0.2
Er, nur = 210e3 , 0.3

material_parameters = [(Em, num), (Er, nur),(Em, num), (Er, nur),(Em, num),\
(Er, nur), (Em, num),(Er, nur), (Em, num),(Er, nur)]

nphases = len(material_parameters)
#define eps and sigma
def eps(v):

def sigma(v,i):
E, nu = material_parameters[i]
lmbda = E*nu/(1+nu)/(1-2*nu)
mu = E/2/(1+nu)
return lmbda*tr(eps(v))*Identity(2) + 2*mu*(eps(v))
# Define function space
W  = VectorFunctionSpace(mesh,"Lagrange", 2)
w  = Function(W)
v = TestFunction(W)
dx = Measure("dx", domain=mesh, subdomain_data=subdomains)

Wint = sum ([inner(sigma(v, i), grad(w))*dx(i) for i in range(nphases)])

#uniaxial strain in y solution
bc_yy = Expression(("0", "x[1]"), degree=2)
bcs1 = [DirichletBC(W, bc_yy, facets, j) for j in [1,2,3,4]]

solve(Wint == 0, w, bcs1)
#compute eff stiffness tensor
area = 100
sigma_fs = TensorFunctionSpace(mesh, "Real", 0)
sigma_test = TestFunction(sigma_fs)
A = assemble(sum([inner(sigma(w, i), sigma_test)*dx(i) for i in range(nphases)]))/ area
AA =np.array(A)
AA = np.delete(AA, 2)[[0,2,1]]

#Shear strain solution
bc_xy = Expression(("x[1]", "x[0]"), degree=2)
bcs2 = [DirichletBC(W, bc_xy, facets, j) for j in [1,2,3,4]]
solve(Wint == 0, w, bcs2)
B = assemble(sum([inner(sigma(w, i), sigma_test)*dx(i) for i in range(nphases)]))/ area
BB =np.array(B)
BB = np.delete(BB, 2)[[0,2,1]]

#uniaxial strain in x solution
bc_xx = Expression(("x[0]","0"), degree=2)
bcs3 = [DirichletBC(W, bc_xx, facets, j) for j in [1,2,3,4]]

solve(Wint == 0, w, bcs3)
C = assemble(sum([inner(sigma(w, i), sigma_test)*dx(i) for i in range(nphases)]))/ area
CC =np.array(C)
CC = np.delete(CC, 2)[[0,2,1]]

#assemble tensor columns
dd = [[m, n, l]for m,n,l in zip(CC,AA,BB)]
np.savetxt("stiffnessmatrix.txt", dd)


On my machine, this produces the following output in stiffnessmatrix.txt:

  1.526894178315140598e+05  3.272079349476299831e+04 -2.101344925113153399e-03
3.272079349479604207e+04  9.543267626480710169e+04 -4.449651732026041126e-03
-1.050665393418484094e-03 -2.224827810501039949e-03  6.996483562031936890e+04


which is symmetric to within discretization error.

1 Like

After thinking about this problem some more, I have realized I should make one minor correction to my answer(s). The 2D strain vector is generally formulated as

\varepsilon = \begin{bmatrix} \varepsilon_{11} \\ \varepsilon_{22} \\ \gamma_{12} \end{bmatrix} = \begin{bmatrix} \varepsilon_{11} \\ \varepsilon_{22} \\ 2\varepsilon_{12} \end{bmatrix}

Then the 2D elasticity relation is written as

\begin{bmatrix} \sigma_{11} \\ \sigma_{22} \\ \sigma_{12} \end{bmatrix} = \begin{bmatrix} C_{11} & C_{12} & C_{16} \\ C_{12} & C_{22} & C_{26} \\ C_{16} & C_{26} & C_{66} \end{bmatrix} \begin{bmatrix} \varepsilon_{11} \\ \varepsilon_{22} \\ \gamma_{12} \end{bmatrix}

Thus, the DirichletBC for a unit shear strain should be

bc_xy = Expression(("x[1]/2", "x[0]/2"), degree=2)


rather than

bc_xy = Expression(("x[1]", "x[0]"), degree=2)


as I originally posted.

Yeah i rectified the mistake !
Thank you very much !

@conpierce8
if i wanna extract the displacement vector and strain and stress tensors in each subdomain, how can i do that from this code ?

this is what i tried to do for now:

    for i in range(nphases) :
sig11 = assemble(sigma(w,i)[0,0]*dx(i))
sig22 = assemble(sigma(w,i)[1,1]*dx(i))
sig12 = assemble(sigma(w,i)[1,0]*dx(i))
eps11 = assemble(eps(w)[0,0]*dx(i))
eps22 = assemble(eps(w)[1,1]*dx(i))
eps12 = assemble(eps(w)[1,0]*dx(i))
ux = assemble(w[0]*dx(i))
uy = assemble(w[1]*dx(i))


and then print them using np.array

The above code should work, but note that you need to divide by the area of the subdomain in order to obtain the correct average stresses, strains, and displacements.

1 Like