Hi everyone!
I’m trying to prove the following result
but FreeFem++ is giving me different values for each DoF of the space P1(K).
This is my code:
load "qf11to25"
//------------------Global Mesh---------------------
int globalH = 2^1;
mesh calP = square(globalH,globalH);
int NbTriangles = calP.nt; //number of triangles
int NbVertices = calP.nv; //number of vertices
fespace V0(calP,P0);
V0 u0;
for(int i = 0; i < NbTriangles; i++){
u0[][i] = i;
}
//-------------------Mesh info---------------------
//-------------------------vector: nodes in elem K
real[int,int] elemNodesGlobal(NbTriangles,3);
for (int i = 0; i < NbTriangles; i++){
for(int j = 0; j < 3; j++)
elemNodesGlobal(i,j) = int(calP[i][j]);
}
//cout << elemNodesGlobal <<"\n";
func f = 8*pi*pi*sin(2*pi*x)*sin(2*pi*y);
//f integration order
int forder = 25;
mesh[int] Th(NbTriangles);
for(int K = 0; K < NbTriangles; K++){
real coordX0, coordX1, coordX2;
real coordY0, coordY1, coordY2;
for(int i = 0; i< NbVertices; i++){
if(elemNodesGlobal(K,0) == i){
coordX0 = calP(i).x;
coordY0 = calP(i).y;
}
if(elemNodesGlobal(K,1) == i){
coordX1 = calP(i).x;
coordY1 = calP(i).y;
}
if(elemNodesGlobal(K,2) == i){
coordX2 = calP(i).x;
coordY2 = calP(i).y;
}
}
real[int, int] nodes = [[coordX0, coordY0], [coordX1,coordY1],
[coordX2, coordY2]];
// cout << nodes << "\n";
border f0(t=0,1){P.x=nodes(2,0)*t + nodes(1,0)*(1-t);P.y=nodes(2,1)*t + nodes(1,1)*(1-t); label=11;};
border f1(t=0,1){P.x=nodes(0,0)*t + nodes(2,0)*(1-t);P.y=nodes(0,1)*t + nodes(2,1)*(1-t); label=22;};
border f2(t=0,1){P.x=nodes(1,0)*t + nodes(0,0)*(1-t);P.y=nodes(1,1)*t + nodes(0,1)*(1-t); label=33;};
Th[K] = buildmesh(f0(1) + f1(1) + f2(1));
Th[K] = trunc(Th[K], abs(u0 -K) < 1e-5, split=2^1);
//projection space
fespace Qh(Th[K], P1);
Qh qk;
varf localMassF(f, qk)
= int2d(Th[K], qforder=forder)(-1*(8*pi*pi*sin(2*pi*x)*sin(2*pi*y))*qk);
real[int] veclocalMassF = localMassF(0,Qh);
cout << "\int_K f*qk, qk \in P1(K): " << "\n";
cout << veclocalMassF << "\n";
Qh projF = -1*f;
cout << "\int_K Pi(f)*qk, qk \in P1(K), Pi(.) projecao em P1(K): " << "\n";
varf localMassprojF(f, qk)
= int2d(Th[K], qforder=forder)(projF*qk);
real[int] veclocalMassprojF = localMassprojF(0,Qh);
cout << veclocalMassprojF << "\n";
}
This is the result for one element K:
int_K f*qk, qk in P1(K):
6
-0.2267604553 -0.2267604553 -0.0901406829 -1.636619772 -0.9098593171
-0.9098593171
int_K Pi(f)*qk, qk in P1(K), Pi(.) projecao em P1(K):
6
-0.2056167584 -0.2056167584 -2.51807905e-17 -1.23370055 -0.4112335167
-0.4112335167
Can someone help me? Maybe I’m doing something wrong.