# Inforce homogeneous Neumann BCs using DG FEM

**URL:** <https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339>\
**Category:** General Discussion\
**Created:** [June 24, 2024, 1:24am UTC](https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339 "2024-06-24T01:24:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![noureddine](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@noureddine](https://community.freefem.org/u/noureddine)\
**Post date:** [June 24, 2024, 1:24am UTC](https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339/1 "2024-06-24T01:24:54Z")

</div>

Dear experts,

I am currently working on implementing the discontinuous Galerkin Finite Element Method (DG-FEM) for solving the Richards equation in a square domain with homogeneous Neumann boundary conditions on the lateral and bottom sides (q.n = 0). Initially, I assumed that these boundary conditions would naturally vanish in the weak form, but this doesn’t seem to be the case.

Below, I have outlined the weak form formulations for both the standard Finite Element Method (FEM) and the corresponding DG-FEM:

// RE: du/dt = div(Kh grad(h + z))

// Standard FEM:  
int nn = 50;  
mesh Th = square(nn, nn, [L_x, L_y]);  
macro dn(u) (N.x \* dx(u) + N.y \* dy(u) ) // Define the normal derivative

varf Richard(h, v, solver = UMFPACK) =  
int2d(Th, qft = qf1pTlump)( Ah \* h \* v + Kh \* (dx(h) \* dx(v) + dy(h) \* dy(v)) )

- int2d(Th, qft = qf1pTlump)( Ah \* hm \* v - (thetam - thetaold0) \* v

- Kh \* dy(v) )

- int1d(Th, 3)(q0 \* v)  
;

// DG-FEM:  
problem Richard(h, v, solver = UMFPACK) =  
int2d(Th, qft = qf1pTlump)( Ah \* h \* v + Kh \* (dy(h) \* dy(v) + dx(h) \* dx(v)) )  
+ intalledges(Th)( ( jump(v) \* mean(Kh \* dn(h)) - jump(h) \* mean(Kh \* dn(v))  
+ pena \* jump(h) \* jump(v) ) / nTonEdge )  
- int2d(Th, qft = qf1pTlump)( Ah \* hm \* v - (thetanew - thetaold0) \* v - Kh \* dy(v) )  
- int1d(Th, 2)(0.15 \* dn(v) + pena \* 0.15 \* v)  
;

I am encountering issues with the implementation and would greatly appreciate your assistance in resolving them. Any guidance or suggestions you can provide to correct this would be invaluable.

Best regards,

Noureddine

---

<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 24, 2024, 10:44am UTC](https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339/2 "2024-06-24T10:44:29Z")

</div>

Sorry, DG FEM is not well defined, This a a lot of formulation , so what the formulation.

---

<div class="post-metadata">

**Author:** ![noureddine](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@noureddine](https://community.freefem.org/u/noureddine)\
**Post date:** [June 24, 2024, 1:29pm UTC](https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339/3 "2024-06-24T13:29:26Z")

</div>

/_\_\_\_\_\_\_Continous Backward Euler \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__/  
macro grad(u) [dx(u),dy(u)] //  
macro dn(u) (N’\*grad(u) ) // def the normal derivative  
real q0 = 0.5;  
problem Richard(h, v, solver = GMRES) =  
int2d(Th, qft = qf1pTlump)( Ah \* h \* v + Kh \* (grad(h)'\*grad(v)) )

- int2d(Th, qft = qf1pTlump)( Ah \* hm \* v - (thetam - thetaold0) \* v
- Kh \* dy(v) )
- int1d(Th,3) (dt \* q0 \* v)  
;  
/_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__/  
/_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_Discontinous Galerkin BE \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__/  
problem Richard(h, v, solver = GMRES) =  
int2d(Th, qft = qf1pTlump)( Ah \* h \* v + Kh \* (grad(h)'\*grad(v)) )

- intalledges(Th)( ( jump(v) \* mean(Kh \* dn(h) )
- pena \* jump(h) \* jump(v) ) / nTonEdge )

- int2d(Th, qft = qf1pTlump)( Ah \* hm \* v - (thetam - thetaold0) \* v
- Kh \* dy(v) )
- int1d(Th,3) (dt \* q0 \* v)  
;

I’m implementing the DG FEM corresponding to the Continuous FEM for the Richards equation. Please note that the Continuous FEM is working well. The flux in the Richards equation is  
q = -Kh∇(h+y), where h is the unknown.

In the DG FEM implementation, I need to ensure that the no-flux (homogeneous Neumann) boundary conditions are correctly applied. Specifically, when setting `intalledges`, I want to ensure it considers all edges except those with no-flux boundary conditions.

Can you provide guidance on how to exclude contributions from the edges with no-flux boundary conditions while implementing the DG FEM in FreeFem++?

---

<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:** [June 24, 2024, 1:44pm UTC](https://community.freefem.org/t/inforce-homogeneous-neumann-bcs-using-dg-fem/3339/4 "2024-06-24T13:44:36Z")

</div>

You can just multiply by `(nTonEdge-1)` to delete the boundary edges,  
see [About intalledges and internal edges - #2 by fb77](https://community.freefem.org/t/about-intalledges-and-internal-edges/3231/2)
