# Need some help to build variation formula for adjacent elements

**URL:** https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023
**Category:** General Discussion
**Created:** [March 8, 2024, 3:00pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023 "2024-03-08T15:00:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [March 8, 2024, 3:00pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/1 "2024-03-08T15:00:34Z")

</div>

Dear Freefem team

` I was wondering if you could give me some guidance to build the second terms of this variation formula. The first term is pretty straight forward. however , the second term need find all the adjacent element share the same face. I know how to build the adjacent matrix in freefem. However, I may need some help to set it in the variation formula and build the right matrix. Thank you for the attention`

Best regards

 ![Screenshot 2024-03-08 at 9.55.45 AM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/53bfca068d2ae9e188e3a3d6505dfea78d3e95a7.png)

---

<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 8, 2024, 5:53pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/2 "2024-03-08T17:53:28Z")

</div>

For equation (2) it. Is not so clean because do have directly asset to this kind of intégrale

But it is possible to bluid the adj of face, after we can the term (2)

Remark I suppose f is a face and e\_i e\_j is element,

I will try to make a small exemple.

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [March 8, 2024, 6:33pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/3 "2024-03-08T18:33:07Z")

</div>

yes, you are right sir, f is the face shared by two elements ei and ej

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [March 11, 2024, 1:55pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/4 "2024-03-11T13:55:19Z")

</div>

Dear sir, I was wondering if you had some examples. Thank you for you attention.

---

<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 11, 2024, 2:44pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/5 "2024-03-11T14:44:11Z")

</div>

REmark, It formula have no real sens if the \nabla G(e\_i) is not constante  
because I do not understand ||\nabla G(e\_i)-\nabla G(e\_j)||\_2^2 because the definition domain is e\_i or e\_j. So for me the formula (2) is wrong it is on ||\nabla G(e\_i)-\nabla G(e\_j)||\_{f,2}^2 (integration of f). remark if G is P\_1 then you have just a change in \omega\_{cg} term.

And in this case no problem to compute

\sum\_f ||\nabla G(e\_i)-\nabla G(e\_j)||\_2^2 = intallface(Th)(Wcg\* InternalBE/2\* jump(G)^2 );

so the varf is

```auto
varf D2(G,GG) = intallface(Th)( Wcg*InternalBE* jump(G)*jump(GG )); 

```

where Wcg is a finite element function defined of face (P0face3d fespace)

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [March 11, 2024, 2:58pm UTC](https://community.freefem.org/t/need-some-help-to-build-variation-formula-for-adjacent-elements/3023/6 "2024-03-11T14:58:41Z")

</div>

Thank you sir, the part you mentioned confused me as well. I will check you example and thank you for the guidance.
