# Implementing new finite element in FreeFEM

**URL:** https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602
**Category:** General Discussion
**Created:** [March 16, 2022, 7:26am UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602 "2022-03-16T07:26:32Z")
**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: [March 16, 2022, 7:26am UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/1 "2022-03-16T07:26:32Z")

</div>

Hello all,

I would like to have some feedback about implementing new finite element in FreeFEM.  
How difficult and how long it is to implement new finite element (in particular non conforming) in FreeFEM ?

For anyone who has already done (or tried it), feel free to share your feedback (the type of finite element, the difficulties you have faced with, if it works well or not, …)

Thank you in advance,

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: [March 16, 2022, 9:51am UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/2 "2022-03-16T09:51:49Z")

</div>

This depend strongly of DoF of the finite element,  
but generally it is not so difficult.

I can help you if you need.

---

<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: [March 24, 2022, 2:40pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/3 "2022-03-24T14:40:49Z")

</div>

Hello @frederichecht

Thank you for you reply,

I would like to implement a non conforming Finite Element which is very popular (in the fluid dynamics domain).

I have explained this finite element in the attached document. I would like to implement the case n=1 and the case n=2. (The case n=2 in priority).

What do you think of the difficulty of this ?

Best regards,

Loïc,  
[Description\_FE\_space\_FreeFEM.pdf](https://community.freefem.org/uploads/short-url/btly5Gw578lWOGaIQPBPSEkcLG2.pdf) (114.9 KB)

---

<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: [March 24, 2022, 4:59pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/4 "2022-03-24T16:59:31Z")

</div>

it is simple do but a little technical, I will ty to make a canvas.

---

<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: [March 25, 2022, 6:19am UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/5 "2022-03-25T06:19:20Z")

</div>

Thank you for your help @frederichecht .

I will try to understand and follow this tutorial: [Developers](https://doc.freefem.org/documentation/developers.html#developersaddingfiniteelement)

If you need more details about this finite element, don’t hesitate to let me know.

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: [March 25, 2022, 9:25am UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/6 "2022-03-25T09:25:51Z")

</div>

Remark the version P2 + bulle exist

P2pnc piecewise quadratic plus a bubble P3 element with the continuity of the 2 moments on each edge (version 3.59) (need load “Element\_P2pnc” is exactly you element in case 1 .

So you can start form this and call it P3pnc for exemple.

---

<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: [March 25, 2022, 12:25pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/7 "2022-03-25T12:25:00Z")

</div>

Thank you,

In the file `Element_P2pnc.cpp` , I can see the 7 basis functions.  
But I cannot understand where the DoF are defined.

Could you help me to understand how the DoF are defined ?

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: [March 25, 2022, 12:57pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/8 "2022-03-25T12:57:35Z")

</div>

you can see in the test testFE-P2pnc.edp  
the 2 dof on edge E = (i,j) are  
\int\_E \lambda\_i v and \int\_E \lambda\_j v where \lambda\_i and \lambda\_j are barycentric  
coordinate

---

<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: [March 25, 2022, 1:21pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/9 "2022-03-25T13:21:43Z")

</div>

I think in the FE definition, these doF are defined there:

```
for (int i = 0; i < 3; i++) {
  for (int p = 0; p < QFE.n; ++p) {
    R l1 = QFE[p].x, l0 = 1 - QFE[p].x;
    if (oe[i] < 0) {
      swap(l0, l1);
    }

    if (ddd < 3) {
      cout << p << " " << oe[i] << " " << l0 << " " << l1 << endl;
    }

    R p0 = l0, p1 = l1;
    R cc1 = p0 * QFE[p].a;
    R cc0 = p1 * QFE[p].a;
    v[k++] = cc0;
    v[k++] = cc1;
  }
}

for (int p = 0; p < QFK.n; ++p) {
  double w = QFK[p].a;
  R l1 = QFK[p].x, l2 = QFK[p].y, l0 = 1 - l1 - l2;
  R b = 1;
  v[k++] = b * w;
}

ffassert(k == this->pij_alpha.N( ));

```

}

But in my case I want that my DoF are \int\_E v L\_k where L\_k are the k-th Legendre polynomial. Thus in case n=1, the 2 polynomial should be 1 and \lambda.

I think this is not what P2Nc does, am I wrong ?

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: [March 25, 2022, 2:34pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/10 "2022-03-25T14:34:12Z")

</div>

Yes the degree of freedom are not exactly the same but a the end the space are exactly the same because we have same constraint;  
But it is trivial to change

---

<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: [March 25, 2022, 3:08pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/11 "2022-03-25T15:08:39Z")

</div>

Yes sure,

And for example in the case n=2,  
we can define the three weight just as P0=1, P1=l\_0 and P2= \frac{1}{2} (3 l\_0^2-1) ?

And I think I have to change the quadrature formula for the case n=2?

I have also few questions about the code in `Element_P2pnc.cpp`,

- What do QFE[p].x, QFE[p].y and QFE[p].a mean ?
- How the double C1[] is defined and what it does ?
- What do K.H(i) and K[i] mean ?
- And what is the function IPJ() ?

Thank you in advance,

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: [March 25, 2022, 3:30pm UTC](https://community.freefem.org/t/implementing-new-finite-element-in-freefem/1602/12 "2022-03-25T15:30:13Z")

</div>

Bonjour,

le plus simple est de faire une visio,  
via zoom , skype, or google meat !

envoyer moi votre mail pour vous envoyer une invitation

mon mail est : Hecht Frédéric \<[Frederic.Hecht@upmc.fr](mailto:Frederic.Hecht@upmc.fr)\>
