The difficulty with using periodic boundary conditions on separate P2 and P1 finite element spaces in FreeFem++ is the degrees of freedom (DOF) mismatch caused by inconsistent periodic node mapping across different spaces, leading to an assertion failure.
My current code using two separate P2 and P1 spaces triggers the DOF mismatch error, and the relevant code is as follows:
mesh Th = square(cm, cm);
fespace Vh(Th, P2, periodic=[[2, y], [4, y], [1, x], [3, x]]);
fespace Wh(Th, P1, periodic=[[2, y], [4, y], [1, x], [3, x]]);
Vh u1,u2,un1,un2,du1,du2,v1,v2;
Wh rho1,rho2,p,mu1,mu2,rhon1,rhon2,drho1,drho2,dp,dmu1,dmu2,psi1, psi2,q,xi1,xi2;
real V1 = 0.3, V2 = 0.7;
rhon1 = 1.0 + 0.5sin(2pix)sin(2piy);
rhon2 = (1.0 - V1rhon1) / V2;
un1 = sin(2pix)cos(2piy);
un2 = -cos(2pix)sin(2pi*y);
The program crashes with the following error log:
– Square mesh : nb vertices =4225 , nb triangles = 8192 , nb boundary edges 256 rmdup= 0
Problem build of FEspace (2d) (may be : due to periodic Boundary condition missing ) FH
The number of DF must be 53248 and it is 54407
Assertion fail : (snbdf == NbOfDF)
line :937, in file ../femlib/FESpace.cpp