Output velocity in txt form with PETSc (transfer values from one mesh to another)

Dear all,

I am running a Navier-stokes 2d problem with PETSc. Now I need to export velocity [ux, uy] in .txt format. I have followed the video ([Paraview Tutorial 4] How to display node and elements data in Paraview - YouTube) to convert the information from local partitions to global mesh and save it in .txt format (using ofstream). However, the number of values I get is more than 140000 which is way higher than the number of triangles (30920) and the number of vertices (15761). I want to ask the following questions:

  1. How does the field data (like velocity) saved in FreeFem? Is it saved as a value per cell or per vertex? I am confused by the large number of values saved by the ofstream function. It is not supposed to be that much.

  2. If the field data is associated to the node or elements, how do I output the data with the sequence of cell numbering or node number?

  3. My ultimate goal is to output the data from one 240 * 60 rectangular mesh domain to a smaller irregular mesh domain. This small domain is actually a part of the larger domain but the meshes are different (as shown below). I am thinking to do like this: output value+output corresponding coordinates and then do interpolation to the new mesh. it is a bit cumbersome. Is there any clever way to do it in freefem?

Screen Shot 2021-08-25 at 12.00.15 AM

Thank you very much!

Why are you not interpolating the velocity field directly in FreeFEM? Why are you not using the .vtu format if you want to postprocess results in ParaView?

Hi, I actually want to interpolate this field directly in FreeFEM. This is not a post-process for me. These are two meshes for two simulations, and I want to run these two simulations in terms while passing the velocity in between them. I have checked the interpolation matrix before, but since one of my meshes is irregular, I don’t know how to use it on my meshes.

Like with any other mesh, see the example at the bottom of this section Finite element.

Thank you for the information. The interpolation function works. I have another question regarding the read and write the solutions. Is there any way to save both the solution and mesh and then read them in another .edp file?

Yes, please read the documentation.

Thank you! I am now working on the Navier Stokes equation with some external force in parallelization, the code I am using is:

varf navierstokes ( [u, v, p], [uh, vh, ph]) =
   int2d(Th) ( rho * u * uh / dt )
 - int2d(Th) ( rho * convect ([uold,vold], -dt, uold) * uh / dt )
 + int2d(Th) ( rho * v * vh / dt )
 - int2d(Th) ( rho * convect ([uold,vold], -dt, vold) * vh / dt )
 + int2d(Th) ( nu * dx(u) * dx(uh) + nu * dy(u) * dy(uh) )
 + int2d(Th) ( nu * dx(v) * dx(vh) + nu * dy(v) * dy(vh) )
 + int2d(Th) ( kcoe * u * uh)
 + int2d(Th) ( kcoe * v * vh)
 - int2d(Th) ( p * dx(uh) + p * dy(vh) )
 - int2d(Th) ( dx(u) * ph + dy(v) * ph )
 // + int1d(Th, Outlet) ( nu * dx(u) * N.x * uh + nu * dy(u) * N.y * uh )
 // + int1d(Th, Outlet) ( nu * dx(v) * N.x * vh + nu * dy(v) * N.y * vh )
 + on ( Wall, u=0.0, v=0.0 )
 + on ( Outlet, p=0 )
 + on ( Inlet, u=uin, v=0);

set(NS, sparams = "-pc_type lu");

However, when I run it with nu = 0.00002, and some coefficients kcoe < 1e-5, it will show an error like

nan != nan diff nan => Sorry error in Optimization add:  (p) int2d(Th,optimize=0)(...)
 remark if you add  (..  ,   optimize=2) then  you remove this check (be carefull); 
  current line = 239 mpirank 1 / 4

but when nu = 0.0002, it can run successfully. And if I add optimize=0 to the integrals, it can run but I get null values. So is the problem is one of the coefficients in the Navier Stokes equation is too small? Is there any other way that I can fix this problem?

Hello, I have a similar problem, what is the cause? Seek guidance