# Element stiffness matrix

**URL:** <https://fenicsproject.discourse.group/t/element-stiffness-matrix/4116>\
**Category:** variational formulation\
**Created:** [September 17, 2020, 10:02pm UTC](https://fenicsproject.discourse.group/t/element-stiffness-matrix/4116 "2020-09-17T22:02:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ss636](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@ss636](https://fenicsproject.discourse.group/u/ss636)\
**Post date:** [September 17, 2020, 10:02pm UTC](https://fenicsproject.discourse.group/t/element-stiffness-matrix/4116/1 "2020-09-17T22:02:21Z")

</div>

Hello,

I am trying to figure, how to print out Element Stiffness matrix for a particular cell in the mesh?

I understand it is trivial to print out the global/assembled stiffness matrix.

Any suggestions will be helpful.

thanks,  
-ss

---

<div class="post-metadata">

**Author:** ![bhaveshshrimali](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bhaveshshrimali/32/124_2.png) [@bhaveshshrimali](https://fenicsproject.discourse.group/u/bhaveshshrimali)\
**Post date:** [September 18, 2020, 3:57am UTC](https://fenicsproject.discourse.group/t/element-stiffness-matrix/4116/2 "2020-09-18T03:57:36Z")

</div>

You can do something like: `assemble_local(form, cell)` to get the local stiffness corresponding to `cell`. For e.g.,

```auto
from dolfin import *

# check for a trivial case of a mesh comprised of two elements
mesh = UnitSquareMesh(1, 1)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
for i, cell in enumerate(cells(mesh)):
    if i==1: # for the second element
        A = assemble_local(inner(grad(u), grad(v)) *dx, cell) # A is the local stiffness

```

I have personally never done this, but it is easily verifiable by a simple hand calculation.

---

<div class="post-metadata">

**Author:** ![lyunfei1211](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lyunfei1211/32/6600_2.png) [@lyunfei1211](https://fenicsproject.discourse.group/u/lyunfei1211)\
**Post date:** [April 17, 2024, 12:41pm UTC](https://fenicsproject.discourse.group/t/element-stiffness-matrix/4116/3 "2024-04-17T12:41:34Z")

</div>

I’d like to ask you a question. Do you know how to get the unit degree matrix in dolfinx v0.7.2?
