# Stokes and Navier-Stokes equations

**URL:** <https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437>\
**Category:** General\
**Created:** [June 8, 2023, 5:44pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437 "2023-06-08T17:44:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sean/32/5181_2.png) [@Sean](https://fenicsproject.discourse.group/u/Sean)\
**Post date:** [June 8, 2023, 5:44pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/1 "2023-06-08T17:44:15Z")

</div>

Hello everyone!  
I’m new to using fenics.  
I see many tutorials and examples to solve incompressible navier stokes and stoke equations using H1 element (like this [[https://fenicsproject.org/olddocs/dolfin/1.6.0/python/demo/documented/stokes-taylor-hood/python/](https://fenicsproject.org/olddocs/dolfin/1.6.0/python/demo/documented/stokes-taylor-hood/python/) documentation.html])  
I noticed that in 2021, there seems to be such a work, [[https://fenics2021.com/slides/dean.pdf.](https://fenics2021.com/slides/dean.pdf.)] But the complete code and demo are not given.  
Is there any example of using Hdiv element (BDM) or DG element?  
Thank you so much.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 8, 2023, 6:03pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/2 "2023-06-08T18:03:41Z")

</div>

@jpdean is the best one to ask about this.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [June 8, 2023, 6:13pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/3 "2023-06-08T18:13:48Z")

</div>

See the [Navier Stokes](https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_navier-stokes.py) demo (which I believe @jpdean wrote) for an example of an inf sup stable formulation with an H(\mathrm{Div};\cdot) conforming velocity space.

Edit: Updated link for March 2025

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 8, 2023, 6:40pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/4 "2023-06-08T18:40:51Z")

</div>

With rendered latex at [Divergence conforming discontinuous Galerkin method for the Navier–Stokes equations — DOLFINx 0.7.0.0 documentation](https://docs.fenicsproject.org/dolfinx/main/python/demos/demo_navier_stokes.html?highlight=navier)

---

<div class="post-metadata">

**Author:** ![Sean](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sean/32/5181_2.png) [@Sean](https://fenicsproject.discourse.group/u/Sean)\
**Post date:** [June 8, 2023, 6:59pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/5 "2023-06-08T18:59:06Z")

</div>

Thanks for replying so fast, but I don’t quite understand this part of the code for Stoke problem.

```auto
# Boundary conditions
boundary_facets = mesh.locate_entities_boundary(msh, msh.topology.dim - 1, boundary_marker)
boundary_vel_dofs = fem.locate_dofs_topological(V, msh.topology.dim - 1, boundary_facets)
bc_u = fem.dirichletbc(u_D, boundary_vel_dofs)
bcs = [bc_u]

```

Isn’t the boundary condition `u_D` already weakly imposed?

```auto
L_0 = inner(f, v) * dx + (1 / Re) * (- inner(outer(u_D, n), grad(v)) * ds
                                     + (alpha / h) * inner(outer(u_D, n), outer(v, n)) * ds)

```

Why set `bc_u = fem.dirichletbc(u_D, boundary_vel_dofs)` again?

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [June 8, 2023, 8:01pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/6 "2023-06-08T20:01:56Z")

</div>

Good question. Referring to [Cockburn et al. (2007)](https://link.springer.com/article/10.1007/s10915-006-9107-7) at the top of the demo’s documentation, the velocity space is constructed such that the velocity’s numerical flux is strongly imposed on the exterior boundary. If you don’t do this the elements adjacent to the boundary will not be diveregence free. The remaining tangential component is enforced weakly through the formulation. @jpdean please correct me if I’m wrong.

---

<div class="post-metadata">

**Author:** ![Sean](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sean/32/5181_2.png) [@Sean](https://fenicsproject.discourse.group/u/Sean)\
**Post date:** [June 8, 2023, 8:26pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/7 "2023-06-08T20:26:35Z")

</div>

Thanks! And now I understand why. This is the reason  
`As pointed out in Section 2, in order to obtain a divergence- free solution in the elements adjacent to the boundary, the Dirichlet boundary condition for the normal component must be implemented in a strong way, while the tangential components obtain their boundary values weakly through the form (2.11).`

---

<div class="post-metadata">

**Author:** ![jpdean](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/jpdean/32/3389_2.png) [@jpdean](https://fenicsproject.discourse.group/u/jpdean)\
**Post date:** [June 9, 2023, 1:02pm UTC](https://fenicsproject.discourse.group/t/stokes-and-navier-stokes-equations/11437/8 "2023-06-09T13:02:32Z")

</div>

Yes that’s right, you have to enforce the normal component in the function space and the tangential component weakly. That demo is for a divergence conforming discontinuous Galerkin method, whereas the slides you have referenced discuss a hybridized discontinuous Galerkin (HDG) method (as described in [[2306.05288] Design and analysis of a hybridized discontinuous Galerkin method for incompressible flows on meshes with quadrilateral cells](https://arxiv.org/abs/2306.05288)). The former can be implemented using main FEniCSx, the latter requires my branches which haven’t been merged yet. A demo of the HDG scheme can be found in [GitHub - jpdean/mixed\_domain\_demos](https://github.com/jpdean/mixed_domain_demos), though it needs some tidying up
