Average of variable

Dear all

I want to take the area average of my velocity field in freefem++ code. is it enough to write
uAverage=int2d(th)(ux)/Area ?
I think something is wrong and the integral must be area weighted.
Do you know how I can write it?

BR

Sounds like you have the right approach:
real uAverage = int2d(th)(ux)/int2d(th)(1.0);

1 Like

Thank you.
I also wrote it in another way witch was comparably in good agreement with Tecplot. I write it here if anyone needs.
int nbtriangle=th.nt;

real[int] uxA(nbtriangle);
uxA=0.;
real uxAverage=0.;
for (int i=0; i<nbtriangle; i++)
{
for (int j=0; j<3; j++)
{
real X=th[i][j].x;
real Y=th[i][j].y;
uxA(i)=velocity(X,Y)+uxA(i);
}
uxA(i)=(uxA(i)/3)*th[i].area;
uxAverage=uxA(i)+uxAverage;
}
uxAverage=uxAverage/(th.area);
cout<<“Average=”<<uxAverage<< " " << “THAREA=”<< th.area <<endl;

This approach may work in your case, but this type of loop is slow and prone to rounding errors on large meshes. Additionally, this definition of uxA does not use a proper quadrature and may be very wrong for elements with bad aspect ratios. In general, I would recommend the other approach.

1 Like

Thank you very much Chris
you are right it is slow.
Your approach worked very well.

1 Like