# Interpretation Stiffness matrix P1edge/P1

**URL:** <https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454>\
**Category:** General Discussion\
**Created:** [January 27, 2022, 3:04pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454 "2022-01-27T15:04:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [January 27, 2022, 3:04pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/1 "2022-01-27T15:04:11Z")

</div>

Hello all,

I need some help to understand a result. I have the following mesh.

 ![mesh](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/79252a00e21591fb1fc3e92a4fefd2284b5f9d32.png)

I define the FE space P1edge on the Coarse mesh (mesh done only with the red edges) TH.  
I define the FE space P1 on the Fine mesh (all edges/vertices) Th. The boundary edges are labelled 3.

Then I compute the stiffness matrix using these two spaces.

```auto
fespace VH(TH,P1edge);
fespace Vh(Th,P1);
varf vtest(u,v) = int1d(Th, 3)(u*v);
matrix = vtest(VH, Vh);

```

```auto
1.179078516 0 0 1.179078516 0 0
0 0 0.389630518 1.610369482 0 0
0 0 1.52782145 0.47217855 0 0
0 0 1.16256891 0 1.178643716 0
1.610369482 0.389630518 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1.592555475 0.4074445248
0.47217855 1.52782145 0 0 0 0
0 0 0 0 0.4074445248 1.592555475
0 1.16256891 0 0 0 1.178643716

```

I don’t understand why for example the second term in the first line (the term A(1,2) is nul and same for the lines 4 and 10), since each DoF of Vh located on the boundary edges should interact with the two DoF of VH, as is in the second line, I suppose.

Could someone, explain me (detailed me) the calculation that it is done ?  
I can interpret the case in which I use P0edge but not the case in which I use P1edge.

Thank you in advance for your help,

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 28, 2022, 4:01pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/2 "2022-01-28T16:01:36Z")

</div>

Without the numbering of mesh it is impossible to given a answer.

And I do not see what is mesh TH  
the matrix is 10x 6 =\> only 3 edge in the mesh TH =\> MeshS but int1d(Th, 3)(u\*v);  
do not work with this mesh.

Please send the 2 mesh Th and TH.

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [January 29, 2022, 6:26am UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/3 "2022-01-29T06:26:30Z")

</div>

Hello,

Sorry I have done a mistake.

My coarse mesh TH is :

 ![meshTH](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/463e5d98962d3b47c88e1fdbbb8a83162b0cf887.png)

My fine mesh Th is:

 ![meshTh](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/11b7b2ffdbb6040686e50c9b2f2e90890830e6a4.png)

I use the FE space P1Edge on the coarse mesh TH (2 basis per edge, thus 6 basis/6 column in the matrix).

I use the FE space P1 on the fine mesh Th (thus 10 DoF/10 lines in the matrix).

Then I compute the stiffness matrix between these two spaces,

```auto
fespace VH(TH,P1edge);
fespace Vh(Th,P1);
varf vtest(u,v) = int1d(Th)(u*v/lenEdge*2);
matrix = vtest(VH, Vh);

```

and I obtain the following stiffness matrix:

```auto
1.179078516 -0.1790785162 -0.1790785162 1.179078516 0 0
0 0 0.389630518 1.610369482 0 0
0 0 1.52782145 0.47217855 0 0
0 0 1.16256891 -0.1625689098 1.178643716 -0.1786437161
1.610369482 0.389630518 0 0 0 0
0 0 0 0 0 0
  0 0 0 0 1.592555475 0.4074445248
0.47217855 1.52782145 0 0 0 0
 0 0 0 0 0.4074445248 1.592555475
 -0.1625689098 1.16256891 0 0 -0.1786437161 1.178643716

```

I want to multiply` v in Vh` by a linear polynomial that is defined on the edge of the coarse mesh TH.  
I have some difficulties to interpret the results.

Could you explain me (detailed me) the calculation that it is done ?  
For a given Edge E in TH, is all the DoF of Vh multiplied by the same polynomial ?

Thank you in advance for your help,

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 30, 2022, 5:42pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/4 "2022-01-30T17:42:39Z")

</div>

```auto
load "msh3"
load "Element_Pkedge"
mesh Th = trunc(square(3,3),x-y<0);
mesh TH = trunc(square(1,1),x-y<0);
plot(Th,TH,wait=1);
int[int] l4=[4];
//mesh TH=Th;//extract(Th,label=l4);
fespace VH(TH,P1edge);
fespace Vh(Th,P1);
varf vtest(u,v) = int1d(Th, 4)(u*v);
matrix H = vtest(VH, Vh);
cout << H << endl; 	

```

le matrix :

```auto
  -- Square mesh : nb vertices =16 , nb triangles = 18 , nb boundary edges 12
  -- Square mesh : nb vertices =4 , nb triangles = 2 , nb boundary edges 4
# HashMatrix Matrix (COO) 0x7fcb34caf800
# n m nnz half fortran state  
10 6 8 0 0 0 0 
         0 2 -0.028929219009093901788
         0 3 0.19559588567576058349
         1 2 0.07044162180172902632
         1 3 0.26289171153160428851
         3 2 0.26289171153160428851
         3 3 0.07044162180172902632
         6 2 0.19559588567576058349
         6 3 -0.028929219009093894849

times: compile 0.006945s, execution 0.00024s, mpirank:0

```

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [January 31, 2022, 6:52am UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/5 "2022-01-31T06:52:46Z")

</div>

Hello @frederichecht ,

Thank you for you reply,

What did you illustrate through this example ?

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 31, 2022, 3:39pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/6 "2022-01-31T15:39:36Z")

</div>

I do that to understand and see the they are a bug.

So a build 2 mesh Th and TH the same caracteristic but not the same numbering  
.I a see I make at erreur in test I

```auto
varf vtest(u,v) = int1d(Th)(u*v);

```

So we compute integral on boundary edge of Th ( small boundary edge of length 1/3 or \sqrt(2)/3)

And we use a quadrature formulas qf3pE (with 3 points exact of P5 ) on each edges …

so in my example 4 vertex (0,1,3,6) on the big edge (the 2 dof are 2,3 and the edge number is 1)

the P1edge are orthogonal polynom of edge such that le sum is 1.  
So the interpolation point are (1 ± \sqrt{1/3} )/2

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 1, 2022, 2:18pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/7 "2022-02-01T14:18:24Z")

</div>

Hello @frederichecht,

Thank you for your message. I understand better the calculation that is done.

One last thing:

1. You use the quadrature formulae qfpE (3 points of interpolations) but you give only two of them (1±√1/3)/2. I think the last one is 0.5, isn’t it ?

2. “The P1edge are orthogonal polynomial of edge such that le sum is 1”: it seems that for a given edge this couple is not unique. Do you know their explicit expression ?

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 1, 2022, 2:32pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/8 "2022-02-01T14:32:27Z")

</div>

No it is qfpE2 (2 points pf interpolation)  
then the it is Lagrange polynom corresponding to this 2 points (1±√1/3)/2,

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 1, 2022, 3:10pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/9 "2022-02-01T15:10:21Z")

</div>

Thank you for your message,

and about their expressions ? (I would like to do some calculation by hand to check my implementation).

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 1, 2022, 3:46pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/10 "2022-02-01T15:46:30Z")

</div>

You put you 6 points on vertical edge  
this point a the gauss point on each sub edge =\> exact integration for P3 polynom.

on each edge of size 1/3 4 function  
first classical P1 on edge l2=x, l1=1-x on 0,1 big edge  
second = f1, f2 function on gauss point (1±√1/3)/2. small edge

It is you job to do the computation but freefem++ make no error!

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 1, 2022, 4:16pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/11 "2022-02-01T16:16:54Z")

</div>

Thank you for your explanations,

These elements of explanation are enough for me to make some calculations,

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 3, 2022, 12:38pm UTC](https://community.freefem.org/t/interpretation-stiffness-matrix-p1edge-p1/1454/12 "2022-02-03T12:38:37Z")

</div>


