FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
755 stars 188 forks source link

suspected bug in outputing 2d vectors #315

Closed edmondztt closed 1 week ago

edmondztt commented 1 week ago

Hi,

I’m trying to save the 2D vector field from Stokes problem. However, no matter how I do it u2 and u1 are exactly the same. Weirdly, plot(u1) and plot(u2) still show correctly different values. Here is my script:

include "./freefem_matlab_octave_plot/release-v2.0/demos/ffmatlib.idp"

macro grad(u) [dx(u),dy(u)]// macro Grad(u1,u2) [ grad(u1), grad(u2)]// macro div(u1,u2) (dx(u1)+dy(u2))//

int nn = 30; // number of edge in each direction // mesh Th=square(nn,nn,[2pix,2piy],flags=3);

real r=0.05; real sep=1.12; real L=3.0; real rcx=L/2.0-rsep; real rcy=L/2.0; real rcx2=L/2.0+rsep; real rcy2=rcy;

int[int] labs = [1,2,3,4];

// border a(t=0, 2pi){x=cos(t); y=sin(t); label=1;} border C01(t=0, 1){x=Lt; y=0; label=labs[0];} border C02(t=0, 1){x=L; y=Lt; label=labs[1];} border C03(t=0, 1){x=L(1-t); y=L; label=labs[2];} border C04(t=0, 1){x=0; y=L*(1-t); label=labs[3];}

border b(t=0, 2pi){x=rcx+rcos(t); y=rcy+rsin(t); label=5;} border b2(t=0, 2pi){x=rcx2+rcos(t); y=rcy2+rsin(t); label=6;}

real factormsh = 3; mesh Th = buildmesh(C01(nn) + C02(nn) + C03(nn) + C04(nn)

mesh ThU=trunc(Th,1,split=2); // Velocity mesh

fespace Uh(ThU,[P1,P1],periodic=[[2, y], [4, y], [1, x], [3, x]]); fespace Ph(Th,P1,periodic=[[2, y], [4, y], [1, x], [3, x]]); Uh [u1,u2], [v1,v2]; Ph p,q; solve Stokes(<[u1,u2],[p]>,<[v1,v2],[q]>) = int2d(ThU)( (Grad(u1,u2):Grad(v1,v2)) )

cout << "u2 dof=" << u2[].n << endl;

for (int i=0; i<4; i++){ cout << u2[][i] << endl; } plot(u1, cmm="u1" , fill=1,value=1); plot(u2, cmm="u2" , fill=1,value=1); string fnamedata="u.txt"; ffSaveData2(u1,u2,fnamedata) So the cout lines give exactly same outputs. And ffSaveData2(u1,u2,fnamedata) also gives exactly same values. the txt file looks like:

1 -1 -9.376217058e-32 -9.376217058e-32 -1 -1 -1.202971747e-31 -1.202971747e-31 -1 -1 ...

cmd8 commented 1 week ago

This is the expected/intended behavior.. See: https://community.freefem.org/t/data-from-p2-p2/2016/2