# 1D discontinuous Galerkin FEM code

**URL:** <https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786>\
**Category:** General Discussion\
**Created:** [May 29, 2022, 12:31pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786 "2022-05-29T12:31:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [May 29, 2022, 12:31pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/1 "2022-05-29T12:31:10Z")

</div>

Hello, teacher, Can freefem++ write 1D discontinuous Galerkin FEM code?

---

<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:** [June 7, 2022, 3:21pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/2 "2022-06-07T15:21:16Z")

</div>

yes you can !  
except periodic boundary condition (no jump, mean, on periodic boundary ).

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 25, 2022, 7:15am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/3 "2022-06-25T07:15:59Z")

</div>

Hello, in fact, if there is a jump on periodic boundary, can freefem++ not implement the 1D discontinuous Galerkin FEM code?

---

<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:** [June 25, 2022, 6:21pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/4 "2022-06-25T18:21:38Z")

</div>

Yes the jump and mean function is implémentée in version 4.11,

I have try it ok for my se thé exemple

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 27, 2022, 9:23am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/6 "2022-06-27T09:23:24Z")

</div>

![QQ截图20220627171943](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/d13dab972d55c557bfabcaa3b0a3ef5e7b8cf8fa.png)

Hello, as shown in the figure, this is a 1D discontinuous finite element problem. If I want to realize the above boundary term (the second term in the last line)in FreeFem++, how can I achieve it? thank you

---

<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:** [June 29, 2022, 7:31pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/7 "2022-06-29T19:31:20Z")

</div>

Read thé CHANGELOG.md file for the syntaxe, sorry the doc is not updated:

- DG formulation in 1d : add integral of all border of element : `intallBE(ThL)` and unified the notation by adding `intallBE(ThS)` , `intallBE(Th2)`, `intallBE(Th3)` `nuVertex` of now the vertex number of element in intallBE0d integral `BoundaryBE`, `InternalBE` to know if border element (BE) is on true boundary of not. update `nElementonB` in case on no manifold data (value greater \> 2) in meshL, MeshS case … add code to use jump, mean of test functuon on MeshL case. ( not in mesh3 ) to compute RHS.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 30, 2022, 1:36am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/8 "2022-06-30T01:36:38Z")

</div>

Hello, thank you for your reply. I understand, but How will this symbol be implemented?

![屏幕截图 2022-06-30 111526](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/0aef59b1b9289bbebdbdde3acf50dc8269ee38c1.png)

> u+ refers to the value on the right of the oriented edge

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [July 4, 2022, 4:52am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/9 "2022-07-04T04:52:15Z")

</div>

Hello, in freefem++, about the one-dimensional discontinuous finite element method, on two adjacent intervals, on the common endpoint K of elements e1 and e2, how to represent the value of this point when k is on the first element?

---

<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:** [July 15, 2022, 12:37pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/10 "2022-07-15T12:37:53Z")

</div>

I am not sure thaï u\_xx is defined , I will se to morrow!

the the way the get the otherside de value is

```auto
otherside(u) 

```

If I make no mistake you formula is

intallBE(Th)((dxx(u)\*jump(v)-dyy(v)_jump(u))_(N.x\>0)/lenEdge)

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [July 31, 2022, 1:06pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/11 "2022-07-31T13:06:37Z")

</div>

Hello, thank you for your answer. The value u^ (+) of the right cell and the value u^ (-) of the left cell are taken on the adjacent cell. How to distinguish these two values when programming? That is, how to define the boundary item u^ (+) \*v^ (-) or u^ (-) \*v^ (+)?

> intallBE(Th)(u^(+)\*v^(-))?

> intallBE(Th)(u^(-)\*v^(+))?

---

<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:** [August 1, 2022, 10:03am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/12 "2022-08-01T10:03:06Z")

</div>

intallBE mean you are on left or right on the segment so all point are vue 2 times.

It is why, I had (N.x \> 0) to get just take the right value

it is impossible of write `intallBE(Th)(u^(+)*v^(-))`because it is non local

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 8, 2022, 7:44am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/13 "2022-08-08T07:44:50Z")

</div>

Hello, I have a boundary item, i.e. U0 ^ {+} \* U1 ^ {-} on \ partial \ Omega. Use this command intallbe (th) (U0 \* (N.x\> 0) \* otherside (U1) \* jump (V)/lenEdge). Is it correct?

---

<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:** [August 8, 2022, 10:13am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/14 "2022-08-08T10:13:47Z")

</div>

I think no if it is a true boundary because `otherside` have no sens and `ìntallbe` do the integration on all triangle boundary.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 8, 2022, 10:29am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/15 "2022-08-08T10:29:42Z")

</div>

Hello, in fact, this is my boundary condition,  
 ![屏幕截图 2022-08-08 181810](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/ae8a16b67932750158615e29684f54ef8891b0e5.png)  
where f is the flux, p = 2.,

 ![屏幕截图 2022-08-08 181838](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5cf1301af6d38ebcaefd237ce17b1e05e2bca208.png)

Expand the flux by u ^ {+} \* u ^ {+} + u ^ {+} \* u ^ {-} + u ^ {-} \* u ^ {-}, then the above boundary condition is

Σ (jump (v) \* (u ^ {+} \* u ^ {+} + u ^ {+} \* u ^ {-} + u ^ {-} \* u ^ {-}), this command

intallBE (Th) (jump (v) \* (u\* u \* (N.x \> 0) + u\* u + u \* u \* (N.x \< 0)) / lenEdge), is it correct?

---

<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:** [August 8, 2022, 2:49pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/16 "2022-08-08T14:49:21Z")

</div>

remark, you schema is def at point and in freefem you have finite element function  
so if you take P1dcL1 finite element when the dof is the value a vertex

so u\_m^- == u[2_m] and u\_m^+ == u[][2_m+1]

where m is ne element element

```auto
load "msh3"
load "Element_P1dc1"
meshL Th=segment(10);
fespace Vh(Th,P1dcL1);
Vh u=x;
cout << u[] << endl; // to see 

for(int m=0;m<10;++m)
{
	cout << " u_m^- " << u[][2*m] << " ";
	cout << " u_m^+ " << u[][2*m+1] << endl;
	
}
 

```

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 10, 2022, 3:16am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/17 "2022-08-10T03:16:46Z")

</div>

Hello, thank you for your reply, in fact, I developed the numerical flux of boundary conditions f = u ^ {+} \* u ^ {+} + u ^ {+} \* u ^ {-} + u ^ {-} \*u ^ {-},p=1, this how to say in FreeFem++?

I want to know if I have the right boundary conditions?

intallBE(th)(jump(v)_(u_u\*(N.x\>0)+u_u+u_u\*(N.x\<0)))

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 15, 2022, 7:46am UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/18 "2022-08-15T07:46:46Z")

</div>

Hello, according to your answer, if **u\_m ^ -** is **N.x \< 0,** then _intallBE (th) (u (N.x\> 0) \* u \* (N.x \< 0) \* jump (v))_\* on the boundary is a nonlinear term?

---

<div class="post-metadata">

**Author:** ![lailai](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@lailai](https://community.freefem.org/u/lailai)\
**Post date:** [September 4, 2023, 1:28pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/19 "2023-09-04T13:28:25Z")

</div>

Hi, Frédéric,  
if i understand it correctly, at this moment, DG in a periodic domain is not supported within freefem, right? thank you very much.

---

<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:** [September 4, 2023, 2:19pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/20 "2023-09-04T14:19:14Z")

</div>

yes, the jump, mean are not correct with periodic BC.

---

<div class="post-metadata">

**Author:** ![lailai](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@lailai](https://community.freefem.org/u/lailai)\
**Post date:** [September 4, 2023, 2:36pm UTC](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786/21 "2023-09-04T14:36:36Z")

</div>

understood, i guess it will be potentially fixed in newer version of freefem, right?

[Next page](https://community.freefem.org/t/1d-discontinuous-galerkin-fem-code/1786.md?page=2)
