# Is the following code is correct?

**URL:** https://community.freefem.org/t/is-the-following-code-is-correct/3590
**Category:** General Discussion
**Created:** [November 21, 2024, 10:38am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590 "2024-11-21T10:38:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)
#### Post date: [November 21, 2024, 10:38am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/1 "2024-11-21T10:38:56Z")

</div>

Can someone help me how to write the second term of the bilinear form??

 ![Help](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/bdeb17438802060bca300b397f947e22da11d483.png)  
 ![Screenshot 2024-11-13 165654](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/3ad10f6e181b50ea3ab7f7ef25a874b15721dafa.png)

Here is my code

> Blockquote  
> +intalledges(Th)((abs(N.x_mean(v1old)+N.y_mean(v2old))_jump(v1)jump(vv1))/nTonEdge(nTonEdge-1))  
> +int1d(Th)(abs(N.x_v1old+N.y_v2old)v1vv1)  
> +intalledges(Th)((abs(N.x_mean(v1old)+N.y_mean(v2old))jump(v2)jump(vv2))/nTonEdge(nTonEdge-1))  
> +int1d(Th)(abs(N.xv1old+N.y_v2old)_v2_vv2)

> Blockquote  
> Here, v is known ,v=(v1old,v2old), z=(v1,v2) is unkown, theta=(vv1,vv2) is test function.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [November 21, 2024, 9:57pm UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/2 "2024-11-21T21:57:30Z")

</div>

I would write for your second term  
`intalledges(Th)((nTonEdge-1)*real(mean(w1)*N.x+mean(w2)*N.y<0.)*abs(N.x*mean(v1old)+N.y*mean(v2old))*(-jump(v1)*vv1-jump(v2)*vv2))`

---

<div class="post-metadata">

### Author: ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)
#### Post date: [November 22, 2024, 3:51am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/3 "2024-11-22T03:51:05Z")

</div>

Thank sir for your replies. But why you are ignoring jump(vv1) and jump(vv2) sir?. Does it has any reason??. In weak formulation in continuous case, theta=0 on boundary of the domain (given). But in discontinuous case, jump(theta)=theta^int-theta^ext. It this may be theta^ext=0 . So, theta^int only there it the bilinear form.

One more that i observe you have not written boundary edges term. But why?. If i am not wrong it is full boundary sir. For nTonEdge=1, term that you wrote becomes zero sir. So, no contribution of boundary are there.

Thanks sir.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [November 22, 2024, 10:41am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/4 "2024-11-22T10:41:15Z")

</div>

> > But why you are ignoring jump(vv1) and jump(vv2) sir?.  
> > There is no jump(theta) appearing in your formulation.  
> > theta\_int=theta

> > theta=0 on boundary of the domain (given).  
> > Since theta is given and vanishes on the boundary, it follows that the boundary term vanishes in your formulation. Thus there is nothing to discretize.

> > One more that i observe you have not written boundary edges term.  
> > You said that theta vanishes on the boundary \partial\Omega. It follows that there is no boundary term.

If theta does not vanish on the boundary, you can add boundary terms by writing another intalledges with factor 2-nTonEdge.

---

<div class="post-metadata">

### Author: ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)
#### Post date: [November 22, 2024, 10:45am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/5 "2024-11-22T10:45:38Z")

</div>

Can write as following sir??

> Blockquote  
> +intalledges(Th)((nTonEdge-1)_real(mean(v1old)N.x+mean(v2old)N.y\<0.)abs(N.xmean(v1old)+N.ymean(v2old))(-jump(v1)vv1-jump(v2)vv2))  
> +int1d(Th)((real(v1oldN.x+v2oldN.y\<0.)abs(N.xv1old+N.y_v2old)_(-v1_vv1-v2\*vv2))) // boundary terms of inflow boundary

> Blockquote  
> Here, w=(v1old, v2old) is known.

According to you sir, am i write as following?

> Blockquote  
> +intalledges(Th)((2-nTonEdge)\*real(mean(v1old)_N.x+mean(v2old)N.y\<0.)abs(N.xmean(v1old)+N.ymean(v2old))_(-jump(v1)\*vv1-jump(v2)\*vv2))

> Blockquote

Which one is best sir?? .

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [November 22, 2024, 10:58am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/6 "2024-11-22T10:58:01Z")

</div>

The most simple is  
`+int1d(Th)(real(v1old*N.x+v2old*N.y<0.)*abs(N.x*v1old+N.y*v2old)*(v1*vv1+v2*vv2))`  
Note the change of sign, because `jump(v)=v_ext-v_int`, not the opposite.  
Here all quantities are evaluated on the interior side of the boundary.

But it depends on the interpretation of your variational formulation for boundary terms.  
– If you want that on the boundary \{v\}=v\_{int} then the previous formula is good.  
– If you want that on the boundary v\_{ext}=0, \{v\}=(v\_{int}+v\_{ext})/2=v\_{int}/2 then you should use the intalledges formula.

---

<div class="post-metadata">

### Author: ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)
#### Post date: [November 22, 2024, 11:08am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/7 "2024-11-22T11:08:01Z")

</div>

I am seeing that you have not divided by nTonEdge while writing intalledges( ). Should we divide by nTonEdge or not sir??.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [November 22, 2024, 11:11am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/8 "2024-11-22T11:11:46Z")

</div>

You must not divide by nTonEdge (or equivalently divide by 2)  
because your variational formulation contains two contributions at each internal edge, one from each triangle on each side.  
You divide by 2 when you want a single contribution for each edge (or the average of the two contributions from each side if these contributions differ).

---

<div class="post-metadata">

### Author: ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)
#### Post date: [November 22, 2024, 11:13am UTC](https://community.freefem.org/t/is-the-following-code-is-correct/3590/9 "2024-11-22T11:13:34Z")

</div>

Okay thanks sir. I got it. So, i will not divide by nTonEdge.
