# Inviscid Incompressible Flow in FreeFEM

**URL:** <https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284>\
**Category:** General Discussion\
**Created:** [June 3, 2024, 5:28pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284 "2024-06-03T17:28:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 3, 2024, 5:28pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/1 "2024-06-03T17:28:10Z")

</div>

Hello !  
I am trying to solve the incompressible and invsicid flow in FreeFEM for a 3D geometry. I have written the code to work in parallel using PETSc. The mesh is imported from GMSH mesh file. I am not sure what is wrong with my code as the solution is not correct. I thought the dt might be a problem but changing dt doesn’t affect the result.

The weak form of the GE I used,  
 ![GE](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/e05bf63bab9a61f965a238dea2edc70fb0e97b1e.png)

Boundary Conditions:

1. Dirchlet B.C. for velocity at inlet.
2. Neumaan B.C. for pressure at outlet
3. Periodic B.C. on the top, bottom, front and back walls of the domain.

varf formulation of the problem

```auto
varf GE([u1,u2,u3,p],[v1,v2,v3,q])
   =int3d(Th)(u1*v1 + u2*v2 + u3*v3
   +(un1*dx(u1) + un2*dy(u1) + un3*dz(u1))*v1*dt
   +(un1*dx(u2) + un2*dy(u2) + un3*dz(u2))*v2*dt
   +(un1*dx(u3) + un2*dy(u3) + un3*dz(u3))*v3*dt
   -(dx(v1) + dy(v2) + dz(v3))*p*dt
   -(dx(u1) + dy(u2) + dz(u3))*q*dt)
   +int3d(Th)(un1*v1 + un2*v2 + un3*v3)
   +on(1, u1=1, u2=0, u3=0)
   +int2d(Th, 2)(0*q);

```

The edp file for your reference. [cyl\_new.edp](https://community.freefem.org/uploads/short-url/m1bh89jvqXZzSbvpMnu64hnbvLy.edp) (2.5 KB)

The velocity field produced from the code. It doesn’t look correct.

 ![At t=0.5 s](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/294b309fa1008e5f0097d6e294eb2811a0859784.jpeg) ![At t=1.5 s](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/1/1183dbcdc6ab78797f33b9a32ea3f63208de586a.jpeg)

Thank you for the help !

Regards,  
Gaurav.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 3, 2024, 6:13pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/2 "2024-06-03T18:13:06Z")

</div>

If you have a periodic `fespace`, you must use the additional macro `ThPeriodicity`, see [FreeFem-sources/examples/hpddm/diffusion-periodic-2d-PETSc.edp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/diffusion-periodic-2d-PETSc.edp#L22).

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 3, 2024, 6:22pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/3 "2024-06-03T18:22:45Z")

</div>

Thanks for the reply ! I will check once, is the missing macro causing the issue ?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 3, 2024, 6:43pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/4 "2024-06-03T18:43:06Z")

</div>

It is definitely _one_ issue. I haven’t checked the rest of the code.

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 3, 2024, 6:58pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/5 "2024-06-03T18:58:38Z")

</div>

I assume you are aware of the problems of singularities and finite-time blow-up in the incompressible Euler equations. Have you already checked your formulation with a simpler 2D/3D sequential problem to rule out such issues?

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 3, 2024, 7:21pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/6 "2024-06-03T19:21:35Z")

</div>

I was actually checking the code with the cylinder case. The problem was there in the sequential case too. No, I am not very well aware of the issues with them. Can you please share ?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 3, 2024, 7:32pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/7 "2024-06-03T19:32:19Z")

</div>

Well the system is hyperbolic except for the divergence-free constraint induced by the pressure. Also, the BCs in the Euler equations are not equivalent to those of the NSE (eg your no-slip condition on the cylinder does not make sense).

What is it precisely that you need from your model?

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 3, 2024, 7:50pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/8 "2024-06-03T19:50:09Z")

</div>

Okay. But, if no viscosity is present then there won’t be any “no-slip” bc on the cylinder body. There will be stagnation point in front of the cylinder but doesn’t necessarily require the velocity to be zero everywhere on the surface. So, it is free slip only, right ? (I haven’t applied any bc for velocity/pressure on the surface of the cylinder).

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 3, 2024, 8:19pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/9 "2024-06-03T20:19:40Z")

</div>

Sorry, I only glanced at your code and misinterpreted your BC. You have not imposed no-slip BC, but you also have not imposed no-penetration BC’s… You just have a hole in your mesh.

Note that there is no natural Neumann condition in the Euler equations since there is no viscous term to integrate by parts…

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 4, 2024, 12:46am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/10 "2024-06-04T00:46:08Z")

</div>

Thanks a lot for looking into. Is it okay if put U•n =0 on all the boundaries except the inlet ?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 4, 2024, 1:25am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/11 "2024-06-04T01:25:25Z")

</div>

Assuming you mean all boundaries except inlet AND outlet, yes. but that is not trivial with curved boundaries. What are you trying to do? I thought you wanted periodic boundaries?

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 4, 2024, 1:47am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/12 "2024-06-04T01:47:37Z")

</div>

Yeah with curved boundary, it is any issue. I have periodic bc on the other boundaries except the cylinder boundary, inlet and outlet, does that prevent the penetration. Any help on implementing the no penetration bc for general boundaries ?

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [June 4, 2024, 6:53am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/13 "2024-06-04T06:53:10Z")

</div>

You could just solve Poisson’s equation for the complex potential; then, obtain the inviscid velocity via differentiation.

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 4, 2024, 7:05am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/14 "2024-06-04T07:05:21Z")

</div>

Stream function method doesn’t work for 3D. I have 3D application.

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 4, 2024, 10:56am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/15 "2024-06-04T10:56:38Z")

</div>

See the notes of @fb77 here:

> [@Boundary condition](https://community.freefem.org/t/boundary-condition/2945/6):
>
> If you want to avoid using a Lagrange multiplier (because it enlarges the matrix to invert), some other ways to penalize the normal boundary conditions are possible. In 3D you can use for example the boundary vertices. You have to define first a continuous approximate normal on the boundary (label 1 is for boundary) fespace Vh1(Th,[P2,P2,P2]); varf bdryn([w1,w2,w3],[v1,v2,v3])=int2d(Th,1)(v1\*N.x+v2\*N.y+v3\*N.z); Vh1 [normalappx,normalappy,normalappz]; normalappx[]=bdryn(0,Vh1); Then you can ad…

---

<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 4, 2024, 12:35pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/16 "2024-06-04T12:35:40Z")

</div>

Hello,  
The no penetration boundary conditions is one possible issue.  
I think that another one is the implicit treatment of convection without viscosity. I would recommend using convect().

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 4, 2024, 12:54pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/17 "2024-06-04T12:54:03Z")

</div>

I had been using convect() earlier but it is not recommended with periodic boundary conditions. I read one discussion about it in the community. So, I switched to this method.

---

<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 4, 2024, 1:27pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/18 "2024-06-04T13:27:57Z")

</div>

I understand your reason, but I think that the implicit method is unstable here. You could try with convect and no penetration condition instead of periodic, to see if it works or not.

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 4, 2024, 1:29pm UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/19 "2024-06-04T13:29:04Z")

</div>

Sure, I will check once. Thank you for the help !

---

<div class="post-metadata">

**Author:** ![airwarriorg91](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/airwarriorg91/32/2387_2.png) [@airwarriorg91](https://community.freefem.org/u/airwarriorg91)\
**Post date:** [June 5, 2024, 6:15am UTC](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284/20 "2024-06-05T06:15:29Z")

</div>

Hello,  
Based on the recommendations, I modified my code to remove the periodic boundary condition and use convect function for the non-linear term along with no-penetration BC using the method suggested by @fb77. Thanks a lot, seems like the divergence problem is solved. But the velocity field is still patchy (See the image for reference). I don’t understand why there are patches of zero velocity. Is it due to the FEM element type. I am using P2 for velocity and P1 for pressure.

 ![Patchy Flow](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/b6e12b0abe943d01c9eaf7677511e54f7d092baf.jpeg)

I have attached the modified code for your reference.

[cyl\_new.edp](https://community.freefem.org/uploads/short-url/b5KCuwDfigi5zxpbauLeaQzMCmr.edp) (3.4 KB)

[Next page](https://community.freefem.org/t/inviscid-incompressible-flow-in-freefem/3284.md?page=2)
