# Navier Stokes on a step

**URL:** <https://community.freefem.org/t/navier-stokes-on-a-step/3861>\
**Category:** General Discussion\
**Created:** [April 13, 2025, 1:51pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861 "2025-04-13T13:51:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lipesantosa](https://avatars.discourse-cdn.com/v4/letter/l/71c47a/32.png) [@lipesantosa](https://community.freefem.org/u/lipesantosa)\
**Post date:** [April 13, 2025, 1:51pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861/1 "2025-04-13T13:51:12Z")

</div>

Hey, everyone! I’m still a problem with solve Navier Stokes equation on a step. When I plot, the vector come out of the mesh (what should not happen). Could someone help me?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/a8ba2c7a46e46dbfc8cd5b3e567946aa9613dc77.png)  
(It stays like this)

Note: I’m using Newton’s Method to linearize

---

<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:** [April 16, 2025, 7:58pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861/2 "2025-04-16T19:58:22Z")

</div>

Without code, or any further info, it is hard to help. I recommend you use paraview to visualize the solution.

---

<div class="post-metadata">

**Author:** ![lipesantosa](https://avatars.discourse-cdn.com/v4/letter/l/71c47a/32.png) [@lipesantosa](https://community.freefem.org/u/lipesantosa)\
**Post date:** [April 20, 2025, 1:17pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861/3 "2025-04-20T13:17:36Z")

</div>

I managed to solve this plot in FreeFEM, but when I export the VTK to Paraview it looks different.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/57fc5e39b2b6c8f5c6492a39d32a93bb08f78a59.jpeg)

```auto
while ((err > tol) && (iter < maxIter)){

  problem NavierStokes([u1,u2,p], [v1,v2,q])
    = int2d(Th)(
      mu*(dx(u1)*dx(v1) + dy(u1)*dy(v1)
        + dx(u2)*dx(v2) + dy(u2)*dy(v2))
      + (u1k*dx(u1) + u2k*dy(u1))*v1
      + (u1k*dx(u2) + u2k*dy(u2))*v2
      - p*(dx(v1) + dy(v2))
      - q*(dx(u1) + dy(u2))
    )
    - int2d(Th)(fx*v1 + fy*v2)
    + on(1, u1=uin, u2=0)
    + on(2, u1=0, u2=0);
  
  NavierStokes;

  // Verify error
  err = sqrt(int2d(Th)((u1 - u1k)^2 + (u2 - u2k)^2));
  u1k = u1;
  u2k = u2;

```

vtk:

```auto
// Cabeçalho do arquivo VTK
  vtkfile << "# vtk DataFile Version 3.0" << endl;
  vtkfile << "Malha P2 com dados P1/P2" << endl;
  vtkfile << "ASCII" << endl;
  vtkfile << "DATASET UNSTRUCTURED_GRID" << endl;

  // Escrever os pontos (vértices) da malha
  vtkfile << "POINTS " << Th.nv << " float" << endl;
  for (int i = 0; i < Th.nv; ++i) {
      vtkfile << Th(i).x << " " << Th(i).y << " 0.0" << endl;
  }

  // Escrever as células (triângulos) da malha
  vtkfile << "CELLS " << Th.nt << " " << 4 * Th.nt << endl;
  for (int i = 0; i < Th.nt; ++i) {
      // Para uma malha triangular: 3 vértices por célula
      vtkfile << "3 " << Th[i][0] << " " << Th[i][1] << " " << Th[i][2] << endl;
  }

  // Escrever os tipos de células (todas serão triângulos)
  vtkfile << "CELL_TYPES " << Th.nt << endl;
  for (int i = 0; i < Th.nt; ++i) {
      vtkfile << "5" << endl; // Tipo "5" é para triângulos
  }

  // Escrever os dados do campo de velocidade
  vtkfile << "POINT_DATA " << Th.nv << endl;
  vtkfile << "VECTORS velocity float" << endl;
  for (int i = 0; i < Th.nv; ++i) {
      vtkfile << u1[][i] << " " << u2[][i] << " 0.0" << endl;
  }

```

---

<div class="post-metadata">

**Author:** ![quentin](https://avatars.discourse-cdn.com/v4/letter/q/e47c2d/32.png) [@quentin](https://community.freefem.org/u/quentin)\
**Post date:** [April 20, 2025, 3:55pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861/4 "2025-04-20T15:55:37Z")

</div>

Maybe you can use “iovtk” to save .vtu file, it is more simple.  
It is like

```auto
load "iovtk"
int[int] fforder = [1,1];
string Dataname = "u";
savevtk("u.vtu", Th, [u1, u2], dataname=Dataname, order=fforder);

```

---

<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:** [April 21, 2025, 2:12pm UTC](https://community.freefem.org/t/navier-stokes-on-a-step/3861/5 "2025-04-21T14:12:44Z")

</div>

I think you need both the LNS/Jacobian and the full Navier-Stokes/error in the problem, like in [SOURCES\_FREEFEM/Newton\_2D.edp · master\_beta · StabFem / StabFem · GitLab](https://gitlab.com/stabfem/StabFem/-/blob/master_beta/SOURCES_FREEFEM/Newton_2D.edp?ref_type=heads)
